* elf64-hppa.c (elf64_hppa_grok_prstatus): New function.
[deliverable/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");
dfa9f0d5
PB
571#define BAD_BRANCH _("branch must be last instruction in IT block")
572#define BAD_NOT_IT _("instruction not allowed in IT block")
c19d1205
ZW
573
574static struct hash_control *arm_ops_hsh;
575static struct hash_control *arm_cond_hsh;
576static struct hash_control *arm_shift_hsh;
577static struct hash_control *arm_psr_hsh;
62b3e311 578static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
579static struct hash_control *arm_reg_hsh;
580static struct hash_control *arm_reloc_hsh;
62b3e311 581static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 582
b99bd4ef
NC
583/* Stuff needed to resolve the label ambiguity
584 As:
585 ...
586 label: <insn>
587 may differ from:
588 ...
589 label:
c19d1205 590 <insn>
b99bd4ef
NC
591*/
592
593symbolS * last_label_seen;
b34976b6 594static int label_is_thumb_function_name = FALSE;
a737bd4d 595\f
3d0c9500
NC
596/* Literal pool structure. Held on a per-section
597 and per-sub-section basis. */
a737bd4d 598
c19d1205 599#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 600typedef struct literal_pool
b99bd4ef 601{
c19d1205
ZW
602 expressionS literals [MAX_LITERAL_POOL_SIZE];
603 unsigned int next_free_entry;
604 unsigned int id;
605 symbolS * symbol;
606 segT section;
607 subsegT sub_section;
61b5f74b 608 struct literal_pool * next;
3d0c9500 609} literal_pool;
b99bd4ef 610
3d0c9500
NC
611/* Pointer to a linked list of literal pools. */
612literal_pool * list_of_pools = NULL;
e27ec89e
PB
613
614/* State variables for IT block handling. */
615static bfd_boolean current_it_mask = 0;
616static int current_cc;
617
c19d1205
ZW
618\f
619/* Pure syntax. */
b99bd4ef 620
c19d1205
ZW
621/* This array holds the chars that always start a comment. If the
622 pre-processor is disabled, these aren't very useful. */
623const char comment_chars[] = "@";
3d0c9500 624
c19d1205
ZW
625/* This array holds the chars that only start a comment at the beginning of
626 a line. If the line seems to have the form '# 123 filename'
627 .line and .file directives will appear in the pre-processed output. */
628/* Note that input_file.c hand checks for '#' at the beginning of the
629 first line of the input file. This is because the compiler outputs
630 #NO_APP at the beginning of its output. */
631/* Also note that comments like this one will always work. */
632const char line_comment_chars[] = "#";
3d0c9500 633
c19d1205 634const char line_separator_chars[] = ";";
b99bd4ef 635
c19d1205
ZW
636/* Chars that can be used to separate mant
637 from exp in floating point numbers. */
638const char EXP_CHARS[] = "eE";
3d0c9500 639
c19d1205
ZW
640/* Chars that mean this number is a floating point constant. */
641/* As in 0f12.456 */
642/* or 0d1.2345e12 */
b99bd4ef 643
c19d1205 644const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 645
c19d1205
ZW
646/* Prefix characters that indicate the start of an immediate
647 value. */
648#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 649
c19d1205
ZW
650/* Separator character handling. */
651
652#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
653
654static inline int
655skip_past_char (char ** str, char c)
656{
657 if (**str == c)
658 {
659 (*str)++;
660 return SUCCESS;
3d0c9500 661 }
c19d1205
ZW
662 else
663 return FAIL;
664}
665#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 666
c19d1205
ZW
667/* Arithmetic expressions (possibly involving symbols). */
668
669/* Return TRUE if anything in the expression is a bignum. */
670
671static int
672walk_no_bignums (symbolS * sp)
673{
674 if (symbol_get_value_expression (sp)->X_op == O_big)
675 return 1;
676
677 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 678 {
c19d1205
ZW
679 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
680 || (symbol_get_value_expression (sp)->X_op_symbol
681 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
682 }
683
c19d1205 684 return 0;
3d0c9500
NC
685}
686
c19d1205
ZW
687static int in_my_get_expression = 0;
688
689/* Third argument to my_get_expression. */
690#define GE_NO_PREFIX 0
691#define GE_IMM_PREFIX 1
692#define GE_OPT_PREFIX 2
a737bd4d 693
b99bd4ef 694static int
c19d1205 695my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 696{
c19d1205
ZW
697 char * save_in;
698 segT seg;
b99bd4ef 699
c19d1205
ZW
700 /* In unified syntax, all prefixes are optional. */
701 if (unified_syntax)
702 prefix_mode = GE_OPT_PREFIX;
b99bd4ef 703
c19d1205 704 switch (prefix_mode)
b99bd4ef 705 {
c19d1205
ZW
706 case GE_NO_PREFIX: break;
707 case GE_IMM_PREFIX:
708 if (!is_immediate_prefix (**str))
709 {
710 inst.error = _("immediate expression requires a # prefix");
711 return FAIL;
712 }
713 (*str)++;
714 break;
715 case GE_OPT_PREFIX:
716 if (is_immediate_prefix (**str))
717 (*str)++;
718 break;
719 default: abort ();
720 }
b99bd4ef 721
c19d1205 722 memset (ep, 0, sizeof (expressionS));
b99bd4ef 723
c19d1205
ZW
724 save_in = input_line_pointer;
725 input_line_pointer = *str;
726 in_my_get_expression = 1;
727 seg = expression (ep);
728 in_my_get_expression = 0;
729
730 if (ep->X_op == O_illegal)
b99bd4ef 731 {
c19d1205
ZW
732 /* We found a bad expression in md_operand(). */
733 *str = input_line_pointer;
734 input_line_pointer = save_in;
735 if (inst.error == NULL)
736 inst.error = _("bad expression");
737 return 1;
738 }
b99bd4ef 739
c19d1205
ZW
740#ifdef OBJ_AOUT
741 if (seg != absolute_section
742 && seg != text_section
743 && seg != data_section
744 && seg != bss_section
745 && seg != undefined_section)
746 {
747 inst.error = _("bad segment");
748 *str = input_line_pointer;
749 input_line_pointer = save_in;
750 return 1;
b99bd4ef 751 }
c19d1205 752#endif
b99bd4ef 753
c19d1205
ZW
754 /* Get rid of any bignums now, so that we don't generate an error for which
755 we can't establish a line number later on. Big numbers are never valid
756 in instructions, which is where this routine is always called. */
757 if (ep->X_op == O_big
758 || (ep->X_add_symbol
759 && (walk_no_bignums (ep->X_add_symbol)
760 || (ep->X_op_symbol
761 && walk_no_bignums (ep->X_op_symbol)))))
762 {
763 inst.error = _("invalid constant");
764 *str = input_line_pointer;
765 input_line_pointer = save_in;
766 return 1;
767 }
b99bd4ef 768
c19d1205
ZW
769 *str = input_line_pointer;
770 input_line_pointer = save_in;
771 return 0;
b99bd4ef
NC
772}
773
c19d1205
ZW
774/* Turn a string in input_line_pointer into a floating point constant
775 of type TYPE, and store the appropriate bytes in *LITP. The number
776 of LITTLENUMS emitted is stored in *SIZEP. An error message is
777 returned, or NULL on OK.
b99bd4ef 778
c19d1205
ZW
779 Note that fp constants aren't represent in the normal way on the ARM.
780 In big endian mode, things are as expected. However, in little endian
781 mode fp constants are big-endian word-wise, and little-endian byte-wise
782 within the words. For example, (double) 1.1 in big endian mode is
783 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
784 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 785
c19d1205 786 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 787
c19d1205
ZW
788char *
789md_atof (int type, char * litP, int * sizeP)
790{
791 int prec;
792 LITTLENUM_TYPE words[MAX_LITTLENUMS];
793 char *t;
794 int i;
b99bd4ef 795
c19d1205
ZW
796 switch (type)
797 {
798 case 'f':
799 case 'F':
800 case 's':
801 case 'S':
802 prec = 2;
803 break;
b99bd4ef 804
c19d1205
ZW
805 case 'd':
806 case 'D':
807 case 'r':
808 case 'R':
809 prec = 4;
810 break;
b99bd4ef 811
c19d1205
ZW
812 case 'x':
813 case 'X':
814 prec = 6;
815 break;
b99bd4ef 816
c19d1205
ZW
817 case 'p':
818 case 'P':
819 prec = 6;
820 break;
a737bd4d 821
c19d1205
ZW
822 default:
823 *sizeP = 0;
824 return _("bad call to MD_ATOF()");
825 }
b99bd4ef 826
c19d1205
ZW
827 t = atof_ieee (input_line_pointer, type, words);
828 if (t)
829 input_line_pointer = t;
830 *sizeP = prec * 2;
b99bd4ef 831
c19d1205
ZW
832 if (target_big_endian)
833 {
834 for (i = 0; i < prec; i++)
835 {
836 md_number_to_chars (litP, (valueT) words[i], 2);
837 litP += 2;
838 }
839 }
840 else
841 {
e74cfd16 842 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
843 for (i = prec - 1; i >= 0; i--)
844 {
845 md_number_to_chars (litP, (valueT) words[i], 2);
846 litP += 2;
847 }
848 else
849 /* For a 4 byte float the order of elements in `words' is 1 0.
850 For an 8 byte float the order is 1 0 3 2. */
851 for (i = 0; i < prec; i += 2)
852 {
853 md_number_to_chars (litP, (valueT) words[i + 1], 2);
854 md_number_to_chars (litP + 2, (valueT) words[i], 2);
855 litP += 4;
856 }
857 }
b99bd4ef 858
c19d1205
ZW
859 return 0;
860}
b99bd4ef 861
c19d1205
ZW
862/* We handle all bad expressions here, so that we can report the faulty
863 instruction in the error message. */
864void
865md_operand (expressionS * expr)
866{
867 if (in_my_get_expression)
868 expr->X_op = O_illegal;
b99bd4ef
NC
869}
870
c19d1205 871/* Immediate values. */
b99bd4ef 872
c19d1205
ZW
873/* Generic immediate-value read function for use in directives.
874 Accepts anything that 'expression' can fold to a constant.
875 *val receives the number. */
876#ifdef OBJ_ELF
877static int
878immediate_for_directive (int *val)
b99bd4ef 879{
c19d1205
ZW
880 expressionS exp;
881 exp.X_op = O_illegal;
b99bd4ef 882
c19d1205
ZW
883 if (is_immediate_prefix (*input_line_pointer))
884 {
885 input_line_pointer++;
886 expression (&exp);
887 }
b99bd4ef 888
c19d1205
ZW
889 if (exp.X_op != O_constant)
890 {
891 as_bad (_("expected #constant"));
892 ignore_rest_of_line ();
893 return FAIL;
894 }
895 *val = exp.X_add_number;
896 return SUCCESS;
b99bd4ef 897}
c19d1205 898#endif
b99bd4ef 899
c19d1205 900/* Register parsing. */
b99bd4ef 901
c19d1205
ZW
902/* Generic register parser. CCP points to what should be the
903 beginning of a register name. If it is indeed a valid register
904 name, advance CCP over it and return the reg_entry structure;
905 otherwise return NULL. Does not issue diagnostics. */
906
907static struct reg_entry *
908arm_reg_parse_multi (char **ccp)
b99bd4ef 909{
c19d1205
ZW
910 char *start = *ccp;
911 char *p;
912 struct reg_entry *reg;
b99bd4ef 913
c19d1205
ZW
914#ifdef REGISTER_PREFIX
915 if (*start != REGISTER_PREFIX)
01cfc07f 916 return NULL;
c19d1205
ZW
917 start++;
918#endif
919#ifdef OPTIONAL_REGISTER_PREFIX
920 if (*start == OPTIONAL_REGISTER_PREFIX)
921 start++;
922#endif
b99bd4ef 923
c19d1205
ZW
924 p = start;
925 if (!ISALPHA (*p) || !is_name_beginner (*p))
926 return NULL;
b99bd4ef 927
c19d1205
ZW
928 do
929 p++;
930 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
931
932 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
933
934 if (!reg)
935 return NULL;
936
937 *ccp = p;
938 return reg;
b99bd4ef
NC
939}
940
c19d1205 941/* As above, but the register must be of type TYPE, and the return
01cfc07f 942 value is the register number or FAIL. */
c19d1205 943
b99bd4ef 944static int
c19d1205 945arm_reg_parse (char **ccp, enum arm_reg_type type)
b99bd4ef 946{
c19d1205
ZW
947 char *start = *ccp;
948 struct reg_entry *reg = arm_reg_parse_multi (ccp);
b99bd4ef 949
c19d1205
ZW
950 if (reg && reg->type == type)
951 return reg->number;
6057a28f 952
c19d1205
ZW
953 /* Alternative syntaxes are accepted for a few register classes. */
954 switch (type)
955 {
956 case REG_TYPE_MVF:
957 case REG_TYPE_MVD:
958 case REG_TYPE_MVFX:
959 case REG_TYPE_MVDX:
960 /* Generic coprocessor register names are allowed for these. */
79134647 961 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
962 return reg->number;
963 break;
69b97547 964
c19d1205
ZW
965 case REG_TYPE_CP:
966 /* For backward compatibility, a bare number is valid here. */
967 {
968 unsigned long processor = strtoul (start, ccp, 10);
969 if (*ccp != start && processor <= 15)
970 return processor;
971 }
6057a28f 972
c19d1205
ZW
973 case REG_TYPE_MMXWC:
974 /* WC includes WCG. ??? I'm not sure this is true for all
975 instructions that take WC registers. */
79134647 976 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 977 return reg->number;
6057a28f 978 break;
c19d1205 979
6057a28f 980 default:
c19d1205 981 break;
6057a28f
NC
982 }
983
c19d1205
ZW
984 *ccp = start;
985 return FAIL;
986}
69b97547 987
c19d1205
ZW
988/* Parse an ARM register list. Returns the bitmask, or FAIL. */
989static long
990parse_reg_list (char ** strp)
991{
992 char * str = * strp;
993 long range = 0;
994 int another_range;
a737bd4d 995
c19d1205
ZW
996 /* We come back here if we get ranges concatenated by '+' or '|'. */
997 do
6057a28f 998 {
c19d1205 999 another_range = 0;
a737bd4d 1000
c19d1205
ZW
1001 if (*str == '{')
1002 {
1003 int in_range = 0;
1004 int cur_reg = -1;
a737bd4d 1005
c19d1205
ZW
1006 str++;
1007 do
1008 {
1009 int reg;
6057a28f 1010
c19d1205
ZW
1011 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1012 {
1013 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
1014 return FAIL;
1015 }
a737bd4d 1016
c19d1205
ZW
1017 if (in_range)
1018 {
1019 int i;
a737bd4d 1020
c19d1205
ZW
1021 if (reg <= cur_reg)
1022 {
1023 inst.error = _("bad range in register list");
1024 return FAIL;
1025 }
40a18ebd 1026
c19d1205
ZW
1027 for (i = cur_reg + 1; i < reg; i++)
1028 {
1029 if (range & (1 << i))
1030 as_tsktsk
1031 (_("Warning: duplicated register (r%d) in register list"),
1032 i);
1033 else
1034 range |= 1 << i;
1035 }
1036 in_range = 0;
1037 }
a737bd4d 1038
c19d1205
ZW
1039 if (range & (1 << reg))
1040 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1041 reg);
1042 else if (reg <= cur_reg)
1043 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1044
c19d1205
ZW
1045 range |= 1 << reg;
1046 cur_reg = reg;
1047 }
1048 while (skip_past_comma (&str) != FAIL
1049 || (in_range = 1, *str++ == '-'));
1050 str--;
a737bd4d 1051
c19d1205
ZW
1052 if (*str++ != '}')
1053 {
1054 inst.error = _("missing `}'");
1055 return FAIL;
1056 }
1057 }
1058 else
1059 {
1060 expressionS expr;
40a18ebd 1061
c19d1205
ZW
1062 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1063 return FAIL;
40a18ebd 1064
c19d1205
ZW
1065 if (expr.X_op == O_constant)
1066 {
1067 if (expr.X_add_number
1068 != (expr.X_add_number & 0x0000ffff))
1069 {
1070 inst.error = _("invalid register mask");
1071 return FAIL;
1072 }
a737bd4d 1073
c19d1205
ZW
1074 if ((range & expr.X_add_number) != 0)
1075 {
1076 int regno = range & expr.X_add_number;
a737bd4d 1077
c19d1205
ZW
1078 regno &= -regno;
1079 regno = (1 << regno) - 1;
1080 as_tsktsk
1081 (_("Warning: duplicated register (r%d) in register list"),
1082 regno);
1083 }
a737bd4d 1084
c19d1205
ZW
1085 range |= expr.X_add_number;
1086 }
1087 else
1088 {
1089 if (inst.reloc.type != 0)
1090 {
1091 inst.error = _("expression too complex");
1092 return FAIL;
1093 }
a737bd4d 1094
c19d1205
ZW
1095 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1096 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1097 inst.reloc.pc_rel = 0;
1098 }
1099 }
a737bd4d 1100
c19d1205
ZW
1101 if (*str == '|' || *str == '+')
1102 {
1103 str++;
1104 another_range = 1;
1105 }
a737bd4d 1106 }
c19d1205 1107 while (another_range);
a737bd4d 1108
c19d1205
ZW
1109 *strp = str;
1110 return range;
a737bd4d
NC
1111}
1112
c19d1205
ZW
1113/* Parse a VFP register list. If the string is invalid return FAIL.
1114 Otherwise return the number of registers, and set PBASE to the first
1115 register. Double precision registers are matched if DP is nonzero. */
6057a28f 1116
c19d1205 1117static int
ca3f61f7 1118parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
6057a28f 1119{
c19d1205
ZW
1120 int base_reg;
1121 int new_base;
1122 int regtype;
1123 int max_regs;
1124 int count = 0;
1125 int warned = 0;
1126 unsigned long mask = 0;
a737bd4d 1127 int i;
6057a28f 1128
c19d1205
ZW
1129 if (**str != '{')
1130 return FAIL;
6057a28f 1131
c19d1205 1132 (*str)++;
6057a28f 1133
c19d1205 1134 if (dp)
a737bd4d 1135 {
c19d1205
ZW
1136 regtype = REG_TYPE_VFD;
1137 max_regs = 16;
1138 }
1139 else
1140 {
1141 regtype = REG_TYPE_VFS;
1142 max_regs = 32;
1143 }
6057a28f 1144
c19d1205 1145 base_reg = max_regs;
a737bd4d 1146
c19d1205
ZW
1147 do
1148 {
1149 new_base = arm_reg_parse (str, regtype);
1150 if (new_base == FAIL)
a737bd4d 1151 {
c19d1205
ZW
1152 inst.error = gettext (reg_expected_msgs[regtype]);
1153 return FAIL;
1154 }
a737bd4d 1155
c19d1205
ZW
1156 if (new_base < base_reg)
1157 base_reg = new_base;
a737bd4d 1158
c19d1205
ZW
1159 if (mask & (1 << new_base))
1160 {
1161 inst.error = _("invalid register list");
1162 return FAIL;
a737bd4d 1163 }
a737bd4d 1164
c19d1205
ZW
1165 if ((mask >> new_base) != 0 && ! warned)
1166 {
1167 as_tsktsk (_("register list not in ascending order"));
1168 warned = 1;
1169 }
0bbf2aa4 1170
c19d1205
ZW
1171 mask |= 1 << new_base;
1172 count++;
0bbf2aa4 1173
c19d1205
ZW
1174 if (**str == '-') /* We have the start of a range expression */
1175 {
1176 int high_range;
0bbf2aa4 1177
c19d1205 1178 (*str)++;
0bbf2aa4 1179
c19d1205
ZW
1180 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1181 {
1182 inst.error = gettext (reg_expected_msgs[regtype]);
1183 return FAIL;
1184 }
0bbf2aa4 1185
c19d1205
ZW
1186 if (high_range <= new_base)
1187 {
1188 inst.error = _("register range not in ascending order");
1189 return FAIL;
1190 }
0bbf2aa4 1191
c19d1205 1192 for (new_base++; new_base <= high_range; new_base++)
0bbf2aa4 1193 {
c19d1205 1194 if (mask & (1 << new_base))
0bbf2aa4 1195 {
c19d1205
ZW
1196 inst.error = _("invalid register list");
1197 return FAIL;
0bbf2aa4 1198 }
c19d1205
ZW
1199
1200 mask |= 1 << new_base;
1201 count++;
0bbf2aa4 1202 }
0bbf2aa4 1203 }
0bbf2aa4 1204 }
c19d1205 1205 while (skip_past_comma (str) != FAIL);
0bbf2aa4 1206
c19d1205 1207 (*str)++;
0bbf2aa4 1208
c19d1205
ZW
1209 /* Sanity check -- should have raised a parse error above. */
1210 if (count == 0 || count > max_regs)
1211 abort ();
1212
1213 *pbase = base_reg;
1214
1215 /* Final test -- the registers must be consecutive. */
1216 mask >>= base_reg;
1217 for (i = 0; i < count; i++)
1218 {
1219 if ((mask & (1u << i)) == 0)
1220 {
1221 inst.error = _("non-contiguous register range");
1222 return FAIL;
1223 }
1224 }
1225
1226 return count;
b99bd4ef
NC
1227}
1228
c19d1205
ZW
1229/* Parse an explicit relocation suffix on an expression. This is
1230 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1231 arm_reloc_hsh contains no entries, so this function can only
1232 succeed if there is no () after the word. Returns -1 on error,
1233 BFD_RELOC_UNUSED if there wasn't any suffix. */
1234static int
1235parse_reloc (char **str)
b99bd4ef 1236{
c19d1205
ZW
1237 struct reloc_entry *r;
1238 char *p, *q;
b99bd4ef 1239
c19d1205
ZW
1240 if (**str != '(')
1241 return BFD_RELOC_UNUSED;
b99bd4ef 1242
c19d1205
ZW
1243 p = *str + 1;
1244 q = p;
1245
1246 while (*q && *q != ')' && *q != ',')
1247 q++;
1248 if (*q != ')')
1249 return -1;
1250
1251 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1252 return -1;
1253
1254 *str = q + 1;
1255 return r->reloc;
b99bd4ef
NC
1256}
1257
c19d1205
ZW
1258/* Directives: register aliases. */
1259
b99bd4ef 1260static void
c19d1205 1261insert_reg_alias (char *str, int number, int type)
b99bd4ef 1262{
c19d1205
ZW
1263 struct reg_entry *new;
1264 const char *name;
b99bd4ef 1265
c19d1205
ZW
1266 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1267 {
1268 if (new->builtin)
1269 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1270
c19d1205
ZW
1271 /* Only warn about a redefinition if it's not defined as the
1272 same register. */
1273 else if (new->number != number || new->type != type)
1274 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1275
c19d1205
ZW
1276 return;
1277 }
b99bd4ef 1278
c19d1205
ZW
1279 name = xstrdup (str);
1280 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1281
c19d1205
ZW
1282 new->name = name;
1283 new->number = number;
1284 new->type = type;
1285 new->builtin = FALSE;
b99bd4ef 1286
c19d1205
ZW
1287 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1288 abort ();
1289}
b99bd4ef 1290
c19d1205 1291/* Look for the .req directive. This is of the form:
b99bd4ef 1292
c19d1205 1293 new_register_name .req existing_register_name
b99bd4ef 1294
c19d1205
ZW
1295 If we find one, or if it looks sufficiently like one that we want to
1296 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 1297
c19d1205
ZW
1298static int
1299create_register_alias (char * newname, char *p)
1300{
1301 struct reg_entry *old;
1302 char *oldname, *nbuf;
1303 size_t nlen;
b99bd4ef 1304
c19d1205
ZW
1305 /* The input scrubber ensures that whitespace after the mnemonic is
1306 collapsed to single spaces. */
1307 oldname = p;
1308 if (strncmp (oldname, " .req ", 6) != 0)
1309 return 0;
b99bd4ef 1310
c19d1205
ZW
1311 oldname += 6;
1312 if (*oldname == '\0')
1313 return 0;
b99bd4ef 1314
c19d1205
ZW
1315 old = hash_find (arm_reg_hsh, oldname);
1316 if (!old)
b99bd4ef 1317 {
c19d1205
ZW
1318 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1319 return 1;
b99bd4ef
NC
1320 }
1321
c19d1205
ZW
1322 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1323 the desired alias name, and p points to its end. If not, then
1324 the desired alias name is in the global original_case_string. */
1325#ifdef TC_CASE_SENSITIVE
1326 nlen = p - newname;
1327#else
1328 newname = original_case_string;
1329 nlen = strlen (newname);
1330#endif
b99bd4ef 1331
c19d1205
ZW
1332 nbuf = alloca (nlen + 1);
1333 memcpy (nbuf, newname, nlen);
1334 nbuf[nlen] = '\0';
b99bd4ef 1335
c19d1205
ZW
1336 /* Create aliases under the new name as stated; an all-lowercase
1337 version of the new name; and an all-uppercase version of the new
1338 name. */
1339 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 1340
c19d1205
ZW
1341 for (p = nbuf; *p; p++)
1342 *p = TOUPPER (*p);
1343
1344 if (strncmp (nbuf, newname, nlen))
1345 insert_reg_alias (nbuf, old->number, old->type);
1346
1347 for (p = nbuf; *p; p++)
1348 *p = TOLOWER (*p);
1349
1350 if (strncmp (nbuf, newname, nlen))
1351 insert_reg_alias (nbuf, old->number, old->type);
1352
1353 return 1;
b99bd4ef
NC
1354}
1355
c19d1205
ZW
1356/* Should never be called, as .req goes between the alias and the
1357 register name, not at the beginning of the line. */
b99bd4ef 1358static void
c19d1205 1359s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 1360{
c19d1205
ZW
1361 as_bad (_("invalid syntax for .req directive"));
1362}
b99bd4ef 1363
c19d1205
ZW
1364/* The .unreq directive deletes an alias which was previously defined
1365 by .req. For example:
b99bd4ef 1366
c19d1205
ZW
1367 my_alias .req r11
1368 .unreq my_alias */
b99bd4ef
NC
1369
1370static void
c19d1205 1371s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 1372{
c19d1205
ZW
1373 char * name;
1374 char saved_char;
b99bd4ef 1375
c19d1205
ZW
1376 name = input_line_pointer;
1377
1378 while (*input_line_pointer != 0
1379 && *input_line_pointer != ' '
1380 && *input_line_pointer != '\n')
1381 ++input_line_pointer;
1382
1383 saved_char = *input_line_pointer;
1384 *input_line_pointer = 0;
1385
1386 if (!*name)
1387 as_bad (_("invalid syntax for .unreq directive"));
1388 else
1389 {
1390 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1391
1392 if (!reg)
1393 as_bad (_("unknown register alias '%s'"), name);
1394 else if (reg->builtin)
1395 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1396 name);
1397 else
1398 {
1399 hash_delete (arm_reg_hsh, name);
1400 free ((char *) reg->name);
1401 free (reg);
1402 }
1403 }
b99bd4ef 1404
c19d1205 1405 *input_line_pointer = saved_char;
b99bd4ef
NC
1406 demand_empty_rest_of_line ();
1407}
1408
c19d1205
ZW
1409/* Directives: Instruction set selection. */
1410
1411#ifdef OBJ_ELF
1412/* This code is to handle mapping symbols as defined in the ARM ELF spec.
1413 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1414 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1415 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1416
1417static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
1418
1419static void
c19d1205 1420mapping_state (enum mstate state)
b99bd4ef 1421{
a737bd4d 1422 symbolS * symbolP;
c19d1205
ZW
1423 const char * symname;
1424 int type;
b99bd4ef 1425
c19d1205
ZW
1426 if (mapstate == state)
1427 /* The mapping symbol has already been emitted.
1428 There is nothing else to do. */
1429 return;
b99bd4ef 1430
c19d1205 1431 mapstate = state;
b99bd4ef 1432
c19d1205 1433 switch (state)
b99bd4ef 1434 {
c19d1205
ZW
1435 case MAP_DATA:
1436 symname = "$d";
1437 type = BSF_NO_FLAGS;
1438 break;
1439 case MAP_ARM:
1440 symname = "$a";
1441 type = BSF_NO_FLAGS;
1442 break;
1443 case MAP_THUMB:
1444 symname = "$t";
1445 type = BSF_NO_FLAGS;
1446 break;
1447 case MAP_UNDEFINED:
1448 return;
1449 default:
1450 abort ();
1451 }
1452
1453 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1454
1455 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1456 symbol_table_insert (symbolP);
1457 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1458
1459 switch (state)
1460 {
1461 case MAP_ARM:
1462 THUMB_SET_FUNC (symbolP, 0);
1463 ARM_SET_THUMB (symbolP, 0);
1464 ARM_SET_INTERWORK (symbolP, support_interwork);
1465 break;
1466
1467 case MAP_THUMB:
1468 THUMB_SET_FUNC (symbolP, 1);
1469 ARM_SET_THUMB (symbolP, 1);
1470 ARM_SET_INTERWORK (symbolP, support_interwork);
1471 break;
1472
1473 case MAP_DATA:
1474 default:
1475 return;
1476 }
1477}
1478#else
1479#define mapping_state(x) /* nothing */
1480#endif
1481
1482/* Find the real, Thumb encoded start of a Thumb function. */
1483
1484static symbolS *
1485find_real_start (symbolS * symbolP)
1486{
1487 char * real_start;
1488 const char * name = S_GET_NAME (symbolP);
1489 symbolS * new_target;
1490
1491 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1492#define STUB_NAME ".real_start_of"
1493
1494 if (name == NULL)
1495 abort ();
1496
37f6032b
ZW
1497 /* The compiler may generate BL instructions to local labels because
1498 it needs to perform a branch to a far away location. These labels
1499 do not have a corresponding ".real_start_of" label. We check
1500 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1501 the ".real_start_of" convention for nonlocal branches. */
1502 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
1503 return symbolP;
1504
37f6032b 1505 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
1506 new_target = symbol_find (real_start);
1507
1508 if (new_target == NULL)
1509 {
1510 as_warn ("Failed to find real start of function: %s\n", name);
1511 new_target = symbolP;
1512 }
1513
c19d1205
ZW
1514 return new_target;
1515}
1516
1517static void
1518opcode_select (int width)
1519{
1520 switch (width)
1521 {
1522 case 16:
1523 if (! thumb_mode)
1524 {
e74cfd16 1525 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
1526 as_bad (_("selected processor does not support THUMB opcodes"));
1527
1528 thumb_mode = 1;
1529 /* No need to force the alignment, since we will have been
1530 coming from ARM mode, which is word-aligned. */
1531 record_alignment (now_seg, 1);
1532 }
1533 mapping_state (MAP_THUMB);
1534 break;
1535
1536 case 32:
1537 if (thumb_mode)
1538 {
e74cfd16 1539 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
1540 as_bad (_("selected processor does not support ARM opcodes"));
1541
1542 thumb_mode = 0;
1543
1544 if (!need_pass_2)
1545 frag_align (2, 0, 0);
1546
1547 record_alignment (now_seg, 1);
1548 }
1549 mapping_state (MAP_ARM);
1550 break;
1551
1552 default:
1553 as_bad (_("invalid instruction size selected (%d)"), width);
1554 }
1555}
1556
1557static void
1558s_arm (int ignore ATTRIBUTE_UNUSED)
1559{
1560 opcode_select (32);
1561 demand_empty_rest_of_line ();
1562}
1563
1564static void
1565s_thumb (int ignore ATTRIBUTE_UNUSED)
1566{
1567 opcode_select (16);
1568 demand_empty_rest_of_line ();
1569}
1570
1571static void
1572s_code (int unused ATTRIBUTE_UNUSED)
1573{
1574 int temp;
1575
1576 temp = get_absolute_expression ();
1577 switch (temp)
1578 {
1579 case 16:
1580 case 32:
1581 opcode_select (temp);
1582 break;
1583
1584 default:
1585 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1586 }
1587}
1588
1589static void
1590s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1591{
1592 /* If we are not already in thumb mode go into it, EVEN if
1593 the target processor does not support thumb instructions.
1594 This is used by gcc/config/arm/lib1funcs.asm for example
1595 to compile interworking support functions even if the
1596 target processor should not support interworking. */
1597 if (! thumb_mode)
1598 {
1599 thumb_mode = 2;
1600 record_alignment (now_seg, 1);
1601 }
1602
1603 demand_empty_rest_of_line ();
1604}
1605
1606static void
1607s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1608{
1609 s_thumb (0);
1610
1611 /* The following label is the name/address of the start of a Thumb function.
1612 We need to know this for the interworking support. */
1613 label_is_thumb_function_name = TRUE;
1614}
1615
1616/* Perform a .set directive, but also mark the alias as
1617 being a thumb function. */
1618
1619static void
1620s_thumb_set (int equiv)
1621{
1622 /* XXX the following is a duplicate of the code for s_set() in read.c
1623 We cannot just call that code as we need to get at the symbol that
1624 is created. */
1625 char * name;
1626 char delim;
1627 char * end_name;
1628 symbolS * symbolP;
1629
1630 /* Especial apologies for the random logic:
1631 This just grew, and could be parsed much more simply!
1632 Dean - in haste. */
1633 name = input_line_pointer;
1634 delim = get_symbol_end ();
1635 end_name = input_line_pointer;
1636 *end_name = delim;
1637
1638 if (*input_line_pointer != ',')
1639 {
1640 *end_name = 0;
1641 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1642 *end_name = delim;
1643 ignore_rest_of_line ();
1644 return;
1645 }
1646
1647 input_line_pointer++;
1648 *end_name = 0;
1649
1650 if (name[0] == '.' && name[1] == '\0')
1651 {
1652 /* XXX - this should not happen to .thumb_set. */
1653 abort ();
1654 }
1655
1656 if ((symbolP = symbol_find (name)) == NULL
1657 && (symbolP = md_undefined_symbol (name)) == NULL)
1658 {
1659#ifndef NO_LISTING
1660 /* When doing symbol listings, play games with dummy fragments living
1661 outside the normal fragment chain to record the file and line info
c19d1205 1662 for this symbol. */
b99bd4ef
NC
1663 if (listing & LISTING_SYMBOLS)
1664 {
1665 extern struct list_info_struct * listing_tail;
a737bd4d 1666 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1667
1668 memset (dummy_frag, 0, sizeof (fragS));
1669 dummy_frag->fr_type = rs_fill;
1670 dummy_frag->line = listing_tail;
1671 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1672 dummy_frag->fr_symbol = symbolP;
1673 }
1674 else
1675#endif
1676 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1677
1678#ifdef OBJ_COFF
1679 /* "set" symbols are local unless otherwise specified. */
1680 SF_SET_LOCAL (symbolP);
1681#endif /* OBJ_COFF */
1682 } /* Make a new symbol. */
1683
1684 symbol_table_insert (symbolP);
1685
1686 * end_name = delim;
1687
1688 if (equiv
1689 && S_IS_DEFINED (symbolP)
1690 && S_GET_SEGMENT (symbolP) != reg_section)
1691 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1692
1693 pseudo_set (symbolP);
1694
1695 demand_empty_rest_of_line ();
1696
c19d1205 1697 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1698
1699 THUMB_SET_FUNC (symbolP, 1);
1700 ARM_SET_THUMB (symbolP, 1);
1701#if defined OBJ_ELF || defined OBJ_COFF
1702 ARM_SET_INTERWORK (symbolP, support_interwork);
1703#endif
1704}
1705
c19d1205 1706/* Directives: Mode selection. */
b99bd4ef 1707
c19d1205
ZW
1708/* .syntax [unified|divided] - choose the new unified syntax
1709 (same for Arm and Thumb encoding, modulo slight differences in what
1710 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1711static void
c19d1205 1712s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1713{
c19d1205
ZW
1714 char *name, delim;
1715
1716 name = input_line_pointer;
1717 delim = get_symbol_end ();
1718
1719 if (!strcasecmp (name, "unified"))
1720 unified_syntax = TRUE;
1721 else if (!strcasecmp (name, "divided"))
1722 unified_syntax = FALSE;
1723 else
1724 {
1725 as_bad (_("unrecognized syntax mode \"%s\""), name);
1726 return;
1727 }
1728 *input_line_pointer = delim;
b99bd4ef
NC
1729 demand_empty_rest_of_line ();
1730}
1731
c19d1205
ZW
1732/* Directives: sectioning and alignment. */
1733
1734/* Same as s_align_ptwo but align 0 => align 2. */
1735
b99bd4ef 1736static void
c19d1205 1737s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1738{
a737bd4d 1739 int temp;
c19d1205
ZW
1740 long temp_fill;
1741 long max_alignment = 15;
b99bd4ef
NC
1742
1743 temp = get_absolute_expression ();
c19d1205
ZW
1744 if (temp > max_alignment)
1745 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1746 else if (temp < 0)
b99bd4ef 1747 {
c19d1205
ZW
1748 as_bad (_("alignment negative. 0 assumed."));
1749 temp = 0;
1750 }
b99bd4ef 1751
c19d1205
ZW
1752 if (*input_line_pointer == ',')
1753 {
1754 input_line_pointer++;
1755 temp_fill = get_absolute_expression ();
b99bd4ef 1756 }
c19d1205
ZW
1757 else
1758 temp_fill = 0;
b99bd4ef 1759
c19d1205
ZW
1760 if (!temp)
1761 temp = 2;
b99bd4ef 1762
c19d1205
ZW
1763 /* Only make a frag if we HAVE to. */
1764 if (temp && !need_pass_2)
1765 frag_align (temp, (int) temp_fill, 0);
1766 demand_empty_rest_of_line ();
1767
1768 record_alignment (now_seg, temp);
b99bd4ef
NC
1769}
1770
c19d1205
ZW
1771static void
1772s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1773{
c19d1205
ZW
1774 /* We don't support putting frags in the BSS segment, we fake it by
1775 marking in_bss, then looking at s_skip for clues. */
1776 subseg_set (bss_section, 0);
1777 demand_empty_rest_of_line ();
1778 mapping_state (MAP_DATA);
1779}
b99bd4ef 1780
c19d1205
ZW
1781static void
1782s_even (int ignore ATTRIBUTE_UNUSED)
1783{
1784 /* Never make frag if expect extra pass. */
1785 if (!need_pass_2)
1786 frag_align (1, 0, 0);
b99bd4ef 1787
c19d1205 1788 record_alignment (now_seg, 1);
b99bd4ef 1789
c19d1205 1790 demand_empty_rest_of_line ();
b99bd4ef
NC
1791}
1792
c19d1205 1793/* Directives: Literal pools. */
a737bd4d 1794
c19d1205
ZW
1795static literal_pool *
1796find_literal_pool (void)
a737bd4d 1797{
c19d1205 1798 literal_pool * pool;
a737bd4d 1799
c19d1205 1800 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1801 {
c19d1205
ZW
1802 if (pool->section == now_seg
1803 && pool->sub_section == now_subseg)
1804 break;
a737bd4d
NC
1805 }
1806
c19d1205 1807 return pool;
a737bd4d
NC
1808}
1809
c19d1205
ZW
1810static literal_pool *
1811find_or_make_literal_pool (void)
a737bd4d 1812{
c19d1205
ZW
1813 /* Next literal pool ID number. */
1814 static unsigned int latest_pool_num = 1;
1815 literal_pool * pool;
a737bd4d 1816
c19d1205 1817 pool = find_literal_pool ();
a737bd4d 1818
c19d1205 1819 if (pool == NULL)
a737bd4d 1820 {
c19d1205
ZW
1821 /* Create a new pool. */
1822 pool = xmalloc (sizeof (* pool));
1823 if (! pool)
1824 return NULL;
a737bd4d 1825
c19d1205
ZW
1826 pool->next_free_entry = 0;
1827 pool->section = now_seg;
1828 pool->sub_section = now_subseg;
1829 pool->next = list_of_pools;
1830 pool->symbol = NULL;
1831
1832 /* Add it to the list. */
1833 list_of_pools = pool;
a737bd4d 1834 }
a737bd4d 1835
c19d1205
ZW
1836 /* New pools, and emptied pools, will have a NULL symbol. */
1837 if (pool->symbol == NULL)
a737bd4d 1838 {
c19d1205
ZW
1839 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1840 (valueT) 0, &zero_address_frag);
1841 pool->id = latest_pool_num ++;
a737bd4d
NC
1842 }
1843
c19d1205
ZW
1844 /* Done. */
1845 return pool;
a737bd4d
NC
1846}
1847
c19d1205
ZW
1848/* Add the literal in the global 'inst'
1849 structure to the relevent literal pool. */
b99bd4ef
NC
1850
1851static int
c19d1205 1852add_to_lit_pool (void)
b99bd4ef 1853{
c19d1205
ZW
1854 literal_pool * pool;
1855 unsigned int entry;
b99bd4ef 1856
c19d1205
ZW
1857 pool = find_or_make_literal_pool ();
1858
1859 /* Check if this literal value is already in the pool. */
1860 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1861 {
c19d1205
ZW
1862 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1863 && (inst.reloc.exp.X_op == O_constant)
1864 && (pool->literals[entry].X_add_number
1865 == inst.reloc.exp.X_add_number)
1866 && (pool->literals[entry].X_unsigned
1867 == inst.reloc.exp.X_unsigned))
1868 break;
1869
1870 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1871 && (inst.reloc.exp.X_op == O_symbol)
1872 && (pool->literals[entry].X_add_number
1873 == inst.reloc.exp.X_add_number)
1874 && (pool->literals[entry].X_add_symbol
1875 == inst.reloc.exp.X_add_symbol)
1876 && (pool->literals[entry].X_op_symbol
1877 == inst.reloc.exp.X_op_symbol))
1878 break;
b99bd4ef
NC
1879 }
1880
c19d1205
ZW
1881 /* Do we need to create a new entry? */
1882 if (entry == pool->next_free_entry)
1883 {
1884 if (entry >= MAX_LITERAL_POOL_SIZE)
1885 {
1886 inst.error = _("literal pool overflow");
1887 return FAIL;
1888 }
1889
1890 pool->literals[entry] = inst.reloc.exp;
1891 pool->next_free_entry += 1;
1892 }
b99bd4ef 1893
c19d1205
ZW
1894 inst.reloc.exp.X_op = O_symbol;
1895 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1896 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1897
c19d1205 1898 return SUCCESS;
b99bd4ef
NC
1899}
1900
c19d1205
ZW
1901/* Can't use symbol_new here, so have to create a symbol and then at
1902 a later date assign it a value. Thats what these functions do. */
e16bb312 1903
c19d1205
ZW
1904static void
1905symbol_locate (symbolS * symbolP,
1906 const char * name, /* It is copied, the caller can modify. */
1907 segT segment, /* Segment identifier (SEG_<something>). */
1908 valueT valu, /* Symbol value. */
1909 fragS * frag) /* Associated fragment. */
1910{
1911 unsigned int name_length;
1912 char * preserved_copy_of_name;
e16bb312 1913
c19d1205
ZW
1914 name_length = strlen (name) + 1; /* +1 for \0. */
1915 obstack_grow (&notes, name, name_length);
1916 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1917
c19d1205
ZW
1918#ifdef tc_canonicalize_symbol_name
1919 preserved_copy_of_name =
1920 tc_canonicalize_symbol_name (preserved_copy_of_name);
1921#endif
b99bd4ef 1922
c19d1205 1923 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1924
c19d1205
ZW
1925 S_SET_SEGMENT (symbolP, segment);
1926 S_SET_VALUE (symbolP, valu);
1927 symbol_clear_list_pointers (symbolP);
b99bd4ef 1928
c19d1205 1929 symbol_set_frag (symbolP, frag);
b99bd4ef 1930
c19d1205
ZW
1931 /* Link to end of symbol chain. */
1932 {
1933 extern int symbol_table_frozen;
b99bd4ef 1934
c19d1205
ZW
1935 if (symbol_table_frozen)
1936 abort ();
1937 }
b99bd4ef 1938
c19d1205 1939 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1940
c19d1205 1941 obj_symbol_new_hook (symbolP);
b99bd4ef 1942
c19d1205
ZW
1943#ifdef tc_symbol_new_hook
1944 tc_symbol_new_hook (symbolP);
1945#endif
1946
1947#ifdef DEBUG_SYMS
1948 verify_symbol_chain (symbol_rootP, symbol_lastP);
1949#endif /* DEBUG_SYMS */
b99bd4ef
NC
1950}
1951
b99bd4ef 1952
c19d1205
ZW
1953static void
1954s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1955{
c19d1205
ZW
1956 unsigned int entry;
1957 literal_pool * pool;
1958 char sym_name[20];
b99bd4ef 1959
c19d1205
ZW
1960 pool = find_literal_pool ();
1961 if (pool == NULL
1962 || pool->symbol == NULL
1963 || pool->next_free_entry == 0)
1964 return;
b99bd4ef 1965
c19d1205 1966 mapping_state (MAP_DATA);
b99bd4ef 1967
c19d1205
ZW
1968 /* Align pool as you have word accesses.
1969 Only make a frag if we have to. */
1970 if (!need_pass_2)
1971 frag_align (2, 0, 0);
b99bd4ef 1972
c19d1205 1973 record_alignment (now_seg, 2);
b99bd4ef 1974
c19d1205 1975 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1976
c19d1205
ZW
1977 symbol_locate (pool->symbol, sym_name, now_seg,
1978 (valueT) frag_now_fix (), frag_now);
1979 symbol_table_insert (pool->symbol);
b99bd4ef 1980
c19d1205 1981 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1982
c19d1205
ZW
1983#if defined OBJ_COFF || defined OBJ_ELF
1984 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1985#endif
6c43fab6 1986
c19d1205
ZW
1987 for (entry = 0; entry < pool->next_free_entry; entry ++)
1988 /* First output the expression in the instruction to the pool. */
1989 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1990
c19d1205
ZW
1991 /* Mark the pool as empty. */
1992 pool->next_free_entry = 0;
1993 pool->symbol = NULL;
b99bd4ef
NC
1994}
1995
c19d1205
ZW
1996#ifdef OBJ_ELF
1997/* Forward declarations for functions below, in the MD interface
1998 section. */
1999static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2000static valueT create_unwind_entry (int);
2001static void start_unwind_section (const segT, int);
2002static void add_unwind_opcode (valueT, int);
2003static void flush_pending_unwind (void);
b99bd4ef 2004
c19d1205 2005/* Directives: Data. */
b99bd4ef 2006
c19d1205
ZW
2007static void
2008s_arm_elf_cons (int nbytes)
2009{
2010 expressionS exp;
b99bd4ef 2011
c19d1205
ZW
2012#ifdef md_flush_pending_output
2013 md_flush_pending_output ();
2014#endif
b99bd4ef 2015
c19d1205 2016 if (is_it_end_of_statement ())
b99bd4ef 2017 {
c19d1205
ZW
2018 demand_empty_rest_of_line ();
2019 return;
b99bd4ef
NC
2020 }
2021
c19d1205
ZW
2022#ifdef md_cons_align
2023 md_cons_align (nbytes);
2024#endif
b99bd4ef 2025
c19d1205
ZW
2026 mapping_state (MAP_DATA);
2027 do
b99bd4ef 2028 {
c19d1205
ZW
2029 int reloc;
2030 char *base = input_line_pointer;
b99bd4ef 2031
c19d1205 2032 expression (& exp);
b99bd4ef 2033
c19d1205
ZW
2034 if (exp.X_op != O_symbol)
2035 emit_expr (&exp, (unsigned int) nbytes);
2036 else
2037 {
2038 char *before_reloc = input_line_pointer;
2039 reloc = parse_reloc (&input_line_pointer);
2040 if (reloc == -1)
2041 {
2042 as_bad (_("unrecognized relocation suffix"));
2043 ignore_rest_of_line ();
2044 return;
2045 }
2046 else if (reloc == BFD_RELOC_UNUSED)
2047 emit_expr (&exp, (unsigned int) nbytes);
2048 else
2049 {
2050 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2051 int size = bfd_get_reloc_size (howto);
b99bd4ef 2052
2fc8bdac
ZW
2053 if (reloc == BFD_RELOC_ARM_PLT32)
2054 {
2055 as_bad (_("(plt) is only valid on branch targets"));
2056 reloc = BFD_RELOC_UNUSED;
2057 size = 0;
2058 }
2059
c19d1205 2060 if (size > nbytes)
2fc8bdac 2061 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2062 howto->name, nbytes);
2063 else
2064 {
2065 /* We've parsed an expression stopping at O_symbol.
2066 But there may be more expression left now that we
2067 have parsed the relocation marker. Parse it again.
2068 XXX Surely there is a cleaner way to do this. */
2069 char *p = input_line_pointer;
2070 int offset;
2071 char *save_buf = alloca (input_line_pointer - base);
2072 memcpy (save_buf, base, input_line_pointer - base);
2073 memmove (base + (input_line_pointer - before_reloc),
2074 base, before_reloc - base);
2075
2076 input_line_pointer = base + (input_line_pointer-before_reloc);
2077 expression (&exp);
2078 memcpy (base, save_buf, p - base);
2079
2080 offset = nbytes - size;
2081 p = frag_more ((int) nbytes);
2082 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2083 size, &exp, 0, reloc);
2084 }
2085 }
2086 }
b99bd4ef 2087 }
c19d1205 2088 while (*input_line_pointer++ == ',');
b99bd4ef 2089
c19d1205
ZW
2090 /* Put terminator back into stream. */
2091 input_line_pointer --;
2092 demand_empty_rest_of_line ();
b99bd4ef
NC
2093}
2094
b99bd4ef 2095
c19d1205 2096/* Parse a .rel31 directive. */
b99bd4ef 2097
c19d1205
ZW
2098static void
2099s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2100{
2101 expressionS exp;
2102 char *p;
2103 valueT highbit;
b99bd4ef 2104
c19d1205
ZW
2105 highbit = 0;
2106 if (*input_line_pointer == '1')
2107 highbit = 0x80000000;
2108 else if (*input_line_pointer != '0')
2109 as_bad (_("expected 0 or 1"));
b99bd4ef 2110
c19d1205
ZW
2111 input_line_pointer++;
2112 if (*input_line_pointer != ',')
2113 as_bad (_("missing comma"));
2114 input_line_pointer++;
b99bd4ef 2115
c19d1205
ZW
2116#ifdef md_flush_pending_output
2117 md_flush_pending_output ();
2118#endif
b99bd4ef 2119
c19d1205
ZW
2120#ifdef md_cons_align
2121 md_cons_align (4);
2122#endif
b99bd4ef 2123
c19d1205 2124 mapping_state (MAP_DATA);
b99bd4ef 2125
c19d1205 2126 expression (&exp);
b99bd4ef 2127
c19d1205
ZW
2128 p = frag_more (4);
2129 md_number_to_chars (p, highbit, 4);
2130 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2131 BFD_RELOC_ARM_PREL31);
b99bd4ef 2132
c19d1205 2133 demand_empty_rest_of_line ();
b99bd4ef
NC
2134}
2135
c19d1205 2136/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2137
c19d1205 2138/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2139
c19d1205
ZW
2140static void
2141s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2142{
2143 demand_empty_rest_of_line ();
2144 /* Mark the start of the function. */
2145 unwind.proc_start = expr_build_dot ();
b99bd4ef 2146
c19d1205
ZW
2147 /* Reset the rest of the unwind info. */
2148 unwind.opcode_count = 0;
2149 unwind.table_entry = NULL;
2150 unwind.personality_routine = NULL;
2151 unwind.personality_index = -1;
2152 unwind.frame_size = 0;
2153 unwind.fp_offset = 0;
2154 unwind.fp_reg = 13;
2155 unwind.fp_used = 0;
2156 unwind.sp_restored = 0;
2157}
b99bd4ef 2158
b99bd4ef 2159
c19d1205
ZW
2160/* Parse a handlerdata directive. Creates the exception handling table entry
2161 for the function. */
b99bd4ef 2162
c19d1205
ZW
2163static void
2164s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2165{
2166 demand_empty_rest_of_line ();
2167 if (unwind.table_entry)
2168 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2169
c19d1205
ZW
2170 create_unwind_entry (1);
2171}
a737bd4d 2172
c19d1205 2173/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2174
c19d1205
ZW
2175static void
2176s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2177{
2178 long where;
2179 char *ptr;
2180 valueT val;
f02232aa 2181
c19d1205 2182 demand_empty_rest_of_line ();
f02232aa 2183
c19d1205
ZW
2184 /* Add eh table entry. */
2185 if (unwind.table_entry == NULL)
2186 val = create_unwind_entry (0);
2187 else
2188 val = 0;
f02232aa 2189
c19d1205
ZW
2190 /* Add index table entry. This is two words. */
2191 start_unwind_section (unwind.saved_seg, 1);
2192 frag_align (2, 0, 0);
2193 record_alignment (now_seg, 2);
b99bd4ef 2194
c19d1205
ZW
2195 ptr = frag_more (8);
2196 where = frag_now_fix () - 8;
f02232aa 2197
c19d1205
ZW
2198 /* Self relative offset of the function start. */
2199 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2200 BFD_RELOC_ARM_PREL31);
f02232aa 2201
c19d1205
ZW
2202 /* Indicate dependency on EHABI-defined personality routines to the
2203 linker, if it hasn't been done already. */
2204 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2205 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2206 {
2207 static const char *const name[] = {
2208 "__aeabi_unwind_cpp_pr0",
2209 "__aeabi_unwind_cpp_pr1",
2210 "__aeabi_unwind_cpp_pr2"
2211 };
2212 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2213 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2214 marked_pr_dependency |= 1 << unwind.personality_index;
2215 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2216 = marked_pr_dependency;
2217 }
f02232aa 2218
c19d1205
ZW
2219 if (val)
2220 /* Inline exception table entry. */
2221 md_number_to_chars (ptr + 4, val, 4);
2222 else
2223 /* Self relative offset of the table entry. */
2224 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2225 BFD_RELOC_ARM_PREL31);
f02232aa 2226
c19d1205
ZW
2227 /* Restore the original section. */
2228 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2229}
f02232aa 2230
f02232aa 2231
c19d1205 2232/* Parse an unwind_cantunwind directive. */
b99bd4ef 2233
c19d1205
ZW
2234static void
2235s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2236{
2237 demand_empty_rest_of_line ();
2238 if (unwind.personality_routine || unwind.personality_index != -1)
2239 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2240
c19d1205
ZW
2241 unwind.personality_index = -2;
2242}
b99bd4ef 2243
b99bd4ef 2244
c19d1205 2245/* Parse a personalityindex directive. */
b99bd4ef 2246
c19d1205
ZW
2247static void
2248s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2249{
2250 expressionS exp;
b99bd4ef 2251
c19d1205
ZW
2252 if (unwind.personality_routine || unwind.personality_index != -1)
2253 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2254
c19d1205 2255 expression (&exp);
b99bd4ef 2256
c19d1205
ZW
2257 if (exp.X_op != O_constant
2258 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2259 {
c19d1205
ZW
2260 as_bad (_("bad personality routine number"));
2261 ignore_rest_of_line ();
2262 return;
b99bd4ef
NC
2263 }
2264
c19d1205 2265 unwind.personality_index = exp.X_add_number;
b99bd4ef 2266
c19d1205
ZW
2267 demand_empty_rest_of_line ();
2268}
e16bb312 2269
e16bb312 2270
c19d1205 2271/* Parse a personality directive. */
e16bb312 2272
c19d1205
ZW
2273static void
2274s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2275{
2276 char *name, *p, c;
a737bd4d 2277
c19d1205
ZW
2278 if (unwind.personality_routine || unwind.personality_index != -1)
2279 as_bad (_("duplicate .personality directive"));
a737bd4d 2280
c19d1205
ZW
2281 name = input_line_pointer;
2282 c = get_symbol_end ();
2283 p = input_line_pointer;
2284 unwind.personality_routine = symbol_find_or_make (name);
2285 *p = c;
2286 demand_empty_rest_of_line ();
2287}
e16bb312 2288
e16bb312 2289
c19d1205 2290/* Parse a directive saving core registers. */
e16bb312 2291
c19d1205
ZW
2292static void
2293s_arm_unwind_save_core (void)
e16bb312 2294{
c19d1205
ZW
2295 valueT op;
2296 long range;
2297 int n;
e16bb312 2298
c19d1205
ZW
2299 range = parse_reg_list (&input_line_pointer);
2300 if (range == FAIL)
e16bb312 2301 {
c19d1205
ZW
2302 as_bad (_("expected register list"));
2303 ignore_rest_of_line ();
2304 return;
2305 }
e16bb312 2306
c19d1205 2307 demand_empty_rest_of_line ();
e16bb312 2308
c19d1205
ZW
2309 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2310 into .unwind_save {..., sp...}. We aren't bothered about the value of
2311 ip because it is clobbered by calls. */
2312 if (unwind.sp_restored && unwind.fp_reg == 12
2313 && (range & 0x3000) == 0x1000)
2314 {
2315 unwind.opcode_count--;
2316 unwind.sp_restored = 0;
2317 range = (range | 0x2000) & ~0x1000;
2318 unwind.pending_offset = 0;
2319 }
e16bb312 2320
01ae4198
DJ
2321 /* Pop r4-r15. */
2322 if (range & 0xfff0)
c19d1205 2323 {
01ae4198
DJ
2324 /* See if we can use the short opcodes. These pop a block of up to 8
2325 registers starting with r4, plus maybe r14. */
2326 for (n = 0; n < 8; n++)
2327 {
2328 /* Break at the first non-saved register. */
2329 if ((range & (1 << (n + 4))) == 0)
2330 break;
2331 }
2332 /* See if there are any other bits set. */
2333 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
2334 {
2335 /* Use the long form. */
2336 op = 0x8000 | ((range >> 4) & 0xfff);
2337 add_unwind_opcode (op, 2);
2338 }
0dd132b6 2339 else
01ae4198
DJ
2340 {
2341 /* Use the short form. */
2342 if (range & 0x4000)
2343 op = 0xa8; /* Pop r14. */
2344 else
2345 op = 0xa0; /* Do not pop r14. */
2346 op |= (n - 1);
2347 add_unwind_opcode (op, 1);
2348 }
c19d1205 2349 }
0dd132b6 2350
c19d1205
ZW
2351 /* Pop r0-r3. */
2352 if (range & 0xf)
2353 {
2354 op = 0xb100 | (range & 0xf);
2355 add_unwind_opcode (op, 2);
0dd132b6
NC
2356 }
2357
c19d1205
ZW
2358 /* Record the number of bytes pushed. */
2359 for (n = 0; n < 16; n++)
2360 {
2361 if (range & (1 << n))
2362 unwind.frame_size += 4;
2363 }
0dd132b6
NC
2364}
2365
c19d1205
ZW
2366
2367/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2368
2369static void
c19d1205 2370s_arm_unwind_save_fpa (int reg)
b99bd4ef 2371{
c19d1205
ZW
2372 expressionS exp;
2373 int num_regs;
2374 valueT op;
b99bd4ef 2375
c19d1205
ZW
2376 /* Get Number of registers to transfer. */
2377 if (skip_past_comma (&input_line_pointer) != FAIL)
2378 expression (&exp);
2379 else
2380 exp.X_op = O_illegal;
b99bd4ef 2381
c19d1205 2382 if (exp.X_op != O_constant)
b99bd4ef 2383 {
c19d1205
ZW
2384 as_bad (_("expected , <constant>"));
2385 ignore_rest_of_line ();
b99bd4ef
NC
2386 return;
2387 }
2388
c19d1205
ZW
2389 num_regs = exp.X_add_number;
2390
2391 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2392 {
c19d1205
ZW
2393 as_bad (_("number of registers must be in the range [1:4]"));
2394 ignore_rest_of_line ();
b99bd4ef
NC
2395 return;
2396 }
2397
c19d1205 2398 demand_empty_rest_of_line ();
b99bd4ef 2399
c19d1205
ZW
2400 if (reg == 4)
2401 {
2402 /* Short form. */
2403 op = 0xb4 | (num_regs - 1);
2404 add_unwind_opcode (op, 1);
2405 }
b99bd4ef
NC
2406 else
2407 {
c19d1205
ZW
2408 /* Long form. */
2409 op = 0xc800 | (reg << 4) | (num_regs - 1);
2410 add_unwind_opcode (op, 2);
b99bd4ef 2411 }
c19d1205 2412 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2413}
2414
c19d1205
ZW
2415
2416/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2417
2418static void
c19d1205 2419s_arm_unwind_save_vfp (void)
b99bd4ef 2420{
c19d1205 2421 int count;
ca3f61f7 2422 unsigned int reg;
c19d1205 2423 valueT op;
b99bd4ef 2424
c19d1205
ZW
2425 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2426 if (count == FAIL)
b99bd4ef 2427 {
c19d1205
ZW
2428 as_bad (_("expected register list"));
2429 ignore_rest_of_line ();
b99bd4ef
NC
2430 return;
2431 }
2432
c19d1205 2433 demand_empty_rest_of_line ();
b99bd4ef 2434
c19d1205 2435 if (reg == 8)
b99bd4ef 2436 {
c19d1205
ZW
2437 /* Short form. */
2438 op = 0xb8 | (count - 1);
2439 add_unwind_opcode (op, 1);
b99bd4ef 2440 }
c19d1205 2441 else
b99bd4ef 2442 {
c19d1205
ZW
2443 /* Long form. */
2444 op = 0xb300 | (reg << 4) | (count - 1);
2445 add_unwind_opcode (op, 2);
b99bd4ef 2446 }
c19d1205
ZW
2447 unwind.frame_size += count * 8 + 4;
2448}
b99bd4ef 2449
b99bd4ef 2450
c19d1205
ZW
2451/* Parse a directive saving iWMMXt data registers. */
2452
2453static void
2454s_arm_unwind_save_mmxwr (void)
2455{
2456 int reg;
2457 int hi_reg;
2458 int i;
2459 unsigned mask = 0;
2460 valueT op;
b99bd4ef 2461
c19d1205
ZW
2462 if (*input_line_pointer == '{')
2463 input_line_pointer++;
b99bd4ef 2464
c19d1205 2465 do
b99bd4ef 2466 {
c19d1205 2467 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2468
c19d1205 2469 if (reg == FAIL)
b99bd4ef 2470 {
c19d1205
ZW
2471 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2472 goto error;
b99bd4ef
NC
2473 }
2474
c19d1205
ZW
2475 if (mask >> reg)
2476 as_tsktsk (_("register list not in ascending order"));
2477 mask |= 1 << reg;
b99bd4ef 2478
c19d1205
ZW
2479 if (*input_line_pointer == '-')
2480 {
2481 input_line_pointer++;
2482 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2483 if (hi_reg == FAIL)
2484 {
2485 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2486 goto error;
2487 }
2488 else if (reg >= hi_reg)
2489 {
2490 as_bad (_("bad register range"));
2491 goto error;
2492 }
2493 for (; reg < hi_reg; reg++)
2494 mask |= 1 << reg;
2495 }
2496 }
2497 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2498
c19d1205
ZW
2499 if (*input_line_pointer == '}')
2500 input_line_pointer++;
b99bd4ef 2501
c19d1205 2502 demand_empty_rest_of_line ();
b99bd4ef 2503
c19d1205
ZW
2504 /* Generate any deferred opcodes becuuse we're going to be looking at
2505 the list. */
2506 flush_pending_unwind ();
b99bd4ef 2507
c19d1205 2508 for (i = 0; i < 16; i++)
b99bd4ef 2509 {
c19d1205
ZW
2510 if (mask & (1 << i))
2511 unwind.frame_size += 8;
b99bd4ef
NC
2512 }
2513
c19d1205
ZW
2514 /* Attempt to combine with a previous opcode. We do this because gcc
2515 likes to output separate unwind directives for a single block of
2516 registers. */
2517 if (unwind.opcode_count > 0)
b99bd4ef 2518 {
c19d1205
ZW
2519 i = unwind.opcodes[unwind.opcode_count - 1];
2520 if ((i & 0xf8) == 0xc0)
2521 {
2522 i &= 7;
2523 /* Only merge if the blocks are contiguous. */
2524 if (i < 6)
2525 {
2526 if ((mask & 0xfe00) == (1 << 9))
2527 {
2528 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2529 unwind.opcode_count--;
2530 }
2531 }
2532 else if (i == 6 && unwind.opcode_count >= 2)
2533 {
2534 i = unwind.opcodes[unwind.opcode_count - 2];
2535 reg = i >> 4;
2536 i &= 0xf;
b99bd4ef 2537
c19d1205
ZW
2538 op = 0xffff << (reg - 1);
2539 if (reg > 0
2540 || ((mask & op) == (1u << (reg - 1))))
2541 {
2542 op = (1 << (reg + i + 1)) - 1;
2543 op &= ~((1 << reg) - 1);
2544 mask |= op;
2545 unwind.opcode_count -= 2;
2546 }
2547 }
2548 }
b99bd4ef
NC
2549 }
2550
c19d1205
ZW
2551 hi_reg = 15;
2552 /* We want to generate opcodes in the order the registers have been
2553 saved, ie. descending order. */
2554 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2555 {
c19d1205
ZW
2556 /* Save registers in blocks. */
2557 if (reg < 0
2558 || !(mask & (1 << reg)))
2559 {
2560 /* We found an unsaved reg. Generate opcodes to save the
2561 preceeding block. */
2562 if (reg != hi_reg)
2563 {
2564 if (reg == 9)
2565 {
2566 /* Short form. */
2567 op = 0xc0 | (hi_reg - 10);
2568 add_unwind_opcode (op, 1);
2569 }
2570 else
2571 {
2572 /* Long form. */
2573 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2574 add_unwind_opcode (op, 2);
2575 }
2576 }
2577 hi_reg = reg - 1;
2578 }
b99bd4ef
NC
2579 }
2580
c19d1205
ZW
2581 return;
2582error:
2583 ignore_rest_of_line ();
b99bd4ef
NC
2584}
2585
2586static void
c19d1205 2587s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2588{
c19d1205
ZW
2589 int reg;
2590 int hi_reg;
2591 unsigned mask = 0;
2592 valueT op;
b99bd4ef 2593
c19d1205
ZW
2594 if (*input_line_pointer == '{')
2595 input_line_pointer++;
b99bd4ef 2596
c19d1205 2597 do
b99bd4ef 2598 {
c19d1205 2599 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2600
c19d1205
ZW
2601 if (reg == FAIL)
2602 {
2603 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2604 goto error;
2605 }
b99bd4ef 2606
c19d1205
ZW
2607 reg -= 8;
2608 if (mask >> reg)
2609 as_tsktsk (_("register list not in ascending order"));
2610 mask |= 1 << reg;
b99bd4ef 2611
c19d1205
ZW
2612 if (*input_line_pointer == '-')
2613 {
2614 input_line_pointer++;
2615 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2616 if (hi_reg == FAIL)
2617 {
2618 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2619 goto error;
2620 }
2621 else if (reg >= hi_reg)
2622 {
2623 as_bad (_("bad register range"));
2624 goto error;
2625 }
2626 for (; reg < hi_reg; reg++)
2627 mask |= 1 << reg;
2628 }
b99bd4ef 2629 }
c19d1205 2630 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2631
c19d1205
ZW
2632 if (*input_line_pointer == '}')
2633 input_line_pointer++;
b99bd4ef 2634
c19d1205
ZW
2635 demand_empty_rest_of_line ();
2636
2637 /* Generate any deferred opcodes becuuse we're going to be looking at
2638 the list. */
2639 flush_pending_unwind ();
b99bd4ef 2640
c19d1205 2641 for (reg = 0; reg < 16; reg++)
b99bd4ef 2642 {
c19d1205
ZW
2643 if (mask & (1 << reg))
2644 unwind.frame_size += 4;
b99bd4ef 2645 }
c19d1205
ZW
2646 op = 0xc700 | mask;
2647 add_unwind_opcode (op, 2);
2648 return;
2649error:
2650 ignore_rest_of_line ();
b99bd4ef
NC
2651}
2652
c19d1205
ZW
2653
2654/* Parse an unwind_save directive. */
2655
b99bd4ef 2656static void
c19d1205 2657s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2658{
c19d1205
ZW
2659 char *peek;
2660 struct reg_entry *reg;
2661 bfd_boolean had_brace = FALSE;
b99bd4ef 2662
c19d1205
ZW
2663 /* Figure out what sort of save we have. */
2664 peek = input_line_pointer;
b99bd4ef 2665
c19d1205 2666 if (*peek == '{')
b99bd4ef 2667 {
c19d1205
ZW
2668 had_brace = TRUE;
2669 peek++;
b99bd4ef
NC
2670 }
2671
c19d1205 2672 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2673
c19d1205 2674 if (!reg)
b99bd4ef 2675 {
c19d1205
ZW
2676 as_bad (_("register expected"));
2677 ignore_rest_of_line ();
b99bd4ef
NC
2678 return;
2679 }
2680
c19d1205 2681 switch (reg->type)
b99bd4ef 2682 {
c19d1205
ZW
2683 case REG_TYPE_FN:
2684 if (had_brace)
2685 {
2686 as_bad (_("FPA .unwind_save does not take a register list"));
2687 ignore_rest_of_line ();
2688 return;
2689 }
2690 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2691 return;
c19d1205
ZW
2692
2693 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2694 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2695 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2696 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2697
2698 default:
2699 as_bad (_(".unwind_save does not support this kind of register"));
2700 ignore_rest_of_line ();
b99bd4ef 2701 }
c19d1205 2702}
b99bd4ef 2703
b99bd4ef 2704
c19d1205
ZW
2705/* Parse an unwind_movsp directive. */
2706
2707static void
2708s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2709{
2710 int reg;
2711 valueT op;
2712
2713 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2714 if (reg == FAIL)
b99bd4ef 2715 {
c19d1205
ZW
2716 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2717 ignore_rest_of_line ();
b99bd4ef
NC
2718 return;
2719 }
c19d1205 2720 demand_empty_rest_of_line ();
b99bd4ef 2721
c19d1205 2722 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2723 {
c19d1205 2724 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2725 return;
2726 }
2727
c19d1205
ZW
2728 if (unwind.fp_reg != REG_SP)
2729 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2730
c19d1205
ZW
2731 /* Generate opcode to restore the value. */
2732 op = 0x90 | reg;
2733 add_unwind_opcode (op, 1);
2734
2735 /* Record the information for later. */
2736 unwind.fp_reg = reg;
2737 unwind.fp_offset = unwind.frame_size;
2738 unwind.sp_restored = 1;
b05fe5cf
ZW
2739}
2740
c19d1205
ZW
2741/* Parse an unwind_pad directive. */
2742
b05fe5cf 2743static void
c19d1205 2744s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2745{
c19d1205 2746 int offset;
b05fe5cf 2747
c19d1205
ZW
2748 if (immediate_for_directive (&offset) == FAIL)
2749 return;
b99bd4ef 2750
c19d1205
ZW
2751 if (offset & 3)
2752 {
2753 as_bad (_("stack increment must be multiple of 4"));
2754 ignore_rest_of_line ();
2755 return;
2756 }
b99bd4ef 2757
c19d1205
ZW
2758 /* Don't generate any opcodes, just record the details for later. */
2759 unwind.frame_size += offset;
2760 unwind.pending_offset += offset;
2761
2762 demand_empty_rest_of_line ();
2763}
2764
2765/* Parse an unwind_setfp directive. */
2766
2767static void
2768s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2769{
c19d1205
ZW
2770 int sp_reg;
2771 int fp_reg;
2772 int offset;
2773
2774 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2775 if (skip_past_comma (&input_line_pointer) == FAIL)
2776 sp_reg = FAIL;
2777 else
2778 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2779
c19d1205
ZW
2780 if (fp_reg == FAIL || sp_reg == FAIL)
2781 {
2782 as_bad (_("expected <reg>, <reg>"));
2783 ignore_rest_of_line ();
2784 return;
2785 }
b99bd4ef 2786
c19d1205
ZW
2787 /* Optional constant. */
2788 if (skip_past_comma (&input_line_pointer) != FAIL)
2789 {
2790 if (immediate_for_directive (&offset) == FAIL)
2791 return;
2792 }
2793 else
2794 offset = 0;
a737bd4d 2795
c19d1205 2796 demand_empty_rest_of_line ();
a737bd4d 2797
c19d1205 2798 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2799 {
c19d1205
ZW
2800 as_bad (_("register must be either sp or set by a previous"
2801 "unwind_movsp directive"));
2802 return;
a737bd4d
NC
2803 }
2804
c19d1205
ZW
2805 /* Don't generate any opcodes, just record the information for later. */
2806 unwind.fp_reg = fp_reg;
2807 unwind.fp_used = 1;
2808 if (sp_reg == 13)
2809 unwind.fp_offset = unwind.frame_size - offset;
2810 else
2811 unwind.fp_offset -= offset;
a737bd4d
NC
2812}
2813
c19d1205
ZW
2814/* Parse an unwind_raw directive. */
2815
2816static void
2817s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2818{
c19d1205
ZW
2819 expressionS exp;
2820 /* This is an arbitary limit. */
2821 unsigned char op[16];
2822 int count;
a737bd4d 2823
c19d1205
ZW
2824 expression (&exp);
2825 if (exp.X_op == O_constant
2826 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2827 {
c19d1205
ZW
2828 unwind.frame_size += exp.X_add_number;
2829 expression (&exp);
2830 }
2831 else
2832 exp.X_op = O_illegal;
a737bd4d 2833
c19d1205
ZW
2834 if (exp.X_op != O_constant)
2835 {
2836 as_bad (_("expected <offset>, <opcode>"));
2837 ignore_rest_of_line ();
2838 return;
2839 }
a737bd4d 2840
c19d1205 2841 count = 0;
a737bd4d 2842
c19d1205
ZW
2843 /* Parse the opcode. */
2844 for (;;)
2845 {
2846 if (count >= 16)
2847 {
2848 as_bad (_("unwind opcode too long"));
2849 ignore_rest_of_line ();
a737bd4d 2850 }
c19d1205 2851 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2852 {
c19d1205
ZW
2853 as_bad (_("invalid unwind opcode"));
2854 ignore_rest_of_line ();
2855 return;
a737bd4d 2856 }
c19d1205 2857 op[count++] = exp.X_add_number;
a737bd4d 2858
c19d1205
ZW
2859 /* Parse the next byte. */
2860 if (skip_past_comma (&input_line_pointer) == FAIL)
2861 break;
a737bd4d 2862
c19d1205
ZW
2863 expression (&exp);
2864 }
b99bd4ef 2865
c19d1205
ZW
2866 /* Add the opcode bytes in reverse order. */
2867 while (count--)
2868 add_unwind_opcode (op[count], 1);
b99bd4ef 2869
c19d1205 2870 demand_empty_rest_of_line ();
b99bd4ef 2871}
ee065d83
PB
2872
2873
2874/* Parse a .eabi_attribute directive. */
2875
2876static void
2877s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
2878{
2879 expressionS exp;
2880 bfd_boolean is_string;
2881 int tag;
2882 unsigned int i = 0;
2883 char *s = NULL;
2884 char saved_char;
2885
2886 expression (& exp);
2887 if (exp.X_op != O_constant)
2888 goto bad;
2889
2890 tag = exp.X_add_number;
2891 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
2892 is_string = 1;
2893 else
2894 is_string = 0;
2895
2896 if (skip_past_comma (&input_line_pointer) == FAIL)
2897 goto bad;
2898 if (tag == 32 || !is_string)
2899 {
2900 expression (& exp);
2901 if (exp.X_op != O_constant)
2902 {
2903 as_bad (_("expected numeric constant"));
2904 ignore_rest_of_line ();
2905 return;
2906 }
2907 i = exp.X_add_number;
2908 }
2909 if (tag == Tag_compatibility
2910 && skip_past_comma (&input_line_pointer) == FAIL)
2911 {
2912 as_bad (_("expected comma"));
2913 ignore_rest_of_line ();
2914 return;
2915 }
2916 if (is_string)
2917 {
2918 skip_whitespace(input_line_pointer);
2919 if (*input_line_pointer != '"')
2920 goto bad_string;
2921 input_line_pointer++;
2922 s = input_line_pointer;
2923 while (*input_line_pointer && *input_line_pointer != '"')
2924 input_line_pointer++;
2925 if (*input_line_pointer != '"')
2926 goto bad_string;
2927 saved_char = *input_line_pointer;
2928 *input_line_pointer = 0;
2929 }
2930 else
2931 {
2932 s = NULL;
2933 saved_char = 0;
2934 }
2935
2936 if (tag == Tag_compatibility)
2937 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
2938 else if (is_string)
2939 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
2940 else
2941 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
2942
2943 if (s)
2944 {
2945 *input_line_pointer = saved_char;
2946 input_line_pointer++;
2947 }
2948 demand_empty_rest_of_line ();
2949 return;
2950bad_string:
2951 as_bad (_("bad string constant"));
2952 ignore_rest_of_line ();
2953 return;
2954bad:
2955 as_bad (_("expected <tag> , <value>"));
2956 ignore_rest_of_line ();
2957}
2958
2959static void s_arm_arch (int);
2960static void s_arm_cpu (int);
2961static void s_arm_fpu (int);
c19d1205 2962#endif /* OBJ_ELF */
b99bd4ef 2963
c19d1205
ZW
2964/* This table describes all the machine specific pseudo-ops the assembler
2965 has to support. The fields are:
2966 pseudo-op name without dot
2967 function to call to execute this pseudo-op
2968 Integer arg to pass to the function. */
b99bd4ef 2969
c19d1205 2970const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2971{
c19d1205
ZW
2972 /* Never called because '.req' does not start a line. */
2973 { "req", s_req, 0 },
2974 { "unreq", s_unreq, 0 },
2975 { "bss", s_bss, 0 },
2976 { "align", s_align, 0 },
2977 { "arm", s_arm, 0 },
2978 { "thumb", s_thumb, 0 },
2979 { "code", s_code, 0 },
2980 { "force_thumb", s_force_thumb, 0 },
2981 { "thumb_func", s_thumb_func, 0 },
2982 { "thumb_set", s_thumb_set, 0 },
2983 { "even", s_even, 0 },
2984 { "ltorg", s_ltorg, 0 },
2985 { "pool", s_ltorg, 0 },
2986 { "syntax", s_syntax, 0 },
2987#ifdef OBJ_ELF
2988 { "word", s_arm_elf_cons, 4 },
2989 { "long", s_arm_elf_cons, 4 },
2990 { "rel31", s_arm_rel31, 0 },
2991 { "fnstart", s_arm_unwind_fnstart, 0 },
2992 { "fnend", s_arm_unwind_fnend, 0 },
2993 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2994 { "personality", s_arm_unwind_personality, 0 },
2995 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2996 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2997 { "save", s_arm_unwind_save, 0 },
2998 { "movsp", s_arm_unwind_movsp, 0 },
2999 { "pad", s_arm_unwind_pad, 0 },
3000 { "setfp", s_arm_unwind_setfp, 0 },
3001 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83
PB
3002 { "cpu", s_arm_cpu, 0 },
3003 { "arch", s_arm_arch, 0 },
3004 { "fpu", s_arm_fpu, 0 },
3005 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3006#else
3007 { "word", cons, 4},
3008#endif
3009 { "extend", float_cons, 'x' },
3010 { "ldouble", float_cons, 'x' },
3011 { "packed", float_cons, 'p' },
3012 { 0, 0, 0 }
3013};
3014\f
3015/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3016
c19d1205
ZW
3017/* Generic immediate-value read function for use in insn parsing.
3018 STR points to the beginning of the immediate (the leading #);
3019 VAL receives the value; if the value is outside [MIN, MAX]
3020 issue an error. PREFIX_OPT is true if the immediate prefix is
3021 optional. */
b99bd4ef 3022
c19d1205
ZW
3023static int
3024parse_immediate (char **str, int *val, int min, int max,
3025 bfd_boolean prefix_opt)
3026{
3027 expressionS exp;
3028 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3029 if (exp.X_op != O_constant)
b99bd4ef 3030 {
c19d1205
ZW
3031 inst.error = _("constant expression required");
3032 return FAIL;
3033 }
b99bd4ef 3034
c19d1205
ZW
3035 if (exp.X_add_number < min || exp.X_add_number > max)
3036 {
3037 inst.error = _("immediate value out of range");
3038 return FAIL;
3039 }
b99bd4ef 3040
c19d1205
ZW
3041 *val = exp.X_add_number;
3042 return SUCCESS;
3043}
b99bd4ef 3044
c19d1205
ZW
3045/* Returns the pseudo-register number of an FPA immediate constant,
3046 or FAIL if there isn't a valid constant here. */
b99bd4ef 3047
c19d1205
ZW
3048static int
3049parse_fpa_immediate (char ** str)
3050{
3051 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3052 char * save_in;
3053 expressionS exp;
3054 int i;
3055 int j;
b99bd4ef 3056
c19d1205
ZW
3057 /* First try and match exact strings, this is to guarantee
3058 that some formats will work even for cross assembly. */
b99bd4ef 3059
c19d1205
ZW
3060 for (i = 0; fp_const[i]; i++)
3061 {
3062 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 3063 {
c19d1205 3064 char *start = *str;
b99bd4ef 3065
c19d1205
ZW
3066 *str += strlen (fp_const[i]);
3067 if (is_end_of_line[(unsigned char) **str])
3068 return i + 8;
3069 *str = start;
3070 }
3071 }
b99bd4ef 3072
c19d1205
ZW
3073 /* Just because we didn't get a match doesn't mean that the constant
3074 isn't valid, just that it is in a format that we don't
3075 automatically recognize. Try parsing it with the standard
3076 expression routines. */
b99bd4ef 3077
c19d1205 3078 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 3079
c19d1205
ZW
3080 /* Look for a raw floating point number. */
3081 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3082 && is_end_of_line[(unsigned char) *save_in])
3083 {
3084 for (i = 0; i < NUM_FLOAT_VALS; i++)
3085 {
3086 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 3087 {
c19d1205
ZW
3088 if (words[j] != fp_values[i][j])
3089 break;
b99bd4ef
NC
3090 }
3091
c19d1205 3092 if (j == MAX_LITTLENUMS)
b99bd4ef 3093 {
c19d1205
ZW
3094 *str = save_in;
3095 return i + 8;
b99bd4ef
NC
3096 }
3097 }
3098 }
b99bd4ef 3099
c19d1205
ZW
3100 /* Try and parse a more complex expression, this will probably fail
3101 unless the code uses a floating point prefix (eg "0f"). */
3102 save_in = input_line_pointer;
3103 input_line_pointer = *str;
3104 if (expression (&exp) == absolute_section
3105 && exp.X_op == O_big
3106 && exp.X_add_number < 0)
3107 {
3108 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3109 Ditto for 15. */
3110 if (gen_to_words (words, 5, (long) 15) == 0)
3111 {
3112 for (i = 0; i < NUM_FLOAT_VALS; i++)
3113 {
3114 for (j = 0; j < MAX_LITTLENUMS; j++)
3115 {
3116 if (words[j] != fp_values[i][j])
3117 break;
3118 }
b99bd4ef 3119
c19d1205
ZW
3120 if (j == MAX_LITTLENUMS)
3121 {
3122 *str = input_line_pointer;
3123 input_line_pointer = save_in;
3124 return i + 8;
3125 }
3126 }
3127 }
b99bd4ef
NC
3128 }
3129
c19d1205
ZW
3130 *str = input_line_pointer;
3131 input_line_pointer = save_in;
3132 inst.error = _("invalid FPA immediate expression");
3133 return FAIL;
b99bd4ef
NC
3134}
3135
c19d1205
ZW
3136/* Shift operands. */
3137enum shift_kind
b99bd4ef 3138{
c19d1205
ZW
3139 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
3140};
b99bd4ef 3141
c19d1205
ZW
3142struct asm_shift_name
3143{
3144 const char *name;
3145 enum shift_kind kind;
3146};
b99bd4ef 3147
c19d1205
ZW
3148/* Third argument to parse_shift. */
3149enum parse_shift_mode
3150{
3151 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
3152 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
3153 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
3154 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
3155 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
3156};
b99bd4ef 3157
c19d1205
ZW
3158/* Parse a <shift> specifier on an ARM data processing instruction.
3159 This has three forms:
b99bd4ef 3160
c19d1205
ZW
3161 (LSL|LSR|ASL|ASR|ROR) Rs
3162 (LSL|LSR|ASL|ASR|ROR) #imm
3163 RRX
b99bd4ef 3164
c19d1205
ZW
3165 Note that ASL is assimilated to LSL in the instruction encoding, and
3166 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 3167
c19d1205
ZW
3168static int
3169parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 3170{
c19d1205
ZW
3171 const struct asm_shift_name *shift_name;
3172 enum shift_kind shift;
3173 char *s = *str;
3174 char *p = s;
3175 int reg;
b99bd4ef 3176
c19d1205
ZW
3177 for (p = *str; ISALPHA (*p); p++)
3178 ;
b99bd4ef 3179
c19d1205 3180 if (p == *str)
b99bd4ef 3181 {
c19d1205
ZW
3182 inst.error = _("shift expression expected");
3183 return FAIL;
b99bd4ef
NC
3184 }
3185
c19d1205
ZW
3186 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3187
3188 if (shift_name == NULL)
b99bd4ef 3189 {
c19d1205
ZW
3190 inst.error = _("shift expression expected");
3191 return FAIL;
b99bd4ef
NC
3192 }
3193
c19d1205 3194 shift = shift_name->kind;
b99bd4ef 3195
c19d1205
ZW
3196 switch (mode)
3197 {
3198 case NO_SHIFT_RESTRICT:
3199 case SHIFT_IMMEDIATE: break;
b99bd4ef 3200
c19d1205
ZW
3201 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3202 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3203 {
3204 inst.error = _("'LSL' or 'ASR' required");
3205 return FAIL;
3206 }
3207 break;
b99bd4ef 3208
c19d1205
ZW
3209 case SHIFT_LSL_IMMEDIATE:
3210 if (shift != SHIFT_LSL)
3211 {
3212 inst.error = _("'LSL' required");
3213 return FAIL;
3214 }
3215 break;
b99bd4ef 3216
c19d1205
ZW
3217 case SHIFT_ASR_IMMEDIATE:
3218 if (shift != SHIFT_ASR)
3219 {
3220 inst.error = _("'ASR' required");
3221 return FAIL;
3222 }
3223 break;
b99bd4ef 3224
c19d1205
ZW
3225 default: abort ();
3226 }
b99bd4ef 3227
c19d1205
ZW
3228 if (shift != SHIFT_RRX)
3229 {
3230 /* Whitespace can appear here if the next thing is a bare digit. */
3231 skip_whitespace (p);
b99bd4ef 3232
c19d1205
ZW
3233 if (mode == NO_SHIFT_RESTRICT
3234 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3235 {
3236 inst.operands[i].imm = reg;
3237 inst.operands[i].immisreg = 1;
3238 }
3239 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3240 return FAIL;
3241 }
3242 inst.operands[i].shift_kind = shift;
3243 inst.operands[i].shifted = 1;
3244 *str = p;
3245 return SUCCESS;
b99bd4ef
NC
3246}
3247
c19d1205 3248/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3249
c19d1205
ZW
3250 #<immediate>
3251 #<immediate>, <rotate>
3252 <Rm>
3253 <Rm>, <shift>
b99bd4ef 3254
c19d1205
ZW
3255 where <shift> is defined by parse_shift above, and <rotate> is a
3256 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3257 is deferred to md_apply_fix. */
b99bd4ef 3258
c19d1205
ZW
3259static int
3260parse_shifter_operand (char **str, int i)
3261{
3262 int value;
3263 expressionS expr;
b99bd4ef 3264
c19d1205
ZW
3265 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3266 {
3267 inst.operands[i].reg = value;
3268 inst.operands[i].isreg = 1;
b99bd4ef 3269
c19d1205
ZW
3270 /* parse_shift will override this if appropriate */
3271 inst.reloc.exp.X_op = O_constant;
3272 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3273
c19d1205
ZW
3274 if (skip_past_comma (str) == FAIL)
3275 return SUCCESS;
b99bd4ef 3276
c19d1205
ZW
3277 /* Shift operation on register. */
3278 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3279 }
3280
c19d1205
ZW
3281 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3282 return FAIL;
b99bd4ef 3283
c19d1205 3284 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3285 {
c19d1205
ZW
3286 /* #x, y -- ie explicit rotation by Y. */
3287 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3288 return FAIL;
b99bd4ef 3289
c19d1205
ZW
3290 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3291 {
3292 inst.error = _("constant expression expected");
3293 return FAIL;
3294 }
b99bd4ef 3295
c19d1205
ZW
3296 value = expr.X_add_number;
3297 if (value < 0 || value > 30 || value % 2 != 0)
3298 {
3299 inst.error = _("invalid rotation");
3300 return FAIL;
3301 }
3302 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3303 {
3304 inst.error = _("invalid constant");
3305 return FAIL;
3306 }
09d92015 3307
55cf6793 3308 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3309 inst.reloc.exp.X_add_number
3310 = (((inst.reloc.exp.X_add_number << (32 - value))
3311 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3312 }
3313
c19d1205
ZW
3314 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3315 inst.reloc.pc_rel = 0;
3316 return SUCCESS;
09d92015
MM
3317}
3318
c19d1205
ZW
3319/* Parse all forms of an ARM address expression. Information is written
3320 to inst.operands[i] and/or inst.reloc.
09d92015 3321
c19d1205 3322 Preindexed addressing (.preind=1):
09d92015 3323
c19d1205
ZW
3324 [Rn, #offset] .reg=Rn .reloc.exp=offset
3325 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3326 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3327 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3328
c19d1205 3329 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3330
c19d1205 3331 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3332
c19d1205
ZW
3333 [Rn], #offset .reg=Rn .reloc.exp=offset
3334 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3335 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3336 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3337
c19d1205 3338 Unindexed addressing (.preind=0, .postind=0):
09d92015 3339
c19d1205 3340 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3341
c19d1205 3342 Other:
09d92015 3343
c19d1205
ZW
3344 [Rn]{!} shorthand for [Rn,#0]{!}
3345 =immediate .isreg=0 .reloc.exp=immediate
3346 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3347
c19d1205
ZW
3348 It is the caller's responsibility to check for addressing modes not
3349 supported by the instruction, and to set inst.reloc.type. */
3350
3351static int
3352parse_address (char **str, int i)
09d92015 3353{
c19d1205
ZW
3354 char *p = *str;
3355 int reg;
09d92015 3356
c19d1205 3357 if (skip_past_char (&p, '[') == FAIL)
09d92015 3358 {
c19d1205
ZW
3359 if (skip_past_char (&p, '=') == FAIL)
3360 {
3361 /* bare address - translate to PC-relative offset */
3362 inst.reloc.pc_rel = 1;
3363 inst.operands[i].reg = REG_PC;
3364 inst.operands[i].isreg = 1;
3365 inst.operands[i].preind = 1;
3366 }
3367 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3368
c19d1205
ZW
3369 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3370 return FAIL;
09d92015 3371
c19d1205
ZW
3372 *str = p;
3373 return SUCCESS;
09d92015
MM
3374 }
3375
c19d1205 3376 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3377 {
c19d1205
ZW
3378 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3379 return FAIL;
09d92015 3380 }
c19d1205
ZW
3381 inst.operands[i].reg = reg;
3382 inst.operands[i].isreg = 1;
09d92015 3383
c19d1205 3384 if (skip_past_comma (&p) == SUCCESS)
09d92015 3385 {
c19d1205 3386 inst.operands[i].preind = 1;
09d92015 3387
c19d1205
ZW
3388 if (*p == '+') p++;
3389 else if (*p == '-') p++, inst.operands[i].negative = 1;
3390
3391 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3392 {
c19d1205
ZW
3393 inst.operands[i].imm = reg;
3394 inst.operands[i].immisreg = 1;
3395
3396 if (skip_past_comma (&p) == SUCCESS)
3397 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3398 return FAIL;
3399 }
3400 else
3401 {
3402 if (inst.operands[i].negative)
3403 {
3404 inst.operands[i].negative = 0;
3405 p--;
3406 }
3407 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3408 return FAIL;
09d92015
MM
3409 }
3410 }
3411
c19d1205 3412 if (skip_past_char (&p, ']') == FAIL)
09d92015 3413 {
c19d1205
ZW
3414 inst.error = _("']' expected");
3415 return FAIL;
09d92015
MM
3416 }
3417
c19d1205
ZW
3418 if (skip_past_char (&p, '!') == SUCCESS)
3419 inst.operands[i].writeback = 1;
09d92015 3420
c19d1205 3421 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3422 {
c19d1205
ZW
3423 if (skip_past_char (&p, '{') == SUCCESS)
3424 {
3425 /* [Rn], {expr} - unindexed, with option */
3426 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 3427 0, 255, TRUE) == FAIL)
c19d1205 3428 return FAIL;
09d92015 3429
c19d1205
ZW
3430 if (skip_past_char (&p, '}') == FAIL)
3431 {
3432 inst.error = _("'}' expected at end of 'option' field");
3433 return FAIL;
3434 }
3435 if (inst.operands[i].preind)
3436 {
3437 inst.error = _("cannot combine index with option");
3438 return FAIL;
3439 }
3440 *str = p;
3441 return SUCCESS;
09d92015 3442 }
c19d1205
ZW
3443 else
3444 {
3445 inst.operands[i].postind = 1;
3446 inst.operands[i].writeback = 1;
09d92015 3447
c19d1205
ZW
3448 if (inst.operands[i].preind)
3449 {
3450 inst.error = _("cannot combine pre- and post-indexing");
3451 return FAIL;
3452 }
09d92015 3453
c19d1205
ZW
3454 if (*p == '+') p++;
3455 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3456
c19d1205
ZW
3457 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3458 {
3459 inst.operands[i].imm = reg;
3460 inst.operands[i].immisreg = 1;
a737bd4d 3461
c19d1205
ZW
3462 if (skip_past_comma (&p) == SUCCESS)
3463 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3464 return FAIL;
3465 }
3466 else
3467 {
3468 if (inst.operands[i].negative)
3469 {
3470 inst.operands[i].negative = 0;
3471 p--;
3472 }
3473 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3474 return FAIL;
3475 }
3476 }
a737bd4d
NC
3477 }
3478
c19d1205
ZW
3479 /* If at this point neither .preind nor .postind is set, we have a
3480 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3481 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3482 {
3483 inst.operands[i].preind = 1;
3484 inst.reloc.exp.X_op = O_constant;
3485 inst.reloc.exp.X_add_number = 0;
3486 }
3487 *str = p;
3488 return SUCCESS;
a737bd4d
NC
3489}
3490
c19d1205 3491/* Miscellaneous. */
a737bd4d 3492
c19d1205
ZW
3493/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3494 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3495static int
3496parse_psr (char **str)
09d92015 3497{
c19d1205
ZW
3498 char *p;
3499 unsigned long psr_field;
62b3e311
PB
3500 const struct asm_psr *psr;
3501 char *start;
09d92015 3502
c19d1205
ZW
3503 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3504 feature for ease of use and backwards compatibility. */
3505 p = *str;
62b3e311 3506 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 3507 psr_field = SPSR_BIT;
62b3e311 3508 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
3509 psr_field = 0;
3510 else
62b3e311
PB
3511 {
3512 start = p;
3513 do
3514 p++;
3515 while (ISALNUM (*p) || *p == '_');
3516
3517 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
3518 if (!psr)
3519 return FAIL;
09d92015 3520
62b3e311
PB
3521 *str = p;
3522 return psr->field;
3523 }
09d92015 3524
62b3e311 3525 p += 4;
c19d1205
ZW
3526 if (*p == '_')
3527 {
3528 /* A suffix follows. */
c19d1205
ZW
3529 p++;
3530 start = p;
a737bd4d 3531
c19d1205
ZW
3532 do
3533 p++;
3534 while (ISALNUM (*p) || *p == '_');
a737bd4d 3535
c19d1205
ZW
3536 psr = hash_find_n (arm_psr_hsh, start, p - start);
3537 if (!psr)
3538 goto error;
a737bd4d 3539
c19d1205 3540 psr_field |= psr->field;
a737bd4d 3541 }
c19d1205 3542 else
a737bd4d 3543 {
c19d1205
ZW
3544 if (ISALNUM (*p))
3545 goto error; /* Garbage after "[CS]PSR". */
3546
3547 psr_field |= (PSR_c | PSR_f);
a737bd4d 3548 }
c19d1205
ZW
3549 *str = p;
3550 return psr_field;
a737bd4d 3551
c19d1205
ZW
3552 error:
3553 inst.error = _("flag for {c}psr instruction expected");
3554 return FAIL;
a737bd4d
NC
3555}
3556
c19d1205
ZW
3557/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3558 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3559
c19d1205
ZW
3560static int
3561parse_cps_flags (char **str)
a737bd4d 3562{
c19d1205
ZW
3563 int val = 0;
3564 int saw_a_flag = 0;
3565 char *s = *str;
a737bd4d 3566
c19d1205
ZW
3567 for (;;)
3568 switch (*s++)
3569 {
3570 case '\0': case ',':
3571 goto done;
a737bd4d 3572
c19d1205
ZW
3573 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3574 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3575 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3576
c19d1205
ZW
3577 default:
3578 inst.error = _("unrecognized CPS flag");
3579 return FAIL;
3580 }
a737bd4d 3581
c19d1205
ZW
3582 done:
3583 if (saw_a_flag == 0)
a737bd4d 3584 {
c19d1205
ZW
3585 inst.error = _("missing CPS flags");
3586 return FAIL;
a737bd4d 3587 }
a737bd4d 3588
c19d1205
ZW
3589 *str = s - 1;
3590 return val;
a737bd4d
NC
3591}
3592
c19d1205
ZW
3593/* Parse an endian specifier ("BE" or "LE", case insensitive);
3594 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3595
3596static int
c19d1205 3597parse_endian_specifier (char **str)
a737bd4d 3598{
c19d1205
ZW
3599 int little_endian;
3600 char *s = *str;
a737bd4d 3601
c19d1205
ZW
3602 if (strncasecmp (s, "BE", 2))
3603 little_endian = 0;
3604 else if (strncasecmp (s, "LE", 2))
3605 little_endian = 1;
3606 else
a737bd4d 3607 {
c19d1205 3608 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3609 return FAIL;
3610 }
3611
c19d1205 3612 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3613 {
c19d1205 3614 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3615 return FAIL;
3616 }
3617
c19d1205
ZW
3618 *str = s + 2;
3619 return little_endian;
3620}
a737bd4d 3621
c19d1205
ZW
3622/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3623 value suitable for poking into the rotate field of an sxt or sxta
3624 instruction, or FAIL on error. */
3625
3626static int
3627parse_ror (char **str)
3628{
3629 int rot;
3630 char *s = *str;
3631
3632 if (strncasecmp (s, "ROR", 3) == 0)
3633 s += 3;
3634 else
a737bd4d 3635 {
c19d1205 3636 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3637 return FAIL;
3638 }
c19d1205
ZW
3639
3640 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3641 return FAIL;
3642
3643 switch (rot)
a737bd4d 3644 {
c19d1205
ZW
3645 case 0: *str = s; return 0x0;
3646 case 8: *str = s; return 0x1;
3647 case 16: *str = s; return 0x2;
3648 case 24: *str = s; return 0x3;
3649
3650 default:
3651 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3652 return FAIL;
3653 }
c19d1205 3654}
a737bd4d 3655
c19d1205
ZW
3656/* Parse a conditional code (from conds[] below). The value returned is in the
3657 range 0 .. 14, or FAIL. */
3658static int
3659parse_cond (char **str)
3660{
3661 char *p, *q;
3662 const struct asm_cond *c;
a737bd4d 3663
c19d1205
ZW
3664 p = q = *str;
3665 while (ISALPHA (*q))
3666 q++;
a737bd4d 3667
c19d1205
ZW
3668 c = hash_find_n (arm_cond_hsh, p, q - p);
3669 if (!c)
a737bd4d 3670 {
c19d1205 3671 inst.error = _("condition required");
a737bd4d
NC
3672 return FAIL;
3673 }
3674
c19d1205
ZW
3675 *str = q;
3676 return c->value;
3677}
3678
62b3e311
PB
3679/* Parse an option for a barrier instruction. Returns the encoding for the
3680 option, or FAIL. */
3681static int
3682parse_barrier (char **str)
3683{
3684 char *p, *q;
3685 const struct asm_barrier_opt *o;
3686
3687 p = q = *str;
3688 while (ISALPHA (*q))
3689 q++;
3690
3691 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
3692 if (!o)
3693 return FAIL;
3694
3695 *str = q;
3696 return o->value;
3697}
3698
92e90b6e
PB
3699/* Parse the operands of a table branch instruction. Similar to a memory
3700 operand. */
3701static int
3702parse_tb (char **str)
3703{
3704 char * p = *str;
3705 int reg;
3706
3707 if (skip_past_char (&p, '[') == FAIL)
3708 return FAIL;
3709
3710 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3711 {
3712 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3713 return FAIL;
3714 }
3715 inst.operands[0].reg = reg;
3716
3717 if (skip_past_comma (&p) == FAIL)
3718 return FAIL;
3719
3720 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3721 {
3722 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3723 return FAIL;
3724 }
3725 inst.operands[0].imm = reg;
3726
3727 if (skip_past_comma (&p) == SUCCESS)
3728 {
3729 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3730 return FAIL;
3731 if (inst.reloc.exp.X_add_number != 1)
3732 {
3733 inst.error = _("invalid shift");
3734 return FAIL;
3735 }
3736 inst.operands[0].shifted = 1;
3737 }
3738
3739 if (skip_past_char (&p, ']') == FAIL)
3740 {
3741 inst.error = _("']' expected");
3742 return FAIL;
3743 }
3744 *str = p;
3745 return SUCCESS;
3746}
3747
c19d1205
ZW
3748/* Matcher codes for parse_operands. */
3749enum operand_parse_code
3750{
3751 OP_stop, /* end of line */
3752
3753 OP_RR, /* ARM register */
3754 OP_RRnpc, /* ARM register, not r15 */
3755 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3756 OP_RRw, /* ARM register, not r15, optional trailing ! */
3757 OP_RCP, /* Coprocessor number */
3758 OP_RCN, /* Coprocessor register */
3759 OP_RF, /* FPA register */
3760 OP_RVS, /* VFP single precision register */
3761 OP_RVD, /* VFP double precision register */
3762 OP_RVC, /* VFP control register */
3763 OP_RMF, /* Maverick F register */
3764 OP_RMD, /* Maverick D register */
3765 OP_RMFX, /* Maverick FX register */
3766 OP_RMDX, /* Maverick DX register */
3767 OP_RMAX, /* Maverick AX register */
3768 OP_RMDS, /* Maverick DSPSC register */
3769 OP_RIWR, /* iWMMXt wR register */
3770 OP_RIWC, /* iWMMXt wC register */
3771 OP_RIWG, /* iWMMXt wCG register */
3772 OP_RXA, /* XScale accumulator register */
3773
3774 OP_REGLST, /* ARM register list */
3775 OP_VRSLST, /* VFP single-precision register list */
3776 OP_VRDLST, /* VFP double-precision register list */
3777
3778 OP_I7, /* immediate value 0 .. 7 */
3779 OP_I15, /* 0 .. 15 */
3780 OP_I16, /* 1 .. 16 */
3781 OP_I31, /* 0 .. 31 */
3782 OP_I31w, /* 0 .. 31, optional trailing ! */
3783 OP_I32, /* 1 .. 32 */
3784 OP_I63s, /* -64 .. 63 */
3785 OP_I255, /* 0 .. 255 */
3786 OP_Iffff, /* 0 .. 65535 */
3787
3788 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3789 OP_I7b, /* 0 .. 7 */
3790 OP_I15b, /* 0 .. 15 */
3791 OP_I31b, /* 0 .. 31 */
3792
3793 OP_SH, /* shifter operand */
3794 OP_ADDR, /* Memory address expression (any mode) */
3795 OP_EXP, /* arbitrary expression */
3796 OP_EXPi, /* same, with optional immediate prefix */
3797 OP_EXPr, /* same, with optional relocation suffix */
3798
3799 OP_CPSF, /* CPS flags */
3800 OP_ENDI, /* Endianness specifier */
3801 OP_PSR, /* CPSR/SPSR mask for msr */
3802 OP_COND, /* conditional code */
92e90b6e 3803 OP_TB, /* Table branch. */
c19d1205
ZW
3804
3805 OP_RRnpc_I0, /* ARM register or literal 0 */
3806 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3807 OP_RR_EXi, /* ARM register or expression with imm prefix */
3808 OP_RF_IF, /* FPA register or immediate */
3809 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3810
3811 /* Optional operands. */
3812 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3813 OP_oI31b, /* 0 .. 31 */
3814 OP_oIffffb, /* 0 .. 65535 */
3815 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3816
3817 OP_oRR, /* ARM register */
3818 OP_oRRnpc, /* ARM register, not the PC */
3819 OP_oSHll, /* LSL immediate */
3820 OP_oSHar, /* ASR immediate */
3821 OP_oSHllar, /* LSL or ASR immediate */
3822 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 3823 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
3824
3825 OP_FIRST_OPTIONAL = OP_oI7b
3826};
a737bd4d 3827
c19d1205
ZW
3828/* Generic instruction operand parser. This does no encoding and no
3829 semantic validation; it merely squirrels values away in the inst
3830 structure. Returns SUCCESS or FAIL depending on whether the
3831 specified grammar matched. */
3832static int
ca3f61f7 3833parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
3834{
3835 unsigned const char *upat = pattern;
3836 char *backtrack_pos = 0;
3837 const char *backtrack_error = 0;
3838 int i, val, backtrack_index = 0;
3839
3840#define po_char_or_fail(chr) do { \
3841 if (skip_past_char (&str, chr) == FAIL) \
3842 goto bad_args; \
3843} while (0)
3844
3845#define po_reg_or_fail(regtype) do { \
3846 val = arm_reg_parse (&str, regtype); \
3847 if (val == FAIL) \
3848 { \
3849 inst.error = _(reg_expected_msgs[regtype]); \
3850 goto failure; \
3851 } \
3852 inst.operands[i].reg = val; \
3853 inst.operands[i].isreg = 1; \
3854} while (0)
3855
3856#define po_reg_or_goto(regtype, label) do { \
3857 val = arm_reg_parse (&str, regtype); \
3858 if (val == FAIL) \
3859 goto label; \
3860 \
3861 inst.operands[i].reg = val; \
3862 inst.operands[i].isreg = 1; \
3863} while (0)
3864
3865#define po_imm_or_fail(min, max, popt) do { \
3866 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3867 goto failure; \
3868 inst.operands[i].imm = val; \
3869} while (0)
3870
3871#define po_misc_or_fail(expr) do { \
3872 if (expr) \
3873 goto failure; \
3874} while (0)
3875
3876 skip_whitespace (str);
3877
3878 for (i = 0; upat[i] != OP_stop; i++)
3879 {
3880 if (upat[i] >= OP_FIRST_OPTIONAL)
3881 {
3882 /* Remember where we are in case we need to backtrack. */
3883 assert (!backtrack_pos);
3884 backtrack_pos = str;
3885 backtrack_error = inst.error;
3886 backtrack_index = i;
3887 }
3888
3889 if (i > 0)
3890 po_char_or_fail (',');
3891
3892 switch (upat[i])
3893 {
3894 /* Registers */
3895 case OP_oRRnpc:
3896 case OP_RRnpc:
3897 case OP_oRR:
3898 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3899 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3900 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3901 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3902 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3903 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3904 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3905 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3906 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3907 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3908 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3909 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3910 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3911 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3912 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3913 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3914 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3915
3916 case OP_RRnpcb:
3917 po_char_or_fail ('[');
3918 po_reg_or_fail (REG_TYPE_RN);
3919 po_char_or_fail (']');
3920 break;
a737bd4d 3921
c19d1205
ZW
3922 case OP_RRw:
3923 po_reg_or_fail (REG_TYPE_RN);
3924 if (skip_past_char (&str, '!') == SUCCESS)
3925 inst.operands[i].writeback = 1;
3926 break;
3927
3928 /* Immediates */
3929 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3930 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3931 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3932 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3933 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3934 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3935 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3936 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3937
3938 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3939 case OP_oI7b:
3940 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3941 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3942 case OP_oI31b:
3943 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3944 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3945
3946 /* Immediate variants */
3947 case OP_oI255c:
3948 po_char_or_fail ('{');
3949 po_imm_or_fail (0, 255, TRUE);
3950 po_char_or_fail ('}');
3951 break;
3952
3953 case OP_I31w:
3954 /* The expression parser chokes on a trailing !, so we have
3955 to find it first and zap it. */
3956 {
3957 char *s = str;
3958 while (*s && *s != ',')
3959 s++;
3960 if (s[-1] == '!')
3961 {
3962 s[-1] = '\0';
3963 inst.operands[i].writeback = 1;
3964 }
3965 po_imm_or_fail (0, 31, TRUE);
3966 if (str == s - 1)
3967 str = s;
3968 }
3969 break;
3970
3971 /* Expressions */
3972 case OP_EXPi: EXPi:
3973 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3974 GE_OPT_PREFIX));
3975 break;
3976
3977 case OP_EXP:
3978 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3979 GE_NO_PREFIX));
3980 break;
3981
3982 case OP_EXPr: EXPr:
3983 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3984 GE_NO_PREFIX));
3985 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3986 {
c19d1205
ZW
3987 val = parse_reloc (&str);
3988 if (val == -1)
3989 {
3990 inst.error = _("unrecognized relocation suffix");
3991 goto failure;
3992 }
3993 else if (val != BFD_RELOC_UNUSED)
3994 {
3995 inst.operands[i].imm = val;
3996 inst.operands[i].hasreloc = 1;
3997 }
a737bd4d 3998 }
c19d1205 3999 break;
a737bd4d 4000
c19d1205
ZW
4001 /* Register or expression */
4002 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
4003 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 4004
c19d1205
ZW
4005 /* Register or immediate */
4006 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
4007 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 4008
c19d1205
ZW
4009 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
4010 IF:
4011 if (!is_immediate_prefix (*str))
4012 goto bad_args;
4013 str++;
4014 val = parse_fpa_immediate (&str);
4015 if (val == FAIL)
4016 goto failure;
4017 /* FPA immediates are encoded as registers 8-15.
4018 parse_fpa_immediate has already applied the offset. */
4019 inst.operands[i].reg = val;
4020 inst.operands[i].isreg = 1;
4021 break;
09d92015 4022
c19d1205
ZW
4023 /* Two kinds of register */
4024 case OP_RIWR_RIWC:
4025 {
4026 struct reg_entry *rege = arm_reg_parse_multi (&str);
4027 if (rege->type != REG_TYPE_MMXWR
4028 && rege->type != REG_TYPE_MMXWC
4029 && rege->type != REG_TYPE_MMXWCG)
4030 {
4031 inst.error = _("iWMMXt data or control register expected");
4032 goto failure;
4033 }
4034 inst.operands[i].reg = rege->number;
4035 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
4036 }
4037 break;
09d92015 4038
c19d1205
ZW
4039 /* Misc */
4040 case OP_CPSF: val = parse_cps_flags (&str); break;
4041 case OP_ENDI: val = parse_endian_specifier (&str); break;
4042 case OP_oROR: val = parse_ror (&str); break;
4043 case OP_PSR: val = parse_psr (&str); break;
4044 case OP_COND: val = parse_cond (&str); break;
62b3e311 4045 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 4046
92e90b6e
PB
4047 case OP_TB:
4048 po_misc_or_fail (parse_tb (&str));
4049 break;
4050
c19d1205
ZW
4051 /* Register lists */
4052 case OP_REGLST:
4053 val = parse_reg_list (&str);
4054 if (*str == '^')
4055 {
4056 inst.operands[1].writeback = 1;
4057 str++;
4058 }
4059 break;
09d92015 4060
c19d1205
ZW
4061 case OP_VRSLST:
4062 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
4063 break;
09d92015 4064
c19d1205
ZW
4065 case OP_VRDLST:
4066 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
4067 break;
a737bd4d 4068
c19d1205
ZW
4069 /* Addressing modes */
4070 case OP_ADDR:
4071 po_misc_or_fail (parse_address (&str, i));
4072 break;
09d92015 4073
c19d1205
ZW
4074 case OP_SH:
4075 po_misc_or_fail (parse_shifter_operand (&str, i));
4076 break;
09d92015 4077
c19d1205
ZW
4078 case OP_oSHll:
4079 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
4080 break;
09d92015 4081
c19d1205
ZW
4082 case OP_oSHar:
4083 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
4084 break;
09d92015 4085
c19d1205
ZW
4086 case OP_oSHllar:
4087 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
4088 break;
09d92015 4089
c19d1205
ZW
4090 default:
4091 as_fatal ("unhandled operand code %d", upat[i]);
4092 }
09d92015 4093
c19d1205
ZW
4094 /* Various value-based sanity checks and shared operations. We
4095 do not signal immediate failures for the register constraints;
4096 this allows a syntax error to take precedence. */
4097 switch (upat[i])
4098 {
4099 case OP_oRRnpc:
4100 case OP_RRnpc:
4101 case OP_RRnpcb:
4102 case OP_RRw:
4103 case OP_RRnpc_I0:
4104 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
4105 inst.error = BAD_PC;
4106 break;
09d92015 4107
c19d1205
ZW
4108 case OP_CPSF:
4109 case OP_ENDI:
4110 case OP_oROR:
4111 case OP_PSR:
4112 case OP_COND:
62b3e311 4113 case OP_oBARRIER:
c19d1205
ZW
4114 case OP_REGLST:
4115 case OP_VRSLST:
4116 case OP_VRDLST:
4117 if (val == FAIL)
4118 goto failure;
4119 inst.operands[i].imm = val;
4120 break;
a737bd4d 4121
c19d1205
ZW
4122 default:
4123 break;
4124 }
09d92015 4125
c19d1205
ZW
4126 /* If we get here, this operand was successfully parsed. */
4127 inst.operands[i].present = 1;
4128 continue;
09d92015 4129
c19d1205 4130 bad_args:
09d92015 4131 inst.error = BAD_ARGS;
c19d1205
ZW
4132
4133 failure:
4134 if (!backtrack_pos)
4135 return FAIL;
4136
4137 /* Do not backtrack over a trailing optional argument that
4138 absorbed some text. We will only fail again, with the
4139 'garbage following instruction' error message, which is
4140 probably less helpful than the current one. */
4141 if (backtrack_index == i && backtrack_pos != str
4142 && upat[i+1] == OP_stop)
4143 return FAIL;
4144
4145 /* Try again, skipping the optional argument at backtrack_pos. */
4146 str = backtrack_pos;
4147 inst.error = backtrack_error;
4148 inst.operands[backtrack_index].present = 0;
4149 i = backtrack_index;
4150 backtrack_pos = 0;
09d92015 4151 }
09d92015 4152
c19d1205
ZW
4153 /* Check that we have parsed all the arguments. */
4154 if (*str != '\0' && !inst.error)
4155 inst.error = _("garbage following instruction");
09d92015 4156
c19d1205 4157 return inst.error ? FAIL : SUCCESS;
09d92015
MM
4158}
4159
c19d1205
ZW
4160#undef po_char_or_fail
4161#undef po_reg_or_fail
4162#undef po_reg_or_goto
4163#undef po_imm_or_fail
4164\f
4165/* Shorthand macro for instruction encoding functions issuing errors. */
4166#define constraint(expr, err) do { \
4167 if (expr) \
4168 { \
4169 inst.error = err; \
4170 return; \
4171 } \
4172} while (0)
4173
4174/* Functions for operand encoding. ARM, then Thumb. */
4175
4176#define rotate_left(v, n) (v << n | v >> (32 - n))
4177
4178/* If VAL can be encoded in the immediate field of an ARM instruction,
4179 return the encoded form. Otherwise, return FAIL. */
4180
4181static unsigned int
4182encode_arm_immediate (unsigned int val)
09d92015 4183{
c19d1205
ZW
4184 unsigned int a, i;
4185
4186 for (i = 0; i < 32; i += 2)
4187 if ((a = rotate_left (val, i)) <= 0xff)
4188 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
4189
4190 return FAIL;
09d92015
MM
4191}
4192
c19d1205
ZW
4193/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
4194 return the encoded form. Otherwise, return FAIL. */
4195static unsigned int
4196encode_thumb32_immediate (unsigned int val)
09d92015 4197{
c19d1205 4198 unsigned int a, i;
09d92015 4199
9c3c69f2 4200 if (val <= 0xff)
c19d1205 4201 return val;
a737bd4d 4202
9c3c69f2 4203 for (i = 1; i <= 24; i++)
09d92015 4204 {
9c3c69f2
PB
4205 a = val >> i;
4206 if ((val & ~(0xff << i)) == 0)
4207 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 4208 }
a737bd4d 4209
c19d1205
ZW
4210 a = val & 0xff;
4211 if (val == ((a << 16) | a))
4212 return 0x100 | a;
4213 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4214 return 0x300 | a;
09d92015 4215
c19d1205
ZW
4216 a = val & 0xff00;
4217 if (val == ((a << 16) | a))
4218 return 0x200 | (a >> 8);
a737bd4d 4219
c19d1205 4220 return FAIL;
09d92015 4221}
c19d1205 4222/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
4223
4224static void
c19d1205 4225encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 4226{
c19d1205 4227 switch (pos)
09d92015 4228 {
c19d1205
ZW
4229 case VFP_REG_Sd:
4230 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4231 break;
4232
4233 case VFP_REG_Sn:
4234 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4235 break;
4236
4237 case VFP_REG_Sm:
4238 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4239 break;
4240
4241 default:
4242 abort ();
09d92015 4243 }
09d92015
MM
4244}
4245
c19d1205 4246/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 4247 if any, is handled by md_apply_fix. */
09d92015 4248static void
c19d1205 4249encode_arm_shift (int i)
09d92015 4250{
c19d1205
ZW
4251 if (inst.operands[i].shift_kind == SHIFT_RRX)
4252 inst.instruction |= SHIFT_ROR << 5;
4253 else
09d92015 4254 {
c19d1205
ZW
4255 inst.instruction |= inst.operands[i].shift_kind << 5;
4256 if (inst.operands[i].immisreg)
4257 {
4258 inst.instruction |= SHIFT_BY_REG;
4259 inst.instruction |= inst.operands[i].imm << 8;
4260 }
4261 else
4262 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 4263 }
c19d1205 4264}
09d92015 4265
c19d1205
ZW
4266static void
4267encode_arm_shifter_operand (int i)
4268{
4269 if (inst.operands[i].isreg)
09d92015 4270 {
c19d1205
ZW
4271 inst.instruction |= inst.operands[i].reg;
4272 encode_arm_shift (i);
09d92015 4273 }
c19d1205
ZW
4274 else
4275 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4276}
4277
c19d1205 4278/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4279static void
c19d1205 4280encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4281{
c19d1205
ZW
4282 assert (inst.operands[i].isreg);
4283 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4284
c19d1205 4285 if (inst.operands[i].preind)
09d92015 4286 {
c19d1205
ZW
4287 if (is_t)
4288 {
4289 inst.error = _("instruction does not accept preindexed addressing");
4290 return;
4291 }
4292 inst.instruction |= PRE_INDEX;
4293 if (inst.operands[i].writeback)
4294 inst.instruction |= WRITE_BACK;
09d92015 4295
c19d1205
ZW
4296 }
4297 else if (inst.operands[i].postind)
4298 {
4299 assert (inst.operands[i].writeback);
4300 if (is_t)
4301 inst.instruction |= WRITE_BACK;
4302 }
4303 else /* unindexed - only for coprocessor */
09d92015 4304 {
c19d1205 4305 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4306 return;
4307 }
4308
c19d1205
ZW
4309 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4310 && (((inst.instruction & 0x000f0000) >> 16)
4311 == ((inst.instruction & 0x0000f000) >> 12)))
4312 as_warn ((inst.instruction & LOAD_BIT)
4313 ? _("destination register same as write-back base")
4314 : _("source register same as write-back base"));
09d92015
MM
4315}
4316
c19d1205
ZW
4317/* inst.operands[i] was set up by parse_address. Encode it into an
4318 ARM-format mode 2 load or store instruction. If is_t is true,
4319 reject forms that cannot be used with a T instruction (i.e. not
4320 post-indexed). */
a737bd4d 4321static void
c19d1205 4322encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4323{
c19d1205 4324 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4325
c19d1205 4326 if (inst.operands[i].immisreg)
09d92015 4327 {
c19d1205
ZW
4328 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4329 inst.instruction |= inst.operands[i].imm;
4330 if (!inst.operands[i].negative)
4331 inst.instruction |= INDEX_UP;
4332 if (inst.operands[i].shifted)
4333 {
4334 if (inst.operands[i].shift_kind == SHIFT_RRX)
4335 inst.instruction |= SHIFT_ROR << 5;
4336 else
4337 {
4338 inst.instruction |= inst.operands[i].shift_kind << 5;
4339 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4340 }
4341 }
09d92015 4342 }
c19d1205 4343 else /* immediate offset in inst.reloc */
09d92015 4344 {
c19d1205
ZW
4345 if (inst.reloc.type == BFD_RELOC_UNUSED)
4346 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 4347 }
09d92015
MM
4348}
4349
c19d1205
ZW
4350/* inst.operands[i] was set up by parse_address. Encode it into an
4351 ARM-format mode 3 load or store instruction. Reject forms that
4352 cannot be used with such instructions. If is_t is true, reject
4353 forms that cannot be used with a T instruction (i.e. not
4354 post-indexed). */
4355static void
4356encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4357{
c19d1205 4358 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4359 {
c19d1205
ZW
4360 inst.error = _("instruction does not accept scaled register index");
4361 return;
09d92015 4362 }
a737bd4d 4363
c19d1205 4364 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4365
c19d1205
ZW
4366 if (inst.operands[i].immisreg)
4367 {
4368 inst.instruction |= inst.operands[i].imm;
4369 if (!inst.operands[i].negative)
4370 inst.instruction |= INDEX_UP;
4371 }
4372 else /* immediate offset in inst.reloc */
4373 {
4374 inst.instruction |= HWOFFSET_IMM;
4375 if (inst.reloc.type == BFD_RELOC_UNUSED)
4376 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 4377 }
a737bd4d
NC
4378}
4379
c19d1205
ZW
4380/* inst.operands[i] was set up by parse_address. Encode it into an
4381 ARM-format instruction. Reject all forms which cannot be encoded
4382 into a coprocessor load/store instruction. If wb_ok is false,
4383 reject use of writeback; if unind_ok is false, reject use of
4384 unindexed addressing. If reloc_override is not 0, use it instead
4385 of BFD_ARM_CP_OFF_IMM. */
09d92015 4386
c19d1205
ZW
4387static int
4388encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4389{
c19d1205 4390 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4391
c19d1205 4392 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4393
c19d1205 4394 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4395 {
c19d1205
ZW
4396 assert (!inst.operands[i].writeback);
4397 if (!unind_ok)
4398 {
4399 inst.error = _("instruction does not support unindexed addressing");
4400 return FAIL;
4401 }
4402 inst.instruction |= inst.operands[i].imm;
4403 inst.instruction |= INDEX_UP;
4404 return SUCCESS;
09d92015 4405 }
a737bd4d 4406
c19d1205
ZW
4407 if (inst.operands[i].preind)
4408 inst.instruction |= PRE_INDEX;
a737bd4d 4409
c19d1205 4410 if (inst.operands[i].writeback)
09d92015 4411 {
c19d1205
ZW
4412 if (inst.operands[i].reg == REG_PC)
4413 {
4414 inst.error = _("pc may not be used with write-back");
4415 return FAIL;
4416 }
4417 if (!wb_ok)
4418 {
4419 inst.error = _("instruction does not support writeback");
4420 return FAIL;
4421 }
4422 inst.instruction |= WRITE_BACK;
09d92015 4423 }
a737bd4d 4424
c19d1205
ZW
4425 if (reloc_override)
4426 inst.reloc.type = reloc_override;
8f06b2d8
PB
4427 else if (thumb_mode)
4428 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
09d92015 4429 else
c19d1205 4430 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205
ZW
4431 return SUCCESS;
4432}
a737bd4d 4433
c19d1205
ZW
4434/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4435 Determine whether it can be performed with a move instruction; if
4436 it can, convert inst.instruction to that move instruction and
4437 return 1; if it can't, convert inst.instruction to a literal-pool
4438 load and return 0. If this is not a valid thing to do in the
4439 current context, set inst.error and return 1.
a737bd4d 4440
c19d1205
ZW
4441 inst.operands[i] describes the destination register. */
4442
4443static int
4444move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4445{
4446 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4447 {
c19d1205
ZW
4448 inst.error = _("invalid pseudo operation");
4449 return 1;
09d92015 4450 }
c19d1205 4451 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4452 {
4453 inst.error = _("constant expression expected");
c19d1205 4454 return 1;
09d92015 4455 }
c19d1205 4456 if (inst.reloc.exp.X_op == O_constant)
09d92015 4457 {
c19d1205
ZW
4458 if (thumb_p)
4459 {
4460 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4461 {
4462 /* This can be done with a mov(1) instruction. */
4463 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4464 inst.instruction |= inst.reloc.exp.X_add_number;
4465 return 1;
4466 }
4467 }
4468 else
4469 {
4470 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4471 if (value != FAIL)
4472 {
4473 /* This can be done with a mov instruction. */
4474 inst.instruction &= LITERAL_MASK;
4475 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4476 inst.instruction |= value & 0xfff;
4477 return 1;
4478 }
09d92015 4479
c19d1205
ZW
4480 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4481 if (value != FAIL)
4482 {
4483 /* This can be done with a mvn instruction. */
4484 inst.instruction &= LITERAL_MASK;
4485 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4486 inst.instruction |= value & 0xfff;
4487 return 1;
4488 }
4489 }
09d92015
MM
4490 }
4491
c19d1205
ZW
4492 if (add_to_lit_pool () == FAIL)
4493 {
4494 inst.error = _("literal pool insertion failed");
4495 return 1;
4496 }
4497 inst.operands[1].reg = REG_PC;
4498 inst.operands[1].isreg = 1;
4499 inst.operands[1].preind = 1;
4500 inst.reloc.pc_rel = 1;
4501 inst.reloc.type = (thumb_p
4502 ? BFD_RELOC_ARM_THUMB_OFFSET
4503 : (mode_3
4504 ? BFD_RELOC_ARM_HWLITERAL
4505 : BFD_RELOC_ARM_LITERAL));
4506 return 0;
09d92015
MM
4507}
4508
c19d1205
ZW
4509/* Functions for instruction encoding, sorted by subarchitecture.
4510 First some generics; their names are taken from the conventional
4511 bit positions for register arguments in ARM format instructions. */
09d92015 4512
a737bd4d 4513static void
c19d1205 4514do_noargs (void)
09d92015 4515{
c19d1205 4516}
a737bd4d 4517
c19d1205
ZW
4518static void
4519do_rd (void)
4520{
4521 inst.instruction |= inst.operands[0].reg << 12;
4522}
a737bd4d 4523
c19d1205
ZW
4524static void
4525do_rd_rm (void)
4526{
4527 inst.instruction |= inst.operands[0].reg << 12;
4528 inst.instruction |= inst.operands[1].reg;
4529}
09d92015 4530
c19d1205
ZW
4531static void
4532do_rd_rn (void)
4533{
4534 inst.instruction |= inst.operands[0].reg << 12;
4535 inst.instruction |= inst.operands[1].reg << 16;
4536}
a737bd4d 4537
c19d1205
ZW
4538static void
4539do_rn_rd (void)
4540{
4541 inst.instruction |= inst.operands[0].reg << 16;
4542 inst.instruction |= inst.operands[1].reg << 12;
4543}
09d92015 4544
c19d1205
ZW
4545static void
4546do_rd_rm_rn (void)
4547{
9a64e435
PB
4548 unsigned Rn = inst.operands[2].reg;
4549 /* Enforce resutrictions on SWP instruction. */
4550 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
4551 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
4552 _("Rn must not overlap other operands"));
c19d1205
ZW
4553 inst.instruction |= inst.operands[0].reg << 12;
4554 inst.instruction |= inst.operands[1].reg;
9a64e435 4555 inst.instruction |= Rn << 16;
c19d1205 4556}
09d92015 4557
c19d1205
ZW
4558static void
4559do_rd_rn_rm (void)
4560{
4561 inst.instruction |= inst.operands[0].reg << 12;
4562 inst.instruction |= inst.operands[1].reg << 16;
4563 inst.instruction |= inst.operands[2].reg;
4564}
a737bd4d 4565
c19d1205
ZW
4566static void
4567do_rm_rd_rn (void)
4568{
4569 inst.instruction |= inst.operands[0].reg;
4570 inst.instruction |= inst.operands[1].reg << 12;
4571 inst.instruction |= inst.operands[2].reg << 16;
4572}
09d92015 4573
c19d1205
ZW
4574static void
4575do_imm0 (void)
4576{
4577 inst.instruction |= inst.operands[0].imm;
4578}
09d92015 4579
c19d1205
ZW
4580static void
4581do_rd_cpaddr (void)
4582{
4583 inst.instruction |= inst.operands[0].reg << 12;
4584 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4585}
a737bd4d 4586
c19d1205
ZW
4587/* ARM instructions, in alphabetical order by function name (except
4588 that wrapper functions appear immediately after the function they
4589 wrap). */
09d92015 4590
c19d1205
ZW
4591/* This is a pseudo-op of the form "adr rd, label" to be converted
4592 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4593
4594static void
c19d1205 4595do_adr (void)
09d92015 4596{
c19d1205 4597 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4598
c19d1205
ZW
4599 /* Frag hacking will turn this into a sub instruction if the offset turns
4600 out to be negative. */
4601 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 4602 inst.reloc.pc_rel = 1;
2fc8bdac 4603 inst.reloc.exp.X_add_number -= 8;
c19d1205 4604}
b99bd4ef 4605
c19d1205
ZW
4606/* This is a pseudo-op of the form "adrl rd, label" to be converted
4607 into a relative address of the form:
4608 add rd, pc, #low(label-.-8)"
4609 add rd, rd, #high(label-.-8)" */
b99bd4ef 4610
c19d1205
ZW
4611static void
4612do_adrl (void)
4613{
4614 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4615
c19d1205
ZW
4616 /* Frag hacking will turn this into a sub instruction if the offset turns
4617 out to be negative. */
4618 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
4619 inst.reloc.pc_rel = 1;
4620 inst.size = INSN_SIZE * 2;
2fc8bdac 4621 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
4622}
4623
b99bd4ef 4624static void
c19d1205 4625do_arit (void)
b99bd4ef 4626{
c19d1205
ZW
4627 if (!inst.operands[1].present)
4628 inst.operands[1].reg = inst.operands[0].reg;
4629 inst.instruction |= inst.operands[0].reg << 12;
4630 inst.instruction |= inst.operands[1].reg << 16;
4631 encode_arm_shifter_operand (2);
4632}
b99bd4ef 4633
62b3e311
PB
4634static void
4635do_barrier (void)
4636{
4637 if (inst.operands[0].present)
4638 {
4639 constraint ((inst.instruction & 0xf0) != 0x40
4640 && inst.operands[0].imm != 0xf,
4641 "bad barrier type");
4642 inst.instruction |= inst.operands[0].imm;
4643 }
4644 else
4645 inst.instruction |= 0xf;
4646}
4647
c19d1205
ZW
4648static void
4649do_bfc (void)
4650{
4651 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4652 constraint (msb > 32, _("bit-field extends past end of register"));
4653 /* The instruction encoding stores the LSB and MSB,
4654 not the LSB and width. */
4655 inst.instruction |= inst.operands[0].reg << 12;
4656 inst.instruction |= inst.operands[1].imm << 7;
4657 inst.instruction |= (msb - 1) << 16;
4658}
b99bd4ef 4659
c19d1205
ZW
4660static void
4661do_bfi (void)
4662{
4663 unsigned int msb;
b99bd4ef 4664
c19d1205
ZW
4665 /* #0 in second position is alternative syntax for bfc, which is
4666 the same instruction but with REG_PC in the Rm field. */
4667 if (!inst.operands[1].isreg)
4668 inst.operands[1].reg = REG_PC;
b99bd4ef 4669
c19d1205
ZW
4670 msb = inst.operands[2].imm + inst.operands[3].imm;
4671 constraint (msb > 32, _("bit-field extends past end of register"));
4672 /* The instruction encoding stores the LSB and MSB,
4673 not the LSB and width. */
4674 inst.instruction |= inst.operands[0].reg << 12;
4675 inst.instruction |= inst.operands[1].reg;
4676 inst.instruction |= inst.operands[2].imm << 7;
4677 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4678}
4679
b99bd4ef 4680static void
c19d1205 4681do_bfx (void)
b99bd4ef 4682{
c19d1205
ZW
4683 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4684 _("bit-field extends past end of register"));
4685 inst.instruction |= inst.operands[0].reg << 12;
4686 inst.instruction |= inst.operands[1].reg;
4687 inst.instruction |= inst.operands[2].imm << 7;
4688 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4689}
09d92015 4690
c19d1205
ZW
4691/* ARM V5 breakpoint instruction (argument parse)
4692 BKPT <16 bit unsigned immediate>
4693 Instruction is not conditional.
4694 The bit pattern given in insns[] has the COND_ALWAYS condition,
4695 and it is an error if the caller tried to override that. */
b99bd4ef 4696
c19d1205
ZW
4697static void
4698do_bkpt (void)
4699{
4700 /* Top 12 of 16 bits to bits 19:8. */
4701 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4702
c19d1205
ZW
4703 /* Bottom 4 of 16 bits to bits 3:0. */
4704 inst.instruction |= inst.operands[0].imm & 0xf;
4705}
09d92015 4706
c19d1205
ZW
4707static void
4708encode_branch (int default_reloc)
4709{
4710 if (inst.operands[0].hasreloc)
4711 {
4712 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4713 _("the only suffix valid here is '(plt)'"));
4714 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 4715 }
b99bd4ef 4716 else
c19d1205
ZW
4717 {
4718 inst.reloc.type = default_reloc;
c19d1205 4719 }
2fc8bdac 4720 inst.reloc.pc_rel = 1;
b99bd4ef
NC
4721}
4722
b99bd4ef 4723static void
c19d1205 4724do_branch (void)
b99bd4ef 4725{
39b41c9c
PB
4726#ifdef OBJ_ELF
4727 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4728 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4729 else
4730#endif
4731 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4732}
4733
4734static void
4735do_bl (void)
4736{
4737#ifdef OBJ_ELF
4738 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4739 {
4740 if (inst.cond == COND_ALWAYS)
4741 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4742 else
4743 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4744 }
4745 else
4746#endif
4747 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 4748}
b99bd4ef 4749
c19d1205
ZW
4750/* ARM V5 branch-link-exchange instruction (argument parse)
4751 BLX <target_addr> ie BLX(1)
4752 BLX{<condition>} <Rm> ie BLX(2)
4753 Unfortunately, there are two different opcodes for this mnemonic.
4754 So, the insns[].value is not used, and the code here zaps values
4755 into inst.instruction.
4756 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4757
c19d1205
ZW
4758static void
4759do_blx (void)
4760{
4761 if (inst.operands[0].isreg)
b99bd4ef 4762 {
c19d1205
ZW
4763 /* Arg is a register; the opcode provided by insns[] is correct.
4764 It is not illegal to do "blx pc", just useless. */
4765 if (inst.operands[0].reg == REG_PC)
4766 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4767
c19d1205
ZW
4768 inst.instruction |= inst.operands[0].reg;
4769 }
4770 else
b99bd4ef 4771 {
c19d1205
ZW
4772 /* Arg is an address; this instruction cannot be executed
4773 conditionally, and the opcode must be adjusted. */
4774 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 4775 inst.instruction = 0xfa000000;
39b41c9c
PB
4776#ifdef OBJ_ELF
4777 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4778 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4779 else
4780#endif
4781 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4782 }
c19d1205
ZW
4783}
4784
4785static void
4786do_bx (void)
4787{
4788 if (inst.operands[0].reg == REG_PC)
4789 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4790
c19d1205 4791 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4792}
4793
c19d1205
ZW
4794
4795/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4796
4797static void
c19d1205 4798do_bxj (void)
a737bd4d 4799{
c19d1205
ZW
4800 if (inst.operands[0].reg == REG_PC)
4801 as_tsktsk (_("use of r15 in bxj is not really useful"));
4802
4803 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4804}
4805
c19d1205
ZW
4806/* Co-processor data operation:
4807 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4808 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4809static void
4810do_cdp (void)
4811{
4812 inst.instruction |= inst.operands[0].reg << 8;
4813 inst.instruction |= inst.operands[1].imm << 20;
4814 inst.instruction |= inst.operands[2].reg << 12;
4815 inst.instruction |= inst.operands[3].reg << 16;
4816 inst.instruction |= inst.operands[4].reg;
4817 inst.instruction |= inst.operands[5].imm << 5;
4818}
a737bd4d
NC
4819
4820static void
c19d1205 4821do_cmp (void)
a737bd4d 4822{
c19d1205
ZW
4823 inst.instruction |= inst.operands[0].reg << 16;
4824 encode_arm_shifter_operand (1);
a737bd4d
NC
4825}
4826
c19d1205
ZW
4827/* Transfer between coprocessor and ARM registers.
4828 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4829 MRC2
4830 MCR{cond}
4831 MCR2
4832
4833 No special properties. */
09d92015
MM
4834
4835static void
c19d1205 4836do_co_reg (void)
09d92015 4837{
c19d1205
ZW
4838 inst.instruction |= inst.operands[0].reg << 8;
4839 inst.instruction |= inst.operands[1].imm << 21;
4840 inst.instruction |= inst.operands[2].reg << 12;
4841 inst.instruction |= inst.operands[3].reg << 16;
4842 inst.instruction |= inst.operands[4].reg;
4843 inst.instruction |= inst.operands[5].imm << 5;
4844}
09d92015 4845
c19d1205
ZW
4846/* Transfer between coprocessor register and pair of ARM registers.
4847 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4848 MCRR2
4849 MRRC{cond}
4850 MRRC2
b99bd4ef 4851
c19d1205 4852 Two XScale instructions are special cases of these:
09d92015 4853
c19d1205
ZW
4854 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4855 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4856
c19d1205 4857 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4858
c19d1205
ZW
4859static void
4860do_co_reg2c (void)
4861{
4862 inst.instruction |= inst.operands[0].reg << 8;
4863 inst.instruction |= inst.operands[1].imm << 4;
4864 inst.instruction |= inst.operands[2].reg << 12;
4865 inst.instruction |= inst.operands[3].reg << 16;
4866 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4867}
4868
c19d1205
ZW
4869static void
4870do_cpsi (void)
4871{
4872 inst.instruction |= inst.operands[0].imm << 6;
4873 inst.instruction |= inst.operands[1].imm;
4874}
b99bd4ef 4875
62b3e311
PB
4876static void
4877do_dbg (void)
4878{
4879 inst.instruction |= inst.operands[0].imm;
4880}
4881
b99bd4ef 4882static void
c19d1205 4883do_it (void)
b99bd4ef 4884{
c19d1205
ZW
4885 /* There is no IT instruction in ARM mode. We
4886 process it but do not generate code for it. */
4887 inst.size = 0;
09d92015 4888}
b99bd4ef 4889
09d92015 4890static void
c19d1205 4891do_ldmstm (void)
ea6ef066 4892{
c19d1205
ZW
4893 int base_reg = inst.operands[0].reg;
4894 int range = inst.operands[1].imm;
ea6ef066 4895
c19d1205
ZW
4896 inst.instruction |= base_reg << 16;
4897 inst.instruction |= range;
ea6ef066 4898
c19d1205
ZW
4899 if (inst.operands[1].writeback)
4900 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4901
c19d1205 4902 if (inst.operands[0].writeback)
ea6ef066 4903 {
c19d1205
ZW
4904 inst.instruction |= WRITE_BACK;
4905 /* Check for unpredictable uses of writeback. */
4906 if (inst.instruction & LOAD_BIT)
09d92015 4907 {
c19d1205
ZW
4908 /* Not allowed in LDM type 2. */
4909 if ((inst.instruction & LDM_TYPE_2_OR_3)
4910 && ((range & (1 << REG_PC)) == 0))
4911 as_warn (_("writeback of base register is UNPREDICTABLE"));
4912 /* Only allowed if base reg not in list for other types. */
4913 else if (range & (1 << base_reg))
4914 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4915 }
4916 else /* STM. */
4917 {
4918 /* Not allowed for type 2. */
4919 if (inst.instruction & LDM_TYPE_2_OR_3)
4920 as_warn (_("writeback of base register is UNPREDICTABLE"));
4921 /* Only allowed if base reg not in list, or first in list. */
4922 else if ((range & (1 << base_reg))
4923 && (range & ((1 << base_reg) - 1)))
4924 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4925 }
ea6ef066 4926 }
a737bd4d
NC
4927}
4928
c19d1205
ZW
4929/* ARMv5TE load-consecutive (argument parse)
4930 Mode is like LDRH.
4931
4932 LDRccD R, mode
4933 STRccD R, mode. */
4934
a737bd4d 4935static void
c19d1205 4936do_ldrd (void)
a737bd4d 4937{
c19d1205
ZW
4938 constraint (inst.operands[0].reg % 2 != 0,
4939 _("first destination register must be even"));
4940 constraint (inst.operands[1].present
4941 && inst.operands[1].reg != inst.operands[0].reg + 1,
4942 _("can only load two consecutive registers"));
4943 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4944 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4945
c19d1205
ZW
4946 if (!inst.operands[1].present)
4947 inst.operands[1].reg = inst.operands[0].reg + 1;
4948
4949 if (inst.instruction & LOAD_BIT)
a737bd4d 4950 {
c19d1205
ZW
4951 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4952 register and the first register written; we have to diagnose
4953 overlap between the base and the second register written here. */
ea6ef066 4954
c19d1205
ZW
4955 if (inst.operands[2].reg == inst.operands[1].reg
4956 && (inst.operands[2].writeback || inst.operands[2].postind))
4957 as_warn (_("base register written back, and overlaps "
4958 "second destination register"));
b05fe5cf 4959
c19d1205
ZW
4960 /* For an index-register load, the index register must not overlap the
4961 destination (even if not write-back). */
4962 else if (inst.operands[2].immisreg
ca3f61f7
NC
4963 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4964 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 4965 as_warn (_("index register overlaps destination register"));
b05fe5cf 4966 }
c19d1205
ZW
4967
4968 inst.instruction |= inst.operands[0].reg << 12;
4969 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4970}
4971
4972static void
c19d1205 4973do_ldrex (void)
b05fe5cf 4974{
c19d1205
ZW
4975 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4976 || inst.operands[1].postind || inst.operands[1].writeback
4977 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
4978 || inst.operands[1].negative
4979 /* This can arise if the programmer has written
4980 strex rN, rM, foo
4981 or if they have mistakenly used a register name as the last
4982 operand, eg:
4983 strex rN, rM, rX
4984 It is very difficult to distinguish between these two cases
4985 because "rX" might actually be a label. ie the register
4986 name has been occluded by a symbol of the same name. So we
4987 just generate a general 'bad addressing mode' type error
4988 message and leave it up to the programmer to discover the
4989 true cause and fix their mistake. */
4990 || (inst.operands[1].reg == REG_PC),
4991 BAD_ADDR_MODE);
b05fe5cf 4992
c19d1205
ZW
4993 constraint (inst.reloc.exp.X_op != O_constant
4994 || inst.reloc.exp.X_add_number != 0,
4995 _("offset must be zero in ARM encoding"));
b05fe5cf 4996
c19d1205
ZW
4997 inst.instruction |= inst.operands[0].reg << 12;
4998 inst.instruction |= inst.operands[1].reg << 16;
4999 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
5000}
5001
5002static void
c19d1205 5003do_ldrexd (void)
b05fe5cf 5004{
c19d1205
ZW
5005 constraint (inst.operands[0].reg % 2 != 0,
5006 _("even register required"));
5007 constraint (inst.operands[1].present
5008 && inst.operands[1].reg != inst.operands[0].reg + 1,
5009 _("can only load two consecutive registers"));
5010 /* If op 1 were present and equal to PC, this function wouldn't
5011 have been called in the first place. */
5012 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 5013
c19d1205
ZW
5014 inst.instruction |= inst.operands[0].reg << 12;
5015 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
5016}
5017
5018static void
c19d1205 5019do_ldst (void)
b05fe5cf 5020{
c19d1205
ZW
5021 inst.instruction |= inst.operands[0].reg << 12;
5022 if (!inst.operands[1].isreg)
5023 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 5024 return;
c19d1205 5025 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
5026}
5027
5028static void
c19d1205 5029do_ldstt (void)
b05fe5cf 5030{
c19d1205
ZW
5031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5032 reject [Rn,...]. */
5033 if (inst.operands[1].preind)
b05fe5cf 5034 {
c19d1205
ZW
5035 constraint (inst.reloc.exp.X_op != O_constant ||
5036 inst.reloc.exp.X_add_number != 0,
5037 _("this instruction requires a post-indexed address"));
b05fe5cf 5038
c19d1205
ZW
5039 inst.operands[1].preind = 0;
5040 inst.operands[1].postind = 1;
5041 inst.operands[1].writeback = 1;
b05fe5cf 5042 }
c19d1205
ZW
5043 inst.instruction |= inst.operands[0].reg << 12;
5044 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
5045}
b05fe5cf 5046
c19d1205 5047/* Halfword and signed-byte load/store operations. */
b05fe5cf 5048
c19d1205
ZW
5049static void
5050do_ldstv4 (void)
5051{
5052 inst.instruction |= inst.operands[0].reg << 12;
5053 if (!inst.operands[1].isreg)
5054 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 5055 return;
c19d1205 5056 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
5057}
5058
5059static void
c19d1205 5060do_ldsttv4 (void)
b05fe5cf 5061{
c19d1205
ZW
5062 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5063 reject [Rn,...]. */
5064 if (inst.operands[1].preind)
b05fe5cf 5065 {
c19d1205
ZW
5066 constraint (inst.reloc.exp.X_op != O_constant ||
5067 inst.reloc.exp.X_add_number != 0,
5068 _("this instruction requires a post-indexed address"));
b05fe5cf 5069
c19d1205
ZW
5070 inst.operands[1].preind = 0;
5071 inst.operands[1].postind = 1;
5072 inst.operands[1].writeback = 1;
b05fe5cf 5073 }
c19d1205
ZW
5074 inst.instruction |= inst.operands[0].reg << 12;
5075 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
5076}
b05fe5cf 5077
c19d1205
ZW
5078/* Co-processor register load/store.
5079 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
5080static void
5081do_lstc (void)
5082{
5083 inst.instruction |= inst.operands[0].reg << 8;
5084 inst.instruction |= inst.operands[1].reg << 12;
5085 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
5086}
5087
b05fe5cf 5088static void
c19d1205 5089do_mlas (void)
b05fe5cf 5090{
c19d1205
ZW
5091 /* This restriction does not apply to mls (nor to mla in v6, but
5092 that's hard to detect at present). */
5093 if (inst.operands[0].reg == inst.operands[1].reg
5094 && !(inst.instruction & 0x00400000))
5095 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 5096
c19d1205
ZW
5097 inst.instruction |= inst.operands[0].reg << 16;
5098 inst.instruction |= inst.operands[1].reg;
5099 inst.instruction |= inst.operands[2].reg << 8;
5100 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 5101
c19d1205 5102}
b05fe5cf 5103
c19d1205
ZW
5104static void
5105do_mov (void)
5106{
5107 inst.instruction |= inst.operands[0].reg << 12;
5108 encode_arm_shifter_operand (1);
5109}
b05fe5cf 5110
c19d1205
ZW
5111/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
5112static void
5113do_mov16 (void)
5114{
5115 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 5116 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
5117 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
5118 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 5119}
b99bd4ef
NC
5120
5121static void
c19d1205 5122do_mrs (void)
b99bd4ef 5123{
c19d1205
ZW
5124 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
5125 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
5126 != (PSR_c|PSR_f),
5127 _("'CPSR' or 'SPSR' expected"));
5128 inst.instruction |= inst.operands[0].reg << 12;
5129 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
5130}
b99bd4ef 5131
c19d1205
ZW
5132/* Two possible forms:
5133 "{C|S}PSR_<field>, Rm",
5134 "{C|S}PSR_f, #expression". */
b99bd4ef 5135
c19d1205
ZW
5136static void
5137do_msr (void)
5138{
5139 inst.instruction |= inst.operands[0].imm;
5140 if (inst.operands[1].isreg)
5141 inst.instruction |= inst.operands[1].reg;
5142 else
b99bd4ef 5143 {
c19d1205
ZW
5144 inst.instruction |= INST_IMMEDIATE;
5145 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5146 inst.reloc.pc_rel = 0;
b99bd4ef 5147 }
b99bd4ef
NC
5148}
5149
c19d1205
ZW
5150static void
5151do_mul (void)
a737bd4d 5152{
c19d1205
ZW
5153 if (!inst.operands[2].present)
5154 inst.operands[2].reg = inst.operands[0].reg;
5155 inst.instruction |= inst.operands[0].reg << 16;
5156 inst.instruction |= inst.operands[1].reg;
5157 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 5158
c19d1205
ZW
5159 if (inst.operands[0].reg == inst.operands[1].reg)
5160 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
5161}
5162
c19d1205
ZW
5163/* Long Multiply Parser
5164 UMULL RdLo, RdHi, Rm, Rs
5165 SMULL RdLo, RdHi, Rm, Rs
5166 UMLAL RdLo, RdHi, Rm, Rs
5167 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
5168
5169static void
c19d1205 5170do_mull (void)
b99bd4ef 5171{
c19d1205
ZW
5172 inst.instruction |= inst.operands[0].reg << 12;
5173 inst.instruction |= inst.operands[1].reg << 16;
5174 inst.instruction |= inst.operands[2].reg;
5175 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 5176
c19d1205
ZW
5177 /* rdhi, rdlo and rm must all be different. */
5178 if (inst.operands[0].reg == inst.operands[1].reg
5179 || inst.operands[0].reg == inst.operands[2].reg
5180 || inst.operands[1].reg == inst.operands[2].reg)
5181 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
5182}
b99bd4ef 5183
c19d1205
ZW
5184static void
5185do_nop (void)
5186{
5187 if (inst.operands[0].present)
5188 {
5189 /* Architectural NOP hints are CPSR sets with no bits selected. */
5190 inst.instruction &= 0xf0000000;
5191 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
5192 }
b99bd4ef
NC
5193}
5194
c19d1205
ZW
5195/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
5196 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
5197 Condition defaults to COND_ALWAYS.
5198 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
5199
5200static void
c19d1205 5201do_pkhbt (void)
b99bd4ef 5202{
c19d1205
ZW
5203 inst.instruction |= inst.operands[0].reg << 12;
5204 inst.instruction |= inst.operands[1].reg << 16;
5205 inst.instruction |= inst.operands[2].reg;
5206 if (inst.operands[3].present)
5207 encode_arm_shift (3);
5208}
b99bd4ef 5209
c19d1205 5210/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 5211
c19d1205
ZW
5212static void
5213do_pkhtb (void)
5214{
5215 if (!inst.operands[3].present)
b99bd4ef 5216 {
c19d1205
ZW
5217 /* If the shift specifier is omitted, turn the instruction
5218 into pkhbt rd, rm, rn. */
5219 inst.instruction &= 0xfff00010;
5220 inst.instruction |= inst.operands[0].reg << 12;
5221 inst.instruction |= inst.operands[1].reg;
5222 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5223 }
5224 else
5225 {
c19d1205
ZW
5226 inst.instruction |= inst.operands[0].reg << 12;
5227 inst.instruction |= inst.operands[1].reg << 16;
5228 inst.instruction |= inst.operands[2].reg;
5229 encode_arm_shift (3);
b99bd4ef
NC
5230 }
5231}
5232
c19d1205
ZW
5233/* ARMv5TE: Preload-Cache
5234
5235 PLD <addr_mode>
5236
5237 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
5238
5239static void
c19d1205 5240do_pld (void)
b99bd4ef 5241{
c19d1205
ZW
5242 constraint (!inst.operands[0].isreg,
5243 _("'[' expected after PLD mnemonic"));
5244 constraint (inst.operands[0].postind,
5245 _("post-indexed expression used in preload instruction"));
5246 constraint (inst.operands[0].writeback,
5247 _("writeback used in preload instruction"));
5248 constraint (!inst.operands[0].preind,
5249 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
5250 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5251}
b99bd4ef 5252
62b3e311
PB
5253/* ARMv7: PLI <addr_mode> */
5254static void
5255do_pli (void)
5256{
5257 constraint (!inst.operands[0].isreg,
5258 _("'[' expected after PLI mnemonic"));
5259 constraint (inst.operands[0].postind,
5260 _("post-indexed expression used in preload instruction"));
5261 constraint (inst.operands[0].writeback,
5262 _("writeback used in preload instruction"));
5263 constraint (!inst.operands[0].preind,
5264 _("unindexed addressing used in preload instruction"));
5265 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5266 inst.instruction &= ~PRE_INDEX;
5267}
5268
c19d1205
ZW
5269static void
5270do_push_pop (void)
5271{
5272 inst.operands[1] = inst.operands[0];
5273 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
5274 inst.operands[0].isreg = 1;
5275 inst.operands[0].writeback = 1;
5276 inst.operands[0].reg = REG_SP;
5277 do_ldmstm ();
5278}
b99bd4ef 5279
c19d1205
ZW
5280/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
5281 word at the specified address and the following word
5282 respectively.
5283 Unconditionally executed.
5284 Error if Rn is R15. */
b99bd4ef 5285
c19d1205
ZW
5286static void
5287do_rfe (void)
5288{
5289 inst.instruction |= inst.operands[0].reg << 16;
5290 if (inst.operands[0].writeback)
5291 inst.instruction |= WRITE_BACK;
5292}
b99bd4ef 5293
c19d1205 5294/* ARM V6 ssat (argument parse). */
b99bd4ef 5295
c19d1205
ZW
5296static void
5297do_ssat (void)
5298{
5299 inst.instruction |= inst.operands[0].reg << 12;
5300 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5301 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5302
c19d1205
ZW
5303 if (inst.operands[3].present)
5304 encode_arm_shift (3);
b99bd4ef
NC
5305}
5306
c19d1205 5307/* ARM V6 usat (argument parse). */
b99bd4ef
NC
5308
5309static void
c19d1205 5310do_usat (void)
b99bd4ef 5311{
c19d1205
ZW
5312 inst.instruction |= inst.operands[0].reg << 12;
5313 inst.instruction |= inst.operands[1].imm << 16;
5314 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5315
c19d1205
ZW
5316 if (inst.operands[3].present)
5317 encode_arm_shift (3);
b99bd4ef
NC
5318}
5319
c19d1205 5320/* ARM V6 ssat16 (argument parse). */
09d92015
MM
5321
5322static void
c19d1205 5323do_ssat16 (void)
09d92015 5324{
c19d1205
ZW
5325 inst.instruction |= inst.operands[0].reg << 12;
5326 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5327 inst.instruction |= inst.operands[2].reg;
09d92015
MM
5328}
5329
c19d1205
ZW
5330static void
5331do_usat16 (void)
a737bd4d 5332{
c19d1205
ZW
5333 inst.instruction |= inst.operands[0].reg << 12;
5334 inst.instruction |= inst.operands[1].imm << 16;
5335 inst.instruction |= inst.operands[2].reg;
5336}
a737bd4d 5337
c19d1205
ZW
5338/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5339 preserving the other bits.
a737bd4d 5340
c19d1205
ZW
5341 setend <endian_specifier>, where <endian_specifier> is either
5342 BE or LE. */
a737bd4d 5343
c19d1205
ZW
5344static void
5345do_setend (void)
5346{
5347 if (inst.operands[0].imm)
5348 inst.instruction |= 0x200;
a737bd4d
NC
5349}
5350
5351static void
c19d1205 5352do_shift (void)
a737bd4d 5353{
c19d1205
ZW
5354 unsigned int Rm = (inst.operands[1].present
5355 ? inst.operands[1].reg
5356 : inst.operands[0].reg);
a737bd4d 5357
c19d1205
ZW
5358 inst.instruction |= inst.operands[0].reg << 12;
5359 inst.instruction |= Rm;
5360 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5361 {
c19d1205
ZW
5362 inst.instruction |= inst.operands[2].reg << 8;
5363 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5364 }
5365 else
c19d1205 5366 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5367}
5368
09d92015 5369static void
3eb17e6b 5370do_smc (void)
09d92015 5371{
3eb17e6b 5372 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 5373 inst.reloc.pc_rel = 0;
09d92015
MM
5374}
5375
09d92015 5376static void
c19d1205 5377do_swi (void)
09d92015 5378{
c19d1205
ZW
5379 inst.reloc.type = BFD_RELOC_ARM_SWI;
5380 inst.reloc.pc_rel = 0;
09d92015
MM
5381}
5382
c19d1205
ZW
5383/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5384 SMLAxy{cond} Rd,Rm,Rs,Rn
5385 SMLAWy{cond} Rd,Rm,Rs,Rn
5386 Error if any register is R15. */
e16bb312 5387
c19d1205
ZW
5388static void
5389do_smla (void)
e16bb312 5390{
c19d1205
ZW
5391 inst.instruction |= inst.operands[0].reg << 16;
5392 inst.instruction |= inst.operands[1].reg;
5393 inst.instruction |= inst.operands[2].reg << 8;
5394 inst.instruction |= inst.operands[3].reg << 12;
5395}
a737bd4d 5396
c19d1205
ZW
5397/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5398 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5399 Error if any register is R15.
5400 Warning if Rdlo == Rdhi. */
a737bd4d 5401
c19d1205
ZW
5402static void
5403do_smlal (void)
5404{
5405 inst.instruction |= inst.operands[0].reg << 12;
5406 inst.instruction |= inst.operands[1].reg << 16;
5407 inst.instruction |= inst.operands[2].reg;
5408 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5409
c19d1205
ZW
5410 if (inst.operands[0].reg == inst.operands[1].reg)
5411 as_tsktsk (_("rdhi and rdlo must be different"));
5412}
a737bd4d 5413
c19d1205
ZW
5414/* ARM V5E (El Segundo) signed-multiply (argument parse)
5415 SMULxy{cond} Rd,Rm,Rs
5416 Error if any register is R15. */
a737bd4d 5417
c19d1205
ZW
5418static void
5419do_smul (void)
5420{
5421 inst.instruction |= inst.operands[0].reg << 16;
5422 inst.instruction |= inst.operands[1].reg;
5423 inst.instruction |= inst.operands[2].reg << 8;
5424}
a737bd4d 5425
c19d1205 5426/* ARM V6 srs (argument parse). */
a737bd4d 5427
c19d1205
ZW
5428static void
5429do_srs (void)
5430{
5431 inst.instruction |= inst.operands[0].imm;
5432 if (inst.operands[0].writeback)
5433 inst.instruction |= WRITE_BACK;
5434}
a737bd4d 5435
c19d1205 5436/* ARM V6 strex (argument parse). */
a737bd4d 5437
c19d1205
ZW
5438static void
5439do_strex (void)
5440{
5441 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5442 || inst.operands[2].postind || inst.operands[2].writeback
5443 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
5444 || inst.operands[2].negative
5445 /* See comment in do_ldrex(). */
5446 || (inst.operands[2].reg == REG_PC),
5447 BAD_ADDR_MODE);
a737bd4d 5448
c19d1205
ZW
5449 constraint (inst.operands[0].reg == inst.operands[1].reg
5450 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5451
c19d1205
ZW
5452 constraint (inst.reloc.exp.X_op != O_constant
5453 || inst.reloc.exp.X_add_number != 0,
5454 _("offset must be zero in ARM encoding"));
a737bd4d 5455
c19d1205
ZW
5456 inst.instruction |= inst.operands[0].reg << 12;
5457 inst.instruction |= inst.operands[1].reg;
5458 inst.instruction |= inst.operands[2].reg << 16;
5459 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5460}
5461
5462static void
c19d1205 5463do_strexd (void)
e16bb312 5464{
c19d1205
ZW
5465 constraint (inst.operands[1].reg % 2 != 0,
5466 _("even register required"));
5467 constraint (inst.operands[2].present
5468 && inst.operands[2].reg != inst.operands[1].reg + 1,
5469 _("can only store two consecutive registers"));
5470 /* If op 2 were present and equal to PC, this function wouldn't
5471 have been called in the first place. */
5472 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5473
c19d1205
ZW
5474 constraint (inst.operands[0].reg == inst.operands[1].reg
5475 || inst.operands[0].reg == inst.operands[1].reg + 1
5476 || inst.operands[0].reg == inst.operands[3].reg,
5477 BAD_OVERLAP);
e16bb312 5478
c19d1205
ZW
5479 inst.instruction |= inst.operands[0].reg << 12;
5480 inst.instruction |= inst.operands[1].reg;
5481 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5482}
5483
c19d1205
ZW
5484/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5485 extends it to 32-bits, and adds the result to a value in another
5486 register. You can specify a rotation by 0, 8, 16, or 24 bits
5487 before extracting the 16-bit value.
5488 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5489 Condition defaults to COND_ALWAYS.
5490 Error if any register uses R15. */
5491
e16bb312 5492static void
c19d1205 5493do_sxtah (void)
e16bb312 5494{
c19d1205
ZW
5495 inst.instruction |= inst.operands[0].reg << 12;
5496 inst.instruction |= inst.operands[1].reg << 16;
5497 inst.instruction |= inst.operands[2].reg;
5498 inst.instruction |= inst.operands[3].imm << 10;
5499}
e16bb312 5500
c19d1205 5501/* ARM V6 SXTH.
e16bb312 5502
c19d1205
ZW
5503 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5504 Condition defaults to COND_ALWAYS.
5505 Error if any register uses R15. */
e16bb312
NC
5506
5507static void
c19d1205 5508do_sxth (void)
e16bb312 5509{
c19d1205
ZW
5510 inst.instruction |= inst.operands[0].reg << 12;
5511 inst.instruction |= inst.operands[1].reg;
5512 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5513}
c19d1205
ZW
5514\f
5515/* VFP instructions. In a logical order: SP variant first, monad
5516 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5517
5518static void
c19d1205 5519do_vfp_sp_monadic (void)
e16bb312 5520{
c19d1205
ZW
5521 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5522 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5523}
5524
5525static void
c19d1205 5526do_vfp_sp_dyadic (void)
e16bb312 5527{
c19d1205
ZW
5528 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5529 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5530 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5531}
5532
5533static void
c19d1205 5534do_vfp_sp_compare_z (void)
e16bb312 5535{
c19d1205 5536 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5537}
5538
5539static void
c19d1205 5540do_vfp_dp_sp_cvt (void)
e16bb312 5541{
c19d1205
ZW
5542 inst.instruction |= inst.operands[0].reg << 12;
5543 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5544}
5545
5546static void
c19d1205 5547do_vfp_sp_dp_cvt (void)
e16bb312 5548{
c19d1205
ZW
5549 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5550 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5551}
5552
5553static void
c19d1205 5554do_vfp_reg_from_sp (void)
e16bb312 5555{
c19d1205
ZW
5556 inst.instruction |= inst.operands[0].reg << 12;
5557 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5558}
5559
5560static void
c19d1205 5561do_vfp_reg2_from_sp2 (void)
e16bb312 5562{
c19d1205
ZW
5563 constraint (inst.operands[2].imm != 2,
5564 _("only two consecutive VFP SP registers allowed here"));
5565 inst.instruction |= inst.operands[0].reg << 12;
5566 inst.instruction |= inst.operands[1].reg << 16;
5567 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5568}
5569
5570static void
c19d1205 5571do_vfp_sp_from_reg (void)
e16bb312 5572{
c19d1205
ZW
5573 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5574 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5575}
5576
5577static void
c19d1205 5578do_vfp_sp2_from_reg2 (void)
e16bb312 5579{
c19d1205
ZW
5580 constraint (inst.operands[0].imm != 2,
5581 _("only two consecutive VFP SP registers allowed here"));
5582 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5583 inst.instruction |= inst.operands[1].reg << 12;
5584 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5585}
5586
5587static void
c19d1205 5588do_vfp_sp_ldst (void)
e16bb312 5589{
c19d1205
ZW
5590 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5591 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5592}
5593
5594static void
c19d1205 5595do_vfp_dp_ldst (void)
e16bb312 5596{
c19d1205
ZW
5597 inst.instruction |= inst.operands[0].reg << 12;
5598 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5599}
5600
c19d1205 5601
e16bb312 5602static void
c19d1205 5603vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5604{
c19d1205
ZW
5605 if (inst.operands[0].writeback)
5606 inst.instruction |= WRITE_BACK;
5607 else
5608 constraint (ldstm_type != VFP_LDSTMIA,
5609 _("this addressing mode requires base-register writeback"));
5610 inst.instruction |= inst.operands[0].reg << 16;
5611 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5612 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5613}
5614
5615static void
c19d1205 5616vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5617{
c19d1205 5618 int count;
e16bb312 5619
c19d1205
ZW
5620 if (inst.operands[0].writeback)
5621 inst.instruction |= WRITE_BACK;
5622 else
5623 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5624 _("this addressing mode requires base-register writeback"));
e16bb312 5625
c19d1205
ZW
5626 inst.instruction |= inst.operands[0].reg << 16;
5627 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5628
c19d1205
ZW
5629 count = inst.operands[1].imm << 1;
5630 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5631 count += 1;
e16bb312 5632
c19d1205 5633 inst.instruction |= count;
e16bb312
NC
5634}
5635
5636static void
c19d1205 5637do_vfp_sp_ldstmia (void)
e16bb312 5638{
c19d1205 5639 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5640}
5641
5642static void
c19d1205 5643do_vfp_sp_ldstmdb (void)
e16bb312 5644{
c19d1205 5645 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5646}
5647
5648static void
c19d1205 5649do_vfp_dp_ldstmia (void)
e16bb312 5650{
c19d1205 5651 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5652}
5653
5654static void
c19d1205 5655do_vfp_dp_ldstmdb (void)
e16bb312 5656{
c19d1205 5657 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5658}
5659
5660static void
c19d1205 5661do_vfp_xp_ldstmia (void)
e16bb312 5662{
c19d1205
ZW
5663 vfp_dp_ldstm (VFP_LDSTMIAX);
5664}
e16bb312 5665
c19d1205
ZW
5666static void
5667do_vfp_xp_ldstmdb (void)
5668{
5669 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5670}
c19d1205
ZW
5671\f
5672/* FPA instructions. Also in a logical order. */
e16bb312 5673
c19d1205
ZW
5674static void
5675do_fpa_cmp (void)
5676{
5677 inst.instruction |= inst.operands[0].reg << 16;
5678 inst.instruction |= inst.operands[1].reg;
5679}
b99bd4ef
NC
5680
5681static void
c19d1205 5682do_fpa_ldmstm (void)
b99bd4ef 5683{
c19d1205
ZW
5684 inst.instruction |= inst.operands[0].reg << 12;
5685 switch (inst.operands[1].imm)
5686 {
5687 case 1: inst.instruction |= CP_T_X; break;
5688 case 2: inst.instruction |= CP_T_Y; break;
5689 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5690 case 4: break;
5691 default: abort ();
5692 }
b99bd4ef 5693
c19d1205
ZW
5694 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5695 {
5696 /* The instruction specified "ea" or "fd", so we can only accept
5697 [Rn]{!}. The instruction does not really support stacking or
5698 unstacking, so we have to emulate these by setting appropriate
5699 bits and offsets. */
5700 constraint (inst.reloc.exp.X_op != O_constant
5701 || inst.reloc.exp.X_add_number != 0,
5702 _("this instruction does not support indexing"));
b99bd4ef 5703
c19d1205
ZW
5704 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5705 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5706
c19d1205
ZW
5707 if (!(inst.instruction & INDEX_UP))
5708 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5709
c19d1205
ZW
5710 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5711 {
5712 inst.operands[2].preind = 0;
5713 inst.operands[2].postind = 1;
5714 }
5715 }
b99bd4ef 5716
c19d1205 5717 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5718}
c19d1205
ZW
5719\f
5720/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5721
c19d1205
ZW
5722static void
5723do_iwmmxt_tandorc (void)
5724{
5725 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5726}
b99bd4ef 5727
c19d1205
ZW
5728static void
5729do_iwmmxt_textrc (void)
5730{
5731 inst.instruction |= inst.operands[0].reg << 12;
5732 inst.instruction |= inst.operands[1].imm;
5733}
b99bd4ef
NC
5734
5735static void
c19d1205 5736do_iwmmxt_textrm (void)
b99bd4ef 5737{
c19d1205
ZW
5738 inst.instruction |= inst.operands[0].reg << 12;
5739 inst.instruction |= inst.operands[1].reg << 16;
5740 inst.instruction |= inst.operands[2].imm;
5741}
b99bd4ef 5742
c19d1205
ZW
5743static void
5744do_iwmmxt_tinsr (void)
5745{
5746 inst.instruction |= inst.operands[0].reg << 16;
5747 inst.instruction |= inst.operands[1].reg << 12;
5748 inst.instruction |= inst.operands[2].imm;
5749}
b99bd4ef 5750
c19d1205
ZW
5751static void
5752do_iwmmxt_tmia (void)
5753{
5754 inst.instruction |= inst.operands[0].reg << 5;
5755 inst.instruction |= inst.operands[1].reg;
5756 inst.instruction |= inst.operands[2].reg << 12;
5757}
b99bd4ef 5758
c19d1205
ZW
5759static void
5760do_iwmmxt_waligni (void)
5761{
5762 inst.instruction |= inst.operands[0].reg << 12;
5763 inst.instruction |= inst.operands[1].reg << 16;
5764 inst.instruction |= inst.operands[2].reg;
5765 inst.instruction |= inst.operands[3].imm << 20;
5766}
b99bd4ef 5767
c19d1205
ZW
5768static void
5769do_iwmmxt_wmov (void)
5770{
5771 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5772 inst.instruction |= inst.operands[0].reg << 12;
5773 inst.instruction |= inst.operands[1].reg << 16;
5774 inst.instruction |= inst.operands[1].reg;
5775}
b99bd4ef 5776
c19d1205
ZW
5777static void
5778do_iwmmxt_wldstbh (void)
5779{
8f06b2d8 5780 int reloc;
c19d1205
ZW
5781 inst.instruction |= inst.operands[0].reg << 12;
5782 inst.reloc.exp.X_add_number *= 4;
8f06b2d8
PB
5783 if (thumb_mode)
5784 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
5785 else
5786 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
5787 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
5788}
5789
c19d1205
ZW
5790static void
5791do_iwmmxt_wldstw (void)
5792{
5793 /* RIWR_RIWC clears .isreg for a control register. */
5794 if (!inst.operands[0].isreg)
5795 {
5796 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5797 inst.instruction |= 0xf0000000;
5798 }
b99bd4ef 5799
c19d1205
ZW
5800 inst.instruction |= inst.operands[0].reg << 12;
5801 encode_arm_cp_address (1, TRUE, TRUE, 0);
5802}
b99bd4ef
NC
5803
5804static void
c19d1205 5805do_iwmmxt_wldstd (void)
b99bd4ef 5806{
c19d1205 5807 inst.instruction |= inst.operands[0].reg << 12;
f2184508 5808 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 5809}
b99bd4ef 5810
c19d1205
ZW
5811static void
5812do_iwmmxt_wshufh (void)
5813{
5814 inst.instruction |= inst.operands[0].reg << 12;
5815 inst.instruction |= inst.operands[1].reg << 16;
5816 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5817 inst.instruction |= (inst.operands[2].imm & 0x0f);
5818}
b99bd4ef 5819
c19d1205
ZW
5820static void
5821do_iwmmxt_wzero (void)
5822{
5823 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5824 inst.instruction |= inst.operands[0].reg;
5825 inst.instruction |= inst.operands[0].reg << 12;
5826 inst.instruction |= inst.operands[0].reg << 16;
5827}
5828\f
5829/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5830 operations first, then control, shift, and load/store. */
b99bd4ef 5831
c19d1205 5832/* Insns like "foo X,Y,Z". */
b99bd4ef 5833
c19d1205
ZW
5834static void
5835do_mav_triple (void)
5836{
5837 inst.instruction |= inst.operands[0].reg << 16;
5838 inst.instruction |= inst.operands[1].reg;
5839 inst.instruction |= inst.operands[2].reg << 12;
5840}
b99bd4ef 5841
c19d1205
ZW
5842/* Insns like "foo W,X,Y,Z".
5843 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5844
c19d1205
ZW
5845static void
5846do_mav_quad (void)
5847{
5848 inst.instruction |= inst.operands[0].reg << 5;
5849 inst.instruction |= inst.operands[1].reg << 12;
5850 inst.instruction |= inst.operands[2].reg << 16;
5851 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5852}
5853
c19d1205
ZW
5854/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5855static void
5856do_mav_dspsc (void)
a737bd4d 5857{
c19d1205
ZW
5858 inst.instruction |= inst.operands[1].reg << 12;
5859}
a737bd4d 5860
c19d1205
ZW
5861/* Maverick shift immediate instructions.
5862 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5863 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5864
c19d1205
ZW
5865static void
5866do_mav_shift (void)
5867{
5868 int imm = inst.operands[2].imm;
a737bd4d 5869
c19d1205
ZW
5870 inst.instruction |= inst.operands[0].reg << 12;
5871 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5872
c19d1205
ZW
5873 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5874 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5875 Bit 4 should be 0. */
5876 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5877
c19d1205
ZW
5878 inst.instruction |= imm;
5879}
5880\f
5881/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5882
c19d1205
ZW
5883/* Xscale multiply-accumulate (argument parse)
5884 MIAcc acc0,Rm,Rs
5885 MIAPHcc acc0,Rm,Rs
5886 MIAxycc acc0,Rm,Rs. */
a737bd4d 5887
c19d1205
ZW
5888static void
5889do_xsc_mia (void)
5890{
5891 inst.instruction |= inst.operands[1].reg;
5892 inst.instruction |= inst.operands[2].reg << 12;
5893}
a737bd4d 5894
c19d1205 5895/* Xscale move-accumulator-register (argument parse)
a737bd4d 5896
c19d1205 5897 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5898
c19d1205
ZW
5899static void
5900do_xsc_mar (void)
5901{
5902 inst.instruction |= inst.operands[1].reg << 12;
5903 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5904}
5905
c19d1205 5906/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5907
c19d1205 5908 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5909
5910static void
c19d1205 5911do_xsc_mra (void)
b99bd4ef 5912{
c19d1205
ZW
5913 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5914 inst.instruction |= inst.operands[0].reg << 12;
5915 inst.instruction |= inst.operands[1].reg << 16;
5916}
5917\f
5918/* Encoding functions relevant only to Thumb. */
b99bd4ef 5919
c19d1205
ZW
5920/* inst.operands[i] is a shifted-register operand; encode
5921 it into inst.instruction in the format used by Thumb32. */
5922
5923static void
5924encode_thumb32_shifted_operand (int i)
5925{
5926 unsigned int value = inst.reloc.exp.X_add_number;
5927 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5928
9c3c69f2
PB
5929 constraint (inst.operands[i].immisreg,
5930 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
5931 inst.instruction |= inst.operands[i].reg;
5932 if (shift == SHIFT_RRX)
5933 inst.instruction |= SHIFT_ROR << 4;
5934 else
b99bd4ef 5935 {
c19d1205
ZW
5936 constraint (inst.reloc.exp.X_op != O_constant,
5937 _("expression too complex"));
5938
5939 constraint (value > 32
5940 || (value == 32 && (shift == SHIFT_LSL
5941 || shift == SHIFT_ROR)),
5942 _("shift expression is too large"));
5943
5944 if (value == 0)
5945 shift = SHIFT_LSL;
5946 else if (value == 32)
5947 value = 0;
5948
5949 inst.instruction |= shift << 4;
5950 inst.instruction |= (value & 0x1c) << 10;
5951 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5952 }
c19d1205 5953}
b99bd4ef 5954
b99bd4ef 5955
c19d1205
ZW
5956/* inst.operands[i] was set up by parse_address. Encode it into a
5957 Thumb32 format load or store instruction. Reject forms that cannot
5958 be used with such instructions. If is_t is true, reject forms that
5959 cannot be used with a T instruction; if is_d is true, reject forms
5960 that cannot be used with a D instruction. */
b99bd4ef 5961
c19d1205
ZW
5962static void
5963encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5964{
5965 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5966
5967 constraint (!inst.operands[i].isreg,
5968 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5969
c19d1205
ZW
5970 inst.instruction |= inst.operands[i].reg << 16;
5971 if (inst.operands[i].immisreg)
b99bd4ef 5972 {
c19d1205
ZW
5973 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5974 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5975 constraint (inst.operands[i].negative,
5976 _("Thumb does not support negative register indexing"));
5977 constraint (inst.operands[i].postind,
5978 _("Thumb does not support register post-indexing"));
5979 constraint (inst.operands[i].writeback,
5980 _("Thumb does not support register indexing with writeback"));
5981 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5982 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5983
f40d1643 5984 inst.instruction |= inst.operands[i].imm;
c19d1205 5985 if (inst.operands[i].shifted)
b99bd4ef 5986 {
c19d1205
ZW
5987 constraint (inst.reloc.exp.X_op != O_constant,
5988 _("expression too complex"));
9c3c69f2
PB
5989 constraint (inst.reloc.exp.X_add_number < 0
5990 || inst.reloc.exp.X_add_number > 3,
c19d1205 5991 _("shift out of range"));
9c3c69f2 5992 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
5993 }
5994 inst.reloc.type = BFD_RELOC_UNUSED;
5995 }
5996 else if (inst.operands[i].preind)
5997 {
5998 constraint (is_pc && inst.operands[i].writeback,
5999 _("cannot use writeback with PC-relative addressing"));
f40d1643 6000 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
6001 _("cannot use writeback with this instruction"));
6002
6003 if (is_d)
6004 {
6005 inst.instruction |= 0x01000000;
6006 if (inst.operands[i].writeback)
6007 inst.instruction |= 0x00200000;
b99bd4ef 6008 }
c19d1205 6009 else
b99bd4ef 6010 {
c19d1205
ZW
6011 inst.instruction |= 0x00000c00;
6012 if (inst.operands[i].writeback)
6013 inst.instruction |= 0x00000100;
b99bd4ef 6014 }
c19d1205 6015 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 6016 }
c19d1205 6017 else if (inst.operands[i].postind)
b99bd4ef 6018 {
c19d1205
ZW
6019 assert (inst.operands[i].writeback);
6020 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
6021 constraint (is_t, _("cannot use post-indexing with this instruction"));
6022
6023 if (is_d)
6024 inst.instruction |= 0x00200000;
6025 else
6026 inst.instruction |= 0x00000900;
6027 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
6028 }
6029 else /* unindexed - only for coprocessor */
6030 inst.error = _("instruction does not accept unindexed addressing");
6031}
6032
6033/* Table of Thumb instructions which exist in both 16- and 32-bit
6034 encodings (the latter only in post-V6T2 cores). The index is the
6035 value used in the insns table below. When there is more than one
6036 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
6037 holds variant (1).
6038 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
6039#define T16_32_TAB \
6040 X(adc, 4140, eb400000), \
6041 X(adcs, 4140, eb500000), \
6042 X(add, 1c00, eb000000), \
6043 X(adds, 1c00, eb100000), \
0110f2b8
PB
6044 X(addi, 0000, f1000000), \
6045 X(addis, 0000, f1100000), \
6046 X(add_pc,000f, f20f0000), \
6047 X(add_sp,000d, f10d0000), \
e9f89963 6048 X(adr, 000f, f20f0000), \
c19d1205
ZW
6049 X(and, 4000, ea000000), \
6050 X(ands, 4000, ea100000), \
6051 X(asr, 1000, fa40f000), \
6052 X(asrs, 1000, fa50f000), \
0110f2b8
PB
6053 X(b, e000, f000b000), \
6054 X(bcond, d000, f0008000), \
c19d1205
ZW
6055 X(bic, 4380, ea200000), \
6056 X(bics, 4380, ea300000), \
6057 X(cmn, 42c0, eb100f00), \
6058 X(cmp, 2800, ebb00f00), \
6059 X(cpsie, b660, f3af8400), \
6060 X(cpsid, b670, f3af8600), \
6061 X(cpy, 4600, ea4f0000), \
0110f2b8 6062 X(dec_sp,80dd, f1bd0d00), \
c19d1205
ZW
6063 X(eor, 4040, ea800000), \
6064 X(eors, 4040, ea900000), \
0110f2b8 6065 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
6066 X(ldmia, c800, e8900000), \
6067 X(ldr, 6800, f8500000), \
6068 X(ldrb, 7800, f8100000), \
6069 X(ldrh, 8800, f8300000), \
6070 X(ldrsb, 5600, f9100000), \
6071 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
6072 X(ldr_pc,4800, f85f0000), \
6073 X(ldr_pc2,4800, f85f0000), \
6074 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
6075 X(lsl, 0000, fa00f000), \
6076 X(lsls, 0000, fa10f000), \
6077 X(lsr, 0800, fa20f000), \
6078 X(lsrs, 0800, fa30f000), \
6079 X(mov, 2000, ea4f0000), \
6080 X(movs, 2000, ea5f0000), \
6081 X(mul, 4340, fb00f000), \
6082 X(muls, 4340, ffffffff), /* no 32b muls */ \
6083 X(mvn, 43c0, ea6f0000), \
6084 X(mvns, 43c0, ea7f0000), \
6085 X(neg, 4240, f1c00000), /* rsb #0 */ \
6086 X(negs, 4240, f1d00000), /* rsbs #0 */ \
6087 X(orr, 4300, ea400000), \
6088 X(orrs, 4300, ea500000), \
e9f89963
PB
6089 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
6090 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
6091 X(rev, ba00, fa90f080), \
6092 X(rev16, ba40, fa90f090), \
6093 X(revsh, bac0, fa90f0b0), \
6094 X(ror, 41c0, fa60f000), \
6095 X(rors, 41c0, fa70f000), \
6096 X(sbc, 4180, eb600000), \
6097 X(sbcs, 4180, eb700000), \
6098 X(stmia, c000, e8800000), \
6099 X(str, 6000, f8400000), \
6100 X(strb, 7000, f8000000), \
6101 X(strh, 8000, f8200000), \
0110f2b8 6102 X(str_sp,9000, f84d0000), \
c19d1205
ZW
6103 X(sub, 1e00, eba00000), \
6104 X(subs, 1e00, ebb00000), \
0110f2b8
PB
6105 X(subi, 8000, f1a00000), \
6106 X(subis, 8000, f1b00000), \
c19d1205
ZW
6107 X(sxtb, b240, fa4ff080), \
6108 X(sxth, b200, fa0ff080), \
6109 X(tst, 4200, ea100f00), \
6110 X(uxtb, b2c0, fa5ff080), \
6111 X(uxth, b280, fa1ff080), \
6112 X(nop, bf00, f3af8000), \
6113 X(yield, bf10, f3af8001), \
6114 X(wfe, bf20, f3af8002), \
6115 X(wfi, bf30, f3af8003), \
6116 X(sev, bf40, f3af9004), /* typo, 8004? */
6117
6118/* To catch errors in encoding functions, the codes are all offset by
6119 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
6120 as 16-bit instructions. */
6121#define X(a,b,c) T_MNEM_##a
6122enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
6123#undef X
6124
6125#define X(a,b,c) 0x##b
6126static const unsigned short thumb_op16[] = { T16_32_TAB };
6127#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
6128#undef X
6129
6130#define X(a,b,c) 0x##c
6131static const unsigned int thumb_op32[] = { T16_32_TAB };
6132#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
6133#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
6134#undef X
6135#undef T16_32_TAB
6136
6137/* Thumb instruction encoders, in alphabetical order. */
6138
92e90b6e
PB
6139/* ADDW or SUBW. */
6140static void
6141do_t_add_sub_w (void)
6142{
6143 int Rd, Rn;
6144
6145 Rd = inst.operands[0].reg;
6146 Rn = inst.operands[1].reg;
6147
6148 constraint (Rd == 15, _("PC not allowed as destination"));
6149 inst.instruction |= (Rn << 16) | (Rd << 8);
6150 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
6151}
6152
c19d1205
ZW
6153/* Parse an add or subtract instruction. We get here with inst.instruction
6154 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
6155
6156static void
6157do_t_add_sub (void)
6158{
6159 int Rd, Rs, Rn;
6160
6161 Rd = inst.operands[0].reg;
6162 Rs = (inst.operands[1].present
6163 ? inst.operands[1].reg /* Rd, Rs, foo */
6164 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6165
6166 if (unified_syntax)
6167 {
0110f2b8
PB
6168 bfd_boolean flags;
6169 bfd_boolean narrow;
6170 int opcode;
6171
6172 flags = (inst.instruction == T_MNEM_adds
6173 || inst.instruction == T_MNEM_subs);
6174 if (flags)
6175 narrow = (current_it_mask == 0);
6176 else
6177 narrow = (current_it_mask != 0);
c19d1205 6178 if (!inst.operands[2].isreg)
b99bd4ef 6179 {
0110f2b8
PB
6180 opcode = 0;
6181 if (inst.size_req != 4)
6182 {
6183 int add;
6184
6185 add = (inst.instruction == T_MNEM_add
6186 || inst.instruction == T_MNEM_adds);
6187 /* Attempt to use a narrow opcode, with relaxation if
6188 appropriate. */
6189 if (Rd == REG_SP && Rs == REG_SP && !flags)
6190 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
6191 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
6192 opcode = T_MNEM_add_sp;
6193 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
6194 opcode = T_MNEM_add_pc;
6195 else if (Rd <= 7 && Rs <= 7 && narrow)
6196 {
6197 if (flags)
6198 opcode = add ? T_MNEM_addis : T_MNEM_subis;
6199 else
6200 opcode = add ? T_MNEM_addi : T_MNEM_subi;
6201 }
6202 if (opcode)
6203 {
6204 inst.instruction = THUMB_OP16(opcode);
6205 inst.instruction |= (Rd << 4) | Rs;
6206 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6207 if (inst.size_req != 2)
6208 inst.relax = opcode;
6209 }
6210 else
6211 constraint (inst.size_req == 2, BAD_HIREG);
6212 }
6213 if (inst.size_req == 4
6214 || (inst.size_req != 2 && !opcode))
6215 {
6216 /* ??? Convert large immediates to addw/subw. */
6217 inst.instruction = THUMB_OP32 (inst.instruction);
6218 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6219 inst.instruction |= inst.operands[0].reg << 8;
6220 inst.instruction |= inst.operands[1].reg << 16;
6221 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6222 }
b99bd4ef 6223 }
c19d1205
ZW
6224 else
6225 {
6226 Rn = inst.operands[2].reg;
6227 /* See if we can do this with a 16-bit instruction. */
6228 if (!inst.operands[2].shifted && inst.size_req != 4)
6229 {
e27ec89e
PB
6230 if (Rd > 7 || Rs > 7 || Rn > 7)
6231 narrow = FALSE;
6232
6233 if (narrow)
c19d1205 6234 {
e27ec89e
PB
6235 inst.instruction = ((inst.instruction == T_MNEM_adds
6236 || inst.instruction == T_MNEM_add)
c19d1205
ZW
6237 ? T_OPCODE_ADD_R3
6238 : T_OPCODE_SUB_R3);
6239 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6240 return;
6241 }
b99bd4ef 6242
c19d1205
ZW
6243 if (inst.instruction == T_MNEM_add)
6244 {
6245 if (Rd == Rs)
6246 {
6247 inst.instruction = T_OPCODE_ADD_HI;
6248 inst.instruction |= (Rd & 8) << 4;
6249 inst.instruction |= (Rd & 7);
6250 inst.instruction |= Rn << 3;
6251 return;
6252 }
6253 /* ... because addition is commutative! */
6254 else if (Rd == Rn)
6255 {
6256 inst.instruction = T_OPCODE_ADD_HI;
6257 inst.instruction |= (Rd & 8) << 4;
6258 inst.instruction |= (Rd & 7);
6259 inst.instruction |= Rs << 3;
6260 return;
6261 }
6262 }
6263 }
6264 /* If we get here, it can't be done in 16 bits. */
6265 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
6266 _("shift must be constant"));
6267 inst.instruction = THUMB_OP32 (inst.instruction);
6268 inst.instruction |= Rd << 8;
6269 inst.instruction |= Rs << 16;
6270 encode_thumb32_shifted_operand (2);
6271 }
6272 }
6273 else
6274 {
6275 constraint (inst.instruction == T_MNEM_adds
6276 || inst.instruction == T_MNEM_subs,
6277 BAD_THUMB32);
b99bd4ef 6278
c19d1205 6279 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 6280 {
c19d1205
ZW
6281 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
6282 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
6283 BAD_HIREG);
6284
6285 inst.instruction = (inst.instruction == T_MNEM_add
6286 ? 0x0000 : 0x8000);
6287 inst.instruction |= (Rd << 4) | Rs;
6288 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
6289 return;
6290 }
6291
c19d1205
ZW
6292 Rn = inst.operands[2].reg;
6293 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 6294
c19d1205
ZW
6295 /* We now have Rd, Rs, and Rn set to registers. */
6296 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 6297 {
c19d1205
ZW
6298 /* Can't do this for SUB. */
6299 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
6300 inst.instruction = T_OPCODE_ADD_HI;
6301 inst.instruction |= (Rd & 8) << 4;
6302 inst.instruction |= (Rd & 7);
6303 if (Rs == Rd)
6304 inst.instruction |= Rn << 3;
6305 else if (Rn == Rd)
6306 inst.instruction |= Rs << 3;
6307 else
6308 constraint (1, _("dest must overlap one source register"));
6309 }
6310 else
6311 {
6312 inst.instruction = (inst.instruction == T_MNEM_add
6313 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
6314 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 6315 }
b99bd4ef 6316 }
b99bd4ef
NC
6317}
6318
c19d1205
ZW
6319static void
6320do_t_adr (void)
6321{
0110f2b8
PB
6322 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
6323 {
6324 /* Defer to section relaxation. */
6325 inst.relax = inst.instruction;
6326 inst.instruction = THUMB_OP16 (inst.instruction);
6327 inst.instruction |= inst.operands[0].reg << 4;
6328 }
6329 else if (unified_syntax && inst.size_req != 2)
e9f89963 6330 {
0110f2b8 6331 /* Generate a 32-bit opcode. */
e9f89963
PB
6332 inst.instruction = THUMB_OP32 (inst.instruction);
6333 inst.instruction |= inst.operands[0].reg << 8;
6334 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
6335 inst.reloc.pc_rel = 1;
6336 }
6337 else
6338 {
0110f2b8 6339 /* Generate a 16-bit opcode. */
e9f89963
PB
6340 inst.instruction = THUMB_OP16 (inst.instruction);
6341 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6342 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
6343 inst.reloc.pc_rel = 1;
b99bd4ef 6344
e9f89963
PB
6345 inst.instruction |= inst.operands[0].reg << 4;
6346 }
c19d1205 6347}
b99bd4ef 6348
c19d1205
ZW
6349/* Arithmetic instructions for which there is just one 16-bit
6350 instruction encoding, and it allows only two low registers.
6351 For maximal compatibility with ARM syntax, we allow three register
6352 operands even when Thumb-32 instructions are not available, as long
6353 as the first two are identical. For instance, both "sbc r0,r1" and
6354 "sbc r0,r0,r1" are allowed. */
b99bd4ef 6355static void
c19d1205 6356do_t_arit3 (void)
b99bd4ef 6357{
c19d1205 6358 int Rd, Rs, Rn;
b99bd4ef 6359
c19d1205
ZW
6360 Rd = inst.operands[0].reg;
6361 Rs = (inst.operands[1].present
6362 ? inst.operands[1].reg /* Rd, Rs, foo */
6363 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6364 Rn = inst.operands[2].reg;
b99bd4ef 6365
c19d1205 6366 if (unified_syntax)
b99bd4ef 6367 {
c19d1205
ZW
6368 if (!inst.operands[2].isreg)
6369 {
6370 /* For an immediate, we always generate a 32-bit opcode;
6371 section relaxation will shrink it later if possible. */
6372 inst.instruction = THUMB_OP32 (inst.instruction);
6373 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6374 inst.instruction |= Rd << 8;
6375 inst.instruction |= Rs << 16;
6376 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6377 }
6378 else
6379 {
e27ec89e
PB
6380 bfd_boolean narrow;
6381
c19d1205 6382 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6383 if (THUMB_SETS_FLAGS (inst.instruction))
6384 narrow = current_it_mask == 0;
6385 else
6386 narrow = current_it_mask != 0;
6387
6388 if (Rd > 7 || Rn > 7 || Rs > 7)
6389 narrow = FALSE;
6390 if (inst.operands[2].shifted)
6391 narrow = FALSE;
6392 if (inst.size_req == 4)
6393 narrow = FALSE;
6394
6395 if (narrow
c19d1205
ZW
6396 && Rd == Rs)
6397 {
6398 inst.instruction = THUMB_OP16 (inst.instruction);
6399 inst.instruction |= Rd;
6400 inst.instruction |= Rn << 3;
6401 return;
6402 }
b99bd4ef 6403
c19d1205
ZW
6404 /* If we get here, it can't be done in 16 bits. */
6405 constraint (inst.operands[2].shifted
6406 && inst.operands[2].immisreg,
6407 _("shift must be constant"));
6408 inst.instruction = THUMB_OP32 (inst.instruction);
6409 inst.instruction |= Rd << 8;
6410 inst.instruction |= Rs << 16;
6411 encode_thumb32_shifted_operand (2);
6412 }
a737bd4d 6413 }
c19d1205 6414 else
b99bd4ef 6415 {
c19d1205
ZW
6416 /* On its face this is a lie - the instruction does set the
6417 flags. However, the only supported mnemonic in this mode
6418 says it doesn't. */
6419 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6420
c19d1205
ZW
6421 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6422 _("unshifted register required"));
6423 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6424 constraint (Rd != Rs,
6425 _("dest and source1 must be the same register"));
a737bd4d 6426
c19d1205
ZW
6427 inst.instruction = THUMB_OP16 (inst.instruction);
6428 inst.instruction |= Rd;
6429 inst.instruction |= Rn << 3;
b99bd4ef 6430 }
a737bd4d 6431}
b99bd4ef 6432
c19d1205
ZW
6433/* Similarly, but for instructions where the arithmetic operation is
6434 commutative, so we can allow either of them to be different from
6435 the destination operand in a 16-bit instruction. For instance, all
6436 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6437 accepted. */
6438static void
6439do_t_arit3c (void)
a737bd4d 6440{
c19d1205 6441 int Rd, Rs, Rn;
b99bd4ef 6442
c19d1205
ZW
6443 Rd = inst.operands[0].reg;
6444 Rs = (inst.operands[1].present
6445 ? inst.operands[1].reg /* Rd, Rs, foo */
6446 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6447 Rn = inst.operands[2].reg;
a737bd4d 6448
c19d1205 6449 if (unified_syntax)
a737bd4d 6450 {
c19d1205 6451 if (!inst.operands[2].isreg)
b99bd4ef 6452 {
c19d1205
ZW
6453 /* For an immediate, we always generate a 32-bit opcode;
6454 section relaxation will shrink it later if possible. */
6455 inst.instruction = THUMB_OP32 (inst.instruction);
6456 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6457 inst.instruction |= Rd << 8;
6458 inst.instruction |= Rs << 16;
6459 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6460 }
c19d1205 6461 else
a737bd4d 6462 {
e27ec89e
PB
6463 bfd_boolean narrow;
6464
c19d1205 6465 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6466 if (THUMB_SETS_FLAGS (inst.instruction))
6467 narrow = current_it_mask == 0;
6468 else
6469 narrow = current_it_mask != 0;
6470
6471 if (Rd > 7 || Rn > 7 || Rs > 7)
6472 narrow = FALSE;
6473 if (inst.operands[2].shifted)
6474 narrow = FALSE;
6475 if (inst.size_req == 4)
6476 narrow = FALSE;
6477
6478 if (narrow)
a737bd4d 6479 {
c19d1205 6480 if (Rd == Rs)
a737bd4d 6481 {
c19d1205
ZW
6482 inst.instruction = THUMB_OP16 (inst.instruction);
6483 inst.instruction |= Rd;
6484 inst.instruction |= Rn << 3;
6485 return;
a737bd4d 6486 }
c19d1205 6487 if (Rd == Rn)
a737bd4d 6488 {
c19d1205
ZW
6489 inst.instruction = THUMB_OP16 (inst.instruction);
6490 inst.instruction |= Rd;
6491 inst.instruction |= Rs << 3;
6492 return;
a737bd4d
NC
6493 }
6494 }
c19d1205
ZW
6495
6496 /* If we get here, it can't be done in 16 bits. */
6497 constraint (inst.operands[2].shifted
6498 && inst.operands[2].immisreg,
6499 _("shift must be constant"));
6500 inst.instruction = THUMB_OP32 (inst.instruction);
6501 inst.instruction |= Rd << 8;
6502 inst.instruction |= Rs << 16;
6503 encode_thumb32_shifted_operand (2);
a737bd4d 6504 }
b99bd4ef 6505 }
c19d1205
ZW
6506 else
6507 {
6508 /* On its face this is a lie - the instruction does set the
6509 flags. However, the only supported mnemonic in this mode
6510 says it doesn't. */
6511 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6512
c19d1205
ZW
6513 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6514 _("unshifted register required"));
6515 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6516
6517 inst.instruction = THUMB_OP16 (inst.instruction);
6518 inst.instruction |= Rd;
6519
6520 if (Rd == Rs)
6521 inst.instruction |= Rn << 3;
6522 else if (Rd == Rn)
6523 inst.instruction |= Rs << 3;
6524 else
6525 constraint (1, _("dest must overlap one source register"));
6526 }
a737bd4d
NC
6527}
6528
62b3e311
PB
6529static void
6530do_t_barrier (void)
6531{
6532 if (inst.operands[0].present)
6533 {
6534 constraint ((inst.instruction & 0xf0) != 0x40
6535 && inst.operands[0].imm != 0xf,
6536 "bad barrier type");
6537 inst.instruction |= inst.operands[0].imm;
6538 }
6539 else
6540 inst.instruction |= 0xf;
6541}
6542
c19d1205
ZW
6543static void
6544do_t_bfc (void)
a737bd4d 6545{
c19d1205
ZW
6546 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6547 constraint (msb > 32, _("bit-field extends past end of register"));
6548 /* The instruction encoding stores the LSB and MSB,
6549 not the LSB and width. */
6550 inst.instruction |= inst.operands[0].reg << 8;
6551 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6552 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6553 inst.instruction |= msb - 1;
b99bd4ef
NC
6554}
6555
c19d1205
ZW
6556static void
6557do_t_bfi (void)
b99bd4ef 6558{
c19d1205 6559 unsigned int msb;
b99bd4ef 6560
c19d1205
ZW
6561 /* #0 in second position is alternative syntax for bfc, which is
6562 the same instruction but with REG_PC in the Rm field. */
6563 if (!inst.operands[1].isreg)
6564 inst.operands[1].reg = REG_PC;
b99bd4ef 6565
c19d1205
ZW
6566 msb = inst.operands[2].imm + inst.operands[3].imm;
6567 constraint (msb > 32, _("bit-field extends past end of register"));
6568 /* The instruction encoding stores the LSB and MSB,
6569 not the LSB and width. */
6570 inst.instruction |= inst.operands[0].reg << 8;
6571 inst.instruction |= inst.operands[1].reg << 16;
6572 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6573 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6574 inst.instruction |= msb - 1;
b99bd4ef
NC
6575}
6576
c19d1205
ZW
6577static void
6578do_t_bfx (void)
b99bd4ef 6579{
c19d1205
ZW
6580 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6581 _("bit-field extends past end of register"));
6582 inst.instruction |= inst.operands[0].reg << 8;
6583 inst.instruction |= inst.operands[1].reg << 16;
6584 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6585 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6586 inst.instruction |= inst.operands[3].imm - 1;
6587}
b99bd4ef 6588
c19d1205
ZW
6589/* ARM V5 Thumb BLX (argument parse)
6590 BLX <target_addr> which is BLX(1)
6591 BLX <Rm> which is BLX(2)
6592 Unfortunately, there are two different opcodes for this mnemonic.
6593 So, the insns[].value is not used, and the code here zaps values
6594 into inst.instruction.
b99bd4ef 6595
c19d1205
ZW
6596 ??? How to take advantage of the additional two bits of displacement
6597 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6598
c19d1205
ZW
6599static void
6600do_t_blx (void)
6601{
dfa9f0d5 6602 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
6603 if (inst.operands[0].isreg)
6604 /* We have a register, so this is BLX(2). */
6605 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6606 else
6607 {
c19d1205 6608 /* No register. This must be BLX(1). */
2fc8bdac 6609 inst.instruction = 0xf000e800;
39b41c9c
PB
6610#ifdef OBJ_ELF
6611 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6612 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6613 else
6614#endif
6615 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 6616 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6617 }
6618}
6619
c19d1205
ZW
6620static void
6621do_t_branch (void)
b99bd4ef 6622{
0110f2b8 6623 int opcode;
dfa9f0d5
PB
6624 int cond;
6625
6626 if (current_it_mask)
6627 {
6628 /* Conditional branches inside IT blocks are encoded as unconditional
6629 branches. */
6630 cond = COND_ALWAYS;
6631 /* A branch must be the last instruction in an IT block. */
6632 constraint (current_it_mask != 0x10, BAD_BRANCH);
6633 }
6634 else
6635 cond = inst.cond;
6636
6637 if (cond != COND_ALWAYS)
0110f2b8
PB
6638 opcode = T_MNEM_bcond;
6639 else
6640 opcode = inst.instruction;
6641
6642 if (unified_syntax && inst.size_req == 4)
c19d1205 6643 {
0110f2b8 6644 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 6645 if (cond == COND_ALWAYS)
0110f2b8 6646 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
6647 else
6648 {
dfa9f0d5
PB
6649 assert (cond != 0xF);
6650 inst.instruction |= cond << 22;
c19d1205
ZW
6651 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6652 }
6653 }
b99bd4ef
NC
6654 else
6655 {
0110f2b8 6656 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 6657 if (cond == COND_ALWAYS)
c19d1205
ZW
6658 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6659 else
b99bd4ef 6660 {
dfa9f0d5 6661 inst.instruction |= cond << 8;
c19d1205 6662 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6663 }
0110f2b8
PB
6664 /* Allow section relaxation. */
6665 if (unified_syntax && inst.size_req != 2)
6666 inst.relax = opcode;
b99bd4ef 6667 }
c19d1205
ZW
6668
6669 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6670}
6671
6672static void
c19d1205 6673do_t_bkpt (void)
b99bd4ef 6674{
dfa9f0d5
PB
6675 constraint (inst.cond != COND_ALWAYS,
6676 _("instruction is always unconditional"));
c19d1205 6677 if (inst.operands[0].present)
b99bd4ef 6678 {
c19d1205
ZW
6679 constraint (inst.operands[0].imm > 255,
6680 _("immediate value out of range"));
6681 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6682 }
b99bd4ef
NC
6683}
6684
6685static void
c19d1205 6686do_t_branch23 (void)
b99bd4ef 6687{
dfa9f0d5 6688 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 6689 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6690 inst.reloc.pc_rel = 1;
6691
c19d1205
ZW
6692 /* If the destination of the branch is a defined symbol which does not have
6693 the THUMB_FUNC attribute, then we must be calling a function which has
6694 the (interfacearm) attribute. We look for the Thumb entry point to that
6695 function and change the branch to refer to that function instead. */
6696 if ( inst.reloc.exp.X_op == O_symbol
6697 && inst.reloc.exp.X_add_symbol != NULL
6698 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6699 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6700 inst.reloc.exp.X_add_symbol =
6701 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6702}
6703
6704static void
c19d1205 6705do_t_bx (void)
90e4755a 6706{
dfa9f0d5 6707 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
6708 inst.instruction |= inst.operands[0].reg << 3;
6709 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6710 should cause the alignment to be checked once it is known. This is
6711 because BX PC only works if the instruction is word aligned. */
6712}
90e4755a 6713
c19d1205
ZW
6714static void
6715do_t_bxj (void)
6716{
dfa9f0d5 6717 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
6718 if (inst.operands[0].reg == REG_PC)
6719 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6720
c19d1205 6721 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6722}
6723
6724static void
c19d1205 6725do_t_clz (void)
90e4755a 6726{
c19d1205
ZW
6727 inst.instruction |= inst.operands[0].reg << 8;
6728 inst.instruction |= inst.operands[1].reg << 16;
6729 inst.instruction |= inst.operands[1].reg;
6730}
90e4755a 6731
dfa9f0d5
PB
6732static void
6733do_t_cps (void)
6734{
6735 constraint (current_it_mask, BAD_NOT_IT);
6736 inst.instruction |= inst.operands[0].imm;
6737}
6738
c19d1205
ZW
6739static void
6740do_t_cpsi (void)
6741{
dfa9f0d5 6742 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 6743 if (unified_syntax
62b3e311
PB
6744 && (inst.operands[1].present || inst.size_req == 4)
6745 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 6746 {
c19d1205
ZW
6747 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6748 inst.instruction = 0xf3af8000;
6749 inst.instruction |= imod << 9;
6750 inst.instruction |= inst.operands[0].imm << 5;
6751 if (inst.operands[1].present)
6752 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6753 }
c19d1205 6754 else
90e4755a 6755 {
62b3e311
PB
6756 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
6757 && (inst.operands[0].imm & 4),
6758 _("selected processor does not support 'A' form "
6759 "of this instruction"));
6760 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
6761 _("Thumb does not support the 2-argument "
6762 "form of this instruction"));
6763 inst.instruction |= inst.operands[0].imm;
90e4755a 6764 }
90e4755a
RE
6765}
6766
c19d1205
ZW
6767/* THUMB CPY instruction (argument parse). */
6768
90e4755a 6769static void
c19d1205 6770do_t_cpy (void)
90e4755a 6771{
c19d1205 6772 if (inst.size_req == 4)
90e4755a 6773 {
c19d1205
ZW
6774 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6775 inst.instruction |= inst.operands[0].reg << 8;
6776 inst.instruction |= inst.operands[1].reg;
90e4755a 6777 }
c19d1205 6778 else
90e4755a 6779 {
c19d1205
ZW
6780 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6781 inst.instruction |= (inst.operands[0].reg & 0x7);
6782 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6783 }
90e4755a
RE
6784}
6785
90e4755a 6786static void
c19d1205 6787do_t_czb (void)
90e4755a 6788{
dfa9f0d5 6789 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
6790 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6791 inst.instruction |= inst.operands[0].reg;
6792 inst.reloc.pc_rel = 1;
6793 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6794}
90e4755a 6795
62b3e311
PB
6796static void
6797do_t_dbg (void)
6798{
6799 inst.instruction |= inst.operands[0].imm;
6800}
6801
6802static void
6803do_t_div (void)
6804{
6805 if (!inst.operands[1].present)
6806 inst.operands[1].reg = inst.operands[0].reg;
6807 inst.instruction |= inst.operands[0].reg << 8;
6808 inst.instruction |= inst.operands[1].reg << 16;
6809 inst.instruction |= inst.operands[2].reg;
6810}
6811
c19d1205
ZW
6812static void
6813do_t_hint (void)
6814{
6815 if (unified_syntax && inst.size_req == 4)
6816 inst.instruction = THUMB_OP32 (inst.instruction);
6817 else
6818 inst.instruction = THUMB_OP16 (inst.instruction);
6819}
90e4755a 6820
c19d1205
ZW
6821static void
6822do_t_it (void)
6823{
6824 unsigned int cond = inst.operands[0].imm;
e27ec89e 6825
dfa9f0d5 6826 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
6827 current_it_mask = (inst.instruction & 0xf) | 0x10;
6828 current_cc = cond;
6829
6830 /* If the condition is a negative condition, invert the mask. */
c19d1205 6831 if ((cond & 0x1) == 0x0)
90e4755a 6832 {
c19d1205 6833 unsigned int mask = inst.instruction & 0x000f;
90e4755a 6834
c19d1205
ZW
6835 if ((mask & 0x7) == 0)
6836 /* no conversion needed */;
6837 else if ((mask & 0x3) == 0)
e27ec89e
PB
6838 mask ^= 0x8;
6839 else if ((mask & 0x1) == 0)
6840 mask ^= 0xC;
c19d1205 6841 else
e27ec89e 6842 mask ^= 0xE;
90e4755a 6843
e27ec89e
PB
6844 inst.instruction &= 0xfff0;
6845 inst.instruction |= mask;
c19d1205 6846 }
90e4755a 6847
c19d1205
ZW
6848 inst.instruction |= cond << 4;
6849}
90e4755a 6850
c19d1205
ZW
6851static void
6852do_t_ldmstm (void)
6853{
6854 /* This really doesn't seem worth it. */
6855 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6856 _("expression too complex"));
6857 constraint (inst.operands[1].writeback,
6858 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6859
c19d1205
ZW
6860 if (unified_syntax)
6861 {
6862 /* See if we can use a 16-bit instruction. */
6863 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6864 && inst.size_req != 4
6865 && inst.operands[0].reg <= 7
6866 && !(inst.operands[1].imm & ~0xff)
6867 && (inst.instruction == T_MNEM_stmia
6868 ? inst.operands[0].writeback
6869 : (inst.operands[0].writeback
6870 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6871 {
c19d1205
ZW
6872 if (inst.instruction == T_MNEM_stmia
6873 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6874 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6875 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6876 inst.operands[0].reg);
90e4755a 6877
c19d1205
ZW
6878 inst.instruction = THUMB_OP16 (inst.instruction);
6879 inst.instruction |= inst.operands[0].reg << 8;
6880 inst.instruction |= inst.operands[1].imm;
6881 }
6882 else
6883 {
6884 if (inst.operands[1].imm & (1 << 13))
6885 as_warn (_("SP should not be in register list"));
6886 if (inst.instruction == T_MNEM_stmia)
90e4755a 6887 {
c19d1205
ZW
6888 if (inst.operands[1].imm & (1 << 15))
6889 as_warn (_("PC should not be in register list"));
6890 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6891 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6892 inst.operands[0].reg);
90e4755a
RE
6893 }
6894 else
6895 {
c19d1205
ZW
6896 if (inst.operands[1].imm & (1 << 14)
6897 && inst.operands[1].imm & (1 << 15))
6898 as_warn (_("LR and PC should not both be in register list"));
6899 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6900 && inst.operands[0].writeback)
6901 as_warn (_("base register should not be in register list "
6902 "when written back"));
90e4755a 6903 }
c19d1205
ZW
6904 if (inst.instruction < 0xffff)
6905 inst.instruction = THUMB_OP32 (inst.instruction);
6906 inst.instruction |= inst.operands[0].reg << 16;
6907 inst.instruction |= inst.operands[1].imm;
6908 if (inst.operands[0].writeback)
6909 inst.instruction |= WRITE_BACK;
90e4755a
RE
6910 }
6911 }
c19d1205 6912 else
90e4755a 6913 {
c19d1205
ZW
6914 constraint (inst.operands[0].reg > 7
6915 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6916 if (inst.instruction == T_MNEM_stmia)
f03698e6 6917 {
c19d1205
ZW
6918 if (!inst.operands[0].writeback)
6919 as_warn (_("this instruction will write back the base register"));
6920 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6921 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6922 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6923 inst.operands[0].reg);
f03698e6 6924 }
c19d1205 6925 else
90e4755a 6926 {
c19d1205
ZW
6927 if (!inst.operands[0].writeback
6928 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6929 as_warn (_("this instruction will write back the base register"));
6930 else if (inst.operands[0].writeback
6931 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6932 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6933 }
6934
c19d1205
ZW
6935 inst.instruction = THUMB_OP16 (inst.instruction);
6936 inst.instruction |= inst.operands[0].reg << 8;
6937 inst.instruction |= inst.operands[1].imm;
6938 }
6939}
e28cd48c 6940
c19d1205
ZW
6941static void
6942do_t_ldrex (void)
6943{
6944 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6945 || inst.operands[1].postind || inst.operands[1].writeback
6946 || inst.operands[1].immisreg || inst.operands[1].shifted
6947 || inst.operands[1].negative,
01cfc07f 6948 BAD_ADDR_MODE);
e28cd48c 6949
c19d1205
ZW
6950 inst.instruction |= inst.operands[0].reg << 12;
6951 inst.instruction |= inst.operands[1].reg << 16;
6952 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6953}
e28cd48c 6954
c19d1205
ZW
6955static void
6956do_t_ldrexd (void)
6957{
6958 if (!inst.operands[1].present)
1cac9012 6959 {
c19d1205
ZW
6960 constraint (inst.operands[0].reg == REG_LR,
6961 _("r14 not allowed as first register "
6962 "when second register is omitted"));
6963 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6964 }
c19d1205
ZW
6965 constraint (inst.operands[0].reg == inst.operands[1].reg,
6966 BAD_OVERLAP);
b99bd4ef 6967
c19d1205
ZW
6968 inst.instruction |= inst.operands[0].reg << 12;
6969 inst.instruction |= inst.operands[1].reg << 8;
6970 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6971}
6972
6973static void
c19d1205 6974do_t_ldst (void)
b99bd4ef 6975{
0110f2b8
PB
6976 unsigned long opcode;
6977 int Rn;
6978
6979 opcode = inst.instruction;
c19d1205 6980 if (unified_syntax)
b99bd4ef 6981 {
0110f2b8
PB
6982 if (inst.operands[1].isreg
6983 && !inst.operands[1].writeback
c19d1205
ZW
6984 && !inst.operands[1].shifted && !inst.operands[1].postind
6985 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
6986 && opcode <= 0xffff
6987 && inst.size_req != 4)
c19d1205 6988 {
0110f2b8
PB
6989 /* Insn may have a 16-bit form. */
6990 Rn = inst.operands[1].reg;
6991 if (inst.operands[1].immisreg)
6992 {
6993 inst.instruction = THUMB_OP16 (opcode);
6994 /* [Rn, Ri] */
6995 if (Rn <= 7 && inst.operands[1].imm <= 7)
6996 goto op16;
6997 }
6998 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
6999 && opcode != T_MNEM_ldrsb)
7000 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
7001 || (Rn == REG_SP && opcode == T_MNEM_str))
7002 {
7003 /* [Rn, #const] */
7004 if (Rn > 7)
7005 {
7006 if (Rn == REG_PC)
7007 {
7008 if (inst.reloc.pc_rel)
7009 opcode = T_MNEM_ldr_pc2;
7010 else
7011 opcode = T_MNEM_ldr_pc;
7012 }
7013 else
7014 {
7015 if (opcode == T_MNEM_ldr)
7016 opcode = T_MNEM_ldr_sp;
7017 else
7018 opcode = T_MNEM_str_sp;
7019 }
7020 inst.instruction = inst.operands[0].reg << 8;
7021 }
7022 else
7023 {
7024 inst.instruction = inst.operands[0].reg;
7025 inst.instruction |= inst.operands[1].reg << 3;
7026 }
7027 inst.instruction |= THUMB_OP16 (opcode);
7028 if (inst.size_req == 2)
7029 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7030 else
7031 inst.relax = opcode;
7032 return;
7033 }
c19d1205 7034 }
0110f2b8
PB
7035 /* Definitely a 32-bit variant. */
7036 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
7037 inst.instruction |= inst.operands[0].reg << 12;
7038 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
7039 return;
7040 }
7041
c19d1205
ZW
7042 constraint (inst.operands[0].reg > 7, BAD_HIREG);
7043
7044 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 7045 {
c19d1205
ZW
7046 /* Only [Rn,Rm] is acceptable. */
7047 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
7048 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
7049 || inst.operands[1].postind || inst.operands[1].shifted
7050 || inst.operands[1].negative,
7051 _("Thumb does not support this addressing mode"));
7052 inst.instruction = THUMB_OP16 (inst.instruction);
7053 goto op16;
b99bd4ef 7054 }
c19d1205
ZW
7055
7056 inst.instruction = THUMB_OP16 (inst.instruction);
7057 if (!inst.operands[1].isreg)
7058 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
7059 return;
b99bd4ef 7060
c19d1205
ZW
7061 constraint (!inst.operands[1].preind
7062 || inst.operands[1].shifted
7063 || inst.operands[1].writeback,
7064 _("Thumb does not support this addressing mode"));
7065 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 7066 {
c19d1205
ZW
7067 constraint (inst.instruction & 0x0600,
7068 _("byte or halfword not valid for base register"));
7069 constraint (inst.operands[1].reg == REG_PC
7070 && !(inst.instruction & THUMB_LOAD_BIT),
7071 _("r15 based store not allowed"));
7072 constraint (inst.operands[1].immisreg,
7073 _("invalid base register for register offset"));
b99bd4ef 7074
c19d1205
ZW
7075 if (inst.operands[1].reg == REG_PC)
7076 inst.instruction = T_OPCODE_LDR_PC;
7077 else if (inst.instruction & THUMB_LOAD_BIT)
7078 inst.instruction = T_OPCODE_LDR_SP;
7079 else
7080 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 7081
c19d1205
ZW
7082 inst.instruction |= inst.operands[0].reg << 8;
7083 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7084 return;
7085 }
90e4755a 7086
c19d1205
ZW
7087 constraint (inst.operands[1].reg > 7, BAD_HIREG);
7088 if (!inst.operands[1].immisreg)
7089 {
7090 /* Immediate offset. */
7091 inst.instruction |= inst.operands[0].reg;
7092 inst.instruction |= inst.operands[1].reg << 3;
7093 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7094 return;
7095 }
90e4755a 7096
c19d1205
ZW
7097 /* Register offset. */
7098 constraint (inst.operands[1].imm > 7, BAD_HIREG);
7099 constraint (inst.operands[1].negative,
7100 _("Thumb does not support this addressing mode"));
90e4755a 7101
c19d1205
ZW
7102 op16:
7103 switch (inst.instruction)
7104 {
7105 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
7106 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
7107 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
7108 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
7109 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
7110 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
7111 case 0x5600 /* ldrsb */:
7112 case 0x5e00 /* ldrsh */: break;
7113 default: abort ();
7114 }
90e4755a 7115
c19d1205
ZW
7116 inst.instruction |= inst.operands[0].reg;
7117 inst.instruction |= inst.operands[1].reg << 3;
7118 inst.instruction |= inst.operands[1].imm << 6;
7119}
90e4755a 7120
c19d1205
ZW
7121static void
7122do_t_ldstd (void)
7123{
7124 if (!inst.operands[1].present)
b99bd4ef 7125 {
c19d1205
ZW
7126 inst.operands[1].reg = inst.operands[0].reg + 1;
7127 constraint (inst.operands[0].reg == REG_LR,
7128 _("r14 not allowed here"));
b99bd4ef 7129 }
c19d1205
ZW
7130 inst.instruction |= inst.operands[0].reg << 12;
7131 inst.instruction |= inst.operands[1].reg << 8;
7132 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
7133
b99bd4ef
NC
7134}
7135
c19d1205
ZW
7136static void
7137do_t_ldstt (void)
7138{
7139 inst.instruction |= inst.operands[0].reg << 12;
7140 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
7141}
a737bd4d 7142
b99bd4ef 7143static void
c19d1205 7144do_t_mla (void)
b99bd4ef 7145{
c19d1205
ZW
7146 inst.instruction |= inst.operands[0].reg << 8;
7147 inst.instruction |= inst.operands[1].reg << 16;
7148 inst.instruction |= inst.operands[2].reg;
7149 inst.instruction |= inst.operands[3].reg << 12;
7150}
b99bd4ef 7151
c19d1205
ZW
7152static void
7153do_t_mlal (void)
7154{
7155 inst.instruction |= inst.operands[0].reg << 12;
7156 inst.instruction |= inst.operands[1].reg << 8;
7157 inst.instruction |= inst.operands[2].reg << 16;
7158 inst.instruction |= inst.operands[3].reg;
7159}
b99bd4ef 7160
c19d1205
ZW
7161static void
7162do_t_mov_cmp (void)
7163{
7164 if (unified_syntax)
b99bd4ef 7165 {
c19d1205
ZW
7166 int r0off = (inst.instruction == T_MNEM_mov
7167 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 7168 unsigned long opcode;
3d388997
PB
7169 bfd_boolean narrow;
7170 bfd_boolean low_regs;
7171
7172 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 7173 opcode = inst.instruction;
3d388997 7174 if (current_it_mask)
0110f2b8 7175 narrow = opcode != T_MNEM_movs;
3d388997 7176 else
0110f2b8 7177 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
7178 if (inst.size_req == 4
7179 || inst.operands[1].shifted)
7180 narrow = FALSE;
7181
c19d1205
ZW
7182 if (!inst.operands[1].isreg)
7183 {
0110f2b8
PB
7184 /* Immediate operand. */
7185 if (current_it_mask == 0 && opcode == T_MNEM_mov)
7186 narrow = 0;
7187 if (low_regs && narrow)
7188 {
7189 inst.instruction = THUMB_OP16 (opcode);
7190 inst.instruction |= inst.operands[0].reg << 8;
7191 if (inst.size_req == 2)
7192 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7193 else
7194 inst.relax = opcode;
7195 }
7196 else
7197 {
7198 inst.instruction = THUMB_OP32 (inst.instruction);
7199 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7200 inst.instruction |= inst.operands[0].reg << r0off;
7201 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7202 }
c19d1205 7203 }
3d388997 7204 else if (!narrow)
c19d1205
ZW
7205 {
7206 inst.instruction = THUMB_OP32 (inst.instruction);
7207 inst.instruction |= inst.operands[0].reg << r0off;
7208 encode_thumb32_shifted_operand (1);
7209 }
7210 else
7211 switch (inst.instruction)
7212 {
7213 case T_MNEM_mov:
7214 inst.instruction = T_OPCODE_MOV_HR;
7215 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7216 inst.instruction |= (inst.operands[0].reg & 0x7);
7217 inst.instruction |= inst.operands[1].reg << 3;
7218 break;
b99bd4ef 7219
c19d1205
ZW
7220 case T_MNEM_movs:
7221 /* We know we have low registers at this point.
7222 Generate ADD Rd, Rs, #0. */
7223 inst.instruction = T_OPCODE_ADD_I3;
7224 inst.instruction |= inst.operands[0].reg;
7225 inst.instruction |= inst.operands[1].reg << 3;
7226 break;
7227
7228 case T_MNEM_cmp:
3d388997 7229 if (low_regs)
c19d1205
ZW
7230 {
7231 inst.instruction = T_OPCODE_CMP_LR;
7232 inst.instruction |= inst.operands[0].reg;
7233 inst.instruction |= inst.operands[1].reg << 3;
7234 }
7235 else
7236 {
7237 inst.instruction = T_OPCODE_CMP_HR;
7238 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7239 inst.instruction |= (inst.operands[0].reg & 0x7);
7240 inst.instruction |= inst.operands[1].reg << 3;
7241 }
7242 break;
7243 }
b99bd4ef
NC
7244 return;
7245 }
7246
c19d1205
ZW
7247 inst.instruction = THUMB_OP16 (inst.instruction);
7248 if (inst.operands[1].isreg)
b99bd4ef 7249 {
c19d1205 7250 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 7251 {
c19d1205
ZW
7252 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
7253 since a MOV instruction produces unpredictable results. */
7254 if (inst.instruction == T_OPCODE_MOV_I8)
7255 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 7256 else
c19d1205 7257 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 7258
c19d1205
ZW
7259 inst.instruction |= inst.operands[0].reg;
7260 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7261 }
7262 else
7263 {
c19d1205
ZW
7264 if (inst.instruction == T_OPCODE_MOV_I8)
7265 inst.instruction = T_OPCODE_MOV_HR;
7266 else
7267 inst.instruction = T_OPCODE_CMP_HR;
7268 do_t_cpy ();
b99bd4ef
NC
7269 }
7270 }
c19d1205 7271 else
b99bd4ef 7272 {
c19d1205
ZW
7273 constraint (inst.operands[0].reg > 7,
7274 _("only lo regs allowed with immediate"));
7275 inst.instruction |= inst.operands[0].reg << 8;
7276 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7277 }
7278}
b99bd4ef 7279
c19d1205
ZW
7280static void
7281do_t_mov16 (void)
7282{
7283 inst.instruction |= inst.operands[0].reg << 8;
7284 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
7285 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
7286 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
7287 inst.instruction |= (inst.operands[1].imm & 0x00ff);
7288}
b99bd4ef 7289
c19d1205
ZW
7290static void
7291do_t_mvn_tst (void)
7292{
7293 if (unified_syntax)
7294 {
7295 int r0off = (inst.instruction == T_MNEM_mvn
7296 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
7297 bfd_boolean narrow;
7298
7299 if (inst.size_req == 4
7300 || inst.instruction > 0xffff
7301 || inst.operands[1].shifted
7302 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7303 narrow = FALSE;
7304 else if (inst.instruction == T_MNEM_cmn)
7305 narrow = TRUE;
7306 else if (THUMB_SETS_FLAGS (inst.instruction))
7307 narrow = (current_it_mask == 0);
7308 else
7309 narrow = (current_it_mask != 0);
7310
c19d1205 7311 if (!inst.operands[1].isreg)
b99bd4ef 7312 {
c19d1205
ZW
7313 /* For an immediate, we always generate a 32-bit opcode;
7314 section relaxation will shrink it later if possible. */
7315 if (inst.instruction < 0xffff)
7316 inst.instruction = THUMB_OP32 (inst.instruction);
7317 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7318 inst.instruction |= inst.operands[0].reg << r0off;
7319 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 7320 }
c19d1205 7321 else
b99bd4ef 7322 {
c19d1205 7323 /* See if we can do this with a 16-bit instruction. */
3d388997 7324 if (narrow)
b99bd4ef 7325 {
c19d1205
ZW
7326 inst.instruction = THUMB_OP16 (inst.instruction);
7327 inst.instruction |= inst.operands[0].reg;
7328 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7329 }
c19d1205 7330 else
b99bd4ef 7331 {
c19d1205
ZW
7332 constraint (inst.operands[1].shifted
7333 && inst.operands[1].immisreg,
7334 _("shift must be constant"));
7335 if (inst.instruction < 0xffff)
7336 inst.instruction = THUMB_OP32 (inst.instruction);
7337 inst.instruction |= inst.operands[0].reg << r0off;
7338 encode_thumb32_shifted_operand (1);
b99bd4ef 7339 }
b99bd4ef
NC
7340 }
7341 }
7342 else
7343 {
c19d1205
ZW
7344 constraint (inst.instruction > 0xffff
7345 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
7346 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
7347 _("unshifted register required"));
7348 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7349 BAD_HIREG);
b99bd4ef 7350
c19d1205
ZW
7351 inst.instruction = THUMB_OP16 (inst.instruction);
7352 inst.instruction |= inst.operands[0].reg;
7353 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7354 }
b99bd4ef
NC
7355}
7356
b05fe5cf 7357static void
c19d1205 7358do_t_mrs (void)
b05fe5cf 7359{
62b3e311
PB
7360 int flags;
7361 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
7362 if (flags == 0)
7363 {
7364 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7365 _("selected processor does not support "
7366 "requested special purpose register"));
7367 }
7368 else
7369 {
7370 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7371 _("selected processor does not support "
7372 "requested special purpose register %x"));
7373 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7374 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
7375 _("'CPSR' or 'SPSR' expected"));
7376 }
7377
c19d1205 7378 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
7379 inst.instruction |= (flags & SPSR_BIT) >> 2;
7380 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 7381}
b05fe5cf 7382
c19d1205
ZW
7383static void
7384do_t_msr (void)
7385{
62b3e311
PB
7386 int flags;
7387
c19d1205
ZW
7388 constraint (!inst.operands[1].isreg,
7389 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
7390 flags = inst.operands[0].imm;
7391 if (flags & ~0xff)
7392 {
7393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7394 _("selected processor does not support "
7395 "requested special purpose register"));
7396 }
7397 else
7398 {
7399 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7400 _("selected processor does not support "
7401 "requested special purpose register"));
7402 flags |= PSR_f;
7403 }
7404 inst.instruction |= (flags & SPSR_BIT) >> 2;
7405 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
7406 inst.instruction |= (flags & 0xff);
c19d1205
ZW
7407 inst.instruction |= inst.operands[1].reg << 16;
7408}
b05fe5cf 7409
c19d1205
ZW
7410static void
7411do_t_mul (void)
7412{
7413 if (!inst.operands[2].present)
7414 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 7415
c19d1205
ZW
7416 /* There is no 32-bit MULS and no 16-bit MUL. */
7417 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 7418 {
c19d1205
ZW
7419 inst.instruction = THUMB_OP32 (inst.instruction);
7420 inst.instruction |= inst.operands[0].reg << 8;
7421 inst.instruction |= inst.operands[1].reg << 16;
7422 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 7423 }
c19d1205 7424 else
b05fe5cf 7425 {
c19d1205
ZW
7426 constraint (!unified_syntax
7427 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
7428 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7429 BAD_HIREG);
b05fe5cf 7430
c19d1205
ZW
7431 inst.instruction = THUMB_OP16 (inst.instruction);
7432 inst.instruction |= inst.operands[0].reg;
b05fe5cf 7433
c19d1205
ZW
7434 if (inst.operands[0].reg == inst.operands[1].reg)
7435 inst.instruction |= inst.operands[2].reg << 3;
7436 else if (inst.operands[0].reg == inst.operands[2].reg)
7437 inst.instruction |= inst.operands[1].reg << 3;
7438 else
7439 constraint (1, _("dest must overlap one source register"));
7440 }
7441}
b05fe5cf 7442
c19d1205
ZW
7443static void
7444do_t_mull (void)
7445{
7446 inst.instruction |= inst.operands[0].reg << 12;
7447 inst.instruction |= inst.operands[1].reg << 8;
7448 inst.instruction |= inst.operands[2].reg << 16;
7449 inst.instruction |= inst.operands[3].reg;
b05fe5cf 7450
c19d1205
ZW
7451 if (inst.operands[0].reg == inst.operands[1].reg)
7452 as_tsktsk (_("rdhi and rdlo must be different"));
7453}
b05fe5cf 7454
c19d1205
ZW
7455static void
7456do_t_nop (void)
7457{
7458 if (unified_syntax)
7459 {
7460 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 7461 {
c19d1205
ZW
7462 inst.instruction = THUMB_OP32 (inst.instruction);
7463 inst.instruction |= inst.operands[0].imm;
7464 }
7465 else
7466 {
7467 inst.instruction = THUMB_OP16 (inst.instruction);
7468 inst.instruction |= inst.operands[0].imm << 4;
7469 }
7470 }
7471 else
7472 {
7473 constraint (inst.operands[0].present,
7474 _("Thumb does not support NOP with hints"));
7475 inst.instruction = 0x46c0;
7476 }
7477}
b05fe5cf 7478
c19d1205
ZW
7479static void
7480do_t_neg (void)
7481{
7482 if (unified_syntax)
7483 {
3d388997
PB
7484 bfd_boolean narrow;
7485
7486 if (THUMB_SETS_FLAGS (inst.instruction))
7487 narrow = (current_it_mask == 0);
7488 else
7489 narrow = (current_it_mask != 0);
7490 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7491 narrow = FALSE;
7492 if (inst.size_req == 4)
7493 narrow = FALSE;
7494
7495 if (!narrow)
c19d1205
ZW
7496 {
7497 inst.instruction = THUMB_OP32 (inst.instruction);
7498 inst.instruction |= inst.operands[0].reg << 8;
7499 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
7500 }
7501 else
7502 {
c19d1205
ZW
7503 inst.instruction = THUMB_OP16 (inst.instruction);
7504 inst.instruction |= inst.operands[0].reg;
7505 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
7506 }
7507 }
7508 else
7509 {
c19d1205
ZW
7510 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7511 BAD_HIREG);
7512 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7513
7514 inst.instruction = THUMB_OP16 (inst.instruction);
7515 inst.instruction |= inst.operands[0].reg;
7516 inst.instruction |= inst.operands[1].reg << 3;
7517 }
7518}
7519
7520static void
7521do_t_pkhbt (void)
7522{
7523 inst.instruction |= inst.operands[0].reg << 8;
7524 inst.instruction |= inst.operands[1].reg << 16;
7525 inst.instruction |= inst.operands[2].reg;
7526 if (inst.operands[3].present)
7527 {
7528 unsigned int val = inst.reloc.exp.X_add_number;
7529 constraint (inst.reloc.exp.X_op != O_constant,
7530 _("expression too complex"));
7531 inst.instruction |= (val & 0x1c) << 10;
7532 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 7533 }
c19d1205 7534}
b05fe5cf 7535
c19d1205
ZW
7536static void
7537do_t_pkhtb (void)
7538{
7539 if (!inst.operands[3].present)
7540 inst.instruction &= ~0x00000020;
7541 do_t_pkhbt ();
b05fe5cf
ZW
7542}
7543
c19d1205
ZW
7544static void
7545do_t_pld (void)
7546{
7547 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7548}
b05fe5cf 7549
c19d1205
ZW
7550static void
7551do_t_push_pop (void)
b99bd4ef 7552{
e9f89963
PB
7553 unsigned mask;
7554
c19d1205
ZW
7555 constraint (inst.operands[0].writeback,
7556 _("push/pop do not support {reglist}^"));
7557 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7558 _("expression too complex"));
b99bd4ef 7559
e9f89963
PB
7560 mask = inst.operands[0].imm;
7561 if ((mask & ~0xff) == 0)
c19d1205
ZW
7562 inst.instruction = THUMB_OP16 (inst.instruction);
7563 else if ((inst.instruction == T_MNEM_push
e9f89963 7564 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 7565 || (inst.instruction == T_MNEM_pop
e9f89963 7566 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 7567 {
c19d1205
ZW
7568 inst.instruction = THUMB_OP16 (inst.instruction);
7569 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 7570 mask &= 0xff;
c19d1205
ZW
7571 }
7572 else if (unified_syntax)
7573 {
e9f89963
PB
7574 if (mask & (1 << 13))
7575 inst.error = _("SP not allowed in register list");
c19d1205 7576 if (inst.instruction == T_MNEM_push)
b99bd4ef 7577 {
e9f89963
PB
7578 if (mask & (1 << 15))
7579 inst.error = _("PC not allowed in register list");
c19d1205
ZW
7580 }
7581 else
7582 {
e9f89963
PB
7583 if (mask & (1 << 14)
7584 && mask & (1 << 15))
7585 inst.error = _("LR and PC should not both be in register list");
c19d1205 7586 }
e9f89963
PB
7587 if ((mask & (mask - 1)) == 0)
7588 {
7589 /* Single register push/pop implemented as str/ldr. */
7590 if (inst.instruction == T_MNEM_push)
7591 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7592 else
7593 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7594 mask = ffs(mask) - 1;
7595 mask <<= 12;
7596 }
7597 else
7598 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
7599 }
7600 else
7601 {
7602 inst.error = _("invalid register list to push/pop instruction");
7603 return;
7604 }
b99bd4ef 7605
e9f89963 7606 inst.instruction |= mask;
c19d1205 7607}
b99bd4ef 7608
c19d1205
ZW
7609static void
7610do_t_rbit (void)
7611{
7612 inst.instruction |= inst.operands[0].reg << 8;
7613 inst.instruction |= inst.operands[1].reg << 16;
7614}
b99bd4ef 7615
c19d1205
ZW
7616static void
7617do_t_rev (void)
7618{
7619 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7620 && inst.size_req != 4)
7621 {
7622 inst.instruction = THUMB_OP16 (inst.instruction);
7623 inst.instruction |= inst.operands[0].reg;
7624 inst.instruction |= inst.operands[1].reg << 3;
7625 }
7626 else if (unified_syntax)
7627 {
7628 inst.instruction = THUMB_OP32 (inst.instruction);
7629 inst.instruction |= inst.operands[0].reg << 8;
7630 inst.instruction |= inst.operands[1].reg << 16;
7631 inst.instruction |= inst.operands[1].reg;
7632 }
7633 else
7634 inst.error = BAD_HIREG;
7635}
b99bd4ef 7636
c19d1205
ZW
7637static void
7638do_t_rsb (void)
7639{
7640 int Rd, Rs;
b99bd4ef 7641
c19d1205
ZW
7642 Rd = inst.operands[0].reg;
7643 Rs = (inst.operands[1].present
7644 ? inst.operands[1].reg /* Rd, Rs, foo */
7645 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 7646
c19d1205
ZW
7647 inst.instruction |= Rd << 8;
7648 inst.instruction |= Rs << 16;
7649 if (!inst.operands[2].isreg)
7650 {
7651 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7652 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7653 }
7654 else
7655 encode_thumb32_shifted_operand (2);
7656}
b99bd4ef 7657
c19d1205
ZW
7658static void
7659do_t_setend (void)
7660{
dfa9f0d5 7661 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
7662 if (inst.operands[0].imm)
7663 inst.instruction |= 0x8;
7664}
b99bd4ef 7665
c19d1205
ZW
7666static void
7667do_t_shift (void)
7668{
7669 if (!inst.operands[1].present)
7670 inst.operands[1].reg = inst.operands[0].reg;
7671
7672 if (unified_syntax)
7673 {
3d388997
PB
7674 bfd_boolean narrow;
7675 int shift_kind;
7676
7677 switch (inst.instruction)
7678 {
7679 case T_MNEM_asr:
7680 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7681 case T_MNEM_lsl:
7682 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7683 case T_MNEM_lsr:
7684 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7685 case T_MNEM_ror:
7686 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7687 default: abort ();
7688 }
7689
7690 if (THUMB_SETS_FLAGS (inst.instruction))
7691 narrow = (current_it_mask == 0);
7692 else
7693 narrow = (current_it_mask != 0);
7694 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7695 narrow = FALSE;
7696 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7697 narrow = FALSE;
7698 if (inst.operands[2].isreg
7699 && (inst.operands[1].reg != inst.operands[0].reg
7700 || inst.operands[2].reg > 7))
7701 narrow = FALSE;
7702 if (inst.size_req == 4)
7703 narrow = FALSE;
7704
7705 if (!narrow)
c19d1205
ZW
7706 {
7707 if (inst.operands[2].isreg)
b99bd4ef 7708 {
c19d1205
ZW
7709 inst.instruction = THUMB_OP32 (inst.instruction);
7710 inst.instruction |= inst.operands[0].reg << 8;
7711 inst.instruction |= inst.operands[1].reg << 16;
7712 inst.instruction |= inst.operands[2].reg;
7713 }
7714 else
7715 {
7716 inst.operands[1].shifted = 1;
3d388997 7717 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
7718 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7719 ? T_MNEM_movs : T_MNEM_mov);
7720 inst.instruction |= inst.operands[0].reg << 8;
7721 encode_thumb32_shifted_operand (1);
7722 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7723 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7724 }
7725 }
7726 else
7727 {
c19d1205 7728 if (inst.operands[2].isreg)
b99bd4ef 7729 {
3d388997 7730 switch (shift_kind)
b99bd4ef 7731 {
3d388997
PB
7732 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7733 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7734 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7735 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 7736 default: abort ();
b99bd4ef 7737 }
c19d1205
ZW
7738
7739 inst.instruction |= inst.operands[0].reg;
7740 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7741 }
7742 else
7743 {
3d388997 7744 switch (shift_kind)
b99bd4ef 7745 {
3d388997
PB
7746 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7747 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7748 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 7749 default: abort ();
b99bd4ef 7750 }
c19d1205
ZW
7751 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7752 inst.instruction |= inst.operands[0].reg;
7753 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7754 }
7755 }
c19d1205
ZW
7756 }
7757 else
7758 {
7759 constraint (inst.operands[0].reg > 7
7760 || inst.operands[1].reg > 7, BAD_HIREG);
7761 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7762
c19d1205
ZW
7763 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7764 {
7765 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7766 constraint (inst.operands[0].reg != inst.operands[1].reg,
7767 _("source1 and dest must be same register"));
b99bd4ef 7768
c19d1205
ZW
7769 switch (inst.instruction)
7770 {
7771 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7772 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7773 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7774 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7775 default: abort ();
7776 }
7777
7778 inst.instruction |= inst.operands[0].reg;
7779 inst.instruction |= inst.operands[2].reg << 3;
7780 }
7781 else
b99bd4ef 7782 {
c19d1205
ZW
7783 switch (inst.instruction)
7784 {
7785 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7786 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7787 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7788 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7789 default: abort ();
7790 }
7791 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7792 inst.instruction |= inst.operands[0].reg;
7793 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7794 }
7795 }
b99bd4ef
NC
7796}
7797
7798static void
c19d1205 7799do_t_simd (void)
b99bd4ef 7800{
c19d1205
ZW
7801 inst.instruction |= inst.operands[0].reg << 8;
7802 inst.instruction |= inst.operands[1].reg << 16;
7803 inst.instruction |= inst.operands[2].reg;
7804}
b99bd4ef 7805
c19d1205 7806static void
3eb17e6b 7807do_t_smc (void)
c19d1205
ZW
7808{
7809 unsigned int value = inst.reloc.exp.X_add_number;
7810 constraint (inst.reloc.exp.X_op != O_constant,
7811 _("expression too complex"));
7812 inst.reloc.type = BFD_RELOC_UNUSED;
7813 inst.instruction |= (value & 0xf000) >> 12;
7814 inst.instruction |= (value & 0x0ff0);
7815 inst.instruction |= (value & 0x000f) << 16;
7816}
b99bd4ef 7817
c19d1205
ZW
7818static void
7819do_t_ssat (void)
7820{
7821 inst.instruction |= inst.operands[0].reg << 8;
7822 inst.instruction |= inst.operands[1].imm - 1;
7823 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7824
c19d1205 7825 if (inst.operands[3].present)
b99bd4ef 7826 {
c19d1205
ZW
7827 constraint (inst.reloc.exp.X_op != O_constant,
7828 _("expression too complex"));
b99bd4ef 7829
c19d1205 7830 if (inst.reloc.exp.X_add_number != 0)
6189168b 7831 {
c19d1205
ZW
7832 if (inst.operands[3].shift_kind == SHIFT_ASR)
7833 inst.instruction |= 0x00200000; /* sh bit */
7834 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7835 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7836 }
c19d1205 7837 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7838 }
b99bd4ef
NC
7839}
7840
0dd132b6 7841static void
c19d1205 7842do_t_ssat16 (void)
0dd132b6 7843{
c19d1205
ZW
7844 inst.instruction |= inst.operands[0].reg << 8;
7845 inst.instruction |= inst.operands[1].imm - 1;
7846 inst.instruction |= inst.operands[2].reg << 16;
7847}
0dd132b6 7848
c19d1205
ZW
7849static void
7850do_t_strex (void)
7851{
7852 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7853 || inst.operands[2].postind || inst.operands[2].writeback
7854 || inst.operands[2].immisreg || inst.operands[2].shifted
7855 || inst.operands[2].negative,
01cfc07f 7856 BAD_ADDR_MODE);
0dd132b6 7857
c19d1205
ZW
7858 inst.instruction |= inst.operands[0].reg << 8;
7859 inst.instruction |= inst.operands[1].reg << 12;
7860 inst.instruction |= inst.operands[2].reg << 16;
7861 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7862}
7863
b99bd4ef 7864static void
c19d1205 7865do_t_strexd (void)
b99bd4ef 7866{
c19d1205
ZW
7867 if (!inst.operands[2].present)
7868 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7869
c19d1205
ZW
7870 constraint (inst.operands[0].reg == inst.operands[1].reg
7871 || inst.operands[0].reg == inst.operands[2].reg
7872 || inst.operands[0].reg == inst.operands[3].reg
7873 || inst.operands[1].reg == inst.operands[2].reg,
7874 BAD_OVERLAP);
b99bd4ef 7875
c19d1205
ZW
7876 inst.instruction |= inst.operands[0].reg;
7877 inst.instruction |= inst.operands[1].reg << 12;
7878 inst.instruction |= inst.operands[2].reg << 8;
7879 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7880}
7881
7882static void
c19d1205 7883do_t_sxtah (void)
b99bd4ef 7884{
c19d1205
ZW
7885 inst.instruction |= inst.operands[0].reg << 8;
7886 inst.instruction |= inst.operands[1].reg << 16;
7887 inst.instruction |= inst.operands[2].reg;
7888 inst.instruction |= inst.operands[3].imm << 4;
7889}
b99bd4ef 7890
c19d1205
ZW
7891static void
7892do_t_sxth (void)
7893{
7894 if (inst.instruction <= 0xffff && inst.size_req != 4
7895 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7896 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7897 {
c19d1205
ZW
7898 inst.instruction = THUMB_OP16 (inst.instruction);
7899 inst.instruction |= inst.operands[0].reg;
7900 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7901 }
c19d1205 7902 else if (unified_syntax)
b99bd4ef 7903 {
c19d1205
ZW
7904 if (inst.instruction <= 0xffff)
7905 inst.instruction = THUMB_OP32 (inst.instruction);
7906 inst.instruction |= inst.operands[0].reg << 8;
7907 inst.instruction |= inst.operands[1].reg;
7908 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7909 }
c19d1205 7910 else
b99bd4ef 7911 {
c19d1205
ZW
7912 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7913 _("Thumb encoding does not support rotation"));
7914 constraint (1, BAD_HIREG);
b99bd4ef 7915 }
c19d1205 7916}
b99bd4ef 7917
c19d1205
ZW
7918static void
7919do_t_swi (void)
7920{
7921 inst.reloc.type = BFD_RELOC_ARM_SWI;
7922}
b99bd4ef 7923
92e90b6e
PB
7924static void
7925do_t_tb (void)
7926{
7927 int half;
7928
7929 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
7930 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
7931 constraint (inst.operands[0].immisreg,
7932 _("instruction requires register index"));
92e90b6e
PB
7933 constraint (inst.operands[0].imm == 15,
7934 _("PC is not a valid index register"));
7935 constraint (!half && inst.operands[0].shifted,
7936 _("instruction does not allow shifted index"));
92e90b6e
PB
7937 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7938}
7939
c19d1205
ZW
7940static void
7941do_t_usat (void)
7942{
7943 inst.instruction |= inst.operands[0].reg << 8;
7944 inst.instruction |= inst.operands[1].imm;
7945 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7946
c19d1205 7947 if (inst.operands[3].present)
b99bd4ef 7948 {
c19d1205
ZW
7949 constraint (inst.reloc.exp.X_op != O_constant,
7950 _("expression too complex"));
7951 if (inst.reloc.exp.X_add_number != 0)
7952 {
7953 if (inst.operands[3].shift_kind == SHIFT_ASR)
7954 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7955
c19d1205
ZW
7956 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7957 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7958 }
7959 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7960 }
b99bd4ef
NC
7961}
7962
7963static void
c19d1205 7964do_t_usat16 (void)
b99bd4ef 7965{
c19d1205
ZW
7966 inst.instruction |= inst.operands[0].reg << 8;
7967 inst.instruction |= inst.operands[1].imm;
7968 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7969}
c19d1205
ZW
7970\f
7971/* Overall per-instruction processing. */
7972
7973/* We need to be able to fix up arbitrary expressions in some statements.
7974 This is so that we can handle symbols that are an arbitrary distance from
7975 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7976 which returns part of an address in a form which will be valid for
7977 a data instruction. We do this by pushing the expression into a symbol
7978 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7979
7980static void
c19d1205
ZW
7981fix_new_arm (fragS * frag,
7982 int where,
7983 short int size,
7984 expressionS * exp,
7985 int pc_rel,
7986 int reloc)
b99bd4ef 7987{
c19d1205 7988 fixS * new_fix;
b99bd4ef 7989
c19d1205 7990 switch (exp->X_op)
b99bd4ef 7991 {
c19d1205
ZW
7992 case O_constant:
7993 case O_symbol:
7994 case O_add:
7995 case O_subtract:
7996 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7997 break;
b99bd4ef 7998
c19d1205
ZW
7999 default:
8000 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
8001 pc_rel, reloc);
8002 break;
b99bd4ef
NC
8003 }
8004
c19d1205
ZW
8005 /* Mark whether the fix is to a THUMB instruction, or an ARM
8006 instruction. */
adbaf948 8007 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
8008}
8009
0110f2b8
PB
8010/* Create a frg for an instruction requiring relaxation. */
8011static void
8012output_relax_insn (void)
8013{
8014 char * to;
8015 symbolS *sym;
8016 int offset;
8017
6e1cb1a6
PB
8018#ifdef OBJ_ELF
8019 /* The size of the instruction is unknown, so tie the debug info to the
8020 start of the instruction. */
8021 dwarf2_emit_insn (0);
8022#endif
8023
0110f2b8
PB
8024 switch (inst.reloc.exp.X_op)
8025 {
8026 case O_symbol:
8027 sym = inst.reloc.exp.X_add_symbol;
8028 offset = inst.reloc.exp.X_add_number;
8029 break;
8030 case O_constant:
8031 sym = NULL;
8032 offset = inst.reloc.exp.X_add_number;
8033 break;
8034 default:
8035 sym = make_expr_symbol (&inst.reloc.exp);
8036 offset = 0;
8037 break;
8038 }
8039 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
8040 inst.relax, sym, offset, NULL/*offset, opcode*/);
8041 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
8042}
8043
8044/* Write a 32-bit thumb instruction to buf. */
8045static void
8046put_thumb32_insn (char * buf, unsigned long insn)
8047{
8048 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
8049 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
8050}
8051
b99bd4ef 8052static void
c19d1205 8053output_inst (const char * str)
b99bd4ef 8054{
c19d1205 8055 char * to = NULL;
b99bd4ef 8056
c19d1205 8057 if (inst.error)
b99bd4ef 8058 {
c19d1205 8059 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
8060 return;
8061 }
0110f2b8
PB
8062 if (inst.relax) {
8063 output_relax_insn();
8064 return;
8065 }
c19d1205
ZW
8066 if (inst.size == 0)
8067 return;
b99bd4ef 8068
c19d1205
ZW
8069 to = frag_more (inst.size);
8070
8071 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 8072 {
c19d1205 8073 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 8074 put_thumb32_insn (to, inst.instruction);
b99bd4ef 8075 }
c19d1205 8076 else if (inst.size > INSN_SIZE)
b99bd4ef 8077 {
c19d1205
ZW
8078 assert (inst.size == (2 * INSN_SIZE));
8079 md_number_to_chars (to, inst.instruction, INSN_SIZE);
8080 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 8081 }
c19d1205
ZW
8082 else
8083 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 8084
c19d1205
ZW
8085 if (inst.reloc.type != BFD_RELOC_UNUSED)
8086 fix_new_arm (frag_now, to - frag_now->fr_literal,
8087 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
8088 inst.reloc.type);
b99bd4ef 8089
c19d1205
ZW
8090#ifdef OBJ_ELF
8091 dwarf2_emit_insn (inst.size);
8092#endif
8093}
b99bd4ef 8094
c19d1205
ZW
8095/* Tag values used in struct asm_opcode's tag field. */
8096enum opcode_tag
8097{
8098 OT_unconditional, /* Instruction cannot be conditionalized.
8099 The ARM condition field is still 0xE. */
8100 OT_unconditionalF, /* Instruction cannot be conditionalized
8101 and carries 0xF in its ARM condition field. */
8102 OT_csuffix, /* Instruction takes a conditional suffix. */
8103 OT_cinfix3, /* Instruction takes a conditional infix,
8104 beginning at character index 3. (In
8105 unified mode, it becomes a suffix.) */
e3cb604e
PB
8106 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
8107 character index 3, even in unified mode. Used for
8108 legacy instructions where suffix and infix forms
8109 may be ambiguous. */
c19d1205 8110 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 8111 suffix or an infix at character index 3. */
c19d1205
ZW
8112 OT_odd_infix_unc, /* This is the unconditional variant of an
8113 instruction that takes a conditional infix
8114 at an unusual position. In unified mode,
8115 this variant will accept a suffix. */
8116 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
8117 are the conditional variants of instructions that
8118 take conditional infixes in unusual positions.
8119 The infix appears at character index
8120 (tag - OT_odd_infix_0). These are not accepted
8121 in unified mode. */
8122};
b99bd4ef 8123
c19d1205
ZW
8124/* Subroutine of md_assemble, responsible for looking up the primary
8125 opcode from the mnemonic the user wrote. STR points to the
8126 beginning of the mnemonic.
8127
8128 This is not simply a hash table lookup, because of conditional
8129 variants. Most instructions have conditional variants, which are
8130 expressed with a _conditional affix_ to the mnemonic. If we were
8131 to encode each conditional variant as a literal string in the opcode
8132 table, it would have approximately 20,000 entries.
8133
8134 Most mnemonics take this affix as a suffix, and in unified syntax,
8135 'most' is upgraded to 'all'. However, in the divided syntax, some
8136 instructions take the affix as an infix, notably the s-variants of
8137 the arithmetic instructions. Of those instructions, all but six
8138 have the infix appear after the third character of the mnemonic.
8139
8140 Accordingly, the algorithm for looking up primary opcodes given
8141 an identifier is:
8142
8143 1. Look up the identifier in the opcode table.
8144 If we find a match, go to step U.
8145
8146 2. Look up the last two characters of the identifier in the
8147 conditions table. If we find a match, look up the first N-2
8148 characters of the identifier in the opcode table. If we
8149 find a match, go to step CE.
8150
8151 3. Look up the fourth and fifth characters of the identifier in
8152 the conditions table. If we find a match, extract those
8153 characters from the identifier, and look up the remaining
8154 characters in the opcode table. If we find a match, go
8155 to step CM.
8156
8157 4. Fail.
8158
8159 U. Examine the tag field of the opcode structure, in case this is
8160 one of the six instructions with its conditional infix in an
8161 unusual place. If it is, the tag tells us where to find the
8162 infix; look it up in the conditions table and set inst.cond
8163 accordingly. Otherwise, this is an unconditional instruction.
8164 Again set inst.cond accordingly. Return the opcode structure.
8165
8166 CE. Examine the tag field to make sure this is an instruction that
8167 should receive a conditional suffix. If it is not, fail.
8168 Otherwise, set inst.cond from the suffix we already looked up,
8169 and return the opcode structure.
8170
8171 CM. Examine the tag field to make sure this is an instruction that
8172 should receive a conditional infix after the third character.
8173 If it is not, fail. Otherwise, undo the edits to the current
8174 line of input and proceed as for case CE. */
8175
8176static const struct asm_opcode *
8177opcode_lookup (char **str)
8178{
8179 char *end, *base;
8180 char *affix;
8181 const struct asm_opcode *opcode;
8182 const struct asm_cond *cond;
e3cb604e 8183 char save[2];
c19d1205
ZW
8184
8185 /* Scan up to the end of the mnemonic, which must end in white space,
8186 '.' (in unified mode only), or end of string. */
8187 for (base = end = *str; *end != '\0'; end++)
8188 if (*end == ' ' || (unified_syntax && *end == '.'))
8189 break;
b99bd4ef 8190
c19d1205
ZW
8191 if (end == base)
8192 return 0;
b99bd4ef 8193
c19d1205
ZW
8194 /* Handle a possible width suffix. */
8195 if (end[0] == '.')
b99bd4ef 8196 {
c19d1205
ZW
8197 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
8198 inst.size_req = 4;
8199 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
8200 inst.size_req = 2;
8201 else
8202 return 0;
b99bd4ef 8203
c19d1205 8204 *str = end + 2;
b99bd4ef 8205 }
c19d1205
ZW
8206 else
8207 *str = end;
b99bd4ef 8208
c19d1205
ZW
8209 /* Look for unaffixed or special-case affixed mnemonic. */
8210 opcode = hash_find_n (arm_ops_hsh, base, end - base);
8211 if (opcode)
b99bd4ef 8212 {
c19d1205
ZW
8213 /* step U */
8214 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 8215 {
c19d1205
ZW
8216 inst.cond = COND_ALWAYS;
8217 return opcode;
b99bd4ef 8218 }
b99bd4ef 8219
c19d1205
ZW
8220 if (unified_syntax)
8221 as_warn (_("conditional infixes are deprecated in unified syntax"));
8222 affix = base + (opcode->tag - OT_odd_infix_0);
8223 cond = hash_find_n (arm_cond_hsh, affix, 2);
8224 assert (cond);
b99bd4ef 8225
c19d1205
ZW
8226 inst.cond = cond->value;
8227 return opcode;
8228 }
b99bd4ef 8229
c19d1205
ZW
8230 /* Cannot have a conditional suffix on a mnemonic of less than two
8231 characters. */
8232 if (end - base < 3)
8233 return 0;
b99bd4ef 8234
c19d1205
ZW
8235 /* Look for suffixed mnemonic. */
8236 affix = end - 2;
8237 cond = hash_find_n (arm_cond_hsh, affix, 2);
8238 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
8239 if (opcode && cond)
8240 {
8241 /* step CE */
8242 switch (opcode->tag)
8243 {
e3cb604e
PB
8244 case OT_cinfix3_legacy:
8245 /* Ignore conditional suffixes matched on infix only mnemonics. */
8246 break;
8247
c19d1205
ZW
8248 case OT_cinfix3:
8249 case OT_odd_infix_unc:
8250 if (!unified_syntax)
e3cb604e 8251 return 0;
c19d1205
ZW
8252 /* else fall through */
8253
8254 case OT_csuffix:
8255 case OT_csuf_or_in3:
8256 inst.cond = cond->value;
8257 return opcode;
8258
8259 case OT_unconditional:
8260 case OT_unconditionalF:
dfa9f0d5
PB
8261 if (thumb_mode)
8262 {
8263 inst.cond = cond->value;
8264 }
8265 else
8266 {
8267 /* delayed diagnostic */
8268 inst.error = BAD_COND;
8269 inst.cond = COND_ALWAYS;
8270 }
c19d1205 8271 return opcode;
b99bd4ef 8272
c19d1205
ZW
8273 default:
8274 return 0;
8275 }
8276 }
b99bd4ef 8277
c19d1205
ZW
8278 /* Cannot have a usual-position infix on a mnemonic of less than
8279 six characters (five would be a suffix). */
8280 if (end - base < 6)
8281 return 0;
b99bd4ef 8282
c19d1205
ZW
8283 /* Look for infixed mnemonic in the usual position. */
8284 affix = base + 3;
8285 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
8286 if (!cond)
8287 return 0;
8288
8289 memcpy (save, affix, 2);
8290 memmove (affix, affix + 2, (end - affix) - 2);
8291 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
8292 memmove (affix + 2, affix, (end - affix) - 2);
8293 memcpy (affix, save, 2);
8294
8295 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
8296 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 8297 {
c19d1205 8298 /* step CM */
e3cb604e 8299 if (unified_syntax && opcode->tag == OT_cinfix3)
c19d1205
ZW
8300 as_warn (_("conditional infixes are deprecated in unified syntax"));
8301
8302 inst.cond = cond->value;
8303 return opcode;
b99bd4ef
NC
8304 }
8305
c19d1205 8306 return 0;
b99bd4ef
NC
8307}
8308
c19d1205
ZW
8309void
8310md_assemble (char *str)
b99bd4ef 8311{
c19d1205
ZW
8312 char *p = str;
8313 const struct asm_opcode * opcode;
b99bd4ef 8314
c19d1205
ZW
8315 /* Align the previous label if needed. */
8316 if (last_label_seen != NULL)
b99bd4ef 8317 {
c19d1205
ZW
8318 symbol_set_frag (last_label_seen, frag_now);
8319 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8320 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
8321 }
8322
c19d1205
ZW
8323 memset (&inst, '\0', sizeof (inst));
8324 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 8325
c19d1205
ZW
8326 opcode = opcode_lookup (&p);
8327 if (!opcode)
b99bd4ef 8328 {
c19d1205
ZW
8329 /* It wasn't an instruction, but it might be a register alias of
8330 the form alias .req reg. */
8331 if (!create_register_alias (str, p))
8332 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 8333
b99bd4ef
NC
8334 return;
8335 }
8336
c19d1205 8337 if (thumb_mode)
b99bd4ef 8338 {
e74cfd16 8339 arm_feature_set variant;
8f06b2d8
PB
8340
8341 variant = cpu_variant;
8342 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
8343 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
8344 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 8345 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
8346 if (!opcode->tvariant
8347 || (thumb_mode == 1
8348 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 8349 {
c19d1205 8350 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
8351 return;
8352 }
c19d1205
ZW
8353 if (inst.cond != COND_ALWAYS && !unified_syntax
8354 && opcode->tencode != do_t_branch)
b99bd4ef 8355 {
c19d1205 8356 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
8357 return;
8358 }
8359
e27ec89e
PB
8360 /* Check conditional suffixes. */
8361 if (current_it_mask)
8362 {
8363 int cond;
8364 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
8365 current_it_mask <<= 1;
8366 current_it_mask &= 0x1f;
8367 /* The BKPT instruction is unconditional even in an IT block. */
8368 if (!inst.error
8369 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
8370 {
8371 as_bad (_("incorrect condition in IT block"));
8372 return;
8373 }
e27ec89e
PB
8374 }
8375 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
8376 {
8377 as_bad (_("thumb conditional instrunction not in IT block"));
8378 return;
8379 }
8380
c19d1205
ZW
8381 mapping_state (MAP_THUMB);
8382 inst.instruction = opcode->tvalue;
8383
8384 if (!parse_operands (p, opcode->operands))
8385 opcode->tencode ();
8386
e27ec89e
PB
8387 /* Clear current_it_mask at the end of an IT block. */
8388 if (current_it_mask == 0x10)
8389 current_it_mask = 0;
8390
0110f2b8 8391 if (!(inst.error || inst.relax))
b99bd4ef 8392 {
c19d1205
ZW
8393 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
8394 inst.size = (inst.instruction > 0xffff ? 4 : 2);
8395 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 8396 {
c19d1205 8397 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
8398 return;
8399 }
8400 }
e74cfd16
PB
8401 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8402 *opcode->tvariant);
ee065d83 8403 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
e74cfd16 8404 set those bits when Thumb-2 32-bit instuctions are seen. ie.
ee065d83
PB
8405 anything other than bl/blx.
8406 This is overly pessimistic for relaxable instructions. */
8407 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
8408 || inst.relax)
e74cfd16
PB
8409 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8410 arm_ext_v6t2);
c19d1205
ZW
8411 }
8412 else
8413 {
8414 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
8415 if (!opcode->avariant ||
8416 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 8417 {
c19d1205
ZW
8418 as_bad (_("selected processor does not support `%s'"), str);
8419 return;
b99bd4ef 8420 }
c19d1205 8421 if (inst.size_req)
b99bd4ef 8422 {
c19d1205
ZW
8423 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
8424 return;
b99bd4ef
NC
8425 }
8426
c19d1205
ZW
8427 mapping_state (MAP_ARM);
8428 inst.instruction = opcode->avalue;
8429 if (opcode->tag == OT_unconditionalF)
8430 inst.instruction |= 0xF << 28;
8431 else
8432 inst.instruction |= inst.cond << 28;
8433 inst.size = INSN_SIZE;
8434 if (!parse_operands (p, opcode->operands))
8435 opcode->aencode ();
ee065d83
PB
8436 /* Arm mode bx is marked as both v4T and v5 because it's still required
8437 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
8438 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
8439 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
8440 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 8441 else
e74cfd16
PB
8442 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8443 *opcode->avariant);
b99bd4ef 8444 }
c19d1205
ZW
8445 output_inst (str);
8446}
b99bd4ef 8447
c19d1205
ZW
8448/* Various frobbings of labels and their addresses. */
8449
8450void
8451arm_start_line_hook (void)
8452{
8453 last_label_seen = NULL;
b99bd4ef
NC
8454}
8455
c19d1205
ZW
8456void
8457arm_frob_label (symbolS * sym)
b99bd4ef 8458{
c19d1205 8459 last_label_seen = sym;
b99bd4ef 8460
c19d1205 8461 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 8462
c19d1205
ZW
8463#if defined OBJ_COFF || defined OBJ_ELF
8464 ARM_SET_INTERWORK (sym, support_interwork);
8465#endif
b99bd4ef 8466
c19d1205
ZW
8467 /* Note - do not allow local symbols (.Lxxx) to be labeled
8468 as Thumb functions. This is because these labels, whilst
8469 they exist inside Thumb code, are not the entry points for
8470 possible ARM->Thumb calls. Also, these labels can be used
8471 as part of a computed goto or switch statement. eg gcc
8472 can generate code that looks like this:
b99bd4ef 8473
c19d1205
ZW
8474 ldr r2, [pc, .Laaa]
8475 lsl r3, r3, #2
8476 ldr r2, [r3, r2]
8477 mov pc, r2
b99bd4ef 8478
c19d1205
ZW
8479 .Lbbb: .word .Lxxx
8480 .Lccc: .word .Lyyy
8481 ..etc...
8482 .Laaa: .word Lbbb
b99bd4ef 8483
c19d1205
ZW
8484 The first instruction loads the address of the jump table.
8485 The second instruction converts a table index into a byte offset.
8486 The third instruction gets the jump address out of the table.
8487 The fourth instruction performs the jump.
b99bd4ef 8488
c19d1205
ZW
8489 If the address stored at .Laaa is that of a symbol which has the
8490 Thumb_Func bit set, then the linker will arrange for this address
8491 to have the bottom bit set, which in turn would mean that the
8492 address computation performed by the third instruction would end
8493 up with the bottom bit set. Since the ARM is capable of unaligned
8494 word loads, the instruction would then load the incorrect address
8495 out of the jump table, and chaos would ensue. */
8496 if (label_is_thumb_function_name
8497 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
8498 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 8499 {
c19d1205
ZW
8500 /* When the address of a Thumb function is taken the bottom
8501 bit of that address should be set. This will allow
8502 interworking between Arm and Thumb functions to work
8503 correctly. */
b99bd4ef 8504
c19d1205 8505 THUMB_SET_FUNC (sym, 1);
b99bd4ef 8506
c19d1205 8507 label_is_thumb_function_name = FALSE;
b99bd4ef 8508 }
07a53e5c
RH
8509
8510#ifdef OBJ_ELF
8511 dwarf2_emit_label (sym);
8512#endif
b99bd4ef
NC
8513}
8514
c19d1205
ZW
8515int
8516arm_data_in_code (void)
b99bd4ef 8517{
c19d1205 8518 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 8519 {
c19d1205
ZW
8520 *input_line_pointer = '/';
8521 input_line_pointer += 5;
8522 *input_line_pointer = 0;
8523 return 1;
b99bd4ef
NC
8524 }
8525
c19d1205 8526 return 0;
b99bd4ef
NC
8527}
8528
c19d1205
ZW
8529char *
8530arm_canonicalize_symbol_name (char * name)
b99bd4ef 8531{
c19d1205 8532 int len;
b99bd4ef 8533
c19d1205
ZW
8534 if (thumb_mode && (len = strlen (name)) > 5
8535 && streq (name + len - 5, "/data"))
8536 *(name + len - 5) = 0;
b99bd4ef 8537
c19d1205 8538 return name;
b99bd4ef 8539}
c19d1205
ZW
8540\f
8541/* Table of all register names defined by default. The user can
8542 define additional names with .req. Note that all register names
8543 should appear in both upper and lowercase variants. Some registers
8544 also have mixed-case names. */
b99bd4ef 8545
c19d1205
ZW
8546#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
8547#define REGNUM(p,n,t) REGDEF(p##n, n, t)
8548#define REGSET(p,t) \
8549 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8550 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8551 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8552 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 8553
c19d1205 8554static const struct reg_entry reg_names[] =
7ed4c4c5 8555{
c19d1205
ZW
8556 /* ARM integer registers. */
8557 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 8558
c19d1205
ZW
8559 /* ATPCS synonyms. */
8560 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
8561 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
8562 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 8563
c19d1205
ZW
8564 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
8565 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
8566 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 8567
c19d1205
ZW
8568 /* Well-known aliases. */
8569 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
8570 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
8571
8572 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
8573 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
8574
8575 /* Coprocessor numbers. */
8576 REGSET(p, CP), REGSET(P, CP),
8577
8578 /* Coprocessor register numbers. The "cr" variants are for backward
8579 compatibility. */
8580 REGSET(c, CN), REGSET(C, CN),
8581 REGSET(cr, CN), REGSET(CR, CN),
8582
8583 /* FPA registers. */
8584 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
8585 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
8586
8587 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
8588 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
8589
8590 /* VFP SP registers. */
8591 REGSET(s,VFS),
8592 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
8593 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
8594 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
8595 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
8596
8597 REGSET(S,VFS),
8598 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
8599 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
8600 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
8601 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
8602
8603 /* VFP DP Registers. */
8604 REGSET(d,VFD), REGSET(D,VFS),
8605
8606 /* VFP control registers. */
8607 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
8608 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
8609
8610 /* Maverick DSP coprocessor registers. */
8611 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8612 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8613
8614 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8615 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8616 REGDEF(dspsc,0,DSPSC),
8617
8618 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8619 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8620 REGDEF(DSPSC,0,DSPSC),
8621
8622 /* iWMMXt data registers - p0, c0-15. */
8623 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8624
8625 /* iWMMXt control registers - p1, c0-3. */
8626 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8627 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8628 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8629 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8630
8631 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8632 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8633 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8634 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8635 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8636
8637 /* XScale accumulator registers. */
8638 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8639};
8640#undef REGDEF
8641#undef REGNUM
8642#undef REGSET
7ed4c4c5 8643
c19d1205
ZW
8644/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8645 within psr_required_here. */
8646static const struct asm_psr psrs[] =
8647{
8648 /* Backward compatibility notation. Note that "all" is no longer
8649 truly all possible PSR bits. */
8650 {"all", PSR_c | PSR_f},
8651 {"flg", PSR_f},
8652 {"ctl", PSR_c},
8653
8654 /* Individual flags. */
8655 {"f", PSR_f},
8656 {"c", PSR_c},
8657 {"x", PSR_x},
8658 {"s", PSR_s},
8659 /* Combinations of flags. */
8660 {"fs", PSR_f | PSR_s},
8661 {"fx", PSR_f | PSR_x},
8662 {"fc", PSR_f | PSR_c},
8663 {"sf", PSR_s | PSR_f},
8664 {"sx", PSR_s | PSR_x},
8665 {"sc", PSR_s | PSR_c},
8666 {"xf", PSR_x | PSR_f},
8667 {"xs", PSR_x | PSR_s},
8668 {"xc", PSR_x | PSR_c},
8669 {"cf", PSR_c | PSR_f},
8670 {"cs", PSR_c | PSR_s},
8671 {"cx", PSR_c | PSR_x},
8672 {"fsx", PSR_f | PSR_s | PSR_x},
8673 {"fsc", PSR_f | PSR_s | PSR_c},
8674 {"fxs", PSR_f | PSR_x | PSR_s},
8675 {"fxc", PSR_f | PSR_x | PSR_c},
8676 {"fcs", PSR_f | PSR_c | PSR_s},
8677 {"fcx", PSR_f | PSR_c | PSR_x},
8678 {"sfx", PSR_s | PSR_f | PSR_x},
8679 {"sfc", PSR_s | PSR_f | PSR_c},
8680 {"sxf", PSR_s | PSR_x | PSR_f},
8681 {"sxc", PSR_s | PSR_x | PSR_c},
8682 {"scf", PSR_s | PSR_c | PSR_f},
8683 {"scx", PSR_s | PSR_c | PSR_x},
8684 {"xfs", PSR_x | PSR_f | PSR_s},
8685 {"xfc", PSR_x | PSR_f | PSR_c},
8686 {"xsf", PSR_x | PSR_s | PSR_f},
8687 {"xsc", PSR_x | PSR_s | PSR_c},
8688 {"xcf", PSR_x | PSR_c | PSR_f},
8689 {"xcs", PSR_x | PSR_c | PSR_s},
8690 {"cfs", PSR_c | PSR_f | PSR_s},
8691 {"cfx", PSR_c | PSR_f | PSR_x},
8692 {"csf", PSR_c | PSR_s | PSR_f},
8693 {"csx", PSR_c | PSR_s | PSR_x},
8694 {"cxf", PSR_c | PSR_x | PSR_f},
8695 {"cxs", PSR_c | PSR_x | PSR_s},
8696 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8697 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8698 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8699 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8700 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8701 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8702 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8703 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8704 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8705 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8706 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8707 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8708 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8709 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8710 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8711 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8712 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8713 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8714 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8715 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8716 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8717 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8718 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8719 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8720};
8721
62b3e311
PB
8722/* Table of V7M psr names. */
8723static const struct asm_psr v7m_psrs[] =
8724{
8725 {"apsr", 0 },
8726 {"iapsr", 1 },
8727 {"eapsr", 2 },
8728 {"psr", 3 },
8729 {"ipsr", 5 },
8730 {"epsr", 6 },
8731 {"iepsr", 7 },
8732 {"msp", 8 },
8733 {"psp", 9 },
8734 {"primask", 16},
8735 {"basepri", 17},
8736 {"basepri_max", 18},
8737 {"faultmask", 19},
8738 {"control", 20}
8739};
8740
c19d1205
ZW
8741/* Table of all shift-in-operand names. */
8742static const struct asm_shift_name shift_names [] =
b99bd4ef 8743{
c19d1205
ZW
8744 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8745 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8746 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8747 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8748 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8749 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8750};
b99bd4ef 8751
c19d1205
ZW
8752/* Table of all explicit relocation names. */
8753#ifdef OBJ_ELF
8754static struct reloc_entry reloc_names[] =
8755{
8756 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8757 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8758 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8759 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8760 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8761 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8762 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8763 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8764 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8765 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8766 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8767};
8768#endif
b99bd4ef 8769
c19d1205
ZW
8770/* Table of all conditional affixes. 0xF is not defined as a condition code. */
8771static const struct asm_cond conds[] =
8772{
8773 {"eq", 0x0},
8774 {"ne", 0x1},
8775 {"cs", 0x2}, {"hs", 0x2},
8776 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8777 {"mi", 0x4},
8778 {"pl", 0x5},
8779 {"vs", 0x6},
8780 {"vc", 0x7},
8781 {"hi", 0x8},
8782 {"ls", 0x9},
8783 {"ge", 0xa},
8784 {"lt", 0xb},
8785 {"gt", 0xc},
8786 {"le", 0xd},
8787 {"al", 0xe}
8788};
bfae80f2 8789
62b3e311
PB
8790static struct asm_barrier_opt barrier_opt_names[] =
8791{
8792 { "sy", 0xf },
8793 { "un", 0x7 },
8794 { "st", 0xe },
8795 { "unst", 0x6 }
8796};
8797
c19d1205
ZW
8798/* Table of ARM-format instructions. */
8799
8800/* Macros for gluing together operand strings. N.B. In all cases
8801 other than OPS0, the trailing OP_stop comes from default
8802 zero-initialization of the unspecified elements of the array. */
8803#define OPS0() { OP_stop, }
8804#define OPS1(a) { OP_##a, }
8805#define OPS2(a,b) { OP_##a,OP_##b, }
8806#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8807#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8808#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8809#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8810
8811/* These macros abstract out the exact format of the mnemonic table and
8812 save some repeated characters. */
8813
8814/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8815#define TxCE(mnem, op, top, nops, ops, ae, te) \
8816 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 8817 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8818
8819/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8820 a T_MNEM_xyz enumerator. */
8821#define TCE(mnem, aop, top, nops, ops, ae, te) \
8822 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8823#define tCE(mnem, aop, top, nops, ops, ae, te) \
8824 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8825
8826/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8827 infix after the third character. */
8828#define TxC3(mnem, op, top, nops, ops, ae, te) \
8829 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 8830 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8831#define TC3(mnem, aop, top, nops, ops, ae, te) \
8832 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8833#define tC3(mnem, aop, top, nops, ops, ae, te) \
8834 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8835
8836/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8837 appear in the condition table. */
8838#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8839 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 8840 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8841
8842#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8843 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8844 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8845 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8846 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8847 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8848 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8849 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8850 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8851 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8852 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8853 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8854 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8855 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8856 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8857 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8858 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8859 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8860 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8861 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8862
8863#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8864 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8865#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8866 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8867
8868/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
8869 field is still 0xE. Many of the Thumb variants can be executed
8870 conditionally, so this is checked separately. */
c19d1205
ZW
8871#define TUE(mnem, op, top, nops, ops, ae, te) \
8872 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8873 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8874
8875/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8876 condition code field. */
8877#define TUF(mnem, op, top, nops, ops, ae, te) \
8878 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8879 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8880
8881/* ARM-only variants of all the above. */
6a86118a
NC
8882#define CE(mnem, op, nops, ops, ae) \
8883 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8884
8885#define C3(mnem, op, nops, ops, ae) \
8886 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8887
e3cb604e
PB
8888/* Legacy mnemonics that always have conditional infix after the third
8889 character. */
8890#define CL(mnem, op, nops, ops, ae) \
8891 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8892 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8893
8f06b2d8
PB
8894/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
8895#define cCE(mnem, op, nops, ops, ae) \
8896 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8897
e3cb604e
PB
8898/* Legacy coprocessor instructions where conditional infix and conditional
8899 suffix are ambiguous. For consistency this includes all FPA instructions,
8900 not just the potentially ambiguous ones. */
8901#define cCL(mnem, op, nops, ops, ae) \
8902 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8903 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8904
8905/* Coprocessor, takes either a suffix or a position-3 infix
8906 (for an FPA corner case). */
8907#define C3E(mnem, op, nops, ops, ae) \
8908 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
8909 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 8910
6a86118a
NC
8911#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8912 { #m1 #m2 #m3, OPS##nops ops, \
8913 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8914 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8915
8916#define CM(m1, m2, op, nops, ops, ae) \
8917 xCM_(m1, , m2, op, nops, ops, ae), \
8918 xCM_(m1, eq, m2, op, nops, ops, ae), \
8919 xCM_(m1, ne, m2, op, nops, ops, ae), \
8920 xCM_(m1, cs, m2, op, nops, ops, ae), \
8921 xCM_(m1, hs, m2, op, nops, ops, ae), \
8922 xCM_(m1, cc, m2, op, nops, ops, ae), \
8923 xCM_(m1, ul, m2, op, nops, ops, ae), \
8924 xCM_(m1, lo, m2, op, nops, ops, ae), \
8925 xCM_(m1, mi, m2, op, nops, ops, ae), \
8926 xCM_(m1, pl, m2, op, nops, ops, ae), \
8927 xCM_(m1, vs, m2, op, nops, ops, ae), \
8928 xCM_(m1, vc, m2, op, nops, ops, ae), \
8929 xCM_(m1, hi, m2, op, nops, ops, ae), \
8930 xCM_(m1, ls, m2, op, nops, ops, ae), \
8931 xCM_(m1, ge, m2, op, nops, ops, ae), \
8932 xCM_(m1, lt, m2, op, nops, ops, ae), \
8933 xCM_(m1, gt, m2, op, nops, ops, ae), \
8934 xCM_(m1, le, m2, op, nops, ops, ae), \
8935 xCM_(m1, al, m2, op, nops, ops, ae)
8936
8937#define UE(mnem, op, nops, ops, ae) \
8938 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8939
8940#define UF(mnem, op, nops, ops, ae) \
8941 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8942
c19d1205
ZW
8943#define do_0 0
8944
8945/* Thumb-only, unconditional. */
8946#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8947
c19d1205 8948static const struct asm_opcode insns[] =
bfae80f2 8949{
e74cfd16
PB
8950#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
8951#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
8952 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8953 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8954 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8955 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8956 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8957 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8958 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8959 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8960 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8961 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8962 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8963 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8964 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8965 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8966 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8967 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8968
8969 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8970 for setting PSR flag bits. They are obsolete in V6 and do not
8971 have Thumb equivalents. */
8972 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8973 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8974 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205
ZW
8975 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8976 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 8977 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205
ZW
8978 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8979 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8980 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
8981
8982 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8983 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8984 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8985 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8986
8987 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8988 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8989 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8990 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8991
f5208ef2 8992 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8993 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8994 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 8995 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8996 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8997 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8998
8999 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 9000 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 9001 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 9002 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 9003
c19d1205 9004 /* Pseudo ops. */
e9f89963 9005 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
9006 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
9007 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
9008
9009 /* Thumb-compatibility pseudo ops. */
9010 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
9011 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
9012 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
9013 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
9014 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 9015 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
9016 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
9017 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
9018 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
9019 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
9020 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
9021 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
9022
9023#undef THUMB_VARIANT
e74cfd16 9024#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 9025 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
9026
9027 /* V1 instructions with no Thumb analogue prior to V6T2. */
9028#undef THUMB_VARIANT
e74cfd16 9029#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9030 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
9031 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
9032 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
9033 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 9034 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
9035
9036 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 9037 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 9038 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 9039 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 9040
9c3c69f2
PB
9041 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9042 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 9043
9c3c69f2
PB
9044 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9045 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
9046
9047 /* V1 instructions with no Thumb analogue at all. */
9048 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
9049 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
9050
9051 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
9052 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
9053 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
9054 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
9055 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
9056 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
9057 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
9058 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
9059
9060#undef ARM_VARIANT
e74cfd16 9061#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 9062#undef THUMB_VARIANT
e74cfd16 9063#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
9064 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9065 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9066
9067#undef THUMB_VARIANT
e74cfd16 9068#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9069 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9070 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
9071
9072 /* Generic coprocessor instructions. */
9073 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9074 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9075 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9076 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9077 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9078 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9079 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9080
9081#undef ARM_VARIANT
e74cfd16 9082#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
9083 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9084 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9085
9086#undef ARM_VARIANT
e74cfd16 9087#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
c19d1205
ZW
9088 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
9089 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
9090
9091#undef ARM_VARIANT
e74cfd16 9092#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
9093 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9094 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9095 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9096 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9097 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9098 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9099 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9100 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9101
9102#undef ARM_VARIANT
e74cfd16 9103#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 9104#undef THUMB_VARIANT
e74cfd16 9105#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
9106 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
9107 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
9108 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9109 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9110 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9111 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9112
9113#undef ARM_VARIANT
e74cfd16 9114#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
9115 /* ARM Architecture 4T. */
9116 /* Note: bx (and blx) are required on V5, even if the processor does
9117 not support Thumb. */
9118 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
9119
9120#undef ARM_VARIANT
e74cfd16 9121#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 9122#undef THUMB_VARIANT
e74cfd16 9123#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
9124 /* Note: blx has 2 variants; the .value coded here is for
9125 BLX(2). Only this variant has conditional execution. */
9126 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
9127 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
9128
9129#undef THUMB_VARIANT
e74cfd16 9130#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9131 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
9132 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9133 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9134 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9135 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9136 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9137 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9138 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9139
9140#undef ARM_VARIANT
e74cfd16 9141#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
9142 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9143 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9144 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9145 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9146
9147 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9148 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9149
9150 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9151 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9152 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9153 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9154
9155 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9156 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9157 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9158 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9159
9160 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9161 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9162
9163 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9164 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9165 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9166 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9167
9168#undef ARM_VARIANT
e74cfd16 9169#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205
ZW
9170 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
9171 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9172 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9173
9174 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9175 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9176
9177#undef ARM_VARIANT
e74cfd16 9178#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
9179 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
9180
9181#undef ARM_VARIANT
e74cfd16 9182#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 9183#undef THUMB_VARIANT
e74cfd16 9184#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
9185 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
9186 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
9187 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9188 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9189 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9190 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9191 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9192 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9193 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9194 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
9195
9196#undef THUMB_VARIANT
e74cfd16 9197#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9198 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
9199 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9200 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
9201
9202 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
9203 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
9204
9205/* ARM V6 not included in V7M (eg. integer SIMD). */
9206#undef THUMB_VARIANT
9207#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 9208 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
9209 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
9210 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
9211 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9212 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9213 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9214 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9215 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9216 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9217 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9218 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9219 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9220 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9221 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9222 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9223 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9224 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9225 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9226 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9227 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9228 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9229 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9230 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9231 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9232 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9233 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9234 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9235 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9236 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9237 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9238 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9239 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9240 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9241 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9242 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9243 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9244 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9245 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9246 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9247 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9248 UF(rfeib, 9900a00, 1, (RRw), rfe),
9249 UF(rfeda, 8100a00, 1, (RRw), rfe),
9250 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9251 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9252 UF(rfefa, 9900a00, 1, (RRw), rfe),
9253 UF(rfeea, 8100a00, 1, (RRw), rfe),
9254 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9255 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9256 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9257 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9258 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9259 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9260 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9261 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9262 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 9263 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
9264 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9265 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9266 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9267 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9268 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9269 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9270 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9271 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9272 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9273 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9274 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9275 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9276 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9277 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9278 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9279 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9280 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9281 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9282 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
9283 UF(srsib, 9cd0500, 1, (I31w), srs),
9284 UF(srsda, 84d0500, 1, (I31w), srs),
9285 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
c19d1205
ZW
9286 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
9287 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
9288 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
9289 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9290 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
9291 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
9292
9293#undef ARM_VARIANT
e74cfd16 9294#define ARM_VARIANT &arm_ext_v6k
c19d1205 9295#undef THUMB_VARIANT
e74cfd16 9296#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
9297 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
9298 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
9299 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
9300 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
9301
ebdca51a
PB
9302#undef THUMB_VARIANT
9303#define THUMB_VARIANT &arm_ext_v6_notm
9304 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
9305 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
9306
c19d1205 9307#undef THUMB_VARIANT
e74cfd16 9308#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9309 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
9310 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
9311 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
9312 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
9313 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
9314
9315#undef ARM_VARIANT
e74cfd16 9316#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 9317 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
9318
9319#undef ARM_VARIANT
e74cfd16 9320#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
9321 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
9322 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
9323 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9324 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9325
9326 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9327 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
9328 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
9329 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
9330
9331 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9332 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9333 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9334 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9335
9336 UT(cbnz, b900, 2, (RR, EXP), t_czb),
9337 UT(cbz, b100, 2, (RR, EXP), t_czb),
9338 /* ARM does not really have an IT instruction. */
9339 TUE(it, 0, bf08, 1, (COND), it, t_it),
9340 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
9341 TUE(ite, 0, bf04, 1, (COND), it, t_it),
9342 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
9343 TUE(itet, 0, bf06, 1, (COND), it, t_it),
9344 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
9345 TUE(itee, 0, bf02, 1, (COND), it, t_it),
9346 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
9347 TUE(itett, 0, bf07, 1, (COND), it, t_it),
9348 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
9349 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
9350 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
9351 TUE(itete, 0, bf05, 1, (COND), it, t_it),
9352 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
9353 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
9354
92e90b6e
PB
9355 /* Thumb2 only instructions. */
9356#undef ARM_VARIANT
e74cfd16 9357#define ARM_VARIANT NULL
92e90b6e
PB
9358
9359 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9360 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9361 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
9362 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
9363
62b3e311
PB
9364 /* Thumb-2 hardware division instructions (R and M profiles only). */
9365#undef THUMB_VARIANT
9366#define THUMB_VARIANT &arm_ext_div
9367 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
9368 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
9369
9370 /* ARM V7 instructions. */
9371#undef ARM_VARIANT
9372#define ARM_VARIANT &arm_ext_v7
9373#undef THUMB_VARIANT
9374#define THUMB_VARIANT &arm_ext_v7
9375 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
9376 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
9377 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
9378 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
9379 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
9380
c19d1205 9381#undef ARM_VARIANT
e74cfd16 9382#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
9383 cCE(wfs, e200110, 1, (RR), rd),
9384 cCE(rfs, e300110, 1, (RR), rd),
9385 cCE(wfc, e400110, 1, (RR), rd),
9386 cCE(rfc, e500110, 1, (RR), rd),
9387
e3cb604e
PB
9388 cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
9389 cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
9390 cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
9391 cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
9392
9393 cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
9394 cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
9395 cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
9396 cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
9397
9398 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
9399 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
9400 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
9401 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
9402 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
9403 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
9404 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
9405 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
9406 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
9407 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
9408 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
9409 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
9410
9411 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
9412 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
9413 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
9414 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
9415 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
9416 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
9417 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
9418 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
9419 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
9420 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
9421 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
9422 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
9423
9424 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
9425 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
9426 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
9427 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
9428 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
9429 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
9430 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
9431 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
9432 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
9433 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
9434 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
9435 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
9436
9437 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
9438 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
9439 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
9440 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
9441 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
9442 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
9443 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
9444 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
9445 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
9446 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
9447 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
9448 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
9449
9450 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
9451 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
9452 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
9453 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
9454 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
9455 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
9456 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
9457 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
9458 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
9459 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
9460 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
9461 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
9462
9463 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
9464 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
9465 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
9466 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
9467 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
9468 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
9469 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
9470 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
9471 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
9472 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
9473 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
9474 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
9475
9476 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
9477 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
9478 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
9479 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
9480 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
9481 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
9482 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
9483 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
9484 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
9485 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
9486 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
9487 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
9488
9489 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
9490 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
9491 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
9492 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
9493 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
9494 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
9495 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
9496 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
9497 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
9498 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
9499 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
9500 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
9501
9502 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
9503 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
9504 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
9505 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
9506 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
9507 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
9508 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
9509 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
9510 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
9511 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
9512 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
9513 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
9514
9515 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
9516 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
9517 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
9518 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
9519 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
9520 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
9521 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
9522 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
9523 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
9524 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
9525 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
9526 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
9527
9528 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
9529 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
9530 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
9531 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
9532 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
9533 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
9534 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
9535 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
9536 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
9537 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
9538 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
9539 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
9540
9541 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
9542 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
9543 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
9544 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
9545 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
9546 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
9547 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
9548 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
9549 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
9550 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
9551 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
9552 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
9553
9554 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
9555 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
9556 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
9557 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
9558 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
9559 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
9560 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
9561 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
9562 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
9563 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
9564 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
9565 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
9566
9567 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
9568 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
9569 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
9570 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
9571 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
9572 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
9573 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
9574 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
9575 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
9576 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
9577 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
9578 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
9579
9580 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
9581 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
9582 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
9583 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
9584 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
9585 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
9586 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
9587 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
9588 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
9589 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
9590 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
9591 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
9592
9593 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
9594 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
9595 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
9596 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
9597 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
9598 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
9599 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
9600 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
9601 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
9602 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
9603 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
9604 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
9605
9606 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
9607 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
9608 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
9609 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
9610 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
9611 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9612 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9613 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9614 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
9615 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
9616 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
9617 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
9618
9619 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
9620 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
9621 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
9622 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
9623 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
9624 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9625 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9626 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9627 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
9628 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
9629 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
9630 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
9631
9632 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
9633 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
9634 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
9635 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
9636 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
9637 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9638 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9639 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9640 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
9641 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
9642 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
9643 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
9644
9645 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
9646 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
9647 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
9648 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
9649 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
9650 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9651 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9652 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9653 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
9654 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
9655 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
9656 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
9657
9658 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
9659 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
9660 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
9661 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
9662 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
9663 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9664 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9665 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9666 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
9667 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
9668 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
9669 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
9670
9671 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
9672 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
9673 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
9674 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
9675 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
9676 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9677 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9678 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9679 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
9680 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
9681 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
9682 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
9683
9684 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9685 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9686 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9687 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9688 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9689 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9690 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9691 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9692 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9693 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9694 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9695 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9696
9697 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9698 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9699 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9700 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9701 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9702 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9703 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9704 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9705 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9706 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9707 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9708 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9709
9710 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9711 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9712 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9713 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9714 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9715 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9716 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9717 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9718 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9719 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9720 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9721 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9722
9723 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9724 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9725 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9726 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9727 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9728 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9729 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9730 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9731 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9732 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9733 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9734 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9735
9736 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9737 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9738 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9739 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9740 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9741 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9742 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9743 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9744 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9745 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9746 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9747 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9748
9749 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9750 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9751 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9752 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9753 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9754 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9755 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9756 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9757 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9758 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9759 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9760 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9761
9762 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9763 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9764 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9765 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9766 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9767 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9768 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9769 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9770 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9771 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9772 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9773 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
9774
9775 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 9776 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 9777 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
9778 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9779
e3cb604e
PB
9780 cCL(flts, e000110, 2, (RF, RR), rn_rd),
9781 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
9782 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
9783 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
9784 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
9785 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9786 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9787 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9788 cCL(flte, e080110, 2, (RF, RR), rn_rd),
9789 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
9790 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
9791 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 9792
c19d1205
ZW
9793 /* The implementation of the FIX instruction is broken on some
9794 assemblers, in that it accepts a precision specifier as well as a
9795 rounding specifier, despite the fact that this is meaningless.
9796 To be more compatible, we accept it as well, though of course it
9797 does not set any bits. */
8f06b2d8 9798 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
9799 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
9800 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
9801 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
9802 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
9803 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
9804 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
9805 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
9806 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
9807 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
9808 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
9809 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
9810 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 9811
c19d1205
ZW
9812 /* Instructions that were new with the real FPA, call them V2. */
9813#undef ARM_VARIANT
e74cfd16 9814#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 9815 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9816 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9817 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 9818 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9819 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9820 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
9821
9822#undef ARM_VARIANT
e74cfd16 9823#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 9824 /* Moves and type conversions. */
8f06b2d8
PB
9825 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9826 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9827 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9828 cCE(fmstat, ef1fa10, 0, (), noargs),
9829 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9830 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9831 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9832 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9833 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9834 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9835 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9836 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
9837
9838 /* Memory operations. */
8f06b2d8
PB
9839 cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9840 cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9841 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9842 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9843 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9844 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9845 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9846 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9847 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9848 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9849 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9850 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9851 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9852 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9853 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9854 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9855 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9856 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 9857
c19d1205 9858 /* Monadic operations. */
8f06b2d8
PB
9859 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9860 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9861 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
9862
9863 /* Dyadic operations. */
8f06b2d8
PB
9864 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9865 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9866 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9867 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9868 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9869 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9870 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9871 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9872 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 9873
c19d1205 9874 /* Comparisons. */
8f06b2d8
PB
9875 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9876 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9877 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9878 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 9879
c19d1205 9880#undef ARM_VARIANT
e74cfd16 9881#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 9882 /* Moves and type conversions. */
8f06b2d8
PB
9883 cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9884 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9885 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9886 cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9887 cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9888 cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9889 cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9890 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9891 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9892 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9893 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9894 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9895 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
9896
9897 /* Memory operations. */
8f06b2d8
PB
9898 cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9899 cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9900 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9901 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9902 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9903 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9904 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9905 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9906 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9907 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9908
c19d1205 9909 /* Monadic operations. */
8f06b2d8
PB
9910 cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9911 cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9912 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
c19d1205
ZW
9913
9914 /* Dyadic operations. */
8f06b2d8
PB
9915 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9916 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9917 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9918 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9919 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9920 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9921 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9922 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9923 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9924
c19d1205 9925 /* Comparisons. */
8f06b2d8
PB
9926 cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9927 cCE(fcmpzd, eb50b40, 1, (RVD), rd),
9928 cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9929 cCE(fcmpezd, eb50bc0, 1, (RVD), rd),
c19d1205
ZW
9930
9931#undef ARM_VARIANT
e74cfd16 9932#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
9933 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9934 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9935 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9936 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
c19d1205
ZW
9937
9938#undef ARM_VARIANT
e74cfd16 9939#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
9940 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9941 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9942 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9943 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9944 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9945 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9946 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9947 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
9948
9949#undef ARM_VARIANT
e74cfd16 9950#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
9951 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9952 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9953 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9954 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9955 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9956 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9957 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9958 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9959 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9960 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9961 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9962 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9963 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9964 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9965 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9966 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9967 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9968 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9969 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9970 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9971 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9972 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9973 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9974 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9975 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9976 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9977 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9978 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9979 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9980 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9981 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9982 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9983 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9984 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9985 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9986 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9987 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9988 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9989 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9990 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9991 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9992 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9993 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9994 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9995 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9996 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9997 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9998 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9999 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10000 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10001 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10002 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10003 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10004 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10005 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10006 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10007 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10008 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10009 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10010 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10011 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10012 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10013 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10014 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10015 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10016 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10017 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10018 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10019 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
10020 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
10021 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10022 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10023 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10024 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10025 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10026 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10027 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10028 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10029 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10030 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10031 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10032 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10033 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10034 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10035 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10036 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10037 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10038 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10039 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
10040 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10041 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10042 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10043 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10044 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10045 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10046 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10047 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10048 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10049 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10050 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10051 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10052 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10053 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10054 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10055 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10056 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10057 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10058 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10059 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10060 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10061 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
10062 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10063 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10064 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10065 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10066 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10067 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10068 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10069 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10070 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10071 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10072 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10073 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10074 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10075 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10076 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10077 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10078 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10079 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10080 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10081 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10082 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
10083 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
10084 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10085 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10086 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10087 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10088 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10089 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10090 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10091 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10092 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10093 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
10094 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
10095 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
10096 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
10097 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
10098 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
10099 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10100 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10101 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10102 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
10103 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
10104 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
10105 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
10106 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
10107 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
10108 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10109 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10110 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10111 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10112 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205
ZW
10113
10114#undef ARM_VARIANT
e74cfd16 10115#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
8f06b2d8
PB
10116 cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
10117 cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
10118 cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
10119 cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
10120 cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
10121 cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
10122 cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
10123 cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
10124 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
10125 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
10126 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
10127 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
10128 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
10129 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
10130 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
10131 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
10132 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
10133 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
10134 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
10135 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
10136 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
10137 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
10138 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
10139 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
10140 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
10141 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
10142 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
10143 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
10144 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
10145 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
10146 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
10147 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
10148 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
10149 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
10150 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
10151 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
10152 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
10153 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
10154 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
10155 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
10156 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
10157 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
10158 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
10159 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
10160 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
10161 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
10162 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
10163 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
10164 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
10165 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
10166 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
10167 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
10168 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
10169 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
10170 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
10171 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
10172 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
10173 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
10174 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
10175 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
10176 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
10177 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
10178 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
10179 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
10180 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10181 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10182 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10183 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10184 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10185 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10186 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10187 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10188 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10189 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10190 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
10191 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
10192};
10193#undef ARM_VARIANT
10194#undef THUMB_VARIANT
10195#undef TCE
10196#undef TCM
10197#undef TUE
10198#undef TUF
10199#undef TCC
8f06b2d8 10200#undef cCE
e3cb604e
PB
10201#undef cCL
10202#undef C3E
c19d1205
ZW
10203#undef CE
10204#undef CM
10205#undef UE
10206#undef UF
10207#undef UT
10208#undef OPS0
10209#undef OPS1
10210#undef OPS2
10211#undef OPS3
10212#undef OPS4
10213#undef OPS5
10214#undef OPS6
10215#undef do_0
10216\f
10217/* MD interface: bits in the object file. */
bfae80f2 10218
c19d1205
ZW
10219/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
10220 for use in the a.out file, and stores them in the array pointed to by buf.
10221 This knows about the endian-ness of the target machine and does
10222 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
10223 2 (short) and 4 (long) Floating numbers are put out as a series of
10224 LITTLENUMS (shorts, here at least). */
b99bd4ef 10225
c19d1205
ZW
10226void
10227md_number_to_chars (char * buf, valueT val, int n)
10228{
10229 if (target_big_endian)
10230 number_to_chars_bigendian (buf, val, n);
10231 else
10232 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
10233}
10234
c19d1205
ZW
10235static valueT
10236md_chars_to_number (char * buf, int n)
bfae80f2 10237{
c19d1205
ZW
10238 valueT result = 0;
10239 unsigned char * where = (unsigned char *) buf;
bfae80f2 10240
c19d1205 10241 if (target_big_endian)
b99bd4ef 10242 {
c19d1205
ZW
10243 while (n--)
10244 {
10245 result <<= 8;
10246 result |= (*where++ & 255);
10247 }
b99bd4ef 10248 }
c19d1205 10249 else
b99bd4ef 10250 {
c19d1205
ZW
10251 while (n--)
10252 {
10253 result <<= 8;
10254 result |= (where[n] & 255);
10255 }
bfae80f2 10256 }
b99bd4ef 10257
c19d1205 10258 return result;
bfae80f2 10259}
b99bd4ef 10260
c19d1205 10261/* MD interface: Sections. */
b99bd4ef 10262
0110f2b8
PB
10263/* Estimate the size of a frag before relaxing. Assume everything fits in
10264 2 bytes. */
10265
c19d1205 10266int
0110f2b8 10267md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
10268 segT segtype ATTRIBUTE_UNUSED)
10269{
0110f2b8
PB
10270 fragp->fr_var = 2;
10271 return 2;
10272}
10273
10274/* Convert a machine dependent frag. */
10275
10276void
10277md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
10278{
10279 unsigned long insn;
10280 unsigned long old_op;
10281 char *buf;
10282 expressionS exp;
10283 fixS *fixp;
10284 int reloc_type;
10285 int pc_rel;
10286 int opcode;
10287
10288 buf = fragp->fr_literal + fragp->fr_fix;
10289
10290 old_op = bfd_get_16(abfd, buf);
10291 if (fragp->fr_symbol) {
10292 exp.X_op = O_symbol;
10293 exp.X_add_symbol = fragp->fr_symbol;
10294 } else {
10295 exp.X_op = O_constant;
10296 }
10297 exp.X_add_number = fragp->fr_offset;
10298 opcode = fragp->fr_subtype;
10299 switch (opcode)
10300 {
10301 case T_MNEM_ldr_pc:
10302 case T_MNEM_ldr_pc2:
10303 case T_MNEM_ldr_sp:
10304 case T_MNEM_str_sp:
10305 case T_MNEM_ldr:
10306 case T_MNEM_ldrb:
10307 case T_MNEM_ldrh:
10308 case T_MNEM_str:
10309 case T_MNEM_strb:
10310 case T_MNEM_strh:
10311 if (fragp->fr_var == 4)
10312 {
10313 insn = THUMB_OP32(opcode);
10314 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
10315 {
10316 insn |= (old_op & 0x700) << 4;
10317 }
10318 else
10319 {
10320 insn |= (old_op & 7) << 12;
10321 insn |= (old_op & 0x38) << 13;
10322 }
10323 insn |= 0x00000c00;
10324 put_thumb32_insn (buf, insn);
10325 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10326 }
10327 else
10328 {
10329 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
10330 }
10331 pc_rel = (opcode == T_MNEM_ldr_pc2);
10332 break;
10333 case T_MNEM_adr:
10334 if (fragp->fr_var == 4)
10335 {
10336 insn = THUMB_OP32 (opcode);
10337 insn |= (old_op & 0xf0) << 4;
10338 put_thumb32_insn (buf, insn);
10339 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
10340 }
10341 else
10342 {
10343 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10344 exp.X_add_number -= 4;
10345 }
10346 pc_rel = 1;
10347 break;
10348 case T_MNEM_mov:
10349 case T_MNEM_movs:
10350 case T_MNEM_cmp:
10351 case T_MNEM_cmn:
10352 if (fragp->fr_var == 4)
10353 {
10354 int r0off = (opcode == T_MNEM_mov
10355 || opcode == T_MNEM_movs) ? 0 : 8;
10356 insn = THUMB_OP32 (opcode);
10357 insn = (insn & 0xe1ffffff) | 0x10000000;
10358 insn |= (old_op & 0x700) << r0off;
10359 put_thumb32_insn (buf, insn);
10360 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10361 }
10362 else
10363 {
10364 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
10365 }
10366 pc_rel = 0;
10367 break;
10368 case T_MNEM_b:
10369 if (fragp->fr_var == 4)
10370 {
10371 insn = THUMB_OP32(opcode);
10372 put_thumb32_insn (buf, insn);
10373 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
10374 }
10375 else
10376 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
10377 pc_rel = 1;
10378 break;
10379 case T_MNEM_bcond:
10380 if (fragp->fr_var == 4)
10381 {
10382 insn = THUMB_OP32(opcode);
10383 insn |= (old_op & 0xf00) << 14;
10384 put_thumb32_insn (buf, insn);
10385 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
10386 }
10387 else
10388 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
10389 pc_rel = 1;
10390 break;
10391 case T_MNEM_add_sp:
10392 case T_MNEM_add_pc:
10393 case T_MNEM_inc_sp:
10394 case T_MNEM_dec_sp:
10395 if (fragp->fr_var == 4)
10396 {
10397 /* ??? Choose between add and addw. */
10398 insn = THUMB_OP32 (opcode);
10399 insn |= (old_op & 0xf0) << 4;
10400 put_thumb32_insn (buf, insn);
10401 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10402 }
10403 else
10404 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10405 pc_rel = 0;
10406 break;
10407
10408 case T_MNEM_addi:
10409 case T_MNEM_addis:
10410 case T_MNEM_subi:
10411 case T_MNEM_subis:
10412 if (fragp->fr_var == 4)
10413 {
10414 insn = THUMB_OP32 (opcode);
10415 insn |= (old_op & 0xf0) << 4;
10416 insn |= (old_op & 0xf) << 16;
10417 put_thumb32_insn (buf, insn);
10418 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10419 }
10420 else
10421 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10422 pc_rel = 0;
10423 break;
10424 default:
10425 abort();
10426 }
10427 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
10428 reloc_type);
10429 fixp->fx_file = fragp->fr_file;
10430 fixp->fx_line = fragp->fr_line;
10431 fragp->fr_fix += fragp->fr_var;
10432}
10433
10434/* Return the size of a relaxable immediate operand instruction.
10435 SHIFT and SIZE specify the form of the allowable immediate. */
10436static int
10437relax_immediate (fragS *fragp, int size, int shift)
10438{
10439 offsetT offset;
10440 offsetT mask;
10441 offsetT low;
10442
10443 /* ??? Should be able to do better than this. */
10444 if (fragp->fr_symbol)
10445 return 4;
10446
10447 low = (1 << shift) - 1;
10448 mask = (1 << (shift + size)) - (1 << shift);
10449 offset = fragp->fr_offset;
10450 /* Force misaligned offsets to 32-bit variant. */
10451 if (offset & low)
10452 return -4;
10453 if (offset & ~mask)
10454 return 4;
10455 return 2;
10456}
10457
10458/* Return the size of a relaxable adr pseudo-instruction or PC-relative
10459 load. */
10460static int
10461relax_adr (fragS *fragp, asection *sec)
10462{
10463 addressT addr;
10464 offsetT val;
10465
10466 /* Assume worst case for symbols not known to be in the same section. */
10467 if (!S_IS_DEFINED(fragp->fr_symbol)
10468 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10469 return 4;
10470
10471 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10472 addr = fragp->fr_address + fragp->fr_fix;
10473 addr = (addr + 4) & ~3;
10474 /* Fix the insn as the 4-byte version if the target address is not
10475 sufficiently aligned. This is prevents an infinite loop when two
10476 instructions have contradictory range/alignment requirements. */
10477 if (val & 3)
10478 return -4;
10479 val -= addr;
10480 if (val < 0 || val > 1020)
10481 return 4;
10482 return 2;
10483}
10484
10485/* Return the size of a relaxable add/sub immediate instruction. */
10486static int
10487relax_addsub (fragS *fragp, asection *sec)
10488{
10489 char *buf;
10490 int op;
10491
10492 buf = fragp->fr_literal + fragp->fr_fix;
10493 op = bfd_get_16(sec->owner, buf);
10494 if ((op & 0xf) == ((op >> 4) & 0xf))
10495 return relax_immediate (fragp, 8, 0);
10496 else
10497 return relax_immediate (fragp, 3, 0);
10498}
10499
10500
10501/* Return the size of a relaxable branch instruction. BITS is the
10502 size of the offset field in the narrow instruction. */
10503
10504static int
10505relax_branch (fragS *fragp, asection *sec, int bits)
10506{
10507 addressT addr;
10508 offsetT val;
10509 offsetT limit;
10510
10511 /* Assume worst case for symbols not known to be in the same section. */
10512 if (!S_IS_DEFINED(fragp->fr_symbol)
10513 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10514 return 4;
10515
10516 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10517 addr = fragp->fr_address + fragp->fr_fix + 4;
10518 val -= addr;
10519
10520 /* Offset is a signed value *2 */
10521 limit = 1 << bits;
10522 if (val >= limit || val < -limit)
10523 return 4;
10524 return 2;
10525}
10526
10527
10528/* Relax a machine dependent frag. This returns the amount by which
10529 the current size of the frag should change. */
10530
10531int
10532arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
10533{
10534 int oldsize;
10535 int newsize;
10536
10537 oldsize = fragp->fr_var;
10538 switch (fragp->fr_subtype)
10539 {
10540 case T_MNEM_ldr_pc2:
10541 newsize = relax_adr(fragp, sec);
10542 break;
10543 case T_MNEM_ldr_pc:
10544 case T_MNEM_ldr_sp:
10545 case T_MNEM_str_sp:
10546 newsize = relax_immediate(fragp, 8, 2);
10547 break;
10548 case T_MNEM_ldr:
10549 case T_MNEM_str:
10550 newsize = relax_immediate(fragp, 5, 2);
10551 break;
10552 case T_MNEM_ldrh:
10553 case T_MNEM_strh:
10554 newsize = relax_immediate(fragp, 5, 1);
10555 break;
10556 case T_MNEM_ldrb:
10557 case T_MNEM_strb:
10558 newsize = relax_immediate(fragp, 5, 0);
10559 break;
10560 case T_MNEM_adr:
10561 newsize = relax_adr(fragp, sec);
10562 break;
10563 case T_MNEM_mov:
10564 case T_MNEM_movs:
10565 case T_MNEM_cmp:
10566 case T_MNEM_cmn:
10567 newsize = relax_immediate(fragp, 8, 0);
10568 break;
10569 case T_MNEM_b:
10570 newsize = relax_branch(fragp, sec, 11);
10571 break;
10572 case T_MNEM_bcond:
10573 newsize = relax_branch(fragp, sec, 8);
10574 break;
10575 case T_MNEM_add_sp:
10576 case T_MNEM_add_pc:
10577 newsize = relax_immediate (fragp, 8, 2);
10578 break;
10579 case T_MNEM_inc_sp:
10580 case T_MNEM_dec_sp:
10581 newsize = relax_immediate (fragp, 7, 2);
10582 break;
10583 case T_MNEM_addi:
10584 case T_MNEM_addis:
10585 case T_MNEM_subi:
10586 case T_MNEM_subis:
10587 newsize = relax_addsub (fragp, sec);
10588 break;
10589 default:
10590 abort();
10591 }
10592 if (newsize < 0)
10593 {
10594 fragp->fr_var = -newsize;
10595 md_convert_frag (sec->owner, sec, fragp);
10596 frag_wane(fragp);
10597 return -(newsize + oldsize);
10598 }
10599 fragp->fr_var = newsize;
10600 return newsize - oldsize;
c19d1205 10601}
b99bd4ef 10602
c19d1205 10603/* Round up a section size to the appropriate boundary. */
b99bd4ef 10604
c19d1205
ZW
10605valueT
10606md_section_align (segT segment ATTRIBUTE_UNUSED,
10607 valueT size)
10608{
10609#ifdef OBJ_ELF
10610 return size;
10611#else
10612 /* Round all sects to multiple of 4. */
10613 return (size + 3) & ~3;
10614#endif
bfae80f2 10615}
b99bd4ef 10616
c19d1205
ZW
10617/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10618 of an rs_align_code fragment. */
10619
10620void
10621arm_handle_align (fragS * fragP)
bfae80f2 10622{
c19d1205
ZW
10623 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
10624 static char const thumb_noop[2] = { 0xc0, 0x46 };
10625 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
10626 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
10627
10628 int bytes, fix, noop_size;
10629 char * p;
10630 const char * noop;
bfae80f2 10631
c19d1205 10632 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
10633 return;
10634
c19d1205
ZW
10635 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
10636 p = fragP->fr_literal + fragP->fr_fix;
10637 fix = 0;
bfae80f2 10638
c19d1205
ZW
10639 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
10640 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 10641
c19d1205 10642 if (fragP->tc_frag_data)
a737bd4d 10643 {
c19d1205
ZW
10644 if (target_big_endian)
10645 noop = thumb_bigend_noop;
10646 else
10647 noop = thumb_noop;
10648 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
10649 }
10650 else
10651 {
c19d1205
ZW
10652 if (target_big_endian)
10653 noop = arm_bigend_noop;
10654 else
10655 noop = arm_noop;
10656 noop_size = sizeof (arm_noop);
7ed4c4c5 10657 }
a737bd4d 10658
c19d1205 10659 if (bytes & (noop_size - 1))
7ed4c4c5 10660 {
c19d1205
ZW
10661 fix = bytes & (noop_size - 1);
10662 memset (p, 0, fix);
10663 p += fix;
10664 bytes -= fix;
a737bd4d 10665 }
a737bd4d 10666
c19d1205 10667 while (bytes >= noop_size)
a737bd4d 10668 {
c19d1205
ZW
10669 memcpy (p, noop, noop_size);
10670 p += noop_size;
10671 bytes -= noop_size;
10672 fix += noop_size;
a737bd4d
NC
10673 }
10674
c19d1205
ZW
10675 fragP->fr_fix += fix;
10676 fragP->fr_var = noop_size;
a737bd4d
NC
10677}
10678
c19d1205
ZW
10679/* Called from md_do_align. Used to create an alignment
10680 frag in a code section. */
10681
10682void
10683arm_frag_align_code (int n, int max)
bfae80f2 10684{
c19d1205 10685 char * p;
7ed4c4c5 10686
c19d1205
ZW
10687 /* We assume that there will never be a requirement
10688 to support alignments greater than 32 bytes. */
10689 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
10690 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 10691
c19d1205
ZW
10692 p = frag_var (rs_align_code,
10693 MAX_MEM_FOR_RS_ALIGN_CODE,
10694 1,
10695 (relax_substateT) max,
10696 (symbolS *) NULL,
10697 (offsetT) n,
10698 (char *) NULL);
10699 *p = 0;
10700}
bfae80f2 10701
c19d1205 10702/* Perform target specific initialisation of a frag. */
bfae80f2 10703
c19d1205
ZW
10704void
10705arm_init_frag (fragS * fragP)
10706{
10707 /* Record whether this frag is in an ARM or a THUMB area. */
10708 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
10709}
10710
c19d1205
ZW
10711#ifdef OBJ_ELF
10712/* When we change sections we need to issue a new mapping symbol. */
10713
10714void
10715arm_elf_change_section (void)
bfae80f2 10716{
c19d1205
ZW
10717 flagword flags;
10718 segment_info_type *seginfo;
bfae80f2 10719
c19d1205
ZW
10720 /* Link an unlinked unwind index table section to the .text section. */
10721 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
10722 && elf_linked_to_section (now_seg) == NULL)
10723 elf_linked_to_section (now_seg) = text_section;
10724
10725 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
10726 return;
10727
c19d1205
ZW
10728 flags = bfd_get_section_flags (stdoutput, now_seg);
10729
10730 /* We can ignore sections that only contain debug info. */
10731 if ((flags & SEC_ALLOC) == 0)
10732 return;
bfae80f2 10733
c19d1205
ZW
10734 seginfo = seg_info (now_seg);
10735 mapstate = seginfo->tc_segment_info_data.mapstate;
10736 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
10737}
10738
c19d1205
ZW
10739int
10740arm_elf_section_type (const char * str, size_t len)
e45d0630 10741{
c19d1205
ZW
10742 if (len == 5 && strncmp (str, "exidx", 5) == 0)
10743 return SHT_ARM_EXIDX;
e45d0630 10744
c19d1205
ZW
10745 return -1;
10746}
10747\f
10748/* Code to deal with unwinding tables. */
e45d0630 10749
c19d1205 10750static void add_unwind_adjustsp (offsetT);
e45d0630 10751
c19d1205 10752/* Cenerate and deferred unwind frame offset. */
e45d0630 10753
bfae80f2 10754static void
c19d1205 10755flush_pending_unwind (void)
bfae80f2 10756{
c19d1205 10757 offsetT offset;
bfae80f2 10758
c19d1205
ZW
10759 offset = unwind.pending_offset;
10760 unwind.pending_offset = 0;
10761 if (offset != 0)
10762 add_unwind_adjustsp (offset);
bfae80f2
RE
10763}
10764
c19d1205
ZW
10765/* Add an opcode to this list for this function. Two-byte opcodes should
10766 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
10767 order. */
10768
bfae80f2 10769static void
c19d1205 10770add_unwind_opcode (valueT op, int length)
bfae80f2 10771{
c19d1205
ZW
10772 /* Add any deferred stack adjustment. */
10773 if (unwind.pending_offset)
10774 flush_pending_unwind ();
bfae80f2 10775
c19d1205 10776 unwind.sp_restored = 0;
bfae80f2 10777
c19d1205 10778 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 10779 {
c19d1205
ZW
10780 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
10781 if (unwind.opcodes)
10782 unwind.opcodes = xrealloc (unwind.opcodes,
10783 unwind.opcode_alloc);
10784 else
10785 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 10786 }
c19d1205 10787 while (length > 0)
bfae80f2 10788 {
c19d1205
ZW
10789 length--;
10790 unwind.opcodes[unwind.opcode_count] = op & 0xff;
10791 op >>= 8;
10792 unwind.opcode_count++;
bfae80f2 10793 }
bfae80f2
RE
10794}
10795
c19d1205
ZW
10796/* Add unwind opcodes to adjust the stack pointer. */
10797
bfae80f2 10798static void
c19d1205 10799add_unwind_adjustsp (offsetT offset)
bfae80f2 10800{
c19d1205 10801 valueT op;
bfae80f2 10802
c19d1205 10803 if (offset > 0x200)
bfae80f2 10804 {
c19d1205
ZW
10805 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
10806 char bytes[5];
10807 int n;
10808 valueT o;
bfae80f2 10809
c19d1205
ZW
10810 /* Long form: 0xb2, uleb128. */
10811 /* This might not fit in a word so add the individual bytes,
10812 remembering the list is built in reverse order. */
10813 o = (valueT) ((offset - 0x204) >> 2);
10814 if (o == 0)
10815 add_unwind_opcode (0, 1);
bfae80f2 10816
c19d1205
ZW
10817 /* Calculate the uleb128 encoding of the offset. */
10818 n = 0;
10819 while (o)
10820 {
10821 bytes[n] = o & 0x7f;
10822 o >>= 7;
10823 if (o)
10824 bytes[n] |= 0x80;
10825 n++;
10826 }
10827 /* Add the insn. */
10828 for (; n; n--)
10829 add_unwind_opcode (bytes[n - 1], 1);
10830 add_unwind_opcode (0xb2, 1);
10831 }
10832 else if (offset > 0x100)
bfae80f2 10833 {
c19d1205
ZW
10834 /* Two short opcodes. */
10835 add_unwind_opcode (0x3f, 1);
10836 op = (offset - 0x104) >> 2;
10837 add_unwind_opcode (op, 1);
bfae80f2 10838 }
c19d1205
ZW
10839 else if (offset > 0)
10840 {
10841 /* Short opcode. */
10842 op = (offset - 4) >> 2;
10843 add_unwind_opcode (op, 1);
10844 }
10845 else if (offset < 0)
bfae80f2 10846 {
c19d1205
ZW
10847 offset = -offset;
10848 while (offset > 0x100)
bfae80f2 10849 {
c19d1205
ZW
10850 add_unwind_opcode (0x7f, 1);
10851 offset -= 0x100;
bfae80f2 10852 }
c19d1205
ZW
10853 op = ((offset - 4) >> 2) | 0x40;
10854 add_unwind_opcode (op, 1);
bfae80f2 10855 }
bfae80f2
RE
10856}
10857
c19d1205
ZW
10858/* Finish the list of unwind opcodes for this function. */
10859static void
10860finish_unwind_opcodes (void)
bfae80f2 10861{
c19d1205 10862 valueT op;
bfae80f2 10863
c19d1205 10864 if (unwind.fp_used)
bfae80f2 10865 {
c19d1205
ZW
10866 /* Adjust sp as neccessary. */
10867 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
10868 flush_pending_unwind ();
bfae80f2 10869
c19d1205
ZW
10870 /* After restoring sp from the frame pointer. */
10871 op = 0x90 | unwind.fp_reg;
10872 add_unwind_opcode (op, 1);
10873 }
10874 else
10875 flush_pending_unwind ();
bfae80f2
RE
10876}
10877
bfae80f2 10878
c19d1205
ZW
10879/* Start an exception table entry. If idx is nonzero this is an index table
10880 entry. */
bfae80f2
RE
10881
10882static void
c19d1205 10883start_unwind_section (const segT text_seg, int idx)
bfae80f2 10884{
c19d1205
ZW
10885 const char * text_name;
10886 const char * prefix;
10887 const char * prefix_once;
10888 const char * group_name;
10889 size_t prefix_len;
10890 size_t text_len;
10891 char * sec_name;
10892 size_t sec_name_len;
10893 int type;
10894 int flags;
10895 int linkonce;
bfae80f2 10896
c19d1205 10897 if (idx)
bfae80f2 10898 {
c19d1205
ZW
10899 prefix = ELF_STRING_ARM_unwind;
10900 prefix_once = ELF_STRING_ARM_unwind_once;
10901 type = SHT_ARM_EXIDX;
bfae80f2 10902 }
c19d1205 10903 else
bfae80f2 10904 {
c19d1205
ZW
10905 prefix = ELF_STRING_ARM_unwind_info;
10906 prefix_once = ELF_STRING_ARM_unwind_info_once;
10907 type = SHT_PROGBITS;
bfae80f2
RE
10908 }
10909
c19d1205
ZW
10910 text_name = segment_name (text_seg);
10911 if (streq (text_name, ".text"))
10912 text_name = "";
10913
10914 if (strncmp (text_name, ".gnu.linkonce.t.",
10915 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 10916 {
c19d1205
ZW
10917 prefix = prefix_once;
10918 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
10919 }
10920
c19d1205
ZW
10921 prefix_len = strlen (prefix);
10922 text_len = strlen (text_name);
10923 sec_name_len = prefix_len + text_len;
10924 sec_name = xmalloc (sec_name_len + 1);
10925 memcpy (sec_name, prefix, prefix_len);
10926 memcpy (sec_name + prefix_len, text_name, text_len);
10927 sec_name[prefix_len + text_len] = '\0';
bfae80f2 10928
c19d1205
ZW
10929 flags = SHF_ALLOC;
10930 linkonce = 0;
10931 group_name = 0;
bfae80f2 10932
c19d1205
ZW
10933 /* Handle COMDAT group. */
10934 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 10935 {
c19d1205
ZW
10936 group_name = elf_group_name (text_seg);
10937 if (group_name == NULL)
10938 {
10939 as_bad ("Group section `%s' has no group signature",
10940 segment_name (text_seg));
10941 ignore_rest_of_line ();
10942 return;
10943 }
10944 flags |= SHF_GROUP;
10945 linkonce = 1;
bfae80f2
RE
10946 }
10947
c19d1205 10948 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 10949
c19d1205
ZW
10950 /* Set the setion link for index tables. */
10951 if (idx)
10952 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
10953}
10954
bfae80f2 10955
c19d1205
ZW
10956/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
10957 personality routine data. Returns zero, or the index table value for
10958 and inline entry. */
10959
10960static valueT
10961create_unwind_entry (int have_data)
bfae80f2 10962{
c19d1205
ZW
10963 int size;
10964 addressT where;
10965 char *ptr;
10966 /* The current word of data. */
10967 valueT data;
10968 /* The number of bytes left in this word. */
10969 int n;
bfae80f2 10970
c19d1205 10971 finish_unwind_opcodes ();
bfae80f2 10972
c19d1205
ZW
10973 /* Remember the current text section. */
10974 unwind.saved_seg = now_seg;
10975 unwind.saved_subseg = now_subseg;
bfae80f2 10976
c19d1205 10977 start_unwind_section (now_seg, 0);
bfae80f2 10978
c19d1205 10979 if (unwind.personality_routine == NULL)
bfae80f2 10980 {
c19d1205
ZW
10981 if (unwind.personality_index == -2)
10982 {
10983 if (have_data)
10984 as_bad (_("handerdata in cantunwind frame"));
10985 return 1; /* EXIDX_CANTUNWIND. */
10986 }
bfae80f2 10987
c19d1205
ZW
10988 /* Use a default personality routine if none is specified. */
10989 if (unwind.personality_index == -1)
10990 {
10991 if (unwind.opcode_count > 3)
10992 unwind.personality_index = 1;
10993 else
10994 unwind.personality_index = 0;
10995 }
bfae80f2 10996
c19d1205
ZW
10997 /* Space for the personality routine entry. */
10998 if (unwind.personality_index == 0)
10999 {
11000 if (unwind.opcode_count > 3)
11001 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 11002
c19d1205
ZW
11003 if (!have_data)
11004 {
11005 /* All the data is inline in the index table. */
11006 data = 0x80;
11007 n = 3;
11008 while (unwind.opcode_count > 0)
11009 {
11010 unwind.opcode_count--;
11011 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
11012 n--;
11013 }
bfae80f2 11014
c19d1205
ZW
11015 /* Pad with "finish" opcodes. */
11016 while (n--)
11017 data = (data << 8) | 0xb0;
bfae80f2 11018
c19d1205
ZW
11019 return data;
11020 }
11021 size = 0;
11022 }
11023 else
11024 /* We get two opcodes "free" in the first word. */
11025 size = unwind.opcode_count - 2;
11026 }
11027 else
11028 /* An extra byte is required for the opcode count. */
11029 size = unwind.opcode_count + 1;
bfae80f2 11030
c19d1205
ZW
11031 size = (size + 3) >> 2;
11032 if (size > 0xff)
11033 as_bad (_("too many unwind opcodes"));
bfae80f2 11034
c19d1205
ZW
11035 frag_align (2, 0, 0);
11036 record_alignment (now_seg, 2);
11037 unwind.table_entry = expr_build_dot ();
11038
11039 /* Allocate the table entry. */
11040 ptr = frag_more ((size << 2) + 4);
11041 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 11042
c19d1205 11043 switch (unwind.personality_index)
bfae80f2 11044 {
c19d1205
ZW
11045 case -1:
11046 /* ??? Should this be a PLT generating relocation? */
11047 /* Custom personality routine. */
11048 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
11049 BFD_RELOC_ARM_PREL31);
bfae80f2 11050
c19d1205
ZW
11051 where += 4;
11052 ptr += 4;
bfae80f2 11053
c19d1205
ZW
11054 /* Set the first byte to the number of additional words. */
11055 data = size - 1;
11056 n = 3;
11057 break;
bfae80f2 11058
c19d1205
ZW
11059 /* ABI defined personality routines. */
11060 case 0:
11061 /* Three opcodes bytes are packed into the first word. */
11062 data = 0x80;
11063 n = 3;
11064 break;
bfae80f2 11065
c19d1205
ZW
11066 case 1:
11067 case 2:
11068 /* The size and first two opcode bytes go in the first word. */
11069 data = ((0x80 + unwind.personality_index) << 8) | size;
11070 n = 2;
11071 break;
bfae80f2 11072
c19d1205
ZW
11073 default:
11074 /* Should never happen. */
11075 abort ();
11076 }
bfae80f2 11077
c19d1205
ZW
11078 /* Pack the opcodes into words (MSB first), reversing the list at the same
11079 time. */
11080 while (unwind.opcode_count > 0)
11081 {
11082 if (n == 0)
11083 {
11084 md_number_to_chars (ptr, data, 4);
11085 ptr += 4;
11086 n = 4;
11087 data = 0;
11088 }
11089 unwind.opcode_count--;
11090 n--;
11091 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
11092 }
11093
11094 /* Finish off the last word. */
11095 if (n < 4)
11096 {
11097 /* Pad with "finish" opcodes. */
11098 while (n--)
11099 data = (data << 8) | 0xb0;
11100
11101 md_number_to_chars (ptr, data, 4);
11102 }
11103
11104 if (!have_data)
11105 {
11106 /* Add an empty descriptor if there is no user-specified data. */
11107 ptr = frag_more (4);
11108 md_number_to_chars (ptr, 0, 4);
11109 }
11110
11111 return 0;
bfae80f2
RE
11112}
11113
c19d1205
ZW
11114/* Convert REGNAME to a DWARF-2 register number. */
11115
11116int
11117tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 11118{
c19d1205
ZW
11119 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
11120
11121 if (reg == FAIL)
11122 return -1;
11123
11124 return reg;
bfae80f2
RE
11125}
11126
c19d1205
ZW
11127/* Initialize the DWARF-2 unwind information for this procedure. */
11128
11129void
11130tc_arm_frame_initial_instructions (void)
bfae80f2 11131{
c19d1205 11132 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 11133}
c19d1205 11134#endif /* OBJ_ELF */
bfae80f2 11135
bfae80f2 11136
c19d1205 11137/* MD interface: Symbol and relocation handling. */
bfae80f2 11138
2fc8bdac
ZW
11139/* Return the address within the segment that a PC-relative fixup is
11140 relative to. For ARM, PC-relative fixups applied to instructions
11141 are generally relative to the location of the fixup plus 8 bytes.
11142 Thumb branches are offset by 4, and Thumb loads relative to PC
11143 require special handling. */
bfae80f2 11144
c19d1205 11145long
2fc8bdac 11146md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 11147{
2fc8bdac
ZW
11148 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
11149
11150 /* If this is pc-relative and we are going to emit a relocation
11151 then we just want to put out any pipeline compensation that the linker
11152 will need. Otherwise we want to use the calculated base. */
11153 if (fixP->fx_pcrel
11154 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
11155 || arm_force_relocation (fixP)))
11156 base = 0;
bfae80f2 11157
c19d1205 11158 switch (fixP->fx_r_type)
bfae80f2 11159 {
2fc8bdac
ZW
11160 /* PC relative addressing on the Thumb is slightly odd as the
11161 bottom two bits of the PC are forced to zero for the
11162 calculation. This happens *after* application of the
11163 pipeline offset. However, Thumb adrl already adjusts for
11164 this, so we need not do it again. */
c19d1205 11165 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 11166 return base & ~3;
c19d1205
ZW
11167
11168 case BFD_RELOC_ARM_THUMB_OFFSET:
11169 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 11170 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 11171 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 11172 return (base + 4) & ~3;
c19d1205 11173
2fc8bdac
ZW
11174 /* Thumb branches are simply offset by +4. */
11175 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11176 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11177 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11178 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11179 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11180 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11181 case BFD_RELOC_THUMB_PCREL_BLX:
11182 return base + 4;
bfae80f2 11183
2fc8bdac
ZW
11184 /* ARM mode branches are offset by +8. However, the Windows CE
11185 loader expects the relocation not to take this into account. */
11186 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
11187 case BFD_RELOC_ARM_PCREL_CALL:
11188 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
11189 case BFD_RELOC_ARM_PCREL_BLX:
11190 case BFD_RELOC_ARM_PLT32:
c19d1205 11191#ifdef TE_WINCE
2fc8bdac 11192 return base;
c19d1205 11193#else
2fc8bdac 11194 return base + 8;
c19d1205 11195#endif
2fc8bdac
ZW
11196
11197 /* ARM mode loads relative to PC are also offset by +8. Unlike
11198 branches, the Windows CE loader *does* expect the relocation
11199 to take this into account. */
11200 case BFD_RELOC_ARM_OFFSET_IMM:
11201 case BFD_RELOC_ARM_OFFSET_IMM8:
11202 case BFD_RELOC_ARM_HWLITERAL:
11203 case BFD_RELOC_ARM_LITERAL:
11204 case BFD_RELOC_ARM_CP_OFF_IMM:
11205 return base + 8;
11206
11207
11208 /* Other PC-relative relocations are un-offset. */
11209 default:
11210 return base;
11211 }
bfae80f2
RE
11212}
11213
c19d1205
ZW
11214/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
11215 Otherwise we have no need to default values of symbols. */
11216
11217symbolS *
11218md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 11219{
c19d1205
ZW
11220#ifdef OBJ_ELF
11221 if (name[0] == '_' && name[1] == 'G'
11222 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
11223 {
11224 if (!GOT_symbol)
11225 {
11226 if (symbol_find (name))
11227 as_bad ("GOT already in the symbol table");
bfae80f2 11228
c19d1205
ZW
11229 GOT_symbol = symbol_new (name, undefined_section,
11230 (valueT) 0, & zero_address_frag);
11231 }
bfae80f2 11232
c19d1205 11233 return GOT_symbol;
bfae80f2 11234 }
c19d1205 11235#endif
bfae80f2 11236
c19d1205 11237 return 0;
bfae80f2
RE
11238}
11239
55cf6793 11240/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
11241 computed as two separate immediate values, added together. We
11242 already know that this value cannot be computed by just one ARM
11243 instruction. */
11244
11245static unsigned int
11246validate_immediate_twopart (unsigned int val,
11247 unsigned int * highpart)
bfae80f2 11248{
c19d1205
ZW
11249 unsigned int a;
11250 unsigned int i;
bfae80f2 11251
c19d1205
ZW
11252 for (i = 0; i < 32; i += 2)
11253 if (((a = rotate_left (val, i)) & 0xff) != 0)
11254 {
11255 if (a & 0xff00)
11256 {
11257 if (a & ~ 0xffff)
11258 continue;
11259 * highpart = (a >> 8) | ((i + 24) << 7);
11260 }
11261 else if (a & 0xff0000)
11262 {
11263 if (a & 0xff000000)
11264 continue;
11265 * highpart = (a >> 16) | ((i + 16) << 7);
11266 }
11267 else
11268 {
11269 assert (a & 0xff000000);
11270 * highpart = (a >> 24) | ((i + 8) << 7);
11271 }
bfae80f2 11272
c19d1205
ZW
11273 return (a & 0xff) | (i << 7);
11274 }
bfae80f2 11275
c19d1205 11276 return FAIL;
bfae80f2
RE
11277}
11278
c19d1205
ZW
11279static int
11280validate_offset_imm (unsigned int val, int hwse)
11281{
11282 if ((hwse && val > 255) || val > 4095)
11283 return FAIL;
11284 return val;
11285}
bfae80f2 11286
55cf6793 11287/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
11288 negative immediate constant by altering the instruction. A bit of
11289 a hack really.
11290 MOV <-> MVN
11291 AND <-> BIC
11292 ADC <-> SBC
11293 by inverting the second operand, and
11294 ADD <-> SUB
11295 CMP <-> CMN
11296 by negating the second operand. */
bfae80f2 11297
c19d1205
ZW
11298static int
11299negate_data_op (unsigned long * instruction,
11300 unsigned long value)
bfae80f2 11301{
c19d1205
ZW
11302 int op, new_inst;
11303 unsigned long negated, inverted;
bfae80f2 11304
c19d1205
ZW
11305 negated = encode_arm_immediate (-value);
11306 inverted = encode_arm_immediate (~value);
bfae80f2 11307
c19d1205
ZW
11308 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
11309 switch (op)
bfae80f2 11310 {
c19d1205
ZW
11311 /* First negates. */
11312 case OPCODE_SUB: /* ADD <-> SUB */
11313 new_inst = OPCODE_ADD;
11314 value = negated;
11315 break;
bfae80f2 11316
c19d1205
ZW
11317 case OPCODE_ADD:
11318 new_inst = OPCODE_SUB;
11319 value = negated;
11320 break;
bfae80f2 11321
c19d1205
ZW
11322 case OPCODE_CMP: /* CMP <-> CMN */
11323 new_inst = OPCODE_CMN;
11324 value = negated;
11325 break;
bfae80f2 11326
c19d1205
ZW
11327 case OPCODE_CMN:
11328 new_inst = OPCODE_CMP;
11329 value = negated;
11330 break;
bfae80f2 11331
c19d1205
ZW
11332 /* Now Inverted ops. */
11333 case OPCODE_MOV: /* MOV <-> MVN */
11334 new_inst = OPCODE_MVN;
11335 value = inverted;
11336 break;
bfae80f2 11337
c19d1205
ZW
11338 case OPCODE_MVN:
11339 new_inst = OPCODE_MOV;
11340 value = inverted;
11341 break;
bfae80f2 11342
c19d1205
ZW
11343 case OPCODE_AND: /* AND <-> BIC */
11344 new_inst = OPCODE_BIC;
11345 value = inverted;
11346 break;
bfae80f2 11347
c19d1205
ZW
11348 case OPCODE_BIC:
11349 new_inst = OPCODE_AND;
11350 value = inverted;
11351 break;
bfae80f2 11352
c19d1205
ZW
11353 case OPCODE_ADC: /* ADC <-> SBC */
11354 new_inst = OPCODE_SBC;
11355 value = inverted;
11356 break;
bfae80f2 11357
c19d1205
ZW
11358 case OPCODE_SBC:
11359 new_inst = OPCODE_ADC;
11360 value = inverted;
11361 break;
bfae80f2 11362
c19d1205
ZW
11363 /* We cannot do anything. */
11364 default:
11365 return FAIL;
b99bd4ef
NC
11366 }
11367
c19d1205
ZW
11368 if (value == (unsigned) FAIL)
11369 return FAIL;
11370
11371 *instruction &= OPCODE_MASK;
11372 *instruction |= new_inst << DATA_OP_SHIFT;
11373 return value;
b99bd4ef
NC
11374}
11375
ef8d22e6
PB
11376/* Like negate_data_op, but for Thumb-2. */
11377
11378static unsigned int
11379thumb32_negate_data_op (offsetT *instruction, offsetT value)
11380{
11381 int op, new_inst;
11382 int rd;
11383 offsetT negated, inverted;
11384
11385 negated = encode_thumb32_immediate (-value);
11386 inverted = encode_thumb32_immediate (~value);
11387
11388 rd = (*instruction >> 8) & 0xf;
11389 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
11390 switch (op)
11391 {
11392 /* ADD <-> SUB. Includes CMP <-> CMN. */
11393 case T2_OPCODE_SUB:
11394 new_inst = T2_OPCODE_ADD;
11395 value = negated;
11396 break;
11397
11398 case T2_OPCODE_ADD:
11399 new_inst = T2_OPCODE_SUB;
11400 value = negated;
11401 break;
11402
11403 /* ORR <-> ORN. Includes MOV <-> MVN. */
11404 case T2_OPCODE_ORR:
11405 new_inst = T2_OPCODE_ORN;
11406 value = inverted;
11407 break;
11408
11409 case T2_OPCODE_ORN:
11410 new_inst = T2_OPCODE_ORR;
11411 value = inverted;
11412 break;
11413
11414 /* AND <-> BIC. TST has no inverted equivalent. */
11415 case T2_OPCODE_AND:
11416 new_inst = T2_OPCODE_BIC;
11417 if (rd == 15)
11418 value = FAIL;
11419 else
11420 value = inverted;
11421 break;
11422
11423 case T2_OPCODE_BIC:
11424 new_inst = T2_OPCODE_AND;
11425 value = inverted;
11426 break;
11427
11428 /* ADC <-> SBC */
11429 case T2_OPCODE_ADC:
11430 new_inst = T2_OPCODE_SBC;
11431 value = inverted;
11432 break;
11433
11434 case T2_OPCODE_SBC:
11435 new_inst = T2_OPCODE_ADC;
11436 value = inverted;
11437 break;
11438
11439 /* We cannot do anything. */
11440 default:
11441 return FAIL;
11442 }
11443
11444 if (value == FAIL)
11445 return FAIL;
11446
11447 *instruction &= T2_OPCODE_MASK;
11448 *instruction |= new_inst << T2_DATA_OP_SHIFT;
11449 return value;
11450}
11451
8f06b2d8
PB
11452/* Read a 32-bit thumb instruction from buf. */
11453static unsigned long
11454get_thumb32_insn (char * buf)
11455{
11456 unsigned long insn;
11457 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
11458 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11459
11460 return insn;
11461}
11462
c19d1205 11463void
55cf6793 11464md_apply_fix (fixS * fixP,
c19d1205
ZW
11465 valueT * valP,
11466 segT seg)
11467{
11468 offsetT value = * valP;
11469 offsetT newval;
11470 unsigned int newimm;
11471 unsigned long temp;
11472 int sign;
11473 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 11474
c19d1205 11475 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 11476
c19d1205
ZW
11477 /* Note whether this will delete the relocation. */
11478 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
11479 fixP->fx_done = 1;
b99bd4ef 11480
adbaf948
ZW
11481 /* On a 64-bit host, silently truncate 'value' to 32 bits for
11482 consistency with the behavior on 32-bit hosts. Remember value
11483 for emit_reloc. */
11484 value &= 0xffffffff;
11485 value ^= 0x80000000;
11486 value -= 0x80000000;
11487
11488 *valP = value;
c19d1205 11489 fixP->fx_addnumber = value;
b99bd4ef 11490
adbaf948
ZW
11491 /* Same treatment for fixP->fx_offset. */
11492 fixP->fx_offset &= 0xffffffff;
11493 fixP->fx_offset ^= 0x80000000;
11494 fixP->fx_offset -= 0x80000000;
11495
c19d1205 11496 switch (fixP->fx_r_type)
b99bd4ef 11497 {
c19d1205
ZW
11498 case BFD_RELOC_NONE:
11499 /* This will need to go in the object file. */
11500 fixP->fx_done = 0;
11501 break;
b99bd4ef 11502
c19d1205
ZW
11503 case BFD_RELOC_ARM_IMMEDIATE:
11504 /* We claim that this fixup has been processed here,
11505 even if in fact we generate an error because we do
11506 not have a reloc for it, so tc_gen_reloc will reject it. */
11507 fixP->fx_done = 1;
b99bd4ef 11508
c19d1205
ZW
11509 if (fixP->fx_addsy
11510 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 11511 {
c19d1205
ZW
11512 as_bad_where (fixP->fx_file, fixP->fx_line,
11513 _("undefined symbol %s used as an immediate value"),
11514 S_GET_NAME (fixP->fx_addsy));
11515 break;
b99bd4ef
NC
11516 }
11517
c19d1205
ZW
11518 newimm = encode_arm_immediate (value);
11519 temp = md_chars_to_number (buf, INSN_SIZE);
11520
11521 /* If the instruction will fail, see if we can fix things up by
11522 changing the opcode. */
11523 if (newimm == (unsigned int) FAIL
11524 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 11525 {
c19d1205
ZW
11526 as_bad_where (fixP->fx_file, fixP->fx_line,
11527 _("invalid constant (%lx) after fixup"),
11528 (unsigned long) value);
11529 break;
b99bd4ef 11530 }
b99bd4ef 11531
c19d1205
ZW
11532 newimm |= (temp & 0xfffff000);
11533 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11534 break;
b99bd4ef 11535
c19d1205
ZW
11536 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11537 {
11538 unsigned int highpart = 0;
11539 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 11540
c19d1205
ZW
11541 newimm = encode_arm_immediate (value);
11542 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 11543
c19d1205
ZW
11544 /* If the instruction will fail, see if we can fix things up by
11545 changing the opcode. */
11546 if (newimm == (unsigned int) FAIL
11547 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
11548 {
11549 /* No ? OK - try using two ADD instructions to generate
11550 the value. */
11551 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 11552
c19d1205
ZW
11553 /* Yes - then make sure that the second instruction is
11554 also an add. */
11555 if (newimm != (unsigned int) FAIL)
11556 newinsn = temp;
11557 /* Still No ? Try using a negated value. */
11558 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
11559 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
11560 /* Otherwise - give up. */
11561 else
11562 {
11563 as_bad_where (fixP->fx_file, fixP->fx_line,
11564 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
11565 (long) value);
11566 break;
11567 }
b99bd4ef 11568
c19d1205
ZW
11569 /* Replace the first operand in the 2nd instruction (which
11570 is the PC) with the destination register. We have
11571 already added in the PC in the first instruction and we
11572 do not want to do it again. */
11573 newinsn &= ~ 0xf0000;
11574 newinsn |= ((newinsn & 0x0f000) << 4);
11575 }
b99bd4ef 11576
c19d1205
ZW
11577 newimm |= (temp & 0xfffff000);
11578 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 11579
c19d1205
ZW
11580 highpart |= (newinsn & 0xfffff000);
11581 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
11582 }
11583 break;
b99bd4ef 11584
c19d1205 11585 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
11586 if (!fixP->fx_done && seg->use_rela_p)
11587 value = 0;
11588
c19d1205
ZW
11589 case BFD_RELOC_ARM_LITERAL:
11590 sign = value >= 0;
b99bd4ef 11591
c19d1205
ZW
11592 if (value < 0)
11593 value = - value;
b99bd4ef 11594
c19d1205 11595 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 11596 {
c19d1205
ZW
11597 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
11598 as_bad_where (fixP->fx_file, fixP->fx_line,
11599 _("invalid literal constant: pool needs to be closer"));
11600 else
11601 as_bad_where (fixP->fx_file, fixP->fx_line,
11602 _("bad immediate value for offset (%ld)"),
11603 (long) value);
11604 break;
f03698e6
RE
11605 }
11606
c19d1205
ZW
11607 newval = md_chars_to_number (buf, INSN_SIZE);
11608 newval &= 0xff7ff000;
11609 newval |= value | (sign ? INDEX_UP : 0);
11610 md_number_to_chars (buf, newval, INSN_SIZE);
11611 break;
b99bd4ef 11612
c19d1205
ZW
11613 case BFD_RELOC_ARM_OFFSET_IMM8:
11614 case BFD_RELOC_ARM_HWLITERAL:
11615 sign = value >= 0;
b99bd4ef 11616
c19d1205
ZW
11617 if (value < 0)
11618 value = - value;
b99bd4ef 11619
c19d1205 11620 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 11621 {
c19d1205
ZW
11622 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
11623 as_bad_where (fixP->fx_file, fixP->fx_line,
11624 _("invalid literal constant: pool needs to be closer"));
11625 else
11626 as_bad (_("bad immediate value for half-word offset (%ld)"),
11627 (long) value);
11628 break;
b99bd4ef
NC
11629 }
11630
c19d1205
ZW
11631 newval = md_chars_to_number (buf, INSN_SIZE);
11632 newval &= 0xff7ff0f0;
11633 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
11634 md_number_to_chars (buf, newval, INSN_SIZE);
11635 break;
b99bd4ef 11636
c19d1205
ZW
11637 case BFD_RELOC_ARM_T32_OFFSET_U8:
11638 if (value < 0 || value > 1020 || value % 4 != 0)
11639 as_bad_where (fixP->fx_file, fixP->fx_line,
11640 _("bad immediate value for offset (%ld)"), (long) value);
11641 value /= 4;
b99bd4ef 11642
c19d1205 11643 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
11644 newval |= value;
11645 md_number_to_chars (buf+2, newval, THUMB_SIZE);
11646 break;
b99bd4ef 11647
c19d1205
ZW
11648 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11649 /* This is a complicated relocation used for all varieties of Thumb32
11650 load/store instruction with immediate offset:
11651
11652 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
11653 *4, optional writeback(W)
11654 (doubleword load/store)
11655
11656 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
11657 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
11658 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
11659 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
11660 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
11661
11662 Uppercase letters indicate bits that are already encoded at
11663 this point. Lowercase letters are our problem. For the
11664 second block of instructions, the secondary opcode nybble
11665 (bits 8..11) is present, and bit 23 is zero, even if this is
11666 a PC-relative operation. */
11667 newval = md_chars_to_number (buf, THUMB_SIZE);
11668 newval <<= 16;
11669 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 11670
c19d1205 11671 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 11672 {
c19d1205
ZW
11673 /* Doubleword load/store: 8-bit offset, scaled by 4. */
11674 if (value >= 0)
11675 newval |= (1 << 23);
11676 else
11677 value = -value;
11678 if (value % 4 != 0)
11679 {
11680 as_bad_where (fixP->fx_file, fixP->fx_line,
11681 _("offset not a multiple of 4"));
11682 break;
11683 }
11684 value /= 4;
216d22bc 11685 if (value > 0xff)
c19d1205
ZW
11686 {
11687 as_bad_where (fixP->fx_file, fixP->fx_line,
11688 _("offset out of range"));
11689 break;
11690 }
11691 newval &= ~0xff;
b99bd4ef 11692 }
c19d1205 11693 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 11694 {
c19d1205
ZW
11695 /* PC-relative, 12-bit offset. */
11696 if (value >= 0)
11697 newval |= (1 << 23);
11698 else
11699 value = -value;
216d22bc 11700 if (value > 0xfff)
c19d1205
ZW
11701 {
11702 as_bad_where (fixP->fx_file, fixP->fx_line,
11703 _("offset out of range"));
11704 break;
11705 }
11706 newval &= ~0xfff;
b99bd4ef 11707 }
c19d1205 11708 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 11709 {
c19d1205
ZW
11710 /* Writeback: 8-bit, +/- offset. */
11711 if (value >= 0)
11712 newval |= (1 << 9);
11713 else
11714 value = -value;
216d22bc 11715 if (value > 0xff)
c19d1205
ZW
11716 {
11717 as_bad_where (fixP->fx_file, fixP->fx_line,
11718 _("offset out of range"));
11719 break;
11720 }
11721 newval &= ~0xff;
b99bd4ef 11722 }
c19d1205 11723 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 11724 {
c19d1205 11725 /* T-instruction: positive 8-bit offset. */
216d22bc 11726 if (value < 0 || value > 0xff)
b99bd4ef 11727 {
c19d1205
ZW
11728 as_bad_where (fixP->fx_file, fixP->fx_line,
11729 _("offset out of range"));
11730 break;
b99bd4ef 11731 }
c19d1205
ZW
11732 newval &= ~0xff;
11733 newval |= value;
b99bd4ef
NC
11734 }
11735 else
b99bd4ef 11736 {
c19d1205
ZW
11737 /* Positive 12-bit or negative 8-bit offset. */
11738 int limit;
11739 if (value >= 0)
b99bd4ef 11740 {
c19d1205
ZW
11741 newval |= (1 << 23);
11742 limit = 0xfff;
11743 }
11744 else
11745 {
11746 value = -value;
11747 limit = 0xff;
11748 }
11749 if (value > limit)
11750 {
11751 as_bad_where (fixP->fx_file, fixP->fx_line,
11752 _("offset out of range"));
11753 break;
b99bd4ef 11754 }
c19d1205 11755 newval &= ~limit;
b99bd4ef 11756 }
b99bd4ef 11757
c19d1205
ZW
11758 newval |= value;
11759 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
11760 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
11761 break;
404ff6b5 11762
c19d1205
ZW
11763 case BFD_RELOC_ARM_SHIFT_IMM:
11764 newval = md_chars_to_number (buf, INSN_SIZE);
11765 if (((unsigned long) value) > 32
11766 || (value == 32
11767 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
11768 {
11769 as_bad_where (fixP->fx_file, fixP->fx_line,
11770 _("shift expression is too large"));
11771 break;
11772 }
404ff6b5 11773
c19d1205
ZW
11774 if (value == 0)
11775 /* Shifts of zero must be done as lsl. */
11776 newval &= ~0x60;
11777 else if (value == 32)
11778 value = 0;
11779 newval &= 0xfffff07f;
11780 newval |= (value & 0x1f) << 7;
11781 md_number_to_chars (buf, newval, INSN_SIZE);
11782 break;
404ff6b5 11783
c19d1205 11784 case BFD_RELOC_ARM_T32_IMMEDIATE:
92e90b6e 11785 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 11786 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
11787 /* We claim that this fixup has been processed here,
11788 even if in fact we generate an error because we do
11789 not have a reloc for it, so tc_gen_reloc will reject it. */
11790 fixP->fx_done = 1;
404ff6b5 11791
c19d1205
ZW
11792 if (fixP->fx_addsy
11793 && ! S_IS_DEFINED (fixP->fx_addsy))
11794 {
11795 as_bad_where (fixP->fx_file, fixP->fx_line,
11796 _("undefined symbol %s used as an immediate value"),
11797 S_GET_NAME (fixP->fx_addsy));
11798 break;
11799 }
404ff6b5 11800
c19d1205
ZW
11801 newval = md_chars_to_number (buf, THUMB_SIZE);
11802 newval <<= 16;
11803 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 11804
e9f89963
PB
11805 /* FUTURE: Implement analogue of negate_data_op for T32. */
11806 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
ef8d22e6
PB
11807 {
11808 newimm = encode_thumb32_immediate (value);
11809 if (newimm == (unsigned int) FAIL)
11810 newimm = thumb32_negate_data_op (&newval, value);
11811 }
e9f89963 11812 else
92e90b6e 11813 {
e9f89963
PB
11814 /* 12 bit immediate for addw/subw. */
11815 if (value < 0)
11816 {
11817 value = -value;
11818 newval ^= 0x00a00000;
11819 }
92e90b6e
PB
11820 if (value > 0xfff)
11821 newimm = (unsigned int) FAIL;
11822 else
11823 newimm = value;
11824 }
cc8a6dd0 11825
c19d1205 11826 if (newimm == (unsigned int)FAIL)
3631a3c8 11827 {
c19d1205
ZW
11828 as_bad_where (fixP->fx_file, fixP->fx_line,
11829 _("invalid constant (%lx) after fixup"),
11830 (unsigned long) value);
11831 break;
3631a3c8
NC
11832 }
11833
c19d1205
ZW
11834 newval |= (newimm & 0x800) << 15;
11835 newval |= (newimm & 0x700) << 4;
11836 newval |= (newimm & 0x0ff);
cc8a6dd0 11837
c19d1205
ZW
11838 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
11839 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
11840 break;
a737bd4d 11841
3eb17e6b 11842 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
11843 if (((unsigned long) value) > 0xffff)
11844 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 11845 _("invalid smc expression"));
2fc8bdac 11846 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11847 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
11848 md_number_to_chars (buf, newval, INSN_SIZE);
11849 break;
a737bd4d 11850
c19d1205 11851 case BFD_RELOC_ARM_SWI:
adbaf948 11852 if (fixP->tc_fix_data != 0)
c19d1205
ZW
11853 {
11854 if (((unsigned long) value) > 0xff)
11855 as_bad_where (fixP->fx_file, fixP->fx_line,
11856 _("invalid swi expression"));
2fc8bdac 11857 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
11858 newval |= value;
11859 md_number_to_chars (buf, newval, THUMB_SIZE);
11860 }
11861 else
11862 {
11863 if (((unsigned long) value) > 0x00ffffff)
11864 as_bad_where (fixP->fx_file, fixP->fx_line,
11865 _("invalid swi expression"));
2fc8bdac 11866 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11867 newval |= value;
11868 md_number_to_chars (buf, newval, INSN_SIZE);
11869 }
11870 break;
a737bd4d 11871
c19d1205
ZW
11872 case BFD_RELOC_ARM_MULTI:
11873 if (((unsigned long) value) > 0xffff)
11874 as_bad_where (fixP->fx_file, fixP->fx_line,
11875 _("invalid expression in load/store multiple"));
11876 newval = value | md_chars_to_number (buf, INSN_SIZE);
11877 md_number_to_chars (buf, newval, INSN_SIZE);
11878 break;
a737bd4d 11879
c19d1205 11880#ifdef OBJ_ELF
39b41c9c
PB
11881 case BFD_RELOC_ARM_PCREL_CALL:
11882 newval = md_chars_to_number (buf, INSN_SIZE);
11883 if ((newval & 0xf0000000) == 0xf0000000)
11884 temp = 1;
11885 else
11886 temp = 3;
11887 goto arm_branch_common;
11888
11889 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 11890 case BFD_RELOC_ARM_PLT32:
c19d1205 11891#endif
39b41c9c
PB
11892 case BFD_RELOC_ARM_PCREL_BRANCH:
11893 temp = 3;
11894 goto arm_branch_common;
a737bd4d 11895
39b41c9c
PB
11896 case BFD_RELOC_ARM_PCREL_BLX:
11897 temp = 1;
11898 arm_branch_common:
c19d1205 11899 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
11900 instruction, in a 24 bit, signed field. Bits 26 through 32 either
11901 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
11902 also be be clear. */
11903 if (value & temp)
c19d1205 11904 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
11905 _("misaligned branch destination"));
11906 if ((value & (offsetT)0xfe000000) != (offsetT)0
11907 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11908 as_bad_where (fixP->fx_file, fixP->fx_line,
11909 _("branch out of range"));
a737bd4d 11910
2fc8bdac 11911 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11912 {
2fc8bdac
ZW
11913 newval = md_chars_to_number (buf, INSN_SIZE);
11914 newval |= (value >> 2) & 0x00ffffff;
11915 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 11916 }
c19d1205 11917 break;
a737bd4d 11918
c19d1205 11919 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
11920 /* CZB can only branch forward. */
11921 if (value & ~0x7e)
11922 as_bad_where (fixP->fx_file, fixP->fx_line,
11923 _("branch out of range"));
a737bd4d 11924
2fc8bdac
ZW
11925 if (fixP->fx_done || !seg->use_rela_p)
11926 {
11927 newval = md_chars_to_number (buf, THUMB_SIZE);
080eb7fe 11928 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
11929 md_number_to_chars (buf, newval, THUMB_SIZE);
11930 }
c19d1205 11931 break;
a737bd4d 11932
c19d1205 11933 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
11934 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
11935 as_bad_where (fixP->fx_file, fixP->fx_line,
11936 _("branch out of range"));
a737bd4d 11937
2fc8bdac
ZW
11938 if (fixP->fx_done || !seg->use_rela_p)
11939 {
11940 newval = md_chars_to_number (buf, THUMB_SIZE);
11941 newval |= (value & 0x1ff) >> 1;
11942 md_number_to_chars (buf, newval, THUMB_SIZE);
11943 }
c19d1205 11944 break;
a737bd4d 11945
c19d1205 11946 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
11947 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
11948 as_bad_where (fixP->fx_file, fixP->fx_line,
11949 _("branch out of range"));
a737bd4d 11950
2fc8bdac
ZW
11951 if (fixP->fx_done || !seg->use_rela_p)
11952 {
11953 newval = md_chars_to_number (buf, THUMB_SIZE);
11954 newval |= (value & 0xfff) >> 1;
11955 md_number_to_chars (buf, newval, THUMB_SIZE);
11956 }
c19d1205 11957 break;
a737bd4d 11958
c19d1205 11959 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
11960 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
11961 as_bad_where (fixP->fx_file, fixP->fx_line,
11962 _("conditional branch out of range"));
404ff6b5 11963
2fc8bdac
ZW
11964 if (fixP->fx_done || !seg->use_rela_p)
11965 {
11966 offsetT newval2;
11967 addressT S, J1, J2, lo, hi;
404ff6b5 11968
2fc8bdac
ZW
11969 S = (value & 0x00100000) >> 20;
11970 J2 = (value & 0x00080000) >> 19;
11971 J1 = (value & 0x00040000) >> 18;
11972 hi = (value & 0x0003f000) >> 12;
11973 lo = (value & 0x00000ffe) >> 1;
6c43fab6 11974
2fc8bdac
ZW
11975 newval = md_chars_to_number (buf, THUMB_SIZE);
11976 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11977 newval |= (S << 10) | hi;
11978 newval2 |= (J1 << 13) | (J2 << 11) | lo;
11979 md_number_to_chars (buf, newval, THUMB_SIZE);
11980 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11981 }
c19d1205 11982 break;
6c43fab6 11983
c19d1205
ZW
11984 case BFD_RELOC_THUMB_PCREL_BLX:
11985 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
11986 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
11987 as_bad_where (fixP->fx_file, fixP->fx_line,
11988 _("branch out of range"));
404ff6b5 11989
2fc8bdac
ZW
11990 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
11991 /* For a BLX instruction, make sure that the relocation is rounded up
11992 to a word boundary. This follows the semantics of the instruction
11993 which specifies that bit 1 of the target address will come from bit
11994 1 of the base address. */
11995 value = (value + 1) & ~ 1;
404ff6b5 11996
2fc8bdac 11997 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11998 {
2fc8bdac
ZW
11999 offsetT newval2;
12000
12001 newval = md_chars_to_number (buf, THUMB_SIZE);
12002 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
12003 newval |= (value & 0x7fffff) >> 12;
12004 newval2 |= (value & 0xfff) >> 1;
12005 md_number_to_chars (buf, newval, THUMB_SIZE);
12006 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 12007 }
c19d1205 12008 break;
404ff6b5 12009
c19d1205 12010 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
12011 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
12012 as_bad_where (fixP->fx_file, fixP->fx_line,
12013 _("branch out of range"));
6c43fab6 12014
2fc8bdac
ZW
12015 if (fixP->fx_done || !seg->use_rela_p)
12016 {
12017 offsetT newval2;
12018 addressT S, I1, I2, lo, hi;
6c43fab6 12019
2fc8bdac
ZW
12020 S = (value & 0x01000000) >> 24;
12021 I1 = (value & 0x00800000) >> 23;
12022 I2 = (value & 0x00400000) >> 22;
12023 hi = (value & 0x003ff000) >> 12;
12024 lo = (value & 0x00000ffe) >> 1;
6c43fab6 12025
2fc8bdac
ZW
12026 I1 = !(I1 ^ S);
12027 I2 = !(I2 ^ S);
a737bd4d 12028
2fc8bdac
ZW
12029 newval = md_chars_to_number (buf, THUMB_SIZE);
12030 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
12031 newval |= (S << 10) | hi;
12032 newval2 |= (I1 << 13) | (I2 << 11) | lo;
12033 md_number_to_chars (buf, newval, THUMB_SIZE);
12034 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
12035 }
12036 break;
a737bd4d 12037
2fc8bdac
ZW
12038 case BFD_RELOC_8:
12039 if (fixP->fx_done || !seg->use_rela_p)
12040 md_number_to_chars (buf, value, 1);
c19d1205 12041 break;
a737bd4d 12042
c19d1205 12043 case BFD_RELOC_16:
2fc8bdac 12044 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 12045 md_number_to_chars (buf, value, 2);
c19d1205 12046 break;
a737bd4d 12047
c19d1205
ZW
12048#ifdef OBJ_ELF
12049 case BFD_RELOC_ARM_TLS_GD32:
12050 case BFD_RELOC_ARM_TLS_LE32:
12051 case BFD_RELOC_ARM_TLS_IE32:
12052 case BFD_RELOC_ARM_TLS_LDM32:
12053 case BFD_RELOC_ARM_TLS_LDO32:
12054 S_SET_THREAD_LOCAL (fixP->fx_addsy);
12055 /* fall through */
6c43fab6 12056
c19d1205
ZW
12057 case BFD_RELOC_ARM_GOT32:
12058 case BFD_RELOC_ARM_GOTOFF:
12059 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
12060 if (fixP->fx_done || !seg->use_rela_p)
12061 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
12062 break;
12063#endif
6c43fab6 12064
c19d1205
ZW
12065 case BFD_RELOC_RVA:
12066 case BFD_RELOC_32:
12067 case BFD_RELOC_ARM_TARGET1:
12068 case BFD_RELOC_ARM_ROSEGREL32:
12069 case BFD_RELOC_ARM_SBREL32:
12070 case BFD_RELOC_32_PCREL:
2fc8bdac 12071 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 12072 md_number_to_chars (buf, value, 4);
c19d1205 12073 break;
6c43fab6 12074
c19d1205
ZW
12075#ifdef OBJ_ELF
12076 case BFD_RELOC_ARM_PREL31:
2fc8bdac 12077 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
12078 {
12079 newval = md_chars_to_number (buf, 4) & 0x80000000;
12080 if ((value ^ (value >> 1)) & 0x40000000)
12081 {
12082 as_bad_where (fixP->fx_file, fixP->fx_line,
12083 _("rel31 relocation overflow"));
12084 }
12085 newval |= value & 0x7fffffff;
12086 md_number_to_chars (buf, newval, 4);
12087 }
12088 break;
c19d1205 12089#endif
a737bd4d 12090
c19d1205 12091 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 12092 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
12093 if (value < -1023 || value > 1023 || (value & 3))
12094 as_bad_where (fixP->fx_file, fixP->fx_line,
12095 _("co-processor offset out of range"));
12096 cp_off_common:
12097 sign = value >= 0;
12098 if (value < 0)
12099 value = -value;
8f06b2d8
PB
12100 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12101 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12102 newval = md_chars_to_number (buf, INSN_SIZE);
12103 else
12104 newval = get_thumb32_insn (buf);
12105 newval &= 0xff7fff00;
c19d1205
ZW
12106 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
12107 if (value == 0)
12108 newval &= ~WRITE_BACK;
8f06b2d8
PB
12109 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12110 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12111 md_number_to_chars (buf, newval, INSN_SIZE);
12112 else
12113 put_thumb32_insn (buf, newval);
c19d1205 12114 break;
a737bd4d 12115
c19d1205 12116 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 12117 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
12118 if (value < -255 || value > 255)
12119 as_bad_where (fixP->fx_file, fixP->fx_line,
12120 _("co-processor offset out of range"));
12121 goto cp_off_common;
6c43fab6 12122
c19d1205
ZW
12123 case BFD_RELOC_ARM_THUMB_OFFSET:
12124 newval = md_chars_to_number (buf, THUMB_SIZE);
12125 /* Exactly what ranges, and where the offset is inserted depends
12126 on the type of instruction, we can establish this from the
12127 top 4 bits. */
12128 switch (newval >> 12)
12129 {
12130 case 4: /* PC load. */
12131 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
12132 forced to zero for these loads; md_pcrel_from has already
12133 compensated for this. */
12134 if (value & 3)
12135 as_bad_where (fixP->fx_file, fixP->fx_line,
12136 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
12137 (((unsigned long) fixP->fx_frag->fr_address
12138 + (unsigned long) fixP->fx_where) & ~3)
12139 + (unsigned long) value);
a737bd4d 12140
c19d1205
ZW
12141 if (value & ~0x3fc)
12142 as_bad_where (fixP->fx_file, fixP->fx_line,
12143 _("invalid offset, value too big (0x%08lX)"),
12144 (long) value);
a737bd4d 12145
c19d1205
ZW
12146 newval |= value >> 2;
12147 break;
a737bd4d 12148
c19d1205
ZW
12149 case 9: /* SP load/store. */
12150 if (value & ~0x3fc)
12151 as_bad_where (fixP->fx_file, fixP->fx_line,
12152 _("invalid offset, value too big (0x%08lX)"),
12153 (long) value);
12154 newval |= value >> 2;
12155 break;
6c43fab6 12156
c19d1205
ZW
12157 case 6: /* Word load/store. */
12158 if (value & ~0x7c)
12159 as_bad_where (fixP->fx_file, fixP->fx_line,
12160 _("invalid offset, value too big (0x%08lX)"),
12161 (long) value);
12162 newval |= value << 4; /* 6 - 2. */
12163 break;
a737bd4d 12164
c19d1205
ZW
12165 case 7: /* Byte load/store. */
12166 if (value & ~0x1f)
12167 as_bad_where (fixP->fx_file, fixP->fx_line,
12168 _("invalid offset, value too big (0x%08lX)"),
12169 (long) value);
12170 newval |= value << 6;
12171 break;
a737bd4d 12172
c19d1205
ZW
12173 case 8: /* Halfword load/store. */
12174 if (value & ~0x3e)
12175 as_bad_where (fixP->fx_file, fixP->fx_line,
12176 _("invalid offset, value too big (0x%08lX)"),
12177 (long) value);
12178 newval |= value << 5; /* 6 - 1. */
12179 break;
a737bd4d 12180
c19d1205
ZW
12181 default:
12182 as_bad_where (fixP->fx_file, fixP->fx_line,
12183 "Unable to process relocation for thumb opcode: %lx",
12184 (unsigned long) newval);
12185 break;
12186 }
12187 md_number_to_chars (buf, newval, THUMB_SIZE);
12188 break;
a737bd4d 12189
c19d1205
ZW
12190 case BFD_RELOC_ARM_THUMB_ADD:
12191 /* This is a complicated relocation, since we use it for all of
12192 the following immediate relocations:
a737bd4d 12193
c19d1205
ZW
12194 3bit ADD/SUB
12195 8bit ADD/SUB
12196 9bit ADD/SUB SP word-aligned
12197 10bit ADD PC/SP word-aligned
a737bd4d 12198
c19d1205
ZW
12199 The type of instruction being processed is encoded in the
12200 instruction field:
a737bd4d 12201
c19d1205
ZW
12202 0x8000 SUB
12203 0x00F0 Rd
12204 0x000F Rs
12205 */
12206 newval = md_chars_to_number (buf, THUMB_SIZE);
12207 {
12208 int rd = (newval >> 4) & 0xf;
12209 int rs = newval & 0xf;
12210 int subtract = !!(newval & 0x8000);
a737bd4d 12211
c19d1205
ZW
12212 /* Check for HI regs, only very restricted cases allowed:
12213 Adjusting SP, and using PC or SP to get an address. */
12214 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
12215 || (rs > 7 && rs != REG_SP && rs != REG_PC))
12216 as_bad_where (fixP->fx_file, fixP->fx_line,
12217 _("invalid Hi register with immediate"));
a737bd4d 12218
c19d1205
ZW
12219 /* If value is negative, choose the opposite instruction. */
12220 if (value < 0)
12221 {
12222 value = -value;
12223 subtract = !subtract;
12224 if (value < 0)
12225 as_bad_where (fixP->fx_file, fixP->fx_line,
12226 _("immediate value out of range"));
12227 }
a737bd4d 12228
c19d1205
ZW
12229 if (rd == REG_SP)
12230 {
12231 if (value & ~0x1fc)
12232 as_bad_where (fixP->fx_file, fixP->fx_line,
12233 _("invalid immediate for stack address calculation"));
12234 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
12235 newval |= value >> 2;
12236 }
12237 else if (rs == REG_PC || rs == REG_SP)
12238 {
12239 if (subtract || value & ~0x3fc)
12240 as_bad_where (fixP->fx_file, fixP->fx_line,
12241 _("invalid immediate for address calculation (value = 0x%08lX)"),
12242 (unsigned long) value);
12243 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
12244 newval |= rd << 8;
12245 newval |= value >> 2;
12246 }
12247 else if (rs == rd)
12248 {
12249 if (value & ~0xff)
12250 as_bad_where (fixP->fx_file, fixP->fx_line,
12251 _("immediate value out of range"));
12252 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
12253 newval |= (rd << 8) | value;
12254 }
12255 else
12256 {
12257 if (value & ~0x7)
12258 as_bad_where (fixP->fx_file, fixP->fx_line,
12259 _("immediate value out of range"));
12260 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
12261 newval |= rd | (rs << 3) | (value << 6);
12262 }
12263 }
12264 md_number_to_chars (buf, newval, THUMB_SIZE);
12265 break;
a737bd4d 12266
c19d1205
ZW
12267 case BFD_RELOC_ARM_THUMB_IMM:
12268 newval = md_chars_to_number (buf, THUMB_SIZE);
12269 if (value < 0 || value > 255)
12270 as_bad_where (fixP->fx_file, fixP->fx_line,
12271 _("invalid immediate: %ld is too large"),
12272 (long) value);
12273 newval |= value;
12274 md_number_to_chars (buf, newval, THUMB_SIZE);
12275 break;
a737bd4d 12276
c19d1205
ZW
12277 case BFD_RELOC_ARM_THUMB_SHIFT:
12278 /* 5bit shift value (0..32). LSL cannot take 32. */
12279 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
12280 temp = newval & 0xf800;
12281 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
12282 as_bad_where (fixP->fx_file, fixP->fx_line,
12283 _("invalid shift value: %ld"), (long) value);
12284 /* Shifts of zero must be encoded as LSL. */
12285 if (value == 0)
12286 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
12287 /* Shifts of 32 are encoded as zero. */
12288 else if (value == 32)
12289 value = 0;
12290 newval |= value << 6;
12291 md_number_to_chars (buf, newval, THUMB_SIZE);
12292 break;
a737bd4d 12293
c19d1205
ZW
12294 case BFD_RELOC_VTABLE_INHERIT:
12295 case BFD_RELOC_VTABLE_ENTRY:
12296 fixP->fx_done = 0;
12297 return;
6c43fab6 12298
c19d1205
ZW
12299 case BFD_RELOC_UNUSED:
12300 default:
12301 as_bad_where (fixP->fx_file, fixP->fx_line,
12302 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
12303 }
6c43fab6
RE
12304}
12305
c19d1205
ZW
12306/* Translate internal representation of relocation info to BFD target
12307 format. */
a737bd4d 12308
c19d1205 12309arelent *
00a97672 12310tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 12311{
c19d1205
ZW
12312 arelent * reloc;
12313 bfd_reloc_code_real_type code;
a737bd4d 12314
c19d1205 12315 reloc = xmalloc (sizeof (arelent));
a737bd4d 12316
c19d1205
ZW
12317 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
12318 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12319 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 12320
2fc8bdac 12321 if (fixp->fx_pcrel)
00a97672
RS
12322 {
12323 if (section->use_rela_p)
12324 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
12325 else
12326 fixp->fx_offset = reloc->address;
12327 }
c19d1205 12328 reloc->addend = fixp->fx_offset;
a737bd4d 12329
c19d1205 12330 switch (fixp->fx_r_type)
a737bd4d 12331 {
c19d1205
ZW
12332 case BFD_RELOC_8:
12333 if (fixp->fx_pcrel)
12334 {
12335 code = BFD_RELOC_8_PCREL;
12336 break;
12337 }
a737bd4d 12338
c19d1205
ZW
12339 case BFD_RELOC_16:
12340 if (fixp->fx_pcrel)
12341 {
12342 code = BFD_RELOC_16_PCREL;
12343 break;
12344 }
6c43fab6 12345
c19d1205
ZW
12346 case BFD_RELOC_32:
12347 if (fixp->fx_pcrel)
12348 {
12349 code = BFD_RELOC_32_PCREL;
12350 break;
12351 }
a737bd4d 12352
c19d1205
ZW
12353 case BFD_RELOC_NONE:
12354 case BFD_RELOC_ARM_PCREL_BRANCH:
12355 case BFD_RELOC_ARM_PCREL_BLX:
12356 case BFD_RELOC_RVA:
12357 case BFD_RELOC_THUMB_PCREL_BRANCH7:
12358 case BFD_RELOC_THUMB_PCREL_BRANCH9:
12359 case BFD_RELOC_THUMB_PCREL_BRANCH12:
12360 case BFD_RELOC_THUMB_PCREL_BRANCH20:
12361 case BFD_RELOC_THUMB_PCREL_BRANCH23:
12362 case BFD_RELOC_THUMB_PCREL_BRANCH25:
12363 case BFD_RELOC_THUMB_PCREL_BLX:
12364 case BFD_RELOC_VTABLE_ENTRY:
12365 case BFD_RELOC_VTABLE_INHERIT:
12366 code = fixp->fx_r_type;
12367 break;
a737bd4d 12368
c19d1205
ZW
12369 case BFD_RELOC_ARM_LITERAL:
12370 case BFD_RELOC_ARM_HWLITERAL:
12371 /* If this is called then the a literal has
12372 been referenced across a section boundary. */
12373 as_bad_where (fixp->fx_file, fixp->fx_line,
12374 _("literal referenced across section boundary"));
12375 return NULL;
a737bd4d 12376
c19d1205
ZW
12377#ifdef OBJ_ELF
12378 case BFD_RELOC_ARM_GOT32:
12379 case BFD_RELOC_ARM_GOTOFF:
12380 case BFD_RELOC_ARM_PLT32:
12381 case BFD_RELOC_ARM_TARGET1:
12382 case BFD_RELOC_ARM_ROSEGREL32:
12383 case BFD_RELOC_ARM_SBREL32:
12384 case BFD_RELOC_ARM_PREL31:
12385 case BFD_RELOC_ARM_TARGET2:
12386 case BFD_RELOC_ARM_TLS_LE32:
12387 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
12388 case BFD_RELOC_ARM_PCREL_CALL:
12389 case BFD_RELOC_ARM_PCREL_JUMP:
c19d1205
ZW
12390 code = fixp->fx_r_type;
12391 break;
a737bd4d 12392
c19d1205
ZW
12393 case BFD_RELOC_ARM_TLS_GD32:
12394 case BFD_RELOC_ARM_TLS_IE32:
12395 case BFD_RELOC_ARM_TLS_LDM32:
12396 /* BFD will include the symbol's address in the addend.
12397 But we don't want that, so subtract it out again here. */
12398 if (!S_IS_COMMON (fixp->fx_addsy))
12399 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
12400 code = fixp->fx_r_type;
12401 break;
12402#endif
a737bd4d 12403
c19d1205
ZW
12404 case BFD_RELOC_ARM_IMMEDIATE:
12405 as_bad_where (fixp->fx_file, fixp->fx_line,
12406 _("internal relocation (type: IMMEDIATE) not fixed up"));
12407 return NULL;
a737bd4d 12408
c19d1205
ZW
12409 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
12410 as_bad_where (fixp->fx_file, fixp->fx_line,
12411 _("ADRL used for a symbol not defined in the same file"));
12412 return NULL;
a737bd4d 12413
c19d1205 12414 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
12415 if (section->use_rela_p)
12416 {
12417 code = fixp->fx_r_type;
12418 break;
12419 }
12420
c19d1205
ZW
12421 if (fixp->fx_addsy != NULL
12422 && !S_IS_DEFINED (fixp->fx_addsy)
12423 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 12424 {
c19d1205
ZW
12425 as_bad_where (fixp->fx_file, fixp->fx_line,
12426 _("undefined local label `%s'"),
12427 S_GET_NAME (fixp->fx_addsy));
12428 return NULL;
a737bd4d
NC
12429 }
12430
c19d1205
ZW
12431 as_bad_where (fixp->fx_file, fixp->fx_line,
12432 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
12433 return NULL;
a737bd4d 12434
c19d1205
ZW
12435 default:
12436 {
12437 char * type;
6c43fab6 12438
c19d1205
ZW
12439 switch (fixp->fx_r_type)
12440 {
12441 case BFD_RELOC_NONE: type = "NONE"; break;
12442 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
12443 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 12444 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
12445 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
12446 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
12447 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 12448 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
12449 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
12450 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
12451 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
12452 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
12453 default: type = _("<unknown>"); break;
12454 }
12455 as_bad_where (fixp->fx_file, fixp->fx_line,
12456 _("cannot represent %s relocation in this object file format"),
12457 type);
12458 return NULL;
12459 }
a737bd4d 12460 }
6c43fab6 12461
c19d1205
ZW
12462#ifdef OBJ_ELF
12463 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
12464 && GOT_symbol
12465 && fixp->fx_addsy == GOT_symbol)
12466 {
12467 code = BFD_RELOC_ARM_GOTPC;
12468 reloc->addend = fixp->fx_offset = reloc->address;
12469 }
12470#endif
6c43fab6 12471
c19d1205 12472 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 12473
c19d1205
ZW
12474 if (reloc->howto == NULL)
12475 {
12476 as_bad_where (fixp->fx_file, fixp->fx_line,
12477 _("cannot represent %s relocation in this object file format"),
12478 bfd_get_reloc_code_name (code));
12479 return NULL;
12480 }
6c43fab6 12481
c19d1205
ZW
12482 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
12483 vtable entry to be used in the relocation's section offset. */
12484 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12485 reloc->address = fixp->fx_offset;
6c43fab6 12486
c19d1205 12487 return reloc;
6c43fab6
RE
12488}
12489
c19d1205 12490/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 12491
c19d1205
ZW
12492void
12493cons_fix_new_arm (fragS * frag,
12494 int where,
12495 int size,
12496 expressionS * exp)
6c43fab6 12497{
c19d1205
ZW
12498 bfd_reloc_code_real_type type;
12499 int pcrel = 0;
6c43fab6 12500
c19d1205
ZW
12501 /* Pick a reloc.
12502 FIXME: @@ Should look at CPU word size. */
12503 switch (size)
12504 {
12505 case 1:
12506 type = BFD_RELOC_8;
12507 break;
12508 case 2:
12509 type = BFD_RELOC_16;
12510 break;
12511 case 4:
12512 default:
12513 type = BFD_RELOC_32;
12514 break;
12515 case 8:
12516 type = BFD_RELOC_64;
12517 break;
12518 }
6c43fab6 12519
c19d1205
ZW
12520 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
12521}
6c43fab6 12522
c19d1205
ZW
12523#if defined OBJ_COFF || defined OBJ_ELF
12524void
12525arm_validate_fix (fixS * fixP)
6c43fab6 12526{
c19d1205
ZW
12527 /* If the destination of the branch is a defined symbol which does not have
12528 the THUMB_FUNC attribute, then we must be calling a function which has
12529 the (interfacearm) attribute. We look for the Thumb entry point to that
12530 function and change the branch to refer to that function instead. */
12531 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
12532 && fixP->fx_addsy != NULL
12533 && S_IS_DEFINED (fixP->fx_addsy)
12534 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 12535 {
c19d1205 12536 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 12537 }
c19d1205
ZW
12538}
12539#endif
6c43fab6 12540
c19d1205
ZW
12541int
12542arm_force_relocation (struct fix * fixp)
12543{
12544#if defined (OBJ_COFF) && defined (TE_PE)
12545 if (fixp->fx_r_type == BFD_RELOC_RVA)
12546 return 1;
12547#endif
6c43fab6 12548
c19d1205
ZW
12549 /* Resolve these relocations even if the symbol is extern or weak. */
12550 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
12551 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8
PB
12552 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
12553 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
12554 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
12555 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 12556 return 0;
a737bd4d 12557
c19d1205 12558 return generic_force_reloc (fixp);
404ff6b5
AH
12559}
12560
c19d1205
ZW
12561#ifdef OBJ_COFF
12562/* This is a little hack to help the gas/arm/adrl.s test. It prevents
12563 local labels from being added to the output symbol table when they
12564 are used with the ADRL pseudo op. The ADRL relocation should always
12565 be resolved before the binbary is emitted, so it is safe to say that
12566 it is adjustable. */
404ff6b5 12567
c19d1205
ZW
12568bfd_boolean
12569arm_fix_adjustable (fixS * fixP)
404ff6b5 12570{
c19d1205
ZW
12571 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
12572 return 1;
12573 return 0;
404ff6b5 12574}
c19d1205 12575#endif
404ff6b5 12576
c19d1205
ZW
12577#ifdef OBJ_ELF
12578/* Relocations against Thumb function names must be left unadjusted,
12579 so that the linker can use this information to correctly set the
12580 bottom bit of their addresses. The MIPS version of this function
12581 also prevents relocations that are mips-16 specific, but I do not
12582 know why it does this.
404ff6b5 12583
c19d1205
ZW
12584 FIXME:
12585 There is one other problem that ought to be addressed here, but
12586 which currently is not: Taking the address of a label (rather
12587 than a function) and then later jumping to that address. Such
12588 addresses also ought to have their bottom bit set (assuming that
12589 they reside in Thumb code), but at the moment they will not. */
404ff6b5 12590
c19d1205
ZW
12591bfd_boolean
12592arm_fix_adjustable (fixS * fixP)
404ff6b5 12593{
c19d1205
ZW
12594 if (fixP->fx_addsy == NULL)
12595 return 1;
404ff6b5 12596
c19d1205
ZW
12597 if (THUMB_IS_FUNC (fixP->fx_addsy)
12598 && fixP->fx_subsy == NULL)
12599 return 0;
a737bd4d 12600
c19d1205
ZW
12601 /* We need the symbol name for the VTABLE entries. */
12602 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12603 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12604 return 0;
404ff6b5 12605
c19d1205
ZW
12606 /* Don't allow symbols to be discarded on GOT related relocs. */
12607 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
12608 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
12609 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
12610 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
12611 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
12612 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
12613 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
12614 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
12615 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
12616 return 0;
a737bd4d 12617
c19d1205 12618 return 1;
a737bd4d 12619}
404ff6b5 12620
c19d1205
ZW
12621const char *
12622elf32_arm_target_format (void)
404ff6b5 12623{
c19d1205
ZW
12624#ifdef TE_SYMBIAN
12625 return (target_big_endian
12626 ? "elf32-bigarm-symbian"
12627 : "elf32-littlearm-symbian");
12628#elif defined (TE_VXWORKS)
12629 return (target_big_endian
12630 ? "elf32-bigarm-vxworks"
12631 : "elf32-littlearm-vxworks");
12632#else
12633 if (target_big_endian)
12634 return "elf32-bigarm";
12635 else
12636 return "elf32-littlearm";
12637#endif
404ff6b5
AH
12638}
12639
c19d1205
ZW
12640void
12641armelf_frob_symbol (symbolS * symp,
12642 int * puntp)
404ff6b5 12643{
c19d1205
ZW
12644 elf_frob_symbol (symp, puntp);
12645}
12646#endif
404ff6b5 12647
c19d1205 12648/* MD interface: Finalization. */
a737bd4d 12649
c19d1205
ZW
12650/* A good place to do this, although this was probably not intended
12651 for this kind of use. We need to dump the literal pool before
12652 references are made to a null symbol pointer. */
a737bd4d 12653
c19d1205
ZW
12654void
12655arm_cleanup (void)
12656{
12657 literal_pool * pool;
a737bd4d 12658
c19d1205
ZW
12659 for (pool = list_of_pools; pool; pool = pool->next)
12660 {
12661 /* Put it at the end of the relevent section. */
12662 subseg_set (pool->section, pool->sub_section);
12663#ifdef OBJ_ELF
12664 arm_elf_change_section ();
12665#endif
12666 s_ltorg (0);
12667 }
404ff6b5
AH
12668}
12669
c19d1205
ZW
12670/* Adjust the symbol table. This marks Thumb symbols as distinct from
12671 ARM ones. */
404ff6b5 12672
c19d1205
ZW
12673void
12674arm_adjust_symtab (void)
404ff6b5 12675{
c19d1205
ZW
12676#ifdef OBJ_COFF
12677 symbolS * sym;
404ff6b5 12678
c19d1205
ZW
12679 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12680 {
12681 if (ARM_IS_THUMB (sym))
12682 {
12683 if (THUMB_IS_FUNC (sym))
12684 {
12685 /* Mark the symbol as a Thumb function. */
12686 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
12687 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
12688 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 12689
c19d1205
ZW
12690 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
12691 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
12692 else
12693 as_bad (_("%s: unexpected function type: %d"),
12694 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
12695 }
12696 else switch (S_GET_STORAGE_CLASS (sym))
12697 {
12698 case C_EXT:
12699 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
12700 break;
12701 case C_STAT:
12702 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
12703 break;
12704 case C_LABEL:
12705 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
12706 break;
12707 default:
12708 /* Do nothing. */
12709 break;
12710 }
12711 }
a737bd4d 12712
c19d1205
ZW
12713 if (ARM_IS_INTERWORK (sym))
12714 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 12715 }
c19d1205
ZW
12716#endif
12717#ifdef OBJ_ELF
12718 symbolS * sym;
12719 char bind;
404ff6b5 12720
c19d1205 12721 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 12722 {
c19d1205
ZW
12723 if (ARM_IS_THUMB (sym))
12724 {
12725 elf_symbol_type * elf_sym;
404ff6b5 12726
c19d1205
ZW
12727 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
12728 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 12729
c19d1205
ZW
12730 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
12731 {
12732 /* If it's a .thumb_func, declare it as so,
12733 otherwise tag label as .code 16. */
12734 if (THUMB_IS_FUNC (sym))
12735 elf_sym->internal_elf_sym.st_info =
12736 ELF_ST_INFO (bind, STT_ARM_TFUNC);
12737 else
12738 elf_sym->internal_elf_sym.st_info =
12739 ELF_ST_INFO (bind, STT_ARM_16BIT);
12740 }
12741 }
12742 }
12743#endif
404ff6b5
AH
12744}
12745
c19d1205 12746/* MD interface: Initialization. */
404ff6b5 12747
a737bd4d 12748static void
c19d1205 12749set_constant_flonums (void)
a737bd4d 12750{
c19d1205 12751 int i;
404ff6b5 12752
c19d1205
ZW
12753 for (i = 0; i < NUM_FLOAT_VALS; i++)
12754 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
12755 abort ();
a737bd4d 12756}
404ff6b5 12757
c19d1205
ZW
12758void
12759md_begin (void)
a737bd4d 12760{
c19d1205
ZW
12761 unsigned mach;
12762 unsigned int i;
404ff6b5 12763
c19d1205
ZW
12764 if ( (arm_ops_hsh = hash_new ()) == NULL
12765 || (arm_cond_hsh = hash_new ()) == NULL
12766 || (arm_shift_hsh = hash_new ()) == NULL
12767 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 12768 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 12769 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
12770 || (arm_reloc_hsh = hash_new ()) == NULL
12771 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
12772 as_fatal (_("virtual memory exhausted"));
12773
12774 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
12775 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
12776 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
12777 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
12778 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
12779 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
12780 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
12781 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
12782 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
12783 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
12784 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
12785 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
12786 for (i = 0;
12787 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
12788 i++)
12789 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
12790 (PTR) (barrier_opt_names + i));
c19d1205
ZW
12791#ifdef OBJ_ELF
12792 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
12793 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
12794#endif
12795
12796 set_constant_flonums ();
404ff6b5 12797
c19d1205
ZW
12798 /* Set the cpu variant based on the command-line options. We prefer
12799 -mcpu= over -march= if both are set (as for GCC); and we prefer
12800 -mfpu= over any other way of setting the floating point unit.
12801 Use of legacy options with new options are faulted. */
e74cfd16 12802 if (legacy_cpu)
404ff6b5 12803 {
e74cfd16 12804 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
12805 as_bad (_("use of old and new-style options to set CPU type"));
12806
12807 mcpu_cpu_opt = legacy_cpu;
404ff6b5 12808 }
e74cfd16 12809 else if (!mcpu_cpu_opt)
c19d1205 12810 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 12811
e74cfd16 12812 if (legacy_fpu)
c19d1205 12813 {
e74cfd16 12814 if (mfpu_opt)
c19d1205 12815 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
12816
12817 mfpu_opt = legacy_fpu;
12818 }
e74cfd16 12819 else if (!mfpu_opt)
03b1477f 12820 {
c19d1205 12821#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
12822 /* Some environments specify a default FPU. If they don't, infer it
12823 from the processor. */
e74cfd16 12824 if (mcpu_fpu_opt)
03b1477f
RE
12825 mfpu_opt = mcpu_fpu_opt;
12826 else
12827 mfpu_opt = march_fpu_opt;
39c2da32 12828#else
e74cfd16 12829 mfpu_opt = &fpu_default;
39c2da32 12830#endif
03b1477f
RE
12831 }
12832
e74cfd16 12833 if (!mfpu_opt)
03b1477f 12834 {
e74cfd16
PB
12835 if (!mcpu_cpu_opt)
12836 mfpu_opt = &fpu_default;
12837 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
12838 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 12839 else
e74cfd16 12840 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
12841 }
12842
ee065d83 12843#ifdef CPU_DEFAULT
e74cfd16 12844 if (!mcpu_cpu_opt)
ee065d83 12845 {
e74cfd16
PB
12846 mcpu_cpu_opt = &cpu_default;
12847 selected_cpu = cpu_default;
ee065d83 12848 }
e74cfd16
PB
12849#else
12850 if (mcpu_cpu_opt)
12851 selected_cpu = *mcpu_cpu_opt;
ee065d83 12852 else
e74cfd16 12853 mcpu_cpu_opt = &arm_arch_any;
ee065d83 12854#endif
03b1477f 12855
e74cfd16 12856 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 12857
e74cfd16 12858 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 12859
f17c130b 12860#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 12861 {
7cc69913
NC
12862 unsigned int flags = 0;
12863
12864#if defined OBJ_ELF
12865 flags = meabi_flags;
d507cf36
PB
12866
12867 switch (meabi_flags)
33a392fb 12868 {
d507cf36 12869 case EF_ARM_EABI_UNKNOWN:
7cc69913 12870#endif
d507cf36
PB
12871 /* Set the flags in the private structure. */
12872 if (uses_apcs_26) flags |= F_APCS26;
12873 if (support_interwork) flags |= F_INTERWORK;
12874 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 12875 if (pic_code) flags |= F_PIC;
e74cfd16 12876 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
12877 flags |= F_SOFT_FLOAT;
12878
d507cf36
PB
12879 switch (mfloat_abi_opt)
12880 {
12881 case ARM_FLOAT_ABI_SOFT:
12882 case ARM_FLOAT_ABI_SOFTFP:
12883 flags |= F_SOFT_FLOAT;
12884 break;
33a392fb 12885
d507cf36
PB
12886 case ARM_FLOAT_ABI_HARD:
12887 if (flags & F_SOFT_FLOAT)
12888 as_bad (_("hard-float conflicts with specified fpu"));
12889 break;
12890 }
03b1477f 12891
e74cfd16
PB
12892 /* Using pure-endian doubles (even if soft-float). */
12893 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 12894 flags |= F_VFP_FLOAT;
f17c130b 12895
fde78edd 12896#if defined OBJ_ELF
e74cfd16 12897 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 12898 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
12899 break;
12900
8cb51566 12901 case EF_ARM_EABI_VER4:
3a4a14e9 12902 case EF_ARM_EABI_VER5:
c19d1205 12903 /* No additional flags to set. */
d507cf36
PB
12904 break;
12905
12906 default:
12907 abort ();
12908 }
7cc69913 12909#endif
b99bd4ef
NC
12910 bfd_set_private_flags (stdoutput, flags);
12911
12912 /* We have run out flags in the COFF header to encode the
12913 status of ATPCS support, so instead we create a dummy,
c19d1205 12914 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
12915 if (atpcs)
12916 {
12917 asection * sec;
12918
12919 sec = bfd_make_section (stdoutput, ".arm.atpcs");
12920
12921 if (sec != NULL)
12922 {
12923 bfd_set_section_flags
12924 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
12925 bfd_set_section_size (stdoutput, sec, 0);
12926 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
12927 }
12928 }
7cc69913 12929 }
f17c130b 12930#endif
b99bd4ef
NC
12931
12932 /* Record the CPU type as well. */
e74cfd16 12933 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 12934 mach = bfd_mach_arm_iWMMXt;
e74cfd16 12935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 12936 mach = bfd_mach_arm_XScale;
e74cfd16 12937 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 12938 mach = bfd_mach_arm_ep9312;
e74cfd16 12939 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 12940 mach = bfd_mach_arm_5TE;
e74cfd16 12941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 12942 {
e74cfd16 12943 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
12944 mach = bfd_mach_arm_5T;
12945 else
12946 mach = bfd_mach_arm_5;
12947 }
e74cfd16 12948 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 12949 {
e74cfd16 12950 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
12951 mach = bfd_mach_arm_4T;
12952 else
12953 mach = bfd_mach_arm_4;
12954 }
e74cfd16 12955 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 12956 mach = bfd_mach_arm_3M;
e74cfd16
PB
12957 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
12958 mach = bfd_mach_arm_3;
12959 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
12960 mach = bfd_mach_arm_2a;
12961 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
12962 mach = bfd_mach_arm_2;
12963 else
12964 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
12965
12966 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
12967}
12968
c19d1205 12969/* Command line processing. */
b99bd4ef 12970
c19d1205
ZW
12971/* md_parse_option
12972 Invocation line includes a switch not recognized by the base assembler.
12973 See if it's a processor-specific option.
b99bd4ef 12974
c19d1205
ZW
12975 This routine is somewhat complicated by the need for backwards
12976 compatibility (since older releases of gcc can't be changed).
12977 The new options try to make the interface as compatible as
12978 possible with GCC.
b99bd4ef 12979
c19d1205 12980 New options (supported) are:
b99bd4ef 12981
c19d1205
ZW
12982 -mcpu=<cpu name> Assemble for selected processor
12983 -march=<architecture name> Assemble for selected architecture
12984 -mfpu=<fpu architecture> Assemble for selected FPU.
12985 -EB/-mbig-endian Big-endian
12986 -EL/-mlittle-endian Little-endian
12987 -k Generate PIC code
12988 -mthumb Start in Thumb mode
12989 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 12990
c19d1205 12991 For now we will also provide support for:
b99bd4ef 12992
c19d1205
ZW
12993 -mapcs-32 32-bit Program counter
12994 -mapcs-26 26-bit Program counter
12995 -macps-float Floats passed in FP registers
12996 -mapcs-reentrant Reentrant code
12997 -matpcs
12998 (sometime these will probably be replaced with -mapcs=<list of options>
12999 and -matpcs=<list of options>)
b99bd4ef 13000
c19d1205
ZW
13001 The remaining options are only supported for back-wards compatibility.
13002 Cpu variants, the arm part is optional:
13003 -m[arm]1 Currently not supported.
13004 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
13005 -m[arm]3 Arm 3 processor
13006 -m[arm]6[xx], Arm 6 processors
13007 -m[arm]7[xx][t][[d]m] Arm 7 processors
13008 -m[arm]8[10] Arm 8 processors
13009 -m[arm]9[20][tdmi] Arm 9 processors
13010 -mstrongarm[110[0]] StrongARM processors
13011 -mxscale XScale processors
13012 -m[arm]v[2345[t[e]]] Arm architectures
13013 -mall All (except the ARM1)
13014 FP variants:
13015 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
13016 -mfpe-old (No float load/store multiples)
13017 -mvfpxd VFP Single precision
13018 -mvfp All VFP
13019 -mno-fpu Disable all floating point instructions
b99bd4ef 13020
c19d1205
ZW
13021 The following CPU names are recognized:
13022 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
13023 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
13024 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
13025 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
13026 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
13027 arm10t arm10e, arm1020t, arm1020e, arm10200e,
13028 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 13029
c19d1205 13030 */
b99bd4ef 13031
c19d1205 13032const char * md_shortopts = "m:k";
b99bd4ef 13033
c19d1205
ZW
13034#ifdef ARM_BI_ENDIAN
13035#define OPTION_EB (OPTION_MD_BASE + 0)
13036#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 13037#else
c19d1205
ZW
13038#if TARGET_BYTES_BIG_ENDIAN
13039#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 13040#else
c19d1205
ZW
13041#define OPTION_EL (OPTION_MD_BASE + 1)
13042#endif
b99bd4ef 13043#endif
b99bd4ef 13044
c19d1205 13045struct option md_longopts[] =
b99bd4ef 13046{
c19d1205
ZW
13047#ifdef OPTION_EB
13048 {"EB", no_argument, NULL, OPTION_EB},
13049#endif
13050#ifdef OPTION_EL
13051 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 13052#endif
c19d1205
ZW
13053 {NULL, no_argument, NULL, 0}
13054};
b99bd4ef 13055
c19d1205 13056size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 13057
c19d1205 13058struct arm_option_table
b99bd4ef 13059{
c19d1205
ZW
13060 char *option; /* Option name to match. */
13061 char *help; /* Help information. */
13062 int *var; /* Variable to change. */
13063 int value; /* What to change it to. */
13064 char *deprecated; /* If non-null, print this message. */
13065};
b99bd4ef 13066
c19d1205
ZW
13067struct arm_option_table arm_opts[] =
13068{
13069 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
13070 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
13071 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
13072 &support_interwork, 1, NULL},
13073 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
13074 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
13075 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
13076 1, NULL},
13077 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
13078 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
13079 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
13080 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
13081 NULL},
b99bd4ef 13082
c19d1205
ZW
13083 /* These are recognized by the assembler, but have no affect on code. */
13084 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
13085 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
13086 {NULL, NULL, NULL, 0, NULL}
13087};
13088
13089struct arm_legacy_option_table
13090{
13091 char *option; /* Option name to match. */
13092 const arm_feature_set **var; /* Variable to change. */
13093 const arm_feature_set value; /* What to change it to. */
13094 char *deprecated; /* If non-null, print this message. */
13095};
b99bd4ef 13096
e74cfd16
PB
13097const struct arm_legacy_option_table arm_legacy_opts[] =
13098{
c19d1205
ZW
13099 /* DON'T add any new processors to this list -- we want the whole list
13100 to go away... Add them to the processors table instead. */
e74cfd16
PB
13101 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13102 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13103 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13104 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13105 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13106 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13107 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13108 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13109 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13110 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13111 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13112 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13113 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13114 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13115 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13116 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13117 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13118 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13119 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13120 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13121 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13122 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13123 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13124 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13125 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13126 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13127 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13128 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13129 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13130 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13131 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13132 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13133 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13134 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13135 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13136 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13137 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13138 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13139 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13140 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13141 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13142 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13143 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13144 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13145 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13146 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13147 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13148 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13149 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13150 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13151 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13152 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13153 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13154 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13155 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13156 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13157 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13158 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13159 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13160 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13161 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13162 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13163 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13164 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13165 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13166 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13167 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13168 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13169 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
13170 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13171 N_("use -mcpu=strongarm110")},
e74cfd16 13172 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13173 N_("use -mcpu=strongarm1100")},
e74cfd16 13174 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13175 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
13176 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
13177 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
13178 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 13179
c19d1205 13180 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
13181 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13182 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13183 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13184 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13185 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13186 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13187 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13188 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13189 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13190 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13191 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13192 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13193 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13194 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13195 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13196 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13197 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
13198 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 13199
c19d1205 13200 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
13201 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
13202 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
13203 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
13204 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 13205 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 13206
e74cfd16 13207 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 13208};
7ed4c4c5 13209
c19d1205 13210struct arm_cpu_option_table
7ed4c4c5 13211{
c19d1205 13212 char *name;
e74cfd16 13213 const arm_feature_set value;
c19d1205
ZW
13214 /* For some CPUs we assume an FPU unless the user explicitly sets
13215 -mfpu=... */
e74cfd16 13216 const arm_feature_set default_fpu;
ee065d83
PB
13217 /* The canonical name of the CPU, or NULL to use NAME converted to upper
13218 case. */
13219 const char *canonical_name;
c19d1205 13220};
7ed4c4c5 13221
c19d1205
ZW
13222/* This list should, at a minimum, contain all the cpu names
13223 recognized by GCC. */
e74cfd16 13224static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 13225{
ee065d83
PB
13226 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
13227 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
13228 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
13229 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13230 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13231 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13232 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13233 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13234 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13235 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13236 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13237 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13238 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13239 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13240 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13241 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13242 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13243 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13244 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13245 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13246 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13247 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13248 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13249 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13250 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13251 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13252 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13253 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13254 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13255 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13256 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13257 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13258 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13259 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13260 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13261 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13262 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13263 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13264 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13265 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
13266 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13267 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13268 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13269 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
13270 /* For V5 or later processors we default to using VFP; but the user
13271 should really set the FPU type explicitly. */
ee065d83
PB
13272 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13273 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13274 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13275 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13276 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13277 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13278 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
13279 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13280 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13281 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
13282 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13283 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13284 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13285 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13286 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13287 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
13288 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13289 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13290 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13291 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
13292 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13293 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
13294 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
13295 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
13296 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
13297 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
13298 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
13299 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
13300 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
13301 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
13302 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
62b3e311
PB
13303 {"cortex-a8", ARM_ARCH_V7A, FPU_ARCH_VFP_V2, NULL},
13304 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
13305 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 13306 /* ??? XSCALE is really an architecture. */
ee065d83 13307 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 13308 /* ??? iwmmxt is not a processor. */
ee065d83
PB
13309 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
13310 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 13311 /* Maverick */
e74cfd16
PB
13312 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
13313 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 13314};
7ed4c4c5 13315
c19d1205 13316struct arm_arch_option_table
7ed4c4c5 13317{
c19d1205 13318 char *name;
e74cfd16
PB
13319 const arm_feature_set value;
13320 const arm_feature_set default_fpu;
c19d1205 13321};
7ed4c4c5 13322
c19d1205
ZW
13323/* This list should, at a minimum, contain all the architecture names
13324 recognized by GCC. */
e74cfd16 13325static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
13326{
13327 {"all", ARM_ANY, FPU_ARCH_FPA},
13328 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
13329 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
13330 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
13331 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
13332 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
13333 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
13334 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
13335 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
13336 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
13337 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
13338 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
13339 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
13340 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
13341 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
13342 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
13343 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
13344 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
13345 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
13346 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
13347 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
13348 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
13349 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
13350 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
13351 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
13352 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311
PB
13353 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
13354 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
13355 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
13356 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
13357 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
13358 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
e74cfd16 13359 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 13360};
7ed4c4c5 13361
c19d1205 13362/* ISA extensions in the co-processor space. */
e74cfd16 13363struct arm_option_cpu_value_table
c19d1205
ZW
13364{
13365 char *name;
e74cfd16 13366 const arm_feature_set value;
c19d1205 13367};
7ed4c4c5 13368
e74cfd16 13369static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 13370{
e74cfd16
PB
13371 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
13372 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
13373 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
13374 {NULL, ARM_ARCH_NONE}
c19d1205 13375};
7ed4c4c5 13376
c19d1205
ZW
13377/* This list should, at a minimum, contain all the fpu names
13378 recognized by GCC. */
e74cfd16 13379static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
13380{
13381 {"softfpa", FPU_NONE},
13382 {"fpe", FPU_ARCH_FPE},
13383 {"fpe2", FPU_ARCH_FPE},
13384 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
13385 {"fpa", FPU_ARCH_FPA},
13386 {"fpa10", FPU_ARCH_FPA},
13387 {"fpa11", FPU_ARCH_FPA},
13388 {"arm7500fe", FPU_ARCH_FPA},
13389 {"softvfp", FPU_ARCH_VFP},
13390 {"softvfp+vfp", FPU_ARCH_VFP_V2},
13391 {"vfp", FPU_ARCH_VFP_V2},
13392 {"vfp9", FPU_ARCH_VFP_V2},
13393 {"vfp10", FPU_ARCH_VFP_V2},
13394 {"vfp10-r0", FPU_ARCH_VFP_V1},
13395 {"vfpxd", FPU_ARCH_VFP_V1xD},
13396 {"arm1020t", FPU_ARCH_VFP_V1},
13397 {"arm1020e", FPU_ARCH_VFP_V2},
13398 {"arm1136jfs", FPU_ARCH_VFP_V2},
13399 {"arm1136jf-s", FPU_ARCH_VFP_V2},
13400 {"maverick", FPU_ARCH_MAVERICK},
e74cfd16
PB
13401 {NULL, ARM_ARCH_NONE}
13402};
13403
13404struct arm_option_value_table
13405{
13406 char *name;
13407 long value;
c19d1205 13408};
7ed4c4c5 13409
e74cfd16 13410static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
13411{
13412 {"hard", ARM_FLOAT_ABI_HARD},
13413 {"softfp", ARM_FLOAT_ABI_SOFTFP},
13414 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 13415 {NULL, 0}
c19d1205 13416};
7ed4c4c5 13417
c19d1205 13418#ifdef OBJ_ELF
3a4a14e9 13419/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 13420static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
13421{
13422 {"gnu", EF_ARM_EABI_UNKNOWN},
13423 {"4", EF_ARM_EABI_VER4},
3a4a14e9 13424 {"5", EF_ARM_EABI_VER5},
e74cfd16 13425 {NULL, 0}
c19d1205
ZW
13426};
13427#endif
7ed4c4c5 13428
c19d1205
ZW
13429struct arm_long_option_table
13430{
13431 char * option; /* Substring to match. */
13432 char * help; /* Help information. */
13433 int (* func) (char * subopt); /* Function to decode sub-option. */
13434 char * deprecated; /* If non-null, print this message. */
13435};
7ed4c4c5
NC
13436
13437static int
e74cfd16 13438arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 13439{
e74cfd16
PB
13440 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
13441
13442 /* Copy the feature set, so that we can modify it. */
13443 *ext_set = **opt_p;
13444 *opt_p = ext_set;
13445
c19d1205 13446 while (str != NULL && *str != 0)
7ed4c4c5 13447 {
e74cfd16 13448 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
13449 char * ext;
13450 int optlen;
7ed4c4c5 13451
c19d1205
ZW
13452 if (*str != '+')
13453 {
13454 as_bad (_("invalid architectural extension"));
13455 return 0;
13456 }
7ed4c4c5 13457
c19d1205
ZW
13458 str++;
13459 ext = strchr (str, '+');
7ed4c4c5 13460
c19d1205
ZW
13461 if (ext != NULL)
13462 optlen = ext - str;
13463 else
13464 optlen = strlen (str);
7ed4c4c5 13465
c19d1205
ZW
13466 if (optlen == 0)
13467 {
13468 as_bad (_("missing architectural extension"));
13469 return 0;
13470 }
7ed4c4c5 13471
c19d1205
ZW
13472 for (opt = arm_extensions; opt->name != NULL; opt++)
13473 if (strncmp (opt->name, str, optlen) == 0)
13474 {
e74cfd16 13475 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
13476 break;
13477 }
7ed4c4c5 13478
c19d1205
ZW
13479 if (opt->name == NULL)
13480 {
13481 as_bad (_("unknown architectural extnsion `%s'"), str);
13482 return 0;
13483 }
7ed4c4c5 13484
c19d1205
ZW
13485 str = ext;
13486 };
7ed4c4c5 13487
c19d1205
ZW
13488 return 1;
13489}
7ed4c4c5 13490
c19d1205
ZW
13491static int
13492arm_parse_cpu (char * str)
7ed4c4c5 13493{
e74cfd16 13494 const struct arm_cpu_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 cpu name `%s'"), str);
13506 return 0;
7ed4c4c5
NC
13507 }
13508
c19d1205
ZW
13509 for (opt = arm_cpus; opt->name != NULL; opt++)
13510 if (strncmp (opt->name, str, optlen) == 0)
13511 {
e74cfd16
PB
13512 mcpu_cpu_opt = &opt->value;
13513 mcpu_fpu_opt = &opt->default_fpu;
ee065d83
PB
13514 if (opt->canonical_name)
13515 strcpy(selected_cpu_name, opt->canonical_name);
13516 else
13517 {
13518 int i;
13519 for (i = 0; i < optlen; i++)
13520 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13521 selected_cpu_name[i] = 0;
13522 }
7ed4c4c5 13523
c19d1205
ZW
13524 if (ext != NULL)
13525 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 13526
c19d1205
ZW
13527 return 1;
13528 }
7ed4c4c5 13529
c19d1205
ZW
13530 as_bad (_("unknown cpu `%s'"), str);
13531 return 0;
7ed4c4c5
NC
13532}
13533
c19d1205
ZW
13534static int
13535arm_parse_arch (char * str)
7ed4c4c5 13536{
e74cfd16 13537 const struct arm_arch_option_table *opt;
c19d1205
ZW
13538 char *ext = strchr (str, '+');
13539 int optlen;
7ed4c4c5 13540
c19d1205
ZW
13541 if (ext != NULL)
13542 optlen = ext - str;
7ed4c4c5 13543 else
c19d1205 13544 optlen = strlen (str);
7ed4c4c5 13545
c19d1205 13546 if (optlen == 0)
7ed4c4c5 13547 {
c19d1205
ZW
13548 as_bad (_("missing architecture name `%s'"), str);
13549 return 0;
7ed4c4c5
NC
13550 }
13551
c19d1205
ZW
13552 for (opt = arm_archs; opt->name != NULL; opt++)
13553 if (streq (opt->name, str))
13554 {
e74cfd16
PB
13555 march_cpu_opt = &opt->value;
13556 march_fpu_opt = &opt->default_fpu;
ee065d83 13557 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 13558
c19d1205
ZW
13559 if (ext != NULL)
13560 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 13561
c19d1205
ZW
13562 return 1;
13563 }
13564
13565 as_bad (_("unknown architecture `%s'\n"), str);
13566 return 0;
7ed4c4c5 13567}
eb043451 13568
c19d1205
ZW
13569static int
13570arm_parse_fpu (char * str)
13571{
e74cfd16 13572 const struct arm_option_cpu_value_table * opt;
b99bd4ef 13573
c19d1205
ZW
13574 for (opt = arm_fpus; opt->name != NULL; opt++)
13575 if (streq (opt->name, str))
13576 {
e74cfd16 13577 mfpu_opt = &opt->value;
c19d1205
ZW
13578 return 1;
13579 }
b99bd4ef 13580
c19d1205
ZW
13581 as_bad (_("unknown floating point format `%s'\n"), str);
13582 return 0;
13583}
13584
13585static int
13586arm_parse_float_abi (char * str)
b99bd4ef 13587{
e74cfd16 13588 const struct arm_option_value_table * opt;
b99bd4ef 13589
c19d1205
ZW
13590 for (opt = arm_float_abis; opt->name != NULL; opt++)
13591 if (streq (opt->name, str))
13592 {
13593 mfloat_abi_opt = opt->value;
13594 return 1;
13595 }
cc8a6dd0 13596
c19d1205
ZW
13597 as_bad (_("unknown floating point abi `%s'\n"), str);
13598 return 0;
13599}
b99bd4ef 13600
c19d1205
ZW
13601#ifdef OBJ_ELF
13602static int
13603arm_parse_eabi (char * str)
13604{
e74cfd16 13605 const struct arm_option_value_table *opt;
cc8a6dd0 13606
c19d1205
ZW
13607 for (opt = arm_eabis; opt->name != NULL; opt++)
13608 if (streq (opt->name, str))
13609 {
13610 meabi_flags = opt->value;
13611 return 1;
13612 }
13613 as_bad (_("unknown EABI `%s'\n"), str);
13614 return 0;
13615}
13616#endif
cc8a6dd0 13617
c19d1205
ZW
13618struct arm_long_option_table arm_long_opts[] =
13619{
13620 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
13621 arm_parse_cpu, NULL},
13622 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
13623 arm_parse_arch, NULL},
13624 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
13625 arm_parse_fpu, NULL},
13626 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
13627 arm_parse_float_abi, NULL},
13628#ifdef OBJ_ELF
13629 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
13630 arm_parse_eabi, NULL},
13631#endif
13632 {NULL, NULL, 0, NULL}
13633};
cc8a6dd0 13634
c19d1205
ZW
13635int
13636md_parse_option (int c, char * arg)
13637{
13638 struct arm_option_table *opt;
e74cfd16 13639 const struct arm_legacy_option_table *fopt;
c19d1205 13640 struct arm_long_option_table *lopt;
b99bd4ef 13641
c19d1205 13642 switch (c)
b99bd4ef 13643 {
c19d1205
ZW
13644#ifdef OPTION_EB
13645 case OPTION_EB:
13646 target_big_endian = 1;
13647 break;
13648#endif
cc8a6dd0 13649
c19d1205
ZW
13650#ifdef OPTION_EL
13651 case OPTION_EL:
13652 target_big_endian = 0;
13653 break;
13654#endif
b99bd4ef 13655
c19d1205
ZW
13656 case 'a':
13657 /* Listing option. Just ignore these, we don't support additional
13658 ones. */
13659 return 0;
b99bd4ef 13660
c19d1205
ZW
13661 default:
13662 for (opt = arm_opts; opt->option != NULL; opt++)
13663 {
13664 if (c == opt->option[0]
13665 && ((arg == NULL && opt->option[1] == 0)
13666 || streq (arg, opt->option + 1)))
13667 {
13668#if WARN_DEPRECATED
13669 /* If the option is deprecated, tell the user. */
13670 if (opt->deprecated != NULL)
13671 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13672 arg ? arg : "", _(opt->deprecated));
13673#endif
b99bd4ef 13674
c19d1205
ZW
13675 if (opt->var != NULL)
13676 *opt->var = opt->value;
cc8a6dd0 13677
c19d1205
ZW
13678 return 1;
13679 }
13680 }
b99bd4ef 13681
e74cfd16
PB
13682 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
13683 {
13684 if (c == fopt->option[0]
13685 && ((arg == NULL && fopt->option[1] == 0)
13686 || streq (arg, fopt->option + 1)))
13687 {
13688#if WARN_DEPRECATED
13689 /* If the option is deprecated, tell the user. */
13690 if (fopt->deprecated != NULL)
13691 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13692 arg ? arg : "", _(fopt->deprecated));
13693#endif
13694
13695 if (fopt->var != NULL)
13696 *fopt->var = &fopt->value;
13697
13698 return 1;
13699 }
13700 }
13701
c19d1205
ZW
13702 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13703 {
13704 /* These options are expected to have an argument. */
13705 if (c == lopt->option[0]
13706 && arg != NULL
13707 && strncmp (arg, lopt->option + 1,
13708 strlen (lopt->option + 1)) == 0)
13709 {
13710#if WARN_DEPRECATED
13711 /* If the option is deprecated, tell the user. */
13712 if (lopt->deprecated != NULL)
13713 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
13714 _(lopt->deprecated));
13715#endif
b99bd4ef 13716
c19d1205
ZW
13717 /* Call the sup-option parser. */
13718 return lopt->func (arg + strlen (lopt->option) - 1);
13719 }
13720 }
a737bd4d 13721
c19d1205
ZW
13722 return 0;
13723 }
a394c00f 13724
c19d1205
ZW
13725 return 1;
13726}
a394c00f 13727
c19d1205
ZW
13728void
13729md_show_usage (FILE * fp)
a394c00f 13730{
c19d1205
ZW
13731 struct arm_option_table *opt;
13732 struct arm_long_option_table *lopt;
a394c00f 13733
c19d1205 13734 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 13735
c19d1205
ZW
13736 for (opt = arm_opts; opt->option != NULL; opt++)
13737 if (opt->help != NULL)
13738 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 13739
c19d1205
ZW
13740 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13741 if (lopt->help != NULL)
13742 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 13743
c19d1205
ZW
13744#ifdef OPTION_EB
13745 fprintf (fp, _("\
13746 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
13747#endif
13748
c19d1205
ZW
13749#ifdef OPTION_EL
13750 fprintf (fp, _("\
13751 -EL assemble code for a little-endian cpu\n"));
a737bd4d 13752#endif
c19d1205 13753}
ee065d83
PB
13754
13755
13756#ifdef OBJ_ELF
62b3e311
PB
13757typedef struct
13758{
13759 int val;
13760 arm_feature_set flags;
13761} cpu_arch_ver_table;
13762
13763/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
13764 least features first. */
13765static const cpu_arch_ver_table cpu_arch_ver[] =
13766{
13767 {1, ARM_ARCH_V4},
13768 {2, ARM_ARCH_V4T},
13769 {3, ARM_ARCH_V5},
13770 {4, ARM_ARCH_V5TE},
13771 {5, ARM_ARCH_V5TEJ},
13772 {6, ARM_ARCH_V6},
13773 {7, ARM_ARCH_V6Z},
13774 {8, ARM_ARCH_V6K},
13775 {9, ARM_ARCH_V6T2},
13776 {10, ARM_ARCH_V7A},
13777 {10, ARM_ARCH_V7R},
13778 {10, ARM_ARCH_V7M},
13779 {0, ARM_ARCH_NONE}
13780};
13781
ee065d83
PB
13782/* Set the public EABI object attributes. */
13783static void
13784aeabi_set_public_attributes (void)
13785{
13786 int arch;
e74cfd16 13787 arm_feature_set flags;
62b3e311
PB
13788 arm_feature_set tmp;
13789 const cpu_arch_ver_table *p;
ee065d83
PB
13790
13791 /* Choose the architecture based on the capabilities of the requested cpu
13792 (if any) and/or the instructions actually used. */
e74cfd16
PB
13793 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
13794 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
13795 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
62b3e311
PB
13796
13797 tmp = flags;
13798 arch = 0;
13799 for (p = cpu_arch_ver; p->val; p++)
13800 {
13801 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
13802 {
13803 arch = p->val;
13804 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
13805 }
13806 }
ee065d83
PB
13807
13808 /* Tag_CPU_name. */
13809 if (selected_cpu_name[0])
13810 {
13811 char *p;
13812
13813 p = selected_cpu_name;
13814 if (strncmp(p, "armv", 4) == 0)
13815 {
13816 int i;
13817
13818 p += 4;
13819 for (i = 0; p[i]; i++)
13820 p[i] = TOUPPER (p[i]);
13821 }
13822 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
13823 }
13824 /* Tag_CPU_arch. */
13825 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
62b3e311
PB
13826 /* Tag_CPU_arch_profile. */
13827 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
13828 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
13829 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
13830 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
13831 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
13832 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
ee065d83 13833 /* Tag_ARM_ISA_use. */
e74cfd16 13834 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
ee065d83
PB
13835 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
13836 /* Tag_THUMB_ISA_use. */
e74cfd16 13837 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
ee065d83 13838 elf32_arm_add_eabi_attr_int (stdoutput, 9,
e74cfd16 13839 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 13840 /* Tag_VFP_arch. */
e74cfd16
PB
13841 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v2)
13842 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v2))
ee065d83 13843 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
e74cfd16
PB
13844 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v1)
13845 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v1))
ee065d83
PB
13846 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
13847 /* Tag_WMMX_arch. */
e74cfd16
PB
13848 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
13849 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
ee065d83
PB
13850 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
13851}
13852
13853/* Add the .ARM.attributes section. */
13854void
13855arm_md_end (void)
13856{
13857 segT s;
13858 char *p;
13859 addressT addr;
13860 offsetT size;
13861
13862 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
13863 return;
13864
13865 aeabi_set_public_attributes ();
13866 size = elf32_arm_eabi_attr_size (stdoutput);
13867 s = subseg_new (".ARM.attributes", 0);
13868 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
13869 addr = frag_now_fix ();
13870 p = frag_more (size);
13871 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
13872}
13873
13874
13875/* Parse a .cpu directive. */
13876
13877static void
13878s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
13879{
e74cfd16 13880 const struct arm_cpu_option_table *opt;
ee065d83
PB
13881 char *name;
13882 char saved_char;
13883
13884 name = input_line_pointer;
13885 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13886 input_line_pointer++;
13887 saved_char = *input_line_pointer;
13888 *input_line_pointer = 0;
13889
13890 /* Skip the first "all" entry. */
13891 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
13892 if (streq (opt->name, name))
13893 {
e74cfd16
PB
13894 mcpu_cpu_opt = &opt->value;
13895 selected_cpu = opt->value;
ee065d83
PB
13896 if (opt->canonical_name)
13897 strcpy(selected_cpu_name, opt->canonical_name);
13898 else
13899 {
13900 int i;
13901 for (i = 0; opt->name[i]; i++)
13902 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13903 selected_cpu_name[i] = 0;
13904 }
e74cfd16 13905 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13906 *input_line_pointer = saved_char;
13907 demand_empty_rest_of_line ();
13908 return;
13909 }
13910 as_bad (_("unknown cpu `%s'"), name);
13911 *input_line_pointer = saved_char;
13912 ignore_rest_of_line ();
13913}
13914
13915
13916/* Parse a .arch directive. */
13917
13918static void
13919s_arm_arch (int ignored ATTRIBUTE_UNUSED)
13920{
e74cfd16 13921 const struct arm_arch_option_table *opt;
ee065d83
PB
13922 char saved_char;
13923 char *name;
13924
13925 name = input_line_pointer;
13926 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13927 input_line_pointer++;
13928 saved_char = *input_line_pointer;
13929 *input_line_pointer = 0;
13930
13931 /* Skip the first "all" entry. */
13932 for (opt = arm_archs + 1; opt->name != NULL; opt++)
13933 if (streq (opt->name, name))
13934 {
e74cfd16
PB
13935 mcpu_cpu_opt = &opt->value;
13936 selected_cpu = opt->value;
ee065d83 13937 strcpy(selected_cpu_name, opt->name);
e74cfd16 13938 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13939 *input_line_pointer = saved_char;
13940 demand_empty_rest_of_line ();
13941 return;
13942 }
13943
13944 as_bad (_("unknown architecture `%s'\n"), name);
13945 *input_line_pointer = saved_char;
13946 ignore_rest_of_line ();
13947}
13948
13949
13950/* Parse a .fpu directive. */
13951
13952static void
13953s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
13954{
e74cfd16 13955 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
13956 char saved_char;
13957 char *name;
13958
13959 name = input_line_pointer;
13960 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13961 input_line_pointer++;
13962 saved_char = *input_line_pointer;
13963 *input_line_pointer = 0;
13964
13965 for (opt = arm_fpus; opt->name != NULL; opt++)
13966 if (streq (opt->name, name))
13967 {
e74cfd16
PB
13968 mfpu_opt = &opt->value;
13969 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13970 *input_line_pointer = saved_char;
13971 demand_empty_rest_of_line ();
13972 return;
13973 }
13974
13975 as_bad (_("unknown floating point format `%s'\n"), name);
13976 *input_line_pointer = saved_char;
13977 ignore_rest_of_line ();
13978}
13979#endif /* OBJ_ELF */
13980
This page took 1.180684 seconds and 4 git commands to generate.