* hppa-tdep.c (hppa_pc_requires_run_before_use): Really test all
[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
178/* Size of relocation record. */
05d2d07e 179const int md_reloc_size = 8;
b99bd4ef
NC
180
181/* 0: assemble for ARM,
182 1: assemble for Thumb,
183 2: assemble for Thumb even though target CPU does not support thumb
184 instructions. */
185static int thumb_mode = 0;
186
c19d1205
ZW
187/* If unified_syntax is true, we are processing the new unified
188 ARM/Thumb syntax. Important differences from the old ARM mode:
189
190 - Immediate operands do not require a # prefix.
191 - Conditional affixes always appear at the end of the
192 instruction. (For backward compatibility, those instructions
193 that formerly had them in the middle, continue to accept them
194 there.)
195 - The IT instruction may appear, and if it does is validated
196 against subsequent conditional affixes. It does not generate
197 machine code.
198
199 Important differences from the old Thumb mode:
200
201 - Immediate operands do not require a # prefix.
202 - Most of the V6T2 instructions are only available in unified mode.
203 - The .N and .W suffixes are recognized and honored (it is an error
204 if they cannot be honored).
205 - All instructions set the flags if and only if they have an 's' affix.
206 - Conditional affixes may be used. They are validated against
207 preceding IT instructions. Unlike ARM mode, you cannot use a
208 conditional affix except in the scope of an IT instruction. */
209
210static bfd_boolean unified_syntax = FALSE;
b99bd4ef
NC
211
212struct arm_it
213{
c19d1205 214 const char * error;
b99bd4ef 215 unsigned long instruction;
c19d1205
ZW
216 int size;
217 int size_req;
218 int cond;
b99bd4ef
NC
219 struct
220 {
221 bfd_reloc_code_real_type type;
c19d1205
ZW
222 expressionS exp;
223 int pc_rel;
b99bd4ef 224 } reloc;
b99bd4ef 225
c19d1205
ZW
226 struct
227 {
228 unsigned reg;
229 unsigned imm;
230 unsigned present : 1; /* operand present */
231 unsigned isreg : 1; /* operand was a register */
232 unsigned immisreg : 1; /* .imm field is a second register */
233 unsigned hasreloc : 1; /* operand has relocation suffix */
234 unsigned writeback : 1; /* operand has trailing ! */
235 unsigned preind : 1; /* preindexed address */
236 unsigned postind : 1; /* postindexed address */
237 unsigned negative : 1; /* index register was negated */
238 unsigned shifted : 1; /* shift applied to operation */
239 unsigned shift_kind : 3; /* shift operation (enum shift_kind) */
240 } operands[6];
b99bd4ef
NC
241};
242
c19d1205 243static struct arm_it inst;
b99bd4ef
NC
244
245#define NUM_FLOAT_VALS 8
246
05d2d07e 247const char * fp_const[] =
b99bd4ef
NC
248{
249 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
250};
251
c19d1205 252/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
253#define MAX_LITTLENUMS 6
254
255LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
256
257#define FAIL (-1)
258#define SUCCESS (0)
259
260#define SUFF_S 1
261#define SUFF_D 2
262#define SUFF_E 3
263#define SUFF_P 4
264
c19d1205
ZW
265#define CP_T_X 0x00008000
266#define CP_T_Y 0x00400000
b99bd4ef 267
c19d1205
ZW
268#define CONDS_BIT 0x00100000
269#define LOAD_BIT 0x00100000
b99bd4ef
NC
270
271#define DOUBLE_LOAD_FLAG 0x00000001
272
273struct asm_cond
274{
c19d1205 275 const char * template;
b99bd4ef
NC
276 unsigned long value;
277};
278
c19d1205 279#define COND_ALWAYS 0xE
b99bd4ef 280
b99bd4ef
NC
281struct asm_psr
282{
b34976b6 283 const char *template;
b99bd4ef
NC
284 unsigned long field;
285};
286
2d2255b5 287/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
288#define SPSR_BIT (1 << 22)
289
c19d1205
ZW
290/* The individual PSR flag bits. */
291#define PSR_c (1 << 16)
292#define PSR_x (1 << 17)
293#define PSR_s (1 << 18)
294#define PSR_f (1 << 19)
b99bd4ef 295
c19d1205 296struct reloc_entry
bfae80f2 297{
c19d1205
ZW
298 char *name;
299 bfd_reloc_code_real_type reloc;
bfae80f2
RE
300};
301
302enum vfp_sp_reg_pos
303{
304 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
305};
306
307enum vfp_ldstm_type
308{
309 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
310};
311
c19d1205
ZW
312/* ARM register categories. This includes coprocessor numbers and various
313 architecture extensions' registers. */
314enum arm_reg_type
bfae80f2 315{
c19d1205
ZW
316 REG_TYPE_RN,
317 REG_TYPE_CP,
318 REG_TYPE_CN,
319 REG_TYPE_FN,
320 REG_TYPE_VFS,
321 REG_TYPE_VFD,
322 REG_TYPE_VFC,
323 REG_TYPE_MVF,
324 REG_TYPE_MVD,
325 REG_TYPE_MVFX,
326 REG_TYPE_MVDX,
327 REG_TYPE_MVAX,
328 REG_TYPE_DSPSC,
329 REG_TYPE_MMXWR,
330 REG_TYPE_MMXWC,
331 REG_TYPE_MMXWCG,
332 REG_TYPE_XSCALE,
bfae80f2
RE
333};
334
6c43fab6
RE
335/* Structure for a hash table entry for a register. */
336struct reg_entry
337{
c19d1205
ZW
338 const char *name;
339 unsigned char number;
340 unsigned char type;
341 unsigned char builtin;
6c43fab6
RE
342};
343
c19d1205
ZW
344/* Diagnostics used when we don't get a register of the expected type. */
345const char *const reg_expected_msgs[] =
346{
347 N_("ARM register expected"),
348 N_("bad or missing co-processor number"),
349 N_("co-processor register expected"),
350 N_("FPA register expected"),
351 N_("VFP single precision register expected"),
352 N_("VFP double precision register expected"),
353 N_("VFP system register expected"),
354 N_("Maverick MVF register expected"),
355 N_("Maverick MVD register expected"),
356 N_("Maverick MVFX register expected"),
357 N_("Maverick MVDX register expected"),
358 N_("Maverick MVAX register expected"),
359 N_("Maverick DSPSC register expected"),
360 N_("iWMMXt data register expected"),
361 N_("iWMMXt control register expected"),
362 N_("iWMMXt scalar register expected"),
363 N_("XScale accumulator register expected"),
6c43fab6
RE
364};
365
c19d1205
ZW
366/* Some well known registers that we refer to directly elsewhere. */
367#define REG_SP 13
368#define REG_LR 14
369#define REG_PC 15
404ff6b5 370
b99bd4ef
NC
371/* ARM instructions take 4bytes in the object file, Thumb instructions
372 take 2: */
c19d1205 373#define INSN_SIZE 4
b99bd4ef
NC
374
375struct asm_opcode
376{
377 /* Basic string to match. */
c19d1205
ZW
378 const char *template;
379
380 /* Parameters to instruction. */
381 unsigned char operands[8];
382
383 /* Conditional tag - see opcode_lookup. */
384 unsigned int tag : 4;
b99bd4ef
NC
385
386 /* Basic instruction code. */
c19d1205 387 unsigned int avalue : 28;
b99bd4ef 388
c19d1205
ZW
389 /* Thumb-format instruction code. */
390 unsigned int tvalue;
b99bd4ef 391
90e4755a 392 /* Which architecture variant provides this instruction. */
c19d1205
ZW
393 unsigned long avariant;
394 unsigned long tvariant;
395
396 /* Function to call to encode instruction in ARM format. */
397 void (* aencode) (void);
b99bd4ef 398
c19d1205
ZW
399 /* Function to call to encode instruction in Thumb format. */
400 void (* tencode) (void);
b99bd4ef
NC
401};
402
a737bd4d
NC
403/* Defines for various bits that we will want to toggle. */
404#define INST_IMMEDIATE 0x02000000
405#define OFFSET_REG 0x02000000
c19d1205 406#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
407#define SHIFT_BY_REG 0x00000010
408#define PRE_INDEX 0x01000000
409#define INDEX_UP 0x00800000
410#define WRITE_BACK 0x00200000
411#define LDM_TYPE_2_OR_3 0x00400000
90e4755a 412
a737bd4d
NC
413#define LITERAL_MASK 0xf000f000
414#define OPCODE_MASK 0xfe1fffff
415#define V4_STR_BIT 0x00000020
90e4755a 416
a737bd4d 417#define DATA_OP_SHIFT 21
90e4755a 418
a737bd4d
NC
419/* Codes to distinguish the arithmetic instructions. */
420#define OPCODE_AND 0
421#define OPCODE_EOR 1
422#define OPCODE_SUB 2
423#define OPCODE_RSB 3
424#define OPCODE_ADD 4
425#define OPCODE_ADC 5
426#define OPCODE_SBC 6
427#define OPCODE_RSC 7
428#define OPCODE_TST 8
429#define OPCODE_TEQ 9
430#define OPCODE_CMP 10
431#define OPCODE_CMN 11
432#define OPCODE_ORR 12
433#define OPCODE_MOV 13
434#define OPCODE_BIC 14
435#define OPCODE_MVN 15
90e4755a 436
a737bd4d
NC
437#define T_OPCODE_MUL 0x4340
438#define T_OPCODE_TST 0x4200
439#define T_OPCODE_CMN 0x42c0
440#define T_OPCODE_NEG 0x4240
441#define T_OPCODE_MVN 0x43c0
90e4755a 442
a737bd4d
NC
443#define T_OPCODE_ADD_R3 0x1800
444#define T_OPCODE_SUB_R3 0x1a00
445#define T_OPCODE_ADD_HI 0x4400
446#define T_OPCODE_ADD_ST 0xb000
447#define T_OPCODE_SUB_ST 0xb080
448#define T_OPCODE_ADD_SP 0xa800
449#define T_OPCODE_ADD_PC 0xa000
450#define T_OPCODE_ADD_I8 0x3000
451#define T_OPCODE_SUB_I8 0x3800
452#define T_OPCODE_ADD_I3 0x1c00
453#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 454
a737bd4d
NC
455#define T_OPCODE_ASR_R 0x4100
456#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
457#define T_OPCODE_LSR_R 0x40c0
458#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
459#define T_OPCODE_ASR_I 0x1000
460#define T_OPCODE_LSL_I 0x0000
461#define T_OPCODE_LSR_I 0x0800
b99bd4ef 462
a737bd4d
NC
463#define T_OPCODE_MOV_I8 0x2000
464#define T_OPCODE_CMP_I8 0x2800
465#define T_OPCODE_CMP_LR 0x4280
466#define T_OPCODE_MOV_HR 0x4600
467#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 468
a737bd4d
NC
469#define T_OPCODE_LDR_PC 0x4800
470#define T_OPCODE_LDR_SP 0x9800
471#define T_OPCODE_STR_SP 0x9000
472#define T_OPCODE_LDR_IW 0x6800
473#define T_OPCODE_STR_IW 0x6000
474#define T_OPCODE_LDR_IH 0x8800
475#define T_OPCODE_STR_IH 0x8000
476#define T_OPCODE_LDR_IB 0x7800
477#define T_OPCODE_STR_IB 0x7000
478#define T_OPCODE_LDR_RW 0x5800
479#define T_OPCODE_STR_RW 0x5000
480#define T_OPCODE_LDR_RH 0x5a00
481#define T_OPCODE_STR_RH 0x5200
482#define T_OPCODE_LDR_RB 0x5c00
483#define T_OPCODE_STR_RB 0x5400
c9b604bd 484
a737bd4d
NC
485#define T_OPCODE_PUSH 0xb400
486#define T_OPCODE_POP 0xbc00
b99bd4ef 487
a737bd4d 488#define T_OPCODE_BRANCH 0xe7fe
b99bd4ef 489
a737bd4d 490#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 491#define THUMB_PP_PC_LR 0x0100
c19d1205
ZW
492#define THUMB_LOAD_BIT 0x0800
493
494#define BAD_ARGS _("bad arguments to instruction")
495#define BAD_PC _("r15 not allowed here")
496#define BAD_COND _("instruction cannot be conditional")
497#define BAD_OVERLAP _("registers may not be the same")
498#define BAD_HIREG _("lo register required")
499#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
500
501static struct hash_control *arm_ops_hsh;
502static struct hash_control *arm_cond_hsh;
503static struct hash_control *arm_shift_hsh;
504static struct hash_control *arm_psr_hsh;
505static struct hash_control *arm_reg_hsh;
506static struct hash_control *arm_reloc_hsh;
b99bd4ef 507
b99bd4ef
NC
508/* Stuff needed to resolve the label ambiguity
509 As:
510 ...
511 label: <insn>
512 may differ from:
513 ...
514 label:
c19d1205 515 <insn>
b99bd4ef
NC
516*/
517
518symbolS * last_label_seen;
b34976b6 519static int label_is_thumb_function_name = FALSE;
a737bd4d 520\f
3d0c9500
NC
521/* Literal pool structure. Held on a per-section
522 and per-sub-section basis. */
a737bd4d 523
c19d1205 524#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 525typedef struct literal_pool
b99bd4ef 526{
c19d1205
ZW
527 expressionS literals [MAX_LITERAL_POOL_SIZE];
528 unsigned int next_free_entry;
529 unsigned int id;
530 symbolS * symbol;
531 segT section;
532 subsegT sub_section;
61b5f74b 533 struct literal_pool * next;
3d0c9500 534} literal_pool;
b99bd4ef 535
3d0c9500
NC
536/* Pointer to a linked list of literal pools. */
537literal_pool * list_of_pools = NULL;
c19d1205
ZW
538\f
539/* Pure syntax. */
b99bd4ef 540
c19d1205
ZW
541/* This array holds the chars that always start a comment. If the
542 pre-processor is disabled, these aren't very useful. */
543const char comment_chars[] = "@";
3d0c9500 544
c19d1205
ZW
545/* This array holds the chars that only start a comment at the beginning of
546 a line. If the line seems to have the form '# 123 filename'
547 .line and .file directives will appear in the pre-processed output. */
548/* Note that input_file.c hand checks for '#' at the beginning of the
549 first line of the input file. This is because the compiler outputs
550 #NO_APP at the beginning of its output. */
551/* Also note that comments like this one will always work. */
552const char line_comment_chars[] = "#";
3d0c9500 553
c19d1205 554const char line_separator_chars[] = ";";
b99bd4ef 555
c19d1205
ZW
556/* Chars that can be used to separate mant
557 from exp in floating point numbers. */
558const char EXP_CHARS[] = "eE";
3d0c9500 559
c19d1205
ZW
560/* Chars that mean this number is a floating point constant. */
561/* As in 0f12.456 */
562/* or 0d1.2345e12 */
b99bd4ef 563
c19d1205 564const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 565
c19d1205
ZW
566/* Prefix characters that indicate the start of an immediate
567 value. */
568#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 569
c19d1205
ZW
570/* Separator character handling. */
571
572#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
573
574static inline int
575skip_past_char (char ** str, char c)
576{
577 if (**str == c)
578 {
579 (*str)++;
580 return SUCCESS;
3d0c9500 581 }
c19d1205
ZW
582 else
583 return FAIL;
584}
585#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 586
c19d1205
ZW
587/* Arithmetic expressions (possibly involving symbols). */
588
589/* Return TRUE if anything in the expression is a bignum. */
590
591static int
592walk_no_bignums (symbolS * sp)
593{
594 if (symbol_get_value_expression (sp)->X_op == O_big)
595 return 1;
596
597 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 598 {
c19d1205
ZW
599 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
600 || (symbol_get_value_expression (sp)->X_op_symbol
601 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
602 }
603
c19d1205 604 return 0;
3d0c9500
NC
605}
606
c19d1205
ZW
607static int in_my_get_expression = 0;
608
609/* Third argument to my_get_expression. */
610#define GE_NO_PREFIX 0
611#define GE_IMM_PREFIX 1
612#define GE_OPT_PREFIX 2
a737bd4d 613
b99bd4ef 614static int
c19d1205 615my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 616{
c19d1205
ZW
617 char * save_in;
618 segT seg;
b99bd4ef 619
c19d1205
ZW
620 /* In unified syntax, all prefixes are optional. */
621 if (unified_syntax)
622 prefix_mode = GE_OPT_PREFIX;
b99bd4ef 623
c19d1205 624 switch (prefix_mode)
b99bd4ef 625 {
c19d1205
ZW
626 case GE_NO_PREFIX: break;
627 case GE_IMM_PREFIX:
628 if (!is_immediate_prefix (**str))
629 {
630 inst.error = _("immediate expression requires a # prefix");
631 return FAIL;
632 }
633 (*str)++;
634 break;
635 case GE_OPT_PREFIX:
636 if (is_immediate_prefix (**str))
637 (*str)++;
638 break;
639 default: abort ();
640 }
b99bd4ef 641
c19d1205 642 memset (ep, 0, sizeof (expressionS));
b99bd4ef 643
c19d1205
ZW
644 save_in = input_line_pointer;
645 input_line_pointer = *str;
646 in_my_get_expression = 1;
647 seg = expression (ep);
648 in_my_get_expression = 0;
649
650 if (ep->X_op == O_illegal)
b99bd4ef 651 {
c19d1205
ZW
652 /* We found a bad expression in md_operand(). */
653 *str = input_line_pointer;
654 input_line_pointer = save_in;
655 if (inst.error == NULL)
656 inst.error = _("bad expression");
657 return 1;
658 }
b99bd4ef 659
c19d1205
ZW
660#ifdef OBJ_AOUT
661 if (seg != absolute_section
662 && seg != text_section
663 && seg != data_section
664 && seg != bss_section
665 && seg != undefined_section)
666 {
667 inst.error = _("bad segment");
668 *str = input_line_pointer;
669 input_line_pointer = save_in;
670 return 1;
b99bd4ef 671 }
c19d1205 672#endif
b99bd4ef 673
c19d1205
ZW
674 /* Get rid of any bignums now, so that we don't generate an error for which
675 we can't establish a line number later on. Big numbers are never valid
676 in instructions, which is where this routine is always called. */
677 if (ep->X_op == O_big
678 || (ep->X_add_symbol
679 && (walk_no_bignums (ep->X_add_symbol)
680 || (ep->X_op_symbol
681 && walk_no_bignums (ep->X_op_symbol)))))
682 {
683 inst.error = _("invalid constant");
684 *str = input_line_pointer;
685 input_line_pointer = save_in;
686 return 1;
687 }
b99bd4ef 688
c19d1205
ZW
689 *str = input_line_pointer;
690 input_line_pointer = save_in;
691 return 0;
b99bd4ef
NC
692}
693
c19d1205
ZW
694/* Turn a string in input_line_pointer into a floating point constant
695 of type TYPE, and store the appropriate bytes in *LITP. The number
696 of LITTLENUMS emitted is stored in *SIZEP. An error message is
697 returned, or NULL on OK.
b99bd4ef 698
c19d1205
ZW
699 Note that fp constants aren't represent in the normal way on the ARM.
700 In big endian mode, things are as expected. However, in little endian
701 mode fp constants are big-endian word-wise, and little-endian byte-wise
702 within the words. For example, (double) 1.1 in big endian mode is
703 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
704 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 705
c19d1205 706 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 707
c19d1205
ZW
708char *
709md_atof (int type, char * litP, int * sizeP)
710{
711 int prec;
712 LITTLENUM_TYPE words[MAX_LITTLENUMS];
713 char *t;
714 int i;
b99bd4ef 715
c19d1205
ZW
716 switch (type)
717 {
718 case 'f':
719 case 'F':
720 case 's':
721 case 'S':
722 prec = 2;
723 break;
b99bd4ef 724
c19d1205
ZW
725 case 'd':
726 case 'D':
727 case 'r':
728 case 'R':
729 prec = 4;
730 break;
b99bd4ef 731
c19d1205
ZW
732 case 'x':
733 case 'X':
734 prec = 6;
735 break;
b99bd4ef 736
c19d1205
ZW
737 case 'p':
738 case 'P':
739 prec = 6;
740 break;
a737bd4d 741
c19d1205
ZW
742 default:
743 *sizeP = 0;
744 return _("bad call to MD_ATOF()");
745 }
b99bd4ef 746
c19d1205
ZW
747 t = atof_ieee (input_line_pointer, type, words);
748 if (t)
749 input_line_pointer = t;
750 *sizeP = prec * 2;
b99bd4ef 751
c19d1205
ZW
752 if (target_big_endian)
753 {
754 for (i = 0; i < prec; i++)
755 {
756 md_number_to_chars (litP, (valueT) words[i], 2);
757 litP += 2;
758 }
759 }
760 else
761 {
762 if (cpu_variant & FPU_ARCH_VFP)
763 for (i = prec - 1; i >= 0; i--)
764 {
765 md_number_to_chars (litP, (valueT) words[i], 2);
766 litP += 2;
767 }
768 else
769 /* For a 4 byte float the order of elements in `words' is 1 0.
770 For an 8 byte float the order is 1 0 3 2. */
771 for (i = 0; i < prec; i += 2)
772 {
773 md_number_to_chars (litP, (valueT) words[i + 1], 2);
774 md_number_to_chars (litP + 2, (valueT) words[i], 2);
775 litP += 4;
776 }
777 }
b99bd4ef 778
c19d1205
ZW
779 return 0;
780}
b99bd4ef 781
c19d1205
ZW
782/* We handle all bad expressions here, so that we can report the faulty
783 instruction in the error message. */
784void
785md_operand (expressionS * expr)
786{
787 if (in_my_get_expression)
788 expr->X_op = O_illegal;
b99bd4ef
NC
789}
790
c19d1205 791/* Immediate values. */
b99bd4ef 792
c19d1205
ZW
793/* Generic immediate-value read function for use in directives.
794 Accepts anything that 'expression' can fold to a constant.
795 *val receives the number. */
796#ifdef OBJ_ELF
797static int
798immediate_for_directive (int *val)
b99bd4ef 799{
c19d1205
ZW
800 expressionS exp;
801 exp.X_op = O_illegal;
b99bd4ef 802
c19d1205
ZW
803 if (is_immediate_prefix (*input_line_pointer))
804 {
805 input_line_pointer++;
806 expression (&exp);
807 }
b99bd4ef 808
c19d1205
ZW
809 if (exp.X_op != O_constant)
810 {
811 as_bad (_("expected #constant"));
812 ignore_rest_of_line ();
813 return FAIL;
814 }
815 *val = exp.X_add_number;
816 return SUCCESS;
b99bd4ef 817}
c19d1205 818#endif
b99bd4ef 819
c19d1205 820/* Register parsing. */
b99bd4ef 821
c19d1205
ZW
822/* Generic register parser. CCP points to what should be the
823 beginning of a register name. If it is indeed a valid register
824 name, advance CCP over it and return the reg_entry structure;
825 otherwise return NULL. Does not issue diagnostics. */
826
827static struct reg_entry *
828arm_reg_parse_multi (char **ccp)
b99bd4ef 829{
c19d1205
ZW
830 char *start = *ccp;
831 char *p;
832 struct reg_entry *reg;
b99bd4ef 833
c19d1205
ZW
834#ifdef REGISTER_PREFIX
835 if (*start != REGISTER_PREFIX)
836 return FAIL;
837 start++;
838#endif
839#ifdef OPTIONAL_REGISTER_PREFIX
840 if (*start == OPTIONAL_REGISTER_PREFIX)
841 start++;
842#endif
b99bd4ef 843
c19d1205
ZW
844 p = start;
845 if (!ISALPHA (*p) || !is_name_beginner (*p))
846 return NULL;
b99bd4ef 847
c19d1205
ZW
848 do
849 p++;
850 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
851
852 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
853
854 if (!reg)
855 return NULL;
856
857 *ccp = p;
858 return reg;
b99bd4ef
NC
859}
860
c19d1205
ZW
861/* As above, but the register must be of type TYPE, and the return
862 value is the register number or NULL. */
863
b99bd4ef 864static int
c19d1205 865arm_reg_parse (char **ccp, enum arm_reg_type type)
b99bd4ef 866{
c19d1205
ZW
867 char *start = *ccp;
868 struct reg_entry *reg = arm_reg_parse_multi (ccp);
b99bd4ef 869
c19d1205
ZW
870 if (reg && reg->type == type)
871 return reg->number;
6057a28f 872
c19d1205
ZW
873 /* Alternative syntaxes are accepted for a few register classes. */
874 switch (type)
875 {
876 case REG_TYPE_MVF:
877 case REG_TYPE_MVD:
878 case REG_TYPE_MVFX:
879 case REG_TYPE_MVDX:
880 /* Generic coprocessor register names are allowed for these. */
881 if (reg->type == REG_TYPE_CN)
882 return reg->number;
883 break;
69b97547 884
c19d1205
ZW
885 case REG_TYPE_CP:
886 /* For backward compatibility, a bare number is valid here. */
887 {
888 unsigned long processor = strtoul (start, ccp, 10);
889 if (*ccp != start && processor <= 15)
890 return processor;
891 }
6057a28f 892
c19d1205
ZW
893 case REG_TYPE_MMXWC:
894 /* WC includes WCG. ??? I'm not sure this is true for all
895 instructions that take WC registers. */
896 if (reg->type == REG_TYPE_MMXWCG)
897 return reg->number;
6057a28f 898 break;
c19d1205 899
6057a28f 900 default:
c19d1205 901 break;
6057a28f
NC
902 }
903
c19d1205
ZW
904 *ccp = start;
905 return FAIL;
906}
69b97547 907
c19d1205
ZW
908/* Parse an ARM register list. Returns the bitmask, or FAIL. */
909static long
910parse_reg_list (char ** strp)
911{
912 char * str = * strp;
913 long range = 0;
914 int another_range;
a737bd4d 915
c19d1205
ZW
916 /* We come back here if we get ranges concatenated by '+' or '|'. */
917 do
6057a28f 918 {
c19d1205 919 another_range = 0;
a737bd4d 920
c19d1205
ZW
921 if (*str == '{')
922 {
923 int in_range = 0;
924 int cur_reg = -1;
a737bd4d 925
c19d1205
ZW
926 str++;
927 do
928 {
929 int reg;
6057a28f 930
c19d1205
ZW
931 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
932 {
933 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
934 return FAIL;
935 }
a737bd4d 936
c19d1205
ZW
937 if (in_range)
938 {
939 int i;
a737bd4d 940
c19d1205
ZW
941 if (reg <= cur_reg)
942 {
943 inst.error = _("bad range in register list");
944 return FAIL;
945 }
40a18ebd 946
c19d1205
ZW
947 for (i = cur_reg + 1; i < reg; i++)
948 {
949 if (range & (1 << i))
950 as_tsktsk
951 (_("Warning: duplicated register (r%d) in register list"),
952 i);
953 else
954 range |= 1 << i;
955 }
956 in_range = 0;
957 }
a737bd4d 958
c19d1205
ZW
959 if (range & (1 << reg))
960 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
961 reg);
962 else if (reg <= cur_reg)
963 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 964
c19d1205
ZW
965 range |= 1 << reg;
966 cur_reg = reg;
967 }
968 while (skip_past_comma (&str) != FAIL
969 || (in_range = 1, *str++ == '-'));
970 str--;
a737bd4d 971
c19d1205
ZW
972 if (*str++ != '}')
973 {
974 inst.error = _("missing `}'");
975 return FAIL;
976 }
977 }
978 else
979 {
980 expressionS expr;
40a18ebd 981
c19d1205
ZW
982 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
983 return FAIL;
40a18ebd 984
c19d1205
ZW
985 if (expr.X_op == O_constant)
986 {
987 if (expr.X_add_number
988 != (expr.X_add_number & 0x0000ffff))
989 {
990 inst.error = _("invalid register mask");
991 return FAIL;
992 }
a737bd4d 993
c19d1205
ZW
994 if ((range & expr.X_add_number) != 0)
995 {
996 int regno = range & expr.X_add_number;
a737bd4d 997
c19d1205
ZW
998 regno &= -regno;
999 regno = (1 << regno) - 1;
1000 as_tsktsk
1001 (_("Warning: duplicated register (r%d) in register list"),
1002 regno);
1003 }
a737bd4d 1004
c19d1205
ZW
1005 range |= expr.X_add_number;
1006 }
1007 else
1008 {
1009 if (inst.reloc.type != 0)
1010 {
1011 inst.error = _("expression too complex");
1012 return FAIL;
1013 }
a737bd4d 1014
c19d1205
ZW
1015 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1016 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1017 inst.reloc.pc_rel = 0;
1018 }
1019 }
a737bd4d 1020
c19d1205
ZW
1021 if (*str == '|' || *str == '+')
1022 {
1023 str++;
1024 another_range = 1;
1025 }
a737bd4d 1026 }
c19d1205 1027 while (another_range);
a737bd4d 1028
c19d1205
ZW
1029 *strp = str;
1030 return range;
a737bd4d
NC
1031}
1032
c19d1205
ZW
1033/* Parse a VFP register list. If the string is invalid return FAIL.
1034 Otherwise return the number of registers, and set PBASE to the first
1035 register. Double precision registers are matched if DP is nonzero. */
6057a28f 1036
c19d1205
ZW
1037static int
1038parse_vfp_reg_list (char **str, int *pbase, int dp)
6057a28f 1039{
c19d1205
ZW
1040 int base_reg;
1041 int new_base;
1042 int regtype;
1043 int max_regs;
1044 int count = 0;
1045 int warned = 0;
1046 unsigned long mask = 0;
a737bd4d 1047 int i;
6057a28f 1048
c19d1205
ZW
1049 if (**str != '{')
1050 return FAIL;
6057a28f 1051
c19d1205 1052 (*str)++;
6057a28f 1053
c19d1205 1054 if (dp)
a737bd4d 1055 {
c19d1205
ZW
1056 regtype = REG_TYPE_VFD;
1057 max_regs = 16;
1058 }
1059 else
1060 {
1061 regtype = REG_TYPE_VFS;
1062 max_regs = 32;
1063 }
6057a28f 1064
c19d1205 1065 base_reg = max_regs;
a737bd4d 1066
c19d1205
ZW
1067 do
1068 {
1069 new_base = arm_reg_parse (str, regtype);
1070 if (new_base == FAIL)
a737bd4d 1071 {
c19d1205
ZW
1072 inst.error = gettext (reg_expected_msgs[regtype]);
1073 return FAIL;
1074 }
a737bd4d 1075
c19d1205
ZW
1076 if (new_base < base_reg)
1077 base_reg = new_base;
a737bd4d 1078
c19d1205
ZW
1079 if (mask & (1 << new_base))
1080 {
1081 inst.error = _("invalid register list");
1082 return FAIL;
a737bd4d 1083 }
a737bd4d 1084
c19d1205
ZW
1085 if ((mask >> new_base) != 0 && ! warned)
1086 {
1087 as_tsktsk (_("register list not in ascending order"));
1088 warned = 1;
1089 }
0bbf2aa4 1090
c19d1205
ZW
1091 mask |= 1 << new_base;
1092 count++;
0bbf2aa4 1093
c19d1205
ZW
1094 if (**str == '-') /* We have the start of a range expression */
1095 {
1096 int high_range;
0bbf2aa4 1097
c19d1205 1098 (*str)++;
0bbf2aa4 1099
c19d1205
ZW
1100 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1101 {
1102 inst.error = gettext (reg_expected_msgs[regtype]);
1103 return FAIL;
1104 }
0bbf2aa4 1105
c19d1205
ZW
1106 if (high_range <= new_base)
1107 {
1108 inst.error = _("register range not in ascending order");
1109 return FAIL;
1110 }
0bbf2aa4 1111
c19d1205 1112 for (new_base++; new_base <= high_range; new_base++)
0bbf2aa4 1113 {
c19d1205 1114 if (mask & (1 << new_base))
0bbf2aa4 1115 {
c19d1205
ZW
1116 inst.error = _("invalid register list");
1117 return FAIL;
0bbf2aa4 1118 }
c19d1205
ZW
1119
1120 mask |= 1 << new_base;
1121 count++;
0bbf2aa4 1122 }
0bbf2aa4 1123 }
0bbf2aa4 1124 }
c19d1205 1125 while (skip_past_comma (str) != FAIL);
0bbf2aa4 1126
c19d1205 1127 (*str)++;
0bbf2aa4 1128
c19d1205
ZW
1129 /* Sanity check -- should have raised a parse error above. */
1130 if (count == 0 || count > max_regs)
1131 abort ();
1132
1133 *pbase = base_reg;
1134
1135 /* Final test -- the registers must be consecutive. */
1136 mask >>= base_reg;
1137 for (i = 0; i < count; i++)
1138 {
1139 if ((mask & (1u << i)) == 0)
1140 {
1141 inst.error = _("non-contiguous register range");
1142 return FAIL;
1143 }
1144 }
1145
1146 return count;
b99bd4ef
NC
1147}
1148
c19d1205
ZW
1149/* Parse an explicit relocation suffix on an expression. This is
1150 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1151 arm_reloc_hsh contains no entries, so this function can only
1152 succeed if there is no () after the word. Returns -1 on error,
1153 BFD_RELOC_UNUSED if there wasn't any suffix. */
1154static int
1155parse_reloc (char **str)
b99bd4ef 1156{
c19d1205
ZW
1157 struct reloc_entry *r;
1158 char *p, *q;
b99bd4ef 1159
c19d1205
ZW
1160 if (**str != '(')
1161 return BFD_RELOC_UNUSED;
b99bd4ef 1162
c19d1205
ZW
1163 p = *str + 1;
1164 q = p;
1165
1166 while (*q && *q != ')' && *q != ',')
1167 q++;
1168 if (*q != ')')
1169 return -1;
1170
1171 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1172 return -1;
1173
1174 *str = q + 1;
1175 return r->reloc;
b99bd4ef
NC
1176}
1177
c19d1205
ZW
1178/* Directives: register aliases. */
1179
b99bd4ef 1180static void
c19d1205 1181insert_reg_alias (char *str, int number, int type)
b99bd4ef 1182{
c19d1205
ZW
1183 struct reg_entry *new;
1184 const char *name;
b99bd4ef 1185
c19d1205
ZW
1186 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1187 {
1188 if (new->builtin)
1189 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1190
c19d1205
ZW
1191 /* Only warn about a redefinition if it's not defined as the
1192 same register. */
1193 else if (new->number != number || new->type != type)
1194 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1195
c19d1205
ZW
1196 return;
1197 }
b99bd4ef 1198
c19d1205
ZW
1199 name = xstrdup (str);
1200 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1201
c19d1205
ZW
1202 new->name = name;
1203 new->number = number;
1204 new->type = type;
1205 new->builtin = FALSE;
b99bd4ef 1206
c19d1205
ZW
1207 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1208 abort ();
1209}
b99bd4ef 1210
c19d1205 1211/* Look for the .req directive. This is of the form:
b99bd4ef 1212
c19d1205 1213 new_register_name .req existing_register_name
b99bd4ef 1214
c19d1205
ZW
1215 If we find one, or if it looks sufficiently like one that we want to
1216 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 1217
c19d1205
ZW
1218static int
1219create_register_alias (char * newname, char *p)
1220{
1221 struct reg_entry *old;
1222 char *oldname, *nbuf;
1223 size_t nlen;
b99bd4ef 1224
c19d1205
ZW
1225 /* The input scrubber ensures that whitespace after the mnemonic is
1226 collapsed to single spaces. */
1227 oldname = p;
1228 if (strncmp (oldname, " .req ", 6) != 0)
1229 return 0;
b99bd4ef 1230
c19d1205
ZW
1231 oldname += 6;
1232 if (*oldname == '\0')
1233 return 0;
b99bd4ef 1234
c19d1205
ZW
1235 old = hash_find (arm_reg_hsh, oldname);
1236 if (!old)
b99bd4ef 1237 {
c19d1205
ZW
1238 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1239 return 1;
b99bd4ef
NC
1240 }
1241
c19d1205
ZW
1242 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1243 the desired alias name, and p points to its end. If not, then
1244 the desired alias name is in the global original_case_string. */
1245#ifdef TC_CASE_SENSITIVE
1246 nlen = p - newname;
1247#else
1248 newname = original_case_string;
1249 nlen = strlen (newname);
1250#endif
b99bd4ef 1251
c19d1205
ZW
1252 nbuf = alloca (nlen + 1);
1253 memcpy (nbuf, newname, nlen);
1254 nbuf[nlen] = '\0';
b99bd4ef 1255
c19d1205
ZW
1256 /* Create aliases under the new name as stated; an all-lowercase
1257 version of the new name; and an all-uppercase version of the new
1258 name. */
1259 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 1260
c19d1205
ZW
1261 for (p = nbuf; *p; p++)
1262 *p = TOUPPER (*p);
1263
1264 if (strncmp (nbuf, newname, nlen))
1265 insert_reg_alias (nbuf, old->number, old->type);
1266
1267 for (p = nbuf; *p; p++)
1268 *p = TOLOWER (*p);
1269
1270 if (strncmp (nbuf, newname, nlen))
1271 insert_reg_alias (nbuf, old->number, old->type);
1272
1273 return 1;
b99bd4ef
NC
1274}
1275
c19d1205
ZW
1276/* Should never be called, as .req goes between the alias and the
1277 register name, not at the beginning of the line. */
b99bd4ef 1278static void
c19d1205 1279s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 1280{
c19d1205
ZW
1281 as_bad (_("invalid syntax for .req directive"));
1282}
b99bd4ef 1283
c19d1205
ZW
1284/* The .unreq directive deletes an alias which was previously defined
1285 by .req. For example:
b99bd4ef 1286
c19d1205
ZW
1287 my_alias .req r11
1288 .unreq my_alias */
b99bd4ef
NC
1289
1290static void
c19d1205 1291s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 1292{
c19d1205
ZW
1293 char * name;
1294 char saved_char;
b99bd4ef 1295
c19d1205
ZW
1296 name = input_line_pointer;
1297
1298 while (*input_line_pointer != 0
1299 && *input_line_pointer != ' '
1300 && *input_line_pointer != '\n')
1301 ++input_line_pointer;
1302
1303 saved_char = *input_line_pointer;
1304 *input_line_pointer = 0;
1305
1306 if (!*name)
1307 as_bad (_("invalid syntax for .unreq directive"));
1308 else
1309 {
1310 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1311
1312 if (!reg)
1313 as_bad (_("unknown register alias '%s'"), name);
1314 else if (reg->builtin)
1315 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1316 name);
1317 else
1318 {
1319 hash_delete (arm_reg_hsh, name);
1320 free ((char *) reg->name);
1321 free (reg);
1322 }
1323 }
b99bd4ef 1324
c19d1205 1325 *input_line_pointer = saved_char;
b99bd4ef
NC
1326 demand_empty_rest_of_line ();
1327}
1328
c19d1205
ZW
1329/* Directives: Instruction set selection. */
1330
1331#ifdef OBJ_ELF
1332/* This code is to handle mapping symbols as defined in the ARM ELF spec.
1333 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1334 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1335 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1336
1337static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
1338
1339static void
c19d1205 1340mapping_state (enum mstate state)
b99bd4ef 1341{
a737bd4d 1342 symbolS * symbolP;
c19d1205
ZW
1343 const char * symname;
1344 int type;
b99bd4ef 1345
c19d1205
ZW
1346 if (mapstate == state)
1347 /* The mapping symbol has already been emitted.
1348 There is nothing else to do. */
1349 return;
b99bd4ef 1350
c19d1205 1351 mapstate = state;
b99bd4ef 1352
c19d1205 1353 switch (state)
b99bd4ef 1354 {
c19d1205
ZW
1355 case MAP_DATA:
1356 symname = "$d";
1357 type = BSF_NO_FLAGS;
1358 break;
1359 case MAP_ARM:
1360 symname = "$a";
1361 type = BSF_NO_FLAGS;
1362 break;
1363 case MAP_THUMB:
1364 symname = "$t";
1365 type = BSF_NO_FLAGS;
1366 break;
1367 case MAP_UNDEFINED:
1368 return;
1369 default:
1370 abort ();
1371 }
1372
1373 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1374
1375 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1376 symbol_table_insert (symbolP);
1377 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1378
1379 switch (state)
1380 {
1381 case MAP_ARM:
1382 THUMB_SET_FUNC (symbolP, 0);
1383 ARM_SET_THUMB (symbolP, 0);
1384 ARM_SET_INTERWORK (symbolP, support_interwork);
1385 break;
1386
1387 case MAP_THUMB:
1388 THUMB_SET_FUNC (symbolP, 1);
1389 ARM_SET_THUMB (symbolP, 1);
1390 ARM_SET_INTERWORK (symbolP, support_interwork);
1391 break;
1392
1393 case MAP_DATA:
1394 default:
1395 return;
1396 }
1397}
1398#else
1399#define mapping_state(x) /* nothing */
1400#endif
1401
1402/* Find the real, Thumb encoded start of a Thumb function. */
1403
1404static symbolS *
1405find_real_start (symbolS * symbolP)
1406{
1407 char * real_start;
1408 const char * name = S_GET_NAME (symbolP);
1409 symbolS * new_target;
1410
1411 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1412#define STUB_NAME ".real_start_of"
1413
1414 if (name == NULL)
1415 abort ();
1416
05ab1f3b
ZW
1417 /* Names that start with '.' are local labels, not function entry points.
1418 The compiler may generate BL instructions to these labels because it
1419 needs to perform a branch to a far away location. */
c19d1205
ZW
1420 if (name[0] == '.')
1421 return symbolP;
1422
1423 real_start = malloc (strlen (name) + strlen (STUB_NAME) + 1);
1424 sprintf (real_start, "%s%s", STUB_NAME, name);
1425
1426 new_target = symbol_find (real_start);
1427
1428 if (new_target == NULL)
1429 {
1430 as_warn ("Failed to find real start of function: %s\n", name);
1431 new_target = symbolP;
1432 }
1433
1434 free (real_start);
1435
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
c19d1205
ZW
1975 if (size > nbytes)
1976 as_bad ("%s relocations do not fit in %d bytes",
1977 howto->name, nbytes);
1978 else
1979 {
1980 /* We've parsed an expression stopping at O_symbol.
1981 But there may be more expression left now that we
1982 have parsed the relocation marker. Parse it again.
1983 XXX Surely there is a cleaner way to do this. */
1984 char *p = input_line_pointer;
1985 int offset;
1986 char *save_buf = alloca (input_line_pointer - base);
1987 memcpy (save_buf, base, input_line_pointer - base);
1988 memmove (base + (input_line_pointer - before_reloc),
1989 base, before_reloc - base);
1990
1991 input_line_pointer = base + (input_line_pointer-before_reloc);
1992 expression (&exp);
1993 memcpy (base, save_buf, p - base);
1994
1995 offset = nbytes - size;
1996 p = frag_more ((int) nbytes);
1997 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
1998 size, &exp, 0, reloc);
1999 }
2000 }
2001 }
b99bd4ef 2002 }
c19d1205 2003 while (*input_line_pointer++ == ',');
b99bd4ef 2004
c19d1205
ZW
2005 /* Put terminator back into stream. */
2006 input_line_pointer --;
2007 demand_empty_rest_of_line ();
b99bd4ef
NC
2008}
2009
b99bd4ef 2010
c19d1205 2011/* Parse a .rel31 directive. */
b99bd4ef 2012
c19d1205
ZW
2013static void
2014s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2015{
2016 expressionS exp;
2017 char *p;
2018 valueT highbit;
b99bd4ef 2019
c19d1205
ZW
2020 highbit = 0;
2021 if (*input_line_pointer == '1')
2022 highbit = 0x80000000;
2023 else if (*input_line_pointer != '0')
2024 as_bad (_("expected 0 or 1"));
b99bd4ef 2025
c19d1205
ZW
2026 input_line_pointer++;
2027 if (*input_line_pointer != ',')
2028 as_bad (_("missing comma"));
2029 input_line_pointer++;
b99bd4ef 2030
c19d1205
ZW
2031#ifdef md_flush_pending_output
2032 md_flush_pending_output ();
2033#endif
b99bd4ef 2034
c19d1205
ZW
2035#ifdef md_cons_align
2036 md_cons_align (4);
2037#endif
b99bd4ef 2038
c19d1205 2039 mapping_state (MAP_DATA);
b99bd4ef 2040
c19d1205 2041 expression (&exp);
b99bd4ef 2042
c19d1205
ZW
2043 p = frag_more (4);
2044 md_number_to_chars (p, highbit, 4);
2045 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2046 BFD_RELOC_ARM_PREL31);
b99bd4ef 2047
c19d1205 2048 demand_empty_rest_of_line ();
b99bd4ef
NC
2049}
2050
c19d1205 2051/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2052
c19d1205 2053/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2054
c19d1205
ZW
2055static void
2056s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2057{
2058 demand_empty_rest_of_line ();
2059 /* Mark the start of the function. */
2060 unwind.proc_start = expr_build_dot ();
b99bd4ef 2061
c19d1205
ZW
2062 /* Reset the rest of the unwind info. */
2063 unwind.opcode_count = 0;
2064 unwind.table_entry = NULL;
2065 unwind.personality_routine = NULL;
2066 unwind.personality_index = -1;
2067 unwind.frame_size = 0;
2068 unwind.fp_offset = 0;
2069 unwind.fp_reg = 13;
2070 unwind.fp_used = 0;
2071 unwind.sp_restored = 0;
2072}
b99bd4ef 2073
b99bd4ef 2074
c19d1205
ZW
2075/* Parse a handlerdata directive. Creates the exception handling table entry
2076 for the function. */
b99bd4ef 2077
c19d1205
ZW
2078static void
2079s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2080{
2081 demand_empty_rest_of_line ();
2082 if (unwind.table_entry)
2083 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2084
c19d1205
ZW
2085 create_unwind_entry (1);
2086}
a737bd4d 2087
c19d1205 2088/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2089
c19d1205
ZW
2090static void
2091s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2092{
2093 long where;
2094 char *ptr;
2095 valueT val;
f02232aa 2096
c19d1205 2097 demand_empty_rest_of_line ();
f02232aa 2098
c19d1205
ZW
2099 /* Add eh table entry. */
2100 if (unwind.table_entry == NULL)
2101 val = create_unwind_entry (0);
2102 else
2103 val = 0;
f02232aa 2104
c19d1205
ZW
2105 /* Add index table entry. This is two words. */
2106 start_unwind_section (unwind.saved_seg, 1);
2107 frag_align (2, 0, 0);
2108 record_alignment (now_seg, 2);
b99bd4ef 2109
c19d1205
ZW
2110 ptr = frag_more (8);
2111 where = frag_now_fix () - 8;
f02232aa 2112
c19d1205
ZW
2113 /* Self relative offset of the function start. */
2114 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2115 BFD_RELOC_ARM_PREL31);
f02232aa 2116
c19d1205
ZW
2117 /* Indicate dependency on EHABI-defined personality routines to the
2118 linker, if it hasn't been done already. */
2119 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2120 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2121 {
2122 static const char *const name[] = {
2123 "__aeabi_unwind_cpp_pr0",
2124 "__aeabi_unwind_cpp_pr1",
2125 "__aeabi_unwind_cpp_pr2"
2126 };
2127 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2128 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2129 marked_pr_dependency |= 1 << unwind.personality_index;
2130 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2131 = marked_pr_dependency;
2132 }
f02232aa 2133
c19d1205
ZW
2134 if (val)
2135 /* Inline exception table entry. */
2136 md_number_to_chars (ptr + 4, val, 4);
2137 else
2138 /* Self relative offset of the table entry. */
2139 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2140 BFD_RELOC_ARM_PREL31);
f02232aa 2141
c19d1205
ZW
2142 /* Restore the original section. */
2143 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2144}
f02232aa 2145
f02232aa 2146
c19d1205 2147/* Parse an unwind_cantunwind directive. */
b99bd4ef 2148
c19d1205
ZW
2149static void
2150s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2151{
2152 demand_empty_rest_of_line ();
2153 if (unwind.personality_routine || unwind.personality_index != -1)
2154 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2155
c19d1205
ZW
2156 unwind.personality_index = -2;
2157}
b99bd4ef 2158
b99bd4ef 2159
c19d1205 2160/* Parse a personalityindex directive. */
b99bd4ef 2161
c19d1205
ZW
2162static void
2163s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2164{
2165 expressionS exp;
b99bd4ef 2166
c19d1205
ZW
2167 if (unwind.personality_routine || unwind.personality_index != -1)
2168 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2169
c19d1205 2170 expression (&exp);
b99bd4ef 2171
c19d1205
ZW
2172 if (exp.X_op != O_constant
2173 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2174 {
c19d1205
ZW
2175 as_bad (_("bad personality routine number"));
2176 ignore_rest_of_line ();
2177 return;
b99bd4ef
NC
2178 }
2179
c19d1205 2180 unwind.personality_index = exp.X_add_number;
b99bd4ef 2181
c19d1205
ZW
2182 demand_empty_rest_of_line ();
2183}
e16bb312 2184
e16bb312 2185
c19d1205 2186/* Parse a personality directive. */
e16bb312 2187
c19d1205
ZW
2188static void
2189s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2190{
2191 char *name, *p, c;
a737bd4d 2192
c19d1205
ZW
2193 if (unwind.personality_routine || unwind.personality_index != -1)
2194 as_bad (_("duplicate .personality directive"));
a737bd4d 2195
c19d1205
ZW
2196 name = input_line_pointer;
2197 c = get_symbol_end ();
2198 p = input_line_pointer;
2199 unwind.personality_routine = symbol_find_or_make (name);
2200 *p = c;
2201 demand_empty_rest_of_line ();
2202}
e16bb312 2203
e16bb312 2204
c19d1205 2205/* Parse a directive saving core registers. */
e16bb312 2206
c19d1205
ZW
2207static void
2208s_arm_unwind_save_core (void)
e16bb312 2209{
c19d1205
ZW
2210 valueT op;
2211 long range;
2212 int n;
e16bb312 2213
c19d1205
ZW
2214 range = parse_reg_list (&input_line_pointer);
2215 if (range == FAIL)
e16bb312 2216 {
c19d1205
ZW
2217 as_bad (_("expected register list"));
2218 ignore_rest_of_line ();
2219 return;
2220 }
e16bb312 2221
c19d1205 2222 demand_empty_rest_of_line ();
e16bb312 2223
c19d1205
ZW
2224 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2225 into .unwind_save {..., sp...}. We aren't bothered about the value of
2226 ip because it is clobbered by calls. */
2227 if (unwind.sp_restored && unwind.fp_reg == 12
2228 && (range & 0x3000) == 0x1000)
2229 {
2230 unwind.opcode_count--;
2231 unwind.sp_restored = 0;
2232 range = (range | 0x2000) & ~0x1000;
2233 unwind.pending_offset = 0;
2234 }
e16bb312 2235
c19d1205
ZW
2236 /* See if we can use the short opcodes. These pop a block of upto 8
2237 registers starting with r4, plus maybe r14. */
2238 for (n = 0; n < 8; n++)
2239 {
2240 /* Break at the first non-saved register. */
2241 if ((range & (1 << (n + 4))) == 0)
2242 break;
e16bb312 2243 }
c19d1205
ZW
2244 /* See if there are any other bits set. */
2245 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
e16bb312 2246 {
c19d1205
ZW
2247 /* Use the long form. */
2248 op = 0x8000 | ((range >> 4) & 0xfff);
2249 add_unwind_opcode (op, 2);
e16bb312 2250 }
c19d1205 2251 else
0dd132b6 2252 {
c19d1205
ZW
2253 /* Use the short form. */
2254 if (range & 0x4000)
2255 op = 0xa8; /* Pop r14. */
0dd132b6 2256 else
c19d1205
ZW
2257 op = 0xa0; /* Do not pop r14. */
2258 op |= (n - 1);
2259 add_unwind_opcode (op, 1);
2260 }
0dd132b6 2261
c19d1205
ZW
2262 /* Pop r0-r3. */
2263 if (range & 0xf)
2264 {
2265 op = 0xb100 | (range & 0xf);
2266 add_unwind_opcode (op, 2);
0dd132b6
NC
2267 }
2268
c19d1205
ZW
2269 /* Record the number of bytes pushed. */
2270 for (n = 0; n < 16; n++)
2271 {
2272 if (range & (1 << n))
2273 unwind.frame_size += 4;
2274 }
0dd132b6
NC
2275}
2276
c19d1205
ZW
2277
2278/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2279
2280static void
c19d1205 2281s_arm_unwind_save_fpa (int reg)
b99bd4ef 2282{
c19d1205
ZW
2283 expressionS exp;
2284 int num_regs;
2285 valueT op;
b99bd4ef 2286
c19d1205
ZW
2287 /* Get Number of registers to transfer. */
2288 if (skip_past_comma (&input_line_pointer) != FAIL)
2289 expression (&exp);
2290 else
2291 exp.X_op = O_illegal;
b99bd4ef 2292
c19d1205 2293 if (exp.X_op != O_constant)
b99bd4ef 2294 {
c19d1205
ZW
2295 as_bad (_("expected , <constant>"));
2296 ignore_rest_of_line ();
b99bd4ef
NC
2297 return;
2298 }
2299
c19d1205
ZW
2300 num_regs = exp.X_add_number;
2301
2302 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2303 {
c19d1205
ZW
2304 as_bad (_("number of registers must be in the range [1:4]"));
2305 ignore_rest_of_line ();
b99bd4ef
NC
2306 return;
2307 }
2308
c19d1205 2309 demand_empty_rest_of_line ();
b99bd4ef 2310
c19d1205
ZW
2311 if (reg == 4)
2312 {
2313 /* Short form. */
2314 op = 0xb4 | (num_regs - 1);
2315 add_unwind_opcode (op, 1);
2316 }
b99bd4ef
NC
2317 else
2318 {
c19d1205
ZW
2319 /* Long form. */
2320 op = 0xc800 | (reg << 4) | (num_regs - 1);
2321 add_unwind_opcode (op, 2);
b99bd4ef 2322 }
c19d1205 2323 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2324}
2325
c19d1205
ZW
2326
2327/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2328
2329static void
c19d1205 2330s_arm_unwind_save_vfp (void)
b99bd4ef 2331{
c19d1205
ZW
2332 int count;
2333 int reg;
2334 valueT op;
b99bd4ef 2335
c19d1205
ZW
2336 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2337 if (count == FAIL)
b99bd4ef 2338 {
c19d1205
ZW
2339 as_bad (_("expected register list"));
2340 ignore_rest_of_line ();
b99bd4ef
NC
2341 return;
2342 }
2343
c19d1205 2344 demand_empty_rest_of_line ();
b99bd4ef 2345
c19d1205 2346 if (reg == 8)
b99bd4ef 2347 {
c19d1205
ZW
2348 /* Short form. */
2349 op = 0xb8 | (count - 1);
2350 add_unwind_opcode (op, 1);
b99bd4ef 2351 }
c19d1205 2352 else
b99bd4ef 2353 {
c19d1205
ZW
2354 /* Long form. */
2355 op = 0xb300 | (reg << 4) | (count - 1);
2356 add_unwind_opcode (op, 2);
b99bd4ef 2357 }
c19d1205
ZW
2358 unwind.frame_size += count * 8 + 4;
2359}
b99bd4ef 2360
b99bd4ef 2361
c19d1205
ZW
2362/* Parse a directive saving iWMMXt data registers. */
2363
2364static void
2365s_arm_unwind_save_mmxwr (void)
2366{
2367 int reg;
2368 int hi_reg;
2369 int i;
2370 unsigned mask = 0;
2371 valueT op;
b99bd4ef 2372
c19d1205
ZW
2373 if (*input_line_pointer == '{')
2374 input_line_pointer++;
b99bd4ef 2375
c19d1205 2376 do
b99bd4ef 2377 {
c19d1205 2378 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2379
c19d1205 2380 if (reg == FAIL)
b99bd4ef 2381 {
c19d1205
ZW
2382 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2383 goto error;
b99bd4ef
NC
2384 }
2385
c19d1205
ZW
2386 if (mask >> reg)
2387 as_tsktsk (_("register list not in ascending order"));
2388 mask |= 1 << reg;
b99bd4ef 2389
c19d1205
ZW
2390 if (*input_line_pointer == '-')
2391 {
2392 input_line_pointer++;
2393 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2394 if (hi_reg == FAIL)
2395 {
2396 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2397 goto error;
2398 }
2399 else if (reg >= hi_reg)
2400 {
2401 as_bad (_("bad register range"));
2402 goto error;
2403 }
2404 for (; reg < hi_reg; reg++)
2405 mask |= 1 << reg;
2406 }
2407 }
2408 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2409
c19d1205
ZW
2410 if (*input_line_pointer == '}')
2411 input_line_pointer++;
b99bd4ef 2412
c19d1205 2413 demand_empty_rest_of_line ();
b99bd4ef 2414
c19d1205
ZW
2415 /* Generate any deferred opcodes becuuse we're going to be looking at
2416 the list. */
2417 flush_pending_unwind ();
b99bd4ef 2418
c19d1205 2419 for (i = 0; i < 16; i++)
b99bd4ef 2420 {
c19d1205
ZW
2421 if (mask & (1 << i))
2422 unwind.frame_size += 8;
b99bd4ef
NC
2423 }
2424
c19d1205
ZW
2425 /* Attempt to combine with a previous opcode. We do this because gcc
2426 likes to output separate unwind directives for a single block of
2427 registers. */
2428 if (unwind.opcode_count > 0)
b99bd4ef 2429 {
c19d1205
ZW
2430 i = unwind.opcodes[unwind.opcode_count - 1];
2431 if ((i & 0xf8) == 0xc0)
2432 {
2433 i &= 7;
2434 /* Only merge if the blocks are contiguous. */
2435 if (i < 6)
2436 {
2437 if ((mask & 0xfe00) == (1 << 9))
2438 {
2439 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2440 unwind.opcode_count--;
2441 }
2442 }
2443 else if (i == 6 && unwind.opcode_count >= 2)
2444 {
2445 i = unwind.opcodes[unwind.opcode_count - 2];
2446 reg = i >> 4;
2447 i &= 0xf;
b99bd4ef 2448
c19d1205
ZW
2449 op = 0xffff << (reg - 1);
2450 if (reg > 0
2451 || ((mask & op) == (1u << (reg - 1))))
2452 {
2453 op = (1 << (reg + i + 1)) - 1;
2454 op &= ~((1 << reg) - 1);
2455 mask |= op;
2456 unwind.opcode_count -= 2;
2457 }
2458 }
2459 }
b99bd4ef
NC
2460 }
2461
c19d1205
ZW
2462 hi_reg = 15;
2463 /* We want to generate opcodes in the order the registers have been
2464 saved, ie. descending order. */
2465 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2466 {
c19d1205
ZW
2467 /* Save registers in blocks. */
2468 if (reg < 0
2469 || !(mask & (1 << reg)))
2470 {
2471 /* We found an unsaved reg. Generate opcodes to save the
2472 preceeding block. */
2473 if (reg != hi_reg)
2474 {
2475 if (reg == 9)
2476 {
2477 /* Short form. */
2478 op = 0xc0 | (hi_reg - 10);
2479 add_unwind_opcode (op, 1);
2480 }
2481 else
2482 {
2483 /* Long form. */
2484 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2485 add_unwind_opcode (op, 2);
2486 }
2487 }
2488 hi_reg = reg - 1;
2489 }
b99bd4ef
NC
2490 }
2491
c19d1205
ZW
2492 return;
2493error:
2494 ignore_rest_of_line ();
b99bd4ef
NC
2495}
2496
2497static void
c19d1205 2498s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2499{
c19d1205
ZW
2500 int reg;
2501 int hi_reg;
2502 unsigned mask = 0;
2503 valueT op;
b99bd4ef 2504
c19d1205
ZW
2505 if (*input_line_pointer == '{')
2506 input_line_pointer++;
b99bd4ef 2507
c19d1205 2508 do
b99bd4ef 2509 {
c19d1205 2510 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2511
c19d1205
ZW
2512 if (reg == FAIL)
2513 {
2514 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2515 goto error;
2516 }
b99bd4ef 2517
c19d1205
ZW
2518 reg -= 8;
2519 if (mask >> reg)
2520 as_tsktsk (_("register list not in ascending order"));
2521 mask |= 1 << reg;
b99bd4ef 2522
c19d1205
ZW
2523 if (*input_line_pointer == '-')
2524 {
2525 input_line_pointer++;
2526 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2527 if (hi_reg == FAIL)
2528 {
2529 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2530 goto error;
2531 }
2532 else if (reg >= hi_reg)
2533 {
2534 as_bad (_("bad register range"));
2535 goto error;
2536 }
2537 for (; reg < hi_reg; reg++)
2538 mask |= 1 << reg;
2539 }
b99bd4ef 2540 }
c19d1205 2541 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2542
c19d1205
ZW
2543 if (*input_line_pointer == '}')
2544 input_line_pointer++;
b99bd4ef 2545
c19d1205
ZW
2546 demand_empty_rest_of_line ();
2547
2548 /* Generate any deferred opcodes becuuse we're going to be looking at
2549 the list. */
2550 flush_pending_unwind ();
b99bd4ef 2551
c19d1205 2552 for (reg = 0; reg < 16; reg++)
b99bd4ef 2553 {
c19d1205
ZW
2554 if (mask & (1 << reg))
2555 unwind.frame_size += 4;
b99bd4ef 2556 }
c19d1205
ZW
2557 op = 0xc700 | mask;
2558 add_unwind_opcode (op, 2);
2559 return;
2560error:
2561 ignore_rest_of_line ();
b99bd4ef
NC
2562}
2563
c19d1205
ZW
2564
2565/* Parse an unwind_save directive. */
2566
b99bd4ef 2567static void
c19d1205 2568s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2569{
c19d1205
ZW
2570 char *peek;
2571 struct reg_entry *reg;
2572 bfd_boolean had_brace = FALSE;
b99bd4ef 2573
c19d1205
ZW
2574 /* Figure out what sort of save we have. */
2575 peek = input_line_pointer;
b99bd4ef 2576
c19d1205 2577 if (*peek == '{')
b99bd4ef 2578 {
c19d1205
ZW
2579 had_brace = TRUE;
2580 peek++;
b99bd4ef
NC
2581 }
2582
c19d1205 2583 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2584
c19d1205 2585 if (!reg)
b99bd4ef 2586 {
c19d1205
ZW
2587 as_bad (_("register expected"));
2588 ignore_rest_of_line ();
b99bd4ef
NC
2589 return;
2590 }
2591
c19d1205 2592 switch (reg->type)
b99bd4ef 2593 {
c19d1205
ZW
2594 case REG_TYPE_FN:
2595 if (had_brace)
2596 {
2597 as_bad (_("FPA .unwind_save does not take a register list"));
2598 ignore_rest_of_line ();
2599 return;
2600 }
2601 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2602 return;
c19d1205
ZW
2603
2604 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2605 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2606 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2607 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2608
2609 default:
2610 as_bad (_(".unwind_save does not support this kind of register"));
2611 ignore_rest_of_line ();
b99bd4ef 2612 }
c19d1205 2613}
b99bd4ef 2614
b99bd4ef 2615
c19d1205
ZW
2616/* Parse an unwind_movsp directive. */
2617
2618static void
2619s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2620{
2621 int reg;
2622 valueT op;
2623
2624 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2625 if (reg == FAIL)
b99bd4ef 2626 {
c19d1205
ZW
2627 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2628 ignore_rest_of_line ();
b99bd4ef
NC
2629 return;
2630 }
c19d1205 2631 demand_empty_rest_of_line ();
b99bd4ef 2632
c19d1205 2633 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2634 {
c19d1205 2635 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2636 return;
2637 }
2638
c19d1205
ZW
2639 if (unwind.fp_reg != REG_SP)
2640 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2641
c19d1205
ZW
2642 /* Generate opcode to restore the value. */
2643 op = 0x90 | reg;
2644 add_unwind_opcode (op, 1);
2645
2646 /* Record the information for later. */
2647 unwind.fp_reg = reg;
2648 unwind.fp_offset = unwind.frame_size;
2649 unwind.sp_restored = 1;
b05fe5cf
ZW
2650}
2651
c19d1205
ZW
2652/* Parse an unwind_pad directive. */
2653
b05fe5cf 2654static void
c19d1205 2655s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2656{
c19d1205 2657 int offset;
b05fe5cf 2658
c19d1205
ZW
2659 if (immediate_for_directive (&offset) == FAIL)
2660 return;
b99bd4ef 2661
c19d1205
ZW
2662 if (offset & 3)
2663 {
2664 as_bad (_("stack increment must be multiple of 4"));
2665 ignore_rest_of_line ();
2666 return;
2667 }
b99bd4ef 2668
c19d1205
ZW
2669 /* Don't generate any opcodes, just record the details for later. */
2670 unwind.frame_size += offset;
2671 unwind.pending_offset += offset;
2672
2673 demand_empty_rest_of_line ();
2674}
2675
2676/* Parse an unwind_setfp directive. */
2677
2678static void
2679s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2680{
c19d1205
ZW
2681 int sp_reg;
2682 int fp_reg;
2683 int offset;
2684
2685 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2686 if (skip_past_comma (&input_line_pointer) == FAIL)
2687 sp_reg = FAIL;
2688 else
2689 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2690
c19d1205
ZW
2691 if (fp_reg == FAIL || sp_reg == FAIL)
2692 {
2693 as_bad (_("expected <reg>, <reg>"));
2694 ignore_rest_of_line ();
2695 return;
2696 }
b99bd4ef 2697
c19d1205
ZW
2698 /* Optional constant. */
2699 if (skip_past_comma (&input_line_pointer) != FAIL)
2700 {
2701 if (immediate_for_directive (&offset) == FAIL)
2702 return;
2703 }
2704 else
2705 offset = 0;
a737bd4d 2706
c19d1205 2707 demand_empty_rest_of_line ();
a737bd4d 2708
c19d1205 2709 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2710 {
c19d1205
ZW
2711 as_bad (_("register must be either sp or set by a previous"
2712 "unwind_movsp directive"));
2713 return;
a737bd4d
NC
2714 }
2715
c19d1205
ZW
2716 /* Don't generate any opcodes, just record the information for later. */
2717 unwind.fp_reg = fp_reg;
2718 unwind.fp_used = 1;
2719 if (sp_reg == 13)
2720 unwind.fp_offset = unwind.frame_size - offset;
2721 else
2722 unwind.fp_offset -= offset;
a737bd4d
NC
2723}
2724
c19d1205
ZW
2725/* Parse an unwind_raw directive. */
2726
2727static void
2728s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2729{
c19d1205
ZW
2730 expressionS exp;
2731 /* This is an arbitary limit. */
2732 unsigned char op[16];
2733 int count;
a737bd4d 2734
c19d1205
ZW
2735 expression (&exp);
2736 if (exp.X_op == O_constant
2737 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2738 {
c19d1205
ZW
2739 unwind.frame_size += exp.X_add_number;
2740 expression (&exp);
2741 }
2742 else
2743 exp.X_op = O_illegal;
a737bd4d 2744
c19d1205
ZW
2745 if (exp.X_op != O_constant)
2746 {
2747 as_bad (_("expected <offset>, <opcode>"));
2748 ignore_rest_of_line ();
2749 return;
2750 }
a737bd4d 2751
c19d1205 2752 count = 0;
a737bd4d 2753
c19d1205
ZW
2754 /* Parse the opcode. */
2755 for (;;)
2756 {
2757 if (count >= 16)
2758 {
2759 as_bad (_("unwind opcode too long"));
2760 ignore_rest_of_line ();
a737bd4d 2761 }
c19d1205 2762 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2763 {
c19d1205
ZW
2764 as_bad (_("invalid unwind opcode"));
2765 ignore_rest_of_line ();
2766 return;
a737bd4d 2767 }
c19d1205 2768 op[count++] = exp.X_add_number;
a737bd4d 2769
c19d1205
ZW
2770 /* Parse the next byte. */
2771 if (skip_past_comma (&input_line_pointer) == FAIL)
2772 break;
a737bd4d 2773
c19d1205
ZW
2774 expression (&exp);
2775 }
b99bd4ef 2776
c19d1205
ZW
2777 /* Add the opcode bytes in reverse order. */
2778 while (count--)
2779 add_unwind_opcode (op[count], 1);
b99bd4ef 2780
c19d1205 2781 demand_empty_rest_of_line ();
b99bd4ef 2782}
c19d1205 2783#endif /* OBJ_ELF */
b99bd4ef 2784
c19d1205
ZW
2785/* This table describes all the machine specific pseudo-ops the assembler
2786 has to support. The fields are:
2787 pseudo-op name without dot
2788 function to call to execute this pseudo-op
2789 Integer arg to pass to the function. */
b99bd4ef 2790
c19d1205 2791const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2792{
c19d1205
ZW
2793 /* Never called because '.req' does not start a line. */
2794 { "req", s_req, 0 },
2795 { "unreq", s_unreq, 0 },
2796 { "bss", s_bss, 0 },
2797 { "align", s_align, 0 },
2798 { "arm", s_arm, 0 },
2799 { "thumb", s_thumb, 0 },
2800 { "code", s_code, 0 },
2801 { "force_thumb", s_force_thumb, 0 },
2802 { "thumb_func", s_thumb_func, 0 },
2803 { "thumb_set", s_thumb_set, 0 },
2804 { "even", s_even, 0 },
2805 { "ltorg", s_ltorg, 0 },
2806 { "pool", s_ltorg, 0 },
2807 { "syntax", s_syntax, 0 },
2808#ifdef OBJ_ELF
2809 { "word", s_arm_elf_cons, 4 },
2810 { "long", s_arm_elf_cons, 4 },
2811 { "rel31", s_arm_rel31, 0 },
2812 { "fnstart", s_arm_unwind_fnstart, 0 },
2813 { "fnend", s_arm_unwind_fnend, 0 },
2814 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2815 { "personality", s_arm_unwind_personality, 0 },
2816 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2817 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2818 { "save", s_arm_unwind_save, 0 },
2819 { "movsp", s_arm_unwind_movsp, 0 },
2820 { "pad", s_arm_unwind_pad, 0 },
2821 { "setfp", s_arm_unwind_setfp, 0 },
2822 { "unwind_raw", s_arm_unwind_raw, 0 },
2823#else
2824 { "word", cons, 4},
2825#endif
2826 { "extend", float_cons, 'x' },
2827 { "ldouble", float_cons, 'x' },
2828 { "packed", float_cons, 'p' },
2829 { 0, 0, 0 }
2830};
2831\f
2832/* Parser functions used exclusively in instruction operands. */
b99bd4ef 2833
c19d1205
ZW
2834/* Generic immediate-value read function for use in insn parsing.
2835 STR points to the beginning of the immediate (the leading #);
2836 VAL receives the value; if the value is outside [MIN, MAX]
2837 issue an error. PREFIX_OPT is true if the immediate prefix is
2838 optional. */
b99bd4ef 2839
c19d1205
ZW
2840static int
2841parse_immediate (char **str, int *val, int min, int max,
2842 bfd_boolean prefix_opt)
2843{
2844 expressionS exp;
2845 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2846 if (exp.X_op != O_constant)
b99bd4ef 2847 {
c19d1205
ZW
2848 inst.error = _("constant expression required");
2849 return FAIL;
2850 }
b99bd4ef 2851
c19d1205
ZW
2852 if (exp.X_add_number < min || exp.X_add_number > max)
2853 {
2854 inst.error = _("immediate value out of range");
2855 return FAIL;
2856 }
b99bd4ef 2857
c19d1205
ZW
2858 *val = exp.X_add_number;
2859 return SUCCESS;
2860}
b99bd4ef 2861
c19d1205
ZW
2862/* Returns the pseudo-register number of an FPA immediate constant,
2863 or FAIL if there isn't a valid constant here. */
b99bd4ef 2864
c19d1205
ZW
2865static int
2866parse_fpa_immediate (char ** str)
2867{
2868 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2869 char * save_in;
2870 expressionS exp;
2871 int i;
2872 int j;
b99bd4ef 2873
c19d1205
ZW
2874 /* First try and match exact strings, this is to guarantee
2875 that some formats will work even for cross assembly. */
b99bd4ef 2876
c19d1205
ZW
2877 for (i = 0; fp_const[i]; i++)
2878 {
2879 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 2880 {
c19d1205 2881 char *start = *str;
b99bd4ef 2882
c19d1205
ZW
2883 *str += strlen (fp_const[i]);
2884 if (is_end_of_line[(unsigned char) **str])
2885 return i + 8;
2886 *str = start;
2887 }
2888 }
b99bd4ef 2889
c19d1205
ZW
2890 /* Just because we didn't get a match doesn't mean that the constant
2891 isn't valid, just that it is in a format that we don't
2892 automatically recognize. Try parsing it with the standard
2893 expression routines. */
b99bd4ef 2894
c19d1205 2895 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 2896
c19d1205
ZW
2897 /* Look for a raw floating point number. */
2898 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
2899 && is_end_of_line[(unsigned char) *save_in])
2900 {
2901 for (i = 0; i < NUM_FLOAT_VALS; i++)
2902 {
2903 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 2904 {
c19d1205
ZW
2905 if (words[j] != fp_values[i][j])
2906 break;
b99bd4ef
NC
2907 }
2908
c19d1205 2909 if (j == MAX_LITTLENUMS)
b99bd4ef 2910 {
c19d1205
ZW
2911 *str = save_in;
2912 return i + 8;
b99bd4ef
NC
2913 }
2914 }
2915 }
b99bd4ef 2916
c19d1205
ZW
2917 /* Try and parse a more complex expression, this will probably fail
2918 unless the code uses a floating point prefix (eg "0f"). */
2919 save_in = input_line_pointer;
2920 input_line_pointer = *str;
2921 if (expression (&exp) == absolute_section
2922 && exp.X_op == O_big
2923 && exp.X_add_number < 0)
2924 {
2925 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
2926 Ditto for 15. */
2927 if (gen_to_words (words, 5, (long) 15) == 0)
2928 {
2929 for (i = 0; i < NUM_FLOAT_VALS; i++)
2930 {
2931 for (j = 0; j < MAX_LITTLENUMS; j++)
2932 {
2933 if (words[j] != fp_values[i][j])
2934 break;
2935 }
b99bd4ef 2936
c19d1205
ZW
2937 if (j == MAX_LITTLENUMS)
2938 {
2939 *str = input_line_pointer;
2940 input_line_pointer = save_in;
2941 return i + 8;
2942 }
2943 }
2944 }
b99bd4ef
NC
2945 }
2946
c19d1205
ZW
2947 *str = input_line_pointer;
2948 input_line_pointer = save_in;
2949 inst.error = _("invalid FPA immediate expression");
2950 return FAIL;
b99bd4ef
NC
2951}
2952
c19d1205
ZW
2953/* Shift operands. */
2954enum shift_kind
b99bd4ef 2955{
c19d1205
ZW
2956 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
2957};
b99bd4ef 2958
c19d1205
ZW
2959struct asm_shift_name
2960{
2961 const char *name;
2962 enum shift_kind kind;
2963};
b99bd4ef 2964
c19d1205
ZW
2965/* Third argument to parse_shift. */
2966enum parse_shift_mode
2967{
2968 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
2969 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
2970 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
2971 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
2972 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
2973};
b99bd4ef 2974
c19d1205
ZW
2975/* Parse a <shift> specifier on an ARM data processing instruction.
2976 This has three forms:
b99bd4ef 2977
c19d1205
ZW
2978 (LSL|LSR|ASL|ASR|ROR) Rs
2979 (LSL|LSR|ASL|ASR|ROR) #imm
2980 RRX
b99bd4ef 2981
c19d1205
ZW
2982 Note that ASL is assimilated to LSL in the instruction encoding, and
2983 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 2984
c19d1205
ZW
2985static int
2986parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 2987{
c19d1205
ZW
2988 const struct asm_shift_name *shift_name;
2989 enum shift_kind shift;
2990 char *s = *str;
2991 char *p = s;
2992 int reg;
b99bd4ef 2993
c19d1205
ZW
2994 for (p = *str; ISALPHA (*p); p++)
2995 ;
b99bd4ef 2996
c19d1205 2997 if (p == *str)
b99bd4ef 2998 {
c19d1205
ZW
2999 inst.error = _("shift expression expected");
3000 return FAIL;
b99bd4ef
NC
3001 }
3002
c19d1205
ZW
3003 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3004
3005 if (shift_name == NULL)
b99bd4ef 3006 {
c19d1205
ZW
3007 inst.error = _("shift expression expected");
3008 return FAIL;
b99bd4ef
NC
3009 }
3010
c19d1205 3011 shift = shift_name->kind;
b99bd4ef 3012
c19d1205
ZW
3013 switch (mode)
3014 {
3015 case NO_SHIFT_RESTRICT:
3016 case SHIFT_IMMEDIATE: break;
b99bd4ef 3017
c19d1205
ZW
3018 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3019 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3020 {
3021 inst.error = _("'LSL' or 'ASR' required");
3022 return FAIL;
3023 }
3024 break;
b99bd4ef 3025
c19d1205
ZW
3026 case SHIFT_LSL_IMMEDIATE:
3027 if (shift != SHIFT_LSL)
3028 {
3029 inst.error = _("'LSL' required");
3030 return FAIL;
3031 }
3032 break;
b99bd4ef 3033
c19d1205
ZW
3034 case SHIFT_ASR_IMMEDIATE:
3035 if (shift != SHIFT_ASR)
3036 {
3037 inst.error = _("'ASR' required");
3038 return FAIL;
3039 }
3040 break;
b99bd4ef 3041
c19d1205
ZW
3042 default: abort ();
3043 }
b99bd4ef 3044
c19d1205
ZW
3045 if (shift != SHIFT_RRX)
3046 {
3047 /* Whitespace can appear here if the next thing is a bare digit. */
3048 skip_whitespace (p);
b99bd4ef 3049
c19d1205
ZW
3050 if (mode == NO_SHIFT_RESTRICT
3051 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3052 {
3053 inst.operands[i].imm = reg;
3054 inst.operands[i].immisreg = 1;
3055 }
3056 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3057 return FAIL;
3058 }
3059 inst.operands[i].shift_kind = shift;
3060 inst.operands[i].shifted = 1;
3061 *str = p;
3062 return SUCCESS;
b99bd4ef
NC
3063}
3064
c19d1205 3065/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3066
c19d1205
ZW
3067 #<immediate>
3068 #<immediate>, <rotate>
3069 <Rm>
3070 <Rm>, <shift>
b99bd4ef 3071
c19d1205
ZW
3072 where <shift> is defined by parse_shift above, and <rotate> is a
3073 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3074 is deferred to md_apply_fix. */
b99bd4ef 3075
c19d1205
ZW
3076static int
3077parse_shifter_operand (char **str, int i)
3078{
3079 int value;
3080 expressionS expr;
b99bd4ef 3081
c19d1205
ZW
3082 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3083 {
3084 inst.operands[i].reg = value;
3085 inst.operands[i].isreg = 1;
b99bd4ef 3086
c19d1205
ZW
3087 /* parse_shift will override this if appropriate */
3088 inst.reloc.exp.X_op = O_constant;
3089 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3090
c19d1205
ZW
3091 if (skip_past_comma (str) == FAIL)
3092 return SUCCESS;
b99bd4ef 3093
c19d1205
ZW
3094 /* Shift operation on register. */
3095 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3096 }
3097
c19d1205
ZW
3098 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3099 return FAIL;
b99bd4ef 3100
c19d1205 3101 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3102 {
c19d1205
ZW
3103 /* #x, y -- ie explicit rotation by Y. */
3104 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3105 return FAIL;
b99bd4ef 3106
c19d1205
ZW
3107 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3108 {
3109 inst.error = _("constant expression expected");
3110 return FAIL;
3111 }
b99bd4ef 3112
c19d1205
ZW
3113 value = expr.X_add_number;
3114 if (value < 0 || value > 30 || value % 2 != 0)
3115 {
3116 inst.error = _("invalid rotation");
3117 return FAIL;
3118 }
3119 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3120 {
3121 inst.error = _("invalid constant");
3122 return FAIL;
3123 }
09d92015 3124
55cf6793 3125 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3126 inst.reloc.exp.X_add_number
3127 = (((inst.reloc.exp.X_add_number << (32 - value))
3128 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3129 }
3130
c19d1205
ZW
3131 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3132 inst.reloc.pc_rel = 0;
3133 return SUCCESS;
09d92015
MM
3134}
3135
c19d1205
ZW
3136/* Parse all forms of an ARM address expression. Information is written
3137 to inst.operands[i] and/or inst.reloc.
09d92015 3138
c19d1205 3139 Preindexed addressing (.preind=1):
09d92015 3140
c19d1205
ZW
3141 [Rn, #offset] .reg=Rn .reloc.exp=offset
3142 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3143 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3144 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3145
c19d1205 3146 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3147
c19d1205 3148 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3149
c19d1205
ZW
3150 [Rn], #offset .reg=Rn .reloc.exp=offset
3151 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3152 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3153 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3154
c19d1205 3155 Unindexed addressing (.preind=0, .postind=0):
09d92015 3156
c19d1205 3157 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3158
c19d1205 3159 Other:
09d92015 3160
c19d1205
ZW
3161 [Rn]{!} shorthand for [Rn,#0]{!}
3162 =immediate .isreg=0 .reloc.exp=immediate
3163 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3164
c19d1205
ZW
3165 It is the caller's responsibility to check for addressing modes not
3166 supported by the instruction, and to set inst.reloc.type. */
3167
3168static int
3169parse_address (char **str, int i)
09d92015 3170{
c19d1205
ZW
3171 char *p = *str;
3172 int reg;
09d92015 3173
c19d1205 3174 if (skip_past_char (&p, '[') == FAIL)
09d92015 3175 {
c19d1205
ZW
3176 if (skip_past_char (&p, '=') == FAIL)
3177 {
3178 /* bare address - translate to PC-relative offset */
3179 inst.reloc.pc_rel = 1;
3180 inst.operands[i].reg = REG_PC;
3181 inst.operands[i].isreg = 1;
3182 inst.operands[i].preind = 1;
3183 }
3184 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3185
c19d1205
ZW
3186 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3187 return FAIL;
09d92015 3188
c19d1205
ZW
3189 *str = p;
3190 return SUCCESS;
09d92015
MM
3191 }
3192
c19d1205 3193 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3194 {
c19d1205
ZW
3195 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3196 return FAIL;
09d92015 3197 }
c19d1205
ZW
3198 inst.operands[i].reg = reg;
3199 inst.operands[i].isreg = 1;
09d92015 3200
c19d1205 3201 if (skip_past_comma (&p) == SUCCESS)
09d92015 3202 {
c19d1205 3203 inst.operands[i].preind = 1;
09d92015 3204
c19d1205
ZW
3205 if (*p == '+') p++;
3206 else if (*p == '-') p++, inst.operands[i].negative = 1;
3207
3208 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3209 {
c19d1205
ZW
3210 inst.operands[i].imm = reg;
3211 inst.operands[i].immisreg = 1;
3212
3213 if (skip_past_comma (&p) == SUCCESS)
3214 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3215 return FAIL;
3216 }
3217 else
3218 {
3219 if (inst.operands[i].negative)
3220 {
3221 inst.operands[i].negative = 0;
3222 p--;
3223 }
3224 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3225 return FAIL;
09d92015
MM
3226 }
3227 }
3228
c19d1205 3229 if (skip_past_char (&p, ']') == FAIL)
09d92015 3230 {
c19d1205
ZW
3231 inst.error = _("']' expected");
3232 return FAIL;
09d92015
MM
3233 }
3234
c19d1205
ZW
3235 if (skip_past_char (&p, '!') == SUCCESS)
3236 inst.operands[i].writeback = 1;
09d92015 3237
c19d1205 3238 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3239 {
c19d1205
ZW
3240 if (skip_past_char (&p, '{') == SUCCESS)
3241 {
3242 /* [Rn], {expr} - unindexed, with option */
3243 if (parse_immediate (&p, &inst.operands[i].imm,
3244 0, 255, TRUE) == FAIL)
3245 return FAIL;
09d92015 3246
c19d1205
ZW
3247 if (skip_past_char (&p, '}') == FAIL)
3248 {
3249 inst.error = _("'}' expected at end of 'option' field");
3250 return FAIL;
3251 }
3252 if (inst.operands[i].preind)
3253 {
3254 inst.error = _("cannot combine index with option");
3255 return FAIL;
3256 }
3257 *str = p;
3258 return SUCCESS;
09d92015 3259 }
c19d1205
ZW
3260 else
3261 {
3262 inst.operands[i].postind = 1;
3263 inst.operands[i].writeback = 1;
09d92015 3264
c19d1205
ZW
3265 if (inst.operands[i].preind)
3266 {
3267 inst.error = _("cannot combine pre- and post-indexing");
3268 return FAIL;
3269 }
09d92015 3270
c19d1205
ZW
3271 if (*p == '+') p++;
3272 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3273
c19d1205
ZW
3274 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3275 {
3276 inst.operands[i].imm = reg;
3277 inst.operands[i].immisreg = 1;
a737bd4d 3278
c19d1205
ZW
3279 if (skip_past_comma (&p) == SUCCESS)
3280 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3281 return FAIL;
3282 }
3283 else
3284 {
3285 if (inst.operands[i].negative)
3286 {
3287 inst.operands[i].negative = 0;
3288 p--;
3289 }
3290 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3291 return FAIL;
3292 }
3293 }
a737bd4d
NC
3294 }
3295
c19d1205
ZW
3296 /* If at this point neither .preind nor .postind is set, we have a
3297 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3298 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3299 {
3300 inst.operands[i].preind = 1;
3301 inst.reloc.exp.X_op = O_constant;
3302 inst.reloc.exp.X_add_number = 0;
3303 }
3304 *str = p;
3305 return SUCCESS;
a737bd4d
NC
3306}
3307
c19d1205 3308/* Miscellaneous. */
a737bd4d 3309
c19d1205
ZW
3310/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3311 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3312static int
3313parse_psr (char **str)
09d92015 3314{
c19d1205
ZW
3315 char *p;
3316 unsigned long psr_field;
09d92015 3317
c19d1205
ZW
3318 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3319 feature for ease of use and backwards compatibility. */
3320 p = *str;
3321 if (*p == 's' || *p == 'S')
3322 psr_field = SPSR_BIT;
3323 else if (*p == 'c' || *p == 'C')
3324 psr_field = 0;
3325 else
3326 goto error;
09d92015 3327
c19d1205
ZW
3328 p++;
3329 if (strncasecmp (p, "PSR", 3) != 0)
3330 goto error;
3331 p += 3;
09d92015 3332
c19d1205
ZW
3333 if (*p == '_')
3334 {
3335 /* A suffix follows. */
3336 const struct asm_psr *psr;
3337 char *start;
a737bd4d 3338
c19d1205
ZW
3339 p++;
3340 start = p;
a737bd4d 3341
c19d1205
ZW
3342 do
3343 p++;
3344 while (ISALNUM (*p) || *p == '_');
a737bd4d 3345
c19d1205
ZW
3346 psr = hash_find_n (arm_psr_hsh, start, p - start);
3347 if (!psr)
3348 goto error;
a737bd4d 3349
c19d1205 3350 psr_field |= psr->field;
a737bd4d 3351 }
c19d1205 3352 else
a737bd4d 3353 {
c19d1205
ZW
3354 if (ISALNUM (*p))
3355 goto error; /* Garbage after "[CS]PSR". */
3356
3357 psr_field |= (PSR_c | PSR_f);
a737bd4d 3358 }
c19d1205
ZW
3359 *str = p;
3360 return psr_field;
a737bd4d 3361
c19d1205
ZW
3362 error:
3363 inst.error = _("flag for {c}psr instruction expected");
3364 return FAIL;
a737bd4d
NC
3365}
3366
c19d1205
ZW
3367/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3368 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3369
c19d1205
ZW
3370static int
3371parse_cps_flags (char **str)
a737bd4d 3372{
c19d1205
ZW
3373 int val = 0;
3374 int saw_a_flag = 0;
3375 char *s = *str;
a737bd4d 3376
c19d1205
ZW
3377 for (;;)
3378 switch (*s++)
3379 {
3380 case '\0': case ',':
3381 goto done;
a737bd4d 3382
c19d1205
ZW
3383 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3384 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3385 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3386
c19d1205
ZW
3387 default:
3388 inst.error = _("unrecognized CPS flag");
3389 return FAIL;
3390 }
a737bd4d 3391
c19d1205
ZW
3392 done:
3393 if (saw_a_flag == 0)
a737bd4d 3394 {
c19d1205
ZW
3395 inst.error = _("missing CPS flags");
3396 return FAIL;
a737bd4d 3397 }
a737bd4d 3398
c19d1205
ZW
3399 *str = s - 1;
3400 return val;
a737bd4d
NC
3401}
3402
c19d1205
ZW
3403/* Parse an endian specifier ("BE" or "LE", case insensitive);
3404 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3405
3406static int
c19d1205 3407parse_endian_specifier (char **str)
a737bd4d 3408{
c19d1205
ZW
3409 int little_endian;
3410 char *s = *str;
a737bd4d 3411
c19d1205
ZW
3412 if (strncasecmp (s, "BE", 2))
3413 little_endian = 0;
3414 else if (strncasecmp (s, "LE", 2))
3415 little_endian = 1;
3416 else
a737bd4d 3417 {
c19d1205 3418 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3419 return FAIL;
3420 }
3421
c19d1205 3422 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3423 {
c19d1205 3424 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3425 return FAIL;
3426 }
3427
c19d1205
ZW
3428 *str = s + 2;
3429 return little_endian;
3430}
a737bd4d 3431
c19d1205
ZW
3432/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3433 value suitable for poking into the rotate field of an sxt or sxta
3434 instruction, or FAIL on error. */
3435
3436static int
3437parse_ror (char **str)
3438{
3439 int rot;
3440 char *s = *str;
3441
3442 if (strncasecmp (s, "ROR", 3) == 0)
3443 s += 3;
3444 else
a737bd4d 3445 {
c19d1205 3446 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3447 return FAIL;
3448 }
c19d1205
ZW
3449
3450 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3451 return FAIL;
3452
3453 switch (rot)
a737bd4d 3454 {
c19d1205
ZW
3455 case 0: *str = s; return 0x0;
3456 case 8: *str = s; return 0x1;
3457 case 16: *str = s; return 0x2;
3458 case 24: *str = s; return 0x3;
3459
3460 default:
3461 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3462 return FAIL;
3463 }
c19d1205 3464}
a737bd4d 3465
c19d1205
ZW
3466/* Parse a conditional code (from conds[] below). The value returned is in the
3467 range 0 .. 14, or FAIL. */
3468static int
3469parse_cond (char **str)
3470{
3471 char *p, *q;
3472 const struct asm_cond *c;
a737bd4d 3473
c19d1205
ZW
3474 p = q = *str;
3475 while (ISALPHA (*q))
3476 q++;
a737bd4d 3477
c19d1205
ZW
3478 c = hash_find_n (arm_cond_hsh, p, q - p);
3479 if (!c)
a737bd4d 3480 {
c19d1205 3481 inst.error = _("condition required");
a737bd4d
NC
3482 return FAIL;
3483 }
3484
c19d1205
ZW
3485 *str = q;
3486 return c->value;
3487}
3488
3489/* Matcher codes for parse_operands. */
3490enum operand_parse_code
3491{
3492 OP_stop, /* end of line */
3493
3494 OP_RR, /* ARM register */
3495 OP_RRnpc, /* ARM register, not r15 */
3496 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3497 OP_RRw, /* ARM register, not r15, optional trailing ! */
3498 OP_RCP, /* Coprocessor number */
3499 OP_RCN, /* Coprocessor register */
3500 OP_RF, /* FPA register */
3501 OP_RVS, /* VFP single precision register */
3502 OP_RVD, /* VFP double precision register */
3503 OP_RVC, /* VFP control register */
3504 OP_RMF, /* Maverick F register */
3505 OP_RMD, /* Maverick D register */
3506 OP_RMFX, /* Maverick FX register */
3507 OP_RMDX, /* Maverick DX register */
3508 OP_RMAX, /* Maverick AX register */
3509 OP_RMDS, /* Maverick DSPSC register */
3510 OP_RIWR, /* iWMMXt wR register */
3511 OP_RIWC, /* iWMMXt wC register */
3512 OP_RIWG, /* iWMMXt wCG register */
3513 OP_RXA, /* XScale accumulator register */
3514
3515 OP_REGLST, /* ARM register list */
3516 OP_VRSLST, /* VFP single-precision register list */
3517 OP_VRDLST, /* VFP double-precision register list */
3518
3519 OP_I7, /* immediate value 0 .. 7 */
3520 OP_I15, /* 0 .. 15 */
3521 OP_I16, /* 1 .. 16 */
3522 OP_I31, /* 0 .. 31 */
3523 OP_I31w, /* 0 .. 31, optional trailing ! */
3524 OP_I32, /* 1 .. 32 */
3525 OP_I63s, /* -64 .. 63 */
3526 OP_I255, /* 0 .. 255 */
3527 OP_Iffff, /* 0 .. 65535 */
3528
3529 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3530 OP_I7b, /* 0 .. 7 */
3531 OP_I15b, /* 0 .. 15 */
3532 OP_I31b, /* 0 .. 31 */
3533
3534 OP_SH, /* shifter operand */
3535 OP_ADDR, /* Memory address expression (any mode) */
3536 OP_EXP, /* arbitrary expression */
3537 OP_EXPi, /* same, with optional immediate prefix */
3538 OP_EXPr, /* same, with optional relocation suffix */
3539
3540 OP_CPSF, /* CPS flags */
3541 OP_ENDI, /* Endianness specifier */
3542 OP_PSR, /* CPSR/SPSR mask for msr */
3543 OP_COND, /* conditional code */
3544
3545 OP_RRnpc_I0, /* ARM register or literal 0 */
3546 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3547 OP_RR_EXi, /* ARM register or expression with imm prefix */
3548 OP_RF_IF, /* FPA register or immediate */
3549 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3550
3551 /* Optional operands. */
3552 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3553 OP_oI31b, /* 0 .. 31 */
3554 OP_oIffffb, /* 0 .. 65535 */
3555 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3556
3557 OP_oRR, /* ARM register */
3558 OP_oRRnpc, /* ARM register, not the PC */
3559 OP_oSHll, /* LSL immediate */
3560 OP_oSHar, /* ASR immediate */
3561 OP_oSHllar, /* LSL or ASR immediate */
3562 OP_oROR, /* ROR 0/8/16/24 */
3563
3564 OP_FIRST_OPTIONAL = OP_oI7b
3565};
a737bd4d 3566
c19d1205
ZW
3567/* Generic instruction operand parser. This does no encoding and no
3568 semantic validation; it merely squirrels values away in the inst
3569 structure. Returns SUCCESS or FAIL depending on whether the
3570 specified grammar matched. */
3571static int
3572parse_operands (char *str, const char *pattern)
3573{
3574 unsigned const char *upat = pattern;
3575 char *backtrack_pos = 0;
3576 const char *backtrack_error = 0;
3577 int i, val, backtrack_index = 0;
3578
3579#define po_char_or_fail(chr) do { \
3580 if (skip_past_char (&str, chr) == FAIL) \
3581 goto bad_args; \
3582} while (0)
3583
3584#define po_reg_or_fail(regtype) do { \
3585 val = arm_reg_parse (&str, regtype); \
3586 if (val == FAIL) \
3587 { \
3588 inst.error = _(reg_expected_msgs[regtype]); \
3589 goto failure; \
3590 } \
3591 inst.operands[i].reg = val; \
3592 inst.operands[i].isreg = 1; \
3593} while (0)
3594
3595#define po_reg_or_goto(regtype, label) do { \
3596 val = arm_reg_parse (&str, regtype); \
3597 if (val == FAIL) \
3598 goto label; \
3599 \
3600 inst.operands[i].reg = val; \
3601 inst.operands[i].isreg = 1; \
3602} while (0)
3603
3604#define po_imm_or_fail(min, max, popt) do { \
3605 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3606 goto failure; \
3607 inst.operands[i].imm = val; \
3608} while (0)
3609
3610#define po_misc_or_fail(expr) do { \
3611 if (expr) \
3612 goto failure; \
3613} while (0)
3614
3615 skip_whitespace (str);
3616
3617 for (i = 0; upat[i] != OP_stop; i++)
3618 {
3619 if (upat[i] >= OP_FIRST_OPTIONAL)
3620 {
3621 /* Remember where we are in case we need to backtrack. */
3622 assert (!backtrack_pos);
3623 backtrack_pos = str;
3624 backtrack_error = inst.error;
3625 backtrack_index = i;
3626 }
3627
3628 if (i > 0)
3629 po_char_or_fail (',');
3630
3631 switch (upat[i])
3632 {
3633 /* Registers */
3634 case OP_oRRnpc:
3635 case OP_RRnpc:
3636 case OP_oRR:
3637 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3638 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3639 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3640 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3641 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3642 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3643 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3644 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3645 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3646 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3647 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3648 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3649 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3650 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3651 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3652 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3653 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3654
3655 case OP_RRnpcb:
3656 po_char_or_fail ('[');
3657 po_reg_or_fail (REG_TYPE_RN);
3658 po_char_or_fail (']');
3659 break;
a737bd4d 3660
c19d1205
ZW
3661 case OP_RRw:
3662 po_reg_or_fail (REG_TYPE_RN);
3663 if (skip_past_char (&str, '!') == SUCCESS)
3664 inst.operands[i].writeback = 1;
3665 break;
3666
3667 /* Immediates */
3668 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3669 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3670 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3671 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3672 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3673 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3674 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3675 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3676
3677 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3678 case OP_oI7b:
3679 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3680 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3681 case OP_oI31b:
3682 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3683 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3684
3685 /* Immediate variants */
3686 case OP_oI255c:
3687 po_char_or_fail ('{');
3688 po_imm_or_fail (0, 255, TRUE);
3689 po_char_or_fail ('}');
3690 break;
3691
3692 case OP_I31w:
3693 /* The expression parser chokes on a trailing !, so we have
3694 to find it first and zap it. */
3695 {
3696 char *s = str;
3697 while (*s && *s != ',')
3698 s++;
3699 if (s[-1] == '!')
3700 {
3701 s[-1] = '\0';
3702 inst.operands[i].writeback = 1;
3703 }
3704 po_imm_or_fail (0, 31, TRUE);
3705 if (str == s - 1)
3706 str = s;
3707 }
3708 break;
3709
3710 /* Expressions */
3711 case OP_EXPi: EXPi:
3712 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3713 GE_OPT_PREFIX));
3714 break;
3715
3716 case OP_EXP:
3717 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3718 GE_NO_PREFIX));
3719 break;
3720
3721 case OP_EXPr: EXPr:
3722 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3723 GE_NO_PREFIX));
3724 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3725 {
c19d1205
ZW
3726 val = parse_reloc (&str);
3727 if (val == -1)
3728 {
3729 inst.error = _("unrecognized relocation suffix");
3730 goto failure;
3731 }
3732 else if (val != BFD_RELOC_UNUSED)
3733 {
3734 inst.operands[i].imm = val;
3735 inst.operands[i].hasreloc = 1;
3736 }
a737bd4d 3737 }
c19d1205 3738 break;
a737bd4d 3739
c19d1205
ZW
3740 /* Register or expression */
3741 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3742 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 3743
c19d1205
ZW
3744 /* Register or immediate */
3745 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3746 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 3747
c19d1205
ZW
3748 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3749 IF:
3750 if (!is_immediate_prefix (*str))
3751 goto bad_args;
3752 str++;
3753 val = parse_fpa_immediate (&str);
3754 if (val == FAIL)
3755 goto failure;
3756 /* FPA immediates are encoded as registers 8-15.
3757 parse_fpa_immediate has already applied the offset. */
3758 inst.operands[i].reg = val;
3759 inst.operands[i].isreg = 1;
3760 break;
09d92015 3761
c19d1205
ZW
3762 /* Two kinds of register */
3763 case OP_RIWR_RIWC:
3764 {
3765 struct reg_entry *rege = arm_reg_parse_multi (&str);
3766 if (rege->type != REG_TYPE_MMXWR
3767 && rege->type != REG_TYPE_MMXWC
3768 && rege->type != REG_TYPE_MMXWCG)
3769 {
3770 inst.error = _("iWMMXt data or control register expected");
3771 goto failure;
3772 }
3773 inst.operands[i].reg = rege->number;
3774 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3775 }
3776 break;
09d92015 3777
c19d1205
ZW
3778 /* Misc */
3779 case OP_CPSF: val = parse_cps_flags (&str); break;
3780 case OP_ENDI: val = parse_endian_specifier (&str); break;
3781 case OP_oROR: val = parse_ror (&str); break;
3782 case OP_PSR: val = parse_psr (&str); break;
3783 case OP_COND: val = parse_cond (&str); break;
3784
3785 /* Register lists */
3786 case OP_REGLST:
3787 val = parse_reg_list (&str);
3788 if (*str == '^')
3789 {
3790 inst.operands[1].writeback = 1;
3791 str++;
3792 }
3793 break;
09d92015 3794
c19d1205
ZW
3795 case OP_VRSLST:
3796 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3797 break;
09d92015 3798
c19d1205
ZW
3799 case OP_VRDLST:
3800 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3801 break;
a737bd4d 3802
c19d1205
ZW
3803 /* Addressing modes */
3804 case OP_ADDR:
3805 po_misc_or_fail (parse_address (&str, i));
3806 break;
09d92015 3807
c19d1205
ZW
3808 case OP_SH:
3809 po_misc_or_fail (parse_shifter_operand (&str, i));
3810 break;
09d92015 3811
c19d1205
ZW
3812 case OP_oSHll:
3813 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3814 break;
09d92015 3815
c19d1205
ZW
3816 case OP_oSHar:
3817 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3818 break;
09d92015 3819
c19d1205
ZW
3820 case OP_oSHllar:
3821 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3822 break;
09d92015 3823
c19d1205
ZW
3824 default:
3825 as_fatal ("unhandled operand code %d", upat[i]);
3826 }
09d92015 3827
c19d1205
ZW
3828 /* Various value-based sanity checks and shared operations. We
3829 do not signal immediate failures for the register constraints;
3830 this allows a syntax error to take precedence. */
3831 switch (upat[i])
3832 {
3833 case OP_oRRnpc:
3834 case OP_RRnpc:
3835 case OP_RRnpcb:
3836 case OP_RRw:
3837 case OP_RRnpc_I0:
3838 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
3839 inst.error = BAD_PC;
3840 break;
09d92015 3841
c19d1205
ZW
3842 case OP_CPSF:
3843 case OP_ENDI:
3844 case OP_oROR:
3845 case OP_PSR:
3846 case OP_COND:
3847 case OP_REGLST:
3848 case OP_VRSLST:
3849 case OP_VRDLST:
3850 if (val == FAIL)
3851 goto failure;
3852 inst.operands[i].imm = val;
3853 break;
a737bd4d 3854
c19d1205
ZW
3855 default:
3856 break;
3857 }
09d92015 3858
c19d1205
ZW
3859 /* If we get here, this operand was successfully parsed. */
3860 inst.operands[i].present = 1;
3861 continue;
09d92015 3862
c19d1205 3863 bad_args:
09d92015 3864 inst.error = BAD_ARGS;
c19d1205
ZW
3865
3866 failure:
3867 if (!backtrack_pos)
3868 return FAIL;
3869
3870 /* Do not backtrack over a trailing optional argument that
3871 absorbed some text. We will only fail again, with the
3872 'garbage following instruction' error message, which is
3873 probably less helpful than the current one. */
3874 if (backtrack_index == i && backtrack_pos != str
3875 && upat[i+1] == OP_stop)
3876 return FAIL;
3877
3878 /* Try again, skipping the optional argument at backtrack_pos. */
3879 str = backtrack_pos;
3880 inst.error = backtrack_error;
3881 inst.operands[backtrack_index].present = 0;
3882 i = backtrack_index;
3883 backtrack_pos = 0;
09d92015 3884 }
09d92015 3885
c19d1205
ZW
3886 /* Check that we have parsed all the arguments. */
3887 if (*str != '\0' && !inst.error)
3888 inst.error = _("garbage following instruction");
09d92015 3889
c19d1205 3890 return inst.error ? FAIL : SUCCESS;
09d92015
MM
3891}
3892
c19d1205
ZW
3893#undef po_char_or_fail
3894#undef po_reg_or_fail
3895#undef po_reg_or_goto
3896#undef po_imm_or_fail
3897\f
3898/* Shorthand macro for instruction encoding functions issuing errors. */
3899#define constraint(expr, err) do { \
3900 if (expr) \
3901 { \
3902 inst.error = err; \
3903 return; \
3904 } \
3905} while (0)
3906
3907/* Functions for operand encoding. ARM, then Thumb. */
3908
3909#define rotate_left(v, n) (v << n | v >> (32 - n))
3910
3911/* If VAL can be encoded in the immediate field of an ARM instruction,
3912 return the encoded form. Otherwise, return FAIL. */
3913
3914static unsigned int
3915encode_arm_immediate (unsigned int val)
09d92015 3916{
c19d1205
ZW
3917 unsigned int a, i;
3918
3919 for (i = 0; i < 32; i += 2)
3920 if ((a = rotate_left (val, i)) <= 0xff)
3921 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
3922
3923 return FAIL;
09d92015
MM
3924}
3925
c19d1205
ZW
3926/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
3927 return the encoded form. Otherwise, return FAIL. */
3928static unsigned int
3929encode_thumb32_immediate (unsigned int val)
09d92015 3930{
c19d1205 3931 unsigned int a, i;
09d92015 3932
c19d1205
ZW
3933 if (val <= 255)
3934 return val;
a737bd4d 3935
c19d1205 3936 for (i = 0; i < 32; i++)
09d92015 3937 {
c19d1205
ZW
3938 a = rotate_left (val, i);
3939 if (a >= 128 && a <= 255)
3940 return (a & 0x7f) | (i << 7);
09d92015 3941 }
a737bd4d 3942
c19d1205
ZW
3943 a = val & 0xff;
3944 if (val == ((a << 16) | a))
3945 return 0x100 | a;
3946 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
3947 return 0x300 | a;
09d92015 3948
c19d1205
ZW
3949 a = val & 0xff00;
3950 if (val == ((a << 16) | a))
3951 return 0x200 | (a >> 8);
a737bd4d 3952
c19d1205 3953 return FAIL;
09d92015 3954}
c19d1205 3955/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
3956
3957static void
c19d1205 3958encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 3959{
c19d1205 3960 switch (pos)
09d92015 3961 {
c19d1205
ZW
3962 case VFP_REG_Sd:
3963 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
3964 break;
3965
3966 case VFP_REG_Sn:
3967 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
3968 break;
3969
3970 case VFP_REG_Sm:
3971 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
3972 break;
3973
3974 default:
3975 abort ();
09d92015 3976 }
09d92015
MM
3977}
3978
c19d1205 3979/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 3980 if any, is handled by md_apply_fix. */
09d92015 3981static void
c19d1205 3982encode_arm_shift (int i)
09d92015 3983{
c19d1205
ZW
3984 if (inst.operands[i].shift_kind == SHIFT_RRX)
3985 inst.instruction |= SHIFT_ROR << 5;
3986 else
09d92015 3987 {
c19d1205
ZW
3988 inst.instruction |= inst.operands[i].shift_kind << 5;
3989 if (inst.operands[i].immisreg)
3990 {
3991 inst.instruction |= SHIFT_BY_REG;
3992 inst.instruction |= inst.operands[i].imm << 8;
3993 }
3994 else
3995 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 3996 }
c19d1205 3997}
09d92015 3998
c19d1205
ZW
3999static void
4000encode_arm_shifter_operand (int i)
4001{
4002 if (inst.operands[i].isreg)
09d92015 4003 {
c19d1205
ZW
4004 inst.instruction |= inst.operands[i].reg;
4005 encode_arm_shift (i);
09d92015 4006 }
c19d1205
ZW
4007 else
4008 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4009}
4010
c19d1205 4011/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4012static void
c19d1205 4013encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4014{
c19d1205
ZW
4015 assert (inst.operands[i].isreg);
4016 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4017
c19d1205 4018 if (inst.operands[i].preind)
09d92015 4019 {
c19d1205
ZW
4020 if (is_t)
4021 {
4022 inst.error = _("instruction does not accept preindexed addressing");
4023 return;
4024 }
4025 inst.instruction |= PRE_INDEX;
4026 if (inst.operands[i].writeback)
4027 inst.instruction |= WRITE_BACK;
09d92015 4028
c19d1205
ZW
4029 }
4030 else if (inst.operands[i].postind)
4031 {
4032 assert (inst.operands[i].writeback);
4033 if (is_t)
4034 inst.instruction |= WRITE_BACK;
4035 }
4036 else /* unindexed - only for coprocessor */
09d92015 4037 {
c19d1205 4038 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4039 return;
4040 }
4041
c19d1205
ZW
4042 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4043 && (((inst.instruction & 0x000f0000) >> 16)
4044 == ((inst.instruction & 0x0000f000) >> 12)))
4045 as_warn ((inst.instruction & LOAD_BIT)
4046 ? _("destination register same as write-back base")
4047 : _("source register same as write-back base"));
09d92015
MM
4048}
4049
c19d1205
ZW
4050/* inst.operands[i] was set up by parse_address. Encode it into an
4051 ARM-format mode 2 load or store instruction. If is_t is true,
4052 reject forms that cannot be used with a T instruction (i.e. not
4053 post-indexed). */
a737bd4d 4054static void
c19d1205 4055encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4056{
c19d1205 4057 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4058
c19d1205 4059 if (inst.operands[i].immisreg)
09d92015 4060 {
c19d1205
ZW
4061 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4062 inst.instruction |= inst.operands[i].imm;
4063 if (!inst.operands[i].negative)
4064 inst.instruction |= INDEX_UP;
4065 if (inst.operands[i].shifted)
4066 {
4067 if (inst.operands[i].shift_kind == SHIFT_RRX)
4068 inst.instruction |= SHIFT_ROR << 5;
4069 else
4070 {
4071 inst.instruction |= inst.operands[i].shift_kind << 5;
4072 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4073 }
4074 }
09d92015 4075 }
c19d1205 4076 else /* immediate offset in inst.reloc */
09d92015 4077 {
c19d1205
ZW
4078 if (inst.reloc.type == BFD_RELOC_UNUSED)
4079 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4080 if (inst.reloc.pc_rel)
4081 inst.reloc.exp.X_add_number -= 8; /* pipeline offset */
09d92015 4082 }
09d92015
MM
4083}
4084
c19d1205
ZW
4085/* inst.operands[i] was set up by parse_address. Encode it into an
4086 ARM-format mode 3 load or store instruction. Reject forms that
4087 cannot be used with such instructions. If is_t is true, reject
4088 forms that cannot be used with a T instruction (i.e. not
4089 post-indexed). */
4090static void
4091encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4092{
c19d1205 4093 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4094 {
c19d1205
ZW
4095 inst.error = _("instruction does not accept scaled register index");
4096 return;
09d92015 4097 }
a737bd4d 4098
c19d1205 4099 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4100
c19d1205
ZW
4101 if (inst.operands[i].immisreg)
4102 {
4103 inst.instruction |= inst.operands[i].imm;
4104 if (!inst.operands[i].negative)
4105 inst.instruction |= INDEX_UP;
4106 }
4107 else /* immediate offset in inst.reloc */
4108 {
4109 inst.instruction |= HWOFFSET_IMM;
4110 if (inst.reloc.type == BFD_RELOC_UNUSED)
4111 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4112 if (inst.reloc.pc_rel)
4113 inst.reloc.exp.X_add_number -= 8; /* pipeline offset */
4114 }
a737bd4d
NC
4115}
4116
c19d1205
ZW
4117/* inst.operands[i] was set up by parse_address. Encode it into an
4118 ARM-format instruction. Reject all forms which cannot be encoded
4119 into a coprocessor load/store instruction. If wb_ok is false,
4120 reject use of writeback; if unind_ok is false, reject use of
4121 unindexed addressing. If reloc_override is not 0, use it instead
4122 of BFD_ARM_CP_OFF_IMM. */
09d92015 4123
c19d1205
ZW
4124static int
4125encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4126{
c19d1205 4127 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4128
c19d1205 4129 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4130
c19d1205 4131 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4132 {
c19d1205
ZW
4133 assert (!inst.operands[i].writeback);
4134 if (!unind_ok)
4135 {
4136 inst.error = _("instruction does not support unindexed addressing");
4137 return FAIL;
4138 }
4139 inst.instruction |= inst.operands[i].imm;
4140 inst.instruction |= INDEX_UP;
4141 return SUCCESS;
09d92015 4142 }
a737bd4d 4143
c19d1205
ZW
4144 if (inst.operands[i].preind)
4145 inst.instruction |= PRE_INDEX;
a737bd4d 4146
c19d1205 4147 if (inst.operands[i].writeback)
09d92015 4148 {
c19d1205
ZW
4149 if (inst.operands[i].reg == REG_PC)
4150 {
4151 inst.error = _("pc may not be used with write-back");
4152 return FAIL;
4153 }
4154 if (!wb_ok)
4155 {
4156 inst.error = _("instruction does not support writeback");
4157 return FAIL;
4158 }
4159 inst.instruction |= WRITE_BACK;
09d92015 4160 }
a737bd4d 4161
c19d1205
ZW
4162 if (reloc_override)
4163 inst.reloc.type = reloc_override;
09d92015 4164 else
c19d1205
ZW
4165 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
4166 if (inst.reloc.pc_rel)
4167 inst.reloc.exp.X_add_number -= 8;
4168 return SUCCESS;
4169}
a737bd4d 4170
c19d1205
ZW
4171/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4172 Determine whether it can be performed with a move instruction; if
4173 it can, convert inst.instruction to that move instruction and
4174 return 1; if it can't, convert inst.instruction to a literal-pool
4175 load and return 0. If this is not a valid thing to do in the
4176 current context, set inst.error and return 1.
a737bd4d 4177
c19d1205
ZW
4178 inst.operands[i] describes the destination register. */
4179
4180static int
4181move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4182{
4183 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4184 {
c19d1205
ZW
4185 inst.error = _("invalid pseudo operation");
4186 return 1;
09d92015 4187 }
c19d1205 4188 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4189 {
4190 inst.error = _("constant expression expected");
c19d1205 4191 return 1;
09d92015 4192 }
c19d1205 4193 if (inst.reloc.exp.X_op == O_constant)
09d92015 4194 {
c19d1205
ZW
4195 if (thumb_p)
4196 {
4197 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4198 {
4199 /* This can be done with a mov(1) instruction. */
4200 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4201 inst.instruction |= inst.reloc.exp.X_add_number;
4202 return 1;
4203 }
4204 }
4205 else
4206 {
4207 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4208 if (value != FAIL)
4209 {
4210 /* This can be done with a mov instruction. */
4211 inst.instruction &= LITERAL_MASK;
4212 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4213 inst.instruction |= value & 0xfff;
4214 return 1;
4215 }
09d92015 4216
c19d1205
ZW
4217 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4218 if (value != FAIL)
4219 {
4220 /* This can be done with a mvn instruction. */
4221 inst.instruction &= LITERAL_MASK;
4222 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4223 inst.instruction |= value & 0xfff;
4224 return 1;
4225 }
4226 }
09d92015
MM
4227 }
4228
c19d1205
ZW
4229 if (add_to_lit_pool () == FAIL)
4230 {
4231 inst.error = _("literal pool insertion failed");
4232 return 1;
4233 }
4234 inst.operands[1].reg = REG_PC;
4235 inst.operands[1].isreg = 1;
4236 inst.operands[1].preind = 1;
4237 inst.reloc.pc_rel = 1;
4238 inst.reloc.type = (thumb_p
4239 ? BFD_RELOC_ARM_THUMB_OFFSET
4240 : (mode_3
4241 ? BFD_RELOC_ARM_HWLITERAL
4242 : BFD_RELOC_ARM_LITERAL));
4243 return 0;
09d92015
MM
4244}
4245
c19d1205
ZW
4246/* Functions for instruction encoding, sorted by subarchitecture.
4247 First some generics; their names are taken from the conventional
4248 bit positions for register arguments in ARM format instructions. */
09d92015 4249
a737bd4d 4250static void
c19d1205 4251do_noargs (void)
09d92015 4252{
c19d1205 4253}
a737bd4d 4254
c19d1205
ZW
4255static void
4256do_rd (void)
4257{
4258 inst.instruction |= inst.operands[0].reg << 12;
4259}
a737bd4d 4260
c19d1205
ZW
4261static void
4262do_rd_rm (void)
4263{
4264 inst.instruction |= inst.operands[0].reg << 12;
4265 inst.instruction |= inst.operands[1].reg;
4266}
09d92015 4267
c19d1205
ZW
4268static void
4269do_rd_rn (void)
4270{
4271 inst.instruction |= inst.operands[0].reg << 12;
4272 inst.instruction |= inst.operands[1].reg << 16;
4273}
a737bd4d 4274
c19d1205
ZW
4275static void
4276do_rn_rd (void)
4277{
4278 inst.instruction |= inst.operands[0].reg << 16;
4279 inst.instruction |= inst.operands[1].reg << 12;
4280}
09d92015 4281
c19d1205
ZW
4282static void
4283do_rd_rm_rn (void)
4284{
4285 inst.instruction |= inst.operands[0].reg << 12;
4286 inst.instruction |= inst.operands[1].reg;
4287 inst.instruction |= inst.operands[2].reg << 16;
4288}
09d92015 4289
c19d1205
ZW
4290static void
4291do_rd_rn_rm (void)
4292{
4293 inst.instruction |= inst.operands[0].reg << 12;
4294 inst.instruction |= inst.operands[1].reg << 16;
4295 inst.instruction |= inst.operands[2].reg;
4296}
a737bd4d 4297
c19d1205
ZW
4298static void
4299do_rm_rd_rn (void)
4300{
4301 inst.instruction |= inst.operands[0].reg;
4302 inst.instruction |= inst.operands[1].reg << 12;
4303 inst.instruction |= inst.operands[2].reg << 16;
4304}
09d92015 4305
c19d1205
ZW
4306static void
4307do_imm0 (void)
4308{
4309 inst.instruction |= inst.operands[0].imm;
4310}
09d92015 4311
c19d1205
ZW
4312static void
4313do_rd_cpaddr (void)
4314{
4315 inst.instruction |= inst.operands[0].reg << 12;
4316 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4317}
a737bd4d 4318
c19d1205
ZW
4319/* ARM instructions, in alphabetical order by function name (except
4320 that wrapper functions appear immediately after the function they
4321 wrap). */
09d92015 4322
c19d1205
ZW
4323/* This is a pseudo-op of the form "adr rd, label" to be converted
4324 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4325
4326static void
c19d1205 4327do_adr (void)
09d92015 4328{
c19d1205 4329 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4330
c19d1205
ZW
4331 /* Frag hacking will turn this into a sub instruction if the offset turns
4332 out to be negative. */
4333 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4334#ifndef TE_WINCE
4335 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust. */
4336#endif
4337 inst.reloc.pc_rel = 1;
4338}
b99bd4ef 4339
c19d1205
ZW
4340/* This is a pseudo-op of the form "adrl rd, label" to be converted
4341 into a relative address of the form:
4342 add rd, pc, #low(label-.-8)"
4343 add rd, rd, #high(label-.-8)" */
b99bd4ef 4344
c19d1205
ZW
4345static void
4346do_adrl (void)
4347{
4348 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4349
c19d1205
ZW
4350 /* Frag hacking will turn this into a sub instruction if the offset turns
4351 out to be negative. */
4352 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
4353#ifndef TE_WINCE
4354 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust */
4355#endif
4356 inst.reloc.pc_rel = 1;
4357 inst.size = INSN_SIZE * 2;
b99bd4ef
NC
4358}
4359
b99bd4ef 4360static void
c19d1205 4361do_arit (void)
b99bd4ef 4362{
c19d1205
ZW
4363 if (!inst.operands[1].present)
4364 inst.operands[1].reg = inst.operands[0].reg;
4365 inst.instruction |= inst.operands[0].reg << 12;
4366 inst.instruction |= inst.operands[1].reg << 16;
4367 encode_arm_shifter_operand (2);
4368}
b99bd4ef 4369
c19d1205
ZW
4370static void
4371do_bfc (void)
4372{
4373 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4374 constraint (msb > 32, _("bit-field extends past end of register"));
4375 /* The instruction encoding stores the LSB and MSB,
4376 not the LSB and width. */
4377 inst.instruction |= inst.operands[0].reg << 12;
4378 inst.instruction |= inst.operands[1].imm << 7;
4379 inst.instruction |= (msb - 1) << 16;
4380}
b99bd4ef 4381
c19d1205
ZW
4382static void
4383do_bfi (void)
4384{
4385 unsigned int msb;
b99bd4ef 4386
c19d1205
ZW
4387 /* #0 in second position is alternative syntax for bfc, which is
4388 the same instruction but with REG_PC in the Rm field. */
4389 if (!inst.operands[1].isreg)
4390 inst.operands[1].reg = REG_PC;
b99bd4ef 4391
c19d1205
ZW
4392 msb = inst.operands[2].imm + inst.operands[3].imm;
4393 constraint (msb > 32, _("bit-field extends past end of register"));
4394 /* The instruction encoding stores the LSB and MSB,
4395 not the LSB and width. */
4396 inst.instruction |= inst.operands[0].reg << 12;
4397 inst.instruction |= inst.operands[1].reg;
4398 inst.instruction |= inst.operands[2].imm << 7;
4399 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4400}
4401
b99bd4ef 4402static void
c19d1205 4403do_bfx (void)
b99bd4ef 4404{
c19d1205
ZW
4405 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4406 _("bit-field extends past end of register"));
4407 inst.instruction |= inst.operands[0].reg << 12;
4408 inst.instruction |= inst.operands[1].reg;
4409 inst.instruction |= inst.operands[2].imm << 7;
4410 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4411}
09d92015 4412
c19d1205
ZW
4413/* ARM V5 breakpoint instruction (argument parse)
4414 BKPT <16 bit unsigned immediate>
4415 Instruction is not conditional.
4416 The bit pattern given in insns[] has the COND_ALWAYS condition,
4417 and it is an error if the caller tried to override that. */
b99bd4ef 4418
c19d1205
ZW
4419static void
4420do_bkpt (void)
4421{
4422 /* Top 12 of 16 bits to bits 19:8. */
4423 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4424
c19d1205
ZW
4425 /* Bottom 4 of 16 bits to bits 3:0. */
4426 inst.instruction |= inst.operands[0].imm & 0xf;
4427}
09d92015 4428
c19d1205
ZW
4429static void
4430encode_branch (int default_reloc)
4431{
4432 if (inst.operands[0].hasreloc)
4433 {
4434 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4435 _("the only suffix valid here is '(plt)'"));
4436 inst.reloc.type = BFD_RELOC_ARM_PLT32;
4437 inst.reloc.pc_rel = 0;
4438 }
b99bd4ef 4439 else
c19d1205
ZW
4440 {
4441 inst.reloc.type = default_reloc;
4442 inst.reloc.pc_rel = 1;
4443 }
b99bd4ef
NC
4444}
4445
b99bd4ef 4446static void
c19d1205 4447do_branch (void)
b99bd4ef 4448{
c19d1205
ZW
4449 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4450}
b99bd4ef 4451
c19d1205
ZW
4452/* ARM V5 branch-link-exchange instruction (argument parse)
4453 BLX <target_addr> ie BLX(1)
4454 BLX{<condition>} <Rm> ie BLX(2)
4455 Unfortunately, there are two different opcodes for this mnemonic.
4456 So, the insns[].value is not used, and the code here zaps values
4457 into inst.instruction.
4458 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4459
c19d1205
ZW
4460static void
4461do_blx (void)
4462{
4463 if (inst.operands[0].isreg)
b99bd4ef 4464 {
c19d1205
ZW
4465 /* Arg is a register; the opcode provided by insns[] is correct.
4466 It is not illegal to do "blx pc", just useless. */
4467 if (inst.operands[0].reg == REG_PC)
4468 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4469
c19d1205
ZW
4470 inst.instruction |= inst.operands[0].reg;
4471 }
4472 else
b99bd4ef 4473 {
c19d1205
ZW
4474 /* Arg is an address; this instruction cannot be executed
4475 conditionally, and the opcode must be adjusted. */
4476 constraint (inst.cond != COND_ALWAYS, BAD_COND);
4477 inst.instruction = 0xfafffffe;
4478 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4479 }
c19d1205
ZW
4480}
4481
4482static void
4483do_bx (void)
4484{
4485 if (inst.operands[0].reg == REG_PC)
4486 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4487
c19d1205 4488 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4489}
4490
c19d1205
ZW
4491
4492/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4493
4494static void
c19d1205 4495do_bxj (void)
a737bd4d 4496{
c19d1205
ZW
4497 if (inst.operands[0].reg == REG_PC)
4498 as_tsktsk (_("use of r15 in bxj is not really useful"));
4499
4500 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4501}
4502
c19d1205
ZW
4503/* Co-processor data operation:
4504 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4505 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4506static void
4507do_cdp (void)
4508{
4509 inst.instruction |= inst.operands[0].reg << 8;
4510 inst.instruction |= inst.operands[1].imm << 20;
4511 inst.instruction |= inst.operands[2].reg << 12;
4512 inst.instruction |= inst.operands[3].reg << 16;
4513 inst.instruction |= inst.operands[4].reg;
4514 inst.instruction |= inst.operands[5].imm << 5;
4515}
a737bd4d
NC
4516
4517static void
c19d1205 4518do_cmp (void)
a737bd4d 4519{
c19d1205
ZW
4520 inst.instruction |= inst.operands[0].reg << 16;
4521 encode_arm_shifter_operand (1);
a737bd4d
NC
4522}
4523
c19d1205
ZW
4524/* Transfer between coprocessor and ARM registers.
4525 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4526 MRC2
4527 MCR{cond}
4528 MCR2
4529
4530 No special properties. */
09d92015
MM
4531
4532static void
c19d1205 4533do_co_reg (void)
09d92015 4534{
c19d1205
ZW
4535 inst.instruction |= inst.operands[0].reg << 8;
4536 inst.instruction |= inst.operands[1].imm << 21;
4537 inst.instruction |= inst.operands[2].reg << 12;
4538 inst.instruction |= inst.operands[3].reg << 16;
4539 inst.instruction |= inst.operands[4].reg;
4540 inst.instruction |= inst.operands[5].imm << 5;
4541}
09d92015 4542
c19d1205
ZW
4543/* Transfer between coprocessor register and pair of ARM registers.
4544 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4545 MCRR2
4546 MRRC{cond}
4547 MRRC2
b99bd4ef 4548
c19d1205 4549 Two XScale instructions are special cases of these:
09d92015 4550
c19d1205
ZW
4551 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4552 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4553
c19d1205 4554 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4555
c19d1205
ZW
4556static void
4557do_co_reg2c (void)
4558{
4559 inst.instruction |= inst.operands[0].reg << 8;
4560 inst.instruction |= inst.operands[1].imm << 4;
4561 inst.instruction |= inst.operands[2].reg << 12;
4562 inst.instruction |= inst.operands[3].reg << 16;
4563 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4564}
4565
c19d1205
ZW
4566static void
4567do_cpsi (void)
4568{
4569 inst.instruction |= inst.operands[0].imm << 6;
4570 inst.instruction |= inst.operands[1].imm;
4571}
b99bd4ef
NC
4572
4573static void
c19d1205 4574do_it (void)
b99bd4ef 4575{
c19d1205
ZW
4576 /* There is no IT instruction in ARM mode. We
4577 process it but do not generate code for it. */
4578 inst.size = 0;
09d92015 4579}
b99bd4ef 4580
09d92015 4581static void
c19d1205 4582do_ldmstm (void)
ea6ef066 4583{
c19d1205
ZW
4584 int base_reg = inst.operands[0].reg;
4585 int range = inst.operands[1].imm;
ea6ef066 4586
c19d1205
ZW
4587 inst.instruction |= base_reg << 16;
4588 inst.instruction |= range;
ea6ef066 4589
c19d1205
ZW
4590 if (inst.operands[1].writeback)
4591 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4592
c19d1205 4593 if (inst.operands[0].writeback)
ea6ef066 4594 {
c19d1205
ZW
4595 inst.instruction |= WRITE_BACK;
4596 /* Check for unpredictable uses of writeback. */
4597 if (inst.instruction & LOAD_BIT)
09d92015 4598 {
c19d1205
ZW
4599 /* Not allowed in LDM type 2. */
4600 if ((inst.instruction & LDM_TYPE_2_OR_3)
4601 && ((range & (1 << REG_PC)) == 0))
4602 as_warn (_("writeback of base register is UNPREDICTABLE"));
4603 /* Only allowed if base reg not in list for other types. */
4604 else if (range & (1 << base_reg))
4605 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4606 }
4607 else /* STM. */
4608 {
4609 /* Not allowed for type 2. */
4610 if (inst.instruction & LDM_TYPE_2_OR_3)
4611 as_warn (_("writeback of base register is UNPREDICTABLE"));
4612 /* Only allowed if base reg not in list, or first in list. */
4613 else if ((range & (1 << base_reg))
4614 && (range & ((1 << base_reg) - 1)))
4615 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4616 }
ea6ef066 4617 }
a737bd4d
NC
4618}
4619
c19d1205
ZW
4620/* ARMv5TE load-consecutive (argument parse)
4621 Mode is like LDRH.
4622
4623 LDRccD R, mode
4624 STRccD R, mode. */
4625
a737bd4d 4626static void
c19d1205 4627do_ldrd (void)
a737bd4d 4628{
c19d1205
ZW
4629 constraint (inst.operands[0].reg % 2 != 0,
4630 _("first destination register must be even"));
4631 constraint (inst.operands[1].present
4632 && inst.operands[1].reg != inst.operands[0].reg + 1,
4633 _("can only load two consecutive registers"));
4634 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4635 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4636
c19d1205
ZW
4637 if (!inst.operands[1].present)
4638 inst.operands[1].reg = inst.operands[0].reg + 1;
4639
4640 if (inst.instruction & LOAD_BIT)
a737bd4d 4641 {
c19d1205
ZW
4642 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4643 register and the first register written; we have to diagnose
4644 overlap between the base and the second register written here. */
ea6ef066 4645
c19d1205
ZW
4646 if (inst.operands[2].reg == inst.operands[1].reg
4647 && (inst.operands[2].writeback || inst.operands[2].postind))
4648 as_warn (_("base register written back, and overlaps "
4649 "second destination register"));
b05fe5cf 4650
c19d1205
ZW
4651 /* For an index-register load, the index register must not overlap the
4652 destination (even if not write-back). */
4653 else if (inst.operands[2].immisreg
4654 && (inst.operands[2].imm == inst.operands[0].reg
4655 || inst.operands[2].imm == inst.operands[1].reg))
4656 as_warn (_("index register overlaps destination register"));
b05fe5cf 4657 }
c19d1205
ZW
4658
4659 inst.instruction |= inst.operands[0].reg << 12;
4660 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4661}
4662
4663static void
c19d1205 4664do_ldrex (void)
b05fe5cf 4665{
c19d1205
ZW
4666 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4667 || inst.operands[1].postind || inst.operands[1].writeback
4668 || inst.operands[1].immisreg || inst.operands[1].shifted
4669 || inst.operands[1].negative,
4670 _("instruction does not accept this addressing mode"));
b05fe5cf 4671
c19d1205 4672 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
b05fe5cf 4673
c19d1205
ZW
4674 constraint (inst.reloc.exp.X_op != O_constant
4675 || inst.reloc.exp.X_add_number != 0,
4676 _("offset must be zero in ARM encoding"));
b05fe5cf 4677
c19d1205
ZW
4678 inst.instruction |= inst.operands[0].reg << 12;
4679 inst.instruction |= inst.operands[1].reg << 16;
4680 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4681}
4682
4683static void
c19d1205 4684do_ldrexd (void)
b05fe5cf 4685{
c19d1205
ZW
4686 constraint (inst.operands[0].reg % 2 != 0,
4687 _("even register required"));
4688 constraint (inst.operands[1].present
4689 && inst.operands[1].reg != inst.operands[0].reg + 1,
4690 _("can only load two consecutive registers"));
4691 /* If op 1 were present and equal to PC, this function wouldn't
4692 have been called in the first place. */
4693 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 4694
c19d1205
ZW
4695 inst.instruction |= inst.operands[0].reg << 12;
4696 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
4697}
4698
4699static void
c19d1205 4700do_ldst (void)
b05fe5cf 4701{
c19d1205
ZW
4702 inst.instruction |= inst.operands[0].reg << 12;
4703 if (!inst.operands[1].isreg)
4704 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 4705 return;
c19d1205 4706 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4707}
4708
4709static void
c19d1205 4710do_ldstt (void)
b05fe5cf 4711{
c19d1205
ZW
4712 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4713 reject [Rn,...]. */
4714 if (inst.operands[1].preind)
b05fe5cf 4715 {
c19d1205
ZW
4716 constraint (inst.reloc.exp.X_op != O_constant ||
4717 inst.reloc.exp.X_add_number != 0,
4718 _("this instruction requires a post-indexed address"));
b05fe5cf 4719
c19d1205
ZW
4720 inst.operands[1].preind = 0;
4721 inst.operands[1].postind = 1;
4722 inst.operands[1].writeback = 1;
b05fe5cf 4723 }
c19d1205
ZW
4724 inst.instruction |= inst.operands[0].reg << 12;
4725 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4726}
b05fe5cf 4727
c19d1205 4728/* Halfword and signed-byte load/store operations. */
b05fe5cf 4729
c19d1205
ZW
4730static void
4731do_ldstv4 (void)
4732{
4733 inst.instruction |= inst.operands[0].reg << 12;
4734 if (!inst.operands[1].isreg)
4735 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 4736 return;
c19d1205 4737 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4738}
4739
4740static void
c19d1205 4741do_ldsttv4 (void)
b05fe5cf 4742{
c19d1205
ZW
4743 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4744 reject [Rn,...]. */
4745 if (inst.operands[1].preind)
b05fe5cf 4746 {
c19d1205
ZW
4747 constraint (inst.reloc.exp.X_op != O_constant ||
4748 inst.reloc.exp.X_add_number != 0,
4749 _("this instruction requires a post-indexed address"));
b05fe5cf 4750
c19d1205
ZW
4751 inst.operands[1].preind = 0;
4752 inst.operands[1].postind = 1;
4753 inst.operands[1].writeback = 1;
b05fe5cf 4754 }
c19d1205
ZW
4755 inst.instruction |= inst.operands[0].reg << 12;
4756 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4757}
b05fe5cf 4758
c19d1205
ZW
4759/* Co-processor register load/store.
4760 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4761static void
4762do_lstc (void)
4763{
4764 inst.instruction |= inst.operands[0].reg << 8;
4765 inst.instruction |= inst.operands[1].reg << 12;
4766 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
4767}
4768
b05fe5cf 4769static void
c19d1205 4770do_mlas (void)
b05fe5cf 4771{
c19d1205
ZW
4772 /* This restriction does not apply to mls (nor to mla in v6, but
4773 that's hard to detect at present). */
4774 if (inst.operands[0].reg == inst.operands[1].reg
4775 && !(inst.instruction & 0x00400000))
4776 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 4777
c19d1205
ZW
4778 inst.instruction |= inst.operands[0].reg << 16;
4779 inst.instruction |= inst.operands[1].reg;
4780 inst.instruction |= inst.operands[2].reg << 8;
4781 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 4782
c19d1205 4783}
b05fe5cf 4784
c19d1205
ZW
4785static void
4786do_mov (void)
4787{
4788 inst.instruction |= inst.operands[0].reg << 12;
4789 encode_arm_shifter_operand (1);
4790}
b05fe5cf 4791
c19d1205
ZW
4792/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4793static void
4794do_mov16 (void)
4795{
4796 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 4797 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
4798 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4799 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 4800}
b99bd4ef
NC
4801
4802static void
c19d1205 4803do_mrs (void)
b99bd4ef 4804{
c19d1205
ZW
4805 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4806 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4807 != (PSR_c|PSR_f),
4808 _("'CPSR' or 'SPSR' expected"));
4809 inst.instruction |= inst.operands[0].reg << 12;
4810 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4811}
b99bd4ef 4812
c19d1205
ZW
4813/* Two possible forms:
4814 "{C|S}PSR_<field>, Rm",
4815 "{C|S}PSR_f, #expression". */
b99bd4ef 4816
c19d1205
ZW
4817static void
4818do_msr (void)
4819{
4820 inst.instruction |= inst.operands[0].imm;
4821 if (inst.operands[1].isreg)
4822 inst.instruction |= inst.operands[1].reg;
4823 else
b99bd4ef 4824 {
c19d1205
ZW
4825 inst.instruction |= INST_IMMEDIATE;
4826 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4827 inst.reloc.pc_rel = 0;
b99bd4ef 4828 }
b99bd4ef
NC
4829}
4830
c19d1205
ZW
4831static void
4832do_mul (void)
a737bd4d 4833{
c19d1205
ZW
4834 if (!inst.operands[2].present)
4835 inst.operands[2].reg = inst.operands[0].reg;
4836 inst.instruction |= inst.operands[0].reg << 16;
4837 inst.instruction |= inst.operands[1].reg;
4838 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 4839
c19d1205
ZW
4840 if (inst.operands[0].reg == inst.operands[1].reg)
4841 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
4842}
4843
c19d1205
ZW
4844/* Long Multiply Parser
4845 UMULL RdLo, RdHi, Rm, Rs
4846 SMULL RdLo, RdHi, Rm, Rs
4847 UMLAL RdLo, RdHi, Rm, Rs
4848 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
4849
4850static void
c19d1205 4851do_mull (void)
b99bd4ef 4852{
c19d1205
ZW
4853 inst.instruction |= inst.operands[0].reg << 12;
4854 inst.instruction |= inst.operands[1].reg << 16;
4855 inst.instruction |= inst.operands[2].reg;
4856 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 4857
c19d1205
ZW
4858 /* rdhi, rdlo and rm must all be different. */
4859 if (inst.operands[0].reg == inst.operands[1].reg
4860 || inst.operands[0].reg == inst.operands[2].reg
4861 || inst.operands[1].reg == inst.operands[2].reg)
4862 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
4863}
b99bd4ef 4864
c19d1205
ZW
4865static void
4866do_nop (void)
4867{
4868 if (inst.operands[0].present)
4869 {
4870 /* Architectural NOP hints are CPSR sets with no bits selected. */
4871 inst.instruction &= 0xf0000000;
4872 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
4873 }
b99bd4ef
NC
4874}
4875
c19d1205
ZW
4876/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
4877 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
4878 Condition defaults to COND_ALWAYS.
4879 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
4880
4881static void
c19d1205 4882do_pkhbt (void)
b99bd4ef 4883{
c19d1205
ZW
4884 inst.instruction |= inst.operands[0].reg << 12;
4885 inst.instruction |= inst.operands[1].reg << 16;
4886 inst.instruction |= inst.operands[2].reg;
4887 if (inst.operands[3].present)
4888 encode_arm_shift (3);
4889}
b99bd4ef 4890
c19d1205 4891/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 4892
c19d1205
ZW
4893static void
4894do_pkhtb (void)
4895{
4896 if (!inst.operands[3].present)
b99bd4ef 4897 {
c19d1205
ZW
4898 /* If the shift specifier is omitted, turn the instruction
4899 into pkhbt rd, rm, rn. */
4900 inst.instruction &= 0xfff00010;
4901 inst.instruction |= inst.operands[0].reg << 12;
4902 inst.instruction |= inst.operands[1].reg;
4903 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
4904 }
4905 else
4906 {
c19d1205
ZW
4907 inst.instruction |= inst.operands[0].reg << 12;
4908 inst.instruction |= inst.operands[1].reg << 16;
4909 inst.instruction |= inst.operands[2].reg;
4910 encode_arm_shift (3);
b99bd4ef
NC
4911 }
4912}
4913
c19d1205
ZW
4914/* ARMv5TE: Preload-Cache
4915
4916 PLD <addr_mode>
4917
4918 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
4919
4920static void
c19d1205 4921do_pld (void)
b99bd4ef 4922{
c19d1205
ZW
4923 constraint (!inst.operands[0].isreg,
4924 _("'[' expected after PLD mnemonic"));
4925 constraint (inst.operands[0].postind,
4926 _("post-indexed expression used in preload instruction"));
4927 constraint (inst.operands[0].writeback,
4928 _("writeback used in preload instruction"));
4929 constraint (!inst.operands[0].preind,
4930 _("unindexed addressing used in preload instruction"));
4931 inst.instruction |= inst.operands[0].reg;
4932 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
4933}
b99bd4ef 4934
c19d1205
ZW
4935static void
4936do_push_pop (void)
4937{
4938 inst.operands[1] = inst.operands[0];
4939 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
4940 inst.operands[0].isreg = 1;
4941 inst.operands[0].writeback = 1;
4942 inst.operands[0].reg = REG_SP;
4943 do_ldmstm ();
4944}
b99bd4ef 4945
c19d1205
ZW
4946/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
4947 word at the specified address and the following word
4948 respectively.
4949 Unconditionally executed.
4950 Error if Rn is R15. */
b99bd4ef 4951
c19d1205
ZW
4952static void
4953do_rfe (void)
4954{
4955 inst.instruction |= inst.operands[0].reg << 16;
4956 if (inst.operands[0].writeback)
4957 inst.instruction |= WRITE_BACK;
4958}
b99bd4ef 4959
c19d1205 4960/* ARM V6 ssat (argument parse). */
b99bd4ef 4961
c19d1205
ZW
4962static void
4963do_ssat (void)
4964{
4965 inst.instruction |= inst.operands[0].reg << 12;
4966 inst.instruction |= (inst.operands[1].imm - 1) << 16;
4967 inst.instruction |= inst.operands[2].reg;
b99bd4ef 4968
c19d1205
ZW
4969 if (inst.operands[3].present)
4970 encode_arm_shift (3);
b99bd4ef
NC
4971}
4972
c19d1205 4973/* ARM V6 usat (argument parse). */
b99bd4ef
NC
4974
4975static void
c19d1205 4976do_usat (void)
b99bd4ef 4977{
c19d1205
ZW
4978 inst.instruction |= inst.operands[0].reg << 12;
4979 inst.instruction |= inst.operands[1].imm << 16;
4980 inst.instruction |= inst.operands[2].reg;
b99bd4ef 4981
c19d1205
ZW
4982 if (inst.operands[3].present)
4983 encode_arm_shift (3);
b99bd4ef
NC
4984}
4985
c19d1205 4986/* ARM V6 ssat16 (argument parse). */
09d92015
MM
4987
4988static void
c19d1205 4989do_ssat16 (void)
09d92015 4990{
c19d1205
ZW
4991 inst.instruction |= inst.operands[0].reg << 12;
4992 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
4993 inst.instruction |= inst.operands[2].reg;
09d92015
MM
4994}
4995
c19d1205
ZW
4996static void
4997do_usat16 (void)
a737bd4d 4998{
c19d1205
ZW
4999 inst.instruction |= inst.operands[0].reg << 12;
5000 inst.instruction |= inst.operands[1].imm << 16;
5001 inst.instruction |= inst.operands[2].reg;
5002}
a737bd4d 5003
c19d1205
ZW
5004/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5005 preserving the other bits.
a737bd4d 5006
c19d1205
ZW
5007 setend <endian_specifier>, where <endian_specifier> is either
5008 BE or LE. */
a737bd4d 5009
c19d1205
ZW
5010static void
5011do_setend (void)
5012{
5013 if (inst.operands[0].imm)
5014 inst.instruction |= 0x200;
a737bd4d
NC
5015}
5016
5017static void
c19d1205 5018do_shift (void)
a737bd4d 5019{
c19d1205
ZW
5020 unsigned int Rm = (inst.operands[1].present
5021 ? inst.operands[1].reg
5022 : inst.operands[0].reg);
a737bd4d 5023
c19d1205
ZW
5024 inst.instruction |= inst.operands[0].reg << 12;
5025 inst.instruction |= Rm;
5026 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5027 {
c19d1205
ZW
5028 constraint (inst.operands[0].reg != Rm,
5029 _("source1 and dest must be same register"));
5030 inst.instruction |= inst.operands[2].reg << 8;
5031 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5032 }
5033 else
c19d1205 5034 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5035}
5036
09d92015 5037static void
c19d1205 5038do_smi (void)
09d92015 5039{
c19d1205
ZW
5040 inst.reloc.type = BFD_RELOC_ARM_SMI;
5041 inst.reloc.pc_rel = 0;
09d92015
MM
5042}
5043
09d92015 5044static void
c19d1205 5045do_swi (void)
09d92015 5046{
c19d1205
ZW
5047 inst.reloc.type = BFD_RELOC_ARM_SWI;
5048 inst.reloc.pc_rel = 0;
09d92015
MM
5049}
5050
c19d1205
ZW
5051/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5052 SMLAxy{cond} Rd,Rm,Rs,Rn
5053 SMLAWy{cond} Rd,Rm,Rs,Rn
5054 Error if any register is R15. */
e16bb312 5055
c19d1205
ZW
5056static void
5057do_smla (void)
e16bb312 5058{
c19d1205
ZW
5059 inst.instruction |= inst.operands[0].reg << 16;
5060 inst.instruction |= inst.operands[1].reg;
5061 inst.instruction |= inst.operands[2].reg << 8;
5062 inst.instruction |= inst.operands[3].reg << 12;
5063}
a737bd4d 5064
c19d1205
ZW
5065/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5066 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5067 Error if any register is R15.
5068 Warning if Rdlo == Rdhi. */
a737bd4d 5069
c19d1205
ZW
5070static void
5071do_smlal (void)
5072{
5073 inst.instruction |= inst.operands[0].reg << 12;
5074 inst.instruction |= inst.operands[1].reg << 16;
5075 inst.instruction |= inst.operands[2].reg;
5076 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5077
c19d1205
ZW
5078 if (inst.operands[0].reg == inst.operands[1].reg)
5079 as_tsktsk (_("rdhi and rdlo must be different"));
5080}
a737bd4d 5081
c19d1205
ZW
5082/* ARM V5E (El Segundo) signed-multiply (argument parse)
5083 SMULxy{cond} Rd,Rm,Rs
5084 Error if any register is R15. */
a737bd4d 5085
c19d1205
ZW
5086static void
5087do_smul (void)
5088{
5089 inst.instruction |= inst.operands[0].reg << 16;
5090 inst.instruction |= inst.operands[1].reg;
5091 inst.instruction |= inst.operands[2].reg << 8;
5092}
a737bd4d 5093
c19d1205 5094/* ARM V6 srs (argument parse). */
a737bd4d 5095
c19d1205
ZW
5096static void
5097do_srs (void)
5098{
5099 inst.instruction |= inst.operands[0].imm;
5100 if (inst.operands[0].writeback)
5101 inst.instruction |= WRITE_BACK;
5102}
a737bd4d 5103
c19d1205 5104/* ARM V6 strex (argument parse). */
a737bd4d 5105
c19d1205
ZW
5106static void
5107do_strex (void)
5108{
5109 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5110 || inst.operands[2].postind || inst.operands[2].writeback
5111 || inst.operands[2].immisreg || inst.operands[2].shifted
5112 || inst.operands[2].negative,
5113 _("instruction does not accept this addressing mode"));
e16bb312 5114
c19d1205 5115 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
a737bd4d 5116
c19d1205
ZW
5117 constraint (inst.operands[0].reg == inst.operands[1].reg
5118 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5119
c19d1205
ZW
5120 constraint (inst.reloc.exp.X_op != O_constant
5121 || inst.reloc.exp.X_add_number != 0,
5122 _("offset must be zero in ARM encoding"));
a737bd4d 5123
c19d1205
ZW
5124 inst.instruction |= inst.operands[0].reg << 12;
5125 inst.instruction |= inst.operands[1].reg;
5126 inst.instruction |= inst.operands[2].reg << 16;
5127 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5128}
5129
5130static void
c19d1205 5131do_strexd (void)
e16bb312 5132{
c19d1205
ZW
5133 constraint (inst.operands[1].reg % 2 != 0,
5134 _("even register required"));
5135 constraint (inst.operands[2].present
5136 && inst.operands[2].reg != inst.operands[1].reg + 1,
5137 _("can only store two consecutive registers"));
5138 /* If op 2 were present and equal to PC, this function wouldn't
5139 have been called in the first place. */
5140 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5141
c19d1205
ZW
5142 constraint (inst.operands[0].reg == inst.operands[1].reg
5143 || inst.operands[0].reg == inst.operands[1].reg + 1
5144 || inst.operands[0].reg == inst.operands[3].reg,
5145 BAD_OVERLAP);
e16bb312 5146
c19d1205
ZW
5147 inst.instruction |= inst.operands[0].reg << 12;
5148 inst.instruction |= inst.operands[1].reg;
5149 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5150}
5151
c19d1205
ZW
5152/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5153 extends it to 32-bits, and adds the result to a value in another
5154 register. You can specify a rotation by 0, 8, 16, or 24 bits
5155 before extracting the 16-bit value.
5156 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5157 Condition defaults to COND_ALWAYS.
5158 Error if any register uses R15. */
5159
e16bb312 5160static void
c19d1205 5161do_sxtah (void)
e16bb312 5162{
c19d1205
ZW
5163 inst.instruction |= inst.operands[0].reg << 12;
5164 inst.instruction |= inst.operands[1].reg << 16;
5165 inst.instruction |= inst.operands[2].reg;
5166 inst.instruction |= inst.operands[3].imm << 10;
5167}
e16bb312 5168
c19d1205 5169/* ARM V6 SXTH.
e16bb312 5170
c19d1205
ZW
5171 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5172 Condition defaults to COND_ALWAYS.
5173 Error if any register uses R15. */
e16bb312
NC
5174
5175static void
c19d1205 5176do_sxth (void)
e16bb312 5177{
c19d1205
ZW
5178 inst.instruction |= inst.operands[0].reg << 12;
5179 inst.instruction |= inst.operands[1].reg;
5180 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5181}
c19d1205
ZW
5182\f
5183/* VFP instructions. In a logical order: SP variant first, monad
5184 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5185
5186static void
c19d1205 5187do_vfp_sp_monadic (void)
e16bb312 5188{
c19d1205
ZW
5189 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5190 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5191}
5192
5193static void
c19d1205 5194do_vfp_sp_dyadic (void)
e16bb312 5195{
c19d1205
ZW
5196 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5197 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5198 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5199}
5200
5201static void
c19d1205 5202do_vfp_sp_compare_z (void)
e16bb312 5203{
c19d1205 5204 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5205}
5206
5207static void
c19d1205 5208do_vfp_dp_sp_cvt (void)
e16bb312 5209{
c19d1205
ZW
5210 inst.instruction |= inst.operands[0].reg << 12;
5211 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5212}
5213
5214static void
c19d1205 5215do_vfp_sp_dp_cvt (void)
e16bb312 5216{
c19d1205
ZW
5217 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5218 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5219}
5220
5221static void
c19d1205 5222do_vfp_reg_from_sp (void)
e16bb312 5223{
c19d1205
ZW
5224 inst.instruction |= inst.operands[0].reg << 12;
5225 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5226}
5227
5228static void
c19d1205 5229do_vfp_reg2_from_sp2 (void)
e16bb312 5230{
c19d1205
ZW
5231 constraint (inst.operands[2].imm != 2,
5232 _("only two consecutive VFP SP registers allowed here"));
5233 inst.instruction |= inst.operands[0].reg << 12;
5234 inst.instruction |= inst.operands[1].reg << 16;
5235 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5236}
5237
5238static void
c19d1205 5239do_vfp_sp_from_reg (void)
e16bb312 5240{
c19d1205
ZW
5241 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5242 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5243}
5244
5245static void
c19d1205 5246do_vfp_sp2_from_reg2 (void)
e16bb312 5247{
c19d1205
ZW
5248 constraint (inst.operands[0].imm != 2,
5249 _("only two consecutive VFP SP registers allowed here"));
5250 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5251 inst.instruction |= inst.operands[1].reg << 12;
5252 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5253}
5254
5255static void
c19d1205 5256do_vfp_sp_ldst (void)
e16bb312 5257{
c19d1205
ZW
5258 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5259 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5260}
5261
5262static void
c19d1205 5263do_vfp_dp_ldst (void)
e16bb312 5264{
c19d1205
ZW
5265 inst.instruction |= inst.operands[0].reg << 12;
5266 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5267}
5268
c19d1205 5269
e16bb312 5270static void
c19d1205 5271vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5272{
c19d1205
ZW
5273 if (inst.operands[0].writeback)
5274 inst.instruction |= WRITE_BACK;
5275 else
5276 constraint (ldstm_type != VFP_LDSTMIA,
5277 _("this addressing mode requires base-register writeback"));
5278 inst.instruction |= inst.operands[0].reg << 16;
5279 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5280 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5281}
5282
5283static void
c19d1205 5284vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5285{
c19d1205 5286 int count;
e16bb312 5287
c19d1205
ZW
5288 if (inst.operands[0].writeback)
5289 inst.instruction |= WRITE_BACK;
5290 else
5291 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5292 _("this addressing mode requires base-register writeback"));
e16bb312 5293
c19d1205
ZW
5294 inst.instruction |= inst.operands[0].reg << 16;
5295 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5296
c19d1205
ZW
5297 count = inst.operands[1].imm << 1;
5298 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5299 count += 1;
e16bb312 5300
c19d1205 5301 inst.instruction |= count;
e16bb312
NC
5302}
5303
5304static void
c19d1205 5305do_vfp_sp_ldstmia (void)
e16bb312 5306{
c19d1205 5307 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5308}
5309
5310static void
c19d1205 5311do_vfp_sp_ldstmdb (void)
e16bb312 5312{
c19d1205 5313 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5314}
5315
5316static void
c19d1205 5317do_vfp_dp_ldstmia (void)
e16bb312 5318{
c19d1205 5319 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5320}
5321
5322static void
c19d1205 5323do_vfp_dp_ldstmdb (void)
e16bb312 5324{
c19d1205 5325 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5326}
5327
5328static void
c19d1205 5329do_vfp_xp_ldstmia (void)
e16bb312 5330{
c19d1205
ZW
5331 vfp_dp_ldstm (VFP_LDSTMIAX);
5332}
e16bb312 5333
c19d1205
ZW
5334static void
5335do_vfp_xp_ldstmdb (void)
5336{
5337 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5338}
c19d1205
ZW
5339\f
5340/* FPA instructions. Also in a logical order. */
e16bb312 5341
c19d1205
ZW
5342static void
5343do_fpa_cmp (void)
5344{
5345 inst.instruction |= inst.operands[0].reg << 16;
5346 inst.instruction |= inst.operands[1].reg;
5347}
b99bd4ef
NC
5348
5349static void
c19d1205 5350do_fpa_ldmstm (void)
b99bd4ef 5351{
c19d1205
ZW
5352 inst.instruction |= inst.operands[0].reg << 12;
5353 switch (inst.operands[1].imm)
5354 {
5355 case 1: inst.instruction |= CP_T_X; break;
5356 case 2: inst.instruction |= CP_T_Y; break;
5357 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5358 case 4: break;
5359 default: abort ();
5360 }
b99bd4ef 5361
c19d1205
ZW
5362 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5363 {
5364 /* The instruction specified "ea" or "fd", so we can only accept
5365 [Rn]{!}. The instruction does not really support stacking or
5366 unstacking, so we have to emulate these by setting appropriate
5367 bits and offsets. */
5368 constraint (inst.reloc.exp.X_op != O_constant
5369 || inst.reloc.exp.X_add_number != 0,
5370 _("this instruction does not support indexing"));
b99bd4ef 5371
c19d1205
ZW
5372 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5373 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5374
c19d1205
ZW
5375 if (!(inst.instruction & INDEX_UP))
5376 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5377
c19d1205
ZW
5378 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5379 {
5380 inst.operands[2].preind = 0;
5381 inst.operands[2].postind = 1;
5382 }
5383 }
b99bd4ef 5384
c19d1205 5385 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5386}
c19d1205
ZW
5387\f
5388/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5389
c19d1205
ZW
5390static void
5391do_iwmmxt_tandorc (void)
5392{
5393 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5394}
b99bd4ef 5395
c19d1205
ZW
5396static void
5397do_iwmmxt_textrc (void)
5398{
5399 inst.instruction |= inst.operands[0].reg << 12;
5400 inst.instruction |= inst.operands[1].imm;
5401}
b99bd4ef
NC
5402
5403static void
c19d1205 5404do_iwmmxt_textrm (void)
b99bd4ef 5405{
c19d1205
ZW
5406 inst.instruction |= inst.operands[0].reg << 12;
5407 inst.instruction |= inst.operands[1].reg << 16;
5408 inst.instruction |= inst.operands[2].imm;
5409}
b99bd4ef 5410
c19d1205
ZW
5411static void
5412do_iwmmxt_tinsr (void)
5413{
5414 inst.instruction |= inst.operands[0].reg << 16;
5415 inst.instruction |= inst.operands[1].reg << 12;
5416 inst.instruction |= inst.operands[2].imm;
5417}
b99bd4ef 5418
c19d1205
ZW
5419static void
5420do_iwmmxt_tmia (void)
5421{
5422 inst.instruction |= inst.operands[0].reg << 5;
5423 inst.instruction |= inst.operands[1].reg;
5424 inst.instruction |= inst.operands[2].reg << 12;
5425}
b99bd4ef 5426
c19d1205
ZW
5427static void
5428do_iwmmxt_waligni (void)
5429{
5430 inst.instruction |= inst.operands[0].reg << 12;
5431 inst.instruction |= inst.operands[1].reg << 16;
5432 inst.instruction |= inst.operands[2].reg;
5433 inst.instruction |= inst.operands[3].imm << 20;
5434}
b99bd4ef 5435
c19d1205
ZW
5436static void
5437do_iwmmxt_wmov (void)
5438{
5439 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5440 inst.instruction |= inst.operands[0].reg << 12;
5441 inst.instruction |= inst.operands[1].reg << 16;
5442 inst.instruction |= inst.operands[1].reg;
5443}
b99bd4ef 5444
c19d1205
ZW
5445static void
5446do_iwmmxt_wldstbh (void)
5447{
5448 inst.instruction |= inst.operands[0].reg << 12;
5449 inst.reloc.exp.X_add_number *= 4;
5450 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
b99bd4ef
NC
5451}
5452
c19d1205
ZW
5453static void
5454do_iwmmxt_wldstw (void)
5455{
5456 /* RIWR_RIWC clears .isreg for a control register. */
5457 if (!inst.operands[0].isreg)
5458 {
5459 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5460 inst.instruction |= 0xf0000000;
5461 }
b99bd4ef 5462
c19d1205
ZW
5463 inst.instruction |= inst.operands[0].reg << 12;
5464 encode_arm_cp_address (1, TRUE, TRUE, 0);
5465}
b99bd4ef
NC
5466
5467static void
c19d1205 5468do_iwmmxt_wldstd (void)
b99bd4ef 5469{
c19d1205
ZW
5470 inst.instruction |= inst.operands[0].reg << 12;
5471 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
5472}
b99bd4ef 5473
c19d1205
ZW
5474static void
5475do_iwmmxt_wshufh (void)
5476{
5477 inst.instruction |= inst.operands[0].reg << 12;
5478 inst.instruction |= inst.operands[1].reg << 16;
5479 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5480 inst.instruction |= (inst.operands[2].imm & 0x0f);
5481}
b99bd4ef 5482
c19d1205
ZW
5483static void
5484do_iwmmxt_wzero (void)
5485{
5486 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5487 inst.instruction |= inst.operands[0].reg;
5488 inst.instruction |= inst.operands[0].reg << 12;
5489 inst.instruction |= inst.operands[0].reg << 16;
5490}
5491\f
5492/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5493 operations first, then control, shift, and load/store. */
b99bd4ef 5494
c19d1205 5495/* Insns like "foo X,Y,Z". */
b99bd4ef 5496
c19d1205
ZW
5497static void
5498do_mav_triple (void)
5499{
5500 inst.instruction |= inst.operands[0].reg << 16;
5501 inst.instruction |= inst.operands[1].reg;
5502 inst.instruction |= inst.operands[2].reg << 12;
5503}
b99bd4ef 5504
c19d1205
ZW
5505/* Insns like "foo W,X,Y,Z".
5506 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5507
c19d1205
ZW
5508static void
5509do_mav_quad (void)
5510{
5511 inst.instruction |= inst.operands[0].reg << 5;
5512 inst.instruction |= inst.operands[1].reg << 12;
5513 inst.instruction |= inst.operands[2].reg << 16;
5514 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5515}
5516
c19d1205
ZW
5517/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5518static void
5519do_mav_dspsc (void)
a737bd4d 5520{
c19d1205
ZW
5521 inst.instruction |= inst.operands[1].reg << 12;
5522}
a737bd4d 5523
c19d1205
ZW
5524/* Maverick shift immediate instructions.
5525 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5526 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5527
c19d1205
ZW
5528static void
5529do_mav_shift (void)
5530{
5531 int imm = inst.operands[2].imm;
a737bd4d 5532
c19d1205
ZW
5533 inst.instruction |= inst.operands[0].reg << 12;
5534 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5535
c19d1205
ZW
5536 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5537 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5538 Bit 4 should be 0. */
5539 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5540
c19d1205
ZW
5541 inst.instruction |= imm;
5542}
5543\f
5544/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5545
c19d1205
ZW
5546/* Xscale multiply-accumulate (argument parse)
5547 MIAcc acc0,Rm,Rs
5548 MIAPHcc acc0,Rm,Rs
5549 MIAxycc acc0,Rm,Rs. */
a737bd4d 5550
c19d1205
ZW
5551static void
5552do_xsc_mia (void)
5553{
5554 inst.instruction |= inst.operands[1].reg;
5555 inst.instruction |= inst.operands[2].reg << 12;
5556}
a737bd4d 5557
c19d1205 5558/* Xscale move-accumulator-register (argument parse)
a737bd4d 5559
c19d1205 5560 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5561
c19d1205
ZW
5562static void
5563do_xsc_mar (void)
5564{
5565 inst.instruction |= inst.operands[1].reg << 12;
5566 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5567}
5568
c19d1205 5569/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5570
c19d1205 5571 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5572
5573static void
c19d1205 5574do_xsc_mra (void)
b99bd4ef 5575{
c19d1205
ZW
5576 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5577 inst.instruction |= inst.operands[0].reg << 12;
5578 inst.instruction |= inst.operands[1].reg << 16;
5579}
5580\f
5581/* Encoding functions relevant only to Thumb. */
b99bd4ef 5582
c19d1205
ZW
5583/* inst.operands[i] is a shifted-register operand; encode
5584 it into inst.instruction in the format used by Thumb32. */
5585
5586static void
5587encode_thumb32_shifted_operand (int i)
5588{
5589 unsigned int value = inst.reloc.exp.X_add_number;
5590 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5591
c19d1205
ZW
5592 inst.instruction |= inst.operands[i].reg;
5593 if (shift == SHIFT_RRX)
5594 inst.instruction |= SHIFT_ROR << 4;
5595 else
b99bd4ef 5596 {
c19d1205
ZW
5597 constraint (inst.reloc.exp.X_op != O_constant,
5598 _("expression too complex"));
5599
5600 constraint (value > 32
5601 || (value == 32 && (shift == SHIFT_LSL
5602 || shift == SHIFT_ROR)),
5603 _("shift expression is too large"));
5604
5605 if (value == 0)
5606 shift = SHIFT_LSL;
5607 else if (value == 32)
5608 value = 0;
5609
5610 inst.instruction |= shift << 4;
5611 inst.instruction |= (value & 0x1c) << 10;
5612 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5613 }
c19d1205 5614}
b99bd4ef 5615
b99bd4ef 5616
c19d1205
ZW
5617/* inst.operands[i] was set up by parse_address. Encode it into a
5618 Thumb32 format load or store instruction. Reject forms that cannot
5619 be used with such instructions. If is_t is true, reject forms that
5620 cannot be used with a T instruction; if is_d is true, reject forms
5621 that cannot be used with a D instruction. */
b99bd4ef 5622
c19d1205
ZW
5623static void
5624encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5625{
5626 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5627
5628 constraint (!inst.operands[i].isreg,
5629 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5630
c19d1205
ZW
5631 inst.instruction |= inst.operands[i].reg << 16;
5632 if (inst.operands[i].immisreg)
b99bd4ef 5633 {
c19d1205
ZW
5634 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5635 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5636 constraint (inst.operands[i].negative,
5637 _("Thumb does not support negative register indexing"));
5638 constraint (inst.operands[i].postind,
5639 _("Thumb does not support register post-indexing"));
5640 constraint (inst.operands[i].writeback,
5641 _("Thumb does not support register indexing with writeback"));
5642 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5643 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5644
c19d1205
ZW
5645 inst.instruction |= inst.operands[1].imm;
5646 if (inst.operands[i].shifted)
b99bd4ef 5647 {
c19d1205
ZW
5648 constraint (inst.reloc.exp.X_op != O_constant,
5649 _("expression too complex"));
5650 constraint (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 3,
5651 _("shift out of range"));
5652 inst.instruction |= inst.reloc.exp.X_op << 4;
5653 }
5654 inst.reloc.type = BFD_RELOC_UNUSED;
5655 }
5656 else if (inst.operands[i].preind)
5657 {
5658 constraint (is_pc && inst.operands[i].writeback,
5659 _("cannot use writeback with PC-relative addressing"));
5660 constraint (is_t && inst.operands[1].writeback,
5661 _("cannot use writeback with this instruction"));
5662
5663 if (is_d)
5664 {
5665 inst.instruction |= 0x01000000;
5666 if (inst.operands[i].writeback)
5667 inst.instruction |= 0x00200000;
b99bd4ef 5668 }
c19d1205 5669 else
b99bd4ef 5670 {
c19d1205
ZW
5671 inst.instruction |= 0x00000c00;
5672 if (inst.operands[i].writeback)
5673 inst.instruction |= 0x00000100;
b99bd4ef 5674 }
c19d1205
ZW
5675 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5676 inst.reloc.pc_rel = is_pc;
b99bd4ef 5677 }
c19d1205 5678 else if (inst.operands[i].postind)
b99bd4ef 5679 {
c19d1205
ZW
5680 assert (inst.operands[i].writeback);
5681 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5682 constraint (is_t, _("cannot use post-indexing with this instruction"));
5683
5684 if (is_d)
5685 inst.instruction |= 0x00200000;
5686 else
5687 inst.instruction |= 0x00000900;
5688 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5689 }
5690 else /* unindexed - only for coprocessor */
5691 inst.error = _("instruction does not accept unindexed addressing");
5692}
5693
5694/* Table of Thumb instructions which exist in both 16- and 32-bit
5695 encodings (the latter only in post-V6T2 cores). The index is the
5696 value used in the insns table below. When there is more than one
5697 possible 16-bit encoding for the instruction, this table always
5698 holds variant (1). */
5699#define T16_32_TAB \
5700 X(adc, 4140, eb400000), \
5701 X(adcs, 4140, eb500000), \
5702 X(add, 1c00, eb000000), \
5703 X(adds, 1c00, eb100000), \
5704 X(and, 4000, ea000000), \
5705 X(ands, 4000, ea100000), \
5706 X(asr, 1000, fa40f000), \
5707 X(asrs, 1000, fa50f000), \
5708 X(bic, 4380, ea200000), \
5709 X(bics, 4380, ea300000), \
5710 X(cmn, 42c0, eb100f00), \
5711 X(cmp, 2800, ebb00f00), \
5712 X(cpsie, b660, f3af8400), \
5713 X(cpsid, b670, f3af8600), \
5714 X(cpy, 4600, ea4f0000), \
5715 X(eor, 4040, ea800000), \
5716 X(eors, 4040, ea900000), \
5717 X(ldmia, c800, e8900000), \
5718 X(ldr, 6800, f8500000), \
5719 X(ldrb, 7800, f8100000), \
5720 X(ldrh, 8800, f8300000), \
5721 X(ldrsb, 5600, f9100000), \
5722 X(ldrsh, 5e00, f9300000), \
5723 X(lsl, 0000, fa00f000), \
5724 X(lsls, 0000, fa10f000), \
5725 X(lsr, 0800, fa20f000), \
5726 X(lsrs, 0800, fa30f000), \
5727 X(mov, 2000, ea4f0000), \
5728 X(movs, 2000, ea5f0000), \
5729 X(mul, 4340, fb00f000), \
5730 X(muls, 4340, ffffffff), /* no 32b muls */ \
5731 X(mvn, 43c0, ea6f0000), \
5732 X(mvns, 43c0, ea7f0000), \
5733 X(neg, 4240, f1c00000), /* rsb #0 */ \
5734 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5735 X(orr, 4300, ea400000), \
5736 X(orrs, 4300, ea500000), \
5737 X(pop, bc00, e8ad0000), /* ldmia sp!,... */ \
5738 X(push, b400, e8bd0000), /* stmia sp!,... */ \
5739 X(rev, ba00, fa90f080), \
5740 X(rev16, ba40, fa90f090), \
5741 X(revsh, bac0, fa90f0b0), \
5742 X(ror, 41c0, fa60f000), \
5743 X(rors, 41c0, fa70f000), \
5744 X(sbc, 4180, eb600000), \
5745 X(sbcs, 4180, eb700000), \
5746 X(stmia, c000, e8800000), \
5747 X(str, 6000, f8400000), \
5748 X(strb, 7000, f8000000), \
5749 X(strh, 8000, f8200000), \
5750 X(sub, 1e00, eba00000), \
5751 X(subs, 1e00, ebb00000), \
5752 X(sxtb, b240, fa4ff080), \
5753 X(sxth, b200, fa0ff080), \
5754 X(tst, 4200, ea100f00), \
5755 X(uxtb, b2c0, fa5ff080), \
5756 X(uxth, b280, fa1ff080), \
5757 X(nop, bf00, f3af8000), \
5758 X(yield, bf10, f3af8001), \
5759 X(wfe, bf20, f3af8002), \
5760 X(wfi, bf30, f3af8003), \
5761 X(sev, bf40, f3af9004), /* typo, 8004? */
5762
5763/* To catch errors in encoding functions, the codes are all offset by
5764 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5765 as 16-bit instructions. */
5766#define X(a,b,c) T_MNEM_##a
5767enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5768#undef X
5769
5770#define X(a,b,c) 0x##b
5771static const unsigned short thumb_op16[] = { T16_32_TAB };
5772#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5773#undef X
5774
5775#define X(a,b,c) 0x##c
5776static const unsigned int thumb_op32[] = { T16_32_TAB };
5777#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5778#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5779#undef X
5780#undef T16_32_TAB
5781
5782/* Thumb instruction encoders, in alphabetical order. */
5783
5784/* Parse an add or subtract instruction. We get here with inst.instruction
5785 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5786
5787static void
5788do_t_add_sub (void)
5789{
5790 int Rd, Rs, Rn;
5791
5792 Rd = inst.operands[0].reg;
5793 Rs = (inst.operands[1].present
5794 ? inst.operands[1].reg /* Rd, Rs, foo */
5795 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5796
5797 if (unified_syntax)
5798 {
5799 if (!inst.operands[2].isreg)
b99bd4ef 5800 {
c19d1205
ZW
5801 /* For an immediate, we always generate a 32-bit opcode;
5802 section relaxation will shrink it later if possible. */
5803 inst.instruction = THUMB_OP32 (inst.instruction);
5804 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5805 inst.instruction |= inst.operands[0].reg << 8;
5806 inst.instruction |= inst.operands[1].reg << 16;
5807 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 5808 }
c19d1205
ZW
5809 else
5810 {
5811 Rn = inst.operands[2].reg;
5812 /* See if we can do this with a 16-bit instruction. */
5813 if (!inst.operands[2].shifted && inst.size_req != 4)
5814 {
5815 if (Rd <= 7 && Rn <= 7 && Rn <= 7
5816 && (inst.instruction == T_MNEM_adds
5817 || inst.instruction == T_MNEM_subs))
5818 {
5819 inst.instruction = (inst.instruction == T_MNEM_adds
5820 ? T_OPCODE_ADD_R3
5821 : T_OPCODE_SUB_R3);
5822 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
5823 return;
5824 }
b99bd4ef 5825
c19d1205
ZW
5826 if (inst.instruction == T_MNEM_add)
5827 {
5828 if (Rd == Rs)
5829 {
5830 inst.instruction = T_OPCODE_ADD_HI;
5831 inst.instruction |= (Rd & 8) << 4;
5832 inst.instruction |= (Rd & 7);
5833 inst.instruction |= Rn << 3;
5834 return;
5835 }
5836 /* ... because addition is commutative! */
5837 else if (Rd == Rn)
5838 {
5839 inst.instruction = T_OPCODE_ADD_HI;
5840 inst.instruction |= (Rd & 8) << 4;
5841 inst.instruction |= (Rd & 7);
5842 inst.instruction |= Rs << 3;
5843 return;
5844 }
5845 }
5846 }
5847 /* If we get here, it can't be done in 16 bits. */
5848 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
5849 _("shift must be constant"));
5850 inst.instruction = THUMB_OP32 (inst.instruction);
5851 inst.instruction |= Rd << 8;
5852 inst.instruction |= Rs << 16;
5853 encode_thumb32_shifted_operand (2);
5854 }
5855 }
5856 else
5857 {
5858 constraint (inst.instruction == T_MNEM_adds
5859 || inst.instruction == T_MNEM_subs,
5860 BAD_THUMB32);
b99bd4ef 5861
c19d1205 5862 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 5863 {
c19d1205
ZW
5864 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
5865 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
5866 BAD_HIREG);
5867
5868 inst.instruction = (inst.instruction == T_MNEM_add
5869 ? 0x0000 : 0x8000);
5870 inst.instruction |= (Rd << 4) | Rs;
5871 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
5872 return;
5873 }
5874
c19d1205
ZW
5875 Rn = inst.operands[2].reg;
5876 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 5877
c19d1205
ZW
5878 /* We now have Rd, Rs, and Rn set to registers. */
5879 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 5880 {
c19d1205
ZW
5881 /* Can't do this for SUB. */
5882 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
5883 inst.instruction = T_OPCODE_ADD_HI;
5884 inst.instruction |= (Rd & 8) << 4;
5885 inst.instruction |= (Rd & 7);
5886 if (Rs == Rd)
5887 inst.instruction |= Rn << 3;
5888 else if (Rn == Rd)
5889 inst.instruction |= Rs << 3;
5890 else
5891 constraint (1, _("dest must overlap one source register"));
5892 }
5893 else
5894 {
5895 inst.instruction = (inst.instruction == T_MNEM_add
5896 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
5897 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 5898 }
b99bd4ef 5899 }
b99bd4ef
NC
5900}
5901
c19d1205
ZW
5902static void
5903do_t_adr (void)
5904{
5905 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
5906 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
5907 inst.reloc.pc_rel = 1;
b99bd4ef 5908
c19d1205
ZW
5909 inst.instruction |= inst.operands[0].reg << 4;
5910}
b99bd4ef 5911
c19d1205
ZW
5912/* Arithmetic instructions for which there is just one 16-bit
5913 instruction encoding, and it allows only two low registers.
5914 For maximal compatibility with ARM syntax, we allow three register
5915 operands even when Thumb-32 instructions are not available, as long
5916 as the first two are identical. For instance, both "sbc r0,r1" and
5917 "sbc r0,r0,r1" are allowed. */
b99bd4ef 5918static void
c19d1205 5919do_t_arit3 (void)
b99bd4ef 5920{
c19d1205 5921 int Rd, Rs, Rn;
b99bd4ef 5922
c19d1205
ZW
5923 Rd = inst.operands[0].reg;
5924 Rs = (inst.operands[1].present
5925 ? inst.operands[1].reg /* Rd, Rs, foo */
5926 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5927 Rn = inst.operands[2].reg;
b99bd4ef 5928
c19d1205 5929 if (unified_syntax)
b99bd4ef 5930 {
c19d1205
ZW
5931 if (!inst.operands[2].isreg)
5932 {
5933 /* For an immediate, we always generate a 32-bit opcode;
5934 section relaxation will shrink it later if possible. */
5935 inst.instruction = THUMB_OP32 (inst.instruction);
5936 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5937 inst.instruction |= Rd << 8;
5938 inst.instruction |= Rs << 16;
5939 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
5940 }
5941 else
5942 {
5943 /* See if we can do this with a 16-bit instruction. */
5944 if (THUMB_SETS_FLAGS (inst.instruction)
5945 && !inst.operands[2].shifted
5946 && inst.size_req != 4
5947 && Rd == Rs)
5948 {
5949 inst.instruction = THUMB_OP16 (inst.instruction);
5950 inst.instruction |= Rd;
5951 inst.instruction |= Rn << 3;
5952 return;
5953 }
b99bd4ef 5954
c19d1205
ZW
5955 /* If we get here, it can't be done in 16 bits. */
5956 constraint (inst.operands[2].shifted
5957 && inst.operands[2].immisreg,
5958 _("shift must be constant"));
5959 inst.instruction = THUMB_OP32 (inst.instruction);
5960 inst.instruction |= Rd << 8;
5961 inst.instruction |= Rs << 16;
5962 encode_thumb32_shifted_operand (2);
5963 }
a737bd4d 5964 }
c19d1205 5965 else
b99bd4ef 5966 {
c19d1205
ZW
5967 /* On its face this is a lie - the instruction does set the
5968 flags. However, the only supported mnemonic in this mode
5969 says it doesn't. */
5970 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 5971
c19d1205
ZW
5972 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
5973 _("unshifted register required"));
5974 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
5975 constraint (Rd != Rs,
5976 _("dest and source1 must be the same register"));
a737bd4d 5977
c19d1205
ZW
5978 inst.instruction = THUMB_OP16 (inst.instruction);
5979 inst.instruction |= Rd;
5980 inst.instruction |= Rn << 3;
b99bd4ef 5981 }
a737bd4d 5982}
b99bd4ef 5983
c19d1205
ZW
5984/* Similarly, but for instructions where the arithmetic operation is
5985 commutative, so we can allow either of them to be different from
5986 the destination operand in a 16-bit instruction. For instance, all
5987 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
5988 accepted. */
5989static void
5990do_t_arit3c (void)
a737bd4d 5991{
c19d1205 5992 int Rd, Rs, Rn;
b99bd4ef 5993
c19d1205
ZW
5994 Rd = inst.operands[0].reg;
5995 Rs = (inst.operands[1].present
5996 ? inst.operands[1].reg /* Rd, Rs, foo */
5997 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5998 Rn = inst.operands[2].reg;
a737bd4d 5999
c19d1205 6000 if (unified_syntax)
a737bd4d 6001 {
c19d1205 6002 if (!inst.operands[2].isreg)
b99bd4ef 6003 {
c19d1205
ZW
6004 /* For an immediate, we always generate a 32-bit opcode;
6005 section relaxation will shrink it later if possible. */
6006 inst.instruction = THUMB_OP32 (inst.instruction);
6007 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6008 inst.instruction |= Rd << 8;
6009 inst.instruction |= Rs << 16;
6010 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6011 }
c19d1205 6012 else
a737bd4d 6013 {
c19d1205
ZW
6014 /* See if we can do this with a 16-bit instruction. */
6015 if (THUMB_SETS_FLAGS (inst.instruction)
6016 && !inst.operands[2].shifted
6017 && inst.size_req != 4)
a737bd4d 6018 {
c19d1205 6019 if (Rd == Rs)
a737bd4d 6020 {
c19d1205
ZW
6021 inst.instruction = THUMB_OP16 (inst.instruction);
6022 inst.instruction |= Rd;
6023 inst.instruction |= Rn << 3;
6024 return;
a737bd4d 6025 }
c19d1205 6026 if (Rd == Rn)
a737bd4d 6027 {
c19d1205
ZW
6028 inst.instruction = THUMB_OP16 (inst.instruction);
6029 inst.instruction |= Rd;
6030 inst.instruction |= Rs << 3;
6031 return;
a737bd4d
NC
6032 }
6033 }
c19d1205
ZW
6034
6035 /* If we get here, it can't be done in 16 bits. */
6036 constraint (inst.operands[2].shifted
6037 && inst.operands[2].immisreg,
6038 _("shift must be constant"));
6039 inst.instruction = THUMB_OP32 (inst.instruction);
6040 inst.instruction |= Rd << 8;
6041 inst.instruction |= Rs << 16;
6042 encode_thumb32_shifted_operand (2);
a737bd4d 6043 }
b99bd4ef 6044 }
c19d1205
ZW
6045 else
6046 {
6047 /* On its face this is a lie - the instruction does set the
6048 flags. However, the only supported mnemonic in this mode
6049 says it doesn't. */
6050 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6051
c19d1205
ZW
6052 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6053 _("unshifted register required"));
6054 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6055
6056 inst.instruction = THUMB_OP16 (inst.instruction);
6057 inst.instruction |= Rd;
6058
6059 if (Rd == Rs)
6060 inst.instruction |= Rn << 3;
6061 else if (Rd == Rn)
6062 inst.instruction |= Rs << 3;
6063 else
6064 constraint (1, _("dest must overlap one source register"));
6065 }
a737bd4d
NC
6066}
6067
c19d1205
ZW
6068static void
6069do_t_bfc (void)
a737bd4d 6070{
c19d1205
ZW
6071 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6072 constraint (msb > 32, _("bit-field extends past end of register"));
6073 /* The instruction encoding stores the LSB and MSB,
6074 not the LSB and width. */
6075 inst.instruction |= inst.operands[0].reg << 8;
6076 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6077 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6078 inst.instruction |= msb - 1;
b99bd4ef
NC
6079}
6080
c19d1205
ZW
6081static void
6082do_t_bfi (void)
b99bd4ef 6083{
c19d1205 6084 unsigned int msb;
b99bd4ef 6085
c19d1205
ZW
6086 /* #0 in second position is alternative syntax for bfc, which is
6087 the same instruction but with REG_PC in the Rm field. */
6088 if (!inst.operands[1].isreg)
6089 inst.operands[1].reg = REG_PC;
b99bd4ef 6090
c19d1205
ZW
6091 msb = inst.operands[2].imm + inst.operands[3].imm;
6092 constraint (msb > 32, _("bit-field extends past end of register"));
6093 /* The instruction encoding stores the LSB and MSB,
6094 not the LSB and width. */
6095 inst.instruction |= inst.operands[0].reg << 8;
6096 inst.instruction |= inst.operands[1].reg << 16;
6097 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6098 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6099 inst.instruction |= msb - 1;
b99bd4ef
NC
6100}
6101
c19d1205
ZW
6102static void
6103do_t_bfx (void)
b99bd4ef 6104{
c19d1205
ZW
6105 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6106 _("bit-field extends past end of register"));
6107 inst.instruction |= inst.operands[0].reg << 8;
6108 inst.instruction |= inst.operands[1].reg << 16;
6109 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6110 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6111 inst.instruction |= inst.operands[3].imm - 1;
6112}
b99bd4ef 6113
c19d1205
ZW
6114/* ARM V5 Thumb BLX (argument parse)
6115 BLX <target_addr> which is BLX(1)
6116 BLX <Rm> which is BLX(2)
6117 Unfortunately, there are two different opcodes for this mnemonic.
6118 So, the insns[].value is not used, and the code here zaps values
6119 into inst.instruction.
b99bd4ef 6120
c19d1205
ZW
6121 ??? How to take advantage of the additional two bits of displacement
6122 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6123
c19d1205
ZW
6124static void
6125do_t_blx (void)
6126{
6127 if (inst.operands[0].isreg)
6128 /* We have a register, so this is BLX(2). */
6129 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6130 else
6131 {
c19d1205
ZW
6132 /* No register. This must be BLX(1). */
6133 inst.instruction = 0xf7ffeffe;
6134 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6135 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6136 }
6137}
6138
c19d1205
ZW
6139static void
6140do_t_branch (void)
b99bd4ef 6141{
c19d1205
ZW
6142 if (unified_syntax && inst.size_req != 2)
6143 {
6144 if (inst.cond == COND_ALWAYS)
6145 {
6146 inst.instruction = 0xf7ffbffe;
6147 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6148 }
6149 else
6150 {
6151 assert (inst.cond != 0xF);
6152 inst.instruction = (inst.cond << 22) | 0xf43faffe;
6153 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6154 }
6155 }
b99bd4ef
NC
6156 else
6157 {
c19d1205
ZW
6158 if (inst.cond == COND_ALWAYS)
6159 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6160 else
b99bd4ef 6161 {
c19d1205
ZW
6162 inst.instruction = 0xd0fe | (inst.cond << 8);
6163 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6164 }
b99bd4ef 6165 }
c19d1205
ZW
6166
6167 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6168}
6169
6170static void
c19d1205 6171do_t_bkpt (void)
b99bd4ef 6172{
c19d1205 6173 if (inst.operands[0].present)
b99bd4ef 6174 {
c19d1205
ZW
6175 constraint (inst.operands[0].imm > 255,
6176 _("immediate value out of range"));
6177 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6178 }
b99bd4ef
NC
6179}
6180
6181static void
c19d1205 6182do_t_branch23 (void)
b99bd4ef 6183{
c19d1205 6184 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6185 inst.reloc.pc_rel = 1;
6186
c19d1205
ZW
6187 /* If the destination of the branch is a defined symbol which does not have
6188 the THUMB_FUNC attribute, then we must be calling a function which has
6189 the (interfacearm) attribute. We look for the Thumb entry point to that
6190 function and change the branch to refer to that function instead. */
6191 if ( inst.reloc.exp.X_op == O_symbol
6192 && inst.reloc.exp.X_add_symbol != NULL
6193 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6194 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6195 inst.reloc.exp.X_add_symbol =
6196 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6197}
6198
6199static void
c19d1205 6200do_t_bx (void)
90e4755a 6201{
c19d1205
ZW
6202 inst.instruction |= inst.operands[0].reg << 3;
6203 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6204 should cause the alignment to be checked once it is known. This is
6205 because BX PC only works if the instruction is word aligned. */
6206}
90e4755a 6207
c19d1205
ZW
6208static void
6209do_t_bxj (void)
6210{
6211 if (inst.operands[0].reg == REG_PC)
6212 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6213
c19d1205 6214 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6215}
6216
6217static void
c19d1205 6218do_t_clz (void)
90e4755a 6219{
c19d1205
ZW
6220 inst.instruction |= inst.operands[0].reg << 8;
6221 inst.instruction |= inst.operands[1].reg << 16;
6222 inst.instruction |= inst.operands[1].reg;
6223}
90e4755a 6224
c19d1205
ZW
6225static void
6226do_t_cpsi (void)
6227{
6228 if (unified_syntax
6229 && (inst.operands[1].present || inst.size_req == 4))
90e4755a 6230 {
c19d1205
ZW
6231 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6232 inst.instruction = 0xf3af8000;
6233 inst.instruction |= imod << 9;
6234 inst.instruction |= inst.operands[0].imm << 5;
6235 if (inst.operands[1].present)
6236 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6237 }
c19d1205 6238 else
90e4755a 6239 {
c19d1205
ZW
6240 constraint (inst.operands[1].present,
6241 _("Thumb does not support the 2-argument "
6242 "form of this instruction"));
6243 inst.instruction |= inst.operands[0].imm;
90e4755a 6244 }
90e4755a
RE
6245}
6246
c19d1205
ZW
6247/* THUMB CPY instruction (argument parse). */
6248
90e4755a 6249static void
c19d1205 6250do_t_cpy (void)
90e4755a 6251{
c19d1205 6252 if (inst.size_req == 4)
90e4755a 6253 {
c19d1205
ZW
6254 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6255 inst.instruction |= inst.operands[0].reg << 8;
6256 inst.instruction |= inst.operands[1].reg;
90e4755a 6257 }
c19d1205 6258 else
90e4755a 6259 {
c19d1205
ZW
6260 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6261 inst.instruction |= (inst.operands[0].reg & 0x7);
6262 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6263 }
90e4755a
RE
6264}
6265
90e4755a 6266static void
c19d1205 6267do_t_czb (void)
90e4755a 6268{
c19d1205
ZW
6269 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6270 inst.instruction |= inst.operands[0].reg;
6271 inst.reloc.pc_rel = 1;
6272 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6273}
90e4755a 6274
c19d1205
ZW
6275static void
6276do_t_hint (void)
6277{
6278 if (unified_syntax && inst.size_req == 4)
6279 inst.instruction = THUMB_OP32 (inst.instruction);
6280 else
6281 inst.instruction = THUMB_OP16 (inst.instruction);
6282}
90e4755a 6283
c19d1205
ZW
6284static void
6285do_t_it (void)
6286{
6287 unsigned int cond = inst.operands[0].imm;
6288 if ((cond & 0x1) == 0x0)
90e4755a 6289 {
c19d1205
ZW
6290 unsigned int mask = inst.instruction & 0x000f;
6291 inst.instruction &= 0xfff0;
90e4755a 6292
c19d1205
ZW
6293 if ((mask & 0x7) == 0)
6294 /* no conversion needed */;
6295 else if ((mask & 0x3) == 0)
6296 mask = (~(mask & 0x8) & 0x8) | 0x4;
6297 else if ((mask & 1) == 0)
6298 mask = (~(mask & 0xC) & 0xC) | 0x2;
6299 else
6300 mask = (~(mask & 0xE) & 0xE) | 0x1;
90e4755a 6301
c19d1205
ZW
6302 inst.instruction |= (mask & 0xF);
6303 }
90e4755a 6304
c19d1205
ZW
6305 inst.instruction |= cond << 4;
6306}
90e4755a 6307
c19d1205
ZW
6308static void
6309do_t_ldmstm (void)
6310{
6311 /* This really doesn't seem worth it. */
6312 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6313 _("expression too complex"));
6314 constraint (inst.operands[1].writeback,
6315 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6316
c19d1205
ZW
6317 if (unified_syntax)
6318 {
6319 /* See if we can use a 16-bit instruction. */
6320 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6321 && inst.size_req != 4
6322 && inst.operands[0].reg <= 7
6323 && !(inst.operands[1].imm & ~0xff)
6324 && (inst.instruction == T_MNEM_stmia
6325 ? inst.operands[0].writeback
6326 : (inst.operands[0].writeback
6327 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6328 {
c19d1205
ZW
6329 if (inst.instruction == T_MNEM_stmia
6330 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6331 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6332 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6333 inst.operands[0].reg);
90e4755a 6334
c19d1205
ZW
6335 inst.instruction = THUMB_OP16 (inst.instruction);
6336 inst.instruction |= inst.operands[0].reg << 8;
6337 inst.instruction |= inst.operands[1].imm;
6338 }
6339 else
6340 {
6341 if (inst.operands[1].imm & (1 << 13))
6342 as_warn (_("SP should not be in register list"));
6343 if (inst.instruction == T_MNEM_stmia)
90e4755a 6344 {
c19d1205
ZW
6345 if (inst.operands[1].imm & (1 << 15))
6346 as_warn (_("PC should not be in register list"));
6347 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6348 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6349 inst.operands[0].reg);
90e4755a
RE
6350 }
6351 else
6352 {
c19d1205
ZW
6353 if (inst.operands[1].imm & (1 << 14)
6354 && inst.operands[1].imm & (1 << 15))
6355 as_warn (_("LR and PC should not both be in register list"));
6356 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6357 && inst.operands[0].writeback)
6358 as_warn (_("base register should not be in register list "
6359 "when written back"));
90e4755a 6360 }
c19d1205
ZW
6361 if (inst.instruction < 0xffff)
6362 inst.instruction = THUMB_OP32 (inst.instruction);
6363 inst.instruction |= inst.operands[0].reg << 16;
6364 inst.instruction |= inst.operands[1].imm;
6365 if (inst.operands[0].writeback)
6366 inst.instruction |= WRITE_BACK;
90e4755a
RE
6367 }
6368 }
c19d1205 6369 else
90e4755a 6370 {
c19d1205
ZW
6371 constraint (inst.operands[0].reg > 7
6372 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6373 if (inst.instruction == T_MNEM_stmia)
f03698e6 6374 {
c19d1205
ZW
6375 if (!inst.operands[0].writeback)
6376 as_warn (_("this instruction will write back the base register"));
6377 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6378 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6379 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6380 inst.operands[0].reg);
f03698e6 6381 }
c19d1205 6382 else
90e4755a 6383 {
c19d1205
ZW
6384 if (!inst.operands[0].writeback
6385 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6386 as_warn (_("this instruction will write back the base register"));
6387 else if (inst.operands[0].writeback
6388 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6389 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6390 }
6391
c19d1205
ZW
6392 inst.instruction = THUMB_OP16 (inst.instruction);
6393 inst.instruction |= inst.operands[0].reg << 8;
6394 inst.instruction |= inst.operands[1].imm;
6395 }
6396}
e28cd48c 6397
c19d1205
ZW
6398static void
6399do_t_ldrex (void)
6400{
6401 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6402 || inst.operands[1].postind || inst.operands[1].writeback
6403 || inst.operands[1].immisreg || inst.operands[1].shifted
6404 || inst.operands[1].negative,
6405 _("instruction does not accept this addressing mode"));
e28cd48c 6406
c19d1205
ZW
6407 inst.instruction |= inst.operands[0].reg << 12;
6408 inst.instruction |= inst.operands[1].reg << 16;
6409 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6410}
e28cd48c 6411
c19d1205
ZW
6412static void
6413do_t_ldrexd (void)
6414{
6415 if (!inst.operands[1].present)
1cac9012 6416 {
c19d1205
ZW
6417 constraint (inst.operands[0].reg == REG_LR,
6418 _("r14 not allowed as first register "
6419 "when second register is omitted"));
6420 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6421 }
c19d1205
ZW
6422 constraint (inst.operands[0].reg == inst.operands[1].reg,
6423 BAD_OVERLAP);
b99bd4ef 6424
c19d1205
ZW
6425 inst.instruction |= inst.operands[0].reg << 12;
6426 inst.instruction |= inst.operands[1].reg << 8;
6427 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6428}
6429
6430static void
c19d1205 6431do_t_ldst (void)
b99bd4ef 6432{
c19d1205 6433 if (unified_syntax)
b99bd4ef 6434 {
c19d1205
ZW
6435 /* Generation of 16-bit instructions for anything other than
6436 Rd, [Rn, Ri] is deferred to section relaxation time. */
6437 if (inst.operands[1].isreg && inst.operands[1].immisreg
6438 && !inst.operands[1].shifted && !inst.operands[1].postind
6439 && !inst.operands[1].negative && inst.operands[0].reg <= 7
6440 && inst.operands[1].reg <= 7 && inst.operands[1].imm <= 7
6441 && inst.instruction <= 0xffff)
6442 {
6443 inst.instruction = THUMB_OP16 (inst.instruction);
6444 goto op16;
6445 }
6446
6447 inst.instruction = THUMB_OP32 (inst.instruction);
6448 inst.instruction |= inst.operands[0].reg << 12;
6449 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
6450 return;
6451 }
6452
c19d1205
ZW
6453 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6454
6455 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 6456 {
c19d1205
ZW
6457 /* Only [Rn,Rm] is acceptable. */
6458 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6459 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6460 || inst.operands[1].postind || inst.operands[1].shifted
6461 || inst.operands[1].negative,
6462 _("Thumb does not support this addressing mode"));
6463 inst.instruction = THUMB_OP16 (inst.instruction);
6464 goto op16;
b99bd4ef 6465 }
c19d1205
ZW
6466
6467 inst.instruction = THUMB_OP16 (inst.instruction);
6468 if (!inst.operands[1].isreg)
6469 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6470 return;
b99bd4ef 6471
c19d1205
ZW
6472 constraint (!inst.operands[1].preind
6473 || inst.operands[1].shifted
6474 || inst.operands[1].writeback,
6475 _("Thumb does not support this addressing mode"));
6476 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 6477 {
c19d1205
ZW
6478 constraint (inst.instruction & 0x0600,
6479 _("byte or halfword not valid for base register"));
6480 constraint (inst.operands[1].reg == REG_PC
6481 && !(inst.instruction & THUMB_LOAD_BIT),
6482 _("r15 based store not allowed"));
6483 constraint (inst.operands[1].immisreg,
6484 _("invalid base register for register offset"));
b99bd4ef 6485
c19d1205
ZW
6486 if (inst.operands[1].reg == REG_PC)
6487 inst.instruction = T_OPCODE_LDR_PC;
6488 else if (inst.instruction & THUMB_LOAD_BIT)
6489 inst.instruction = T_OPCODE_LDR_SP;
6490 else
6491 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 6492
c19d1205
ZW
6493 inst.instruction |= inst.operands[0].reg << 8;
6494 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6495 return;
6496 }
90e4755a 6497
c19d1205
ZW
6498 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6499 if (!inst.operands[1].immisreg)
6500 {
6501 /* Immediate offset. */
6502 inst.instruction |= inst.operands[0].reg;
6503 inst.instruction |= inst.operands[1].reg << 3;
6504 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6505 return;
6506 }
90e4755a 6507
c19d1205
ZW
6508 /* Register offset. */
6509 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6510 constraint (inst.operands[1].negative,
6511 _("Thumb does not support this addressing mode"));
90e4755a 6512
c19d1205
ZW
6513 op16:
6514 switch (inst.instruction)
6515 {
6516 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6517 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6518 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6519 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6520 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6521 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6522 case 0x5600 /* ldrsb */:
6523 case 0x5e00 /* ldrsh */: break;
6524 default: abort ();
6525 }
90e4755a 6526
c19d1205
ZW
6527 inst.instruction |= inst.operands[0].reg;
6528 inst.instruction |= inst.operands[1].reg << 3;
6529 inst.instruction |= inst.operands[1].imm << 6;
6530}
90e4755a 6531
c19d1205
ZW
6532static void
6533do_t_ldstd (void)
6534{
6535 if (!inst.operands[1].present)
b99bd4ef 6536 {
c19d1205
ZW
6537 inst.operands[1].reg = inst.operands[0].reg + 1;
6538 constraint (inst.operands[0].reg == REG_LR,
6539 _("r14 not allowed here"));
b99bd4ef 6540 }
c19d1205
ZW
6541 inst.instruction |= inst.operands[0].reg << 12;
6542 inst.instruction |= inst.operands[1].reg << 8;
6543 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6544
b99bd4ef
NC
6545}
6546
c19d1205
ZW
6547static void
6548do_t_ldstt (void)
6549{
6550 inst.instruction |= inst.operands[0].reg << 12;
6551 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6552}
a737bd4d 6553
b99bd4ef 6554static void
c19d1205 6555do_t_mla (void)
b99bd4ef 6556{
c19d1205
ZW
6557 inst.instruction |= inst.operands[0].reg << 8;
6558 inst.instruction |= inst.operands[1].reg << 16;
6559 inst.instruction |= inst.operands[2].reg;
6560 inst.instruction |= inst.operands[3].reg << 12;
6561}
b99bd4ef 6562
c19d1205
ZW
6563static void
6564do_t_mlal (void)
6565{
6566 inst.instruction |= inst.operands[0].reg << 12;
6567 inst.instruction |= inst.operands[1].reg << 8;
6568 inst.instruction |= inst.operands[2].reg << 16;
6569 inst.instruction |= inst.operands[3].reg;
6570}
b99bd4ef 6571
c19d1205
ZW
6572static void
6573do_t_mov_cmp (void)
6574{
6575 if (unified_syntax)
b99bd4ef 6576 {
c19d1205
ZW
6577 int r0off = (inst.instruction == T_MNEM_mov
6578 || inst.instruction == T_MNEM_movs) ? 8 : 16;
6579 if (!inst.operands[1].isreg)
6580 {
6581 /* For an immediate, we always generate a 32-bit opcode;
6582 section relaxation will shrink it later if possible. */
6583 inst.instruction = THUMB_OP32 (inst.instruction);
6584 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6585 inst.instruction |= inst.operands[0].reg << r0off;
6586 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6587 }
6588 else if (inst.size_req == 4
6589 || inst.operands[1].shifted
6590 || (inst.instruction == T_MNEM_movs
6591 && (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)))
6592 {
6593 inst.instruction = THUMB_OP32 (inst.instruction);
6594 inst.instruction |= inst.operands[0].reg << r0off;
6595 encode_thumb32_shifted_operand (1);
6596 }
6597 else
6598 switch (inst.instruction)
6599 {
6600 case T_MNEM_mov:
6601 inst.instruction = T_OPCODE_MOV_HR;
6602 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6603 inst.instruction |= (inst.operands[0].reg & 0x7);
6604 inst.instruction |= inst.operands[1].reg << 3;
6605 break;
b99bd4ef 6606
c19d1205
ZW
6607 case T_MNEM_movs:
6608 /* We know we have low registers at this point.
6609 Generate ADD Rd, Rs, #0. */
6610 inst.instruction = T_OPCODE_ADD_I3;
6611 inst.instruction |= inst.operands[0].reg;
6612 inst.instruction |= inst.operands[1].reg << 3;
6613 break;
6614
6615 case T_MNEM_cmp:
6616 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7)
6617 {
6618 inst.instruction = T_OPCODE_CMP_LR;
6619 inst.instruction |= inst.operands[0].reg;
6620 inst.instruction |= inst.operands[1].reg << 3;
6621 }
6622 else
6623 {
6624 inst.instruction = T_OPCODE_CMP_HR;
6625 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6626 inst.instruction |= (inst.operands[0].reg & 0x7);
6627 inst.instruction |= inst.operands[1].reg << 3;
6628 }
6629 break;
6630 }
b99bd4ef
NC
6631 return;
6632 }
6633
c19d1205
ZW
6634 inst.instruction = THUMB_OP16 (inst.instruction);
6635 if (inst.operands[1].isreg)
b99bd4ef 6636 {
c19d1205 6637 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 6638 {
c19d1205
ZW
6639 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
6640 since a MOV instruction produces unpredictable results. */
6641 if (inst.instruction == T_OPCODE_MOV_I8)
6642 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 6643 else
c19d1205 6644 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 6645
c19d1205
ZW
6646 inst.instruction |= inst.operands[0].reg;
6647 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
6648 }
6649 else
6650 {
c19d1205
ZW
6651 if (inst.instruction == T_OPCODE_MOV_I8)
6652 inst.instruction = T_OPCODE_MOV_HR;
6653 else
6654 inst.instruction = T_OPCODE_CMP_HR;
6655 do_t_cpy ();
b99bd4ef
NC
6656 }
6657 }
c19d1205 6658 else
b99bd4ef 6659 {
c19d1205
ZW
6660 constraint (inst.operands[0].reg > 7,
6661 _("only lo regs allowed with immediate"));
6662 inst.instruction |= inst.operands[0].reg << 8;
6663 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6664 }
6665}
b99bd4ef 6666
c19d1205
ZW
6667static void
6668do_t_mov16 (void)
6669{
6670 inst.instruction |= inst.operands[0].reg << 8;
6671 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
6672 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
6673 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
6674 inst.instruction |= (inst.operands[1].imm & 0x00ff);
6675}
b99bd4ef 6676
c19d1205
ZW
6677static void
6678do_t_mvn_tst (void)
6679{
6680 if (unified_syntax)
6681 {
6682 int r0off = (inst.instruction == T_MNEM_mvn
6683 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
6684 if (!inst.operands[1].isreg)
b99bd4ef 6685 {
c19d1205
ZW
6686 /* For an immediate, we always generate a 32-bit opcode;
6687 section relaxation will shrink it later if possible. */
6688 if (inst.instruction < 0xffff)
6689 inst.instruction = THUMB_OP32 (inst.instruction);
6690 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6691 inst.instruction |= inst.operands[0].reg << r0off;
6692 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6693 }
c19d1205 6694 else
b99bd4ef 6695 {
c19d1205
ZW
6696 /* See if we can do this with a 16-bit instruction. */
6697 if (inst.instruction < 0xffff
6698 && THUMB_SETS_FLAGS (inst.instruction)
6699 && !inst.operands[1].shifted
6700 && inst.operands[0].reg <= 7
6701 && inst.operands[1].reg <= 7
6702 && inst.size_req != 4)
b99bd4ef 6703 {
c19d1205
ZW
6704 inst.instruction = THUMB_OP16 (inst.instruction);
6705 inst.instruction |= inst.operands[0].reg;
6706 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6707 }
c19d1205 6708 else
b99bd4ef 6709 {
c19d1205
ZW
6710 constraint (inst.operands[1].shifted
6711 && inst.operands[1].immisreg,
6712 _("shift must be constant"));
6713 if (inst.instruction < 0xffff)
6714 inst.instruction = THUMB_OP32 (inst.instruction);
6715 inst.instruction |= inst.operands[0].reg << r0off;
6716 encode_thumb32_shifted_operand (1);
b99bd4ef 6717 }
b99bd4ef
NC
6718 }
6719 }
6720 else
6721 {
c19d1205
ZW
6722 constraint (inst.instruction > 0xffff
6723 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
6724 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
6725 _("unshifted register required"));
6726 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6727 BAD_HIREG);
b99bd4ef 6728
c19d1205
ZW
6729 inst.instruction = THUMB_OP16 (inst.instruction);
6730 inst.instruction |= inst.operands[0].reg;
6731 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6732 }
b99bd4ef
NC
6733}
6734
b05fe5cf 6735static void
c19d1205 6736do_t_mrs (void)
b05fe5cf 6737{
c19d1205
ZW
6738 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
6739 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
6740 != (PSR_c|PSR_f),
6741 _("'CPSR' or 'SPSR' expected"));
6742 inst.instruction |= inst.operands[0].reg << 8;
6743 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
6744}
b05fe5cf 6745
c19d1205
ZW
6746static void
6747do_t_msr (void)
6748{
6749 constraint (!inst.operands[1].isreg,
6750 _("Thumb encoding does not support an immediate here"));
6751 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
6752 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
6753 inst.instruction |= inst.operands[1].reg << 16;
6754}
b05fe5cf 6755
c19d1205
ZW
6756static void
6757do_t_mul (void)
6758{
6759 if (!inst.operands[2].present)
6760 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 6761
c19d1205
ZW
6762 /* There is no 32-bit MULS and no 16-bit MUL. */
6763 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 6764 {
c19d1205
ZW
6765 inst.instruction = THUMB_OP32 (inst.instruction);
6766 inst.instruction |= inst.operands[0].reg << 8;
6767 inst.instruction |= inst.operands[1].reg << 16;
6768 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 6769 }
c19d1205 6770 else
b05fe5cf 6771 {
c19d1205
ZW
6772 constraint (!unified_syntax
6773 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
6774 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6775 BAD_HIREG);
b05fe5cf 6776
c19d1205
ZW
6777 inst.instruction = THUMB_OP16 (inst.instruction);
6778 inst.instruction |= inst.operands[0].reg;
b05fe5cf 6779
c19d1205
ZW
6780 if (inst.operands[0].reg == inst.operands[1].reg)
6781 inst.instruction |= inst.operands[2].reg << 3;
6782 else if (inst.operands[0].reg == inst.operands[2].reg)
6783 inst.instruction |= inst.operands[1].reg << 3;
6784 else
6785 constraint (1, _("dest must overlap one source register"));
6786 }
6787}
b05fe5cf 6788
c19d1205
ZW
6789static void
6790do_t_mull (void)
6791{
6792 inst.instruction |= inst.operands[0].reg << 12;
6793 inst.instruction |= inst.operands[1].reg << 8;
6794 inst.instruction |= inst.operands[2].reg << 16;
6795 inst.instruction |= inst.operands[3].reg;
b05fe5cf 6796
c19d1205
ZW
6797 if (inst.operands[0].reg == inst.operands[1].reg)
6798 as_tsktsk (_("rdhi and rdlo must be different"));
6799}
b05fe5cf 6800
c19d1205
ZW
6801static void
6802do_t_nop (void)
6803{
6804 if (unified_syntax)
6805 {
6806 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 6807 {
c19d1205
ZW
6808 inst.instruction = THUMB_OP32 (inst.instruction);
6809 inst.instruction |= inst.operands[0].imm;
6810 }
6811 else
6812 {
6813 inst.instruction = THUMB_OP16 (inst.instruction);
6814 inst.instruction |= inst.operands[0].imm << 4;
6815 }
6816 }
6817 else
6818 {
6819 constraint (inst.operands[0].present,
6820 _("Thumb does not support NOP with hints"));
6821 inst.instruction = 0x46c0;
6822 }
6823}
b05fe5cf 6824
c19d1205
ZW
6825static void
6826do_t_neg (void)
6827{
6828 if (unified_syntax)
6829 {
6830 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7
6831 || !THUMB_SETS_FLAGS (inst.instruction)
6832 || inst.size_req == 4)
6833 {
6834 inst.instruction = THUMB_OP32 (inst.instruction);
6835 inst.instruction |= inst.operands[0].reg << 8;
6836 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
6837 }
6838 else
6839 {
c19d1205
ZW
6840 inst.instruction = THUMB_OP16 (inst.instruction);
6841 inst.instruction |= inst.operands[0].reg;
6842 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
6843 }
6844 }
6845 else
6846 {
c19d1205
ZW
6847 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6848 BAD_HIREG);
6849 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6850
6851 inst.instruction = THUMB_OP16 (inst.instruction);
6852 inst.instruction |= inst.operands[0].reg;
6853 inst.instruction |= inst.operands[1].reg << 3;
6854 }
6855}
6856
6857static void
6858do_t_pkhbt (void)
6859{
6860 inst.instruction |= inst.operands[0].reg << 8;
6861 inst.instruction |= inst.operands[1].reg << 16;
6862 inst.instruction |= inst.operands[2].reg;
6863 if (inst.operands[3].present)
6864 {
6865 unsigned int val = inst.reloc.exp.X_add_number;
6866 constraint (inst.reloc.exp.X_op != O_constant,
6867 _("expression too complex"));
6868 inst.instruction |= (val & 0x1c) << 10;
6869 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 6870 }
c19d1205 6871}
b05fe5cf 6872
c19d1205
ZW
6873static void
6874do_t_pkhtb (void)
6875{
6876 if (!inst.operands[3].present)
6877 inst.instruction &= ~0x00000020;
6878 do_t_pkhbt ();
b05fe5cf
ZW
6879}
6880
c19d1205
ZW
6881static void
6882do_t_pld (void)
6883{
6884 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
6885}
b05fe5cf 6886
c19d1205
ZW
6887static void
6888do_t_push_pop (void)
b99bd4ef 6889{
c19d1205
ZW
6890 constraint (inst.operands[0].writeback,
6891 _("push/pop do not support {reglist}^"));
6892 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6893 _("expression too complex"));
b99bd4ef 6894
c19d1205
ZW
6895 if ((inst.operands[0].imm & ~0xff) == 0)
6896 inst.instruction = THUMB_OP16 (inst.instruction);
6897 else if ((inst.instruction == T_MNEM_push
6898 && (inst.operands[0].imm & ~0xff) == 1 << REG_LR)
6899 || (inst.instruction == T_MNEM_pop
6900 && (inst.operands[0].imm & ~0xff) == 1 << REG_PC))
b99bd4ef 6901 {
c19d1205
ZW
6902 inst.instruction = THUMB_OP16 (inst.instruction);
6903 inst.instruction |= THUMB_PP_PC_LR;
6904 inst.operands[0].imm &= 0xff;
6905 }
6906 else if (unified_syntax)
6907 {
6908 if (inst.operands[1].imm & (1 << 13))
6909 as_warn (_("SP should not be in register list"));
6910 if (inst.instruction == T_MNEM_push)
b99bd4ef 6911 {
c19d1205
ZW
6912 if (inst.operands[1].imm & (1 << 15))
6913 as_warn (_("PC should not be in register list"));
6914 }
6915 else
6916 {
6917 if (inst.operands[1].imm & (1 << 14)
6918 && inst.operands[1].imm & (1 << 15))
6919 as_warn (_("LR and PC should not both be in register list"));
6920 }
b99bd4ef 6921
c19d1205
ZW
6922 inst.instruction = THUMB_OP32 (inst.instruction);
6923 }
6924 else
6925 {
6926 inst.error = _("invalid register list to push/pop instruction");
6927 return;
6928 }
b99bd4ef 6929
c19d1205
ZW
6930 inst.instruction |= inst.operands[0].imm;
6931}
b99bd4ef 6932
c19d1205
ZW
6933static void
6934do_t_rbit (void)
6935{
6936 inst.instruction |= inst.operands[0].reg << 8;
6937 inst.instruction |= inst.operands[1].reg << 16;
6938}
b99bd4ef 6939
c19d1205
ZW
6940static void
6941do_t_rev (void)
6942{
6943 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
6944 && inst.size_req != 4)
6945 {
6946 inst.instruction = THUMB_OP16 (inst.instruction);
6947 inst.instruction |= inst.operands[0].reg;
6948 inst.instruction |= inst.operands[1].reg << 3;
6949 }
6950 else if (unified_syntax)
6951 {
6952 inst.instruction = THUMB_OP32 (inst.instruction);
6953 inst.instruction |= inst.operands[0].reg << 8;
6954 inst.instruction |= inst.operands[1].reg << 16;
6955 inst.instruction |= inst.operands[1].reg;
6956 }
6957 else
6958 inst.error = BAD_HIREG;
6959}
b99bd4ef 6960
c19d1205
ZW
6961static void
6962do_t_rsb (void)
6963{
6964 int Rd, Rs;
b99bd4ef 6965
c19d1205
ZW
6966 Rd = inst.operands[0].reg;
6967 Rs = (inst.operands[1].present
6968 ? inst.operands[1].reg /* Rd, Rs, foo */
6969 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 6970
c19d1205
ZW
6971 inst.instruction |= Rd << 8;
6972 inst.instruction |= Rs << 16;
6973 if (!inst.operands[2].isreg)
6974 {
6975 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6976 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6977 }
6978 else
6979 encode_thumb32_shifted_operand (2);
6980}
b99bd4ef 6981
c19d1205
ZW
6982static void
6983do_t_setend (void)
6984{
6985 if (inst.operands[0].imm)
6986 inst.instruction |= 0x8;
6987}
b99bd4ef 6988
c19d1205
ZW
6989static void
6990do_t_shift (void)
6991{
6992 if (!inst.operands[1].present)
6993 inst.operands[1].reg = inst.operands[0].reg;
6994
6995 if (unified_syntax)
6996 {
6997 if (inst.operands[0].reg > 7
6998 || inst.operands[1].reg > 7
6999 || !THUMB_SETS_FLAGS (inst.instruction)
7000 || (!inst.operands[2].isreg && inst.instruction == T_MNEM_rors)
7001 || (inst.operands[2].isreg && inst.operands[1].reg != inst.operands[0].reg)
7002 || inst.size_req == 4)
7003 {
7004 if (inst.operands[2].isreg)
b99bd4ef 7005 {
c19d1205
ZW
7006 inst.instruction = THUMB_OP32 (inst.instruction);
7007 inst.instruction |= inst.operands[0].reg << 8;
7008 inst.instruction |= inst.operands[1].reg << 16;
7009 inst.instruction |= inst.operands[2].reg;
7010 }
7011 else
7012 {
7013 inst.operands[1].shifted = 1;
7014 switch (inst.instruction)
7015 {
7016 case T_MNEM_asr:
7017 case T_MNEM_asrs: inst.operands[1].shift_kind = SHIFT_ASR; break;
7018 case T_MNEM_lsl:
7019 case T_MNEM_lsls: inst.operands[1].shift_kind = SHIFT_LSL; break;
7020 case T_MNEM_lsr:
7021 case T_MNEM_lsrs: inst.operands[1].shift_kind = SHIFT_LSR; break;
7022 case T_MNEM_ror:
7023 case T_MNEM_rors: inst.operands[1].shift_kind = SHIFT_ROR; break;
7024 default: abort ();
7025 }
7026
7027 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7028 ? T_MNEM_movs : T_MNEM_mov);
7029 inst.instruction |= inst.operands[0].reg << 8;
7030 encode_thumb32_shifted_operand (1);
7031 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7032 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7033 }
7034 }
7035 else
7036 {
c19d1205 7037 if (inst.operands[2].isreg)
b99bd4ef 7038 {
c19d1205 7039 switch (inst.instruction)
b99bd4ef 7040 {
c19d1205
ZW
7041 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_R; break;
7042 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_R; break;
7043 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_R; break;
7044 case T_MNEM_rors: inst.instruction = T_OPCODE_ROR_R; break;
7045 default: abort ();
b99bd4ef 7046 }
c19d1205
ZW
7047
7048 inst.instruction |= inst.operands[0].reg;
7049 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7050 }
7051 else
7052 {
c19d1205 7053 switch (inst.instruction)
b99bd4ef 7054 {
c19d1205
ZW
7055 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_I; break;
7056 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_I; break;
7057 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_I; break;
7058 default: abort ();
b99bd4ef 7059 }
c19d1205
ZW
7060 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7061 inst.instruction |= inst.operands[0].reg;
7062 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7063 }
7064 }
c19d1205
ZW
7065 }
7066 else
7067 {
7068 constraint (inst.operands[0].reg > 7
7069 || inst.operands[1].reg > 7, BAD_HIREG);
7070 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7071
c19d1205
ZW
7072 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7073 {
7074 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7075 constraint (inst.operands[0].reg != inst.operands[1].reg,
7076 _("source1 and dest must be same register"));
b99bd4ef 7077
c19d1205
ZW
7078 switch (inst.instruction)
7079 {
7080 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7081 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7082 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7083 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7084 default: abort ();
7085 }
7086
7087 inst.instruction |= inst.operands[0].reg;
7088 inst.instruction |= inst.operands[2].reg << 3;
7089 }
7090 else
b99bd4ef 7091 {
c19d1205
ZW
7092 switch (inst.instruction)
7093 {
7094 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7095 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7096 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7097 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7098 default: abort ();
7099 }
7100 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7101 inst.instruction |= inst.operands[0].reg;
7102 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7103 }
7104 }
b99bd4ef
NC
7105}
7106
7107static void
c19d1205 7108do_t_simd (void)
b99bd4ef 7109{
c19d1205
ZW
7110 inst.instruction |= inst.operands[0].reg << 8;
7111 inst.instruction |= inst.operands[1].reg << 16;
7112 inst.instruction |= inst.operands[2].reg;
7113}
b99bd4ef 7114
c19d1205
ZW
7115static void
7116do_t_smi (void)
7117{
7118 unsigned int value = inst.reloc.exp.X_add_number;
7119 constraint (inst.reloc.exp.X_op != O_constant,
7120 _("expression too complex"));
7121 inst.reloc.type = BFD_RELOC_UNUSED;
7122 inst.instruction |= (value & 0xf000) >> 12;
7123 inst.instruction |= (value & 0x0ff0);
7124 inst.instruction |= (value & 0x000f) << 16;
7125}
b99bd4ef 7126
c19d1205
ZW
7127static void
7128do_t_ssat (void)
7129{
7130 inst.instruction |= inst.operands[0].reg << 8;
7131 inst.instruction |= inst.operands[1].imm - 1;
7132 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7133
c19d1205 7134 if (inst.operands[3].present)
b99bd4ef 7135 {
c19d1205
ZW
7136 constraint (inst.reloc.exp.X_op != O_constant,
7137 _("expression too complex"));
b99bd4ef 7138
c19d1205 7139 if (inst.reloc.exp.X_add_number != 0)
6189168b 7140 {
c19d1205
ZW
7141 if (inst.operands[3].shift_kind == SHIFT_ASR)
7142 inst.instruction |= 0x00200000; /* sh bit */
7143 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7144 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7145 }
c19d1205 7146 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7147 }
b99bd4ef
NC
7148}
7149
0dd132b6 7150static void
c19d1205 7151do_t_ssat16 (void)
0dd132b6 7152{
c19d1205
ZW
7153 inst.instruction |= inst.operands[0].reg << 8;
7154 inst.instruction |= inst.operands[1].imm - 1;
7155 inst.instruction |= inst.operands[2].reg << 16;
7156}
0dd132b6 7157
c19d1205
ZW
7158static void
7159do_t_strex (void)
7160{
7161 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7162 || inst.operands[2].postind || inst.operands[2].writeback
7163 || inst.operands[2].immisreg || inst.operands[2].shifted
7164 || inst.operands[2].negative,
7165 _("instruction does not accept this addressing mode"));
0dd132b6 7166
c19d1205
ZW
7167 inst.instruction |= inst.operands[0].reg << 8;
7168 inst.instruction |= inst.operands[1].reg << 12;
7169 inst.instruction |= inst.operands[2].reg << 16;
7170 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7171}
7172
b99bd4ef 7173static void
c19d1205 7174do_t_strexd (void)
b99bd4ef 7175{
c19d1205
ZW
7176 if (!inst.operands[2].present)
7177 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7178
c19d1205
ZW
7179 constraint (inst.operands[0].reg == inst.operands[1].reg
7180 || inst.operands[0].reg == inst.operands[2].reg
7181 || inst.operands[0].reg == inst.operands[3].reg
7182 || inst.operands[1].reg == inst.operands[2].reg,
7183 BAD_OVERLAP);
b99bd4ef 7184
c19d1205
ZW
7185 inst.instruction |= inst.operands[0].reg;
7186 inst.instruction |= inst.operands[1].reg << 12;
7187 inst.instruction |= inst.operands[2].reg << 8;
7188 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7189}
7190
7191static void
c19d1205 7192do_t_sxtah (void)
b99bd4ef 7193{
c19d1205
ZW
7194 inst.instruction |= inst.operands[0].reg << 8;
7195 inst.instruction |= inst.operands[1].reg << 16;
7196 inst.instruction |= inst.operands[2].reg;
7197 inst.instruction |= inst.operands[3].imm << 4;
7198}
b99bd4ef 7199
c19d1205
ZW
7200static void
7201do_t_sxth (void)
7202{
7203 if (inst.instruction <= 0xffff && inst.size_req != 4
7204 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7205 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7206 {
c19d1205
ZW
7207 inst.instruction = THUMB_OP16 (inst.instruction);
7208 inst.instruction |= inst.operands[0].reg;
7209 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7210 }
c19d1205 7211 else if (unified_syntax)
b99bd4ef 7212 {
c19d1205
ZW
7213 if (inst.instruction <= 0xffff)
7214 inst.instruction = THUMB_OP32 (inst.instruction);
7215 inst.instruction |= inst.operands[0].reg << 8;
7216 inst.instruction |= inst.operands[1].reg;
7217 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7218 }
c19d1205 7219 else
b99bd4ef 7220 {
c19d1205
ZW
7221 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7222 _("Thumb encoding does not support rotation"));
7223 constraint (1, BAD_HIREG);
b99bd4ef 7224 }
c19d1205 7225}
b99bd4ef 7226
c19d1205
ZW
7227static void
7228do_t_swi (void)
7229{
7230 inst.reloc.type = BFD_RELOC_ARM_SWI;
7231}
b99bd4ef 7232
c19d1205
ZW
7233static void
7234do_t_usat (void)
7235{
7236 inst.instruction |= inst.operands[0].reg << 8;
7237 inst.instruction |= inst.operands[1].imm;
7238 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7239
c19d1205 7240 if (inst.operands[3].present)
b99bd4ef 7241 {
c19d1205
ZW
7242 constraint (inst.reloc.exp.X_op != O_constant,
7243 _("expression too complex"));
7244 if (inst.reloc.exp.X_add_number != 0)
7245 {
7246 if (inst.operands[3].shift_kind == SHIFT_ASR)
7247 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7248
c19d1205
ZW
7249 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7250 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7251 }
7252 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7253 }
b99bd4ef
NC
7254}
7255
7256static void
c19d1205 7257do_t_usat16 (void)
b99bd4ef 7258{
c19d1205
ZW
7259 inst.instruction |= inst.operands[0].reg << 8;
7260 inst.instruction |= inst.operands[1].imm;
7261 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7262}
c19d1205
ZW
7263\f
7264/* Overall per-instruction processing. */
7265
7266/* We need to be able to fix up arbitrary expressions in some statements.
7267 This is so that we can handle symbols that are an arbitrary distance from
7268 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7269 which returns part of an address in a form which will be valid for
7270 a data instruction. We do this by pushing the expression into a symbol
7271 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7272
7273static void
c19d1205
ZW
7274fix_new_arm (fragS * frag,
7275 int where,
7276 short int size,
7277 expressionS * exp,
7278 int pc_rel,
7279 int reloc)
b99bd4ef 7280{
c19d1205 7281 fixS * new_fix;
b99bd4ef 7282
c19d1205 7283 switch (exp->X_op)
b99bd4ef 7284 {
c19d1205
ZW
7285 case O_constant:
7286 case O_symbol:
7287 case O_add:
7288 case O_subtract:
7289 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7290 break;
b99bd4ef 7291
c19d1205
ZW
7292 default:
7293 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7294 pc_rel, reloc);
7295 break;
b99bd4ef
NC
7296 }
7297
c19d1205
ZW
7298 /* Mark whether the fix is to a THUMB instruction, or an ARM
7299 instruction. */
adbaf948 7300 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7301}
7302
7303static void
c19d1205 7304output_inst (const char * str)
b99bd4ef 7305{
c19d1205 7306 char * to = NULL;
b99bd4ef 7307
c19d1205 7308 if (inst.error)
b99bd4ef 7309 {
c19d1205 7310 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
7311 return;
7312 }
c19d1205
ZW
7313 if (inst.size == 0)
7314 return;
b99bd4ef 7315
c19d1205
ZW
7316 to = frag_more (inst.size);
7317
7318 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 7319 {
c19d1205
ZW
7320 assert (inst.size == (2 * THUMB_SIZE));
7321 md_number_to_chars (to, inst.instruction >> 16, THUMB_SIZE);
7322 md_number_to_chars (to + THUMB_SIZE, inst.instruction, THUMB_SIZE);
b99bd4ef 7323 }
c19d1205 7324 else if (inst.size > INSN_SIZE)
b99bd4ef 7325 {
c19d1205
ZW
7326 assert (inst.size == (2 * INSN_SIZE));
7327 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7328 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 7329 }
c19d1205
ZW
7330 else
7331 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 7332
c19d1205
ZW
7333 if (inst.reloc.type != BFD_RELOC_UNUSED)
7334 fix_new_arm (frag_now, to - frag_now->fr_literal,
7335 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7336 inst.reloc.type);
b99bd4ef 7337
c19d1205
ZW
7338#ifdef OBJ_ELF
7339 dwarf2_emit_insn (inst.size);
7340#endif
7341}
b99bd4ef 7342
c19d1205
ZW
7343/* Tag values used in struct asm_opcode's tag field. */
7344enum opcode_tag
7345{
7346 OT_unconditional, /* Instruction cannot be conditionalized.
7347 The ARM condition field is still 0xE. */
7348 OT_unconditionalF, /* Instruction cannot be conditionalized
7349 and carries 0xF in its ARM condition field. */
7350 OT_csuffix, /* Instruction takes a conditional suffix. */
7351 OT_cinfix3, /* Instruction takes a conditional infix,
7352 beginning at character index 3. (In
7353 unified mode, it becomes a suffix.) */
7354 OT_csuf_or_in3, /* Instruction takes either a conditional
7355 suffix or an infix at character index 3.
7356 (In unified mode, a suffix only. */
7357 OT_odd_infix_unc, /* This is the unconditional variant of an
7358 instruction that takes a conditional infix
7359 at an unusual position. In unified mode,
7360 this variant will accept a suffix. */
7361 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7362 are the conditional variants of instructions that
7363 take conditional infixes in unusual positions.
7364 The infix appears at character index
7365 (tag - OT_odd_infix_0). These are not accepted
7366 in unified mode. */
7367};
b99bd4ef 7368
c19d1205
ZW
7369/* Subroutine of md_assemble, responsible for looking up the primary
7370 opcode from the mnemonic the user wrote. STR points to the
7371 beginning of the mnemonic.
7372
7373 This is not simply a hash table lookup, because of conditional
7374 variants. Most instructions have conditional variants, which are
7375 expressed with a _conditional affix_ to the mnemonic. If we were
7376 to encode each conditional variant as a literal string in the opcode
7377 table, it would have approximately 20,000 entries.
7378
7379 Most mnemonics take this affix as a suffix, and in unified syntax,
7380 'most' is upgraded to 'all'. However, in the divided syntax, some
7381 instructions take the affix as an infix, notably the s-variants of
7382 the arithmetic instructions. Of those instructions, all but six
7383 have the infix appear after the third character of the mnemonic.
7384
7385 Accordingly, the algorithm for looking up primary opcodes given
7386 an identifier is:
7387
7388 1. Look up the identifier in the opcode table.
7389 If we find a match, go to step U.
7390
7391 2. Look up the last two characters of the identifier in the
7392 conditions table. If we find a match, look up the first N-2
7393 characters of the identifier in the opcode table. If we
7394 find a match, go to step CE.
7395
7396 3. Look up the fourth and fifth characters of the identifier in
7397 the conditions table. If we find a match, extract those
7398 characters from the identifier, and look up the remaining
7399 characters in the opcode table. If we find a match, go
7400 to step CM.
7401
7402 4. Fail.
7403
7404 U. Examine the tag field of the opcode structure, in case this is
7405 one of the six instructions with its conditional infix in an
7406 unusual place. If it is, the tag tells us where to find the
7407 infix; look it up in the conditions table and set inst.cond
7408 accordingly. Otherwise, this is an unconditional instruction.
7409 Again set inst.cond accordingly. Return the opcode structure.
7410
7411 CE. Examine the tag field to make sure this is an instruction that
7412 should receive a conditional suffix. If it is not, fail.
7413 Otherwise, set inst.cond from the suffix we already looked up,
7414 and return the opcode structure.
7415
7416 CM. Examine the tag field to make sure this is an instruction that
7417 should receive a conditional infix after the third character.
7418 If it is not, fail. Otherwise, undo the edits to the current
7419 line of input and proceed as for case CE. */
7420
7421static const struct asm_opcode *
7422opcode_lookup (char **str)
7423{
7424 char *end, *base;
7425 char *affix;
7426 const struct asm_opcode *opcode;
7427 const struct asm_cond *cond;
7428
7429 /* Scan up to the end of the mnemonic, which must end in white space,
7430 '.' (in unified mode only), or end of string. */
7431 for (base = end = *str; *end != '\0'; end++)
7432 if (*end == ' ' || (unified_syntax && *end == '.'))
7433 break;
b99bd4ef 7434
c19d1205
ZW
7435 if (end == base)
7436 return 0;
b99bd4ef 7437
c19d1205
ZW
7438 /* Handle a possible width suffix. */
7439 if (end[0] == '.')
b99bd4ef 7440 {
c19d1205
ZW
7441 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7442 inst.size_req = 4;
7443 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7444 inst.size_req = 2;
7445 else
7446 return 0;
b99bd4ef 7447
c19d1205 7448 *str = end + 2;
b99bd4ef 7449 }
c19d1205
ZW
7450 else
7451 *str = end;
b99bd4ef 7452
c19d1205
ZW
7453 /* Look for unaffixed or special-case affixed mnemonic. */
7454 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7455 if (opcode)
b99bd4ef 7456 {
c19d1205
ZW
7457 /* step U */
7458 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 7459 {
c19d1205
ZW
7460 inst.cond = COND_ALWAYS;
7461 return opcode;
b99bd4ef 7462 }
b99bd4ef 7463
c19d1205
ZW
7464 if (unified_syntax)
7465 as_warn (_("conditional infixes are deprecated in unified syntax"));
7466 affix = base + (opcode->tag - OT_odd_infix_0);
7467 cond = hash_find_n (arm_cond_hsh, affix, 2);
7468 assert (cond);
b99bd4ef 7469
c19d1205
ZW
7470 inst.cond = cond->value;
7471 return opcode;
7472 }
b99bd4ef 7473
c19d1205
ZW
7474 /* Cannot have a conditional suffix on a mnemonic of less than two
7475 characters. */
7476 if (end - base < 3)
7477 return 0;
b99bd4ef 7478
c19d1205
ZW
7479 /* Look for suffixed mnemonic. */
7480 affix = end - 2;
7481 cond = hash_find_n (arm_cond_hsh, affix, 2);
7482 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7483 if (opcode && cond)
7484 {
7485 /* step CE */
7486 switch (opcode->tag)
7487 {
7488 case OT_cinfix3:
7489 case OT_odd_infix_unc:
7490 if (!unified_syntax)
7491 return 0;
7492 /* else fall through */
7493
7494 case OT_csuffix:
7495 case OT_csuf_or_in3:
7496 inst.cond = cond->value;
7497 return opcode;
7498
7499 case OT_unconditional:
7500 case OT_unconditionalF:
7501 /* delayed diagnostic */
7502 inst.error = BAD_COND;
7503 inst.cond = COND_ALWAYS;
7504 return opcode;
b99bd4ef 7505
c19d1205
ZW
7506 default:
7507 return 0;
7508 }
7509 }
b99bd4ef 7510
c19d1205
ZW
7511 /* Cannot have a usual-position infix on a mnemonic of less than
7512 six characters (five would be a suffix). */
7513 if (end - base < 6)
7514 return 0;
b99bd4ef 7515
c19d1205
ZW
7516 /* Look for infixed mnemonic in the usual position. */
7517 affix = base + 3;
7518 cond = hash_find_n (arm_cond_hsh, affix, 2);
7519 if (cond)
b99bd4ef 7520 {
c19d1205
ZW
7521 char save[2];
7522 memcpy (save, affix, 2);
7523 memmove (affix, affix + 2, (end - affix) - 2);
7524 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
7525 memmove (affix + 2, affix, (end - affix) - 2);
7526 memcpy (affix, save, 2);
b99bd4ef 7527 }
c19d1205 7528 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3))
b99bd4ef 7529 {
c19d1205
ZW
7530 /* step CM */
7531 if (unified_syntax)
7532 as_warn (_("conditional infixes are deprecated in unified syntax"));
7533
7534 inst.cond = cond->value;
7535 return opcode;
b99bd4ef
NC
7536 }
7537
c19d1205 7538 return 0;
b99bd4ef
NC
7539}
7540
c19d1205
ZW
7541void
7542md_assemble (char *str)
b99bd4ef 7543{
c19d1205
ZW
7544 char *p = str;
7545 const struct asm_opcode * opcode;
b99bd4ef 7546
c19d1205
ZW
7547 /* Align the previous label if needed. */
7548 if (last_label_seen != NULL)
b99bd4ef 7549 {
c19d1205
ZW
7550 symbol_set_frag (last_label_seen, frag_now);
7551 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
7552 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
7553 }
7554
c19d1205
ZW
7555 memset (&inst, '\0', sizeof (inst));
7556 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7557
c19d1205
ZW
7558 opcode = opcode_lookup (&p);
7559 if (!opcode)
b99bd4ef 7560 {
c19d1205
ZW
7561 /* It wasn't an instruction, but it might be a register alias of
7562 the form alias .req reg. */
7563 if (!create_register_alias (str, p))
7564 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 7565
b99bd4ef
NC
7566 return;
7567 }
7568
c19d1205 7569 if (thumb_mode)
b99bd4ef 7570 {
c19d1205
ZW
7571 /* Check that this instruction is supported for this CPU. */
7572 if (thumb_mode == 1 && (opcode->tvariant & cpu_variant) == 0)
b99bd4ef 7573 {
c19d1205 7574 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
7575 return;
7576 }
c19d1205
ZW
7577 if (inst.cond != COND_ALWAYS && !unified_syntax
7578 && opcode->tencode != do_t_branch)
b99bd4ef 7579 {
c19d1205 7580 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
7581 return;
7582 }
7583
c19d1205
ZW
7584 mapping_state (MAP_THUMB);
7585 inst.instruction = opcode->tvalue;
7586
7587 if (!parse_operands (p, opcode->operands))
7588 opcode->tencode ();
7589
7590 if (!inst.error)
b99bd4ef 7591 {
c19d1205
ZW
7592 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
7593 inst.size = (inst.instruction > 0xffff ? 4 : 2);
7594 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 7595 {
c19d1205 7596 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
7597 return;
7598 }
7599 }
c19d1205
ZW
7600 }
7601 else
7602 {
7603 /* Check that this instruction is supported for this CPU. */
7604 if ((opcode->avariant & cpu_variant) == 0)
b99bd4ef 7605 {
c19d1205
ZW
7606 as_bad (_("selected processor does not support `%s'"), str);
7607 return;
b99bd4ef 7608 }
c19d1205 7609 if (inst.size_req)
b99bd4ef 7610 {
c19d1205
ZW
7611 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
7612 return;
b99bd4ef
NC
7613 }
7614
c19d1205
ZW
7615 mapping_state (MAP_ARM);
7616 inst.instruction = opcode->avalue;
7617 if (opcode->tag == OT_unconditionalF)
7618 inst.instruction |= 0xF << 28;
7619 else
7620 inst.instruction |= inst.cond << 28;
7621 inst.size = INSN_SIZE;
7622 if (!parse_operands (p, opcode->operands))
7623 opcode->aencode ();
b99bd4ef 7624 }
c19d1205
ZW
7625 output_inst (str);
7626}
b99bd4ef 7627
c19d1205
ZW
7628/* Various frobbings of labels and their addresses. */
7629
7630void
7631arm_start_line_hook (void)
7632{
7633 last_label_seen = NULL;
b99bd4ef
NC
7634}
7635
c19d1205
ZW
7636void
7637arm_frob_label (symbolS * sym)
b99bd4ef 7638{
c19d1205 7639 last_label_seen = sym;
b99bd4ef 7640
c19d1205 7641 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 7642
c19d1205
ZW
7643#if defined OBJ_COFF || defined OBJ_ELF
7644 ARM_SET_INTERWORK (sym, support_interwork);
7645#endif
b99bd4ef 7646
c19d1205
ZW
7647 /* Note - do not allow local symbols (.Lxxx) to be labeled
7648 as Thumb functions. This is because these labels, whilst
7649 they exist inside Thumb code, are not the entry points for
7650 possible ARM->Thumb calls. Also, these labels can be used
7651 as part of a computed goto or switch statement. eg gcc
7652 can generate code that looks like this:
b99bd4ef 7653
c19d1205
ZW
7654 ldr r2, [pc, .Laaa]
7655 lsl r3, r3, #2
7656 ldr r2, [r3, r2]
7657 mov pc, r2
b99bd4ef 7658
c19d1205
ZW
7659 .Lbbb: .word .Lxxx
7660 .Lccc: .word .Lyyy
7661 ..etc...
7662 .Laaa: .word Lbbb
b99bd4ef 7663
c19d1205
ZW
7664 The first instruction loads the address of the jump table.
7665 The second instruction converts a table index into a byte offset.
7666 The third instruction gets the jump address out of the table.
7667 The fourth instruction performs the jump.
b99bd4ef 7668
c19d1205
ZW
7669 If the address stored at .Laaa is that of a symbol which has the
7670 Thumb_Func bit set, then the linker will arrange for this address
7671 to have the bottom bit set, which in turn would mean that the
7672 address computation performed by the third instruction would end
7673 up with the bottom bit set. Since the ARM is capable of unaligned
7674 word loads, the instruction would then load the incorrect address
7675 out of the jump table, and chaos would ensue. */
7676 if (label_is_thumb_function_name
7677 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
7678 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 7679 {
c19d1205
ZW
7680 /* When the address of a Thumb function is taken the bottom
7681 bit of that address should be set. This will allow
7682 interworking between Arm and Thumb functions to work
7683 correctly. */
b99bd4ef 7684
c19d1205 7685 THUMB_SET_FUNC (sym, 1);
b99bd4ef 7686
c19d1205 7687 label_is_thumb_function_name = FALSE;
b99bd4ef 7688 }
b99bd4ef
NC
7689}
7690
c19d1205
ZW
7691int
7692arm_data_in_code (void)
b99bd4ef 7693{
c19d1205 7694 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 7695 {
c19d1205
ZW
7696 *input_line_pointer = '/';
7697 input_line_pointer += 5;
7698 *input_line_pointer = 0;
7699 return 1;
b99bd4ef
NC
7700 }
7701
c19d1205 7702 return 0;
b99bd4ef
NC
7703}
7704
c19d1205
ZW
7705char *
7706arm_canonicalize_symbol_name (char * name)
b99bd4ef 7707{
c19d1205 7708 int len;
b99bd4ef 7709
c19d1205
ZW
7710 if (thumb_mode && (len = strlen (name)) > 5
7711 && streq (name + len - 5, "/data"))
7712 *(name + len - 5) = 0;
b99bd4ef 7713
c19d1205 7714 return name;
b99bd4ef 7715}
c19d1205
ZW
7716\f
7717/* Table of all register names defined by default. The user can
7718 define additional names with .req. Note that all register names
7719 should appear in both upper and lowercase variants. Some registers
7720 also have mixed-case names. */
b99bd4ef 7721
c19d1205
ZW
7722#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
7723#define REGNUM(p,n,t) REGDEF(p##n, n, t)
7724#define REGSET(p,t) \
7725 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
7726 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
7727 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
7728 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 7729
c19d1205 7730static const struct reg_entry reg_names[] =
7ed4c4c5 7731{
c19d1205
ZW
7732 /* ARM integer registers. */
7733 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 7734
c19d1205
ZW
7735 /* ATPCS synonyms. */
7736 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
7737 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
7738 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 7739
c19d1205
ZW
7740 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
7741 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
7742 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 7743
c19d1205
ZW
7744 /* Well-known aliases. */
7745 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
7746 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
7747
7748 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
7749 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
7750
7751 /* Coprocessor numbers. */
7752 REGSET(p, CP), REGSET(P, CP),
7753
7754 /* Coprocessor register numbers. The "cr" variants are for backward
7755 compatibility. */
7756 REGSET(c, CN), REGSET(C, CN),
7757 REGSET(cr, CN), REGSET(CR, CN),
7758
7759 /* FPA registers. */
7760 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
7761 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
7762
7763 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
7764 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
7765
7766 /* VFP SP registers. */
7767 REGSET(s,VFS),
7768 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
7769 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
7770 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
7771 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
7772
7773 REGSET(S,VFS),
7774 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
7775 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
7776 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
7777 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
7778
7779 /* VFP DP Registers. */
7780 REGSET(d,VFD), REGSET(D,VFS),
7781
7782 /* VFP control registers. */
7783 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
7784 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
7785
7786 /* Maverick DSP coprocessor registers. */
7787 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
7788 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
7789
7790 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
7791 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
7792 REGDEF(dspsc,0,DSPSC),
7793
7794 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
7795 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
7796 REGDEF(DSPSC,0,DSPSC),
7797
7798 /* iWMMXt data registers - p0, c0-15. */
7799 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
7800
7801 /* iWMMXt control registers - p1, c0-3. */
7802 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
7803 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
7804 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
7805 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
7806
7807 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
7808 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
7809 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
7810 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
7811 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
7812
7813 /* XScale accumulator registers. */
7814 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
7815};
7816#undef REGDEF
7817#undef REGNUM
7818#undef REGSET
7ed4c4c5 7819
c19d1205
ZW
7820/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
7821 within psr_required_here. */
7822static const struct asm_psr psrs[] =
7823{
7824 /* Backward compatibility notation. Note that "all" is no longer
7825 truly all possible PSR bits. */
7826 {"all", PSR_c | PSR_f},
7827 {"flg", PSR_f},
7828 {"ctl", PSR_c},
7829
7830 /* Individual flags. */
7831 {"f", PSR_f},
7832 {"c", PSR_c},
7833 {"x", PSR_x},
7834 {"s", PSR_s},
7835 /* Combinations of flags. */
7836 {"fs", PSR_f | PSR_s},
7837 {"fx", PSR_f | PSR_x},
7838 {"fc", PSR_f | PSR_c},
7839 {"sf", PSR_s | PSR_f},
7840 {"sx", PSR_s | PSR_x},
7841 {"sc", PSR_s | PSR_c},
7842 {"xf", PSR_x | PSR_f},
7843 {"xs", PSR_x | PSR_s},
7844 {"xc", PSR_x | PSR_c},
7845 {"cf", PSR_c | PSR_f},
7846 {"cs", PSR_c | PSR_s},
7847 {"cx", PSR_c | PSR_x},
7848 {"fsx", PSR_f | PSR_s | PSR_x},
7849 {"fsc", PSR_f | PSR_s | PSR_c},
7850 {"fxs", PSR_f | PSR_x | PSR_s},
7851 {"fxc", PSR_f | PSR_x | PSR_c},
7852 {"fcs", PSR_f | PSR_c | PSR_s},
7853 {"fcx", PSR_f | PSR_c | PSR_x},
7854 {"sfx", PSR_s | PSR_f | PSR_x},
7855 {"sfc", PSR_s | PSR_f | PSR_c},
7856 {"sxf", PSR_s | PSR_x | PSR_f},
7857 {"sxc", PSR_s | PSR_x | PSR_c},
7858 {"scf", PSR_s | PSR_c | PSR_f},
7859 {"scx", PSR_s | PSR_c | PSR_x},
7860 {"xfs", PSR_x | PSR_f | PSR_s},
7861 {"xfc", PSR_x | PSR_f | PSR_c},
7862 {"xsf", PSR_x | PSR_s | PSR_f},
7863 {"xsc", PSR_x | PSR_s | PSR_c},
7864 {"xcf", PSR_x | PSR_c | PSR_f},
7865 {"xcs", PSR_x | PSR_c | PSR_s},
7866 {"cfs", PSR_c | PSR_f | PSR_s},
7867 {"cfx", PSR_c | PSR_f | PSR_x},
7868 {"csf", PSR_c | PSR_s | PSR_f},
7869 {"csx", PSR_c | PSR_s | PSR_x},
7870 {"cxf", PSR_c | PSR_x | PSR_f},
7871 {"cxs", PSR_c | PSR_x | PSR_s},
7872 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
7873 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
7874 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
7875 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
7876 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
7877 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
7878 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
7879 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
7880 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
7881 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
7882 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
7883 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
7884 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
7885 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
7886 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
7887 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
7888 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
7889 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
7890 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
7891 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
7892 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
7893 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
7894 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
7895 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
7896};
7897
7898/* Table of all shift-in-operand names. */
7899static const struct asm_shift_name shift_names [] =
b99bd4ef 7900{
c19d1205
ZW
7901 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
7902 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
7903 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
7904 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
7905 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
7906 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
7907};
b99bd4ef 7908
c19d1205
ZW
7909/* Table of all explicit relocation names. */
7910#ifdef OBJ_ELF
7911static struct reloc_entry reloc_names[] =
7912{
7913 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
7914 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
7915 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
7916 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
7917 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
7918 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
7919 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
7920 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
7921 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
7922 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
7923 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
7924};
7925#endif
b99bd4ef 7926
c19d1205
ZW
7927/* Table of all conditional affixes. 0xF is not defined as a condition code. */
7928static const struct asm_cond conds[] =
7929{
7930 {"eq", 0x0},
7931 {"ne", 0x1},
7932 {"cs", 0x2}, {"hs", 0x2},
7933 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
7934 {"mi", 0x4},
7935 {"pl", 0x5},
7936 {"vs", 0x6},
7937 {"vc", 0x7},
7938 {"hi", 0x8},
7939 {"ls", 0x9},
7940 {"ge", 0xa},
7941 {"lt", 0xb},
7942 {"gt", 0xc},
7943 {"le", 0xd},
7944 {"al", 0xe}
7945};
bfae80f2 7946
c19d1205
ZW
7947/* Table of ARM-format instructions. */
7948
7949/* Macros for gluing together operand strings. N.B. In all cases
7950 other than OPS0, the trailing OP_stop comes from default
7951 zero-initialization of the unspecified elements of the array. */
7952#define OPS0() { OP_stop, }
7953#define OPS1(a) { OP_##a, }
7954#define OPS2(a,b) { OP_##a,OP_##b, }
7955#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
7956#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
7957#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
7958#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
7959
7960/* These macros abstract out the exact format of the mnemonic table and
7961 save some repeated characters. */
7962
7963/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
7964#define TxCE(mnem, op, top, nops, ops, ae, te) \
7965 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 7966 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7967
7968/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
7969 a T_MNEM_xyz enumerator. */
7970#define TCE(mnem, aop, top, nops, ops, ae, te) \
7971 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
7972#define tCE(mnem, aop, top, nops, ops, ae, te) \
7973 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
7974
7975/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
7976 infix after the third character. */
7977#define TxC3(mnem, op, top, nops, ops, ae, te) \
7978 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 7979 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7980#define TC3(mnem, aop, top, nops, ops, ae, te) \
7981 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
7982#define tC3(mnem, aop, top, nops, ops, ae, te) \
7983 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
7984
7985/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
7986 appear in the condition table. */
7987#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
7988 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 7989 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7990
7991#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
7992 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
7993 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
7994 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
7995 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
7996 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
7997 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
7998 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
7999 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8000 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8001 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8002 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8003 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8004 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8005 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8006 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8007 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8008 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8009 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8010 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8011
8012#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8013 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8014#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8015 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8016
8017/* Mnemonic that cannot be conditionalized. The ARM condition-code
8018 field is still 0xE. */
8019#define TUE(mnem, op, top, nops, ops, ae, te) \
8020 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8021 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8022
8023/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8024 condition code field. */
8025#define TUF(mnem, op, top, nops, ops, ae, te) \
8026 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8027 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8028
8029/* ARM-only variants of all the above. */
6a86118a
NC
8030#define CE(mnem, op, nops, ops, ae) \
8031 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8032
8033#define C3(mnem, op, nops, ops, ae) \
8034 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8035
8036#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8037 { #m1 #m2 #m3, OPS##nops ops, \
8038 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8039 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8040
8041#define CM(m1, m2, op, nops, ops, ae) \
8042 xCM_(m1, , m2, op, nops, ops, ae), \
8043 xCM_(m1, eq, m2, op, nops, ops, ae), \
8044 xCM_(m1, ne, m2, op, nops, ops, ae), \
8045 xCM_(m1, cs, m2, op, nops, ops, ae), \
8046 xCM_(m1, hs, m2, op, nops, ops, ae), \
8047 xCM_(m1, cc, m2, op, nops, ops, ae), \
8048 xCM_(m1, ul, m2, op, nops, ops, ae), \
8049 xCM_(m1, lo, m2, op, nops, ops, ae), \
8050 xCM_(m1, mi, m2, op, nops, ops, ae), \
8051 xCM_(m1, pl, m2, op, nops, ops, ae), \
8052 xCM_(m1, vs, m2, op, nops, ops, ae), \
8053 xCM_(m1, vc, m2, op, nops, ops, ae), \
8054 xCM_(m1, hi, m2, op, nops, ops, ae), \
8055 xCM_(m1, ls, m2, op, nops, ops, ae), \
8056 xCM_(m1, ge, m2, op, nops, ops, ae), \
8057 xCM_(m1, lt, m2, op, nops, ops, ae), \
8058 xCM_(m1, gt, m2, op, nops, ops, ae), \
8059 xCM_(m1, le, m2, op, nops, ops, ae), \
8060 xCM_(m1, al, m2, op, nops, ops, ae)
8061
8062#define UE(mnem, op, nops, ops, ae) \
8063 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8064
8065#define UF(mnem, op, nops, ops, ae) \
8066 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8067
c19d1205
ZW
8068#define do_0 0
8069
8070/* Thumb-only, unconditional. */
8071#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8072
8073/* ARM-only, takes either a suffix or a position-3 infix
8074 (for an FPA corner case). */
8075#define C3E(mnem, op, nops, ops, ae) \
8076 { #mnem, OPS##nops ops, OT_csuf_or_in3, 0x##op, 0, ARM_VARIANT, 0, do_##ae, 0 }
bfae80f2 8077
c19d1205 8078static const struct asm_opcode insns[] =
bfae80f2 8079{
c19d1205
ZW
8080#define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8081#define THUMB_VARIANT ARM_EXT_V4T
8082 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8083 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8084 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8085 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8086 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8087 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8088 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8089 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8090 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8091 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8092 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8093 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8094 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8095 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8096 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8097 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8098
8099 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8100 for setting PSR flag bits. They are obsolete in V6 and do not
8101 have Thumb equivalents. */
8102 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8103 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8104 C3(tstp, 110f000, 2, (RR, SH), cmp),
8105 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8106 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8107 C3(cmpp, 150f000, 2, (RR, SH), cmp),
8108 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8109 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8110 C3(cmnp, 170f000, 2, (RR, SH), cmp),
8111
8112 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8113 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8114 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8115 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8116
8117 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8118 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8119 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8120 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8121
8122 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8123 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8124 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8125 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8126
8127 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
8128#ifdef TE_WINCE
8129 /* XXX This is the wrong place to do this. Think multi-arch. */
8130 TCE(b, a000000, e7fe, 1, (EXPr), branch, t_branch),
8131 TCE(bl, b000000, f7fffffe, 1, (EXPr), branch, t_branch23),
8132#else
8133 TCE(b, afffffe, e7fe, 1, (EXPr), branch, t_branch),
8134 TCE(bl, bfffffe, f7fffffe, 1, (EXPr), branch, t_branch23),
8135#endif
bfae80f2 8136
c19d1205
ZW
8137 /* Pseudo ops. */
8138 TCE(adr, 28f0000, 000f, 2, (RR, EXP), adr, t_adr),
8139 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8140 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
8141
8142 /* Thumb-compatibility pseudo ops. */
8143 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8144 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8145 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8146 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8147 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
8148 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
8149 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8150 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8151 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8152 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8153 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8154 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8155
8156#undef THUMB_VARIANT
8157#define THUMB_VARIANT ARM_EXT_V6
8158 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
8159
8160 /* V1 instructions with no Thumb analogue prior to V6T2. */
8161#undef THUMB_VARIANT
8162#define THUMB_VARIANT ARM_EXT_V6T2
8163 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8164 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8165 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8166 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8167 C3(teqp, 130f000, 2, (RR, SH), cmp),
8168
8169 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8170 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8171 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8172 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8173
8174 TC3(stmdb, 9000000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8175 TC3(stmfd, 9000000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8176
8177 TC3(ldmdb, 9100000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8178 TC3(ldmea, 9100000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8179
8180 /* V1 instructions with no Thumb analogue at all. */
8181 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8182 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8183
8184 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8185 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8186 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8187 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8188 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8189 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8190 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8191 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8192
8193#undef ARM_VARIANT
8194#define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8195#undef THUMB_VARIANT
8196#define THUMB_VARIANT ARM_EXT_V4T
8197 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8198 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8199
8200#undef THUMB_VARIANT
8201#define THUMB_VARIANT ARM_EXT_V6T2
8202 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8203 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8204
8205 /* Generic coprocessor instructions. */
8206 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8207 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8208 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8209 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8210 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8211 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8212 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8213
8214#undef ARM_VARIANT
8215#define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8216 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8217 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8218
8219#undef ARM_VARIANT
8220#define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8221 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8222 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8223
8224#undef ARM_VARIANT
8225#define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8226 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8227 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8228 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8229 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8230 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8231 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8232 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8233 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8234
8235#undef ARM_VARIANT
8236#define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8237#undef THUMB_VARIANT
8238#define THUMB_VARIANT ARM_EXT_V4T
8239 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8240 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8241 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8242 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8243 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8244 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8245
8246#undef ARM_VARIANT
8247#define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8248 /* ARM Architecture 4T. */
8249 /* Note: bx (and blx) are required on V5, even if the processor does
8250 not support Thumb. */
8251 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8252
8253#undef ARM_VARIANT
8254#define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8255#undef THUMB_VARIANT
8256#define THUMB_VARIANT ARM_EXT_V5T
8257 /* Note: blx has 2 variants; the .value coded here is for
8258 BLX(2). Only this variant has conditional execution. */
8259 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8260 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8261
8262#undef THUMB_VARIANT
8263#define THUMB_VARIANT ARM_EXT_V6T2
8264 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8265 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8266 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8267 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8268 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8269 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8270 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8271 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8272
8273#undef ARM_VARIANT
8274#define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8275 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8276 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8277 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8278 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8279
8280 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8281 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8282
8283 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8284 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8285 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8286 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8287
8288 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8289 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8290 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8291 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8292
8293 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8294 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8295
8296 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8297 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8298 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8299 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8300
8301#undef ARM_VARIANT
8302#define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8303 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8304 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8305 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8306
8307 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8308 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8309
8310#undef ARM_VARIANT
8311#define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8312 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8313
8314#undef ARM_VARIANT
8315#define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8316#undef THUMB_VARIANT
8317#define THUMB_VARIANT ARM_EXT_V6
8318 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8319 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8320 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8321 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8322 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8323 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8324 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8325 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8326 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8327 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8328
8329#undef THUMB_VARIANT
8330#define THUMB_VARIANT ARM_EXT_V6T2
8331 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8332 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8333 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8334 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8335 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8336 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8337 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8338 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8339 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8340 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8341 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8342 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8343 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8344 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8345 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8346 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8347 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8348 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8349 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8350 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8351 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8352 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8353 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8354 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8355 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8356 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8357 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8358 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8359 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8360 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8361 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8362 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8363 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8364 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8365 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8366 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8367 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8368 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8369 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8370 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8371 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8372 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8373 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8374 UF(rfeib, 9900a00, 1, (RRw), rfe),
8375 UF(rfeda, 8100a00, 1, (RRw), rfe),
8376 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8377 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8378 UF(rfefa, 9900a00, 1, (RRw), rfe),
8379 UF(rfeea, 8100a00, 1, (RRw), rfe),
8380 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8381 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8382 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8383 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8384 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8385 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8386 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8387 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8388 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8389 TCE(sel, 68000b0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8390 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8391 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8392 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8393 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8394 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8395 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8396 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8397 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8398 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8399 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8400 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8401 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8402 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8403 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8404 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8405 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8406 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8407 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8408 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8409 UF(srsib, 9cd0500, 1, (I31w), srs),
8410 UF(srsda, 84d0500, 1, (I31w), srs),
8411 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8412 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8413 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8414 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8415 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8416 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8417 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8418 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8419 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8420
8421#undef ARM_VARIANT
8422#define ARM_VARIANT ARM_EXT_V6K
8423#undef THUMB_VARIANT
8424#define THUMB_VARIANT ARM_EXT_V6K
8425 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8426 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8427 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8428 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8429
8430#undef THUMB_VARIANT
8431#define THUMB_VARIANT ARM_EXT_V6T2
8432 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8433 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8434 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8435 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8436 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8437 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8438 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8439
8440#undef ARM_VARIANT
8441#define ARM_VARIANT ARM_EXT_V6Z
8442 TCE(smi, 1600070, f7f08000, 1, (EXPi), smi, t_smi),
8443
8444#undef ARM_VARIANT
8445#define ARM_VARIANT ARM_EXT_V6T2
8446 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8447 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8448 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8449 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8450
8451 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8452 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8453 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8454 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8455
8456 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8457 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8458 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8459 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8460
8461 UT(cbnz, b900, 2, (RR, EXP), t_czb),
8462 UT(cbz, b100, 2, (RR, EXP), t_czb),
8463 /* ARM does not really have an IT instruction. */
8464 TUE(it, 0, bf08, 1, (COND), it, t_it),
8465 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
8466 TUE(ite, 0, bf04, 1, (COND), it, t_it),
8467 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
8468 TUE(itet, 0, bf06, 1, (COND), it, t_it),
8469 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
8470 TUE(itee, 0, bf02, 1, (COND), it, t_it),
8471 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
8472 TUE(itett, 0, bf07, 1, (COND), it, t_it),
8473 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
8474 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
8475 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
8476 TUE(itete, 0, bf05, 1, (COND), it, t_it),
8477 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
8478 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
8479
8480#undef ARM_VARIANT
8481#define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
8482 CE(wfs, e200110, 1, (RR), rd),
8483 CE(rfs, e300110, 1, (RR), rd),
8484 CE(wfc, e400110, 1, (RR), rd),
8485 CE(rfc, e500110, 1, (RR), rd),
8486
8487 C3(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
8488 C3(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
8489 C3(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
8490 C3(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
8491
8492 C3(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
8493 C3(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
8494 C3(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
8495 C3(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
8496
8497 C3(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
8498 C3(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
8499 C3(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
8500 C3(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
8501 C3(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
8502 C3(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
8503 C3(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
8504 C3(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
8505 C3(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
8506 C3(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
8507 C3(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
8508 C3(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
8509
8510 C3(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
8511 C3(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
8512 C3(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
8513 C3(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
8514 C3(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
8515 C3(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
8516 C3(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
8517 C3(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
8518 C3(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
8519 C3(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
8520 C3(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
8521 C3(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
8522
8523 C3(abss, e208100, 2, (RF, RF_IF), rd_rm),
8524 C3(abssp, e208120, 2, (RF, RF_IF), rd_rm),
8525 C3(abssm, e208140, 2, (RF, RF_IF), rd_rm),
8526 C3(abssz, e208160, 2, (RF, RF_IF), rd_rm),
8527 C3(absd, e208180, 2, (RF, RF_IF), rd_rm),
8528 C3(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
8529 C3(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
8530 C3(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
8531 C3(abse, e288100, 2, (RF, RF_IF), rd_rm),
8532 C3(absep, e288120, 2, (RF, RF_IF), rd_rm),
8533 C3(absem, e288140, 2, (RF, RF_IF), rd_rm),
8534 C3(absez, e288160, 2, (RF, RF_IF), rd_rm),
8535
8536 C3(rnds, e308100, 2, (RF, RF_IF), rd_rm),
8537 C3(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
8538 C3(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
8539 C3(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
8540 C3(rndd, e308180, 2, (RF, RF_IF), rd_rm),
8541 C3(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
8542 C3(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
8543 C3(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
8544 C3(rnde, e388100, 2, (RF, RF_IF), rd_rm),
8545 C3(rndep, e388120, 2, (RF, RF_IF), rd_rm),
8546 C3(rndem, e388140, 2, (RF, RF_IF), rd_rm),
8547 C3(rndez, e388160, 2, (RF, RF_IF), rd_rm),
8548
8549 C3(sqts, e408100, 2, (RF, RF_IF), rd_rm),
8550 C3(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
8551 C3(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
8552 C3(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
8553 C3(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
8554 C3(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
8555 C3(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
8556 C3(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
8557 C3(sqte, e488100, 2, (RF, RF_IF), rd_rm),
8558 C3(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
8559 C3(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
8560 C3(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
8561
8562 C3(logs, e508100, 2, (RF, RF_IF), rd_rm),
8563 C3(logsp, e508120, 2, (RF, RF_IF), rd_rm),
8564 C3(logsm, e508140, 2, (RF, RF_IF), rd_rm),
8565 C3(logsz, e508160, 2, (RF, RF_IF), rd_rm),
8566 C3(logd, e508180, 2, (RF, RF_IF), rd_rm),
8567 C3(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
8568 C3(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
8569 C3(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
8570 C3(loge, e588100, 2, (RF, RF_IF), rd_rm),
8571 C3(logep, e588120, 2, (RF, RF_IF), rd_rm),
8572 C3(logem, e588140, 2, (RF, RF_IF), rd_rm),
8573 C3(logez, e588160, 2, (RF, RF_IF), rd_rm),
8574
8575 C3(lgns, e608100, 2, (RF, RF_IF), rd_rm),
8576 C3(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
8577 C3(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
8578 C3(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
8579 C3(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
8580 C3(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
8581 C3(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
8582 C3(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
8583 C3(lgne, e688100, 2, (RF, RF_IF), rd_rm),
8584 C3(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
8585 C3(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
8586 C3(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
8587
8588 C3(exps, e708100, 2, (RF, RF_IF), rd_rm),
8589 C3(expsp, e708120, 2, (RF, RF_IF), rd_rm),
8590 C3(expsm, e708140, 2, (RF, RF_IF), rd_rm),
8591 C3(expsz, e708160, 2, (RF, RF_IF), rd_rm),
8592 C3(expd, e708180, 2, (RF, RF_IF), rd_rm),
8593 C3(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
8594 C3(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
8595 C3(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
8596 C3(expe, e788100, 2, (RF, RF_IF), rd_rm),
8597 C3(expep, e788120, 2, (RF, RF_IF), rd_rm),
8598 C3(expem, e788140, 2, (RF, RF_IF), rd_rm),
8599 C3(expdz, e788160, 2, (RF, RF_IF), rd_rm),
8600
8601 C3(sins, e808100, 2, (RF, RF_IF), rd_rm),
8602 C3(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
8603 C3(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
8604 C3(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
8605 C3(sind, e808180, 2, (RF, RF_IF), rd_rm),
8606 C3(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
8607 C3(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
8608 C3(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
8609 C3(sine, e888100, 2, (RF, RF_IF), rd_rm),
8610 C3(sinep, e888120, 2, (RF, RF_IF), rd_rm),
8611 C3(sinem, e888140, 2, (RF, RF_IF), rd_rm),
8612 C3(sinez, e888160, 2, (RF, RF_IF), rd_rm),
8613
8614 C3(coss, e908100, 2, (RF, RF_IF), rd_rm),
8615 C3(cossp, e908120, 2, (RF, RF_IF), rd_rm),
8616 C3(cossm, e908140, 2, (RF, RF_IF), rd_rm),
8617 C3(cossz, e908160, 2, (RF, RF_IF), rd_rm),
8618 C3(cosd, e908180, 2, (RF, RF_IF), rd_rm),
8619 C3(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
8620 C3(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
8621 C3(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
8622 C3(cose, e988100, 2, (RF, RF_IF), rd_rm),
8623 C3(cosep, e988120, 2, (RF, RF_IF), rd_rm),
8624 C3(cosem, e988140, 2, (RF, RF_IF), rd_rm),
8625 C3(cosez, e988160, 2, (RF, RF_IF), rd_rm),
8626
8627 C3(tans, ea08100, 2, (RF, RF_IF), rd_rm),
8628 C3(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
8629 C3(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
8630 C3(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
8631 C3(tand, ea08180, 2, (RF, RF_IF), rd_rm),
8632 C3(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
8633 C3(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
8634 C3(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
8635 C3(tane, ea88100, 2, (RF, RF_IF), rd_rm),
8636 C3(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
8637 C3(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
8638 C3(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
8639
8640 C3(asns, eb08100, 2, (RF, RF_IF), rd_rm),
8641 C3(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
8642 C3(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
8643 C3(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
8644 C3(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
8645 C3(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
8646 C3(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
8647 C3(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
8648 C3(asne, eb88100, 2, (RF, RF_IF), rd_rm),
8649 C3(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
8650 C3(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
8651 C3(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
8652
8653 C3(acss, ec08100, 2, (RF, RF_IF), rd_rm),
8654 C3(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
8655 C3(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
8656 C3(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
8657 C3(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
8658 C3(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
8659 C3(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
8660 C3(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
8661 C3(acse, ec88100, 2, (RF, RF_IF), rd_rm),
8662 C3(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
8663 C3(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
8664 C3(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
8665
8666 C3(atns, ed08100, 2, (RF, RF_IF), rd_rm),
8667 C3(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
8668 C3(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
8669 C3(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
8670 C3(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
8671 C3(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
8672 C3(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
8673 C3(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
8674 C3(atne, ed88100, 2, (RF, RF_IF), rd_rm),
8675 C3(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
8676 C3(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
8677 C3(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
8678
8679 C3(urds, ee08100, 2, (RF, RF_IF), rd_rm),
8680 C3(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
8681 C3(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
8682 C3(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
8683 C3(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
8684 C3(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
8685 C3(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
8686 C3(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
8687 C3(urde, ee88100, 2, (RF, RF_IF), rd_rm),
8688 C3(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
8689 C3(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
8690 C3(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
8691
8692 C3(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
8693 C3(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
8694 C3(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
8695 C3(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
8696 C3(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
8697 C3(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
8698 C3(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
8699 C3(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
8700 C3(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
8701 C3(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
8702 C3(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
8703 C3(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
8704
8705 C3(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
8706 C3(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
8707 C3(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
8708 C3(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
8709 C3(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
8710 C3(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8711 C3(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8712 C3(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8713 C3(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
8714 C3(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
8715 C3(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
8716 C3(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
8717
8718 C3(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
8719 C3(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
8720 C3(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
8721 C3(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
8722 C3(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
8723 C3(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8724 C3(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8725 C3(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8726 C3(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
8727 C3(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
8728 C3(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
8729 C3(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
8730
8731 C3(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
8732 C3(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
8733 C3(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
8734 C3(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
8735 C3(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
8736 C3(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8737 C3(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8738 C3(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8739 C3(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
8740 C3(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
8741 C3(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
8742 C3(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
8743
8744 C3(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
8745 C3(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
8746 C3(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
8747 C3(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
8748 C3(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
8749 C3(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8750 C3(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8751 C3(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8752 C3(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
8753 C3(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
8754 C3(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
8755 C3(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
8756
8757 C3(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
8758 C3(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
8759 C3(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
8760 C3(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
8761 C3(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
8762 C3(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8763 C3(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8764 C3(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8765 C3(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
8766 C3(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
8767 C3(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
8768 C3(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
8769
8770 C3(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
8771 C3(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
8772 C3(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
8773 C3(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
8774 C3(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
8775 C3(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8776 C3(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8777 C3(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8778 C3(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
8779 C3(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
8780 C3(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
8781 C3(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
8782
8783 C3(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
8784 C3(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
8785 C3(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
8786 C3(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
8787 C3(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
8788 C3(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8789 C3(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8790 C3(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8791 C3(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
8792 C3(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
8793 C3(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
8794 C3(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
8795
8796 C3(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
8797 C3(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
8798 C3(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
8799 C3(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
8800 C3(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
8801 C3(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8802 C3(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8803 C3(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8804 C3(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
8805 C3(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
8806 C3(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
8807 C3(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
8808
8809 C3(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
8810 C3(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
8811 C3(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
8812 C3(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
8813 C3(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
8814 C3(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8815 C3(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8816 C3(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8817 C3(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
8818 C3(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
8819 C3(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
8820 C3(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
8821
8822 C3(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
8823 C3(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
8824 C3(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
8825 C3(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
8826 C3(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
8827 C3(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8828 C3(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8829 C3(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8830 C3(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
8831 C3(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
8832 C3(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
8833 C3(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
8834
8835 C3(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8836 C3(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8837 C3(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8838 C3(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8839 C3(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8840 C3(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8841 C3(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8842 C3(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8843 C3(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8844 C3(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8845 C3(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8846 C3(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8847
8848 C3(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8849 C3(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8850 C3(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8851 C3(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8852 C3(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8853 C3(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8854 C3(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8855 C3(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8856 C3(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8857 C3(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8858 C3(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8859 C3(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8860
8861 C3(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8862 C3(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8863 C3(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8864 C3(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8865 C3(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8866 C3(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8867 C3(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8868 C3(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8869 C3(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8870 C3(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8871 C3(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8872 C3(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8873
8874 CE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
8875 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8876 CE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
8877 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
8878
8879 C3(flts, e000110, 2, (RF, RR), rn_rd),
8880 C3(fltsp, e000130, 2, (RF, RR), rn_rd),
8881 C3(fltsm, e000150, 2, (RF, RR), rn_rd),
8882 C3(fltsz, e000170, 2, (RF, RR), rn_rd),
8883 C3(fltd, e000190, 2, (RF, RR), rn_rd),
8884 C3(fltdp, e0001b0, 2, (RF, RR), rn_rd),
8885 C3(fltdm, e0001d0, 2, (RF, RR), rn_rd),
8886 C3(fltdz, e0001f0, 2, (RF, RR), rn_rd),
8887 C3(flte, e080110, 2, (RF, RR), rn_rd),
8888 C3(fltep, e080130, 2, (RF, RR), rn_rd),
8889 C3(fltem, e080150, 2, (RF, RR), rn_rd),
8890 C3(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 8891
c19d1205
ZW
8892 /* The implementation of the FIX instruction is broken on some
8893 assemblers, in that it accepts a precision specifier as well as a
8894 rounding specifier, despite the fact that this is meaningless.
8895 To be more compatible, we accept it as well, though of course it
8896 does not set any bits. */
8897 CE(fix, e100110, 2, (RR, RF), rd_rm),
8898 C3(fixp, e100130, 2, (RR, RF), rd_rm),
8899 C3(fixm, e100150, 2, (RR, RF), rd_rm),
8900 C3(fixz, e100170, 2, (RR, RF), rd_rm),
8901 C3(fixsp, e100130, 2, (RR, RF), rd_rm),
8902 C3(fixsm, e100150, 2, (RR, RF), rd_rm),
8903 C3(fixsz, e100170, 2, (RR, RF), rd_rm),
8904 C3(fixdp, e100130, 2, (RR, RF), rd_rm),
8905 C3(fixdm, e100150, 2, (RR, RF), rd_rm),
8906 C3(fixdz, e100170, 2, (RR, RF), rd_rm),
8907 C3(fixep, e100130, 2, (RR, RF), rd_rm),
8908 C3(fixem, e100150, 2, (RR, RF), rd_rm),
8909 C3(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 8910
c19d1205
ZW
8911 /* Instructions that were new with the real FPA, call them V2. */
8912#undef ARM_VARIANT
8913#define ARM_VARIANT FPU_FPA_EXT_V2
8914 CE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8915 C3(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8916 C3(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8917 CE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8918 C3(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8919 C3(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8920
8921#undef ARM_VARIANT
8922#define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
8923 /* Moves and type conversions. */
8924 CE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
8925 CE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
8926 CE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
8927 CE(fmstat, ef1fa10, 0, (), noargs),
8928 CE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
8929 CE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
8930 CE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
8931 CE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
8932 CE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
8933 CE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
8934 CE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
8935 CE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
8936
8937 /* Memory operations. */
8938 CE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
8939 CE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
8940 CE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8941 CE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8942 CE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8943 CE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8944 CE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8945 CE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8946 CE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8947 CE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8948 CE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8949 CE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8950 CE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8951 CE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8952 CE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8953 CE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8954 CE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8955 CE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 8956
c19d1205
ZW
8957 /* Monadic operations. */
8958 CE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
8959 CE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
8960 CE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
8961
8962 /* Dyadic operations. */
8963 CE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8964 CE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8965 CE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8966 CE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8967 CE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8968 CE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8969 CE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8970 CE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8971 CE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 8972
c19d1205
ZW
8973 /* Comparisons. */
8974 CE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
8975 CE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
8976 CE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
8977 CE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 8978
c19d1205
ZW
8979#undef ARM_VARIANT
8980#define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
8981 /* Moves and type conversions. */
8982 CE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
8983 CE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
8984 CE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8985 CE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
8986 CE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
8987 CE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
8988 CE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
8989 CE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
8990 CE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
8991 CE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
8992 CE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8993 CE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
8994 CE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8995
8996 /* Memory operations. */
8997 CE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
8998 CE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
8999 CE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9000 CE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9001 CE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9002 CE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9003 CE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9004 CE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9005 CE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9006 CE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9007
c19d1205
ZW
9008 /* Monadic operations. */
9009 CE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9010 CE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9011 CE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9012
9013 /* Dyadic operations. */
9014 CE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9015 CE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9016 CE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9017 CE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9018 CE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9019 CE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9020 CE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9021 CE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9022 CE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9023
c19d1205
ZW
9024 /* Comparisons. */
9025 CE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9026 CE(fcmpzd, eb50b40, 1, (RVD), rd),
9027 CE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9028 CE(fcmpezd, eb50bc0, 1, (RVD), rd),
9029
9030#undef ARM_VARIANT
9031#define ARM_VARIANT FPU_VFP_EXT_V2
9032 CE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9033 CE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9034 CE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9035 CE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9036
9037#undef ARM_VARIANT
9038#define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
9039 CE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9040 CE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9041 CE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9042 CE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9043 CE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9044 CE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9045 CE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9046 CE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9047
9048#undef ARM_VARIANT
9049#define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
9050 CE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9051 CE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9052 CE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9053 CE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9054 CE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9055 CE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9056 CE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9057 CE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9058 CE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9059 CE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9060 CE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9061 CE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9062 CE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9063 CE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9064 CE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9065 CE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9066 CE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9067 CE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9068 CE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9069 CE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9070 CE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9071 CE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9072 CE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9073 CE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9074 CE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9075 CE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9076 CE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9077 CE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9078 CE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9079 CE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9080 CE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9081 CE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9082 CE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9083 CE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9084 CE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9085 CE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9086 CE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9087 CE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9088 CE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9089 CE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9090 CE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9091 CE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9092 CE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9093 CE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9094 CE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9095 CE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9096 CE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9097 CE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9098 CE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9099 CE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9100 CE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9101 CE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9102 CE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9103 CE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9104 CE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9105 CE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9106 CE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9107 CE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9108 CE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9109 CE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9110 CE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9111 CE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9112 CE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9113 CE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9114 CE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9115 CE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9116 CE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9117 CE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9118 CE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9119 CE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9120 CE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9121 CE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9122 CE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9123 CE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9124 CE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9125 CE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9126 CE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9127 CE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9128 CE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9129 CE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9130 CE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9131 CE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9132 CE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9133 CE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9134 CE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9135 CE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9136 CE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9137 CE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9138 CE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9139 CE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9140 CE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9141 CE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9142 CE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9143 CE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9144 CE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9145 CE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9146 CE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9147 CE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9148 CE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9149 CE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9150 CE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9151 CE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9152 CE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9153 CE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9154 CE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9155 CE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9156 CE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9157 CE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9158 CE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9159 CE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9160 CE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9161 CE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9162 CE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9163 CE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9164 CE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9165 CE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9166 CE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9167 CE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9168 CE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9169 CE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9170 CE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9171 CE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9172 CE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9173 CE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9174 CE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9175 CE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9176 CE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9177 CE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9178 CE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9179 CE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9180 CE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9181 CE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9182 CE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9183 CE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9184 CE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9185 CE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9186 CE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9187 CE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9188 CE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9189 CE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9190 CE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9191 CE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9192 CE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9193 CE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9194 CE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9195 CE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9196 CE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9197 CE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9198 CE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9199 CE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9200 CE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9201 CE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9202 CE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9203 CE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9204 CE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9205 CE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9206 CE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9207 CE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9208 CE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9209 CE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9210 CE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9211 CE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
9212
9213#undef ARM_VARIANT
9214#define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
9215 CE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9216 CE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9217 CE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9218 CE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9219 CE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9220 CE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9221 CE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9222 CE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9223 CE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9224 CE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9225 CE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9226 CE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9227 CE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9228 CE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9229 CE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9230 CE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9231 CE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9232 CE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9233 CE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9234 CE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9235 CE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9236 CE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9237 CE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9238 CE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9239 CE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9240 CE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9241 CE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9242 CE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9243 CE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9244 CE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9245 CE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9246 CE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9247 CE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9248 CE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9249 CE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9250 CE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9251 CE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9252 CE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9253 CE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9254 CE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9255 CE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9256 CE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9257 CE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9258 CE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9259 CE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9260 CE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9261 CE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9262 CE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9263 CE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9264 CE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9265 CE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9266 CE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9267 CE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9268 CE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9269 CE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9270 CE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9271 CE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9272 CE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9273 CE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9274 CE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9275 CE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9276 CE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9277 CE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9278 CE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9279 CE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9280 CE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9281 CE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9282 CE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9283 CE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9284 CE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9285 CE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9286 CE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9287 CE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9288 CE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9289 CE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9290 CE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9291};
9292#undef ARM_VARIANT
9293#undef THUMB_VARIANT
9294#undef TCE
9295#undef TCM
9296#undef TUE
9297#undef TUF
9298#undef TCC
9299#undef CE
9300#undef CM
9301#undef UE
9302#undef UF
9303#undef UT
9304#undef OPS0
9305#undef OPS1
9306#undef OPS2
9307#undef OPS3
9308#undef OPS4
9309#undef OPS5
9310#undef OPS6
9311#undef do_0
9312\f
9313/* MD interface: bits in the object file. */
bfae80f2 9314
c19d1205
ZW
9315/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9316 for use in the a.out file, and stores them in the array pointed to by buf.
9317 This knows about the endian-ness of the target machine and does
9318 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9319 2 (short) and 4 (long) Floating numbers are put out as a series of
9320 LITTLENUMS (shorts, here at least). */
b99bd4ef 9321
c19d1205
ZW
9322void
9323md_number_to_chars (char * buf, valueT val, int n)
9324{
9325 if (target_big_endian)
9326 number_to_chars_bigendian (buf, val, n);
9327 else
9328 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
9329}
9330
c19d1205
ZW
9331static valueT
9332md_chars_to_number (char * buf, int n)
bfae80f2 9333{
c19d1205
ZW
9334 valueT result = 0;
9335 unsigned char * where = (unsigned char *) buf;
bfae80f2 9336
c19d1205 9337 if (target_big_endian)
b99bd4ef 9338 {
c19d1205
ZW
9339 while (n--)
9340 {
9341 result <<= 8;
9342 result |= (*where++ & 255);
9343 }
b99bd4ef 9344 }
c19d1205 9345 else
b99bd4ef 9346 {
c19d1205
ZW
9347 while (n--)
9348 {
9349 result <<= 8;
9350 result |= (where[n] & 255);
9351 }
bfae80f2 9352 }
b99bd4ef 9353
c19d1205 9354 return result;
bfae80f2 9355}
b99bd4ef 9356
c19d1205 9357/* MD interface: Sections. */
b99bd4ef 9358
c19d1205
ZW
9359int
9360md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
9361 segT segtype ATTRIBUTE_UNUSED)
9362{
9363 as_fatal (_("md_estimate_size_before_relax\n"));
9364 return 1;
9365}
b99bd4ef 9366
c19d1205 9367/* Round up a section size to the appropriate boundary. */
b99bd4ef 9368
c19d1205
ZW
9369valueT
9370md_section_align (segT segment ATTRIBUTE_UNUSED,
9371 valueT size)
9372{
9373#ifdef OBJ_ELF
9374 return size;
9375#else
9376 /* Round all sects to multiple of 4. */
9377 return (size + 3) & ~3;
9378#endif
bfae80f2 9379}
b99bd4ef 9380
c19d1205
ZW
9381/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
9382 of an rs_align_code fragment. */
9383
9384void
9385arm_handle_align (fragS * fragP)
bfae80f2 9386{
c19d1205
ZW
9387 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
9388 static char const thumb_noop[2] = { 0xc0, 0x46 };
9389 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
9390 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
9391
9392 int bytes, fix, noop_size;
9393 char * p;
9394 const char * noop;
bfae80f2 9395
c19d1205 9396 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
9397 return;
9398
c19d1205
ZW
9399 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
9400 p = fragP->fr_literal + fragP->fr_fix;
9401 fix = 0;
bfae80f2 9402
c19d1205
ZW
9403 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
9404 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 9405
c19d1205 9406 if (fragP->tc_frag_data)
a737bd4d 9407 {
c19d1205
ZW
9408 if (target_big_endian)
9409 noop = thumb_bigend_noop;
9410 else
9411 noop = thumb_noop;
9412 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
9413 }
9414 else
9415 {
c19d1205
ZW
9416 if (target_big_endian)
9417 noop = arm_bigend_noop;
9418 else
9419 noop = arm_noop;
9420 noop_size = sizeof (arm_noop);
7ed4c4c5 9421 }
a737bd4d 9422
c19d1205 9423 if (bytes & (noop_size - 1))
7ed4c4c5 9424 {
c19d1205
ZW
9425 fix = bytes & (noop_size - 1);
9426 memset (p, 0, fix);
9427 p += fix;
9428 bytes -= fix;
a737bd4d 9429 }
a737bd4d 9430
c19d1205 9431 while (bytes >= noop_size)
a737bd4d 9432 {
c19d1205
ZW
9433 memcpy (p, noop, noop_size);
9434 p += noop_size;
9435 bytes -= noop_size;
9436 fix += noop_size;
a737bd4d
NC
9437 }
9438
c19d1205
ZW
9439 fragP->fr_fix += fix;
9440 fragP->fr_var = noop_size;
a737bd4d
NC
9441}
9442
c19d1205
ZW
9443/* Called from md_do_align. Used to create an alignment
9444 frag in a code section. */
9445
9446void
9447arm_frag_align_code (int n, int max)
bfae80f2 9448{
c19d1205 9449 char * p;
7ed4c4c5 9450
c19d1205
ZW
9451 /* We assume that there will never be a requirement
9452 to support alignments greater than 32 bytes. */
9453 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
9454 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 9455
c19d1205
ZW
9456 p = frag_var (rs_align_code,
9457 MAX_MEM_FOR_RS_ALIGN_CODE,
9458 1,
9459 (relax_substateT) max,
9460 (symbolS *) NULL,
9461 (offsetT) n,
9462 (char *) NULL);
9463 *p = 0;
9464}
bfae80f2 9465
c19d1205 9466/* Perform target specific initialisation of a frag. */
bfae80f2 9467
c19d1205
ZW
9468void
9469arm_init_frag (fragS * fragP)
9470{
9471 /* Record whether this frag is in an ARM or a THUMB area. */
9472 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
9473}
9474
c19d1205
ZW
9475#ifdef OBJ_ELF
9476/* When we change sections we need to issue a new mapping symbol. */
9477
9478void
9479arm_elf_change_section (void)
bfae80f2 9480{
c19d1205
ZW
9481 flagword flags;
9482 segment_info_type *seginfo;
bfae80f2 9483
c19d1205
ZW
9484 /* Link an unlinked unwind index table section to the .text section. */
9485 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
9486 && elf_linked_to_section (now_seg) == NULL)
9487 elf_linked_to_section (now_seg) = text_section;
9488
9489 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
9490 return;
9491
c19d1205
ZW
9492 flags = bfd_get_section_flags (stdoutput, now_seg);
9493
9494 /* We can ignore sections that only contain debug info. */
9495 if ((flags & SEC_ALLOC) == 0)
9496 return;
bfae80f2 9497
c19d1205
ZW
9498 seginfo = seg_info (now_seg);
9499 mapstate = seginfo->tc_segment_info_data.mapstate;
9500 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
9501}
9502
c19d1205
ZW
9503int
9504arm_elf_section_type (const char * str, size_t len)
e45d0630 9505{
c19d1205
ZW
9506 if (len == 5 && strncmp (str, "exidx", 5) == 0)
9507 return SHT_ARM_EXIDX;
e45d0630 9508
c19d1205
ZW
9509 return -1;
9510}
9511\f
9512/* Code to deal with unwinding tables. */
e45d0630 9513
c19d1205 9514static void add_unwind_adjustsp (offsetT);
e45d0630 9515
c19d1205 9516/* Cenerate and deferred unwind frame offset. */
e45d0630 9517
bfae80f2 9518static void
c19d1205 9519flush_pending_unwind (void)
bfae80f2 9520{
c19d1205 9521 offsetT offset;
bfae80f2 9522
c19d1205
ZW
9523 offset = unwind.pending_offset;
9524 unwind.pending_offset = 0;
9525 if (offset != 0)
9526 add_unwind_adjustsp (offset);
bfae80f2
RE
9527}
9528
c19d1205
ZW
9529/* Add an opcode to this list for this function. Two-byte opcodes should
9530 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
9531 order. */
9532
bfae80f2 9533static void
c19d1205 9534add_unwind_opcode (valueT op, int length)
bfae80f2 9535{
c19d1205
ZW
9536 /* Add any deferred stack adjustment. */
9537 if (unwind.pending_offset)
9538 flush_pending_unwind ();
bfae80f2 9539
c19d1205 9540 unwind.sp_restored = 0;
bfae80f2 9541
c19d1205 9542 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 9543 {
c19d1205
ZW
9544 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
9545 if (unwind.opcodes)
9546 unwind.opcodes = xrealloc (unwind.opcodes,
9547 unwind.opcode_alloc);
9548 else
9549 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 9550 }
c19d1205 9551 while (length > 0)
bfae80f2 9552 {
c19d1205
ZW
9553 length--;
9554 unwind.opcodes[unwind.opcode_count] = op & 0xff;
9555 op >>= 8;
9556 unwind.opcode_count++;
bfae80f2 9557 }
bfae80f2
RE
9558}
9559
c19d1205
ZW
9560/* Add unwind opcodes to adjust the stack pointer. */
9561
bfae80f2 9562static void
c19d1205 9563add_unwind_adjustsp (offsetT offset)
bfae80f2 9564{
c19d1205 9565 valueT op;
bfae80f2 9566
c19d1205 9567 if (offset > 0x200)
bfae80f2 9568 {
c19d1205
ZW
9569 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
9570 char bytes[5];
9571 int n;
9572 valueT o;
bfae80f2 9573
c19d1205
ZW
9574 /* Long form: 0xb2, uleb128. */
9575 /* This might not fit in a word so add the individual bytes,
9576 remembering the list is built in reverse order. */
9577 o = (valueT) ((offset - 0x204) >> 2);
9578 if (o == 0)
9579 add_unwind_opcode (0, 1);
bfae80f2 9580
c19d1205
ZW
9581 /* Calculate the uleb128 encoding of the offset. */
9582 n = 0;
9583 while (o)
9584 {
9585 bytes[n] = o & 0x7f;
9586 o >>= 7;
9587 if (o)
9588 bytes[n] |= 0x80;
9589 n++;
9590 }
9591 /* Add the insn. */
9592 for (; n; n--)
9593 add_unwind_opcode (bytes[n - 1], 1);
9594 add_unwind_opcode (0xb2, 1);
9595 }
9596 else if (offset > 0x100)
bfae80f2 9597 {
c19d1205
ZW
9598 /* Two short opcodes. */
9599 add_unwind_opcode (0x3f, 1);
9600 op = (offset - 0x104) >> 2;
9601 add_unwind_opcode (op, 1);
bfae80f2 9602 }
c19d1205
ZW
9603 else if (offset > 0)
9604 {
9605 /* Short opcode. */
9606 op = (offset - 4) >> 2;
9607 add_unwind_opcode (op, 1);
9608 }
9609 else if (offset < 0)
bfae80f2 9610 {
c19d1205
ZW
9611 offset = -offset;
9612 while (offset > 0x100)
bfae80f2 9613 {
c19d1205
ZW
9614 add_unwind_opcode (0x7f, 1);
9615 offset -= 0x100;
bfae80f2 9616 }
c19d1205
ZW
9617 op = ((offset - 4) >> 2) | 0x40;
9618 add_unwind_opcode (op, 1);
bfae80f2 9619 }
bfae80f2
RE
9620}
9621
c19d1205
ZW
9622/* Finish the list of unwind opcodes for this function. */
9623static void
9624finish_unwind_opcodes (void)
bfae80f2 9625{
c19d1205 9626 valueT op;
bfae80f2 9627
c19d1205 9628 if (unwind.fp_used)
bfae80f2 9629 {
c19d1205
ZW
9630 /* Adjust sp as neccessary. */
9631 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
9632 flush_pending_unwind ();
bfae80f2 9633
c19d1205
ZW
9634 /* After restoring sp from the frame pointer. */
9635 op = 0x90 | unwind.fp_reg;
9636 add_unwind_opcode (op, 1);
9637 }
9638 else
9639 flush_pending_unwind ();
bfae80f2
RE
9640}
9641
bfae80f2 9642
c19d1205
ZW
9643/* Start an exception table entry. If idx is nonzero this is an index table
9644 entry. */
bfae80f2
RE
9645
9646static void
c19d1205 9647start_unwind_section (const segT text_seg, int idx)
bfae80f2 9648{
c19d1205
ZW
9649 const char * text_name;
9650 const char * prefix;
9651 const char * prefix_once;
9652 const char * group_name;
9653 size_t prefix_len;
9654 size_t text_len;
9655 char * sec_name;
9656 size_t sec_name_len;
9657 int type;
9658 int flags;
9659 int linkonce;
bfae80f2 9660
c19d1205 9661 if (idx)
bfae80f2 9662 {
c19d1205
ZW
9663 prefix = ELF_STRING_ARM_unwind;
9664 prefix_once = ELF_STRING_ARM_unwind_once;
9665 type = SHT_ARM_EXIDX;
bfae80f2 9666 }
c19d1205 9667 else
bfae80f2 9668 {
c19d1205
ZW
9669 prefix = ELF_STRING_ARM_unwind_info;
9670 prefix_once = ELF_STRING_ARM_unwind_info_once;
9671 type = SHT_PROGBITS;
bfae80f2
RE
9672 }
9673
c19d1205
ZW
9674 text_name = segment_name (text_seg);
9675 if (streq (text_name, ".text"))
9676 text_name = "";
9677
9678 if (strncmp (text_name, ".gnu.linkonce.t.",
9679 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 9680 {
c19d1205
ZW
9681 prefix = prefix_once;
9682 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
9683 }
9684
c19d1205
ZW
9685 prefix_len = strlen (prefix);
9686 text_len = strlen (text_name);
9687 sec_name_len = prefix_len + text_len;
9688 sec_name = xmalloc (sec_name_len + 1);
9689 memcpy (sec_name, prefix, prefix_len);
9690 memcpy (sec_name + prefix_len, text_name, text_len);
9691 sec_name[prefix_len + text_len] = '\0';
bfae80f2 9692
c19d1205
ZW
9693 flags = SHF_ALLOC;
9694 linkonce = 0;
9695 group_name = 0;
bfae80f2 9696
c19d1205
ZW
9697 /* Handle COMDAT group. */
9698 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 9699 {
c19d1205
ZW
9700 group_name = elf_group_name (text_seg);
9701 if (group_name == NULL)
9702 {
9703 as_bad ("Group section `%s' has no group signature",
9704 segment_name (text_seg));
9705 ignore_rest_of_line ();
9706 return;
9707 }
9708 flags |= SHF_GROUP;
9709 linkonce = 1;
bfae80f2
RE
9710 }
9711
c19d1205 9712 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 9713
c19d1205
ZW
9714 /* Set the setion link for index tables. */
9715 if (idx)
9716 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
9717}
9718
bfae80f2 9719
c19d1205
ZW
9720/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
9721 personality routine data. Returns zero, or the index table value for
9722 and inline entry. */
9723
9724static valueT
9725create_unwind_entry (int have_data)
bfae80f2 9726{
c19d1205
ZW
9727 int size;
9728 addressT where;
9729 char *ptr;
9730 /* The current word of data. */
9731 valueT data;
9732 /* The number of bytes left in this word. */
9733 int n;
bfae80f2 9734
c19d1205 9735 finish_unwind_opcodes ();
bfae80f2 9736
c19d1205
ZW
9737 /* Remember the current text section. */
9738 unwind.saved_seg = now_seg;
9739 unwind.saved_subseg = now_subseg;
bfae80f2 9740
c19d1205 9741 start_unwind_section (now_seg, 0);
bfae80f2 9742
c19d1205 9743 if (unwind.personality_routine == NULL)
bfae80f2 9744 {
c19d1205
ZW
9745 if (unwind.personality_index == -2)
9746 {
9747 if (have_data)
9748 as_bad (_("handerdata in cantunwind frame"));
9749 return 1; /* EXIDX_CANTUNWIND. */
9750 }
bfae80f2 9751
c19d1205
ZW
9752 /* Use a default personality routine if none is specified. */
9753 if (unwind.personality_index == -1)
9754 {
9755 if (unwind.opcode_count > 3)
9756 unwind.personality_index = 1;
9757 else
9758 unwind.personality_index = 0;
9759 }
bfae80f2 9760
c19d1205
ZW
9761 /* Space for the personality routine entry. */
9762 if (unwind.personality_index == 0)
9763 {
9764 if (unwind.opcode_count > 3)
9765 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 9766
c19d1205
ZW
9767 if (!have_data)
9768 {
9769 /* All the data is inline in the index table. */
9770 data = 0x80;
9771 n = 3;
9772 while (unwind.opcode_count > 0)
9773 {
9774 unwind.opcode_count--;
9775 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9776 n--;
9777 }
bfae80f2 9778
c19d1205
ZW
9779 /* Pad with "finish" opcodes. */
9780 while (n--)
9781 data = (data << 8) | 0xb0;
bfae80f2 9782
c19d1205
ZW
9783 return data;
9784 }
9785 size = 0;
9786 }
9787 else
9788 /* We get two opcodes "free" in the first word. */
9789 size = unwind.opcode_count - 2;
9790 }
9791 else
9792 /* An extra byte is required for the opcode count. */
9793 size = unwind.opcode_count + 1;
bfae80f2 9794
c19d1205
ZW
9795 size = (size + 3) >> 2;
9796 if (size > 0xff)
9797 as_bad (_("too many unwind opcodes"));
bfae80f2 9798
c19d1205
ZW
9799 frag_align (2, 0, 0);
9800 record_alignment (now_seg, 2);
9801 unwind.table_entry = expr_build_dot ();
9802
9803 /* Allocate the table entry. */
9804 ptr = frag_more ((size << 2) + 4);
9805 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 9806
c19d1205 9807 switch (unwind.personality_index)
bfae80f2 9808 {
c19d1205
ZW
9809 case -1:
9810 /* ??? Should this be a PLT generating relocation? */
9811 /* Custom personality routine. */
9812 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
9813 BFD_RELOC_ARM_PREL31);
bfae80f2 9814
c19d1205
ZW
9815 where += 4;
9816 ptr += 4;
bfae80f2 9817
c19d1205
ZW
9818 /* Set the first byte to the number of additional words. */
9819 data = size - 1;
9820 n = 3;
9821 break;
bfae80f2 9822
c19d1205
ZW
9823 /* ABI defined personality routines. */
9824 case 0:
9825 /* Three opcodes bytes are packed into the first word. */
9826 data = 0x80;
9827 n = 3;
9828 break;
bfae80f2 9829
c19d1205
ZW
9830 case 1:
9831 case 2:
9832 /* The size and first two opcode bytes go in the first word. */
9833 data = ((0x80 + unwind.personality_index) << 8) | size;
9834 n = 2;
9835 break;
bfae80f2 9836
c19d1205
ZW
9837 default:
9838 /* Should never happen. */
9839 abort ();
9840 }
bfae80f2 9841
c19d1205
ZW
9842 /* Pack the opcodes into words (MSB first), reversing the list at the same
9843 time. */
9844 while (unwind.opcode_count > 0)
9845 {
9846 if (n == 0)
9847 {
9848 md_number_to_chars (ptr, data, 4);
9849 ptr += 4;
9850 n = 4;
9851 data = 0;
9852 }
9853 unwind.opcode_count--;
9854 n--;
9855 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9856 }
9857
9858 /* Finish off the last word. */
9859 if (n < 4)
9860 {
9861 /* Pad with "finish" opcodes. */
9862 while (n--)
9863 data = (data << 8) | 0xb0;
9864
9865 md_number_to_chars (ptr, data, 4);
9866 }
9867
9868 if (!have_data)
9869 {
9870 /* Add an empty descriptor if there is no user-specified data. */
9871 ptr = frag_more (4);
9872 md_number_to_chars (ptr, 0, 4);
9873 }
9874
9875 return 0;
bfae80f2
RE
9876}
9877
c19d1205
ZW
9878/* Convert REGNAME to a DWARF-2 register number. */
9879
9880int
9881tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 9882{
c19d1205
ZW
9883 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
9884
9885 if (reg == FAIL)
9886 return -1;
9887
9888 return reg;
bfae80f2
RE
9889}
9890
c19d1205
ZW
9891/* Initialize the DWARF-2 unwind information for this procedure. */
9892
9893void
9894tc_arm_frame_initial_instructions (void)
bfae80f2 9895{
c19d1205 9896 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 9897}
c19d1205 9898#endif /* OBJ_ELF */
bfae80f2 9899
bfae80f2 9900
c19d1205 9901/* MD interface: Symbol and relocation handling. */
bfae80f2 9902
c19d1205
ZW
9903/* The knowledge of the PC's pipeline offset is built into the insns
9904 themselves. */
bfae80f2 9905
c19d1205
ZW
9906long
9907md_pcrel_from (fixS * fixP)
bfae80f2 9908{
c19d1205
ZW
9909 if (fixP->fx_addsy
9910 && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section
9911 && fixP->fx_subsy == NULL)
9912 return 0;
bfae80f2 9913
c19d1205
ZW
9914 /* PC relative addressing on the Thumb is slightly odd as the bottom
9915 two bits of the PC are forced to zero for the calculation. This
9916 happens *after* application of the pipeline offset. However,
9917 Thumb adrl already adjusts for this, so we need not do it again. */
9918 switch (fixP->fx_r_type)
bfae80f2 9919 {
c19d1205
ZW
9920 case BFD_RELOC_ARM_THUMB_ADD:
9921 return (fixP->fx_where + fixP->fx_frag->fr_address) & ~3;
9922
9923 case BFD_RELOC_ARM_THUMB_OFFSET:
9924 case BFD_RELOC_ARM_T32_OFFSET_IMM:
9925 return (fixP->fx_where + fixP->fx_frag->fr_address + 4) & ~3;
9926
9927 default:
9928 break;
bfae80f2
RE
9929 }
9930
c19d1205
ZW
9931#ifdef TE_WINCE
9932 /* The pattern was adjusted to accommodate CE's off-by-one fixups,
9933 so we un-adjust here to compensate for the accommodation. */
9934 return fixP->fx_where + fixP->fx_frag->fr_address + 8;
9935#else
9936 return fixP->fx_where + fixP->fx_frag->fr_address;
9937#endif
bfae80f2
RE
9938}
9939
c19d1205
ZW
9940/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
9941 Otherwise we have no need to default values of symbols. */
9942
9943symbolS *
9944md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 9945{
c19d1205
ZW
9946#ifdef OBJ_ELF
9947 if (name[0] == '_' && name[1] == 'G'
9948 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
9949 {
9950 if (!GOT_symbol)
9951 {
9952 if (symbol_find (name))
9953 as_bad ("GOT already in the symbol table");
bfae80f2 9954
c19d1205
ZW
9955 GOT_symbol = symbol_new (name, undefined_section,
9956 (valueT) 0, & zero_address_frag);
9957 }
bfae80f2 9958
c19d1205 9959 return GOT_symbol;
bfae80f2 9960 }
c19d1205 9961#endif
bfae80f2 9962
c19d1205 9963 return 0;
bfae80f2
RE
9964}
9965
55cf6793 9966/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
9967 computed as two separate immediate values, added together. We
9968 already know that this value cannot be computed by just one ARM
9969 instruction. */
9970
9971static unsigned int
9972validate_immediate_twopart (unsigned int val,
9973 unsigned int * highpart)
bfae80f2 9974{
c19d1205
ZW
9975 unsigned int a;
9976 unsigned int i;
bfae80f2 9977
c19d1205
ZW
9978 for (i = 0; i < 32; i += 2)
9979 if (((a = rotate_left (val, i)) & 0xff) != 0)
9980 {
9981 if (a & 0xff00)
9982 {
9983 if (a & ~ 0xffff)
9984 continue;
9985 * highpart = (a >> 8) | ((i + 24) << 7);
9986 }
9987 else if (a & 0xff0000)
9988 {
9989 if (a & 0xff000000)
9990 continue;
9991 * highpart = (a >> 16) | ((i + 16) << 7);
9992 }
9993 else
9994 {
9995 assert (a & 0xff000000);
9996 * highpart = (a >> 24) | ((i + 8) << 7);
9997 }
bfae80f2 9998
c19d1205
ZW
9999 return (a & 0xff) | (i << 7);
10000 }
bfae80f2 10001
c19d1205 10002 return FAIL;
bfae80f2
RE
10003}
10004
c19d1205
ZW
10005static int
10006validate_offset_imm (unsigned int val, int hwse)
10007{
10008 if ((hwse && val > 255) || val > 4095)
10009 return FAIL;
10010 return val;
10011}
bfae80f2 10012
55cf6793 10013/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
10014 negative immediate constant by altering the instruction. A bit of
10015 a hack really.
10016 MOV <-> MVN
10017 AND <-> BIC
10018 ADC <-> SBC
10019 by inverting the second operand, and
10020 ADD <-> SUB
10021 CMP <-> CMN
10022 by negating the second operand. */
bfae80f2 10023
c19d1205
ZW
10024static int
10025negate_data_op (unsigned long * instruction,
10026 unsigned long value)
bfae80f2 10027{
c19d1205
ZW
10028 int op, new_inst;
10029 unsigned long negated, inverted;
bfae80f2 10030
c19d1205
ZW
10031 negated = encode_arm_immediate (-value);
10032 inverted = encode_arm_immediate (~value);
bfae80f2 10033
c19d1205
ZW
10034 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10035 switch (op)
bfae80f2 10036 {
c19d1205
ZW
10037 /* First negates. */
10038 case OPCODE_SUB: /* ADD <-> SUB */
10039 new_inst = OPCODE_ADD;
10040 value = negated;
10041 break;
bfae80f2 10042
c19d1205
ZW
10043 case OPCODE_ADD:
10044 new_inst = OPCODE_SUB;
10045 value = negated;
10046 break;
bfae80f2 10047
c19d1205
ZW
10048 case OPCODE_CMP: /* CMP <-> CMN */
10049 new_inst = OPCODE_CMN;
10050 value = negated;
10051 break;
bfae80f2 10052
c19d1205
ZW
10053 case OPCODE_CMN:
10054 new_inst = OPCODE_CMP;
10055 value = negated;
10056 break;
bfae80f2 10057
c19d1205
ZW
10058 /* Now Inverted ops. */
10059 case OPCODE_MOV: /* MOV <-> MVN */
10060 new_inst = OPCODE_MVN;
10061 value = inverted;
10062 break;
bfae80f2 10063
c19d1205
ZW
10064 case OPCODE_MVN:
10065 new_inst = OPCODE_MOV;
10066 value = inverted;
10067 break;
bfae80f2 10068
c19d1205
ZW
10069 case OPCODE_AND: /* AND <-> BIC */
10070 new_inst = OPCODE_BIC;
10071 value = inverted;
10072 break;
bfae80f2 10073
c19d1205
ZW
10074 case OPCODE_BIC:
10075 new_inst = OPCODE_AND;
10076 value = inverted;
10077 break;
bfae80f2 10078
c19d1205
ZW
10079 case OPCODE_ADC: /* ADC <-> SBC */
10080 new_inst = OPCODE_SBC;
10081 value = inverted;
10082 break;
bfae80f2 10083
c19d1205
ZW
10084 case OPCODE_SBC:
10085 new_inst = OPCODE_ADC;
10086 value = inverted;
10087 break;
bfae80f2 10088
c19d1205
ZW
10089 /* We cannot do anything. */
10090 default:
10091 return FAIL;
b99bd4ef
NC
10092 }
10093
c19d1205
ZW
10094 if (value == (unsigned) FAIL)
10095 return FAIL;
10096
10097 *instruction &= OPCODE_MASK;
10098 *instruction |= new_inst << DATA_OP_SHIFT;
10099 return value;
b99bd4ef
NC
10100}
10101
c19d1205 10102void
55cf6793 10103md_apply_fix (fixS * fixP,
c19d1205
ZW
10104 valueT * valP,
10105 segT seg)
10106{
10107 offsetT value = * valP;
10108 offsetT newval;
10109 unsigned int newimm;
10110 unsigned long temp;
10111 int sign;
10112 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 10113
c19d1205 10114 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 10115
c19d1205
ZW
10116 /* Note whether this will delete the relocation. */
10117 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
10118 fixP->fx_done = 1;
b99bd4ef 10119
c19d1205
ZW
10120 /* If this symbol is in a different section then we need to leave it for
10121 the linker to deal with. Unfortunately, md_pcrel_from can't tell,
10122 so we have to undo its effects here. */
10123 if (fixP->fx_pcrel)
b99bd4ef 10124 {
c19d1205
ZW
10125 if (fixP->fx_addsy != NULL
10126 && S_IS_DEFINED (fixP->fx_addsy)
10127 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10128 value += md_pcrel_from (fixP);
b99bd4ef
NC
10129 }
10130
adbaf948
ZW
10131 /* On a 64-bit host, silently truncate 'value' to 32 bits for
10132 consistency with the behavior on 32-bit hosts. Remember value
10133 for emit_reloc. */
10134 value &= 0xffffffff;
10135 value ^= 0x80000000;
10136 value -= 0x80000000;
10137
10138 *valP = value;
c19d1205 10139 fixP->fx_addnumber = value;
b99bd4ef 10140
adbaf948
ZW
10141 /* Same treatment for fixP->fx_offset. */
10142 fixP->fx_offset &= 0xffffffff;
10143 fixP->fx_offset ^= 0x80000000;
10144 fixP->fx_offset -= 0x80000000;
10145
c19d1205 10146 switch (fixP->fx_r_type)
b99bd4ef 10147 {
c19d1205
ZW
10148 case BFD_RELOC_NONE:
10149 /* This will need to go in the object file. */
10150 fixP->fx_done = 0;
10151 break;
b99bd4ef 10152
c19d1205
ZW
10153 case BFD_RELOC_ARM_IMMEDIATE:
10154 /* We claim that this fixup has been processed here,
10155 even if in fact we generate an error because we do
10156 not have a reloc for it, so tc_gen_reloc will reject it. */
10157 fixP->fx_done = 1;
b99bd4ef 10158
c19d1205
ZW
10159 if (fixP->fx_addsy
10160 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 10161 {
c19d1205
ZW
10162 as_bad_where (fixP->fx_file, fixP->fx_line,
10163 _("undefined symbol %s used as an immediate value"),
10164 S_GET_NAME (fixP->fx_addsy));
10165 break;
b99bd4ef
NC
10166 }
10167
c19d1205
ZW
10168 newimm = encode_arm_immediate (value);
10169 temp = md_chars_to_number (buf, INSN_SIZE);
10170
10171 /* If the instruction will fail, see if we can fix things up by
10172 changing the opcode. */
10173 if (newimm == (unsigned int) FAIL
10174 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 10175 {
c19d1205
ZW
10176 as_bad_where (fixP->fx_file, fixP->fx_line,
10177 _("invalid constant (%lx) after fixup"),
10178 (unsigned long) value);
10179 break;
b99bd4ef 10180 }
b99bd4ef 10181
c19d1205
ZW
10182 newimm |= (temp & 0xfffff000);
10183 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
10184 break;
b99bd4ef 10185
c19d1205
ZW
10186 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
10187 {
10188 unsigned int highpart = 0;
10189 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 10190
c19d1205
ZW
10191 newimm = encode_arm_immediate (value);
10192 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 10193
c19d1205
ZW
10194 /* If the instruction will fail, see if we can fix things up by
10195 changing the opcode. */
10196 if (newimm == (unsigned int) FAIL
10197 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
10198 {
10199 /* No ? OK - try using two ADD instructions to generate
10200 the value. */
10201 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 10202
c19d1205
ZW
10203 /* Yes - then make sure that the second instruction is
10204 also an add. */
10205 if (newimm != (unsigned int) FAIL)
10206 newinsn = temp;
10207 /* Still No ? Try using a negated value. */
10208 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
10209 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
10210 /* Otherwise - give up. */
10211 else
10212 {
10213 as_bad_where (fixP->fx_file, fixP->fx_line,
10214 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
10215 (long) value);
10216 break;
10217 }
b99bd4ef 10218
c19d1205
ZW
10219 /* Replace the first operand in the 2nd instruction (which
10220 is the PC) with the destination register. We have
10221 already added in the PC in the first instruction and we
10222 do not want to do it again. */
10223 newinsn &= ~ 0xf0000;
10224 newinsn |= ((newinsn & 0x0f000) << 4);
10225 }
b99bd4ef 10226
c19d1205
ZW
10227 newimm |= (temp & 0xfffff000);
10228 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 10229
c19d1205
ZW
10230 highpart |= (newinsn & 0xfffff000);
10231 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
10232 }
10233 break;
b99bd4ef 10234
c19d1205
ZW
10235 case BFD_RELOC_ARM_OFFSET_IMM:
10236 case BFD_RELOC_ARM_LITERAL:
10237 sign = value >= 0;
b99bd4ef 10238
c19d1205
ZW
10239 if (value < 0)
10240 value = - value;
b99bd4ef 10241
c19d1205 10242 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 10243 {
c19d1205
ZW
10244 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
10245 as_bad_where (fixP->fx_file, fixP->fx_line,
10246 _("invalid literal constant: pool needs to be closer"));
10247 else
10248 as_bad_where (fixP->fx_file, fixP->fx_line,
10249 _("bad immediate value for offset (%ld)"),
10250 (long) value);
10251 break;
f03698e6
RE
10252 }
10253
c19d1205
ZW
10254 newval = md_chars_to_number (buf, INSN_SIZE);
10255 newval &= 0xff7ff000;
10256 newval |= value | (sign ? INDEX_UP : 0);
10257 md_number_to_chars (buf, newval, INSN_SIZE);
10258 break;
b99bd4ef 10259
c19d1205
ZW
10260 case BFD_RELOC_ARM_OFFSET_IMM8:
10261 case BFD_RELOC_ARM_HWLITERAL:
10262 sign = value >= 0;
b99bd4ef 10263
c19d1205
ZW
10264 if (value < 0)
10265 value = - value;
b99bd4ef 10266
c19d1205 10267 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 10268 {
c19d1205
ZW
10269 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
10270 as_bad_where (fixP->fx_file, fixP->fx_line,
10271 _("invalid literal constant: pool needs to be closer"));
10272 else
10273 as_bad (_("bad immediate value for half-word offset (%ld)"),
10274 (long) value);
10275 break;
b99bd4ef
NC
10276 }
10277
c19d1205
ZW
10278 newval = md_chars_to_number (buf, INSN_SIZE);
10279 newval &= 0xff7ff0f0;
10280 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
10281 md_number_to_chars (buf, newval, INSN_SIZE);
10282 break;
b99bd4ef 10283
c19d1205
ZW
10284 case BFD_RELOC_ARM_T32_OFFSET_U8:
10285 if (value < 0 || value > 1020 || value % 4 != 0)
10286 as_bad_where (fixP->fx_file, fixP->fx_line,
10287 _("bad immediate value for offset (%ld)"), (long) value);
10288 value /= 4;
b99bd4ef 10289
c19d1205
ZW
10290 newval = md_chars_to_number (buf+2, THUMB_SIZE);
10291 newval &= 0xff00;
10292 newval |= value;
10293 md_number_to_chars (buf+2, newval, THUMB_SIZE);
10294 break;
b99bd4ef 10295
c19d1205
ZW
10296 case BFD_RELOC_ARM_T32_OFFSET_IMM:
10297 /* This is a complicated relocation used for all varieties of Thumb32
10298 load/store instruction with immediate offset:
10299
10300 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
10301 *4, optional writeback(W)
10302 (doubleword load/store)
10303
10304 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
10305 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
10306 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
10307 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
10308 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
10309
10310 Uppercase letters indicate bits that are already encoded at
10311 this point. Lowercase letters are our problem. For the
10312 second block of instructions, the secondary opcode nybble
10313 (bits 8..11) is present, and bit 23 is zero, even if this is
10314 a PC-relative operation. */
10315 newval = md_chars_to_number (buf, THUMB_SIZE);
10316 newval <<= 16;
10317 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 10318
c19d1205 10319 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 10320 {
c19d1205
ZW
10321 /* Doubleword load/store: 8-bit offset, scaled by 4. */
10322 if (value >= 0)
10323 newval |= (1 << 23);
10324 else
10325 value = -value;
10326 if (value % 4 != 0)
10327 {
10328 as_bad_where (fixP->fx_file, fixP->fx_line,
10329 _("offset not a multiple of 4"));
10330 break;
10331 }
10332 value /= 4;
10333 if (value >= 0xff)
10334 {
10335 as_bad_where (fixP->fx_file, fixP->fx_line,
10336 _("offset out of range"));
10337 break;
10338 }
10339 newval &= ~0xff;
b99bd4ef 10340 }
c19d1205 10341 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 10342 {
c19d1205
ZW
10343 /* PC-relative, 12-bit offset. */
10344 if (value >= 0)
10345 newval |= (1 << 23);
10346 else
10347 value = -value;
10348 if (value >= 0xfff)
10349 {
10350 as_bad_where (fixP->fx_file, fixP->fx_line,
10351 _("offset out of range"));
10352 break;
10353 }
10354 newval &= ~0xfff;
b99bd4ef 10355 }
c19d1205 10356 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 10357 {
c19d1205
ZW
10358 /* Writeback: 8-bit, +/- offset. */
10359 if (value >= 0)
10360 newval |= (1 << 9);
10361 else
10362 value = -value;
10363 if (value >= 0xff)
10364 {
10365 as_bad_where (fixP->fx_file, fixP->fx_line,
10366 _("offset out of range"));
10367 break;
10368 }
10369 newval &= ~0xff;
b99bd4ef 10370 }
c19d1205 10371 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 10372 {
c19d1205
ZW
10373 /* T-instruction: positive 8-bit offset. */
10374 if (value < 0 || value >= 0xff)
b99bd4ef 10375 {
c19d1205
ZW
10376 as_bad_where (fixP->fx_file, fixP->fx_line,
10377 _("offset out of range"));
10378 break;
b99bd4ef 10379 }
c19d1205
ZW
10380 newval &= ~0xff;
10381 newval |= value;
b99bd4ef
NC
10382 }
10383 else
b99bd4ef 10384 {
c19d1205
ZW
10385 /* Positive 12-bit or negative 8-bit offset. */
10386 int limit;
10387 if (value >= 0)
b99bd4ef 10388 {
c19d1205
ZW
10389 newval |= (1 << 23);
10390 limit = 0xfff;
10391 }
10392 else
10393 {
10394 value = -value;
10395 limit = 0xff;
10396 }
10397 if (value > limit)
10398 {
10399 as_bad_where (fixP->fx_file, fixP->fx_line,
10400 _("offset out of range"));
10401 break;
b99bd4ef 10402 }
c19d1205 10403 newval &= ~limit;
b99bd4ef 10404 }
b99bd4ef 10405
c19d1205
ZW
10406 newval |= value;
10407 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
10408 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
10409 break;
404ff6b5 10410
c19d1205
ZW
10411 case BFD_RELOC_ARM_SHIFT_IMM:
10412 newval = md_chars_to_number (buf, INSN_SIZE);
10413 if (((unsigned long) value) > 32
10414 || (value == 32
10415 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
10416 {
10417 as_bad_where (fixP->fx_file, fixP->fx_line,
10418 _("shift expression is too large"));
10419 break;
10420 }
404ff6b5 10421
c19d1205
ZW
10422 if (value == 0)
10423 /* Shifts of zero must be done as lsl. */
10424 newval &= ~0x60;
10425 else if (value == 32)
10426 value = 0;
10427 newval &= 0xfffff07f;
10428 newval |= (value & 0x1f) << 7;
10429 md_number_to_chars (buf, newval, INSN_SIZE);
10430 break;
404ff6b5 10431
c19d1205
ZW
10432 case BFD_RELOC_ARM_T32_IMMEDIATE:
10433 /* We claim that this fixup has been processed here,
10434 even if in fact we generate an error because we do
10435 not have a reloc for it, so tc_gen_reloc will reject it. */
10436 fixP->fx_done = 1;
404ff6b5 10437
c19d1205
ZW
10438 if (fixP->fx_addsy
10439 && ! S_IS_DEFINED (fixP->fx_addsy))
10440 {
10441 as_bad_where (fixP->fx_file, fixP->fx_line,
10442 _("undefined symbol %s used as an immediate value"),
10443 S_GET_NAME (fixP->fx_addsy));
10444 break;
10445 }
404ff6b5 10446
c19d1205
ZW
10447 newval = md_chars_to_number (buf, THUMB_SIZE);
10448 newval <<= 16;
10449 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 10450
c19d1205 10451 newimm = encode_thumb32_immediate (value);
cc8a6dd0 10452
c19d1205
ZW
10453 /* FUTURE: Implement analogue of negate_data_op for T32. */
10454 if (newimm == (unsigned int)FAIL)
3631a3c8 10455 {
c19d1205
ZW
10456 as_bad_where (fixP->fx_file, fixP->fx_line,
10457 _("invalid constant (%lx) after fixup"),
10458 (unsigned long) value);
10459 break;
3631a3c8
NC
10460 }
10461
c19d1205
ZW
10462 newval &= 0xfbff8f00;
10463 newval |= (newimm & 0x800) << 15;
10464 newval |= (newimm & 0x700) << 4;
10465 newval |= (newimm & 0x0ff);
cc8a6dd0 10466
c19d1205
ZW
10467 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
10468 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
10469 break;
a737bd4d 10470
c19d1205
ZW
10471 case BFD_RELOC_ARM_SMI:
10472 if (((unsigned long) value) > 0xffff)
10473 as_bad_where (fixP->fx_file, fixP->fx_line,
10474 _("invalid smi expression"));
10475 newval = md_chars_to_number (buf, INSN_SIZE) & 0xfff000f0;
10476 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
10477 md_number_to_chars (buf, newval, INSN_SIZE);
10478 break;
a737bd4d 10479
c19d1205 10480 case BFD_RELOC_ARM_SWI:
adbaf948 10481 if (fixP->tc_fix_data != 0)
c19d1205
ZW
10482 {
10483 if (((unsigned long) value) > 0xff)
10484 as_bad_where (fixP->fx_file, fixP->fx_line,
10485 _("invalid swi expression"));
10486 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xff00;
10487 newval |= value;
10488 md_number_to_chars (buf, newval, THUMB_SIZE);
10489 }
10490 else
10491 {
10492 if (((unsigned long) value) > 0x00ffffff)
10493 as_bad_where (fixP->fx_file, fixP->fx_line,
10494 _("invalid swi expression"));
10495 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff000000;
10496 newval |= value;
10497 md_number_to_chars (buf, newval, INSN_SIZE);
10498 }
10499 break;
a737bd4d 10500
c19d1205
ZW
10501 case BFD_RELOC_ARM_MULTI:
10502 if (((unsigned long) value) > 0xffff)
10503 as_bad_where (fixP->fx_file, fixP->fx_line,
10504 _("invalid expression in load/store multiple"));
10505 newval = value | md_chars_to_number (buf, INSN_SIZE);
10506 md_number_to_chars (buf, newval, INSN_SIZE);
10507 break;
a737bd4d 10508
c19d1205
ZW
10509 case BFD_RELOC_ARM_PCREL_BRANCH:
10510 newval = md_chars_to_number (buf, INSN_SIZE);
a737bd4d 10511
c19d1205
ZW
10512 /* Sign-extend a 24-bit number. */
10513#define SEXT24(x) ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000)
a737bd4d 10514
c19d1205 10515#ifdef OBJ_ELF
05ab1f3b 10516 value = fixP->fx_offset;
c19d1205 10517#endif
a737bd4d 10518
c19d1205
ZW
10519 /* We are going to store value (shifted right by two) in the
10520 instruction, in a 24 bit, signed field Thus we need to check
10521 that none of the top 8 bits of the shifted value (top 7 bits of
10522 the unshifted, unsigned value) are set, or that they are all set. */
10523 if ((value & ~ ((offsetT) 0x1ffffff)) != 0
10524 && ((value & ~ ((offsetT) 0x1ffffff)) != ~ ((offsetT) 0x1ffffff)))
10525 {
10526#ifdef OBJ_ELF
10527 /* Normally we would be stuck at this point, since we cannot store
10528 the absolute address that is the destination of the branch in the
10529 24 bits of the branch instruction. If however, we happen to know
10530 that the destination of the branch is in the same section as the
10531 branch instruction itself, then we can compute the relocation for
10532 ourselves and not have to bother the linker with it.
a737bd4d 10533
c19d1205
ZW
10534 FIXME: The test for OBJ_ELF is only here because I have not
10535 worked out how to do this for OBJ_COFF. */
10536 if (fixP->fx_addsy != NULL
10537 && S_IS_DEFINED (fixP->fx_addsy)
10538 && S_GET_SEGMENT (fixP->fx_addsy) == seg)
10539 {
10540 /* Get pc relative value to go into the branch. */
10541 value = * valP;
a737bd4d 10542
c19d1205
ZW
10543 /* Permit a backward branch provided that enough bits
10544 are set. Allow a forwards branch, provided that
10545 enough bits are clear. */
10546 if ( (value & ~ ((offsetT) 0x1ffffff)) == ~ ((offsetT) 0x1ffffff)
10547 || (value & ~ ((offsetT) 0x1ffffff)) == 0)
10548 fixP->fx_done = 1;
10549 }
a737bd4d 10550
c19d1205
ZW
10551 if (! fixP->fx_done)
10552#endif
10553 as_bad_where (fixP->fx_file, fixP->fx_line,
10554 _("GAS can't handle same-section branch dest >= 0x04000000"));
10555 }
a737bd4d 10556
c19d1205
ZW
10557 value >>= 2;
10558 value += SEXT24 (newval);
a737bd4d 10559
c19d1205
ZW
10560 if ( (value & ~ ((offsetT) 0xffffff)) != 0
10561 && ((value & ~ ((offsetT) 0xffffff)) != ~ ((offsetT) 0xffffff)))
10562 as_bad_where (fixP->fx_file, fixP->fx_line,
10563 _("out of range branch"));
a737bd4d 10564
c19d1205
ZW
10565 if (seg->use_rela_p && !fixP->fx_done)
10566 {
10567 /* Must unshift the value before storing it in the addend. */
10568 value <<= 2;
10569#ifdef OBJ_ELF
10570 fixP->fx_offset = value;
10571#endif
10572 fixP->fx_addnumber = value;
10573 newval = newval & 0xff000000;
10574 }
10575 else
10576 newval = (value & 0x00ffffff) | (newval & 0xff000000);
10577 md_number_to_chars (buf, newval, INSN_SIZE);
10578 break;
a737bd4d 10579
c19d1205
ZW
10580 case BFD_RELOC_ARM_PCREL_BLX:
10581 {
10582 offsetT hbit;
10583 newval = md_chars_to_number (buf, INSN_SIZE);
a737bd4d 10584
c19d1205 10585#ifdef OBJ_ELF
05ab1f3b 10586 value = fixP->fx_offset;
c19d1205
ZW
10587#endif
10588 hbit = (value >> 1) & 1;
10589 value = (value >> 2) & 0x00ffffff;
10590 value = (value + (newval & 0x00ffffff)) & 0x00ffffff;
a737bd4d 10591
c19d1205
ZW
10592 if (seg->use_rela_p && !fixP->fx_done)
10593 {
10594 /* Must sign-extend and unshift the value before storing
10595 it in the addend. */
10596 value = SEXT24 (value);
10597 value = (value << 2) | hbit;
10598#ifdef OBJ_ELF
10599 fixP->fx_offset = value;
10600#endif
10601 fixP->fx_addnumber = value;
10602 newval = newval & 0xfe000000;
10603 }
10604 else
10605 newval = value | (newval & 0xfe000000) | (hbit << 24);
10606 md_number_to_chars (buf, newval, INSN_SIZE);
10607 }
10608 break;
a737bd4d 10609
c19d1205
ZW
10610 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
10611 newval = md_chars_to_number (buf, THUMB_SIZE);
10612 {
10613 addressT diff = ((newval & 0x00f8) >> 2) | (newval & 0x0200) >> 3;
10614 /* This one does not have the offset encoded in the pattern. */
10615 value = value + diff - 4;
10616 /* CZB can only branch forward. */
10617 if (value & ~0x7e)
10618 as_bad_where (fixP->fx_file, fixP->fx_line,
10619 _("branch out of range"));
a737bd4d 10620
c19d1205
ZW
10621 newval &= 0xfd07;
10622 if (seg->use_rela_p && !fixP->fx_done)
10623 {
10624#ifdef OBJ_ELF
10625 fixP->fx_offset = value;
10626#endif
10627 fixP->fx_addnumber = value;
10628 }
10629 else
10630 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
10631 }
10632 md_number_to_chars (buf, newval, THUMB_SIZE);
10633 break;
a737bd4d 10634
c19d1205
ZW
10635 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
10636 newval = md_chars_to_number (buf, THUMB_SIZE);
10637 {
10638 addressT diff = (newval & 0xff) << 1;
10639 if (diff & 0x100)
10640 diff |= ~0xff;
a737bd4d 10641
c19d1205
ZW
10642 value += diff;
10643 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
10644 as_bad_where (fixP->fx_file, fixP->fx_line,
10645 _("branch out of range"));
10646 if (seg->use_rela_p && !fixP->fx_done)
10647 {
10648#ifdef OBJ_ELF
10649 fixP->fx_offset = value;
10650#endif
10651 fixP->fx_addnumber = value;
10652 newval = newval & 0xff00;
10653 }
10654 else
10655 newval = (newval & 0xff00) | ((value & 0x1ff) >> 1);
10656 }
10657 md_number_to_chars (buf, newval, THUMB_SIZE);
10658 break;
a737bd4d 10659
c19d1205
ZW
10660 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
10661 newval = md_chars_to_number (buf, THUMB_SIZE);
10662 {
10663 addressT diff = (newval & 0x7ff) << 1;
10664 if (diff & 0x800)
10665 diff |= ~0x7ff;
a737bd4d 10666
c19d1205
ZW
10667 value += diff;
10668 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
10669 as_bad_where (fixP->fx_file, fixP->fx_line,
10670 _("branch out of range"));
10671 if (seg->use_rela_p && !fixP->fx_done)
10672 {
10673#ifdef OBJ_ELF
10674 fixP->fx_offset = value;
10675#endif
10676 fixP->fx_addnumber = value;
10677 newval = newval & 0xf800;
10678 }
10679 else
10680 newval = (newval & 0xf800) | ((value & 0xfff) >> 1);
10681 }
10682 md_number_to_chars (buf, newval, THUMB_SIZE);
10683 break;
a737bd4d 10684
c19d1205
ZW
10685 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10686 {
10687 offsetT newval2;
10688 addressT diff, S, J1, J2, lo, hi;
a737bd4d 10689
c19d1205
ZW
10690 newval = md_chars_to_number (buf, THUMB_SIZE);
10691 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
a737bd4d 10692
c19d1205
ZW
10693 S = !(newval & 0x0400); /* flipped - 0=negative */
10694 hi = (newval & 0x003f);
10695 J1 = (newval2 & 0x2000) >> 13;
10696 J2 = (newval2 & 0x0800) >> 11;
10697 lo = (newval2 & 0x07ff);
a737bd4d 10698
c19d1205
ZW
10699 diff = ((S << 20) | (J2 << 19) | (J1 << 18) | (hi << 12) | (lo << 1));
10700 diff -= (1 << 20); /* sign extend */
10701 value += diff;
404ff6b5 10702
c19d1205
ZW
10703 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
10704 as_bad_where (fixP->fx_file, fixP->fx_line,
10705 _("conditional branch out of range"));
404ff6b5 10706
c19d1205
ZW
10707 newval = newval & 0xfbc0;
10708 newval2 = newval2 & 0xd000;
10709 if (seg->use_rela_p && !fixP->fx_done)
10710 {
10711#ifdef OBJ_ELF
10712 fixP->fx_offset = value;
10713#endif
10714 fixP->fx_addnumber = value;
10715 }
10716 else
10717 {
10718 S = (value & 0x00100000) >> 20;
10719 J2 = (value & 0x00080000) >> 19;
10720 J1 = (value & 0x00040000) >> 18;
10721 hi = (value & 0x0003f000) >> 12;
10722 lo = (value & 0x00000ffe) >> 1;
10723
10724 newval = newval | (S << 10) | hi;
10725 newval2 = newval2 | (J1 << 13) | (J2 << 11) | lo;
10726 }
6c43fab6 10727
c19d1205
ZW
10728 md_number_to_chars (buf, newval, THUMB_SIZE);
10729 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10730 }
10731 break;
6c43fab6 10732
c19d1205
ZW
10733 case BFD_RELOC_THUMB_PCREL_BLX:
10734 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10735 {
10736 offsetT newval2;
10737 addressT diff;
404ff6b5 10738
c19d1205
ZW
10739 newval = md_chars_to_number (buf, THUMB_SIZE);
10740 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10741 diff = ((newval & 0x7ff) << 12) | ((newval2 & 0x7ff) << 1);
10742 if (diff & 0x400000)
10743 diff |= ~0x3fffff;
10744#ifdef OBJ_ELF
05ab1f3b 10745 value = fixP->fx_offset;
c19d1205
ZW
10746#endif
10747 value += diff;
404ff6b5 10748
c19d1205
ZW
10749 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
10750 as_bad_where (fixP->fx_file, fixP->fx_line,
10751 _("branch with link out of range"));
404ff6b5 10752
c19d1205
ZW
10753 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
10754 /* For a BLX instruction, make sure that the relocation is rounded up
10755 to a word boundary. This follows the semantics of the instruction
10756 which specifies that bit 1 of the target address will come from bit
10757 1 of the base address. */
10758 value = (value + 1) & ~ 1;
404ff6b5 10759
c19d1205
ZW
10760 if (seg->use_rela_p && !fixP->fx_done)
10761 {
10762#ifdef OBJ_ELF
10763 fixP->fx_offset = value;
10764#endif
10765 fixP->fx_addnumber = value;
10766 newval = newval & 0xf800;
10767 newval2 = newval2 & 0xf800;
10768 }
10769 else
10770 {
10771 newval = (newval & 0xf800) | ((value & 0x7fffff) >> 12);
10772 newval2 = (newval2 & 0xf800) | ((value & 0xfff) >> 1);
10773 }
10774 md_number_to_chars (buf, newval, THUMB_SIZE);
10775 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10776 }
10777 break;
404ff6b5 10778
c19d1205
ZW
10779 case BFD_RELOC_8:
10780 if (seg->use_rela_p && !fixP->fx_done)
10781 break;
10782 if (fixP->fx_done || fixP->fx_pcrel)
10783 md_number_to_chars (buf, value, 1);
10784#ifdef OBJ_ELF
10785 else
10786 {
10787 value = fixP->fx_offset;
10788 md_number_to_chars (buf, value, 1);
10789 }
10790#endif
10791 break;
404ff6b5 10792
c19d1205
ZW
10793 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10794 {
10795 offsetT newval2;
10796 addressT diff, S, I1, I2, lo, hi;
6c43fab6 10797
c19d1205
ZW
10798 newval = md_chars_to_number (buf, THUMB_SIZE);
10799 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
6c43fab6 10800
c19d1205
ZW
10801 S = (newval & 0x0400) >> 10;
10802 hi = (newval & 0x03ff);
10803 I1 = (newval2 & 0x2000) >> 13;
10804 I2 = (newval2 & 0x0800) >> 11;
10805 lo = (newval2 & 0x07ff);
6c43fab6 10806
c19d1205
ZW
10807 I1 = !(I1 ^ S);
10808 I2 = !(I2 ^ S);
10809 S = !S;
6c43fab6 10810
c19d1205
ZW
10811 diff = ((S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1));
10812 diff -= (1 << 24); /* sign extend */
10813 value += diff;
6c43fab6 10814
c19d1205
ZW
10815 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
10816 as_bad_where (fixP->fx_file, fixP->fx_line,
10817 _("branch out of range"));
6c43fab6 10818
c19d1205
ZW
10819 newval = newval & 0xf800;
10820 newval2 = newval2 & 0xd000;
10821 if (seg->use_rela_p && !fixP->fx_done)
10822 {
10823#ifdef OBJ_ELF
10824 fixP->fx_offset = value;
10825#endif
10826 fixP->fx_addnumber = value;
10827 }
10828 else
10829 {
10830 S = (value & 0x01000000) >> 24;
10831 I1 = (value & 0x00800000) >> 23;
10832 I2 = (value & 0x00400000) >> 22;
10833 hi = (value & 0x003ff000) >> 12;
10834 lo = (value & 0x00000ffe) >> 1;
a737bd4d 10835
c19d1205
ZW
10836 I1 = !(I1 ^ S);
10837 I2 = !(I2 ^ S);
a737bd4d 10838
c19d1205
ZW
10839 newval = newval | (S << 10) | hi;
10840 newval2 = newval2 | (I1 << 13) | (I2 << 11) | lo;
10841 }
10842 md_number_to_chars (buf, newval, THUMB_SIZE);
10843 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10844 }
10845 break;
a737bd4d 10846
c19d1205
ZW
10847 case BFD_RELOC_16:
10848 if (seg->use_rela_p && !fixP->fx_done)
10849 break;
10850 if (fixP->fx_done || fixP->fx_pcrel)
10851 md_number_to_chars (buf, value, 2);
10852#ifdef OBJ_ELF
10853 else
10854 {
10855 value = fixP->fx_offset;
10856 md_number_to_chars (buf, value, 2);
10857 }
10858#endif
10859 break;
a737bd4d 10860
c19d1205
ZW
10861#ifdef OBJ_ELF
10862 case BFD_RELOC_ARM_TLS_GD32:
10863 case BFD_RELOC_ARM_TLS_LE32:
10864 case BFD_RELOC_ARM_TLS_IE32:
10865 case BFD_RELOC_ARM_TLS_LDM32:
10866 case BFD_RELOC_ARM_TLS_LDO32:
10867 S_SET_THREAD_LOCAL (fixP->fx_addsy);
10868 /* fall through */
6c43fab6 10869
c19d1205
ZW
10870 case BFD_RELOC_ARM_GOT32:
10871 case BFD_RELOC_ARM_GOTOFF:
10872 case BFD_RELOC_ARM_TARGET2:
10873 if (seg->use_rela_p && !fixP->fx_done)
10874 break;
10875 md_number_to_chars (buf, 0, 4);
10876 break;
10877#endif
6c43fab6 10878
c19d1205
ZW
10879 case BFD_RELOC_RVA:
10880 case BFD_RELOC_32:
10881 case BFD_RELOC_ARM_TARGET1:
10882 case BFD_RELOC_ARM_ROSEGREL32:
10883 case BFD_RELOC_ARM_SBREL32:
10884 case BFD_RELOC_32_PCREL:
10885 if (seg->use_rela_p && !fixP->fx_done)
10886 break;
10887 if (fixP->fx_done || fixP->fx_pcrel)
10888 md_number_to_chars (buf, value, 4);
10889#ifdef OBJ_ELF
10890 else
10891 {
10892 value = fixP->fx_offset;
10893 md_number_to_chars (buf, value, 4);
10894 }
10895#endif
10896 break;
6c43fab6 10897
c19d1205
ZW
10898#ifdef OBJ_ELF
10899 case BFD_RELOC_ARM_PREL31:
10900 if (fixP->fx_done || fixP->fx_pcrel)
10901 {
10902 newval = md_chars_to_number (buf, 4) & 0x80000000;
10903 if ((value ^ (value >> 1)) & 0x40000000)
10904 {
10905 as_bad_where (fixP->fx_file, fixP->fx_line,
10906 _("rel31 relocation overflow"));
10907 }
10908 newval |= value & 0x7fffffff;
10909 md_number_to_chars (buf, newval, 4);
10910 }
10911 break;
a737bd4d 10912
c19d1205
ZW
10913 case BFD_RELOC_ARM_PLT32:
10914 /* It appears the instruction is fully prepared at this point. */
10915 break;
10916#endif
a737bd4d 10917
c19d1205
ZW
10918 case BFD_RELOC_ARM_CP_OFF_IMM:
10919 if (value < -1023 || value > 1023 || (value & 3))
10920 as_bad_where (fixP->fx_file, fixP->fx_line,
10921 _("co-processor offset out of range"));
10922 cp_off_common:
10923 sign = value >= 0;
10924 if (value < 0)
10925 value = -value;
10926 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
10927 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
10928 if (value == 0)
10929 newval &= ~WRITE_BACK;
10930 md_number_to_chars (buf, newval, INSN_SIZE);
10931 break;
a737bd4d 10932
c19d1205
ZW
10933 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
10934 if (value < -255 || value > 255)
10935 as_bad_where (fixP->fx_file, fixP->fx_line,
10936 _("co-processor offset out of range"));
10937 goto cp_off_common;
6c43fab6 10938
c19d1205
ZW
10939 case BFD_RELOC_ARM_THUMB_OFFSET:
10940 newval = md_chars_to_number (buf, THUMB_SIZE);
10941 /* Exactly what ranges, and where the offset is inserted depends
10942 on the type of instruction, we can establish this from the
10943 top 4 bits. */
10944 switch (newval >> 12)
10945 {
10946 case 4: /* PC load. */
10947 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
10948 forced to zero for these loads; md_pcrel_from has already
10949 compensated for this. */
10950 if (value & 3)
10951 as_bad_where (fixP->fx_file, fixP->fx_line,
10952 _("invalid offset, target not word aligned (0x%08lX)"),
10953 (((unsigned int) fixP->fx_frag->fr_address
10954 + (unsigned int) fixP->fx_where) & ~3) + value);
a737bd4d 10955
c19d1205
ZW
10956 if (value & ~0x3fc)
10957 as_bad_where (fixP->fx_file, fixP->fx_line,
10958 _("invalid offset, value too big (0x%08lX)"),
10959 (long) value);
a737bd4d 10960
c19d1205
ZW
10961 newval |= value >> 2;
10962 break;
a737bd4d 10963
c19d1205
ZW
10964 case 9: /* SP load/store. */
10965 if (value & ~0x3fc)
10966 as_bad_where (fixP->fx_file, fixP->fx_line,
10967 _("invalid offset, value too big (0x%08lX)"),
10968 (long) value);
10969 newval |= value >> 2;
10970 break;
6c43fab6 10971
c19d1205
ZW
10972 case 6: /* Word load/store. */
10973 if (value & ~0x7c)
10974 as_bad_where (fixP->fx_file, fixP->fx_line,
10975 _("invalid offset, value too big (0x%08lX)"),
10976 (long) value);
10977 newval |= value << 4; /* 6 - 2. */
10978 break;
a737bd4d 10979
c19d1205
ZW
10980 case 7: /* Byte load/store. */
10981 if (value & ~0x1f)
10982 as_bad_where (fixP->fx_file, fixP->fx_line,
10983 _("invalid offset, value too big (0x%08lX)"),
10984 (long) value);
10985 newval |= value << 6;
10986 break;
a737bd4d 10987
c19d1205
ZW
10988 case 8: /* Halfword load/store. */
10989 if (value & ~0x3e)
10990 as_bad_where (fixP->fx_file, fixP->fx_line,
10991 _("invalid offset, value too big (0x%08lX)"),
10992 (long) value);
10993 newval |= value << 5; /* 6 - 1. */
10994 break;
a737bd4d 10995
c19d1205
ZW
10996 default:
10997 as_bad_where (fixP->fx_file, fixP->fx_line,
10998 "Unable to process relocation for thumb opcode: %lx",
10999 (unsigned long) newval);
11000 break;
11001 }
11002 md_number_to_chars (buf, newval, THUMB_SIZE);
11003 break;
a737bd4d 11004
c19d1205
ZW
11005 case BFD_RELOC_ARM_THUMB_ADD:
11006 /* This is a complicated relocation, since we use it for all of
11007 the following immediate relocations:
a737bd4d 11008
c19d1205
ZW
11009 3bit ADD/SUB
11010 8bit ADD/SUB
11011 9bit ADD/SUB SP word-aligned
11012 10bit ADD PC/SP word-aligned
a737bd4d 11013
c19d1205
ZW
11014 The type of instruction being processed is encoded in the
11015 instruction field:
a737bd4d 11016
c19d1205
ZW
11017 0x8000 SUB
11018 0x00F0 Rd
11019 0x000F Rs
11020 */
11021 newval = md_chars_to_number (buf, THUMB_SIZE);
11022 {
11023 int rd = (newval >> 4) & 0xf;
11024 int rs = newval & 0xf;
11025 int subtract = !!(newval & 0x8000);
a737bd4d 11026
c19d1205
ZW
11027 /* Check for HI regs, only very restricted cases allowed:
11028 Adjusting SP, and using PC or SP to get an address. */
11029 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
11030 || (rs > 7 && rs != REG_SP && rs != REG_PC))
11031 as_bad_where (fixP->fx_file, fixP->fx_line,
11032 _("invalid Hi register with immediate"));
a737bd4d 11033
c19d1205
ZW
11034 /* If value is negative, choose the opposite instruction. */
11035 if (value < 0)
11036 {
11037 value = -value;
11038 subtract = !subtract;
11039 if (value < 0)
11040 as_bad_where (fixP->fx_file, fixP->fx_line,
11041 _("immediate value out of range"));
11042 }
a737bd4d 11043
c19d1205
ZW
11044 if (rd == REG_SP)
11045 {
11046 if (value & ~0x1fc)
11047 as_bad_where (fixP->fx_file, fixP->fx_line,
11048 _("invalid immediate for stack address calculation"));
11049 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11050 newval |= value >> 2;
11051 }
11052 else if (rs == REG_PC || rs == REG_SP)
11053 {
11054 if (subtract || value & ~0x3fc)
11055 as_bad_where (fixP->fx_file, fixP->fx_line,
11056 _("invalid immediate for address calculation (value = 0x%08lX)"),
11057 (unsigned long) value);
11058 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11059 newval |= rd << 8;
11060 newval |= value >> 2;
11061 }
11062 else if (rs == rd)
11063 {
11064 if (value & ~0xff)
11065 as_bad_where (fixP->fx_file, fixP->fx_line,
11066 _("immediate value out of range"));
11067 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11068 newval |= (rd << 8) | value;
11069 }
11070 else
11071 {
11072 if (value & ~0x7)
11073 as_bad_where (fixP->fx_file, fixP->fx_line,
11074 _("immediate value out of range"));
11075 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11076 newval |= rd | (rs << 3) | (value << 6);
11077 }
11078 }
11079 md_number_to_chars (buf, newval, THUMB_SIZE);
11080 break;
a737bd4d 11081
c19d1205
ZW
11082 case BFD_RELOC_ARM_THUMB_IMM:
11083 newval = md_chars_to_number (buf, THUMB_SIZE);
11084 if (value < 0 || value > 255)
11085 as_bad_where (fixP->fx_file, fixP->fx_line,
11086 _("invalid immediate: %ld is too large"),
11087 (long) value);
11088 newval |= value;
11089 md_number_to_chars (buf, newval, THUMB_SIZE);
11090 break;
a737bd4d 11091
c19d1205
ZW
11092 case BFD_RELOC_ARM_THUMB_SHIFT:
11093 /* 5bit shift value (0..32). LSL cannot take 32. */
11094 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11095 temp = newval & 0xf800;
11096 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11097 as_bad_where (fixP->fx_file, fixP->fx_line,
11098 _("invalid shift value: %ld"), (long) value);
11099 /* Shifts of zero must be encoded as LSL. */
11100 if (value == 0)
11101 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11102 /* Shifts of 32 are encoded as zero. */
11103 else if (value == 32)
11104 value = 0;
11105 newval |= value << 6;
11106 md_number_to_chars (buf, newval, THUMB_SIZE);
11107 break;
a737bd4d 11108
c19d1205
ZW
11109 case BFD_RELOC_VTABLE_INHERIT:
11110 case BFD_RELOC_VTABLE_ENTRY:
11111 fixP->fx_done = 0;
11112 return;
6c43fab6 11113
c19d1205
ZW
11114 case BFD_RELOC_UNUSED:
11115 default:
11116 as_bad_where (fixP->fx_file, fixP->fx_line,
11117 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11118 }
6c43fab6
RE
11119}
11120
c19d1205
ZW
11121/* Translate internal representation of relocation info to BFD target
11122 format. */
a737bd4d 11123
c19d1205
ZW
11124arelent *
11125tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11126 fixS * fixp)
a737bd4d 11127{
c19d1205
ZW
11128 arelent * reloc;
11129 bfd_reloc_code_real_type code;
a737bd4d 11130
c19d1205 11131 reloc = xmalloc (sizeof (arelent));
a737bd4d 11132
c19d1205
ZW
11133 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11134 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11135 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 11136
c19d1205
ZW
11137 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
11138#ifndef OBJ_ELF
11139 if (fixp->fx_pcrel == 0)
11140 reloc->addend = fixp->fx_offset;
11141 else
11142 reloc->addend = fixp->fx_offset = reloc->address;
11143#else /* OBJ_ELF */
11144 reloc->addend = fixp->fx_offset;
11145#endif
a737bd4d 11146
c19d1205 11147 switch (fixp->fx_r_type)
a737bd4d 11148 {
c19d1205
ZW
11149 case BFD_RELOC_8:
11150 if (fixp->fx_pcrel)
11151 {
11152 code = BFD_RELOC_8_PCREL;
11153 break;
11154 }
a737bd4d 11155
c19d1205
ZW
11156 case BFD_RELOC_16:
11157 if (fixp->fx_pcrel)
11158 {
11159 code = BFD_RELOC_16_PCREL;
11160 break;
11161 }
6c43fab6 11162
c19d1205
ZW
11163 case BFD_RELOC_32:
11164 if (fixp->fx_pcrel)
11165 {
11166 code = BFD_RELOC_32_PCREL;
11167 break;
11168 }
a737bd4d 11169
c19d1205
ZW
11170 case BFD_RELOC_NONE:
11171 case BFD_RELOC_ARM_PCREL_BRANCH:
11172 case BFD_RELOC_ARM_PCREL_BLX:
11173 case BFD_RELOC_RVA:
11174 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11175 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11176 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11177 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11178 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11179 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11180 case BFD_RELOC_THUMB_PCREL_BLX:
11181 case BFD_RELOC_VTABLE_ENTRY:
11182 case BFD_RELOC_VTABLE_INHERIT:
11183 code = fixp->fx_r_type;
11184 break;
a737bd4d 11185
c19d1205
ZW
11186 case BFD_RELOC_ARM_LITERAL:
11187 case BFD_RELOC_ARM_HWLITERAL:
11188 /* If this is called then the a literal has
11189 been referenced across a section boundary. */
11190 as_bad_where (fixp->fx_file, fixp->fx_line,
11191 _("literal referenced across section boundary"));
11192 return NULL;
a737bd4d 11193
c19d1205
ZW
11194#ifdef OBJ_ELF
11195 case BFD_RELOC_ARM_GOT32:
11196 case BFD_RELOC_ARM_GOTOFF:
11197 case BFD_RELOC_ARM_PLT32:
11198 case BFD_RELOC_ARM_TARGET1:
11199 case BFD_RELOC_ARM_ROSEGREL32:
11200 case BFD_RELOC_ARM_SBREL32:
11201 case BFD_RELOC_ARM_PREL31:
11202 case BFD_RELOC_ARM_TARGET2:
11203 case BFD_RELOC_ARM_TLS_LE32:
11204 case BFD_RELOC_ARM_TLS_LDO32:
11205 code = fixp->fx_r_type;
11206 break;
a737bd4d 11207
c19d1205
ZW
11208 case BFD_RELOC_ARM_TLS_GD32:
11209 case BFD_RELOC_ARM_TLS_IE32:
11210 case BFD_RELOC_ARM_TLS_LDM32:
11211 /* BFD will include the symbol's address in the addend.
11212 But we don't want that, so subtract it out again here. */
11213 if (!S_IS_COMMON (fixp->fx_addsy))
11214 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11215 code = fixp->fx_r_type;
11216 break;
11217#endif
a737bd4d 11218
c19d1205
ZW
11219 case BFD_RELOC_ARM_IMMEDIATE:
11220 as_bad_where (fixp->fx_file, fixp->fx_line,
11221 _("internal relocation (type: IMMEDIATE) not fixed up"));
11222 return NULL;
a737bd4d 11223
c19d1205
ZW
11224 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11225 as_bad_where (fixp->fx_file, fixp->fx_line,
11226 _("ADRL used for a symbol not defined in the same file"));
11227 return NULL;
a737bd4d 11228
c19d1205
ZW
11229 case BFD_RELOC_ARM_OFFSET_IMM:
11230 if (fixp->fx_addsy != NULL
11231 && !S_IS_DEFINED (fixp->fx_addsy)
11232 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 11233 {
c19d1205
ZW
11234 as_bad_where (fixp->fx_file, fixp->fx_line,
11235 _("undefined local label `%s'"),
11236 S_GET_NAME (fixp->fx_addsy));
11237 return NULL;
a737bd4d
NC
11238 }
11239
c19d1205
ZW
11240 as_bad_where (fixp->fx_file, fixp->fx_line,
11241 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11242 return NULL;
a737bd4d 11243
c19d1205
ZW
11244 default:
11245 {
11246 char * type;
6c43fab6 11247
c19d1205
ZW
11248 switch (fixp->fx_r_type)
11249 {
11250 case BFD_RELOC_NONE: type = "NONE"; break;
11251 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
11252 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
11253 case BFD_RELOC_ARM_SMI: type = "SMI"; break;
11254 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
11255 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
11256 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
11257 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
11258 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
11259 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
11260 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
11261 default: type = _("<unknown>"); break;
11262 }
11263 as_bad_where (fixp->fx_file, fixp->fx_line,
11264 _("cannot represent %s relocation in this object file format"),
11265 type);
11266 return NULL;
11267 }
a737bd4d 11268 }
6c43fab6 11269
c19d1205
ZW
11270#ifdef OBJ_ELF
11271 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
11272 && GOT_symbol
11273 && fixp->fx_addsy == GOT_symbol)
11274 {
11275 code = BFD_RELOC_ARM_GOTPC;
11276 reloc->addend = fixp->fx_offset = reloc->address;
11277 }
11278#endif
6c43fab6 11279
c19d1205 11280 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 11281
c19d1205
ZW
11282 if (reloc->howto == NULL)
11283 {
11284 as_bad_where (fixp->fx_file, fixp->fx_line,
11285 _("cannot represent %s relocation in this object file format"),
11286 bfd_get_reloc_code_name (code));
11287 return NULL;
11288 }
6c43fab6 11289
c19d1205
ZW
11290 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
11291 vtable entry to be used in the relocation's section offset. */
11292 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11293 reloc->address = fixp->fx_offset;
6c43fab6 11294
c19d1205 11295 return reloc;
6c43fab6
RE
11296}
11297
c19d1205 11298/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 11299
c19d1205
ZW
11300void
11301cons_fix_new_arm (fragS * frag,
11302 int where,
11303 int size,
11304 expressionS * exp)
6c43fab6 11305{
c19d1205
ZW
11306 bfd_reloc_code_real_type type;
11307 int pcrel = 0;
6c43fab6 11308
c19d1205
ZW
11309 /* Pick a reloc.
11310 FIXME: @@ Should look at CPU word size. */
11311 switch (size)
11312 {
11313 case 1:
11314 type = BFD_RELOC_8;
11315 break;
11316 case 2:
11317 type = BFD_RELOC_16;
11318 break;
11319 case 4:
11320 default:
11321 type = BFD_RELOC_32;
11322 break;
11323 case 8:
11324 type = BFD_RELOC_64;
11325 break;
11326 }
6c43fab6 11327
c19d1205
ZW
11328 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
11329}
6c43fab6 11330
c19d1205
ZW
11331#if defined OBJ_COFF || defined OBJ_ELF
11332void
11333arm_validate_fix (fixS * fixP)
6c43fab6 11334{
c19d1205
ZW
11335 /* If the destination of the branch is a defined symbol which does not have
11336 the THUMB_FUNC attribute, then we must be calling a function which has
11337 the (interfacearm) attribute. We look for the Thumb entry point to that
11338 function and change the branch to refer to that function instead. */
11339 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
11340 && fixP->fx_addsy != NULL
11341 && S_IS_DEFINED (fixP->fx_addsy)
11342 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 11343 {
c19d1205 11344 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 11345 }
c19d1205
ZW
11346}
11347#endif
6c43fab6 11348
c19d1205
ZW
11349int
11350arm_force_relocation (struct fix * fixp)
11351{
11352#if defined (OBJ_COFF) && defined (TE_PE)
11353 if (fixp->fx_r_type == BFD_RELOC_RVA)
11354 return 1;
11355#endif
05ab1f3b
ZW
11356#ifdef OBJ_ELF
11357 if (fixp->fx_r_type == BFD_RELOC_ARM_PCREL_BRANCH
11358 || fixp->fx_r_type == BFD_RELOC_ARM_PCREL_BLX
11359 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX
11360 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23)
11361 return 1;
11362#endif
6c43fab6 11363
c19d1205
ZW
11364 /* Resolve these relocations even if the symbol is extern or weak. */
11365 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
11366 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
11367 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11368 return 0;
a737bd4d 11369
c19d1205 11370 return generic_force_reloc (fixp);
404ff6b5
AH
11371}
11372
c19d1205
ZW
11373#ifdef OBJ_COFF
11374/* This is a little hack to help the gas/arm/adrl.s test. It prevents
11375 local labels from being added to the output symbol table when they
11376 are used with the ADRL pseudo op. The ADRL relocation should always
11377 be resolved before the binbary is emitted, so it is safe to say that
11378 it is adjustable. */
404ff6b5 11379
c19d1205
ZW
11380bfd_boolean
11381arm_fix_adjustable (fixS * fixP)
404ff6b5 11382{
c19d1205
ZW
11383 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11384 return 1;
11385 return 0;
404ff6b5 11386}
c19d1205 11387#endif
404ff6b5 11388
c19d1205
ZW
11389#ifdef OBJ_ELF
11390/* Relocations against Thumb function names must be left unadjusted,
11391 so that the linker can use this information to correctly set the
11392 bottom bit of their addresses. The MIPS version of this function
11393 also prevents relocations that are mips-16 specific, but I do not
11394 know why it does this.
404ff6b5 11395
c19d1205
ZW
11396 FIXME:
11397 There is one other problem that ought to be addressed here, but
11398 which currently is not: Taking the address of a label (rather
11399 than a function) and then later jumping to that address. Such
11400 addresses also ought to have their bottom bit set (assuming that
11401 they reside in Thumb code), but at the moment they will not. */
404ff6b5 11402
c19d1205
ZW
11403bfd_boolean
11404arm_fix_adjustable (fixS * fixP)
404ff6b5 11405{
c19d1205
ZW
11406 if (fixP->fx_addsy == NULL)
11407 return 1;
404ff6b5 11408
c19d1205
ZW
11409 if (THUMB_IS_FUNC (fixP->fx_addsy)
11410 && fixP->fx_subsy == NULL)
11411 return 0;
a737bd4d 11412
c19d1205
ZW
11413 /* We need the symbol name for the VTABLE entries. */
11414 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11415 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11416 return 0;
404ff6b5 11417
c19d1205
ZW
11418 /* Don't allow symbols to be discarded on GOT related relocs. */
11419 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
11420 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
11421 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
11422 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
11423 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
11424 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
11425 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
11426 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
11427 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
11428 return 0;
a737bd4d 11429
c19d1205 11430 return 1;
a737bd4d 11431}
404ff6b5 11432
c19d1205
ZW
11433const char *
11434elf32_arm_target_format (void)
404ff6b5 11435{
c19d1205
ZW
11436#ifdef TE_SYMBIAN
11437 return (target_big_endian
11438 ? "elf32-bigarm-symbian"
11439 : "elf32-littlearm-symbian");
11440#elif defined (TE_VXWORKS)
11441 return (target_big_endian
11442 ? "elf32-bigarm-vxworks"
11443 : "elf32-littlearm-vxworks");
11444#else
11445 if (target_big_endian)
11446 return "elf32-bigarm";
11447 else
11448 return "elf32-littlearm";
11449#endif
404ff6b5
AH
11450}
11451
c19d1205
ZW
11452void
11453armelf_frob_symbol (symbolS * symp,
11454 int * puntp)
404ff6b5 11455{
c19d1205
ZW
11456 elf_frob_symbol (symp, puntp);
11457}
11458#endif
404ff6b5 11459
c19d1205 11460/* MD interface: Finalization. */
a737bd4d 11461
c19d1205
ZW
11462/* A good place to do this, although this was probably not intended
11463 for this kind of use. We need to dump the literal pool before
11464 references are made to a null symbol pointer. */
a737bd4d 11465
c19d1205
ZW
11466void
11467arm_cleanup (void)
11468{
11469 literal_pool * pool;
a737bd4d 11470
c19d1205
ZW
11471 for (pool = list_of_pools; pool; pool = pool->next)
11472 {
11473 /* Put it at the end of the relevent section. */
11474 subseg_set (pool->section, pool->sub_section);
11475#ifdef OBJ_ELF
11476 arm_elf_change_section ();
11477#endif
11478 s_ltorg (0);
11479 }
404ff6b5
AH
11480}
11481
c19d1205
ZW
11482/* Adjust the symbol table. This marks Thumb symbols as distinct from
11483 ARM ones. */
404ff6b5 11484
c19d1205
ZW
11485void
11486arm_adjust_symtab (void)
404ff6b5 11487{
c19d1205
ZW
11488#ifdef OBJ_COFF
11489 symbolS * sym;
404ff6b5 11490
c19d1205
ZW
11491 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
11492 {
11493 if (ARM_IS_THUMB (sym))
11494 {
11495 if (THUMB_IS_FUNC (sym))
11496 {
11497 /* Mark the symbol as a Thumb function. */
11498 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
11499 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
11500 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 11501
c19d1205
ZW
11502 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
11503 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
11504 else
11505 as_bad (_("%s: unexpected function type: %d"),
11506 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
11507 }
11508 else switch (S_GET_STORAGE_CLASS (sym))
11509 {
11510 case C_EXT:
11511 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
11512 break;
11513 case C_STAT:
11514 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
11515 break;
11516 case C_LABEL:
11517 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
11518 break;
11519 default:
11520 /* Do nothing. */
11521 break;
11522 }
11523 }
a737bd4d 11524
c19d1205
ZW
11525 if (ARM_IS_INTERWORK (sym))
11526 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 11527 }
c19d1205
ZW
11528#endif
11529#ifdef OBJ_ELF
11530 symbolS * sym;
11531 char bind;
404ff6b5 11532
c19d1205 11533 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 11534 {
c19d1205
ZW
11535 if (ARM_IS_THUMB (sym))
11536 {
11537 elf_symbol_type * elf_sym;
404ff6b5 11538
c19d1205
ZW
11539 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
11540 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 11541
c19d1205
ZW
11542 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
11543 {
11544 /* If it's a .thumb_func, declare it as so,
11545 otherwise tag label as .code 16. */
11546 if (THUMB_IS_FUNC (sym))
11547 elf_sym->internal_elf_sym.st_info =
11548 ELF_ST_INFO (bind, STT_ARM_TFUNC);
11549 else
11550 elf_sym->internal_elf_sym.st_info =
11551 ELF_ST_INFO (bind, STT_ARM_16BIT);
11552 }
11553 }
11554 }
11555#endif
404ff6b5
AH
11556}
11557
c19d1205 11558/* MD interface: Initialization. */
404ff6b5 11559
a737bd4d 11560static void
c19d1205 11561set_constant_flonums (void)
a737bd4d 11562{
c19d1205 11563 int i;
404ff6b5 11564
c19d1205
ZW
11565 for (i = 0; i < NUM_FLOAT_VALS; i++)
11566 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
11567 abort ();
a737bd4d 11568}
404ff6b5 11569
c19d1205
ZW
11570void
11571md_begin (void)
a737bd4d 11572{
c19d1205
ZW
11573 unsigned mach;
11574 unsigned int i;
404ff6b5 11575
c19d1205
ZW
11576 if ( (arm_ops_hsh = hash_new ()) == NULL
11577 || (arm_cond_hsh = hash_new ()) == NULL
11578 || (arm_shift_hsh = hash_new ()) == NULL
11579 || (arm_psr_hsh = hash_new ()) == NULL
11580 || (arm_reg_hsh = hash_new ()) == NULL
11581 || (arm_reloc_hsh = hash_new ()) == NULL)
11582 as_fatal (_("virtual memory exhausted"));
11583
11584 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
11585 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
11586 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
11587 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
11588 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
11589 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
11590 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
11591 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
11592 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
11593 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
11594#ifdef OBJ_ELF
11595 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
11596 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
11597#endif
11598
11599 set_constant_flonums ();
404ff6b5 11600
c19d1205
ZW
11601 /* Set the cpu variant based on the command-line options. We prefer
11602 -mcpu= over -march= if both are set (as for GCC); and we prefer
11603 -mfpu= over any other way of setting the floating point unit.
11604 Use of legacy options with new options are faulted. */
11605 if (legacy_cpu != -1)
404ff6b5 11606 {
c19d1205
ZW
11607 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
11608 as_bad (_("use of old and new-style options to set CPU type"));
11609
11610 mcpu_cpu_opt = legacy_cpu;
404ff6b5 11611 }
c19d1205
ZW
11612 else if (mcpu_cpu_opt == -1)
11613 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 11614
c19d1205
ZW
11615 if (legacy_fpu != -1)
11616 {
11617 if (mfpu_opt != -1)
11618 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
11619
11620 mfpu_opt = legacy_fpu;
11621 }
11622 else if (mfpu_opt == -1)
11623 {
c19d1205 11624#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
11625 /* Some environments specify a default FPU. If they don't, infer it
11626 from the processor. */
03b1477f
RE
11627 if (mcpu_fpu_opt != -1)
11628 mfpu_opt = mcpu_fpu_opt;
11629 else
11630 mfpu_opt = march_fpu_opt;
39c2da32
RE
11631#else
11632 mfpu_opt = FPU_DEFAULT;
11633#endif
03b1477f
RE
11634 }
11635
11636 if (mfpu_opt == -1)
11637 {
11638 if (mcpu_cpu_opt == -1)
11639 mfpu_opt = FPU_DEFAULT;
11640 else if (mcpu_cpu_opt & ARM_EXT_V5)
11641 mfpu_opt = FPU_ARCH_VFP_V2;
11642 else
11643 mfpu_opt = FPU_ARCH_FPA;
11644 }
11645
11646 if (mcpu_cpu_opt == -1)
11647 mcpu_cpu_opt = CPU_DEFAULT;
11648
11649 cpu_variant = mcpu_cpu_opt | mfpu_opt;
11650
f17c130b 11651#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 11652 {
7cc69913
NC
11653 unsigned int flags = 0;
11654
11655#if defined OBJ_ELF
11656 flags = meabi_flags;
d507cf36
PB
11657
11658 switch (meabi_flags)
33a392fb 11659 {
d507cf36 11660 case EF_ARM_EABI_UNKNOWN:
7cc69913 11661#endif
d507cf36
PB
11662 /* Set the flags in the private structure. */
11663 if (uses_apcs_26) flags |= F_APCS26;
11664 if (support_interwork) flags |= F_INTERWORK;
11665 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 11666 if (pic_code) flags |= F_PIC;
d507cf36
PB
11667 if ((cpu_variant & FPU_ANY) == FPU_NONE
11668 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
7cc69913
NC
11669 flags |= F_SOFT_FLOAT;
11670
d507cf36
PB
11671 switch (mfloat_abi_opt)
11672 {
11673 case ARM_FLOAT_ABI_SOFT:
11674 case ARM_FLOAT_ABI_SOFTFP:
11675 flags |= F_SOFT_FLOAT;
11676 break;
33a392fb 11677
d507cf36
PB
11678 case ARM_FLOAT_ABI_HARD:
11679 if (flags & F_SOFT_FLOAT)
11680 as_bad (_("hard-float conflicts with specified fpu"));
11681 break;
11682 }
03b1477f 11683
c19d1205 11684 /* Using VFP conventions (even if soft-float). */
7cc69913
NC
11685 if (cpu_variant & FPU_VFP_EXT_NONE)
11686 flags |= F_VFP_FLOAT;
f17c130b 11687
fde78edd 11688#if defined OBJ_ELF
d507cf36
PB
11689 if (cpu_variant & FPU_ARCH_MAVERICK)
11690 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
11691 break;
11692
8cb51566 11693 case EF_ARM_EABI_VER4:
c19d1205 11694 /* No additional flags to set. */
d507cf36
PB
11695 break;
11696
11697 default:
11698 abort ();
11699 }
7cc69913 11700#endif
b99bd4ef
NC
11701 bfd_set_private_flags (stdoutput, flags);
11702
11703 /* We have run out flags in the COFF header to encode the
11704 status of ATPCS support, so instead we create a dummy,
c19d1205 11705 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
11706 if (atpcs)
11707 {
11708 asection * sec;
11709
11710 sec = bfd_make_section (stdoutput, ".arm.atpcs");
11711
11712 if (sec != NULL)
11713 {
11714 bfd_set_section_flags
11715 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
11716 bfd_set_section_size (stdoutput, sec, 0);
11717 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
11718 }
11719 }
7cc69913 11720 }
f17c130b 11721#endif
b99bd4ef
NC
11722
11723 /* Record the CPU type as well. */
11724 switch (cpu_variant & ARM_CPU_MASK)
11725 {
11726 case ARM_2:
11727 mach = bfd_mach_arm_2;
11728 break;
11729
c19d1205 11730 case ARM_3: /* Also ARM_250. */
b99bd4ef
NC
11731 mach = bfd_mach_arm_2a;
11732 break;
11733
c19d1205 11734 case ARM_6: /* Also ARM_7. */
b89dddec
RE
11735 mach = bfd_mach_arm_3;
11736 break;
11737
b99bd4ef 11738 default:
5a6c6817 11739 mach = bfd_mach_arm_unknown;
b99bd4ef 11740 break;
b99bd4ef
NC
11741 }
11742
11743 /* Catch special cases. */
e16bb312
NC
11744 if (cpu_variant & ARM_CEXT_IWMMXT)
11745 mach = bfd_mach_arm_iWMMXt;
11746 else if (cpu_variant & ARM_CEXT_XSCALE)
b99bd4ef 11747 mach = bfd_mach_arm_XScale;
fde78edd
NC
11748 else if (cpu_variant & ARM_CEXT_MAVERICK)
11749 mach = bfd_mach_arm_ep9312;
b99bd4ef
NC
11750 else if (cpu_variant & ARM_EXT_V5E)
11751 mach = bfd_mach_arm_5TE;
11752 else if (cpu_variant & ARM_EXT_V5)
11753 {
b89dddec 11754 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11755 mach = bfd_mach_arm_5T;
11756 else
11757 mach = bfd_mach_arm_5;
11758 }
b89dddec 11759 else if (cpu_variant & ARM_EXT_V4)
b99bd4ef 11760 {
b89dddec 11761 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11762 mach = bfd_mach_arm_4T;
11763 else
11764 mach = bfd_mach_arm_4;
11765 }
b89dddec 11766 else if (cpu_variant & ARM_EXT_V3M)
b99bd4ef
NC
11767 mach = bfd_mach_arm_3M;
11768
11769 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
11770}
11771
c19d1205 11772/* Command line processing. */
b99bd4ef 11773
c19d1205
ZW
11774/* md_parse_option
11775 Invocation line includes a switch not recognized by the base assembler.
11776 See if it's a processor-specific option.
b99bd4ef 11777
c19d1205
ZW
11778 This routine is somewhat complicated by the need for backwards
11779 compatibility (since older releases of gcc can't be changed).
11780 The new options try to make the interface as compatible as
11781 possible with GCC.
b99bd4ef 11782
c19d1205 11783 New options (supported) are:
b99bd4ef 11784
c19d1205
ZW
11785 -mcpu=<cpu name> Assemble for selected processor
11786 -march=<architecture name> Assemble for selected architecture
11787 -mfpu=<fpu architecture> Assemble for selected FPU.
11788 -EB/-mbig-endian Big-endian
11789 -EL/-mlittle-endian Little-endian
11790 -k Generate PIC code
11791 -mthumb Start in Thumb mode
11792 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 11793
c19d1205 11794 For now we will also provide support for:
b99bd4ef 11795
c19d1205
ZW
11796 -mapcs-32 32-bit Program counter
11797 -mapcs-26 26-bit Program counter
11798 -macps-float Floats passed in FP registers
11799 -mapcs-reentrant Reentrant code
11800 -matpcs
11801 (sometime these will probably be replaced with -mapcs=<list of options>
11802 and -matpcs=<list of options>)
b99bd4ef 11803
c19d1205
ZW
11804 The remaining options are only supported for back-wards compatibility.
11805 Cpu variants, the arm part is optional:
11806 -m[arm]1 Currently not supported.
11807 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
11808 -m[arm]3 Arm 3 processor
11809 -m[arm]6[xx], Arm 6 processors
11810 -m[arm]7[xx][t][[d]m] Arm 7 processors
11811 -m[arm]8[10] Arm 8 processors
11812 -m[arm]9[20][tdmi] Arm 9 processors
11813 -mstrongarm[110[0]] StrongARM processors
11814 -mxscale XScale processors
11815 -m[arm]v[2345[t[e]]] Arm architectures
11816 -mall All (except the ARM1)
11817 FP variants:
11818 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
11819 -mfpe-old (No float load/store multiples)
11820 -mvfpxd VFP Single precision
11821 -mvfp All VFP
11822 -mno-fpu Disable all floating point instructions
b99bd4ef 11823
c19d1205
ZW
11824 The following CPU names are recognized:
11825 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
11826 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
11827 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
11828 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
11829 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
11830 arm10t arm10e, arm1020t, arm1020e, arm10200e,
11831 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 11832
c19d1205 11833 */
b99bd4ef 11834
c19d1205 11835const char * md_shortopts = "m:k";
b99bd4ef 11836
c19d1205
ZW
11837#ifdef ARM_BI_ENDIAN
11838#define OPTION_EB (OPTION_MD_BASE + 0)
11839#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 11840#else
c19d1205
ZW
11841#if TARGET_BYTES_BIG_ENDIAN
11842#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 11843#else
c19d1205
ZW
11844#define OPTION_EL (OPTION_MD_BASE + 1)
11845#endif
b99bd4ef 11846#endif
b99bd4ef 11847
c19d1205 11848struct option md_longopts[] =
b99bd4ef 11849{
c19d1205
ZW
11850#ifdef OPTION_EB
11851 {"EB", no_argument, NULL, OPTION_EB},
11852#endif
11853#ifdef OPTION_EL
11854 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 11855#endif
c19d1205
ZW
11856 {NULL, no_argument, NULL, 0}
11857};
b99bd4ef 11858
c19d1205 11859size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 11860
c19d1205 11861struct arm_option_table
b99bd4ef 11862{
c19d1205
ZW
11863 char *option; /* Option name to match. */
11864 char *help; /* Help information. */
11865 int *var; /* Variable to change. */
11866 int value; /* What to change it to. */
11867 char *deprecated; /* If non-null, print this message. */
11868};
b99bd4ef 11869
c19d1205
ZW
11870struct arm_option_table arm_opts[] =
11871{
11872 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
11873 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
11874 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
11875 &support_interwork, 1, NULL},
11876 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
11877 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
11878 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
11879 1, NULL},
11880 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
11881 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
11882 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
11883 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
11884 NULL},
b99bd4ef 11885
c19d1205
ZW
11886 /* These are recognized by the assembler, but have no affect on code. */
11887 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
11888 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
b99bd4ef 11889
c19d1205
ZW
11890 /* DON'T add any new processors to this list -- we want the whole list
11891 to go away... Add them to the processors table instead. */
11892 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11893 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11894 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11895 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11896 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11897 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11898 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11899 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11900 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11901 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11902 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11903 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11904 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11905 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11906 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11907 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11908 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11909 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11910 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11911 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11912 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11913 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11914 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11915 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11916 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11917 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11918 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11919 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11920 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11921 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11922 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11923 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11924 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11925 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11926 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11927 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11928 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11929 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11930 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11931 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11932 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11933 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11934 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11935 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11936 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11937 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11938 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11939 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11940 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11941 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11942 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11943 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11944 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11945 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11946 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11947 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11948 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11949 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11950 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11951 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11952 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11953 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11954 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11955 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11956 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11957 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11958 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11959 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11960 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
11961 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
11962 N_("use -mcpu=strongarm110")},
11963 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
11964 N_("use -mcpu=strongarm1100")},
11965 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
11966 N_("use -mcpu=strongarm1110")},
11967 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
11968 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
11969 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 11970
c19d1205
ZW
11971 /* Architecture variants -- don't add any more to this list either. */
11972 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11973 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11974 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11975 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11976 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11977 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11978 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11979 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11980 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11981 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11982 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11983 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11984 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11985 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11986 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11987 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11988 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
11989 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 11990
c19d1205
ZW
11991 /* Floating point variants -- don't add any more to this list either. */
11992 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
11993 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
11994 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
11995 {"mno-fpu", NULL, &legacy_fpu, 0,
11996 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 11997
c19d1205
ZW
11998 {NULL, NULL, NULL, 0, NULL}
11999};
7ed4c4c5 12000
c19d1205 12001struct arm_cpu_option_table
7ed4c4c5 12002{
c19d1205
ZW
12003 char *name;
12004 int value;
12005 /* For some CPUs we assume an FPU unless the user explicitly sets
12006 -mfpu=... */
12007 int default_fpu;
12008};
7ed4c4c5 12009
c19d1205
ZW
12010/* This list should, at a minimum, contain all the cpu names
12011 recognized by GCC. */
12012static struct arm_cpu_option_table arm_cpus[] =
12013{
12014 {"all", ARM_ANY, FPU_ARCH_FPA},
12015 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA},
12016 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA},
12017 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA},
12018 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA},
12019 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA},
12020 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA},
12021 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA},
12022 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA},
12023 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA},
12024 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA},
12025 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12026 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA},
12027 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA},
12028 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA},
12029 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA},
12030 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA},
12031 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA},
12032 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA},
12033 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA},
12034 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12035 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA},
12036 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12037 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12038 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA},
12039 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA},
12040 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA},
12041 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA},
12042 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12043 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12044 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA},
12045 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA},
12046 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA},
12047 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA},
12048 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA},
12049 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA},
12050 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA},
12051 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA},
12052 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA},
12053 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA},
12054 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12055 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12056 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12057 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12058 /* For V5 or later processors we default to using VFP; but the user
12059 should really set the FPU type explicitly. */
12060 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12061 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12062 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12063 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12064 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12065 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12066 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12067 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12068 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12069 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12070 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12071 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12072 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12073 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12074 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12075 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12076 {"arm1136js", ARM_ARCH_V6, FPU_NONE},
12077 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE},
12078 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12079 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12080 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2},
12081 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE},
12082 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE},
12083 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2},
12084 /* ??? XSCALE is really an architecture. */
12085 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12086 /* ??? iwmmxt is not a processor. */
12087 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2},
12088 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12089 /* Maverick */
12090 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK},
12091 {NULL, 0, 0}
12092};
7ed4c4c5 12093
c19d1205 12094struct arm_arch_option_table
7ed4c4c5 12095{
c19d1205
ZW
12096 char *name;
12097 int value;
12098 int default_fpu;
12099};
7ed4c4c5 12100
c19d1205
ZW
12101/* This list should, at a minimum, contain all the architecture names
12102 recognized by GCC. */
12103static struct arm_arch_option_table arm_archs[] =
12104{
12105 {"all", ARM_ANY, FPU_ARCH_FPA},
12106 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12107 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12108 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12109 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12110 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12111 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12112 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12113 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12114 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12115 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12116 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12117 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12118 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12119 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12120 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12121 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12122 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12123 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12124 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12125 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12126 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12127 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12128 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12129 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12130 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12131 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12132 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12133 {NULL, 0, 0}
12134};
7ed4c4c5 12135
c19d1205
ZW
12136/* ISA extensions in the co-processor space. */
12137struct arm_option_value_table
12138{
12139 char *name;
12140 int value;
12141};
7ed4c4c5 12142
c19d1205
ZW
12143static struct arm_option_value_table arm_extensions[] =
12144{
12145 {"maverick", ARM_CEXT_MAVERICK},
12146 {"xscale", ARM_CEXT_XSCALE},
12147 {"iwmmxt", ARM_CEXT_IWMMXT},
12148 {NULL, 0}
12149};
7ed4c4c5 12150
c19d1205
ZW
12151/* This list should, at a minimum, contain all the fpu names
12152 recognized by GCC. */
12153static struct arm_option_value_table arm_fpus[] =
12154{
12155 {"softfpa", FPU_NONE},
12156 {"fpe", FPU_ARCH_FPE},
12157 {"fpe2", FPU_ARCH_FPE},
12158 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12159 {"fpa", FPU_ARCH_FPA},
12160 {"fpa10", FPU_ARCH_FPA},
12161 {"fpa11", FPU_ARCH_FPA},
12162 {"arm7500fe", FPU_ARCH_FPA},
12163 {"softvfp", FPU_ARCH_VFP},
12164 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12165 {"vfp", FPU_ARCH_VFP_V2},
12166 {"vfp9", FPU_ARCH_VFP_V2},
12167 {"vfp10", FPU_ARCH_VFP_V2},
12168 {"vfp10-r0", FPU_ARCH_VFP_V1},
12169 {"vfpxd", FPU_ARCH_VFP_V1xD},
12170 {"arm1020t", FPU_ARCH_VFP_V1},
12171 {"arm1020e", FPU_ARCH_VFP_V2},
12172 {"arm1136jfs", FPU_ARCH_VFP_V2},
12173 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12174 {"maverick", FPU_ARCH_MAVERICK},
12175 {NULL, 0}
12176};
7ed4c4c5 12177
c19d1205
ZW
12178static struct arm_option_value_table arm_float_abis[] =
12179{
12180 {"hard", ARM_FLOAT_ABI_HARD},
12181 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12182 {"soft", ARM_FLOAT_ABI_SOFT},
12183 {NULL, 0}
12184};
7ed4c4c5 12185
c19d1205
ZW
12186#ifdef OBJ_ELF
12187/* We only know how to output GNU and ver 4 (AAELF) formats. */
12188static struct arm_option_value_table arm_eabis[] =
12189{
12190 {"gnu", EF_ARM_EABI_UNKNOWN},
12191 {"4", EF_ARM_EABI_VER4},
12192 {NULL, 0}
12193};
12194#endif
7ed4c4c5 12195
c19d1205
ZW
12196struct arm_long_option_table
12197{
12198 char * option; /* Substring to match. */
12199 char * help; /* Help information. */
12200 int (* func) (char * subopt); /* Function to decode sub-option. */
12201 char * deprecated; /* If non-null, print this message. */
12202};
7ed4c4c5
NC
12203
12204static int
c19d1205 12205arm_parse_extension (char * str, int * opt_p)
7ed4c4c5 12206{
c19d1205 12207 while (str != NULL && *str != 0)
7ed4c4c5 12208 {
c19d1205
ZW
12209 struct arm_option_value_table * opt;
12210 char * ext;
12211 int optlen;
7ed4c4c5 12212
c19d1205
ZW
12213 if (*str != '+')
12214 {
12215 as_bad (_("invalid architectural extension"));
12216 return 0;
12217 }
7ed4c4c5 12218
c19d1205
ZW
12219 str++;
12220 ext = strchr (str, '+');
7ed4c4c5 12221
c19d1205
ZW
12222 if (ext != NULL)
12223 optlen = ext - str;
12224 else
12225 optlen = strlen (str);
7ed4c4c5 12226
c19d1205
ZW
12227 if (optlen == 0)
12228 {
12229 as_bad (_("missing architectural extension"));
12230 return 0;
12231 }
7ed4c4c5 12232
c19d1205
ZW
12233 for (opt = arm_extensions; opt->name != NULL; opt++)
12234 if (strncmp (opt->name, str, optlen) == 0)
12235 {
12236 *opt_p |= opt->value;
12237 break;
12238 }
7ed4c4c5 12239
c19d1205
ZW
12240 if (opt->name == NULL)
12241 {
12242 as_bad (_("unknown architectural extnsion `%s'"), str);
12243 return 0;
12244 }
7ed4c4c5 12245
c19d1205
ZW
12246 str = ext;
12247 };
7ed4c4c5 12248
c19d1205
ZW
12249 return 1;
12250}
7ed4c4c5 12251
c19d1205
ZW
12252static int
12253arm_parse_cpu (char * str)
7ed4c4c5 12254{
c19d1205
ZW
12255 struct arm_cpu_option_table * opt;
12256 char * ext = strchr (str, '+');
12257 int optlen;
7ed4c4c5 12258
c19d1205
ZW
12259 if (ext != NULL)
12260 optlen = ext - str;
7ed4c4c5 12261 else
c19d1205 12262 optlen = strlen (str);
7ed4c4c5 12263
c19d1205 12264 if (optlen == 0)
7ed4c4c5 12265 {
c19d1205
ZW
12266 as_bad (_("missing cpu name `%s'"), str);
12267 return 0;
7ed4c4c5
NC
12268 }
12269
c19d1205
ZW
12270 for (opt = arm_cpus; opt->name != NULL; opt++)
12271 if (strncmp (opt->name, str, optlen) == 0)
12272 {
12273 mcpu_cpu_opt = opt->value;
12274 mcpu_fpu_opt = opt->default_fpu;
7ed4c4c5 12275
c19d1205
ZW
12276 if (ext != NULL)
12277 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 12278
c19d1205
ZW
12279 return 1;
12280 }
7ed4c4c5 12281
c19d1205
ZW
12282 as_bad (_("unknown cpu `%s'"), str);
12283 return 0;
7ed4c4c5
NC
12284}
12285
c19d1205
ZW
12286static int
12287arm_parse_arch (char * str)
7ed4c4c5 12288{
c19d1205
ZW
12289 struct arm_arch_option_table *opt;
12290 char *ext = strchr (str, '+');
12291 int optlen;
7ed4c4c5 12292
c19d1205
ZW
12293 if (ext != NULL)
12294 optlen = ext - str;
7ed4c4c5 12295 else
c19d1205 12296 optlen = strlen (str);
7ed4c4c5 12297
c19d1205 12298 if (optlen == 0)
7ed4c4c5 12299 {
c19d1205
ZW
12300 as_bad (_("missing architecture name `%s'"), str);
12301 return 0;
7ed4c4c5
NC
12302 }
12303
7ed4c4c5 12304
c19d1205
ZW
12305 for (opt = arm_archs; opt->name != NULL; opt++)
12306 if (streq (opt->name, str))
12307 {
12308 march_cpu_opt = opt->value;
12309 march_fpu_opt = opt->default_fpu;
7ed4c4c5 12310
c19d1205
ZW
12311 if (ext != NULL)
12312 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 12313
c19d1205
ZW
12314 return 1;
12315 }
12316
12317 as_bad (_("unknown architecture `%s'\n"), str);
12318 return 0;
7ed4c4c5 12319}
eb043451 12320
c19d1205
ZW
12321static int
12322arm_parse_fpu (char * str)
12323{
12324 struct arm_option_value_table * opt;
b99bd4ef 12325
c19d1205
ZW
12326 for (opt = arm_fpus; opt->name != NULL; opt++)
12327 if (streq (opt->name, str))
12328 {
12329 mfpu_opt = opt->value;
12330 return 1;
12331 }
b99bd4ef 12332
c19d1205
ZW
12333 as_bad (_("unknown floating point format `%s'\n"), str);
12334 return 0;
12335}
12336
12337static int
12338arm_parse_float_abi (char * str)
b99bd4ef 12339{
c19d1205 12340 struct arm_option_value_table * opt;
b99bd4ef 12341
c19d1205
ZW
12342 for (opt = arm_float_abis; opt->name != NULL; opt++)
12343 if (streq (opt->name, str))
12344 {
12345 mfloat_abi_opt = opt->value;
12346 return 1;
12347 }
cc8a6dd0 12348
c19d1205
ZW
12349 as_bad (_("unknown floating point abi `%s'\n"), str);
12350 return 0;
12351}
b99bd4ef 12352
c19d1205
ZW
12353#ifdef OBJ_ELF
12354static int
12355arm_parse_eabi (char * str)
12356{
12357 struct arm_option_value_table *opt;
cc8a6dd0 12358
c19d1205
ZW
12359 for (opt = arm_eabis; opt->name != NULL; opt++)
12360 if (streq (opt->name, str))
12361 {
12362 meabi_flags = opt->value;
12363 return 1;
12364 }
12365 as_bad (_("unknown EABI `%s'\n"), str);
12366 return 0;
12367}
12368#endif
cc8a6dd0 12369
c19d1205
ZW
12370struct arm_long_option_table arm_long_opts[] =
12371{
12372 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
12373 arm_parse_cpu, NULL},
12374 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
12375 arm_parse_arch, NULL},
12376 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
12377 arm_parse_fpu, NULL},
12378 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
12379 arm_parse_float_abi, NULL},
12380#ifdef OBJ_ELF
12381 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
12382 arm_parse_eabi, NULL},
12383#endif
12384 {NULL, NULL, 0, NULL}
12385};
cc8a6dd0 12386
c19d1205
ZW
12387int
12388md_parse_option (int c, char * arg)
12389{
12390 struct arm_option_table *opt;
12391 struct arm_long_option_table *lopt;
b99bd4ef 12392
c19d1205 12393 switch (c)
b99bd4ef 12394 {
c19d1205
ZW
12395#ifdef OPTION_EB
12396 case OPTION_EB:
12397 target_big_endian = 1;
12398 break;
12399#endif
cc8a6dd0 12400
c19d1205
ZW
12401#ifdef OPTION_EL
12402 case OPTION_EL:
12403 target_big_endian = 0;
12404 break;
12405#endif
b99bd4ef 12406
c19d1205
ZW
12407 case 'a':
12408 /* Listing option. Just ignore these, we don't support additional
12409 ones. */
12410 return 0;
b99bd4ef 12411
c19d1205
ZW
12412 default:
12413 for (opt = arm_opts; opt->option != NULL; opt++)
12414 {
12415 if (c == opt->option[0]
12416 && ((arg == NULL && opt->option[1] == 0)
12417 || streq (arg, opt->option + 1)))
12418 {
12419#if WARN_DEPRECATED
12420 /* If the option is deprecated, tell the user. */
12421 if (opt->deprecated != NULL)
12422 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
12423 arg ? arg : "", _(opt->deprecated));
12424#endif
b99bd4ef 12425
c19d1205
ZW
12426 if (opt->var != NULL)
12427 *opt->var = opt->value;
cc8a6dd0 12428
c19d1205
ZW
12429 return 1;
12430 }
12431 }
b99bd4ef 12432
c19d1205
ZW
12433 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12434 {
12435 /* These options are expected to have an argument. */
12436 if (c == lopt->option[0]
12437 && arg != NULL
12438 && strncmp (arg, lopt->option + 1,
12439 strlen (lopt->option + 1)) == 0)
12440 {
12441#if WARN_DEPRECATED
12442 /* If the option is deprecated, tell the user. */
12443 if (lopt->deprecated != NULL)
12444 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
12445 _(lopt->deprecated));
12446#endif
b99bd4ef 12447
c19d1205
ZW
12448 /* Call the sup-option parser. */
12449 return lopt->func (arg + strlen (lopt->option) - 1);
12450 }
12451 }
a737bd4d 12452
c19d1205
ZW
12453 return 0;
12454 }
a394c00f 12455
c19d1205
ZW
12456 return 1;
12457}
a394c00f 12458
c19d1205
ZW
12459void
12460md_show_usage (FILE * fp)
a394c00f 12461{
c19d1205
ZW
12462 struct arm_option_table *opt;
12463 struct arm_long_option_table *lopt;
a394c00f 12464
c19d1205 12465 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 12466
c19d1205
ZW
12467 for (opt = arm_opts; opt->option != NULL; opt++)
12468 if (opt->help != NULL)
12469 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 12470
c19d1205
ZW
12471 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12472 if (lopt->help != NULL)
12473 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 12474
c19d1205
ZW
12475#ifdef OPTION_EB
12476 fprintf (fp, _("\
12477 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
12478#endif
12479
c19d1205
ZW
12480#ifdef OPTION_EL
12481 fprintf (fp, _("\
12482 -EL assemble code for a little-endian cpu\n"));
a737bd4d 12483#endif
c19d1205 12484}
This page took 1.060145 seconds and 4 git commands to generate.