gas:
[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
55cf6793
ZW
1417 /* The compiler may generate BL instructions to local labels because
1418 it needs to perform a branch to a far away location. These labels
1419 do not have a corresponding ".real_start_of" label. To accomodate
1420 hand-written assembly, we don't insist on a leading ".L", just a
1421 leading dot. */
c19d1205
ZW
1422 if (name[0] == '.')
1423 return symbolP;
1424
1425 real_start = malloc (strlen (name) + strlen (STUB_NAME) + 1);
1426 sprintf (real_start, "%s%s", STUB_NAME, name);
1427
1428 new_target = symbol_find (real_start);
1429
1430 if (new_target == NULL)
1431 {
1432 as_warn ("Failed to find real start of function: %s\n", name);
1433 new_target = symbolP;
1434 }
1435
1436 free (real_start);
1437
1438 return new_target;
1439}
1440
1441static void
1442opcode_select (int width)
1443{
1444 switch (width)
1445 {
1446 case 16:
1447 if (! thumb_mode)
1448 {
1449 if (! (cpu_variant & ARM_EXT_V4T))
1450 as_bad (_("selected processor does not support THUMB opcodes"));
1451
1452 thumb_mode = 1;
1453 /* No need to force the alignment, since we will have been
1454 coming from ARM mode, which is word-aligned. */
1455 record_alignment (now_seg, 1);
1456 }
1457 mapping_state (MAP_THUMB);
1458 break;
1459
1460 case 32:
1461 if (thumb_mode)
1462 {
1463 if ((cpu_variant & ARM_ALL) == ARM_EXT_V4T)
1464 as_bad (_("selected processor does not support ARM opcodes"));
1465
1466 thumb_mode = 0;
1467
1468 if (!need_pass_2)
1469 frag_align (2, 0, 0);
1470
1471 record_alignment (now_seg, 1);
1472 }
1473 mapping_state (MAP_ARM);
1474 break;
1475
1476 default:
1477 as_bad (_("invalid instruction size selected (%d)"), width);
1478 }
1479}
1480
1481static void
1482s_arm (int ignore ATTRIBUTE_UNUSED)
1483{
1484 opcode_select (32);
1485 demand_empty_rest_of_line ();
1486}
1487
1488static void
1489s_thumb (int ignore ATTRIBUTE_UNUSED)
1490{
1491 opcode_select (16);
1492 demand_empty_rest_of_line ();
1493}
1494
1495static void
1496s_code (int unused ATTRIBUTE_UNUSED)
1497{
1498 int temp;
1499
1500 temp = get_absolute_expression ();
1501 switch (temp)
1502 {
1503 case 16:
1504 case 32:
1505 opcode_select (temp);
1506 break;
1507
1508 default:
1509 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1510 }
1511}
1512
1513static void
1514s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1515{
1516 /* If we are not already in thumb mode go into it, EVEN if
1517 the target processor does not support thumb instructions.
1518 This is used by gcc/config/arm/lib1funcs.asm for example
1519 to compile interworking support functions even if the
1520 target processor should not support interworking. */
1521 if (! thumb_mode)
1522 {
1523 thumb_mode = 2;
1524 record_alignment (now_seg, 1);
1525 }
1526
1527 demand_empty_rest_of_line ();
1528}
1529
1530static void
1531s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1532{
1533 s_thumb (0);
1534
1535 /* The following label is the name/address of the start of a Thumb function.
1536 We need to know this for the interworking support. */
1537 label_is_thumb_function_name = TRUE;
1538}
1539
1540/* Perform a .set directive, but also mark the alias as
1541 being a thumb function. */
1542
1543static void
1544s_thumb_set (int equiv)
1545{
1546 /* XXX the following is a duplicate of the code for s_set() in read.c
1547 We cannot just call that code as we need to get at the symbol that
1548 is created. */
1549 char * name;
1550 char delim;
1551 char * end_name;
1552 symbolS * symbolP;
1553
1554 /* Especial apologies for the random logic:
1555 This just grew, and could be parsed much more simply!
1556 Dean - in haste. */
1557 name = input_line_pointer;
1558 delim = get_symbol_end ();
1559 end_name = input_line_pointer;
1560 *end_name = delim;
1561
1562 if (*input_line_pointer != ',')
1563 {
1564 *end_name = 0;
1565 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1566 *end_name = delim;
1567 ignore_rest_of_line ();
1568 return;
1569 }
1570
1571 input_line_pointer++;
1572 *end_name = 0;
1573
1574 if (name[0] == '.' && name[1] == '\0')
1575 {
1576 /* XXX - this should not happen to .thumb_set. */
1577 abort ();
1578 }
1579
1580 if ((symbolP = symbol_find (name)) == NULL
1581 && (symbolP = md_undefined_symbol (name)) == NULL)
1582 {
1583#ifndef NO_LISTING
1584 /* When doing symbol listings, play games with dummy fragments living
1585 outside the normal fragment chain to record the file and line info
c19d1205 1586 for this symbol. */
b99bd4ef
NC
1587 if (listing & LISTING_SYMBOLS)
1588 {
1589 extern struct list_info_struct * listing_tail;
a737bd4d 1590 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1591
1592 memset (dummy_frag, 0, sizeof (fragS));
1593 dummy_frag->fr_type = rs_fill;
1594 dummy_frag->line = listing_tail;
1595 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1596 dummy_frag->fr_symbol = symbolP;
1597 }
1598 else
1599#endif
1600 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1601
1602#ifdef OBJ_COFF
1603 /* "set" symbols are local unless otherwise specified. */
1604 SF_SET_LOCAL (symbolP);
1605#endif /* OBJ_COFF */
1606 } /* Make a new symbol. */
1607
1608 symbol_table_insert (symbolP);
1609
1610 * end_name = delim;
1611
1612 if (equiv
1613 && S_IS_DEFINED (symbolP)
1614 && S_GET_SEGMENT (symbolP) != reg_section)
1615 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1616
1617 pseudo_set (symbolP);
1618
1619 demand_empty_rest_of_line ();
1620
c19d1205 1621 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1622
1623 THUMB_SET_FUNC (symbolP, 1);
1624 ARM_SET_THUMB (symbolP, 1);
1625#if defined OBJ_ELF || defined OBJ_COFF
1626 ARM_SET_INTERWORK (symbolP, support_interwork);
1627#endif
1628}
1629
c19d1205 1630/* Directives: Mode selection. */
b99bd4ef 1631
c19d1205
ZW
1632/* .syntax [unified|divided] - choose the new unified syntax
1633 (same for Arm and Thumb encoding, modulo slight differences in what
1634 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1635static void
c19d1205 1636s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1637{
c19d1205
ZW
1638 char *name, delim;
1639
1640 name = input_line_pointer;
1641 delim = get_symbol_end ();
1642
1643 if (!strcasecmp (name, "unified"))
1644 unified_syntax = TRUE;
1645 else if (!strcasecmp (name, "divided"))
1646 unified_syntax = FALSE;
1647 else
1648 {
1649 as_bad (_("unrecognized syntax mode \"%s\""), name);
1650 return;
1651 }
1652 *input_line_pointer = delim;
b99bd4ef
NC
1653 demand_empty_rest_of_line ();
1654}
1655
c19d1205
ZW
1656/* Directives: sectioning and alignment. */
1657
1658/* Same as s_align_ptwo but align 0 => align 2. */
1659
b99bd4ef 1660static void
c19d1205 1661s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1662{
a737bd4d 1663 int temp;
c19d1205
ZW
1664 long temp_fill;
1665 long max_alignment = 15;
b99bd4ef
NC
1666
1667 temp = get_absolute_expression ();
c19d1205
ZW
1668 if (temp > max_alignment)
1669 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1670 else if (temp < 0)
b99bd4ef 1671 {
c19d1205
ZW
1672 as_bad (_("alignment negative. 0 assumed."));
1673 temp = 0;
1674 }
b99bd4ef 1675
c19d1205
ZW
1676 if (*input_line_pointer == ',')
1677 {
1678 input_line_pointer++;
1679 temp_fill = get_absolute_expression ();
b99bd4ef 1680 }
c19d1205
ZW
1681 else
1682 temp_fill = 0;
b99bd4ef 1683
c19d1205
ZW
1684 if (!temp)
1685 temp = 2;
b99bd4ef 1686
c19d1205
ZW
1687 /* Only make a frag if we HAVE to. */
1688 if (temp && !need_pass_2)
1689 frag_align (temp, (int) temp_fill, 0);
1690 demand_empty_rest_of_line ();
1691
1692 record_alignment (now_seg, temp);
b99bd4ef
NC
1693}
1694
c19d1205
ZW
1695static void
1696s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1697{
c19d1205
ZW
1698 /* We don't support putting frags in the BSS segment, we fake it by
1699 marking in_bss, then looking at s_skip for clues. */
1700 subseg_set (bss_section, 0);
1701 demand_empty_rest_of_line ();
1702 mapping_state (MAP_DATA);
1703}
b99bd4ef 1704
c19d1205
ZW
1705static void
1706s_even (int ignore ATTRIBUTE_UNUSED)
1707{
1708 /* Never make frag if expect extra pass. */
1709 if (!need_pass_2)
1710 frag_align (1, 0, 0);
b99bd4ef 1711
c19d1205 1712 record_alignment (now_seg, 1);
b99bd4ef 1713
c19d1205 1714 demand_empty_rest_of_line ();
b99bd4ef
NC
1715}
1716
c19d1205 1717/* Directives: Literal pools. */
a737bd4d 1718
c19d1205
ZW
1719static literal_pool *
1720find_literal_pool (void)
a737bd4d 1721{
c19d1205 1722 literal_pool * pool;
a737bd4d 1723
c19d1205 1724 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1725 {
c19d1205
ZW
1726 if (pool->section == now_seg
1727 && pool->sub_section == now_subseg)
1728 break;
a737bd4d
NC
1729 }
1730
c19d1205 1731 return pool;
a737bd4d
NC
1732}
1733
c19d1205
ZW
1734static literal_pool *
1735find_or_make_literal_pool (void)
a737bd4d 1736{
c19d1205
ZW
1737 /* Next literal pool ID number. */
1738 static unsigned int latest_pool_num = 1;
1739 literal_pool * pool;
a737bd4d 1740
c19d1205 1741 pool = find_literal_pool ();
a737bd4d 1742
c19d1205 1743 if (pool == NULL)
a737bd4d 1744 {
c19d1205
ZW
1745 /* Create a new pool. */
1746 pool = xmalloc (sizeof (* pool));
1747 if (! pool)
1748 return NULL;
a737bd4d 1749
c19d1205
ZW
1750 pool->next_free_entry = 0;
1751 pool->section = now_seg;
1752 pool->sub_section = now_subseg;
1753 pool->next = list_of_pools;
1754 pool->symbol = NULL;
1755
1756 /* Add it to the list. */
1757 list_of_pools = pool;
a737bd4d 1758 }
a737bd4d 1759
c19d1205
ZW
1760 /* New pools, and emptied pools, will have a NULL symbol. */
1761 if (pool->symbol == NULL)
a737bd4d 1762 {
c19d1205
ZW
1763 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1764 (valueT) 0, &zero_address_frag);
1765 pool->id = latest_pool_num ++;
a737bd4d
NC
1766 }
1767
c19d1205
ZW
1768 /* Done. */
1769 return pool;
a737bd4d
NC
1770}
1771
c19d1205
ZW
1772/* Add the literal in the global 'inst'
1773 structure to the relevent literal pool. */
b99bd4ef
NC
1774
1775static int
c19d1205 1776add_to_lit_pool (void)
b99bd4ef 1777{
c19d1205
ZW
1778 literal_pool * pool;
1779 unsigned int entry;
b99bd4ef 1780
c19d1205
ZW
1781 pool = find_or_make_literal_pool ();
1782
1783 /* Check if this literal value is already in the pool. */
1784 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1785 {
c19d1205
ZW
1786 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1787 && (inst.reloc.exp.X_op == O_constant)
1788 && (pool->literals[entry].X_add_number
1789 == inst.reloc.exp.X_add_number)
1790 && (pool->literals[entry].X_unsigned
1791 == inst.reloc.exp.X_unsigned))
1792 break;
1793
1794 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1795 && (inst.reloc.exp.X_op == O_symbol)
1796 && (pool->literals[entry].X_add_number
1797 == inst.reloc.exp.X_add_number)
1798 && (pool->literals[entry].X_add_symbol
1799 == inst.reloc.exp.X_add_symbol)
1800 && (pool->literals[entry].X_op_symbol
1801 == inst.reloc.exp.X_op_symbol))
1802 break;
b99bd4ef
NC
1803 }
1804
c19d1205
ZW
1805 /* Do we need to create a new entry? */
1806 if (entry == pool->next_free_entry)
1807 {
1808 if (entry >= MAX_LITERAL_POOL_SIZE)
1809 {
1810 inst.error = _("literal pool overflow");
1811 return FAIL;
1812 }
1813
1814 pool->literals[entry] = inst.reloc.exp;
1815 pool->next_free_entry += 1;
1816 }
b99bd4ef 1817
c19d1205
ZW
1818 inst.reloc.exp.X_op = O_symbol;
1819 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1820 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1821
c19d1205 1822 return SUCCESS;
b99bd4ef
NC
1823}
1824
c19d1205
ZW
1825/* Can't use symbol_new here, so have to create a symbol and then at
1826 a later date assign it a value. Thats what these functions do. */
e16bb312 1827
c19d1205
ZW
1828static void
1829symbol_locate (symbolS * symbolP,
1830 const char * name, /* It is copied, the caller can modify. */
1831 segT segment, /* Segment identifier (SEG_<something>). */
1832 valueT valu, /* Symbol value. */
1833 fragS * frag) /* Associated fragment. */
1834{
1835 unsigned int name_length;
1836 char * preserved_copy_of_name;
e16bb312 1837
c19d1205
ZW
1838 name_length = strlen (name) + 1; /* +1 for \0. */
1839 obstack_grow (&notes, name, name_length);
1840 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1841
c19d1205
ZW
1842#ifdef tc_canonicalize_symbol_name
1843 preserved_copy_of_name =
1844 tc_canonicalize_symbol_name (preserved_copy_of_name);
1845#endif
b99bd4ef 1846
c19d1205 1847 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1848
c19d1205
ZW
1849 S_SET_SEGMENT (symbolP, segment);
1850 S_SET_VALUE (symbolP, valu);
1851 symbol_clear_list_pointers (symbolP);
b99bd4ef 1852
c19d1205 1853 symbol_set_frag (symbolP, frag);
b99bd4ef 1854
c19d1205
ZW
1855 /* Link to end of symbol chain. */
1856 {
1857 extern int symbol_table_frozen;
b99bd4ef 1858
c19d1205
ZW
1859 if (symbol_table_frozen)
1860 abort ();
1861 }
b99bd4ef 1862
c19d1205 1863 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1864
c19d1205 1865 obj_symbol_new_hook (symbolP);
b99bd4ef 1866
c19d1205
ZW
1867#ifdef tc_symbol_new_hook
1868 tc_symbol_new_hook (symbolP);
1869#endif
1870
1871#ifdef DEBUG_SYMS
1872 verify_symbol_chain (symbol_rootP, symbol_lastP);
1873#endif /* DEBUG_SYMS */
b99bd4ef
NC
1874}
1875
b99bd4ef 1876
c19d1205
ZW
1877static void
1878s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1879{
c19d1205
ZW
1880 unsigned int entry;
1881 literal_pool * pool;
1882 char sym_name[20];
b99bd4ef 1883
c19d1205
ZW
1884 pool = find_literal_pool ();
1885 if (pool == NULL
1886 || pool->symbol == NULL
1887 || pool->next_free_entry == 0)
1888 return;
b99bd4ef 1889
c19d1205 1890 mapping_state (MAP_DATA);
b99bd4ef 1891
c19d1205
ZW
1892 /* Align pool as you have word accesses.
1893 Only make a frag if we have to. */
1894 if (!need_pass_2)
1895 frag_align (2, 0, 0);
b99bd4ef 1896
c19d1205 1897 record_alignment (now_seg, 2);
b99bd4ef 1898
c19d1205 1899 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1900
c19d1205
ZW
1901 symbol_locate (pool->symbol, sym_name, now_seg,
1902 (valueT) frag_now_fix (), frag_now);
1903 symbol_table_insert (pool->symbol);
b99bd4ef 1904
c19d1205 1905 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1906
c19d1205
ZW
1907#if defined OBJ_COFF || defined OBJ_ELF
1908 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1909#endif
6c43fab6 1910
c19d1205
ZW
1911 for (entry = 0; entry < pool->next_free_entry; entry ++)
1912 /* First output the expression in the instruction to the pool. */
1913 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1914
c19d1205
ZW
1915 /* Mark the pool as empty. */
1916 pool->next_free_entry = 0;
1917 pool->symbol = NULL;
b99bd4ef
NC
1918}
1919
c19d1205
ZW
1920#ifdef OBJ_ELF
1921/* Forward declarations for functions below, in the MD interface
1922 section. */
1923static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1924static valueT create_unwind_entry (int);
1925static void start_unwind_section (const segT, int);
1926static void add_unwind_opcode (valueT, int);
1927static void flush_pending_unwind (void);
b99bd4ef 1928
c19d1205 1929/* Directives: Data. */
b99bd4ef 1930
c19d1205
ZW
1931static void
1932s_arm_elf_cons (int nbytes)
1933{
1934 expressionS exp;
b99bd4ef 1935
c19d1205
ZW
1936#ifdef md_flush_pending_output
1937 md_flush_pending_output ();
1938#endif
b99bd4ef 1939
c19d1205 1940 if (is_it_end_of_statement ())
b99bd4ef 1941 {
c19d1205
ZW
1942 demand_empty_rest_of_line ();
1943 return;
b99bd4ef
NC
1944 }
1945
c19d1205
ZW
1946#ifdef md_cons_align
1947 md_cons_align (nbytes);
1948#endif
b99bd4ef 1949
c19d1205
ZW
1950 mapping_state (MAP_DATA);
1951 do
b99bd4ef 1952 {
c19d1205
ZW
1953 int reloc;
1954 char *base = input_line_pointer;
b99bd4ef 1955
c19d1205 1956 expression (& exp);
b99bd4ef 1957
c19d1205
ZW
1958 if (exp.X_op != O_symbol)
1959 emit_expr (&exp, (unsigned int) nbytes);
1960 else
1961 {
1962 char *before_reloc = input_line_pointer;
1963 reloc = parse_reloc (&input_line_pointer);
1964 if (reloc == -1)
1965 {
1966 as_bad (_("unrecognized relocation suffix"));
1967 ignore_rest_of_line ();
1968 return;
1969 }
1970 else if (reloc == BFD_RELOC_UNUSED)
1971 emit_expr (&exp, (unsigned int) nbytes);
1972 else
1973 {
1974 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
1975 int size = bfd_get_reloc_size (howto);
b99bd4ef 1976
c19d1205
ZW
1977 if (size > nbytes)
1978 as_bad ("%s relocations do not fit in %d bytes",
1979 howto->name, nbytes);
1980 else
1981 {
1982 /* We've parsed an expression stopping at O_symbol.
1983 But there may be more expression left now that we
1984 have parsed the relocation marker. Parse it again.
1985 XXX Surely there is a cleaner way to do this. */
1986 char *p = input_line_pointer;
1987 int offset;
1988 char *save_buf = alloca (input_line_pointer - base);
1989 memcpy (save_buf, base, input_line_pointer - base);
1990 memmove (base + (input_line_pointer - before_reloc),
1991 base, before_reloc - base);
1992
1993 input_line_pointer = base + (input_line_pointer-before_reloc);
1994 expression (&exp);
1995 memcpy (base, save_buf, p - base);
1996
1997 offset = nbytes - size;
1998 p = frag_more ((int) nbytes);
1999 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2000 size, &exp, 0, reloc);
2001 }
2002 }
2003 }
b99bd4ef 2004 }
c19d1205 2005 while (*input_line_pointer++ == ',');
b99bd4ef 2006
c19d1205
ZW
2007 /* Put terminator back into stream. */
2008 input_line_pointer --;
2009 demand_empty_rest_of_line ();
b99bd4ef
NC
2010}
2011
b99bd4ef 2012
c19d1205 2013/* Parse a .rel31 directive. */
b99bd4ef 2014
c19d1205
ZW
2015static void
2016s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2017{
2018 expressionS exp;
2019 char *p;
2020 valueT highbit;
b99bd4ef 2021
c19d1205
ZW
2022 highbit = 0;
2023 if (*input_line_pointer == '1')
2024 highbit = 0x80000000;
2025 else if (*input_line_pointer != '0')
2026 as_bad (_("expected 0 or 1"));
b99bd4ef 2027
c19d1205
ZW
2028 input_line_pointer++;
2029 if (*input_line_pointer != ',')
2030 as_bad (_("missing comma"));
2031 input_line_pointer++;
b99bd4ef 2032
c19d1205
ZW
2033#ifdef md_flush_pending_output
2034 md_flush_pending_output ();
2035#endif
b99bd4ef 2036
c19d1205
ZW
2037#ifdef md_cons_align
2038 md_cons_align (4);
2039#endif
b99bd4ef 2040
c19d1205 2041 mapping_state (MAP_DATA);
b99bd4ef 2042
c19d1205 2043 expression (&exp);
b99bd4ef 2044
c19d1205
ZW
2045 p = frag_more (4);
2046 md_number_to_chars (p, highbit, 4);
2047 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2048 BFD_RELOC_ARM_PREL31);
b99bd4ef 2049
c19d1205 2050 demand_empty_rest_of_line ();
b99bd4ef
NC
2051}
2052
c19d1205 2053/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2054
c19d1205 2055/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2056
c19d1205
ZW
2057static void
2058s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2059{
2060 demand_empty_rest_of_line ();
2061 /* Mark the start of the function. */
2062 unwind.proc_start = expr_build_dot ();
b99bd4ef 2063
c19d1205
ZW
2064 /* Reset the rest of the unwind info. */
2065 unwind.opcode_count = 0;
2066 unwind.table_entry = NULL;
2067 unwind.personality_routine = NULL;
2068 unwind.personality_index = -1;
2069 unwind.frame_size = 0;
2070 unwind.fp_offset = 0;
2071 unwind.fp_reg = 13;
2072 unwind.fp_used = 0;
2073 unwind.sp_restored = 0;
2074}
b99bd4ef 2075
b99bd4ef 2076
c19d1205
ZW
2077/* Parse a handlerdata directive. Creates the exception handling table entry
2078 for the function. */
b99bd4ef 2079
c19d1205
ZW
2080static void
2081s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2082{
2083 demand_empty_rest_of_line ();
2084 if (unwind.table_entry)
2085 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2086
c19d1205
ZW
2087 create_unwind_entry (1);
2088}
a737bd4d 2089
c19d1205 2090/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2091
c19d1205
ZW
2092static void
2093s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2094{
2095 long where;
2096 char *ptr;
2097 valueT val;
f02232aa 2098
c19d1205 2099 demand_empty_rest_of_line ();
f02232aa 2100
c19d1205
ZW
2101 /* Add eh table entry. */
2102 if (unwind.table_entry == NULL)
2103 val = create_unwind_entry (0);
2104 else
2105 val = 0;
f02232aa 2106
c19d1205
ZW
2107 /* Add index table entry. This is two words. */
2108 start_unwind_section (unwind.saved_seg, 1);
2109 frag_align (2, 0, 0);
2110 record_alignment (now_seg, 2);
b99bd4ef 2111
c19d1205
ZW
2112 ptr = frag_more (8);
2113 where = frag_now_fix () - 8;
f02232aa 2114
c19d1205
ZW
2115 /* Self relative offset of the function start. */
2116 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2117 BFD_RELOC_ARM_PREL31);
f02232aa 2118
c19d1205
ZW
2119 /* Indicate dependency on EHABI-defined personality routines to the
2120 linker, if it hasn't been done already. */
2121 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2122 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2123 {
2124 static const char *const name[] = {
2125 "__aeabi_unwind_cpp_pr0",
2126 "__aeabi_unwind_cpp_pr1",
2127 "__aeabi_unwind_cpp_pr2"
2128 };
2129 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2130 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2131 marked_pr_dependency |= 1 << unwind.personality_index;
2132 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2133 = marked_pr_dependency;
2134 }
f02232aa 2135
c19d1205
ZW
2136 if (val)
2137 /* Inline exception table entry. */
2138 md_number_to_chars (ptr + 4, val, 4);
2139 else
2140 /* Self relative offset of the table entry. */
2141 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2142 BFD_RELOC_ARM_PREL31);
f02232aa 2143
c19d1205
ZW
2144 /* Restore the original section. */
2145 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2146}
f02232aa 2147
f02232aa 2148
c19d1205 2149/* Parse an unwind_cantunwind directive. */
b99bd4ef 2150
c19d1205
ZW
2151static void
2152s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2153{
2154 demand_empty_rest_of_line ();
2155 if (unwind.personality_routine || unwind.personality_index != -1)
2156 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2157
c19d1205
ZW
2158 unwind.personality_index = -2;
2159}
b99bd4ef 2160
b99bd4ef 2161
c19d1205 2162/* Parse a personalityindex directive. */
b99bd4ef 2163
c19d1205
ZW
2164static void
2165s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2166{
2167 expressionS exp;
b99bd4ef 2168
c19d1205
ZW
2169 if (unwind.personality_routine || unwind.personality_index != -1)
2170 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2171
c19d1205 2172 expression (&exp);
b99bd4ef 2173
c19d1205
ZW
2174 if (exp.X_op != O_constant
2175 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2176 {
c19d1205
ZW
2177 as_bad (_("bad personality routine number"));
2178 ignore_rest_of_line ();
2179 return;
b99bd4ef
NC
2180 }
2181
c19d1205 2182 unwind.personality_index = exp.X_add_number;
b99bd4ef 2183
c19d1205
ZW
2184 demand_empty_rest_of_line ();
2185}
e16bb312 2186
e16bb312 2187
c19d1205 2188/* Parse a personality directive. */
e16bb312 2189
c19d1205
ZW
2190static void
2191s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2192{
2193 char *name, *p, c;
a737bd4d 2194
c19d1205
ZW
2195 if (unwind.personality_routine || unwind.personality_index != -1)
2196 as_bad (_("duplicate .personality directive"));
a737bd4d 2197
c19d1205
ZW
2198 name = input_line_pointer;
2199 c = get_symbol_end ();
2200 p = input_line_pointer;
2201 unwind.personality_routine = symbol_find_or_make (name);
2202 *p = c;
2203 demand_empty_rest_of_line ();
2204}
e16bb312 2205
e16bb312 2206
c19d1205 2207/* Parse a directive saving core registers. */
e16bb312 2208
c19d1205
ZW
2209static void
2210s_arm_unwind_save_core (void)
e16bb312 2211{
c19d1205
ZW
2212 valueT op;
2213 long range;
2214 int n;
e16bb312 2215
c19d1205
ZW
2216 range = parse_reg_list (&input_line_pointer);
2217 if (range == FAIL)
e16bb312 2218 {
c19d1205
ZW
2219 as_bad (_("expected register list"));
2220 ignore_rest_of_line ();
2221 return;
2222 }
e16bb312 2223
c19d1205 2224 demand_empty_rest_of_line ();
e16bb312 2225
c19d1205
ZW
2226 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2227 into .unwind_save {..., sp...}. We aren't bothered about the value of
2228 ip because it is clobbered by calls. */
2229 if (unwind.sp_restored && unwind.fp_reg == 12
2230 && (range & 0x3000) == 0x1000)
2231 {
2232 unwind.opcode_count--;
2233 unwind.sp_restored = 0;
2234 range = (range | 0x2000) & ~0x1000;
2235 unwind.pending_offset = 0;
2236 }
e16bb312 2237
c19d1205
ZW
2238 /* See if we can use the short opcodes. These pop a block of upto 8
2239 registers starting with r4, plus maybe r14. */
2240 for (n = 0; n < 8; n++)
2241 {
2242 /* Break at the first non-saved register. */
2243 if ((range & (1 << (n + 4))) == 0)
2244 break;
e16bb312 2245 }
c19d1205
ZW
2246 /* See if there are any other bits set. */
2247 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
e16bb312 2248 {
c19d1205
ZW
2249 /* Use the long form. */
2250 op = 0x8000 | ((range >> 4) & 0xfff);
2251 add_unwind_opcode (op, 2);
e16bb312 2252 }
c19d1205 2253 else
0dd132b6 2254 {
c19d1205
ZW
2255 /* Use the short form. */
2256 if (range & 0x4000)
2257 op = 0xa8; /* Pop r14. */
0dd132b6 2258 else
c19d1205
ZW
2259 op = 0xa0; /* Do not pop r14. */
2260 op |= (n - 1);
2261 add_unwind_opcode (op, 1);
2262 }
0dd132b6 2263
c19d1205
ZW
2264 /* Pop r0-r3. */
2265 if (range & 0xf)
2266 {
2267 op = 0xb100 | (range & 0xf);
2268 add_unwind_opcode (op, 2);
0dd132b6
NC
2269 }
2270
c19d1205
ZW
2271 /* Record the number of bytes pushed. */
2272 for (n = 0; n < 16; n++)
2273 {
2274 if (range & (1 << n))
2275 unwind.frame_size += 4;
2276 }
0dd132b6
NC
2277}
2278
c19d1205
ZW
2279
2280/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2281
2282static void
c19d1205 2283s_arm_unwind_save_fpa (int reg)
b99bd4ef 2284{
c19d1205
ZW
2285 expressionS exp;
2286 int num_regs;
2287 valueT op;
b99bd4ef 2288
c19d1205
ZW
2289 /* Get Number of registers to transfer. */
2290 if (skip_past_comma (&input_line_pointer) != FAIL)
2291 expression (&exp);
2292 else
2293 exp.X_op = O_illegal;
b99bd4ef 2294
c19d1205 2295 if (exp.X_op != O_constant)
b99bd4ef 2296 {
c19d1205
ZW
2297 as_bad (_("expected , <constant>"));
2298 ignore_rest_of_line ();
b99bd4ef
NC
2299 return;
2300 }
2301
c19d1205
ZW
2302 num_regs = exp.X_add_number;
2303
2304 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2305 {
c19d1205
ZW
2306 as_bad (_("number of registers must be in the range [1:4]"));
2307 ignore_rest_of_line ();
b99bd4ef
NC
2308 return;
2309 }
2310
c19d1205 2311 demand_empty_rest_of_line ();
b99bd4ef 2312
c19d1205
ZW
2313 if (reg == 4)
2314 {
2315 /* Short form. */
2316 op = 0xb4 | (num_regs - 1);
2317 add_unwind_opcode (op, 1);
2318 }
b99bd4ef
NC
2319 else
2320 {
c19d1205
ZW
2321 /* Long form. */
2322 op = 0xc800 | (reg << 4) | (num_regs - 1);
2323 add_unwind_opcode (op, 2);
b99bd4ef 2324 }
c19d1205 2325 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2326}
2327
c19d1205
ZW
2328
2329/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2330
2331static void
c19d1205 2332s_arm_unwind_save_vfp (void)
b99bd4ef 2333{
c19d1205
ZW
2334 int count;
2335 int reg;
2336 valueT op;
b99bd4ef 2337
c19d1205
ZW
2338 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2339 if (count == FAIL)
b99bd4ef 2340 {
c19d1205
ZW
2341 as_bad (_("expected register list"));
2342 ignore_rest_of_line ();
b99bd4ef
NC
2343 return;
2344 }
2345
c19d1205 2346 demand_empty_rest_of_line ();
b99bd4ef 2347
c19d1205 2348 if (reg == 8)
b99bd4ef 2349 {
c19d1205
ZW
2350 /* Short form. */
2351 op = 0xb8 | (count - 1);
2352 add_unwind_opcode (op, 1);
b99bd4ef 2353 }
c19d1205 2354 else
b99bd4ef 2355 {
c19d1205
ZW
2356 /* Long form. */
2357 op = 0xb300 | (reg << 4) | (count - 1);
2358 add_unwind_opcode (op, 2);
b99bd4ef 2359 }
c19d1205
ZW
2360 unwind.frame_size += count * 8 + 4;
2361}
b99bd4ef 2362
b99bd4ef 2363
c19d1205
ZW
2364/* Parse a directive saving iWMMXt data registers. */
2365
2366static void
2367s_arm_unwind_save_mmxwr (void)
2368{
2369 int reg;
2370 int hi_reg;
2371 int i;
2372 unsigned mask = 0;
2373 valueT op;
b99bd4ef 2374
c19d1205
ZW
2375 if (*input_line_pointer == '{')
2376 input_line_pointer++;
b99bd4ef 2377
c19d1205 2378 do
b99bd4ef 2379 {
c19d1205 2380 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2381
c19d1205 2382 if (reg == FAIL)
b99bd4ef 2383 {
c19d1205
ZW
2384 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2385 goto error;
b99bd4ef
NC
2386 }
2387
c19d1205
ZW
2388 if (mask >> reg)
2389 as_tsktsk (_("register list not in ascending order"));
2390 mask |= 1 << reg;
b99bd4ef 2391
c19d1205
ZW
2392 if (*input_line_pointer == '-')
2393 {
2394 input_line_pointer++;
2395 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2396 if (hi_reg == FAIL)
2397 {
2398 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2399 goto error;
2400 }
2401 else if (reg >= hi_reg)
2402 {
2403 as_bad (_("bad register range"));
2404 goto error;
2405 }
2406 for (; reg < hi_reg; reg++)
2407 mask |= 1 << reg;
2408 }
2409 }
2410 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2411
c19d1205
ZW
2412 if (*input_line_pointer == '}')
2413 input_line_pointer++;
b99bd4ef 2414
c19d1205 2415 demand_empty_rest_of_line ();
b99bd4ef 2416
c19d1205
ZW
2417 /* Generate any deferred opcodes becuuse we're going to be looking at
2418 the list. */
2419 flush_pending_unwind ();
b99bd4ef 2420
c19d1205 2421 for (i = 0; i < 16; i++)
b99bd4ef 2422 {
c19d1205
ZW
2423 if (mask & (1 << i))
2424 unwind.frame_size += 8;
b99bd4ef
NC
2425 }
2426
c19d1205
ZW
2427 /* Attempt to combine with a previous opcode. We do this because gcc
2428 likes to output separate unwind directives for a single block of
2429 registers. */
2430 if (unwind.opcode_count > 0)
b99bd4ef 2431 {
c19d1205
ZW
2432 i = unwind.opcodes[unwind.opcode_count - 1];
2433 if ((i & 0xf8) == 0xc0)
2434 {
2435 i &= 7;
2436 /* Only merge if the blocks are contiguous. */
2437 if (i < 6)
2438 {
2439 if ((mask & 0xfe00) == (1 << 9))
2440 {
2441 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2442 unwind.opcode_count--;
2443 }
2444 }
2445 else if (i == 6 && unwind.opcode_count >= 2)
2446 {
2447 i = unwind.opcodes[unwind.opcode_count - 2];
2448 reg = i >> 4;
2449 i &= 0xf;
b99bd4ef 2450
c19d1205
ZW
2451 op = 0xffff << (reg - 1);
2452 if (reg > 0
2453 || ((mask & op) == (1u << (reg - 1))))
2454 {
2455 op = (1 << (reg + i + 1)) - 1;
2456 op &= ~((1 << reg) - 1);
2457 mask |= op;
2458 unwind.opcode_count -= 2;
2459 }
2460 }
2461 }
b99bd4ef
NC
2462 }
2463
c19d1205
ZW
2464 hi_reg = 15;
2465 /* We want to generate opcodes in the order the registers have been
2466 saved, ie. descending order. */
2467 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2468 {
c19d1205
ZW
2469 /* Save registers in blocks. */
2470 if (reg < 0
2471 || !(mask & (1 << reg)))
2472 {
2473 /* We found an unsaved reg. Generate opcodes to save the
2474 preceeding block. */
2475 if (reg != hi_reg)
2476 {
2477 if (reg == 9)
2478 {
2479 /* Short form. */
2480 op = 0xc0 | (hi_reg - 10);
2481 add_unwind_opcode (op, 1);
2482 }
2483 else
2484 {
2485 /* Long form. */
2486 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2487 add_unwind_opcode (op, 2);
2488 }
2489 }
2490 hi_reg = reg - 1;
2491 }
b99bd4ef
NC
2492 }
2493
c19d1205
ZW
2494 return;
2495error:
2496 ignore_rest_of_line ();
b99bd4ef
NC
2497}
2498
2499static void
c19d1205 2500s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2501{
c19d1205
ZW
2502 int reg;
2503 int hi_reg;
2504 unsigned mask = 0;
2505 valueT op;
b99bd4ef 2506
c19d1205
ZW
2507 if (*input_line_pointer == '{')
2508 input_line_pointer++;
b99bd4ef 2509
c19d1205 2510 do
b99bd4ef 2511 {
c19d1205 2512 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2513
c19d1205
ZW
2514 if (reg == FAIL)
2515 {
2516 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2517 goto error;
2518 }
b99bd4ef 2519
c19d1205
ZW
2520 reg -= 8;
2521 if (mask >> reg)
2522 as_tsktsk (_("register list not in ascending order"));
2523 mask |= 1 << reg;
b99bd4ef 2524
c19d1205
ZW
2525 if (*input_line_pointer == '-')
2526 {
2527 input_line_pointer++;
2528 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2529 if (hi_reg == FAIL)
2530 {
2531 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2532 goto error;
2533 }
2534 else if (reg >= hi_reg)
2535 {
2536 as_bad (_("bad register range"));
2537 goto error;
2538 }
2539 for (; reg < hi_reg; reg++)
2540 mask |= 1 << reg;
2541 }
b99bd4ef 2542 }
c19d1205 2543 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2544
c19d1205
ZW
2545 if (*input_line_pointer == '}')
2546 input_line_pointer++;
b99bd4ef 2547
c19d1205
ZW
2548 demand_empty_rest_of_line ();
2549
2550 /* Generate any deferred opcodes becuuse we're going to be looking at
2551 the list. */
2552 flush_pending_unwind ();
b99bd4ef 2553
c19d1205 2554 for (reg = 0; reg < 16; reg++)
b99bd4ef 2555 {
c19d1205
ZW
2556 if (mask & (1 << reg))
2557 unwind.frame_size += 4;
b99bd4ef 2558 }
c19d1205
ZW
2559 op = 0xc700 | mask;
2560 add_unwind_opcode (op, 2);
2561 return;
2562error:
2563 ignore_rest_of_line ();
b99bd4ef
NC
2564}
2565
c19d1205
ZW
2566
2567/* Parse an unwind_save directive. */
2568
b99bd4ef 2569static void
c19d1205 2570s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2571{
c19d1205
ZW
2572 char *peek;
2573 struct reg_entry *reg;
2574 bfd_boolean had_brace = FALSE;
b99bd4ef 2575
c19d1205
ZW
2576 /* Figure out what sort of save we have. */
2577 peek = input_line_pointer;
b99bd4ef 2578
c19d1205 2579 if (*peek == '{')
b99bd4ef 2580 {
c19d1205
ZW
2581 had_brace = TRUE;
2582 peek++;
b99bd4ef
NC
2583 }
2584
c19d1205 2585 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2586
c19d1205 2587 if (!reg)
b99bd4ef 2588 {
c19d1205
ZW
2589 as_bad (_("register expected"));
2590 ignore_rest_of_line ();
b99bd4ef
NC
2591 return;
2592 }
2593
c19d1205 2594 switch (reg->type)
b99bd4ef 2595 {
c19d1205
ZW
2596 case REG_TYPE_FN:
2597 if (had_brace)
2598 {
2599 as_bad (_("FPA .unwind_save does not take a register list"));
2600 ignore_rest_of_line ();
2601 return;
2602 }
2603 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2604 return;
c19d1205
ZW
2605
2606 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2607 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2608 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2609 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2610
2611 default:
2612 as_bad (_(".unwind_save does not support this kind of register"));
2613 ignore_rest_of_line ();
b99bd4ef 2614 }
c19d1205 2615}
b99bd4ef 2616
b99bd4ef 2617
c19d1205
ZW
2618/* Parse an unwind_movsp directive. */
2619
2620static void
2621s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2622{
2623 int reg;
2624 valueT op;
2625
2626 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2627 if (reg == FAIL)
b99bd4ef 2628 {
c19d1205
ZW
2629 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2630 ignore_rest_of_line ();
b99bd4ef
NC
2631 return;
2632 }
c19d1205 2633 demand_empty_rest_of_line ();
b99bd4ef 2634
c19d1205 2635 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2636 {
c19d1205 2637 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2638 return;
2639 }
2640
c19d1205
ZW
2641 if (unwind.fp_reg != REG_SP)
2642 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2643
c19d1205
ZW
2644 /* Generate opcode to restore the value. */
2645 op = 0x90 | reg;
2646 add_unwind_opcode (op, 1);
2647
2648 /* Record the information for later. */
2649 unwind.fp_reg = reg;
2650 unwind.fp_offset = unwind.frame_size;
2651 unwind.sp_restored = 1;
b05fe5cf
ZW
2652}
2653
c19d1205
ZW
2654/* Parse an unwind_pad directive. */
2655
b05fe5cf 2656static void
c19d1205 2657s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2658{
c19d1205 2659 int offset;
b05fe5cf 2660
c19d1205
ZW
2661 if (immediate_for_directive (&offset) == FAIL)
2662 return;
b99bd4ef 2663
c19d1205
ZW
2664 if (offset & 3)
2665 {
2666 as_bad (_("stack increment must be multiple of 4"));
2667 ignore_rest_of_line ();
2668 return;
2669 }
b99bd4ef 2670
c19d1205
ZW
2671 /* Don't generate any opcodes, just record the details for later. */
2672 unwind.frame_size += offset;
2673 unwind.pending_offset += offset;
2674
2675 demand_empty_rest_of_line ();
2676}
2677
2678/* Parse an unwind_setfp directive. */
2679
2680static void
2681s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2682{
c19d1205
ZW
2683 int sp_reg;
2684 int fp_reg;
2685 int offset;
2686
2687 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2688 if (skip_past_comma (&input_line_pointer) == FAIL)
2689 sp_reg = FAIL;
2690 else
2691 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2692
c19d1205
ZW
2693 if (fp_reg == FAIL || sp_reg == FAIL)
2694 {
2695 as_bad (_("expected <reg>, <reg>"));
2696 ignore_rest_of_line ();
2697 return;
2698 }
b99bd4ef 2699
c19d1205
ZW
2700 /* Optional constant. */
2701 if (skip_past_comma (&input_line_pointer) != FAIL)
2702 {
2703 if (immediate_for_directive (&offset) == FAIL)
2704 return;
2705 }
2706 else
2707 offset = 0;
a737bd4d 2708
c19d1205 2709 demand_empty_rest_of_line ();
a737bd4d 2710
c19d1205 2711 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2712 {
c19d1205
ZW
2713 as_bad (_("register must be either sp or set by a previous"
2714 "unwind_movsp directive"));
2715 return;
a737bd4d
NC
2716 }
2717
c19d1205
ZW
2718 /* Don't generate any opcodes, just record the information for later. */
2719 unwind.fp_reg = fp_reg;
2720 unwind.fp_used = 1;
2721 if (sp_reg == 13)
2722 unwind.fp_offset = unwind.frame_size - offset;
2723 else
2724 unwind.fp_offset -= offset;
a737bd4d
NC
2725}
2726
c19d1205
ZW
2727/* Parse an unwind_raw directive. */
2728
2729static void
2730s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2731{
c19d1205
ZW
2732 expressionS exp;
2733 /* This is an arbitary limit. */
2734 unsigned char op[16];
2735 int count;
a737bd4d 2736
c19d1205
ZW
2737 expression (&exp);
2738 if (exp.X_op == O_constant
2739 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2740 {
c19d1205
ZW
2741 unwind.frame_size += exp.X_add_number;
2742 expression (&exp);
2743 }
2744 else
2745 exp.X_op = O_illegal;
a737bd4d 2746
c19d1205
ZW
2747 if (exp.X_op != O_constant)
2748 {
2749 as_bad (_("expected <offset>, <opcode>"));
2750 ignore_rest_of_line ();
2751 return;
2752 }
a737bd4d 2753
c19d1205 2754 count = 0;
a737bd4d 2755
c19d1205
ZW
2756 /* Parse the opcode. */
2757 for (;;)
2758 {
2759 if (count >= 16)
2760 {
2761 as_bad (_("unwind opcode too long"));
2762 ignore_rest_of_line ();
a737bd4d 2763 }
c19d1205 2764 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2765 {
c19d1205
ZW
2766 as_bad (_("invalid unwind opcode"));
2767 ignore_rest_of_line ();
2768 return;
a737bd4d 2769 }
c19d1205 2770 op[count++] = exp.X_add_number;
a737bd4d 2771
c19d1205
ZW
2772 /* Parse the next byte. */
2773 if (skip_past_comma (&input_line_pointer) == FAIL)
2774 break;
a737bd4d 2775
c19d1205
ZW
2776 expression (&exp);
2777 }
b99bd4ef 2778
c19d1205
ZW
2779 /* Add the opcode bytes in reverse order. */
2780 while (count--)
2781 add_unwind_opcode (op[count], 1);
b99bd4ef 2782
c19d1205 2783 demand_empty_rest_of_line ();
b99bd4ef 2784}
c19d1205 2785#endif /* OBJ_ELF */
b99bd4ef 2786
c19d1205
ZW
2787/* This table describes all the machine specific pseudo-ops the assembler
2788 has to support. The fields are:
2789 pseudo-op name without dot
2790 function to call to execute this pseudo-op
2791 Integer arg to pass to the function. */
b99bd4ef 2792
c19d1205 2793const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2794{
c19d1205
ZW
2795 /* Never called because '.req' does not start a line. */
2796 { "req", s_req, 0 },
2797 { "unreq", s_unreq, 0 },
2798 { "bss", s_bss, 0 },
2799 { "align", s_align, 0 },
2800 { "arm", s_arm, 0 },
2801 { "thumb", s_thumb, 0 },
2802 { "code", s_code, 0 },
2803 { "force_thumb", s_force_thumb, 0 },
2804 { "thumb_func", s_thumb_func, 0 },
2805 { "thumb_set", s_thumb_set, 0 },
2806 { "even", s_even, 0 },
2807 { "ltorg", s_ltorg, 0 },
2808 { "pool", s_ltorg, 0 },
2809 { "syntax", s_syntax, 0 },
2810#ifdef OBJ_ELF
2811 { "word", s_arm_elf_cons, 4 },
2812 { "long", s_arm_elf_cons, 4 },
2813 { "rel31", s_arm_rel31, 0 },
2814 { "fnstart", s_arm_unwind_fnstart, 0 },
2815 { "fnend", s_arm_unwind_fnend, 0 },
2816 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2817 { "personality", s_arm_unwind_personality, 0 },
2818 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2819 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2820 { "save", s_arm_unwind_save, 0 },
2821 { "movsp", s_arm_unwind_movsp, 0 },
2822 { "pad", s_arm_unwind_pad, 0 },
2823 { "setfp", s_arm_unwind_setfp, 0 },
2824 { "unwind_raw", s_arm_unwind_raw, 0 },
2825#else
2826 { "word", cons, 4},
2827#endif
2828 { "extend", float_cons, 'x' },
2829 { "ldouble", float_cons, 'x' },
2830 { "packed", float_cons, 'p' },
2831 { 0, 0, 0 }
2832};
2833\f
2834/* Parser functions used exclusively in instruction operands. */
b99bd4ef 2835
c19d1205
ZW
2836/* Generic immediate-value read function for use in insn parsing.
2837 STR points to the beginning of the immediate (the leading #);
2838 VAL receives the value; if the value is outside [MIN, MAX]
2839 issue an error. PREFIX_OPT is true if the immediate prefix is
2840 optional. */
b99bd4ef 2841
c19d1205
ZW
2842static int
2843parse_immediate (char **str, int *val, int min, int max,
2844 bfd_boolean prefix_opt)
2845{
2846 expressionS exp;
2847 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2848 if (exp.X_op != O_constant)
b99bd4ef 2849 {
c19d1205
ZW
2850 inst.error = _("constant expression required");
2851 return FAIL;
2852 }
b99bd4ef 2853
c19d1205
ZW
2854 if (exp.X_add_number < min || exp.X_add_number > max)
2855 {
2856 inst.error = _("immediate value out of range");
2857 return FAIL;
2858 }
b99bd4ef 2859
c19d1205
ZW
2860 *val = exp.X_add_number;
2861 return SUCCESS;
2862}
b99bd4ef 2863
c19d1205
ZW
2864/* Returns the pseudo-register number of an FPA immediate constant,
2865 or FAIL if there isn't a valid constant here. */
b99bd4ef 2866
c19d1205
ZW
2867static int
2868parse_fpa_immediate (char ** str)
2869{
2870 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2871 char * save_in;
2872 expressionS exp;
2873 int i;
2874 int j;
b99bd4ef 2875
c19d1205
ZW
2876 /* First try and match exact strings, this is to guarantee
2877 that some formats will work even for cross assembly. */
b99bd4ef 2878
c19d1205
ZW
2879 for (i = 0; fp_const[i]; i++)
2880 {
2881 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 2882 {
c19d1205 2883 char *start = *str;
b99bd4ef 2884
c19d1205
ZW
2885 *str += strlen (fp_const[i]);
2886 if (is_end_of_line[(unsigned char) **str])
2887 return i + 8;
2888 *str = start;
2889 }
2890 }
b99bd4ef 2891
c19d1205
ZW
2892 /* Just because we didn't get a match doesn't mean that the constant
2893 isn't valid, just that it is in a format that we don't
2894 automatically recognize. Try parsing it with the standard
2895 expression routines. */
b99bd4ef 2896
c19d1205 2897 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 2898
c19d1205
ZW
2899 /* Look for a raw floating point number. */
2900 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
2901 && is_end_of_line[(unsigned char) *save_in])
2902 {
2903 for (i = 0; i < NUM_FLOAT_VALS; i++)
2904 {
2905 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 2906 {
c19d1205
ZW
2907 if (words[j] != fp_values[i][j])
2908 break;
b99bd4ef
NC
2909 }
2910
c19d1205 2911 if (j == MAX_LITTLENUMS)
b99bd4ef 2912 {
c19d1205
ZW
2913 *str = save_in;
2914 return i + 8;
b99bd4ef
NC
2915 }
2916 }
2917 }
b99bd4ef 2918
c19d1205
ZW
2919 /* Try and parse a more complex expression, this will probably fail
2920 unless the code uses a floating point prefix (eg "0f"). */
2921 save_in = input_line_pointer;
2922 input_line_pointer = *str;
2923 if (expression (&exp) == absolute_section
2924 && exp.X_op == O_big
2925 && exp.X_add_number < 0)
2926 {
2927 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
2928 Ditto for 15. */
2929 if (gen_to_words (words, 5, (long) 15) == 0)
2930 {
2931 for (i = 0; i < NUM_FLOAT_VALS; i++)
2932 {
2933 for (j = 0; j < MAX_LITTLENUMS; j++)
2934 {
2935 if (words[j] != fp_values[i][j])
2936 break;
2937 }
b99bd4ef 2938
c19d1205
ZW
2939 if (j == MAX_LITTLENUMS)
2940 {
2941 *str = input_line_pointer;
2942 input_line_pointer = save_in;
2943 return i + 8;
2944 }
2945 }
2946 }
b99bd4ef
NC
2947 }
2948
c19d1205
ZW
2949 *str = input_line_pointer;
2950 input_line_pointer = save_in;
2951 inst.error = _("invalid FPA immediate expression");
2952 return FAIL;
b99bd4ef
NC
2953}
2954
c19d1205
ZW
2955/* Shift operands. */
2956enum shift_kind
b99bd4ef 2957{
c19d1205
ZW
2958 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
2959};
b99bd4ef 2960
c19d1205
ZW
2961struct asm_shift_name
2962{
2963 const char *name;
2964 enum shift_kind kind;
2965};
b99bd4ef 2966
c19d1205
ZW
2967/* Third argument to parse_shift. */
2968enum parse_shift_mode
2969{
2970 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
2971 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
2972 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
2973 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
2974 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
2975};
b99bd4ef 2976
c19d1205
ZW
2977/* Parse a <shift> specifier on an ARM data processing instruction.
2978 This has three forms:
b99bd4ef 2979
c19d1205
ZW
2980 (LSL|LSR|ASL|ASR|ROR) Rs
2981 (LSL|LSR|ASL|ASR|ROR) #imm
2982 RRX
b99bd4ef 2983
c19d1205
ZW
2984 Note that ASL is assimilated to LSL in the instruction encoding, and
2985 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 2986
c19d1205
ZW
2987static int
2988parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 2989{
c19d1205
ZW
2990 const struct asm_shift_name *shift_name;
2991 enum shift_kind shift;
2992 char *s = *str;
2993 char *p = s;
2994 int reg;
b99bd4ef 2995
c19d1205
ZW
2996 for (p = *str; ISALPHA (*p); p++)
2997 ;
b99bd4ef 2998
c19d1205 2999 if (p == *str)
b99bd4ef 3000 {
c19d1205
ZW
3001 inst.error = _("shift expression expected");
3002 return FAIL;
b99bd4ef
NC
3003 }
3004
c19d1205
ZW
3005 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3006
3007 if (shift_name == NULL)
b99bd4ef 3008 {
c19d1205
ZW
3009 inst.error = _("shift expression expected");
3010 return FAIL;
b99bd4ef
NC
3011 }
3012
c19d1205 3013 shift = shift_name->kind;
b99bd4ef 3014
c19d1205
ZW
3015 switch (mode)
3016 {
3017 case NO_SHIFT_RESTRICT:
3018 case SHIFT_IMMEDIATE: break;
b99bd4ef 3019
c19d1205
ZW
3020 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3021 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3022 {
3023 inst.error = _("'LSL' or 'ASR' required");
3024 return FAIL;
3025 }
3026 break;
b99bd4ef 3027
c19d1205
ZW
3028 case SHIFT_LSL_IMMEDIATE:
3029 if (shift != SHIFT_LSL)
3030 {
3031 inst.error = _("'LSL' required");
3032 return FAIL;
3033 }
3034 break;
b99bd4ef 3035
c19d1205
ZW
3036 case SHIFT_ASR_IMMEDIATE:
3037 if (shift != SHIFT_ASR)
3038 {
3039 inst.error = _("'ASR' required");
3040 return FAIL;
3041 }
3042 break;
b99bd4ef 3043
c19d1205
ZW
3044 default: abort ();
3045 }
b99bd4ef 3046
c19d1205
ZW
3047 if (shift != SHIFT_RRX)
3048 {
3049 /* Whitespace can appear here if the next thing is a bare digit. */
3050 skip_whitespace (p);
b99bd4ef 3051
c19d1205
ZW
3052 if (mode == NO_SHIFT_RESTRICT
3053 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3054 {
3055 inst.operands[i].imm = reg;
3056 inst.operands[i].immisreg = 1;
3057 }
3058 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3059 return FAIL;
3060 }
3061 inst.operands[i].shift_kind = shift;
3062 inst.operands[i].shifted = 1;
3063 *str = p;
3064 return SUCCESS;
b99bd4ef
NC
3065}
3066
c19d1205 3067/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3068
c19d1205
ZW
3069 #<immediate>
3070 #<immediate>, <rotate>
3071 <Rm>
3072 <Rm>, <shift>
b99bd4ef 3073
c19d1205
ZW
3074 where <shift> is defined by parse_shift above, and <rotate> is a
3075 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3076 is deferred to md_apply_fix. */
b99bd4ef 3077
c19d1205
ZW
3078static int
3079parse_shifter_operand (char **str, int i)
3080{
3081 int value;
3082 expressionS expr;
b99bd4ef 3083
c19d1205
ZW
3084 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3085 {
3086 inst.operands[i].reg = value;
3087 inst.operands[i].isreg = 1;
b99bd4ef 3088
c19d1205
ZW
3089 /* parse_shift will override this if appropriate */
3090 inst.reloc.exp.X_op = O_constant;
3091 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3092
c19d1205
ZW
3093 if (skip_past_comma (str) == FAIL)
3094 return SUCCESS;
b99bd4ef 3095
c19d1205
ZW
3096 /* Shift operation on register. */
3097 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3098 }
3099
c19d1205
ZW
3100 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3101 return FAIL;
b99bd4ef 3102
c19d1205 3103 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3104 {
c19d1205
ZW
3105 /* #x, y -- ie explicit rotation by Y. */
3106 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3107 return FAIL;
b99bd4ef 3108
c19d1205
ZW
3109 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3110 {
3111 inst.error = _("constant expression expected");
3112 return FAIL;
3113 }
b99bd4ef 3114
c19d1205
ZW
3115 value = expr.X_add_number;
3116 if (value < 0 || value > 30 || value % 2 != 0)
3117 {
3118 inst.error = _("invalid rotation");
3119 return FAIL;
3120 }
3121 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3122 {
3123 inst.error = _("invalid constant");
3124 return FAIL;
3125 }
09d92015 3126
55cf6793 3127 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3128 inst.reloc.exp.X_add_number
3129 = (((inst.reloc.exp.X_add_number << (32 - value))
3130 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3131 }
3132
c19d1205
ZW
3133 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3134 inst.reloc.pc_rel = 0;
3135 return SUCCESS;
09d92015
MM
3136}
3137
c19d1205
ZW
3138/* Parse all forms of an ARM address expression. Information is written
3139 to inst.operands[i] and/or inst.reloc.
09d92015 3140
c19d1205 3141 Preindexed addressing (.preind=1):
09d92015 3142
c19d1205
ZW
3143 [Rn, #offset] .reg=Rn .reloc.exp=offset
3144 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3145 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3146 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3147
c19d1205 3148 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3149
c19d1205 3150 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3151
c19d1205
ZW
3152 [Rn], #offset .reg=Rn .reloc.exp=offset
3153 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3154 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3155 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3156
c19d1205 3157 Unindexed addressing (.preind=0, .postind=0):
09d92015 3158
c19d1205 3159 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3160
c19d1205 3161 Other:
09d92015 3162
c19d1205
ZW
3163 [Rn]{!} shorthand for [Rn,#0]{!}
3164 =immediate .isreg=0 .reloc.exp=immediate
3165 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3166
c19d1205
ZW
3167 It is the caller's responsibility to check for addressing modes not
3168 supported by the instruction, and to set inst.reloc.type. */
3169
3170static int
3171parse_address (char **str, int i)
09d92015 3172{
c19d1205
ZW
3173 char *p = *str;
3174 int reg;
09d92015 3175
c19d1205 3176 if (skip_past_char (&p, '[') == FAIL)
09d92015 3177 {
c19d1205
ZW
3178 if (skip_past_char (&p, '=') == FAIL)
3179 {
3180 /* bare address - translate to PC-relative offset */
3181 inst.reloc.pc_rel = 1;
3182 inst.operands[i].reg = REG_PC;
3183 inst.operands[i].isreg = 1;
3184 inst.operands[i].preind = 1;
3185 }
3186 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3187
c19d1205
ZW
3188 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3189 return FAIL;
09d92015 3190
c19d1205
ZW
3191 *str = p;
3192 return SUCCESS;
09d92015
MM
3193 }
3194
c19d1205 3195 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3196 {
c19d1205
ZW
3197 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3198 return FAIL;
09d92015 3199 }
c19d1205
ZW
3200 inst.operands[i].reg = reg;
3201 inst.operands[i].isreg = 1;
09d92015 3202
c19d1205 3203 if (skip_past_comma (&p) == SUCCESS)
09d92015 3204 {
c19d1205 3205 inst.operands[i].preind = 1;
09d92015 3206
c19d1205
ZW
3207 if (*p == '+') p++;
3208 else if (*p == '-') p++, inst.operands[i].negative = 1;
3209
3210 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3211 {
c19d1205
ZW
3212 inst.operands[i].imm = reg;
3213 inst.operands[i].immisreg = 1;
3214
3215 if (skip_past_comma (&p) == SUCCESS)
3216 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3217 return FAIL;
3218 }
3219 else
3220 {
3221 if (inst.operands[i].negative)
3222 {
3223 inst.operands[i].negative = 0;
3224 p--;
3225 }
3226 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3227 return FAIL;
09d92015
MM
3228 }
3229 }
3230
c19d1205 3231 if (skip_past_char (&p, ']') == FAIL)
09d92015 3232 {
c19d1205
ZW
3233 inst.error = _("']' expected");
3234 return FAIL;
09d92015
MM
3235 }
3236
c19d1205
ZW
3237 if (skip_past_char (&p, '!') == SUCCESS)
3238 inst.operands[i].writeback = 1;
09d92015 3239
c19d1205 3240 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3241 {
c19d1205
ZW
3242 if (skip_past_char (&p, '{') == SUCCESS)
3243 {
3244 /* [Rn], {expr} - unindexed, with option */
3245 if (parse_immediate (&p, &inst.operands[i].imm,
3246 0, 255, TRUE) == FAIL)
3247 return FAIL;
09d92015 3248
c19d1205
ZW
3249 if (skip_past_char (&p, '}') == FAIL)
3250 {
3251 inst.error = _("'}' expected at end of 'option' field");
3252 return FAIL;
3253 }
3254 if (inst.operands[i].preind)
3255 {
3256 inst.error = _("cannot combine index with option");
3257 return FAIL;
3258 }
3259 *str = p;
3260 return SUCCESS;
09d92015 3261 }
c19d1205
ZW
3262 else
3263 {
3264 inst.operands[i].postind = 1;
3265 inst.operands[i].writeback = 1;
09d92015 3266
c19d1205
ZW
3267 if (inst.operands[i].preind)
3268 {
3269 inst.error = _("cannot combine pre- and post-indexing");
3270 return FAIL;
3271 }
09d92015 3272
c19d1205
ZW
3273 if (*p == '+') p++;
3274 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3275
c19d1205
ZW
3276 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3277 {
3278 inst.operands[i].imm = reg;
3279 inst.operands[i].immisreg = 1;
a737bd4d 3280
c19d1205
ZW
3281 if (skip_past_comma (&p) == SUCCESS)
3282 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3283 return FAIL;
3284 }
3285 else
3286 {
3287 if (inst.operands[i].negative)
3288 {
3289 inst.operands[i].negative = 0;
3290 p--;
3291 }
3292 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3293 return FAIL;
3294 }
3295 }
a737bd4d
NC
3296 }
3297
c19d1205
ZW
3298 /* If at this point neither .preind nor .postind is set, we have a
3299 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3300 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3301 {
3302 inst.operands[i].preind = 1;
3303 inst.reloc.exp.X_op = O_constant;
3304 inst.reloc.exp.X_add_number = 0;
3305 }
3306 *str = p;
3307 return SUCCESS;
a737bd4d
NC
3308}
3309
c19d1205 3310/* Miscellaneous. */
a737bd4d 3311
c19d1205
ZW
3312/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3313 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3314static int
3315parse_psr (char **str)
09d92015 3316{
c19d1205
ZW
3317 char *p;
3318 unsigned long psr_field;
09d92015 3319
c19d1205
ZW
3320 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3321 feature for ease of use and backwards compatibility. */
3322 p = *str;
3323 if (*p == 's' || *p == 'S')
3324 psr_field = SPSR_BIT;
3325 else if (*p == 'c' || *p == 'C')
3326 psr_field = 0;
3327 else
3328 goto error;
09d92015 3329
c19d1205
ZW
3330 p++;
3331 if (strncasecmp (p, "PSR", 3) != 0)
3332 goto error;
3333 p += 3;
09d92015 3334
c19d1205
ZW
3335 if (*p == '_')
3336 {
3337 /* A suffix follows. */
3338 const struct asm_psr *psr;
3339 char *start;
a737bd4d 3340
c19d1205
ZW
3341 p++;
3342 start = p;
a737bd4d 3343
c19d1205
ZW
3344 do
3345 p++;
3346 while (ISALNUM (*p) || *p == '_');
a737bd4d 3347
c19d1205
ZW
3348 psr = hash_find_n (arm_psr_hsh, start, p - start);
3349 if (!psr)
3350 goto error;
a737bd4d 3351
c19d1205 3352 psr_field |= psr->field;
a737bd4d 3353 }
c19d1205 3354 else
a737bd4d 3355 {
c19d1205
ZW
3356 if (ISALNUM (*p))
3357 goto error; /* Garbage after "[CS]PSR". */
3358
3359 psr_field |= (PSR_c | PSR_f);
a737bd4d 3360 }
c19d1205
ZW
3361 *str = p;
3362 return psr_field;
a737bd4d 3363
c19d1205
ZW
3364 error:
3365 inst.error = _("flag for {c}psr instruction expected");
3366 return FAIL;
a737bd4d
NC
3367}
3368
c19d1205
ZW
3369/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3370 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3371
c19d1205
ZW
3372static int
3373parse_cps_flags (char **str)
a737bd4d 3374{
c19d1205
ZW
3375 int val = 0;
3376 int saw_a_flag = 0;
3377 char *s = *str;
a737bd4d 3378
c19d1205
ZW
3379 for (;;)
3380 switch (*s++)
3381 {
3382 case '\0': case ',':
3383 goto done;
a737bd4d 3384
c19d1205
ZW
3385 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3386 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3387 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3388
c19d1205
ZW
3389 default:
3390 inst.error = _("unrecognized CPS flag");
3391 return FAIL;
3392 }
a737bd4d 3393
c19d1205
ZW
3394 done:
3395 if (saw_a_flag == 0)
a737bd4d 3396 {
c19d1205
ZW
3397 inst.error = _("missing CPS flags");
3398 return FAIL;
a737bd4d 3399 }
a737bd4d 3400
c19d1205
ZW
3401 *str = s - 1;
3402 return val;
a737bd4d
NC
3403}
3404
c19d1205
ZW
3405/* Parse an endian specifier ("BE" or "LE", case insensitive);
3406 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3407
3408static int
c19d1205 3409parse_endian_specifier (char **str)
a737bd4d 3410{
c19d1205
ZW
3411 int little_endian;
3412 char *s = *str;
a737bd4d 3413
c19d1205
ZW
3414 if (strncasecmp (s, "BE", 2))
3415 little_endian = 0;
3416 else if (strncasecmp (s, "LE", 2))
3417 little_endian = 1;
3418 else
a737bd4d 3419 {
c19d1205 3420 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3421 return FAIL;
3422 }
3423
c19d1205 3424 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3425 {
c19d1205 3426 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3427 return FAIL;
3428 }
3429
c19d1205
ZW
3430 *str = s + 2;
3431 return little_endian;
3432}
a737bd4d 3433
c19d1205
ZW
3434/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3435 value suitable for poking into the rotate field of an sxt or sxta
3436 instruction, or FAIL on error. */
3437
3438static int
3439parse_ror (char **str)
3440{
3441 int rot;
3442 char *s = *str;
3443
3444 if (strncasecmp (s, "ROR", 3) == 0)
3445 s += 3;
3446 else
a737bd4d 3447 {
c19d1205 3448 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3449 return FAIL;
3450 }
c19d1205
ZW
3451
3452 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3453 return FAIL;
3454
3455 switch (rot)
a737bd4d 3456 {
c19d1205
ZW
3457 case 0: *str = s; return 0x0;
3458 case 8: *str = s; return 0x1;
3459 case 16: *str = s; return 0x2;
3460 case 24: *str = s; return 0x3;
3461
3462 default:
3463 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3464 return FAIL;
3465 }
c19d1205 3466}
a737bd4d 3467
c19d1205
ZW
3468/* Parse a conditional code (from conds[] below). The value returned is in the
3469 range 0 .. 14, or FAIL. */
3470static int
3471parse_cond (char **str)
3472{
3473 char *p, *q;
3474 const struct asm_cond *c;
a737bd4d 3475
c19d1205
ZW
3476 p = q = *str;
3477 while (ISALPHA (*q))
3478 q++;
a737bd4d 3479
c19d1205
ZW
3480 c = hash_find_n (arm_cond_hsh, p, q - p);
3481 if (!c)
a737bd4d 3482 {
c19d1205 3483 inst.error = _("condition required");
a737bd4d
NC
3484 return FAIL;
3485 }
3486
c19d1205
ZW
3487 *str = q;
3488 return c->value;
3489}
3490
3491/* Matcher codes for parse_operands. */
3492enum operand_parse_code
3493{
3494 OP_stop, /* end of line */
3495
3496 OP_RR, /* ARM register */
3497 OP_RRnpc, /* ARM register, not r15 */
3498 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3499 OP_RRw, /* ARM register, not r15, optional trailing ! */
3500 OP_RCP, /* Coprocessor number */
3501 OP_RCN, /* Coprocessor register */
3502 OP_RF, /* FPA register */
3503 OP_RVS, /* VFP single precision register */
3504 OP_RVD, /* VFP double precision register */
3505 OP_RVC, /* VFP control register */
3506 OP_RMF, /* Maverick F register */
3507 OP_RMD, /* Maverick D register */
3508 OP_RMFX, /* Maverick FX register */
3509 OP_RMDX, /* Maverick DX register */
3510 OP_RMAX, /* Maverick AX register */
3511 OP_RMDS, /* Maverick DSPSC register */
3512 OP_RIWR, /* iWMMXt wR register */
3513 OP_RIWC, /* iWMMXt wC register */
3514 OP_RIWG, /* iWMMXt wCG register */
3515 OP_RXA, /* XScale accumulator register */
3516
3517 OP_REGLST, /* ARM register list */
3518 OP_VRSLST, /* VFP single-precision register list */
3519 OP_VRDLST, /* VFP double-precision register list */
3520
3521 OP_I7, /* immediate value 0 .. 7 */
3522 OP_I15, /* 0 .. 15 */
3523 OP_I16, /* 1 .. 16 */
3524 OP_I31, /* 0 .. 31 */
3525 OP_I31w, /* 0 .. 31, optional trailing ! */
3526 OP_I32, /* 1 .. 32 */
3527 OP_I63s, /* -64 .. 63 */
3528 OP_I255, /* 0 .. 255 */
3529 OP_Iffff, /* 0 .. 65535 */
3530
3531 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3532 OP_I7b, /* 0 .. 7 */
3533 OP_I15b, /* 0 .. 15 */
3534 OP_I31b, /* 0 .. 31 */
3535
3536 OP_SH, /* shifter operand */
3537 OP_ADDR, /* Memory address expression (any mode) */
3538 OP_EXP, /* arbitrary expression */
3539 OP_EXPi, /* same, with optional immediate prefix */
3540 OP_EXPr, /* same, with optional relocation suffix */
3541
3542 OP_CPSF, /* CPS flags */
3543 OP_ENDI, /* Endianness specifier */
3544 OP_PSR, /* CPSR/SPSR mask for msr */
3545 OP_COND, /* conditional code */
3546
3547 OP_RRnpc_I0, /* ARM register or literal 0 */
3548 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3549 OP_RR_EXi, /* ARM register or expression with imm prefix */
3550 OP_RF_IF, /* FPA register or immediate */
3551 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3552
3553 /* Optional operands. */
3554 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3555 OP_oI31b, /* 0 .. 31 */
3556 OP_oIffffb, /* 0 .. 65535 */
3557 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3558
3559 OP_oRR, /* ARM register */
3560 OP_oRRnpc, /* ARM register, not the PC */
3561 OP_oSHll, /* LSL immediate */
3562 OP_oSHar, /* ASR immediate */
3563 OP_oSHllar, /* LSL or ASR immediate */
3564 OP_oROR, /* ROR 0/8/16/24 */
3565
3566 OP_FIRST_OPTIONAL = OP_oI7b
3567};
a737bd4d 3568
c19d1205
ZW
3569/* Generic instruction operand parser. This does no encoding and no
3570 semantic validation; it merely squirrels values away in the inst
3571 structure. Returns SUCCESS or FAIL depending on whether the
3572 specified grammar matched. */
3573static int
3574parse_operands (char *str, const char *pattern)
3575{
3576 unsigned const char *upat = pattern;
3577 char *backtrack_pos = 0;
3578 const char *backtrack_error = 0;
3579 int i, val, backtrack_index = 0;
3580
3581#define po_char_or_fail(chr) do { \
3582 if (skip_past_char (&str, chr) == FAIL) \
3583 goto bad_args; \
3584} while (0)
3585
3586#define po_reg_or_fail(regtype) do { \
3587 val = arm_reg_parse (&str, regtype); \
3588 if (val == FAIL) \
3589 { \
3590 inst.error = _(reg_expected_msgs[regtype]); \
3591 goto failure; \
3592 } \
3593 inst.operands[i].reg = val; \
3594 inst.operands[i].isreg = 1; \
3595} while (0)
3596
3597#define po_reg_or_goto(regtype, label) do { \
3598 val = arm_reg_parse (&str, regtype); \
3599 if (val == FAIL) \
3600 goto label; \
3601 \
3602 inst.operands[i].reg = val; \
3603 inst.operands[i].isreg = 1; \
3604} while (0)
3605
3606#define po_imm_or_fail(min, max, popt) do { \
3607 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3608 goto failure; \
3609 inst.operands[i].imm = val; \
3610} while (0)
3611
3612#define po_misc_or_fail(expr) do { \
3613 if (expr) \
3614 goto failure; \
3615} while (0)
3616
3617 skip_whitespace (str);
3618
3619 for (i = 0; upat[i] != OP_stop; i++)
3620 {
3621 if (upat[i] >= OP_FIRST_OPTIONAL)
3622 {
3623 /* Remember where we are in case we need to backtrack. */
3624 assert (!backtrack_pos);
3625 backtrack_pos = str;
3626 backtrack_error = inst.error;
3627 backtrack_index = i;
3628 }
3629
3630 if (i > 0)
3631 po_char_or_fail (',');
3632
3633 switch (upat[i])
3634 {
3635 /* Registers */
3636 case OP_oRRnpc:
3637 case OP_RRnpc:
3638 case OP_oRR:
3639 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3640 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3641 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3642 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3643 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3644 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3645 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3646 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3647 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3648 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3649 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3650 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3651 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3652 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3653 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3654 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3655 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3656
3657 case OP_RRnpcb:
3658 po_char_or_fail ('[');
3659 po_reg_or_fail (REG_TYPE_RN);
3660 po_char_or_fail (']');
3661 break;
a737bd4d 3662
c19d1205
ZW
3663 case OP_RRw:
3664 po_reg_or_fail (REG_TYPE_RN);
3665 if (skip_past_char (&str, '!') == SUCCESS)
3666 inst.operands[i].writeback = 1;
3667 break;
3668
3669 /* Immediates */
3670 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3671 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3672 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3673 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3674 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3675 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3676 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3677 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3678
3679 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3680 case OP_oI7b:
3681 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3682 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3683 case OP_oI31b:
3684 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3685 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3686
3687 /* Immediate variants */
3688 case OP_oI255c:
3689 po_char_or_fail ('{');
3690 po_imm_or_fail (0, 255, TRUE);
3691 po_char_or_fail ('}');
3692 break;
3693
3694 case OP_I31w:
3695 /* The expression parser chokes on a trailing !, so we have
3696 to find it first and zap it. */
3697 {
3698 char *s = str;
3699 while (*s && *s != ',')
3700 s++;
3701 if (s[-1] == '!')
3702 {
3703 s[-1] = '\0';
3704 inst.operands[i].writeback = 1;
3705 }
3706 po_imm_or_fail (0, 31, TRUE);
3707 if (str == s - 1)
3708 str = s;
3709 }
3710 break;
3711
3712 /* Expressions */
3713 case OP_EXPi: EXPi:
3714 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3715 GE_OPT_PREFIX));
3716 break;
3717
3718 case OP_EXP:
3719 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3720 GE_NO_PREFIX));
3721 break;
3722
3723 case OP_EXPr: EXPr:
3724 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3725 GE_NO_PREFIX));
3726 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3727 {
c19d1205
ZW
3728 val = parse_reloc (&str);
3729 if (val == -1)
3730 {
3731 inst.error = _("unrecognized relocation suffix");
3732 goto failure;
3733 }
3734 else if (val != BFD_RELOC_UNUSED)
3735 {
3736 inst.operands[i].imm = val;
3737 inst.operands[i].hasreloc = 1;
3738 }
a737bd4d 3739 }
c19d1205 3740 break;
a737bd4d 3741
c19d1205
ZW
3742 /* Register or expression */
3743 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3744 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 3745
c19d1205
ZW
3746 /* Register or immediate */
3747 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3748 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 3749
c19d1205
ZW
3750 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3751 IF:
3752 if (!is_immediate_prefix (*str))
3753 goto bad_args;
3754 str++;
3755 val = parse_fpa_immediate (&str);
3756 if (val == FAIL)
3757 goto failure;
3758 /* FPA immediates are encoded as registers 8-15.
3759 parse_fpa_immediate has already applied the offset. */
3760 inst.operands[i].reg = val;
3761 inst.operands[i].isreg = 1;
3762 break;
09d92015 3763
c19d1205
ZW
3764 /* Two kinds of register */
3765 case OP_RIWR_RIWC:
3766 {
3767 struct reg_entry *rege = arm_reg_parse_multi (&str);
3768 if (rege->type != REG_TYPE_MMXWR
3769 && rege->type != REG_TYPE_MMXWC
3770 && rege->type != REG_TYPE_MMXWCG)
3771 {
3772 inst.error = _("iWMMXt data or control register expected");
3773 goto failure;
3774 }
3775 inst.operands[i].reg = rege->number;
3776 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3777 }
3778 break;
09d92015 3779
c19d1205
ZW
3780 /* Misc */
3781 case OP_CPSF: val = parse_cps_flags (&str); break;
3782 case OP_ENDI: val = parse_endian_specifier (&str); break;
3783 case OP_oROR: val = parse_ror (&str); break;
3784 case OP_PSR: val = parse_psr (&str); break;
3785 case OP_COND: val = parse_cond (&str); break;
3786
3787 /* Register lists */
3788 case OP_REGLST:
3789 val = parse_reg_list (&str);
3790 if (*str == '^')
3791 {
3792 inst.operands[1].writeback = 1;
3793 str++;
3794 }
3795 break;
09d92015 3796
c19d1205
ZW
3797 case OP_VRSLST:
3798 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3799 break;
09d92015 3800
c19d1205
ZW
3801 case OP_VRDLST:
3802 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3803 break;
a737bd4d 3804
c19d1205
ZW
3805 /* Addressing modes */
3806 case OP_ADDR:
3807 po_misc_or_fail (parse_address (&str, i));
3808 break;
09d92015 3809
c19d1205
ZW
3810 case OP_SH:
3811 po_misc_or_fail (parse_shifter_operand (&str, i));
3812 break;
09d92015 3813
c19d1205
ZW
3814 case OP_oSHll:
3815 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3816 break;
09d92015 3817
c19d1205
ZW
3818 case OP_oSHar:
3819 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3820 break;
09d92015 3821
c19d1205
ZW
3822 case OP_oSHllar:
3823 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3824 break;
09d92015 3825
c19d1205
ZW
3826 default:
3827 as_fatal ("unhandled operand code %d", upat[i]);
3828 }
09d92015 3829
c19d1205
ZW
3830 /* Various value-based sanity checks and shared operations. We
3831 do not signal immediate failures for the register constraints;
3832 this allows a syntax error to take precedence. */
3833 switch (upat[i])
3834 {
3835 case OP_oRRnpc:
3836 case OP_RRnpc:
3837 case OP_RRnpcb:
3838 case OP_RRw:
3839 case OP_RRnpc_I0:
3840 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
3841 inst.error = BAD_PC;
3842 break;
09d92015 3843
c19d1205
ZW
3844 case OP_CPSF:
3845 case OP_ENDI:
3846 case OP_oROR:
3847 case OP_PSR:
3848 case OP_COND:
3849 case OP_REGLST:
3850 case OP_VRSLST:
3851 case OP_VRDLST:
3852 if (val == FAIL)
3853 goto failure;
3854 inst.operands[i].imm = val;
3855 break;
a737bd4d 3856
c19d1205
ZW
3857 default:
3858 break;
3859 }
09d92015 3860
c19d1205
ZW
3861 /* If we get here, this operand was successfully parsed. */
3862 inst.operands[i].present = 1;
3863 continue;
09d92015 3864
c19d1205 3865 bad_args:
09d92015 3866 inst.error = BAD_ARGS;
c19d1205
ZW
3867
3868 failure:
3869 if (!backtrack_pos)
3870 return FAIL;
3871
3872 /* Do not backtrack over a trailing optional argument that
3873 absorbed some text. We will only fail again, with the
3874 'garbage following instruction' error message, which is
3875 probably less helpful than the current one. */
3876 if (backtrack_index == i && backtrack_pos != str
3877 && upat[i+1] == OP_stop)
3878 return FAIL;
3879
3880 /* Try again, skipping the optional argument at backtrack_pos. */
3881 str = backtrack_pos;
3882 inst.error = backtrack_error;
3883 inst.operands[backtrack_index].present = 0;
3884 i = backtrack_index;
3885 backtrack_pos = 0;
09d92015 3886 }
09d92015 3887
c19d1205
ZW
3888 /* Check that we have parsed all the arguments. */
3889 if (*str != '\0' && !inst.error)
3890 inst.error = _("garbage following instruction");
09d92015 3891
c19d1205 3892 return inst.error ? FAIL : SUCCESS;
09d92015
MM
3893}
3894
c19d1205
ZW
3895#undef po_char_or_fail
3896#undef po_reg_or_fail
3897#undef po_reg_or_goto
3898#undef po_imm_or_fail
3899\f
3900/* Shorthand macro for instruction encoding functions issuing errors. */
3901#define constraint(expr, err) do { \
3902 if (expr) \
3903 { \
3904 inst.error = err; \
3905 return; \
3906 } \
3907} while (0)
3908
3909/* Functions for operand encoding. ARM, then Thumb. */
3910
3911#define rotate_left(v, n) (v << n | v >> (32 - n))
3912
3913/* If VAL can be encoded in the immediate field of an ARM instruction,
3914 return the encoded form. Otherwise, return FAIL. */
3915
3916static unsigned int
3917encode_arm_immediate (unsigned int val)
09d92015 3918{
c19d1205
ZW
3919 unsigned int a, i;
3920
3921 for (i = 0; i < 32; i += 2)
3922 if ((a = rotate_left (val, i)) <= 0xff)
3923 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
3924
3925 return FAIL;
09d92015
MM
3926}
3927
c19d1205
ZW
3928/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
3929 return the encoded form. Otherwise, return FAIL. */
3930static unsigned int
3931encode_thumb32_immediate (unsigned int val)
09d92015 3932{
c19d1205 3933 unsigned int a, i;
09d92015 3934
c19d1205
ZW
3935 if (val <= 255)
3936 return val;
a737bd4d 3937
c19d1205 3938 for (i = 0; i < 32; i++)
09d92015 3939 {
c19d1205
ZW
3940 a = rotate_left (val, i);
3941 if (a >= 128 && a <= 255)
3942 return (a & 0x7f) | (i << 7);
09d92015 3943 }
a737bd4d 3944
c19d1205
ZW
3945 a = val & 0xff;
3946 if (val == ((a << 16) | a))
3947 return 0x100 | a;
3948 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
3949 return 0x300 | a;
09d92015 3950
c19d1205
ZW
3951 a = val & 0xff00;
3952 if (val == ((a << 16) | a))
3953 return 0x200 | (a >> 8);
a737bd4d 3954
c19d1205 3955 return FAIL;
09d92015 3956}
c19d1205 3957/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
3958
3959static void
c19d1205 3960encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 3961{
c19d1205 3962 switch (pos)
09d92015 3963 {
c19d1205
ZW
3964 case VFP_REG_Sd:
3965 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
3966 break;
3967
3968 case VFP_REG_Sn:
3969 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
3970 break;
3971
3972 case VFP_REG_Sm:
3973 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
3974 break;
3975
3976 default:
3977 abort ();
09d92015 3978 }
09d92015
MM
3979}
3980
c19d1205 3981/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 3982 if any, is handled by md_apply_fix. */
09d92015 3983static void
c19d1205 3984encode_arm_shift (int i)
09d92015 3985{
c19d1205
ZW
3986 if (inst.operands[i].shift_kind == SHIFT_RRX)
3987 inst.instruction |= SHIFT_ROR << 5;
3988 else
09d92015 3989 {
c19d1205
ZW
3990 inst.instruction |= inst.operands[i].shift_kind << 5;
3991 if (inst.operands[i].immisreg)
3992 {
3993 inst.instruction |= SHIFT_BY_REG;
3994 inst.instruction |= inst.operands[i].imm << 8;
3995 }
3996 else
3997 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 3998 }
c19d1205 3999}
09d92015 4000
c19d1205
ZW
4001static void
4002encode_arm_shifter_operand (int i)
4003{
4004 if (inst.operands[i].isreg)
09d92015 4005 {
c19d1205
ZW
4006 inst.instruction |= inst.operands[i].reg;
4007 encode_arm_shift (i);
09d92015 4008 }
c19d1205
ZW
4009 else
4010 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4011}
4012
c19d1205 4013/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4014static void
c19d1205 4015encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4016{
c19d1205
ZW
4017 assert (inst.operands[i].isreg);
4018 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4019
c19d1205 4020 if (inst.operands[i].preind)
09d92015 4021 {
c19d1205
ZW
4022 if (is_t)
4023 {
4024 inst.error = _("instruction does not accept preindexed addressing");
4025 return;
4026 }
4027 inst.instruction |= PRE_INDEX;
4028 if (inst.operands[i].writeback)
4029 inst.instruction |= WRITE_BACK;
09d92015 4030
c19d1205
ZW
4031 }
4032 else if (inst.operands[i].postind)
4033 {
4034 assert (inst.operands[i].writeback);
4035 if (is_t)
4036 inst.instruction |= WRITE_BACK;
4037 }
4038 else /* unindexed - only for coprocessor */
09d92015 4039 {
c19d1205 4040 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4041 return;
4042 }
4043
c19d1205
ZW
4044 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4045 && (((inst.instruction & 0x000f0000) >> 16)
4046 == ((inst.instruction & 0x0000f000) >> 12)))
4047 as_warn ((inst.instruction & LOAD_BIT)
4048 ? _("destination register same as write-back base")
4049 : _("source register same as write-back base"));
09d92015
MM
4050}
4051
c19d1205
ZW
4052/* inst.operands[i] was set up by parse_address. Encode it into an
4053 ARM-format mode 2 load or store instruction. If is_t is true,
4054 reject forms that cannot be used with a T instruction (i.e. not
4055 post-indexed). */
a737bd4d 4056static void
c19d1205 4057encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4058{
c19d1205 4059 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4060
c19d1205 4061 if (inst.operands[i].immisreg)
09d92015 4062 {
c19d1205
ZW
4063 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4064 inst.instruction |= inst.operands[i].imm;
4065 if (!inst.operands[i].negative)
4066 inst.instruction |= INDEX_UP;
4067 if (inst.operands[i].shifted)
4068 {
4069 if (inst.operands[i].shift_kind == SHIFT_RRX)
4070 inst.instruction |= SHIFT_ROR << 5;
4071 else
4072 {
4073 inst.instruction |= inst.operands[i].shift_kind << 5;
4074 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4075 }
4076 }
09d92015 4077 }
c19d1205 4078 else /* immediate offset in inst.reloc */
09d92015 4079 {
c19d1205
ZW
4080 if (inst.reloc.type == BFD_RELOC_UNUSED)
4081 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4082 if (inst.reloc.pc_rel)
4083 inst.reloc.exp.X_add_number -= 8; /* pipeline offset */
09d92015 4084 }
09d92015
MM
4085}
4086
c19d1205
ZW
4087/* inst.operands[i] was set up by parse_address. Encode it into an
4088 ARM-format mode 3 load or store instruction. Reject forms that
4089 cannot be used with such instructions. If is_t is true, reject
4090 forms that cannot be used with a T instruction (i.e. not
4091 post-indexed). */
4092static void
4093encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4094{
c19d1205 4095 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4096 {
c19d1205
ZW
4097 inst.error = _("instruction does not accept scaled register index");
4098 return;
09d92015 4099 }
a737bd4d 4100
c19d1205 4101 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4102
c19d1205
ZW
4103 if (inst.operands[i].immisreg)
4104 {
4105 inst.instruction |= inst.operands[i].imm;
4106 if (!inst.operands[i].negative)
4107 inst.instruction |= INDEX_UP;
4108 }
4109 else /* immediate offset in inst.reloc */
4110 {
4111 inst.instruction |= HWOFFSET_IMM;
4112 if (inst.reloc.type == BFD_RELOC_UNUSED)
4113 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4114 if (inst.reloc.pc_rel)
4115 inst.reloc.exp.X_add_number -= 8; /* pipeline offset */
4116 }
a737bd4d
NC
4117}
4118
c19d1205
ZW
4119/* inst.operands[i] was set up by parse_address. Encode it into an
4120 ARM-format instruction. Reject all forms which cannot be encoded
4121 into a coprocessor load/store instruction. If wb_ok is false,
4122 reject use of writeback; if unind_ok is false, reject use of
4123 unindexed addressing. If reloc_override is not 0, use it instead
4124 of BFD_ARM_CP_OFF_IMM. */
09d92015 4125
c19d1205
ZW
4126static int
4127encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4128{
c19d1205 4129 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4130
c19d1205 4131 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4132
c19d1205 4133 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4134 {
c19d1205
ZW
4135 assert (!inst.operands[i].writeback);
4136 if (!unind_ok)
4137 {
4138 inst.error = _("instruction does not support unindexed addressing");
4139 return FAIL;
4140 }
4141 inst.instruction |= inst.operands[i].imm;
4142 inst.instruction |= INDEX_UP;
4143 return SUCCESS;
09d92015 4144 }
a737bd4d 4145
c19d1205
ZW
4146 if (inst.operands[i].preind)
4147 inst.instruction |= PRE_INDEX;
a737bd4d 4148
c19d1205 4149 if (inst.operands[i].writeback)
09d92015 4150 {
c19d1205
ZW
4151 if (inst.operands[i].reg == REG_PC)
4152 {
4153 inst.error = _("pc may not be used with write-back");
4154 return FAIL;
4155 }
4156 if (!wb_ok)
4157 {
4158 inst.error = _("instruction does not support writeback");
4159 return FAIL;
4160 }
4161 inst.instruction |= WRITE_BACK;
09d92015 4162 }
a737bd4d 4163
c19d1205
ZW
4164 if (reloc_override)
4165 inst.reloc.type = reloc_override;
09d92015 4166 else
c19d1205
ZW
4167 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
4168 if (inst.reloc.pc_rel)
4169 inst.reloc.exp.X_add_number -= 8;
4170 return SUCCESS;
4171}
a737bd4d 4172
c19d1205
ZW
4173/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4174 Determine whether it can be performed with a move instruction; if
4175 it can, convert inst.instruction to that move instruction and
4176 return 1; if it can't, convert inst.instruction to a literal-pool
4177 load and return 0. If this is not a valid thing to do in the
4178 current context, set inst.error and return 1.
a737bd4d 4179
c19d1205
ZW
4180 inst.operands[i] describes the destination register. */
4181
4182static int
4183move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4184{
4185 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4186 {
c19d1205
ZW
4187 inst.error = _("invalid pseudo operation");
4188 return 1;
09d92015 4189 }
c19d1205 4190 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4191 {
4192 inst.error = _("constant expression expected");
c19d1205 4193 return 1;
09d92015 4194 }
c19d1205 4195 if (inst.reloc.exp.X_op == O_constant)
09d92015 4196 {
c19d1205
ZW
4197 if (thumb_p)
4198 {
4199 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4200 {
4201 /* This can be done with a mov(1) instruction. */
4202 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4203 inst.instruction |= inst.reloc.exp.X_add_number;
4204 return 1;
4205 }
4206 }
4207 else
4208 {
4209 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4210 if (value != FAIL)
4211 {
4212 /* This can be done with a mov instruction. */
4213 inst.instruction &= LITERAL_MASK;
4214 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4215 inst.instruction |= value & 0xfff;
4216 return 1;
4217 }
09d92015 4218
c19d1205
ZW
4219 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4220 if (value != FAIL)
4221 {
4222 /* This can be done with a mvn instruction. */
4223 inst.instruction &= LITERAL_MASK;
4224 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4225 inst.instruction |= value & 0xfff;
4226 return 1;
4227 }
4228 }
09d92015
MM
4229 }
4230
c19d1205
ZW
4231 if (add_to_lit_pool () == FAIL)
4232 {
4233 inst.error = _("literal pool insertion failed");
4234 return 1;
4235 }
4236 inst.operands[1].reg = REG_PC;
4237 inst.operands[1].isreg = 1;
4238 inst.operands[1].preind = 1;
4239 inst.reloc.pc_rel = 1;
4240 inst.reloc.type = (thumb_p
4241 ? BFD_RELOC_ARM_THUMB_OFFSET
4242 : (mode_3
4243 ? BFD_RELOC_ARM_HWLITERAL
4244 : BFD_RELOC_ARM_LITERAL));
4245 return 0;
09d92015
MM
4246}
4247
c19d1205
ZW
4248/* Functions for instruction encoding, sorted by subarchitecture.
4249 First some generics; their names are taken from the conventional
4250 bit positions for register arguments in ARM format instructions. */
09d92015 4251
a737bd4d 4252static void
c19d1205 4253do_noargs (void)
09d92015 4254{
c19d1205 4255}
a737bd4d 4256
c19d1205
ZW
4257static void
4258do_rd (void)
4259{
4260 inst.instruction |= inst.operands[0].reg << 12;
4261}
a737bd4d 4262
c19d1205
ZW
4263static void
4264do_rd_rm (void)
4265{
4266 inst.instruction |= inst.operands[0].reg << 12;
4267 inst.instruction |= inst.operands[1].reg;
4268}
09d92015 4269
c19d1205
ZW
4270static void
4271do_rd_rn (void)
4272{
4273 inst.instruction |= inst.operands[0].reg << 12;
4274 inst.instruction |= inst.operands[1].reg << 16;
4275}
a737bd4d 4276
c19d1205
ZW
4277static void
4278do_rn_rd (void)
4279{
4280 inst.instruction |= inst.operands[0].reg << 16;
4281 inst.instruction |= inst.operands[1].reg << 12;
4282}
09d92015 4283
c19d1205
ZW
4284static void
4285do_rd_rm_rn (void)
4286{
4287 inst.instruction |= inst.operands[0].reg << 12;
4288 inst.instruction |= inst.operands[1].reg;
4289 inst.instruction |= inst.operands[2].reg << 16;
4290}
09d92015 4291
c19d1205
ZW
4292static void
4293do_rd_rn_rm (void)
4294{
4295 inst.instruction |= inst.operands[0].reg << 12;
4296 inst.instruction |= inst.operands[1].reg << 16;
4297 inst.instruction |= inst.operands[2].reg;
4298}
a737bd4d 4299
c19d1205
ZW
4300static void
4301do_rm_rd_rn (void)
4302{
4303 inst.instruction |= inst.operands[0].reg;
4304 inst.instruction |= inst.operands[1].reg << 12;
4305 inst.instruction |= inst.operands[2].reg << 16;
4306}
09d92015 4307
c19d1205
ZW
4308static void
4309do_imm0 (void)
4310{
4311 inst.instruction |= inst.operands[0].imm;
4312}
09d92015 4313
c19d1205
ZW
4314static void
4315do_rd_cpaddr (void)
4316{
4317 inst.instruction |= inst.operands[0].reg << 12;
4318 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4319}
a737bd4d 4320
c19d1205
ZW
4321/* ARM instructions, in alphabetical order by function name (except
4322 that wrapper functions appear immediately after the function they
4323 wrap). */
09d92015 4324
c19d1205
ZW
4325/* This is a pseudo-op of the form "adr rd, label" to be converted
4326 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4327
4328static void
c19d1205 4329do_adr (void)
09d92015 4330{
c19d1205 4331 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4332
c19d1205
ZW
4333 /* Frag hacking will turn this into a sub instruction if the offset turns
4334 out to be negative. */
4335 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4336#ifndef TE_WINCE
4337 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust. */
4338#endif
4339 inst.reloc.pc_rel = 1;
4340}
b99bd4ef 4341
c19d1205
ZW
4342/* This is a pseudo-op of the form "adrl rd, label" to be converted
4343 into a relative address of the form:
4344 add rd, pc, #low(label-.-8)"
4345 add rd, rd, #high(label-.-8)" */
b99bd4ef 4346
c19d1205
ZW
4347static void
4348do_adrl (void)
4349{
4350 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4351
c19d1205
ZW
4352 /* Frag hacking will turn this into a sub instruction if the offset turns
4353 out to be negative. */
4354 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
4355#ifndef TE_WINCE
4356 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust */
4357#endif
4358 inst.reloc.pc_rel = 1;
4359 inst.size = INSN_SIZE * 2;
b99bd4ef
NC
4360}
4361
b99bd4ef 4362static void
c19d1205 4363do_arit (void)
b99bd4ef 4364{
c19d1205
ZW
4365 if (!inst.operands[1].present)
4366 inst.operands[1].reg = inst.operands[0].reg;
4367 inst.instruction |= inst.operands[0].reg << 12;
4368 inst.instruction |= inst.operands[1].reg << 16;
4369 encode_arm_shifter_operand (2);
4370}
b99bd4ef 4371
c19d1205
ZW
4372static void
4373do_bfc (void)
4374{
4375 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4376 constraint (msb > 32, _("bit-field extends past end of register"));
4377 /* The instruction encoding stores the LSB and MSB,
4378 not the LSB and width. */
4379 inst.instruction |= inst.operands[0].reg << 12;
4380 inst.instruction |= inst.operands[1].imm << 7;
4381 inst.instruction |= (msb - 1) << 16;
4382}
b99bd4ef 4383
c19d1205
ZW
4384static void
4385do_bfi (void)
4386{
4387 unsigned int msb;
b99bd4ef 4388
c19d1205
ZW
4389 /* #0 in second position is alternative syntax for bfc, which is
4390 the same instruction but with REG_PC in the Rm field. */
4391 if (!inst.operands[1].isreg)
4392 inst.operands[1].reg = REG_PC;
b99bd4ef 4393
c19d1205
ZW
4394 msb = inst.operands[2].imm + inst.operands[3].imm;
4395 constraint (msb > 32, _("bit-field extends past end of register"));
4396 /* The instruction encoding stores the LSB and MSB,
4397 not the LSB and width. */
4398 inst.instruction |= inst.operands[0].reg << 12;
4399 inst.instruction |= inst.operands[1].reg;
4400 inst.instruction |= inst.operands[2].imm << 7;
4401 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4402}
4403
b99bd4ef 4404static void
c19d1205 4405do_bfx (void)
b99bd4ef 4406{
c19d1205
ZW
4407 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4408 _("bit-field extends past end of register"));
4409 inst.instruction |= inst.operands[0].reg << 12;
4410 inst.instruction |= inst.operands[1].reg;
4411 inst.instruction |= inst.operands[2].imm << 7;
4412 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4413}
09d92015 4414
c19d1205
ZW
4415/* ARM V5 breakpoint instruction (argument parse)
4416 BKPT <16 bit unsigned immediate>
4417 Instruction is not conditional.
4418 The bit pattern given in insns[] has the COND_ALWAYS condition,
4419 and it is an error if the caller tried to override that. */
b99bd4ef 4420
c19d1205
ZW
4421static void
4422do_bkpt (void)
4423{
4424 /* Top 12 of 16 bits to bits 19:8. */
4425 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4426
c19d1205
ZW
4427 /* Bottom 4 of 16 bits to bits 3:0. */
4428 inst.instruction |= inst.operands[0].imm & 0xf;
4429}
09d92015 4430
c19d1205
ZW
4431static void
4432encode_branch (int default_reloc)
4433{
4434 if (inst.operands[0].hasreloc)
4435 {
4436 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4437 _("the only suffix valid here is '(plt)'"));
4438 inst.reloc.type = BFD_RELOC_ARM_PLT32;
4439 inst.reloc.pc_rel = 0;
4440 }
b99bd4ef 4441 else
c19d1205
ZW
4442 {
4443 inst.reloc.type = default_reloc;
4444 inst.reloc.pc_rel = 1;
4445 }
b99bd4ef
NC
4446}
4447
b99bd4ef 4448static void
c19d1205 4449do_branch (void)
b99bd4ef 4450{
c19d1205
ZW
4451 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4452}
b99bd4ef 4453
c19d1205
ZW
4454/* ARM V5 branch-link-exchange instruction (argument parse)
4455 BLX <target_addr> ie BLX(1)
4456 BLX{<condition>} <Rm> ie BLX(2)
4457 Unfortunately, there are two different opcodes for this mnemonic.
4458 So, the insns[].value is not used, and the code here zaps values
4459 into inst.instruction.
4460 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4461
c19d1205
ZW
4462static void
4463do_blx (void)
4464{
4465 if (inst.operands[0].isreg)
b99bd4ef 4466 {
c19d1205
ZW
4467 /* Arg is a register; the opcode provided by insns[] is correct.
4468 It is not illegal to do "blx pc", just useless. */
4469 if (inst.operands[0].reg == REG_PC)
4470 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4471
c19d1205
ZW
4472 inst.instruction |= inst.operands[0].reg;
4473 }
4474 else
b99bd4ef 4475 {
c19d1205
ZW
4476 /* Arg is an address; this instruction cannot be executed
4477 conditionally, and the opcode must be adjusted. */
4478 constraint (inst.cond != COND_ALWAYS, BAD_COND);
4479 inst.instruction = 0xfafffffe;
4480 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4481 }
c19d1205
ZW
4482}
4483
4484static void
4485do_bx (void)
4486{
4487 if (inst.operands[0].reg == REG_PC)
4488 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4489
c19d1205 4490 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4491}
4492
c19d1205
ZW
4493
4494/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4495
4496static void
c19d1205 4497do_bxj (void)
a737bd4d 4498{
c19d1205
ZW
4499 if (inst.operands[0].reg == REG_PC)
4500 as_tsktsk (_("use of r15 in bxj is not really useful"));
4501
4502 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4503}
4504
c19d1205
ZW
4505/* Co-processor data operation:
4506 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4507 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4508static void
4509do_cdp (void)
4510{
4511 inst.instruction |= inst.operands[0].reg << 8;
4512 inst.instruction |= inst.operands[1].imm << 20;
4513 inst.instruction |= inst.operands[2].reg << 12;
4514 inst.instruction |= inst.operands[3].reg << 16;
4515 inst.instruction |= inst.operands[4].reg;
4516 inst.instruction |= inst.operands[5].imm << 5;
4517}
a737bd4d
NC
4518
4519static void
c19d1205 4520do_cmp (void)
a737bd4d 4521{
c19d1205
ZW
4522 inst.instruction |= inst.operands[0].reg << 16;
4523 encode_arm_shifter_operand (1);
a737bd4d
NC
4524}
4525
c19d1205
ZW
4526/* Transfer between coprocessor and ARM registers.
4527 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4528 MRC2
4529 MCR{cond}
4530 MCR2
4531
4532 No special properties. */
09d92015
MM
4533
4534static void
c19d1205 4535do_co_reg (void)
09d92015 4536{
c19d1205
ZW
4537 inst.instruction |= inst.operands[0].reg << 8;
4538 inst.instruction |= inst.operands[1].imm << 21;
4539 inst.instruction |= inst.operands[2].reg << 12;
4540 inst.instruction |= inst.operands[3].reg << 16;
4541 inst.instruction |= inst.operands[4].reg;
4542 inst.instruction |= inst.operands[5].imm << 5;
4543}
09d92015 4544
c19d1205
ZW
4545/* Transfer between coprocessor register and pair of ARM registers.
4546 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4547 MCRR2
4548 MRRC{cond}
4549 MRRC2
b99bd4ef 4550
c19d1205 4551 Two XScale instructions are special cases of these:
09d92015 4552
c19d1205
ZW
4553 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4554 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4555
c19d1205 4556 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4557
c19d1205
ZW
4558static void
4559do_co_reg2c (void)
4560{
4561 inst.instruction |= inst.operands[0].reg << 8;
4562 inst.instruction |= inst.operands[1].imm << 4;
4563 inst.instruction |= inst.operands[2].reg << 12;
4564 inst.instruction |= inst.operands[3].reg << 16;
4565 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4566}
4567
c19d1205
ZW
4568static void
4569do_cpsi (void)
4570{
4571 inst.instruction |= inst.operands[0].imm << 6;
4572 inst.instruction |= inst.operands[1].imm;
4573}
b99bd4ef
NC
4574
4575static void
c19d1205 4576do_it (void)
b99bd4ef 4577{
c19d1205
ZW
4578 /* There is no IT instruction in ARM mode. We
4579 process it but do not generate code for it. */
4580 inst.size = 0;
09d92015 4581}
b99bd4ef 4582
09d92015 4583static void
c19d1205 4584do_ldmstm (void)
ea6ef066 4585{
c19d1205
ZW
4586 int base_reg = inst.operands[0].reg;
4587 int range = inst.operands[1].imm;
ea6ef066 4588
c19d1205
ZW
4589 inst.instruction |= base_reg << 16;
4590 inst.instruction |= range;
ea6ef066 4591
c19d1205
ZW
4592 if (inst.operands[1].writeback)
4593 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4594
c19d1205 4595 if (inst.operands[0].writeback)
ea6ef066 4596 {
c19d1205
ZW
4597 inst.instruction |= WRITE_BACK;
4598 /* Check for unpredictable uses of writeback. */
4599 if (inst.instruction & LOAD_BIT)
09d92015 4600 {
c19d1205
ZW
4601 /* Not allowed in LDM type 2. */
4602 if ((inst.instruction & LDM_TYPE_2_OR_3)
4603 && ((range & (1 << REG_PC)) == 0))
4604 as_warn (_("writeback of base register is UNPREDICTABLE"));
4605 /* Only allowed if base reg not in list for other types. */
4606 else if (range & (1 << base_reg))
4607 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4608 }
4609 else /* STM. */
4610 {
4611 /* Not allowed for type 2. */
4612 if (inst.instruction & LDM_TYPE_2_OR_3)
4613 as_warn (_("writeback of base register is UNPREDICTABLE"));
4614 /* Only allowed if base reg not in list, or first in list. */
4615 else if ((range & (1 << base_reg))
4616 && (range & ((1 << base_reg) - 1)))
4617 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4618 }
ea6ef066 4619 }
a737bd4d
NC
4620}
4621
c19d1205
ZW
4622/* ARMv5TE load-consecutive (argument parse)
4623 Mode is like LDRH.
4624
4625 LDRccD R, mode
4626 STRccD R, mode. */
4627
a737bd4d 4628static void
c19d1205 4629do_ldrd (void)
a737bd4d 4630{
c19d1205
ZW
4631 constraint (inst.operands[0].reg % 2 != 0,
4632 _("first destination register must be even"));
4633 constraint (inst.operands[1].present
4634 && inst.operands[1].reg != inst.operands[0].reg + 1,
4635 _("can only load two consecutive registers"));
4636 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4637 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4638
c19d1205
ZW
4639 if (!inst.operands[1].present)
4640 inst.operands[1].reg = inst.operands[0].reg + 1;
4641
4642 if (inst.instruction & LOAD_BIT)
a737bd4d 4643 {
c19d1205
ZW
4644 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4645 register and the first register written; we have to diagnose
4646 overlap between the base and the second register written here. */
ea6ef066 4647
c19d1205
ZW
4648 if (inst.operands[2].reg == inst.operands[1].reg
4649 && (inst.operands[2].writeback || inst.operands[2].postind))
4650 as_warn (_("base register written back, and overlaps "
4651 "second destination register"));
b05fe5cf 4652
c19d1205
ZW
4653 /* For an index-register load, the index register must not overlap the
4654 destination (even if not write-back). */
4655 else if (inst.operands[2].immisreg
4656 && (inst.operands[2].imm == inst.operands[0].reg
4657 || inst.operands[2].imm == inst.operands[1].reg))
4658 as_warn (_("index register overlaps destination register"));
b05fe5cf 4659 }
c19d1205
ZW
4660
4661 inst.instruction |= inst.operands[0].reg << 12;
4662 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4663}
4664
4665static void
c19d1205 4666do_ldrex (void)
b05fe5cf 4667{
c19d1205
ZW
4668 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4669 || inst.operands[1].postind || inst.operands[1].writeback
4670 || inst.operands[1].immisreg || inst.operands[1].shifted
4671 || inst.operands[1].negative,
4672 _("instruction does not accept this addressing mode"));
b05fe5cf 4673
c19d1205 4674 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
b05fe5cf 4675
c19d1205
ZW
4676 constraint (inst.reloc.exp.X_op != O_constant
4677 || inst.reloc.exp.X_add_number != 0,
4678 _("offset must be zero in ARM encoding"));
b05fe5cf 4679
c19d1205
ZW
4680 inst.instruction |= inst.operands[0].reg << 12;
4681 inst.instruction |= inst.operands[1].reg << 16;
4682 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4683}
4684
4685static void
c19d1205 4686do_ldrexd (void)
b05fe5cf 4687{
c19d1205
ZW
4688 constraint (inst.operands[0].reg % 2 != 0,
4689 _("even register required"));
4690 constraint (inst.operands[1].present
4691 && inst.operands[1].reg != inst.operands[0].reg + 1,
4692 _("can only load two consecutive registers"));
4693 /* If op 1 were present and equal to PC, this function wouldn't
4694 have been called in the first place. */
4695 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 4696
c19d1205
ZW
4697 inst.instruction |= inst.operands[0].reg << 12;
4698 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
4699}
4700
4701static void
c19d1205 4702do_ldst (void)
b05fe5cf 4703{
c19d1205
ZW
4704 inst.instruction |= inst.operands[0].reg << 12;
4705 if (!inst.operands[1].isreg)
4706 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 4707 return;
c19d1205 4708 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4709}
4710
4711static void
c19d1205 4712do_ldstt (void)
b05fe5cf 4713{
c19d1205
ZW
4714 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4715 reject [Rn,...]. */
4716 if (inst.operands[1].preind)
b05fe5cf 4717 {
c19d1205
ZW
4718 constraint (inst.reloc.exp.X_op != O_constant ||
4719 inst.reloc.exp.X_add_number != 0,
4720 _("this instruction requires a post-indexed address"));
b05fe5cf 4721
c19d1205
ZW
4722 inst.operands[1].preind = 0;
4723 inst.operands[1].postind = 1;
4724 inst.operands[1].writeback = 1;
b05fe5cf 4725 }
c19d1205
ZW
4726 inst.instruction |= inst.operands[0].reg << 12;
4727 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4728}
b05fe5cf 4729
c19d1205 4730/* Halfword and signed-byte load/store operations. */
b05fe5cf 4731
c19d1205
ZW
4732static void
4733do_ldstv4 (void)
4734{
4735 inst.instruction |= inst.operands[0].reg << 12;
4736 if (!inst.operands[1].isreg)
4737 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 4738 return;
c19d1205 4739 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4740}
4741
4742static void
c19d1205 4743do_ldsttv4 (void)
b05fe5cf 4744{
c19d1205
ZW
4745 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4746 reject [Rn,...]. */
4747 if (inst.operands[1].preind)
b05fe5cf 4748 {
c19d1205
ZW
4749 constraint (inst.reloc.exp.X_op != O_constant ||
4750 inst.reloc.exp.X_add_number != 0,
4751 _("this instruction requires a post-indexed address"));
b05fe5cf 4752
c19d1205
ZW
4753 inst.operands[1].preind = 0;
4754 inst.operands[1].postind = 1;
4755 inst.operands[1].writeback = 1;
b05fe5cf 4756 }
c19d1205
ZW
4757 inst.instruction |= inst.operands[0].reg << 12;
4758 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4759}
b05fe5cf 4760
c19d1205
ZW
4761/* Co-processor register load/store.
4762 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4763static void
4764do_lstc (void)
4765{
4766 inst.instruction |= inst.operands[0].reg << 8;
4767 inst.instruction |= inst.operands[1].reg << 12;
4768 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
4769}
4770
b05fe5cf 4771static void
c19d1205 4772do_mlas (void)
b05fe5cf 4773{
c19d1205
ZW
4774 /* This restriction does not apply to mls (nor to mla in v6, but
4775 that's hard to detect at present). */
4776 if (inst.operands[0].reg == inst.operands[1].reg
4777 && !(inst.instruction & 0x00400000))
4778 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 4779
c19d1205
ZW
4780 inst.instruction |= inst.operands[0].reg << 16;
4781 inst.instruction |= inst.operands[1].reg;
4782 inst.instruction |= inst.operands[2].reg << 8;
4783 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 4784
c19d1205 4785}
b05fe5cf 4786
c19d1205
ZW
4787static void
4788do_mov (void)
4789{
4790 inst.instruction |= inst.operands[0].reg << 12;
4791 encode_arm_shifter_operand (1);
4792}
b05fe5cf 4793
c19d1205
ZW
4794/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4795static void
4796do_mov16 (void)
4797{
4798 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 4799 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
4800 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4801 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 4802}
b99bd4ef
NC
4803
4804static void
c19d1205 4805do_mrs (void)
b99bd4ef 4806{
c19d1205
ZW
4807 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4808 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4809 != (PSR_c|PSR_f),
4810 _("'CPSR' or 'SPSR' expected"));
4811 inst.instruction |= inst.operands[0].reg << 12;
4812 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4813}
b99bd4ef 4814
c19d1205
ZW
4815/* Two possible forms:
4816 "{C|S}PSR_<field>, Rm",
4817 "{C|S}PSR_f, #expression". */
b99bd4ef 4818
c19d1205
ZW
4819static void
4820do_msr (void)
4821{
4822 inst.instruction |= inst.operands[0].imm;
4823 if (inst.operands[1].isreg)
4824 inst.instruction |= inst.operands[1].reg;
4825 else
b99bd4ef 4826 {
c19d1205
ZW
4827 inst.instruction |= INST_IMMEDIATE;
4828 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4829 inst.reloc.pc_rel = 0;
b99bd4ef 4830 }
b99bd4ef
NC
4831}
4832
c19d1205
ZW
4833static void
4834do_mul (void)
a737bd4d 4835{
c19d1205
ZW
4836 if (!inst.operands[2].present)
4837 inst.operands[2].reg = inst.operands[0].reg;
4838 inst.instruction |= inst.operands[0].reg << 16;
4839 inst.instruction |= inst.operands[1].reg;
4840 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 4841
c19d1205
ZW
4842 if (inst.operands[0].reg == inst.operands[1].reg)
4843 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
4844}
4845
c19d1205
ZW
4846/* Long Multiply Parser
4847 UMULL RdLo, RdHi, Rm, Rs
4848 SMULL RdLo, RdHi, Rm, Rs
4849 UMLAL RdLo, RdHi, Rm, Rs
4850 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
4851
4852static void
c19d1205 4853do_mull (void)
b99bd4ef 4854{
c19d1205
ZW
4855 inst.instruction |= inst.operands[0].reg << 12;
4856 inst.instruction |= inst.operands[1].reg << 16;
4857 inst.instruction |= inst.operands[2].reg;
4858 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 4859
c19d1205
ZW
4860 /* rdhi, rdlo and rm must all be different. */
4861 if (inst.operands[0].reg == inst.operands[1].reg
4862 || inst.operands[0].reg == inst.operands[2].reg
4863 || inst.operands[1].reg == inst.operands[2].reg)
4864 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
4865}
b99bd4ef 4866
c19d1205
ZW
4867static void
4868do_nop (void)
4869{
4870 if (inst.operands[0].present)
4871 {
4872 /* Architectural NOP hints are CPSR sets with no bits selected. */
4873 inst.instruction &= 0xf0000000;
4874 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
4875 }
b99bd4ef
NC
4876}
4877
c19d1205
ZW
4878/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
4879 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
4880 Condition defaults to COND_ALWAYS.
4881 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
4882
4883static void
c19d1205 4884do_pkhbt (void)
b99bd4ef 4885{
c19d1205
ZW
4886 inst.instruction |= inst.operands[0].reg << 12;
4887 inst.instruction |= inst.operands[1].reg << 16;
4888 inst.instruction |= inst.operands[2].reg;
4889 if (inst.operands[3].present)
4890 encode_arm_shift (3);
4891}
b99bd4ef 4892
c19d1205 4893/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 4894
c19d1205
ZW
4895static void
4896do_pkhtb (void)
4897{
4898 if (!inst.operands[3].present)
b99bd4ef 4899 {
c19d1205
ZW
4900 /* If the shift specifier is omitted, turn the instruction
4901 into pkhbt rd, rm, rn. */
4902 inst.instruction &= 0xfff00010;
4903 inst.instruction |= inst.operands[0].reg << 12;
4904 inst.instruction |= inst.operands[1].reg;
4905 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
4906 }
4907 else
4908 {
c19d1205
ZW
4909 inst.instruction |= inst.operands[0].reg << 12;
4910 inst.instruction |= inst.operands[1].reg << 16;
4911 inst.instruction |= inst.operands[2].reg;
4912 encode_arm_shift (3);
b99bd4ef
NC
4913 }
4914}
4915
c19d1205
ZW
4916/* ARMv5TE: Preload-Cache
4917
4918 PLD <addr_mode>
4919
4920 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
4921
4922static void
c19d1205 4923do_pld (void)
b99bd4ef 4924{
c19d1205
ZW
4925 constraint (!inst.operands[0].isreg,
4926 _("'[' expected after PLD mnemonic"));
4927 constraint (inst.operands[0].postind,
4928 _("post-indexed expression used in preload instruction"));
4929 constraint (inst.operands[0].writeback,
4930 _("writeback used in preload instruction"));
4931 constraint (!inst.operands[0].preind,
4932 _("unindexed addressing used in preload instruction"));
4933 inst.instruction |= inst.operands[0].reg;
4934 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
4935}
b99bd4ef 4936
c19d1205
ZW
4937static void
4938do_push_pop (void)
4939{
4940 inst.operands[1] = inst.operands[0];
4941 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
4942 inst.operands[0].isreg = 1;
4943 inst.operands[0].writeback = 1;
4944 inst.operands[0].reg = REG_SP;
4945 do_ldmstm ();
4946}
b99bd4ef 4947
c19d1205
ZW
4948/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
4949 word at the specified address and the following word
4950 respectively.
4951 Unconditionally executed.
4952 Error if Rn is R15. */
b99bd4ef 4953
c19d1205
ZW
4954static void
4955do_rfe (void)
4956{
4957 inst.instruction |= inst.operands[0].reg << 16;
4958 if (inst.operands[0].writeback)
4959 inst.instruction |= WRITE_BACK;
4960}
b99bd4ef 4961
c19d1205 4962/* ARM V6 ssat (argument parse). */
b99bd4ef 4963
c19d1205
ZW
4964static void
4965do_ssat (void)
4966{
4967 inst.instruction |= inst.operands[0].reg << 12;
4968 inst.instruction |= (inst.operands[1].imm - 1) << 16;
4969 inst.instruction |= inst.operands[2].reg;
b99bd4ef 4970
c19d1205
ZW
4971 if (inst.operands[3].present)
4972 encode_arm_shift (3);
b99bd4ef
NC
4973}
4974
c19d1205 4975/* ARM V6 usat (argument parse). */
b99bd4ef
NC
4976
4977static void
c19d1205 4978do_usat (void)
b99bd4ef 4979{
c19d1205
ZW
4980 inst.instruction |= inst.operands[0].reg << 12;
4981 inst.instruction |= inst.operands[1].imm << 16;
4982 inst.instruction |= inst.operands[2].reg;
b99bd4ef 4983
c19d1205
ZW
4984 if (inst.operands[3].present)
4985 encode_arm_shift (3);
b99bd4ef
NC
4986}
4987
c19d1205 4988/* ARM V6 ssat16 (argument parse). */
09d92015
MM
4989
4990static void
c19d1205 4991do_ssat16 (void)
09d92015 4992{
c19d1205
ZW
4993 inst.instruction |= inst.operands[0].reg << 12;
4994 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
4995 inst.instruction |= inst.operands[2].reg;
09d92015
MM
4996}
4997
c19d1205
ZW
4998static void
4999do_usat16 (void)
a737bd4d 5000{
c19d1205
ZW
5001 inst.instruction |= inst.operands[0].reg << 12;
5002 inst.instruction |= inst.operands[1].imm << 16;
5003 inst.instruction |= inst.operands[2].reg;
5004}
a737bd4d 5005
c19d1205
ZW
5006/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5007 preserving the other bits.
a737bd4d 5008
c19d1205
ZW
5009 setend <endian_specifier>, where <endian_specifier> is either
5010 BE or LE. */
a737bd4d 5011
c19d1205
ZW
5012static void
5013do_setend (void)
5014{
5015 if (inst.operands[0].imm)
5016 inst.instruction |= 0x200;
a737bd4d
NC
5017}
5018
5019static void
c19d1205 5020do_shift (void)
a737bd4d 5021{
c19d1205
ZW
5022 unsigned int Rm = (inst.operands[1].present
5023 ? inst.operands[1].reg
5024 : inst.operands[0].reg);
a737bd4d 5025
c19d1205
ZW
5026 inst.instruction |= inst.operands[0].reg << 12;
5027 inst.instruction |= Rm;
5028 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5029 {
c19d1205
ZW
5030 constraint (inst.operands[0].reg != Rm,
5031 _("source1 and dest must be same register"));
5032 inst.instruction |= inst.operands[2].reg << 8;
5033 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5034 }
5035 else
c19d1205 5036 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5037}
5038
09d92015 5039static void
c19d1205 5040do_smi (void)
09d92015 5041{
c19d1205
ZW
5042 inst.reloc.type = BFD_RELOC_ARM_SMI;
5043 inst.reloc.pc_rel = 0;
09d92015
MM
5044}
5045
09d92015 5046static void
c19d1205 5047do_swi (void)
09d92015 5048{
c19d1205
ZW
5049 inst.reloc.type = BFD_RELOC_ARM_SWI;
5050 inst.reloc.pc_rel = 0;
09d92015
MM
5051}
5052
c19d1205
ZW
5053/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5054 SMLAxy{cond} Rd,Rm,Rs,Rn
5055 SMLAWy{cond} Rd,Rm,Rs,Rn
5056 Error if any register is R15. */
e16bb312 5057
c19d1205
ZW
5058static void
5059do_smla (void)
e16bb312 5060{
c19d1205
ZW
5061 inst.instruction |= inst.operands[0].reg << 16;
5062 inst.instruction |= inst.operands[1].reg;
5063 inst.instruction |= inst.operands[2].reg << 8;
5064 inst.instruction |= inst.operands[3].reg << 12;
5065}
a737bd4d 5066
c19d1205
ZW
5067/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5068 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5069 Error if any register is R15.
5070 Warning if Rdlo == Rdhi. */
a737bd4d 5071
c19d1205
ZW
5072static void
5073do_smlal (void)
5074{
5075 inst.instruction |= inst.operands[0].reg << 12;
5076 inst.instruction |= inst.operands[1].reg << 16;
5077 inst.instruction |= inst.operands[2].reg;
5078 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5079
c19d1205
ZW
5080 if (inst.operands[0].reg == inst.operands[1].reg)
5081 as_tsktsk (_("rdhi and rdlo must be different"));
5082}
a737bd4d 5083
c19d1205
ZW
5084/* ARM V5E (El Segundo) signed-multiply (argument parse)
5085 SMULxy{cond} Rd,Rm,Rs
5086 Error if any register is R15. */
a737bd4d 5087
c19d1205
ZW
5088static void
5089do_smul (void)
5090{
5091 inst.instruction |= inst.operands[0].reg << 16;
5092 inst.instruction |= inst.operands[1].reg;
5093 inst.instruction |= inst.operands[2].reg << 8;
5094}
a737bd4d 5095
c19d1205 5096/* ARM V6 srs (argument parse). */
a737bd4d 5097
c19d1205
ZW
5098static void
5099do_srs (void)
5100{
5101 inst.instruction |= inst.operands[0].imm;
5102 if (inst.operands[0].writeback)
5103 inst.instruction |= WRITE_BACK;
5104}
a737bd4d 5105
c19d1205 5106/* ARM V6 strex (argument parse). */
a737bd4d 5107
c19d1205
ZW
5108static void
5109do_strex (void)
5110{
5111 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5112 || inst.operands[2].postind || inst.operands[2].writeback
5113 || inst.operands[2].immisreg || inst.operands[2].shifted
5114 || inst.operands[2].negative,
5115 _("instruction does not accept this addressing mode"));
e16bb312 5116
c19d1205 5117 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
a737bd4d 5118
c19d1205
ZW
5119 constraint (inst.operands[0].reg == inst.operands[1].reg
5120 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5121
c19d1205
ZW
5122 constraint (inst.reloc.exp.X_op != O_constant
5123 || inst.reloc.exp.X_add_number != 0,
5124 _("offset must be zero in ARM encoding"));
a737bd4d 5125
c19d1205
ZW
5126 inst.instruction |= inst.operands[0].reg << 12;
5127 inst.instruction |= inst.operands[1].reg;
5128 inst.instruction |= inst.operands[2].reg << 16;
5129 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5130}
5131
5132static void
c19d1205 5133do_strexd (void)
e16bb312 5134{
c19d1205
ZW
5135 constraint (inst.operands[1].reg % 2 != 0,
5136 _("even register required"));
5137 constraint (inst.operands[2].present
5138 && inst.operands[2].reg != inst.operands[1].reg + 1,
5139 _("can only store two consecutive registers"));
5140 /* If op 2 were present and equal to PC, this function wouldn't
5141 have been called in the first place. */
5142 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5143
c19d1205
ZW
5144 constraint (inst.operands[0].reg == inst.operands[1].reg
5145 || inst.operands[0].reg == inst.operands[1].reg + 1
5146 || inst.operands[0].reg == inst.operands[3].reg,
5147 BAD_OVERLAP);
e16bb312 5148
c19d1205
ZW
5149 inst.instruction |= inst.operands[0].reg << 12;
5150 inst.instruction |= inst.operands[1].reg;
5151 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5152}
5153
c19d1205
ZW
5154/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5155 extends it to 32-bits, and adds the result to a value in another
5156 register. You can specify a rotation by 0, 8, 16, or 24 bits
5157 before extracting the 16-bit value.
5158 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5159 Condition defaults to COND_ALWAYS.
5160 Error if any register uses R15. */
5161
e16bb312 5162static void
c19d1205 5163do_sxtah (void)
e16bb312 5164{
c19d1205
ZW
5165 inst.instruction |= inst.operands[0].reg << 12;
5166 inst.instruction |= inst.operands[1].reg << 16;
5167 inst.instruction |= inst.operands[2].reg;
5168 inst.instruction |= inst.operands[3].imm << 10;
5169}
e16bb312 5170
c19d1205 5171/* ARM V6 SXTH.
e16bb312 5172
c19d1205
ZW
5173 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5174 Condition defaults to COND_ALWAYS.
5175 Error if any register uses R15. */
e16bb312
NC
5176
5177static void
c19d1205 5178do_sxth (void)
e16bb312 5179{
c19d1205
ZW
5180 inst.instruction |= inst.operands[0].reg << 12;
5181 inst.instruction |= inst.operands[1].reg;
5182 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5183}
c19d1205
ZW
5184\f
5185/* VFP instructions. In a logical order: SP variant first, monad
5186 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5187
5188static void
c19d1205 5189do_vfp_sp_monadic (void)
e16bb312 5190{
c19d1205
ZW
5191 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5192 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5193}
5194
5195static void
c19d1205 5196do_vfp_sp_dyadic (void)
e16bb312 5197{
c19d1205
ZW
5198 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5199 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5200 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5201}
5202
5203static void
c19d1205 5204do_vfp_sp_compare_z (void)
e16bb312 5205{
c19d1205 5206 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5207}
5208
5209static void
c19d1205 5210do_vfp_dp_sp_cvt (void)
e16bb312 5211{
c19d1205
ZW
5212 inst.instruction |= inst.operands[0].reg << 12;
5213 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5214}
5215
5216static void
c19d1205 5217do_vfp_sp_dp_cvt (void)
e16bb312 5218{
c19d1205
ZW
5219 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5220 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5221}
5222
5223static void
c19d1205 5224do_vfp_reg_from_sp (void)
e16bb312 5225{
c19d1205
ZW
5226 inst.instruction |= inst.operands[0].reg << 12;
5227 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5228}
5229
5230static void
c19d1205 5231do_vfp_reg2_from_sp2 (void)
e16bb312 5232{
c19d1205
ZW
5233 constraint (inst.operands[2].imm != 2,
5234 _("only two consecutive VFP SP registers allowed here"));
5235 inst.instruction |= inst.operands[0].reg << 12;
5236 inst.instruction |= inst.operands[1].reg << 16;
5237 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5238}
5239
5240static void
c19d1205 5241do_vfp_sp_from_reg (void)
e16bb312 5242{
c19d1205
ZW
5243 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5244 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5245}
5246
5247static void
c19d1205 5248do_vfp_sp2_from_reg2 (void)
e16bb312 5249{
c19d1205
ZW
5250 constraint (inst.operands[0].imm != 2,
5251 _("only two consecutive VFP SP registers allowed here"));
5252 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5253 inst.instruction |= inst.operands[1].reg << 12;
5254 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5255}
5256
5257static void
c19d1205 5258do_vfp_sp_ldst (void)
e16bb312 5259{
c19d1205
ZW
5260 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5261 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5262}
5263
5264static void
c19d1205 5265do_vfp_dp_ldst (void)
e16bb312 5266{
c19d1205
ZW
5267 inst.instruction |= inst.operands[0].reg << 12;
5268 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5269}
5270
c19d1205 5271
e16bb312 5272static void
c19d1205 5273vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5274{
c19d1205
ZW
5275 if (inst.operands[0].writeback)
5276 inst.instruction |= WRITE_BACK;
5277 else
5278 constraint (ldstm_type != VFP_LDSTMIA,
5279 _("this addressing mode requires base-register writeback"));
5280 inst.instruction |= inst.operands[0].reg << 16;
5281 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5282 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5283}
5284
5285static void
c19d1205 5286vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5287{
c19d1205 5288 int count;
e16bb312 5289
c19d1205
ZW
5290 if (inst.operands[0].writeback)
5291 inst.instruction |= WRITE_BACK;
5292 else
5293 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5294 _("this addressing mode requires base-register writeback"));
e16bb312 5295
c19d1205
ZW
5296 inst.instruction |= inst.operands[0].reg << 16;
5297 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5298
c19d1205
ZW
5299 count = inst.operands[1].imm << 1;
5300 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5301 count += 1;
e16bb312 5302
c19d1205 5303 inst.instruction |= count;
e16bb312
NC
5304}
5305
5306static void
c19d1205 5307do_vfp_sp_ldstmia (void)
e16bb312 5308{
c19d1205 5309 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5310}
5311
5312static void
c19d1205 5313do_vfp_sp_ldstmdb (void)
e16bb312 5314{
c19d1205 5315 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5316}
5317
5318static void
c19d1205 5319do_vfp_dp_ldstmia (void)
e16bb312 5320{
c19d1205 5321 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5322}
5323
5324static void
c19d1205 5325do_vfp_dp_ldstmdb (void)
e16bb312 5326{
c19d1205 5327 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5328}
5329
5330static void
c19d1205 5331do_vfp_xp_ldstmia (void)
e16bb312 5332{
c19d1205
ZW
5333 vfp_dp_ldstm (VFP_LDSTMIAX);
5334}
e16bb312 5335
c19d1205
ZW
5336static void
5337do_vfp_xp_ldstmdb (void)
5338{
5339 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5340}
c19d1205
ZW
5341\f
5342/* FPA instructions. Also in a logical order. */
e16bb312 5343
c19d1205
ZW
5344static void
5345do_fpa_cmp (void)
5346{
5347 inst.instruction |= inst.operands[0].reg << 16;
5348 inst.instruction |= inst.operands[1].reg;
5349}
b99bd4ef
NC
5350
5351static void
c19d1205 5352do_fpa_ldmstm (void)
b99bd4ef 5353{
c19d1205
ZW
5354 inst.instruction |= inst.operands[0].reg << 12;
5355 switch (inst.operands[1].imm)
5356 {
5357 case 1: inst.instruction |= CP_T_X; break;
5358 case 2: inst.instruction |= CP_T_Y; break;
5359 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5360 case 4: break;
5361 default: abort ();
5362 }
b99bd4ef 5363
c19d1205
ZW
5364 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5365 {
5366 /* The instruction specified "ea" or "fd", so we can only accept
5367 [Rn]{!}. The instruction does not really support stacking or
5368 unstacking, so we have to emulate these by setting appropriate
5369 bits and offsets. */
5370 constraint (inst.reloc.exp.X_op != O_constant
5371 || inst.reloc.exp.X_add_number != 0,
5372 _("this instruction does not support indexing"));
b99bd4ef 5373
c19d1205
ZW
5374 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5375 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5376
c19d1205
ZW
5377 if (!(inst.instruction & INDEX_UP))
5378 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5379
c19d1205
ZW
5380 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5381 {
5382 inst.operands[2].preind = 0;
5383 inst.operands[2].postind = 1;
5384 }
5385 }
b99bd4ef 5386
c19d1205 5387 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5388}
c19d1205
ZW
5389\f
5390/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5391
c19d1205
ZW
5392static void
5393do_iwmmxt_tandorc (void)
5394{
5395 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5396}
b99bd4ef 5397
c19d1205
ZW
5398static void
5399do_iwmmxt_textrc (void)
5400{
5401 inst.instruction |= inst.operands[0].reg << 12;
5402 inst.instruction |= inst.operands[1].imm;
5403}
b99bd4ef
NC
5404
5405static void
c19d1205 5406do_iwmmxt_textrm (void)
b99bd4ef 5407{
c19d1205
ZW
5408 inst.instruction |= inst.operands[0].reg << 12;
5409 inst.instruction |= inst.operands[1].reg << 16;
5410 inst.instruction |= inst.operands[2].imm;
5411}
b99bd4ef 5412
c19d1205
ZW
5413static void
5414do_iwmmxt_tinsr (void)
5415{
5416 inst.instruction |= inst.operands[0].reg << 16;
5417 inst.instruction |= inst.operands[1].reg << 12;
5418 inst.instruction |= inst.operands[2].imm;
5419}
b99bd4ef 5420
c19d1205
ZW
5421static void
5422do_iwmmxt_tmia (void)
5423{
5424 inst.instruction |= inst.operands[0].reg << 5;
5425 inst.instruction |= inst.operands[1].reg;
5426 inst.instruction |= inst.operands[2].reg << 12;
5427}
b99bd4ef 5428
c19d1205
ZW
5429static void
5430do_iwmmxt_waligni (void)
5431{
5432 inst.instruction |= inst.operands[0].reg << 12;
5433 inst.instruction |= inst.operands[1].reg << 16;
5434 inst.instruction |= inst.operands[2].reg;
5435 inst.instruction |= inst.operands[3].imm << 20;
5436}
b99bd4ef 5437
c19d1205
ZW
5438static void
5439do_iwmmxt_wmov (void)
5440{
5441 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5442 inst.instruction |= inst.operands[0].reg << 12;
5443 inst.instruction |= inst.operands[1].reg << 16;
5444 inst.instruction |= inst.operands[1].reg;
5445}
b99bd4ef 5446
c19d1205
ZW
5447static void
5448do_iwmmxt_wldstbh (void)
5449{
5450 inst.instruction |= inst.operands[0].reg << 12;
5451 inst.reloc.exp.X_add_number *= 4;
5452 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
b99bd4ef
NC
5453}
5454
c19d1205
ZW
5455static void
5456do_iwmmxt_wldstw (void)
5457{
5458 /* RIWR_RIWC clears .isreg for a control register. */
5459 if (!inst.operands[0].isreg)
5460 {
5461 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5462 inst.instruction |= 0xf0000000;
5463 }
b99bd4ef 5464
c19d1205
ZW
5465 inst.instruction |= inst.operands[0].reg << 12;
5466 encode_arm_cp_address (1, TRUE, TRUE, 0);
5467}
b99bd4ef
NC
5468
5469static void
c19d1205 5470do_iwmmxt_wldstd (void)
b99bd4ef 5471{
c19d1205
ZW
5472 inst.instruction |= inst.operands[0].reg << 12;
5473 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
5474}
b99bd4ef 5475
c19d1205
ZW
5476static void
5477do_iwmmxt_wshufh (void)
5478{
5479 inst.instruction |= inst.operands[0].reg << 12;
5480 inst.instruction |= inst.operands[1].reg << 16;
5481 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5482 inst.instruction |= (inst.operands[2].imm & 0x0f);
5483}
b99bd4ef 5484
c19d1205
ZW
5485static void
5486do_iwmmxt_wzero (void)
5487{
5488 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5489 inst.instruction |= inst.operands[0].reg;
5490 inst.instruction |= inst.operands[0].reg << 12;
5491 inst.instruction |= inst.operands[0].reg << 16;
5492}
5493\f
5494/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5495 operations first, then control, shift, and load/store. */
b99bd4ef 5496
c19d1205 5497/* Insns like "foo X,Y,Z". */
b99bd4ef 5498
c19d1205
ZW
5499static void
5500do_mav_triple (void)
5501{
5502 inst.instruction |= inst.operands[0].reg << 16;
5503 inst.instruction |= inst.operands[1].reg;
5504 inst.instruction |= inst.operands[2].reg << 12;
5505}
b99bd4ef 5506
c19d1205
ZW
5507/* Insns like "foo W,X,Y,Z".
5508 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5509
c19d1205
ZW
5510static void
5511do_mav_quad (void)
5512{
5513 inst.instruction |= inst.operands[0].reg << 5;
5514 inst.instruction |= inst.operands[1].reg << 12;
5515 inst.instruction |= inst.operands[2].reg << 16;
5516 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5517}
5518
c19d1205
ZW
5519/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5520static void
5521do_mav_dspsc (void)
a737bd4d 5522{
c19d1205
ZW
5523 inst.instruction |= inst.operands[1].reg << 12;
5524}
a737bd4d 5525
c19d1205
ZW
5526/* Maverick shift immediate instructions.
5527 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5528 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5529
c19d1205
ZW
5530static void
5531do_mav_shift (void)
5532{
5533 int imm = inst.operands[2].imm;
a737bd4d 5534
c19d1205
ZW
5535 inst.instruction |= inst.operands[0].reg << 12;
5536 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5537
c19d1205
ZW
5538 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5539 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5540 Bit 4 should be 0. */
5541 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5542
c19d1205
ZW
5543 inst.instruction |= imm;
5544}
5545\f
5546/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5547
c19d1205
ZW
5548/* Xscale multiply-accumulate (argument parse)
5549 MIAcc acc0,Rm,Rs
5550 MIAPHcc acc0,Rm,Rs
5551 MIAxycc acc0,Rm,Rs. */
a737bd4d 5552
c19d1205
ZW
5553static void
5554do_xsc_mia (void)
5555{
5556 inst.instruction |= inst.operands[1].reg;
5557 inst.instruction |= inst.operands[2].reg << 12;
5558}
a737bd4d 5559
c19d1205 5560/* Xscale move-accumulator-register (argument parse)
a737bd4d 5561
c19d1205 5562 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5563
c19d1205
ZW
5564static void
5565do_xsc_mar (void)
5566{
5567 inst.instruction |= inst.operands[1].reg << 12;
5568 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5569}
5570
c19d1205 5571/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5572
c19d1205 5573 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5574
5575static void
c19d1205 5576do_xsc_mra (void)
b99bd4ef 5577{
c19d1205
ZW
5578 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5579 inst.instruction |= inst.operands[0].reg << 12;
5580 inst.instruction |= inst.operands[1].reg << 16;
5581}
5582\f
5583/* Encoding functions relevant only to Thumb. */
b99bd4ef 5584
c19d1205
ZW
5585/* inst.operands[i] is a shifted-register operand; encode
5586 it into inst.instruction in the format used by Thumb32. */
5587
5588static void
5589encode_thumb32_shifted_operand (int i)
5590{
5591 unsigned int value = inst.reloc.exp.X_add_number;
5592 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5593
c19d1205
ZW
5594 inst.instruction |= inst.operands[i].reg;
5595 if (shift == SHIFT_RRX)
5596 inst.instruction |= SHIFT_ROR << 4;
5597 else
b99bd4ef 5598 {
c19d1205
ZW
5599 constraint (inst.reloc.exp.X_op != O_constant,
5600 _("expression too complex"));
5601
5602 constraint (value > 32
5603 || (value == 32 && (shift == SHIFT_LSL
5604 || shift == SHIFT_ROR)),
5605 _("shift expression is too large"));
5606
5607 if (value == 0)
5608 shift = SHIFT_LSL;
5609 else if (value == 32)
5610 value = 0;
5611
5612 inst.instruction |= shift << 4;
5613 inst.instruction |= (value & 0x1c) << 10;
5614 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5615 }
c19d1205 5616}
b99bd4ef 5617
b99bd4ef 5618
c19d1205
ZW
5619/* inst.operands[i] was set up by parse_address. Encode it into a
5620 Thumb32 format load or store instruction. Reject forms that cannot
5621 be used with such instructions. If is_t is true, reject forms that
5622 cannot be used with a T instruction; if is_d is true, reject forms
5623 that cannot be used with a D instruction. */
b99bd4ef 5624
c19d1205
ZW
5625static void
5626encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5627{
5628 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5629
5630 constraint (!inst.operands[i].isreg,
5631 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5632
c19d1205
ZW
5633 inst.instruction |= inst.operands[i].reg << 16;
5634 if (inst.operands[i].immisreg)
b99bd4ef 5635 {
c19d1205
ZW
5636 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5637 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5638 constraint (inst.operands[i].negative,
5639 _("Thumb does not support negative register indexing"));
5640 constraint (inst.operands[i].postind,
5641 _("Thumb does not support register post-indexing"));
5642 constraint (inst.operands[i].writeback,
5643 _("Thumb does not support register indexing with writeback"));
5644 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5645 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5646
c19d1205
ZW
5647 inst.instruction |= inst.operands[1].imm;
5648 if (inst.operands[i].shifted)
b99bd4ef 5649 {
c19d1205
ZW
5650 constraint (inst.reloc.exp.X_op != O_constant,
5651 _("expression too complex"));
5652 constraint (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 3,
5653 _("shift out of range"));
5654 inst.instruction |= inst.reloc.exp.X_op << 4;
5655 }
5656 inst.reloc.type = BFD_RELOC_UNUSED;
5657 }
5658 else if (inst.operands[i].preind)
5659 {
5660 constraint (is_pc && inst.operands[i].writeback,
5661 _("cannot use writeback with PC-relative addressing"));
5662 constraint (is_t && inst.operands[1].writeback,
5663 _("cannot use writeback with this instruction"));
5664
5665 if (is_d)
5666 {
5667 inst.instruction |= 0x01000000;
5668 if (inst.operands[i].writeback)
5669 inst.instruction |= 0x00200000;
b99bd4ef 5670 }
c19d1205 5671 else
b99bd4ef 5672 {
c19d1205
ZW
5673 inst.instruction |= 0x00000c00;
5674 if (inst.operands[i].writeback)
5675 inst.instruction |= 0x00000100;
b99bd4ef 5676 }
c19d1205
ZW
5677 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5678 inst.reloc.pc_rel = is_pc;
b99bd4ef 5679 }
c19d1205 5680 else if (inst.operands[i].postind)
b99bd4ef 5681 {
c19d1205
ZW
5682 assert (inst.operands[i].writeback);
5683 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5684 constraint (is_t, _("cannot use post-indexing with this instruction"));
5685
5686 if (is_d)
5687 inst.instruction |= 0x00200000;
5688 else
5689 inst.instruction |= 0x00000900;
5690 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5691 }
5692 else /* unindexed - only for coprocessor */
5693 inst.error = _("instruction does not accept unindexed addressing");
5694}
5695
5696/* Table of Thumb instructions which exist in both 16- and 32-bit
5697 encodings (the latter only in post-V6T2 cores). The index is the
5698 value used in the insns table below. When there is more than one
5699 possible 16-bit encoding for the instruction, this table always
5700 holds variant (1). */
5701#define T16_32_TAB \
5702 X(adc, 4140, eb400000), \
5703 X(adcs, 4140, eb500000), \
5704 X(add, 1c00, eb000000), \
5705 X(adds, 1c00, eb100000), \
5706 X(and, 4000, ea000000), \
5707 X(ands, 4000, ea100000), \
5708 X(asr, 1000, fa40f000), \
5709 X(asrs, 1000, fa50f000), \
5710 X(bic, 4380, ea200000), \
5711 X(bics, 4380, ea300000), \
5712 X(cmn, 42c0, eb100f00), \
5713 X(cmp, 2800, ebb00f00), \
5714 X(cpsie, b660, f3af8400), \
5715 X(cpsid, b670, f3af8600), \
5716 X(cpy, 4600, ea4f0000), \
5717 X(eor, 4040, ea800000), \
5718 X(eors, 4040, ea900000), \
5719 X(ldmia, c800, e8900000), \
5720 X(ldr, 6800, f8500000), \
5721 X(ldrb, 7800, f8100000), \
5722 X(ldrh, 8800, f8300000), \
5723 X(ldrsb, 5600, f9100000), \
5724 X(ldrsh, 5e00, f9300000), \
5725 X(lsl, 0000, fa00f000), \
5726 X(lsls, 0000, fa10f000), \
5727 X(lsr, 0800, fa20f000), \
5728 X(lsrs, 0800, fa30f000), \
5729 X(mov, 2000, ea4f0000), \
5730 X(movs, 2000, ea5f0000), \
5731 X(mul, 4340, fb00f000), \
5732 X(muls, 4340, ffffffff), /* no 32b muls */ \
5733 X(mvn, 43c0, ea6f0000), \
5734 X(mvns, 43c0, ea7f0000), \
5735 X(neg, 4240, f1c00000), /* rsb #0 */ \
5736 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5737 X(orr, 4300, ea400000), \
5738 X(orrs, 4300, ea500000), \
5739 X(pop, bc00, e8ad0000), /* ldmia sp!,... */ \
5740 X(push, b400, e8bd0000), /* stmia sp!,... */ \
5741 X(rev, ba00, fa90f080), \
5742 X(rev16, ba40, fa90f090), \
5743 X(revsh, bac0, fa90f0b0), \
5744 X(ror, 41c0, fa60f000), \
5745 X(rors, 41c0, fa70f000), \
5746 X(sbc, 4180, eb600000), \
5747 X(sbcs, 4180, eb700000), \
5748 X(stmia, c000, e8800000), \
5749 X(str, 6000, f8400000), \
5750 X(strb, 7000, f8000000), \
5751 X(strh, 8000, f8200000), \
5752 X(sub, 1e00, eba00000), \
5753 X(subs, 1e00, ebb00000), \
5754 X(sxtb, b240, fa4ff080), \
5755 X(sxth, b200, fa0ff080), \
5756 X(tst, 4200, ea100f00), \
5757 X(uxtb, b2c0, fa5ff080), \
5758 X(uxth, b280, fa1ff080), \
5759 X(nop, bf00, f3af8000), \
5760 X(yield, bf10, f3af8001), \
5761 X(wfe, bf20, f3af8002), \
5762 X(wfi, bf30, f3af8003), \
5763 X(sev, bf40, f3af9004), /* typo, 8004? */
5764
5765/* To catch errors in encoding functions, the codes are all offset by
5766 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5767 as 16-bit instructions. */
5768#define X(a,b,c) T_MNEM_##a
5769enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5770#undef X
5771
5772#define X(a,b,c) 0x##b
5773static const unsigned short thumb_op16[] = { T16_32_TAB };
5774#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5775#undef X
5776
5777#define X(a,b,c) 0x##c
5778static const unsigned int thumb_op32[] = { T16_32_TAB };
5779#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5780#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5781#undef X
5782#undef T16_32_TAB
5783
5784/* Thumb instruction encoders, in alphabetical order. */
5785
5786/* Parse an add or subtract instruction. We get here with inst.instruction
5787 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5788
5789static void
5790do_t_add_sub (void)
5791{
5792 int Rd, Rs, Rn;
5793
5794 Rd = inst.operands[0].reg;
5795 Rs = (inst.operands[1].present
5796 ? inst.operands[1].reg /* Rd, Rs, foo */
5797 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5798
5799 if (unified_syntax)
5800 {
5801 if (!inst.operands[2].isreg)
b99bd4ef 5802 {
c19d1205
ZW
5803 /* For an immediate, we always generate a 32-bit opcode;
5804 section relaxation will shrink it later if possible. */
5805 inst.instruction = THUMB_OP32 (inst.instruction);
5806 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5807 inst.instruction |= inst.operands[0].reg << 8;
5808 inst.instruction |= inst.operands[1].reg << 16;
5809 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 5810 }
c19d1205
ZW
5811 else
5812 {
5813 Rn = inst.operands[2].reg;
5814 /* See if we can do this with a 16-bit instruction. */
5815 if (!inst.operands[2].shifted && inst.size_req != 4)
5816 {
5817 if (Rd <= 7 && Rn <= 7 && Rn <= 7
5818 && (inst.instruction == T_MNEM_adds
5819 || inst.instruction == T_MNEM_subs))
5820 {
5821 inst.instruction = (inst.instruction == T_MNEM_adds
5822 ? T_OPCODE_ADD_R3
5823 : T_OPCODE_SUB_R3);
5824 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
5825 return;
5826 }
b99bd4ef 5827
c19d1205
ZW
5828 if (inst.instruction == T_MNEM_add)
5829 {
5830 if (Rd == Rs)
5831 {
5832 inst.instruction = T_OPCODE_ADD_HI;
5833 inst.instruction |= (Rd & 8) << 4;
5834 inst.instruction |= (Rd & 7);
5835 inst.instruction |= Rn << 3;
5836 return;
5837 }
5838 /* ... because addition is commutative! */
5839 else if (Rd == Rn)
5840 {
5841 inst.instruction = T_OPCODE_ADD_HI;
5842 inst.instruction |= (Rd & 8) << 4;
5843 inst.instruction |= (Rd & 7);
5844 inst.instruction |= Rs << 3;
5845 return;
5846 }
5847 }
5848 }
5849 /* If we get here, it can't be done in 16 bits. */
5850 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
5851 _("shift must be constant"));
5852 inst.instruction = THUMB_OP32 (inst.instruction);
5853 inst.instruction |= Rd << 8;
5854 inst.instruction |= Rs << 16;
5855 encode_thumb32_shifted_operand (2);
5856 }
5857 }
5858 else
5859 {
5860 constraint (inst.instruction == T_MNEM_adds
5861 || inst.instruction == T_MNEM_subs,
5862 BAD_THUMB32);
b99bd4ef 5863
c19d1205 5864 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 5865 {
c19d1205
ZW
5866 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
5867 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
5868 BAD_HIREG);
5869
5870 inst.instruction = (inst.instruction == T_MNEM_add
5871 ? 0x0000 : 0x8000);
5872 inst.instruction |= (Rd << 4) | Rs;
5873 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
5874 return;
5875 }
5876
c19d1205
ZW
5877 Rn = inst.operands[2].reg;
5878 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 5879
c19d1205
ZW
5880 /* We now have Rd, Rs, and Rn set to registers. */
5881 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 5882 {
c19d1205
ZW
5883 /* Can't do this for SUB. */
5884 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
5885 inst.instruction = T_OPCODE_ADD_HI;
5886 inst.instruction |= (Rd & 8) << 4;
5887 inst.instruction |= (Rd & 7);
5888 if (Rs == Rd)
5889 inst.instruction |= Rn << 3;
5890 else if (Rn == Rd)
5891 inst.instruction |= Rs << 3;
5892 else
5893 constraint (1, _("dest must overlap one source register"));
5894 }
5895 else
5896 {
5897 inst.instruction = (inst.instruction == T_MNEM_add
5898 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
5899 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 5900 }
b99bd4ef 5901 }
b99bd4ef
NC
5902}
5903
c19d1205
ZW
5904static void
5905do_t_adr (void)
5906{
5907 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
5908 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
5909 inst.reloc.pc_rel = 1;
b99bd4ef 5910
c19d1205
ZW
5911 inst.instruction |= inst.operands[0].reg << 4;
5912}
b99bd4ef 5913
c19d1205
ZW
5914/* Arithmetic instructions for which there is just one 16-bit
5915 instruction encoding, and it allows only two low registers.
5916 For maximal compatibility with ARM syntax, we allow three register
5917 operands even when Thumb-32 instructions are not available, as long
5918 as the first two are identical. For instance, both "sbc r0,r1" and
5919 "sbc r0,r0,r1" are allowed. */
b99bd4ef 5920static void
c19d1205 5921do_t_arit3 (void)
b99bd4ef 5922{
c19d1205 5923 int Rd, Rs, Rn;
b99bd4ef 5924
c19d1205
ZW
5925 Rd = inst.operands[0].reg;
5926 Rs = (inst.operands[1].present
5927 ? inst.operands[1].reg /* Rd, Rs, foo */
5928 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5929 Rn = inst.operands[2].reg;
b99bd4ef 5930
c19d1205 5931 if (unified_syntax)
b99bd4ef 5932 {
c19d1205
ZW
5933 if (!inst.operands[2].isreg)
5934 {
5935 /* For an immediate, we always generate a 32-bit opcode;
5936 section relaxation will shrink it later if possible. */
5937 inst.instruction = THUMB_OP32 (inst.instruction);
5938 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5939 inst.instruction |= Rd << 8;
5940 inst.instruction |= Rs << 16;
5941 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
5942 }
5943 else
5944 {
5945 /* See if we can do this with a 16-bit instruction. */
5946 if (THUMB_SETS_FLAGS (inst.instruction)
5947 && !inst.operands[2].shifted
5948 && inst.size_req != 4
5949 && Rd == Rs)
5950 {
5951 inst.instruction = THUMB_OP16 (inst.instruction);
5952 inst.instruction |= Rd;
5953 inst.instruction |= Rn << 3;
5954 return;
5955 }
b99bd4ef 5956
c19d1205
ZW
5957 /* If we get here, it can't be done in 16 bits. */
5958 constraint (inst.operands[2].shifted
5959 && inst.operands[2].immisreg,
5960 _("shift must be constant"));
5961 inst.instruction = THUMB_OP32 (inst.instruction);
5962 inst.instruction |= Rd << 8;
5963 inst.instruction |= Rs << 16;
5964 encode_thumb32_shifted_operand (2);
5965 }
a737bd4d 5966 }
c19d1205 5967 else
b99bd4ef 5968 {
c19d1205
ZW
5969 /* On its face this is a lie - the instruction does set the
5970 flags. However, the only supported mnemonic in this mode
5971 says it doesn't. */
5972 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 5973
c19d1205
ZW
5974 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
5975 _("unshifted register required"));
5976 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
5977 constraint (Rd != Rs,
5978 _("dest and source1 must be the same register"));
a737bd4d 5979
c19d1205
ZW
5980 inst.instruction = THUMB_OP16 (inst.instruction);
5981 inst.instruction |= Rd;
5982 inst.instruction |= Rn << 3;
b99bd4ef 5983 }
a737bd4d 5984}
b99bd4ef 5985
c19d1205
ZW
5986/* Similarly, but for instructions where the arithmetic operation is
5987 commutative, so we can allow either of them to be different from
5988 the destination operand in a 16-bit instruction. For instance, all
5989 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
5990 accepted. */
5991static void
5992do_t_arit3c (void)
a737bd4d 5993{
c19d1205 5994 int Rd, Rs, Rn;
b99bd4ef 5995
c19d1205
ZW
5996 Rd = inst.operands[0].reg;
5997 Rs = (inst.operands[1].present
5998 ? inst.operands[1].reg /* Rd, Rs, foo */
5999 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6000 Rn = inst.operands[2].reg;
a737bd4d 6001
c19d1205 6002 if (unified_syntax)
a737bd4d 6003 {
c19d1205 6004 if (!inst.operands[2].isreg)
b99bd4ef 6005 {
c19d1205
ZW
6006 /* For an immediate, we always generate a 32-bit opcode;
6007 section relaxation will shrink it later if possible. */
6008 inst.instruction = THUMB_OP32 (inst.instruction);
6009 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6010 inst.instruction |= Rd << 8;
6011 inst.instruction |= Rs << 16;
6012 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6013 }
c19d1205 6014 else
a737bd4d 6015 {
c19d1205
ZW
6016 /* See if we can do this with a 16-bit instruction. */
6017 if (THUMB_SETS_FLAGS (inst.instruction)
6018 && !inst.operands[2].shifted
6019 && inst.size_req != 4)
a737bd4d 6020 {
c19d1205 6021 if (Rd == Rs)
a737bd4d 6022 {
c19d1205
ZW
6023 inst.instruction = THUMB_OP16 (inst.instruction);
6024 inst.instruction |= Rd;
6025 inst.instruction |= Rn << 3;
6026 return;
a737bd4d 6027 }
c19d1205 6028 if (Rd == Rn)
a737bd4d 6029 {
c19d1205
ZW
6030 inst.instruction = THUMB_OP16 (inst.instruction);
6031 inst.instruction |= Rd;
6032 inst.instruction |= Rs << 3;
6033 return;
a737bd4d
NC
6034 }
6035 }
c19d1205
ZW
6036
6037 /* If we get here, it can't be done in 16 bits. */
6038 constraint (inst.operands[2].shifted
6039 && inst.operands[2].immisreg,
6040 _("shift must be constant"));
6041 inst.instruction = THUMB_OP32 (inst.instruction);
6042 inst.instruction |= Rd << 8;
6043 inst.instruction |= Rs << 16;
6044 encode_thumb32_shifted_operand (2);
a737bd4d 6045 }
b99bd4ef 6046 }
c19d1205
ZW
6047 else
6048 {
6049 /* On its face this is a lie - the instruction does set the
6050 flags. However, the only supported mnemonic in this mode
6051 says it doesn't. */
6052 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6053
c19d1205
ZW
6054 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6055 _("unshifted register required"));
6056 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6057
6058 inst.instruction = THUMB_OP16 (inst.instruction);
6059 inst.instruction |= Rd;
6060
6061 if (Rd == Rs)
6062 inst.instruction |= Rn << 3;
6063 else if (Rd == Rn)
6064 inst.instruction |= Rs << 3;
6065 else
6066 constraint (1, _("dest must overlap one source register"));
6067 }
a737bd4d
NC
6068}
6069
c19d1205
ZW
6070static void
6071do_t_bfc (void)
a737bd4d 6072{
c19d1205
ZW
6073 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6074 constraint (msb > 32, _("bit-field extends past end of register"));
6075 /* The instruction encoding stores the LSB and MSB,
6076 not the LSB and width. */
6077 inst.instruction |= inst.operands[0].reg << 8;
6078 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6079 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6080 inst.instruction |= msb - 1;
b99bd4ef
NC
6081}
6082
c19d1205
ZW
6083static void
6084do_t_bfi (void)
b99bd4ef 6085{
c19d1205 6086 unsigned int msb;
b99bd4ef 6087
c19d1205
ZW
6088 /* #0 in second position is alternative syntax for bfc, which is
6089 the same instruction but with REG_PC in the Rm field. */
6090 if (!inst.operands[1].isreg)
6091 inst.operands[1].reg = REG_PC;
b99bd4ef 6092
c19d1205
ZW
6093 msb = inst.operands[2].imm + inst.operands[3].imm;
6094 constraint (msb > 32, _("bit-field extends past end of register"));
6095 /* The instruction encoding stores the LSB and MSB,
6096 not the LSB and width. */
6097 inst.instruction |= inst.operands[0].reg << 8;
6098 inst.instruction |= inst.operands[1].reg << 16;
6099 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6100 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6101 inst.instruction |= msb - 1;
b99bd4ef
NC
6102}
6103
c19d1205
ZW
6104static void
6105do_t_bfx (void)
b99bd4ef 6106{
c19d1205
ZW
6107 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6108 _("bit-field extends past end of register"));
6109 inst.instruction |= inst.operands[0].reg << 8;
6110 inst.instruction |= inst.operands[1].reg << 16;
6111 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6112 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6113 inst.instruction |= inst.operands[3].imm - 1;
6114}
b99bd4ef 6115
c19d1205
ZW
6116/* ARM V5 Thumb BLX (argument parse)
6117 BLX <target_addr> which is BLX(1)
6118 BLX <Rm> which is BLX(2)
6119 Unfortunately, there are two different opcodes for this mnemonic.
6120 So, the insns[].value is not used, and the code here zaps values
6121 into inst.instruction.
b99bd4ef 6122
c19d1205
ZW
6123 ??? How to take advantage of the additional two bits of displacement
6124 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6125
c19d1205
ZW
6126static void
6127do_t_blx (void)
6128{
6129 if (inst.operands[0].isreg)
6130 /* We have a register, so this is BLX(2). */
6131 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6132 else
6133 {
c19d1205
ZW
6134 /* No register. This must be BLX(1). */
6135 inst.instruction = 0xf7ffeffe;
6136 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6137 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6138 }
6139}
6140
c19d1205
ZW
6141static void
6142do_t_branch (void)
b99bd4ef 6143{
c19d1205
ZW
6144 if (unified_syntax && inst.size_req != 2)
6145 {
6146 if (inst.cond == COND_ALWAYS)
6147 {
6148 inst.instruction = 0xf7ffbffe;
6149 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6150 }
6151 else
6152 {
6153 assert (inst.cond != 0xF);
6154 inst.instruction = (inst.cond << 22) | 0xf43faffe;
6155 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6156 }
6157 }
b99bd4ef
NC
6158 else
6159 {
c19d1205
ZW
6160 if (inst.cond == COND_ALWAYS)
6161 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6162 else
b99bd4ef 6163 {
c19d1205
ZW
6164 inst.instruction = 0xd0fe | (inst.cond << 8);
6165 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6166 }
b99bd4ef 6167 }
c19d1205
ZW
6168
6169 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6170}
6171
6172static void
c19d1205 6173do_t_bkpt (void)
b99bd4ef 6174{
c19d1205 6175 if (inst.operands[0].present)
b99bd4ef 6176 {
c19d1205
ZW
6177 constraint (inst.operands[0].imm > 255,
6178 _("immediate value out of range"));
6179 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6180 }
b99bd4ef
NC
6181}
6182
6183static void
c19d1205 6184do_t_branch23 (void)
b99bd4ef 6185{
c19d1205 6186 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6187 inst.reloc.pc_rel = 1;
6188
c19d1205
ZW
6189 /* If the destination of the branch is a defined symbol which does not have
6190 the THUMB_FUNC attribute, then we must be calling a function which has
6191 the (interfacearm) attribute. We look for the Thumb entry point to that
6192 function and change the branch to refer to that function instead. */
6193 if ( inst.reloc.exp.X_op == O_symbol
6194 && inst.reloc.exp.X_add_symbol != NULL
6195 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6196 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6197 inst.reloc.exp.X_add_symbol =
6198 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6199}
6200
6201static void
c19d1205 6202do_t_bx (void)
90e4755a 6203{
c19d1205
ZW
6204 inst.instruction |= inst.operands[0].reg << 3;
6205 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6206 should cause the alignment to be checked once it is known. This is
6207 because BX PC only works if the instruction is word aligned. */
6208}
90e4755a 6209
c19d1205
ZW
6210static void
6211do_t_bxj (void)
6212{
6213 if (inst.operands[0].reg == REG_PC)
6214 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6215
c19d1205 6216 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6217}
6218
6219static void
c19d1205 6220do_t_clz (void)
90e4755a 6221{
c19d1205
ZW
6222 inst.instruction |= inst.operands[0].reg << 8;
6223 inst.instruction |= inst.operands[1].reg << 16;
6224 inst.instruction |= inst.operands[1].reg;
6225}
90e4755a 6226
c19d1205
ZW
6227static void
6228do_t_cpsi (void)
6229{
6230 if (unified_syntax
6231 && (inst.operands[1].present || inst.size_req == 4))
90e4755a 6232 {
c19d1205
ZW
6233 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6234 inst.instruction = 0xf3af8000;
6235 inst.instruction |= imod << 9;
6236 inst.instruction |= inst.operands[0].imm << 5;
6237 if (inst.operands[1].present)
6238 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6239 }
c19d1205 6240 else
90e4755a 6241 {
c19d1205
ZW
6242 constraint (inst.operands[1].present,
6243 _("Thumb does not support the 2-argument "
6244 "form of this instruction"));
6245 inst.instruction |= inst.operands[0].imm;
90e4755a 6246 }
90e4755a
RE
6247}
6248
c19d1205
ZW
6249/* THUMB CPY instruction (argument parse). */
6250
90e4755a 6251static void
c19d1205 6252do_t_cpy (void)
90e4755a 6253{
c19d1205 6254 if (inst.size_req == 4)
90e4755a 6255 {
c19d1205
ZW
6256 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6257 inst.instruction |= inst.operands[0].reg << 8;
6258 inst.instruction |= inst.operands[1].reg;
90e4755a 6259 }
c19d1205 6260 else
90e4755a 6261 {
c19d1205
ZW
6262 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6263 inst.instruction |= (inst.operands[0].reg & 0x7);
6264 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6265 }
90e4755a
RE
6266}
6267
90e4755a 6268static void
c19d1205 6269do_t_czb (void)
90e4755a 6270{
c19d1205
ZW
6271 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6272 inst.instruction |= inst.operands[0].reg;
6273 inst.reloc.pc_rel = 1;
6274 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6275}
90e4755a 6276
c19d1205
ZW
6277static void
6278do_t_hint (void)
6279{
6280 if (unified_syntax && inst.size_req == 4)
6281 inst.instruction = THUMB_OP32 (inst.instruction);
6282 else
6283 inst.instruction = THUMB_OP16 (inst.instruction);
6284}
90e4755a 6285
c19d1205
ZW
6286static void
6287do_t_it (void)
6288{
6289 unsigned int cond = inst.operands[0].imm;
6290 if ((cond & 0x1) == 0x0)
90e4755a 6291 {
c19d1205
ZW
6292 unsigned int mask = inst.instruction & 0x000f;
6293 inst.instruction &= 0xfff0;
90e4755a 6294
c19d1205
ZW
6295 if ((mask & 0x7) == 0)
6296 /* no conversion needed */;
6297 else if ((mask & 0x3) == 0)
6298 mask = (~(mask & 0x8) & 0x8) | 0x4;
6299 else if ((mask & 1) == 0)
6300 mask = (~(mask & 0xC) & 0xC) | 0x2;
6301 else
6302 mask = (~(mask & 0xE) & 0xE) | 0x1;
90e4755a 6303
c19d1205
ZW
6304 inst.instruction |= (mask & 0xF);
6305 }
90e4755a 6306
c19d1205
ZW
6307 inst.instruction |= cond << 4;
6308}
90e4755a 6309
c19d1205
ZW
6310static void
6311do_t_ldmstm (void)
6312{
6313 /* This really doesn't seem worth it. */
6314 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6315 _("expression too complex"));
6316 constraint (inst.operands[1].writeback,
6317 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6318
c19d1205
ZW
6319 if (unified_syntax)
6320 {
6321 /* See if we can use a 16-bit instruction. */
6322 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6323 && inst.size_req != 4
6324 && inst.operands[0].reg <= 7
6325 && !(inst.operands[1].imm & ~0xff)
6326 && (inst.instruction == T_MNEM_stmia
6327 ? inst.operands[0].writeback
6328 : (inst.operands[0].writeback
6329 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6330 {
c19d1205
ZW
6331 if (inst.instruction == T_MNEM_stmia
6332 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6333 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6334 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6335 inst.operands[0].reg);
90e4755a 6336
c19d1205
ZW
6337 inst.instruction = THUMB_OP16 (inst.instruction);
6338 inst.instruction |= inst.operands[0].reg << 8;
6339 inst.instruction |= inst.operands[1].imm;
6340 }
6341 else
6342 {
6343 if (inst.operands[1].imm & (1 << 13))
6344 as_warn (_("SP should not be in register list"));
6345 if (inst.instruction == T_MNEM_stmia)
90e4755a 6346 {
c19d1205
ZW
6347 if (inst.operands[1].imm & (1 << 15))
6348 as_warn (_("PC should not be in register list"));
6349 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6350 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6351 inst.operands[0].reg);
90e4755a
RE
6352 }
6353 else
6354 {
c19d1205
ZW
6355 if (inst.operands[1].imm & (1 << 14)
6356 && inst.operands[1].imm & (1 << 15))
6357 as_warn (_("LR and PC should not both be in register list"));
6358 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6359 && inst.operands[0].writeback)
6360 as_warn (_("base register should not be in register list "
6361 "when written back"));
90e4755a 6362 }
c19d1205
ZW
6363 if (inst.instruction < 0xffff)
6364 inst.instruction = THUMB_OP32 (inst.instruction);
6365 inst.instruction |= inst.operands[0].reg << 16;
6366 inst.instruction |= inst.operands[1].imm;
6367 if (inst.operands[0].writeback)
6368 inst.instruction |= WRITE_BACK;
90e4755a
RE
6369 }
6370 }
c19d1205 6371 else
90e4755a 6372 {
c19d1205
ZW
6373 constraint (inst.operands[0].reg > 7
6374 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6375 if (inst.instruction == T_MNEM_stmia)
f03698e6 6376 {
c19d1205
ZW
6377 if (!inst.operands[0].writeback)
6378 as_warn (_("this instruction will write back the base register"));
6379 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6380 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6381 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6382 inst.operands[0].reg);
f03698e6 6383 }
c19d1205 6384 else
90e4755a 6385 {
c19d1205
ZW
6386 if (!inst.operands[0].writeback
6387 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6388 as_warn (_("this instruction will write back the base register"));
6389 else if (inst.operands[0].writeback
6390 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6391 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6392 }
6393
c19d1205
ZW
6394 inst.instruction = THUMB_OP16 (inst.instruction);
6395 inst.instruction |= inst.operands[0].reg << 8;
6396 inst.instruction |= inst.operands[1].imm;
6397 }
6398}
e28cd48c 6399
c19d1205
ZW
6400static void
6401do_t_ldrex (void)
6402{
6403 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6404 || inst.operands[1].postind || inst.operands[1].writeback
6405 || inst.operands[1].immisreg || inst.operands[1].shifted
6406 || inst.operands[1].negative,
6407 _("instruction does not accept this addressing mode"));
e28cd48c 6408
c19d1205
ZW
6409 inst.instruction |= inst.operands[0].reg << 12;
6410 inst.instruction |= inst.operands[1].reg << 16;
6411 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6412}
e28cd48c 6413
c19d1205
ZW
6414static void
6415do_t_ldrexd (void)
6416{
6417 if (!inst.operands[1].present)
1cac9012 6418 {
c19d1205
ZW
6419 constraint (inst.operands[0].reg == REG_LR,
6420 _("r14 not allowed as first register "
6421 "when second register is omitted"));
6422 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6423 }
c19d1205
ZW
6424 constraint (inst.operands[0].reg == inst.operands[1].reg,
6425 BAD_OVERLAP);
b99bd4ef 6426
c19d1205
ZW
6427 inst.instruction |= inst.operands[0].reg << 12;
6428 inst.instruction |= inst.operands[1].reg << 8;
6429 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6430}
6431
6432static void
c19d1205 6433do_t_ldst (void)
b99bd4ef 6434{
c19d1205 6435 if (unified_syntax)
b99bd4ef 6436 {
c19d1205
ZW
6437 /* Generation of 16-bit instructions for anything other than
6438 Rd, [Rn, Ri] is deferred to section relaxation time. */
6439 if (inst.operands[1].isreg && inst.operands[1].immisreg
6440 && !inst.operands[1].shifted && !inst.operands[1].postind
6441 && !inst.operands[1].negative && inst.operands[0].reg <= 7
6442 && inst.operands[1].reg <= 7 && inst.operands[1].imm <= 7
6443 && inst.instruction <= 0xffff)
6444 {
6445 inst.instruction = THUMB_OP16 (inst.instruction);
6446 goto op16;
6447 }
6448
6449 inst.instruction = THUMB_OP32 (inst.instruction);
6450 inst.instruction |= inst.operands[0].reg << 12;
6451 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
6452 return;
6453 }
6454
c19d1205
ZW
6455 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6456
6457 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 6458 {
c19d1205
ZW
6459 /* Only [Rn,Rm] is acceptable. */
6460 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6461 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6462 || inst.operands[1].postind || inst.operands[1].shifted
6463 || inst.operands[1].negative,
6464 _("Thumb does not support this addressing mode"));
6465 inst.instruction = THUMB_OP16 (inst.instruction);
6466 goto op16;
b99bd4ef 6467 }
c19d1205
ZW
6468
6469 inst.instruction = THUMB_OP16 (inst.instruction);
6470 if (!inst.operands[1].isreg)
6471 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6472 return;
b99bd4ef 6473
c19d1205
ZW
6474 constraint (!inst.operands[1].preind
6475 || inst.operands[1].shifted
6476 || inst.operands[1].writeback,
6477 _("Thumb does not support this addressing mode"));
6478 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 6479 {
c19d1205
ZW
6480 constraint (inst.instruction & 0x0600,
6481 _("byte or halfword not valid for base register"));
6482 constraint (inst.operands[1].reg == REG_PC
6483 && !(inst.instruction & THUMB_LOAD_BIT),
6484 _("r15 based store not allowed"));
6485 constraint (inst.operands[1].immisreg,
6486 _("invalid base register for register offset"));
b99bd4ef 6487
c19d1205
ZW
6488 if (inst.operands[1].reg == REG_PC)
6489 inst.instruction = T_OPCODE_LDR_PC;
6490 else if (inst.instruction & THUMB_LOAD_BIT)
6491 inst.instruction = T_OPCODE_LDR_SP;
6492 else
6493 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 6494
c19d1205
ZW
6495 inst.instruction |= inst.operands[0].reg << 8;
6496 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6497 return;
6498 }
90e4755a 6499
c19d1205
ZW
6500 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6501 if (!inst.operands[1].immisreg)
6502 {
6503 /* Immediate offset. */
6504 inst.instruction |= inst.operands[0].reg;
6505 inst.instruction |= inst.operands[1].reg << 3;
6506 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6507 return;
6508 }
90e4755a 6509
c19d1205
ZW
6510 /* Register offset. */
6511 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6512 constraint (inst.operands[1].negative,
6513 _("Thumb does not support this addressing mode"));
90e4755a 6514
c19d1205
ZW
6515 op16:
6516 switch (inst.instruction)
6517 {
6518 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6519 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6520 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6521 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6522 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6523 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6524 case 0x5600 /* ldrsb */:
6525 case 0x5e00 /* ldrsh */: break;
6526 default: abort ();
6527 }
90e4755a 6528
c19d1205
ZW
6529 inst.instruction |= inst.operands[0].reg;
6530 inst.instruction |= inst.operands[1].reg << 3;
6531 inst.instruction |= inst.operands[1].imm << 6;
6532}
90e4755a 6533
c19d1205
ZW
6534static void
6535do_t_ldstd (void)
6536{
6537 if (!inst.operands[1].present)
b99bd4ef 6538 {
c19d1205
ZW
6539 inst.operands[1].reg = inst.operands[0].reg + 1;
6540 constraint (inst.operands[0].reg == REG_LR,
6541 _("r14 not allowed here"));
b99bd4ef 6542 }
c19d1205
ZW
6543 inst.instruction |= inst.operands[0].reg << 12;
6544 inst.instruction |= inst.operands[1].reg << 8;
6545 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6546
b99bd4ef
NC
6547}
6548
c19d1205
ZW
6549static void
6550do_t_ldstt (void)
6551{
6552 inst.instruction |= inst.operands[0].reg << 12;
6553 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6554}
a737bd4d 6555
b99bd4ef 6556static void
c19d1205 6557do_t_mla (void)
b99bd4ef 6558{
c19d1205
ZW
6559 inst.instruction |= inst.operands[0].reg << 8;
6560 inst.instruction |= inst.operands[1].reg << 16;
6561 inst.instruction |= inst.operands[2].reg;
6562 inst.instruction |= inst.operands[3].reg << 12;
6563}
b99bd4ef 6564
c19d1205
ZW
6565static void
6566do_t_mlal (void)
6567{
6568 inst.instruction |= inst.operands[0].reg << 12;
6569 inst.instruction |= inst.operands[1].reg << 8;
6570 inst.instruction |= inst.operands[2].reg << 16;
6571 inst.instruction |= inst.operands[3].reg;
6572}
b99bd4ef 6573
c19d1205
ZW
6574static void
6575do_t_mov_cmp (void)
6576{
6577 if (unified_syntax)
b99bd4ef 6578 {
c19d1205
ZW
6579 int r0off = (inst.instruction == T_MNEM_mov
6580 || inst.instruction == T_MNEM_movs) ? 8 : 16;
6581 if (!inst.operands[1].isreg)
6582 {
6583 /* For an immediate, we always generate a 32-bit opcode;
6584 section relaxation will shrink it later if possible. */
6585 inst.instruction = THUMB_OP32 (inst.instruction);
6586 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6587 inst.instruction |= inst.operands[0].reg << r0off;
6588 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6589 }
6590 else if (inst.size_req == 4
6591 || inst.operands[1].shifted
6592 || (inst.instruction == T_MNEM_movs
6593 && (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)))
6594 {
6595 inst.instruction = THUMB_OP32 (inst.instruction);
6596 inst.instruction |= inst.operands[0].reg << r0off;
6597 encode_thumb32_shifted_operand (1);
6598 }
6599 else
6600 switch (inst.instruction)
6601 {
6602 case T_MNEM_mov:
6603 inst.instruction = T_OPCODE_MOV_HR;
6604 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6605 inst.instruction |= (inst.operands[0].reg & 0x7);
6606 inst.instruction |= inst.operands[1].reg << 3;
6607 break;
b99bd4ef 6608
c19d1205
ZW
6609 case T_MNEM_movs:
6610 /* We know we have low registers at this point.
6611 Generate ADD Rd, Rs, #0. */
6612 inst.instruction = T_OPCODE_ADD_I3;
6613 inst.instruction |= inst.operands[0].reg;
6614 inst.instruction |= inst.operands[1].reg << 3;
6615 break;
6616
6617 case T_MNEM_cmp:
6618 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7)
6619 {
6620 inst.instruction = T_OPCODE_CMP_LR;
6621 inst.instruction |= inst.operands[0].reg;
6622 inst.instruction |= inst.operands[1].reg << 3;
6623 }
6624 else
6625 {
6626 inst.instruction = T_OPCODE_CMP_HR;
6627 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6628 inst.instruction |= (inst.operands[0].reg & 0x7);
6629 inst.instruction |= inst.operands[1].reg << 3;
6630 }
6631 break;
6632 }
b99bd4ef
NC
6633 return;
6634 }
6635
c19d1205
ZW
6636 inst.instruction = THUMB_OP16 (inst.instruction);
6637 if (inst.operands[1].isreg)
b99bd4ef 6638 {
c19d1205 6639 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 6640 {
c19d1205
ZW
6641 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
6642 since a MOV instruction produces unpredictable results. */
6643 if (inst.instruction == T_OPCODE_MOV_I8)
6644 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 6645 else
c19d1205 6646 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 6647
c19d1205
ZW
6648 inst.instruction |= inst.operands[0].reg;
6649 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
6650 }
6651 else
6652 {
c19d1205
ZW
6653 if (inst.instruction == T_OPCODE_MOV_I8)
6654 inst.instruction = T_OPCODE_MOV_HR;
6655 else
6656 inst.instruction = T_OPCODE_CMP_HR;
6657 do_t_cpy ();
b99bd4ef
NC
6658 }
6659 }
c19d1205 6660 else
b99bd4ef 6661 {
c19d1205
ZW
6662 constraint (inst.operands[0].reg > 7,
6663 _("only lo regs allowed with immediate"));
6664 inst.instruction |= inst.operands[0].reg << 8;
6665 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6666 }
6667}
b99bd4ef 6668
c19d1205
ZW
6669static void
6670do_t_mov16 (void)
6671{
6672 inst.instruction |= inst.operands[0].reg << 8;
6673 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
6674 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
6675 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
6676 inst.instruction |= (inst.operands[1].imm & 0x00ff);
6677}
b99bd4ef 6678
c19d1205
ZW
6679static void
6680do_t_mvn_tst (void)
6681{
6682 if (unified_syntax)
6683 {
6684 int r0off = (inst.instruction == T_MNEM_mvn
6685 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
6686 if (!inst.operands[1].isreg)
b99bd4ef 6687 {
c19d1205
ZW
6688 /* For an immediate, we always generate a 32-bit opcode;
6689 section relaxation will shrink it later if possible. */
6690 if (inst.instruction < 0xffff)
6691 inst.instruction = THUMB_OP32 (inst.instruction);
6692 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6693 inst.instruction |= inst.operands[0].reg << r0off;
6694 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6695 }
c19d1205 6696 else
b99bd4ef 6697 {
c19d1205
ZW
6698 /* See if we can do this with a 16-bit instruction. */
6699 if (inst.instruction < 0xffff
6700 && THUMB_SETS_FLAGS (inst.instruction)
6701 && !inst.operands[1].shifted
6702 && inst.operands[0].reg <= 7
6703 && inst.operands[1].reg <= 7
6704 && inst.size_req != 4)
b99bd4ef 6705 {
c19d1205
ZW
6706 inst.instruction = THUMB_OP16 (inst.instruction);
6707 inst.instruction |= inst.operands[0].reg;
6708 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6709 }
c19d1205 6710 else
b99bd4ef 6711 {
c19d1205
ZW
6712 constraint (inst.operands[1].shifted
6713 && inst.operands[1].immisreg,
6714 _("shift must be constant"));
6715 if (inst.instruction < 0xffff)
6716 inst.instruction = THUMB_OP32 (inst.instruction);
6717 inst.instruction |= inst.operands[0].reg << r0off;
6718 encode_thumb32_shifted_operand (1);
b99bd4ef 6719 }
b99bd4ef
NC
6720 }
6721 }
6722 else
6723 {
c19d1205
ZW
6724 constraint (inst.instruction > 0xffff
6725 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
6726 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
6727 _("unshifted register required"));
6728 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6729 BAD_HIREG);
b99bd4ef 6730
c19d1205
ZW
6731 inst.instruction = THUMB_OP16 (inst.instruction);
6732 inst.instruction |= inst.operands[0].reg;
6733 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6734 }
b99bd4ef
NC
6735}
6736
b05fe5cf 6737static void
c19d1205 6738do_t_mrs (void)
b05fe5cf 6739{
c19d1205
ZW
6740 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
6741 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
6742 != (PSR_c|PSR_f),
6743 _("'CPSR' or 'SPSR' expected"));
6744 inst.instruction |= inst.operands[0].reg << 8;
6745 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
6746}
b05fe5cf 6747
c19d1205
ZW
6748static void
6749do_t_msr (void)
6750{
6751 constraint (!inst.operands[1].isreg,
6752 _("Thumb encoding does not support an immediate here"));
6753 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
6754 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
6755 inst.instruction |= inst.operands[1].reg << 16;
6756}
b05fe5cf 6757
c19d1205
ZW
6758static void
6759do_t_mul (void)
6760{
6761 if (!inst.operands[2].present)
6762 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 6763
c19d1205
ZW
6764 /* There is no 32-bit MULS and no 16-bit MUL. */
6765 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 6766 {
c19d1205
ZW
6767 inst.instruction = THUMB_OP32 (inst.instruction);
6768 inst.instruction |= inst.operands[0].reg << 8;
6769 inst.instruction |= inst.operands[1].reg << 16;
6770 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 6771 }
c19d1205 6772 else
b05fe5cf 6773 {
c19d1205
ZW
6774 constraint (!unified_syntax
6775 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
6776 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6777 BAD_HIREG);
b05fe5cf 6778
c19d1205
ZW
6779 inst.instruction = THUMB_OP16 (inst.instruction);
6780 inst.instruction |= inst.operands[0].reg;
b05fe5cf 6781
c19d1205
ZW
6782 if (inst.operands[0].reg == inst.operands[1].reg)
6783 inst.instruction |= inst.operands[2].reg << 3;
6784 else if (inst.operands[0].reg == inst.operands[2].reg)
6785 inst.instruction |= inst.operands[1].reg << 3;
6786 else
6787 constraint (1, _("dest must overlap one source register"));
6788 }
6789}
b05fe5cf 6790
c19d1205
ZW
6791static void
6792do_t_mull (void)
6793{
6794 inst.instruction |= inst.operands[0].reg << 12;
6795 inst.instruction |= inst.operands[1].reg << 8;
6796 inst.instruction |= inst.operands[2].reg << 16;
6797 inst.instruction |= inst.operands[3].reg;
b05fe5cf 6798
c19d1205
ZW
6799 if (inst.operands[0].reg == inst.operands[1].reg)
6800 as_tsktsk (_("rdhi and rdlo must be different"));
6801}
b05fe5cf 6802
c19d1205
ZW
6803static void
6804do_t_nop (void)
6805{
6806 if (unified_syntax)
6807 {
6808 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 6809 {
c19d1205
ZW
6810 inst.instruction = THUMB_OP32 (inst.instruction);
6811 inst.instruction |= inst.operands[0].imm;
6812 }
6813 else
6814 {
6815 inst.instruction = THUMB_OP16 (inst.instruction);
6816 inst.instruction |= inst.operands[0].imm << 4;
6817 }
6818 }
6819 else
6820 {
6821 constraint (inst.operands[0].present,
6822 _("Thumb does not support NOP with hints"));
6823 inst.instruction = 0x46c0;
6824 }
6825}
b05fe5cf 6826
c19d1205
ZW
6827static void
6828do_t_neg (void)
6829{
6830 if (unified_syntax)
6831 {
6832 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7
6833 || !THUMB_SETS_FLAGS (inst.instruction)
6834 || inst.size_req == 4)
6835 {
6836 inst.instruction = THUMB_OP32 (inst.instruction);
6837 inst.instruction |= inst.operands[0].reg << 8;
6838 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
6839 }
6840 else
6841 {
c19d1205
ZW
6842 inst.instruction = THUMB_OP16 (inst.instruction);
6843 inst.instruction |= inst.operands[0].reg;
6844 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
6845 }
6846 }
6847 else
6848 {
c19d1205
ZW
6849 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6850 BAD_HIREG);
6851 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6852
6853 inst.instruction = THUMB_OP16 (inst.instruction);
6854 inst.instruction |= inst.operands[0].reg;
6855 inst.instruction |= inst.operands[1].reg << 3;
6856 }
6857}
6858
6859static void
6860do_t_pkhbt (void)
6861{
6862 inst.instruction |= inst.operands[0].reg << 8;
6863 inst.instruction |= inst.operands[1].reg << 16;
6864 inst.instruction |= inst.operands[2].reg;
6865 if (inst.operands[3].present)
6866 {
6867 unsigned int val = inst.reloc.exp.X_add_number;
6868 constraint (inst.reloc.exp.X_op != O_constant,
6869 _("expression too complex"));
6870 inst.instruction |= (val & 0x1c) << 10;
6871 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 6872 }
c19d1205 6873}
b05fe5cf 6874
c19d1205
ZW
6875static void
6876do_t_pkhtb (void)
6877{
6878 if (!inst.operands[3].present)
6879 inst.instruction &= ~0x00000020;
6880 do_t_pkhbt ();
b05fe5cf
ZW
6881}
6882
c19d1205
ZW
6883static void
6884do_t_pld (void)
6885{
6886 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
6887}
b05fe5cf 6888
c19d1205
ZW
6889static void
6890do_t_push_pop (void)
b99bd4ef 6891{
c19d1205
ZW
6892 constraint (inst.operands[0].writeback,
6893 _("push/pop do not support {reglist}^"));
6894 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6895 _("expression too complex"));
b99bd4ef 6896
c19d1205
ZW
6897 if ((inst.operands[0].imm & ~0xff) == 0)
6898 inst.instruction = THUMB_OP16 (inst.instruction);
6899 else if ((inst.instruction == T_MNEM_push
6900 && (inst.operands[0].imm & ~0xff) == 1 << REG_LR)
6901 || (inst.instruction == T_MNEM_pop
6902 && (inst.operands[0].imm & ~0xff) == 1 << REG_PC))
b99bd4ef 6903 {
c19d1205
ZW
6904 inst.instruction = THUMB_OP16 (inst.instruction);
6905 inst.instruction |= THUMB_PP_PC_LR;
6906 inst.operands[0].imm &= 0xff;
6907 }
6908 else if (unified_syntax)
6909 {
6910 if (inst.operands[1].imm & (1 << 13))
6911 as_warn (_("SP should not be in register list"));
6912 if (inst.instruction == T_MNEM_push)
b99bd4ef 6913 {
c19d1205
ZW
6914 if (inst.operands[1].imm & (1 << 15))
6915 as_warn (_("PC should not be in register list"));
6916 }
6917 else
6918 {
6919 if (inst.operands[1].imm & (1 << 14)
6920 && inst.operands[1].imm & (1 << 15))
6921 as_warn (_("LR and PC should not both be in register list"));
6922 }
b99bd4ef 6923
c19d1205
ZW
6924 inst.instruction = THUMB_OP32 (inst.instruction);
6925 }
6926 else
6927 {
6928 inst.error = _("invalid register list to push/pop instruction");
6929 return;
6930 }
b99bd4ef 6931
c19d1205
ZW
6932 inst.instruction |= inst.operands[0].imm;
6933}
b99bd4ef 6934
c19d1205
ZW
6935static void
6936do_t_rbit (void)
6937{
6938 inst.instruction |= inst.operands[0].reg << 8;
6939 inst.instruction |= inst.operands[1].reg << 16;
6940}
b99bd4ef 6941
c19d1205
ZW
6942static void
6943do_t_rev (void)
6944{
6945 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
6946 && inst.size_req != 4)
6947 {
6948 inst.instruction = THUMB_OP16 (inst.instruction);
6949 inst.instruction |= inst.operands[0].reg;
6950 inst.instruction |= inst.operands[1].reg << 3;
6951 }
6952 else if (unified_syntax)
6953 {
6954 inst.instruction = THUMB_OP32 (inst.instruction);
6955 inst.instruction |= inst.operands[0].reg << 8;
6956 inst.instruction |= inst.operands[1].reg << 16;
6957 inst.instruction |= inst.operands[1].reg;
6958 }
6959 else
6960 inst.error = BAD_HIREG;
6961}
b99bd4ef 6962
c19d1205
ZW
6963static void
6964do_t_rsb (void)
6965{
6966 int Rd, Rs;
b99bd4ef 6967
c19d1205
ZW
6968 Rd = inst.operands[0].reg;
6969 Rs = (inst.operands[1].present
6970 ? inst.operands[1].reg /* Rd, Rs, foo */
6971 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 6972
c19d1205
ZW
6973 inst.instruction |= Rd << 8;
6974 inst.instruction |= Rs << 16;
6975 if (!inst.operands[2].isreg)
6976 {
6977 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6978 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6979 }
6980 else
6981 encode_thumb32_shifted_operand (2);
6982}
b99bd4ef 6983
c19d1205
ZW
6984static void
6985do_t_setend (void)
6986{
6987 if (inst.operands[0].imm)
6988 inst.instruction |= 0x8;
6989}
b99bd4ef 6990
c19d1205
ZW
6991static void
6992do_t_shift (void)
6993{
6994 if (!inst.operands[1].present)
6995 inst.operands[1].reg = inst.operands[0].reg;
6996
6997 if (unified_syntax)
6998 {
6999 if (inst.operands[0].reg > 7
7000 || inst.operands[1].reg > 7
7001 || !THUMB_SETS_FLAGS (inst.instruction)
7002 || (!inst.operands[2].isreg && inst.instruction == T_MNEM_rors)
7003 || (inst.operands[2].isreg && inst.operands[1].reg != inst.operands[0].reg)
7004 || inst.size_req == 4)
7005 {
7006 if (inst.operands[2].isreg)
b99bd4ef 7007 {
c19d1205
ZW
7008 inst.instruction = THUMB_OP32 (inst.instruction);
7009 inst.instruction |= inst.operands[0].reg << 8;
7010 inst.instruction |= inst.operands[1].reg << 16;
7011 inst.instruction |= inst.operands[2].reg;
7012 }
7013 else
7014 {
7015 inst.operands[1].shifted = 1;
7016 switch (inst.instruction)
7017 {
7018 case T_MNEM_asr:
7019 case T_MNEM_asrs: inst.operands[1].shift_kind = SHIFT_ASR; break;
7020 case T_MNEM_lsl:
7021 case T_MNEM_lsls: inst.operands[1].shift_kind = SHIFT_LSL; break;
7022 case T_MNEM_lsr:
7023 case T_MNEM_lsrs: inst.operands[1].shift_kind = SHIFT_LSR; break;
7024 case T_MNEM_ror:
7025 case T_MNEM_rors: inst.operands[1].shift_kind = SHIFT_ROR; break;
7026 default: abort ();
7027 }
7028
7029 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7030 ? T_MNEM_movs : T_MNEM_mov);
7031 inst.instruction |= inst.operands[0].reg << 8;
7032 encode_thumb32_shifted_operand (1);
7033 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7034 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7035 }
7036 }
7037 else
7038 {
c19d1205 7039 if (inst.operands[2].isreg)
b99bd4ef 7040 {
c19d1205 7041 switch (inst.instruction)
b99bd4ef 7042 {
c19d1205
ZW
7043 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_R; break;
7044 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_R; break;
7045 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_R; break;
7046 case T_MNEM_rors: inst.instruction = T_OPCODE_ROR_R; break;
7047 default: abort ();
b99bd4ef 7048 }
c19d1205
ZW
7049
7050 inst.instruction |= inst.operands[0].reg;
7051 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7052 }
7053 else
7054 {
c19d1205 7055 switch (inst.instruction)
b99bd4ef 7056 {
c19d1205
ZW
7057 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_I; break;
7058 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_I; break;
7059 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_I; break;
7060 default: abort ();
b99bd4ef 7061 }
c19d1205
ZW
7062 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7063 inst.instruction |= inst.operands[0].reg;
7064 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7065 }
7066 }
c19d1205
ZW
7067 }
7068 else
7069 {
7070 constraint (inst.operands[0].reg > 7
7071 || inst.operands[1].reg > 7, BAD_HIREG);
7072 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7073
c19d1205
ZW
7074 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7075 {
7076 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7077 constraint (inst.operands[0].reg != inst.operands[1].reg,
7078 _("source1 and dest must be same register"));
b99bd4ef 7079
c19d1205
ZW
7080 switch (inst.instruction)
7081 {
7082 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7083 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7084 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7085 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7086 default: abort ();
7087 }
7088
7089 inst.instruction |= inst.operands[0].reg;
7090 inst.instruction |= inst.operands[2].reg << 3;
7091 }
7092 else
b99bd4ef 7093 {
c19d1205
ZW
7094 switch (inst.instruction)
7095 {
7096 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7097 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7098 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7099 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7100 default: abort ();
7101 }
7102 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7103 inst.instruction |= inst.operands[0].reg;
7104 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7105 }
7106 }
b99bd4ef
NC
7107}
7108
7109static void
c19d1205 7110do_t_simd (void)
b99bd4ef 7111{
c19d1205
ZW
7112 inst.instruction |= inst.operands[0].reg << 8;
7113 inst.instruction |= inst.operands[1].reg << 16;
7114 inst.instruction |= inst.operands[2].reg;
7115}
b99bd4ef 7116
c19d1205
ZW
7117static void
7118do_t_smi (void)
7119{
7120 unsigned int value = inst.reloc.exp.X_add_number;
7121 constraint (inst.reloc.exp.X_op != O_constant,
7122 _("expression too complex"));
7123 inst.reloc.type = BFD_RELOC_UNUSED;
7124 inst.instruction |= (value & 0xf000) >> 12;
7125 inst.instruction |= (value & 0x0ff0);
7126 inst.instruction |= (value & 0x000f) << 16;
7127}
b99bd4ef 7128
c19d1205
ZW
7129static void
7130do_t_ssat (void)
7131{
7132 inst.instruction |= inst.operands[0].reg << 8;
7133 inst.instruction |= inst.operands[1].imm - 1;
7134 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7135
c19d1205 7136 if (inst.operands[3].present)
b99bd4ef 7137 {
c19d1205
ZW
7138 constraint (inst.reloc.exp.X_op != O_constant,
7139 _("expression too complex"));
b99bd4ef 7140
c19d1205 7141 if (inst.reloc.exp.X_add_number != 0)
6189168b 7142 {
c19d1205
ZW
7143 if (inst.operands[3].shift_kind == SHIFT_ASR)
7144 inst.instruction |= 0x00200000; /* sh bit */
7145 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7146 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7147 }
c19d1205 7148 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7149 }
b99bd4ef
NC
7150}
7151
0dd132b6 7152static void
c19d1205 7153do_t_ssat16 (void)
0dd132b6 7154{
c19d1205
ZW
7155 inst.instruction |= inst.operands[0].reg << 8;
7156 inst.instruction |= inst.operands[1].imm - 1;
7157 inst.instruction |= inst.operands[2].reg << 16;
7158}
0dd132b6 7159
c19d1205
ZW
7160static void
7161do_t_strex (void)
7162{
7163 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7164 || inst.operands[2].postind || inst.operands[2].writeback
7165 || inst.operands[2].immisreg || inst.operands[2].shifted
7166 || inst.operands[2].negative,
7167 _("instruction does not accept this addressing mode"));
0dd132b6 7168
c19d1205
ZW
7169 inst.instruction |= inst.operands[0].reg << 8;
7170 inst.instruction |= inst.operands[1].reg << 12;
7171 inst.instruction |= inst.operands[2].reg << 16;
7172 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7173}
7174
b99bd4ef 7175static void
c19d1205 7176do_t_strexd (void)
b99bd4ef 7177{
c19d1205
ZW
7178 if (!inst.operands[2].present)
7179 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7180
c19d1205
ZW
7181 constraint (inst.operands[0].reg == inst.operands[1].reg
7182 || inst.operands[0].reg == inst.operands[2].reg
7183 || inst.operands[0].reg == inst.operands[3].reg
7184 || inst.operands[1].reg == inst.operands[2].reg,
7185 BAD_OVERLAP);
b99bd4ef 7186
c19d1205
ZW
7187 inst.instruction |= inst.operands[0].reg;
7188 inst.instruction |= inst.operands[1].reg << 12;
7189 inst.instruction |= inst.operands[2].reg << 8;
7190 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7191}
7192
7193static void
c19d1205 7194do_t_sxtah (void)
b99bd4ef 7195{
c19d1205
ZW
7196 inst.instruction |= inst.operands[0].reg << 8;
7197 inst.instruction |= inst.operands[1].reg << 16;
7198 inst.instruction |= inst.operands[2].reg;
7199 inst.instruction |= inst.operands[3].imm << 4;
7200}
b99bd4ef 7201
c19d1205
ZW
7202static void
7203do_t_sxth (void)
7204{
7205 if (inst.instruction <= 0xffff && inst.size_req != 4
7206 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7207 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7208 {
c19d1205
ZW
7209 inst.instruction = THUMB_OP16 (inst.instruction);
7210 inst.instruction |= inst.operands[0].reg;
7211 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7212 }
c19d1205 7213 else if (unified_syntax)
b99bd4ef 7214 {
c19d1205
ZW
7215 if (inst.instruction <= 0xffff)
7216 inst.instruction = THUMB_OP32 (inst.instruction);
7217 inst.instruction |= inst.operands[0].reg << 8;
7218 inst.instruction |= inst.operands[1].reg;
7219 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7220 }
c19d1205 7221 else
b99bd4ef 7222 {
c19d1205
ZW
7223 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7224 _("Thumb encoding does not support rotation"));
7225 constraint (1, BAD_HIREG);
b99bd4ef 7226 }
c19d1205 7227}
b99bd4ef 7228
c19d1205
ZW
7229static void
7230do_t_swi (void)
7231{
7232 inst.reloc.type = BFD_RELOC_ARM_SWI;
7233}
b99bd4ef 7234
c19d1205
ZW
7235static void
7236do_t_usat (void)
7237{
7238 inst.instruction |= inst.operands[0].reg << 8;
7239 inst.instruction |= inst.operands[1].imm;
7240 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7241
c19d1205 7242 if (inst.operands[3].present)
b99bd4ef 7243 {
c19d1205
ZW
7244 constraint (inst.reloc.exp.X_op != O_constant,
7245 _("expression too complex"));
7246 if (inst.reloc.exp.X_add_number != 0)
7247 {
7248 if (inst.operands[3].shift_kind == SHIFT_ASR)
7249 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7250
c19d1205
ZW
7251 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7252 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7253 }
7254 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7255 }
b99bd4ef
NC
7256}
7257
7258static void
c19d1205 7259do_t_usat16 (void)
b99bd4ef 7260{
c19d1205
ZW
7261 inst.instruction |= inst.operands[0].reg << 8;
7262 inst.instruction |= inst.operands[1].imm;
7263 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7264}
c19d1205
ZW
7265\f
7266/* Overall per-instruction processing. */
7267
7268/* We need to be able to fix up arbitrary expressions in some statements.
7269 This is so that we can handle symbols that are an arbitrary distance from
7270 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7271 which returns part of an address in a form which will be valid for
7272 a data instruction. We do this by pushing the expression into a symbol
7273 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7274
7275static void
c19d1205
ZW
7276fix_new_arm (fragS * frag,
7277 int where,
7278 short int size,
7279 expressionS * exp,
7280 int pc_rel,
7281 int reloc)
b99bd4ef 7282{
c19d1205 7283 fixS * new_fix;
b99bd4ef 7284
c19d1205 7285 switch (exp->X_op)
b99bd4ef 7286 {
c19d1205
ZW
7287 case O_constant:
7288 case O_symbol:
7289 case O_add:
7290 case O_subtract:
7291 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7292 break;
b99bd4ef 7293
c19d1205
ZW
7294 default:
7295 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7296 pc_rel, reloc);
7297 break;
b99bd4ef
NC
7298 }
7299
c19d1205
ZW
7300 /* Mark whether the fix is to a THUMB instruction, or an ARM
7301 instruction. */
adbaf948 7302 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7303}
7304
7305static void
c19d1205 7306output_inst (const char * str)
b99bd4ef 7307{
c19d1205 7308 char * to = NULL;
b99bd4ef 7309
c19d1205 7310 if (inst.error)
b99bd4ef 7311 {
c19d1205 7312 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
7313 return;
7314 }
c19d1205
ZW
7315 if (inst.size == 0)
7316 return;
b99bd4ef 7317
c19d1205
ZW
7318 to = frag_more (inst.size);
7319
7320 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 7321 {
c19d1205
ZW
7322 assert (inst.size == (2 * THUMB_SIZE));
7323 md_number_to_chars (to, inst.instruction >> 16, THUMB_SIZE);
7324 md_number_to_chars (to + THUMB_SIZE, inst.instruction, THUMB_SIZE);
b99bd4ef 7325 }
c19d1205 7326 else if (inst.size > INSN_SIZE)
b99bd4ef 7327 {
c19d1205
ZW
7328 assert (inst.size == (2 * INSN_SIZE));
7329 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7330 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 7331 }
c19d1205
ZW
7332 else
7333 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 7334
c19d1205
ZW
7335 if (inst.reloc.type != BFD_RELOC_UNUSED)
7336 fix_new_arm (frag_now, to - frag_now->fr_literal,
7337 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7338 inst.reloc.type);
b99bd4ef 7339
c19d1205
ZW
7340#ifdef OBJ_ELF
7341 dwarf2_emit_insn (inst.size);
7342#endif
7343}
b99bd4ef 7344
c19d1205
ZW
7345/* Tag values used in struct asm_opcode's tag field. */
7346enum opcode_tag
7347{
7348 OT_unconditional, /* Instruction cannot be conditionalized.
7349 The ARM condition field is still 0xE. */
7350 OT_unconditionalF, /* Instruction cannot be conditionalized
7351 and carries 0xF in its ARM condition field. */
7352 OT_csuffix, /* Instruction takes a conditional suffix. */
7353 OT_cinfix3, /* Instruction takes a conditional infix,
7354 beginning at character index 3. (In
7355 unified mode, it becomes a suffix.) */
7356 OT_csuf_or_in3, /* Instruction takes either a conditional
7357 suffix or an infix at character index 3.
7358 (In unified mode, a suffix only. */
7359 OT_odd_infix_unc, /* This is the unconditional variant of an
7360 instruction that takes a conditional infix
7361 at an unusual position. In unified mode,
7362 this variant will accept a suffix. */
7363 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7364 are the conditional variants of instructions that
7365 take conditional infixes in unusual positions.
7366 The infix appears at character index
7367 (tag - OT_odd_infix_0). These are not accepted
7368 in unified mode. */
7369};
b99bd4ef 7370
c19d1205
ZW
7371/* Subroutine of md_assemble, responsible for looking up the primary
7372 opcode from the mnemonic the user wrote. STR points to the
7373 beginning of the mnemonic.
7374
7375 This is not simply a hash table lookup, because of conditional
7376 variants. Most instructions have conditional variants, which are
7377 expressed with a _conditional affix_ to the mnemonic. If we were
7378 to encode each conditional variant as a literal string in the opcode
7379 table, it would have approximately 20,000 entries.
7380
7381 Most mnemonics take this affix as a suffix, and in unified syntax,
7382 'most' is upgraded to 'all'. However, in the divided syntax, some
7383 instructions take the affix as an infix, notably the s-variants of
7384 the arithmetic instructions. Of those instructions, all but six
7385 have the infix appear after the third character of the mnemonic.
7386
7387 Accordingly, the algorithm for looking up primary opcodes given
7388 an identifier is:
7389
7390 1. Look up the identifier in the opcode table.
7391 If we find a match, go to step U.
7392
7393 2. Look up the last two characters of the identifier in the
7394 conditions table. If we find a match, look up the first N-2
7395 characters of the identifier in the opcode table. If we
7396 find a match, go to step CE.
7397
7398 3. Look up the fourth and fifth characters of the identifier in
7399 the conditions table. If we find a match, extract those
7400 characters from the identifier, and look up the remaining
7401 characters in the opcode table. If we find a match, go
7402 to step CM.
7403
7404 4. Fail.
7405
7406 U. Examine the tag field of the opcode structure, in case this is
7407 one of the six instructions with its conditional infix in an
7408 unusual place. If it is, the tag tells us where to find the
7409 infix; look it up in the conditions table and set inst.cond
7410 accordingly. Otherwise, this is an unconditional instruction.
7411 Again set inst.cond accordingly. Return the opcode structure.
7412
7413 CE. Examine the tag field to make sure this is an instruction that
7414 should receive a conditional suffix. If it is not, fail.
7415 Otherwise, set inst.cond from the suffix we already looked up,
7416 and return the opcode structure.
7417
7418 CM. Examine the tag field to make sure this is an instruction that
7419 should receive a conditional infix after the third character.
7420 If it is not, fail. Otherwise, undo the edits to the current
7421 line of input and proceed as for case CE. */
7422
7423static const struct asm_opcode *
7424opcode_lookup (char **str)
7425{
7426 char *end, *base;
7427 char *affix;
7428 const struct asm_opcode *opcode;
7429 const struct asm_cond *cond;
7430
7431 /* Scan up to the end of the mnemonic, which must end in white space,
7432 '.' (in unified mode only), or end of string. */
7433 for (base = end = *str; *end != '\0'; end++)
7434 if (*end == ' ' || (unified_syntax && *end == '.'))
7435 break;
b99bd4ef 7436
c19d1205
ZW
7437 if (end == base)
7438 return 0;
b99bd4ef 7439
c19d1205
ZW
7440 /* Handle a possible width suffix. */
7441 if (end[0] == '.')
b99bd4ef 7442 {
c19d1205
ZW
7443 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7444 inst.size_req = 4;
7445 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7446 inst.size_req = 2;
7447 else
7448 return 0;
b99bd4ef 7449
c19d1205 7450 *str = end + 2;
b99bd4ef 7451 }
c19d1205
ZW
7452 else
7453 *str = end;
b99bd4ef 7454
c19d1205
ZW
7455 /* Look for unaffixed or special-case affixed mnemonic. */
7456 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7457 if (opcode)
b99bd4ef 7458 {
c19d1205
ZW
7459 /* step U */
7460 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 7461 {
c19d1205
ZW
7462 inst.cond = COND_ALWAYS;
7463 return opcode;
b99bd4ef 7464 }
b99bd4ef 7465
c19d1205
ZW
7466 if (unified_syntax)
7467 as_warn (_("conditional infixes are deprecated in unified syntax"));
7468 affix = base + (opcode->tag - OT_odd_infix_0);
7469 cond = hash_find_n (arm_cond_hsh, affix, 2);
7470 assert (cond);
b99bd4ef 7471
c19d1205
ZW
7472 inst.cond = cond->value;
7473 return opcode;
7474 }
b99bd4ef 7475
c19d1205
ZW
7476 /* Cannot have a conditional suffix on a mnemonic of less than two
7477 characters. */
7478 if (end - base < 3)
7479 return 0;
b99bd4ef 7480
c19d1205
ZW
7481 /* Look for suffixed mnemonic. */
7482 affix = end - 2;
7483 cond = hash_find_n (arm_cond_hsh, affix, 2);
7484 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7485 if (opcode && cond)
7486 {
7487 /* step CE */
7488 switch (opcode->tag)
7489 {
7490 case OT_cinfix3:
7491 case OT_odd_infix_unc:
7492 if (!unified_syntax)
7493 return 0;
7494 /* else fall through */
7495
7496 case OT_csuffix:
7497 case OT_csuf_or_in3:
7498 inst.cond = cond->value;
7499 return opcode;
7500
7501 case OT_unconditional:
7502 case OT_unconditionalF:
7503 /* delayed diagnostic */
7504 inst.error = BAD_COND;
7505 inst.cond = COND_ALWAYS;
7506 return opcode;
b99bd4ef 7507
c19d1205
ZW
7508 default:
7509 return 0;
7510 }
7511 }
b99bd4ef 7512
c19d1205
ZW
7513 /* Cannot have a usual-position infix on a mnemonic of less than
7514 six characters (five would be a suffix). */
7515 if (end - base < 6)
7516 return 0;
b99bd4ef 7517
c19d1205
ZW
7518 /* Look for infixed mnemonic in the usual position. */
7519 affix = base + 3;
7520 cond = hash_find_n (arm_cond_hsh, affix, 2);
7521 if (cond)
b99bd4ef 7522 {
c19d1205
ZW
7523 char save[2];
7524 memcpy (save, affix, 2);
7525 memmove (affix, affix + 2, (end - affix) - 2);
7526 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
7527 memmove (affix + 2, affix, (end - affix) - 2);
7528 memcpy (affix, save, 2);
b99bd4ef 7529 }
c19d1205 7530 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3))
b99bd4ef 7531 {
c19d1205
ZW
7532 /* step CM */
7533 if (unified_syntax)
7534 as_warn (_("conditional infixes are deprecated in unified syntax"));
7535
7536 inst.cond = cond->value;
7537 return opcode;
b99bd4ef
NC
7538 }
7539
c19d1205 7540 return 0;
b99bd4ef
NC
7541}
7542
c19d1205
ZW
7543void
7544md_assemble (char *str)
b99bd4ef 7545{
c19d1205
ZW
7546 char *p = str;
7547 const struct asm_opcode * opcode;
b99bd4ef 7548
c19d1205
ZW
7549 /* Align the previous label if needed. */
7550 if (last_label_seen != NULL)
b99bd4ef 7551 {
c19d1205
ZW
7552 symbol_set_frag (last_label_seen, frag_now);
7553 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
7554 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
7555 }
7556
c19d1205
ZW
7557 memset (&inst, '\0', sizeof (inst));
7558 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7559
c19d1205
ZW
7560 opcode = opcode_lookup (&p);
7561 if (!opcode)
b99bd4ef 7562 {
c19d1205
ZW
7563 /* It wasn't an instruction, but it might be a register alias of
7564 the form alias .req reg. */
7565 if (!create_register_alias (str, p))
7566 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 7567
b99bd4ef
NC
7568 return;
7569 }
7570
c19d1205 7571 if (thumb_mode)
b99bd4ef 7572 {
c19d1205
ZW
7573 /* Check that this instruction is supported for this CPU. */
7574 if (thumb_mode == 1 && (opcode->tvariant & cpu_variant) == 0)
b99bd4ef 7575 {
c19d1205 7576 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
7577 return;
7578 }
c19d1205
ZW
7579 if (inst.cond != COND_ALWAYS && !unified_syntax
7580 && opcode->tencode != do_t_branch)
b99bd4ef 7581 {
c19d1205 7582 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
7583 return;
7584 }
7585
c19d1205
ZW
7586 mapping_state (MAP_THUMB);
7587 inst.instruction = opcode->tvalue;
7588
7589 if (!parse_operands (p, opcode->operands))
7590 opcode->tencode ();
7591
7592 if (!inst.error)
b99bd4ef 7593 {
c19d1205
ZW
7594 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
7595 inst.size = (inst.instruction > 0xffff ? 4 : 2);
7596 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 7597 {
c19d1205 7598 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
7599 return;
7600 }
7601 }
c19d1205
ZW
7602 }
7603 else
7604 {
7605 /* Check that this instruction is supported for this CPU. */
7606 if ((opcode->avariant & cpu_variant) == 0)
b99bd4ef 7607 {
c19d1205
ZW
7608 as_bad (_("selected processor does not support `%s'"), str);
7609 return;
b99bd4ef 7610 }
c19d1205 7611 if (inst.size_req)
b99bd4ef 7612 {
c19d1205
ZW
7613 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
7614 return;
b99bd4ef
NC
7615 }
7616
c19d1205
ZW
7617 mapping_state (MAP_ARM);
7618 inst.instruction = opcode->avalue;
7619 if (opcode->tag == OT_unconditionalF)
7620 inst.instruction |= 0xF << 28;
7621 else
7622 inst.instruction |= inst.cond << 28;
7623 inst.size = INSN_SIZE;
7624 if (!parse_operands (p, opcode->operands))
7625 opcode->aencode ();
b99bd4ef 7626 }
c19d1205
ZW
7627 output_inst (str);
7628}
b99bd4ef 7629
c19d1205
ZW
7630/* Various frobbings of labels and their addresses. */
7631
7632void
7633arm_start_line_hook (void)
7634{
7635 last_label_seen = NULL;
b99bd4ef
NC
7636}
7637
c19d1205
ZW
7638void
7639arm_frob_label (symbolS * sym)
b99bd4ef 7640{
c19d1205 7641 last_label_seen = sym;
b99bd4ef 7642
c19d1205 7643 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 7644
c19d1205
ZW
7645#if defined OBJ_COFF || defined OBJ_ELF
7646 ARM_SET_INTERWORK (sym, support_interwork);
7647#endif
b99bd4ef 7648
c19d1205
ZW
7649 /* Note - do not allow local symbols (.Lxxx) to be labeled
7650 as Thumb functions. This is because these labels, whilst
7651 they exist inside Thumb code, are not the entry points for
7652 possible ARM->Thumb calls. Also, these labels can be used
7653 as part of a computed goto or switch statement. eg gcc
7654 can generate code that looks like this:
b99bd4ef 7655
c19d1205
ZW
7656 ldr r2, [pc, .Laaa]
7657 lsl r3, r3, #2
7658 ldr r2, [r3, r2]
7659 mov pc, r2
b99bd4ef 7660
c19d1205
ZW
7661 .Lbbb: .word .Lxxx
7662 .Lccc: .word .Lyyy
7663 ..etc...
7664 .Laaa: .word Lbbb
b99bd4ef 7665
c19d1205
ZW
7666 The first instruction loads the address of the jump table.
7667 The second instruction converts a table index into a byte offset.
7668 The third instruction gets the jump address out of the table.
7669 The fourth instruction performs the jump.
b99bd4ef 7670
c19d1205
ZW
7671 If the address stored at .Laaa is that of a symbol which has the
7672 Thumb_Func bit set, then the linker will arrange for this address
7673 to have the bottom bit set, which in turn would mean that the
7674 address computation performed by the third instruction would end
7675 up with the bottom bit set. Since the ARM is capable of unaligned
7676 word loads, the instruction would then load the incorrect address
7677 out of the jump table, and chaos would ensue. */
7678 if (label_is_thumb_function_name
7679 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
7680 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 7681 {
c19d1205
ZW
7682 /* When the address of a Thumb function is taken the bottom
7683 bit of that address should be set. This will allow
7684 interworking between Arm and Thumb functions to work
7685 correctly. */
b99bd4ef 7686
c19d1205 7687 THUMB_SET_FUNC (sym, 1);
b99bd4ef 7688
c19d1205 7689 label_is_thumb_function_name = FALSE;
b99bd4ef 7690 }
b99bd4ef
NC
7691}
7692
c19d1205
ZW
7693int
7694arm_data_in_code (void)
b99bd4ef 7695{
c19d1205 7696 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 7697 {
c19d1205
ZW
7698 *input_line_pointer = '/';
7699 input_line_pointer += 5;
7700 *input_line_pointer = 0;
7701 return 1;
b99bd4ef
NC
7702 }
7703
c19d1205 7704 return 0;
b99bd4ef
NC
7705}
7706
c19d1205
ZW
7707char *
7708arm_canonicalize_symbol_name (char * name)
b99bd4ef 7709{
c19d1205 7710 int len;
b99bd4ef 7711
c19d1205
ZW
7712 if (thumb_mode && (len = strlen (name)) > 5
7713 && streq (name + len - 5, "/data"))
7714 *(name + len - 5) = 0;
b99bd4ef 7715
c19d1205 7716 return name;
b99bd4ef 7717}
c19d1205
ZW
7718\f
7719/* Table of all register names defined by default. The user can
7720 define additional names with .req. Note that all register names
7721 should appear in both upper and lowercase variants. Some registers
7722 also have mixed-case names. */
b99bd4ef 7723
c19d1205
ZW
7724#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
7725#define REGNUM(p,n,t) REGDEF(p##n, n, t)
7726#define REGSET(p,t) \
7727 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
7728 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
7729 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
7730 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 7731
c19d1205 7732static const struct reg_entry reg_names[] =
7ed4c4c5 7733{
c19d1205
ZW
7734 /* ARM integer registers. */
7735 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 7736
c19d1205
ZW
7737 /* ATPCS synonyms. */
7738 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
7739 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
7740 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 7741
c19d1205
ZW
7742 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
7743 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
7744 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 7745
c19d1205
ZW
7746 /* Well-known aliases. */
7747 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
7748 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
7749
7750 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
7751 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
7752
7753 /* Coprocessor numbers. */
7754 REGSET(p, CP), REGSET(P, CP),
7755
7756 /* Coprocessor register numbers. The "cr" variants are for backward
7757 compatibility. */
7758 REGSET(c, CN), REGSET(C, CN),
7759 REGSET(cr, CN), REGSET(CR, CN),
7760
7761 /* FPA registers. */
7762 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
7763 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
7764
7765 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
7766 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
7767
7768 /* VFP SP registers. */
7769 REGSET(s,VFS),
7770 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
7771 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
7772 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
7773 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
7774
7775 REGSET(S,VFS),
7776 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
7777 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
7778 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
7779 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
7780
7781 /* VFP DP Registers. */
7782 REGSET(d,VFD), REGSET(D,VFS),
7783
7784 /* VFP control registers. */
7785 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
7786 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
7787
7788 /* Maverick DSP coprocessor registers. */
7789 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
7790 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
7791
7792 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
7793 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
7794 REGDEF(dspsc,0,DSPSC),
7795
7796 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
7797 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
7798 REGDEF(DSPSC,0,DSPSC),
7799
7800 /* iWMMXt data registers - p0, c0-15. */
7801 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
7802
7803 /* iWMMXt control registers - p1, c0-3. */
7804 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
7805 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
7806 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
7807 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
7808
7809 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
7810 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
7811 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
7812 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
7813 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
7814
7815 /* XScale accumulator registers. */
7816 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
7817};
7818#undef REGDEF
7819#undef REGNUM
7820#undef REGSET
7ed4c4c5 7821
c19d1205
ZW
7822/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
7823 within psr_required_here. */
7824static const struct asm_psr psrs[] =
7825{
7826 /* Backward compatibility notation. Note that "all" is no longer
7827 truly all possible PSR bits. */
7828 {"all", PSR_c | PSR_f},
7829 {"flg", PSR_f},
7830 {"ctl", PSR_c},
7831
7832 /* Individual flags. */
7833 {"f", PSR_f},
7834 {"c", PSR_c},
7835 {"x", PSR_x},
7836 {"s", PSR_s},
7837 /* Combinations of flags. */
7838 {"fs", PSR_f | PSR_s},
7839 {"fx", PSR_f | PSR_x},
7840 {"fc", PSR_f | PSR_c},
7841 {"sf", PSR_s | PSR_f},
7842 {"sx", PSR_s | PSR_x},
7843 {"sc", PSR_s | PSR_c},
7844 {"xf", PSR_x | PSR_f},
7845 {"xs", PSR_x | PSR_s},
7846 {"xc", PSR_x | PSR_c},
7847 {"cf", PSR_c | PSR_f},
7848 {"cs", PSR_c | PSR_s},
7849 {"cx", PSR_c | PSR_x},
7850 {"fsx", PSR_f | PSR_s | PSR_x},
7851 {"fsc", PSR_f | PSR_s | PSR_c},
7852 {"fxs", PSR_f | PSR_x | PSR_s},
7853 {"fxc", PSR_f | PSR_x | PSR_c},
7854 {"fcs", PSR_f | PSR_c | PSR_s},
7855 {"fcx", PSR_f | PSR_c | PSR_x},
7856 {"sfx", PSR_s | PSR_f | PSR_x},
7857 {"sfc", PSR_s | PSR_f | PSR_c},
7858 {"sxf", PSR_s | PSR_x | PSR_f},
7859 {"sxc", PSR_s | PSR_x | PSR_c},
7860 {"scf", PSR_s | PSR_c | PSR_f},
7861 {"scx", PSR_s | PSR_c | PSR_x},
7862 {"xfs", PSR_x | PSR_f | PSR_s},
7863 {"xfc", PSR_x | PSR_f | PSR_c},
7864 {"xsf", PSR_x | PSR_s | PSR_f},
7865 {"xsc", PSR_x | PSR_s | PSR_c},
7866 {"xcf", PSR_x | PSR_c | PSR_f},
7867 {"xcs", PSR_x | PSR_c | PSR_s},
7868 {"cfs", PSR_c | PSR_f | PSR_s},
7869 {"cfx", PSR_c | PSR_f | PSR_x},
7870 {"csf", PSR_c | PSR_s | PSR_f},
7871 {"csx", PSR_c | PSR_s | PSR_x},
7872 {"cxf", PSR_c | PSR_x | PSR_f},
7873 {"cxs", PSR_c | PSR_x | PSR_s},
7874 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
7875 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
7876 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
7877 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
7878 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
7879 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
7880 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
7881 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
7882 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
7883 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
7884 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
7885 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
7886 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
7887 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
7888 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
7889 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
7890 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
7891 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
7892 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
7893 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
7894 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
7895 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
7896 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
7897 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
7898};
7899
7900/* Table of all shift-in-operand names. */
7901static const struct asm_shift_name shift_names [] =
b99bd4ef 7902{
c19d1205
ZW
7903 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
7904 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
7905 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
7906 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
7907 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
7908 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
7909};
b99bd4ef 7910
c19d1205
ZW
7911/* Table of all explicit relocation names. */
7912#ifdef OBJ_ELF
7913static struct reloc_entry reloc_names[] =
7914{
7915 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
7916 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
7917 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
7918 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
7919 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
7920 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
7921 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
7922 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
7923 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
7924 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
7925 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
7926};
7927#endif
b99bd4ef 7928
c19d1205
ZW
7929/* Table of all conditional affixes. 0xF is not defined as a condition code. */
7930static const struct asm_cond conds[] =
7931{
7932 {"eq", 0x0},
7933 {"ne", 0x1},
7934 {"cs", 0x2}, {"hs", 0x2},
7935 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
7936 {"mi", 0x4},
7937 {"pl", 0x5},
7938 {"vs", 0x6},
7939 {"vc", 0x7},
7940 {"hi", 0x8},
7941 {"ls", 0x9},
7942 {"ge", 0xa},
7943 {"lt", 0xb},
7944 {"gt", 0xc},
7945 {"le", 0xd},
7946 {"al", 0xe}
7947};
bfae80f2 7948
c19d1205
ZW
7949/* Table of ARM-format instructions. */
7950
7951/* Macros for gluing together operand strings. N.B. In all cases
7952 other than OPS0, the trailing OP_stop comes from default
7953 zero-initialization of the unspecified elements of the array. */
7954#define OPS0() { OP_stop, }
7955#define OPS1(a) { OP_##a, }
7956#define OPS2(a,b) { OP_##a,OP_##b, }
7957#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
7958#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
7959#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
7960#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
7961
7962/* These macros abstract out the exact format of the mnemonic table and
7963 save some repeated characters. */
7964
7965/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
7966#define TxCE(mnem, op, top, nops, ops, ae, te) \
7967 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 7968 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7969
7970/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
7971 a T_MNEM_xyz enumerator. */
7972#define TCE(mnem, aop, top, nops, ops, ae, te) \
7973 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
7974#define tCE(mnem, aop, top, nops, ops, ae, te) \
7975 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
7976
7977/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
7978 infix after the third character. */
7979#define TxC3(mnem, op, top, nops, ops, ae, te) \
7980 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 7981 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7982#define TC3(mnem, aop, top, nops, ops, ae, te) \
7983 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
7984#define tC3(mnem, aop, top, nops, ops, ae, te) \
7985 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
7986
7987/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
7988 appear in the condition table. */
7989#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
7990 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 7991 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
7992
7993#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
7994 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
7995 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
7996 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
7997 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
7998 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
7999 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8000 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8001 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8002 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8003 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8004 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8005 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8006 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8007 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8008 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8009 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8010 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8011 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8012 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8013
8014#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8015 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8016#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8017 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8018
8019/* Mnemonic that cannot be conditionalized. The ARM condition-code
8020 field is still 0xE. */
8021#define TUE(mnem, op, top, nops, ops, ae, te) \
8022 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8023 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8024
8025/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8026 condition code field. */
8027#define TUF(mnem, op, top, nops, ops, ae, te) \
8028 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8029 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8030
8031/* ARM-only variants of all the above. */
6a86118a
NC
8032#define CE(mnem, op, nops, ops, ae) \
8033 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8034
8035#define C3(mnem, op, nops, ops, ae) \
8036 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8037
8038#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8039 { #m1 #m2 #m3, OPS##nops ops, \
8040 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8041 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8042
8043#define CM(m1, m2, op, nops, ops, ae) \
8044 xCM_(m1, , m2, op, nops, ops, ae), \
8045 xCM_(m1, eq, m2, op, nops, ops, ae), \
8046 xCM_(m1, ne, m2, op, nops, ops, ae), \
8047 xCM_(m1, cs, m2, op, nops, ops, ae), \
8048 xCM_(m1, hs, m2, op, nops, ops, ae), \
8049 xCM_(m1, cc, m2, op, nops, ops, ae), \
8050 xCM_(m1, ul, m2, op, nops, ops, ae), \
8051 xCM_(m1, lo, m2, op, nops, ops, ae), \
8052 xCM_(m1, mi, m2, op, nops, ops, ae), \
8053 xCM_(m1, pl, m2, op, nops, ops, ae), \
8054 xCM_(m1, vs, m2, op, nops, ops, ae), \
8055 xCM_(m1, vc, m2, op, nops, ops, ae), \
8056 xCM_(m1, hi, m2, op, nops, ops, ae), \
8057 xCM_(m1, ls, m2, op, nops, ops, ae), \
8058 xCM_(m1, ge, m2, op, nops, ops, ae), \
8059 xCM_(m1, lt, m2, op, nops, ops, ae), \
8060 xCM_(m1, gt, m2, op, nops, ops, ae), \
8061 xCM_(m1, le, m2, op, nops, ops, ae), \
8062 xCM_(m1, al, m2, op, nops, ops, ae)
8063
8064#define UE(mnem, op, nops, ops, ae) \
8065 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8066
8067#define UF(mnem, op, nops, ops, ae) \
8068 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8069
c19d1205
ZW
8070#define do_0 0
8071
8072/* Thumb-only, unconditional. */
8073#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8074
8075/* ARM-only, takes either a suffix or a position-3 infix
8076 (for an FPA corner case). */
8077#define C3E(mnem, op, nops, ops, ae) \
8078 { #mnem, OPS##nops ops, OT_csuf_or_in3, 0x##op, 0, ARM_VARIANT, 0, do_##ae, 0 }
bfae80f2 8079
c19d1205 8080static const struct asm_opcode insns[] =
bfae80f2 8081{
c19d1205
ZW
8082#define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8083#define THUMB_VARIANT ARM_EXT_V4T
8084 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8085 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8086 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8087 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8088 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8089 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8090 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8091 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8092 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8093 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8094 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8095 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8096 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8097 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8098 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8099 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8100
8101 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8102 for setting PSR flag bits. They are obsolete in V6 and do not
8103 have Thumb equivalents. */
8104 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8105 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8106 C3(tstp, 110f000, 2, (RR, SH), cmp),
8107 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8108 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8109 C3(cmpp, 150f000, 2, (RR, SH), cmp),
8110 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8111 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8112 C3(cmnp, 170f000, 2, (RR, SH), cmp),
8113
8114 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8115 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8116 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8117 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8118
8119 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8120 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8121 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8122 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8123
8124 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8125 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8126 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8127 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8128
8129 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
8130#ifdef TE_WINCE
8131 /* XXX This is the wrong place to do this. Think multi-arch. */
8132 TCE(b, a000000, e7fe, 1, (EXPr), branch, t_branch),
8133 TCE(bl, b000000, f7fffffe, 1, (EXPr), branch, t_branch23),
8134#else
8135 TCE(b, afffffe, e7fe, 1, (EXPr), branch, t_branch),
8136 TCE(bl, bfffffe, f7fffffe, 1, (EXPr), branch, t_branch23),
8137#endif
bfae80f2 8138
c19d1205
ZW
8139 /* Pseudo ops. */
8140 TCE(adr, 28f0000, 000f, 2, (RR, EXP), adr, t_adr),
8141 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8142 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
8143
8144 /* Thumb-compatibility pseudo ops. */
8145 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8146 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8147 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8148 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8149 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
8150 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
8151 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8152 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8153 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8154 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8155 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8156 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8157
8158#undef THUMB_VARIANT
8159#define THUMB_VARIANT ARM_EXT_V6
8160 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
8161
8162 /* V1 instructions with no Thumb analogue prior to V6T2. */
8163#undef THUMB_VARIANT
8164#define THUMB_VARIANT ARM_EXT_V6T2
8165 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8166 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8167 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8168 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8169 C3(teqp, 130f000, 2, (RR, SH), cmp),
8170
8171 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8172 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8173 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8174 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8175
8176 TC3(stmdb, 9000000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8177 TC3(stmfd, 9000000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8178
8179 TC3(ldmdb, 9100000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8180 TC3(ldmea, 9100000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8181
8182 /* V1 instructions with no Thumb analogue at all. */
8183 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8184 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8185
8186 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8187 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8188 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8189 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8190 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8191 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8192 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8193 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8194
8195#undef ARM_VARIANT
8196#define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8197#undef THUMB_VARIANT
8198#define THUMB_VARIANT ARM_EXT_V4T
8199 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8200 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8201
8202#undef THUMB_VARIANT
8203#define THUMB_VARIANT ARM_EXT_V6T2
8204 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8205 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8206
8207 /* Generic coprocessor instructions. */
8208 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8209 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8210 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8211 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8212 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8213 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8214 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8215
8216#undef ARM_VARIANT
8217#define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8218 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8219 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8220
8221#undef ARM_VARIANT
8222#define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8223 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8224 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8225
8226#undef ARM_VARIANT
8227#define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8228 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8229 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8230 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8231 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8232 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8233 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8234 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8235 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8236
8237#undef ARM_VARIANT
8238#define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8239#undef THUMB_VARIANT
8240#define THUMB_VARIANT ARM_EXT_V4T
8241 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8242 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8243 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8244 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8245 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8246 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8247
8248#undef ARM_VARIANT
8249#define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8250 /* ARM Architecture 4T. */
8251 /* Note: bx (and blx) are required on V5, even if the processor does
8252 not support Thumb. */
8253 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8254
8255#undef ARM_VARIANT
8256#define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8257#undef THUMB_VARIANT
8258#define THUMB_VARIANT ARM_EXT_V5T
8259 /* Note: blx has 2 variants; the .value coded here is for
8260 BLX(2). Only this variant has conditional execution. */
8261 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8262 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8263
8264#undef THUMB_VARIANT
8265#define THUMB_VARIANT ARM_EXT_V6T2
8266 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8267 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8268 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8269 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8270 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8271 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8272 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8273 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8274
8275#undef ARM_VARIANT
8276#define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8277 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8278 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8279 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8280 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8281
8282 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8283 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8284
8285 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8286 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8287 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8288 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8289
8290 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8291 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8292 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8293 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8294
8295 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8296 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8297
8298 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8299 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8300 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8301 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8302
8303#undef ARM_VARIANT
8304#define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8305 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8306 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8307 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8308
8309 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8310 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8311
8312#undef ARM_VARIANT
8313#define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8314 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8315
8316#undef ARM_VARIANT
8317#define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8318#undef THUMB_VARIANT
8319#define THUMB_VARIANT ARM_EXT_V6
8320 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8321 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8322 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8323 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8324 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8325 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8326 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8327 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8328 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8329 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8330
8331#undef THUMB_VARIANT
8332#define THUMB_VARIANT ARM_EXT_V6T2
8333 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8334 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8335 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8336 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8337 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8338 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8339 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8340 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8341 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8342 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8343 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8344 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8345 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8346 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8347 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8348 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8349 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8350 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8351 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8352 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8353 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8354 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8355 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8356 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8357 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8358 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8359 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8360 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8361 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8362 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8363 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8364 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8365 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8366 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8367 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8368 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8369 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8370 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8371 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8372 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8373 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8374 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8375 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8376 UF(rfeib, 9900a00, 1, (RRw), rfe),
8377 UF(rfeda, 8100a00, 1, (RRw), rfe),
8378 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8379 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8380 UF(rfefa, 9900a00, 1, (RRw), rfe),
8381 UF(rfeea, 8100a00, 1, (RRw), rfe),
8382 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8383 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8384 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8385 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8386 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8387 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8388 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8389 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8390 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8391 TCE(sel, 68000b0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8392 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8393 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8394 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8395 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8396 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8397 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8398 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8399 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8400 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8401 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8402 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8403 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8404 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8405 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8406 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8407 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8408 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8409 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8410 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8411 UF(srsib, 9cd0500, 1, (I31w), srs),
8412 UF(srsda, 84d0500, 1, (I31w), srs),
8413 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8414 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8415 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8416 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8417 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8418 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8419 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8420 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8421 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8422
8423#undef ARM_VARIANT
8424#define ARM_VARIANT ARM_EXT_V6K
8425#undef THUMB_VARIANT
8426#define THUMB_VARIANT ARM_EXT_V6K
8427 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8428 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8429 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8430 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8431
8432#undef THUMB_VARIANT
8433#define THUMB_VARIANT ARM_EXT_V6T2
8434 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8435 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8436 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8437 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8438 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8439 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8440 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8441
8442#undef ARM_VARIANT
8443#define ARM_VARIANT ARM_EXT_V6Z
8444 TCE(smi, 1600070, f7f08000, 1, (EXPi), smi, t_smi),
8445
8446#undef ARM_VARIANT
8447#define ARM_VARIANT ARM_EXT_V6T2
8448 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8449 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8450 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8451 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8452
8453 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8454 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8455 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8456 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8457
8458 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8459 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8460 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8461 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8462
8463 UT(cbnz, b900, 2, (RR, EXP), t_czb),
8464 UT(cbz, b100, 2, (RR, EXP), t_czb),
8465 /* ARM does not really have an IT instruction. */
8466 TUE(it, 0, bf08, 1, (COND), it, t_it),
8467 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
8468 TUE(ite, 0, bf04, 1, (COND), it, t_it),
8469 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
8470 TUE(itet, 0, bf06, 1, (COND), it, t_it),
8471 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
8472 TUE(itee, 0, bf02, 1, (COND), it, t_it),
8473 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
8474 TUE(itett, 0, bf07, 1, (COND), it, t_it),
8475 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
8476 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
8477 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
8478 TUE(itete, 0, bf05, 1, (COND), it, t_it),
8479 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
8480 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
8481
8482#undef ARM_VARIANT
8483#define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
8484 CE(wfs, e200110, 1, (RR), rd),
8485 CE(rfs, e300110, 1, (RR), rd),
8486 CE(wfc, e400110, 1, (RR), rd),
8487 CE(rfc, e500110, 1, (RR), rd),
8488
8489 C3(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
8490 C3(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
8491 C3(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
8492 C3(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
8493
8494 C3(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
8495 C3(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
8496 C3(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
8497 C3(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
8498
8499 C3(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
8500 C3(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
8501 C3(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
8502 C3(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
8503 C3(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
8504 C3(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
8505 C3(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
8506 C3(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
8507 C3(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
8508 C3(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
8509 C3(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
8510 C3(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
8511
8512 C3(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
8513 C3(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
8514 C3(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
8515 C3(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
8516 C3(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
8517 C3(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
8518 C3(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
8519 C3(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
8520 C3(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
8521 C3(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
8522 C3(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
8523 C3(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
8524
8525 C3(abss, e208100, 2, (RF, RF_IF), rd_rm),
8526 C3(abssp, e208120, 2, (RF, RF_IF), rd_rm),
8527 C3(abssm, e208140, 2, (RF, RF_IF), rd_rm),
8528 C3(abssz, e208160, 2, (RF, RF_IF), rd_rm),
8529 C3(absd, e208180, 2, (RF, RF_IF), rd_rm),
8530 C3(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
8531 C3(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
8532 C3(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
8533 C3(abse, e288100, 2, (RF, RF_IF), rd_rm),
8534 C3(absep, e288120, 2, (RF, RF_IF), rd_rm),
8535 C3(absem, e288140, 2, (RF, RF_IF), rd_rm),
8536 C3(absez, e288160, 2, (RF, RF_IF), rd_rm),
8537
8538 C3(rnds, e308100, 2, (RF, RF_IF), rd_rm),
8539 C3(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
8540 C3(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
8541 C3(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
8542 C3(rndd, e308180, 2, (RF, RF_IF), rd_rm),
8543 C3(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
8544 C3(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
8545 C3(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
8546 C3(rnde, e388100, 2, (RF, RF_IF), rd_rm),
8547 C3(rndep, e388120, 2, (RF, RF_IF), rd_rm),
8548 C3(rndem, e388140, 2, (RF, RF_IF), rd_rm),
8549 C3(rndez, e388160, 2, (RF, RF_IF), rd_rm),
8550
8551 C3(sqts, e408100, 2, (RF, RF_IF), rd_rm),
8552 C3(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
8553 C3(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
8554 C3(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
8555 C3(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
8556 C3(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
8557 C3(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
8558 C3(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
8559 C3(sqte, e488100, 2, (RF, RF_IF), rd_rm),
8560 C3(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
8561 C3(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
8562 C3(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
8563
8564 C3(logs, e508100, 2, (RF, RF_IF), rd_rm),
8565 C3(logsp, e508120, 2, (RF, RF_IF), rd_rm),
8566 C3(logsm, e508140, 2, (RF, RF_IF), rd_rm),
8567 C3(logsz, e508160, 2, (RF, RF_IF), rd_rm),
8568 C3(logd, e508180, 2, (RF, RF_IF), rd_rm),
8569 C3(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
8570 C3(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
8571 C3(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
8572 C3(loge, e588100, 2, (RF, RF_IF), rd_rm),
8573 C3(logep, e588120, 2, (RF, RF_IF), rd_rm),
8574 C3(logem, e588140, 2, (RF, RF_IF), rd_rm),
8575 C3(logez, e588160, 2, (RF, RF_IF), rd_rm),
8576
8577 C3(lgns, e608100, 2, (RF, RF_IF), rd_rm),
8578 C3(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
8579 C3(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
8580 C3(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
8581 C3(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
8582 C3(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
8583 C3(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
8584 C3(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
8585 C3(lgne, e688100, 2, (RF, RF_IF), rd_rm),
8586 C3(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
8587 C3(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
8588 C3(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
8589
8590 C3(exps, e708100, 2, (RF, RF_IF), rd_rm),
8591 C3(expsp, e708120, 2, (RF, RF_IF), rd_rm),
8592 C3(expsm, e708140, 2, (RF, RF_IF), rd_rm),
8593 C3(expsz, e708160, 2, (RF, RF_IF), rd_rm),
8594 C3(expd, e708180, 2, (RF, RF_IF), rd_rm),
8595 C3(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
8596 C3(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
8597 C3(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
8598 C3(expe, e788100, 2, (RF, RF_IF), rd_rm),
8599 C3(expep, e788120, 2, (RF, RF_IF), rd_rm),
8600 C3(expem, e788140, 2, (RF, RF_IF), rd_rm),
8601 C3(expdz, e788160, 2, (RF, RF_IF), rd_rm),
8602
8603 C3(sins, e808100, 2, (RF, RF_IF), rd_rm),
8604 C3(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
8605 C3(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
8606 C3(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
8607 C3(sind, e808180, 2, (RF, RF_IF), rd_rm),
8608 C3(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
8609 C3(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
8610 C3(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
8611 C3(sine, e888100, 2, (RF, RF_IF), rd_rm),
8612 C3(sinep, e888120, 2, (RF, RF_IF), rd_rm),
8613 C3(sinem, e888140, 2, (RF, RF_IF), rd_rm),
8614 C3(sinez, e888160, 2, (RF, RF_IF), rd_rm),
8615
8616 C3(coss, e908100, 2, (RF, RF_IF), rd_rm),
8617 C3(cossp, e908120, 2, (RF, RF_IF), rd_rm),
8618 C3(cossm, e908140, 2, (RF, RF_IF), rd_rm),
8619 C3(cossz, e908160, 2, (RF, RF_IF), rd_rm),
8620 C3(cosd, e908180, 2, (RF, RF_IF), rd_rm),
8621 C3(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
8622 C3(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
8623 C3(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
8624 C3(cose, e988100, 2, (RF, RF_IF), rd_rm),
8625 C3(cosep, e988120, 2, (RF, RF_IF), rd_rm),
8626 C3(cosem, e988140, 2, (RF, RF_IF), rd_rm),
8627 C3(cosez, e988160, 2, (RF, RF_IF), rd_rm),
8628
8629 C3(tans, ea08100, 2, (RF, RF_IF), rd_rm),
8630 C3(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
8631 C3(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
8632 C3(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
8633 C3(tand, ea08180, 2, (RF, RF_IF), rd_rm),
8634 C3(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
8635 C3(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
8636 C3(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
8637 C3(tane, ea88100, 2, (RF, RF_IF), rd_rm),
8638 C3(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
8639 C3(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
8640 C3(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
8641
8642 C3(asns, eb08100, 2, (RF, RF_IF), rd_rm),
8643 C3(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
8644 C3(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
8645 C3(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
8646 C3(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
8647 C3(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
8648 C3(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
8649 C3(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
8650 C3(asne, eb88100, 2, (RF, RF_IF), rd_rm),
8651 C3(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
8652 C3(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
8653 C3(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
8654
8655 C3(acss, ec08100, 2, (RF, RF_IF), rd_rm),
8656 C3(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
8657 C3(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
8658 C3(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
8659 C3(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
8660 C3(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
8661 C3(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
8662 C3(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
8663 C3(acse, ec88100, 2, (RF, RF_IF), rd_rm),
8664 C3(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
8665 C3(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
8666 C3(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
8667
8668 C3(atns, ed08100, 2, (RF, RF_IF), rd_rm),
8669 C3(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
8670 C3(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
8671 C3(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
8672 C3(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
8673 C3(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
8674 C3(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
8675 C3(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
8676 C3(atne, ed88100, 2, (RF, RF_IF), rd_rm),
8677 C3(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
8678 C3(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
8679 C3(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
8680
8681 C3(urds, ee08100, 2, (RF, RF_IF), rd_rm),
8682 C3(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
8683 C3(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
8684 C3(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
8685 C3(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
8686 C3(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
8687 C3(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
8688 C3(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
8689 C3(urde, ee88100, 2, (RF, RF_IF), rd_rm),
8690 C3(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
8691 C3(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
8692 C3(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
8693
8694 C3(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
8695 C3(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
8696 C3(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
8697 C3(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
8698 C3(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
8699 C3(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
8700 C3(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
8701 C3(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
8702 C3(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
8703 C3(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
8704 C3(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
8705 C3(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
8706
8707 C3(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
8708 C3(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
8709 C3(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
8710 C3(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
8711 C3(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
8712 C3(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8713 C3(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8714 C3(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8715 C3(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
8716 C3(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
8717 C3(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
8718 C3(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
8719
8720 C3(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
8721 C3(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
8722 C3(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
8723 C3(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
8724 C3(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
8725 C3(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8726 C3(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8727 C3(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8728 C3(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
8729 C3(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
8730 C3(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
8731 C3(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
8732
8733 C3(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
8734 C3(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
8735 C3(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
8736 C3(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
8737 C3(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
8738 C3(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8739 C3(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8740 C3(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8741 C3(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
8742 C3(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
8743 C3(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
8744 C3(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
8745
8746 C3(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
8747 C3(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
8748 C3(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
8749 C3(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
8750 C3(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
8751 C3(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8752 C3(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8753 C3(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8754 C3(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
8755 C3(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
8756 C3(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
8757 C3(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
8758
8759 C3(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
8760 C3(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
8761 C3(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
8762 C3(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
8763 C3(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
8764 C3(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8765 C3(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8766 C3(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8767 C3(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
8768 C3(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
8769 C3(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
8770 C3(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
8771
8772 C3(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
8773 C3(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
8774 C3(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
8775 C3(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
8776 C3(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
8777 C3(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8778 C3(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8779 C3(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8780 C3(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
8781 C3(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
8782 C3(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
8783 C3(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
8784
8785 C3(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
8786 C3(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
8787 C3(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
8788 C3(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
8789 C3(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
8790 C3(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8791 C3(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8792 C3(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8793 C3(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
8794 C3(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
8795 C3(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
8796 C3(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
8797
8798 C3(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
8799 C3(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
8800 C3(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
8801 C3(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
8802 C3(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
8803 C3(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8804 C3(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8805 C3(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8806 C3(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
8807 C3(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
8808 C3(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
8809 C3(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
8810
8811 C3(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
8812 C3(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
8813 C3(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
8814 C3(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
8815 C3(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
8816 C3(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8817 C3(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8818 C3(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8819 C3(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
8820 C3(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
8821 C3(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
8822 C3(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
8823
8824 C3(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
8825 C3(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
8826 C3(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
8827 C3(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
8828 C3(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
8829 C3(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8830 C3(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8831 C3(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8832 C3(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
8833 C3(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
8834 C3(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
8835 C3(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
8836
8837 C3(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8838 C3(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8839 C3(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8840 C3(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8841 C3(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8842 C3(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8843 C3(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8844 C3(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8845 C3(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8846 C3(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8847 C3(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8848 C3(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8849
8850 C3(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8851 C3(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8852 C3(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8853 C3(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8854 C3(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8855 C3(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8856 C3(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8857 C3(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8858 C3(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8859 C3(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8860 C3(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8861 C3(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8862
8863 C3(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8864 C3(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8865 C3(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8866 C3(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8867 C3(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8868 C3(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8869 C3(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8870 C3(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8871 C3(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8872 C3(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8873 C3(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8874 C3(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8875
8876 CE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
8877 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8878 CE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
8879 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
8880
8881 C3(flts, e000110, 2, (RF, RR), rn_rd),
8882 C3(fltsp, e000130, 2, (RF, RR), rn_rd),
8883 C3(fltsm, e000150, 2, (RF, RR), rn_rd),
8884 C3(fltsz, e000170, 2, (RF, RR), rn_rd),
8885 C3(fltd, e000190, 2, (RF, RR), rn_rd),
8886 C3(fltdp, e0001b0, 2, (RF, RR), rn_rd),
8887 C3(fltdm, e0001d0, 2, (RF, RR), rn_rd),
8888 C3(fltdz, e0001f0, 2, (RF, RR), rn_rd),
8889 C3(flte, e080110, 2, (RF, RR), rn_rd),
8890 C3(fltep, e080130, 2, (RF, RR), rn_rd),
8891 C3(fltem, e080150, 2, (RF, RR), rn_rd),
8892 C3(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 8893
c19d1205
ZW
8894 /* The implementation of the FIX instruction is broken on some
8895 assemblers, in that it accepts a precision specifier as well as a
8896 rounding specifier, despite the fact that this is meaningless.
8897 To be more compatible, we accept it as well, though of course it
8898 does not set any bits. */
8899 CE(fix, e100110, 2, (RR, RF), rd_rm),
8900 C3(fixp, e100130, 2, (RR, RF), rd_rm),
8901 C3(fixm, e100150, 2, (RR, RF), rd_rm),
8902 C3(fixz, e100170, 2, (RR, RF), rd_rm),
8903 C3(fixsp, e100130, 2, (RR, RF), rd_rm),
8904 C3(fixsm, e100150, 2, (RR, RF), rd_rm),
8905 C3(fixsz, e100170, 2, (RR, RF), rd_rm),
8906 C3(fixdp, e100130, 2, (RR, RF), rd_rm),
8907 C3(fixdm, e100150, 2, (RR, RF), rd_rm),
8908 C3(fixdz, e100170, 2, (RR, RF), rd_rm),
8909 C3(fixep, e100130, 2, (RR, RF), rd_rm),
8910 C3(fixem, e100150, 2, (RR, RF), rd_rm),
8911 C3(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 8912
c19d1205
ZW
8913 /* Instructions that were new with the real FPA, call them V2. */
8914#undef ARM_VARIANT
8915#define ARM_VARIANT FPU_FPA_EXT_V2
8916 CE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8917 C3(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8918 C3(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8919 CE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8920 C3(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8921 C3(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8922
8923#undef ARM_VARIANT
8924#define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
8925 /* Moves and type conversions. */
8926 CE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
8927 CE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
8928 CE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
8929 CE(fmstat, ef1fa10, 0, (), noargs),
8930 CE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
8931 CE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
8932 CE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
8933 CE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
8934 CE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
8935 CE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
8936 CE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
8937 CE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
8938
8939 /* Memory operations. */
8940 CE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
8941 CE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
8942 CE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8943 CE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8944 CE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8945 CE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8946 CE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8947 CE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8948 CE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8949 CE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8950 CE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8951 CE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
8952 CE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8953 CE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
8954 CE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8955 CE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
8956 CE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
8957 CE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 8958
c19d1205
ZW
8959 /* Monadic operations. */
8960 CE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
8961 CE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
8962 CE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
8963
8964 /* Dyadic operations. */
8965 CE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8966 CE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8967 CE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8968 CE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8969 CE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8970 CE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8971 CE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8972 CE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
8973 CE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 8974
c19d1205
ZW
8975 /* Comparisons. */
8976 CE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
8977 CE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
8978 CE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
8979 CE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 8980
c19d1205
ZW
8981#undef ARM_VARIANT
8982#define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
8983 /* Moves and type conversions. */
8984 CE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
8985 CE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
8986 CE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8987 CE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
8988 CE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
8989 CE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
8990 CE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
8991 CE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
8992 CE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
8993 CE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
8994 CE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8995 CE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
8996 CE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
8997
8998 /* Memory operations. */
8999 CE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9000 CE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9001 CE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9002 CE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9003 CE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9004 CE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9005 CE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9006 CE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9007 CE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9008 CE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9009
c19d1205
ZW
9010 /* Monadic operations. */
9011 CE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9012 CE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9013 CE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9014
9015 /* Dyadic operations. */
9016 CE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9017 CE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9018 CE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9019 CE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9020 CE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9021 CE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9022 CE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9023 CE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9024 CE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9025
c19d1205
ZW
9026 /* Comparisons. */
9027 CE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9028 CE(fcmpzd, eb50b40, 1, (RVD), rd),
9029 CE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9030 CE(fcmpezd, eb50bc0, 1, (RVD), rd),
9031
9032#undef ARM_VARIANT
9033#define ARM_VARIANT FPU_VFP_EXT_V2
9034 CE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9035 CE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9036 CE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9037 CE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9038
9039#undef ARM_VARIANT
9040#define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
9041 CE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9042 CE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9043 CE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9044 CE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9045 CE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9046 CE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9047 CE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9048 CE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9049
9050#undef ARM_VARIANT
9051#define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
9052 CE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9053 CE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9054 CE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9055 CE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9056 CE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9057 CE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9058 CE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9059 CE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9060 CE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9061 CE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9062 CE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9063 CE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9064 CE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9065 CE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9066 CE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9067 CE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9068 CE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9069 CE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9070 CE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9071 CE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9072 CE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9073 CE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9074 CE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9075 CE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9076 CE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9077 CE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9078 CE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9079 CE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9080 CE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9081 CE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9082 CE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9083 CE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9084 CE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9085 CE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9086 CE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9087 CE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9088 CE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9089 CE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9090 CE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9091 CE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9092 CE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9093 CE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9094 CE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9095 CE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9096 CE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9097 CE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9098 CE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9099 CE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9100 CE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9101 CE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9102 CE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9103 CE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9104 CE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9105 CE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9106 CE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9107 CE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9108 CE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9109 CE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9110 CE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9111 CE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9112 CE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9113 CE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9114 CE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9115 CE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9116 CE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9117 CE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9118 CE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9119 CE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9120 CE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9121 CE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9122 CE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9123 CE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9124 CE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9125 CE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9126 CE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9127 CE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9128 CE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9129 CE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9130 CE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9131 CE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9132 CE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9133 CE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9134 CE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9135 CE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9136 CE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9137 CE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9138 CE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9139 CE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9140 CE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9141 CE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9142 CE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9143 CE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9144 CE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9145 CE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9146 CE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9147 CE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9148 CE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9149 CE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9150 CE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9151 CE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9152 CE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9153 CE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9154 CE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9155 CE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9156 CE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9157 CE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9158 CE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9159 CE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9160 CE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9161 CE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9162 CE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9163 CE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9164 CE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9165 CE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9166 CE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9167 CE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9168 CE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9169 CE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9170 CE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9171 CE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9172 CE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9173 CE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9174 CE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9175 CE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9176 CE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9177 CE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9178 CE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9179 CE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9180 CE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9181 CE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9182 CE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9183 CE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9184 CE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9185 CE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9186 CE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9187 CE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9188 CE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9189 CE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9190 CE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9191 CE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9192 CE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9193 CE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9194 CE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9195 CE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9196 CE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9197 CE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9198 CE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9199 CE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9200 CE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9201 CE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9202 CE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9203 CE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9204 CE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9205 CE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9206 CE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9207 CE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9208 CE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9209 CE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9210 CE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9211 CE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9212 CE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9213 CE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
9214
9215#undef ARM_VARIANT
9216#define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
9217 CE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9218 CE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9219 CE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9220 CE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9221 CE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9222 CE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9223 CE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9224 CE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9225 CE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9226 CE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9227 CE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9228 CE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9229 CE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9230 CE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9231 CE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9232 CE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9233 CE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9234 CE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9235 CE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9236 CE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9237 CE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9238 CE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9239 CE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9240 CE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9241 CE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9242 CE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9243 CE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9244 CE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9245 CE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9246 CE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9247 CE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9248 CE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9249 CE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9250 CE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9251 CE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9252 CE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9253 CE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9254 CE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9255 CE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9256 CE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9257 CE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9258 CE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9259 CE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9260 CE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9261 CE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9262 CE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9263 CE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9264 CE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9265 CE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9266 CE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9267 CE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9268 CE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9269 CE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9270 CE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9271 CE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9272 CE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9273 CE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9274 CE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9275 CE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9276 CE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9277 CE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9278 CE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9279 CE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9280 CE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9281 CE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9282 CE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9283 CE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9284 CE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9285 CE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9286 CE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9287 CE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9288 CE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9289 CE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9290 CE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9291 CE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9292 CE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9293};
9294#undef ARM_VARIANT
9295#undef THUMB_VARIANT
9296#undef TCE
9297#undef TCM
9298#undef TUE
9299#undef TUF
9300#undef TCC
9301#undef CE
9302#undef CM
9303#undef UE
9304#undef UF
9305#undef UT
9306#undef OPS0
9307#undef OPS1
9308#undef OPS2
9309#undef OPS3
9310#undef OPS4
9311#undef OPS5
9312#undef OPS6
9313#undef do_0
9314\f
9315/* MD interface: bits in the object file. */
bfae80f2 9316
c19d1205
ZW
9317/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9318 for use in the a.out file, and stores them in the array pointed to by buf.
9319 This knows about the endian-ness of the target machine and does
9320 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9321 2 (short) and 4 (long) Floating numbers are put out as a series of
9322 LITTLENUMS (shorts, here at least). */
b99bd4ef 9323
c19d1205
ZW
9324void
9325md_number_to_chars (char * buf, valueT val, int n)
9326{
9327 if (target_big_endian)
9328 number_to_chars_bigendian (buf, val, n);
9329 else
9330 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
9331}
9332
c19d1205
ZW
9333static valueT
9334md_chars_to_number (char * buf, int n)
bfae80f2 9335{
c19d1205
ZW
9336 valueT result = 0;
9337 unsigned char * where = (unsigned char *) buf;
bfae80f2 9338
c19d1205 9339 if (target_big_endian)
b99bd4ef 9340 {
c19d1205
ZW
9341 while (n--)
9342 {
9343 result <<= 8;
9344 result |= (*where++ & 255);
9345 }
b99bd4ef 9346 }
c19d1205 9347 else
b99bd4ef 9348 {
c19d1205
ZW
9349 while (n--)
9350 {
9351 result <<= 8;
9352 result |= (where[n] & 255);
9353 }
bfae80f2 9354 }
b99bd4ef 9355
c19d1205 9356 return result;
bfae80f2 9357}
b99bd4ef 9358
c19d1205 9359/* MD interface: Sections. */
b99bd4ef 9360
c19d1205
ZW
9361int
9362md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
9363 segT segtype ATTRIBUTE_UNUSED)
9364{
9365 as_fatal (_("md_estimate_size_before_relax\n"));
9366 return 1;
9367}
b99bd4ef 9368
c19d1205 9369/* Round up a section size to the appropriate boundary. */
b99bd4ef 9370
c19d1205
ZW
9371valueT
9372md_section_align (segT segment ATTRIBUTE_UNUSED,
9373 valueT size)
9374{
9375#ifdef OBJ_ELF
9376 return size;
9377#else
9378 /* Round all sects to multiple of 4. */
9379 return (size + 3) & ~3;
9380#endif
bfae80f2 9381}
b99bd4ef 9382
c19d1205
ZW
9383/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
9384 of an rs_align_code fragment. */
9385
9386void
9387arm_handle_align (fragS * fragP)
bfae80f2 9388{
c19d1205
ZW
9389 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
9390 static char const thumb_noop[2] = { 0xc0, 0x46 };
9391 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
9392 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
9393
9394 int bytes, fix, noop_size;
9395 char * p;
9396 const char * noop;
bfae80f2 9397
c19d1205 9398 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
9399 return;
9400
c19d1205
ZW
9401 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
9402 p = fragP->fr_literal + fragP->fr_fix;
9403 fix = 0;
bfae80f2 9404
c19d1205
ZW
9405 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
9406 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 9407
c19d1205 9408 if (fragP->tc_frag_data)
a737bd4d 9409 {
c19d1205
ZW
9410 if (target_big_endian)
9411 noop = thumb_bigend_noop;
9412 else
9413 noop = thumb_noop;
9414 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
9415 }
9416 else
9417 {
c19d1205
ZW
9418 if (target_big_endian)
9419 noop = arm_bigend_noop;
9420 else
9421 noop = arm_noop;
9422 noop_size = sizeof (arm_noop);
7ed4c4c5 9423 }
a737bd4d 9424
c19d1205 9425 if (bytes & (noop_size - 1))
7ed4c4c5 9426 {
c19d1205
ZW
9427 fix = bytes & (noop_size - 1);
9428 memset (p, 0, fix);
9429 p += fix;
9430 bytes -= fix;
a737bd4d 9431 }
a737bd4d 9432
c19d1205 9433 while (bytes >= noop_size)
a737bd4d 9434 {
c19d1205
ZW
9435 memcpy (p, noop, noop_size);
9436 p += noop_size;
9437 bytes -= noop_size;
9438 fix += noop_size;
a737bd4d
NC
9439 }
9440
c19d1205
ZW
9441 fragP->fr_fix += fix;
9442 fragP->fr_var = noop_size;
a737bd4d
NC
9443}
9444
c19d1205
ZW
9445/* Called from md_do_align. Used to create an alignment
9446 frag in a code section. */
9447
9448void
9449arm_frag_align_code (int n, int max)
bfae80f2 9450{
c19d1205 9451 char * p;
7ed4c4c5 9452
c19d1205
ZW
9453 /* We assume that there will never be a requirement
9454 to support alignments greater than 32 bytes. */
9455 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
9456 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 9457
c19d1205
ZW
9458 p = frag_var (rs_align_code,
9459 MAX_MEM_FOR_RS_ALIGN_CODE,
9460 1,
9461 (relax_substateT) max,
9462 (symbolS *) NULL,
9463 (offsetT) n,
9464 (char *) NULL);
9465 *p = 0;
9466}
bfae80f2 9467
c19d1205 9468/* Perform target specific initialisation of a frag. */
bfae80f2 9469
c19d1205
ZW
9470void
9471arm_init_frag (fragS * fragP)
9472{
9473 /* Record whether this frag is in an ARM or a THUMB area. */
9474 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
9475}
9476
c19d1205
ZW
9477#ifdef OBJ_ELF
9478/* When we change sections we need to issue a new mapping symbol. */
9479
9480void
9481arm_elf_change_section (void)
bfae80f2 9482{
c19d1205
ZW
9483 flagword flags;
9484 segment_info_type *seginfo;
bfae80f2 9485
c19d1205
ZW
9486 /* Link an unlinked unwind index table section to the .text section. */
9487 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
9488 && elf_linked_to_section (now_seg) == NULL)
9489 elf_linked_to_section (now_seg) = text_section;
9490
9491 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
9492 return;
9493
c19d1205
ZW
9494 flags = bfd_get_section_flags (stdoutput, now_seg);
9495
9496 /* We can ignore sections that only contain debug info. */
9497 if ((flags & SEC_ALLOC) == 0)
9498 return;
bfae80f2 9499
c19d1205
ZW
9500 seginfo = seg_info (now_seg);
9501 mapstate = seginfo->tc_segment_info_data.mapstate;
9502 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
9503}
9504
c19d1205
ZW
9505int
9506arm_elf_section_type (const char * str, size_t len)
e45d0630 9507{
c19d1205
ZW
9508 if (len == 5 && strncmp (str, "exidx", 5) == 0)
9509 return SHT_ARM_EXIDX;
e45d0630 9510
c19d1205
ZW
9511 return -1;
9512}
9513\f
9514/* Code to deal with unwinding tables. */
e45d0630 9515
c19d1205 9516static void add_unwind_adjustsp (offsetT);
e45d0630 9517
c19d1205 9518/* Cenerate and deferred unwind frame offset. */
e45d0630 9519
bfae80f2 9520static void
c19d1205 9521flush_pending_unwind (void)
bfae80f2 9522{
c19d1205 9523 offsetT offset;
bfae80f2 9524
c19d1205
ZW
9525 offset = unwind.pending_offset;
9526 unwind.pending_offset = 0;
9527 if (offset != 0)
9528 add_unwind_adjustsp (offset);
bfae80f2
RE
9529}
9530
c19d1205
ZW
9531/* Add an opcode to this list for this function. Two-byte opcodes should
9532 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
9533 order. */
9534
bfae80f2 9535static void
c19d1205 9536add_unwind_opcode (valueT op, int length)
bfae80f2 9537{
c19d1205
ZW
9538 /* Add any deferred stack adjustment. */
9539 if (unwind.pending_offset)
9540 flush_pending_unwind ();
bfae80f2 9541
c19d1205 9542 unwind.sp_restored = 0;
bfae80f2 9543
c19d1205 9544 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 9545 {
c19d1205
ZW
9546 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
9547 if (unwind.opcodes)
9548 unwind.opcodes = xrealloc (unwind.opcodes,
9549 unwind.opcode_alloc);
9550 else
9551 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 9552 }
c19d1205 9553 while (length > 0)
bfae80f2 9554 {
c19d1205
ZW
9555 length--;
9556 unwind.opcodes[unwind.opcode_count] = op & 0xff;
9557 op >>= 8;
9558 unwind.opcode_count++;
bfae80f2 9559 }
bfae80f2
RE
9560}
9561
c19d1205
ZW
9562/* Add unwind opcodes to adjust the stack pointer. */
9563
bfae80f2 9564static void
c19d1205 9565add_unwind_adjustsp (offsetT offset)
bfae80f2 9566{
c19d1205 9567 valueT op;
bfae80f2 9568
c19d1205 9569 if (offset > 0x200)
bfae80f2 9570 {
c19d1205
ZW
9571 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
9572 char bytes[5];
9573 int n;
9574 valueT o;
bfae80f2 9575
c19d1205
ZW
9576 /* Long form: 0xb2, uleb128. */
9577 /* This might not fit in a word so add the individual bytes,
9578 remembering the list is built in reverse order. */
9579 o = (valueT) ((offset - 0x204) >> 2);
9580 if (o == 0)
9581 add_unwind_opcode (0, 1);
bfae80f2 9582
c19d1205
ZW
9583 /* Calculate the uleb128 encoding of the offset. */
9584 n = 0;
9585 while (o)
9586 {
9587 bytes[n] = o & 0x7f;
9588 o >>= 7;
9589 if (o)
9590 bytes[n] |= 0x80;
9591 n++;
9592 }
9593 /* Add the insn. */
9594 for (; n; n--)
9595 add_unwind_opcode (bytes[n - 1], 1);
9596 add_unwind_opcode (0xb2, 1);
9597 }
9598 else if (offset > 0x100)
bfae80f2 9599 {
c19d1205
ZW
9600 /* Two short opcodes. */
9601 add_unwind_opcode (0x3f, 1);
9602 op = (offset - 0x104) >> 2;
9603 add_unwind_opcode (op, 1);
bfae80f2 9604 }
c19d1205
ZW
9605 else if (offset > 0)
9606 {
9607 /* Short opcode. */
9608 op = (offset - 4) >> 2;
9609 add_unwind_opcode (op, 1);
9610 }
9611 else if (offset < 0)
bfae80f2 9612 {
c19d1205
ZW
9613 offset = -offset;
9614 while (offset > 0x100)
bfae80f2 9615 {
c19d1205
ZW
9616 add_unwind_opcode (0x7f, 1);
9617 offset -= 0x100;
bfae80f2 9618 }
c19d1205
ZW
9619 op = ((offset - 4) >> 2) | 0x40;
9620 add_unwind_opcode (op, 1);
bfae80f2 9621 }
bfae80f2
RE
9622}
9623
c19d1205
ZW
9624/* Finish the list of unwind opcodes for this function. */
9625static void
9626finish_unwind_opcodes (void)
bfae80f2 9627{
c19d1205 9628 valueT op;
bfae80f2 9629
c19d1205 9630 if (unwind.fp_used)
bfae80f2 9631 {
c19d1205
ZW
9632 /* Adjust sp as neccessary. */
9633 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
9634 flush_pending_unwind ();
bfae80f2 9635
c19d1205
ZW
9636 /* After restoring sp from the frame pointer. */
9637 op = 0x90 | unwind.fp_reg;
9638 add_unwind_opcode (op, 1);
9639 }
9640 else
9641 flush_pending_unwind ();
bfae80f2
RE
9642}
9643
bfae80f2 9644
c19d1205
ZW
9645/* Start an exception table entry. If idx is nonzero this is an index table
9646 entry. */
bfae80f2
RE
9647
9648static void
c19d1205 9649start_unwind_section (const segT text_seg, int idx)
bfae80f2 9650{
c19d1205
ZW
9651 const char * text_name;
9652 const char * prefix;
9653 const char * prefix_once;
9654 const char * group_name;
9655 size_t prefix_len;
9656 size_t text_len;
9657 char * sec_name;
9658 size_t sec_name_len;
9659 int type;
9660 int flags;
9661 int linkonce;
bfae80f2 9662
c19d1205 9663 if (idx)
bfae80f2 9664 {
c19d1205
ZW
9665 prefix = ELF_STRING_ARM_unwind;
9666 prefix_once = ELF_STRING_ARM_unwind_once;
9667 type = SHT_ARM_EXIDX;
bfae80f2 9668 }
c19d1205 9669 else
bfae80f2 9670 {
c19d1205
ZW
9671 prefix = ELF_STRING_ARM_unwind_info;
9672 prefix_once = ELF_STRING_ARM_unwind_info_once;
9673 type = SHT_PROGBITS;
bfae80f2
RE
9674 }
9675
c19d1205
ZW
9676 text_name = segment_name (text_seg);
9677 if (streq (text_name, ".text"))
9678 text_name = "";
9679
9680 if (strncmp (text_name, ".gnu.linkonce.t.",
9681 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 9682 {
c19d1205
ZW
9683 prefix = prefix_once;
9684 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
9685 }
9686
c19d1205
ZW
9687 prefix_len = strlen (prefix);
9688 text_len = strlen (text_name);
9689 sec_name_len = prefix_len + text_len;
9690 sec_name = xmalloc (sec_name_len + 1);
9691 memcpy (sec_name, prefix, prefix_len);
9692 memcpy (sec_name + prefix_len, text_name, text_len);
9693 sec_name[prefix_len + text_len] = '\0';
bfae80f2 9694
c19d1205
ZW
9695 flags = SHF_ALLOC;
9696 linkonce = 0;
9697 group_name = 0;
bfae80f2 9698
c19d1205
ZW
9699 /* Handle COMDAT group. */
9700 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 9701 {
c19d1205
ZW
9702 group_name = elf_group_name (text_seg);
9703 if (group_name == NULL)
9704 {
9705 as_bad ("Group section `%s' has no group signature",
9706 segment_name (text_seg));
9707 ignore_rest_of_line ();
9708 return;
9709 }
9710 flags |= SHF_GROUP;
9711 linkonce = 1;
bfae80f2
RE
9712 }
9713
c19d1205 9714 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 9715
c19d1205
ZW
9716 /* Set the setion link for index tables. */
9717 if (idx)
9718 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
9719}
9720
bfae80f2 9721
c19d1205
ZW
9722/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
9723 personality routine data. Returns zero, or the index table value for
9724 and inline entry. */
9725
9726static valueT
9727create_unwind_entry (int have_data)
bfae80f2 9728{
c19d1205
ZW
9729 int size;
9730 addressT where;
9731 char *ptr;
9732 /* The current word of data. */
9733 valueT data;
9734 /* The number of bytes left in this word. */
9735 int n;
bfae80f2 9736
c19d1205 9737 finish_unwind_opcodes ();
bfae80f2 9738
c19d1205
ZW
9739 /* Remember the current text section. */
9740 unwind.saved_seg = now_seg;
9741 unwind.saved_subseg = now_subseg;
bfae80f2 9742
c19d1205 9743 start_unwind_section (now_seg, 0);
bfae80f2 9744
c19d1205 9745 if (unwind.personality_routine == NULL)
bfae80f2 9746 {
c19d1205
ZW
9747 if (unwind.personality_index == -2)
9748 {
9749 if (have_data)
9750 as_bad (_("handerdata in cantunwind frame"));
9751 return 1; /* EXIDX_CANTUNWIND. */
9752 }
bfae80f2 9753
c19d1205
ZW
9754 /* Use a default personality routine if none is specified. */
9755 if (unwind.personality_index == -1)
9756 {
9757 if (unwind.opcode_count > 3)
9758 unwind.personality_index = 1;
9759 else
9760 unwind.personality_index = 0;
9761 }
bfae80f2 9762
c19d1205
ZW
9763 /* Space for the personality routine entry. */
9764 if (unwind.personality_index == 0)
9765 {
9766 if (unwind.opcode_count > 3)
9767 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 9768
c19d1205
ZW
9769 if (!have_data)
9770 {
9771 /* All the data is inline in the index table. */
9772 data = 0x80;
9773 n = 3;
9774 while (unwind.opcode_count > 0)
9775 {
9776 unwind.opcode_count--;
9777 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9778 n--;
9779 }
bfae80f2 9780
c19d1205
ZW
9781 /* Pad with "finish" opcodes. */
9782 while (n--)
9783 data = (data << 8) | 0xb0;
bfae80f2 9784
c19d1205
ZW
9785 return data;
9786 }
9787 size = 0;
9788 }
9789 else
9790 /* We get two opcodes "free" in the first word. */
9791 size = unwind.opcode_count - 2;
9792 }
9793 else
9794 /* An extra byte is required for the opcode count. */
9795 size = unwind.opcode_count + 1;
bfae80f2 9796
c19d1205
ZW
9797 size = (size + 3) >> 2;
9798 if (size > 0xff)
9799 as_bad (_("too many unwind opcodes"));
bfae80f2 9800
c19d1205
ZW
9801 frag_align (2, 0, 0);
9802 record_alignment (now_seg, 2);
9803 unwind.table_entry = expr_build_dot ();
9804
9805 /* Allocate the table entry. */
9806 ptr = frag_more ((size << 2) + 4);
9807 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 9808
c19d1205 9809 switch (unwind.personality_index)
bfae80f2 9810 {
c19d1205
ZW
9811 case -1:
9812 /* ??? Should this be a PLT generating relocation? */
9813 /* Custom personality routine. */
9814 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
9815 BFD_RELOC_ARM_PREL31);
bfae80f2 9816
c19d1205
ZW
9817 where += 4;
9818 ptr += 4;
bfae80f2 9819
c19d1205
ZW
9820 /* Set the first byte to the number of additional words. */
9821 data = size - 1;
9822 n = 3;
9823 break;
bfae80f2 9824
c19d1205
ZW
9825 /* ABI defined personality routines. */
9826 case 0:
9827 /* Three opcodes bytes are packed into the first word. */
9828 data = 0x80;
9829 n = 3;
9830 break;
bfae80f2 9831
c19d1205
ZW
9832 case 1:
9833 case 2:
9834 /* The size and first two opcode bytes go in the first word. */
9835 data = ((0x80 + unwind.personality_index) << 8) | size;
9836 n = 2;
9837 break;
bfae80f2 9838
c19d1205
ZW
9839 default:
9840 /* Should never happen. */
9841 abort ();
9842 }
bfae80f2 9843
c19d1205
ZW
9844 /* Pack the opcodes into words (MSB first), reversing the list at the same
9845 time. */
9846 while (unwind.opcode_count > 0)
9847 {
9848 if (n == 0)
9849 {
9850 md_number_to_chars (ptr, data, 4);
9851 ptr += 4;
9852 n = 4;
9853 data = 0;
9854 }
9855 unwind.opcode_count--;
9856 n--;
9857 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9858 }
9859
9860 /* Finish off the last word. */
9861 if (n < 4)
9862 {
9863 /* Pad with "finish" opcodes. */
9864 while (n--)
9865 data = (data << 8) | 0xb0;
9866
9867 md_number_to_chars (ptr, data, 4);
9868 }
9869
9870 if (!have_data)
9871 {
9872 /* Add an empty descriptor if there is no user-specified data. */
9873 ptr = frag_more (4);
9874 md_number_to_chars (ptr, 0, 4);
9875 }
9876
9877 return 0;
bfae80f2
RE
9878}
9879
c19d1205
ZW
9880/* Convert REGNAME to a DWARF-2 register number. */
9881
9882int
9883tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 9884{
c19d1205
ZW
9885 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
9886
9887 if (reg == FAIL)
9888 return -1;
9889
9890 return reg;
bfae80f2
RE
9891}
9892
c19d1205
ZW
9893/* Initialize the DWARF-2 unwind information for this procedure. */
9894
9895void
9896tc_arm_frame_initial_instructions (void)
bfae80f2 9897{
c19d1205 9898 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 9899}
c19d1205 9900#endif /* OBJ_ELF */
bfae80f2 9901
bfae80f2 9902
c19d1205 9903/* MD interface: Symbol and relocation handling. */
bfae80f2 9904
c19d1205
ZW
9905/* The knowledge of the PC's pipeline offset is built into the insns
9906 themselves. */
bfae80f2 9907
c19d1205
ZW
9908long
9909md_pcrel_from (fixS * fixP)
bfae80f2 9910{
c19d1205
ZW
9911 if (fixP->fx_addsy
9912 && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section
9913 && fixP->fx_subsy == NULL)
9914 return 0;
bfae80f2 9915
c19d1205
ZW
9916 /* PC relative addressing on the Thumb is slightly odd as the bottom
9917 two bits of the PC are forced to zero for the calculation. This
9918 happens *after* application of the pipeline offset. However,
9919 Thumb adrl already adjusts for this, so we need not do it again. */
9920 switch (fixP->fx_r_type)
bfae80f2 9921 {
c19d1205
ZW
9922 case BFD_RELOC_ARM_THUMB_ADD:
9923 return (fixP->fx_where + fixP->fx_frag->fr_address) & ~3;
9924
9925 case BFD_RELOC_ARM_THUMB_OFFSET:
9926 case BFD_RELOC_ARM_T32_OFFSET_IMM:
9927 return (fixP->fx_where + fixP->fx_frag->fr_address + 4) & ~3;
9928
9929 default:
9930 break;
bfae80f2
RE
9931 }
9932
c19d1205
ZW
9933#ifdef TE_WINCE
9934 /* The pattern was adjusted to accommodate CE's off-by-one fixups,
9935 so we un-adjust here to compensate for the accommodation. */
9936 return fixP->fx_where + fixP->fx_frag->fr_address + 8;
9937#else
9938 return fixP->fx_where + fixP->fx_frag->fr_address;
9939#endif
bfae80f2
RE
9940}
9941
c19d1205
ZW
9942/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
9943 Otherwise we have no need to default values of symbols. */
9944
9945symbolS *
9946md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 9947{
c19d1205
ZW
9948#ifdef OBJ_ELF
9949 if (name[0] == '_' && name[1] == 'G'
9950 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
9951 {
9952 if (!GOT_symbol)
9953 {
9954 if (symbol_find (name))
9955 as_bad ("GOT already in the symbol table");
bfae80f2 9956
c19d1205
ZW
9957 GOT_symbol = symbol_new (name, undefined_section,
9958 (valueT) 0, & zero_address_frag);
9959 }
bfae80f2 9960
c19d1205 9961 return GOT_symbol;
bfae80f2 9962 }
c19d1205 9963#endif
bfae80f2 9964
c19d1205 9965 return 0;
bfae80f2
RE
9966}
9967
55cf6793 9968/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
9969 computed as two separate immediate values, added together. We
9970 already know that this value cannot be computed by just one ARM
9971 instruction. */
9972
9973static unsigned int
9974validate_immediate_twopart (unsigned int val,
9975 unsigned int * highpart)
bfae80f2 9976{
c19d1205
ZW
9977 unsigned int a;
9978 unsigned int i;
bfae80f2 9979
c19d1205
ZW
9980 for (i = 0; i < 32; i += 2)
9981 if (((a = rotate_left (val, i)) & 0xff) != 0)
9982 {
9983 if (a & 0xff00)
9984 {
9985 if (a & ~ 0xffff)
9986 continue;
9987 * highpart = (a >> 8) | ((i + 24) << 7);
9988 }
9989 else if (a & 0xff0000)
9990 {
9991 if (a & 0xff000000)
9992 continue;
9993 * highpart = (a >> 16) | ((i + 16) << 7);
9994 }
9995 else
9996 {
9997 assert (a & 0xff000000);
9998 * highpart = (a >> 24) | ((i + 8) << 7);
9999 }
bfae80f2 10000
c19d1205
ZW
10001 return (a & 0xff) | (i << 7);
10002 }
bfae80f2 10003
c19d1205 10004 return FAIL;
bfae80f2
RE
10005}
10006
c19d1205
ZW
10007static int
10008validate_offset_imm (unsigned int val, int hwse)
10009{
10010 if ((hwse && val > 255) || val > 4095)
10011 return FAIL;
10012 return val;
10013}
bfae80f2 10014
55cf6793 10015/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
10016 negative immediate constant by altering the instruction. A bit of
10017 a hack really.
10018 MOV <-> MVN
10019 AND <-> BIC
10020 ADC <-> SBC
10021 by inverting the second operand, and
10022 ADD <-> SUB
10023 CMP <-> CMN
10024 by negating the second operand. */
bfae80f2 10025
c19d1205
ZW
10026static int
10027negate_data_op (unsigned long * instruction,
10028 unsigned long value)
bfae80f2 10029{
c19d1205
ZW
10030 int op, new_inst;
10031 unsigned long negated, inverted;
bfae80f2 10032
c19d1205
ZW
10033 negated = encode_arm_immediate (-value);
10034 inverted = encode_arm_immediate (~value);
bfae80f2 10035
c19d1205
ZW
10036 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10037 switch (op)
bfae80f2 10038 {
c19d1205
ZW
10039 /* First negates. */
10040 case OPCODE_SUB: /* ADD <-> SUB */
10041 new_inst = OPCODE_ADD;
10042 value = negated;
10043 break;
bfae80f2 10044
c19d1205
ZW
10045 case OPCODE_ADD:
10046 new_inst = OPCODE_SUB;
10047 value = negated;
10048 break;
bfae80f2 10049
c19d1205
ZW
10050 case OPCODE_CMP: /* CMP <-> CMN */
10051 new_inst = OPCODE_CMN;
10052 value = negated;
10053 break;
bfae80f2 10054
c19d1205
ZW
10055 case OPCODE_CMN:
10056 new_inst = OPCODE_CMP;
10057 value = negated;
10058 break;
bfae80f2 10059
c19d1205
ZW
10060 /* Now Inverted ops. */
10061 case OPCODE_MOV: /* MOV <-> MVN */
10062 new_inst = OPCODE_MVN;
10063 value = inverted;
10064 break;
bfae80f2 10065
c19d1205
ZW
10066 case OPCODE_MVN:
10067 new_inst = OPCODE_MOV;
10068 value = inverted;
10069 break;
bfae80f2 10070
c19d1205
ZW
10071 case OPCODE_AND: /* AND <-> BIC */
10072 new_inst = OPCODE_BIC;
10073 value = inverted;
10074 break;
bfae80f2 10075
c19d1205
ZW
10076 case OPCODE_BIC:
10077 new_inst = OPCODE_AND;
10078 value = inverted;
10079 break;
bfae80f2 10080
c19d1205
ZW
10081 case OPCODE_ADC: /* ADC <-> SBC */
10082 new_inst = OPCODE_SBC;
10083 value = inverted;
10084 break;
bfae80f2 10085
c19d1205
ZW
10086 case OPCODE_SBC:
10087 new_inst = OPCODE_ADC;
10088 value = inverted;
10089 break;
bfae80f2 10090
c19d1205
ZW
10091 /* We cannot do anything. */
10092 default:
10093 return FAIL;
b99bd4ef
NC
10094 }
10095
c19d1205
ZW
10096 if (value == (unsigned) FAIL)
10097 return FAIL;
10098
10099 *instruction &= OPCODE_MASK;
10100 *instruction |= new_inst << DATA_OP_SHIFT;
10101 return value;
b99bd4ef
NC
10102}
10103
c19d1205 10104void
55cf6793 10105md_apply_fix (fixS * fixP,
c19d1205
ZW
10106 valueT * valP,
10107 segT seg)
10108{
10109 offsetT value = * valP;
10110 offsetT newval;
10111 unsigned int newimm;
10112 unsigned long temp;
10113 int sign;
10114 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 10115
c19d1205 10116 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 10117
c19d1205
ZW
10118 /* Note whether this will delete the relocation. */
10119 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
10120 fixP->fx_done = 1;
b99bd4ef 10121
c19d1205
ZW
10122 /* If this symbol is in a different section then we need to leave it for
10123 the linker to deal with. Unfortunately, md_pcrel_from can't tell,
10124 so we have to undo its effects here. */
10125 if (fixP->fx_pcrel)
b99bd4ef 10126 {
c19d1205
ZW
10127 if (fixP->fx_addsy != NULL
10128 && S_IS_DEFINED (fixP->fx_addsy)
10129 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10130 value += md_pcrel_from (fixP);
b99bd4ef
NC
10131 }
10132
adbaf948
ZW
10133 /* On a 64-bit host, silently truncate 'value' to 32 bits for
10134 consistency with the behavior on 32-bit hosts. Remember value
10135 for emit_reloc. */
10136 value &= 0xffffffff;
10137 value ^= 0x80000000;
10138 value -= 0x80000000;
10139
10140 *valP = value;
c19d1205 10141 fixP->fx_addnumber = value;
b99bd4ef 10142
adbaf948
ZW
10143 /* Same treatment for fixP->fx_offset. */
10144 fixP->fx_offset &= 0xffffffff;
10145 fixP->fx_offset ^= 0x80000000;
10146 fixP->fx_offset -= 0x80000000;
10147
c19d1205 10148 switch (fixP->fx_r_type)
b99bd4ef 10149 {
c19d1205
ZW
10150 case BFD_RELOC_NONE:
10151 /* This will need to go in the object file. */
10152 fixP->fx_done = 0;
10153 break;
b99bd4ef 10154
c19d1205
ZW
10155 case BFD_RELOC_ARM_IMMEDIATE:
10156 /* We claim that this fixup has been processed here,
10157 even if in fact we generate an error because we do
10158 not have a reloc for it, so tc_gen_reloc will reject it. */
10159 fixP->fx_done = 1;
b99bd4ef 10160
c19d1205
ZW
10161 if (fixP->fx_addsy
10162 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 10163 {
c19d1205
ZW
10164 as_bad_where (fixP->fx_file, fixP->fx_line,
10165 _("undefined symbol %s used as an immediate value"),
10166 S_GET_NAME (fixP->fx_addsy));
10167 break;
b99bd4ef
NC
10168 }
10169
c19d1205
ZW
10170 newimm = encode_arm_immediate (value);
10171 temp = md_chars_to_number (buf, INSN_SIZE);
10172
10173 /* If the instruction will fail, see if we can fix things up by
10174 changing the opcode. */
10175 if (newimm == (unsigned int) FAIL
10176 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 10177 {
c19d1205
ZW
10178 as_bad_where (fixP->fx_file, fixP->fx_line,
10179 _("invalid constant (%lx) after fixup"),
10180 (unsigned long) value);
10181 break;
b99bd4ef 10182 }
b99bd4ef 10183
c19d1205
ZW
10184 newimm |= (temp & 0xfffff000);
10185 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
10186 break;
b99bd4ef 10187
c19d1205
ZW
10188 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
10189 {
10190 unsigned int highpart = 0;
10191 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 10192
c19d1205
ZW
10193 newimm = encode_arm_immediate (value);
10194 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 10195
c19d1205
ZW
10196 /* If the instruction will fail, see if we can fix things up by
10197 changing the opcode. */
10198 if (newimm == (unsigned int) FAIL
10199 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
10200 {
10201 /* No ? OK - try using two ADD instructions to generate
10202 the value. */
10203 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 10204
c19d1205
ZW
10205 /* Yes - then make sure that the second instruction is
10206 also an add. */
10207 if (newimm != (unsigned int) FAIL)
10208 newinsn = temp;
10209 /* Still No ? Try using a negated value. */
10210 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
10211 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
10212 /* Otherwise - give up. */
10213 else
10214 {
10215 as_bad_where (fixP->fx_file, fixP->fx_line,
10216 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
10217 (long) value);
10218 break;
10219 }
b99bd4ef 10220
c19d1205
ZW
10221 /* Replace the first operand in the 2nd instruction (which
10222 is the PC) with the destination register. We have
10223 already added in the PC in the first instruction and we
10224 do not want to do it again. */
10225 newinsn &= ~ 0xf0000;
10226 newinsn |= ((newinsn & 0x0f000) << 4);
10227 }
b99bd4ef 10228
c19d1205
ZW
10229 newimm |= (temp & 0xfffff000);
10230 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 10231
c19d1205
ZW
10232 highpart |= (newinsn & 0xfffff000);
10233 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
10234 }
10235 break;
b99bd4ef 10236
c19d1205
ZW
10237 case BFD_RELOC_ARM_OFFSET_IMM:
10238 case BFD_RELOC_ARM_LITERAL:
10239 sign = value >= 0;
b99bd4ef 10240
c19d1205
ZW
10241 if (value < 0)
10242 value = - value;
b99bd4ef 10243
c19d1205 10244 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 10245 {
c19d1205
ZW
10246 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
10247 as_bad_where (fixP->fx_file, fixP->fx_line,
10248 _("invalid literal constant: pool needs to be closer"));
10249 else
10250 as_bad_where (fixP->fx_file, fixP->fx_line,
10251 _("bad immediate value for offset (%ld)"),
10252 (long) value);
10253 break;
f03698e6
RE
10254 }
10255
c19d1205
ZW
10256 newval = md_chars_to_number (buf, INSN_SIZE);
10257 newval &= 0xff7ff000;
10258 newval |= value | (sign ? INDEX_UP : 0);
10259 md_number_to_chars (buf, newval, INSN_SIZE);
10260 break;
b99bd4ef 10261
c19d1205
ZW
10262 case BFD_RELOC_ARM_OFFSET_IMM8:
10263 case BFD_RELOC_ARM_HWLITERAL:
10264 sign = value >= 0;
b99bd4ef 10265
c19d1205
ZW
10266 if (value < 0)
10267 value = - value;
b99bd4ef 10268
c19d1205 10269 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 10270 {
c19d1205
ZW
10271 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
10272 as_bad_where (fixP->fx_file, fixP->fx_line,
10273 _("invalid literal constant: pool needs to be closer"));
10274 else
10275 as_bad (_("bad immediate value for half-word offset (%ld)"),
10276 (long) value);
10277 break;
b99bd4ef
NC
10278 }
10279
c19d1205
ZW
10280 newval = md_chars_to_number (buf, INSN_SIZE);
10281 newval &= 0xff7ff0f0;
10282 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
10283 md_number_to_chars (buf, newval, INSN_SIZE);
10284 break;
b99bd4ef 10285
c19d1205
ZW
10286 case BFD_RELOC_ARM_T32_OFFSET_U8:
10287 if (value < 0 || value > 1020 || value % 4 != 0)
10288 as_bad_where (fixP->fx_file, fixP->fx_line,
10289 _("bad immediate value for offset (%ld)"), (long) value);
10290 value /= 4;
b99bd4ef 10291
c19d1205
ZW
10292 newval = md_chars_to_number (buf+2, THUMB_SIZE);
10293 newval &= 0xff00;
10294 newval |= value;
10295 md_number_to_chars (buf+2, newval, THUMB_SIZE);
10296 break;
b99bd4ef 10297
c19d1205
ZW
10298 case BFD_RELOC_ARM_T32_OFFSET_IMM:
10299 /* This is a complicated relocation used for all varieties of Thumb32
10300 load/store instruction with immediate offset:
10301
10302 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
10303 *4, optional writeback(W)
10304 (doubleword load/store)
10305
10306 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
10307 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
10308 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
10309 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
10310 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
10311
10312 Uppercase letters indicate bits that are already encoded at
10313 this point. Lowercase letters are our problem. For the
10314 second block of instructions, the secondary opcode nybble
10315 (bits 8..11) is present, and bit 23 is zero, even if this is
10316 a PC-relative operation. */
10317 newval = md_chars_to_number (buf, THUMB_SIZE);
10318 newval <<= 16;
10319 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 10320
c19d1205 10321 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 10322 {
c19d1205
ZW
10323 /* Doubleword load/store: 8-bit offset, scaled by 4. */
10324 if (value >= 0)
10325 newval |= (1 << 23);
10326 else
10327 value = -value;
10328 if (value % 4 != 0)
10329 {
10330 as_bad_where (fixP->fx_file, fixP->fx_line,
10331 _("offset not a multiple of 4"));
10332 break;
10333 }
10334 value /= 4;
10335 if (value >= 0xff)
10336 {
10337 as_bad_where (fixP->fx_file, fixP->fx_line,
10338 _("offset out of range"));
10339 break;
10340 }
10341 newval &= ~0xff;
b99bd4ef 10342 }
c19d1205 10343 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 10344 {
c19d1205
ZW
10345 /* PC-relative, 12-bit offset. */
10346 if (value >= 0)
10347 newval |= (1 << 23);
10348 else
10349 value = -value;
10350 if (value >= 0xfff)
10351 {
10352 as_bad_where (fixP->fx_file, fixP->fx_line,
10353 _("offset out of range"));
10354 break;
10355 }
10356 newval &= ~0xfff;
b99bd4ef 10357 }
c19d1205 10358 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 10359 {
c19d1205
ZW
10360 /* Writeback: 8-bit, +/- offset. */
10361 if (value >= 0)
10362 newval |= (1 << 9);
10363 else
10364 value = -value;
10365 if (value >= 0xff)
10366 {
10367 as_bad_where (fixP->fx_file, fixP->fx_line,
10368 _("offset out of range"));
10369 break;
10370 }
10371 newval &= ~0xff;
b99bd4ef 10372 }
c19d1205 10373 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 10374 {
c19d1205
ZW
10375 /* T-instruction: positive 8-bit offset. */
10376 if (value < 0 || value >= 0xff)
b99bd4ef 10377 {
c19d1205
ZW
10378 as_bad_where (fixP->fx_file, fixP->fx_line,
10379 _("offset out of range"));
10380 break;
b99bd4ef 10381 }
c19d1205
ZW
10382 newval &= ~0xff;
10383 newval |= value;
b99bd4ef
NC
10384 }
10385 else
b99bd4ef 10386 {
c19d1205
ZW
10387 /* Positive 12-bit or negative 8-bit offset. */
10388 int limit;
10389 if (value >= 0)
b99bd4ef 10390 {
c19d1205
ZW
10391 newval |= (1 << 23);
10392 limit = 0xfff;
10393 }
10394 else
10395 {
10396 value = -value;
10397 limit = 0xff;
10398 }
10399 if (value > limit)
10400 {
10401 as_bad_where (fixP->fx_file, fixP->fx_line,
10402 _("offset out of range"));
10403 break;
b99bd4ef 10404 }
c19d1205 10405 newval &= ~limit;
b99bd4ef 10406 }
b99bd4ef 10407
c19d1205
ZW
10408 newval |= value;
10409 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
10410 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
10411 break;
404ff6b5 10412
c19d1205
ZW
10413 case BFD_RELOC_ARM_SHIFT_IMM:
10414 newval = md_chars_to_number (buf, INSN_SIZE);
10415 if (((unsigned long) value) > 32
10416 || (value == 32
10417 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
10418 {
10419 as_bad_where (fixP->fx_file, fixP->fx_line,
10420 _("shift expression is too large"));
10421 break;
10422 }
404ff6b5 10423
c19d1205
ZW
10424 if (value == 0)
10425 /* Shifts of zero must be done as lsl. */
10426 newval &= ~0x60;
10427 else if (value == 32)
10428 value = 0;
10429 newval &= 0xfffff07f;
10430 newval |= (value & 0x1f) << 7;
10431 md_number_to_chars (buf, newval, INSN_SIZE);
10432 break;
404ff6b5 10433
c19d1205
ZW
10434 case BFD_RELOC_ARM_T32_IMMEDIATE:
10435 /* We claim that this fixup has been processed here,
10436 even if in fact we generate an error because we do
10437 not have a reloc for it, so tc_gen_reloc will reject it. */
10438 fixP->fx_done = 1;
404ff6b5 10439
c19d1205
ZW
10440 if (fixP->fx_addsy
10441 && ! S_IS_DEFINED (fixP->fx_addsy))
10442 {
10443 as_bad_where (fixP->fx_file, fixP->fx_line,
10444 _("undefined symbol %s used as an immediate value"),
10445 S_GET_NAME (fixP->fx_addsy));
10446 break;
10447 }
404ff6b5 10448
c19d1205
ZW
10449 newval = md_chars_to_number (buf, THUMB_SIZE);
10450 newval <<= 16;
10451 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 10452
c19d1205 10453 newimm = encode_thumb32_immediate (value);
cc8a6dd0 10454
c19d1205
ZW
10455 /* FUTURE: Implement analogue of negate_data_op for T32. */
10456 if (newimm == (unsigned int)FAIL)
3631a3c8 10457 {
c19d1205
ZW
10458 as_bad_where (fixP->fx_file, fixP->fx_line,
10459 _("invalid constant (%lx) after fixup"),
10460 (unsigned long) value);
10461 break;
3631a3c8
NC
10462 }
10463
c19d1205
ZW
10464 newval &= 0xfbff8f00;
10465 newval |= (newimm & 0x800) << 15;
10466 newval |= (newimm & 0x700) << 4;
10467 newval |= (newimm & 0x0ff);
cc8a6dd0 10468
c19d1205
ZW
10469 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
10470 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
10471 break;
a737bd4d 10472
c19d1205
ZW
10473 case BFD_RELOC_ARM_SMI:
10474 if (((unsigned long) value) > 0xffff)
10475 as_bad_where (fixP->fx_file, fixP->fx_line,
10476 _("invalid smi expression"));
10477 newval = md_chars_to_number (buf, INSN_SIZE) & 0xfff000f0;
10478 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
10479 md_number_to_chars (buf, newval, INSN_SIZE);
10480 break;
a737bd4d 10481
c19d1205 10482 case BFD_RELOC_ARM_SWI:
adbaf948 10483 if (fixP->tc_fix_data != 0)
c19d1205
ZW
10484 {
10485 if (((unsigned long) value) > 0xff)
10486 as_bad_where (fixP->fx_file, fixP->fx_line,
10487 _("invalid swi expression"));
10488 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xff00;
10489 newval |= value;
10490 md_number_to_chars (buf, newval, THUMB_SIZE);
10491 }
10492 else
10493 {
10494 if (((unsigned long) value) > 0x00ffffff)
10495 as_bad_where (fixP->fx_file, fixP->fx_line,
10496 _("invalid swi expression"));
10497 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff000000;
10498 newval |= value;
10499 md_number_to_chars (buf, newval, INSN_SIZE);
10500 }
10501 break;
a737bd4d 10502
c19d1205
ZW
10503 case BFD_RELOC_ARM_MULTI:
10504 if (((unsigned long) value) > 0xffff)
10505 as_bad_where (fixP->fx_file, fixP->fx_line,
10506 _("invalid expression in load/store multiple"));
10507 newval = value | md_chars_to_number (buf, INSN_SIZE);
10508 md_number_to_chars (buf, newval, INSN_SIZE);
10509 break;
a737bd4d 10510
c19d1205
ZW
10511 case BFD_RELOC_ARM_PCREL_BRANCH:
10512 newval = md_chars_to_number (buf, INSN_SIZE);
a737bd4d 10513
c19d1205
ZW
10514 /* Sign-extend a 24-bit number. */
10515#define SEXT24(x) ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000)
a737bd4d 10516
c19d1205 10517#ifdef OBJ_ELF
55cf6793
ZW
10518 if (!fixP->fx_done)
10519 value = fixP->fx_offset;
c19d1205 10520#endif
a737bd4d 10521
c19d1205
ZW
10522 /* We are going to store value (shifted right by two) in the
10523 instruction, in a 24 bit, signed field Thus we need to check
10524 that none of the top 8 bits of the shifted value (top 7 bits of
10525 the unshifted, unsigned value) are set, or that they are all set. */
10526 if ((value & ~ ((offsetT) 0x1ffffff)) != 0
10527 && ((value & ~ ((offsetT) 0x1ffffff)) != ~ ((offsetT) 0x1ffffff)))
10528 {
10529#ifdef OBJ_ELF
10530 /* Normally we would be stuck at this point, since we cannot store
10531 the absolute address that is the destination of the branch in the
10532 24 bits of the branch instruction. If however, we happen to know
10533 that the destination of the branch is in the same section as the
10534 branch instruction itself, then we can compute the relocation for
10535 ourselves and not have to bother the linker with it.
a737bd4d 10536
c19d1205
ZW
10537 FIXME: The test for OBJ_ELF is only here because I have not
10538 worked out how to do this for OBJ_COFF. */
10539 if (fixP->fx_addsy != NULL
10540 && S_IS_DEFINED (fixP->fx_addsy)
10541 && S_GET_SEGMENT (fixP->fx_addsy) == seg)
10542 {
10543 /* Get pc relative value to go into the branch. */
10544 value = * valP;
a737bd4d 10545
c19d1205
ZW
10546 /* Permit a backward branch provided that enough bits
10547 are set. Allow a forwards branch, provided that
10548 enough bits are clear. */
10549 if ( (value & ~ ((offsetT) 0x1ffffff)) == ~ ((offsetT) 0x1ffffff)
10550 || (value & ~ ((offsetT) 0x1ffffff)) == 0)
10551 fixP->fx_done = 1;
10552 }
a737bd4d 10553
c19d1205
ZW
10554 if (! fixP->fx_done)
10555#endif
10556 as_bad_where (fixP->fx_file, fixP->fx_line,
10557 _("GAS can't handle same-section branch dest >= 0x04000000"));
10558 }
a737bd4d 10559
c19d1205
ZW
10560 value >>= 2;
10561 value += SEXT24 (newval);
a737bd4d 10562
c19d1205
ZW
10563 if ( (value & ~ ((offsetT) 0xffffff)) != 0
10564 && ((value & ~ ((offsetT) 0xffffff)) != ~ ((offsetT) 0xffffff)))
10565 as_bad_where (fixP->fx_file, fixP->fx_line,
10566 _("out of range branch"));
a737bd4d 10567
c19d1205
ZW
10568 if (seg->use_rela_p && !fixP->fx_done)
10569 {
10570 /* Must unshift the value before storing it in the addend. */
10571 value <<= 2;
10572#ifdef OBJ_ELF
10573 fixP->fx_offset = value;
10574#endif
10575 fixP->fx_addnumber = value;
10576 newval = newval & 0xff000000;
10577 }
10578 else
10579 newval = (value & 0x00ffffff) | (newval & 0xff000000);
10580 md_number_to_chars (buf, newval, INSN_SIZE);
10581 break;
a737bd4d 10582
c19d1205
ZW
10583 case BFD_RELOC_ARM_PCREL_BLX:
10584 {
10585 offsetT hbit;
10586 newval = md_chars_to_number (buf, INSN_SIZE);
a737bd4d 10587
c19d1205 10588#ifdef OBJ_ELF
55cf6793
ZW
10589 if (!fixP->fx_done)
10590 value = fixP->fx_offset;
c19d1205
ZW
10591#endif
10592 hbit = (value >> 1) & 1;
10593 value = (value >> 2) & 0x00ffffff;
10594 value = (value + (newval & 0x00ffffff)) & 0x00ffffff;
a737bd4d 10595
c19d1205
ZW
10596 if (seg->use_rela_p && !fixP->fx_done)
10597 {
10598 /* Must sign-extend and unshift the value before storing
10599 it in the addend. */
10600 value = SEXT24 (value);
10601 value = (value << 2) | hbit;
10602#ifdef OBJ_ELF
10603 fixP->fx_offset = value;
10604#endif
10605 fixP->fx_addnumber = value;
10606 newval = newval & 0xfe000000;
10607 }
10608 else
10609 newval = value | (newval & 0xfe000000) | (hbit << 24);
10610 md_number_to_chars (buf, newval, INSN_SIZE);
10611 }
10612 break;
a737bd4d 10613
c19d1205
ZW
10614 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
10615 newval = md_chars_to_number (buf, THUMB_SIZE);
10616 {
10617 addressT diff = ((newval & 0x00f8) >> 2) | (newval & 0x0200) >> 3;
10618 /* This one does not have the offset encoded in the pattern. */
10619 value = value + diff - 4;
10620 /* CZB can only branch forward. */
10621 if (value & ~0x7e)
10622 as_bad_where (fixP->fx_file, fixP->fx_line,
10623 _("branch out of range"));
a737bd4d 10624
c19d1205
ZW
10625 newval &= 0xfd07;
10626 if (seg->use_rela_p && !fixP->fx_done)
10627 {
10628#ifdef OBJ_ELF
10629 fixP->fx_offset = value;
10630#endif
10631 fixP->fx_addnumber = value;
10632 }
10633 else
10634 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
10635 }
10636 md_number_to_chars (buf, newval, THUMB_SIZE);
10637 break;
a737bd4d 10638
c19d1205
ZW
10639 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
10640 newval = md_chars_to_number (buf, THUMB_SIZE);
10641 {
10642 addressT diff = (newval & 0xff) << 1;
10643 if (diff & 0x100)
10644 diff |= ~0xff;
a737bd4d 10645
c19d1205
ZW
10646 value += diff;
10647 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
10648 as_bad_where (fixP->fx_file, fixP->fx_line,
10649 _("branch out of range"));
10650 if (seg->use_rela_p && !fixP->fx_done)
10651 {
10652#ifdef OBJ_ELF
10653 fixP->fx_offset = value;
10654#endif
10655 fixP->fx_addnumber = value;
10656 newval = newval & 0xff00;
10657 }
10658 else
10659 newval = (newval & 0xff00) | ((value & 0x1ff) >> 1);
10660 }
10661 md_number_to_chars (buf, newval, THUMB_SIZE);
10662 break;
a737bd4d 10663
c19d1205
ZW
10664 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
10665 newval = md_chars_to_number (buf, THUMB_SIZE);
10666 {
10667 addressT diff = (newval & 0x7ff) << 1;
10668 if (diff & 0x800)
10669 diff |= ~0x7ff;
a737bd4d 10670
c19d1205
ZW
10671 value += diff;
10672 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
10673 as_bad_where (fixP->fx_file, fixP->fx_line,
10674 _("branch out of range"));
10675 if (seg->use_rela_p && !fixP->fx_done)
10676 {
10677#ifdef OBJ_ELF
10678 fixP->fx_offset = value;
10679#endif
10680 fixP->fx_addnumber = value;
10681 newval = newval & 0xf800;
10682 }
10683 else
10684 newval = (newval & 0xf800) | ((value & 0xfff) >> 1);
10685 }
10686 md_number_to_chars (buf, newval, THUMB_SIZE);
10687 break;
a737bd4d 10688
c19d1205
ZW
10689 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10690 {
10691 offsetT newval2;
10692 addressT diff, S, J1, J2, lo, hi;
a737bd4d 10693
c19d1205
ZW
10694 newval = md_chars_to_number (buf, THUMB_SIZE);
10695 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
a737bd4d 10696
c19d1205
ZW
10697 S = !(newval & 0x0400); /* flipped - 0=negative */
10698 hi = (newval & 0x003f);
10699 J1 = (newval2 & 0x2000) >> 13;
10700 J2 = (newval2 & 0x0800) >> 11;
10701 lo = (newval2 & 0x07ff);
a737bd4d 10702
c19d1205
ZW
10703 diff = ((S << 20) | (J2 << 19) | (J1 << 18) | (hi << 12) | (lo << 1));
10704 diff -= (1 << 20); /* sign extend */
10705 value += diff;
404ff6b5 10706
c19d1205
ZW
10707 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
10708 as_bad_where (fixP->fx_file, fixP->fx_line,
10709 _("conditional branch out of range"));
404ff6b5 10710
c19d1205
ZW
10711 newval = newval & 0xfbc0;
10712 newval2 = newval2 & 0xd000;
10713 if (seg->use_rela_p && !fixP->fx_done)
10714 {
10715#ifdef OBJ_ELF
10716 fixP->fx_offset = value;
10717#endif
10718 fixP->fx_addnumber = value;
10719 }
10720 else
10721 {
10722 S = (value & 0x00100000) >> 20;
10723 J2 = (value & 0x00080000) >> 19;
10724 J1 = (value & 0x00040000) >> 18;
10725 hi = (value & 0x0003f000) >> 12;
10726 lo = (value & 0x00000ffe) >> 1;
10727
10728 newval = newval | (S << 10) | hi;
10729 newval2 = newval2 | (J1 << 13) | (J2 << 11) | lo;
10730 }
6c43fab6 10731
c19d1205
ZW
10732 md_number_to_chars (buf, newval, THUMB_SIZE);
10733 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10734 }
10735 break;
6c43fab6 10736
c19d1205
ZW
10737 case BFD_RELOC_THUMB_PCREL_BLX:
10738 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10739 {
10740 offsetT newval2;
10741 addressT diff;
404ff6b5 10742
c19d1205
ZW
10743 newval = md_chars_to_number (buf, THUMB_SIZE);
10744 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10745 diff = ((newval & 0x7ff) << 12) | ((newval2 & 0x7ff) << 1);
10746 if (diff & 0x400000)
10747 diff |= ~0x3fffff;
10748#ifdef OBJ_ELF
55cf6793
ZW
10749 if (!fixP->fx_done)
10750 value = fixP->fx_offset;
c19d1205
ZW
10751#endif
10752 value += diff;
404ff6b5 10753
c19d1205
ZW
10754 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
10755 as_bad_where (fixP->fx_file, fixP->fx_line,
10756 _("branch with link out of range"));
404ff6b5 10757
c19d1205
ZW
10758 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
10759 /* For a BLX instruction, make sure that the relocation is rounded up
10760 to a word boundary. This follows the semantics of the instruction
10761 which specifies that bit 1 of the target address will come from bit
10762 1 of the base address. */
10763 value = (value + 1) & ~ 1;
404ff6b5 10764
c19d1205
ZW
10765 if (seg->use_rela_p && !fixP->fx_done)
10766 {
10767#ifdef OBJ_ELF
10768 fixP->fx_offset = value;
10769#endif
10770 fixP->fx_addnumber = value;
10771 newval = newval & 0xf800;
10772 newval2 = newval2 & 0xf800;
10773 }
10774 else
10775 {
10776 newval = (newval & 0xf800) | ((value & 0x7fffff) >> 12);
10777 newval2 = (newval2 & 0xf800) | ((value & 0xfff) >> 1);
10778 }
10779 md_number_to_chars (buf, newval, THUMB_SIZE);
10780 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10781 }
10782 break;
404ff6b5 10783
c19d1205
ZW
10784 case BFD_RELOC_8:
10785 if (seg->use_rela_p && !fixP->fx_done)
10786 break;
10787 if (fixP->fx_done || fixP->fx_pcrel)
10788 md_number_to_chars (buf, value, 1);
10789#ifdef OBJ_ELF
10790 else
10791 {
10792 value = fixP->fx_offset;
10793 md_number_to_chars (buf, value, 1);
10794 }
10795#endif
10796 break;
404ff6b5 10797
c19d1205
ZW
10798 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10799 {
10800 offsetT newval2;
10801 addressT diff, S, I1, I2, lo, hi;
6c43fab6 10802
c19d1205
ZW
10803 newval = md_chars_to_number (buf, THUMB_SIZE);
10804 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
6c43fab6 10805
c19d1205
ZW
10806 S = (newval & 0x0400) >> 10;
10807 hi = (newval & 0x03ff);
10808 I1 = (newval2 & 0x2000) >> 13;
10809 I2 = (newval2 & 0x0800) >> 11;
10810 lo = (newval2 & 0x07ff);
6c43fab6 10811
c19d1205
ZW
10812 I1 = !(I1 ^ S);
10813 I2 = !(I2 ^ S);
10814 S = !S;
6c43fab6 10815
c19d1205
ZW
10816 diff = ((S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1));
10817 diff -= (1 << 24); /* sign extend */
10818 value += diff;
6c43fab6 10819
c19d1205
ZW
10820 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
10821 as_bad_where (fixP->fx_file, fixP->fx_line,
10822 _("branch out of range"));
6c43fab6 10823
c19d1205
ZW
10824 newval = newval & 0xf800;
10825 newval2 = newval2 & 0xd000;
10826 if (seg->use_rela_p && !fixP->fx_done)
10827 {
10828#ifdef OBJ_ELF
10829 fixP->fx_offset = value;
10830#endif
10831 fixP->fx_addnumber = value;
10832 }
10833 else
10834 {
10835 S = (value & 0x01000000) >> 24;
10836 I1 = (value & 0x00800000) >> 23;
10837 I2 = (value & 0x00400000) >> 22;
10838 hi = (value & 0x003ff000) >> 12;
10839 lo = (value & 0x00000ffe) >> 1;
a737bd4d 10840
c19d1205
ZW
10841 I1 = !(I1 ^ S);
10842 I2 = !(I2 ^ S);
a737bd4d 10843
c19d1205
ZW
10844 newval = newval | (S << 10) | hi;
10845 newval2 = newval2 | (I1 << 13) | (I2 << 11) | lo;
10846 }
10847 md_number_to_chars (buf, newval, THUMB_SIZE);
10848 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10849 }
10850 break;
a737bd4d 10851
c19d1205
ZW
10852 case BFD_RELOC_16:
10853 if (seg->use_rela_p && !fixP->fx_done)
10854 break;
10855 if (fixP->fx_done || fixP->fx_pcrel)
10856 md_number_to_chars (buf, value, 2);
10857#ifdef OBJ_ELF
10858 else
10859 {
10860 value = fixP->fx_offset;
10861 md_number_to_chars (buf, value, 2);
10862 }
10863#endif
10864 break;
a737bd4d 10865
c19d1205
ZW
10866#ifdef OBJ_ELF
10867 case BFD_RELOC_ARM_TLS_GD32:
10868 case BFD_RELOC_ARM_TLS_LE32:
10869 case BFD_RELOC_ARM_TLS_IE32:
10870 case BFD_RELOC_ARM_TLS_LDM32:
10871 case BFD_RELOC_ARM_TLS_LDO32:
10872 S_SET_THREAD_LOCAL (fixP->fx_addsy);
10873 /* fall through */
6c43fab6 10874
c19d1205
ZW
10875 case BFD_RELOC_ARM_GOT32:
10876 case BFD_RELOC_ARM_GOTOFF:
10877 case BFD_RELOC_ARM_TARGET2:
10878 if (seg->use_rela_p && !fixP->fx_done)
10879 break;
10880 md_number_to_chars (buf, 0, 4);
10881 break;
10882#endif
6c43fab6 10883
c19d1205
ZW
10884 case BFD_RELOC_RVA:
10885 case BFD_RELOC_32:
10886 case BFD_RELOC_ARM_TARGET1:
10887 case BFD_RELOC_ARM_ROSEGREL32:
10888 case BFD_RELOC_ARM_SBREL32:
10889 case BFD_RELOC_32_PCREL:
10890 if (seg->use_rela_p && !fixP->fx_done)
10891 break;
10892 if (fixP->fx_done || fixP->fx_pcrel)
10893 md_number_to_chars (buf, value, 4);
10894#ifdef OBJ_ELF
10895 else
10896 {
10897 value = fixP->fx_offset;
10898 md_number_to_chars (buf, value, 4);
10899 }
10900#endif
10901 break;
6c43fab6 10902
c19d1205
ZW
10903#ifdef OBJ_ELF
10904 case BFD_RELOC_ARM_PREL31:
10905 if (fixP->fx_done || fixP->fx_pcrel)
10906 {
10907 newval = md_chars_to_number (buf, 4) & 0x80000000;
10908 if ((value ^ (value >> 1)) & 0x40000000)
10909 {
10910 as_bad_where (fixP->fx_file, fixP->fx_line,
10911 _("rel31 relocation overflow"));
10912 }
10913 newval |= value & 0x7fffffff;
10914 md_number_to_chars (buf, newval, 4);
10915 }
10916 break;
a737bd4d 10917
c19d1205
ZW
10918 case BFD_RELOC_ARM_PLT32:
10919 /* It appears the instruction is fully prepared at this point. */
10920 break;
10921#endif
a737bd4d 10922
c19d1205
ZW
10923 case BFD_RELOC_ARM_CP_OFF_IMM:
10924 if (value < -1023 || value > 1023 || (value & 3))
10925 as_bad_where (fixP->fx_file, fixP->fx_line,
10926 _("co-processor offset out of range"));
10927 cp_off_common:
10928 sign = value >= 0;
10929 if (value < 0)
10930 value = -value;
10931 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
10932 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
10933 if (value == 0)
10934 newval &= ~WRITE_BACK;
10935 md_number_to_chars (buf, newval, INSN_SIZE);
10936 break;
a737bd4d 10937
c19d1205
ZW
10938 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
10939 if (value < -255 || value > 255)
10940 as_bad_where (fixP->fx_file, fixP->fx_line,
10941 _("co-processor offset out of range"));
10942 goto cp_off_common;
6c43fab6 10943
c19d1205
ZW
10944 case BFD_RELOC_ARM_THUMB_OFFSET:
10945 newval = md_chars_to_number (buf, THUMB_SIZE);
10946 /* Exactly what ranges, and where the offset is inserted depends
10947 on the type of instruction, we can establish this from the
10948 top 4 bits. */
10949 switch (newval >> 12)
10950 {
10951 case 4: /* PC load. */
10952 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
10953 forced to zero for these loads; md_pcrel_from has already
10954 compensated for this. */
10955 if (value & 3)
10956 as_bad_where (fixP->fx_file, fixP->fx_line,
10957 _("invalid offset, target not word aligned (0x%08lX)"),
10958 (((unsigned int) fixP->fx_frag->fr_address
10959 + (unsigned int) fixP->fx_where) & ~3) + value);
a737bd4d 10960
c19d1205
ZW
10961 if (value & ~0x3fc)
10962 as_bad_where (fixP->fx_file, fixP->fx_line,
10963 _("invalid offset, value too big (0x%08lX)"),
10964 (long) value);
a737bd4d 10965
c19d1205
ZW
10966 newval |= value >> 2;
10967 break;
a737bd4d 10968
c19d1205
ZW
10969 case 9: /* SP load/store. */
10970 if (value & ~0x3fc)
10971 as_bad_where (fixP->fx_file, fixP->fx_line,
10972 _("invalid offset, value too big (0x%08lX)"),
10973 (long) value);
10974 newval |= value >> 2;
10975 break;
6c43fab6 10976
c19d1205
ZW
10977 case 6: /* Word load/store. */
10978 if (value & ~0x7c)
10979 as_bad_where (fixP->fx_file, fixP->fx_line,
10980 _("invalid offset, value too big (0x%08lX)"),
10981 (long) value);
10982 newval |= value << 4; /* 6 - 2. */
10983 break;
a737bd4d 10984
c19d1205
ZW
10985 case 7: /* Byte load/store. */
10986 if (value & ~0x1f)
10987 as_bad_where (fixP->fx_file, fixP->fx_line,
10988 _("invalid offset, value too big (0x%08lX)"),
10989 (long) value);
10990 newval |= value << 6;
10991 break;
a737bd4d 10992
c19d1205
ZW
10993 case 8: /* Halfword load/store. */
10994 if (value & ~0x3e)
10995 as_bad_where (fixP->fx_file, fixP->fx_line,
10996 _("invalid offset, value too big (0x%08lX)"),
10997 (long) value);
10998 newval |= value << 5; /* 6 - 1. */
10999 break;
a737bd4d 11000
c19d1205
ZW
11001 default:
11002 as_bad_where (fixP->fx_file, fixP->fx_line,
11003 "Unable to process relocation for thumb opcode: %lx",
11004 (unsigned long) newval);
11005 break;
11006 }
11007 md_number_to_chars (buf, newval, THUMB_SIZE);
11008 break;
a737bd4d 11009
c19d1205
ZW
11010 case BFD_RELOC_ARM_THUMB_ADD:
11011 /* This is a complicated relocation, since we use it for all of
11012 the following immediate relocations:
a737bd4d 11013
c19d1205
ZW
11014 3bit ADD/SUB
11015 8bit ADD/SUB
11016 9bit ADD/SUB SP word-aligned
11017 10bit ADD PC/SP word-aligned
a737bd4d 11018
c19d1205
ZW
11019 The type of instruction being processed is encoded in the
11020 instruction field:
a737bd4d 11021
c19d1205
ZW
11022 0x8000 SUB
11023 0x00F0 Rd
11024 0x000F Rs
11025 */
11026 newval = md_chars_to_number (buf, THUMB_SIZE);
11027 {
11028 int rd = (newval >> 4) & 0xf;
11029 int rs = newval & 0xf;
11030 int subtract = !!(newval & 0x8000);
a737bd4d 11031
c19d1205
ZW
11032 /* Check for HI regs, only very restricted cases allowed:
11033 Adjusting SP, and using PC or SP to get an address. */
11034 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
11035 || (rs > 7 && rs != REG_SP && rs != REG_PC))
11036 as_bad_where (fixP->fx_file, fixP->fx_line,
11037 _("invalid Hi register with immediate"));
a737bd4d 11038
c19d1205
ZW
11039 /* If value is negative, choose the opposite instruction. */
11040 if (value < 0)
11041 {
11042 value = -value;
11043 subtract = !subtract;
11044 if (value < 0)
11045 as_bad_where (fixP->fx_file, fixP->fx_line,
11046 _("immediate value out of range"));
11047 }
a737bd4d 11048
c19d1205
ZW
11049 if (rd == REG_SP)
11050 {
11051 if (value & ~0x1fc)
11052 as_bad_where (fixP->fx_file, fixP->fx_line,
11053 _("invalid immediate for stack address calculation"));
11054 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11055 newval |= value >> 2;
11056 }
11057 else if (rs == REG_PC || rs == REG_SP)
11058 {
11059 if (subtract || value & ~0x3fc)
11060 as_bad_where (fixP->fx_file, fixP->fx_line,
11061 _("invalid immediate for address calculation (value = 0x%08lX)"),
11062 (unsigned long) value);
11063 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11064 newval |= rd << 8;
11065 newval |= value >> 2;
11066 }
11067 else if (rs == rd)
11068 {
11069 if (value & ~0xff)
11070 as_bad_where (fixP->fx_file, fixP->fx_line,
11071 _("immediate value out of range"));
11072 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11073 newval |= (rd << 8) | value;
11074 }
11075 else
11076 {
11077 if (value & ~0x7)
11078 as_bad_where (fixP->fx_file, fixP->fx_line,
11079 _("immediate value out of range"));
11080 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11081 newval |= rd | (rs << 3) | (value << 6);
11082 }
11083 }
11084 md_number_to_chars (buf, newval, THUMB_SIZE);
11085 break;
a737bd4d 11086
c19d1205
ZW
11087 case BFD_RELOC_ARM_THUMB_IMM:
11088 newval = md_chars_to_number (buf, THUMB_SIZE);
11089 if (value < 0 || value > 255)
11090 as_bad_where (fixP->fx_file, fixP->fx_line,
11091 _("invalid immediate: %ld is too large"),
11092 (long) value);
11093 newval |= value;
11094 md_number_to_chars (buf, newval, THUMB_SIZE);
11095 break;
a737bd4d 11096
c19d1205
ZW
11097 case BFD_RELOC_ARM_THUMB_SHIFT:
11098 /* 5bit shift value (0..32). LSL cannot take 32. */
11099 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11100 temp = newval & 0xf800;
11101 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11102 as_bad_where (fixP->fx_file, fixP->fx_line,
11103 _("invalid shift value: %ld"), (long) value);
11104 /* Shifts of zero must be encoded as LSL. */
11105 if (value == 0)
11106 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11107 /* Shifts of 32 are encoded as zero. */
11108 else if (value == 32)
11109 value = 0;
11110 newval |= value << 6;
11111 md_number_to_chars (buf, newval, THUMB_SIZE);
11112 break;
a737bd4d 11113
c19d1205
ZW
11114 case BFD_RELOC_VTABLE_INHERIT:
11115 case BFD_RELOC_VTABLE_ENTRY:
11116 fixP->fx_done = 0;
11117 return;
6c43fab6 11118
c19d1205
ZW
11119 case BFD_RELOC_UNUSED:
11120 default:
11121 as_bad_where (fixP->fx_file, fixP->fx_line,
11122 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11123 }
6c43fab6
RE
11124}
11125
c19d1205
ZW
11126/* Translate internal representation of relocation info to BFD target
11127 format. */
a737bd4d 11128
c19d1205
ZW
11129arelent *
11130tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11131 fixS * fixp)
a737bd4d 11132{
c19d1205
ZW
11133 arelent * reloc;
11134 bfd_reloc_code_real_type code;
a737bd4d 11135
c19d1205 11136 reloc = xmalloc (sizeof (arelent));
a737bd4d 11137
c19d1205
ZW
11138 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11139 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11140 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 11141
c19d1205
ZW
11142 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
11143#ifndef OBJ_ELF
11144 if (fixp->fx_pcrel == 0)
11145 reloc->addend = fixp->fx_offset;
11146 else
11147 reloc->addend = fixp->fx_offset = reloc->address;
11148#else /* OBJ_ELF */
11149 reloc->addend = fixp->fx_offset;
11150#endif
a737bd4d 11151
c19d1205 11152 switch (fixp->fx_r_type)
a737bd4d 11153 {
c19d1205
ZW
11154 case BFD_RELOC_8:
11155 if (fixp->fx_pcrel)
11156 {
11157 code = BFD_RELOC_8_PCREL;
11158 break;
11159 }
a737bd4d 11160
c19d1205
ZW
11161 case BFD_RELOC_16:
11162 if (fixp->fx_pcrel)
11163 {
11164 code = BFD_RELOC_16_PCREL;
11165 break;
11166 }
6c43fab6 11167
c19d1205
ZW
11168 case BFD_RELOC_32:
11169 if (fixp->fx_pcrel)
11170 {
11171 code = BFD_RELOC_32_PCREL;
11172 break;
11173 }
a737bd4d 11174
c19d1205
ZW
11175 case BFD_RELOC_NONE:
11176 case BFD_RELOC_ARM_PCREL_BRANCH:
11177 case BFD_RELOC_ARM_PCREL_BLX:
11178 case BFD_RELOC_RVA:
11179 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11180 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11181 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11182 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11183 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11184 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11185 case BFD_RELOC_THUMB_PCREL_BLX:
11186 case BFD_RELOC_VTABLE_ENTRY:
11187 case BFD_RELOC_VTABLE_INHERIT:
11188 code = fixp->fx_r_type;
11189 break;
a737bd4d 11190
c19d1205
ZW
11191 case BFD_RELOC_ARM_LITERAL:
11192 case BFD_RELOC_ARM_HWLITERAL:
11193 /* If this is called then the a literal has
11194 been referenced across a section boundary. */
11195 as_bad_where (fixp->fx_file, fixp->fx_line,
11196 _("literal referenced across section boundary"));
11197 return NULL;
a737bd4d 11198
c19d1205
ZW
11199#ifdef OBJ_ELF
11200 case BFD_RELOC_ARM_GOT32:
11201 case BFD_RELOC_ARM_GOTOFF:
11202 case BFD_RELOC_ARM_PLT32:
11203 case BFD_RELOC_ARM_TARGET1:
11204 case BFD_RELOC_ARM_ROSEGREL32:
11205 case BFD_RELOC_ARM_SBREL32:
11206 case BFD_RELOC_ARM_PREL31:
11207 case BFD_RELOC_ARM_TARGET2:
11208 case BFD_RELOC_ARM_TLS_LE32:
11209 case BFD_RELOC_ARM_TLS_LDO32:
11210 code = fixp->fx_r_type;
11211 break;
a737bd4d 11212
c19d1205
ZW
11213 case BFD_RELOC_ARM_TLS_GD32:
11214 case BFD_RELOC_ARM_TLS_IE32:
11215 case BFD_RELOC_ARM_TLS_LDM32:
11216 /* BFD will include the symbol's address in the addend.
11217 But we don't want that, so subtract it out again here. */
11218 if (!S_IS_COMMON (fixp->fx_addsy))
11219 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11220 code = fixp->fx_r_type;
11221 break;
11222#endif
a737bd4d 11223
c19d1205
ZW
11224 case BFD_RELOC_ARM_IMMEDIATE:
11225 as_bad_where (fixp->fx_file, fixp->fx_line,
11226 _("internal relocation (type: IMMEDIATE) not fixed up"));
11227 return NULL;
a737bd4d 11228
c19d1205
ZW
11229 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11230 as_bad_where (fixp->fx_file, fixp->fx_line,
11231 _("ADRL used for a symbol not defined in the same file"));
11232 return NULL;
a737bd4d 11233
c19d1205
ZW
11234 case BFD_RELOC_ARM_OFFSET_IMM:
11235 if (fixp->fx_addsy != NULL
11236 && !S_IS_DEFINED (fixp->fx_addsy)
11237 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 11238 {
c19d1205
ZW
11239 as_bad_where (fixp->fx_file, fixp->fx_line,
11240 _("undefined local label `%s'"),
11241 S_GET_NAME (fixp->fx_addsy));
11242 return NULL;
a737bd4d
NC
11243 }
11244
c19d1205
ZW
11245 as_bad_where (fixp->fx_file, fixp->fx_line,
11246 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11247 return NULL;
a737bd4d 11248
c19d1205
ZW
11249 default:
11250 {
11251 char * type;
6c43fab6 11252
c19d1205
ZW
11253 switch (fixp->fx_r_type)
11254 {
11255 case BFD_RELOC_NONE: type = "NONE"; break;
11256 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
11257 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
11258 case BFD_RELOC_ARM_SMI: type = "SMI"; break;
11259 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
11260 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
11261 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
11262 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
11263 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
11264 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
11265 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
11266 default: type = _("<unknown>"); break;
11267 }
11268 as_bad_where (fixp->fx_file, fixp->fx_line,
11269 _("cannot represent %s relocation in this object file format"),
11270 type);
11271 return NULL;
11272 }
a737bd4d 11273 }
6c43fab6 11274
c19d1205
ZW
11275#ifdef OBJ_ELF
11276 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
11277 && GOT_symbol
11278 && fixp->fx_addsy == GOT_symbol)
11279 {
11280 code = BFD_RELOC_ARM_GOTPC;
11281 reloc->addend = fixp->fx_offset = reloc->address;
11282 }
11283#endif
6c43fab6 11284
c19d1205 11285 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 11286
c19d1205
ZW
11287 if (reloc->howto == NULL)
11288 {
11289 as_bad_where (fixp->fx_file, fixp->fx_line,
11290 _("cannot represent %s relocation in this object file format"),
11291 bfd_get_reloc_code_name (code));
11292 return NULL;
11293 }
6c43fab6 11294
c19d1205
ZW
11295 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
11296 vtable entry to be used in the relocation's section offset. */
11297 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11298 reloc->address = fixp->fx_offset;
6c43fab6 11299
c19d1205 11300 return reloc;
6c43fab6
RE
11301}
11302
c19d1205 11303/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 11304
c19d1205
ZW
11305void
11306cons_fix_new_arm (fragS * frag,
11307 int where,
11308 int size,
11309 expressionS * exp)
6c43fab6 11310{
c19d1205
ZW
11311 bfd_reloc_code_real_type type;
11312 int pcrel = 0;
6c43fab6 11313
c19d1205
ZW
11314 /* Pick a reloc.
11315 FIXME: @@ Should look at CPU word size. */
11316 switch (size)
11317 {
11318 case 1:
11319 type = BFD_RELOC_8;
11320 break;
11321 case 2:
11322 type = BFD_RELOC_16;
11323 break;
11324 case 4:
11325 default:
11326 type = BFD_RELOC_32;
11327 break;
11328 case 8:
11329 type = BFD_RELOC_64;
11330 break;
11331 }
6c43fab6 11332
c19d1205
ZW
11333 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
11334}
6c43fab6 11335
c19d1205
ZW
11336#if defined OBJ_COFF || defined OBJ_ELF
11337void
11338arm_validate_fix (fixS * fixP)
6c43fab6 11339{
c19d1205
ZW
11340 /* If the destination of the branch is a defined symbol which does not have
11341 the THUMB_FUNC attribute, then we must be calling a function which has
11342 the (interfacearm) attribute. We look for the Thumb entry point to that
11343 function and change the branch to refer to that function instead. */
11344 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
11345 && fixP->fx_addsy != NULL
11346 && S_IS_DEFINED (fixP->fx_addsy)
11347 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 11348 {
c19d1205 11349 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 11350 }
c19d1205
ZW
11351}
11352#endif
6c43fab6 11353
c19d1205
ZW
11354int
11355arm_force_relocation (struct fix * fixp)
11356{
11357#if defined (OBJ_COFF) && defined (TE_PE)
11358 if (fixp->fx_r_type == BFD_RELOC_RVA)
11359 return 1;
11360#endif
6c43fab6 11361
c19d1205
ZW
11362 /* Resolve these relocations even if the symbol is extern or weak. */
11363 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
11364 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
11365 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11366 return 0;
a737bd4d 11367
c19d1205 11368 return generic_force_reloc (fixp);
404ff6b5
AH
11369}
11370
c19d1205
ZW
11371#ifdef OBJ_COFF
11372/* This is a little hack to help the gas/arm/adrl.s test. It prevents
11373 local labels from being added to the output symbol table when they
11374 are used with the ADRL pseudo op. The ADRL relocation should always
11375 be resolved before the binbary is emitted, so it is safe to say that
11376 it is adjustable. */
404ff6b5 11377
c19d1205
ZW
11378bfd_boolean
11379arm_fix_adjustable (fixS * fixP)
404ff6b5 11380{
c19d1205
ZW
11381 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11382 return 1;
11383 return 0;
404ff6b5 11384}
c19d1205 11385#endif
404ff6b5 11386
c19d1205
ZW
11387#ifdef OBJ_ELF
11388/* Relocations against Thumb function names must be left unadjusted,
11389 so that the linker can use this information to correctly set the
11390 bottom bit of their addresses. The MIPS version of this function
11391 also prevents relocations that are mips-16 specific, but I do not
11392 know why it does this.
404ff6b5 11393
c19d1205
ZW
11394 FIXME:
11395 There is one other problem that ought to be addressed here, but
11396 which currently is not: Taking the address of a label (rather
11397 than a function) and then later jumping to that address. Such
11398 addresses also ought to have their bottom bit set (assuming that
11399 they reside in Thumb code), but at the moment they will not. */
404ff6b5 11400
c19d1205
ZW
11401bfd_boolean
11402arm_fix_adjustable (fixS * fixP)
404ff6b5 11403{
c19d1205
ZW
11404 if (fixP->fx_addsy == NULL)
11405 return 1;
404ff6b5 11406
c19d1205
ZW
11407 if (THUMB_IS_FUNC (fixP->fx_addsy)
11408 && fixP->fx_subsy == NULL)
11409 return 0;
a737bd4d 11410
c19d1205
ZW
11411 /* We need the symbol name for the VTABLE entries. */
11412 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11413 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11414 return 0;
404ff6b5 11415
c19d1205
ZW
11416 /* Don't allow symbols to be discarded on GOT related relocs. */
11417 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
11418 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
11419 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
11420 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
11421 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
11422 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
11423 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
11424 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
11425 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
11426 return 0;
a737bd4d 11427
c19d1205 11428 return 1;
a737bd4d 11429}
404ff6b5 11430
c19d1205
ZW
11431const char *
11432elf32_arm_target_format (void)
404ff6b5 11433{
c19d1205
ZW
11434#ifdef TE_SYMBIAN
11435 return (target_big_endian
11436 ? "elf32-bigarm-symbian"
11437 : "elf32-littlearm-symbian");
11438#elif defined (TE_VXWORKS)
11439 return (target_big_endian
11440 ? "elf32-bigarm-vxworks"
11441 : "elf32-littlearm-vxworks");
11442#else
11443 if (target_big_endian)
11444 return "elf32-bigarm";
11445 else
11446 return "elf32-littlearm";
11447#endif
404ff6b5
AH
11448}
11449
c19d1205
ZW
11450void
11451armelf_frob_symbol (symbolS * symp,
11452 int * puntp)
404ff6b5 11453{
c19d1205
ZW
11454 elf_frob_symbol (symp, puntp);
11455}
11456#endif
404ff6b5 11457
c19d1205 11458/* MD interface: Finalization. */
a737bd4d 11459
c19d1205
ZW
11460/* A good place to do this, although this was probably not intended
11461 for this kind of use. We need to dump the literal pool before
11462 references are made to a null symbol pointer. */
a737bd4d 11463
c19d1205
ZW
11464void
11465arm_cleanup (void)
11466{
11467 literal_pool * pool;
a737bd4d 11468
c19d1205
ZW
11469 for (pool = list_of_pools; pool; pool = pool->next)
11470 {
11471 /* Put it at the end of the relevent section. */
11472 subseg_set (pool->section, pool->sub_section);
11473#ifdef OBJ_ELF
11474 arm_elf_change_section ();
11475#endif
11476 s_ltorg (0);
11477 }
404ff6b5
AH
11478}
11479
c19d1205
ZW
11480/* Adjust the symbol table. This marks Thumb symbols as distinct from
11481 ARM ones. */
404ff6b5 11482
c19d1205
ZW
11483void
11484arm_adjust_symtab (void)
404ff6b5 11485{
c19d1205
ZW
11486#ifdef OBJ_COFF
11487 symbolS * sym;
404ff6b5 11488
c19d1205
ZW
11489 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
11490 {
11491 if (ARM_IS_THUMB (sym))
11492 {
11493 if (THUMB_IS_FUNC (sym))
11494 {
11495 /* Mark the symbol as a Thumb function. */
11496 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
11497 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
11498 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 11499
c19d1205
ZW
11500 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
11501 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
11502 else
11503 as_bad (_("%s: unexpected function type: %d"),
11504 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
11505 }
11506 else switch (S_GET_STORAGE_CLASS (sym))
11507 {
11508 case C_EXT:
11509 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
11510 break;
11511 case C_STAT:
11512 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
11513 break;
11514 case C_LABEL:
11515 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
11516 break;
11517 default:
11518 /* Do nothing. */
11519 break;
11520 }
11521 }
a737bd4d 11522
c19d1205
ZW
11523 if (ARM_IS_INTERWORK (sym))
11524 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 11525 }
c19d1205
ZW
11526#endif
11527#ifdef OBJ_ELF
11528 symbolS * sym;
11529 char bind;
404ff6b5 11530
c19d1205 11531 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 11532 {
c19d1205
ZW
11533 if (ARM_IS_THUMB (sym))
11534 {
11535 elf_symbol_type * elf_sym;
404ff6b5 11536
c19d1205
ZW
11537 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
11538 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 11539
c19d1205
ZW
11540 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
11541 {
11542 /* If it's a .thumb_func, declare it as so,
11543 otherwise tag label as .code 16. */
11544 if (THUMB_IS_FUNC (sym))
11545 elf_sym->internal_elf_sym.st_info =
11546 ELF_ST_INFO (bind, STT_ARM_TFUNC);
11547 else
11548 elf_sym->internal_elf_sym.st_info =
11549 ELF_ST_INFO (bind, STT_ARM_16BIT);
11550 }
11551 }
11552 }
11553#endif
404ff6b5
AH
11554}
11555
c19d1205 11556/* MD interface: Initialization. */
404ff6b5 11557
a737bd4d 11558static void
c19d1205 11559set_constant_flonums (void)
a737bd4d 11560{
c19d1205 11561 int i;
404ff6b5 11562
c19d1205
ZW
11563 for (i = 0; i < NUM_FLOAT_VALS; i++)
11564 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
11565 abort ();
a737bd4d 11566}
404ff6b5 11567
c19d1205
ZW
11568void
11569md_begin (void)
a737bd4d 11570{
c19d1205
ZW
11571 unsigned mach;
11572 unsigned int i;
404ff6b5 11573
c19d1205
ZW
11574 if ( (arm_ops_hsh = hash_new ()) == NULL
11575 || (arm_cond_hsh = hash_new ()) == NULL
11576 || (arm_shift_hsh = hash_new ()) == NULL
11577 || (arm_psr_hsh = hash_new ()) == NULL
11578 || (arm_reg_hsh = hash_new ()) == NULL
11579 || (arm_reloc_hsh = hash_new ()) == NULL)
11580 as_fatal (_("virtual memory exhausted"));
11581
11582 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
11583 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
11584 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
11585 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
11586 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
11587 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
11588 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
11589 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
11590 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
11591 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
11592#ifdef OBJ_ELF
11593 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
11594 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
11595#endif
11596
11597 set_constant_flonums ();
404ff6b5 11598
c19d1205
ZW
11599 /* Set the cpu variant based on the command-line options. We prefer
11600 -mcpu= over -march= if both are set (as for GCC); and we prefer
11601 -mfpu= over any other way of setting the floating point unit.
11602 Use of legacy options with new options are faulted. */
11603 if (legacy_cpu != -1)
404ff6b5 11604 {
c19d1205
ZW
11605 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
11606 as_bad (_("use of old and new-style options to set CPU type"));
11607
11608 mcpu_cpu_opt = legacy_cpu;
404ff6b5 11609 }
c19d1205
ZW
11610 else if (mcpu_cpu_opt == -1)
11611 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 11612
c19d1205
ZW
11613 if (legacy_fpu != -1)
11614 {
11615 if (mfpu_opt != -1)
11616 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
11617
11618 mfpu_opt = legacy_fpu;
11619 }
11620 else if (mfpu_opt == -1)
11621 {
c19d1205 11622#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
11623 /* Some environments specify a default FPU. If they don't, infer it
11624 from the processor. */
03b1477f
RE
11625 if (mcpu_fpu_opt != -1)
11626 mfpu_opt = mcpu_fpu_opt;
11627 else
11628 mfpu_opt = march_fpu_opt;
39c2da32
RE
11629#else
11630 mfpu_opt = FPU_DEFAULT;
11631#endif
03b1477f
RE
11632 }
11633
11634 if (mfpu_opt == -1)
11635 {
11636 if (mcpu_cpu_opt == -1)
11637 mfpu_opt = FPU_DEFAULT;
11638 else if (mcpu_cpu_opt & ARM_EXT_V5)
11639 mfpu_opt = FPU_ARCH_VFP_V2;
11640 else
11641 mfpu_opt = FPU_ARCH_FPA;
11642 }
11643
11644 if (mcpu_cpu_opt == -1)
11645 mcpu_cpu_opt = CPU_DEFAULT;
11646
11647 cpu_variant = mcpu_cpu_opt | mfpu_opt;
11648
f17c130b 11649#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 11650 {
7cc69913
NC
11651 unsigned int flags = 0;
11652
11653#if defined OBJ_ELF
11654 flags = meabi_flags;
d507cf36
PB
11655
11656 switch (meabi_flags)
33a392fb 11657 {
d507cf36 11658 case EF_ARM_EABI_UNKNOWN:
7cc69913 11659#endif
d507cf36
PB
11660 /* Set the flags in the private structure. */
11661 if (uses_apcs_26) flags |= F_APCS26;
11662 if (support_interwork) flags |= F_INTERWORK;
11663 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 11664 if (pic_code) flags |= F_PIC;
d507cf36
PB
11665 if ((cpu_variant & FPU_ANY) == FPU_NONE
11666 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
7cc69913
NC
11667 flags |= F_SOFT_FLOAT;
11668
d507cf36
PB
11669 switch (mfloat_abi_opt)
11670 {
11671 case ARM_FLOAT_ABI_SOFT:
11672 case ARM_FLOAT_ABI_SOFTFP:
11673 flags |= F_SOFT_FLOAT;
11674 break;
33a392fb 11675
d507cf36
PB
11676 case ARM_FLOAT_ABI_HARD:
11677 if (flags & F_SOFT_FLOAT)
11678 as_bad (_("hard-float conflicts with specified fpu"));
11679 break;
11680 }
03b1477f 11681
c19d1205 11682 /* Using VFP conventions (even if soft-float). */
7cc69913
NC
11683 if (cpu_variant & FPU_VFP_EXT_NONE)
11684 flags |= F_VFP_FLOAT;
f17c130b 11685
fde78edd 11686#if defined OBJ_ELF
d507cf36
PB
11687 if (cpu_variant & FPU_ARCH_MAVERICK)
11688 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
11689 break;
11690
8cb51566 11691 case EF_ARM_EABI_VER4:
c19d1205 11692 /* No additional flags to set. */
d507cf36
PB
11693 break;
11694
11695 default:
11696 abort ();
11697 }
7cc69913 11698#endif
b99bd4ef
NC
11699 bfd_set_private_flags (stdoutput, flags);
11700
11701 /* We have run out flags in the COFF header to encode the
11702 status of ATPCS support, so instead we create a dummy,
c19d1205 11703 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
11704 if (atpcs)
11705 {
11706 asection * sec;
11707
11708 sec = bfd_make_section (stdoutput, ".arm.atpcs");
11709
11710 if (sec != NULL)
11711 {
11712 bfd_set_section_flags
11713 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
11714 bfd_set_section_size (stdoutput, sec, 0);
11715 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
11716 }
11717 }
7cc69913 11718 }
f17c130b 11719#endif
b99bd4ef
NC
11720
11721 /* Record the CPU type as well. */
11722 switch (cpu_variant & ARM_CPU_MASK)
11723 {
11724 case ARM_2:
11725 mach = bfd_mach_arm_2;
11726 break;
11727
c19d1205 11728 case ARM_3: /* Also ARM_250. */
b99bd4ef
NC
11729 mach = bfd_mach_arm_2a;
11730 break;
11731
c19d1205 11732 case ARM_6: /* Also ARM_7. */
b89dddec
RE
11733 mach = bfd_mach_arm_3;
11734 break;
11735
b99bd4ef 11736 default:
5a6c6817 11737 mach = bfd_mach_arm_unknown;
b99bd4ef 11738 break;
b99bd4ef
NC
11739 }
11740
11741 /* Catch special cases. */
e16bb312
NC
11742 if (cpu_variant & ARM_CEXT_IWMMXT)
11743 mach = bfd_mach_arm_iWMMXt;
11744 else if (cpu_variant & ARM_CEXT_XSCALE)
b99bd4ef 11745 mach = bfd_mach_arm_XScale;
fde78edd
NC
11746 else if (cpu_variant & ARM_CEXT_MAVERICK)
11747 mach = bfd_mach_arm_ep9312;
b99bd4ef
NC
11748 else if (cpu_variant & ARM_EXT_V5E)
11749 mach = bfd_mach_arm_5TE;
11750 else if (cpu_variant & ARM_EXT_V5)
11751 {
b89dddec 11752 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11753 mach = bfd_mach_arm_5T;
11754 else
11755 mach = bfd_mach_arm_5;
11756 }
b89dddec 11757 else if (cpu_variant & ARM_EXT_V4)
b99bd4ef 11758 {
b89dddec 11759 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11760 mach = bfd_mach_arm_4T;
11761 else
11762 mach = bfd_mach_arm_4;
11763 }
b89dddec 11764 else if (cpu_variant & ARM_EXT_V3M)
b99bd4ef
NC
11765 mach = bfd_mach_arm_3M;
11766
11767 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
11768}
11769
c19d1205 11770/* Command line processing. */
b99bd4ef 11771
c19d1205
ZW
11772/* md_parse_option
11773 Invocation line includes a switch not recognized by the base assembler.
11774 See if it's a processor-specific option.
b99bd4ef 11775
c19d1205
ZW
11776 This routine is somewhat complicated by the need for backwards
11777 compatibility (since older releases of gcc can't be changed).
11778 The new options try to make the interface as compatible as
11779 possible with GCC.
b99bd4ef 11780
c19d1205 11781 New options (supported) are:
b99bd4ef 11782
c19d1205
ZW
11783 -mcpu=<cpu name> Assemble for selected processor
11784 -march=<architecture name> Assemble for selected architecture
11785 -mfpu=<fpu architecture> Assemble for selected FPU.
11786 -EB/-mbig-endian Big-endian
11787 -EL/-mlittle-endian Little-endian
11788 -k Generate PIC code
11789 -mthumb Start in Thumb mode
11790 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 11791
c19d1205 11792 For now we will also provide support for:
b99bd4ef 11793
c19d1205
ZW
11794 -mapcs-32 32-bit Program counter
11795 -mapcs-26 26-bit Program counter
11796 -macps-float Floats passed in FP registers
11797 -mapcs-reentrant Reentrant code
11798 -matpcs
11799 (sometime these will probably be replaced with -mapcs=<list of options>
11800 and -matpcs=<list of options>)
b99bd4ef 11801
c19d1205
ZW
11802 The remaining options are only supported for back-wards compatibility.
11803 Cpu variants, the arm part is optional:
11804 -m[arm]1 Currently not supported.
11805 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
11806 -m[arm]3 Arm 3 processor
11807 -m[arm]6[xx], Arm 6 processors
11808 -m[arm]7[xx][t][[d]m] Arm 7 processors
11809 -m[arm]8[10] Arm 8 processors
11810 -m[arm]9[20][tdmi] Arm 9 processors
11811 -mstrongarm[110[0]] StrongARM processors
11812 -mxscale XScale processors
11813 -m[arm]v[2345[t[e]]] Arm architectures
11814 -mall All (except the ARM1)
11815 FP variants:
11816 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
11817 -mfpe-old (No float load/store multiples)
11818 -mvfpxd VFP Single precision
11819 -mvfp All VFP
11820 -mno-fpu Disable all floating point instructions
b99bd4ef 11821
c19d1205
ZW
11822 The following CPU names are recognized:
11823 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
11824 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
11825 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
11826 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
11827 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
11828 arm10t arm10e, arm1020t, arm1020e, arm10200e,
11829 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 11830
c19d1205 11831 */
b99bd4ef 11832
c19d1205 11833const char * md_shortopts = "m:k";
b99bd4ef 11834
c19d1205
ZW
11835#ifdef ARM_BI_ENDIAN
11836#define OPTION_EB (OPTION_MD_BASE + 0)
11837#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 11838#else
c19d1205
ZW
11839#if TARGET_BYTES_BIG_ENDIAN
11840#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 11841#else
c19d1205
ZW
11842#define OPTION_EL (OPTION_MD_BASE + 1)
11843#endif
b99bd4ef 11844#endif
b99bd4ef 11845
c19d1205 11846struct option md_longopts[] =
b99bd4ef 11847{
c19d1205
ZW
11848#ifdef OPTION_EB
11849 {"EB", no_argument, NULL, OPTION_EB},
11850#endif
11851#ifdef OPTION_EL
11852 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 11853#endif
c19d1205
ZW
11854 {NULL, no_argument, NULL, 0}
11855};
b99bd4ef 11856
c19d1205 11857size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 11858
c19d1205 11859struct arm_option_table
b99bd4ef 11860{
c19d1205
ZW
11861 char *option; /* Option name to match. */
11862 char *help; /* Help information. */
11863 int *var; /* Variable to change. */
11864 int value; /* What to change it to. */
11865 char *deprecated; /* If non-null, print this message. */
11866};
b99bd4ef 11867
c19d1205
ZW
11868struct arm_option_table arm_opts[] =
11869{
11870 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
11871 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
11872 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
11873 &support_interwork, 1, NULL},
11874 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
11875 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
11876 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
11877 1, NULL},
11878 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
11879 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
11880 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
11881 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
11882 NULL},
b99bd4ef 11883
c19d1205
ZW
11884 /* These are recognized by the assembler, but have no affect on code. */
11885 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
11886 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
b99bd4ef 11887
c19d1205
ZW
11888 /* DON'T add any new processors to this list -- we want the whole list
11889 to go away... Add them to the processors table instead. */
11890 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11891 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11892 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11893 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11894 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11895 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11896 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11897 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11898 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11899 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11900 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11901 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11902 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11903 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11904 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11905 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11906 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11907 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11908 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11909 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11910 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11911 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11912 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11913 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11914 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11915 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11916 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11917 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11918 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11919 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11920 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11921 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11922 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11923 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11924 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11925 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11926 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11927 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11928 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11929 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11930 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11931 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11932 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11933 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11934 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11935 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11936 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11937 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11938 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11939 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11940 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11941 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11942 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11943 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11944 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11945 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11946 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11947 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11948 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11949 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11950 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11951 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11952 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11953 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11954 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11955 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11956 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11957 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11958 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
11959 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
11960 N_("use -mcpu=strongarm110")},
11961 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
11962 N_("use -mcpu=strongarm1100")},
11963 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
11964 N_("use -mcpu=strongarm1110")},
11965 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
11966 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
11967 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 11968
c19d1205
ZW
11969 /* Architecture variants -- don't add any more to this list either. */
11970 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11971 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11972 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11973 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11974 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11975 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11976 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11977 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11978 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11979 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11980 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11981 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11982 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11983 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11984 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11985 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11986 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
11987 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 11988
c19d1205
ZW
11989 /* Floating point variants -- don't add any more to this list either. */
11990 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
11991 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
11992 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
11993 {"mno-fpu", NULL, &legacy_fpu, 0,
11994 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 11995
c19d1205
ZW
11996 {NULL, NULL, NULL, 0, NULL}
11997};
7ed4c4c5 11998
c19d1205 11999struct arm_cpu_option_table
7ed4c4c5 12000{
c19d1205
ZW
12001 char *name;
12002 int value;
12003 /* For some CPUs we assume an FPU unless the user explicitly sets
12004 -mfpu=... */
12005 int default_fpu;
12006};
7ed4c4c5 12007
c19d1205
ZW
12008/* This list should, at a minimum, contain all the cpu names
12009 recognized by GCC. */
12010static struct arm_cpu_option_table arm_cpus[] =
12011{
12012 {"all", ARM_ANY, FPU_ARCH_FPA},
12013 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA},
12014 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA},
12015 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA},
12016 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA},
12017 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA},
12018 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA},
12019 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA},
12020 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA},
12021 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA},
12022 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA},
12023 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12024 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA},
12025 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA},
12026 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA},
12027 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA},
12028 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA},
12029 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA},
12030 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA},
12031 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA},
12032 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12033 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA},
12034 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12035 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12036 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA},
12037 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA},
12038 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA},
12039 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA},
12040 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12041 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12042 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA},
12043 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA},
12044 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA},
12045 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA},
12046 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA},
12047 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA},
12048 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA},
12049 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA},
12050 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA},
12051 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA},
12052 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12053 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12054 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12055 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12056 /* For V5 or later processors we default to using VFP; but the user
12057 should really set the FPU type explicitly. */
12058 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12059 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12060 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12061 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12062 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12063 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12064 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12065 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12066 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12067 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12068 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12069 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12070 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12071 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12072 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12073 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12074 {"arm1136js", ARM_ARCH_V6, FPU_NONE},
12075 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE},
12076 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12077 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12078 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2},
12079 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE},
12080 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE},
12081 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2},
12082 /* ??? XSCALE is really an architecture. */
12083 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12084 /* ??? iwmmxt is not a processor. */
12085 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2},
12086 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12087 /* Maverick */
12088 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK},
12089 {NULL, 0, 0}
12090};
7ed4c4c5 12091
c19d1205 12092struct arm_arch_option_table
7ed4c4c5 12093{
c19d1205
ZW
12094 char *name;
12095 int value;
12096 int default_fpu;
12097};
7ed4c4c5 12098
c19d1205
ZW
12099/* This list should, at a minimum, contain all the architecture names
12100 recognized by GCC. */
12101static struct arm_arch_option_table arm_archs[] =
12102{
12103 {"all", ARM_ANY, FPU_ARCH_FPA},
12104 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12105 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12106 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12107 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12108 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12109 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12110 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12111 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12112 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12113 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12114 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12115 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12116 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12117 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12118 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12119 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12120 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12121 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12122 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12123 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12124 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12125 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12126 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12127 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12128 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12129 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12130 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12131 {NULL, 0, 0}
12132};
7ed4c4c5 12133
c19d1205
ZW
12134/* ISA extensions in the co-processor space. */
12135struct arm_option_value_table
12136{
12137 char *name;
12138 int value;
12139};
7ed4c4c5 12140
c19d1205
ZW
12141static struct arm_option_value_table arm_extensions[] =
12142{
12143 {"maverick", ARM_CEXT_MAVERICK},
12144 {"xscale", ARM_CEXT_XSCALE},
12145 {"iwmmxt", ARM_CEXT_IWMMXT},
12146 {NULL, 0}
12147};
7ed4c4c5 12148
c19d1205
ZW
12149/* This list should, at a minimum, contain all the fpu names
12150 recognized by GCC. */
12151static struct arm_option_value_table arm_fpus[] =
12152{
12153 {"softfpa", FPU_NONE},
12154 {"fpe", FPU_ARCH_FPE},
12155 {"fpe2", FPU_ARCH_FPE},
12156 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12157 {"fpa", FPU_ARCH_FPA},
12158 {"fpa10", FPU_ARCH_FPA},
12159 {"fpa11", FPU_ARCH_FPA},
12160 {"arm7500fe", FPU_ARCH_FPA},
12161 {"softvfp", FPU_ARCH_VFP},
12162 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12163 {"vfp", FPU_ARCH_VFP_V2},
12164 {"vfp9", FPU_ARCH_VFP_V2},
12165 {"vfp10", FPU_ARCH_VFP_V2},
12166 {"vfp10-r0", FPU_ARCH_VFP_V1},
12167 {"vfpxd", FPU_ARCH_VFP_V1xD},
12168 {"arm1020t", FPU_ARCH_VFP_V1},
12169 {"arm1020e", FPU_ARCH_VFP_V2},
12170 {"arm1136jfs", FPU_ARCH_VFP_V2},
12171 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12172 {"maverick", FPU_ARCH_MAVERICK},
12173 {NULL, 0}
12174};
7ed4c4c5 12175
c19d1205
ZW
12176static struct arm_option_value_table arm_float_abis[] =
12177{
12178 {"hard", ARM_FLOAT_ABI_HARD},
12179 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12180 {"soft", ARM_FLOAT_ABI_SOFT},
12181 {NULL, 0}
12182};
7ed4c4c5 12183
c19d1205
ZW
12184#ifdef OBJ_ELF
12185/* We only know how to output GNU and ver 4 (AAELF) formats. */
12186static struct arm_option_value_table arm_eabis[] =
12187{
12188 {"gnu", EF_ARM_EABI_UNKNOWN},
12189 {"4", EF_ARM_EABI_VER4},
12190 {NULL, 0}
12191};
12192#endif
7ed4c4c5 12193
c19d1205
ZW
12194struct arm_long_option_table
12195{
12196 char * option; /* Substring to match. */
12197 char * help; /* Help information. */
12198 int (* func) (char * subopt); /* Function to decode sub-option. */
12199 char * deprecated; /* If non-null, print this message. */
12200};
7ed4c4c5
NC
12201
12202static int
c19d1205 12203arm_parse_extension (char * str, int * opt_p)
7ed4c4c5 12204{
c19d1205 12205 while (str != NULL && *str != 0)
7ed4c4c5 12206 {
c19d1205
ZW
12207 struct arm_option_value_table * opt;
12208 char * ext;
12209 int optlen;
7ed4c4c5 12210
c19d1205
ZW
12211 if (*str != '+')
12212 {
12213 as_bad (_("invalid architectural extension"));
12214 return 0;
12215 }
7ed4c4c5 12216
c19d1205
ZW
12217 str++;
12218 ext = strchr (str, '+');
7ed4c4c5 12219
c19d1205
ZW
12220 if (ext != NULL)
12221 optlen = ext - str;
12222 else
12223 optlen = strlen (str);
7ed4c4c5 12224
c19d1205
ZW
12225 if (optlen == 0)
12226 {
12227 as_bad (_("missing architectural extension"));
12228 return 0;
12229 }
7ed4c4c5 12230
c19d1205
ZW
12231 for (opt = arm_extensions; opt->name != NULL; opt++)
12232 if (strncmp (opt->name, str, optlen) == 0)
12233 {
12234 *opt_p |= opt->value;
12235 break;
12236 }
7ed4c4c5 12237
c19d1205
ZW
12238 if (opt->name == NULL)
12239 {
12240 as_bad (_("unknown architectural extnsion `%s'"), str);
12241 return 0;
12242 }
7ed4c4c5 12243
c19d1205
ZW
12244 str = ext;
12245 };
7ed4c4c5 12246
c19d1205
ZW
12247 return 1;
12248}
7ed4c4c5 12249
c19d1205
ZW
12250static int
12251arm_parse_cpu (char * str)
7ed4c4c5 12252{
c19d1205
ZW
12253 struct arm_cpu_option_table * opt;
12254 char * ext = strchr (str, '+');
12255 int optlen;
7ed4c4c5 12256
c19d1205
ZW
12257 if (ext != NULL)
12258 optlen = ext - str;
7ed4c4c5 12259 else
c19d1205 12260 optlen = strlen (str);
7ed4c4c5 12261
c19d1205 12262 if (optlen == 0)
7ed4c4c5 12263 {
c19d1205
ZW
12264 as_bad (_("missing cpu name `%s'"), str);
12265 return 0;
7ed4c4c5
NC
12266 }
12267
c19d1205
ZW
12268 for (opt = arm_cpus; opt->name != NULL; opt++)
12269 if (strncmp (opt->name, str, optlen) == 0)
12270 {
12271 mcpu_cpu_opt = opt->value;
12272 mcpu_fpu_opt = opt->default_fpu;
7ed4c4c5 12273
c19d1205
ZW
12274 if (ext != NULL)
12275 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 12276
c19d1205
ZW
12277 return 1;
12278 }
7ed4c4c5 12279
c19d1205
ZW
12280 as_bad (_("unknown cpu `%s'"), str);
12281 return 0;
7ed4c4c5
NC
12282}
12283
c19d1205
ZW
12284static int
12285arm_parse_arch (char * str)
7ed4c4c5 12286{
c19d1205
ZW
12287 struct arm_arch_option_table *opt;
12288 char *ext = strchr (str, '+');
12289 int optlen;
7ed4c4c5 12290
c19d1205
ZW
12291 if (ext != NULL)
12292 optlen = ext - str;
7ed4c4c5 12293 else
c19d1205 12294 optlen = strlen (str);
7ed4c4c5 12295
c19d1205 12296 if (optlen == 0)
7ed4c4c5 12297 {
c19d1205
ZW
12298 as_bad (_("missing architecture name `%s'"), str);
12299 return 0;
7ed4c4c5
NC
12300 }
12301
7ed4c4c5 12302
c19d1205
ZW
12303 for (opt = arm_archs; opt->name != NULL; opt++)
12304 if (streq (opt->name, str))
12305 {
12306 march_cpu_opt = opt->value;
12307 march_fpu_opt = opt->default_fpu;
7ed4c4c5 12308
c19d1205
ZW
12309 if (ext != NULL)
12310 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 12311
c19d1205
ZW
12312 return 1;
12313 }
12314
12315 as_bad (_("unknown architecture `%s'\n"), str);
12316 return 0;
7ed4c4c5 12317}
eb043451 12318
c19d1205
ZW
12319static int
12320arm_parse_fpu (char * str)
12321{
12322 struct arm_option_value_table * opt;
b99bd4ef 12323
c19d1205
ZW
12324 for (opt = arm_fpus; opt->name != NULL; opt++)
12325 if (streq (opt->name, str))
12326 {
12327 mfpu_opt = opt->value;
12328 return 1;
12329 }
b99bd4ef 12330
c19d1205
ZW
12331 as_bad (_("unknown floating point format `%s'\n"), str);
12332 return 0;
12333}
12334
12335static int
12336arm_parse_float_abi (char * str)
b99bd4ef 12337{
c19d1205 12338 struct arm_option_value_table * opt;
b99bd4ef 12339
c19d1205
ZW
12340 for (opt = arm_float_abis; opt->name != NULL; opt++)
12341 if (streq (opt->name, str))
12342 {
12343 mfloat_abi_opt = opt->value;
12344 return 1;
12345 }
cc8a6dd0 12346
c19d1205
ZW
12347 as_bad (_("unknown floating point abi `%s'\n"), str);
12348 return 0;
12349}
b99bd4ef 12350
c19d1205
ZW
12351#ifdef OBJ_ELF
12352static int
12353arm_parse_eabi (char * str)
12354{
12355 struct arm_option_value_table *opt;
cc8a6dd0 12356
c19d1205
ZW
12357 for (opt = arm_eabis; opt->name != NULL; opt++)
12358 if (streq (opt->name, str))
12359 {
12360 meabi_flags = opt->value;
12361 return 1;
12362 }
12363 as_bad (_("unknown EABI `%s'\n"), str);
12364 return 0;
12365}
12366#endif
cc8a6dd0 12367
c19d1205
ZW
12368struct arm_long_option_table arm_long_opts[] =
12369{
12370 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
12371 arm_parse_cpu, NULL},
12372 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
12373 arm_parse_arch, NULL},
12374 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
12375 arm_parse_fpu, NULL},
12376 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
12377 arm_parse_float_abi, NULL},
12378#ifdef OBJ_ELF
12379 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
12380 arm_parse_eabi, NULL},
12381#endif
12382 {NULL, NULL, 0, NULL}
12383};
cc8a6dd0 12384
c19d1205
ZW
12385int
12386md_parse_option (int c, char * arg)
12387{
12388 struct arm_option_table *opt;
12389 struct arm_long_option_table *lopt;
b99bd4ef 12390
c19d1205 12391 switch (c)
b99bd4ef 12392 {
c19d1205
ZW
12393#ifdef OPTION_EB
12394 case OPTION_EB:
12395 target_big_endian = 1;
12396 break;
12397#endif
cc8a6dd0 12398
c19d1205
ZW
12399#ifdef OPTION_EL
12400 case OPTION_EL:
12401 target_big_endian = 0;
12402 break;
12403#endif
b99bd4ef 12404
c19d1205
ZW
12405 case 'a':
12406 /* Listing option. Just ignore these, we don't support additional
12407 ones. */
12408 return 0;
b99bd4ef 12409
c19d1205
ZW
12410 default:
12411 for (opt = arm_opts; opt->option != NULL; opt++)
12412 {
12413 if (c == opt->option[0]
12414 && ((arg == NULL && opt->option[1] == 0)
12415 || streq (arg, opt->option + 1)))
12416 {
12417#if WARN_DEPRECATED
12418 /* If the option is deprecated, tell the user. */
12419 if (opt->deprecated != NULL)
12420 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
12421 arg ? arg : "", _(opt->deprecated));
12422#endif
b99bd4ef 12423
c19d1205
ZW
12424 if (opt->var != NULL)
12425 *opt->var = opt->value;
cc8a6dd0 12426
c19d1205
ZW
12427 return 1;
12428 }
12429 }
b99bd4ef 12430
c19d1205
ZW
12431 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12432 {
12433 /* These options are expected to have an argument. */
12434 if (c == lopt->option[0]
12435 && arg != NULL
12436 && strncmp (arg, lopt->option + 1,
12437 strlen (lopt->option + 1)) == 0)
12438 {
12439#if WARN_DEPRECATED
12440 /* If the option is deprecated, tell the user. */
12441 if (lopt->deprecated != NULL)
12442 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
12443 _(lopt->deprecated));
12444#endif
b99bd4ef 12445
c19d1205
ZW
12446 /* Call the sup-option parser. */
12447 return lopt->func (arg + strlen (lopt->option) - 1);
12448 }
12449 }
a737bd4d 12450
c19d1205
ZW
12451 return 0;
12452 }
a394c00f 12453
c19d1205
ZW
12454 return 1;
12455}
a394c00f 12456
c19d1205
ZW
12457void
12458md_show_usage (FILE * fp)
a394c00f 12459{
c19d1205
ZW
12460 struct arm_option_table *opt;
12461 struct arm_long_option_table *lopt;
a394c00f 12462
c19d1205 12463 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 12464
c19d1205
ZW
12465 for (opt = arm_opts; opt->option != NULL; opt++)
12466 if (opt->help != NULL)
12467 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 12468
c19d1205
ZW
12469 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12470 if (lopt->help != NULL)
12471 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 12472
c19d1205
ZW
12473#ifdef OPTION_EB
12474 fprintf (fp, _("\
12475 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
12476#endif
12477
c19d1205
ZW
12478#ifdef OPTION_EL
12479 fprintf (fp, _("\
12480 -EL assemble code for a little-endian cpu\n"));
a737bd4d 12481#endif
c19d1205 12482}
This page took 1.043466 seconds and 4 git commands to generate.