2005-09-02 Paul Brook <paul@codesourcery.com>
[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. */
b89dddec
RE
101#define ARM_1 ARM_ARCH_V1
102#define ARM_2 ARM_ARCH_V2
103#define ARM_3 ARM_ARCH_V2S
104#define ARM_250 ARM_ARCH_V2S
105#define ARM_6 ARM_ARCH_V3
106#define ARM_7 ARM_ARCH_V3
107#define ARM_8 ARM_ARCH_V4
108#define ARM_9 ARM_ARCH_V4T
109#define ARM_STRONG ARM_ARCH_V4
c19d1205 110#define ARM_CPU_MASK 0x0000000f /* XXX? */
b99bd4ef
NC
111
112#ifndef CPU_DEFAULT
113#if defined __XSCALE__
b89dddec 114#define CPU_DEFAULT (ARM_ARCH_XSCALE)
b99bd4ef
NC
115#else
116#if defined __thumb__
c19d1205 117#define CPU_DEFAULT (ARM_ARCH_V5T)
b99bd4ef 118#else
c19d1205 119#define CPU_DEFAULT ARM_ANY
b99bd4ef
NC
120#endif
121#endif
122#endif
123
124#ifndef FPU_DEFAULT
c820d418
MM
125# ifdef TE_LINUX
126# define FPU_DEFAULT FPU_ARCH_FPA
127# elif defined (TE_NetBSD)
128# ifdef OBJ_ELF
129# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
130# else
131 /* Legacy a.out format. */
132# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
133# endif
4e7fd91e
PB
134# elif defined (TE_VXWORKS)
135# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
136# else
137 /* For backwards compatibility, default to FPA. */
138# define FPU_DEFAULT FPU_ARCH_FPA
139# endif
140#endif /* ifndef FPU_DEFAULT */
b99bd4ef 141
c19d1205 142#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 143
03b1477f 144static unsigned long cpu_variant;
b99bd4ef 145
b99bd4ef 146/* Flags stored in private area of BFD structure. */
c19d1205
ZW
147static int uses_apcs_26 = FALSE;
148static int atpcs = FALSE;
b34976b6
AM
149static int support_interwork = FALSE;
150static int uses_apcs_float = FALSE;
c19d1205 151static int pic_code = FALSE;
03b1477f
RE
152
153/* Variables that we set while parsing command-line options. Once all
154 options have been read we re-process these values to set the real
155 assembly flags. */
156static int legacy_cpu = -1;
157static int legacy_fpu = -1;
158
159static int mcpu_cpu_opt = -1;
160static int mcpu_fpu_opt = -1;
161static int march_cpu_opt = -1;
162static int march_fpu_opt = -1;
163static int mfpu_opt = -1;
33a392fb 164static int mfloat_abi_opt = -1;
7cc69913 165#ifdef OBJ_ELF
deeaaff8
DJ
166# ifdef EABI_DEFAULT
167static int meabi_flags = EABI_DEFAULT;
168# else
d507cf36 169static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 170# endif
7cc69913 171#endif
b99bd4ef 172
b99bd4ef 173#ifdef OBJ_ELF
c19d1205 174/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
175symbolS * GOT_symbol;
176#endif
177
b99bd4ef
NC
178/* 0: assemble for ARM,
179 1: assemble for Thumb,
180 2: assemble for Thumb even though target CPU does not support thumb
181 instructions. */
182static int thumb_mode = 0;
183
c19d1205
ZW
184/* If unified_syntax is true, we are processing the new unified
185 ARM/Thumb syntax. Important differences from the old ARM mode:
186
187 - Immediate operands do not require a # prefix.
188 - Conditional affixes always appear at the end of the
189 instruction. (For backward compatibility, those instructions
190 that formerly had them in the middle, continue to accept them
191 there.)
192 - The IT instruction may appear, and if it does is validated
193 against subsequent conditional affixes. It does not generate
194 machine code.
195
196 Important differences from the old Thumb mode:
197
198 - Immediate operands do not require a # prefix.
199 - Most of the V6T2 instructions are only available in unified mode.
200 - The .N and .W suffixes are recognized and honored (it is an error
201 if they cannot be honored).
202 - All instructions set the flags if and only if they have an 's' affix.
203 - Conditional affixes may be used. They are validated against
204 preceding IT instructions. Unlike ARM mode, you cannot use a
205 conditional affix except in the scope of an IT instruction. */
206
207static bfd_boolean unified_syntax = FALSE;
b99bd4ef
NC
208
209struct arm_it
210{
c19d1205 211 const char * error;
b99bd4ef 212 unsigned long instruction;
c19d1205
ZW
213 int size;
214 int size_req;
215 int cond;
b99bd4ef
NC
216 struct
217 {
218 bfd_reloc_code_real_type type;
c19d1205
ZW
219 expressionS exp;
220 int pc_rel;
b99bd4ef 221 } reloc;
b99bd4ef 222
c19d1205
ZW
223 struct
224 {
225 unsigned reg;
ca3f61f7
NC
226 signed int imm;
227 unsigned present : 1; /* Operand present. */
228 unsigned isreg : 1; /* Operand was a register. */
229 unsigned immisreg : 1; /* .imm field is a second register. */
230 unsigned hasreloc : 1; /* Operand has relocation suffix. */
231 unsigned writeback : 1; /* Operand has trailing ! */
232 unsigned preind : 1; /* Preindexed address. */
233 unsigned postind : 1; /* Postindexed address. */
234 unsigned negative : 1; /* Index register was negated. */
235 unsigned shifted : 1; /* Shift applied to operation. */
236 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 237 } operands[6];
b99bd4ef
NC
238};
239
c19d1205 240static struct arm_it inst;
b99bd4ef
NC
241
242#define NUM_FLOAT_VALS 8
243
05d2d07e 244const char * fp_const[] =
b99bd4ef
NC
245{
246 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
247};
248
c19d1205 249/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
250#define MAX_LITTLENUMS 6
251
252LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
253
254#define FAIL (-1)
255#define SUCCESS (0)
256
257#define SUFF_S 1
258#define SUFF_D 2
259#define SUFF_E 3
260#define SUFF_P 4
261
c19d1205
ZW
262#define CP_T_X 0x00008000
263#define CP_T_Y 0x00400000
b99bd4ef 264
c19d1205
ZW
265#define CONDS_BIT 0x00100000
266#define LOAD_BIT 0x00100000
b99bd4ef
NC
267
268#define DOUBLE_LOAD_FLAG 0x00000001
269
270struct asm_cond
271{
c19d1205 272 const char * template;
b99bd4ef
NC
273 unsigned long value;
274};
275
c19d1205 276#define COND_ALWAYS 0xE
b99bd4ef 277
b99bd4ef
NC
278struct asm_psr
279{
b34976b6 280 const char *template;
b99bd4ef
NC
281 unsigned long field;
282};
283
2d2255b5 284/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
285#define SPSR_BIT (1 << 22)
286
c19d1205
ZW
287/* The individual PSR flag bits. */
288#define PSR_c (1 << 16)
289#define PSR_x (1 << 17)
290#define PSR_s (1 << 18)
291#define PSR_f (1 << 19)
b99bd4ef 292
c19d1205 293struct reloc_entry
bfae80f2 294{
c19d1205
ZW
295 char *name;
296 bfd_reloc_code_real_type reloc;
bfae80f2
RE
297};
298
299enum vfp_sp_reg_pos
300{
301 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
302};
303
304enum vfp_ldstm_type
305{
306 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
307};
308
c19d1205
ZW
309/* ARM register categories. This includes coprocessor numbers and various
310 architecture extensions' registers. */
311enum arm_reg_type
bfae80f2 312{
c19d1205
ZW
313 REG_TYPE_RN,
314 REG_TYPE_CP,
315 REG_TYPE_CN,
316 REG_TYPE_FN,
317 REG_TYPE_VFS,
318 REG_TYPE_VFD,
319 REG_TYPE_VFC,
320 REG_TYPE_MVF,
321 REG_TYPE_MVD,
322 REG_TYPE_MVFX,
323 REG_TYPE_MVDX,
324 REG_TYPE_MVAX,
325 REG_TYPE_DSPSC,
326 REG_TYPE_MMXWR,
327 REG_TYPE_MMXWC,
328 REG_TYPE_MMXWCG,
329 REG_TYPE_XSCALE,
bfae80f2
RE
330};
331
6c43fab6
RE
332/* Structure for a hash table entry for a register. */
333struct reg_entry
334{
c19d1205
ZW
335 const char *name;
336 unsigned char number;
337 unsigned char type;
338 unsigned char builtin;
6c43fab6
RE
339};
340
c19d1205
ZW
341/* Diagnostics used when we don't get a register of the expected type. */
342const char *const reg_expected_msgs[] =
343{
344 N_("ARM register expected"),
345 N_("bad or missing co-processor number"),
346 N_("co-processor register expected"),
347 N_("FPA register expected"),
348 N_("VFP single precision register expected"),
349 N_("VFP double precision register expected"),
350 N_("VFP system register expected"),
351 N_("Maverick MVF register expected"),
352 N_("Maverick MVD register expected"),
353 N_("Maverick MVFX register expected"),
354 N_("Maverick MVDX register expected"),
355 N_("Maverick MVAX register expected"),
356 N_("Maverick DSPSC register expected"),
357 N_("iWMMXt data register expected"),
358 N_("iWMMXt control register expected"),
359 N_("iWMMXt scalar register expected"),
360 N_("XScale accumulator register expected"),
6c43fab6
RE
361};
362
c19d1205
ZW
363/* Some well known registers that we refer to directly elsewhere. */
364#define REG_SP 13
365#define REG_LR 14
366#define REG_PC 15
404ff6b5 367
b99bd4ef
NC
368/* ARM instructions take 4bytes in the object file, Thumb instructions
369 take 2: */
c19d1205 370#define INSN_SIZE 4
b99bd4ef
NC
371
372struct asm_opcode
373{
374 /* Basic string to match. */
c19d1205
ZW
375 const char *template;
376
377 /* Parameters to instruction. */
378 unsigned char operands[8];
379
380 /* Conditional tag - see opcode_lookup. */
381 unsigned int tag : 4;
b99bd4ef
NC
382
383 /* Basic instruction code. */
c19d1205 384 unsigned int avalue : 28;
b99bd4ef 385
c19d1205
ZW
386 /* Thumb-format instruction code. */
387 unsigned int tvalue;
b99bd4ef 388
90e4755a 389 /* Which architecture variant provides this instruction. */
c19d1205
ZW
390 unsigned long avariant;
391 unsigned long tvariant;
392
393 /* Function to call to encode instruction in ARM format. */
394 void (* aencode) (void);
b99bd4ef 395
c19d1205
ZW
396 /* Function to call to encode instruction in Thumb format. */
397 void (* tencode) (void);
b99bd4ef
NC
398};
399
a737bd4d
NC
400/* Defines for various bits that we will want to toggle. */
401#define INST_IMMEDIATE 0x02000000
402#define OFFSET_REG 0x02000000
c19d1205 403#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
404#define SHIFT_BY_REG 0x00000010
405#define PRE_INDEX 0x01000000
406#define INDEX_UP 0x00800000
407#define WRITE_BACK 0x00200000
408#define LDM_TYPE_2_OR_3 0x00400000
90e4755a 409
a737bd4d
NC
410#define LITERAL_MASK 0xf000f000
411#define OPCODE_MASK 0xfe1fffff
412#define V4_STR_BIT 0x00000020
90e4755a 413
a737bd4d 414#define DATA_OP_SHIFT 21
90e4755a 415
a737bd4d
NC
416/* Codes to distinguish the arithmetic instructions. */
417#define OPCODE_AND 0
418#define OPCODE_EOR 1
419#define OPCODE_SUB 2
420#define OPCODE_RSB 3
421#define OPCODE_ADD 4
422#define OPCODE_ADC 5
423#define OPCODE_SBC 6
424#define OPCODE_RSC 7
425#define OPCODE_TST 8
426#define OPCODE_TEQ 9
427#define OPCODE_CMP 10
428#define OPCODE_CMN 11
429#define OPCODE_ORR 12
430#define OPCODE_MOV 13
431#define OPCODE_BIC 14
432#define OPCODE_MVN 15
90e4755a 433
a737bd4d
NC
434#define T_OPCODE_MUL 0x4340
435#define T_OPCODE_TST 0x4200
436#define T_OPCODE_CMN 0x42c0
437#define T_OPCODE_NEG 0x4240
438#define T_OPCODE_MVN 0x43c0
90e4755a 439
a737bd4d
NC
440#define T_OPCODE_ADD_R3 0x1800
441#define T_OPCODE_SUB_R3 0x1a00
442#define T_OPCODE_ADD_HI 0x4400
443#define T_OPCODE_ADD_ST 0xb000
444#define T_OPCODE_SUB_ST 0xb080
445#define T_OPCODE_ADD_SP 0xa800
446#define T_OPCODE_ADD_PC 0xa000
447#define T_OPCODE_ADD_I8 0x3000
448#define T_OPCODE_SUB_I8 0x3800
449#define T_OPCODE_ADD_I3 0x1c00
450#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 451
a737bd4d
NC
452#define T_OPCODE_ASR_R 0x4100
453#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
454#define T_OPCODE_LSR_R 0x40c0
455#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
456#define T_OPCODE_ASR_I 0x1000
457#define T_OPCODE_LSL_I 0x0000
458#define T_OPCODE_LSR_I 0x0800
b99bd4ef 459
a737bd4d
NC
460#define T_OPCODE_MOV_I8 0x2000
461#define T_OPCODE_CMP_I8 0x2800
462#define T_OPCODE_CMP_LR 0x4280
463#define T_OPCODE_MOV_HR 0x4600
464#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 465
a737bd4d
NC
466#define T_OPCODE_LDR_PC 0x4800
467#define T_OPCODE_LDR_SP 0x9800
468#define T_OPCODE_STR_SP 0x9000
469#define T_OPCODE_LDR_IW 0x6800
470#define T_OPCODE_STR_IW 0x6000
471#define T_OPCODE_LDR_IH 0x8800
472#define T_OPCODE_STR_IH 0x8000
473#define T_OPCODE_LDR_IB 0x7800
474#define T_OPCODE_STR_IB 0x7000
475#define T_OPCODE_LDR_RW 0x5800
476#define T_OPCODE_STR_RW 0x5000
477#define T_OPCODE_LDR_RH 0x5a00
478#define T_OPCODE_STR_RH 0x5200
479#define T_OPCODE_LDR_RB 0x5c00
480#define T_OPCODE_STR_RB 0x5400
c9b604bd 481
a737bd4d
NC
482#define T_OPCODE_PUSH 0xb400
483#define T_OPCODE_POP 0xbc00
b99bd4ef 484
2fc8bdac 485#define T_OPCODE_BRANCH 0xe000
b99bd4ef 486
a737bd4d 487#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 488#define THUMB_PP_PC_LR 0x0100
c19d1205
ZW
489#define THUMB_LOAD_BIT 0x0800
490
491#define BAD_ARGS _("bad arguments to instruction")
492#define BAD_PC _("r15 not allowed here")
493#define BAD_COND _("instruction cannot be conditional")
494#define BAD_OVERLAP _("registers may not be the same")
495#define BAD_HIREG _("lo register required")
496#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
497
498static struct hash_control *arm_ops_hsh;
499static struct hash_control *arm_cond_hsh;
500static struct hash_control *arm_shift_hsh;
501static struct hash_control *arm_psr_hsh;
502static struct hash_control *arm_reg_hsh;
503static struct hash_control *arm_reloc_hsh;
b99bd4ef 504
b99bd4ef
NC
505/* Stuff needed to resolve the label ambiguity
506 As:
507 ...
508 label: <insn>
509 may differ from:
510 ...
511 label:
c19d1205 512 <insn>
b99bd4ef
NC
513*/
514
515symbolS * last_label_seen;
b34976b6 516static int label_is_thumb_function_name = FALSE;
a737bd4d 517\f
3d0c9500
NC
518/* Literal pool structure. Held on a per-section
519 and per-sub-section basis. */
a737bd4d 520
c19d1205 521#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 522typedef struct literal_pool
b99bd4ef 523{
c19d1205
ZW
524 expressionS literals [MAX_LITERAL_POOL_SIZE];
525 unsigned int next_free_entry;
526 unsigned int id;
527 symbolS * symbol;
528 segT section;
529 subsegT sub_section;
61b5f74b 530 struct literal_pool * next;
3d0c9500 531} literal_pool;
b99bd4ef 532
3d0c9500
NC
533/* Pointer to a linked list of literal pools. */
534literal_pool * list_of_pools = NULL;
e27ec89e
PB
535
536/* State variables for IT block handling. */
537static bfd_boolean current_it_mask = 0;
538static int current_cc;
539
c19d1205
ZW
540\f
541/* Pure syntax. */
b99bd4ef 542
c19d1205
ZW
543/* This array holds the chars that always start a comment. If the
544 pre-processor is disabled, these aren't very useful. */
545const char comment_chars[] = "@";
3d0c9500 546
c19d1205
ZW
547/* This array holds the chars that only start a comment at the beginning of
548 a line. If the line seems to have the form '# 123 filename'
549 .line and .file directives will appear in the pre-processed output. */
550/* Note that input_file.c hand checks for '#' at the beginning of the
551 first line of the input file. This is because the compiler outputs
552 #NO_APP at the beginning of its output. */
553/* Also note that comments like this one will always work. */
554const char line_comment_chars[] = "#";
3d0c9500 555
c19d1205 556const char line_separator_chars[] = ";";
b99bd4ef 557
c19d1205
ZW
558/* Chars that can be used to separate mant
559 from exp in floating point numbers. */
560const char EXP_CHARS[] = "eE";
3d0c9500 561
c19d1205
ZW
562/* Chars that mean this number is a floating point constant. */
563/* As in 0f12.456 */
564/* or 0d1.2345e12 */
b99bd4ef 565
c19d1205 566const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 567
c19d1205
ZW
568/* Prefix characters that indicate the start of an immediate
569 value. */
570#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 571
c19d1205
ZW
572/* Separator character handling. */
573
574#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
575
576static inline int
577skip_past_char (char ** str, char c)
578{
579 if (**str == c)
580 {
581 (*str)++;
582 return SUCCESS;
3d0c9500 583 }
c19d1205
ZW
584 else
585 return FAIL;
586}
587#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 588
c19d1205
ZW
589/* Arithmetic expressions (possibly involving symbols). */
590
591/* Return TRUE if anything in the expression is a bignum. */
592
593static int
594walk_no_bignums (symbolS * sp)
595{
596 if (symbol_get_value_expression (sp)->X_op == O_big)
597 return 1;
598
599 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 600 {
c19d1205
ZW
601 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
602 || (symbol_get_value_expression (sp)->X_op_symbol
603 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
604 }
605
c19d1205 606 return 0;
3d0c9500
NC
607}
608
c19d1205
ZW
609static int in_my_get_expression = 0;
610
611/* Third argument to my_get_expression. */
612#define GE_NO_PREFIX 0
613#define GE_IMM_PREFIX 1
614#define GE_OPT_PREFIX 2
a737bd4d 615
b99bd4ef 616static int
c19d1205 617my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 618{
c19d1205
ZW
619 char * save_in;
620 segT seg;
b99bd4ef 621
c19d1205
ZW
622 /* In unified syntax, all prefixes are optional. */
623 if (unified_syntax)
624 prefix_mode = GE_OPT_PREFIX;
b99bd4ef 625
c19d1205 626 switch (prefix_mode)
b99bd4ef 627 {
c19d1205
ZW
628 case GE_NO_PREFIX: break;
629 case GE_IMM_PREFIX:
630 if (!is_immediate_prefix (**str))
631 {
632 inst.error = _("immediate expression requires a # prefix");
633 return FAIL;
634 }
635 (*str)++;
636 break;
637 case GE_OPT_PREFIX:
638 if (is_immediate_prefix (**str))
639 (*str)++;
640 break;
641 default: abort ();
642 }
b99bd4ef 643
c19d1205 644 memset (ep, 0, sizeof (expressionS));
b99bd4ef 645
c19d1205
ZW
646 save_in = input_line_pointer;
647 input_line_pointer = *str;
648 in_my_get_expression = 1;
649 seg = expression (ep);
650 in_my_get_expression = 0;
651
652 if (ep->X_op == O_illegal)
b99bd4ef 653 {
c19d1205
ZW
654 /* We found a bad expression in md_operand(). */
655 *str = input_line_pointer;
656 input_line_pointer = save_in;
657 if (inst.error == NULL)
658 inst.error = _("bad expression");
659 return 1;
660 }
b99bd4ef 661
c19d1205
ZW
662#ifdef OBJ_AOUT
663 if (seg != absolute_section
664 && seg != text_section
665 && seg != data_section
666 && seg != bss_section
667 && seg != undefined_section)
668 {
669 inst.error = _("bad segment");
670 *str = input_line_pointer;
671 input_line_pointer = save_in;
672 return 1;
b99bd4ef 673 }
c19d1205 674#endif
b99bd4ef 675
c19d1205
ZW
676 /* Get rid of any bignums now, so that we don't generate an error for which
677 we can't establish a line number later on. Big numbers are never valid
678 in instructions, which is where this routine is always called. */
679 if (ep->X_op == O_big
680 || (ep->X_add_symbol
681 && (walk_no_bignums (ep->X_add_symbol)
682 || (ep->X_op_symbol
683 && walk_no_bignums (ep->X_op_symbol)))))
684 {
685 inst.error = _("invalid constant");
686 *str = input_line_pointer;
687 input_line_pointer = save_in;
688 return 1;
689 }
b99bd4ef 690
c19d1205
ZW
691 *str = input_line_pointer;
692 input_line_pointer = save_in;
693 return 0;
b99bd4ef
NC
694}
695
c19d1205
ZW
696/* Turn a string in input_line_pointer into a floating point constant
697 of type TYPE, and store the appropriate bytes in *LITP. The number
698 of LITTLENUMS emitted is stored in *SIZEP. An error message is
699 returned, or NULL on OK.
b99bd4ef 700
c19d1205
ZW
701 Note that fp constants aren't represent in the normal way on the ARM.
702 In big endian mode, things are as expected. However, in little endian
703 mode fp constants are big-endian word-wise, and little-endian byte-wise
704 within the words. For example, (double) 1.1 in big endian mode is
705 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
706 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 707
c19d1205 708 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 709
c19d1205
ZW
710char *
711md_atof (int type, char * litP, int * sizeP)
712{
713 int prec;
714 LITTLENUM_TYPE words[MAX_LITTLENUMS];
715 char *t;
716 int i;
b99bd4ef 717
c19d1205
ZW
718 switch (type)
719 {
720 case 'f':
721 case 'F':
722 case 's':
723 case 'S':
724 prec = 2;
725 break;
b99bd4ef 726
c19d1205
ZW
727 case 'd':
728 case 'D':
729 case 'r':
730 case 'R':
731 prec = 4;
732 break;
b99bd4ef 733
c19d1205
ZW
734 case 'x':
735 case 'X':
736 prec = 6;
737 break;
b99bd4ef 738
c19d1205
ZW
739 case 'p':
740 case 'P':
741 prec = 6;
742 break;
a737bd4d 743
c19d1205
ZW
744 default:
745 *sizeP = 0;
746 return _("bad call to MD_ATOF()");
747 }
b99bd4ef 748
c19d1205
ZW
749 t = atof_ieee (input_line_pointer, type, words);
750 if (t)
751 input_line_pointer = t;
752 *sizeP = prec * 2;
b99bd4ef 753
c19d1205
ZW
754 if (target_big_endian)
755 {
756 for (i = 0; i < prec; i++)
757 {
758 md_number_to_chars (litP, (valueT) words[i], 2);
759 litP += 2;
760 }
761 }
762 else
763 {
764 if (cpu_variant & FPU_ARCH_VFP)
765 for (i = prec - 1; i >= 0; i--)
766 {
767 md_number_to_chars (litP, (valueT) words[i], 2);
768 litP += 2;
769 }
770 else
771 /* For a 4 byte float the order of elements in `words' is 1 0.
772 For an 8 byte float the order is 1 0 3 2. */
773 for (i = 0; i < prec; i += 2)
774 {
775 md_number_to_chars (litP, (valueT) words[i + 1], 2);
776 md_number_to_chars (litP + 2, (valueT) words[i], 2);
777 litP += 4;
778 }
779 }
b99bd4ef 780
c19d1205
ZW
781 return 0;
782}
b99bd4ef 783
c19d1205
ZW
784/* We handle all bad expressions here, so that we can report the faulty
785 instruction in the error message. */
786void
787md_operand (expressionS * expr)
788{
789 if (in_my_get_expression)
790 expr->X_op = O_illegal;
b99bd4ef
NC
791}
792
c19d1205 793/* Immediate values. */
b99bd4ef 794
c19d1205
ZW
795/* Generic immediate-value read function for use in directives.
796 Accepts anything that 'expression' can fold to a constant.
797 *val receives the number. */
798#ifdef OBJ_ELF
799static int
800immediate_for_directive (int *val)
b99bd4ef 801{
c19d1205
ZW
802 expressionS exp;
803 exp.X_op = O_illegal;
b99bd4ef 804
c19d1205
ZW
805 if (is_immediate_prefix (*input_line_pointer))
806 {
807 input_line_pointer++;
808 expression (&exp);
809 }
b99bd4ef 810
c19d1205
ZW
811 if (exp.X_op != O_constant)
812 {
813 as_bad (_("expected #constant"));
814 ignore_rest_of_line ();
815 return FAIL;
816 }
817 *val = exp.X_add_number;
818 return SUCCESS;
b99bd4ef 819}
c19d1205 820#endif
b99bd4ef 821
c19d1205 822/* Register parsing. */
b99bd4ef 823
c19d1205
ZW
824/* Generic register parser. CCP points to what should be the
825 beginning of a register name. If it is indeed a valid register
826 name, advance CCP over it and return the reg_entry structure;
827 otherwise return NULL. Does not issue diagnostics. */
828
829static struct reg_entry *
830arm_reg_parse_multi (char **ccp)
b99bd4ef 831{
c19d1205
ZW
832 char *start = *ccp;
833 char *p;
834 struct reg_entry *reg;
b99bd4ef 835
c19d1205
ZW
836#ifdef REGISTER_PREFIX
837 if (*start != REGISTER_PREFIX)
838 return FAIL;
839 start++;
840#endif
841#ifdef OPTIONAL_REGISTER_PREFIX
842 if (*start == OPTIONAL_REGISTER_PREFIX)
843 start++;
844#endif
b99bd4ef 845
c19d1205
ZW
846 p = start;
847 if (!ISALPHA (*p) || !is_name_beginner (*p))
848 return NULL;
b99bd4ef 849
c19d1205
ZW
850 do
851 p++;
852 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
853
854 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
855
856 if (!reg)
857 return NULL;
858
859 *ccp = p;
860 return reg;
b99bd4ef
NC
861}
862
c19d1205
ZW
863/* As above, but the register must be of type TYPE, and the return
864 value is the register number or NULL. */
865
b99bd4ef 866static int
c19d1205 867arm_reg_parse (char **ccp, enum arm_reg_type type)
b99bd4ef 868{
c19d1205
ZW
869 char *start = *ccp;
870 struct reg_entry *reg = arm_reg_parse_multi (ccp);
b99bd4ef 871
c19d1205
ZW
872 if (reg && reg->type == type)
873 return reg->number;
6057a28f 874
c19d1205
ZW
875 /* Alternative syntaxes are accepted for a few register classes. */
876 switch (type)
877 {
878 case REG_TYPE_MVF:
879 case REG_TYPE_MVD:
880 case REG_TYPE_MVFX:
881 case REG_TYPE_MVDX:
882 /* Generic coprocessor register names are allowed for these. */
883 if (reg->type == REG_TYPE_CN)
884 return reg->number;
885 break;
69b97547 886
c19d1205
ZW
887 case REG_TYPE_CP:
888 /* For backward compatibility, a bare number is valid here. */
889 {
890 unsigned long processor = strtoul (start, ccp, 10);
891 if (*ccp != start && processor <= 15)
892 return processor;
893 }
6057a28f 894
c19d1205
ZW
895 case REG_TYPE_MMXWC:
896 /* WC includes WCG. ??? I'm not sure this is true for all
897 instructions that take WC registers. */
898 if (reg->type == REG_TYPE_MMXWCG)
899 return reg->number;
6057a28f 900 break;
c19d1205 901
6057a28f 902 default:
c19d1205 903 break;
6057a28f
NC
904 }
905
c19d1205
ZW
906 *ccp = start;
907 return FAIL;
908}
69b97547 909
c19d1205
ZW
910/* Parse an ARM register list. Returns the bitmask, or FAIL. */
911static long
912parse_reg_list (char ** strp)
913{
914 char * str = * strp;
915 long range = 0;
916 int another_range;
a737bd4d 917
c19d1205
ZW
918 /* We come back here if we get ranges concatenated by '+' or '|'. */
919 do
6057a28f 920 {
c19d1205 921 another_range = 0;
a737bd4d 922
c19d1205
ZW
923 if (*str == '{')
924 {
925 int in_range = 0;
926 int cur_reg = -1;
a737bd4d 927
c19d1205
ZW
928 str++;
929 do
930 {
931 int reg;
6057a28f 932
c19d1205
ZW
933 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
934 {
935 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
936 return FAIL;
937 }
a737bd4d 938
c19d1205
ZW
939 if (in_range)
940 {
941 int i;
a737bd4d 942
c19d1205
ZW
943 if (reg <= cur_reg)
944 {
945 inst.error = _("bad range in register list");
946 return FAIL;
947 }
40a18ebd 948
c19d1205
ZW
949 for (i = cur_reg + 1; i < reg; i++)
950 {
951 if (range & (1 << i))
952 as_tsktsk
953 (_("Warning: duplicated register (r%d) in register list"),
954 i);
955 else
956 range |= 1 << i;
957 }
958 in_range = 0;
959 }
a737bd4d 960
c19d1205
ZW
961 if (range & (1 << reg))
962 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
963 reg);
964 else if (reg <= cur_reg)
965 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 966
c19d1205
ZW
967 range |= 1 << reg;
968 cur_reg = reg;
969 }
970 while (skip_past_comma (&str) != FAIL
971 || (in_range = 1, *str++ == '-'));
972 str--;
a737bd4d 973
c19d1205
ZW
974 if (*str++ != '}')
975 {
976 inst.error = _("missing `}'");
977 return FAIL;
978 }
979 }
980 else
981 {
982 expressionS expr;
40a18ebd 983
c19d1205
ZW
984 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
985 return FAIL;
40a18ebd 986
c19d1205
ZW
987 if (expr.X_op == O_constant)
988 {
989 if (expr.X_add_number
990 != (expr.X_add_number & 0x0000ffff))
991 {
992 inst.error = _("invalid register mask");
993 return FAIL;
994 }
a737bd4d 995
c19d1205
ZW
996 if ((range & expr.X_add_number) != 0)
997 {
998 int regno = range & expr.X_add_number;
a737bd4d 999
c19d1205
ZW
1000 regno &= -regno;
1001 regno = (1 << regno) - 1;
1002 as_tsktsk
1003 (_("Warning: duplicated register (r%d) in register list"),
1004 regno);
1005 }
a737bd4d 1006
c19d1205
ZW
1007 range |= expr.X_add_number;
1008 }
1009 else
1010 {
1011 if (inst.reloc.type != 0)
1012 {
1013 inst.error = _("expression too complex");
1014 return FAIL;
1015 }
a737bd4d 1016
c19d1205
ZW
1017 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1018 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1019 inst.reloc.pc_rel = 0;
1020 }
1021 }
a737bd4d 1022
c19d1205
ZW
1023 if (*str == '|' || *str == '+')
1024 {
1025 str++;
1026 another_range = 1;
1027 }
a737bd4d 1028 }
c19d1205 1029 while (another_range);
a737bd4d 1030
c19d1205
ZW
1031 *strp = str;
1032 return range;
a737bd4d
NC
1033}
1034
c19d1205
ZW
1035/* Parse a VFP register list. If the string is invalid return FAIL.
1036 Otherwise return the number of registers, and set PBASE to the first
1037 register. Double precision registers are matched if DP is nonzero. */
6057a28f 1038
c19d1205 1039static int
ca3f61f7 1040parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
6057a28f 1041{
c19d1205
ZW
1042 int base_reg;
1043 int new_base;
1044 int regtype;
1045 int max_regs;
1046 int count = 0;
1047 int warned = 0;
1048 unsigned long mask = 0;
a737bd4d 1049 int i;
6057a28f 1050
c19d1205
ZW
1051 if (**str != '{')
1052 return FAIL;
6057a28f 1053
c19d1205 1054 (*str)++;
6057a28f 1055
c19d1205 1056 if (dp)
a737bd4d 1057 {
c19d1205
ZW
1058 regtype = REG_TYPE_VFD;
1059 max_regs = 16;
1060 }
1061 else
1062 {
1063 regtype = REG_TYPE_VFS;
1064 max_regs = 32;
1065 }
6057a28f 1066
c19d1205 1067 base_reg = max_regs;
a737bd4d 1068
c19d1205
ZW
1069 do
1070 {
1071 new_base = arm_reg_parse (str, regtype);
1072 if (new_base == FAIL)
a737bd4d 1073 {
c19d1205
ZW
1074 inst.error = gettext (reg_expected_msgs[regtype]);
1075 return FAIL;
1076 }
a737bd4d 1077
c19d1205
ZW
1078 if (new_base < base_reg)
1079 base_reg = new_base;
a737bd4d 1080
c19d1205
ZW
1081 if (mask & (1 << new_base))
1082 {
1083 inst.error = _("invalid register list");
1084 return FAIL;
a737bd4d 1085 }
a737bd4d 1086
c19d1205
ZW
1087 if ((mask >> new_base) != 0 && ! warned)
1088 {
1089 as_tsktsk (_("register list not in ascending order"));
1090 warned = 1;
1091 }
0bbf2aa4 1092
c19d1205
ZW
1093 mask |= 1 << new_base;
1094 count++;
0bbf2aa4 1095
c19d1205
ZW
1096 if (**str == '-') /* We have the start of a range expression */
1097 {
1098 int high_range;
0bbf2aa4 1099
c19d1205 1100 (*str)++;
0bbf2aa4 1101
c19d1205
ZW
1102 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1103 {
1104 inst.error = gettext (reg_expected_msgs[regtype]);
1105 return FAIL;
1106 }
0bbf2aa4 1107
c19d1205
ZW
1108 if (high_range <= new_base)
1109 {
1110 inst.error = _("register range not in ascending order");
1111 return FAIL;
1112 }
0bbf2aa4 1113
c19d1205 1114 for (new_base++; new_base <= high_range; new_base++)
0bbf2aa4 1115 {
c19d1205 1116 if (mask & (1 << new_base))
0bbf2aa4 1117 {
c19d1205
ZW
1118 inst.error = _("invalid register list");
1119 return FAIL;
0bbf2aa4 1120 }
c19d1205
ZW
1121
1122 mask |= 1 << new_base;
1123 count++;
0bbf2aa4 1124 }
0bbf2aa4 1125 }
0bbf2aa4 1126 }
c19d1205 1127 while (skip_past_comma (str) != FAIL);
0bbf2aa4 1128
c19d1205 1129 (*str)++;
0bbf2aa4 1130
c19d1205
ZW
1131 /* Sanity check -- should have raised a parse error above. */
1132 if (count == 0 || count > max_regs)
1133 abort ();
1134
1135 *pbase = base_reg;
1136
1137 /* Final test -- the registers must be consecutive. */
1138 mask >>= base_reg;
1139 for (i = 0; i < count; i++)
1140 {
1141 if ((mask & (1u << i)) == 0)
1142 {
1143 inst.error = _("non-contiguous register range");
1144 return FAIL;
1145 }
1146 }
1147
1148 return count;
b99bd4ef
NC
1149}
1150
c19d1205
ZW
1151/* Parse an explicit relocation suffix on an expression. This is
1152 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1153 arm_reloc_hsh contains no entries, so this function can only
1154 succeed if there is no () after the word. Returns -1 on error,
1155 BFD_RELOC_UNUSED if there wasn't any suffix. */
1156static int
1157parse_reloc (char **str)
b99bd4ef 1158{
c19d1205
ZW
1159 struct reloc_entry *r;
1160 char *p, *q;
b99bd4ef 1161
c19d1205
ZW
1162 if (**str != '(')
1163 return BFD_RELOC_UNUSED;
b99bd4ef 1164
c19d1205
ZW
1165 p = *str + 1;
1166 q = p;
1167
1168 while (*q && *q != ')' && *q != ',')
1169 q++;
1170 if (*q != ')')
1171 return -1;
1172
1173 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1174 return -1;
1175
1176 *str = q + 1;
1177 return r->reloc;
b99bd4ef
NC
1178}
1179
c19d1205
ZW
1180/* Directives: register aliases. */
1181
b99bd4ef 1182static void
c19d1205 1183insert_reg_alias (char *str, int number, int type)
b99bd4ef 1184{
c19d1205
ZW
1185 struct reg_entry *new;
1186 const char *name;
b99bd4ef 1187
c19d1205
ZW
1188 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1189 {
1190 if (new->builtin)
1191 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1192
c19d1205
ZW
1193 /* Only warn about a redefinition if it's not defined as the
1194 same register. */
1195 else if (new->number != number || new->type != type)
1196 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1197
c19d1205
ZW
1198 return;
1199 }
b99bd4ef 1200
c19d1205
ZW
1201 name = xstrdup (str);
1202 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1203
c19d1205
ZW
1204 new->name = name;
1205 new->number = number;
1206 new->type = type;
1207 new->builtin = FALSE;
b99bd4ef 1208
c19d1205
ZW
1209 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1210 abort ();
1211}
b99bd4ef 1212
c19d1205 1213/* Look for the .req directive. This is of the form:
b99bd4ef 1214
c19d1205 1215 new_register_name .req existing_register_name
b99bd4ef 1216
c19d1205
ZW
1217 If we find one, or if it looks sufficiently like one that we want to
1218 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 1219
c19d1205
ZW
1220static int
1221create_register_alias (char * newname, char *p)
1222{
1223 struct reg_entry *old;
1224 char *oldname, *nbuf;
1225 size_t nlen;
b99bd4ef 1226
c19d1205
ZW
1227 /* The input scrubber ensures that whitespace after the mnemonic is
1228 collapsed to single spaces. */
1229 oldname = p;
1230 if (strncmp (oldname, " .req ", 6) != 0)
1231 return 0;
b99bd4ef 1232
c19d1205
ZW
1233 oldname += 6;
1234 if (*oldname == '\0')
1235 return 0;
b99bd4ef 1236
c19d1205
ZW
1237 old = hash_find (arm_reg_hsh, oldname);
1238 if (!old)
b99bd4ef 1239 {
c19d1205
ZW
1240 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1241 return 1;
b99bd4ef
NC
1242 }
1243
c19d1205
ZW
1244 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1245 the desired alias name, and p points to its end. If not, then
1246 the desired alias name is in the global original_case_string. */
1247#ifdef TC_CASE_SENSITIVE
1248 nlen = p - newname;
1249#else
1250 newname = original_case_string;
1251 nlen = strlen (newname);
1252#endif
b99bd4ef 1253
c19d1205
ZW
1254 nbuf = alloca (nlen + 1);
1255 memcpy (nbuf, newname, nlen);
1256 nbuf[nlen] = '\0';
b99bd4ef 1257
c19d1205
ZW
1258 /* Create aliases under the new name as stated; an all-lowercase
1259 version of the new name; and an all-uppercase version of the new
1260 name. */
1261 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 1262
c19d1205
ZW
1263 for (p = nbuf; *p; p++)
1264 *p = TOUPPER (*p);
1265
1266 if (strncmp (nbuf, newname, nlen))
1267 insert_reg_alias (nbuf, old->number, old->type);
1268
1269 for (p = nbuf; *p; p++)
1270 *p = TOLOWER (*p);
1271
1272 if (strncmp (nbuf, newname, nlen))
1273 insert_reg_alias (nbuf, old->number, old->type);
1274
1275 return 1;
b99bd4ef
NC
1276}
1277
c19d1205
ZW
1278/* Should never be called, as .req goes between the alias and the
1279 register name, not at the beginning of the line. */
b99bd4ef 1280static void
c19d1205 1281s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 1282{
c19d1205
ZW
1283 as_bad (_("invalid syntax for .req directive"));
1284}
b99bd4ef 1285
c19d1205
ZW
1286/* The .unreq directive deletes an alias which was previously defined
1287 by .req. For example:
b99bd4ef 1288
c19d1205
ZW
1289 my_alias .req r11
1290 .unreq my_alias */
b99bd4ef
NC
1291
1292static void
c19d1205 1293s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 1294{
c19d1205
ZW
1295 char * name;
1296 char saved_char;
b99bd4ef 1297
c19d1205
ZW
1298 name = input_line_pointer;
1299
1300 while (*input_line_pointer != 0
1301 && *input_line_pointer != ' '
1302 && *input_line_pointer != '\n')
1303 ++input_line_pointer;
1304
1305 saved_char = *input_line_pointer;
1306 *input_line_pointer = 0;
1307
1308 if (!*name)
1309 as_bad (_("invalid syntax for .unreq directive"));
1310 else
1311 {
1312 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1313
1314 if (!reg)
1315 as_bad (_("unknown register alias '%s'"), name);
1316 else if (reg->builtin)
1317 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1318 name);
1319 else
1320 {
1321 hash_delete (arm_reg_hsh, name);
1322 free ((char *) reg->name);
1323 free (reg);
1324 }
1325 }
b99bd4ef 1326
c19d1205 1327 *input_line_pointer = saved_char;
b99bd4ef
NC
1328 demand_empty_rest_of_line ();
1329}
1330
c19d1205
ZW
1331/* Directives: Instruction set selection. */
1332
1333#ifdef OBJ_ELF
1334/* This code is to handle mapping symbols as defined in the ARM ELF spec.
1335 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1336 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1337 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1338
1339static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
1340
1341static void
c19d1205 1342mapping_state (enum mstate state)
b99bd4ef 1343{
a737bd4d 1344 symbolS * symbolP;
c19d1205
ZW
1345 const char * symname;
1346 int type;
b99bd4ef 1347
c19d1205
ZW
1348 if (mapstate == state)
1349 /* The mapping symbol has already been emitted.
1350 There is nothing else to do. */
1351 return;
b99bd4ef 1352
c19d1205 1353 mapstate = state;
b99bd4ef 1354
c19d1205 1355 switch (state)
b99bd4ef 1356 {
c19d1205
ZW
1357 case MAP_DATA:
1358 symname = "$d";
1359 type = BSF_NO_FLAGS;
1360 break;
1361 case MAP_ARM:
1362 symname = "$a";
1363 type = BSF_NO_FLAGS;
1364 break;
1365 case MAP_THUMB:
1366 symname = "$t";
1367 type = BSF_NO_FLAGS;
1368 break;
1369 case MAP_UNDEFINED:
1370 return;
1371 default:
1372 abort ();
1373 }
1374
1375 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1376
1377 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1378 symbol_table_insert (symbolP);
1379 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1380
1381 switch (state)
1382 {
1383 case MAP_ARM:
1384 THUMB_SET_FUNC (symbolP, 0);
1385 ARM_SET_THUMB (symbolP, 0);
1386 ARM_SET_INTERWORK (symbolP, support_interwork);
1387 break;
1388
1389 case MAP_THUMB:
1390 THUMB_SET_FUNC (symbolP, 1);
1391 ARM_SET_THUMB (symbolP, 1);
1392 ARM_SET_INTERWORK (symbolP, support_interwork);
1393 break;
1394
1395 case MAP_DATA:
1396 default:
1397 return;
1398 }
1399}
1400#else
1401#define mapping_state(x) /* nothing */
1402#endif
1403
1404/* Find the real, Thumb encoded start of a Thumb function. */
1405
1406static symbolS *
1407find_real_start (symbolS * symbolP)
1408{
1409 char * real_start;
1410 const char * name = S_GET_NAME (symbolP);
1411 symbolS * new_target;
1412
1413 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1414#define STUB_NAME ".real_start_of"
1415
1416 if (name == NULL)
1417 abort ();
1418
37f6032b
ZW
1419 /* The compiler may generate BL instructions to local labels because
1420 it needs to perform a branch to a far away location. These labels
1421 do not have a corresponding ".real_start_of" label. We check
1422 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1423 the ".real_start_of" convention for nonlocal branches. */
1424 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
1425 return symbolP;
1426
37f6032b 1427 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
1428 new_target = symbol_find (real_start);
1429
1430 if (new_target == NULL)
1431 {
1432 as_warn ("Failed to find real start of function: %s\n", name);
1433 new_target = symbolP;
1434 }
1435
c19d1205
ZW
1436 return new_target;
1437}
1438
1439static void
1440opcode_select (int width)
1441{
1442 switch (width)
1443 {
1444 case 16:
1445 if (! thumb_mode)
1446 {
1447 if (! (cpu_variant & ARM_EXT_V4T))
1448 as_bad (_("selected processor does not support THUMB opcodes"));
1449
1450 thumb_mode = 1;
1451 /* No need to force the alignment, since we will have been
1452 coming from ARM mode, which is word-aligned. */
1453 record_alignment (now_seg, 1);
1454 }
1455 mapping_state (MAP_THUMB);
1456 break;
1457
1458 case 32:
1459 if (thumb_mode)
1460 {
1461 if ((cpu_variant & ARM_ALL) == ARM_EXT_V4T)
1462 as_bad (_("selected processor does not support ARM opcodes"));
1463
1464 thumb_mode = 0;
1465
1466 if (!need_pass_2)
1467 frag_align (2, 0, 0);
1468
1469 record_alignment (now_seg, 1);
1470 }
1471 mapping_state (MAP_ARM);
1472 break;
1473
1474 default:
1475 as_bad (_("invalid instruction size selected (%d)"), width);
1476 }
1477}
1478
1479static void
1480s_arm (int ignore ATTRIBUTE_UNUSED)
1481{
1482 opcode_select (32);
1483 demand_empty_rest_of_line ();
1484}
1485
1486static void
1487s_thumb (int ignore ATTRIBUTE_UNUSED)
1488{
1489 opcode_select (16);
1490 demand_empty_rest_of_line ();
1491}
1492
1493static void
1494s_code (int unused ATTRIBUTE_UNUSED)
1495{
1496 int temp;
1497
1498 temp = get_absolute_expression ();
1499 switch (temp)
1500 {
1501 case 16:
1502 case 32:
1503 opcode_select (temp);
1504 break;
1505
1506 default:
1507 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1508 }
1509}
1510
1511static void
1512s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1513{
1514 /* If we are not already in thumb mode go into it, EVEN if
1515 the target processor does not support thumb instructions.
1516 This is used by gcc/config/arm/lib1funcs.asm for example
1517 to compile interworking support functions even if the
1518 target processor should not support interworking. */
1519 if (! thumb_mode)
1520 {
1521 thumb_mode = 2;
1522 record_alignment (now_seg, 1);
1523 }
1524
1525 demand_empty_rest_of_line ();
1526}
1527
1528static void
1529s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1530{
1531 s_thumb (0);
1532
1533 /* The following label is the name/address of the start of a Thumb function.
1534 We need to know this for the interworking support. */
1535 label_is_thumb_function_name = TRUE;
1536}
1537
1538/* Perform a .set directive, but also mark the alias as
1539 being a thumb function. */
1540
1541static void
1542s_thumb_set (int equiv)
1543{
1544 /* XXX the following is a duplicate of the code for s_set() in read.c
1545 We cannot just call that code as we need to get at the symbol that
1546 is created. */
1547 char * name;
1548 char delim;
1549 char * end_name;
1550 symbolS * symbolP;
1551
1552 /* Especial apologies for the random logic:
1553 This just grew, and could be parsed much more simply!
1554 Dean - in haste. */
1555 name = input_line_pointer;
1556 delim = get_symbol_end ();
1557 end_name = input_line_pointer;
1558 *end_name = delim;
1559
1560 if (*input_line_pointer != ',')
1561 {
1562 *end_name = 0;
1563 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1564 *end_name = delim;
1565 ignore_rest_of_line ();
1566 return;
1567 }
1568
1569 input_line_pointer++;
1570 *end_name = 0;
1571
1572 if (name[0] == '.' && name[1] == '\0')
1573 {
1574 /* XXX - this should not happen to .thumb_set. */
1575 abort ();
1576 }
1577
1578 if ((symbolP = symbol_find (name)) == NULL
1579 && (symbolP = md_undefined_symbol (name)) == NULL)
1580 {
1581#ifndef NO_LISTING
1582 /* When doing symbol listings, play games with dummy fragments living
1583 outside the normal fragment chain to record the file and line info
c19d1205 1584 for this symbol. */
b99bd4ef
NC
1585 if (listing & LISTING_SYMBOLS)
1586 {
1587 extern struct list_info_struct * listing_tail;
a737bd4d 1588 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1589
1590 memset (dummy_frag, 0, sizeof (fragS));
1591 dummy_frag->fr_type = rs_fill;
1592 dummy_frag->line = listing_tail;
1593 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1594 dummy_frag->fr_symbol = symbolP;
1595 }
1596 else
1597#endif
1598 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1599
1600#ifdef OBJ_COFF
1601 /* "set" symbols are local unless otherwise specified. */
1602 SF_SET_LOCAL (symbolP);
1603#endif /* OBJ_COFF */
1604 } /* Make a new symbol. */
1605
1606 symbol_table_insert (symbolP);
1607
1608 * end_name = delim;
1609
1610 if (equiv
1611 && S_IS_DEFINED (symbolP)
1612 && S_GET_SEGMENT (symbolP) != reg_section)
1613 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1614
1615 pseudo_set (symbolP);
1616
1617 demand_empty_rest_of_line ();
1618
c19d1205 1619 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1620
1621 THUMB_SET_FUNC (symbolP, 1);
1622 ARM_SET_THUMB (symbolP, 1);
1623#if defined OBJ_ELF || defined OBJ_COFF
1624 ARM_SET_INTERWORK (symbolP, support_interwork);
1625#endif
1626}
1627
c19d1205 1628/* Directives: Mode selection. */
b99bd4ef 1629
c19d1205
ZW
1630/* .syntax [unified|divided] - choose the new unified syntax
1631 (same for Arm and Thumb encoding, modulo slight differences in what
1632 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1633static void
c19d1205 1634s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1635{
c19d1205
ZW
1636 char *name, delim;
1637
1638 name = input_line_pointer;
1639 delim = get_symbol_end ();
1640
1641 if (!strcasecmp (name, "unified"))
1642 unified_syntax = TRUE;
1643 else if (!strcasecmp (name, "divided"))
1644 unified_syntax = FALSE;
1645 else
1646 {
1647 as_bad (_("unrecognized syntax mode \"%s\""), name);
1648 return;
1649 }
1650 *input_line_pointer = delim;
b99bd4ef
NC
1651 demand_empty_rest_of_line ();
1652}
1653
c19d1205
ZW
1654/* Directives: sectioning and alignment. */
1655
1656/* Same as s_align_ptwo but align 0 => align 2. */
1657
b99bd4ef 1658static void
c19d1205 1659s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1660{
a737bd4d 1661 int temp;
c19d1205
ZW
1662 long temp_fill;
1663 long max_alignment = 15;
b99bd4ef
NC
1664
1665 temp = get_absolute_expression ();
c19d1205
ZW
1666 if (temp > max_alignment)
1667 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1668 else if (temp < 0)
b99bd4ef 1669 {
c19d1205
ZW
1670 as_bad (_("alignment negative. 0 assumed."));
1671 temp = 0;
1672 }
b99bd4ef 1673
c19d1205
ZW
1674 if (*input_line_pointer == ',')
1675 {
1676 input_line_pointer++;
1677 temp_fill = get_absolute_expression ();
b99bd4ef 1678 }
c19d1205
ZW
1679 else
1680 temp_fill = 0;
b99bd4ef 1681
c19d1205
ZW
1682 if (!temp)
1683 temp = 2;
b99bd4ef 1684
c19d1205
ZW
1685 /* Only make a frag if we HAVE to. */
1686 if (temp && !need_pass_2)
1687 frag_align (temp, (int) temp_fill, 0);
1688 demand_empty_rest_of_line ();
1689
1690 record_alignment (now_seg, temp);
b99bd4ef
NC
1691}
1692
c19d1205
ZW
1693static void
1694s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1695{
c19d1205
ZW
1696 /* We don't support putting frags in the BSS segment, we fake it by
1697 marking in_bss, then looking at s_skip for clues. */
1698 subseg_set (bss_section, 0);
1699 demand_empty_rest_of_line ();
1700 mapping_state (MAP_DATA);
1701}
b99bd4ef 1702
c19d1205
ZW
1703static void
1704s_even (int ignore ATTRIBUTE_UNUSED)
1705{
1706 /* Never make frag if expect extra pass. */
1707 if (!need_pass_2)
1708 frag_align (1, 0, 0);
b99bd4ef 1709
c19d1205 1710 record_alignment (now_seg, 1);
b99bd4ef 1711
c19d1205 1712 demand_empty_rest_of_line ();
b99bd4ef
NC
1713}
1714
c19d1205 1715/* Directives: Literal pools. */
a737bd4d 1716
c19d1205
ZW
1717static literal_pool *
1718find_literal_pool (void)
a737bd4d 1719{
c19d1205 1720 literal_pool * pool;
a737bd4d 1721
c19d1205 1722 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1723 {
c19d1205
ZW
1724 if (pool->section == now_seg
1725 && pool->sub_section == now_subseg)
1726 break;
a737bd4d
NC
1727 }
1728
c19d1205 1729 return pool;
a737bd4d
NC
1730}
1731
c19d1205
ZW
1732static literal_pool *
1733find_or_make_literal_pool (void)
a737bd4d 1734{
c19d1205
ZW
1735 /* Next literal pool ID number. */
1736 static unsigned int latest_pool_num = 1;
1737 literal_pool * pool;
a737bd4d 1738
c19d1205 1739 pool = find_literal_pool ();
a737bd4d 1740
c19d1205 1741 if (pool == NULL)
a737bd4d 1742 {
c19d1205
ZW
1743 /* Create a new pool. */
1744 pool = xmalloc (sizeof (* pool));
1745 if (! pool)
1746 return NULL;
a737bd4d 1747
c19d1205
ZW
1748 pool->next_free_entry = 0;
1749 pool->section = now_seg;
1750 pool->sub_section = now_subseg;
1751 pool->next = list_of_pools;
1752 pool->symbol = NULL;
1753
1754 /* Add it to the list. */
1755 list_of_pools = pool;
a737bd4d 1756 }
a737bd4d 1757
c19d1205
ZW
1758 /* New pools, and emptied pools, will have a NULL symbol. */
1759 if (pool->symbol == NULL)
a737bd4d 1760 {
c19d1205
ZW
1761 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1762 (valueT) 0, &zero_address_frag);
1763 pool->id = latest_pool_num ++;
a737bd4d
NC
1764 }
1765
c19d1205
ZW
1766 /* Done. */
1767 return pool;
a737bd4d
NC
1768}
1769
c19d1205
ZW
1770/* Add the literal in the global 'inst'
1771 structure to the relevent literal pool. */
b99bd4ef
NC
1772
1773static int
c19d1205 1774add_to_lit_pool (void)
b99bd4ef 1775{
c19d1205
ZW
1776 literal_pool * pool;
1777 unsigned int entry;
b99bd4ef 1778
c19d1205
ZW
1779 pool = find_or_make_literal_pool ();
1780
1781 /* Check if this literal value is already in the pool. */
1782 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1783 {
c19d1205
ZW
1784 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1785 && (inst.reloc.exp.X_op == O_constant)
1786 && (pool->literals[entry].X_add_number
1787 == inst.reloc.exp.X_add_number)
1788 && (pool->literals[entry].X_unsigned
1789 == inst.reloc.exp.X_unsigned))
1790 break;
1791
1792 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1793 && (inst.reloc.exp.X_op == O_symbol)
1794 && (pool->literals[entry].X_add_number
1795 == inst.reloc.exp.X_add_number)
1796 && (pool->literals[entry].X_add_symbol
1797 == inst.reloc.exp.X_add_symbol)
1798 && (pool->literals[entry].X_op_symbol
1799 == inst.reloc.exp.X_op_symbol))
1800 break;
b99bd4ef
NC
1801 }
1802
c19d1205
ZW
1803 /* Do we need to create a new entry? */
1804 if (entry == pool->next_free_entry)
1805 {
1806 if (entry >= MAX_LITERAL_POOL_SIZE)
1807 {
1808 inst.error = _("literal pool overflow");
1809 return FAIL;
1810 }
1811
1812 pool->literals[entry] = inst.reloc.exp;
1813 pool->next_free_entry += 1;
1814 }
b99bd4ef 1815
c19d1205
ZW
1816 inst.reloc.exp.X_op = O_symbol;
1817 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1818 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1819
c19d1205 1820 return SUCCESS;
b99bd4ef
NC
1821}
1822
c19d1205
ZW
1823/* Can't use symbol_new here, so have to create a symbol and then at
1824 a later date assign it a value. Thats what these functions do. */
e16bb312 1825
c19d1205
ZW
1826static void
1827symbol_locate (symbolS * symbolP,
1828 const char * name, /* It is copied, the caller can modify. */
1829 segT segment, /* Segment identifier (SEG_<something>). */
1830 valueT valu, /* Symbol value. */
1831 fragS * frag) /* Associated fragment. */
1832{
1833 unsigned int name_length;
1834 char * preserved_copy_of_name;
e16bb312 1835
c19d1205
ZW
1836 name_length = strlen (name) + 1; /* +1 for \0. */
1837 obstack_grow (&notes, name, name_length);
1838 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1839
c19d1205
ZW
1840#ifdef tc_canonicalize_symbol_name
1841 preserved_copy_of_name =
1842 tc_canonicalize_symbol_name (preserved_copy_of_name);
1843#endif
b99bd4ef 1844
c19d1205 1845 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1846
c19d1205
ZW
1847 S_SET_SEGMENT (symbolP, segment);
1848 S_SET_VALUE (symbolP, valu);
1849 symbol_clear_list_pointers (symbolP);
b99bd4ef 1850
c19d1205 1851 symbol_set_frag (symbolP, frag);
b99bd4ef 1852
c19d1205
ZW
1853 /* Link to end of symbol chain. */
1854 {
1855 extern int symbol_table_frozen;
b99bd4ef 1856
c19d1205
ZW
1857 if (symbol_table_frozen)
1858 abort ();
1859 }
b99bd4ef 1860
c19d1205 1861 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1862
c19d1205 1863 obj_symbol_new_hook (symbolP);
b99bd4ef 1864
c19d1205
ZW
1865#ifdef tc_symbol_new_hook
1866 tc_symbol_new_hook (symbolP);
1867#endif
1868
1869#ifdef DEBUG_SYMS
1870 verify_symbol_chain (symbol_rootP, symbol_lastP);
1871#endif /* DEBUG_SYMS */
b99bd4ef
NC
1872}
1873
b99bd4ef 1874
c19d1205
ZW
1875static void
1876s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1877{
c19d1205
ZW
1878 unsigned int entry;
1879 literal_pool * pool;
1880 char sym_name[20];
b99bd4ef 1881
c19d1205
ZW
1882 pool = find_literal_pool ();
1883 if (pool == NULL
1884 || pool->symbol == NULL
1885 || pool->next_free_entry == 0)
1886 return;
b99bd4ef 1887
c19d1205 1888 mapping_state (MAP_DATA);
b99bd4ef 1889
c19d1205
ZW
1890 /* Align pool as you have word accesses.
1891 Only make a frag if we have to. */
1892 if (!need_pass_2)
1893 frag_align (2, 0, 0);
b99bd4ef 1894
c19d1205 1895 record_alignment (now_seg, 2);
b99bd4ef 1896
c19d1205 1897 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1898
c19d1205
ZW
1899 symbol_locate (pool->symbol, sym_name, now_seg,
1900 (valueT) frag_now_fix (), frag_now);
1901 symbol_table_insert (pool->symbol);
b99bd4ef 1902
c19d1205 1903 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1904
c19d1205
ZW
1905#if defined OBJ_COFF || defined OBJ_ELF
1906 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1907#endif
6c43fab6 1908
c19d1205
ZW
1909 for (entry = 0; entry < pool->next_free_entry; entry ++)
1910 /* First output the expression in the instruction to the pool. */
1911 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1912
c19d1205
ZW
1913 /* Mark the pool as empty. */
1914 pool->next_free_entry = 0;
1915 pool->symbol = NULL;
b99bd4ef
NC
1916}
1917
c19d1205
ZW
1918#ifdef OBJ_ELF
1919/* Forward declarations for functions below, in the MD interface
1920 section. */
1921static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1922static valueT create_unwind_entry (int);
1923static void start_unwind_section (const segT, int);
1924static void add_unwind_opcode (valueT, int);
1925static void flush_pending_unwind (void);
b99bd4ef 1926
c19d1205 1927/* Directives: Data. */
b99bd4ef 1928
c19d1205
ZW
1929static void
1930s_arm_elf_cons (int nbytes)
1931{
1932 expressionS exp;
b99bd4ef 1933
c19d1205
ZW
1934#ifdef md_flush_pending_output
1935 md_flush_pending_output ();
1936#endif
b99bd4ef 1937
c19d1205 1938 if (is_it_end_of_statement ())
b99bd4ef 1939 {
c19d1205
ZW
1940 demand_empty_rest_of_line ();
1941 return;
b99bd4ef
NC
1942 }
1943
c19d1205
ZW
1944#ifdef md_cons_align
1945 md_cons_align (nbytes);
1946#endif
b99bd4ef 1947
c19d1205
ZW
1948 mapping_state (MAP_DATA);
1949 do
b99bd4ef 1950 {
c19d1205
ZW
1951 int reloc;
1952 char *base = input_line_pointer;
b99bd4ef 1953
c19d1205 1954 expression (& exp);
b99bd4ef 1955
c19d1205
ZW
1956 if (exp.X_op != O_symbol)
1957 emit_expr (&exp, (unsigned int) nbytes);
1958 else
1959 {
1960 char *before_reloc = input_line_pointer;
1961 reloc = parse_reloc (&input_line_pointer);
1962 if (reloc == -1)
1963 {
1964 as_bad (_("unrecognized relocation suffix"));
1965 ignore_rest_of_line ();
1966 return;
1967 }
1968 else if (reloc == BFD_RELOC_UNUSED)
1969 emit_expr (&exp, (unsigned int) nbytes);
1970 else
1971 {
1972 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
1973 int size = bfd_get_reloc_size (howto);
b99bd4ef 1974
2fc8bdac
ZW
1975 if (reloc == BFD_RELOC_ARM_PLT32)
1976 {
1977 as_bad (_("(plt) is only valid on branch targets"));
1978 reloc = BFD_RELOC_UNUSED;
1979 size = 0;
1980 }
1981
c19d1205 1982 if (size > nbytes)
2fc8bdac 1983 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
1984 howto->name, nbytes);
1985 else
1986 {
1987 /* We've parsed an expression stopping at O_symbol.
1988 But there may be more expression left now that we
1989 have parsed the relocation marker. Parse it again.
1990 XXX Surely there is a cleaner way to do this. */
1991 char *p = input_line_pointer;
1992 int offset;
1993 char *save_buf = alloca (input_line_pointer - base);
1994 memcpy (save_buf, base, input_line_pointer - base);
1995 memmove (base + (input_line_pointer - before_reloc),
1996 base, before_reloc - base);
1997
1998 input_line_pointer = base + (input_line_pointer-before_reloc);
1999 expression (&exp);
2000 memcpy (base, save_buf, p - base);
2001
2002 offset = nbytes - size;
2003 p = frag_more ((int) nbytes);
2004 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2005 size, &exp, 0, reloc);
2006 }
2007 }
2008 }
b99bd4ef 2009 }
c19d1205 2010 while (*input_line_pointer++ == ',');
b99bd4ef 2011
c19d1205
ZW
2012 /* Put terminator back into stream. */
2013 input_line_pointer --;
2014 demand_empty_rest_of_line ();
b99bd4ef
NC
2015}
2016
b99bd4ef 2017
c19d1205 2018/* Parse a .rel31 directive. */
b99bd4ef 2019
c19d1205
ZW
2020static void
2021s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2022{
2023 expressionS exp;
2024 char *p;
2025 valueT highbit;
b99bd4ef 2026
c19d1205
ZW
2027 highbit = 0;
2028 if (*input_line_pointer == '1')
2029 highbit = 0x80000000;
2030 else if (*input_line_pointer != '0')
2031 as_bad (_("expected 0 or 1"));
b99bd4ef 2032
c19d1205
ZW
2033 input_line_pointer++;
2034 if (*input_line_pointer != ',')
2035 as_bad (_("missing comma"));
2036 input_line_pointer++;
b99bd4ef 2037
c19d1205
ZW
2038#ifdef md_flush_pending_output
2039 md_flush_pending_output ();
2040#endif
b99bd4ef 2041
c19d1205
ZW
2042#ifdef md_cons_align
2043 md_cons_align (4);
2044#endif
b99bd4ef 2045
c19d1205 2046 mapping_state (MAP_DATA);
b99bd4ef 2047
c19d1205 2048 expression (&exp);
b99bd4ef 2049
c19d1205
ZW
2050 p = frag_more (4);
2051 md_number_to_chars (p, highbit, 4);
2052 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2053 BFD_RELOC_ARM_PREL31);
b99bd4ef 2054
c19d1205 2055 demand_empty_rest_of_line ();
b99bd4ef
NC
2056}
2057
c19d1205 2058/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2059
c19d1205 2060/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2061
c19d1205
ZW
2062static void
2063s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2064{
2065 demand_empty_rest_of_line ();
2066 /* Mark the start of the function. */
2067 unwind.proc_start = expr_build_dot ();
b99bd4ef 2068
c19d1205
ZW
2069 /* Reset the rest of the unwind info. */
2070 unwind.opcode_count = 0;
2071 unwind.table_entry = NULL;
2072 unwind.personality_routine = NULL;
2073 unwind.personality_index = -1;
2074 unwind.frame_size = 0;
2075 unwind.fp_offset = 0;
2076 unwind.fp_reg = 13;
2077 unwind.fp_used = 0;
2078 unwind.sp_restored = 0;
2079}
b99bd4ef 2080
b99bd4ef 2081
c19d1205
ZW
2082/* Parse a handlerdata directive. Creates the exception handling table entry
2083 for the function. */
b99bd4ef 2084
c19d1205
ZW
2085static void
2086s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2087{
2088 demand_empty_rest_of_line ();
2089 if (unwind.table_entry)
2090 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2091
c19d1205
ZW
2092 create_unwind_entry (1);
2093}
a737bd4d 2094
c19d1205 2095/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2096
c19d1205
ZW
2097static void
2098s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2099{
2100 long where;
2101 char *ptr;
2102 valueT val;
f02232aa 2103
c19d1205 2104 demand_empty_rest_of_line ();
f02232aa 2105
c19d1205
ZW
2106 /* Add eh table entry. */
2107 if (unwind.table_entry == NULL)
2108 val = create_unwind_entry (0);
2109 else
2110 val = 0;
f02232aa 2111
c19d1205
ZW
2112 /* Add index table entry. This is two words. */
2113 start_unwind_section (unwind.saved_seg, 1);
2114 frag_align (2, 0, 0);
2115 record_alignment (now_seg, 2);
b99bd4ef 2116
c19d1205
ZW
2117 ptr = frag_more (8);
2118 where = frag_now_fix () - 8;
f02232aa 2119
c19d1205
ZW
2120 /* Self relative offset of the function start. */
2121 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2122 BFD_RELOC_ARM_PREL31);
f02232aa 2123
c19d1205
ZW
2124 /* Indicate dependency on EHABI-defined personality routines to the
2125 linker, if it hasn't been done already. */
2126 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2127 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2128 {
2129 static const char *const name[] = {
2130 "__aeabi_unwind_cpp_pr0",
2131 "__aeabi_unwind_cpp_pr1",
2132 "__aeabi_unwind_cpp_pr2"
2133 };
2134 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2135 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2136 marked_pr_dependency |= 1 << unwind.personality_index;
2137 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2138 = marked_pr_dependency;
2139 }
f02232aa 2140
c19d1205
ZW
2141 if (val)
2142 /* Inline exception table entry. */
2143 md_number_to_chars (ptr + 4, val, 4);
2144 else
2145 /* Self relative offset of the table entry. */
2146 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2147 BFD_RELOC_ARM_PREL31);
f02232aa 2148
c19d1205
ZW
2149 /* Restore the original section. */
2150 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2151}
f02232aa 2152
f02232aa 2153
c19d1205 2154/* Parse an unwind_cantunwind directive. */
b99bd4ef 2155
c19d1205
ZW
2156static void
2157s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2158{
2159 demand_empty_rest_of_line ();
2160 if (unwind.personality_routine || unwind.personality_index != -1)
2161 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2162
c19d1205
ZW
2163 unwind.personality_index = -2;
2164}
b99bd4ef 2165
b99bd4ef 2166
c19d1205 2167/* Parse a personalityindex directive. */
b99bd4ef 2168
c19d1205
ZW
2169static void
2170s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2171{
2172 expressionS exp;
b99bd4ef 2173
c19d1205
ZW
2174 if (unwind.personality_routine || unwind.personality_index != -1)
2175 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2176
c19d1205 2177 expression (&exp);
b99bd4ef 2178
c19d1205
ZW
2179 if (exp.X_op != O_constant
2180 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2181 {
c19d1205
ZW
2182 as_bad (_("bad personality routine number"));
2183 ignore_rest_of_line ();
2184 return;
b99bd4ef
NC
2185 }
2186
c19d1205 2187 unwind.personality_index = exp.X_add_number;
b99bd4ef 2188
c19d1205
ZW
2189 demand_empty_rest_of_line ();
2190}
e16bb312 2191
e16bb312 2192
c19d1205 2193/* Parse a personality directive. */
e16bb312 2194
c19d1205
ZW
2195static void
2196s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2197{
2198 char *name, *p, c;
a737bd4d 2199
c19d1205
ZW
2200 if (unwind.personality_routine || unwind.personality_index != -1)
2201 as_bad (_("duplicate .personality directive"));
a737bd4d 2202
c19d1205
ZW
2203 name = input_line_pointer;
2204 c = get_symbol_end ();
2205 p = input_line_pointer;
2206 unwind.personality_routine = symbol_find_or_make (name);
2207 *p = c;
2208 demand_empty_rest_of_line ();
2209}
e16bb312 2210
e16bb312 2211
c19d1205 2212/* Parse a directive saving core registers. */
e16bb312 2213
c19d1205
ZW
2214static void
2215s_arm_unwind_save_core (void)
e16bb312 2216{
c19d1205
ZW
2217 valueT op;
2218 long range;
2219 int n;
e16bb312 2220
c19d1205
ZW
2221 range = parse_reg_list (&input_line_pointer);
2222 if (range == FAIL)
e16bb312 2223 {
c19d1205
ZW
2224 as_bad (_("expected register list"));
2225 ignore_rest_of_line ();
2226 return;
2227 }
e16bb312 2228
c19d1205 2229 demand_empty_rest_of_line ();
e16bb312 2230
c19d1205
ZW
2231 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2232 into .unwind_save {..., sp...}. We aren't bothered about the value of
2233 ip because it is clobbered by calls. */
2234 if (unwind.sp_restored && unwind.fp_reg == 12
2235 && (range & 0x3000) == 0x1000)
2236 {
2237 unwind.opcode_count--;
2238 unwind.sp_restored = 0;
2239 range = (range | 0x2000) & ~0x1000;
2240 unwind.pending_offset = 0;
2241 }
e16bb312 2242
c19d1205
ZW
2243 /* See if we can use the short opcodes. These pop a block of upto 8
2244 registers starting with r4, plus maybe r14. */
2245 for (n = 0; n < 8; n++)
2246 {
2247 /* Break at the first non-saved register. */
2248 if ((range & (1 << (n + 4))) == 0)
2249 break;
e16bb312 2250 }
c19d1205
ZW
2251 /* See if there are any other bits set. */
2252 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
e16bb312 2253 {
c19d1205
ZW
2254 /* Use the long form. */
2255 op = 0x8000 | ((range >> 4) & 0xfff);
2256 add_unwind_opcode (op, 2);
e16bb312 2257 }
c19d1205 2258 else
0dd132b6 2259 {
c19d1205
ZW
2260 /* Use the short form. */
2261 if (range & 0x4000)
2262 op = 0xa8; /* Pop r14. */
0dd132b6 2263 else
c19d1205
ZW
2264 op = 0xa0; /* Do not pop r14. */
2265 op |= (n - 1);
2266 add_unwind_opcode (op, 1);
2267 }
0dd132b6 2268
c19d1205
ZW
2269 /* Pop r0-r3. */
2270 if (range & 0xf)
2271 {
2272 op = 0xb100 | (range & 0xf);
2273 add_unwind_opcode (op, 2);
0dd132b6
NC
2274 }
2275
c19d1205
ZW
2276 /* Record the number of bytes pushed. */
2277 for (n = 0; n < 16; n++)
2278 {
2279 if (range & (1 << n))
2280 unwind.frame_size += 4;
2281 }
0dd132b6
NC
2282}
2283
c19d1205
ZW
2284
2285/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2286
2287static void
c19d1205 2288s_arm_unwind_save_fpa (int reg)
b99bd4ef 2289{
c19d1205
ZW
2290 expressionS exp;
2291 int num_regs;
2292 valueT op;
b99bd4ef 2293
c19d1205
ZW
2294 /* Get Number of registers to transfer. */
2295 if (skip_past_comma (&input_line_pointer) != FAIL)
2296 expression (&exp);
2297 else
2298 exp.X_op = O_illegal;
b99bd4ef 2299
c19d1205 2300 if (exp.X_op != O_constant)
b99bd4ef 2301 {
c19d1205
ZW
2302 as_bad (_("expected , <constant>"));
2303 ignore_rest_of_line ();
b99bd4ef
NC
2304 return;
2305 }
2306
c19d1205
ZW
2307 num_regs = exp.X_add_number;
2308
2309 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2310 {
c19d1205
ZW
2311 as_bad (_("number of registers must be in the range [1:4]"));
2312 ignore_rest_of_line ();
b99bd4ef
NC
2313 return;
2314 }
2315
c19d1205 2316 demand_empty_rest_of_line ();
b99bd4ef 2317
c19d1205
ZW
2318 if (reg == 4)
2319 {
2320 /* Short form. */
2321 op = 0xb4 | (num_regs - 1);
2322 add_unwind_opcode (op, 1);
2323 }
b99bd4ef
NC
2324 else
2325 {
c19d1205
ZW
2326 /* Long form. */
2327 op = 0xc800 | (reg << 4) | (num_regs - 1);
2328 add_unwind_opcode (op, 2);
b99bd4ef 2329 }
c19d1205 2330 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2331}
2332
c19d1205
ZW
2333
2334/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2335
2336static void
c19d1205 2337s_arm_unwind_save_vfp (void)
b99bd4ef 2338{
c19d1205 2339 int count;
ca3f61f7 2340 unsigned int reg;
c19d1205 2341 valueT op;
b99bd4ef 2342
c19d1205
ZW
2343 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2344 if (count == FAIL)
b99bd4ef 2345 {
c19d1205
ZW
2346 as_bad (_("expected register list"));
2347 ignore_rest_of_line ();
b99bd4ef
NC
2348 return;
2349 }
2350
c19d1205 2351 demand_empty_rest_of_line ();
b99bd4ef 2352
c19d1205 2353 if (reg == 8)
b99bd4ef 2354 {
c19d1205
ZW
2355 /* Short form. */
2356 op = 0xb8 | (count - 1);
2357 add_unwind_opcode (op, 1);
b99bd4ef 2358 }
c19d1205 2359 else
b99bd4ef 2360 {
c19d1205
ZW
2361 /* Long form. */
2362 op = 0xb300 | (reg << 4) | (count - 1);
2363 add_unwind_opcode (op, 2);
b99bd4ef 2364 }
c19d1205
ZW
2365 unwind.frame_size += count * 8 + 4;
2366}
b99bd4ef 2367
b99bd4ef 2368
c19d1205
ZW
2369/* Parse a directive saving iWMMXt data registers. */
2370
2371static void
2372s_arm_unwind_save_mmxwr (void)
2373{
2374 int reg;
2375 int hi_reg;
2376 int i;
2377 unsigned mask = 0;
2378 valueT op;
b99bd4ef 2379
c19d1205
ZW
2380 if (*input_line_pointer == '{')
2381 input_line_pointer++;
b99bd4ef 2382
c19d1205 2383 do
b99bd4ef 2384 {
c19d1205 2385 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2386
c19d1205 2387 if (reg == FAIL)
b99bd4ef 2388 {
c19d1205
ZW
2389 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2390 goto error;
b99bd4ef
NC
2391 }
2392
c19d1205
ZW
2393 if (mask >> reg)
2394 as_tsktsk (_("register list not in ascending order"));
2395 mask |= 1 << reg;
b99bd4ef 2396
c19d1205
ZW
2397 if (*input_line_pointer == '-')
2398 {
2399 input_line_pointer++;
2400 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2401 if (hi_reg == FAIL)
2402 {
2403 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2404 goto error;
2405 }
2406 else if (reg >= hi_reg)
2407 {
2408 as_bad (_("bad register range"));
2409 goto error;
2410 }
2411 for (; reg < hi_reg; reg++)
2412 mask |= 1 << reg;
2413 }
2414 }
2415 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2416
c19d1205
ZW
2417 if (*input_line_pointer == '}')
2418 input_line_pointer++;
b99bd4ef 2419
c19d1205 2420 demand_empty_rest_of_line ();
b99bd4ef 2421
c19d1205
ZW
2422 /* Generate any deferred opcodes becuuse we're going to be looking at
2423 the list. */
2424 flush_pending_unwind ();
b99bd4ef 2425
c19d1205 2426 for (i = 0; i < 16; i++)
b99bd4ef 2427 {
c19d1205
ZW
2428 if (mask & (1 << i))
2429 unwind.frame_size += 8;
b99bd4ef
NC
2430 }
2431
c19d1205
ZW
2432 /* Attempt to combine with a previous opcode. We do this because gcc
2433 likes to output separate unwind directives for a single block of
2434 registers. */
2435 if (unwind.opcode_count > 0)
b99bd4ef 2436 {
c19d1205
ZW
2437 i = unwind.opcodes[unwind.opcode_count - 1];
2438 if ((i & 0xf8) == 0xc0)
2439 {
2440 i &= 7;
2441 /* Only merge if the blocks are contiguous. */
2442 if (i < 6)
2443 {
2444 if ((mask & 0xfe00) == (1 << 9))
2445 {
2446 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2447 unwind.opcode_count--;
2448 }
2449 }
2450 else if (i == 6 && unwind.opcode_count >= 2)
2451 {
2452 i = unwind.opcodes[unwind.opcode_count - 2];
2453 reg = i >> 4;
2454 i &= 0xf;
b99bd4ef 2455
c19d1205
ZW
2456 op = 0xffff << (reg - 1);
2457 if (reg > 0
2458 || ((mask & op) == (1u << (reg - 1))))
2459 {
2460 op = (1 << (reg + i + 1)) - 1;
2461 op &= ~((1 << reg) - 1);
2462 mask |= op;
2463 unwind.opcode_count -= 2;
2464 }
2465 }
2466 }
b99bd4ef
NC
2467 }
2468
c19d1205
ZW
2469 hi_reg = 15;
2470 /* We want to generate opcodes in the order the registers have been
2471 saved, ie. descending order. */
2472 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2473 {
c19d1205
ZW
2474 /* Save registers in blocks. */
2475 if (reg < 0
2476 || !(mask & (1 << reg)))
2477 {
2478 /* We found an unsaved reg. Generate opcodes to save the
2479 preceeding block. */
2480 if (reg != hi_reg)
2481 {
2482 if (reg == 9)
2483 {
2484 /* Short form. */
2485 op = 0xc0 | (hi_reg - 10);
2486 add_unwind_opcode (op, 1);
2487 }
2488 else
2489 {
2490 /* Long form. */
2491 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2492 add_unwind_opcode (op, 2);
2493 }
2494 }
2495 hi_reg = reg - 1;
2496 }
b99bd4ef
NC
2497 }
2498
c19d1205
ZW
2499 return;
2500error:
2501 ignore_rest_of_line ();
b99bd4ef
NC
2502}
2503
2504static void
c19d1205 2505s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2506{
c19d1205
ZW
2507 int reg;
2508 int hi_reg;
2509 unsigned mask = 0;
2510 valueT op;
b99bd4ef 2511
c19d1205
ZW
2512 if (*input_line_pointer == '{')
2513 input_line_pointer++;
b99bd4ef 2514
c19d1205 2515 do
b99bd4ef 2516 {
c19d1205 2517 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2518
c19d1205
ZW
2519 if (reg == FAIL)
2520 {
2521 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2522 goto error;
2523 }
b99bd4ef 2524
c19d1205
ZW
2525 reg -= 8;
2526 if (mask >> reg)
2527 as_tsktsk (_("register list not in ascending order"));
2528 mask |= 1 << reg;
b99bd4ef 2529
c19d1205
ZW
2530 if (*input_line_pointer == '-')
2531 {
2532 input_line_pointer++;
2533 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2534 if (hi_reg == FAIL)
2535 {
2536 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2537 goto error;
2538 }
2539 else if (reg >= hi_reg)
2540 {
2541 as_bad (_("bad register range"));
2542 goto error;
2543 }
2544 for (; reg < hi_reg; reg++)
2545 mask |= 1 << reg;
2546 }
b99bd4ef 2547 }
c19d1205 2548 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2549
c19d1205
ZW
2550 if (*input_line_pointer == '}')
2551 input_line_pointer++;
b99bd4ef 2552
c19d1205
ZW
2553 demand_empty_rest_of_line ();
2554
2555 /* Generate any deferred opcodes becuuse we're going to be looking at
2556 the list. */
2557 flush_pending_unwind ();
b99bd4ef 2558
c19d1205 2559 for (reg = 0; reg < 16; reg++)
b99bd4ef 2560 {
c19d1205
ZW
2561 if (mask & (1 << reg))
2562 unwind.frame_size += 4;
b99bd4ef 2563 }
c19d1205
ZW
2564 op = 0xc700 | mask;
2565 add_unwind_opcode (op, 2);
2566 return;
2567error:
2568 ignore_rest_of_line ();
b99bd4ef
NC
2569}
2570
c19d1205
ZW
2571
2572/* Parse an unwind_save directive. */
2573
b99bd4ef 2574static void
c19d1205 2575s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2576{
c19d1205
ZW
2577 char *peek;
2578 struct reg_entry *reg;
2579 bfd_boolean had_brace = FALSE;
b99bd4ef 2580
c19d1205
ZW
2581 /* Figure out what sort of save we have. */
2582 peek = input_line_pointer;
b99bd4ef 2583
c19d1205 2584 if (*peek == '{')
b99bd4ef 2585 {
c19d1205
ZW
2586 had_brace = TRUE;
2587 peek++;
b99bd4ef
NC
2588 }
2589
c19d1205 2590 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2591
c19d1205 2592 if (!reg)
b99bd4ef 2593 {
c19d1205
ZW
2594 as_bad (_("register expected"));
2595 ignore_rest_of_line ();
b99bd4ef
NC
2596 return;
2597 }
2598
c19d1205 2599 switch (reg->type)
b99bd4ef 2600 {
c19d1205
ZW
2601 case REG_TYPE_FN:
2602 if (had_brace)
2603 {
2604 as_bad (_("FPA .unwind_save does not take a register list"));
2605 ignore_rest_of_line ();
2606 return;
2607 }
2608 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2609 return;
c19d1205
ZW
2610
2611 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2612 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2613 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2614 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2615
2616 default:
2617 as_bad (_(".unwind_save does not support this kind of register"));
2618 ignore_rest_of_line ();
b99bd4ef 2619 }
c19d1205 2620}
b99bd4ef 2621
b99bd4ef 2622
c19d1205
ZW
2623/* Parse an unwind_movsp directive. */
2624
2625static void
2626s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2627{
2628 int reg;
2629 valueT op;
2630
2631 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2632 if (reg == FAIL)
b99bd4ef 2633 {
c19d1205
ZW
2634 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2635 ignore_rest_of_line ();
b99bd4ef
NC
2636 return;
2637 }
c19d1205 2638 demand_empty_rest_of_line ();
b99bd4ef 2639
c19d1205 2640 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2641 {
c19d1205 2642 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2643 return;
2644 }
2645
c19d1205
ZW
2646 if (unwind.fp_reg != REG_SP)
2647 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2648
c19d1205
ZW
2649 /* Generate opcode to restore the value. */
2650 op = 0x90 | reg;
2651 add_unwind_opcode (op, 1);
2652
2653 /* Record the information for later. */
2654 unwind.fp_reg = reg;
2655 unwind.fp_offset = unwind.frame_size;
2656 unwind.sp_restored = 1;
b05fe5cf
ZW
2657}
2658
c19d1205
ZW
2659/* Parse an unwind_pad directive. */
2660
b05fe5cf 2661static void
c19d1205 2662s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2663{
c19d1205 2664 int offset;
b05fe5cf 2665
c19d1205
ZW
2666 if (immediate_for_directive (&offset) == FAIL)
2667 return;
b99bd4ef 2668
c19d1205
ZW
2669 if (offset & 3)
2670 {
2671 as_bad (_("stack increment must be multiple of 4"));
2672 ignore_rest_of_line ();
2673 return;
2674 }
b99bd4ef 2675
c19d1205
ZW
2676 /* Don't generate any opcodes, just record the details for later. */
2677 unwind.frame_size += offset;
2678 unwind.pending_offset += offset;
2679
2680 demand_empty_rest_of_line ();
2681}
2682
2683/* Parse an unwind_setfp directive. */
2684
2685static void
2686s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2687{
c19d1205
ZW
2688 int sp_reg;
2689 int fp_reg;
2690 int offset;
2691
2692 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2693 if (skip_past_comma (&input_line_pointer) == FAIL)
2694 sp_reg = FAIL;
2695 else
2696 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2697
c19d1205
ZW
2698 if (fp_reg == FAIL || sp_reg == FAIL)
2699 {
2700 as_bad (_("expected <reg>, <reg>"));
2701 ignore_rest_of_line ();
2702 return;
2703 }
b99bd4ef 2704
c19d1205
ZW
2705 /* Optional constant. */
2706 if (skip_past_comma (&input_line_pointer) != FAIL)
2707 {
2708 if (immediate_for_directive (&offset) == FAIL)
2709 return;
2710 }
2711 else
2712 offset = 0;
a737bd4d 2713
c19d1205 2714 demand_empty_rest_of_line ();
a737bd4d 2715
c19d1205 2716 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2717 {
c19d1205
ZW
2718 as_bad (_("register must be either sp or set by a previous"
2719 "unwind_movsp directive"));
2720 return;
a737bd4d
NC
2721 }
2722
c19d1205
ZW
2723 /* Don't generate any opcodes, just record the information for later. */
2724 unwind.fp_reg = fp_reg;
2725 unwind.fp_used = 1;
2726 if (sp_reg == 13)
2727 unwind.fp_offset = unwind.frame_size - offset;
2728 else
2729 unwind.fp_offset -= offset;
a737bd4d
NC
2730}
2731
c19d1205
ZW
2732/* Parse an unwind_raw directive. */
2733
2734static void
2735s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2736{
c19d1205
ZW
2737 expressionS exp;
2738 /* This is an arbitary limit. */
2739 unsigned char op[16];
2740 int count;
a737bd4d 2741
c19d1205
ZW
2742 expression (&exp);
2743 if (exp.X_op == O_constant
2744 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2745 {
c19d1205
ZW
2746 unwind.frame_size += exp.X_add_number;
2747 expression (&exp);
2748 }
2749 else
2750 exp.X_op = O_illegal;
a737bd4d 2751
c19d1205
ZW
2752 if (exp.X_op != O_constant)
2753 {
2754 as_bad (_("expected <offset>, <opcode>"));
2755 ignore_rest_of_line ();
2756 return;
2757 }
a737bd4d 2758
c19d1205 2759 count = 0;
a737bd4d 2760
c19d1205
ZW
2761 /* Parse the opcode. */
2762 for (;;)
2763 {
2764 if (count >= 16)
2765 {
2766 as_bad (_("unwind opcode too long"));
2767 ignore_rest_of_line ();
a737bd4d 2768 }
c19d1205 2769 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2770 {
c19d1205
ZW
2771 as_bad (_("invalid unwind opcode"));
2772 ignore_rest_of_line ();
2773 return;
a737bd4d 2774 }
c19d1205 2775 op[count++] = exp.X_add_number;
a737bd4d 2776
c19d1205
ZW
2777 /* Parse the next byte. */
2778 if (skip_past_comma (&input_line_pointer) == FAIL)
2779 break;
a737bd4d 2780
c19d1205
ZW
2781 expression (&exp);
2782 }
b99bd4ef 2783
c19d1205
ZW
2784 /* Add the opcode bytes in reverse order. */
2785 while (count--)
2786 add_unwind_opcode (op[count], 1);
b99bd4ef 2787
c19d1205 2788 demand_empty_rest_of_line ();
b99bd4ef 2789}
c19d1205 2790#endif /* OBJ_ELF */
b99bd4ef 2791
c19d1205
ZW
2792/* This table describes all the machine specific pseudo-ops the assembler
2793 has to support. The fields are:
2794 pseudo-op name without dot
2795 function to call to execute this pseudo-op
2796 Integer arg to pass to the function. */
b99bd4ef 2797
c19d1205 2798const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2799{
c19d1205
ZW
2800 /* Never called because '.req' does not start a line. */
2801 { "req", s_req, 0 },
2802 { "unreq", s_unreq, 0 },
2803 { "bss", s_bss, 0 },
2804 { "align", s_align, 0 },
2805 { "arm", s_arm, 0 },
2806 { "thumb", s_thumb, 0 },
2807 { "code", s_code, 0 },
2808 { "force_thumb", s_force_thumb, 0 },
2809 { "thumb_func", s_thumb_func, 0 },
2810 { "thumb_set", s_thumb_set, 0 },
2811 { "even", s_even, 0 },
2812 { "ltorg", s_ltorg, 0 },
2813 { "pool", s_ltorg, 0 },
2814 { "syntax", s_syntax, 0 },
2815#ifdef OBJ_ELF
2816 { "word", s_arm_elf_cons, 4 },
2817 { "long", s_arm_elf_cons, 4 },
2818 { "rel31", s_arm_rel31, 0 },
2819 { "fnstart", s_arm_unwind_fnstart, 0 },
2820 { "fnend", s_arm_unwind_fnend, 0 },
2821 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2822 { "personality", s_arm_unwind_personality, 0 },
2823 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2824 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2825 { "save", s_arm_unwind_save, 0 },
2826 { "movsp", s_arm_unwind_movsp, 0 },
2827 { "pad", s_arm_unwind_pad, 0 },
2828 { "setfp", s_arm_unwind_setfp, 0 },
2829 { "unwind_raw", s_arm_unwind_raw, 0 },
2830#else
2831 { "word", cons, 4},
2832#endif
2833 { "extend", float_cons, 'x' },
2834 { "ldouble", float_cons, 'x' },
2835 { "packed", float_cons, 'p' },
2836 { 0, 0, 0 }
2837};
2838\f
2839/* Parser functions used exclusively in instruction operands. */
b99bd4ef 2840
c19d1205
ZW
2841/* Generic immediate-value read function for use in insn parsing.
2842 STR points to the beginning of the immediate (the leading #);
2843 VAL receives the value; if the value is outside [MIN, MAX]
2844 issue an error. PREFIX_OPT is true if the immediate prefix is
2845 optional. */
b99bd4ef 2846
c19d1205
ZW
2847static int
2848parse_immediate (char **str, int *val, int min, int max,
2849 bfd_boolean prefix_opt)
2850{
2851 expressionS exp;
2852 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2853 if (exp.X_op != O_constant)
b99bd4ef 2854 {
c19d1205
ZW
2855 inst.error = _("constant expression required");
2856 return FAIL;
2857 }
b99bd4ef 2858
c19d1205
ZW
2859 if (exp.X_add_number < min || exp.X_add_number > max)
2860 {
2861 inst.error = _("immediate value out of range");
2862 return FAIL;
2863 }
b99bd4ef 2864
c19d1205
ZW
2865 *val = exp.X_add_number;
2866 return SUCCESS;
2867}
b99bd4ef 2868
c19d1205
ZW
2869/* Returns the pseudo-register number of an FPA immediate constant,
2870 or FAIL if there isn't a valid constant here. */
b99bd4ef 2871
c19d1205
ZW
2872static int
2873parse_fpa_immediate (char ** str)
2874{
2875 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2876 char * save_in;
2877 expressionS exp;
2878 int i;
2879 int j;
b99bd4ef 2880
c19d1205
ZW
2881 /* First try and match exact strings, this is to guarantee
2882 that some formats will work even for cross assembly. */
b99bd4ef 2883
c19d1205
ZW
2884 for (i = 0; fp_const[i]; i++)
2885 {
2886 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 2887 {
c19d1205 2888 char *start = *str;
b99bd4ef 2889
c19d1205
ZW
2890 *str += strlen (fp_const[i]);
2891 if (is_end_of_line[(unsigned char) **str])
2892 return i + 8;
2893 *str = start;
2894 }
2895 }
b99bd4ef 2896
c19d1205
ZW
2897 /* Just because we didn't get a match doesn't mean that the constant
2898 isn't valid, just that it is in a format that we don't
2899 automatically recognize. Try parsing it with the standard
2900 expression routines. */
b99bd4ef 2901
c19d1205 2902 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 2903
c19d1205
ZW
2904 /* Look for a raw floating point number. */
2905 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
2906 && is_end_of_line[(unsigned char) *save_in])
2907 {
2908 for (i = 0; i < NUM_FLOAT_VALS; i++)
2909 {
2910 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 2911 {
c19d1205
ZW
2912 if (words[j] != fp_values[i][j])
2913 break;
b99bd4ef
NC
2914 }
2915
c19d1205 2916 if (j == MAX_LITTLENUMS)
b99bd4ef 2917 {
c19d1205
ZW
2918 *str = save_in;
2919 return i + 8;
b99bd4ef
NC
2920 }
2921 }
2922 }
b99bd4ef 2923
c19d1205
ZW
2924 /* Try and parse a more complex expression, this will probably fail
2925 unless the code uses a floating point prefix (eg "0f"). */
2926 save_in = input_line_pointer;
2927 input_line_pointer = *str;
2928 if (expression (&exp) == absolute_section
2929 && exp.X_op == O_big
2930 && exp.X_add_number < 0)
2931 {
2932 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
2933 Ditto for 15. */
2934 if (gen_to_words (words, 5, (long) 15) == 0)
2935 {
2936 for (i = 0; i < NUM_FLOAT_VALS; i++)
2937 {
2938 for (j = 0; j < MAX_LITTLENUMS; j++)
2939 {
2940 if (words[j] != fp_values[i][j])
2941 break;
2942 }
b99bd4ef 2943
c19d1205
ZW
2944 if (j == MAX_LITTLENUMS)
2945 {
2946 *str = input_line_pointer;
2947 input_line_pointer = save_in;
2948 return i + 8;
2949 }
2950 }
2951 }
b99bd4ef
NC
2952 }
2953
c19d1205
ZW
2954 *str = input_line_pointer;
2955 input_line_pointer = save_in;
2956 inst.error = _("invalid FPA immediate expression");
2957 return FAIL;
b99bd4ef
NC
2958}
2959
c19d1205
ZW
2960/* Shift operands. */
2961enum shift_kind
b99bd4ef 2962{
c19d1205
ZW
2963 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
2964};
b99bd4ef 2965
c19d1205
ZW
2966struct asm_shift_name
2967{
2968 const char *name;
2969 enum shift_kind kind;
2970};
b99bd4ef 2971
c19d1205
ZW
2972/* Third argument to parse_shift. */
2973enum parse_shift_mode
2974{
2975 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
2976 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
2977 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
2978 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
2979 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
2980};
b99bd4ef 2981
c19d1205
ZW
2982/* Parse a <shift> specifier on an ARM data processing instruction.
2983 This has three forms:
b99bd4ef 2984
c19d1205
ZW
2985 (LSL|LSR|ASL|ASR|ROR) Rs
2986 (LSL|LSR|ASL|ASR|ROR) #imm
2987 RRX
b99bd4ef 2988
c19d1205
ZW
2989 Note that ASL is assimilated to LSL in the instruction encoding, and
2990 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 2991
c19d1205
ZW
2992static int
2993parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 2994{
c19d1205
ZW
2995 const struct asm_shift_name *shift_name;
2996 enum shift_kind shift;
2997 char *s = *str;
2998 char *p = s;
2999 int reg;
b99bd4ef 3000
c19d1205
ZW
3001 for (p = *str; ISALPHA (*p); p++)
3002 ;
b99bd4ef 3003
c19d1205 3004 if (p == *str)
b99bd4ef 3005 {
c19d1205
ZW
3006 inst.error = _("shift expression expected");
3007 return FAIL;
b99bd4ef
NC
3008 }
3009
c19d1205
ZW
3010 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3011
3012 if (shift_name == NULL)
b99bd4ef 3013 {
c19d1205
ZW
3014 inst.error = _("shift expression expected");
3015 return FAIL;
b99bd4ef
NC
3016 }
3017
c19d1205 3018 shift = shift_name->kind;
b99bd4ef 3019
c19d1205
ZW
3020 switch (mode)
3021 {
3022 case NO_SHIFT_RESTRICT:
3023 case SHIFT_IMMEDIATE: break;
b99bd4ef 3024
c19d1205
ZW
3025 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3026 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3027 {
3028 inst.error = _("'LSL' or 'ASR' required");
3029 return FAIL;
3030 }
3031 break;
b99bd4ef 3032
c19d1205
ZW
3033 case SHIFT_LSL_IMMEDIATE:
3034 if (shift != SHIFT_LSL)
3035 {
3036 inst.error = _("'LSL' required");
3037 return FAIL;
3038 }
3039 break;
b99bd4ef 3040
c19d1205
ZW
3041 case SHIFT_ASR_IMMEDIATE:
3042 if (shift != SHIFT_ASR)
3043 {
3044 inst.error = _("'ASR' required");
3045 return FAIL;
3046 }
3047 break;
b99bd4ef 3048
c19d1205
ZW
3049 default: abort ();
3050 }
b99bd4ef 3051
c19d1205
ZW
3052 if (shift != SHIFT_RRX)
3053 {
3054 /* Whitespace can appear here if the next thing is a bare digit. */
3055 skip_whitespace (p);
b99bd4ef 3056
c19d1205
ZW
3057 if (mode == NO_SHIFT_RESTRICT
3058 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3059 {
3060 inst.operands[i].imm = reg;
3061 inst.operands[i].immisreg = 1;
3062 }
3063 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3064 return FAIL;
3065 }
3066 inst.operands[i].shift_kind = shift;
3067 inst.operands[i].shifted = 1;
3068 *str = p;
3069 return SUCCESS;
b99bd4ef
NC
3070}
3071
c19d1205 3072/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3073
c19d1205
ZW
3074 #<immediate>
3075 #<immediate>, <rotate>
3076 <Rm>
3077 <Rm>, <shift>
b99bd4ef 3078
c19d1205
ZW
3079 where <shift> is defined by parse_shift above, and <rotate> is a
3080 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3081 is deferred to md_apply_fix. */
b99bd4ef 3082
c19d1205
ZW
3083static int
3084parse_shifter_operand (char **str, int i)
3085{
3086 int value;
3087 expressionS expr;
b99bd4ef 3088
c19d1205
ZW
3089 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3090 {
3091 inst.operands[i].reg = value;
3092 inst.operands[i].isreg = 1;
b99bd4ef 3093
c19d1205
ZW
3094 /* parse_shift will override this if appropriate */
3095 inst.reloc.exp.X_op = O_constant;
3096 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3097
c19d1205
ZW
3098 if (skip_past_comma (str) == FAIL)
3099 return SUCCESS;
b99bd4ef 3100
c19d1205
ZW
3101 /* Shift operation on register. */
3102 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3103 }
3104
c19d1205
ZW
3105 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3106 return FAIL;
b99bd4ef 3107
c19d1205 3108 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3109 {
c19d1205
ZW
3110 /* #x, y -- ie explicit rotation by Y. */
3111 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3112 return FAIL;
b99bd4ef 3113
c19d1205
ZW
3114 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3115 {
3116 inst.error = _("constant expression expected");
3117 return FAIL;
3118 }
b99bd4ef 3119
c19d1205
ZW
3120 value = expr.X_add_number;
3121 if (value < 0 || value > 30 || value % 2 != 0)
3122 {
3123 inst.error = _("invalid rotation");
3124 return FAIL;
3125 }
3126 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3127 {
3128 inst.error = _("invalid constant");
3129 return FAIL;
3130 }
09d92015 3131
55cf6793 3132 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3133 inst.reloc.exp.X_add_number
3134 = (((inst.reloc.exp.X_add_number << (32 - value))
3135 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3136 }
3137
c19d1205
ZW
3138 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3139 inst.reloc.pc_rel = 0;
3140 return SUCCESS;
09d92015
MM
3141}
3142
c19d1205
ZW
3143/* Parse all forms of an ARM address expression. Information is written
3144 to inst.operands[i] and/or inst.reloc.
09d92015 3145
c19d1205 3146 Preindexed addressing (.preind=1):
09d92015 3147
c19d1205
ZW
3148 [Rn, #offset] .reg=Rn .reloc.exp=offset
3149 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3150 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3151 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3152
c19d1205 3153 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3154
c19d1205 3155 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3156
c19d1205
ZW
3157 [Rn], #offset .reg=Rn .reloc.exp=offset
3158 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3159 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3160 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3161
c19d1205 3162 Unindexed addressing (.preind=0, .postind=0):
09d92015 3163
c19d1205 3164 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3165
c19d1205 3166 Other:
09d92015 3167
c19d1205
ZW
3168 [Rn]{!} shorthand for [Rn,#0]{!}
3169 =immediate .isreg=0 .reloc.exp=immediate
3170 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3171
c19d1205
ZW
3172 It is the caller's responsibility to check for addressing modes not
3173 supported by the instruction, and to set inst.reloc.type. */
3174
3175static int
3176parse_address (char **str, int i)
09d92015 3177{
c19d1205
ZW
3178 char *p = *str;
3179 int reg;
09d92015 3180
c19d1205 3181 if (skip_past_char (&p, '[') == FAIL)
09d92015 3182 {
c19d1205
ZW
3183 if (skip_past_char (&p, '=') == FAIL)
3184 {
3185 /* bare address - translate to PC-relative offset */
3186 inst.reloc.pc_rel = 1;
3187 inst.operands[i].reg = REG_PC;
3188 inst.operands[i].isreg = 1;
3189 inst.operands[i].preind = 1;
3190 }
3191 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3192
c19d1205
ZW
3193 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3194 return FAIL;
09d92015 3195
c19d1205
ZW
3196 *str = p;
3197 return SUCCESS;
09d92015
MM
3198 }
3199
c19d1205 3200 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3201 {
c19d1205
ZW
3202 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3203 return FAIL;
09d92015 3204 }
c19d1205
ZW
3205 inst.operands[i].reg = reg;
3206 inst.operands[i].isreg = 1;
09d92015 3207
c19d1205 3208 if (skip_past_comma (&p) == SUCCESS)
09d92015 3209 {
c19d1205 3210 inst.operands[i].preind = 1;
09d92015 3211
c19d1205
ZW
3212 if (*p == '+') p++;
3213 else if (*p == '-') p++, inst.operands[i].negative = 1;
3214
3215 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3216 {
c19d1205
ZW
3217 inst.operands[i].imm = reg;
3218 inst.operands[i].immisreg = 1;
3219
3220 if (skip_past_comma (&p) == SUCCESS)
3221 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3222 return FAIL;
3223 }
3224 else
3225 {
3226 if (inst.operands[i].negative)
3227 {
3228 inst.operands[i].negative = 0;
3229 p--;
3230 }
3231 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3232 return FAIL;
09d92015
MM
3233 }
3234 }
3235
c19d1205 3236 if (skip_past_char (&p, ']') == FAIL)
09d92015 3237 {
c19d1205
ZW
3238 inst.error = _("']' expected");
3239 return FAIL;
09d92015
MM
3240 }
3241
c19d1205
ZW
3242 if (skip_past_char (&p, '!') == SUCCESS)
3243 inst.operands[i].writeback = 1;
09d92015 3244
c19d1205 3245 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3246 {
c19d1205
ZW
3247 if (skip_past_char (&p, '{') == SUCCESS)
3248 {
3249 /* [Rn], {expr} - unindexed, with option */
3250 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 3251 0, 255, TRUE) == FAIL)
c19d1205 3252 return FAIL;
09d92015 3253
c19d1205
ZW
3254 if (skip_past_char (&p, '}') == FAIL)
3255 {
3256 inst.error = _("'}' expected at end of 'option' field");
3257 return FAIL;
3258 }
3259 if (inst.operands[i].preind)
3260 {
3261 inst.error = _("cannot combine index with option");
3262 return FAIL;
3263 }
3264 *str = p;
3265 return SUCCESS;
09d92015 3266 }
c19d1205
ZW
3267 else
3268 {
3269 inst.operands[i].postind = 1;
3270 inst.operands[i].writeback = 1;
09d92015 3271
c19d1205
ZW
3272 if (inst.operands[i].preind)
3273 {
3274 inst.error = _("cannot combine pre- and post-indexing");
3275 return FAIL;
3276 }
09d92015 3277
c19d1205
ZW
3278 if (*p == '+') p++;
3279 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3280
c19d1205
ZW
3281 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3282 {
3283 inst.operands[i].imm = reg;
3284 inst.operands[i].immisreg = 1;
a737bd4d 3285
c19d1205
ZW
3286 if (skip_past_comma (&p) == SUCCESS)
3287 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3288 return FAIL;
3289 }
3290 else
3291 {
3292 if (inst.operands[i].negative)
3293 {
3294 inst.operands[i].negative = 0;
3295 p--;
3296 }
3297 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3298 return FAIL;
3299 }
3300 }
a737bd4d
NC
3301 }
3302
c19d1205
ZW
3303 /* If at this point neither .preind nor .postind is set, we have a
3304 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3305 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3306 {
3307 inst.operands[i].preind = 1;
3308 inst.reloc.exp.X_op = O_constant;
3309 inst.reloc.exp.X_add_number = 0;
3310 }
3311 *str = p;
3312 return SUCCESS;
a737bd4d
NC
3313}
3314
c19d1205 3315/* Miscellaneous. */
a737bd4d 3316
c19d1205
ZW
3317/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3318 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3319static int
3320parse_psr (char **str)
09d92015 3321{
c19d1205
ZW
3322 char *p;
3323 unsigned long psr_field;
09d92015 3324
c19d1205
ZW
3325 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3326 feature for ease of use and backwards compatibility. */
3327 p = *str;
3328 if (*p == 's' || *p == 'S')
3329 psr_field = SPSR_BIT;
3330 else if (*p == 'c' || *p == 'C')
3331 psr_field = 0;
3332 else
3333 goto error;
09d92015 3334
c19d1205
ZW
3335 p++;
3336 if (strncasecmp (p, "PSR", 3) != 0)
3337 goto error;
3338 p += 3;
09d92015 3339
c19d1205
ZW
3340 if (*p == '_')
3341 {
3342 /* A suffix follows. */
3343 const struct asm_psr *psr;
3344 char *start;
a737bd4d 3345
c19d1205
ZW
3346 p++;
3347 start = p;
a737bd4d 3348
c19d1205
ZW
3349 do
3350 p++;
3351 while (ISALNUM (*p) || *p == '_');
a737bd4d 3352
c19d1205
ZW
3353 psr = hash_find_n (arm_psr_hsh, start, p - start);
3354 if (!psr)
3355 goto error;
a737bd4d 3356
c19d1205 3357 psr_field |= psr->field;
a737bd4d 3358 }
c19d1205 3359 else
a737bd4d 3360 {
c19d1205
ZW
3361 if (ISALNUM (*p))
3362 goto error; /* Garbage after "[CS]PSR". */
3363
3364 psr_field |= (PSR_c | PSR_f);
a737bd4d 3365 }
c19d1205
ZW
3366 *str = p;
3367 return psr_field;
a737bd4d 3368
c19d1205
ZW
3369 error:
3370 inst.error = _("flag for {c}psr instruction expected");
3371 return FAIL;
a737bd4d
NC
3372}
3373
c19d1205
ZW
3374/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3375 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3376
c19d1205
ZW
3377static int
3378parse_cps_flags (char **str)
a737bd4d 3379{
c19d1205
ZW
3380 int val = 0;
3381 int saw_a_flag = 0;
3382 char *s = *str;
a737bd4d 3383
c19d1205
ZW
3384 for (;;)
3385 switch (*s++)
3386 {
3387 case '\0': case ',':
3388 goto done;
a737bd4d 3389
c19d1205
ZW
3390 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3391 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3392 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3393
c19d1205
ZW
3394 default:
3395 inst.error = _("unrecognized CPS flag");
3396 return FAIL;
3397 }
a737bd4d 3398
c19d1205
ZW
3399 done:
3400 if (saw_a_flag == 0)
a737bd4d 3401 {
c19d1205
ZW
3402 inst.error = _("missing CPS flags");
3403 return FAIL;
a737bd4d 3404 }
a737bd4d 3405
c19d1205
ZW
3406 *str = s - 1;
3407 return val;
a737bd4d
NC
3408}
3409
c19d1205
ZW
3410/* Parse an endian specifier ("BE" or "LE", case insensitive);
3411 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3412
3413static int
c19d1205 3414parse_endian_specifier (char **str)
a737bd4d 3415{
c19d1205
ZW
3416 int little_endian;
3417 char *s = *str;
a737bd4d 3418
c19d1205
ZW
3419 if (strncasecmp (s, "BE", 2))
3420 little_endian = 0;
3421 else if (strncasecmp (s, "LE", 2))
3422 little_endian = 1;
3423 else
a737bd4d 3424 {
c19d1205 3425 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3426 return FAIL;
3427 }
3428
c19d1205 3429 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3430 {
c19d1205 3431 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3432 return FAIL;
3433 }
3434
c19d1205
ZW
3435 *str = s + 2;
3436 return little_endian;
3437}
a737bd4d 3438
c19d1205
ZW
3439/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3440 value suitable for poking into the rotate field of an sxt or sxta
3441 instruction, or FAIL on error. */
3442
3443static int
3444parse_ror (char **str)
3445{
3446 int rot;
3447 char *s = *str;
3448
3449 if (strncasecmp (s, "ROR", 3) == 0)
3450 s += 3;
3451 else
a737bd4d 3452 {
c19d1205 3453 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3454 return FAIL;
3455 }
c19d1205
ZW
3456
3457 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3458 return FAIL;
3459
3460 switch (rot)
a737bd4d 3461 {
c19d1205
ZW
3462 case 0: *str = s; return 0x0;
3463 case 8: *str = s; return 0x1;
3464 case 16: *str = s; return 0x2;
3465 case 24: *str = s; return 0x3;
3466
3467 default:
3468 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3469 return FAIL;
3470 }
c19d1205 3471}
a737bd4d 3472
c19d1205
ZW
3473/* Parse a conditional code (from conds[] below). The value returned is in the
3474 range 0 .. 14, or FAIL. */
3475static int
3476parse_cond (char **str)
3477{
3478 char *p, *q;
3479 const struct asm_cond *c;
a737bd4d 3480
c19d1205
ZW
3481 p = q = *str;
3482 while (ISALPHA (*q))
3483 q++;
a737bd4d 3484
c19d1205
ZW
3485 c = hash_find_n (arm_cond_hsh, p, q - p);
3486 if (!c)
a737bd4d 3487 {
c19d1205 3488 inst.error = _("condition required");
a737bd4d
NC
3489 return FAIL;
3490 }
3491
c19d1205
ZW
3492 *str = q;
3493 return c->value;
3494}
3495
92e90b6e
PB
3496/* Parse the operands of a table branch instruction. Similar to a memory
3497 operand. */
3498static int
3499parse_tb (char **str)
3500{
3501 char * p = *str;
3502 int reg;
3503
3504 if (skip_past_char (&p, '[') == FAIL)
3505 return FAIL;
3506
3507 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3508 {
3509 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3510 return FAIL;
3511 }
3512 inst.operands[0].reg = reg;
3513
3514 if (skip_past_comma (&p) == FAIL)
3515 return FAIL;
3516
3517 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3518 {
3519 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3520 return FAIL;
3521 }
3522 inst.operands[0].imm = reg;
3523
3524 if (skip_past_comma (&p) == SUCCESS)
3525 {
3526 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3527 return FAIL;
3528 if (inst.reloc.exp.X_add_number != 1)
3529 {
3530 inst.error = _("invalid shift");
3531 return FAIL;
3532 }
3533 inst.operands[0].shifted = 1;
3534 }
3535
3536 if (skip_past_char (&p, ']') == FAIL)
3537 {
3538 inst.error = _("']' expected");
3539 return FAIL;
3540 }
3541 *str = p;
3542 return SUCCESS;
3543}
3544
c19d1205
ZW
3545/* Matcher codes for parse_operands. */
3546enum operand_parse_code
3547{
3548 OP_stop, /* end of line */
3549
3550 OP_RR, /* ARM register */
3551 OP_RRnpc, /* ARM register, not r15 */
3552 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3553 OP_RRw, /* ARM register, not r15, optional trailing ! */
3554 OP_RCP, /* Coprocessor number */
3555 OP_RCN, /* Coprocessor register */
3556 OP_RF, /* FPA register */
3557 OP_RVS, /* VFP single precision register */
3558 OP_RVD, /* VFP double precision register */
3559 OP_RVC, /* VFP control register */
3560 OP_RMF, /* Maverick F register */
3561 OP_RMD, /* Maverick D register */
3562 OP_RMFX, /* Maverick FX register */
3563 OP_RMDX, /* Maverick DX register */
3564 OP_RMAX, /* Maverick AX register */
3565 OP_RMDS, /* Maverick DSPSC register */
3566 OP_RIWR, /* iWMMXt wR register */
3567 OP_RIWC, /* iWMMXt wC register */
3568 OP_RIWG, /* iWMMXt wCG register */
3569 OP_RXA, /* XScale accumulator register */
3570
3571 OP_REGLST, /* ARM register list */
3572 OP_VRSLST, /* VFP single-precision register list */
3573 OP_VRDLST, /* VFP double-precision register list */
3574
3575 OP_I7, /* immediate value 0 .. 7 */
3576 OP_I15, /* 0 .. 15 */
3577 OP_I16, /* 1 .. 16 */
3578 OP_I31, /* 0 .. 31 */
3579 OP_I31w, /* 0 .. 31, optional trailing ! */
3580 OP_I32, /* 1 .. 32 */
3581 OP_I63s, /* -64 .. 63 */
3582 OP_I255, /* 0 .. 255 */
3583 OP_Iffff, /* 0 .. 65535 */
3584
3585 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3586 OP_I7b, /* 0 .. 7 */
3587 OP_I15b, /* 0 .. 15 */
3588 OP_I31b, /* 0 .. 31 */
3589
3590 OP_SH, /* shifter operand */
3591 OP_ADDR, /* Memory address expression (any mode) */
3592 OP_EXP, /* arbitrary expression */
3593 OP_EXPi, /* same, with optional immediate prefix */
3594 OP_EXPr, /* same, with optional relocation suffix */
3595
3596 OP_CPSF, /* CPS flags */
3597 OP_ENDI, /* Endianness specifier */
3598 OP_PSR, /* CPSR/SPSR mask for msr */
3599 OP_COND, /* conditional code */
92e90b6e 3600 OP_TB, /* Table branch. */
c19d1205
ZW
3601
3602 OP_RRnpc_I0, /* ARM register or literal 0 */
3603 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3604 OP_RR_EXi, /* ARM register or expression with imm prefix */
3605 OP_RF_IF, /* FPA register or immediate */
3606 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3607
3608 /* Optional operands. */
3609 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3610 OP_oI31b, /* 0 .. 31 */
3611 OP_oIffffb, /* 0 .. 65535 */
3612 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3613
3614 OP_oRR, /* ARM register */
3615 OP_oRRnpc, /* ARM register, not the PC */
3616 OP_oSHll, /* LSL immediate */
3617 OP_oSHar, /* ASR immediate */
3618 OP_oSHllar, /* LSL or ASR immediate */
3619 OP_oROR, /* ROR 0/8/16/24 */
3620
3621 OP_FIRST_OPTIONAL = OP_oI7b
3622};
a737bd4d 3623
c19d1205
ZW
3624/* Generic instruction operand parser. This does no encoding and no
3625 semantic validation; it merely squirrels values away in the inst
3626 structure. Returns SUCCESS or FAIL depending on whether the
3627 specified grammar matched. */
3628static int
ca3f61f7 3629parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
3630{
3631 unsigned const char *upat = pattern;
3632 char *backtrack_pos = 0;
3633 const char *backtrack_error = 0;
3634 int i, val, backtrack_index = 0;
3635
3636#define po_char_or_fail(chr) do { \
3637 if (skip_past_char (&str, chr) == FAIL) \
3638 goto bad_args; \
3639} while (0)
3640
3641#define po_reg_or_fail(regtype) do { \
3642 val = arm_reg_parse (&str, regtype); \
3643 if (val == FAIL) \
3644 { \
3645 inst.error = _(reg_expected_msgs[regtype]); \
3646 goto failure; \
3647 } \
3648 inst.operands[i].reg = val; \
3649 inst.operands[i].isreg = 1; \
3650} while (0)
3651
3652#define po_reg_or_goto(regtype, label) do { \
3653 val = arm_reg_parse (&str, regtype); \
3654 if (val == FAIL) \
3655 goto label; \
3656 \
3657 inst.operands[i].reg = val; \
3658 inst.operands[i].isreg = 1; \
3659} while (0)
3660
3661#define po_imm_or_fail(min, max, popt) do { \
3662 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3663 goto failure; \
3664 inst.operands[i].imm = val; \
3665} while (0)
3666
3667#define po_misc_or_fail(expr) do { \
3668 if (expr) \
3669 goto failure; \
3670} while (0)
3671
3672 skip_whitespace (str);
3673
3674 for (i = 0; upat[i] != OP_stop; i++)
3675 {
3676 if (upat[i] >= OP_FIRST_OPTIONAL)
3677 {
3678 /* Remember where we are in case we need to backtrack. */
3679 assert (!backtrack_pos);
3680 backtrack_pos = str;
3681 backtrack_error = inst.error;
3682 backtrack_index = i;
3683 }
3684
3685 if (i > 0)
3686 po_char_or_fail (',');
3687
3688 switch (upat[i])
3689 {
3690 /* Registers */
3691 case OP_oRRnpc:
3692 case OP_RRnpc:
3693 case OP_oRR:
3694 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3695 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3696 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3697 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3698 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3699 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3700 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3701 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3702 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3703 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3704 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3705 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3706 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3707 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3708 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3709 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3710 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3711
3712 case OP_RRnpcb:
3713 po_char_or_fail ('[');
3714 po_reg_or_fail (REG_TYPE_RN);
3715 po_char_or_fail (']');
3716 break;
a737bd4d 3717
c19d1205
ZW
3718 case OP_RRw:
3719 po_reg_or_fail (REG_TYPE_RN);
3720 if (skip_past_char (&str, '!') == SUCCESS)
3721 inst.operands[i].writeback = 1;
3722 break;
3723
3724 /* Immediates */
3725 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3726 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3727 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3728 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3729 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3730 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3731 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3732 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3733
3734 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3735 case OP_oI7b:
3736 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3737 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3738 case OP_oI31b:
3739 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3740 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3741
3742 /* Immediate variants */
3743 case OP_oI255c:
3744 po_char_or_fail ('{');
3745 po_imm_or_fail (0, 255, TRUE);
3746 po_char_or_fail ('}');
3747 break;
3748
3749 case OP_I31w:
3750 /* The expression parser chokes on a trailing !, so we have
3751 to find it first and zap it. */
3752 {
3753 char *s = str;
3754 while (*s && *s != ',')
3755 s++;
3756 if (s[-1] == '!')
3757 {
3758 s[-1] = '\0';
3759 inst.operands[i].writeback = 1;
3760 }
3761 po_imm_or_fail (0, 31, TRUE);
3762 if (str == s - 1)
3763 str = s;
3764 }
3765 break;
3766
3767 /* Expressions */
3768 case OP_EXPi: EXPi:
3769 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3770 GE_OPT_PREFIX));
3771 break;
3772
3773 case OP_EXP:
3774 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3775 GE_NO_PREFIX));
3776 break;
3777
3778 case OP_EXPr: EXPr:
3779 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3780 GE_NO_PREFIX));
3781 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3782 {
c19d1205
ZW
3783 val = parse_reloc (&str);
3784 if (val == -1)
3785 {
3786 inst.error = _("unrecognized relocation suffix");
3787 goto failure;
3788 }
3789 else if (val != BFD_RELOC_UNUSED)
3790 {
3791 inst.operands[i].imm = val;
3792 inst.operands[i].hasreloc = 1;
3793 }
a737bd4d 3794 }
c19d1205 3795 break;
a737bd4d 3796
c19d1205
ZW
3797 /* Register or expression */
3798 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3799 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 3800
c19d1205
ZW
3801 /* Register or immediate */
3802 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3803 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 3804
c19d1205
ZW
3805 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3806 IF:
3807 if (!is_immediate_prefix (*str))
3808 goto bad_args;
3809 str++;
3810 val = parse_fpa_immediate (&str);
3811 if (val == FAIL)
3812 goto failure;
3813 /* FPA immediates are encoded as registers 8-15.
3814 parse_fpa_immediate has already applied the offset. */
3815 inst.operands[i].reg = val;
3816 inst.operands[i].isreg = 1;
3817 break;
09d92015 3818
c19d1205
ZW
3819 /* Two kinds of register */
3820 case OP_RIWR_RIWC:
3821 {
3822 struct reg_entry *rege = arm_reg_parse_multi (&str);
3823 if (rege->type != REG_TYPE_MMXWR
3824 && rege->type != REG_TYPE_MMXWC
3825 && rege->type != REG_TYPE_MMXWCG)
3826 {
3827 inst.error = _("iWMMXt data or control register expected");
3828 goto failure;
3829 }
3830 inst.operands[i].reg = rege->number;
3831 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3832 }
3833 break;
09d92015 3834
c19d1205
ZW
3835 /* Misc */
3836 case OP_CPSF: val = parse_cps_flags (&str); break;
3837 case OP_ENDI: val = parse_endian_specifier (&str); break;
3838 case OP_oROR: val = parse_ror (&str); break;
3839 case OP_PSR: val = parse_psr (&str); break;
3840 case OP_COND: val = parse_cond (&str); break;
3841
92e90b6e
PB
3842 case OP_TB:
3843 po_misc_or_fail (parse_tb (&str));
3844 break;
3845
c19d1205
ZW
3846 /* Register lists */
3847 case OP_REGLST:
3848 val = parse_reg_list (&str);
3849 if (*str == '^')
3850 {
3851 inst.operands[1].writeback = 1;
3852 str++;
3853 }
3854 break;
09d92015 3855
c19d1205
ZW
3856 case OP_VRSLST:
3857 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3858 break;
09d92015 3859
c19d1205
ZW
3860 case OP_VRDLST:
3861 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3862 break;
a737bd4d 3863
c19d1205
ZW
3864 /* Addressing modes */
3865 case OP_ADDR:
3866 po_misc_or_fail (parse_address (&str, i));
3867 break;
09d92015 3868
c19d1205
ZW
3869 case OP_SH:
3870 po_misc_or_fail (parse_shifter_operand (&str, i));
3871 break;
09d92015 3872
c19d1205
ZW
3873 case OP_oSHll:
3874 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3875 break;
09d92015 3876
c19d1205
ZW
3877 case OP_oSHar:
3878 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3879 break;
09d92015 3880
c19d1205
ZW
3881 case OP_oSHllar:
3882 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3883 break;
09d92015 3884
c19d1205
ZW
3885 default:
3886 as_fatal ("unhandled operand code %d", upat[i]);
3887 }
09d92015 3888
c19d1205
ZW
3889 /* Various value-based sanity checks and shared operations. We
3890 do not signal immediate failures for the register constraints;
3891 this allows a syntax error to take precedence. */
3892 switch (upat[i])
3893 {
3894 case OP_oRRnpc:
3895 case OP_RRnpc:
3896 case OP_RRnpcb:
3897 case OP_RRw:
3898 case OP_RRnpc_I0:
3899 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
3900 inst.error = BAD_PC;
3901 break;
09d92015 3902
c19d1205
ZW
3903 case OP_CPSF:
3904 case OP_ENDI:
3905 case OP_oROR:
3906 case OP_PSR:
3907 case OP_COND:
3908 case OP_REGLST:
3909 case OP_VRSLST:
3910 case OP_VRDLST:
3911 if (val == FAIL)
3912 goto failure;
3913 inst.operands[i].imm = val;
3914 break;
a737bd4d 3915
c19d1205
ZW
3916 default:
3917 break;
3918 }
09d92015 3919
c19d1205
ZW
3920 /* If we get here, this operand was successfully parsed. */
3921 inst.operands[i].present = 1;
3922 continue;
09d92015 3923
c19d1205 3924 bad_args:
09d92015 3925 inst.error = BAD_ARGS;
c19d1205
ZW
3926
3927 failure:
3928 if (!backtrack_pos)
3929 return FAIL;
3930
3931 /* Do not backtrack over a trailing optional argument that
3932 absorbed some text. We will only fail again, with the
3933 'garbage following instruction' error message, which is
3934 probably less helpful than the current one. */
3935 if (backtrack_index == i && backtrack_pos != str
3936 && upat[i+1] == OP_stop)
3937 return FAIL;
3938
3939 /* Try again, skipping the optional argument at backtrack_pos. */
3940 str = backtrack_pos;
3941 inst.error = backtrack_error;
3942 inst.operands[backtrack_index].present = 0;
3943 i = backtrack_index;
3944 backtrack_pos = 0;
09d92015 3945 }
09d92015 3946
c19d1205
ZW
3947 /* Check that we have parsed all the arguments. */
3948 if (*str != '\0' && !inst.error)
3949 inst.error = _("garbage following instruction");
09d92015 3950
c19d1205 3951 return inst.error ? FAIL : SUCCESS;
09d92015
MM
3952}
3953
c19d1205
ZW
3954#undef po_char_or_fail
3955#undef po_reg_or_fail
3956#undef po_reg_or_goto
3957#undef po_imm_or_fail
3958\f
3959/* Shorthand macro for instruction encoding functions issuing errors. */
3960#define constraint(expr, err) do { \
3961 if (expr) \
3962 { \
3963 inst.error = err; \
3964 return; \
3965 } \
3966} while (0)
3967
3968/* Functions for operand encoding. ARM, then Thumb. */
3969
3970#define rotate_left(v, n) (v << n | v >> (32 - n))
3971
3972/* If VAL can be encoded in the immediate field of an ARM instruction,
3973 return the encoded form. Otherwise, return FAIL. */
3974
3975static unsigned int
3976encode_arm_immediate (unsigned int val)
09d92015 3977{
c19d1205
ZW
3978 unsigned int a, i;
3979
3980 for (i = 0; i < 32; i += 2)
3981 if ((a = rotate_left (val, i)) <= 0xff)
3982 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
3983
3984 return FAIL;
09d92015
MM
3985}
3986
c19d1205
ZW
3987/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
3988 return the encoded form. Otherwise, return FAIL. */
3989static unsigned int
3990encode_thumb32_immediate (unsigned int val)
09d92015 3991{
c19d1205 3992 unsigned int a, i;
09d92015 3993
9c3c69f2 3994 if (val <= 0xff)
c19d1205 3995 return val;
a737bd4d 3996
9c3c69f2 3997 for (i = 1; i <= 24; i++)
09d92015 3998 {
9c3c69f2
PB
3999 a = val >> i;
4000 if ((val & ~(0xff << i)) == 0)
4001 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 4002 }
a737bd4d 4003
c19d1205
ZW
4004 a = val & 0xff;
4005 if (val == ((a << 16) | a))
4006 return 0x100 | a;
4007 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4008 return 0x300 | a;
09d92015 4009
c19d1205
ZW
4010 a = val & 0xff00;
4011 if (val == ((a << 16) | a))
4012 return 0x200 | (a >> 8);
a737bd4d 4013
c19d1205 4014 return FAIL;
09d92015 4015}
c19d1205 4016/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
4017
4018static void
c19d1205 4019encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 4020{
c19d1205 4021 switch (pos)
09d92015 4022 {
c19d1205
ZW
4023 case VFP_REG_Sd:
4024 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4025 break;
4026
4027 case VFP_REG_Sn:
4028 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4029 break;
4030
4031 case VFP_REG_Sm:
4032 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4033 break;
4034
4035 default:
4036 abort ();
09d92015 4037 }
09d92015
MM
4038}
4039
c19d1205 4040/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 4041 if any, is handled by md_apply_fix. */
09d92015 4042static void
c19d1205 4043encode_arm_shift (int i)
09d92015 4044{
c19d1205
ZW
4045 if (inst.operands[i].shift_kind == SHIFT_RRX)
4046 inst.instruction |= SHIFT_ROR << 5;
4047 else
09d92015 4048 {
c19d1205
ZW
4049 inst.instruction |= inst.operands[i].shift_kind << 5;
4050 if (inst.operands[i].immisreg)
4051 {
4052 inst.instruction |= SHIFT_BY_REG;
4053 inst.instruction |= inst.operands[i].imm << 8;
4054 }
4055 else
4056 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 4057 }
c19d1205 4058}
09d92015 4059
c19d1205
ZW
4060static void
4061encode_arm_shifter_operand (int i)
4062{
4063 if (inst.operands[i].isreg)
09d92015 4064 {
c19d1205
ZW
4065 inst.instruction |= inst.operands[i].reg;
4066 encode_arm_shift (i);
09d92015 4067 }
c19d1205
ZW
4068 else
4069 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4070}
4071
c19d1205 4072/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4073static void
c19d1205 4074encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4075{
c19d1205
ZW
4076 assert (inst.operands[i].isreg);
4077 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4078
c19d1205 4079 if (inst.operands[i].preind)
09d92015 4080 {
c19d1205
ZW
4081 if (is_t)
4082 {
4083 inst.error = _("instruction does not accept preindexed addressing");
4084 return;
4085 }
4086 inst.instruction |= PRE_INDEX;
4087 if (inst.operands[i].writeback)
4088 inst.instruction |= WRITE_BACK;
09d92015 4089
c19d1205
ZW
4090 }
4091 else if (inst.operands[i].postind)
4092 {
4093 assert (inst.operands[i].writeback);
4094 if (is_t)
4095 inst.instruction |= WRITE_BACK;
4096 }
4097 else /* unindexed - only for coprocessor */
09d92015 4098 {
c19d1205 4099 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4100 return;
4101 }
4102
c19d1205
ZW
4103 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4104 && (((inst.instruction & 0x000f0000) >> 16)
4105 == ((inst.instruction & 0x0000f000) >> 12)))
4106 as_warn ((inst.instruction & LOAD_BIT)
4107 ? _("destination register same as write-back base")
4108 : _("source register same as write-back base"));
09d92015
MM
4109}
4110
c19d1205
ZW
4111/* inst.operands[i] was set up by parse_address. Encode it into an
4112 ARM-format mode 2 load or store instruction. If is_t is true,
4113 reject forms that cannot be used with a T instruction (i.e. not
4114 post-indexed). */
a737bd4d 4115static void
c19d1205 4116encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4117{
c19d1205 4118 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4119
c19d1205 4120 if (inst.operands[i].immisreg)
09d92015 4121 {
c19d1205
ZW
4122 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4123 inst.instruction |= inst.operands[i].imm;
4124 if (!inst.operands[i].negative)
4125 inst.instruction |= INDEX_UP;
4126 if (inst.operands[i].shifted)
4127 {
4128 if (inst.operands[i].shift_kind == SHIFT_RRX)
4129 inst.instruction |= SHIFT_ROR << 5;
4130 else
4131 {
4132 inst.instruction |= inst.operands[i].shift_kind << 5;
4133 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4134 }
4135 }
09d92015 4136 }
c19d1205 4137 else /* immediate offset in inst.reloc */
09d92015 4138 {
c19d1205
ZW
4139 if (inst.reloc.type == BFD_RELOC_UNUSED)
4140 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 4141 }
09d92015
MM
4142}
4143
c19d1205
ZW
4144/* inst.operands[i] was set up by parse_address. Encode it into an
4145 ARM-format mode 3 load or store instruction. Reject forms that
4146 cannot be used with such instructions. If is_t is true, reject
4147 forms that cannot be used with a T instruction (i.e. not
4148 post-indexed). */
4149static void
4150encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4151{
c19d1205 4152 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4153 {
c19d1205
ZW
4154 inst.error = _("instruction does not accept scaled register index");
4155 return;
09d92015 4156 }
a737bd4d 4157
c19d1205 4158 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4159
c19d1205
ZW
4160 if (inst.operands[i].immisreg)
4161 {
4162 inst.instruction |= inst.operands[i].imm;
4163 if (!inst.operands[i].negative)
4164 inst.instruction |= INDEX_UP;
4165 }
4166 else /* immediate offset in inst.reloc */
4167 {
4168 inst.instruction |= HWOFFSET_IMM;
4169 if (inst.reloc.type == BFD_RELOC_UNUSED)
4170 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 4171 }
a737bd4d
NC
4172}
4173
c19d1205
ZW
4174/* inst.operands[i] was set up by parse_address. Encode it into an
4175 ARM-format instruction. Reject all forms which cannot be encoded
4176 into a coprocessor load/store instruction. If wb_ok is false,
4177 reject use of writeback; if unind_ok is false, reject use of
4178 unindexed addressing. If reloc_override is not 0, use it instead
4179 of BFD_ARM_CP_OFF_IMM. */
09d92015 4180
c19d1205
ZW
4181static int
4182encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4183{
c19d1205 4184 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4185
c19d1205 4186 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4187
c19d1205 4188 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4189 {
c19d1205
ZW
4190 assert (!inst.operands[i].writeback);
4191 if (!unind_ok)
4192 {
4193 inst.error = _("instruction does not support unindexed addressing");
4194 return FAIL;
4195 }
4196 inst.instruction |= inst.operands[i].imm;
4197 inst.instruction |= INDEX_UP;
4198 return SUCCESS;
09d92015 4199 }
a737bd4d 4200
c19d1205
ZW
4201 if (inst.operands[i].preind)
4202 inst.instruction |= PRE_INDEX;
a737bd4d 4203
c19d1205 4204 if (inst.operands[i].writeback)
09d92015 4205 {
c19d1205
ZW
4206 if (inst.operands[i].reg == REG_PC)
4207 {
4208 inst.error = _("pc may not be used with write-back");
4209 return FAIL;
4210 }
4211 if (!wb_ok)
4212 {
4213 inst.error = _("instruction does not support writeback");
4214 return FAIL;
4215 }
4216 inst.instruction |= WRITE_BACK;
09d92015 4217 }
a737bd4d 4218
c19d1205
ZW
4219 if (reloc_override)
4220 inst.reloc.type = reloc_override;
09d92015 4221 else
c19d1205 4222 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205
ZW
4223 return SUCCESS;
4224}
a737bd4d 4225
c19d1205
ZW
4226/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4227 Determine whether it can be performed with a move instruction; if
4228 it can, convert inst.instruction to that move instruction and
4229 return 1; if it can't, convert inst.instruction to a literal-pool
4230 load and return 0. If this is not a valid thing to do in the
4231 current context, set inst.error and return 1.
a737bd4d 4232
c19d1205
ZW
4233 inst.operands[i] describes the destination register. */
4234
4235static int
4236move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4237{
4238 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4239 {
c19d1205
ZW
4240 inst.error = _("invalid pseudo operation");
4241 return 1;
09d92015 4242 }
c19d1205 4243 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4244 {
4245 inst.error = _("constant expression expected");
c19d1205 4246 return 1;
09d92015 4247 }
c19d1205 4248 if (inst.reloc.exp.X_op == O_constant)
09d92015 4249 {
c19d1205
ZW
4250 if (thumb_p)
4251 {
4252 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4253 {
4254 /* This can be done with a mov(1) instruction. */
4255 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4256 inst.instruction |= inst.reloc.exp.X_add_number;
4257 return 1;
4258 }
4259 }
4260 else
4261 {
4262 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4263 if (value != FAIL)
4264 {
4265 /* This can be done with a mov instruction. */
4266 inst.instruction &= LITERAL_MASK;
4267 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4268 inst.instruction |= value & 0xfff;
4269 return 1;
4270 }
09d92015 4271
c19d1205
ZW
4272 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4273 if (value != FAIL)
4274 {
4275 /* This can be done with a mvn instruction. */
4276 inst.instruction &= LITERAL_MASK;
4277 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4278 inst.instruction |= value & 0xfff;
4279 return 1;
4280 }
4281 }
09d92015
MM
4282 }
4283
c19d1205
ZW
4284 if (add_to_lit_pool () == FAIL)
4285 {
4286 inst.error = _("literal pool insertion failed");
4287 return 1;
4288 }
4289 inst.operands[1].reg = REG_PC;
4290 inst.operands[1].isreg = 1;
4291 inst.operands[1].preind = 1;
4292 inst.reloc.pc_rel = 1;
4293 inst.reloc.type = (thumb_p
4294 ? BFD_RELOC_ARM_THUMB_OFFSET
4295 : (mode_3
4296 ? BFD_RELOC_ARM_HWLITERAL
4297 : BFD_RELOC_ARM_LITERAL));
4298 return 0;
09d92015
MM
4299}
4300
c19d1205
ZW
4301/* Functions for instruction encoding, sorted by subarchitecture.
4302 First some generics; their names are taken from the conventional
4303 bit positions for register arguments in ARM format instructions. */
09d92015 4304
a737bd4d 4305static void
c19d1205 4306do_noargs (void)
09d92015 4307{
c19d1205 4308}
a737bd4d 4309
c19d1205
ZW
4310static void
4311do_rd (void)
4312{
4313 inst.instruction |= inst.operands[0].reg << 12;
4314}
a737bd4d 4315
c19d1205
ZW
4316static void
4317do_rd_rm (void)
4318{
4319 inst.instruction |= inst.operands[0].reg << 12;
4320 inst.instruction |= inst.operands[1].reg;
4321}
09d92015 4322
c19d1205
ZW
4323static void
4324do_rd_rn (void)
4325{
4326 inst.instruction |= inst.operands[0].reg << 12;
4327 inst.instruction |= inst.operands[1].reg << 16;
4328}
a737bd4d 4329
c19d1205
ZW
4330static void
4331do_rn_rd (void)
4332{
4333 inst.instruction |= inst.operands[0].reg << 16;
4334 inst.instruction |= inst.operands[1].reg << 12;
4335}
09d92015 4336
c19d1205
ZW
4337static void
4338do_rd_rm_rn (void)
4339{
4340 inst.instruction |= inst.operands[0].reg << 12;
4341 inst.instruction |= inst.operands[1].reg;
4342 inst.instruction |= inst.operands[2].reg << 16;
4343}
09d92015 4344
c19d1205
ZW
4345static void
4346do_rd_rn_rm (void)
4347{
4348 inst.instruction |= inst.operands[0].reg << 12;
4349 inst.instruction |= inst.operands[1].reg << 16;
4350 inst.instruction |= inst.operands[2].reg;
4351}
a737bd4d 4352
c19d1205
ZW
4353static void
4354do_rm_rd_rn (void)
4355{
4356 inst.instruction |= inst.operands[0].reg;
4357 inst.instruction |= inst.operands[1].reg << 12;
4358 inst.instruction |= inst.operands[2].reg << 16;
4359}
09d92015 4360
c19d1205
ZW
4361static void
4362do_imm0 (void)
4363{
4364 inst.instruction |= inst.operands[0].imm;
4365}
09d92015 4366
c19d1205
ZW
4367static void
4368do_rd_cpaddr (void)
4369{
4370 inst.instruction |= inst.operands[0].reg << 12;
4371 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4372}
a737bd4d 4373
c19d1205
ZW
4374/* ARM instructions, in alphabetical order by function name (except
4375 that wrapper functions appear immediately after the function they
4376 wrap). */
09d92015 4377
c19d1205
ZW
4378/* This is a pseudo-op of the form "adr rd, label" to be converted
4379 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4380
4381static void
c19d1205 4382do_adr (void)
09d92015 4383{
c19d1205 4384 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4385
c19d1205
ZW
4386 /* Frag hacking will turn this into a sub instruction if the offset turns
4387 out to be negative. */
4388 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 4389 inst.reloc.pc_rel = 1;
2fc8bdac 4390 inst.reloc.exp.X_add_number -= 8;
c19d1205 4391}
b99bd4ef 4392
c19d1205
ZW
4393/* This is a pseudo-op of the form "adrl rd, label" to be converted
4394 into a relative address of the form:
4395 add rd, pc, #low(label-.-8)"
4396 add rd, rd, #high(label-.-8)" */
b99bd4ef 4397
c19d1205
ZW
4398static void
4399do_adrl (void)
4400{
4401 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4402
c19d1205
ZW
4403 /* Frag hacking will turn this into a sub instruction if the offset turns
4404 out to be negative. */
4405 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
4406 inst.reloc.pc_rel = 1;
4407 inst.size = INSN_SIZE * 2;
2fc8bdac 4408 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
4409}
4410
b99bd4ef 4411static void
c19d1205 4412do_arit (void)
b99bd4ef 4413{
c19d1205
ZW
4414 if (!inst.operands[1].present)
4415 inst.operands[1].reg = inst.operands[0].reg;
4416 inst.instruction |= inst.operands[0].reg << 12;
4417 inst.instruction |= inst.operands[1].reg << 16;
4418 encode_arm_shifter_operand (2);
4419}
b99bd4ef 4420
c19d1205
ZW
4421static void
4422do_bfc (void)
4423{
4424 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4425 constraint (msb > 32, _("bit-field extends past end of register"));
4426 /* The instruction encoding stores the LSB and MSB,
4427 not the LSB and width. */
4428 inst.instruction |= inst.operands[0].reg << 12;
4429 inst.instruction |= inst.operands[1].imm << 7;
4430 inst.instruction |= (msb - 1) << 16;
4431}
b99bd4ef 4432
c19d1205
ZW
4433static void
4434do_bfi (void)
4435{
4436 unsigned int msb;
b99bd4ef 4437
c19d1205
ZW
4438 /* #0 in second position is alternative syntax for bfc, which is
4439 the same instruction but with REG_PC in the Rm field. */
4440 if (!inst.operands[1].isreg)
4441 inst.operands[1].reg = REG_PC;
b99bd4ef 4442
c19d1205
ZW
4443 msb = inst.operands[2].imm + inst.operands[3].imm;
4444 constraint (msb > 32, _("bit-field extends past end of register"));
4445 /* The instruction encoding stores the LSB and MSB,
4446 not the LSB and width. */
4447 inst.instruction |= inst.operands[0].reg << 12;
4448 inst.instruction |= inst.operands[1].reg;
4449 inst.instruction |= inst.operands[2].imm << 7;
4450 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4451}
4452
b99bd4ef 4453static void
c19d1205 4454do_bfx (void)
b99bd4ef 4455{
c19d1205
ZW
4456 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4457 _("bit-field extends past end of register"));
4458 inst.instruction |= inst.operands[0].reg << 12;
4459 inst.instruction |= inst.operands[1].reg;
4460 inst.instruction |= inst.operands[2].imm << 7;
4461 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4462}
09d92015 4463
c19d1205
ZW
4464/* ARM V5 breakpoint instruction (argument parse)
4465 BKPT <16 bit unsigned immediate>
4466 Instruction is not conditional.
4467 The bit pattern given in insns[] has the COND_ALWAYS condition,
4468 and it is an error if the caller tried to override that. */
b99bd4ef 4469
c19d1205
ZW
4470static void
4471do_bkpt (void)
4472{
4473 /* Top 12 of 16 bits to bits 19:8. */
4474 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4475
c19d1205
ZW
4476 /* Bottom 4 of 16 bits to bits 3:0. */
4477 inst.instruction |= inst.operands[0].imm & 0xf;
4478}
09d92015 4479
c19d1205
ZW
4480static void
4481encode_branch (int default_reloc)
4482{
4483 if (inst.operands[0].hasreloc)
4484 {
4485 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4486 _("the only suffix valid here is '(plt)'"));
4487 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 4488 }
b99bd4ef 4489 else
c19d1205
ZW
4490 {
4491 inst.reloc.type = default_reloc;
c19d1205 4492 }
2fc8bdac 4493 inst.reloc.pc_rel = 1;
b99bd4ef
NC
4494}
4495
b99bd4ef 4496static void
c19d1205 4497do_branch (void)
b99bd4ef 4498{
c19d1205
ZW
4499 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4500}
b99bd4ef 4501
c19d1205
ZW
4502/* ARM V5 branch-link-exchange instruction (argument parse)
4503 BLX <target_addr> ie BLX(1)
4504 BLX{<condition>} <Rm> ie BLX(2)
4505 Unfortunately, there are two different opcodes for this mnemonic.
4506 So, the insns[].value is not used, and the code here zaps values
4507 into inst.instruction.
4508 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4509
c19d1205
ZW
4510static void
4511do_blx (void)
4512{
4513 if (inst.operands[0].isreg)
b99bd4ef 4514 {
c19d1205
ZW
4515 /* Arg is a register; the opcode provided by insns[] is correct.
4516 It is not illegal to do "blx pc", just useless. */
4517 if (inst.operands[0].reg == REG_PC)
4518 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4519
c19d1205
ZW
4520 inst.instruction |= inst.operands[0].reg;
4521 }
4522 else
b99bd4ef 4523 {
c19d1205
ZW
4524 /* Arg is an address; this instruction cannot be executed
4525 conditionally, and the opcode must be adjusted. */
4526 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 4527 inst.instruction = 0xfa000000;
c19d1205 4528 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4529 }
c19d1205
ZW
4530}
4531
4532static void
4533do_bx (void)
4534{
4535 if (inst.operands[0].reg == REG_PC)
4536 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4537
c19d1205 4538 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4539}
4540
c19d1205
ZW
4541
4542/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4543
4544static void
c19d1205 4545do_bxj (void)
a737bd4d 4546{
c19d1205
ZW
4547 if (inst.operands[0].reg == REG_PC)
4548 as_tsktsk (_("use of r15 in bxj is not really useful"));
4549
4550 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4551}
4552
c19d1205
ZW
4553/* Co-processor data operation:
4554 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4555 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4556static void
4557do_cdp (void)
4558{
4559 inst.instruction |= inst.operands[0].reg << 8;
4560 inst.instruction |= inst.operands[1].imm << 20;
4561 inst.instruction |= inst.operands[2].reg << 12;
4562 inst.instruction |= inst.operands[3].reg << 16;
4563 inst.instruction |= inst.operands[4].reg;
4564 inst.instruction |= inst.operands[5].imm << 5;
4565}
a737bd4d
NC
4566
4567static void
c19d1205 4568do_cmp (void)
a737bd4d 4569{
c19d1205
ZW
4570 inst.instruction |= inst.operands[0].reg << 16;
4571 encode_arm_shifter_operand (1);
a737bd4d
NC
4572}
4573
c19d1205
ZW
4574/* Transfer between coprocessor and ARM registers.
4575 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4576 MRC2
4577 MCR{cond}
4578 MCR2
4579
4580 No special properties. */
09d92015
MM
4581
4582static void
c19d1205 4583do_co_reg (void)
09d92015 4584{
c19d1205
ZW
4585 inst.instruction |= inst.operands[0].reg << 8;
4586 inst.instruction |= inst.operands[1].imm << 21;
4587 inst.instruction |= inst.operands[2].reg << 12;
4588 inst.instruction |= inst.operands[3].reg << 16;
4589 inst.instruction |= inst.operands[4].reg;
4590 inst.instruction |= inst.operands[5].imm << 5;
4591}
09d92015 4592
c19d1205
ZW
4593/* Transfer between coprocessor register and pair of ARM registers.
4594 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4595 MCRR2
4596 MRRC{cond}
4597 MRRC2
b99bd4ef 4598
c19d1205 4599 Two XScale instructions are special cases of these:
09d92015 4600
c19d1205
ZW
4601 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4602 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4603
c19d1205 4604 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4605
c19d1205
ZW
4606static void
4607do_co_reg2c (void)
4608{
4609 inst.instruction |= inst.operands[0].reg << 8;
4610 inst.instruction |= inst.operands[1].imm << 4;
4611 inst.instruction |= inst.operands[2].reg << 12;
4612 inst.instruction |= inst.operands[3].reg << 16;
4613 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4614}
4615
c19d1205
ZW
4616static void
4617do_cpsi (void)
4618{
4619 inst.instruction |= inst.operands[0].imm << 6;
4620 inst.instruction |= inst.operands[1].imm;
4621}
b99bd4ef
NC
4622
4623static void
c19d1205 4624do_it (void)
b99bd4ef 4625{
c19d1205
ZW
4626 /* There is no IT instruction in ARM mode. We
4627 process it but do not generate code for it. */
4628 inst.size = 0;
09d92015 4629}
b99bd4ef 4630
09d92015 4631static void
c19d1205 4632do_ldmstm (void)
ea6ef066 4633{
c19d1205
ZW
4634 int base_reg = inst.operands[0].reg;
4635 int range = inst.operands[1].imm;
ea6ef066 4636
c19d1205
ZW
4637 inst.instruction |= base_reg << 16;
4638 inst.instruction |= range;
ea6ef066 4639
c19d1205
ZW
4640 if (inst.operands[1].writeback)
4641 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4642
c19d1205 4643 if (inst.operands[0].writeback)
ea6ef066 4644 {
c19d1205
ZW
4645 inst.instruction |= WRITE_BACK;
4646 /* Check for unpredictable uses of writeback. */
4647 if (inst.instruction & LOAD_BIT)
09d92015 4648 {
c19d1205
ZW
4649 /* Not allowed in LDM type 2. */
4650 if ((inst.instruction & LDM_TYPE_2_OR_3)
4651 && ((range & (1 << REG_PC)) == 0))
4652 as_warn (_("writeback of base register is UNPREDICTABLE"));
4653 /* Only allowed if base reg not in list for other types. */
4654 else if (range & (1 << base_reg))
4655 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4656 }
4657 else /* STM. */
4658 {
4659 /* Not allowed for type 2. */
4660 if (inst.instruction & LDM_TYPE_2_OR_3)
4661 as_warn (_("writeback of base register is UNPREDICTABLE"));
4662 /* Only allowed if base reg not in list, or first in list. */
4663 else if ((range & (1 << base_reg))
4664 && (range & ((1 << base_reg) - 1)))
4665 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4666 }
ea6ef066 4667 }
a737bd4d
NC
4668}
4669
c19d1205
ZW
4670/* ARMv5TE load-consecutive (argument parse)
4671 Mode is like LDRH.
4672
4673 LDRccD R, mode
4674 STRccD R, mode. */
4675
a737bd4d 4676static void
c19d1205 4677do_ldrd (void)
a737bd4d 4678{
c19d1205
ZW
4679 constraint (inst.operands[0].reg % 2 != 0,
4680 _("first destination register must be even"));
4681 constraint (inst.operands[1].present
4682 && inst.operands[1].reg != inst.operands[0].reg + 1,
4683 _("can only load two consecutive registers"));
4684 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4685 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4686
c19d1205
ZW
4687 if (!inst.operands[1].present)
4688 inst.operands[1].reg = inst.operands[0].reg + 1;
4689
4690 if (inst.instruction & LOAD_BIT)
a737bd4d 4691 {
c19d1205
ZW
4692 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4693 register and the first register written; we have to diagnose
4694 overlap between the base and the second register written here. */
ea6ef066 4695
c19d1205
ZW
4696 if (inst.operands[2].reg == inst.operands[1].reg
4697 && (inst.operands[2].writeback || inst.operands[2].postind))
4698 as_warn (_("base register written back, and overlaps "
4699 "second destination register"));
b05fe5cf 4700
c19d1205
ZW
4701 /* For an index-register load, the index register must not overlap the
4702 destination (even if not write-back). */
4703 else if (inst.operands[2].immisreg
ca3f61f7
NC
4704 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4705 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 4706 as_warn (_("index register overlaps destination register"));
b05fe5cf 4707 }
c19d1205
ZW
4708
4709 inst.instruction |= inst.operands[0].reg << 12;
4710 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4711}
4712
4713static void
c19d1205 4714do_ldrex (void)
b05fe5cf 4715{
c19d1205
ZW
4716 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4717 || inst.operands[1].postind || inst.operands[1].writeback
4718 || inst.operands[1].immisreg || inst.operands[1].shifted
4719 || inst.operands[1].negative,
4720 _("instruction does not accept this addressing mode"));
b05fe5cf 4721
c19d1205 4722 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
b05fe5cf 4723
c19d1205
ZW
4724 constraint (inst.reloc.exp.X_op != O_constant
4725 || inst.reloc.exp.X_add_number != 0,
4726 _("offset must be zero in ARM encoding"));
b05fe5cf 4727
c19d1205
ZW
4728 inst.instruction |= inst.operands[0].reg << 12;
4729 inst.instruction |= inst.operands[1].reg << 16;
4730 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4731}
4732
4733static void
c19d1205 4734do_ldrexd (void)
b05fe5cf 4735{
c19d1205
ZW
4736 constraint (inst.operands[0].reg % 2 != 0,
4737 _("even register required"));
4738 constraint (inst.operands[1].present
4739 && inst.operands[1].reg != inst.operands[0].reg + 1,
4740 _("can only load two consecutive registers"));
4741 /* If op 1 were present and equal to PC, this function wouldn't
4742 have been called in the first place. */
4743 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 4744
c19d1205
ZW
4745 inst.instruction |= inst.operands[0].reg << 12;
4746 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
4747}
4748
4749static void
c19d1205 4750do_ldst (void)
b05fe5cf 4751{
c19d1205
ZW
4752 inst.instruction |= inst.operands[0].reg << 12;
4753 if (!inst.operands[1].isreg)
4754 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 4755 return;
c19d1205 4756 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4757}
4758
4759static void
c19d1205 4760do_ldstt (void)
b05fe5cf 4761{
c19d1205
ZW
4762 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4763 reject [Rn,...]. */
4764 if (inst.operands[1].preind)
b05fe5cf 4765 {
c19d1205
ZW
4766 constraint (inst.reloc.exp.X_op != O_constant ||
4767 inst.reloc.exp.X_add_number != 0,
4768 _("this instruction requires a post-indexed address"));
b05fe5cf 4769
c19d1205
ZW
4770 inst.operands[1].preind = 0;
4771 inst.operands[1].postind = 1;
4772 inst.operands[1].writeback = 1;
b05fe5cf 4773 }
c19d1205
ZW
4774 inst.instruction |= inst.operands[0].reg << 12;
4775 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4776}
b05fe5cf 4777
c19d1205 4778/* Halfword and signed-byte load/store operations. */
b05fe5cf 4779
c19d1205
ZW
4780static void
4781do_ldstv4 (void)
4782{
4783 inst.instruction |= inst.operands[0].reg << 12;
4784 if (!inst.operands[1].isreg)
4785 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 4786 return;
c19d1205 4787 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4788}
4789
4790static void
c19d1205 4791do_ldsttv4 (void)
b05fe5cf 4792{
c19d1205
ZW
4793 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4794 reject [Rn,...]. */
4795 if (inst.operands[1].preind)
b05fe5cf 4796 {
c19d1205
ZW
4797 constraint (inst.reloc.exp.X_op != O_constant ||
4798 inst.reloc.exp.X_add_number != 0,
4799 _("this instruction requires a post-indexed address"));
b05fe5cf 4800
c19d1205
ZW
4801 inst.operands[1].preind = 0;
4802 inst.operands[1].postind = 1;
4803 inst.operands[1].writeback = 1;
b05fe5cf 4804 }
c19d1205
ZW
4805 inst.instruction |= inst.operands[0].reg << 12;
4806 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4807}
b05fe5cf 4808
c19d1205
ZW
4809/* Co-processor register load/store.
4810 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4811static void
4812do_lstc (void)
4813{
4814 inst.instruction |= inst.operands[0].reg << 8;
4815 inst.instruction |= inst.operands[1].reg << 12;
4816 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
4817}
4818
b05fe5cf 4819static void
c19d1205 4820do_mlas (void)
b05fe5cf 4821{
c19d1205
ZW
4822 /* This restriction does not apply to mls (nor to mla in v6, but
4823 that's hard to detect at present). */
4824 if (inst.operands[0].reg == inst.operands[1].reg
4825 && !(inst.instruction & 0x00400000))
4826 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 4827
c19d1205
ZW
4828 inst.instruction |= inst.operands[0].reg << 16;
4829 inst.instruction |= inst.operands[1].reg;
4830 inst.instruction |= inst.operands[2].reg << 8;
4831 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 4832
c19d1205 4833}
b05fe5cf 4834
c19d1205
ZW
4835static void
4836do_mov (void)
4837{
4838 inst.instruction |= inst.operands[0].reg << 12;
4839 encode_arm_shifter_operand (1);
4840}
b05fe5cf 4841
c19d1205
ZW
4842/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4843static void
4844do_mov16 (void)
4845{
4846 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 4847 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
4848 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4849 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 4850}
b99bd4ef
NC
4851
4852static void
c19d1205 4853do_mrs (void)
b99bd4ef 4854{
c19d1205
ZW
4855 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4856 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4857 != (PSR_c|PSR_f),
4858 _("'CPSR' or 'SPSR' expected"));
4859 inst.instruction |= inst.operands[0].reg << 12;
4860 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4861}
b99bd4ef 4862
c19d1205
ZW
4863/* Two possible forms:
4864 "{C|S}PSR_<field>, Rm",
4865 "{C|S}PSR_f, #expression". */
b99bd4ef 4866
c19d1205
ZW
4867static void
4868do_msr (void)
4869{
4870 inst.instruction |= inst.operands[0].imm;
4871 if (inst.operands[1].isreg)
4872 inst.instruction |= inst.operands[1].reg;
4873 else
b99bd4ef 4874 {
c19d1205
ZW
4875 inst.instruction |= INST_IMMEDIATE;
4876 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4877 inst.reloc.pc_rel = 0;
b99bd4ef 4878 }
b99bd4ef
NC
4879}
4880
c19d1205
ZW
4881static void
4882do_mul (void)
a737bd4d 4883{
c19d1205
ZW
4884 if (!inst.operands[2].present)
4885 inst.operands[2].reg = inst.operands[0].reg;
4886 inst.instruction |= inst.operands[0].reg << 16;
4887 inst.instruction |= inst.operands[1].reg;
4888 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 4889
c19d1205
ZW
4890 if (inst.operands[0].reg == inst.operands[1].reg)
4891 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
4892}
4893
c19d1205
ZW
4894/* Long Multiply Parser
4895 UMULL RdLo, RdHi, Rm, Rs
4896 SMULL RdLo, RdHi, Rm, Rs
4897 UMLAL RdLo, RdHi, Rm, Rs
4898 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
4899
4900static void
c19d1205 4901do_mull (void)
b99bd4ef 4902{
c19d1205
ZW
4903 inst.instruction |= inst.operands[0].reg << 12;
4904 inst.instruction |= inst.operands[1].reg << 16;
4905 inst.instruction |= inst.operands[2].reg;
4906 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 4907
c19d1205
ZW
4908 /* rdhi, rdlo and rm must all be different. */
4909 if (inst.operands[0].reg == inst.operands[1].reg
4910 || inst.operands[0].reg == inst.operands[2].reg
4911 || inst.operands[1].reg == inst.operands[2].reg)
4912 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
4913}
b99bd4ef 4914
c19d1205
ZW
4915static void
4916do_nop (void)
4917{
4918 if (inst.operands[0].present)
4919 {
4920 /* Architectural NOP hints are CPSR sets with no bits selected. */
4921 inst.instruction &= 0xf0000000;
4922 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
4923 }
b99bd4ef
NC
4924}
4925
c19d1205
ZW
4926/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
4927 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
4928 Condition defaults to COND_ALWAYS.
4929 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
4930
4931static void
c19d1205 4932do_pkhbt (void)
b99bd4ef 4933{
c19d1205
ZW
4934 inst.instruction |= inst.operands[0].reg << 12;
4935 inst.instruction |= inst.operands[1].reg << 16;
4936 inst.instruction |= inst.operands[2].reg;
4937 if (inst.operands[3].present)
4938 encode_arm_shift (3);
4939}
b99bd4ef 4940
c19d1205 4941/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 4942
c19d1205
ZW
4943static void
4944do_pkhtb (void)
4945{
4946 if (!inst.operands[3].present)
b99bd4ef 4947 {
c19d1205
ZW
4948 /* If the shift specifier is omitted, turn the instruction
4949 into pkhbt rd, rm, rn. */
4950 inst.instruction &= 0xfff00010;
4951 inst.instruction |= inst.operands[0].reg << 12;
4952 inst.instruction |= inst.operands[1].reg;
4953 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
4954 }
4955 else
4956 {
c19d1205
ZW
4957 inst.instruction |= inst.operands[0].reg << 12;
4958 inst.instruction |= inst.operands[1].reg << 16;
4959 inst.instruction |= inst.operands[2].reg;
4960 encode_arm_shift (3);
b99bd4ef
NC
4961 }
4962}
4963
c19d1205
ZW
4964/* ARMv5TE: Preload-Cache
4965
4966 PLD <addr_mode>
4967
4968 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
4969
4970static void
c19d1205 4971do_pld (void)
b99bd4ef 4972{
c19d1205
ZW
4973 constraint (!inst.operands[0].isreg,
4974 _("'[' expected after PLD mnemonic"));
4975 constraint (inst.operands[0].postind,
4976 _("post-indexed expression used in preload instruction"));
4977 constraint (inst.operands[0].writeback,
4978 _("writeback used in preload instruction"));
4979 constraint (!inst.operands[0].preind,
4980 _("unindexed addressing used in preload instruction"));
4981 inst.instruction |= inst.operands[0].reg;
4982 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
4983}
b99bd4ef 4984
c19d1205
ZW
4985static void
4986do_push_pop (void)
4987{
4988 inst.operands[1] = inst.operands[0];
4989 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
4990 inst.operands[0].isreg = 1;
4991 inst.operands[0].writeback = 1;
4992 inst.operands[0].reg = REG_SP;
4993 do_ldmstm ();
4994}
b99bd4ef 4995
c19d1205
ZW
4996/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
4997 word at the specified address and the following word
4998 respectively.
4999 Unconditionally executed.
5000 Error if Rn is R15. */
b99bd4ef 5001
c19d1205
ZW
5002static void
5003do_rfe (void)
5004{
5005 inst.instruction |= inst.operands[0].reg << 16;
5006 if (inst.operands[0].writeback)
5007 inst.instruction |= WRITE_BACK;
5008}
b99bd4ef 5009
c19d1205 5010/* ARM V6 ssat (argument parse). */
b99bd4ef 5011
c19d1205
ZW
5012static void
5013do_ssat (void)
5014{
5015 inst.instruction |= inst.operands[0].reg << 12;
5016 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5017 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5018
c19d1205
ZW
5019 if (inst.operands[3].present)
5020 encode_arm_shift (3);
b99bd4ef
NC
5021}
5022
c19d1205 5023/* ARM V6 usat (argument parse). */
b99bd4ef
NC
5024
5025static void
c19d1205 5026do_usat (void)
b99bd4ef 5027{
c19d1205
ZW
5028 inst.instruction |= inst.operands[0].reg << 12;
5029 inst.instruction |= inst.operands[1].imm << 16;
5030 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5031
c19d1205
ZW
5032 if (inst.operands[3].present)
5033 encode_arm_shift (3);
b99bd4ef
NC
5034}
5035
c19d1205 5036/* ARM V6 ssat16 (argument parse). */
09d92015
MM
5037
5038static void
c19d1205 5039do_ssat16 (void)
09d92015 5040{
c19d1205
ZW
5041 inst.instruction |= inst.operands[0].reg << 12;
5042 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5043 inst.instruction |= inst.operands[2].reg;
09d92015
MM
5044}
5045
c19d1205
ZW
5046static void
5047do_usat16 (void)
a737bd4d 5048{
c19d1205
ZW
5049 inst.instruction |= inst.operands[0].reg << 12;
5050 inst.instruction |= inst.operands[1].imm << 16;
5051 inst.instruction |= inst.operands[2].reg;
5052}
a737bd4d 5053
c19d1205
ZW
5054/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5055 preserving the other bits.
a737bd4d 5056
c19d1205
ZW
5057 setend <endian_specifier>, where <endian_specifier> is either
5058 BE or LE. */
a737bd4d 5059
c19d1205
ZW
5060static void
5061do_setend (void)
5062{
5063 if (inst.operands[0].imm)
5064 inst.instruction |= 0x200;
a737bd4d
NC
5065}
5066
5067static void
c19d1205 5068do_shift (void)
a737bd4d 5069{
c19d1205
ZW
5070 unsigned int Rm = (inst.operands[1].present
5071 ? inst.operands[1].reg
5072 : inst.operands[0].reg);
a737bd4d 5073
c19d1205
ZW
5074 inst.instruction |= inst.operands[0].reg << 12;
5075 inst.instruction |= Rm;
5076 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5077 {
c19d1205
ZW
5078 constraint (inst.operands[0].reg != Rm,
5079 _("source1 and dest must be same register"));
5080 inst.instruction |= inst.operands[2].reg << 8;
5081 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5082 }
5083 else
c19d1205 5084 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5085}
5086
09d92015 5087static void
c19d1205 5088do_smi (void)
09d92015 5089{
c19d1205
ZW
5090 inst.reloc.type = BFD_RELOC_ARM_SMI;
5091 inst.reloc.pc_rel = 0;
09d92015
MM
5092}
5093
09d92015 5094static void
c19d1205 5095do_swi (void)
09d92015 5096{
c19d1205
ZW
5097 inst.reloc.type = BFD_RELOC_ARM_SWI;
5098 inst.reloc.pc_rel = 0;
09d92015
MM
5099}
5100
c19d1205
ZW
5101/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5102 SMLAxy{cond} Rd,Rm,Rs,Rn
5103 SMLAWy{cond} Rd,Rm,Rs,Rn
5104 Error if any register is R15. */
e16bb312 5105
c19d1205
ZW
5106static void
5107do_smla (void)
e16bb312 5108{
c19d1205
ZW
5109 inst.instruction |= inst.operands[0].reg << 16;
5110 inst.instruction |= inst.operands[1].reg;
5111 inst.instruction |= inst.operands[2].reg << 8;
5112 inst.instruction |= inst.operands[3].reg << 12;
5113}
a737bd4d 5114
c19d1205
ZW
5115/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5116 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5117 Error if any register is R15.
5118 Warning if Rdlo == Rdhi. */
a737bd4d 5119
c19d1205
ZW
5120static void
5121do_smlal (void)
5122{
5123 inst.instruction |= inst.operands[0].reg << 12;
5124 inst.instruction |= inst.operands[1].reg << 16;
5125 inst.instruction |= inst.operands[2].reg;
5126 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5127
c19d1205
ZW
5128 if (inst.operands[0].reg == inst.operands[1].reg)
5129 as_tsktsk (_("rdhi and rdlo must be different"));
5130}
a737bd4d 5131
c19d1205
ZW
5132/* ARM V5E (El Segundo) signed-multiply (argument parse)
5133 SMULxy{cond} Rd,Rm,Rs
5134 Error if any register is R15. */
a737bd4d 5135
c19d1205
ZW
5136static void
5137do_smul (void)
5138{
5139 inst.instruction |= inst.operands[0].reg << 16;
5140 inst.instruction |= inst.operands[1].reg;
5141 inst.instruction |= inst.operands[2].reg << 8;
5142}
a737bd4d 5143
c19d1205 5144/* ARM V6 srs (argument parse). */
a737bd4d 5145
c19d1205
ZW
5146static void
5147do_srs (void)
5148{
5149 inst.instruction |= inst.operands[0].imm;
5150 if (inst.operands[0].writeback)
5151 inst.instruction |= WRITE_BACK;
5152}
a737bd4d 5153
c19d1205 5154/* ARM V6 strex (argument parse). */
a737bd4d 5155
c19d1205
ZW
5156static void
5157do_strex (void)
5158{
5159 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5160 || inst.operands[2].postind || inst.operands[2].writeback
5161 || inst.operands[2].immisreg || inst.operands[2].shifted
5162 || inst.operands[2].negative,
5163 _("instruction does not accept this addressing mode"));
e16bb312 5164
c19d1205 5165 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
a737bd4d 5166
c19d1205
ZW
5167 constraint (inst.operands[0].reg == inst.operands[1].reg
5168 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5169
c19d1205
ZW
5170 constraint (inst.reloc.exp.X_op != O_constant
5171 || inst.reloc.exp.X_add_number != 0,
5172 _("offset must be zero in ARM encoding"));
a737bd4d 5173
c19d1205
ZW
5174 inst.instruction |= inst.operands[0].reg << 12;
5175 inst.instruction |= inst.operands[1].reg;
5176 inst.instruction |= inst.operands[2].reg << 16;
5177 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5178}
5179
5180static void
c19d1205 5181do_strexd (void)
e16bb312 5182{
c19d1205
ZW
5183 constraint (inst.operands[1].reg % 2 != 0,
5184 _("even register required"));
5185 constraint (inst.operands[2].present
5186 && inst.operands[2].reg != inst.operands[1].reg + 1,
5187 _("can only store two consecutive registers"));
5188 /* If op 2 were present and equal to PC, this function wouldn't
5189 have been called in the first place. */
5190 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5191
c19d1205
ZW
5192 constraint (inst.operands[0].reg == inst.operands[1].reg
5193 || inst.operands[0].reg == inst.operands[1].reg + 1
5194 || inst.operands[0].reg == inst.operands[3].reg,
5195 BAD_OVERLAP);
e16bb312 5196
c19d1205
ZW
5197 inst.instruction |= inst.operands[0].reg << 12;
5198 inst.instruction |= inst.operands[1].reg;
5199 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5200}
5201
c19d1205
ZW
5202/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5203 extends it to 32-bits, and adds the result to a value in another
5204 register. You can specify a rotation by 0, 8, 16, or 24 bits
5205 before extracting the 16-bit value.
5206 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5207 Condition defaults to COND_ALWAYS.
5208 Error if any register uses R15. */
5209
e16bb312 5210static void
c19d1205 5211do_sxtah (void)
e16bb312 5212{
c19d1205
ZW
5213 inst.instruction |= inst.operands[0].reg << 12;
5214 inst.instruction |= inst.operands[1].reg << 16;
5215 inst.instruction |= inst.operands[2].reg;
5216 inst.instruction |= inst.operands[3].imm << 10;
5217}
e16bb312 5218
c19d1205 5219/* ARM V6 SXTH.
e16bb312 5220
c19d1205
ZW
5221 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5222 Condition defaults to COND_ALWAYS.
5223 Error if any register uses R15. */
e16bb312
NC
5224
5225static void
c19d1205 5226do_sxth (void)
e16bb312 5227{
c19d1205
ZW
5228 inst.instruction |= inst.operands[0].reg << 12;
5229 inst.instruction |= inst.operands[1].reg;
5230 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5231}
c19d1205
ZW
5232\f
5233/* VFP instructions. In a logical order: SP variant first, monad
5234 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5235
5236static void
c19d1205 5237do_vfp_sp_monadic (void)
e16bb312 5238{
c19d1205
ZW
5239 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5240 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5241}
5242
5243static void
c19d1205 5244do_vfp_sp_dyadic (void)
e16bb312 5245{
c19d1205
ZW
5246 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5247 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5248 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5249}
5250
5251static void
c19d1205 5252do_vfp_sp_compare_z (void)
e16bb312 5253{
c19d1205 5254 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5255}
5256
5257static void
c19d1205 5258do_vfp_dp_sp_cvt (void)
e16bb312 5259{
c19d1205
ZW
5260 inst.instruction |= inst.operands[0].reg << 12;
5261 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5262}
5263
5264static void
c19d1205 5265do_vfp_sp_dp_cvt (void)
e16bb312 5266{
c19d1205
ZW
5267 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5268 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5269}
5270
5271static void
c19d1205 5272do_vfp_reg_from_sp (void)
e16bb312 5273{
c19d1205
ZW
5274 inst.instruction |= inst.operands[0].reg << 12;
5275 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5276}
5277
5278static void
c19d1205 5279do_vfp_reg2_from_sp2 (void)
e16bb312 5280{
c19d1205
ZW
5281 constraint (inst.operands[2].imm != 2,
5282 _("only two consecutive VFP SP registers allowed here"));
5283 inst.instruction |= inst.operands[0].reg << 12;
5284 inst.instruction |= inst.operands[1].reg << 16;
5285 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5286}
5287
5288static void
c19d1205 5289do_vfp_sp_from_reg (void)
e16bb312 5290{
c19d1205
ZW
5291 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5292 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5293}
5294
5295static void
c19d1205 5296do_vfp_sp2_from_reg2 (void)
e16bb312 5297{
c19d1205
ZW
5298 constraint (inst.operands[0].imm != 2,
5299 _("only two consecutive VFP SP registers allowed here"));
5300 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5301 inst.instruction |= inst.operands[1].reg << 12;
5302 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5303}
5304
5305static void
c19d1205 5306do_vfp_sp_ldst (void)
e16bb312 5307{
c19d1205
ZW
5308 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5309 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5310}
5311
5312static void
c19d1205 5313do_vfp_dp_ldst (void)
e16bb312 5314{
c19d1205
ZW
5315 inst.instruction |= inst.operands[0].reg << 12;
5316 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5317}
5318
c19d1205 5319
e16bb312 5320static void
c19d1205 5321vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5322{
c19d1205
ZW
5323 if (inst.operands[0].writeback)
5324 inst.instruction |= WRITE_BACK;
5325 else
5326 constraint (ldstm_type != VFP_LDSTMIA,
5327 _("this addressing mode requires base-register writeback"));
5328 inst.instruction |= inst.operands[0].reg << 16;
5329 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5330 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5331}
5332
5333static void
c19d1205 5334vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5335{
c19d1205 5336 int count;
e16bb312 5337
c19d1205
ZW
5338 if (inst.operands[0].writeback)
5339 inst.instruction |= WRITE_BACK;
5340 else
5341 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5342 _("this addressing mode requires base-register writeback"));
e16bb312 5343
c19d1205
ZW
5344 inst.instruction |= inst.operands[0].reg << 16;
5345 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5346
c19d1205
ZW
5347 count = inst.operands[1].imm << 1;
5348 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5349 count += 1;
e16bb312 5350
c19d1205 5351 inst.instruction |= count;
e16bb312
NC
5352}
5353
5354static void
c19d1205 5355do_vfp_sp_ldstmia (void)
e16bb312 5356{
c19d1205 5357 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5358}
5359
5360static void
c19d1205 5361do_vfp_sp_ldstmdb (void)
e16bb312 5362{
c19d1205 5363 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5364}
5365
5366static void
c19d1205 5367do_vfp_dp_ldstmia (void)
e16bb312 5368{
c19d1205 5369 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5370}
5371
5372static void
c19d1205 5373do_vfp_dp_ldstmdb (void)
e16bb312 5374{
c19d1205 5375 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5376}
5377
5378static void
c19d1205 5379do_vfp_xp_ldstmia (void)
e16bb312 5380{
c19d1205
ZW
5381 vfp_dp_ldstm (VFP_LDSTMIAX);
5382}
e16bb312 5383
c19d1205
ZW
5384static void
5385do_vfp_xp_ldstmdb (void)
5386{
5387 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5388}
c19d1205
ZW
5389\f
5390/* FPA instructions. Also in a logical order. */
e16bb312 5391
c19d1205
ZW
5392static void
5393do_fpa_cmp (void)
5394{
5395 inst.instruction |= inst.operands[0].reg << 16;
5396 inst.instruction |= inst.operands[1].reg;
5397}
b99bd4ef
NC
5398
5399static void
c19d1205 5400do_fpa_ldmstm (void)
b99bd4ef 5401{
c19d1205
ZW
5402 inst.instruction |= inst.operands[0].reg << 12;
5403 switch (inst.operands[1].imm)
5404 {
5405 case 1: inst.instruction |= CP_T_X; break;
5406 case 2: inst.instruction |= CP_T_Y; break;
5407 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5408 case 4: break;
5409 default: abort ();
5410 }
b99bd4ef 5411
c19d1205
ZW
5412 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5413 {
5414 /* The instruction specified "ea" or "fd", so we can only accept
5415 [Rn]{!}. The instruction does not really support stacking or
5416 unstacking, so we have to emulate these by setting appropriate
5417 bits and offsets. */
5418 constraint (inst.reloc.exp.X_op != O_constant
5419 || inst.reloc.exp.X_add_number != 0,
5420 _("this instruction does not support indexing"));
b99bd4ef 5421
c19d1205
ZW
5422 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5423 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5424
c19d1205
ZW
5425 if (!(inst.instruction & INDEX_UP))
5426 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5427
c19d1205
ZW
5428 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5429 {
5430 inst.operands[2].preind = 0;
5431 inst.operands[2].postind = 1;
5432 }
5433 }
b99bd4ef 5434
c19d1205 5435 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5436}
c19d1205
ZW
5437\f
5438/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5439
c19d1205
ZW
5440static void
5441do_iwmmxt_tandorc (void)
5442{
5443 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5444}
b99bd4ef 5445
c19d1205
ZW
5446static void
5447do_iwmmxt_textrc (void)
5448{
5449 inst.instruction |= inst.operands[0].reg << 12;
5450 inst.instruction |= inst.operands[1].imm;
5451}
b99bd4ef
NC
5452
5453static void
c19d1205 5454do_iwmmxt_textrm (void)
b99bd4ef 5455{
c19d1205
ZW
5456 inst.instruction |= inst.operands[0].reg << 12;
5457 inst.instruction |= inst.operands[1].reg << 16;
5458 inst.instruction |= inst.operands[2].imm;
5459}
b99bd4ef 5460
c19d1205
ZW
5461static void
5462do_iwmmxt_tinsr (void)
5463{
5464 inst.instruction |= inst.operands[0].reg << 16;
5465 inst.instruction |= inst.operands[1].reg << 12;
5466 inst.instruction |= inst.operands[2].imm;
5467}
b99bd4ef 5468
c19d1205
ZW
5469static void
5470do_iwmmxt_tmia (void)
5471{
5472 inst.instruction |= inst.operands[0].reg << 5;
5473 inst.instruction |= inst.operands[1].reg;
5474 inst.instruction |= inst.operands[2].reg << 12;
5475}
b99bd4ef 5476
c19d1205
ZW
5477static void
5478do_iwmmxt_waligni (void)
5479{
5480 inst.instruction |= inst.operands[0].reg << 12;
5481 inst.instruction |= inst.operands[1].reg << 16;
5482 inst.instruction |= inst.operands[2].reg;
5483 inst.instruction |= inst.operands[3].imm << 20;
5484}
b99bd4ef 5485
c19d1205
ZW
5486static void
5487do_iwmmxt_wmov (void)
5488{
5489 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5490 inst.instruction |= inst.operands[0].reg << 12;
5491 inst.instruction |= inst.operands[1].reg << 16;
5492 inst.instruction |= inst.operands[1].reg;
5493}
b99bd4ef 5494
c19d1205
ZW
5495static void
5496do_iwmmxt_wldstbh (void)
5497{
5498 inst.instruction |= inst.operands[0].reg << 12;
5499 inst.reloc.exp.X_add_number *= 4;
5500 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
b99bd4ef
NC
5501}
5502
c19d1205
ZW
5503static void
5504do_iwmmxt_wldstw (void)
5505{
5506 /* RIWR_RIWC clears .isreg for a control register. */
5507 if (!inst.operands[0].isreg)
5508 {
5509 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5510 inst.instruction |= 0xf0000000;
5511 }
b99bd4ef 5512
c19d1205
ZW
5513 inst.instruction |= inst.operands[0].reg << 12;
5514 encode_arm_cp_address (1, TRUE, TRUE, 0);
5515}
b99bd4ef
NC
5516
5517static void
c19d1205 5518do_iwmmxt_wldstd (void)
b99bd4ef 5519{
c19d1205 5520 inst.instruction |= inst.operands[0].reg << 12;
f2184508 5521 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 5522}
b99bd4ef 5523
c19d1205
ZW
5524static void
5525do_iwmmxt_wshufh (void)
5526{
5527 inst.instruction |= inst.operands[0].reg << 12;
5528 inst.instruction |= inst.operands[1].reg << 16;
5529 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5530 inst.instruction |= (inst.operands[2].imm & 0x0f);
5531}
b99bd4ef 5532
c19d1205
ZW
5533static void
5534do_iwmmxt_wzero (void)
5535{
5536 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5537 inst.instruction |= inst.operands[0].reg;
5538 inst.instruction |= inst.operands[0].reg << 12;
5539 inst.instruction |= inst.operands[0].reg << 16;
5540}
5541\f
5542/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5543 operations first, then control, shift, and load/store. */
b99bd4ef 5544
c19d1205 5545/* Insns like "foo X,Y,Z". */
b99bd4ef 5546
c19d1205
ZW
5547static void
5548do_mav_triple (void)
5549{
5550 inst.instruction |= inst.operands[0].reg << 16;
5551 inst.instruction |= inst.operands[1].reg;
5552 inst.instruction |= inst.operands[2].reg << 12;
5553}
b99bd4ef 5554
c19d1205
ZW
5555/* Insns like "foo W,X,Y,Z".
5556 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5557
c19d1205
ZW
5558static void
5559do_mav_quad (void)
5560{
5561 inst.instruction |= inst.operands[0].reg << 5;
5562 inst.instruction |= inst.operands[1].reg << 12;
5563 inst.instruction |= inst.operands[2].reg << 16;
5564 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5565}
5566
c19d1205
ZW
5567/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5568static void
5569do_mav_dspsc (void)
a737bd4d 5570{
c19d1205
ZW
5571 inst.instruction |= inst.operands[1].reg << 12;
5572}
a737bd4d 5573
c19d1205
ZW
5574/* Maverick shift immediate instructions.
5575 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5576 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5577
c19d1205
ZW
5578static void
5579do_mav_shift (void)
5580{
5581 int imm = inst.operands[2].imm;
a737bd4d 5582
c19d1205
ZW
5583 inst.instruction |= inst.operands[0].reg << 12;
5584 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5585
c19d1205
ZW
5586 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5587 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5588 Bit 4 should be 0. */
5589 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5590
c19d1205
ZW
5591 inst.instruction |= imm;
5592}
5593\f
5594/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5595
c19d1205
ZW
5596/* Xscale multiply-accumulate (argument parse)
5597 MIAcc acc0,Rm,Rs
5598 MIAPHcc acc0,Rm,Rs
5599 MIAxycc acc0,Rm,Rs. */
a737bd4d 5600
c19d1205
ZW
5601static void
5602do_xsc_mia (void)
5603{
5604 inst.instruction |= inst.operands[1].reg;
5605 inst.instruction |= inst.operands[2].reg << 12;
5606}
a737bd4d 5607
c19d1205 5608/* Xscale move-accumulator-register (argument parse)
a737bd4d 5609
c19d1205 5610 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5611
c19d1205
ZW
5612static void
5613do_xsc_mar (void)
5614{
5615 inst.instruction |= inst.operands[1].reg << 12;
5616 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5617}
5618
c19d1205 5619/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5620
c19d1205 5621 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5622
5623static void
c19d1205 5624do_xsc_mra (void)
b99bd4ef 5625{
c19d1205
ZW
5626 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5627 inst.instruction |= inst.operands[0].reg << 12;
5628 inst.instruction |= inst.operands[1].reg << 16;
5629}
5630\f
5631/* Encoding functions relevant only to Thumb. */
b99bd4ef 5632
c19d1205
ZW
5633/* inst.operands[i] is a shifted-register operand; encode
5634 it into inst.instruction in the format used by Thumb32. */
5635
5636static void
5637encode_thumb32_shifted_operand (int i)
5638{
5639 unsigned int value = inst.reloc.exp.X_add_number;
5640 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5641
9c3c69f2
PB
5642 constraint (inst.operands[i].immisreg,
5643 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
5644 inst.instruction |= inst.operands[i].reg;
5645 if (shift == SHIFT_RRX)
5646 inst.instruction |= SHIFT_ROR << 4;
5647 else
b99bd4ef 5648 {
c19d1205
ZW
5649 constraint (inst.reloc.exp.X_op != O_constant,
5650 _("expression too complex"));
5651
5652 constraint (value > 32
5653 || (value == 32 && (shift == SHIFT_LSL
5654 || shift == SHIFT_ROR)),
5655 _("shift expression is too large"));
5656
5657 if (value == 0)
5658 shift = SHIFT_LSL;
5659 else if (value == 32)
5660 value = 0;
5661
5662 inst.instruction |= shift << 4;
5663 inst.instruction |= (value & 0x1c) << 10;
5664 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5665 }
c19d1205 5666}
b99bd4ef 5667
b99bd4ef 5668
c19d1205
ZW
5669/* inst.operands[i] was set up by parse_address. Encode it into a
5670 Thumb32 format load or store instruction. Reject forms that cannot
5671 be used with such instructions. If is_t is true, reject forms that
5672 cannot be used with a T instruction; if is_d is true, reject forms
5673 that cannot be used with a D instruction. */
b99bd4ef 5674
c19d1205
ZW
5675static void
5676encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5677{
5678 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5679
5680 constraint (!inst.operands[i].isreg,
5681 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5682
c19d1205
ZW
5683 inst.instruction |= inst.operands[i].reg << 16;
5684 if (inst.operands[i].immisreg)
b99bd4ef 5685 {
c19d1205
ZW
5686 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5687 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5688 constraint (inst.operands[i].negative,
5689 _("Thumb does not support negative register indexing"));
5690 constraint (inst.operands[i].postind,
5691 _("Thumb does not support register post-indexing"));
5692 constraint (inst.operands[i].writeback,
5693 _("Thumb does not support register indexing with writeback"));
5694 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5695 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5696
c19d1205
ZW
5697 inst.instruction |= inst.operands[1].imm;
5698 if (inst.operands[i].shifted)
b99bd4ef 5699 {
c19d1205
ZW
5700 constraint (inst.reloc.exp.X_op != O_constant,
5701 _("expression too complex"));
9c3c69f2
PB
5702 constraint (inst.reloc.exp.X_add_number < 0
5703 || inst.reloc.exp.X_add_number > 3,
c19d1205 5704 _("shift out of range"));
9c3c69f2 5705 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
5706 }
5707 inst.reloc.type = BFD_RELOC_UNUSED;
5708 }
5709 else if (inst.operands[i].preind)
5710 {
5711 constraint (is_pc && inst.operands[i].writeback,
5712 _("cannot use writeback with PC-relative addressing"));
5713 constraint (is_t && inst.operands[1].writeback,
5714 _("cannot use writeback with this instruction"));
5715
5716 if (is_d)
5717 {
5718 inst.instruction |= 0x01000000;
5719 if (inst.operands[i].writeback)
5720 inst.instruction |= 0x00200000;
b99bd4ef 5721 }
c19d1205 5722 else
b99bd4ef 5723 {
c19d1205
ZW
5724 inst.instruction |= 0x00000c00;
5725 if (inst.operands[i].writeback)
5726 inst.instruction |= 0x00000100;
b99bd4ef 5727 }
c19d1205 5728 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 5729 }
c19d1205 5730 else if (inst.operands[i].postind)
b99bd4ef 5731 {
c19d1205
ZW
5732 assert (inst.operands[i].writeback);
5733 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5734 constraint (is_t, _("cannot use post-indexing with this instruction"));
5735
5736 if (is_d)
5737 inst.instruction |= 0x00200000;
5738 else
5739 inst.instruction |= 0x00000900;
5740 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5741 }
5742 else /* unindexed - only for coprocessor */
5743 inst.error = _("instruction does not accept unindexed addressing");
5744}
5745
5746/* Table of Thumb instructions which exist in both 16- and 32-bit
5747 encodings (the latter only in post-V6T2 cores). The index is the
5748 value used in the insns table below. When there is more than one
5749 possible 16-bit encoding for the instruction, this table always
5750 holds variant (1). */
5751#define T16_32_TAB \
5752 X(adc, 4140, eb400000), \
5753 X(adcs, 4140, eb500000), \
5754 X(add, 1c00, eb000000), \
5755 X(adds, 1c00, eb100000), \
e9f89963 5756 X(adr, 000f, f20f0000), \
c19d1205
ZW
5757 X(and, 4000, ea000000), \
5758 X(ands, 4000, ea100000), \
5759 X(asr, 1000, fa40f000), \
5760 X(asrs, 1000, fa50f000), \
5761 X(bic, 4380, ea200000), \
5762 X(bics, 4380, ea300000), \
5763 X(cmn, 42c0, eb100f00), \
5764 X(cmp, 2800, ebb00f00), \
5765 X(cpsie, b660, f3af8400), \
5766 X(cpsid, b670, f3af8600), \
5767 X(cpy, 4600, ea4f0000), \
5768 X(eor, 4040, ea800000), \
5769 X(eors, 4040, ea900000), \
5770 X(ldmia, c800, e8900000), \
5771 X(ldr, 6800, f8500000), \
5772 X(ldrb, 7800, f8100000), \
5773 X(ldrh, 8800, f8300000), \
5774 X(ldrsb, 5600, f9100000), \
5775 X(ldrsh, 5e00, f9300000), \
5776 X(lsl, 0000, fa00f000), \
5777 X(lsls, 0000, fa10f000), \
5778 X(lsr, 0800, fa20f000), \
5779 X(lsrs, 0800, fa30f000), \
5780 X(mov, 2000, ea4f0000), \
5781 X(movs, 2000, ea5f0000), \
5782 X(mul, 4340, fb00f000), \
5783 X(muls, 4340, ffffffff), /* no 32b muls */ \
5784 X(mvn, 43c0, ea6f0000), \
5785 X(mvns, 43c0, ea7f0000), \
5786 X(neg, 4240, f1c00000), /* rsb #0 */ \
5787 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5788 X(orr, 4300, ea400000), \
5789 X(orrs, 4300, ea500000), \
e9f89963
PB
5790 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
5791 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
5792 X(rev, ba00, fa90f080), \
5793 X(rev16, ba40, fa90f090), \
5794 X(revsh, bac0, fa90f0b0), \
5795 X(ror, 41c0, fa60f000), \
5796 X(rors, 41c0, fa70f000), \
5797 X(sbc, 4180, eb600000), \
5798 X(sbcs, 4180, eb700000), \
5799 X(stmia, c000, e8800000), \
5800 X(str, 6000, f8400000), \
5801 X(strb, 7000, f8000000), \
5802 X(strh, 8000, f8200000), \
5803 X(sub, 1e00, eba00000), \
5804 X(subs, 1e00, ebb00000), \
5805 X(sxtb, b240, fa4ff080), \
5806 X(sxth, b200, fa0ff080), \
5807 X(tst, 4200, ea100f00), \
5808 X(uxtb, b2c0, fa5ff080), \
5809 X(uxth, b280, fa1ff080), \
5810 X(nop, bf00, f3af8000), \
5811 X(yield, bf10, f3af8001), \
5812 X(wfe, bf20, f3af8002), \
5813 X(wfi, bf30, f3af8003), \
5814 X(sev, bf40, f3af9004), /* typo, 8004? */
5815
5816/* To catch errors in encoding functions, the codes are all offset by
5817 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5818 as 16-bit instructions. */
5819#define X(a,b,c) T_MNEM_##a
5820enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5821#undef X
5822
5823#define X(a,b,c) 0x##b
5824static const unsigned short thumb_op16[] = { T16_32_TAB };
5825#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5826#undef X
5827
5828#define X(a,b,c) 0x##c
5829static const unsigned int thumb_op32[] = { T16_32_TAB };
5830#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5831#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5832#undef X
5833#undef T16_32_TAB
5834
5835/* Thumb instruction encoders, in alphabetical order. */
5836
92e90b6e
PB
5837/* ADDW or SUBW. */
5838static void
5839do_t_add_sub_w (void)
5840{
5841 int Rd, Rn;
5842
5843 Rd = inst.operands[0].reg;
5844 Rn = inst.operands[1].reg;
5845
5846 constraint (Rd == 15, _("PC not allowed as destination"));
5847 inst.instruction |= (Rn << 16) | (Rd << 8);
5848 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
5849}
5850
c19d1205
ZW
5851/* Parse an add or subtract instruction. We get here with inst.instruction
5852 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5853
5854static void
5855do_t_add_sub (void)
5856{
5857 int Rd, Rs, Rn;
5858
5859 Rd = inst.operands[0].reg;
5860 Rs = (inst.operands[1].present
5861 ? inst.operands[1].reg /* Rd, Rs, foo */
5862 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5863
5864 if (unified_syntax)
5865 {
5866 if (!inst.operands[2].isreg)
b99bd4ef 5867 {
e27ec89e
PB
5868 /* ??? Convert large immediates to addw/subw. */
5869 /* ??? 16-bit adds with small immediates. */
c19d1205
ZW
5870 /* For an immediate, we always generate a 32-bit opcode;
5871 section relaxation will shrink it later if possible. */
5872 inst.instruction = THUMB_OP32 (inst.instruction);
5873 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5874 inst.instruction |= inst.operands[0].reg << 8;
5875 inst.instruction |= inst.operands[1].reg << 16;
5876 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 5877 }
c19d1205
ZW
5878 else
5879 {
5880 Rn = inst.operands[2].reg;
5881 /* See if we can do this with a 16-bit instruction. */
5882 if (!inst.operands[2].shifted && inst.size_req != 4)
5883 {
e27ec89e
PB
5884 bfd_boolean narrow;
5885
5886 if (inst.instruction == T_MNEM_adds
5887 || inst.instruction == T_MNEM_subs)
5888 narrow = (current_it_mask == 0);
5889 else
5890 narrow = (current_it_mask != 0);
5891 if (Rd > 7 || Rs > 7 || Rn > 7)
5892 narrow = FALSE;
5893
5894 if (narrow)
c19d1205 5895 {
e27ec89e
PB
5896 inst.instruction = ((inst.instruction == T_MNEM_adds
5897 || inst.instruction == T_MNEM_add)
c19d1205
ZW
5898 ? T_OPCODE_ADD_R3
5899 : T_OPCODE_SUB_R3);
5900 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
5901 return;
5902 }
b99bd4ef 5903
c19d1205
ZW
5904 if (inst.instruction == T_MNEM_add)
5905 {
5906 if (Rd == Rs)
5907 {
5908 inst.instruction = T_OPCODE_ADD_HI;
5909 inst.instruction |= (Rd & 8) << 4;
5910 inst.instruction |= (Rd & 7);
5911 inst.instruction |= Rn << 3;
5912 return;
5913 }
5914 /* ... because addition is commutative! */
5915 else if (Rd == Rn)
5916 {
5917 inst.instruction = T_OPCODE_ADD_HI;
5918 inst.instruction |= (Rd & 8) << 4;
5919 inst.instruction |= (Rd & 7);
5920 inst.instruction |= Rs << 3;
5921 return;
5922 }
5923 }
5924 }
5925 /* If we get here, it can't be done in 16 bits. */
5926 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
5927 _("shift must be constant"));
5928 inst.instruction = THUMB_OP32 (inst.instruction);
5929 inst.instruction |= Rd << 8;
5930 inst.instruction |= Rs << 16;
5931 encode_thumb32_shifted_operand (2);
5932 }
5933 }
5934 else
5935 {
5936 constraint (inst.instruction == T_MNEM_adds
5937 || inst.instruction == T_MNEM_subs,
5938 BAD_THUMB32);
b99bd4ef 5939
c19d1205 5940 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 5941 {
c19d1205
ZW
5942 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
5943 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
5944 BAD_HIREG);
5945
5946 inst.instruction = (inst.instruction == T_MNEM_add
5947 ? 0x0000 : 0x8000);
5948 inst.instruction |= (Rd << 4) | Rs;
5949 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
5950 return;
5951 }
5952
c19d1205
ZW
5953 Rn = inst.operands[2].reg;
5954 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 5955
c19d1205
ZW
5956 /* We now have Rd, Rs, and Rn set to registers. */
5957 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 5958 {
c19d1205
ZW
5959 /* Can't do this for SUB. */
5960 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
5961 inst.instruction = T_OPCODE_ADD_HI;
5962 inst.instruction |= (Rd & 8) << 4;
5963 inst.instruction |= (Rd & 7);
5964 if (Rs == Rd)
5965 inst.instruction |= Rn << 3;
5966 else if (Rn == Rd)
5967 inst.instruction |= Rs << 3;
5968 else
5969 constraint (1, _("dest must overlap one source register"));
5970 }
5971 else
5972 {
5973 inst.instruction = (inst.instruction == T_MNEM_add
5974 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
5975 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 5976 }
b99bd4ef 5977 }
b99bd4ef
NC
5978}
5979
c19d1205
ZW
5980static void
5981do_t_adr (void)
5982{
e9f89963
PB
5983 if (unified_syntax && inst.size_req != 2)
5984 {
5985 /* Always generate a 32-bit opcode;
5986 section relaxation will shrink it later if possible. */
5987 inst.instruction = THUMB_OP32 (inst.instruction);
5988 inst.instruction |= inst.operands[0].reg << 8;
5989 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
5990 inst.reloc.pc_rel = 1;
5991 }
5992 else
5993 {
5994 inst.instruction = THUMB_OP16 (inst.instruction);
5995 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
5996 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
5997 inst.reloc.pc_rel = 1;
b99bd4ef 5998
e9f89963
PB
5999 inst.instruction |= inst.operands[0].reg << 4;
6000 }
c19d1205 6001}
b99bd4ef 6002
c19d1205
ZW
6003/* Arithmetic instructions for which there is just one 16-bit
6004 instruction encoding, and it allows only two low registers.
6005 For maximal compatibility with ARM syntax, we allow three register
6006 operands even when Thumb-32 instructions are not available, as long
6007 as the first two are identical. For instance, both "sbc r0,r1" and
6008 "sbc r0,r0,r1" are allowed. */
b99bd4ef 6009static void
c19d1205 6010do_t_arit3 (void)
b99bd4ef 6011{
c19d1205 6012 int Rd, Rs, Rn;
b99bd4ef 6013
c19d1205
ZW
6014 Rd = inst.operands[0].reg;
6015 Rs = (inst.operands[1].present
6016 ? inst.operands[1].reg /* Rd, Rs, foo */
6017 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6018 Rn = inst.operands[2].reg;
b99bd4ef 6019
c19d1205 6020 if (unified_syntax)
b99bd4ef 6021 {
c19d1205
ZW
6022 if (!inst.operands[2].isreg)
6023 {
6024 /* For an immediate, we always generate a 32-bit opcode;
6025 section relaxation will shrink it later if possible. */
6026 inst.instruction = THUMB_OP32 (inst.instruction);
6027 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6028 inst.instruction |= Rd << 8;
6029 inst.instruction |= Rs << 16;
6030 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6031 }
6032 else
6033 {
e27ec89e
PB
6034 bfd_boolean narrow;
6035
c19d1205 6036 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6037 if (THUMB_SETS_FLAGS (inst.instruction))
6038 narrow = current_it_mask == 0;
6039 else
6040 narrow = current_it_mask != 0;
6041
6042 if (Rd > 7 || Rn > 7 || Rs > 7)
6043 narrow = FALSE;
6044 if (inst.operands[2].shifted)
6045 narrow = FALSE;
6046 if (inst.size_req == 4)
6047 narrow = FALSE;
6048
6049 if (narrow
c19d1205
ZW
6050 && Rd == Rs)
6051 {
6052 inst.instruction = THUMB_OP16 (inst.instruction);
6053 inst.instruction |= Rd;
6054 inst.instruction |= Rn << 3;
6055 return;
6056 }
b99bd4ef 6057
c19d1205
ZW
6058 /* If we get here, it can't be done in 16 bits. */
6059 constraint (inst.operands[2].shifted
6060 && inst.operands[2].immisreg,
6061 _("shift must be constant"));
6062 inst.instruction = THUMB_OP32 (inst.instruction);
6063 inst.instruction |= Rd << 8;
6064 inst.instruction |= Rs << 16;
6065 encode_thumb32_shifted_operand (2);
6066 }
a737bd4d 6067 }
c19d1205 6068 else
b99bd4ef 6069 {
c19d1205
ZW
6070 /* On its face this is a lie - the instruction does set the
6071 flags. However, the only supported mnemonic in this mode
6072 says it doesn't. */
6073 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6074
c19d1205
ZW
6075 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6076 _("unshifted register required"));
6077 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6078 constraint (Rd != Rs,
6079 _("dest and source1 must be the same register"));
a737bd4d 6080
c19d1205
ZW
6081 inst.instruction = THUMB_OP16 (inst.instruction);
6082 inst.instruction |= Rd;
6083 inst.instruction |= Rn << 3;
b99bd4ef 6084 }
a737bd4d 6085}
b99bd4ef 6086
c19d1205
ZW
6087/* Similarly, but for instructions where the arithmetic operation is
6088 commutative, so we can allow either of them to be different from
6089 the destination operand in a 16-bit instruction. For instance, all
6090 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6091 accepted. */
6092static void
6093do_t_arit3c (void)
a737bd4d 6094{
c19d1205 6095 int Rd, Rs, Rn;
b99bd4ef 6096
c19d1205
ZW
6097 Rd = inst.operands[0].reg;
6098 Rs = (inst.operands[1].present
6099 ? inst.operands[1].reg /* Rd, Rs, foo */
6100 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6101 Rn = inst.operands[2].reg;
a737bd4d 6102
c19d1205 6103 if (unified_syntax)
a737bd4d 6104 {
c19d1205 6105 if (!inst.operands[2].isreg)
b99bd4ef 6106 {
c19d1205
ZW
6107 /* For an immediate, we always generate a 32-bit opcode;
6108 section relaxation will shrink it later if possible. */
6109 inst.instruction = THUMB_OP32 (inst.instruction);
6110 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6111 inst.instruction |= Rd << 8;
6112 inst.instruction |= Rs << 16;
6113 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6114 }
c19d1205 6115 else
a737bd4d 6116 {
e27ec89e
PB
6117 bfd_boolean narrow;
6118
c19d1205 6119 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6120 if (THUMB_SETS_FLAGS (inst.instruction))
6121 narrow = current_it_mask == 0;
6122 else
6123 narrow = current_it_mask != 0;
6124
6125 if (Rd > 7 || Rn > 7 || Rs > 7)
6126 narrow = FALSE;
6127 if (inst.operands[2].shifted)
6128 narrow = FALSE;
6129 if (inst.size_req == 4)
6130 narrow = FALSE;
6131
6132 if (narrow)
a737bd4d 6133 {
c19d1205 6134 if (Rd == Rs)
a737bd4d 6135 {
c19d1205
ZW
6136 inst.instruction = THUMB_OP16 (inst.instruction);
6137 inst.instruction |= Rd;
6138 inst.instruction |= Rn << 3;
6139 return;
a737bd4d 6140 }
c19d1205 6141 if (Rd == Rn)
a737bd4d 6142 {
c19d1205
ZW
6143 inst.instruction = THUMB_OP16 (inst.instruction);
6144 inst.instruction |= Rd;
6145 inst.instruction |= Rs << 3;
6146 return;
a737bd4d
NC
6147 }
6148 }
c19d1205
ZW
6149
6150 /* If we get here, it can't be done in 16 bits. */
6151 constraint (inst.operands[2].shifted
6152 && inst.operands[2].immisreg,
6153 _("shift must be constant"));
6154 inst.instruction = THUMB_OP32 (inst.instruction);
6155 inst.instruction |= Rd << 8;
6156 inst.instruction |= Rs << 16;
6157 encode_thumb32_shifted_operand (2);
a737bd4d 6158 }
b99bd4ef 6159 }
c19d1205
ZW
6160 else
6161 {
6162 /* On its face this is a lie - the instruction does set the
6163 flags. However, the only supported mnemonic in this mode
6164 says it doesn't. */
6165 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6166
c19d1205
ZW
6167 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6168 _("unshifted register required"));
6169 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6170
6171 inst.instruction = THUMB_OP16 (inst.instruction);
6172 inst.instruction |= Rd;
6173
6174 if (Rd == Rs)
6175 inst.instruction |= Rn << 3;
6176 else if (Rd == Rn)
6177 inst.instruction |= Rs << 3;
6178 else
6179 constraint (1, _("dest must overlap one source register"));
6180 }
a737bd4d
NC
6181}
6182
c19d1205
ZW
6183static void
6184do_t_bfc (void)
a737bd4d 6185{
c19d1205
ZW
6186 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6187 constraint (msb > 32, _("bit-field extends past end of register"));
6188 /* The instruction encoding stores the LSB and MSB,
6189 not the LSB and width. */
6190 inst.instruction |= inst.operands[0].reg << 8;
6191 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6192 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6193 inst.instruction |= msb - 1;
b99bd4ef
NC
6194}
6195
c19d1205
ZW
6196static void
6197do_t_bfi (void)
b99bd4ef 6198{
c19d1205 6199 unsigned int msb;
b99bd4ef 6200
c19d1205
ZW
6201 /* #0 in second position is alternative syntax for bfc, which is
6202 the same instruction but with REG_PC in the Rm field. */
6203 if (!inst.operands[1].isreg)
6204 inst.operands[1].reg = REG_PC;
b99bd4ef 6205
c19d1205
ZW
6206 msb = inst.operands[2].imm + inst.operands[3].imm;
6207 constraint (msb > 32, _("bit-field extends past end of register"));
6208 /* The instruction encoding stores the LSB and MSB,
6209 not the LSB and width. */
6210 inst.instruction |= inst.operands[0].reg << 8;
6211 inst.instruction |= inst.operands[1].reg << 16;
6212 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6213 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6214 inst.instruction |= msb - 1;
b99bd4ef
NC
6215}
6216
c19d1205
ZW
6217static void
6218do_t_bfx (void)
b99bd4ef 6219{
c19d1205
ZW
6220 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6221 _("bit-field extends past end of register"));
6222 inst.instruction |= inst.operands[0].reg << 8;
6223 inst.instruction |= inst.operands[1].reg << 16;
6224 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6225 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6226 inst.instruction |= inst.operands[3].imm - 1;
6227}
b99bd4ef 6228
c19d1205
ZW
6229/* ARM V5 Thumb BLX (argument parse)
6230 BLX <target_addr> which is BLX(1)
6231 BLX <Rm> which is BLX(2)
6232 Unfortunately, there are two different opcodes for this mnemonic.
6233 So, the insns[].value is not used, and the code here zaps values
6234 into inst.instruction.
b99bd4ef 6235
c19d1205
ZW
6236 ??? How to take advantage of the additional two bits of displacement
6237 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6238
c19d1205
ZW
6239static void
6240do_t_blx (void)
6241{
6242 if (inst.operands[0].isreg)
6243 /* We have a register, so this is BLX(2). */
6244 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6245 else
6246 {
c19d1205 6247 /* No register. This must be BLX(1). */
2fc8bdac 6248 inst.instruction = 0xf000e800;
c19d1205
ZW
6249 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6250 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6251 }
6252}
6253
c19d1205
ZW
6254static void
6255do_t_branch (void)
b99bd4ef 6256{
c19d1205
ZW
6257 if (unified_syntax && inst.size_req != 2)
6258 {
6259 if (inst.cond == COND_ALWAYS)
6260 {
2fc8bdac 6261 inst.instruction = 0xf000b000;
c19d1205
ZW
6262 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6263 }
6264 else
6265 {
6266 assert (inst.cond != 0xF);
2fc8bdac 6267 inst.instruction = (inst.cond << 22) | 0xf0008000;
c19d1205
ZW
6268 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6269 }
6270 }
b99bd4ef
NC
6271 else
6272 {
c19d1205
ZW
6273 if (inst.cond == COND_ALWAYS)
6274 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6275 else
b99bd4ef 6276 {
2fc8bdac 6277 inst.instruction = 0xd000 | (inst.cond << 8);
c19d1205 6278 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6279 }
b99bd4ef 6280 }
c19d1205
ZW
6281
6282 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6283}
6284
6285static void
c19d1205 6286do_t_bkpt (void)
b99bd4ef 6287{
c19d1205 6288 if (inst.operands[0].present)
b99bd4ef 6289 {
c19d1205
ZW
6290 constraint (inst.operands[0].imm > 255,
6291 _("immediate value out of range"));
6292 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6293 }
b99bd4ef
NC
6294}
6295
6296static void
c19d1205 6297do_t_branch23 (void)
b99bd4ef 6298{
c19d1205 6299 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6300 inst.reloc.pc_rel = 1;
6301
c19d1205
ZW
6302 /* If the destination of the branch is a defined symbol which does not have
6303 the THUMB_FUNC attribute, then we must be calling a function which has
6304 the (interfacearm) attribute. We look for the Thumb entry point to that
6305 function and change the branch to refer to that function instead. */
6306 if ( inst.reloc.exp.X_op == O_symbol
6307 && inst.reloc.exp.X_add_symbol != NULL
6308 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6309 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6310 inst.reloc.exp.X_add_symbol =
6311 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6312}
6313
6314static void
c19d1205 6315do_t_bx (void)
90e4755a 6316{
c19d1205
ZW
6317 inst.instruction |= inst.operands[0].reg << 3;
6318 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6319 should cause the alignment to be checked once it is known. This is
6320 because BX PC only works if the instruction is word aligned. */
6321}
90e4755a 6322
c19d1205
ZW
6323static void
6324do_t_bxj (void)
6325{
6326 if (inst.operands[0].reg == REG_PC)
6327 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6328
c19d1205 6329 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6330}
6331
6332static void
c19d1205 6333do_t_clz (void)
90e4755a 6334{
c19d1205
ZW
6335 inst.instruction |= inst.operands[0].reg << 8;
6336 inst.instruction |= inst.operands[1].reg << 16;
6337 inst.instruction |= inst.operands[1].reg;
6338}
90e4755a 6339
c19d1205
ZW
6340static void
6341do_t_cpsi (void)
6342{
6343 if (unified_syntax
6344 && (inst.operands[1].present || inst.size_req == 4))
90e4755a 6345 {
c19d1205
ZW
6346 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6347 inst.instruction = 0xf3af8000;
6348 inst.instruction |= imod << 9;
6349 inst.instruction |= inst.operands[0].imm << 5;
6350 if (inst.operands[1].present)
6351 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6352 }
c19d1205 6353 else
90e4755a 6354 {
c19d1205
ZW
6355 constraint (inst.operands[1].present,
6356 _("Thumb does not support the 2-argument "
6357 "form of this instruction"));
6358 inst.instruction |= inst.operands[0].imm;
90e4755a 6359 }
90e4755a
RE
6360}
6361
c19d1205
ZW
6362/* THUMB CPY instruction (argument parse). */
6363
90e4755a 6364static void
c19d1205 6365do_t_cpy (void)
90e4755a 6366{
c19d1205 6367 if (inst.size_req == 4)
90e4755a 6368 {
c19d1205
ZW
6369 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6370 inst.instruction |= inst.operands[0].reg << 8;
6371 inst.instruction |= inst.operands[1].reg;
90e4755a 6372 }
c19d1205 6373 else
90e4755a 6374 {
c19d1205
ZW
6375 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6376 inst.instruction |= (inst.operands[0].reg & 0x7);
6377 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6378 }
90e4755a
RE
6379}
6380
90e4755a 6381static void
c19d1205 6382do_t_czb (void)
90e4755a 6383{
c19d1205
ZW
6384 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6385 inst.instruction |= inst.operands[0].reg;
6386 inst.reloc.pc_rel = 1;
6387 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6388}
90e4755a 6389
c19d1205
ZW
6390static void
6391do_t_hint (void)
6392{
6393 if (unified_syntax && inst.size_req == 4)
6394 inst.instruction = THUMB_OP32 (inst.instruction);
6395 else
6396 inst.instruction = THUMB_OP16 (inst.instruction);
6397}
90e4755a 6398
c19d1205
ZW
6399static void
6400do_t_it (void)
6401{
6402 unsigned int cond = inst.operands[0].imm;
e27ec89e
PB
6403
6404 current_it_mask = (inst.instruction & 0xf) | 0x10;
6405 current_cc = cond;
6406
6407 /* If the condition is a negative condition, invert the mask. */
c19d1205 6408 if ((cond & 0x1) == 0x0)
90e4755a 6409 {
c19d1205 6410 unsigned int mask = inst.instruction & 0x000f;
90e4755a 6411
c19d1205
ZW
6412 if ((mask & 0x7) == 0)
6413 /* no conversion needed */;
6414 else if ((mask & 0x3) == 0)
e27ec89e
PB
6415 mask ^= 0x8;
6416 else if ((mask & 0x1) == 0)
6417 mask ^= 0xC;
c19d1205 6418 else
e27ec89e 6419 mask ^= 0xE;
90e4755a 6420
e27ec89e
PB
6421 inst.instruction &= 0xfff0;
6422 inst.instruction |= mask;
c19d1205 6423 }
90e4755a 6424
c19d1205
ZW
6425 inst.instruction |= cond << 4;
6426}
90e4755a 6427
c19d1205
ZW
6428static void
6429do_t_ldmstm (void)
6430{
6431 /* This really doesn't seem worth it. */
6432 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6433 _("expression too complex"));
6434 constraint (inst.operands[1].writeback,
6435 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6436
c19d1205
ZW
6437 if (unified_syntax)
6438 {
6439 /* See if we can use a 16-bit instruction. */
6440 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6441 && inst.size_req != 4
6442 && inst.operands[0].reg <= 7
6443 && !(inst.operands[1].imm & ~0xff)
6444 && (inst.instruction == T_MNEM_stmia
6445 ? inst.operands[0].writeback
6446 : (inst.operands[0].writeback
6447 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6448 {
c19d1205
ZW
6449 if (inst.instruction == T_MNEM_stmia
6450 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6451 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6452 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6453 inst.operands[0].reg);
90e4755a 6454
c19d1205
ZW
6455 inst.instruction = THUMB_OP16 (inst.instruction);
6456 inst.instruction |= inst.operands[0].reg << 8;
6457 inst.instruction |= inst.operands[1].imm;
6458 }
6459 else
6460 {
6461 if (inst.operands[1].imm & (1 << 13))
6462 as_warn (_("SP should not be in register list"));
6463 if (inst.instruction == T_MNEM_stmia)
90e4755a 6464 {
c19d1205
ZW
6465 if (inst.operands[1].imm & (1 << 15))
6466 as_warn (_("PC should not be in register list"));
6467 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6468 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6469 inst.operands[0].reg);
90e4755a
RE
6470 }
6471 else
6472 {
c19d1205
ZW
6473 if (inst.operands[1].imm & (1 << 14)
6474 && inst.operands[1].imm & (1 << 15))
6475 as_warn (_("LR and PC should not both be in register list"));
6476 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6477 && inst.operands[0].writeback)
6478 as_warn (_("base register should not be in register list "
6479 "when written back"));
90e4755a 6480 }
c19d1205
ZW
6481 if (inst.instruction < 0xffff)
6482 inst.instruction = THUMB_OP32 (inst.instruction);
6483 inst.instruction |= inst.operands[0].reg << 16;
6484 inst.instruction |= inst.operands[1].imm;
6485 if (inst.operands[0].writeback)
6486 inst.instruction |= WRITE_BACK;
90e4755a
RE
6487 }
6488 }
c19d1205 6489 else
90e4755a 6490 {
c19d1205
ZW
6491 constraint (inst.operands[0].reg > 7
6492 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6493 if (inst.instruction == T_MNEM_stmia)
f03698e6 6494 {
c19d1205
ZW
6495 if (!inst.operands[0].writeback)
6496 as_warn (_("this instruction will write back the base register"));
6497 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6498 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6499 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6500 inst.operands[0].reg);
f03698e6 6501 }
c19d1205 6502 else
90e4755a 6503 {
c19d1205
ZW
6504 if (!inst.operands[0].writeback
6505 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6506 as_warn (_("this instruction will write back the base register"));
6507 else if (inst.operands[0].writeback
6508 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6509 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6510 }
6511
c19d1205
ZW
6512 inst.instruction = THUMB_OP16 (inst.instruction);
6513 inst.instruction |= inst.operands[0].reg << 8;
6514 inst.instruction |= inst.operands[1].imm;
6515 }
6516}
e28cd48c 6517
c19d1205
ZW
6518static void
6519do_t_ldrex (void)
6520{
6521 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6522 || inst.operands[1].postind || inst.operands[1].writeback
6523 || inst.operands[1].immisreg || inst.operands[1].shifted
6524 || inst.operands[1].negative,
6525 _("instruction does not accept this addressing mode"));
e28cd48c 6526
c19d1205
ZW
6527 inst.instruction |= inst.operands[0].reg << 12;
6528 inst.instruction |= inst.operands[1].reg << 16;
6529 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6530}
e28cd48c 6531
c19d1205
ZW
6532static void
6533do_t_ldrexd (void)
6534{
6535 if (!inst.operands[1].present)
1cac9012 6536 {
c19d1205
ZW
6537 constraint (inst.operands[0].reg == REG_LR,
6538 _("r14 not allowed as first register "
6539 "when second register is omitted"));
6540 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6541 }
c19d1205
ZW
6542 constraint (inst.operands[0].reg == inst.operands[1].reg,
6543 BAD_OVERLAP);
b99bd4ef 6544
c19d1205
ZW
6545 inst.instruction |= inst.operands[0].reg << 12;
6546 inst.instruction |= inst.operands[1].reg << 8;
6547 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6548}
6549
6550static void
c19d1205 6551do_t_ldst (void)
b99bd4ef 6552{
c19d1205 6553 if (unified_syntax)
b99bd4ef 6554 {
c19d1205
ZW
6555 /* Generation of 16-bit instructions for anything other than
6556 Rd, [Rn, Ri] is deferred to section relaxation time. */
6557 if (inst.operands[1].isreg && inst.operands[1].immisreg
6558 && !inst.operands[1].shifted && !inst.operands[1].postind
6559 && !inst.operands[1].negative && inst.operands[0].reg <= 7
6560 && inst.operands[1].reg <= 7 && inst.operands[1].imm <= 7
6561 && inst.instruction <= 0xffff)
6562 {
6563 inst.instruction = THUMB_OP16 (inst.instruction);
6564 goto op16;
6565 }
6566
6567 inst.instruction = THUMB_OP32 (inst.instruction);
6568 inst.instruction |= inst.operands[0].reg << 12;
6569 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
6570 return;
6571 }
6572
c19d1205
ZW
6573 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6574
6575 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 6576 {
c19d1205
ZW
6577 /* Only [Rn,Rm] is acceptable. */
6578 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6579 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6580 || inst.operands[1].postind || inst.operands[1].shifted
6581 || inst.operands[1].negative,
6582 _("Thumb does not support this addressing mode"));
6583 inst.instruction = THUMB_OP16 (inst.instruction);
6584 goto op16;
b99bd4ef 6585 }
c19d1205
ZW
6586
6587 inst.instruction = THUMB_OP16 (inst.instruction);
6588 if (!inst.operands[1].isreg)
6589 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6590 return;
b99bd4ef 6591
c19d1205
ZW
6592 constraint (!inst.operands[1].preind
6593 || inst.operands[1].shifted
6594 || inst.operands[1].writeback,
6595 _("Thumb does not support this addressing mode"));
6596 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 6597 {
c19d1205
ZW
6598 constraint (inst.instruction & 0x0600,
6599 _("byte or halfword not valid for base register"));
6600 constraint (inst.operands[1].reg == REG_PC
6601 && !(inst.instruction & THUMB_LOAD_BIT),
6602 _("r15 based store not allowed"));
6603 constraint (inst.operands[1].immisreg,
6604 _("invalid base register for register offset"));
b99bd4ef 6605
c19d1205
ZW
6606 if (inst.operands[1].reg == REG_PC)
6607 inst.instruction = T_OPCODE_LDR_PC;
6608 else if (inst.instruction & THUMB_LOAD_BIT)
6609 inst.instruction = T_OPCODE_LDR_SP;
6610 else
6611 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 6612
c19d1205
ZW
6613 inst.instruction |= inst.operands[0].reg << 8;
6614 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6615 return;
6616 }
90e4755a 6617
c19d1205
ZW
6618 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6619 if (!inst.operands[1].immisreg)
6620 {
6621 /* Immediate offset. */
6622 inst.instruction |= inst.operands[0].reg;
6623 inst.instruction |= inst.operands[1].reg << 3;
6624 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6625 return;
6626 }
90e4755a 6627
c19d1205
ZW
6628 /* Register offset. */
6629 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6630 constraint (inst.operands[1].negative,
6631 _("Thumb does not support this addressing mode"));
90e4755a 6632
c19d1205
ZW
6633 op16:
6634 switch (inst.instruction)
6635 {
6636 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6637 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6638 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6639 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6640 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6641 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6642 case 0x5600 /* ldrsb */:
6643 case 0x5e00 /* ldrsh */: break;
6644 default: abort ();
6645 }
90e4755a 6646
c19d1205
ZW
6647 inst.instruction |= inst.operands[0].reg;
6648 inst.instruction |= inst.operands[1].reg << 3;
6649 inst.instruction |= inst.operands[1].imm << 6;
6650}
90e4755a 6651
c19d1205
ZW
6652static void
6653do_t_ldstd (void)
6654{
6655 if (!inst.operands[1].present)
b99bd4ef 6656 {
c19d1205
ZW
6657 inst.operands[1].reg = inst.operands[0].reg + 1;
6658 constraint (inst.operands[0].reg == REG_LR,
6659 _("r14 not allowed here"));
b99bd4ef 6660 }
c19d1205
ZW
6661 inst.instruction |= inst.operands[0].reg << 12;
6662 inst.instruction |= inst.operands[1].reg << 8;
6663 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6664
b99bd4ef
NC
6665}
6666
c19d1205
ZW
6667static void
6668do_t_ldstt (void)
6669{
6670 inst.instruction |= inst.operands[0].reg << 12;
6671 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6672}
a737bd4d 6673
b99bd4ef 6674static void
c19d1205 6675do_t_mla (void)
b99bd4ef 6676{
c19d1205
ZW
6677 inst.instruction |= inst.operands[0].reg << 8;
6678 inst.instruction |= inst.operands[1].reg << 16;
6679 inst.instruction |= inst.operands[2].reg;
6680 inst.instruction |= inst.operands[3].reg << 12;
6681}
b99bd4ef 6682
c19d1205
ZW
6683static void
6684do_t_mlal (void)
6685{
6686 inst.instruction |= inst.operands[0].reg << 12;
6687 inst.instruction |= inst.operands[1].reg << 8;
6688 inst.instruction |= inst.operands[2].reg << 16;
6689 inst.instruction |= inst.operands[3].reg;
6690}
b99bd4ef 6691
c19d1205
ZW
6692static void
6693do_t_mov_cmp (void)
6694{
6695 if (unified_syntax)
b99bd4ef 6696 {
c19d1205
ZW
6697 int r0off = (inst.instruction == T_MNEM_mov
6698 || inst.instruction == T_MNEM_movs) ? 8 : 16;
3d388997
PB
6699 bfd_boolean narrow;
6700 bfd_boolean low_regs;
6701
6702 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
6703 if (current_it_mask)
6704 narrow = inst.instruction != T_MNEM_movs;
6705 else
6706 narrow = inst.instruction != T_MNEM_movs || low_regs;
6707 if (inst.size_req == 4
6708 || inst.operands[1].shifted)
6709 narrow = FALSE;
6710
c19d1205
ZW
6711 if (!inst.operands[1].isreg)
6712 {
6713 /* For an immediate, we always generate a 32-bit opcode;
6714 section relaxation will shrink it later if possible. */
6715 inst.instruction = THUMB_OP32 (inst.instruction);
6716 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6717 inst.instruction |= inst.operands[0].reg << r0off;
6718 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6719 }
3d388997 6720 else if (!narrow)
c19d1205
ZW
6721 {
6722 inst.instruction = THUMB_OP32 (inst.instruction);
6723 inst.instruction |= inst.operands[0].reg << r0off;
6724 encode_thumb32_shifted_operand (1);
6725 }
6726 else
6727 switch (inst.instruction)
6728 {
6729 case T_MNEM_mov:
6730 inst.instruction = T_OPCODE_MOV_HR;
6731 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6732 inst.instruction |= (inst.operands[0].reg & 0x7);
6733 inst.instruction |= inst.operands[1].reg << 3;
6734 break;
b99bd4ef 6735
c19d1205
ZW
6736 case T_MNEM_movs:
6737 /* We know we have low registers at this point.
6738 Generate ADD Rd, Rs, #0. */
6739 inst.instruction = T_OPCODE_ADD_I3;
6740 inst.instruction |= inst.operands[0].reg;
6741 inst.instruction |= inst.operands[1].reg << 3;
6742 break;
6743
6744 case T_MNEM_cmp:
3d388997 6745 if (low_regs)
c19d1205
ZW
6746 {
6747 inst.instruction = T_OPCODE_CMP_LR;
6748 inst.instruction |= inst.operands[0].reg;
6749 inst.instruction |= inst.operands[1].reg << 3;
6750 }
6751 else
6752 {
6753 inst.instruction = T_OPCODE_CMP_HR;
6754 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6755 inst.instruction |= (inst.operands[0].reg & 0x7);
6756 inst.instruction |= inst.operands[1].reg << 3;
6757 }
6758 break;
6759 }
b99bd4ef
NC
6760 return;
6761 }
6762
c19d1205
ZW
6763 inst.instruction = THUMB_OP16 (inst.instruction);
6764 if (inst.operands[1].isreg)
b99bd4ef 6765 {
c19d1205 6766 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 6767 {
c19d1205
ZW
6768 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
6769 since a MOV instruction produces unpredictable results. */
6770 if (inst.instruction == T_OPCODE_MOV_I8)
6771 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 6772 else
c19d1205 6773 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 6774
c19d1205
ZW
6775 inst.instruction |= inst.operands[0].reg;
6776 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
6777 }
6778 else
6779 {
c19d1205
ZW
6780 if (inst.instruction == T_OPCODE_MOV_I8)
6781 inst.instruction = T_OPCODE_MOV_HR;
6782 else
6783 inst.instruction = T_OPCODE_CMP_HR;
6784 do_t_cpy ();
b99bd4ef
NC
6785 }
6786 }
c19d1205 6787 else
b99bd4ef 6788 {
c19d1205
ZW
6789 constraint (inst.operands[0].reg > 7,
6790 _("only lo regs allowed with immediate"));
6791 inst.instruction |= inst.operands[0].reg << 8;
6792 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6793 }
6794}
b99bd4ef 6795
c19d1205
ZW
6796static void
6797do_t_mov16 (void)
6798{
6799 inst.instruction |= inst.operands[0].reg << 8;
6800 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
6801 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
6802 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
6803 inst.instruction |= (inst.operands[1].imm & 0x00ff);
6804}
b99bd4ef 6805
c19d1205
ZW
6806static void
6807do_t_mvn_tst (void)
6808{
6809 if (unified_syntax)
6810 {
6811 int r0off = (inst.instruction == T_MNEM_mvn
6812 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
6813 bfd_boolean narrow;
6814
6815 if (inst.size_req == 4
6816 || inst.instruction > 0xffff
6817 || inst.operands[1].shifted
6818 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
6819 narrow = FALSE;
6820 else if (inst.instruction == T_MNEM_cmn)
6821 narrow = TRUE;
6822 else if (THUMB_SETS_FLAGS (inst.instruction))
6823 narrow = (current_it_mask == 0);
6824 else
6825 narrow = (current_it_mask != 0);
6826
c19d1205 6827 if (!inst.operands[1].isreg)
b99bd4ef 6828 {
c19d1205
ZW
6829 /* For an immediate, we always generate a 32-bit opcode;
6830 section relaxation will shrink it later if possible. */
6831 if (inst.instruction < 0xffff)
6832 inst.instruction = THUMB_OP32 (inst.instruction);
6833 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6834 inst.instruction |= inst.operands[0].reg << r0off;
6835 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6836 }
c19d1205 6837 else
b99bd4ef 6838 {
c19d1205 6839 /* See if we can do this with a 16-bit instruction. */
3d388997 6840 if (narrow)
b99bd4ef 6841 {
c19d1205
ZW
6842 inst.instruction = THUMB_OP16 (inst.instruction);
6843 inst.instruction |= inst.operands[0].reg;
6844 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6845 }
c19d1205 6846 else
b99bd4ef 6847 {
c19d1205
ZW
6848 constraint (inst.operands[1].shifted
6849 && inst.operands[1].immisreg,
6850 _("shift must be constant"));
6851 if (inst.instruction < 0xffff)
6852 inst.instruction = THUMB_OP32 (inst.instruction);
6853 inst.instruction |= inst.operands[0].reg << r0off;
6854 encode_thumb32_shifted_operand (1);
b99bd4ef 6855 }
b99bd4ef
NC
6856 }
6857 }
6858 else
6859 {
c19d1205
ZW
6860 constraint (inst.instruction > 0xffff
6861 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
6862 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
6863 _("unshifted register required"));
6864 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6865 BAD_HIREG);
b99bd4ef 6866
c19d1205
ZW
6867 inst.instruction = THUMB_OP16 (inst.instruction);
6868 inst.instruction |= inst.operands[0].reg;
6869 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6870 }
b99bd4ef
NC
6871}
6872
b05fe5cf 6873static void
c19d1205 6874do_t_mrs (void)
b05fe5cf 6875{
c19d1205
ZW
6876 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
6877 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
6878 != (PSR_c|PSR_f),
6879 _("'CPSR' or 'SPSR' expected"));
6880 inst.instruction |= inst.operands[0].reg << 8;
6881 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
6882}
b05fe5cf 6883
c19d1205
ZW
6884static void
6885do_t_msr (void)
6886{
6887 constraint (!inst.operands[1].isreg,
6888 _("Thumb encoding does not support an immediate here"));
6889 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
6890 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
6891 inst.instruction |= inst.operands[1].reg << 16;
6892}
b05fe5cf 6893
c19d1205
ZW
6894static void
6895do_t_mul (void)
6896{
6897 if (!inst.operands[2].present)
6898 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 6899
c19d1205
ZW
6900 /* There is no 32-bit MULS and no 16-bit MUL. */
6901 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 6902 {
c19d1205
ZW
6903 inst.instruction = THUMB_OP32 (inst.instruction);
6904 inst.instruction |= inst.operands[0].reg << 8;
6905 inst.instruction |= inst.operands[1].reg << 16;
6906 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 6907 }
c19d1205 6908 else
b05fe5cf 6909 {
c19d1205
ZW
6910 constraint (!unified_syntax
6911 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
6912 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6913 BAD_HIREG);
b05fe5cf 6914
c19d1205
ZW
6915 inst.instruction = THUMB_OP16 (inst.instruction);
6916 inst.instruction |= inst.operands[0].reg;
b05fe5cf 6917
c19d1205
ZW
6918 if (inst.operands[0].reg == inst.operands[1].reg)
6919 inst.instruction |= inst.operands[2].reg << 3;
6920 else if (inst.operands[0].reg == inst.operands[2].reg)
6921 inst.instruction |= inst.operands[1].reg << 3;
6922 else
6923 constraint (1, _("dest must overlap one source register"));
6924 }
6925}
b05fe5cf 6926
c19d1205
ZW
6927static void
6928do_t_mull (void)
6929{
6930 inst.instruction |= inst.operands[0].reg << 12;
6931 inst.instruction |= inst.operands[1].reg << 8;
6932 inst.instruction |= inst.operands[2].reg << 16;
6933 inst.instruction |= inst.operands[3].reg;
b05fe5cf 6934
c19d1205
ZW
6935 if (inst.operands[0].reg == inst.operands[1].reg)
6936 as_tsktsk (_("rdhi and rdlo must be different"));
6937}
b05fe5cf 6938
c19d1205
ZW
6939static void
6940do_t_nop (void)
6941{
6942 if (unified_syntax)
6943 {
6944 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 6945 {
c19d1205
ZW
6946 inst.instruction = THUMB_OP32 (inst.instruction);
6947 inst.instruction |= inst.operands[0].imm;
6948 }
6949 else
6950 {
6951 inst.instruction = THUMB_OP16 (inst.instruction);
6952 inst.instruction |= inst.operands[0].imm << 4;
6953 }
6954 }
6955 else
6956 {
6957 constraint (inst.operands[0].present,
6958 _("Thumb does not support NOP with hints"));
6959 inst.instruction = 0x46c0;
6960 }
6961}
b05fe5cf 6962
c19d1205
ZW
6963static void
6964do_t_neg (void)
6965{
6966 if (unified_syntax)
6967 {
3d388997
PB
6968 bfd_boolean narrow;
6969
6970 if (THUMB_SETS_FLAGS (inst.instruction))
6971 narrow = (current_it_mask == 0);
6972 else
6973 narrow = (current_it_mask != 0);
6974 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
6975 narrow = FALSE;
6976 if (inst.size_req == 4)
6977 narrow = FALSE;
6978
6979 if (!narrow)
c19d1205
ZW
6980 {
6981 inst.instruction = THUMB_OP32 (inst.instruction);
6982 inst.instruction |= inst.operands[0].reg << 8;
6983 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
6984 }
6985 else
6986 {
c19d1205
ZW
6987 inst.instruction = THUMB_OP16 (inst.instruction);
6988 inst.instruction |= inst.operands[0].reg;
6989 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
6990 }
6991 }
6992 else
6993 {
c19d1205
ZW
6994 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6995 BAD_HIREG);
6996 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6997
6998 inst.instruction = THUMB_OP16 (inst.instruction);
6999 inst.instruction |= inst.operands[0].reg;
7000 inst.instruction |= inst.operands[1].reg << 3;
7001 }
7002}
7003
7004static void
7005do_t_pkhbt (void)
7006{
7007 inst.instruction |= inst.operands[0].reg << 8;
7008 inst.instruction |= inst.operands[1].reg << 16;
7009 inst.instruction |= inst.operands[2].reg;
7010 if (inst.operands[3].present)
7011 {
7012 unsigned int val = inst.reloc.exp.X_add_number;
7013 constraint (inst.reloc.exp.X_op != O_constant,
7014 _("expression too complex"));
7015 inst.instruction |= (val & 0x1c) << 10;
7016 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 7017 }
c19d1205 7018}
b05fe5cf 7019
c19d1205
ZW
7020static void
7021do_t_pkhtb (void)
7022{
7023 if (!inst.operands[3].present)
7024 inst.instruction &= ~0x00000020;
7025 do_t_pkhbt ();
b05fe5cf
ZW
7026}
7027
c19d1205
ZW
7028static void
7029do_t_pld (void)
7030{
7031 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7032}
b05fe5cf 7033
c19d1205
ZW
7034static void
7035do_t_push_pop (void)
b99bd4ef 7036{
e9f89963
PB
7037 unsigned mask;
7038
c19d1205
ZW
7039 constraint (inst.operands[0].writeback,
7040 _("push/pop do not support {reglist}^"));
7041 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7042 _("expression too complex"));
b99bd4ef 7043
e9f89963
PB
7044 mask = inst.operands[0].imm;
7045 if ((mask & ~0xff) == 0)
c19d1205
ZW
7046 inst.instruction = THUMB_OP16 (inst.instruction);
7047 else if ((inst.instruction == T_MNEM_push
e9f89963 7048 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 7049 || (inst.instruction == T_MNEM_pop
e9f89963 7050 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 7051 {
c19d1205
ZW
7052 inst.instruction = THUMB_OP16 (inst.instruction);
7053 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 7054 mask &= 0xff;
c19d1205
ZW
7055 }
7056 else if (unified_syntax)
7057 {
e9f89963
PB
7058 if (mask & (1 << 13))
7059 inst.error = _("SP not allowed in register list");
c19d1205 7060 if (inst.instruction == T_MNEM_push)
b99bd4ef 7061 {
e9f89963
PB
7062 if (mask & (1 << 15))
7063 inst.error = _("PC not allowed in register list");
c19d1205
ZW
7064 }
7065 else
7066 {
e9f89963
PB
7067 if (mask & (1 << 14)
7068 && mask & (1 << 15))
7069 inst.error = _("LR and PC should not both be in register list");
c19d1205 7070 }
e9f89963
PB
7071 if ((mask & (mask - 1)) == 0)
7072 {
7073 /* Single register push/pop implemented as str/ldr. */
7074 if (inst.instruction == T_MNEM_push)
7075 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7076 else
7077 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7078 mask = ffs(mask) - 1;
7079 mask <<= 12;
7080 }
7081 else
7082 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
7083 }
7084 else
7085 {
7086 inst.error = _("invalid register list to push/pop instruction");
7087 return;
7088 }
b99bd4ef 7089
e9f89963 7090 inst.instruction |= mask;
c19d1205 7091}
b99bd4ef 7092
c19d1205
ZW
7093static void
7094do_t_rbit (void)
7095{
7096 inst.instruction |= inst.operands[0].reg << 8;
7097 inst.instruction |= inst.operands[1].reg << 16;
7098}
b99bd4ef 7099
c19d1205
ZW
7100static void
7101do_t_rev (void)
7102{
7103 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7104 && inst.size_req != 4)
7105 {
7106 inst.instruction = THUMB_OP16 (inst.instruction);
7107 inst.instruction |= inst.operands[0].reg;
7108 inst.instruction |= inst.operands[1].reg << 3;
7109 }
7110 else if (unified_syntax)
7111 {
7112 inst.instruction = THUMB_OP32 (inst.instruction);
7113 inst.instruction |= inst.operands[0].reg << 8;
7114 inst.instruction |= inst.operands[1].reg << 16;
7115 inst.instruction |= inst.operands[1].reg;
7116 }
7117 else
7118 inst.error = BAD_HIREG;
7119}
b99bd4ef 7120
c19d1205
ZW
7121static void
7122do_t_rsb (void)
7123{
7124 int Rd, Rs;
b99bd4ef 7125
c19d1205
ZW
7126 Rd = inst.operands[0].reg;
7127 Rs = (inst.operands[1].present
7128 ? inst.operands[1].reg /* Rd, Rs, foo */
7129 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 7130
c19d1205
ZW
7131 inst.instruction |= Rd << 8;
7132 inst.instruction |= Rs << 16;
7133 if (!inst.operands[2].isreg)
7134 {
7135 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7136 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7137 }
7138 else
7139 encode_thumb32_shifted_operand (2);
7140}
b99bd4ef 7141
c19d1205
ZW
7142static void
7143do_t_setend (void)
7144{
7145 if (inst.operands[0].imm)
7146 inst.instruction |= 0x8;
7147}
b99bd4ef 7148
c19d1205
ZW
7149static void
7150do_t_shift (void)
7151{
7152 if (!inst.operands[1].present)
7153 inst.operands[1].reg = inst.operands[0].reg;
7154
7155 if (unified_syntax)
7156 {
3d388997
PB
7157 bfd_boolean narrow;
7158 int shift_kind;
7159
7160 switch (inst.instruction)
7161 {
7162 case T_MNEM_asr:
7163 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7164 case T_MNEM_lsl:
7165 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7166 case T_MNEM_lsr:
7167 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7168 case T_MNEM_ror:
7169 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7170 default: abort ();
7171 }
7172
7173 if (THUMB_SETS_FLAGS (inst.instruction))
7174 narrow = (current_it_mask == 0);
7175 else
7176 narrow = (current_it_mask != 0);
7177 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7178 narrow = FALSE;
7179 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7180 narrow = FALSE;
7181 if (inst.operands[2].isreg
7182 && (inst.operands[1].reg != inst.operands[0].reg
7183 || inst.operands[2].reg > 7))
7184 narrow = FALSE;
7185 if (inst.size_req == 4)
7186 narrow = FALSE;
7187
7188 if (!narrow)
c19d1205
ZW
7189 {
7190 if (inst.operands[2].isreg)
b99bd4ef 7191 {
c19d1205
ZW
7192 inst.instruction = THUMB_OP32 (inst.instruction);
7193 inst.instruction |= inst.operands[0].reg << 8;
7194 inst.instruction |= inst.operands[1].reg << 16;
7195 inst.instruction |= inst.operands[2].reg;
7196 }
7197 else
7198 {
7199 inst.operands[1].shifted = 1;
3d388997 7200 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
7201 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7202 ? T_MNEM_movs : T_MNEM_mov);
7203 inst.instruction |= inst.operands[0].reg << 8;
7204 encode_thumb32_shifted_operand (1);
7205 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7206 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7207 }
7208 }
7209 else
7210 {
c19d1205 7211 if (inst.operands[2].isreg)
b99bd4ef 7212 {
3d388997 7213 switch (shift_kind)
b99bd4ef 7214 {
3d388997
PB
7215 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7216 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7217 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7218 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 7219 default: abort ();
b99bd4ef 7220 }
c19d1205
ZW
7221
7222 inst.instruction |= inst.operands[0].reg;
7223 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7224 }
7225 else
7226 {
3d388997 7227 switch (shift_kind)
b99bd4ef 7228 {
3d388997
PB
7229 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7230 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7231 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 7232 default: abort ();
b99bd4ef 7233 }
c19d1205
ZW
7234 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7235 inst.instruction |= inst.operands[0].reg;
7236 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7237 }
7238 }
c19d1205
ZW
7239 }
7240 else
7241 {
7242 constraint (inst.operands[0].reg > 7
7243 || inst.operands[1].reg > 7, BAD_HIREG);
7244 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7245
c19d1205
ZW
7246 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7247 {
7248 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7249 constraint (inst.operands[0].reg != inst.operands[1].reg,
7250 _("source1 and dest must be same register"));
b99bd4ef 7251
c19d1205
ZW
7252 switch (inst.instruction)
7253 {
7254 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7255 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7256 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7257 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7258 default: abort ();
7259 }
7260
7261 inst.instruction |= inst.operands[0].reg;
7262 inst.instruction |= inst.operands[2].reg << 3;
7263 }
7264 else
b99bd4ef 7265 {
c19d1205
ZW
7266 switch (inst.instruction)
7267 {
7268 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7269 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7270 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7271 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7272 default: abort ();
7273 }
7274 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7275 inst.instruction |= inst.operands[0].reg;
7276 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7277 }
7278 }
b99bd4ef
NC
7279}
7280
7281static void
c19d1205 7282do_t_simd (void)
b99bd4ef 7283{
c19d1205
ZW
7284 inst.instruction |= inst.operands[0].reg << 8;
7285 inst.instruction |= inst.operands[1].reg << 16;
7286 inst.instruction |= inst.operands[2].reg;
7287}
b99bd4ef 7288
c19d1205
ZW
7289static void
7290do_t_smi (void)
7291{
7292 unsigned int value = inst.reloc.exp.X_add_number;
7293 constraint (inst.reloc.exp.X_op != O_constant,
7294 _("expression too complex"));
7295 inst.reloc.type = BFD_RELOC_UNUSED;
7296 inst.instruction |= (value & 0xf000) >> 12;
7297 inst.instruction |= (value & 0x0ff0);
7298 inst.instruction |= (value & 0x000f) << 16;
7299}
b99bd4ef 7300
c19d1205
ZW
7301static void
7302do_t_ssat (void)
7303{
7304 inst.instruction |= inst.operands[0].reg << 8;
7305 inst.instruction |= inst.operands[1].imm - 1;
7306 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7307
c19d1205 7308 if (inst.operands[3].present)
b99bd4ef 7309 {
c19d1205
ZW
7310 constraint (inst.reloc.exp.X_op != O_constant,
7311 _("expression too complex"));
b99bd4ef 7312
c19d1205 7313 if (inst.reloc.exp.X_add_number != 0)
6189168b 7314 {
c19d1205
ZW
7315 if (inst.operands[3].shift_kind == SHIFT_ASR)
7316 inst.instruction |= 0x00200000; /* sh bit */
7317 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7318 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7319 }
c19d1205 7320 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7321 }
b99bd4ef
NC
7322}
7323
0dd132b6 7324static void
c19d1205 7325do_t_ssat16 (void)
0dd132b6 7326{
c19d1205
ZW
7327 inst.instruction |= inst.operands[0].reg << 8;
7328 inst.instruction |= inst.operands[1].imm - 1;
7329 inst.instruction |= inst.operands[2].reg << 16;
7330}
0dd132b6 7331
c19d1205
ZW
7332static void
7333do_t_strex (void)
7334{
7335 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7336 || inst.operands[2].postind || inst.operands[2].writeback
7337 || inst.operands[2].immisreg || inst.operands[2].shifted
7338 || inst.operands[2].negative,
7339 _("instruction does not accept this addressing mode"));
0dd132b6 7340
c19d1205
ZW
7341 inst.instruction |= inst.operands[0].reg << 8;
7342 inst.instruction |= inst.operands[1].reg << 12;
7343 inst.instruction |= inst.operands[2].reg << 16;
7344 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7345}
7346
b99bd4ef 7347static void
c19d1205 7348do_t_strexd (void)
b99bd4ef 7349{
c19d1205
ZW
7350 if (!inst.operands[2].present)
7351 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7352
c19d1205
ZW
7353 constraint (inst.operands[0].reg == inst.operands[1].reg
7354 || inst.operands[0].reg == inst.operands[2].reg
7355 || inst.operands[0].reg == inst.operands[3].reg
7356 || inst.operands[1].reg == inst.operands[2].reg,
7357 BAD_OVERLAP);
b99bd4ef 7358
c19d1205
ZW
7359 inst.instruction |= inst.operands[0].reg;
7360 inst.instruction |= inst.operands[1].reg << 12;
7361 inst.instruction |= inst.operands[2].reg << 8;
7362 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7363}
7364
7365static void
c19d1205 7366do_t_sxtah (void)
b99bd4ef 7367{
c19d1205
ZW
7368 inst.instruction |= inst.operands[0].reg << 8;
7369 inst.instruction |= inst.operands[1].reg << 16;
7370 inst.instruction |= inst.operands[2].reg;
7371 inst.instruction |= inst.operands[3].imm << 4;
7372}
b99bd4ef 7373
c19d1205
ZW
7374static void
7375do_t_sxth (void)
7376{
7377 if (inst.instruction <= 0xffff && inst.size_req != 4
7378 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7379 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7380 {
c19d1205
ZW
7381 inst.instruction = THUMB_OP16 (inst.instruction);
7382 inst.instruction |= inst.operands[0].reg;
7383 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7384 }
c19d1205 7385 else if (unified_syntax)
b99bd4ef 7386 {
c19d1205
ZW
7387 if (inst.instruction <= 0xffff)
7388 inst.instruction = THUMB_OP32 (inst.instruction);
7389 inst.instruction |= inst.operands[0].reg << 8;
7390 inst.instruction |= inst.operands[1].reg;
7391 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7392 }
c19d1205 7393 else
b99bd4ef 7394 {
c19d1205
ZW
7395 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7396 _("Thumb encoding does not support rotation"));
7397 constraint (1, BAD_HIREG);
b99bd4ef 7398 }
c19d1205 7399}
b99bd4ef 7400
c19d1205
ZW
7401static void
7402do_t_swi (void)
7403{
7404 inst.reloc.type = BFD_RELOC_ARM_SWI;
7405}
b99bd4ef 7406
92e90b6e
PB
7407static void
7408do_t_tb (void)
7409{
7410 int half;
7411
7412 half = (inst.instruction & 0x10) != 0;
7413 constraint (inst.operands[0].imm == 15,
7414 _("PC is not a valid index register"));
7415 constraint (!half && inst.operands[0].shifted,
7416 _("instruction does not allow shifted index"));
7417 constraint (half && !inst.operands[0].shifted,
7418 _("instruction requires shifted index"));
7419 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7420}
7421
c19d1205
ZW
7422static void
7423do_t_usat (void)
7424{
7425 inst.instruction |= inst.operands[0].reg << 8;
7426 inst.instruction |= inst.operands[1].imm;
7427 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7428
c19d1205 7429 if (inst.operands[3].present)
b99bd4ef 7430 {
c19d1205
ZW
7431 constraint (inst.reloc.exp.X_op != O_constant,
7432 _("expression too complex"));
7433 if (inst.reloc.exp.X_add_number != 0)
7434 {
7435 if (inst.operands[3].shift_kind == SHIFT_ASR)
7436 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7437
c19d1205
ZW
7438 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7439 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7440 }
7441 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7442 }
b99bd4ef
NC
7443}
7444
7445static void
c19d1205 7446do_t_usat16 (void)
b99bd4ef 7447{
c19d1205
ZW
7448 inst.instruction |= inst.operands[0].reg << 8;
7449 inst.instruction |= inst.operands[1].imm;
7450 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7451}
c19d1205
ZW
7452\f
7453/* Overall per-instruction processing. */
7454
7455/* We need to be able to fix up arbitrary expressions in some statements.
7456 This is so that we can handle symbols that are an arbitrary distance from
7457 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7458 which returns part of an address in a form which will be valid for
7459 a data instruction. We do this by pushing the expression into a symbol
7460 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7461
7462static void
c19d1205
ZW
7463fix_new_arm (fragS * frag,
7464 int where,
7465 short int size,
7466 expressionS * exp,
7467 int pc_rel,
7468 int reloc)
b99bd4ef 7469{
c19d1205 7470 fixS * new_fix;
b99bd4ef 7471
c19d1205 7472 switch (exp->X_op)
b99bd4ef 7473 {
c19d1205
ZW
7474 case O_constant:
7475 case O_symbol:
7476 case O_add:
7477 case O_subtract:
7478 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7479 break;
b99bd4ef 7480
c19d1205
ZW
7481 default:
7482 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7483 pc_rel, reloc);
7484 break;
b99bd4ef
NC
7485 }
7486
c19d1205
ZW
7487 /* Mark whether the fix is to a THUMB instruction, or an ARM
7488 instruction. */
adbaf948 7489 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7490}
7491
7492static void
c19d1205 7493output_inst (const char * str)
b99bd4ef 7494{
c19d1205 7495 char * to = NULL;
b99bd4ef 7496
c19d1205 7497 if (inst.error)
b99bd4ef 7498 {
c19d1205 7499 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
7500 return;
7501 }
c19d1205
ZW
7502 if (inst.size == 0)
7503 return;
b99bd4ef 7504
c19d1205
ZW
7505 to = frag_more (inst.size);
7506
7507 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 7508 {
c19d1205
ZW
7509 assert (inst.size == (2 * THUMB_SIZE));
7510 md_number_to_chars (to, inst.instruction >> 16, THUMB_SIZE);
7511 md_number_to_chars (to + THUMB_SIZE, inst.instruction, THUMB_SIZE);
b99bd4ef 7512 }
c19d1205 7513 else if (inst.size > INSN_SIZE)
b99bd4ef 7514 {
c19d1205
ZW
7515 assert (inst.size == (2 * INSN_SIZE));
7516 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7517 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 7518 }
c19d1205
ZW
7519 else
7520 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 7521
c19d1205
ZW
7522 if (inst.reloc.type != BFD_RELOC_UNUSED)
7523 fix_new_arm (frag_now, to - frag_now->fr_literal,
7524 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7525 inst.reloc.type);
b99bd4ef 7526
c19d1205
ZW
7527#ifdef OBJ_ELF
7528 dwarf2_emit_insn (inst.size);
7529#endif
7530}
b99bd4ef 7531
c19d1205
ZW
7532/* Tag values used in struct asm_opcode's tag field. */
7533enum opcode_tag
7534{
7535 OT_unconditional, /* Instruction cannot be conditionalized.
7536 The ARM condition field is still 0xE. */
7537 OT_unconditionalF, /* Instruction cannot be conditionalized
7538 and carries 0xF in its ARM condition field. */
7539 OT_csuffix, /* Instruction takes a conditional suffix. */
7540 OT_cinfix3, /* Instruction takes a conditional infix,
7541 beginning at character index 3. (In
7542 unified mode, it becomes a suffix.) */
7543 OT_csuf_or_in3, /* Instruction takes either a conditional
7544 suffix or an infix at character index 3.
7545 (In unified mode, a suffix only. */
7546 OT_odd_infix_unc, /* This is the unconditional variant of an
7547 instruction that takes a conditional infix
7548 at an unusual position. In unified mode,
7549 this variant will accept a suffix. */
7550 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7551 are the conditional variants of instructions that
7552 take conditional infixes in unusual positions.
7553 The infix appears at character index
7554 (tag - OT_odd_infix_0). These are not accepted
7555 in unified mode. */
7556};
b99bd4ef 7557
c19d1205
ZW
7558/* Subroutine of md_assemble, responsible for looking up the primary
7559 opcode from the mnemonic the user wrote. STR points to the
7560 beginning of the mnemonic.
7561
7562 This is not simply a hash table lookup, because of conditional
7563 variants. Most instructions have conditional variants, which are
7564 expressed with a _conditional affix_ to the mnemonic. If we were
7565 to encode each conditional variant as a literal string in the opcode
7566 table, it would have approximately 20,000 entries.
7567
7568 Most mnemonics take this affix as a suffix, and in unified syntax,
7569 'most' is upgraded to 'all'. However, in the divided syntax, some
7570 instructions take the affix as an infix, notably the s-variants of
7571 the arithmetic instructions. Of those instructions, all but six
7572 have the infix appear after the third character of the mnemonic.
7573
7574 Accordingly, the algorithm for looking up primary opcodes given
7575 an identifier is:
7576
7577 1. Look up the identifier in the opcode table.
7578 If we find a match, go to step U.
7579
7580 2. Look up the last two characters of the identifier in the
7581 conditions table. If we find a match, look up the first N-2
7582 characters of the identifier in the opcode table. If we
7583 find a match, go to step CE.
7584
7585 3. Look up the fourth and fifth characters of the identifier in
7586 the conditions table. If we find a match, extract those
7587 characters from the identifier, and look up the remaining
7588 characters in the opcode table. If we find a match, go
7589 to step CM.
7590
7591 4. Fail.
7592
7593 U. Examine the tag field of the opcode structure, in case this is
7594 one of the six instructions with its conditional infix in an
7595 unusual place. If it is, the tag tells us where to find the
7596 infix; look it up in the conditions table and set inst.cond
7597 accordingly. Otherwise, this is an unconditional instruction.
7598 Again set inst.cond accordingly. Return the opcode structure.
7599
7600 CE. Examine the tag field to make sure this is an instruction that
7601 should receive a conditional suffix. If it is not, fail.
7602 Otherwise, set inst.cond from the suffix we already looked up,
7603 and return the opcode structure.
7604
7605 CM. Examine the tag field to make sure this is an instruction that
7606 should receive a conditional infix after the third character.
7607 If it is not, fail. Otherwise, undo the edits to the current
7608 line of input and proceed as for case CE. */
7609
7610static const struct asm_opcode *
7611opcode_lookup (char **str)
7612{
7613 char *end, *base;
7614 char *affix;
7615 const struct asm_opcode *opcode;
7616 const struct asm_cond *cond;
7617
7618 /* Scan up to the end of the mnemonic, which must end in white space,
7619 '.' (in unified mode only), or end of string. */
7620 for (base = end = *str; *end != '\0'; end++)
7621 if (*end == ' ' || (unified_syntax && *end == '.'))
7622 break;
b99bd4ef 7623
c19d1205
ZW
7624 if (end == base)
7625 return 0;
b99bd4ef 7626
c19d1205
ZW
7627 /* Handle a possible width suffix. */
7628 if (end[0] == '.')
b99bd4ef 7629 {
c19d1205
ZW
7630 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7631 inst.size_req = 4;
7632 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7633 inst.size_req = 2;
7634 else
7635 return 0;
b99bd4ef 7636
c19d1205 7637 *str = end + 2;
b99bd4ef 7638 }
c19d1205
ZW
7639 else
7640 *str = end;
b99bd4ef 7641
c19d1205
ZW
7642 /* Look for unaffixed or special-case affixed mnemonic. */
7643 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7644 if (opcode)
b99bd4ef 7645 {
c19d1205
ZW
7646 /* step U */
7647 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 7648 {
c19d1205
ZW
7649 inst.cond = COND_ALWAYS;
7650 return opcode;
b99bd4ef 7651 }
b99bd4ef 7652
c19d1205
ZW
7653 if (unified_syntax)
7654 as_warn (_("conditional infixes are deprecated in unified syntax"));
7655 affix = base + (opcode->tag - OT_odd_infix_0);
7656 cond = hash_find_n (arm_cond_hsh, affix, 2);
7657 assert (cond);
b99bd4ef 7658
c19d1205
ZW
7659 inst.cond = cond->value;
7660 return opcode;
7661 }
b99bd4ef 7662
c19d1205
ZW
7663 /* Cannot have a conditional suffix on a mnemonic of less than two
7664 characters. */
7665 if (end - base < 3)
7666 return 0;
b99bd4ef 7667
c19d1205
ZW
7668 /* Look for suffixed mnemonic. */
7669 affix = end - 2;
7670 cond = hash_find_n (arm_cond_hsh, affix, 2);
7671 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7672 if (opcode && cond)
7673 {
7674 /* step CE */
7675 switch (opcode->tag)
7676 {
7677 case OT_cinfix3:
7678 case OT_odd_infix_unc:
c4188bc9
PB
7679 /* Some mnemonics are ambiguous between infix and suffix
7680 conditions. Disambiguate based on assembly syntax. */
c19d1205 7681 if (!unified_syntax)
c4188bc9 7682 break;
c19d1205
ZW
7683 /* else fall through */
7684
7685 case OT_csuffix:
7686 case OT_csuf_or_in3:
7687 inst.cond = cond->value;
7688 return opcode;
7689
7690 case OT_unconditional:
7691 case OT_unconditionalF:
7692 /* delayed diagnostic */
7693 inst.error = BAD_COND;
7694 inst.cond = COND_ALWAYS;
7695 return opcode;
b99bd4ef 7696
c19d1205
ZW
7697 default:
7698 return 0;
7699 }
7700 }
b99bd4ef 7701
c19d1205
ZW
7702 /* Cannot have a usual-position infix on a mnemonic of less than
7703 six characters (five would be a suffix). */
7704 if (end - base < 6)
7705 return 0;
b99bd4ef 7706
c19d1205
ZW
7707 /* Look for infixed mnemonic in the usual position. */
7708 affix = base + 3;
7709 cond = hash_find_n (arm_cond_hsh, affix, 2);
7710 if (cond)
b99bd4ef 7711 {
c19d1205
ZW
7712 char save[2];
7713 memcpy (save, affix, 2);
7714 memmove (affix, affix + 2, (end - affix) - 2);
7715 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
7716 memmove (affix + 2, affix, (end - affix) - 2);
7717 memcpy (affix, save, 2);
b99bd4ef 7718 }
c19d1205 7719 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3))
b99bd4ef 7720 {
c19d1205
ZW
7721 /* step CM */
7722 if (unified_syntax)
7723 as_warn (_("conditional infixes are deprecated in unified syntax"));
7724
7725 inst.cond = cond->value;
7726 return opcode;
b99bd4ef
NC
7727 }
7728
c19d1205 7729 return 0;
b99bd4ef
NC
7730}
7731
c19d1205
ZW
7732void
7733md_assemble (char *str)
b99bd4ef 7734{
c19d1205
ZW
7735 char *p = str;
7736 const struct asm_opcode * opcode;
b99bd4ef 7737
c19d1205
ZW
7738 /* Align the previous label if needed. */
7739 if (last_label_seen != NULL)
b99bd4ef 7740 {
c19d1205
ZW
7741 symbol_set_frag (last_label_seen, frag_now);
7742 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
7743 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
7744 }
7745
c19d1205
ZW
7746 memset (&inst, '\0', sizeof (inst));
7747 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7748
c19d1205
ZW
7749 opcode = opcode_lookup (&p);
7750 if (!opcode)
b99bd4ef 7751 {
c19d1205
ZW
7752 /* It wasn't an instruction, but it might be a register alias of
7753 the form alias .req reg. */
7754 if (!create_register_alias (str, p))
7755 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 7756
b99bd4ef
NC
7757 return;
7758 }
7759
c19d1205 7760 if (thumb_mode)
b99bd4ef 7761 {
c19d1205
ZW
7762 /* Check that this instruction is supported for this CPU. */
7763 if (thumb_mode == 1 && (opcode->tvariant & cpu_variant) == 0)
b99bd4ef 7764 {
c19d1205 7765 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
7766 return;
7767 }
c19d1205
ZW
7768 if (inst.cond != COND_ALWAYS && !unified_syntax
7769 && opcode->tencode != do_t_branch)
b99bd4ef 7770 {
c19d1205 7771 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
7772 return;
7773 }
7774
e27ec89e
PB
7775 /* Check conditional suffixes. */
7776 if (current_it_mask)
7777 {
7778 int cond;
7779 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
7780 if (cond != inst.cond)
7781 {
7782 as_bad (_("incorrect condition in IT block"));
7783 return;
7784 }
7785 current_it_mask <<= 1;
7786 current_it_mask &= 0x1f;
7787 }
7788 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
7789 {
7790 as_bad (_("thumb conditional instrunction not in IT block"));
7791 return;
7792 }
7793
c19d1205
ZW
7794 mapping_state (MAP_THUMB);
7795 inst.instruction = opcode->tvalue;
7796
7797 if (!parse_operands (p, opcode->operands))
7798 opcode->tencode ();
7799
e27ec89e
PB
7800 /* Clear current_it_mask at the end of an IT block. */
7801 if (current_it_mask == 0x10)
7802 current_it_mask = 0;
7803
c19d1205 7804 if (!inst.error)
b99bd4ef 7805 {
c19d1205
ZW
7806 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
7807 inst.size = (inst.instruction > 0xffff ? 4 : 2);
7808 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 7809 {
c19d1205 7810 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
7811 return;
7812 }
7813 }
c19d1205
ZW
7814 }
7815 else
7816 {
7817 /* Check that this instruction is supported for this CPU. */
7818 if ((opcode->avariant & cpu_variant) == 0)
b99bd4ef 7819 {
c19d1205
ZW
7820 as_bad (_("selected processor does not support `%s'"), str);
7821 return;
b99bd4ef 7822 }
c19d1205 7823 if (inst.size_req)
b99bd4ef 7824 {
c19d1205
ZW
7825 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
7826 return;
b99bd4ef
NC
7827 }
7828
c19d1205
ZW
7829 mapping_state (MAP_ARM);
7830 inst.instruction = opcode->avalue;
7831 if (opcode->tag == OT_unconditionalF)
7832 inst.instruction |= 0xF << 28;
7833 else
7834 inst.instruction |= inst.cond << 28;
7835 inst.size = INSN_SIZE;
7836 if (!parse_operands (p, opcode->operands))
7837 opcode->aencode ();
b99bd4ef 7838 }
c19d1205
ZW
7839 output_inst (str);
7840}
b99bd4ef 7841
c19d1205
ZW
7842/* Various frobbings of labels and their addresses. */
7843
7844void
7845arm_start_line_hook (void)
7846{
7847 last_label_seen = NULL;
b99bd4ef
NC
7848}
7849
c19d1205
ZW
7850void
7851arm_frob_label (symbolS * sym)
b99bd4ef 7852{
c19d1205 7853 last_label_seen = sym;
b99bd4ef 7854
c19d1205 7855 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 7856
c19d1205
ZW
7857#if defined OBJ_COFF || defined OBJ_ELF
7858 ARM_SET_INTERWORK (sym, support_interwork);
7859#endif
b99bd4ef 7860
c19d1205
ZW
7861 /* Note - do not allow local symbols (.Lxxx) to be labeled
7862 as Thumb functions. This is because these labels, whilst
7863 they exist inside Thumb code, are not the entry points for
7864 possible ARM->Thumb calls. Also, these labels can be used
7865 as part of a computed goto or switch statement. eg gcc
7866 can generate code that looks like this:
b99bd4ef 7867
c19d1205
ZW
7868 ldr r2, [pc, .Laaa]
7869 lsl r3, r3, #2
7870 ldr r2, [r3, r2]
7871 mov pc, r2
b99bd4ef 7872
c19d1205
ZW
7873 .Lbbb: .word .Lxxx
7874 .Lccc: .word .Lyyy
7875 ..etc...
7876 .Laaa: .word Lbbb
b99bd4ef 7877
c19d1205
ZW
7878 The first instruction loads the address of the jump table.
7879 The second instruction converts a table index into a byte offset.
7880 The third instruction gets the jump address out of the table.
7881 The fourth instruction performs the jump.
b99bd4ef 7882
c19d1205
ZW
7883 If the address stored at .Laaa is that of a symbol which has the
7884 Thumb_Func bit set, then the linker will arrange for this address
7885 to have the bottom bit set, which in turn would mean that the
7886 address computation performed by the third instruction would end
7887 up with the bottom bit set. Since the ARM is capable of unaligned
7888 word loads, the instruction would then load the incorrect address
7889 out of the jump table, and chaos would ensue. */
7890 if (label_is_thumb_function_name
7891 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
7892 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 7893 {
c19d1205
ZW
7894 /* When the address of a Thumb function is taken the bottom
7895 bit of that address should be set. This will allow
7896 interworking between Arm and Thumb functions to work
7897 correctly. */
b99bd4ef 7898
c19d1205 7899 THUMB_SET_FUNC (sym, 1);
b99bd4ef 7900
c19d1205 7901 label_is_thumb_function_name = FALSE;
b99bd4ef 7902 }
b99bd4ef
NC
7903}
7904
c19d1205
ZW
7905int
7906arm_data_in_code (void)
b99bd4ef 7907{
c19d1205 7908 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 7909 {
c19d1205
ZW
7910 *input_line_pointer = '/';
7911 input_line_pointer += 5;
7912 *input_line_pointer = 0;
7913 return 1;
b99bd4ef
NC
7914 }
7915
c19d1205 7916 return 0;
b99bd4ef
NC
7917}
7918
c19d1205
ZW
7919char *
7920arm_canonicalize_symbol_name (char * name)
b99bd4ef 7921{
c19d1205 7922 int len;
b99bd4ef 7923
c19d1205
ZW
7924 if (thumb_mode && (len = strlen (name)) > 5
7925 && streq (name + len - 5, "/data"))
7926 *(name + len - 5) = 0;
b99bd4ef 7927
c19d1205 7928 return name;
b99bd4ef 7929}
c19d1205
ZW
7930\f
7931/* Table of all register names defined by default. The user can
7932 define additional names with .req. Note that all register names
7933 should appear in both upper and lowercase variants. Some registers
7934 also have mixed-case names. */
b99bd4ef 7935
c19d1205
ZW
7936#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
7937#define REGNUM(p,n,t) REGDEF(p##n, n, t)
7938#define REGSET(p,t) \
7939 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
7940 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
7941 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
7942 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 7943
c19d1205 7944static const struct reg_entry reg_names[] =
7ed4c4c5 7945{
c19d1205
ZW
7946 /* ARM integer registers. */
7947 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 7948
c19d1205
ZW
7949 /* ATPCS synonyms. */
7950 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
7951 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
7952 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 7953
c19d1205
ZW
7954 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
7955 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
7956 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 7957
c19d1205
ZW
7958 /* Well-known aliases. */
7959 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
7960 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
7961
7962 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
7963 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
7964
7965 /* Coprocessor numbers. */
7966 REGSET(p, CP), REGSET(P, CP),
7967
7968 /* Coprocessor register numbers. The "cr" variants are for backward
7969 compatibility. */
7970 REGSET(c, CN), REGSET(C, CN),
7971 REGSET(cr, CN), REGSET(CR, CN),
7972
7973 /* FPA registers. */
7974 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
7975 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
7976
7977 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
7978 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
7979
7980 /* VFP SP registers. */
7981 REGSET(s,VFS),
7982 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
7983 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
7984 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
7985 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
7986
7987 REGSET(S,VFS),
7988 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
7989 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
7990 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
7991 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
7992
7993 /* VFP DP Registers. */
7994 REGSET(d,VFD), REGSET(D,VFS),
7995
7996 /* VFP control registers. */
7997 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
7998 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
7999
8000 /* Maverick DSP coprocessor registers. */
8001 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8002 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8003
8004 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8005 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8006 REGDEF(dspsc,0,DSPSC),
8007
8008 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8009 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8010 REGDEF(DSPSC,0,DSPSC),
8011
8012 /* iWMMXt data registers - p0, c0-15. */
8013 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8014
8015 /* iWMMXt control registers - p1, c0-3. */
8016 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8017 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8018 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8019 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8020
8021 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8022 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8023 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8024 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8025 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8026
8027 /* XScale accumulator registers. */
8028 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8029};
8030#undef REGDEF
8031#undef REGNUM
8032#undef REGSET
7ed4c4c5 8033
c19d1205
ZW
8034/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8035 within psr_required_here. */
8036static const struct asm_psr psrs[] =
8037{
8038 /* Backward compatibility notation. Note that "all" is no longer
8039 truly all possible PSR bits. */
8040 {"all", PSR_c | PSR_f},
8041 {"flg", PSR_f},
8042 {"ctl", PSR_c},
8043
8044 /* Individual flags. */
8045 {"f", PSR_f},
8046 {"c", PSR_c},
8047 {"x", PSR_x},
8048 {"s", PSR_s},
8049 /* Combinations of flags. */
8050 {"fs", PSR_f | PSR_s},
8051 {"fx", PSR_f | PSR_x},
8052 {"fc", PSR_f | PSR_c},
8053 {"sf", PSR_s | PSR_f},
8054 {"sx", PSR_s | PSR_x},
8055 {"sc", PSR_s | PSR_c},
8056 {"xf", PSR_x | PSR_f},
8057 {"xs", PSR_x | PSR_s},
8058 {"xc", PSR_x | PSR_c},
8059 {"cf", PSR_c | PSR_f},
8060 {"cs", PSR_c | PSR_s},
8061 {"cx", PSR_c | PSR_x},
8062 {"fsx", PSR_f | PSR_s | PSR_x},
8063 {"fsc", PSR_f | PSR_s | PSR_c},
8064 {"fxs", PSR_f | PSR_x | PSR_s},
8065 {"fxc", PSR_f | PSR_x | PSR_c},
8066 {"fcs", PSR_f | PSR_c | PSR_s},
8067 {"fcx", PSR_f | PSR_c | PSR_x},
8068 {"sfx", PSR_s | PSR_f | PSR_x},
8069 {"sfc", PSR_s | PSR_f | PSR_c},
8070 {"sxf", PSR_s | PSR_x | PSR_f},
8071 {"sxc", PSR_s | PSR_x | PSR_c},
8072 {"scf", PSR_s | PSR_c | PSR_f},
8073 {"scx", PSR_s | PSR_c | PSR_x},
8074 {"xfs", PSR_x | PSR_f | PSR_s},
8075 {"xfc", PSR_x | PSR_f | PSR_c},
8076 {"xsf", PSR_x | PSR_s | PSR_f},
8077 {"xsc", PSR_x | PSR_s | PSR_c},
8078 {"xcf", PSR_x | PSR_c | PSR_f},
8079 {"xcs", PSR_x | PSR_c | PSR_s},
8080 {"cfs", PSR_c | PSR_f | PSR_s},
8081 {"cfx", PSR_c | PSR_f | PSR_x},
8082 {"csf", PSR_c | PSR_s | PSR_f},
8083 {"csx", PSR_c | PSR_s | PSR_x},
8084 {"cxf", PSR_c | PSR_x | PSR_f},
8085 {"cxs", PSR_c | PSR_x | PSR_s},
8086 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8087 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8088 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8089 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8090 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8091 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8092 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8093 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8094 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8095 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8096 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8097 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8098 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8099 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8100 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8101 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8102 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8103 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8104 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8105 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8106 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8107 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8108 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8109 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8110};
8111
8112/* Table of all shift-in-operand names. */
8113static const struct asm_shift_name shift_names [] =
b99bd4ef 8114{
c19d1205
ZW
8115 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8116 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8117 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8118 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8119 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8120 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8121};
b99bd4ef 8122
c19d1205
ZW
8123/* Table of all explicit relocation names. */
8124#ifdef OBJ_ELF
8125static struct reloc_entry reloc_names[] =
8126{
8127 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8128 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8129 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8130 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8131 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8132 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8133 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8134 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8135 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8136 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8137 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8138};
8139#endif
b99bd4ef 8140
c19d1205
ZW
8141/* Table of all conditional affixes. 0xF is not defined as a condition code. */
8142static const struct asm_cond conds[] =
8143{
8144 {"eq", 0x0},
8145 {"ne", 0x1},
8146 {"cs", 0x2}, {"hs", 0x2},
8147 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8148 {"mi", 0x4},
8149 {"pl", 0x5},
8150 {"vs", 0x6},
8151 {"vc", 0x7},
8152 {"hi", 0x8},
8153 {"ls", 0x9},
8154 {"ge", 0xa},
8155 {"lt", 0xb},
8156 {"gt", 0xc},
8157 {"le", 0xd},
8158 {"al", 0xe}
8159};
bfae80f2 8160
c19d1205
ZW
8161/* Table of ARM-format instructions. */
8162
8163/* Macros for gluing together operand strings. N.B. In all cases
8164 other than OPS0, the trailing OP_stop comes from default
8165 zero-initialization of the unspecified elements of the array. */
8166#define OPS0() { OP_stop, }
8167#define OPS1(a) { OP_##a, }
8168#define OPS2(a,b) { OP_##a,OP_##b, }
8169#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8170#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8171#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8172#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8173
8174/* These macros abstract out the exact format of the mnemonic table and
8175 save some repeated characters. */
8176
8177/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8178#define TxCE(mnem, op, top, nops, ops, ae, te) \
8179 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 8180 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8181
8182/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8183 a T_MNEM_xyz enumerator. */
8184#define TCE(mnem, aop, top, nops, ops, ae, te) \
8185 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8186#define tCE(mnem, aop, top, nops, ops, ae, te) \
8187 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8188
8189/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8190 infix after the third character. */
8191#define TxC3(mnem, op, top, nops, ops, ae, te) \
8192 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 8193 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8194#define TC3(mnem, aop, top, nops, ops, ae, te) \
8195 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8196#define tC3(mnem, aop, top, nops, ops, ae, te) \
8197 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8198
8199/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8200 appear in the condition table. */
8201#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8202 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 8203 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8204
8205#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8206 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8207 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8208 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8209 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8210 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8211 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8212 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8213 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8214 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8215 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8216 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8217 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8218 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8219 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8220 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8221 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8222 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8223 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8224 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8225
8226#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8227 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8228#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8229 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8230
8231/* Mnemonic that cannot be conditionalized. The ARM condition-code
8232 field is still 0xE. */
8233#define TUE(mnem, op, top, nops, ops, ae, te) \
8234 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8235 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8236
8237/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8238 condition code field. */
8239#define TUF(mnem, op, top, nops, ops, ae, te) \
8240 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8241 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8242
8243/* ARM-only variants of all the above. */
6a86118a
NC
8244#define CE(mnem, op, nops, ops, ae) \
8245 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8246
8247#define C3(mnem, op, nops, ops, ae) \
8248 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8249
8250#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8251 { #m1 #m2 #m3, OPS##nops ops, \
8252 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8253 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8254
8255#define CM(m1, m2, op, nops, ops, ae) \
8256 xCM_(m1, , m2, op, nops, ops, ae), \
8257 xCM_(m1, eq, m2, op, nops, ops, ae), \
8258 xCM_(m1, ne, m2, op, nops, ops, ae), \
8259 xCM_(m1, cs, m2, op, nops, ops, ae), \
8260 xCM_(m1, hs, m2, op, nops, ops, ae), \
8261 xCM_(m1, cc, m2, op, nops, ops, ae), \
8262 xCM_(m1, ul, m2, op, nops, ops, ae), \
8263 xCM_(m1, lo, m2, op, nops, ops, ae), \
8264 xCM_(m1, mi, m2, op, nops, ops, ae), \
8265 xCM_(m1, pl, m2, op, nops, ops, ae), \
8266 xCM_(m1, vs, m2, op, nops, ops, ae), \
8267 xCM_(m1, vc, m2, op, nops, ops, ae), \
8268 xCM_(m1, hi, m2, op, nops, ops, ae), \
8269 xCM_(m1, ls, m2, op, nops, ops, ae), \
8270 xCM_(m1, ge, m2, op, nops, ops, ae), \
8271 xCM_(m1, lt, m2, op, nops, ops, ae), \
8272 xCM_(m1, gt, m2, op, nops, ops, ae), \
8273 xCM_(m1, le, m2, op, nops, ops, ae), \
8274 xCM_(m1, al, m2, op, nops, ops, ae)
8275
8276#define UE(mnem, op, nops, ops, ae) \
8277 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8278
8279#define UF(mnem, op, nops, ops, ae) \
8280 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8281
c19d1205
ZW
8282#define do_0 0
8283
8284/* Thumb-only, unconditional. */
8285#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8286
8287/* ARM-only, takes either a suffix or a position-3 infix
8288 (for an FPA corner case). */
8289#define C3E(mnem, op, nops, ops, ae) \
8290 { #mnem, OPS##nops ops, OT_csuf_or_in3, 0x##op, 0, ARM_VARIANT, 0, do_##ae, 0 }
bfae80f2 8291
c19d1205 8292static const struct asm_opcode insns[] =
bfae80f2 8293{
c19d1205
ZW
8294#define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8295#define THUMB_VARIANT ARM_EXT_V4T
8296 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8297 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8298 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8299 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8300 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8301 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8302 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8303 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8304 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8305 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8306 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8307 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8308 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8309 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8310 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8311 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8312
8313 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8314 for setting PSR flag bits. They are obsolete in V6 and do not
8315 have Thumb equivalents. */
8316 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8317 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8318 C3(tstp, 110f000, 2, (RR, SH), cmp),
8319 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8320 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8321 C3(cmpp, 150f000, 2, (RR, SH), cmp),
8322 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8323 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8324 C3(cmnp, 170f000, 2, (RR, SH), cmp),
8325
8326 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8327 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8328 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8329 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8330
8331 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8332 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8333 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8334 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8335
8336 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8337 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8338 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8339 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8340
8341 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
2fc8bdac
ZW
8342 TCE(b, a000000, e000, 1, (EXPr), branch, t_branch),
8343 TCE(bl, b000000, f000f800, 1, (EXPr), branch, t_branch23),
bfae80f2 8344
c19d1205 8345 /* Pseudo ops. */
e9f89963 8346 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
8347 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8348 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
8349
8350 /* Thumb-compatibility pseudo ops. */
8351 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8352 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8353 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8354 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8355 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 8356 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
8357 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8358 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8359 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8360 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8361 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8362 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8363
8364#undef THUMB_VARIANT
8365#define THUMB_VARIANT ARM_EXT_V6
2fc8bdac 8366 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
8367
8368 /* V1 instructions with no Thumb analogue prior to V6T2. */
8369#undef THUMB_VARIANT
8370#define THUMB_VARIANT ARM_EXT_V6T2
8371 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8372 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8373 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8374 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8375 C3(teqp, 130f000, 2, (RR, SH), cmp),
8376
8377 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8378 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8379 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8380 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8381
9c3c69f2
PB
8382 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8383 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 8384
9c3c69f2
PB
8385 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8386 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8387
8388 /* V1 instructions with no Thumb analogue at all. */
8389 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8390 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8391
8392 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8393 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8394 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8395 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8396 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8397 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8398 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8399 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8400
8401#undef ARM_VARIANT
8402#define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8403#undef THUMB_VARIANT
8404#define THUMB_VARIANT ARM_EXT_V4T
8405 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8406 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8407
8408#undef THUMB_VARIANT
8409#define THUMB_VARIANT ARM_EXT_V6T2
8410 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8411 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8412
8413 /* Generic coprocessor instructions. */
8414 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8415 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8416 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8417 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8418 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8419 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8420 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8421
8422#undef ARM_VARIANT
8423#define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8424 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8425 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8426
8427#undef ARM_VARIANT
8428#define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8429 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8430 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8431
8432#undef ARM_VARIANT
8433#define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8434 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8435 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8436 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8437 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8438 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8439 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8440 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8441 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8442
8443#undef ARM_VARIANT
8444#define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8445#undef THUMB_VARIANT
8446#define THUMB_VARIANT ARM_EXT_V4T
8447 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8448 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8449 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8450 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8451 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8452 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8453
8454#undef ARM_VARIANT
8455#define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8456 /* ARM Architecture 4T. */
8457 /* Note: bx (and blx) are required on V5, even if the processor does
8458 not support Thumb. */
8459 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8460
8461#undef ARM_VARIANT
8462#define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8463#undef THUMB_VARIANT
8464#define THUMB_VARIANT ARM_EXT_V5T
8465 /* Note: blx has 2 variants; the .value coded here is for
8466 BLX(2). Only this variant has conditional execution. */
8467 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8468 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8469
8470#undef THUMB_VARIANT
8471#define THUMB_VARIANT ARM_EXT_V6T2
8472 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8473 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8474 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8475 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8476 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8477 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8478 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8479 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8480
8481#undef ARM_VARIANT
8482#define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8483 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8484 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8485 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8486 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8487
8488 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8489 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8490
8491 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8492 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8493 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8494 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8495
8496 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8497 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8498 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8499 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8500
8501 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8502 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8503
8504 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8505 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8506 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8507 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8508
8509#undef ARM_VARIANT
8510#define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8511 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8512 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8513 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8514
8515 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8516 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8517
8518#undef ARM_VARIANT
8519#define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8520 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8521
8522#undef ARM_VARIANT
8523#define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8524#undef THUMB_VARIANT
8525#define THUMB_VARIANT ARM_EXT_V6
8526 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8527 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8528 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8529 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8530 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8531 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8532 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8533 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8534 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8535 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8536
8537#undef THUMB_VARIANT
8538#define THUMB_VARIANT ARM_EXT_V6T2
8539 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8540 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8541 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8542 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8543 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8544 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8545 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8546 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8547 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8548 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8549 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8550 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8551 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8552 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8553 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8554 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8555 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8556 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8557 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8558 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8559 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8560 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8561 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8562 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8563 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8564 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8565 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8566 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8567 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8568 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8569 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8570 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8571 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8572 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8573 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8574 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8575 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8576 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8577 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8578 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8579 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8580 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8581 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8582 UF(rfeib, 9900a00, 1, (RRw), rfe),
8583 UF(rfeda, 8100a00, 1, (RRw), rfe),
8584 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8585 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8586 UF(rfefa, 9900a00, 1, (RRw), rfe),
8587 UF(rfeea, 8100a00, 1, (RRw), rfe),
8588 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8589 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8590 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8591 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8592 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8593 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8594 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8595 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8596 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8597 TCE(sel, 68000b0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8598 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8599 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8600 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8601 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8602 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8603 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8604 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8605 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8606 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8607 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8608 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8609 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8610 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8611 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8612 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8613 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8614 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8615 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8616 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8617 UF(srsib, 9cd0500, 1, (I31w), srs),
8618 UF(srsda, 84d0500, 1, (I31w), srs),
8619 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8620 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8621 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8622 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8623 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8624 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8625 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8626 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8627 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8628
8629#undef ARM_VARIANT
8630#define ARM_VARIANT ARM_EXT_V6K
8631#undef THUMB_VARIANT
8632#define THUMB_VARIANT ARM_EXT_V6K
8633 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8634 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8635 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8636 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8637
8638#undef THUMB_VARIANT
8639#define THUMB_VARIANT ARM_EXT_V6T2
8640 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8641 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8642 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8643 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8644 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8645 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8646 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8647
8648#undef ARM_VARIANT
8649#define ARM_VARIANT ARM_EXT_V6Z
8650 TCE(smi, 1600070, f7f08000, 1, (EXPi), smi, t_smi),
8651
8652#undef ARM_VARIANT
8653#define ARM_VARIANT ARM_EXT_V6T2
8654 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8655 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8656 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8657 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8658
8659 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8660 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8661 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8662 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8663
8664 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8665 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8666 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8667 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8668
8669 UT(cbnz, b900, 2, (RR, EXP), t_czb),
8670 UT(cbz, b100, 2, (RR, EXP), t_czb),
8671 /* ARM does not really have an IT instruction. */
8672 TUE(it, 0, bf08, 1, (COND), it, t_it),
8673 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
8674 TUE(ite, 0, bf04, 1, (COND), it, t_it),
8675 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
8676 TUE(itet, 0, bf06, 1, (COND), it, t_it),
8677 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
8678 TUE(itee, 0, bf02, 1, (COND), it, t_it),
8679 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
8680 TUE(itett, 0, bf07, 1, (COND), it, t_it),
8681 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
8682 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
8683 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
8684 TUE(itete, 0, bf05, 1, (COND), it, t_it),
8685 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
8686 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
8687
92e90b6e
PB
8688 /* Thumb2 only instructions. */
8689#undef ARM_VARIANT
8690#define ARM_VARIANT 0
8691
8692 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
8693 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
8694 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
8695 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
8696
c19d1205
ZW
8697#undef ARM_VARIANT
8698#define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
8699 CE(wfs, e200110, 1, (RR), rd),
8700 CE(rfs, e300110, 1, (RR), rd),
8701 CE(wfc, e400110, 1, (RR), rd),
8702 CE(rfc, e500110, 1, (RR), rd),
8703
8704 C3(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
8705 C3(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
8706 C3(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
8707 C3(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
8708
8709 C3(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
8710 C3(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
8711 C3(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
8712 C3(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
8713
8714 C3(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
8715 C3(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
8716 C3(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
8717 C3(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
8718 C3(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
8719 C3(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
8720 C3(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
8721 C3(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
8722 C3(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
8723 C3(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
8724 C3(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
8725 C3(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
8726
8727 C3(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
8728 C3(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
8729 C3(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
8730 C3(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
8731 C3(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
8732 C3(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
8733 C3(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
8734 C3(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
8735 C3(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
8736 C3(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
8737 C3(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
8738 C3(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
8739
8740 C3(abss, e208100, 2, (RF, RF_IF), rd_rm),
8741 C3(abssp, e208120, 2, (RF, RF_IF), rd_rm),
8742 C3(abssm, e208140, 2, (RF, RF_IF), rd_rm),
8743 C3(abssz, e208160, 2, (RF, RF_IF), rd_rm),
8744 C3(absd, e208180, 2, (RF, RF_IF), rd_rm),
8745 C3(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
8746 C3(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
8747 C3(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
8748 C3(abse, e288100, 2, (RF, RF_IF), rd_rm),
8749 C3(absep, e288120, 2, (RF, RF_IF), rd_rm),
8750 C3(absem, e288140, 2, (RF, RF_IF), rd_rm),
8751 C3(absez, e288160, 2, (RF, RF_IF), rd_rm),
8752
8753 C3(rnds, e308100, 2, (RF, RF_IF), rd_rm),
8754 C3(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
8755 C3(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
8756 C3(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
8757 C3(rndd, e308180, 2, (RF, RF_IF), rd_rm),
8758 C3(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
8759 C3(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
8760 C3(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
8761 C3(rnde, e388100, 2, (RF, RF_IF), rd_rm),
8762 C3(rndep, e388120, 2, (RF, RF_IF), rd_rm),
8763 C3(rndem, e388140, 2, (RF, RF_IF), rd_rm),
8764 C3(rndez, e388160, 2, (RF, RF_IF), rd_rm),
8765
8766 C3(sqts, e408100, 2, (RF, RF_IF), rd_rm),
8767 C3(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
8768 C3(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
8769 C3(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
8770 C3(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
8771 C3(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
8772 C3(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
8773 C3(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
8774 C3(sqte, e488100, 2, (RF, RF_IF), rd_rm),
8775 C3(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
8776 C3(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
8777 C3(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
8778
8779 C3(logs, e508100, 2, (RF, RF_IF), rd_rm),
8780 C3(logsp, e508120, 2, (RF, RF_IF), rd_rm),
8781 C3(logsm, e508140, 2, (RF, RF_IF), rd_rm),
8782 C3(logsz, e508160, 2, (RF, RF_IF), rd_rm),
8783 C3(logd, e508180, 2, (RF, RF_IF), rd_rm),
8784 C3(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
8785 C3(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
8786 C3(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
8787 C3(loge, e588100, 2, (RF, RF_IF), rd_rm),
8788 C3(logep, e588120, 2, (RF, RF_IF), rd_rm),
8789 C3(logem, e588140, 2, (RF, RF_IF), rd_rm),
8790 C3(logez, e588160, 2, (RF, RF_IF), rd_rm),
8791
8792 C3(lgns, e608100, 2, (RF, RF_IF), rd_rm),
8793 C3(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
8794 C3(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
8795 C3(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
8796 C3(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
8797 C3(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
8798 C3(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
8799 C3(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
8800 C3(lgne, e688100, 2, (RF, RF_IF), rd_rm),
8801 C3(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
8802 C3(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
8803 C3(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
8804
8805 C3(exps, e708100, 2, (RF, RF_IF), rd_rm),
8806 C3(expsp, e708120, 2, (RF, RF_IF), rd_rm),
8807 C3(expsm, e708140, 2, (RF, RF_IF), rd_rm),
8808 C3(expsz, e708160, 2, (RF, RF_IF), rd_rm),
8809 C3(expd, e708180, 2, (RF, RF_IF), rd_rm),
8810 C3(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
8811 C3(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
8812 C3(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
8813 C3(expe, e788100, 2, (RF, RF_IF), rd_rm),
8814 C3(expep, e788120, 2, (RF, RF_IF), rd_rm),
8815 C3(expem, e788140, 2, (RF, RF_IF), rd_rm),
8816 C3(expdz, e788160, 2, (RF, RF_IF), rd_rm),
8817
8818 C3(sins, e808100, 2, (RF, RF_IF), rd_rm),
8819 C3(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
8820 C3(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
8821 C3(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
8822 C3(sind, e808180, 2, (RF, RF_IF), rd_rm),
8823 C3(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
8824 C3(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
8825 C3(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
8826 C3(sine, e888100, 2, (RF, RF_IF), rd_rm),
8827 C3(sinep, e888120, 2, (RF, RF_IF), rd_rm),
8828 C3(sinem, e888140, 2, (RF, RF_IF), rd_rm),
8829 C3(sinez, e888160, 2, (RF, RF_IF), rd_rm),
8830
8831 C3(coss, e908100, 2, (RF, RF_IF), rd_rm),
8832 C3(cossp, e908120, 2, (RF, RF_IF), rd_rm),
8833 C3(cossm, e908140, 2, (RF, RF_IF), rd_rm),
8834 C3(cossz, e908160, 2, (RF, RF_IF), rd_rm),
8835 C3(cosd, e908180, 2, (RF, RF_IF), rd_rm),
8836 C3(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
8837 C3(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
8838 C3(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
8839 C3(cose, e988100, 2, (RF, RF_IF), rd_rm),
8840 C3(cosep, e988120, 2, (RF, RF_IF), rd_rm),
8841 C3(cosem, e988140, 2, (RF, RF_IF), rd_rm),
8842 C3(cosez, e988160, 2, (RF, RF_IF), rd_rm),
8843
8844 C3(tans, ea08100, 2, (RF, RF_IF), rd_rm),
8845 C3(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
8846 C3(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
8847 C3(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
8848 C3(tand, ea08180, 2, (RF, RF_IF), rd_rm),
8849 C3(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
8850 C3(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
8851 C3(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
8852 C3(tane, ea88100, 2, (RF, RF_IF), rd_rm),
8853 C3(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
8854 C3(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
8855 C3(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
8856
8857 C3(asns, eb08100, 2, (RF, RF_IF), rd_rm),
8858 C3(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
8859 C3(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
8860 C3(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
8861 C3(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
8862 C3(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
8863 C3(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
8864 C3(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
8865 C3(asne, eb88100, 2, (RF, RF_IF), rd_rm),
8866 C3(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
8867 C3(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
8868 C3(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
8869
8870 C3(acss, ec08100, 2, (RF, RF_IF), rd_rm),
8871 C3(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
8872 C3(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
8873 C3(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
8874 C3(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
8875 C3(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
8876 C3(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
8877 C3(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
8878 C3(acse, ec88100, 2, (RF, RF_IF), rd_rm),
8879 C3(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
8880 C3(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
8881 C3(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
8882
8883 C3(atns, ed08100, 2, (RF, RF_IF), rd_rm),
8884 C3(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
8885 C3(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
8886 C3(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
8887 C3(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
8888 C3(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
8889 C3(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
8890 C3(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
8891 C3(atne, ed88100, 2, (RF, RF_IF), rd_rm),
8892 C3(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
8893 C3(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
8894 C3(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
8895
8896 C3(urds, ee08100, 2, (RF, RF_IF), rd_rm),
8897 C3(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
8898 C3(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
8899 C3(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
8900 C3(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
8901 C3(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
8902 C3(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
8903 C3(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
8904 C3(urde, ee88100, 2, (RF, RF_IF), rd_rm),
8905 C3(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
8906 C3(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
8907 C3(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
8908
8909 C3(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
8910 C3(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
8911 C3(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
8912 C3(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
8913 C3(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
8914 C3(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
8915 C3(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
8916 C3(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
8917 C3(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
8918 C3(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
8919 C3(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
8920 C3(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
8921
8922 C3(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
8923 C3(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
8924 C3(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
8925 C3(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
8926 C3(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
8927 C3(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8928 C3(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8929 C3(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8930 C3(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
8931 C3(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
8932 C3(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
8933 C3(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
8934
8935 C3(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
8936 C3(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
8937 C3(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
8938 C3(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
8939 C3(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
8940 C3(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8941 C3(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8942 C3(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8943 C3(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
8944 C3(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
8945 C3(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
8946 C3(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
8947
8948 C3(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
8949 C3(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
8950 C3(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
8951 C3(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
8952 C3(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
8953 C3(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8954 C3(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8955 C3(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8956 C3(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
8957 C3(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
8958 C3(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
8959 C3(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
8960
8961 C3(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
8962 C3(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
8963 C3(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
8964 C3(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
8965 C3(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
8966 C3(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8967 C3(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8968 C3(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8969 C3(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
8970 C3(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
8971 C3(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
8972 C3(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
8973
8974 C3(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
8975 C3(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
8976 C3(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
8977 C3(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
8978 C3(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
8979 C3(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8980 C3(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8981 C3(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8982 C3(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
8983 C3(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
8984 C3(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
8985 C3(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
8986
8987 C3(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
8988 C3(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
8989 C3(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
8990 C3(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
8991 C3(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
8992 C3(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8993 C3(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8994 C3(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8995 C3(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
8996 C3(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
8997 C3(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
8998 C3(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
8999
9000 C3(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9001 C3(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9002 C3(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9003 C3(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9004 C3(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9005 C3(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9006 C3(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9007 C3(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9008 C3(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9009 C3(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9010 C3(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9011 C3(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9012
9013 C3(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9014 C3(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9015 C3(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9016 C3(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9017 C3(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9018 C3(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9019 C3(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9020 C3(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9021 C3(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9022 C3(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9023 C3(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9024 C3(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9025
9026 C3(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9027 C3(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9028 C3(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9029 C3(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9030 C3(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9031 C3(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9032 C3(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9033 C3(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9034 C3(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9035 C3(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9036 C3(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9037 C3(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9038
9039 C3(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9040 C3(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9041 C3(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9042 C3(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9043 C3(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9044 C3(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9045 C3(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9046 C3(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9047 C3(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9048 C3(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9049 C3(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9050 C3(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9051
9052 C3(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9053 C3(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9054 C3(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9055 C3(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9056 C3(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9057 C3(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9058 C3(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9059 C3(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9060 C3(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9061 C3(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9062 C3(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9063 C3(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9064
9065 C3(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9066 C3(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9067 C3(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9068 C3(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9069 C3(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9070 C3(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9071 C3(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9072 C3(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9073 C3(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9074 C3(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9075 C3(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9076 C3(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9077
9078 C3(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9079 C3(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9080 C3(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9081 C3(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9082 C3(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9083 C3(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9084 C3(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9085 C3(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9086 C3(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9087 C3(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9088 C3(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9089 C3(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9090
9091 CE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
9092 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
9093 CE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
9094 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9095
9096 C3(flts, e000110, 2, (RF, RR), rn_rd),
9097 C3(fltsp, e000130, 2, (RF, RR), rn_rd),
9098 C3(fltsm, e000150, 2, (RF, RR), rn_rd),
9099 C3(fltsz, e000170, 2, (RF, RR), rn_rd),
9100 C3(fltd, e000190, 2, (RF, RR), rn_rd),
9101 C3(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9102 C3(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9103 C3(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9104 C3(flte, e080110, 2, (RF, RR), rn_rd),
9105 C3(fltep, e080130, 2, (RF, RR), rn_rd),
9106 C3(fltem, e080150, 2, (RF, RR), rn_rd),
9107 C3(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 9108
c19d1205
ZW
9109 /* The implementation of the FIX instruction is broken on some
9110 assemblers, in that it accepts a precision specifier as well as a
9111 rounding specifier, despite the fact that this is meaningless.
9112 To be more compatible, we accept it as well, though of course it
9113 does not set any bits. */
9114 CE(fix, e100110, 2, (RR, RF), rd_rm),
9115 C3(fixp, e100130, 2, (RR, RF), rd_rm),
9116 C3(fixm, e100150, 2, (RR, RF), rd_rm),
9117 C3(fixz, e100170, 2, (RR, RF), rd_rm),
9118 C3(fixsp, e100130, 2, (RR, RF), rd_rm),
9119 C3(fixsm, e100150, 2, (RR, RF), rd_rm),
9120 C3(fixsz, e100170, 2, (RR, RF), rd_rm),
9121 C3(fixdp, e100130, 2, (RR, RF), rd_rm),
9122 C3(fixdm, e100150, 2, (RR, RF), rd_rm),
9123 C3(fixdz, e100170, 2, (RR, RF), rd_rm),
9124 C3(fixep, e100130, 2, (RR, RF), rd_rm),
9125 C3(fixem, e100150, 2, (RR, RF), rd_rm),
9126 C3(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 9127
c19d1205
ZW
9128 /* Instructions that were new with the real FPA, call them V2. */
9129#undef ARM_VARIANT
9130#define ARM_VARIANT FPU_FPA_EXT_V2
9131 CE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9132 C3(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9133 C3(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9134 CE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9135 C3(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9136 C3(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9137
9138#undef ARM_VARIANT
9139#define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
9140 /* Moves and type conversions. */
9141 CE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9142 CE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9143 CE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9144 CE(fmstat, ef1fa10, 0, (), noargs),
9145 CE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9146 CE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9147 CE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9148 CE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9149 CE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9150 CE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9151 CE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9152 CE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
9153
9154 /* Memory operations. */
9155 CE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9156 CE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9157 CE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9158 CE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9159 CE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9160 CE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9161 CE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9162 CE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9163 CE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9164 CE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9165 CE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9166 CE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9167 CE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9168 CE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9169 CE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9170 CE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9171 CE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9172 CE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 9173
c19d1205
ZW
9174 /* Monadic operations. */
9175 CE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9176 CE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9177 CE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
9178
9179 /* Dyadic operations. */
9180 CE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9181 CE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9182 CE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9183 CE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9184 CE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9185 CE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9186 CE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9187 CE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9188 CE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 9189
c19d1205
ZW
9190 /* Comparisons. */
9191 CE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9192 CE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9193 CE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9194 CE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 9195
c19d1205
ZW
9196#undef ARM_VARIANT
9197#define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
9198 /* Moves and type conversions. */
9199 CE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9200 CE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9201 CE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9202 CE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9203 CE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9204 CE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9205 CE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9206 CE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9207 CE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9208 CE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9209 CE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9210 CE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9211 CE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9212
9213 /* Memory operations. */
9214 CE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9215 CE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9216 CE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9217 CE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9218 CE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9219 CE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9220 CE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9221 CE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9222 CE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9223 CE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9224
c19d1205
ZW
9225 /* Monadic operations. */
9226 CE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9227 CE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9228 CE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9229
9230 /* Dyadic operations. */
9231 CE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9232 CE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9233 CE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9234 CE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9235 CE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9236 CE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9237 CE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9238 CE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9239 CE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9240
c19d1205
ZW
9241 /* Comparisons. */
9242 CE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9243 CE(fcmpzd, eb50b40, 1, (RVD), rd),
9244 CE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9245 CE(fcmpezd, eb50bc0, 1, (RVD), rd),
9246
9247#undef ARM_VARIANT
9248#define ARM_VARIANT FPU_VFP_EXT_V2
9249 CE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9250 CE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9251 CE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9252 CE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9253
9254#undef ARM_VARIANT
9255#define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
9256 CE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9257 CE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9258 CE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9259 CE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9260 CE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9261 CE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9262 CE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9263 CE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9264
9265#undef ARM_VARIANT
9266#define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
9267 CE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9268 CE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9269 CE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9270 CE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9271 CE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9272 CE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9273 CE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9274 CE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9275 CE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9276 CE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9277 CE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9278 CE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9279 CE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9280 CE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9281 CE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9282 CE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9283 CE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9284 CE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9285 CE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9286 CE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9287 CE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9288 CE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9289 CE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9290 CE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9291 CE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9292 CE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9293 CE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9294 CE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9295 CE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9296 CE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9297 CE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9298 CE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9299 CE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9300 CE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9301 CE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9302 CE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9303 CE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9304 CE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9305 CE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9306 CE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9307 CE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9308 CE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9309 CE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9310 CE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9311 CE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9312 CE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9313 CE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9314 CE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9315 CE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9316 CE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9317 CE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9318 CE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9319 CE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9320 CE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9321 CE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9322 CE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9323 CE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9324 CE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9325 CE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9326 CE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9327 CE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9328 CE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9329 CE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9330 CE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9331 CE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9332 CE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9333 CE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9334 CE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9335 CE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9336 CE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9337 CE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9338 CE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9339 CE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9340 CE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9341 CE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9342 CE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9343 CE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9344 CE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9345 CE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9346 CE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9347 CE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9348 CE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9349 CE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9350 CE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9351 CE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9352 CE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9353 CE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9354 CE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9355 CE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9356 CE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9357 CE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9358 CE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9359 CE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9360 CE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9361 CE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9362 CE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9363 CE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9364 CE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9365 CE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9366 CE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9367 CE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9368 CE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9369 CE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9370 CE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9371 CE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9372 CE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9373 CE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9374 CE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9375 CE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9376 CE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9377 CE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9378 CE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9379 CE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9380 CE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9381 CE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9382 CE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9383 CE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9384 CE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9385 CE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9386 CE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9387 CE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9388 CE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9389 CE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9390 CE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9391 CE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9392 CE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9393 CE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9394 CE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9395 CE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9396 CE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9397 CE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9398 CE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9399 CE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9400 CE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9401 CE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9402 CE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9403 CE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9404 CE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9405 CE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9406 CE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9407 CE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9408 CE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9409 CE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9410 CE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9411 CE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9412 CE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9413 CE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9414 CE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9415 CE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9416 CE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9417 CE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9418 CE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9419 CE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9420 CE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9421 CE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9422 CE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9423 CE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9424 CE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9425 CE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9426 CE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9427 CE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9428 CE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
9429
9430#undef ARM_VARIANT
9431#define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
9432 CE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9433 CE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9434 CE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9435 CE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9436 CE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9437 CE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9438 CE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9439 CE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9440 CE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9441 CE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9442 CE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9443 CE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9444 CE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9445 CE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9446 CE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9447 CE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9448 CE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9449 CE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9450 CE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9451 CE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9452 CE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9453 CE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9454 CE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9455 CE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9456 CE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9457 CE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9458 CE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9459 CE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9460 CE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9461 CE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9462 CE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9463 CE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9464 CE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9465 CE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9466 CE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9467 CE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9468 CE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9469 CE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9470 CE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9471 CE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9472 CE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9473 CE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9474 CE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9475 CE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9476 CE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9477 CE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9478 CE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9479 CE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9480 CE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9481 CE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9482 CE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9483 CE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9484 CE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9485 CE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9486 CE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9487 CE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9488 CE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9489 CE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9490 CE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9491 CE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9492 CE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9493 CE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9494 CE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9495 CE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9496 CE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9497 CE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9498 CE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9499 CE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9500 CE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9501 CE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9502 CE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9503 CE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9504 CE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9505 CE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9506 CE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9507 CE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9508};
9509#undef ARM_VARIANT
9510#undef THUMB_VARIANT
9511#undef TCE
9512#undef TCM
9513#undef TUE
9514#undef TUF
9515#undef TCC
9516#undef CE
9517#undef CM
9518#undef UE
9519#undef UF
9520#undef UT
9521#undef OPS0
9522#undef OPS1
9523#undef OPS2
9524#undef OPS3
9525#undef OPS4
9526#undef OPS5
9527#undef OPS6
9528#undef do_0
9529\f
9530/* MD interface: bits in the object file. */
bfae80f2 9531
c19d1205
ZW
9532/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9533 for use in the a.out file, and stores them in the array pointed to by buf.
9534 This knows about the endian-ness of the target machine and does
9535 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9536 2 (short) and 4 (long) Floating numbers are put out as a series of
9537 LITTLENUMS (shorts, here at least). */
b99bd4ef 9538
c19d1205
ZW
9539void
9540md_number_to_chars (char * buf, valueT val, int n)
9541{
9542 if (target_big_endian)
9543 number_to_chars_bigendian (buf, val, n);
9544 else
9545 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
9546}
9547
c19d1205
ZW
9548static valueT
9549md_chars_to_number (char * buf, int n)
bfae80f2 9550{
c19d1205
ZW
9551 valueT result = 0;
9552 unsigned char * where = (unsigned char *) buf;
bfae80f2 9553
c19d1205 9554 if (target_big_endian)
b99bd4ef 9555 {
c19d1205
ZW
9556 while (n--)
9557 {
9558 result <<= 8;
9559 result |= (*where++ & 255);
9560 }
b99bd4ef 9561 }
c19d1205 9562 else
b99bd4ef 9563 {
c19d1205
ZW
9564 while (n--)
9565 {
9566 result <<= 8;
9567 result |= (where[n] & 255);
9568 }
bfae80f2 9569 }
b99bd4ef 9570
c19d1205 9571 return result;
bfae80f2 9572}
b99bd4ef 9573
c19d1205 9574/* MD interface: Sections. */
b99bd4ef 9575
c19d1205
ZW
9576int
9577md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
9578 segT segtype ATTRIBUTE_UNUSED)
9579{
9580 as_fatal (_("md_estimate_size_before_relax\n"));
9581 return 1;
9582}
b99bd4ef 9583
c19d1205 9584/* Round up a section size to the appropriate boundary. */
b99bd4ef 9585
c19d1205
ZW
9586valueT
9587md_section_align (segT segment ATTRIBUTE_UNUSED,
9588 valueT size)
9589{
9590#ifdef OBJ_ELF
9591 return size;
9592#else
9593 /* Round all sects to multiple of 4. */
9594 return (size + 3) & ~3;
9595#endif
bfae80f2 9596}
b99bd4ef 9597
c19d1205
ZW
9598/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
9599 of an rs_align_code fragment. */
9600
9601void
9602arm_handle_align (fragS * fragP)
bfae80f2 9603{
c19d1205
ZW
9604 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
9605 static char const thumb_noop[2] = { 0xc0, 0x46 };
9606 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
9607 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
9608
9609 int bytes, fix, noop_size;
9610 char * p;
9611 const char * noop;
bfae80f2 9612
c19d1205 9613 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
9614 return;
9615
c19d1205
ZW
9616 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
9617 p = fragP->fr_literal + fragP->fr_fix;
9618 fix = 0;
bfae80f2 9619
c19d1205
ZW
9620 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
9621 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 9622
c19d1205 9623 if (fragP->tc_frag_data)
a737bd4d 9624 {
c19d1205
ZW
9625 if (target_big_endian)
9626 noop = thumb_bigend_noop;
9627 else
9628 noop = thumb_noop;
9629 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
9630 }
9631 else
9632 {
c19d1205
ZW
9633 if (target_big_endian)
9634 noop = arm_bigend_noop;
9635 else
9636 noop = arm_noop;
9637 noop_size = sizeof (arm_noop);
7ed4c4c5 9638 }
a737bd4d 9639
c19d1205 9640 if (bytes & (noop_size - 1))
7ed4c4c5 9641 {
c19d1205
ZW
9642 fix = bytes & (noop_size - 1);
9643 memset (p, 0, fix);
9644 p += fix;
9645 bytes -= fix;
a737bd4d 9646 }
a737bd4d 9647
c19d1205 9648 while (bytes >= noop_size)
a737bd4d 9649 {
c19d1205
ZW
9650 memcpy (p, noop, noop_size);
9651 p += noop_size;
9652 bytes -= noop_size;
9653 fix += noop_size;
a737bd4d
NC
9654 }
9655
c19d1205
ZW
9656 fragP->fr_fix += fix;
9657 fragP->fr_var = noop_size;
a737bd4d
NC
9658}
9659
c19d1205
ZW
9660/* Called from md_do_align. Used to create an alignment
9661 frag in a code section. */
9662
9663void
9664arm_frag_align_code (int n, int max)
bfae80f2 9665{
c19d1205 9666 char * p;
7ed4c4c5 9667
c19d1205
ZW
9668 /* We assume that there will never be a requirement
9669 to support alignments greater than 32 bytes. */
9670 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
9671 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 9672
c19d1205
ZW
9673 p = frag_var (rs_align_code,
9674 MAX_MEM_FOR_RS_ALIGN_CODE,
9675 1,
9676 (relax_substateT) max,
9677 (symbolS *) NULL,
9678 (offsetT) n,
9679 (char *) NULL);
9680 *p = 0;
9681}
bfae80f2 9682
c19d1205 9683/* Perform target specific initialisation of a frag. */
bfae80f2 9684
c19d1205
ZW
9685void
9686arm_init_frag (fragS * fragP)
9687{
9688 /* Record whether this frag is in an ARM or a THUMB area. */
9689 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
9690}
9691
c19d1205
ZW
9692#ifdef OBJ_ELF
9693/* When we change sections we need to issue a new mapping symbol. */
9694
9695void
9696arm_elf_change_section (void)
bfae80f2 9697{
c19d1205
ZW
9698 flagword flags;
9699 segment_info_type *seginfo;
bfae80f2 9700
c19d1205
ZW
9701 /* Link an unlinked unwind index table section to the .text section. */
9702 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
9703 && elf_linked_to_section (now_seg) == NULL)
9704 elf_linked_to_section (now_seg) = text_section;
9705
9706 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
9707 return;
9708
c19d1205
ZW
9709 flags = bfd_get_section_flags (stdoutput, now_seg);
9710
9711 /* We can ignore sections that only contain debug info. */
9712 if ((flags & SEC_ALLOC) == 0)
9713 return;
bfae80f2 9714
c19d1205
ZW
9715 seginfo = seg_info (now_seg);
9716 mapstate = seginfo->tc_segment_info_data.mapstate;
9717 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
9718}
9719
c19d1205
ZW
9720int
9721arm_elf_section_type (const char * str, size_t len)
e45d0630 9722{
c19d1205
ZW
9723 if (len == 5 && strncmp (str, "exidx", 5) == 0)
9724 return SHT_ARM_EXIDX;
e45d0630 9725
c19d1205
ZW
9726 return -1;
9727}
9728\f
9729/* Code to deal with unwinding tables. */
e45d0630 9730
c19d1205 9731static void add_unwind_adjustsp (offsetT);
e45d0630 9732
c19d1205 9733/* Cenerate and deferred unwind frame offset. */
e45d0630 9734
bfae80f2 9735static void
c19d1205 9736flush_pending_unwind (void)
bfae80f2 9737{
c19d1205 9738 offsetT offset;
bfae80f2 9739
c19d1205
ZW
9740 offset = unwind.pending_offset;
9741 unwind.pending_offset = 0;
9742 if (offset != 0)
9743 add_unwind_adjustsp (offset);
bfae80f2
RE
9744}
9745
c19d1205
ZW
9746/* Add an opcode to this list for this function. Two-byte opcodes should
9747 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
9748 order. */
9749
bfae80f2 9750static void
c19d1205 9751add_unwind_opcode (valueT op, int length)
bfae80f2 9752{
c19d1205
ZW
9753 /* Add any deferred stack adjustment. */
9754 if (unwind.pending_offset)
9755 flush_pending_unwind ();
bfae80f2 9756
c19d1205 9757 unwind.sp_restored = 0;
bfae80f2 9758
c19d1205 9759 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 9760 {
c19d1205
ZW
9761 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
9762 if (unwind.opcodes)
9763 unwind.opcodes = xrealloc (unwind.opcodes,
9764 unwind.opcode_alloc);
9765 else
9766 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 9767 }
c19d1205 9768 while (length > 0)
bfae80f2 9769 {
c19d1205
ZW
9770 length--;
9771 unwind.opcodes[unwind.opcode_count] = op & 0xff;
9772 op >>= 8;
9773 unwind.opcode_count++;
bfae80f2 9774 }
bfae80f2
RE
9775}
9776
c19d1205
ZW
9777/* Add unwind opcodes to adjust the stack pointer. */
9778
bfae80f2 9779static void
c19d1205 9780add_unwind_adjustsp (offsetT offset)
bfae80f2 9781{
c19d1205 9782 valueT op;
bfae80f2 9783
c19d1205 9784 if (offset > 0x200)
bfae80f2 9785 {
c19d1205
ZW
9786 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
9787 char bytes[5];
9788 int n;
9789 valueT o;
bfae80f2 9790
c19d1205
ZW
9791 /* Long form: 0xb2, uleb128. */
9792 /* This might not fit in a word so add the individual bytes,
9793 remembering the list is built in reverse order. */
9794 o = (valueT) ((offset - 0x204) >> 2);
9795 if (o == 0)
9796 add_unwind_opcode (0, 1);
bfae80f2 9797
c19d1205
ZW
9798 /* Calculate the uleb128 encoding of the offset. */
9799 n = 0;
9800 while (o)
9801 {
9802 bytes[n] = o & 0x7f;
9803 o >>= 7;
9804 if (o)
9805 bytes[n] |= 0x80;
9806 n++;
9807 }
9808 /* Add the insn. */
9809 for (; n; n--)
9810 add_unwind_opcode (bytes[n - 1], 1);
9811 add_unwind_opcode (0xb2, 1);
9812 }
9813 else if (offset > 0x100)
bfae80f2 9814 {
c19d1205
ZW
9815 /* Two short opcodes. */
9816 add_unwind_opcode (0x3f, 1);
9817 op = (offset - 0x104) >> 2;
9818 add_unwind_opcode (op, 1);
bfae80f2 9819 }
c19d1205
ZW
9820 else if (offset > 0)
9821 {
9822 /* Short opcode. */
9823 op = (offset - 4) >> 2;
9824 add_unwind_opcode (op, 1);
9825 }
9826 else if (offset < 0)
bfae80f2 9827 {
c19d1205
ZW
9828 offset = -offset;
9829 while (offset > 0x100)
bfae80f2 9830 {
c19d1205
ZW
9831 add_unwind_opcode (0x7f, 1);
9832 offset -= 0x100;
bfae80f2 9833 }
c19d1205
ZW
9834 op = ((offset - 4) >> 2) | 0x40;
9835 add_unwind_opcode (op, 1);
bfae80f2 9836 }
bfae80f2
RE
9837}
9838
c19d1205
ZW
9839/* Finish the list of unwind opcodes for this function. */
9840static void
9841finish_unwind_opcodes (void)
bfae80f2 9842{
c19d1205 9843 valueT op;
bfae80f2 9844
c19d1205 9845 if (unwind.fp_used)
bfae80f2 9846 {
c19d1205
ZW
9847 /* Adjust sp as neccessary. */
9848 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
9849 flush_pending_unwind ();
bfae80f2 9850
c19d1205
ZW
9851 /* After restoring sp from the frame pointer. */
9852 op = 0x90 | unwind.fp_reg;
9853 add_unwind_opcode (op, 1);
9854 }
9855 else
9856 flush_pending_unwind ();
bfae80f2
RE
9857}
9858
bfae80f2 9859
c19d1205
ZW
9860/* Start an exception table entry. If idx is nonzero this is an index table
9861 entry. */
bfae80f2
RE
9862
9863static void
c19d1205 9864start_unwind_section (const segT text_seg, int idx)
bfae80f2 9865{
c19d1205
ZW
9866 const char * text_name;
9867 const char * prefix;
9868 const char * prefix_once;
9869 const char * group_name;
9870 size_t prefix_len;
9871 size_t text_len;
9872 char * sec_name;
9873 size_t sec_name_len;
9874 int type;
9875 int flags;
9876 int linkonce;
bfae80f2 9877
c19d1205 9878 if (idx)
bfae80f2 9879 {
c19d1205
ZW
9880 prefix = ELF_STRING_ARM_unwind;
9881 prefix_once = ELF_STRING_ARM_unwind_once;
9882 type = SHT_ARM_EXIDX;
bfae80f2 9883 }
c19d1205 9884 else
bfae80f2 9885 {
c19d1205
ZW
9886 prefix = ELF_STRING_ARM_unwind_info;
9887 prefix_once = ELF_STRING_ARM_unwind_info_once;
9888 type = SHT_PROGBITS;
bfae80f2
RE
9889 }
9890
c19d1205
ZW
9891 text_name = segment_name (text_seg);
9892 if (streq (text_name, ".text"))
9893 text_name = "";
9894
9895 if (strncmp (text_name, ".gnu.linkonce.t.",
9896 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 9897 {
c19d1205
ZW
9898 prefix = prefix_once;
9899 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
9900 }
9901
c19d1205
ZW
9902 prefix_len = strlen (prefix);
9903 text_len = strlen (text_name);
9904 sec_name_len = prefix_len + text_len;
9905 sec_name = xmalloc (sec_name_len + 1);
9906 memcpy (sec_name, prefix, prefix_len);
9907 memcpy (sec_name + prefix_len, text_name, text_len);
9908 sec_name[prefix_len + text_len] = '\0';
bfae80f2 9909
c19d1205
ZW
9910 flags = SHF_ALLOC;
9911 linkonce = 0;
9912 group_name = 0;
bfae80f2 9913
c19d1205
ZW
9914 /* Handle COMDAT group. */
9915 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 9916 {
c19d1205
ZW
9917 group_name = elf_group_name (text_seg);
9918 if (group_name == NULL)
9919 {
9920 as_bad ("Group section `%s' has no group signature",
9921 segment_name (text_seg));
9922 ignore_rest_of_line ();
9923 return;
9924 }
9925 flags |= SHF_GROUP;
9926 linkonce = 1;
bfae80f2
RE
9927 }
9928
c19d1205 9929 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 9930
c19d1205
ZW
9931 /* Set the setion link for index tables. */
9932 if (idx)
9933 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
9934}
9935
bfae80f2 9936
c19d1205
ZW
9937/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
9938 personality routine data. Returns zero, or the index table value for
9939 and inline entry. */
9940
9941static valueT
9942create_unwind_entry (int have_data)
bfae80f2 9943{
c19d1205
ZW
9944 int size;
9945 addressT where;
9946 char *ptr;
9947 /* The current word of data. */
9948 valueT data;
9949 /* The number of bytes left in this word. */
9950 int n;
bfae80f2 9951
c19d1205 9952 finish_unwind_opcodes ();
bfae80f2 9953
c19d1205
ZW
9954 /* Remember the current text section. */
9955 unwind.saved_seg = now_seg;
9956 unwind.saved_subseg = now_subseg;
bfae80f2 9957
c19d1205 9958 start_unwind_section (now_seg, 0);
bfae80f2 9959
c19d1205 9960 if (unwind.personality_routine == NULL)
bfae80f2 9961 {
c19d1205
ZW
9962 if (unwind.personality_index == -2)
9963 {
9964 if (have_data)
9965 as_bad (_("handerdata in cantunwind frame"));
9966 return 1; /* EXIDX_CANTUNWIND. */
9967 }
bfae80f2 9968
c19d1205
ZW
9969 /* Use a default personality routine if none is specified. */
9970 if (unwind.personality_index == -1)
9971 {
9972 if (unwind.opcode_count > 3)
9973 unwind.personality_index = 1;
9974 else
9975 unwind.personality_index = 0;
9976 }
bfae80f2 9977
c19d1205
ZW
9978 /* Space for the personality routine entry. */
9979 if (unwind.personality_index == 0)
9980 {
9981 if (unwind.opcode_count > 3)
9982 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 9983
c19d1205
ZW
9984 if (!have_data)
9985 {
9986 /* All the data is inline in the index table. */
9987 data = 0x80;
9988 n = 3;
9989 while (unwind.opcode_count > 0)
9990 {
9991 unwind.opcode_count--;
9992 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9993 n--;
9994 }
bfae80f2 9995
c19d1205
ZW
9996 /* Pad with "finish" opcodes. */
9997 while (n--)
9998 data = (data << 8) | 0xb0;
bfae80f2 9999
c19d1205
ZW
10000 return data;
10001 }
10002 size = 0;
10003 }
10004 else
10005 /* We get two opcodes "free" in the first word. */
10006 size = unwind.opcode_count - 2;
10007 }
10008 else
10009 /* An extra byte is required for the opcode count. */
10010 size = unwind.opcode_count + 1;
bfae80f2 10011
c19d1205
ZW
10012 size = (size + 3) >> 2;
10013 if (size > 0xff)
10014 as_bad (_("too many unwind opcodes"));
bfae80f2 10015
c19d1205
ZW
10016 frag_align (2, 0, 0);
10017 record_alignment (now_seg, 2);
10018 unwind.table_entry = expr_build_dot ();
10019
10020 /* Allocate the table entry. */
10021 ptr = frag_more ((size << 2) + 4);
10022 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 10023
c19d1205 10024 switch (unwind.personality_index)
bfae80f2 10025 {
c19d1205
ZW
10026 case -1:
10027 /* ??? Should this be a PLT generating relocation? */
10028 /* Custom personality routine. */
10029 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
10030 BFD_RELOC_ARM_PREL31);
bfae80f2 10031
c19d1205
ZW
10032 where += 4;
10033 ptr += 4;
bfae80f2 10034
c19d1205
ZW
10035 /* Set the first byte to the number of additional words. */
10036 data = size - 1;
10037 n = 3;
10038 break;
bfae80f2 10039
c19d1205
ZW
10040 /* ABI defined personality routines. */
10041 case 0:
10042 /* Three opcodes bytes are packed into the first word. */
10043 data = 0x80;
10044 n = 3;
10045 break;
bfae80f2 10046
c19d1205
ZW
10047 case 1:
10048 case 2:
10049 /* The size and first two opcode bytes go in the first word. */
10050 data = ((0x80 + unwind.personality_index) << 8) | size;
10051 n = 2;
10052 break;
bfae80f2 10053
c19d1205
ZW
10054 default:
10055 /* Should never happen. */
10056 abort ();
10057 }
bfae80f2 10058
c19d1205
ZW
10059 /* Pack the opcodes into words (MSB first), reversing the list at the same
10060 time. */
10061 while (unwind.opcode_count > 0)
10062 {
10063 if (n == 0)
10064 {
10065 md_number_to_chars (ptr, data, 4);
10066 ptr += 4;
10067 n = 4;
10068 data = 0;
10069 }
10070 unwind.opcode_count--;
10071 n--;
10072 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10073 }
10074
10075 /* Finish off the last word. */
10076 if (n < 4)
10077 {
10078 /* Pad with "finish" opcodes. */
10079 while (n--)
10080 data = (data << 8) | 0xb0;
10081
10082 md_number_to_chars (ptr, data, 4);
10083 }
10084
10085 if (!have_data)
10086 {
10087 /* Add an empty descriptor if there is no user-specified data. */
10088 ptr = frag_more (4);
10089 md_number_to_chars (ptr, 0, 4);
10090 }
10091
10092 return 0;
bfae80f2
RE
10093}
10094
c19d1205
ZW
10095/* Convert REGNAME to a DWARF-2 register number. */
10096
10097int
10098tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 10099{
c19d1205
ZW
10100 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
10101
10102 if (reg == FAIL)
10103 return -1;
10104
10105 return reg;
bfae80f2
RE
10106}
10107
c19d1205
ZW
10108/* Initialize the DWARF-2 unwind information for this procedure. */
10109
10110void
10111tc_arm_frame_initial_instructions (void)
bfae80f2 10112{
c19d1205 10113 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 10114}
c19d1205 10115#endif /* OBJ_ELF */
bfae80f2 10116
bfae80f2 10117
c19d1205 10118/* MD interface: Symbol and relocation handling. */
bfae80f2 10119
2fc8bdac
ZW
10120/* Return the address within the segment that a PC-relative fixup is
10121 relative to. For ARM, PC-relative fixups applied to instructions
10122 are generally relative to the location of the fixup plus 8 bytes.
10123 Thumb branches are offset by 4, and Thumb loads relative to PC
10124 require special handling. */
bfae80f2 10125
c19d1205 10126long
2fc8bdac 10127md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 10128{
2fc8bdac
ZW
10129 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
10130
10131 /* If this is pc-relative and we are going to emit a relocation
10132 then we just want to put out any pipeline compensation that the linker
10133 will need. Otherwise we want to use the calculated base. */
10134 if (fixP->fx_pcrel
10135 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10136 || arm_force_relocation (fixP)))
10137 base = 0;
bfae80f2 10138
c19d1205 10139 switch (fixP->fx_r_type)
bfae80f2 10140 {
2fc8bdac
ZW
10141 /* PC relative addressing on the Thumb is slightly odd as the
10142 bottom two bits of the PC are forced to zero for the
10143 calculation. This happens *after* application of the
10144 pipeline offset. However, Thumb adrl already adjusts for
10145 this, so we need not do it again. */
c19d1205 10146 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 10147 return base & ~3;
c19d1205
ZW
10148
10149 case BFD_RELOC_ARM_THUMB_OFFSET:
10150 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 10151 case BFD_RELOC_ARM_T32_ADD_PC12:
2fc8bdac 10152 return (base + 4) & ~3;
c19d1205 10153
2fc8bdac
ZW
10154 /* Thumb branches are simply offset by +4. */
10155 case BFD_RELOC_THUMB_PCREL_BRANCH7:
10156 case BFD_RELOC_THUMB_PCREL_BRANCH9:
10157 case BFD_RELOC_THUMB_PCREL_BRANCH12:
10158 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10159 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10160 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10161 case BFD_RELOC_THUMB_PCREL_BLX:
10162 return base + 4;
bfae80f2 10163
2fc8bdac
ZW
10164 /* ARM mode branches are offset by +8. However, the Windows CE
10165 loader expects the relocation not to take this into account. */
10166 case BFD_RELOC_ARM_PCREL_BRANCH:
10167 case BFD_RELOC_ARM_PCREL_BLX:
10168 case BFD_RELOC_ARM_PLT32:
c19d1205 10169#ifdef TE_WINCE
2fc8bdac 10170 return base;
c19d1205 10171#else
2fc8bdac 10172 return base + 8;
c19d1205 10173#endif
2fc8bdac
ZW
10174
10175 /* ARM mode loads relative to PC are also offset by +8. Unlike
10176 branches, the Windows CE loader *does* expect the relocation
10177 to take this into account. */
10178 case BFD_RELOC_ARM_OFFSET_IMM:
10179 case BFD_RELOC_ARM_OFFSET_IMM8:
10180 case BFD_RELOC_ARM_HWLITERAL:
10181 case BFD_RELOC_ARM_LITERAL:
10182 case BFD_RELOC_ARM_CP_OFF_IMM:
10183 return base + 8;
10184
10185
10186 /* Other PC-relative relocations are un-offset. */
10187 default:
10188 return base;
10189 }
bfae80f2
RE
10190}
10191
c19d1205
ZW
10192/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
10193 Otherwise we have no need to default values of symbols. */
10194
10195symbolS *
10196md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 10197{
c19d1205
ZW
10198#ifdef OBJ_ELF
10199 if (name[0] == '_' && name[1] == 'G'
10200 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
10201 {
10202 if (!GOT_symbol)
10203 {
10204 if (symbol_find (name))
10205 as_bad ("GOT already in the symbol table");
bfae80f2 10206
c19d1205
ZW
10207 GOT_symbol = symbol_new (name, undefined_section,
10208 (valueT) 0, & zero_address_frag);
10209 }
bfae80f2 10210
c19d1205 10211 return GOT_symbol;
bfae80f2 10212 }
c19d1205 10213#endif
bfae80f2 10214
c19d1205 10215 return 0;
bfae80f2
RE
10216}
10217
55cf6793 10218/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
10219 computed as two separate immediate values, added together. We
10220 already know that this value cannot be computed by just one ARM
10221 instruction. */
10222
10223static unsigned int
10224validate_immediate_twopart (unsigned int val,
10225 unsigned int * highpart)
bfae80f2 10226{
c19d1205
ZW
10227 unsigned int a;
10228 unsigned int i;
bfae80f2 10229
c19d1205
ZW
10230 for (i = 0; i < 32; i += 2)
10231 if (((a = rotate_left (val, i)) & 0xff) != 0)
10232 {
10233 if (a & 0xff00)
10234 {
10235 if (a & ~ 0xffff)
10236 continue;
10237 * highpart = (a >> 8) | ((i + 24) << 7);
10238 }
10239 else if (a & 0xff0000)
10240 {
10241 if (a & 0xff000000)
10242 continue;
10243 * highpart = (a >> 16) | ((i + 16) << 7);
10244 }
10245 else
10246 {
10247 assert (a & 0xff000000);
10248 * highpart = (a >> 24) | ((i + 8) << 7);
10249 }
bfae80f2 10250
c19d1205
ZW
10251 return (a & 0xff) | (i << 7);
10252 }
bfae80f2 10253
c19d1205 10254 return FAIL;
bfae80f2
RE
10255}
10256
c19d1205
ZW
10257static int
10258validate_offset_imm (unsigned int val, int hwse)
10259{
10260 if ((hwse && val > 255) || val > 4095)
10261 return FAIL;
10262 return val;
10263}
bfae80f2 10264
55cf6793 10265/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
10266 negative immediate constant by altering the instruction. A bit of
10267 a hack really.
10268 MOV <-> MVN
10269 AND <-> BIC
10270 ADC <-> SBC
10271 by inverting the second operand, and
10272 ADD <-> SUB
10273 CMP <-> CMN
10274 by negating the second operand. */
bfae80f2 10275
c19d1205
ZW
10276static int
10277negate_data_op (unsigned long * instruction,
10278 unsigned long value)
bfae80f2 10279{
c19d1205
ZW
10280 int op, new_inst;
10281 unsigned long negated, inverted;
bfae80f2 10282
c19d1205
ZW
10283 negated = encode_arm_immediate (-value);
10284 inverted = encode_arm_immediate (~value);
bfae80f2 10285
c19d1205
ZW
10286 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10287 switch (op)
bfae80f2 10288 {
c19d1205
ZW
10289 /* First negates. */
10290 case OPCODE_SUB: /* ADD <-> SUB */
10291 new_inst = OPCODE_ADD;
10292 value = negated;
10293 break;
bfae80f2 10294
c19d1205
ZW
10295 case OPCODE_ADD:
10296 new_inst = OPCODE_SUB;
10297 value = negated;
10298 break;
bfae80f2 10299
c19d1205
ZW
10300 case OPCODE_CMP: /* CMP <-> CMN */
10301 new_inst = OPCODE_CMN;
10302 value = negated;
10303 break;
bfae80f2 10304
c19d1205
ZW
10305 case OPCODE_CMN:
10306 new_inst = OPCODE_CMP;
10307 value = negated;
10308 break;
bfae80f2 10309
c19d1205
ZW
10310 /* Now Inverted ops. */
10311 case OPCODE_MOV: /* MOV <-> MVN */
10312 new_inst = OPCODE_MVN;
10313 value = inverted;
10314 break;
bfae80f2 10315
c19d1205
ZW
10316 case OPCODE_MVN:
10317 new_inst = OPCODE_MOV;
10318 value = inverted;
10319 break;
bfae80f2 10320
c19d1205
ZW
10321 case OPCODE_AND: /* AND <-> BIC */
10322 new_inst = OPCODE_BIC;
10323 value = inverted;
10324 break;
bfae80f2 10325
c19d1205
ZW
10326 case OPCODE_BIC:
10327 new_inst = OPCODE_AND;
10328 value = inverted;
10329 break;
bfae80f2 10330
c19d1205
ZW
10331 case OPCODE_ADC: /* ADC <-> SBC */
10332 new_inst = OPCODE_SBC;
10333 value = inverted;
10334 break;
bfae80f2 10335
c19d1205
ZW
10336 case OPCODE_SBC:
10337 new_inst = OPCODE_ADC;
10338 value = inverted;
10339 break;
bfae80f2 10340
c19d1205
ZW
10341 /* We cannot do anything. */
10342 default:
10343 return FAIL;
b99bd4ef
NC
10344 }
10345
c19d1205
ZW
10346 if (value == (unsigned) FAIL)
10347 return FAIL;
10348
10349 *instruction &= OPCODE_MASK;
10350 *instruction |= new_inst << DATA_OP_SHIFT;
10351 return value;
b99bd4ef
NC
10352}
10353
c19d1205 10354void
55cf6793 10355md_apply_fix (fixS * fixP,
c19d1205
ZW
10356 valueT * valP,
10357 segT seg)
10358{
10359 offsetT value = * valP;
10360 offsetT newval;
10361 unsigned int newimm;
10362 unsigned long temp;
10363 int sign;
10364 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 10365
c19d1205 10366 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 10367
c19d1205
ZW
10368 /* Note whether this will delete the relocation. */
10369 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
10370 fixP->fx_done = 1;
b99bd4ef 10371
adbaf948
ZW
10372 /* On a 64-bit host, silently truncate 'value' to 32 bits for
10373 consistency with the behavior on 32-bit hosts. Remember value
10374 for emit_reloc. */
10375 value &= 0xffffffff;
10376 value ^= 0x80000000;
10377 value -= 0x80000000;
10378
10379 *valP = value;
c19d1205 10380 fixP->fx_addnumber = value;
b99bd4ef 10381
adbaf948
ZW
10382 /* Same treatment for fixP->fx_offset. */
10383 fixP->fx_offset &= 0xffffffff;
10384 fixP->fx_offset ^= 0x80000000;
10385 fixP->fx_offset -= 0x80000000;
10386
c19d1205 10387 switch (fixP->fx_r_type)
b99bd4ef 10388 {
c19d1205
ZW
10389 case BFD_RELOC_NONE:
10390 /* This will need to go in the object file. */
10391 fixP->fx_done = 0;
10392 break;
b99bd4ef 10393
c19d1205
ZW
10394 case BFD_RELOC_ARM_IMMEDIATE:
10395 /* We claim that this fixup has been processed here,
10396 even if in fact we generate an error because we do
10397 not have a reloc for it, so tc_gen_reloc will reject it. */
10398 fixP->fx_done = 1;
b99bd4ef 10399
c19d1205
ZW
10400 if (fixP->fx_addsy
10401 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 10402 {
c19d1205
ZW
10403 as_bad_where (fixP->fx_file, fixP->fx_line,
10404 _("undefined symbol %s used as an immediate value"),
10405 S_GET_NAME (fixP->fx_addsy));
10406 break;
b99bd4ef
NC
10407 }
10408
c19d1205
ZW
10409 newimm = encode_arm_immediate (value);
10410 temp = md_chars_to_number (buf, INSN_SIZE);
10411
10412 /* If the instruction will fail, see if we can fix things up by
10413 changing the opcode. */
10414 if (newimm == (unsigned int) FAIL
10415 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 10416 {
c19d1205
ZW
10417 as_bad_where (fixP->fx_file, fixP->fx_line,
10418 _("invalid constant (%lx) after fixup"),
10419 (unsigned long) value);
10420 break;
b99bd4ef 10421 }
b99bd4ef 10422
c19d1205
ZW
10423 newimm |= (temp & 0xfffff000);
10424 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
10425 break;
b99bd4ef 10426
c19d1205
ZW
10427 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
10428 {
10429 unsigned int highpart = 0;
10430 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 10431
c19d1205
ZW
10432 newimm = encode_arm_immediate (value);
10433 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 10434
c19d1205
ZW
10435 /* If the instruction will fail, see if we can fix things up by
10436 changing the opcode. */
10437 if (newimm == (unsigned int) FAIL
10438 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
10439 {
10440 /* No ? OK - try using two ADD instructions to generate
10441 the value. */
10442 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 10443
c19d1205
ZW
10444 /* Yes - then make sure that the second instruction is
10445 also an add. */
10446 if (newimm != (unsigned int) FAIL)
10447 newinsn = temp;
10448 /* Still No ? Try using a negated value. */
10449 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
10450 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
10451 /* Otherwise - give up. */
10452 else
10453 {
10454 as_bad_where (fixP->fx_file, fixP->fx_line,
10455 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
10456 (long) value);
10457 break;
10458 }
b99bd4ef 10459
c19d1205
ZW
10460 /* Replace the first operand in the 2nd instruction (which
10461 is the PC) with the destination register. We have
10462 already added in the PC in the first instruction and we
10463 do not want to do it again. */
10464 newinsn &= ~ 0xf0000;
10465 newinsn |= ((newinsn & 0x0f000) << 4);
10466 }
b99bd4ef 10467
c19d1205
ZW
10468 newimm |= (temp & 0xfffff000);
10469 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 10470
c19d1205
ZW
10471 highpart |= (newinsn & 0xfffff000);
10472 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
10473 }
10474 break;
b99bd4ef 10475
c19d1205
ZW
10476 case BFD_RELOC_ARM_OFFSET_IMM:
10477 case BFD_RELOC_ARM_LITERAL:
10478 sign = value >= 0;
b99bd4ef 10479
c19d1205
ZW
10480 if (value < 0)
10481 value = - value;
b99bd4ef 10482
c19d1205 10483 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 10484 {
c19d1205
ZW
10485 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
10486 as_bad_where (fixP->fx_file, fixP->fx_line,
10487 _("invalid literal constant: pool needs to be closer"));
10488 else
10489 as_bad_where (fixP->fx_file, fixP->fx_line,
10490 _("bad immediate value for offset (%ld)"),
10491 (long) value);
10492 break;
f03698e6
RE
10493 }
10494
c19d1205
ZW
10495 newval = md_chars_to_number (buf, INSN_SIZE);
10496 newval &= 0xff7ff000;
10497 newval |= value | (sign ? INDEX_UP : 0);
10498 md_number_to_chars (buf, newval, INSN_SIZE);
10499 break;
b99bd4ef 10500
c19d1205
ZW
10501 case BFD_RELOC_ARM_OFFSET_IMM8:
10502 case BFD_RELOC_ARM_HWLITERAL:
10503 sign = value >= 0;
b99bd4ef 10504
c19d1205
ZW
10505 if (value < 0)
10506 value = - value;
b99bd4ef 10507
c19d1205 10508 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 10509 {
c19d1205
ZW
10510 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
10511 as_bad_where (fixP->fx_file, fixP->fx_line,
10512 _("invalid literal constant: pool needs to be closer"));
10513 else
10514 as_bad (_("bad immediate value for half-word offset (%ld)"),
10515 (long) value);
10516 break;
b99bd4ef
NC
10517 }
10518
c19d1205
ZW
10519 newval = md_chars_to_number (buf, INSN_SIZE);
10520 newval &= 0xff7ff0f0;
10521 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
10522 md_number_to_chars (buf, newval, INSN_SIZE);
10523 break;
b99bd4ef 10524
c19d1205
ZW
10525 case BFD_RELOC_ARM_T32_OFFSET_U8:
10526 if (value < 0 || value > 1020 || value % 4 != 0)
10527 as_bad_where (fixP->fx_file, fixP->fx_line,
10528 _("bad immediate value for offset (%ld)"), (long) value);
10529 value /= 4;
b99bd4ef 10530
c19d1205 10531 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
10532 newval |= value;
10533 md_number_to_chars (buf+2, newval, THUMB_SIZE);
10534 break;
b99bd4ef 10535
c19d1205
ZW
10536 case BFD_RELOC_ARM_T32_OFFSET_IMM:
10537 /* This is a complicated relocation used for all varieties of Thumb32
10538 load/store instruction with immediate offset:
10539
10540 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
10541 *4, optional writeback(W)
10542 (doubleword load/store)
10543
10544 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
10545 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
10546 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
10547 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
10548 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
10549
10550 Uppercase letters indicate bits that are already encoded at
10551 this point. Lowercase letters are our problem. For the
10552 second block of instructions, the secondary opcode nybble
10553 (bits 8..11) is present, and bit 23 is zero, even if this is
10554 a PC-relative operation. */
10555 newval = md_chars_to_number (buf, THUMB_SIZE);
10556 newval <<= 16;
10557 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 10558
c19d1205 10559 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 10560 {
c19d1205
ZW
10561 /* Doubleword load/store: 8-bit offset, scaled by 4. */
10562 if (value >= 0)
10563 newval |= (1 << 23);
10564 else
10565 value = -value;
10566 if (value % 4 != 0)
10567 {
10568 as_bad_where (fixP->fx_file, fixP->fx_line,
10569 _("offset not a multiple of 4"));
10570 break;
10571 }
10572 value /= 4;
10573 if (value >= 0xff)
10574 {
10575 as_bad_where (fixP->fx_file, fixP->fx_line,
10576 _("offset out of range"));
10577 break;
10578 }
10579 newval &= ~0xff;
b99bd4ef 10580 }
c19d1205 10581 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 10582 {
c19d1205
ZW
10583 /* PC-relative, 12-bit offset. */
10584 if (value >= 0)
10585 newval |= (1 << 23);
10586 else
10587 value = -value;
10588 if (value >= 0xfff)
10589 {
10590 as_bad_where (fixP->fx_file, fixP->fx_line,
10591 _("offset out of range"));
10592 break;
10593 }
10594 newval &= ~0xfff;
b99bd4ef 10595 }
c19d1205 10596 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 10597 {
c19d1205
ZW
10598 /* Writeback: 8-bit, +/- offset. */
10599 if (value >= 0)
10600 newval |= (1 << 9);
10601 else
10602 value = -value;
10603 if (value >= 0xff)
10604 {
10605 as_bad_where (fixP->fx_file, fixP->fx_line,
10606 _("offset out of range"));
10607 break;
10608 }
10609 newval &= ~0xff;
b99bd4ef 10610 }
c19d1205 10611 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 10612 {
c19d1205
ZW
10613 /* T-instruction: positive 8-bit offset. */
10614 if (value < 0 || value >= 0xff)
b99bd4ef 10615 {
c19d1205
ZW
10616 as_bad_where (fixP->fx_file, fixP->fx_line,
10617 _("offset out of range"));
10618 break;
b99bd4ef 10619 }
c19d1205
ZW
10620 newval &= ~0xff;
10621 newval |= value;
b99bd4ef
NC
10622 }
10623 else
b99bd4ef 10624 {
c19d1205
ZW
10625 /* Positive 12-bit or negative 8-bit offset. */
10626 int limit;
10627 if (value >= 0)
b99bd4ef 10628 {
c19d1205
ZW
10629 newval |= (1 << 23);
10630 limit = 0xfff;
10631 }
10632 else
10633 {
10634 value = -value;
10635 limit = 0xff;
10636 }
10637 if (value > limit)
10638 {
10639 as_bad_where (fixP->fx_file, fixP->fx_line,
10640 _("offset out of range"));
10641 break;
b99bd4ef 10642 }
c19d1205 10643 newval &= ~limit;
b99bd4ef 10644 }
b99bd4ef 10645
c19d1205
ZW
10646 newval |= value;
10647 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
10648 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
10649 break;
404ff6b5 10650
c19d1205
ZW
10651 case BFD_RELOC_ARM_SHIFT_IMM:
10652 newval = md_chars_to_number (buf, INSN_SIZE);
10653 if (((unsigned long) value) > 32
10654 || (value == 32
10655 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
10656 {
10657 as_bad_where (fixP->fx_file, fixP->fx_line,
10658 _("shift expression is too large"));
10659 break;
10660 }
404ff6b5 10661
c19d1205
ZW
10662 if (value == 0)
10663 /* Shifts of zero must be done as lsl. */
10664 newval &= ~0x60;
10665 else if (value == 32)
10666 value = 0;
10667 newval &= 0xfffff07f;
10668 newval |= (value & 0x1f) << 7;
10669 md_number_to_chars (buf, newval, INSN_SIZE);
10670 break;
404ff6b5 10671
c19d1205 10672 case BFD_RELOC_ARM_T32_IMMEDIATE:
92e90b6e 10673 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 10674 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
10675 /* We claim that this fixup has been processed here,
10676 even if in fact we generate an error because we do
10677 not have a reloc for it, so tc_gen_reloc will reject it. */
10678 fixP->fx_done = 1;
404ff6b5 10679
c19d1205
ZW
10680 if (fixP->fx_addsy
10681 && ! S_IS_DEFINED (fixP->fx_addsy))
10682 {
10683 as_bad_where (fixP->fx_file, fixP->fx_line,
10684 _("undefined symbol %s used as an immediate value"),
10685 S_GET_NAME (fixP->fx_addsy));
10686 break;
10687 }
404ff6b5 10688
c19d1205
ZW
10689 newval = md_chars_to_number (buf, THUMB_SIZE);
10690 newval <<= 16;
10691 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 10692
e9f89963
PB
10693 /* FUTURE: Implement analogue of negate_data_op for T32. */
10694 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
10695 newimm = encode_thumb32_immediate (value);
10696 else
92e90b6e 10697 {
e9f89963
PB
10698 /* 12 bit immediate for addw/subw. */
10699 if (value < 0)
10700 {
10701 value = -value;
10702 newval ^= 0x00a00000;
10703 }
92e90b6e
PB
10704 if (value > 0xfff)
10705 newimm = (unsigned int) FAIL;
10706 else
10707 newimm = value;
10708 }
cc8a6dd0 10709
c19d1205 10710 if (newimm == (unsigned int)FAIL)
3631a3c8 10711 {
c19d1205
ZW
10712 as_bad_where (fixP->fx_file, fixP->fx_line,
10713 _("invalid constant (%lx) after fixup"),
10714 (unsigned long) value);
10715 break;
3631a3c8
NC
10716 }
10717
c19d1205
ZW
10718 newval |= (newimm & 0x800) << 15;
10719 newval |= (newimm & 0x700) << 4;
10720 newval |= (newimm & 0x0ff);
cc8a6dd0 10721
c19d1205
ZW
10722 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
10723 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
10724 break;
a737bd4d 10725
c19d1205
ZW
10726 case BFD_RELOC_ARM_SMI:
10727 if (((unsigned long) value) > 0xffff)
10728 as_bad_where (fixP->fx_file, fixP->fx_line,
10729 _("invalid smi expression"));
2fc8bdac 10730 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
10731 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
10732 md_number_to_chars (buf, newval, INSN_SIZE);
10733 break;
a737bd4d 10734
c19d1205 10735 case BFD_RELOC_ARM_SWI:
adbaf948 10736 if (fixP->tc_fix_data != 0)
c19d1205
ZW
10737 {
10738 if (((unsigned long) value) > 0xff)
10739 as_bad_where (fixP->fx_file, fixP->fx_line,
10740 _("invalid swi expression"));
2fc8bdac 10741 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
10742 newval |= value;
10743 md_number_to_chars (buf, newval, THUMB_SIZE);
10744 }
10745 else
10746 {
10747 if (((unsigned long) value) > 0x00ffffff)
10748 as_bad_where (fixP->fx_file, fixP->fx_line,
10749 _("invalid swi expression"));
2fc8bdac 10750 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
10751 newval |= value;
10752 md_number_to_chars (buf, newval, INSN_SIZE);
10753 }
10754 break;
a737bd4d 10755
c19d1205
ZW
10756 case BFD_RELOC_ARM_MULTI:
10757 if (((unsigned long) value) > 0xffff)
10758 as_bad_where (fixP->fx_file, fixP->fx_line,
10759 _("invalid expression in load/store multiple"));
10760 newval = value | md_chars_to_number (buf, INSN_SIZE);
10761 md_number_to_chars (buf, newval, INSN_SIZE);
10762 break;
a737bd4d 10763
c19d1205 10764 case BFD_RELOC_ARM_PCREL_BRANCH:
c19d1205 10765#ifdef OBJ_ELF
2fc8bdac 10766 case BFD_RELOC_ARM_PLT32:
c19d1205 10767#endif
a737bd4d 10768
c19d1205 10769 /* We are going to store value (shifted right by two) in the
2fc8bdac
ZW
10770 instruction, in a 24 bit, signed field. Bits 0 and 1 must be
10771 clear, and bits 26 through 32 either all clear or all set. */
10772 if (value & 0x00000003)
c19d1205 10773 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
10774 _("misaligned branch destination"));
10775 if ((value & (offsetT)0xfe000000) != (offsetT)0
10776 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
10777 as_bad_where (fixP->fx_file, fixP->fx_line,
10778 _("branch out of range"));
a737bd4d 10779
2fc8bdac 10780 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10781 {
2fc8bdac
ZW
10782 newval = md_chars_to_number (buf, INSN_SIZE);
10783 newval |= (value >> 2) & 0x00ffffff;
10784 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 10785 }
c19d1205 10786 break;
a737bd4d 10787
c19d1205 10788 case BFD_RELOC_ARM_PCREL_BLX:
2fc8bdac
ZW
10789 /* BLX allows bit 1 to be set in the branch destination, since
10790 it targets a Thumb instruction which is only required to be
10791 aligned modulo 2. Other constraints are as for B/BL. */
10792 if (value & 0x00000001)
10793 as_bad_where (fixP->fx_file, fixP->fx_line,
10794 _("misaligned BLX destination"));
10795 if ((value & (offsetT)0xfe000000) != (offsetT)0
10796 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
10797 as_bad_where (fixP->fx_file, fixP->fx_line,
10798 _("branch out of range"));
a737bd4d 10799
2fc8bdac
ZW
10800 if (fixP->fx_done || !seg->use_rela_p)
10801 {
10802 offsetT hbit;
10803 hbit = (value >> 1) & 1;
10804 value = (value >> 2) & 0x00ffffff;
a737bd4d 10805
2fc8bdac
ZW
10806 newval = md_chars_to_number (buf, INSN_SIZE);
10807 newval |= value | hbit << 24;
10808 md_number_to_chars (buf, newval, INSN_SIZE);
10809 }
c19d1205 10810 break;
a737bd4d 10811
c19d1205 10812 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
10813 /* CZB can only branch forward. */
10814 if (value & ~0x7e)
10815 as_bad_where (fixP->fx_file, fixP->fx_line,
10816 _("branch out of range"));
a737bd4d 10817
2fc8bdac
ZW
10818 if (fixP->fx_done || !seg->use_rela_p)
10819 {
10820 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205 10821 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
10822 md_number_to_chars (buf, newval, THUMB_SIZE);
10823 }
c19d1205 10824 break;
a737bd4d 10825
c19d1205 10826 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
10827 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
10828 as_bad_where (fixP->fx_file, fixP->fx_line,
10829 _("branch out of range"));
a737bd4d 10830
2fc8bdac
ZW
10831 if (fixP->fx_done || !seg->use_rela_p)
10832 {
10833 newval = md_chars_to_number (buf, THUMB_SIZE);
10834 newval |= (value & 0x1ff) >> 1;
10835 md_number_to_chars (buf, newval, THUMB_SIZE);
10836 }
c19d1205 10837 break;
a737bd4d 10838
c19d1205 10839 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
10840 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
10841 as_bad_where (fixP->fx_file, fixP->fx_line,
10842 _("branch out of range"));
a737bd4d 10843
2fc8bdac
ZW
10844 if (fixP->fx_done || !seg->use_rela_p)
10845 {
10846 newval = md_chars_to_number (buf, THUMB_SIZE);
10847 newval |= (value & 0xfff) >> 1;
10848 md_number_to_chars (buf, newval, THUMB_SIZE);
10849 }
c19d1205 10850 break;
a737bd4d 10851
c19d1205 10852 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
10853 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
10854 as_bad_where (fixP->fx_file, fixP->fx_line,
10855 _("conditional branch out of range"));
404ff6b5 10856
2fc8bdac
ZW
10857 if (fixP->fx_done || !seg->use_rela_p)
10858 {
10859 offsetT newval2;
10860 addressT S, J1, J2, lo, hi;
404ff6b5 10861
2fc8bdac
ZW
10862 S = (value & 0x00100000) >> 20;
10863 J2 = (value & 0x00080000) >> 19;
10864 J1 = (value & 0x00040000) >> 18;
10865 hi = (value & 0x0003f000) >> 12;
10866 lo = (value & 0x00000ffe) >> 1;
6c43fab6 10867
2fc8bdac
ZW
10868 newval = md_chars_to_number (buf, THUMB_SIZE);
10869 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10870 newval |= (S << 10) | hi;
10871 newval2 |= (J1 << 13) | (J2 << 11) | lo;
10872 md_number_to_chars (buf, newval, THUMB_SIZE);
10873 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10874 }
c19d1205 10875 break;
6c43fab6 10876
c19d1205
ZW
10877 case BFD_RELOC_THUMB_PCREL_BLX:
10878 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
10879 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
10880 as_bad_where (fixP->fx_file, fixP->fx_line,
10881 _("branch out of range"));
404ff6b5 10882
2fc8bdac
ZW
10883 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
10884 /* For a BLX instruction, make sure that the relocation is rounded up
10885 to a word boundary. This follows the semantics of the instruction
10886 which specifies that bit 1 of the target address will come from bit
10887 1 of the base address. */
10888 value = (value + 1) & ~ 1;
404ff6b5 10889
2fc8bdac 10890 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10891 {
2fc8bdac
ZW
10892 offsetT newval2;
10893
10894 newval = md_chars_to_number (buf, THUMB_SIZE);
10895 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10896 newval |= (value & 0x7fffff) >> 12;
10897 newval2 |= (value & 0xfff) >> 1;
10898 md_number_to_chars (buf, newval, THUMB_SIZE);
10899 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 10900 }
c19d1205 10901 break;
404ff6b5 10902
c19d1205 10903 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
10904 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
10905 as_bad_where (fixP->fx_file, fixP->fx_line,
10906 _("branch out of range"));
6c43fab6 10907
2fc8bdac
ZW
10908 if (fixP->fx_done || !seg->use_rela_p)
10909 {
10910 offsetT newval2;
10911 addressT S, I1, I2, lo, hi;
6c43fab6 10912
2fc8bdac
ZW
10913 S = (value & 0x01000000) >> 24;
10914 I1 = (value & 0x00800000) >> 23;
10915 I2 = (value & 0x00400000) >> 22;
10916 hi = (value & 0x003ff000) >> 12;
10917 lo = (value & 0x00000ffe) >> 1;
6c43fab6 10918
2fc8bdac
ZW
10919 I1 = !(I1 ^ S);
10920 I2 = !(I2 ^ S);
a737bd4d 10921
2fc8bdac
ZW
10922 newval = md_chars_to_number (buf, THUMB_SIZE);
10923 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10924 newval |= (S << 10) | hi;
10925 newval2 |= (I1 << 13) | (I2 << 11) | lo;
10926 md_number_to_chars (buf, newval, THUMB_SIZE);
10927 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10928 }
10929 break;
a737bd4d 10930
2fc8bdac
ZW
10931 case BFD_RELOC_8:
10932 if (fixP->fx_done || !seg->use_rela_p)
10933 md_number_to_chars (buf, value, 1);
c19d1205 10934 break;
a737bd4d 10935
c19d1205 10936 case BFD_RELOC_16:
2fc8bdac 10937 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10938 md_number_to_chars (buf, value, 2);
c19d1205 10939 break;
a737bd4d 10940
c19d1205
ZW
10941#ifdef OBJ_ELF
10942 case BFD_RELOC_ARM_TLS_GD32:
10943 case BFD_RELOC_ARM_TLS_LE32:
10944 case BFD_RELOC_ARM_TLS_IE32:
10945 case BFD_RELOC_ARM_TLS_LDM32:
10946 case BFD_RELOC_ARM_TLS_LDO32:
10947 S_SET_THREAD_LOCAL (fixP->fx_addsy);
10948 /* fall through */
6c43fab6 10949
c19d1205
ZW
10950 case BFD_RELOC_ARM_GOT32:
10951 case BFD_RELOC_ARM_GOTOFF:
10952 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
10953 if (fixP->fx_done || !seg->use_rela_p)
10954 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
10955 break;
10956#endif
6c43fab6 10957
c19d1205
ZW
10958 case BFD_RELOC_RVA:
10959 case BFD_RELOC_32:
10960 case BFD_RELOC_ARM_TARGET1:
10961 case BFD_RELOC_ARM_ROSEGREL32:
10962 case BFD_RELOC_ARM_SBREL32:
10963 case BFD_RELOC_32_PCREL:
2fc8bdac 10964 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10965 md_number_to_chars (buf, value, 4);
c19d1205 10966 break;
6c43fab6 10967
c19d1205
ZW
10968#ifdef OBJ_ELF
10969 case BFD_RELOC_ARM_PREL31:
2fc8bdac 10970 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
10971 {
10972 newval = md_chars_to_number (buf, 4) & 0x80000000;
10973 if ((value ^ (value >> 1)) & 0x40000000)
10974 {
10975 as_bad_where (fixP->fx_file, fixP->fx_line,
10976 _("rel31 relocation overflow"));
10977 }
10978 newval |= value & 0x7fffffff;
10979 md_number_to_chars (buf, newval, 4);
10980 }
10981 break;
c19d1205 10982#endif
a737bd4d 10983
c19d1205
ZW
10984 case BFD_RELOC_ARM_CP_OFF_IMM:
10985 if (value < -1023 || value > 1023 || (value & 3))
10986 as_bad_where (fixP->fx_file, fixP->fx_line,
10987 _("co-processor offset out of range"));
10988 cp_off_common:
10989 sign = value >= 0;
10990 if (value < 0)
10991 value = -value;
10992 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
10993 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
10994 if (value == 0)
10995 newval &= ~WRITE_BACK;
10996 md_number_to_chars (buf, newval, INSN_SIZE);
10997 break;
a737bd4d 10998
c19d1205
ZW
10999 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
11000 if (value < -255 || value > 255)
11001 as_bad_where (fixP->fx_file, fixP->fx_line,
11002 _("co-processor offset out of range"));
11003 goto cp_off_common;
6c43fab6 11004
c19d1205
ZW
11005 case BFD_RELOC_ARM_THUMB_OFFSET:
11006 newval = md_chars_to_number (buf, THUMB_SIZE);
11007 /* Exactly what ranges, and where the offset is inserted depends
11008 on the type of instruction, we can establish this from the
11009 top 4 bits. */
11010 switch (newval >> 12)
11011 {
11012 case 4: /* PC load. */
11013 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
11014 forced to zero for these loads; md_pcrel_from has already
11015 compensated for this. */
11016 if (value & 3)
11017 as_bad_where (fixP->fx_file, fixP->fx_line,
11018 _("invalid offset, target not word aligned (0x%08lX)"),
11019 (((unsigned int) fixP->fx_frag->fr_address
11020 + (unsigned int) fixP->fx_where) & ~3) + value);
a737bd4d 11021
c19d1205
ZW
11022 if (value & ~0x3fc)
11023 as_bad_where (fixP->fx_file, fixP->fx_line,
11024 _("invalid offset, value too big (0x%08lX)"),
11025 (long) value);
a737bd4d 11026
c19d1205
ZW
11027 newval |= value >> 2;
11028 break;
a737bd4d 11029
c19d1205
ZW
11030 case 9: /* SP load/store. */
11031 if (value & ~0x3fc)
11032 as_bad_where (fixP->fx_file, fixP->fx_line,
11033 _("invalid offset, value too big (0x%08lX)"),
11034 (long) value);
11035 newval |= value >> 2;
11036 break;
6c43fab6 11037
c19d1205
ZW
11038 case 6: /* Word load/store. */
11039 if (value & ~0x7c)
11040 as_bad_where (fixP->fx_file, fixP->fx_line,
11041 _("invalid offset, value too big (0x%08lX)"),
11042 (long) value);
11043 newval |= value << 4; /* 6 - 2. */
11044 break;
a737bd4d 11045
c19d1205
ZW
11046 case 7: /* Byte load/store. */
11047 if (value & ~0x1f)
11048 as_bad_where (fixP->fx_file, fixP->fx_line,
11049 _("invalid offset, value too big (0x%08lX)"),
11050 (long) value);
11051 newval |= value << 6;
11052 break;
a737bd4d 11053
c19d1205
ZW
11054 case 8: /* Halfword load/store. */
11055 if (value & ~0x3e)
11056 as_bad_where (fixP->fx_file, fixP->fx_line,
11057 _("invalid offset, value too big (0x%08lX)"),
11058 (long) value);
11059 newval |= value << 5; /* 6 - 1. */
11060 break;
a737bd4d 11061
c19d1205
ZW
11062 default:
11063 as_bad_where (fixP->fx_file, fixP->fx_line,
11064 "Unable to process relocation for thumb opcode: %lx",
11065 (unsigned long) newval);
11066 break;
11067 }
11068 md_number_to_chars (buf, newval, THUMB_SIZE);
11069 break;
a737bd4d 11070
c19d1205
ZW
11071 case BFD_RELOC_ARM_THUMB_ADD:
11072 /* This is a complicated relocation, since we use it for all of
11073 the following immediate relocations:
a737bd4d 11074
c19d1205
ZW
11075 3bit ADD/SUB
11076 8bit ADD/SUB
11077 9bit ADD/SUB SP word-aligned
11078 10bit ADD PC/SP word-aligned
a737bd4d 11079
c19d1205
ZW
11080 The type of instruction being processed is encoded in the
11081 instruction field:
a737bd4d 11082
c19d1205
ZW
11083 0x8000 SUB
11084 0x00F0 Rd
11085 0x000F Rs
11086 */
11087 newval = md_chars_to_number (buf, THUMB_SIZE);
11088 {
11089 int rd = (newval >> 4) & 0xf;
11090 int rs = newval & 0xf;
11091 int subtract = !!(newval & 0x8000);
a737bd4d 11092
c19d1205
ZW
11093 /* Check for HI regs, only very restricted cases allowed:
11094 Adjusting SP, and using PC or SP to get an address. */
11095 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
11096 || (rs > 7 && rs != REG_SP && rs != REG_PC))
11097 as_bad_where (fixP->fx_file, fixP->fx_line,
11098 _("invalid Hi register with immediate"));
a737bd4d 11099
c19d1205
ZW
11100 /* If value is negative, choose the opposite instruction. */
11101 if (value < 0)
11102 {
11103 value = -value;
11104 subtract = !subtract;
11105 if (value < 0)
11106 as_bad_where (fixP->fx_file, fixP->fx_line,
11107 _("immediate value out of range"));
11108 }
a737bd4d 11109
c19d1205
ZW
11110 if (rd == REG_SP)
11111 {
11112 if (value & ~0x1fc)
11113 as_bad_where (fixP->fx_file, fixP->fx_line,
11114 _("invalid immediate for stack address calculation"));
11115 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11116 newval |= value >> 2;
11117 }
11118 else if (rs == REG_PC || rs == REG_SP)
11119 {
11120 if (subtract || value & ~0x3fc)
11121 as_bad_where (fixP->fx_file, fixP->fx_line,
11122 _("invalid immediate for address calculation (value = 0x%08lX)"),
11123 (unsigned long) value);
11124 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11125 newval |= rd << 8;
11126 newval |= value >> 2;
11127 }
11128 else if (rs == rd)
11129 {
11130 if (value & ~0xff)
11131 as_bad_where (fixP->fx_file, fixP->fx_line,
11132 _("immediate value out of range"));
11133 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11134 newval |= (rd << 8) | value;
11135 }
11136 else
11137 {
11138 if (value & ~0x7)
11139 as_bad_where (fixP->fx_file, fixP->fx_line,
11140 _("immediate value out of range"));
11141 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11142 newval |= rd | (rs << 3) | (value << 6);
11143 }
11144 }
11145 md_number_to_chars (buf, newval, THUMB_SIZE);
11146 break;
a737bd4d 11147
c19d1205
ZW
11148 case BFD_RELOC_ARM_THUMB_IMM:
11149 newval = md_chars_to_number (buf, THUMB_SIZE);
11150 if (value < 0 || value > 255)
11151 as_bad_where (fixP->fx_file, fixP->fx_line,
11152 _("invalid immediate: %ld is too large"),
11153 (long) value);
11154 newval |= value;
11155 md_number_to_chars (buf, newval, THUMB_SIZE);
11156 break;
a737bd4d 11157
c19d1205
ZW
11158 case BFD_RELOC_ARM_THUMB_SHIFT:
11159 /* 5bit shift value (0..32). LSL cannot take 32. */
11160 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11161 temp = newval & 0xf800;
11162 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11163 as_bad_where (fixP->fx_file, fixP->fx_line,
11164 _("invalid shift value: %ld"), (long) value);
11165 /* Shifts of zero must be encoded as LSL. */
11166 if (value == 0)
11167 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11168 /* Shifts of 32 are encoded as zero. */
11169 else if (value == 32)
11170 value = 0;
11171 newval |= value << 6;
11172 md_number_to_chars (buf, newval, THUMB_SIZE);
11173 break;
a737bd4d 11174
c19d1205
ZW
11175 case BFD_RELOC_VTABLE_INHERIT:
11176 case BFD_RELOC_VTABLE_ENTRY:
11177 fixP->fx_done = 0;
11178 return;
6c43fab6 11179
c19d1205
ZW
11180 case BFD_RELOC_UNUSED:
11181 default:
11182 as_bad_where (fixP->fx_file, fixP->fx_line,
11183 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11184 }
6c43fab6
RE
11185}
11186
c19d1205
ZW
11187/* Translate internal representation of relocation info to BFD target
11188 format. */
a737bd4d 11189
c19d1205
ZW
11190arelent *
11191tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11192 fixS * fixp)
a737bd4d 11193{
c19d1205
ZW
11194 arelent * reloc;
11195 bfd_reloc_code_real_type code;
a737bd4d 11196
c19d1205 11197 reloc = xmalloc (sizeof (arelent));
a737bd4d 11198
c19d1205
ZW
11199 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11200 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11201 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 11202
2fc8bdac
ZW
11203 if (fixp->fx_pcrel)
11204 fixp->fx_offset = reloc->address;
c19d1205 11205 reloc->addend = fixp->fx_offset;
a737bd4d 11206
c19d1205 11207 switch (fixp->fx_r_type)
a737bd4d 11208 {
c19d1205
ZW
11209 case BFD_RELOC_8:
11210 if (fixp->fx_pcrel)
11211 {
11212 code = BFD_RELOC_8_PCREL;
11213 break;
11214 }
a737bd4d 11215
c19d1205
ZW
11216 case BFD_RELOC_16:
11217 if (fixp->fx_pcrel)
11218 {
11219 code = BFD_RELOC_16_PCREL;
11220 break;
11221 }
6c43fab6 11222
c19d1205
ZW
11223 case BFD_RELOC_32:
11224 if (fixp->fx_pcrel)
11225 {
11226 code = BFD_RELOC_32_PCREL;
11227 break;
11228 }
a737bd4d 11229
c19d1205
ZW
11230 case BFD_RELOC_NONE:
11231 case BFD_RELOC_ARM_PCREL_BRANCH:
11232 case BFD_RELOC_ARM_PCREL_BLX:
11233 case BFD_RELOC_RVA:
11234 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11235 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11236 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11237 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11238 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11239 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11240 case BFD_RELOC_THUMB_PCREL_BLX:
11241 case BFD_RELOC_VTABLE_ENTRY:
11242 case BFD_RELOC_VTABLE_INHERIT:
11243 code = fixp->fx_r_type;
11244 break;
a737bd4d 11245
c19d1205
ZW
11246 case BFD_RELOC_ARM_LITERAL:
11247 case BFD_RELOC_ARM_HWLITERAL:
11248 /* If this is called then the a literal has
11249 been referenced across a section boundary. */
11250 as_bad_where (fixp->fx_file, fixp->fx_line,
11251 _("literal referenced across section boundary"));
11252 return NULL;
a737bd4d 11253
c19d1205
ZW
11254#ifdef OBJ_ELF
11255 case BFD_RELOC_ARM_GOT32:
11256 case BFD_RELOC_ARM_GOTOFF:
11257 case BFD_RELOC_ARM_PLT32:
11258 case BFD_RELOC_ARM_TARGET1:
11259 case BFD_RELOC_ARM_ROSEGREL32:
11260 case BFD_RELOC_ARM_SBREL32:
11261 case BFD_RELOC_ARM_PREL31:
11262 case BFD_RELOC_ARM_TARGET2:
11263 case BFD_RELOC_ARM_TLS_LE32:
11264 case BFD_RELOC_ARM_TLS_LDO32:
11265 code = fixp->fx_r_type;
11266 break;
a737bd4d 11267
c19d1205
ZW
11268 case BFD_RELOC_ARM_TLS_GD32:
11269 case BFD_RELOC_ARM_TLS_IE32:
11270 case BFD_RELOC_ARM_TLS_LDM32:
11271 /* BFD will include the symbol's address in the addend.
11272 But we don't want that, so subtract it out again here. */
11273 if (!S_IS_COMMON (fixp->fx_addsy))
11274 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11275 code = fixp->fx_r_type;
11276 break;
11277#endif
a737bd4d 11278
c19d1205
ZW
11279 case BFD_RELOC_ARM_IMMEDIATE:
11280 as_bad_where (fixp->fx_file, fixp->fx_line,
11281 _("internal relocation (type: IMMEDIATE) not fixed up"));
11282 return NULL;
a737bd4d 11283
c19d1205
ZW
11284 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11285 as_bad_where (fixp->fx_file, fixp->fx_line,
11286 _("ADRL used for a symbol not defined in the same file"));
11287 return NULL;
a737bd4d 11288
c19d1205
ZW
11289 case BFD_RELOC_ARM_OFFSET_IMM:
11290 if (fixp->fx_addsy != NULL
11291 && !S_IS_DEFINED (fixp->fx_addsy)
11292 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 11293 {
c19d1205
ZW
11294 as_bad_where (fixp->fx_file, fixp->fx_line,
11295 _("undefined local label `%s'"),
11296 S_GET_NAME (fixp->fx_addsy));
11297 return NULL;
a737bd4d
NC
11298 }
11299
c19d1205
ZW
11300 as_bad_where (fixp->fx_file, fixp->fx_line,
11301 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11302 return NULL;
a737bd4d 11303
c19d1205
ZW
11304 default:
11305 {
11306 char * type;
6c43fab6 11307
c19d1205
ZW
11308 switch (fixp->fx_r_type)
11309 {
11310 case BFD_RELOC_NONE: type = "NONE"; break;
11311 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
11312 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
11313 case BFD_RELOC_ARM_SMI: type = "SMI"; break;
11314 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
11315 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
11316 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
11317 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
11318 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
11319 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
11320 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
11321 default: type = _("<unknown>"); break;
11322 }
11323 as_bad_where (fixp->fx_file, fixp->fx_line,
11324 _("cannot represent %s relocation in this object file format"),
11325 type);
11326 return NULL;
11327 }
a737bd4d 11328 }
6c43fab6 11329
c19d1205
ZW
11330#ifdef OBJ_ELF
11331 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
11332 && GOT_symbol
11333 && fixp->fx_addsy == GOT_symbol)
11334 {
11335 code = BFD_RELOC_ARM_GOTPC;
11336 reloc->addend = fixp->fx_offset = reloc->address;
11337 }
11338#endif
6c43fab6 11339
c19d1205 11340 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 11341
c19d1205
ZW
11342 if (reloc->howto == NULL)
11343 {
11344 as_bad_where (fixp->fx_file, fixp->fx_line,
11345 _("cannot represent %s relocation in this object file format"),
11346 bfd_get_reloc_code_name (code));
11347 return NULL;
11348 }
6c43fab6 11349
c19d1205
ZW
11350 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
11351 vtable entry to be used in the relocation's section offset. */
11352 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11353 reloc->address = fixp->fx_offset;
6c43fab6 11354
c19d1205 11355 return reloc;
6c43fab6
RE
11356}
11357
c19d1205 11358/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 11359
c19d1205
ZW
11360void
11361cons_fix_new_arm (fragS * frag,
11362 int where,
11363 int size,
11364 expressionS * exp)
6c43fab6 11365{
c19d1205
ZW
11366 bfd_reloc_code_real_type type;
11367 int pcrel = 0;
6c43fab6 11368
c19d1205
ZW
11369 /* Pick a reloc.
11370 FIXME: @@ Should look at CPU word size. */
11371 switch (size)
11372 {
11373 case 1:
11374 type = BFD_RELOC_8;
11375 break;
11376 case 2:
11377 type = BFD_RELOC_16;
11378 break;
11379 case 4:
11380 default:
11381 type = BFD_RELOC_32;
11382 break;
11383 case 8:
11384 type = BFD_RELOC_64;
11385 break;
11386 }
6c43fab6 11387
c19d1205
ZW
11388 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
11389}
6c43fab6 11390
c19d1205
ZW
11391#if defined OBJ_COFF || defined OBJ_ELF
11392void
11393arm_validate_fix (fixS * fixP)
6c43fab6 11394{
c19d1205
ZW
11395 /* If the destination of the branch is a defined symbol which does not have
11396 the THUMB_FUNC attribute, then we must be calling a function which has
11397 the (interfacearm) attribute. We look for the Thumb entry point to that
11398 function and change the branch to refer to that function instead. */
11399 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
11400 && fixP->fx_addsy != NULL
11401 && S_IS_DEFINED (fixP->fx_addsy)
11402 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 11403 {
c19d1205 11404 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 11405 }
c19d1205
ZW
11406}
11407#endif
6c43fab6 11408
c19d1205
ZW
11409int
11410arm_force_relocation (struct fix * fixp)
11411{
11412#if defined (OBJ_COFF) && defined (TE_PE)
11413 if (fixp->fx_r_type == BFD_RELOC_RVA)
11414 return 1;
11415#endif
6c43fab6 11416
c19d1205
ZW
11417 /* Resolve these relocations even if the symbol is extern or weak. */
11418 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
11419 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
11420 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11421 return 0;
a737bd4d 11422
c19d1205 11423 return generic_force_reloc (fixp);
404ff6b5
AH
11424}
11425
c19d1205
ZW
11426#ifdef OBJ_COFF
11427/* This is a little hack to help the gas/arm/adrl.s test. It prevents
11428 local labels from being added to the output symbol table when they
11429 are used with the ADRL pseudo op. The ADRL relocation should always
11430 be resolved before the binbary is emitted, so it is safe to say that
11431 it is adjustable. */
404ff6b5 11432
c19d1205
ZW
11433bfd_boolean
11434arm_fix_adjustable (fixS * fixP)
404ff6b5 11435{
c19d1205
ZW
11436 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11437 return 1;
11438 return 0;
404ff6b5 11439}
c19d1205 11440#endif
404ff6b5 11441
c19d1205
ZW
11442#ifdef OBJ_ELF
11443/* Relocations against Thumb function names must be left unadjusted,
11444 so that the linker can use this information to correctly set the
11445 bottom bit of their addresses. The MIPS version of this function
11446 also prevents relocations that are mips-16 specific, but I do not
11447 know why it does this.
404ff6b5 11448
c19d1205
ZW
11449 FIXME:
11450 There is one other problem that ought to be addressed here, but
11451 which currently is not: Taking the address of a label (rather
11452 than a function) and then later jumping to that address. Such
11453 addresses also ought to have their bottom bit set (assuming that
11454 they reside in Thumb code), but at the moment they will not. */
404ff6b5 11455
c19d1205
ZW
11456bfd_boolean
11457arm_fix_adjustable (fixS * fixP)
404ff6b5 11458{
c19d1205
ZW
11459 if (fixP->fx_addsy == NULL)
11460 return 1;
404ff6b5 11461
c19d1205
ZW
11462 if (THUMB_IS_FUNC (fixP->fx_addsy)
11463 && fixP->fx_subsy == NULL)
11464 return 0;
a737bd4d 11465
c19d1205
ZW
11466 /* We need the symbol name for the VTABLE entries. */
11467 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11468 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11469 return 0;
404ff6b5 11470
c19d1205
ZW
11471 /* Don't allow symbols to be discarded on GOT related relocs. */
11472 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
11473 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
11474 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
11475 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
11476 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
11477 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
11478 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
11479 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
11480 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
11481 return 0;
a737bd4d 11482
c19d1205 11483 return 1;
a737bd4d 11484}
404ff6b5 11485
c19d1205
ZW
11486const char *
11487elf32_arm_target_format (void)
404ff6b5 11488{
c19d1205
ZW
11489#ifdef TE_SYMBIAN
11490 return (target_big_endian
11491 ? "elf32-bigarm-symbian"
11492 : "elf32-littlearm-symbian");
11493#elif defined (TE_VXWORKS)
11494 return (target_big_endian
11495 ? "elf32-bigarm-vxworks"
11496 : "elf32-littlearm-vxworks");
11497#else
11498 if (target_big_endian)
11499 return "elf32-bigarm";
11500 else
11501 return "elf32-littlearm";
11502#endif
404ff6b5
AH
11503}
11504
c19d1205
ZW
11505void
11506armelf_frob_symbol (symbolS * symp,
11507 int * puntp)
404ff6b5 11508{
c19d1205
ZW
11509 elf_frob_symbol (symp, puntp);
11510}
11511#endif
404ff6b5 11512
c19d1205 11513/* MD interface: Finalization. */
a737bd4d 11514
c19d1205
ZW
11515/* A good place to do this, although this was probably not intended
11516 for this kind of use. We need to dump the literal pool before
11517 references are made to a null symbol pointer. */
a737bd4d 11518
c19d1205
ZW
11519void
11520arm_cleanup (void)
11521{
11522 literal_pool * pool;
a737bd4d 11523
c19d1205
ZW
11524 for (pool = list_of_pools; pool; pool = pool->next)
11525 {
11526 /* Put it at the end of the relevent section. */
11527 subseg_set (pool->section, pool->sub_section);
11528#ifdef OBJ_ELF
11529 arm_elf_change_section ();
11530#endif
11531 s_ltorg (0);
11532 }
404ff6b5
AH
11533}
11534
c19d1205
ZW
11535/* Adjust the symbol table. This marks Thumb symbols as distinct from
11536 ARM ones. */
404ff6b5 11537
c19d1205
ZW
11538void
11539arm_adjust_symtab (void)
404ff6b5 11540{
c19d1205
ZW
11541#ifdef OBJ_COFF
11542 symbolS * sym;
404ff6b5 11543
c19d1205
ZW
11544 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
11545 {
11546 if (ARM_IS_THUMB (sym))
11547 {
11548 if (THUMB_IS_FUNC (sym))
11549 {
11550 /* Mark the symbol as a Thumb function. */
11551 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
11552 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
11553 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 11554
c19d1205
ZW
11555 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
11556 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
11557 else
11558 as_bad (_("%s: unexpected function type: %d"),
11559 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
11560 }
11561 else switch (S_GET_STORAGE_CLASS (sym))
11562 {
11563 case C_EXT:
11564 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
11565 break;
11566 case C_STAT:
11567 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
11568 break;
11569 case C_LABEL:
11570 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
11571 break;
11572 default:
11573 /* Do nothing. */
11574 break;
11575 }
11576 }
a737bd4d 11577
c19d1205
ZW
11578 if (ARM_IS_INTERWORK (sym))
11579 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 11580 }
c19d1205
ZW
11581#endif
11582#ifdef OBJ_ELF
11583 symbolS * sym;
11584 char bind;
404ff6b5 11585
c19d1205 11586 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 11587 {
c19d1205
ZW
11588 if (ARM_IS_THUMB (sym))
11589 {
11590 elf_symbol_type * elf_sym;
404ff6b5 11591
c19d1205
ZW
11592 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
11593 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 11594
c19d1205
ZW
11595 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
11596 {
11597 /* If it's a .thumb_func, declare it as so,
11598 otherwise tag label as .code 16. */
11599 if (THUMB_IS_FUNC (sym))
11600 elf_sym->internal_elf_sym.st_info =
11601 ELF_ST_INFO (bind, STT_ARM_TFUNC);
11602 else
11603 elf_sym->internal_elf_sym.st_info =
11604 ELF_ST_INFO (bind, STT_ARM_16BIT);
11605 }
11606 }
11607 }
11608#endif
404ff6b5
AH
11609}
11610
c19d1205 11611/* MD interface: Initialization. */
404ff6b5 11612
a737bd4d 11613static void
c19d1205 11614set_constant_flonums (void)
a737bd4d 11615{
c19d1205 11616 int i;
404ff6b5 11617
c19d1205
ZW
11618 for (i = 0; i < NUM_FLOAT_VALS; i++)
11619 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
11620 abort ();
a737bd4d 11621}
404ff6b5 11622
c19d1205
ZW
11623void
11624md_begin (void)
a737bd4d 11625{
c19d1205
ZW
11626 unsigned mach;
11627 unsigned int i;
404ff6b5 11628
c19d1205
ZW
11629 if ( (arm_ops_hsh = hash_new ()) == NULL
11630 || (arm_cond_hsh = hash_new ()) == NULL
11631 || (arm_shift_hsh = hash_new ()) == NULL
11632 || (arm_psr_hsh = hash_new ()) == NULL
11633 || (arm_reg_hsh = hash_new ()) == NULL
11634 || (arm_reloc_hsh = hash_new ()) == NULL)
11635 as_fatal (_("virtual memory exhausted"));
11636
11637 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
11638 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
11639 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
11640 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
11641 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
11642 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
11643 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
11644 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
11645 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
11646 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
11647#ifdef OBJ_ELF
11648 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
11649 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
11650#endif
11651
11652 set_constant_flonums ();
404ff6b5 11653
c19d1205
ZW
11654 /* Set the cpu variant based on the command-line options. We prefer
11655 -mcpu= over -march= if both are set (as for GCC); and we prefer
11656 -mfpu= over any other way of setting the floating point unit.
11657 Use of legacy options with new options are faulted. */
11658 if (legacy_cpu != -1)
404ff6b5 11659 {
c19d1205
ZW
11660 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
11661 as_bad (_("use of old and new-style options to set CPU type"));
11662
11663 mcpu_cpu_opt = legacy_cpu;
404ff6b5 11664 }
c19d1205
ZW
11665 else if (mcpu_cpu_opt == -1)
11666 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 11667
c19d1205
ZW
11668 if (legacy_fpu != -1)
11669 {
11670 if (mfpu_opt != -1)
11671 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
11672
11673 mfpu_opt = legacy_fpu;
11674 }
11675 else if (mfpu_opt == -1)
11676 {
c19d1205 11677#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
11678 /* Some environments specify a default FPU. If they don't, infer it
11679 from the processor. */
03b1477f
RE
11680 if (mcpu_fpu_opt != -1)
11681 mfpu_opt = mcpu_fpu_opt;
11682 else
11683 mfpu_opt = march_fpu_opt;
39c2da32
RE
11684#else
11685 mfpu_opt = FPU_DEFAULT;
11686#endif
03b1477f
RE
11687 }
11688
11689 if (mfpu_opt == -1)
11690 {
11691 if (mcpu_cpu_opt == -1)
11692 mfpu_opt = FPU_DEFAULT;
11693 else if (mcpu_cpu_opt & ARM_EXT_V5)
11694 mfpu_opt = FPU_ARCH_VFP_V2;
11695 else
11696 mfpu_opt = FPU_ARCH_FPA;
11697 }
11698
11699 if (mcpu_cpu_opt == -1)
11700 mcpu_cpu_opt = CPU_DEFAULT;
11701
11702 cpu_variant = mcpu_cpu_opt | mfpu_opt;
11703
f17c130b 11704#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 11705 {
7cc69913
NC
11706 unsigned int flags = 0;
11707
11708#if defined OBJ_ELF
11709 flags = meabi_flags;
d507cf36
PB
11710
11711 switch (meabi_flags)
33a392fb 11712 {
d507cf36 11713 case EF_ARM_EABI_UNKNOWN:
7cc69913 11714#endif
d507cf36
PB
11715 /* Set the flags in the private structure. */
11716 if (uses_apcs_26) flags |= F_APCS26;
11717 if (support_interwork) flags |= F_INTERWORK;
11718 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 11719 if (pic_code) flags |= F_PIC;
d507cf36
PB
11720 if ((cpu_variant & FPU_ANY) == FPU_NONE
11721 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
7cc69913
NC
11722 flags |= F_SOFT_FLOAT;
11723
d507cf36
PB
11724 switch (mfloat_abi_opt)
11725 {
11726 case ARM_FLOAT_ABI_SOFT:
11727 case ARM_FLOAT_ABI_SOFTFP:
11728 flags |= F_SOFT_FLOAT;
11729 break;
33a392fb 11730
d507cf36
PB
11731 case ARM_FLOAT_ABI_HARD:
11732 if (flags & F_SOFT_FLOAT)
11733 as_bad (_("hard-float conflicts with specified fpu"));
11734 break;
11735 }
03b1477f 11736
c19d1205 11737 /* Using VFP conventions (even if soft-float). */
7cc69913
NC
11738 if (cpu_variant & FPU_VFP_EXT_NONE)
11739 flags |= F_VFP_FLOAT;
f17c130b 11740
fde78edd 11741#if defined OBJ_ELF
d507cf36
PB
11742 if (cpu_variant & FPU_ARCH_MAVERICK)
11743 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
11744 break;
11745
8cb51566 11746 case EF_ARM_EABI_VER4:
c19d1205 11747 /* No additional flags to set. */
d507cf36
PB
11748 break;
11749
11750 default:
11751 abort ();
11752 }
7cc69913 11753#endif
b99bd4ef
NC
11754 bfd_set_private_flags (stdoutput, flags);
11755
11756 /* We have run out flags in the COFF header to encode the
11757 status of ATPCS support, so instead we create a dummy,
c19d1205 11758 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
11759 if (atpcs)
11760 {
11761 asection * sec;
11762
11763 sec = bfd_make_section (stdoutput, ".arm.atpcs");
11764
11765 if (sec != NULL)
11766 {
11767 bfd_set_section_flags
11768 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
11769 bfd_set_section_size (stdoutput, sec, 0);
11770 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
11771 }
11772 }
7cc69913 11773 }
f17c130b 11774#endif
b99bd4ef
NC
11775
11776 /* Record the CPU type as well. */
11777 switch (cpu_variant & ARM_CPU_MASK)
11778 {
11779 case ARM_2:
11780 mach = bfd_mach_arm_2;
11781 break;
11782
c19d1205 11783 case ARM_3: /* Also ARM_250. */
b99bd4ef
NC
11784 mach = bfd_mach_arm_2a;
11785 break;
11786
c19d1205 11787 case ARM_6: /* Also ARM_7. */
b89dddec
RE
11788 mach = bfd_mach_arm_3;
11789 break;
11790
b99bd4ef 11791 default:
5a6c6817 11792 mach = bfd_mach_arm_unknown;
b99bd4ef 11793 break;
b99bd4ef
NC
11794 }
11795
11796 /* Catch special cases. */
e16bb312
NC
11797 if (cpu_variant & ARM_CEXT_IWMMXT)
11798 mach = bfd_mach_arm_iWMMXt;
11799 else if (cpu_variant & ARM_CEXT_XSCALE)
b99bd4ef 11800 mach = bfd_mach_arm_XScale;
fde78edd
NC
11801 else if (cpu_variant & ARM_CEXT_MAVERICK)
11802 mach = bfd_mach_arm_ep9312;
b99bd4ef
NC
11803 else if (cpu_variant & ARM_EXT_V5E)
11804 mach = bfd_mach_arm_5TE;
11805 else if (cpu_variant & ARM_EXT_V5)
11806 {
b89dddec 11807 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11808 mach = bfd_mach_arm_5T;
11809 else
11810 mach = bfd_mach_arm_5;
11811 }
b89dddec 11812 else if (cpu_variant & ARM_EXT_V4)
b99bd4ef 11813 {
b89dddec 11814 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11815 mach = bfd_mach_arm_4T;
11816 else
11817 mach = bfd_mach_arm_4;
11818 }
b89dddec 11819 else if (cpu_variant & ARM_EXT_V3M)
b99bd4ef
NC
11820 mach = bfd_mach_arm_3M;
11821
11822 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
11823}
11824
c19d1205 11825/* Command line processing. */
b99bd4ef 11826
c19d1205
ZW
11827/* md_parse_option
11828 Invocation line includes a switch not recognized by the base assembler.
11829 See if it's a processor-specific option.
b99bd4ef 11830
c19d1205
ZW
11831 This routine is somewhat complicated by the need for backwards
11832 compatibility (since older releases of gcc can't be changed).
11833 The new options try to make the interface as compatible as
11834 possible with GCC.
b99bd4ef 11835
c19d1205 11836 New options (supported) are:
b99bd4ef 11837
c19d1205
ZW
11838 -mcpu=<cpu name> Assemble for selected processor
11839 -march=<architecture name> Assemble for selected architecture
11840 -mfpu=<fpu architecture> Assemble for selected FPU.
11841 -EB/-mbig-endian Big-endian
11842 -EL/-mlittle-endian Little-endian
11843 -k Generate PIC code
11844 -mthumb Start in Thumb mode
11845 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 11846
c19d1205 11847 For now we will also provide support for:
b99bd4ef 11848
c19d1205
ZW
11849 -mapcs-32 32-bit Program counter
11850 -mapcs-26 26-bit Program counter
11851 -macps-float Floats passed in FP registers
11852 -mapcs-reentrant Reentrant code
11853 -matpcs
11854 (sometime these will probably be replaced with -mapcs=<list of options>
11855 and -matpcs=<list of options>)
b99bd4ef 11856
c19d1205
ZW
11857 The remaining options are only supported for back-wards compatibility.
11858 Cpu variants, the arm part is optional:
11859 -m[arm]1 Currently not supported.
11860 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
11861 -m[arm]3 Arm 3 processor
11862 -m[arm]6[xx], Arm 6 processors
11863 -m[arm]7[xx][t][[d]m] Arm 7 processors
11864 -m[arm]8[10] Arm 8 processors
11865 -m[arm]9[20][tdmi] Arm 9 processors
11866 -mstrongarm[110[0]] StrongARM processors
11867 -mxscale XScale processors
11868 -m[arm]v[2345[t[e]]] Arm architectures
11869 -mall All (except the ARM1)
11870 FP variants:
11871 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
11872 -mfpe-old (No float load/store multiples)
11873 -mvfpxd VFP Single precision
11874 -mvfp All VFP
11875 -mno-fpu Disable all floating point instructions
b99bd4ef 11876
c19d1205
ZW
11877 The following CPU names are recognized:
11878 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
11879 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
11880 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
11881 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
11882 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
11883 arm10t arm10e, arm1020t, arm1020e, arm10200e,
11884 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 11885
c19d1205 11886 */
b99bd4ef 11887
c19d1205 11888const char * md_shortopts = "m:k";
b99bd4ef 11889
c19d1205
ZW
11890#ifdef ARM_BI_ENDIAN
11891#define OPTION_EB (OPTION_MD_BASE + 0)
11892#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 11893#else
c19d1205
ZW
11894#if TARGET_BYTES_BIG_ENDIAN
11895#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 11896#else
c19d1205
ZW
11897#define OPTION_EL (OPTION_MD_BASE + 1)
11898#endif
b99bd4ef 11899#endif
b99bd4ef 11900
c19d1205 11901struct option md_longopts[] =
b99bd4ef 11902{
c19d1205
ZW
11903#ifdef OPTION_EB
11904 {"EB", no_argument, NULL, OPTION_EB},
11905#endif
11906#ifdef OPTION_EL
11907 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 11908#endif
c19d1205
ZW
11909 {NULL, no_argument, NULL, 0}
11910};
b99bd4ef 11911
c19d1205 11912size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 11913
c19d1205 11914struct arm_option_table
b99bd4ef 11915{
c19d1205
ZW
11916 char *option; /* Option name to match. */
11917 char *help; /* Help information. */
11918 int *var; /* Variable to change. */
11919 int value; /* What to change it to. */
11920 char *deprecated; /* If non-null, print this message. */
11921};
b99bd4ef 11922
c19d1205
ZW
11923struct arm_option_table arm_opts[] =
11924{
11925 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
11926 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
11927 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
11928 &support_interwork, 1, NULL},
11929 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
11930 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
11931 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
11932 1, NULL},
11933 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
11934 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
11935 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
11936 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
11937 NULL},
b99bd4ef 11938
c19d1205
ZW
11939 /* These are recognized by the assembler, but have no affect on code. */
11940 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
11941 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
b99bd4ef 11942
c19d1205
ZW
11943 /* DON'T add any new processors to this list -- we want the whole list
11944 to go away... Add them to the processors table instead. */
11945 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11946 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11947 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11948 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11949 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11950 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11951 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11952 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11953 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11954 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11955 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11956 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11957 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11958 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11959 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11960 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11961 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11962 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11963 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11964 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11965 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11966 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11967 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11968 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11969 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11970 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11971 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11972 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11973 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11974 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11975 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11976 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11977 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11978 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11979 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11980 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11981 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11982 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11983 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11984 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11985 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11986 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11987 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11988 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11989 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11990 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11991 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11992 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11993 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11994 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11995 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11996 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11997 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11998 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11999 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12000 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12001 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12002 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12003 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12004 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12005 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12006 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12007 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12008 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12009 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12010 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12011 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12012 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12013 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
12014 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
12015 N_("use -mcpu=strongarm110")},
12016 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
12017 N_("use -mcpu=strongarm1100")},
12018 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
12019 N_("use -mcpu=strongarm1110")},
12020 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
12021 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
12022 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 12023
c19d1205
ZW
12024 /* Architecture variants -- don't add any more to this list either. */
12025 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12026 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12027 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12028 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12029 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12030 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12031 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12032 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12033 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12034 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12035 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12036 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12037 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12038 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12039 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12040 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12041 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
12042 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 12043
c19d1205
ZW
12044 /* Floating point variants -- don't add any more to this list either. */
12045 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
12046 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
12047 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
12048 {"mno-fpu", NULL, &legacy_fpu, 0,
12049 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 12050
c19d1205
ZW
12051 {NULL, NULL, NULL, 0, NULL}
12052};
7ed4c4c5 12053
c19d1205 12054struct arm_cpu_option_table
7ed4c4c5 12055{
c19d1205
ZW
12056 char *name;
12057 int value;
12058 /* For some CPUs we assume an FPU unless the user explicitly sets
12059 -mfpu=... */
12060 int default_fpu;
12061};
7ed4c4c5 12062
c19d1205
ZW
12063/* This list should, at a minimum, contain all the cpu names
12064 recognized by GCC. */
12065static struct arm_cpu_option_table arm_cpus[] =
12066{
12067 {"all", ARM_ANY, FPU_ARCH_FPA},
12068 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA},
12069 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA},
12070 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA},
12071 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA},
12072 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA},
12073 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA},
12074 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA},
12075 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA},
12076 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA},
12077 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA},
12078 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12079 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA},
12080 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA},
12081 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA},
12082 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA},
12083 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA},
12084 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA},
12085 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA},
12086 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA},
12087 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12088 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA},
12089 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12090 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12091 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA},
12092 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA},
12093 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA},
12094 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA},
12095 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12096 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12097 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA},
12098 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA},
12099 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA},
12100 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA},
12101 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA},
12102 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA},
12103 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA},
12104 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA},
12105 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA},
12106 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA},
12107 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12108 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12109 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12110 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12111 /* For V5 or later processors we default to using VFP; but the user
12112 should really set the FPU type explicitly. */
12113 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12114 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12115 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12116 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12117 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12118 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12119 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12120 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12121 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12122 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12123 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12124 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12125 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12126 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12127 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12128 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12129 {"arm1136js", ARM_ARCH_V6, FPU_NONE},
12130 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE},
12131 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12132 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12133 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2},
12134 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE},
12135 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE},
12136 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2},
12137 /* ??? XSCALE is really an architecture. */
12138 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12139 /* ??? iwmmxt is not a processor. */
12140 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2},
12141 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12142 /* Maverick */
12143 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK},
12144 {NULL, 0, 0}
12145};
7ed4c4c5 12146
c19d1205 12147struct arm_arch_option_table
7ed4c4c5 12148{
c19d1205
ZW
12149 char *name;
12150 int value;
12151 int default_fpu;
12152};
7ed4c4c5 12153
c19d1205
ZW
12154/* This list should, at a minimum, contain all the architecture names
12155 recognized by GCC. */
12156static struct arm_arch_option_table arm_archs[] =
12157{
12158 {"all", ARM_ANY, FPU_ARCH_FPA},
12159 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12160 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12161 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12162 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12163 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12164 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12165 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12166 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12167 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12168 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12169 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12170 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12171 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12172 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12173 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12174 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12175 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12176 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12177 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12178 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12179 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12180 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12181 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12182 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12183 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12184 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12185 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12186 {NULL, 0, 0}
12187};
7ed4c4c5 12188
c19d1205
ZW
12189/* ISA extensions in the co-processor space. */
12190struct arm_option_value_table
12191{
12192 char *name;
12193 int value;
12194};
7ed4c4c5 12195
c19d1205
ZW
12196static struct arm_option_value_table arm_extensions[] =
12197{
12198 {"maverick", ARM_CEXT_MAVERICK},
12199 {"xscale", ARM_CEXT_XSCALE},
12200 {"iwmmxt", ARM_CEXT_IWMMXT},
12201 {NULL, 0}
12202};
7ed4c4c5 12203
c19d1205
ZW
12204/* This list should, at a minimum, contain all the fpu names
12205 recognized by GCC. */
12206static struct arm_option_value_table arm_fpus[] =
12207{
12208 {"softfpa", FPU_NONE},
12209 {"fpe", FPU_ARCH_FPE},
12210 {"fpe2", FPU_ARCH_FPE},
12211 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12212 {"fpa", FPU_ARCH_FPA},
12213 {"fpa10", FPU_ARCH_FPA},
12214 {"fpa11", FPU_ARCH_FPA},
12215 {"arm7500fe", FPU_ARCH_FPA},
12216 {"softvfp", FPU_ARCH_VFP},
12217 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12218 {"vfp", FPU_ARCH_VFP_V2},
12219 {"vfp9", FPU_ARCH_VFP_V2},
12220 {"vfp10", FPU_ARCH_VFP_V2},
12221 {"vfp10-r0", FPU_ARCH_VFP_V1},
12222 {"vfpxd", FPU_ARCH_VFP_V1xD},
12223 {"arm1020t", FPU_ARCH_VFP_V1},
12224 {"arm1020e", FPU_ARCH_VFP_V2},
12225 {"arm1136jfs", FPU_ARCH_VFP_V2},
12226 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12227 {"maverick", FPU_ARCH_MAVERICK},
12228 {NULL, 0}
12229};
7ed4c4c5 12230
c19d1205
ZW
12231static struct arm_option_value_table arm_float_abis[] =
12232{
12233 {"hard", ARM_FLOAT_ABI_HARD},
12234 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12235 {"soft", ARM_FLOAT_ABI_SOFT},
12236 {NULL, 0}
12237};
7ed4c4c5 12238
c19d1205
ZW
12239#ifdef OBJ_ELF
12240/* We only know how to output GNU and ver 4 (AAELF) formats. */
12241static struct arm_option_value_table arm_eabis[] =
12242{
12243 {"gnu", EF_ARM_EABI_UNKNOWN},
12244 {"4", EF_ARM_EABI_VER4},
12245 {NULL, 0}
12246};
12247#endif
7ed4c4c5 12248
c19d1205
ZW
12249struct arm_long_option_table
12250{
12251 char * option; /* Substring to match. */
12252 char * help; /* Help information. */
12253 int (* func) (char * subopt); /* Function to decode sub-option. */
12254 char * deprecated; /* If non-null, print this message. */
12255};
7ed4c4c5
NC
12256
12257static int
c19d1205 12258arm_parse_extension (char * str, int * opt_p)
7ed4c4c5 12259{
c19d1205 12260 while (str != NULL && *str != 0)
7ed4c4c5 12261 {
c19d1205
ZW
12262 struct arm_option_value_table * opt;
12263 char * ext;
12264 int optlen;
7ed4c4c5 12265
c19d1205
ZW
12266 if (*str != '+')
12267 {
12268 as_bad (_("invalid architectural extension"));
12269 return 0;
12270 }
7ed4c4c5 12271
c19d1205
ZW
12272 str++;
12273 ext = strchr (str, '+');
7ed4c4c5 12274
c19d1205
ZW
12275 if (ext != NULL)
12276 optlen = ext - str;
12277 else
12278 optlen = strlen (str);
7ed4c4c5 12279
c19d1205
ZW
12280 if (optlen == 0)
12281 {
12282 as_bad (_("missing architectural extension"));
12283 return 0;
12284 }
7ed4c4c5 12285
c19d1205
ZW
12286 for (opt = arm_extensions; opt->name != NULL; opt++)
12287 if (strncmp (opt->name, str, optlen) == 0)
12288 {
12289 *opt_p |= opt->value;
12290 break;
12291 }
7ed4c4c5 12292
c19d1205
ZW
12293 if (opt->name == NULL)
12294 {
12295 as_bad (_("unknown architectural extnsion `%s'"), str);
12296 return 0;
12297 }
7ed4c4c5 12298
c19d1205
ZW
12299 str = ext;
12300 };
7ed4c4c5 12301
c19d1205
ZW
12302 return 1;
12303}
7ed4c4c5 12304
c19d1205
ZW
12305static int
12306arm_parse_cpu (char * str)
7ed4c4c5 12307{
c19d1205
ZW
12308 struct arm_cpu_option_table * opt;
12309 char * ext = strchr (str, '+');
12310 int optlen;
7ed4c4c5 12311
c19d1205
ZW
12312 if (ext != NULL)
12313 optlen = ext - str;
7ed4c4c5 12314 else
c19d1205 12315 optlen = strlen (str);
7ed4c4c5 12316
c19d1205 12317 if (optlen == 0)
7ed4c4c5 12318 {
c19d1205
ZW
12319 as_bad (_("missing cpu name `%s'"), str);
12320 return 0;
7ed4c4c5
NC
12321 }
12322
c19d1205
ZW
12323 for (opt = arm_cpus; opt->name != NULL; opt++)
12324 if (strncmp (opt->name, str, optlen) == 0)
12325 {
12326 mcpu_cpu_opt = opt->value;
12327 mcpu_fpu_opt = opt->default_fpu;
7ed4c4c5 12328
c19d1205
ZW
12329 if (ext != NULL)
12330 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 12331
c19d1205
ZW
12332 return 1;
12333 }
7ed4c4c5 12334
c19d1205
ZW
12335 as_bad (_("unknown cpu `%s'"), str);
12336 return 0;
7ed4c4c5
NC
12337}
12338
c19d1205
ZW
12339static int
12340arm_parse_arch (char * str)
7ed4c4c5 12341{
c19d1205
ZW
12342 struct arm_arch_option_table *opt;
12343 char *ext = strchr (str, '+');
12344 int optlen;
7ed4c4c5 12345
c19d1205
ZW
12346 if (ext != NULL)
12347 optlen = ext - str;
7ed4c4c5 12348 else
c19d1205 12349 optlen = strlen (str);
7ed4c4c5 12350
c19d1205 12351 if (optlen == 0)
7ed4c4c5 12352 {
c19d1205
ZW
12353 as_bad (_("missing architecture name `%s'"), str);
12354 return 0;
7ed4c4c5
NC
12355 }
12356
7ed4c4c5 12357
c19d1205
ZW
12358 for (opt = arm_archs; opt->name != NULL; opt++)
12359 if (streq (opt->name, str))
12360 {
12361 march_cpu_opt = opt->value;
12362 march_fpu_opt = opt->default_fpu;
7ed4c4c5 12363
c19d1205
ZW
12364 if (ext != NULL)
12365 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 12366
c19d1205
ZW
12367 return 1;
12368 }
12369
12370 as_bad (_("unknown architecture `%s'\n"), str);
12371 return 0;
7ed4c4c5 12372}
eb043451 12373
c19d1205
ZW
12374static int
12375arm_parse_fpu (char * str)
12376{
12377 struct arm_option_value_table * opt;
b99bd4ef 12378
c19d1205
ZW
12379 for (opt = arm_fpus; opt->name != NULL; opt++)
12380 if (streq (opt->name, str))
12381 {
12382 mfpu_opt = opt->value;
12383 return 1;
12384 }
b99bd4ef 12385
c19d1205
ZW
12386 as_bad (_("unknown floating point format `%s'\n"), str);
12387 return 0;
12388}
12389
12390static int
12391arm_parse_float_abi (char * str)
b99bd4ef 12392{
c19d1205 12393 struct arm_option_value_table * opt;
b99bd4ef 12394
c19d1205
ZW
12395 for (opt = arm_float_abis; opt->name != NULL; opt++)
12396 if (streq (opt->name, str))
12397 {
12398 mfloat_abi_opt = opt->value;
12399 return 1;
12400 }
cc8a6dd0 12401
c19d1205
ZW
12402 as_bad (_("unknown floating point abi `%s'\n"), str);
12403 return 0;
12404}
b99bd4ef 12405
c19d1205
ZW
12406#ifdef OBJ_ELF
12407static int
12408arm_parse_eabi (char * str)
12409{
12410 struct arm_option_value_table *opt;
cc8a6dd0 12411
c19d1205
ZW
12412 for (opt = arm_eabis; opt->name != NULL; opt++)
12413 if (streq (opt->name, str))
12414 {
12415 meabi_flags = opt->value;
12416 return 1;
12417 }
12418 as_bad (_("unknown EABI `%s'\n"), str);
12419 return 0;
12420}
12421#endif
cc8a6dd0 12422
c19d1205
ZW
12423struct arm_long_option_table arm_long_opts[] =
12424{
12425 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
12426 arm_parse_cpu, NULL},
12427 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
12428 arm_parse_arch, NULL},
12429 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
12430 arm_parse_fpu, NULL},
12431 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
12432 arm_parse_float_abi, NULL},
12433#ifdef OBJ_ELF
12434 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
12435 arm_parse_eabi, NULL},
12436#endif
12437 {NULL, NULL, 0, NULL}
12438};
cc8a6dd0 12439
c19d1205
ZW
12440int
12441md_parse_option (int c, char * arg)
12442{
12443 struct arm_option_table *opt;
12444 struct arm_long_option_table *lopt;
b99bd4ef 12445
c19d1205 12446 switch (c)
b99bd4ef 12447 {
c19d1205
ZW
12448#ifdef OPTION_EB
12449 case OPTION_EB:
12450 target_big_endian = 1;
12451 break;
12452#endif
cc8a6dd0 12453
c19d1205
ZW
12454#ifdef OPTION_EL
12455 case OPTION_EL:
12456 target_big_endian = 0;
12457 break;
12458#endif
b99bd4ef 12459
c19d1205
ZW
12460 case 'a':
12461 /* Listing option. Just ignore these, we don't support additional
12462 ones. */
12463 return 0;
b99bd4ef 12464
c19d1205
ZW
12465 default:
12466 for (opt = arm_opts; opt->option != NULL; opt++)
12467 {
12468 if (c == opt->option[0]
12469 && ((arg == NULL && opt->option[1] == 0)
12470 || streq (arg, opt->option + 1)))
12471 {
12472#if WARN_DEPRECATED
12473 /* If the option is deprecated, tell the user. */
12474 if (opt->deprecated != NULL)
12475 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
12476 arg ? arg : "", _(opt->deprecated));
12477#endif
b99bd4ef 12478
c19d1205
ZW
12479 if (opt->var != NULL)
12480 *opt->var = opt->value;
cc8a6dd0 12481
c19d1205
ZW
12482 return 1;
12483 }
12484 }
b99bd4ef 12485
c19d1205
ZW
12486 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12487 {
12488 /* These options are expected to have an argument. */
12489 if (c == lopt->option[0]
12490 && arg != NULL
12491 && strncmp (arg, lopt->option + 1,
12492 strlen (lopt->option + 1)) == 0)
12493 {
12494#if WARN_DEPRECATED
12495 /* If the option is deprecated, tell the user. */
12496 if (lopt->deprecated != NULL)
12497 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
12498 _(lopt->deprecated));
12499#endif
b99bd4ef 12500
c19d1205
ZW
12501 /* Call the sup-option parser. */
12502 return lopt->func (arg + strlen (lopt->option) - 1);
12503 }
12504 }
a737bd4d 12505
c19d1205
ZW
12506 return 0;
12507 }
a394c00f 12508
c19d1205
ZW
12509 return 1;
12510}
a394c00f 12511
c19d1205
ZW
12512void
12513md_show_usage (FILE * fp)
a394c00f 12514{
c19d1205
ZW
12515 struct arm_option_table *opt;
12516 struct arm_long_option_table *lopt;
a394c00f 12517
c19d1205 12518 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 12519
c19d1205
ZW
12520 for (opt = arm_opts; opt->option != NULL; opt++)
12521 if (opt->help != NULL)
12522 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 12523
c19d1205
ZW
12524 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12525 if (lopt->help != NULL)
12526 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 12527
c19d1205
ZW
12528#ifdef OPTION_EB
12529 fprintf (fp, _("\
12530 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
12531#endif
12532
c19d1205
ZW
12533#ifdef OPTION_EL
12534 fprintf (fp, _("\
12535 -EL assemble code for a little-endian cpu\n"));
a737bd4d 12536#endif
c19d1205 12537}
This page took 1.281108 seconds and 4 git commands to generate.