]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
2005-08-05 Paul Brook <paul@codesourcery.com>
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b
AM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
b99bd4ef 28#include <string.h>
c19d1205 29#define NO_RELOC 0
b99bd4ef 30#include "as.h"
3882b010 31#include "safe-ctype.h"
b99bd4ef
NC
32
33/* Need TARGET_CPU. */
34#include "config.h"
35#include "subsegs.h"
36#include "obstack.h"
37#include "symbols.h"
38#include "listing.h"
39
f263249b
RE
40#include "opcode/arm.h"
41
b99bd4ef
NC
42#ifdef OBJ_ELF
43#include "elf/arm.h"
44#include "dwarf2dbg.h"
a394c00f 45#include "dw2gencfi.h"
b99bd4ef
NC
46#endif
47
7ed4c4c5 48/* XXX Set this to 1 after the next binutils release. */
03b1477f
RE
49#define WARN_DEPRECATED 0
50
7ed4c4c5
NC
51#ifdef OBJ_ELF
52/* Must be at least the size of the largest unwind opcode (currently two). */
53#define ARM_OPCODE_CHUNK_SIZE 8
54
55/* This structure holds the unwinding state. */
56
57static struct
58{
c19d1205
ZW
59 symbolS * proc_start;
60 symbolS * table_entry;
61 symbolS * personality_routine;
62 int personality_index;
7ed4c4c5 63 /* The segment containing the function. */
c19d1205
ZW
64 segT saved_seg;
65 subsegT saved_subseg;
7ed4c4c5
NC
66 /* Opcodes generated from this function. */
67 unsigned char * opcodes;
c19d1205
ZW
68 int opcode_count;
69 int opcode_alloc;
7ed4c4c5 70 /* The number of bytes pushed to the stack. */
c19d1205 71 offsetT frame_size;
7ed4c4c5
NC
72 /* We don't add stack adjustment opcodes immediately so that we can merge
73 multiple adjustments. We can also omit the final adjustment
74 when using a frame pointer. */
c19d1205 75 offsetT pending_offset;
7ed4c4c5 76 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
77 hold the reg+offset to use when restoring sp from a frame pointer. */
78 offsetT fp_offset;
79 int fp_reg;
7ed4c4c5 80 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 81 unsigned fp_used:1;
7ed4c4c5 82 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 83 unsigned sp_restored:1;
7ed4c4c5
NC
84} unwind;
85
84798bd6
JB
86/* Bit N indicates that an R_ARM_NONE relocation has been output for
87 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
88 emitted only once per section, to save unnecessary bloat. */
89static unsigned int marked_pr_dependency = 0;
90
7ed4c4c5
NC
91#endif /* OBJ_ELF */
92
33a392fb
PB
93enum arm_float_abi
94{
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98};
99
c19d1205 100/* Types of processor to assemble for. */
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;
ca3f61f7
NC
229 signed int 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). */
c19d1205 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
2fc8bdac 488#define T_OPCODE_BRANCH 0xe000
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 1037static int
ca3f61f7 1038parse_vfp_reg_list (char **str, unsigned 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
37f6032b
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. We check
1420 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1421 the ".real_start_of" convention for nonlocal branches. */
1422 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
1423 return symbolP;
1424
37f6032b 1425 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
1426 new_target = symbol_find (real_start);
1427
1428 if (new_target == NULL)
1429 {
1430 as_warn ("Failed to find real start of function: %s\n", name);
1431 new_target = symbolP;
1432 }
1433
c19d1205
ZW
1434 return new_target;
1435}
1436
1437static void
1438opcode_select (int width)
1439{
1440 switch (width)
1441 {
1442 case 16:
1443 if (! thumb_mode)
1444 {
1445 if (! (cpu_variant & ARM_EXT_V4T))
1446 as_bad (_("selected processor does not support THUMB opcodes"));
1447
1448 thumb_mode = 1;
1449 /* No need to force the alignment, since we will have been
1450 coming from ARM mode, which is word-aligned. */
1451 record_alignment (now_seg, 1);
1452 }
1453 mapping_state (MAP_THUMB);
1454 break;
1455
1456 case 32:
1457 if (thumb_mode)
1458 {
1459 if ((cpu_variant & ARM_ALL) == ARM_EXT_V4T)
1460 as_bad (_("selected processor does not support ARM opcodes"));
1461
1462 thumb_mode = 0;
1463
1464 if (!need_pass_2)
1465 frag_align (2, 0, 0);
1466
1467 record_alignment (now_seg, 1);
1468 }
1469 mapping_state (MAP_ARM);
1470 break;
1471
1472 default:
1473 as_bad (_("invalid instruction size selected (%d)"), width);
1474 }
1475}
1476
1477static void
1478s_arm (int ignore ATTRIBUTE_UNUSED)
1479{
1480 opcode_select (32);
1481 demand_empty_rest_of_line ();
1482}
1483
1484static void
1485s_thumb (int ignore ATTRIBUTE_UNUSED)
1486{
1487 opcode_select (16);
1488 demand_empty_rest_of_line ();
1489}
1490
1491static void
1492s_code (int unused ATTRIBUTE_UNUSED)
1493{
1494 int temp;
1495
1496 temp = get_absolute_expression ();
1497 switch (temp)
1498 {
1499 case 16:
1500 case 32:
1501 opcode_select (temp);
1502 break;
1503
1504 default:
1505 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1506 }
1507}
1508
1509static void
1510s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1511{
1512 /* If we are not already in thumb mode go into it, EVEN if
1513 the target processor does not support thumb instructions.
1514 This is used by gcc/config/arm/lib1funcs.asm for example
1515 to compile interworking support functions even if the
1516 target processor should not support interworking. */
1517 if (! thumb_mode)
1518 {
1519 thumb_mode = 2;
1520 record_alignment (now_seg, 1);
1521 }
1522
1523 demand_empty_rest_of_line ();
1524}
1525
1526static void
1527s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1528{
1529 s_thumb (0);
1530
1531 /* The following label is the name/address of the start of a Thumb function.
1532 We need to know this for the interworking support. */
1533 label_is_thumb_function_name = TRUE;
1534}
1535
1536/* Perform a .set directive, but also mark the alias as
1537 being a thumb function. */
1538
1539static void
1540s_thumb_set (int equiv)
1541{
1542 /* XXX the following is a duplicate of the code for s_set() in read.c
1543 We cannot just call that code as we need to get at the symbol that
1544 is created. */
1545 char * name;
1546 char delim;
1547 char * end_name;
1548 symbolS * symbolP;
1549
1550 /* Especial apologies for the random logic:
1551 This just grew, and could be parsed much more simply!
1552 Dean - in haste. */
1553 name = input_line_pointer;
1554 delim = get_symbol_end ();
1555 end_name = input_line_pointer;
1556 *end_name = delim;
1557
1558 if (*input_line_pointer != ',')
1559 {
1560 *end_name = 0;
1561 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1562 *end_name = delim;
1563 ignore_rest_of_line ();
1564 return;
1565 }
1566
1567 input_line_pointer++;
1568 *end_name = 0;
1569
1570 if (name[0] == '.' && name[1] == '\0')
1571 {
1572 /* XXX - this should not happen to .thumb_set. */
1573 abort ();
1574 }
1575
1576 if ((symbolP = symbol_find (name)) == NULL
1577 && (symbolP = md_undefined_symbol (name)) == NULL)
1578 {
1579#ifndef NO_LISTING
1580 /* When doing symbol listings, play games with dummy fragments living
1581 outside the normal fragment chain to record the file and line info
c19d1205 1582 for this symbol. */
b99bd4ef
NC
1583 if (listing & LISTING_SYMBOLS)
1584 {
1585 extern struct list_info_struct * listing_tail;
a737bd4d 1586 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1587
1588 memset (dummy_frag, 0, sizeof (fragS));
1589 dummy_frag->fr_type = rs_fill;
1590 dummy_frag->line = listing_tail;
1591 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1592 dummy_frag->fr_symbol = symbolP;
1593 }
1594 else
1595#endif
1596 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1597
1598#ifdef OBJ_COFF
1599 /* "set" symbols are local unless otherwise specified. */
1600 SF_SET_LOCAL (symbolP);
1601#endif /* OBJ_COFF */
1602 } /* Make a new symbol. */
1603
1604 symbol_table_insert (symbolP);
1605
1606 * end_name = delim;
1607
1608 if (equiv
1609 && S_IS_DEFINED (symbolP)
1610 && S_GET_SEGMENT (symbolP) != reg_section)
1611 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1612
1613 pseudo_set (symbolP);
1614
1615 demand_empty_rest_of_line ();
1616
c19d1205 1617 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1618
1619 THUMB_SET_FUNC (symbolP, 1);
1620 ARM_SET_THUMB (symbolP, 1);
1621#if defined OBJ_ELF || defined OBJ_COFF
1622 ARM_SET_INTERWORK (symbolP, support_interwork);
1623#endif
1624}
1625
c19d1205 1626/* Directives: Mode selection. */
b99bd4ef 1627
c19d1205
ZW
1628/* .syntax [unified|divided] - choose the new unified syntax
1629 (same for Arm and Thumb encoding, modulo slight differences in what
1630 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1631static void
c19d1205 1632s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1633{
c19d1205
ZW
1634 char *name, delim;
1635
1636 name = input_line_pointer;
1637 delim = get_symbol_end ();
1638
1639 if (!strcasecmp (name, "unified"))
1640 unified_syntax = TRUE;
1641 else if (!strcasecmp (name, "divided"))
1642 unified_syntax = FALSE;
1643 else
1644 {
1645 as_bad (_("unrecognized syntax mode \"%s\""), name);
1646 return;
1647 }
1648 *input_line_pointer = delim;
b99bd4ef
NC
1649 demand_empty_rest_of_line ();
1650}
1651
c19d1205
ZW
1652/* Directives: sectioning and alignment. */
1653
1654/* Same as s_align_ptwo but align 0 => align 2. */
1655
b99bd4ef 1656static void
c19d1205 1657s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1658{
a737bd4d 1659 int temp;
c19d1205
ZW
1660 long temp_fill;
1661 long max_alignment = 15;
b99bd4ef
NC
1662
1663 temp = get_absolute_expression ();
c19d1205
ZW
1664 if (temp > max_alignment)
1665 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1666 else if (temp < 0)
b99bd4ef 1667 {
c19d1205
ZW
1668 as_bad (_("alignment negative. 0 assumed."));
1669 temp = 0;
1670 }
b99bd4ef 1671
c19d1205
ZW
1672 if (*input_line_pointer == ',')
1673 {
1674 input_line_pointer++;
1675 temp_fill = get_absolute_expression ();
b99bd4ef 1676 }
c19d1205
ZW
1677 else
1678 temp_fill = 0;
b99bd4ef 1679
c19d1205
ZW
1680 if (!temp)
1681 temp = 2;
b99bd4ef 1682
c19d1205
ZW
1683 /* Only make a frag if we HAVE to. */
1684 if (temp && !need_pass_2)
1685 frag_align (temp, (int) temp_fill, 0);
1686 demand_empty_rest_of_line ();
1687
1688 record_alignment (now_seg, temp);
b99bd4ef
NC
1689}
1690
c19d1205
ZW
1691static void
1692s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1693{
c19d1205
ZW
1694 /* We don't support putting frags in the BSS segment, we fake it by
1695 marking in_bss, then looking at s_skip for clues. */
1696 subseg_set (bss_section, 0);
1697 demand_empty_rest_of_line ();
1698 mapping_state (MAP_DATA);
1699}
b99bd4ef 1700
c19d1205
ZW
1701static void
1702s_even (int ignore ATTRIBUTE_UNUSED)
1703{
1704 /* Never make frag if expect extra pass. */
1705 if (!need_pass_2)
1706 frag_align (1, 0, 0);
b99bd4ef 1707
c19d1205 1708 record_alignment (now_seg, 1);
b99bd4ef 1709
c19d1205 1710 demand_empty_rest_of_line ();
b99bd4ef
NC
1711}
1712
c19d1205 1713/* Directives: Literal pools. */
a737bd4d 1714
c19d1205
ZW
1715static literal_pool *
1716find_literal_pool (void)
a737bd4d 1717{
c19d1205 1718 literal_pool * pool;
a737bd4d 1719
c19d1205 1720 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1721 {
c19d1205
ZW
1722 if (pool->section == now_seg
1723 && pool->sub_section == now_subseg)
1724 break;
a737bd4d
NC
1725 }
1726
c19d1205 1727 return pool;
a737bd4d
NC
1728}
1729
c19d1205
ZW
1730static literal_pool *
1731find_or_make_literal_pool (void)
a737bd4d 1732{
c19d1205
ZW
1733 /* Next literal pool ID number. */
1734 static unsigned int latest_pool_num = 1;
1735 literal_pool * pool;
a737bd4d 1736
c19d1205 1737 pool = find_literal_pool ();
a737bd4d 1738
c19d1205 1739 if (pool == NULL)
a737bd4d 1740 {
c19d1205
ZW
1741 /* Create a new pool. */
1742 pool = xmalloc (sizeof (* pool));
1743 if (! pool)
1744 return NULL;
a737bd4d 1745
c19d1205
ZW
1746 pool->next_free_entry = 0;
1747 pool->section = now_seg;
1748 pool->sub_section = now_subseg;
1749 pool->next = list_of_pools;
1750 pool->symbol = NULL;
1751
1752 /* Add it to the list. */
1753 list_of_pools = pool;
a737bd4d 1754 }
a737bd4d 1755
c19d1205
ZW
1756 /* New pools, and emptied pools, will have a NULL symbol. */
1757 if (pool->symbol == NULL)
a737bd4d 1758 {
c19d1205
ZW
1759 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1760 (valueT) 0, &zero_address_frag);
1761 pool->id = latest_pool_num ++;
a737bd4d
NC
1762 }
1763
c19d1205
ZW
1764 /* Done. */
1765 return pool;
a737bd4d
NC
1766}
1767
c19d1205
ZW
1768/* Add the literal in the global 'inst'
1769 structure to the relevent literal pool. */
b99bd4ef
NC
1770
1771static int
c19d1205 1772add_to_lit_pool (void)
b99bd4ef 1773{
c19d1205
ZW
1774 literal_pool * pool;
1775 unsigned int entry;
b99bd4ef 1776
c19d1205
ZW
1777 pool = find_or_make_literal_pool ();
1778
1779 /* Check if this literal value is already in the pool. */
1780 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1781 {
c19d1205
ZW
1782 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1783 && (inst.reloc.exp.X_op == O_constant)
1784 && (pool->literals[entry].X_add_number
1785 == inst.reloc.exp.X_add_number)
1786 && (pool->literals[entry].X_unsigned
1787 == inst.reloc.exp.X_unsigned))
1788 break;
1789
1790 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1791 && (inst.reloc.exp.X_op == O_symbol)
1792 && (pool->literals[entry].X_add_number
1793 == inst.reloc.exp.X_add_number)
1794 && (pool->literals[entry].X_add_symbol
1795 == inst.reloc.exp.X_add_symbol)
1796 && (pool->literals[entry].X_op_symbol
1797 == inst.reloc.exp.X_op_symbol))
1798 break;
b99bd4ef
NC
1799 }
1800
c19d1205
ZW
1801 /* Do we need to create a new entry? */
1802 if (entry == pool->next_free_entry)
1803 {
1804 if (entry >= MAX_LITERAL_POOL_SIZE)
1805 {
1806 inst.error = _("literal pool overflow");
1807 return FAIL;
1808 }
1809
1810 pool->literals[entry] = inst.reloc.exp;
1811 pool->next_free_entry += 1;
1812 }
b99bd4ef 1813
c19d1205
ZW
1814 inst.reloc.exp.X_op = O_symbol;
1815 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1816 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1817
c19d1205 1818 return SUCCESS;
b99bd4ef
NC
1819}
1820
c19d1205
ZW
1821/* Can't use symbol_new here, so have to create a symbol and then at
1822 a later date assign it a value. Thats what these functions do. */
e16bb312 1823
c19d1205
ZW
1824static void
1825symbol_locate (symbolS * symbolP,
1826 const char * name, /* It is copied, the caller can modify. */
1827 segT segment, /* Segment identifier (SEG_<something>). */
1828 valueT valu, /* Symbol value. */
1829 fragS * frag) /* Associated fragment. */
1830{
1831 unsigned int name_length;
1832 char * preserved_copy_of_name;
e16bb312 1833
c19d1205
ZW
1834 name_length = strlen (name) + 1; /* +1 for \0. */
1835 obstack_grow (&notes, name, name_length);
1836 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1837
c19d1205
ZW
1838#ifdef tc_canonicalize_symbol_name
1839 preserved_copy_of_name =
1840 tc_canonicalize_symbol_name (preserved_copy_of_name);
1841#endif
b99bd4ef 1842
c19d1205 1843 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1844
c19d1205
ZW
1845 S_SET_SEGMENT (symbolP, segment);
1846 S_SET_VALUE (symbolP, valu);
1847 symbol_clear_list_pointers (symbolP);
b99bd4ef 1848
c19d1205 1849 symbol_set_frag (symbolP, frag);
b99bd4ef 1850
c19d1205
ZW
1851 /* Link to end of symbol chain. */
1852 {
1853 extern int symbol_table_frozen;
b99bd4ef 1854
c19d1205
ZW
1855 if (symbol_table_frozen)
1856 abort ();
1857 }
b99bd4ef 1858
c19d1205 1859 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1860
c19d1205 1861 obj_symbol_new_hook (symbolP);
b99bd4ef 1862
c19d1205
ZW
1863#ifdef tc_symbol_new_hook
1864 tc_symbol_new_hook (symbolP);
1865#endif
1866
1867#ifdef DEBUG_SYMS
1868 verify_symbol_chain (symbol_rootP, symbol_lastP);
1869#endif /* DEBUG_SYMS */
b99bd4ef
NC
1870}
1871
b99bd4ef 1872
c19d1205
ZW
1873static void
1874s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1875{
c19d1205
ZW
1876 unsigned int entry;
1877 literal_pool * pool;
1878 char sym_name[20];
b99bd4ef 1879
c19d1205
ZW
1880 pool = find_literal_pool ();
1881 if (pool == NULL
1882 || pool->symbol == NULL
1883 || pool->next_free_entry == 0)
1884 return;
b99bd4ef 1885
c19d1205 1886 mapping_state (MAP_DATA);
b99bd4ef 1887
c19d1205
ZW
1888 /* Align pool as you have word accesses.
1889 Only make a frag if we have to. */
1890 if (!need_pass_2)
1891 frag_align (2, 0, 0);
b99bd4ef 1892
c19d1205 1893 record_alignment (now_seg, 2);
b99bd4ef 1894
c19d1205 1895 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1896
c19d1205
ZW
1897 symbol_locate (pool->symbol, sym_name, now_seg,
1898 (valueT) frag_now_fix (), frag_now);
1899 symbol_table_insert (pool->symbol);
b99bd4ef 1900
c19d1205 1901 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1902
c19d1205
ZW
1903#if defined OBJ_COFF || defined OBJ_ELF
1904 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1905#endif
6c43fab6 1906
c19d1205
ZW
1907 for (entry = 0; entry < pool->next_free_entry; entry ++)
1908 /* First output the expression in the instruction to the pool. */
1909 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1910
c19d1205
ZW
1911 /* Mark the pool as empty. */
1912 pool->next_free_entry = 0;
1913 pool->symbol = NULL;
b99bd4ef
NC
1914}
1915
c19d1205
ZW
1916#ifdef OBJ_ELF
1917/* Forward declarations for functions below, in the MD interface
1918 section. */
1919static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1920static valueT create_unwind_entry (int);
1921static void start_unwind_section (const segT, int);
1922static void add_unwind_opcode (valueT, int);
1923static void flush_pending_unwind (void);
b99bd4ef 1924
c19d1205 1925/* Directives: Data. */
b99bd4ef 1926
c19d1205
ZW
1927static void
1928s_arm_elf_cons (int nbytes)
1929{
1930 expressionS exp;
b99bd4ef 1931
c19d1205
ZW
1932#ifdef md_flush_pending_output
1933 md_flush_pending_output ();
1934#endif
b99bd4ef 1935
c19d1205 1936 if (is_it_end_of_statement ())
b99bd4ef 1937 {
c19d1205
ZW
1938 demand_empty_rest_of_line ();
1939 return;
b99bd4ef
NC
1940 }
1941
c19d1205
ZW
1942#ifdef md_cons_align
1943 md_cons_align (nbytes);
1944#endif
b99bd4ef 1945
c19d1205
ZW
1946 mapping_state (MAP_DATA);
1947 do
b99bd4ef 1948 {
c19d1205
ZW
1949 int reloc;
1950 char *base = input_line_pointer;
b99bd4ef 1951
c19d1205 1952 expression (& exp);
b99bd4ef 1953
c19d1205
ZW
1954 if (exp.X_op != O_symbol)
1955 emit_expr (&exp, (unsigned int) nbytes);
1956 else
1957 {
1958 char *before_reloc = input_line_pointer;
1959 reloc = parse_reloc (&input_line_pointer);
1960 if (reloc == -1)
1961 {
1962 as_bad (_("unrecognized relocation suffix"));
1963 ignore_rest_of_line ();
1964 return;
1965 }
1966 else if (reloc == BFD_RELOC_UNUSED)
1967 emit_expr (&exp, (unsigned int) nbytes);
1968 else
1969 {
1970 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
1971 int size = bfd_get_reloc_size (howto);
b99bd4ef 1972
2fc8bdac
ZW
1973 if (reloc == BFD_RELOC_ARM_PLT32)
1974 {
1975 as_bad (_("(plt) is only valid on branch targets"));
1976 reloc = BFD_RELOC_UNUSED;
1977 size = 0;
1978 }
1979
c19d1205 1980 if (size > nbytes)
2fc8bdac 1981 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
1982 howto->name, nbytes);
1983 else
1984 {
1985 /* We've parsed an expression stopping at O_symbol.
1986 But there may be more expression left now that we
1987 have parsed the relocation marker. Parse it again.
1988 XXX Surely there is a cleaner way to do this. */
1989 char *p = input_line_pointer;
1990 int offset;
1991 char *save_buf = alloca (input_line_pointer - base);
1992 memcpy (save_buf, base, input_line_pointer - base);
1993 memmove (base + (input_line_pointer - before_reloc),
1994 base, before_reloc - base);
1995
1996 input_line_pointer = base + (input_line_pointer-before_reloc);
1997 expression (&exp);
1998 memcpy (base, save_buf, p - base);
1999
2000 offset = nbytes - size;
2001 p = frag_more ((int) nbytes);
2002 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2003 size, &exp, 0, reloc);
2004 }
2005 }
2006 }
b99bd4ef 2007 }
c19d1205 2008 while (*input_line_pointer++ == ',');
b99bd4ef 2009
c19d1205
ZW
2010 /* Put terminator back into stream. */
2011 input_line_pointer --;
2012 demand_empty_rest_of_line ();
b99bd4ef
NC
2013}
2014
b99bd4ef 2015
c19d1205 2016/* Parse a .rel31 directive. */
b99bd4ef 2017
c19d1205
ZW
2018static void
2019s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2020{
2021 expressionS exp;
2022 char *p;
2023 valueT highbit;
b99bd4ef 2024
c19d1205
ZW
2025 highbit = 0;
2026 if (*input_line_pointer == '1')
2027 highbit = 0x80000000;
2028 else if (*input_line_pointer != '0')
2029 as_bad (_("expected 0 or 1"));
b99bd4ef 2030
c19d1205
ZW
2031 input_line_pointer++;
2032 if (*input_line_pointer != ',')
2033 as_bad (_("missing comma"));
2034 input_line_pointer++;
b99bd4ef 2035
c19d1205
ZW
2036#ifdef md_flush_pending_output
2037 md_flush_pending_output ();
2038#endif
b99bd4ef 2039
c19d1205
ZW
2040#ifdef md_cons_align
2041 md_cons_align (4);
2042#endif
b99bd4ef 2043
c19d1205 2044 mapping_state (MAP_DATA);
b99bd4ef 2045
c19d1205 2046 expression (&exp);
b99bd4ef 2047
c19d1205
ZW
2048 p = frag_more (4);
2049 md_number_to_chars (p, highbit, 4);
2050 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2051 BFD_RELOC_ARM_PREL31);
b99bd4ef 2052
c19d1205 2053 demand_empty_rest_of_line ();
b99bd4ef
NC
2054}
2055
c19d1205 2056/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2057
c19d1205 2058/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2059
c19d1205
ZW
2060static void
2061s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2062{
2063 demand_empty_rest_of_line ();
2064 /* Mark the start of the function. */
2065 unwind.proc_start = expr_build_dot ();
b99bd4ef 2066
c19d1205
ZW
2067 /* Reset the rest of the unwind info. */
2068 unwind.opcode_count = 0;
2069 unwind.table_entry = NULL;
2070 unwind.personality_routine = NULL;
2071 unwind.personality_index = -1;
2072 unwind.frame_size = 0;
2073 unwind.fp_offset = 0;
2074 unwind.fp_reg = 13;
2075 unwind.fp_used = 0;
2076 unwind.sp_restored = 0;
2077}
b99bd4ef 2078
b99bd4ef 2079
c19d1205
ZW
2080/* Parse a handlerdata directive. Creates the exception handling table entry
2081 for the function. */
b99bd4ef 2082
c19d1205
ZW
2083static void
2084s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2085{
2086 demand_empty_rest_of_line ();
2087 if (unwind.table_entry)
2088 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2089
c19d1205
ZW
2090 create_unwind_entry (1);
2091}
a737bd4d 2092
c19d1205 2093/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2094
c19d1205
ZW
2095static void
2096s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2097{
2098 long where;
2099 char *ptr;
2100 valueT val;
f02232aa 2101
c19d1205 2102 demand_empty_rest_of_line ();
f02232aa 2103
c19d1205
ZW
2104 /* Add eh table entry. */
2105 if (unwind.table_entry == NULL)
2106 val = create_unwind_entry (0);
2107 else
2108 val = 0;
f02232aa 2109
c19d1205
ZW
2110 /* Add index table entry. This is two words. */
2111 start_unwind_section (unwind.saved_seg, 1);
2112 frag_align (2, 0, 0);
2113 record_alignment (now_seg, 2);
b99bd4ef 2114
c19d1205
ZW
2115 ptr = frag_more (8);
2116 where = frag_now_fix () - 8;
f02232aa 2117
c19d1205
ZW
2118 /* Self relative offset of the function start. */
2119 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2120 BFD_RELOC_ARM_PREL31);
f02232aa 2121
c19d1205
ZW
2122 /* Indicate dependency on EHABI-defined personality routines to the
2123 linker, if it hasn't been done already. */
2124 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2125 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2126 {
2127 static const char *const name[] = {
2128 "__aeabi_unwind_cpp_pr0",
2129 "__aeabi_unwind_cpp_pr1",
2130 "__aeabi_unwind_cpp_pr2"
2131 };
2132 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2133 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2134 marked_pr_dependency |= 1 << unwind.personality_index;
2135 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2136 = marked_pr_dependency;
2137 }
f02232aa 2138
c19d1205
ZW
2139 if (val)
2140 /* Inline exception table entry. */
2141 md_number_to_chars (ptr + 4, val, 4);
2142 else
2143 /* Self relative offset of the table entry. */
2144 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2145 BFD_RELOC_ARM_PREL31);
f02232aa 2146
c19d1205
ZW
2147 /* Restore the original section. */
2148 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2149}
f02232aa 2150
f02232aa 2151
c19d1205 2152/* Parse an unwind_cantunwind directive. */
b99bd4ef 2153
c19d1205
ZW
2154static void
2155s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2156{
2157 demand_empty_rest_of_line ();
2158 if (unwind.personality_routine || unwind.personality_index != -1)
2159 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2160
c19d1205
ZW
2161 unwind.personality_index = -2;
2162}
b99bd4ef 2163
b99bd4ef 2164
c19d1205 2165/* Parse a personalityindex directive. */
b99bd4ef 2166
c19d1205
ZW
2167static void
2168s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2169{
2170 expressionS exp;
b99bd4ef 2171
c19d1205
ZW
2172 if (unwind.personality_routine || unwind.personality_index != -1)
2173 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2174
c19d1205 2175 expression (&exp);
b99bd4ef 2176
c19d1205
ZW
2177 if (exp.X_op != O_constant
2178 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2179 {
c19d1205
ZW
2180 as_bad (_("bad personality routine number"));
2181 ignore_rest_of_line ();
2182 return;
b99bd4ef
NC
2183 }
2184
c19d1205 2185 unwind.personality_index = exp.X_add_number;
b99bd4ef 2186
c19d1205
ZW
2187 demand_empty_rest_of_line ();
2188}
e16bb312 2189
e16bb312 2190
c19d1205 2191/* Parse a personality directive. */
e16bb312 2192
c19d1205
ZW
2193static void
2194s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2195{
2196 char *name, *p, c;
a737bd4d 2197
c19d1205
ZW
2198 if (unwind.personality_routine || unwind.personality_index != -1)
2199 as_bad (_("duplicate .personality directive"));
a737bd4d 2200
c19d1205
ZW
2201 name = input_line_pointer;
2202 c = get_symbol_end ();
2203 p = input_line_pointer;
2204 unwind.personality_routine = symbol_find_or_make (name);
2205 *p = c;
2206 demand_empty_rest_of_line ();
2207}
e16bb312 2208
e16bb312 2209
c19d1205 2210/* Parse a directive saving core registers. */
e16bb312 2211
c19d1205
ZW
2212static void
2213s_arm_unwind_save_core (void)
e16bb312 2214{
c19d1205
ZW
2215 valueT op;
2216 long range;
2217 int n;
e16bb312 2218
c19d1205
ZW
2219 range = parse_reg_list (&input_line_pointer);
2220 if (range == FAIL)
e16bb312 2221 {
c19d1205
ZW
2222 as_bad (_("expected register list"));
2223 ignore_rest_of_line ();
2224 return;
2225 }
e16bb312 2226
c19d1205 2227 demand_empty_rest_of_line ();
e16bb312 2228
c19d1205
ZW
2229 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2230 into .unwind_save {..., sp...}. We aren't bothered about the value of
2231 ip because it is clobbered by calls. */
2232 if (unwind.sp_restored && unwind.fp_reg == 12
2233 && (range & 0x3000) == 0x1000)
2234 {
2235 unwind.opcode_count--;
2236 unwind.sp_restored = 0;
2237 range = (range | 0x2000) & ~0x1000;
2238 unwind.pending_offset = 0;
2239 }
e16bb312 2240
c19d1205
ZW
2241 /* See if we can use the short opcodes. These pop a block of upto 8
2242 registers starting with r4, plus maybe r14. */
2243 for (n = 0; n < 8; n++)
2244 {
2245 /* Break at the first non-saved register. */
2246 if ((range & (1 << (n + 4))) == 0)
2247 break;
e16bb312 2248 }
c19d1205
ZW
2249 /* See if there are any other bits set. */
2250 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
e16bb312 2251 {
c19d1205
ZW
2252 /* Use the long form. */
2253 op = 0x8000 | ((range >> 4) & 0xfff);
2254 add_unwind_opcode (op, 2);
e16bb312 2255 }
c19d1205 2256 else
0dd132b6 2257 {
c19d1205
ZW
2258 /* Use the short form. */
2259 if (range & 0x4000)
2260 op = 0xa8; /* Pop r14. */
0dd132b6 2261 else
c19d1205
ZW
2262 op = 0xa0; /* Do not pop r14. */
2263 op |= (n - 1);
2264 add_unwind_opcode (op, 1);
2265 }
0dd132b6 2266
c19d1205
ZW
2267 /* Pop r0-r3. */
2268 if (range & 0xf)
2269 {
2270 op = 0xb100 | (range & 0xf);
2271 add_unwind_opcode (op, 2);
0dd132b6
NC
2272 }
2273
c19d1205
ZW
2274 /* Record the number of bytes pushed. */
2275 for (n = 0; n < 16; n++)
2276 {
2277 if (range & (1 << n))
2278 unwind.frame_size += 4;
2279 }
0dd132b6
NC
2280}
2281
c19d1205
ZW
2282
2283/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2284
2285static void
c19d1205 2286s_arm_unwind_save_fpa (int reg)
b99bd4ef 2287{
c19d1205
ZW
2288 expressionS exp;
2289 int num_regs;
2290 valueT op;
b99bd4ef 2291
c19d1205
ZW
2292 /* Get Number of registers to transfer. */
2293 if (skip_past_comma (&input_line_pointer) != FAIL)
2294 expression (&exp);
2295 else
2296 exp.X_op = O_illegal;
b99bd4ef 2297
c19d1205 2298 if (exp.X_op != O_constant)
b99bd4ef 2299 {
c19d1205
ZW
2300 as_bad (_("expected , <constant>"));
2301 ignore_rest_of_line ();
b99bd4ef
NC
2302 return;
2303 }
2304
c19d1205
ZW
2305 num_regs = exp.X_add_number;
2306
2307 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2308 {
c19d1205
ZW
2309 as_bad (_("number of registers must be in the range [1:4]"));
2310 ignore_rest_of_line ();
b99bd4ef
NC
2311 return;
2312 }
2313
c19d1205 2314 demand_empty_rest_of_line ();
b99bd4ef 2315
c19d1205
ZW
2316 if (reg == 4)
2317 {
2318 /* Short form. */
2319 op = 0xb4 | (num_regs - 1);
2320 add_unwind_opcode (op, 1);
2321 }
b99bd4ef
NC
2322 else
2323 {
c19d1205
ZW
2324 /* Long form. */
2325 op = 0xc800 | (reg << 4) | (num_regs - 1);
2326 add_unwind_opcode (op, 2);
b99bd4ef 2327 }
c19d1205 2328 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2329}
2330
c19d1205
ZW
2331
2332/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2333
2334static void
c19d1205 2335s_arm_unwind_save_vfp (void)
b99bd4ef 2336{
c19d1205 2337 int count;
ca3f61f7 2338 unsigned int reg;
c19d1205 2339 valueT op;
b99bd4ef 2340
c19d1205
ZW
2341 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2342 if (count == FAIL)
b99bd4ef 2343 {
c19d1205
ZW
2344 as_bad (_("expected register list"));
2345 ignore_rest_of_line ();
b99bd4ef
NC
2346 return;
2347 }
2348
c19d1205 2349 demand_empty_rest_of_line ();
b99bd4ef 2350
c19d1205 2351 if (reg == 8)
b99bd4ef 2352 {
c19d1205
ZW
2353 /* Short form. */
2354 op = 0xb8 | (count - 1);
2355 add_unwind_opcode (op, 1);
b99bd4ef 2356 }
c19d1205 2357 else
b99bd4ef 2358 {
c19d1205
ZW
2359 /* Long form. */
2360 op = 0xb300 | (reg << 4) | (count - 1);
2361 add_unwind_opcode (op, 2);
b99bd4ef 2362 }
c19d1205
ZW
2363 unwind.frame_size += count * 8 + 4;
2364}
b99bd4ef 2365
b99bd4ef 2366
c19d1205
ZW
2367/* Parse a directive saving iWMMXt data registers. */
2368
2369static void
2370s_arm_unwind_save_mmxwr (void)
2371{
2372 int reg;
2373 int hi_reg;
2374 int i;
2375 unsigned mask = 0;
2376 valueT op;
b99bd4ef 2377
c19d1205
ZW
2378 if (*input_line_pointer == '{')
2379 input_line_pointer++;
b99bd4ef 2380
c19d1205 2381 do
b99bd4ef 2382 {
c19d1205 2383 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2384
c19d1205 2385 if (reg == FAIL)
b99bd4ef 2386 {
c19d1205
ZW
2387 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2388 goto error;
b99bd4ef
NC
2389 }
2390
c19d1205
ZW
2391 if (mask >> reg)
2392 as_tsktsk (_("register list not in ascending order"));
2393 mask |= 1 << reg;
b99bd4ef 2394
c19d1205
ZW
2395 if (*input_line_pointer == '-')
2396 {
2397 input_line_pointer++;
2398 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2399 if (hi_reg == FAIL)
2400 {
2401 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2402 goto error;
2403 }
2404 else if (reg >= hi_reg)
2405 {
2406 as_bad (_("bad register range"));
2407 goto error;
2408 }
2409 for (; reg < hi_reg; reg++)
2410 mask |= 1 << reg;
2411 }
2412 }
2413 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2414
c19d1205
ZW
2415 if (*input_line_pointer == '}')
2416 input_line_pointer++;
b99bd4ef 2417
c19d1205 2418 demand_empty_rest_of_line ();
b99bd4ef 2419
c19d1205
ZW
2420 /* Generate any deferred opcodes becuuse we're going to be looking at
2421 the list. */
2422 flush_pending_unwind ();
b99bd4ef 2423
c19d1205 2424 for (i = 0; i < 16; i++)
b99bd4ef 2425 {
c19d1205
ZW
2426 if (mask & (1 << i))
2427 unwind.frame_size += 8;
b99bd4ef
NC
2428 }
2429
c19d1205
ZW
2430 /* Attempt to combine with a previous opcode. We do this because gcc
2431 likes to output separate unwind directives for a single block of
2432 registers. */
2433 if (unwind.opcode_count > 0)
b99bd4ef 2434 {
c19d1205
ZW
2435 i = unwind.opcodes[unwind.opcode_count - 1];
2436 if ((i & 0xf8) == 0xc0)
2437 {
2438 i &= 7;
2439 /* Only merge if the blocks are contiguous. */
2440 if (i < 6)
2441 {
2442 if ((mask & 0xfe00) == (1 << 9))
2443 {
2444 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2445 unwind.opcode_count--;
2446 }
2447 }
2448 else if (i == 6 && unwind.opcode_count >= 2)
2449 {
2450 i = unwind.opcodes[unwind.opcode_count - 2];
2451 reg = i >> 4;
2452 i &= 0xf;
b99bd4ef 2453
c19d1205
ZW
2454 op = 0xffff << (reg - 1);
2455 if (reg > 0
2456 || ((mask & op) == (1u << (reg - 1))))
2457 {
2458 op = (1 << (reg + i + 1)) - 1;
2459 op &= ~((1 << reg) - 1);
2460 mask |= op;
2461 unwind.opcode_count -= 2;
2462 }
2463 }
2464 }
b99bd4ef
NC
2465 }
2466
c19d1205
ZW
2467 hi_reg = 15;
2468 /* We want to generate opcodes in the order the registers have been
2469 saved, ie. descending order. */
2470 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2471 {
c19d1205
ZW
2472 /* Save registers in blocks. */
2473 if (reg < 0
2474 || !(mask & (1 << reg)))
2475 {
2476 /* We found an unsaved reg. Generate opcodes to save the
2477 preceeding block. */
2478 if (reg != hi_reg)
2479 {
2480 if (reg == 9)
2481 {
2482 /* Short form. */
2483 op = 0xc0 | (hi_reg - 10);
2484 add_unwind_opcode (op, 1);
2485 }
2486 else
2487 {
2488 /* Long form. */
2489 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2490 add_unwind_opcode (op, 2);
2491 }
2492 }
2493 hi_reg = reg - 1;
2494 }
b99bd4ef
NC
2495 }
2496
c19d1205
ZW
2497 return;
2498error:
2499 ignore_rest_of_line ();
b99bd4ef
NC
2500}
2501
2502static void
c19d1205 2503s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2504{
c19d1205
ZW
2505 int reg;
2506 int hi_reg;
2507 unsigned mask = 0;
2508 valueT op;
b99bd4ef 2509
c19d1205
ZW
2510 if (*input_line_pointer == '{')
2511 input_line_pointer++;
b99bd4ef 2512
c19d1205 2513 do
b99bd4ef 2514 {
c19d1205 2515 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2516
c19d1205
ZW
2517 if (reg == FAIL)
2518 {
2519 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2520 goto error;
2521 }
b99bd4ef 2522
c19d1205
ZW
2523 reg -= 8;
2524 if (mask >> reg)
2525 as_tsktsk (_("register list not in ascending order"));
2526 mask |= 1 << reg;
b99bd4ef 2527
c19d1205
ZW
2528 if (*input_line_pointer == '-')
2529 {
2530 input_line_pointer++;
2531 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2532 if (hi_reg == FAIL)
2533 {
2534 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2535 goto error;
2536 }
2537 else if (reg >= hi_reg)
2538 {
2539 as_bad (_("bad register range"));
2540 goto error;
2541 }
2542 for (; reg < hi_reg; reg++)
2543 mask |= 1 << reg;
2544 }
b99bd4ef 2545 }
c19d1205 2546 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2547
c19d1205
ZW
2548 if (*input_line_pointer == '}')
2549 input_line_pointer++;
b99bd4ef 2550
c19d1205
ZW
2551 demand_empty_rest_of_line ();
2552
2553 /* Generate any deferred opcodes becuuse we're going to be looking at
2554 the list. */
2555 flush_pending_unwind ();
b99bd4ef 2556
c19d1205 2557 for (reg = 0; reg < 16; reg++)
b99bd4ef 2558 {
c19d1205
ZW
2559 if (mask & (1 << reg))
2560 unwind.frame_size += 4;
b99bd4ef 2561 }
c19d1205
ZW
2562 op = 0xc700 | mask;
2563 add_unwind_opcode (op, 2);
2564 return;
2565error:
2566 ignore_rest_of_line ();
b99bd4ef
NC
2567}
2568
c19d1205
ZW
2569
2570/* Parse an unwind_save directive. */
2571
b99bd4ef 2572static void
c19d1205 2573s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2574{
c19d1205
ZW
2575 char *peek;
2576 struct reg_entry *reg;
2577 bfd_boolean had_brace = FALSE;
b99bd4ef 2578
c19d1205
ZW
2579 /* Figure out what sort of save we have. */
2580 peek = input_line_pointer;
b99bd4ef 2581
c19d1205 2582 if (*peek == '{')
b99bd4ef 2583 {
c19d1205
ZW
2584 had_brace = TRUE;
2585 peek++;
b99bd4ef
NC
2586 }
2587
c19d1205 2588 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2589
c19d1205 2590 if (!reg)
b99bd4ef 2591 {
c19d1205
ZW
2592 as_bad (_("register expected"));
2593 ignore_rest_of_line ();
b99bd4ef
NC
2594 return;
2595 }
2596
c19d1205 2597 switch (reg->type)
b99bd4ef 2598 {
c19d1205
ZW
2599 case REG_TYPE_FN:
2600 if (had_brace)
2601 {
2602 as_bad (_("FPA .unwind_save does not take a register list"));
2603 ignore_rest_of_line ();
2604 return;
2605 }
2606 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2607 return;
c19d1205
ZW
2608
2609 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2610 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2611 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2612 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2613
2614 default:
2615 as_bad (_(".unwind_save does not support this kind of register"));
2616 ignore_rest_of_line ();
b99bd4ef 2617 }
c19d1205 2618}
b99bd4ef 2619
b99bd4ef 2620
c19d1205
ZW
2621/* Parse an unwind_movsp directive. */
2622
2623static void
2624s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2625{
2626 int reg;
2627 valueT op;
2628
2629 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2630 if (reg == FAIL)
b99bd4ef 2631 {
c19d1205
ZW
2632 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2633 ignore_rest_of_line ();
b99bd4ef
NC
2634 return;
2635 }
c19d1205 2636 demand_empty_rest_of_line ();
b99bd4ef 2637
c19d1205 2638 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2639 {
c19d1205 2640 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2641 return;
2642 }
2643
c19d1205
ZW
2644 if (unwind.fp_reg != REG_SP)
2645 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2646
c19d1205
ZW
2647 /* Generate opcode to restore the value. */
2648 op = 0x90 | reg;
2649 add_unwind_opcode (op, 1);
2650
2651 /* Record the information for later. */
2652 unwind.fp_reg = reg;
2653 unwind.fp_offset = unwind.frame_size;
2654 unwind.sp_restored = 1;
b05fe5cf
ZW
2655}
2656
c19d1205
ZW
2657/* Parse an unwind_pad directive. */
2658
b05fe5cf 2659static void
c19d1205 2660s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2661{
c19d1205 2662 int offset;
b05fe5cf 2663
c19d1205
ZW
2664 if (immediate_for_directive (&offset) == FAIL)
2665 return;
b99bd4ef 2666
c19d1205
ZW
2667 if (offset & 3)
2668 {
2669 as_bad (_("stack increment must be multiple of 4"));
2670 ignore_rest_of_line ();
2671 return;
2672 }
b99bd4ef 2673
c19d1205
ZW
2674 /* Don't generate any opcodes, just record the details for later. */
2675 unwind.frame_size += offset;
2676 unwind.pending_offset += offset;
2677
2678 demand_empty_rest_of_line ();
2679}
2680
2681/* Parse an unwind_setfp directive. */
2682
2683static void
2684s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2685{
c19d1205
ZW
2686 int sp_reg;
2687 int fp_reg;
2688 int offset;
2689
2690 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2691 if (skip_past_comma (&input_line_pointer) == FAIL)
2692 sp_reg = FAIL;
2693 else
2694 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2695
c19d1205
ZW
2696 if (fp_reg == FAIL || sp_reg == FAIL)
2697 {
2698 as_bad (_("expected <reg>, <reg>"));
2699 ignore_rest_of_line ();
2700 return;
2701 }
b99bd4ef 2702
c19d1205
ZW
2703 /* Optional constant. */
2704 if (skip_past_comma (&input_line_pointer) != FAIL)
2705 {
2706 if (immediate_for_directive (&offset) == FAIL)
2707 return;
2708 }
2709 else
2710 offset = 0;
a737bd4d 2711
c19d1205 2712 demand_empty_rest_of_line ();
a737bd4d 2713
c19d1205 2714 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2715 {
c19d1205
ZW
2716 as_bad (_("register must be either sp or set by a previous"
2717 "unwind_movsp directive"));
2718 return;
a737bd4d
NC
2719 }
2720
c19d1205
ZW
2721 /* Don't generate any opcodes, just record the information for later. */
2722 unwind.fp_reg = fp_reg;
2723 unwind.fp_used = 1;
2724 if (sp_reg == 13)
2725 unwind.fp_offset = unwind.frame_size - offset;
2726 else
2727 unwind.fp_offset -= offset;
a737bd4d
NC
2728}
2729
c19d1205
ZW
2730/* Parse an unwind_raw directive. */
2731
2732static void
2733s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2734{
c19d1205
ZW
2735 expressionS exp;
2736 /* This is an arbitary limit. */
2737 unsigned char op[16];
2738 int count;
a737bd4d 2739
c19d1205
ZW
2740 expression (&exp);
2741 if (exp.X_op == O_constant
2742 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2743 {
c19d1205
ZW
2744 unwind.frame_size += exp.X_add_number;
2745 expression (&exp);
2746 }
2747 else
2748 exp.X_op = O_illegal;
a737bd4d 2749
c19d1205
ZW
2750 if (exp.X_op != O_constant)
2751 {
2752 as_bad (_("expected <offset>, <opcode>"));
2753 ignore_rest_of_line ();
2754 return;
2755 }
a737bd4d 2756
c19d1205 2757 count = 0;
a737bd4d 2758
c19d1205
ZW
2759 /* Parse the opcode. */
2760 for (;;)
2761 {
2762 if (count >= 16)
2763 {
2764 as_bad (_("unwind opcode too long"));
2765 ignore_rest_of_line ();
a737bd4d 2766 }
c19d1205 2767 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2768 {
c19d1205
ZW
2769 as_bad (_("invalid unwind opcode"));
2770 ignore_rest_of_line ();
2771 return;
a737bd4d 2772 }
c19d1205 2773 op[count++] = exp.X_add_number;
a737bd4d 2774
c19d1205
ZW
2775 /* Parse the next byte. */
2776 if (skip_past_comma (&input_line_pointer) == FAIL)
2777 break;
a737bd4d 2778
c19d1205
ZW
2779 expression (&exp);
2780 }
b99bd4ef 2781
c19d1205
ZW
2782 /* Add the opcode bytes in reverse order. */
2783 while (count--)
2784 add_unwind_opcode (op[count], 1);
b99bd4ef 2785
c19d1205 2786 demand_empty_rest_of_line ();
b99bd4ef 2787}
c19d1205 2788#endif /* OBJ_ELF */
b99bd4ef 2789
c19d1205
ZW
2790/* This table describes all the machine specific pseudo-ops the assembler
2791 has to support. The fields are:
2792 pseudo-op name without dot
2793 function to call to execute this pseudo-op
2794 Integer arg to pass to the function. */
b99bd4ef 2795
c19d1205 2796const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2797{
c19d1205
ZW
2798 /* Never called because '.req' does not start a line. */
2799 { "req", s_req, 0 },
2800 { "unreq", s_unreq, 0 },
2801 { "bss", s_bss, 0 },
2802 { "align", s_align, 0 },
2803 { "arm", s_arm, 0 },
2804 { "thumb", s_thumb, 0 },
2805 { "code", s_code, 0 },
2806 { "force_thumb", s_force_thumb, 0 },
2807 { "thumb_func", s_thumb_func, 0 },
2808 { "thumb_set", s_thumb_set, 0 },
2809 { "even", s_even, 0 },
2810 { "ltorg", s_ltorg, 0 },
2811 { "pool", s_ltorg, 0 },
2812 { "syntax", s_syntax, 0 },
2813#ifdef OBJ_ELF
2814 { "word", s_arm_elf_cons, 4 },
2815 { "long", s_arm_elf_cons, 4 },
2816 { "rel31", s_arm_rel31, 0 },
2817 { "fnstart", s_arm_unwind_fnstart, 0 },
2818 { "fnend", s_arm_unwind_fnend, 0 },
2819 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2820 { "personality", s_arm_unwind_personality, 0 },
2821 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2822 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2823 { "save", s_arm_unwind_save, 0 },
2824 { "movsp", s_arm_unwind_movsp, 0 },
2825 { "pad", s_arm_unwind_pad, 0 },
2826 { "setfp", s_arm_unwind_setfp, 0 },
2827 { "unwind_raw", s_arm_unwind_raw, 0 },
2828#else
2829 { "word", cons, 4},
2830#endif
2831 { "extend", float_cons, 'x' },
2832 { "ldouble", float_cons, 'x' },
2833 { "packed", float_cons, 'p' },
2834 { 0, 0, 0 }
2835};
2836\f
2837/* Parser functions used exclusively in instruction operands. */
b99bd4ef 2838
c19d1205
ZW
2839/* Generic immediate-value read function for use in insn parsing.
2840 STR points to the beginning of the immediate (the leading #);
2841 VAL receives the value; if the value is outside [MIN, MAX]
2842 issue an error. PREFIX_OPT is true if the immediate prefix is
2843 optional. */
b99bd4ef 2844
c19d1205
ZW
2845static int
2846parse_immediate (char **str, int *val, int min, int max,
2847 bfd_boolean prefix_opt)
2848{
2849 expressionS exp;
2850 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2851 if (exp.X_op != O_constant)
b99bd4ef 2852 {
c19d1205
ZW
2853 inst.error = _("constant expression required");
2854 return FAIL;
2855 }
b99bd4ef 2856
c19d1205
ZW
2857 if (exp.X_add_number < min || exp.X_add_number > max)
2858 {
2859 inst.error = _("immediate value out of range");
2860 return FAIL;
2861 }
b99bd4ef 2862
c19d1205
ZW
2863 *val = exp.X_add_number;
2864 return SUCCESS;
2865}
b99bd4ef 2866
c19d1205
ZW
2867/* Returns the pseudo-register number of an FPA immediate constant,
2868 or FAIL if there isn't a valid constant here. */
b99bd4ef 2869
c19d1205
ZW
2870static int
2871parse_fpa_immediate (char ** str)
2872{
2873 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2874 char * save_in;
2875 expressionS exp;
2876 int i;
2877 int j;
b99bd4ef 2878
c19d1205
ZW
2879 /* First try and match exact strings, this is to guarantee
2880 that some formats will work even for cross assembly. */
b99bd4ef 2881
c19d1205
ZW
2882 for (i = 0; fp_const[i]; i++)
2883 {
2884 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 2885 {
c19d1205 2886 char *start = *str;
b99bd4ef 2887
c19d1205
ZW
2888 *str += strlen (fp_const[i]);
2889 if (is_end_of_line[(unsigned char) **str])
2890 return i + 8;
2891 *str = start;
2892 }
2893 }
b99bd4ef 2894
c19d1205
ZW
2895 /* Just because we didn't get a match doesn't mean that the constant
2896 isn't valid, just that it is in a format that we don't
2897 automatically recognize. Try parsing it with the standard
2898 expression routines. */
b99bd4ef 2899
c19d1205 2900 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 2901
c19d1205
ZW
2902 /* Look for a raw floating point number. */
2903 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
2904 && is_end_of_line[(unsigned char) *save_in])
2905 {
2906 for (i = 0; i < NUM_FLOAT_VALS; i++)
2907 {
2908 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 2909 {
c19d1205
ZW
2910 if (words[j] != fp_values[i][j])
2911 break;
b99bd4ef
NC
2912 }
2913
c19d1205 2914 if (j == MAX_LITTLENUMS)
b99bd4ef 2915 {
c19d1205
ZW
2916 *str = save_in;
2917 return i + 8;
b99bd4ef
NC
2918 }
2919 }
2920 }
b99bd4ef 2921
c19d1205
ZW
2922 /* Try and parse a more complex expression, this will probably fail
2923 unless the code uses a floating point prefix (eg "0f"). */
2924 save_in = input_line_pointer;
2925 input_line_pointer = *str;
2926 if (expression (&exp) == absolute_section
2927 && exp.X_op == O_big
2928 && exp.X_add_number < 0)
2929 {
2930 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
2931 Ditto for 15. */
2932 if (gen_to_words (words, 5, (long) 15) == 0)
2933 {
2934 for (i = 0; i < NUM_FLOAT_VALS; i++)
2935 {
2936 for (j = 0; j < MAX_LITTLENUMS; j++)
2937 {
2938 if (words[j] != fp_values[i][j])
2939 break;
2940 }
b99bd4ef 2941
c19d1205
ZW
2942 if (j == MAX_LITTLENUMS)
2943 {
2944 *str = input_line_pointer;
2945 input_line_pointer = save_in;
2946 return i + 8;
2947 }
2948 }
2949 }
b99bd4ef
NC
2950 }
2951
c19d1205
ZW
2952 *str = input_line_pointer;
2953 input_line_pointer = save_in;
2954 inst.error = _("invalid FPA immediate expression");
2955 return FAIL;
b99bd4ef
NC
2956}
2957
c19d1205
ZW
2958/* Shift operands. */
2959enum shift_kind
b99bd4ef 2960{
c19d1205
ZW
2961 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
2962};
b99bd4ef 2963
c19d1205
ZW
2964struct asm_shift_name
2965{
2966 const char *name;
2967 enum shift_kind kind;
2968};
b99bd4ef 2969
c19d1205
ZW
2970/* Third argument to parse_shift. */
2971enum parse_shift_mode
2972{
2973 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
2974 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
2975 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
2976 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
2977 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
2978};
b99bd4ef 2979
c19d1205
ZW
2980/* Parse a <shift> specifier on an ARM data processing instruction.
2981 This has three forms:
b99bd4ef 2982
c19d1205
ZW
2983 (LSL|LSR|ASL|ASR|ROR) Rs
2984 (LSL|LSR|ASL|ASR|ROR) #imm
2985 RRX
b99bd4ef 2986
c19d1205
ZW
2987 Note that ASL is assimilated to LSL in the instruction encoding, and
2988 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 2989
c19d1205
ZW
2990static int
2991parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 2992{
c19d1205
ZW
2993 const struct asm_shift_name *shift_name;
2994 enum shift_kind shift;
2995 char *s = *str;
2996 char *p = s;
2997 int reg;
b99bd4ef 2998
c19d1205
ZW
2999 for (p = *str; ISALPHA (*p); p++)
3000 ;
b99bd4ef 3001
c19d1205 3002 if (p == *str)
b99bd4ef 3003 {
c19d1205
ZW
3004 inst.error = _("shift expression expected");
3005 return FAIL;
b99bd4ef
NC
3006 }
3007
c19d1205
ZW
3008 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3009
3010 if (shift_name == NULL)
b99bd4ef 3011 {
c19d1205
ZW
3012 inst.error = _("shift expression expected");
3013 return FAIL;
b99bd4ef
NC
3014 }
3015
c19d1205 3016 shift = shift_name->kind;
b99bd4ef 3017
c19d1205
ZW
3018 switch (mode)
3019 {
3020 case NO_SHIFT_RESTRICT:
3021 case SHIFT_IMMEDIATE: break;
b99bd4ef 3022
c19d1205
ZW
3023 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3024 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3025 {
3026 inst.error = _("'LSL' or 'ASR' required");
3027 return FAIL;
3028 }
3029 break;
b99bd4ef 3030
c19d1205
ZW
3031 case SHIFT_LSL_IMMEDIATE:
3032 if (shift != SHIFT_LSL)
3033 {
3034 inst.error = _("'LSL' required");
3035 return FAIL;
3036 }
3037 break;
b99bd4ef 3038
c19d1205
ZW
3039 case SHIFT_ASR_IMMEDIATE:
3040 if (shift != SHIFT_ASR)
3041 {
3042 inst.error = _("'ASR' required");
3043 return FAIL;
3044 }
3045 break;
b99bd4ef 3046
c19d1205
ZW
3047 default: abort ();
3048 }
b99bd4ef 3049
c19d1205
ZW
3050 if (shift != SHIFT_RRX)
3051 {
3052 /* Whitespace can appear here if the next thing is a bare digit. */
3053 skip_whitespace (p);
b99bd4ef 3054
c19d1205
ZW
3055 if (mode == NO_SHIFT_RESTRICT
3056 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3057 {
3058 inst.operands[i].imm = reg;
3059 inst.operands[i].immisreg = 1;
3060 }
3061 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3062 return FAIL;
3063 }
3064 inst.operands[i].shift_kind = shift;
3065 inst.operands[i].shifted = 1;
3066 *str = p;
3067 return SUCCESS;
b99bd4ef
NC
3068}
3069
c19d1205 3070/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3071
c19d1205
ZW
3072 #<immediate>
3073 #<immediate>, <rotate>
3074 <Rm>
3075 <Rm>, <shift>
b99bd4ef 3076
c19d1205
ZW
3077 where <shift> is defined by parse_shift above, and <rotate> is a
3078 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3079 is deferred to md_apply_fix. */
b99bd4ef 3080
c19d1205
ZW
3081static int
3082parse_shifter_operand (char **str, int i)
3083{
3084 int value;
3085 expressionS expr;
b99bd4ef 3086
c19d1205
ZW
3087 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3088 {
3089 inst.operands[i].reg = value;
3090 inst.operands[i].isreg = 1;
b99bd4ef 3091
c19d1205
ZW
3092 /* parse_shift will override this if appropriate */
3093 inst.reloc.exp.X_op = O_constant;
3094 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3095
c19d1205
ZW
3096 if (skip_past_comma (str) == FAIL)
3097 return SUCCESS;
b99bd4ef 3098
c19d1205
ZW
3099 /* Shift operation on register. */
3100 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3101 }
3102
c19d1205
ZW
3103 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3104 return FAIL;
b99bd4ef 3105
c19d1205 3106 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3107 {
c19d1205
ZW
3108 /* #x, y -- ie explicit rotation by Y. */
3109 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3110 return FAIL;
b99bd4ef 3111
c19d1205
ZW
3112 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3113 {
3114 inst.error = _("constant expression expected");
3115 return FAIL;
3116 }
b99bd4ef 3117
c19d1205
ZW
3118 value = expr.X_add_number;
3119 if (value < 0 || value > 30 || value % 2 != 0)
3120 {
3121 inst.error = _("invalid rotation");
3122 return FAIL;
3123 }
3124 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3125 {
3126 inst.error = _("invalid constant");
3127 return FAIL;
3128 }
09d92015 3129
55cf6793 3130 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3131 inst.reloc.exp.X_add_number
3132 = (((inst.reloc.exp.X_add_number << (32 - value))
3133 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3134 }
3135
c19d1205
ZW
3136 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3137 inst.reloc.pc_rel = 0;
3138 return SUCCESS;
09d92015
MM
3139}
3140
c19d1205
ZW
3141/* Parse all forms of an ARM address expression. Information is written
3142 to inst.operands[i] and/or inst.reloc.
09d92015 3143
c19d1205 3144 Preindexed addressing (.preind=1):
09d92015 3145
c19d1205
ZW
3146 [Rn, #offset] .reg=Rn .reloc.exp=offset
3147 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3148 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3149 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3150
c19d1205 3151 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3152
c19d1205 3153 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3154
c19d1205
ZW
3155 [Rn], #offset .reg=Rn .reloc.exp=offset
3156 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3157 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3158 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3159
c19d1205 3160 Unindexed addressing (.preind=0, .postind=0):
09d92015 3161
c19d1205 3162 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3163
c19d1205 3164 Other:
09d92015 3165
c19d1205
ZW
3166 [Rn]{!} shorthand for [Rn,#0]{!}
3167 =immediate .isreg=0 .reloc.exp=immediate
3168 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3169
c19d1205
ZW
3170 It is the caller's responsibility to check for addressing modes not
3171 supported by the instruction, and to set inst.reloc.type. */
3172
3173static int
3174parse_address (char **str, int i)
09d92015 3175{
c19d1205
ZW
3176 char *p = *str;
3177 int reg;
09d92015 3178
c19d1205 3179 if (skip_past_char (&p, '[') == FAIL)
09d92015 3180 {
c19d1205
ZW
3181 if (skip_past_char (&p, '=') == FAIL)
3182 {
3183 /* bare address - translate to PC-relative offset */
3184 inst.reloc.pc_rel = 1;
3185 inst.operands[i].reg = REG_PC;
3186 inst.operands[i].isreg = 1;
3187 inst.operands[i].preind = 1;
3188 }
3189 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3190
c19d1205
ZW
3191 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3192 return FAIL;
09d92015 3193
c19d1205
ZW
3194 *str = p;
3195 return SUCCESS;
09d92015
MM
3196 }
3197
c19d1205 3198 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3199 {
c19d1205
ZW
3200 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3201 return FAIL;
09d92015 3202 }
c19d1205
ZW
3203 inst.operands[i].reg = reg;
3204 inst.operands[i].isreg = 1;
09d92015 3205
c19d1205 3206 if (skip_past_comma (&p) == SUCCESS)
09d92015 3207 {
c19d1205 3208 inst.operands[i].preind = 1;
09d92015 3209
c19d1205
ZW
3210 if (*p == '+') p++;
3211 else if (*p == '-') p++, inst.operands[i].negative = 1;
3212
3213 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3214 {
c19d1205
ZW
3215 inst.operands[i].imm = reg;
3216 inst.operands[i].immisreg = 1;
3217
3218 if (skip_past_comma (&p) == SUCCESS)
3219 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3220 return FAIL;
3221 }
3222 else
3223 {
3224 if (inst.operands[i].negative)
3225 {
3226 inst.operands[i].negative = 0;
3227 p--;
3228 }
3229 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3230 return FAIL;
09d92015
MM
3231 }
3232 }
3233
c19d1205 3234 if (skip_past_char (&p, ']') == FAIL)
09d92015 3235 {
c19d1205
ZW
3236 inst.error = _("']' expected");
3237 return FAIL;
09d92015
MM
3238 }
3239
c19d1205
ZW
3240 if (skip_past_char (&p, '!') == SUCCESS)
3241 inst.operands[i].writeback = 1;
09d92015 3242
c19d1205 3243 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3244 {
c19d1205
ZW
3245 if (skip_past_char (&p, '{') == SUCCESS)
3246 {
3247 /* [Rn], {expr} - unindexed, with option */
3248 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 3249 0, 255, TRUE) == FAIL)
c19d1205 3250 return FAIL;
09d92015 3251
c19d1205
ZW
3252 if (skip_past_char (&p, '}') == FAIL)
3253 {
3254 inst.error = _("'}' expected at end of 'option' field");
3255 return FAIL;
3256 }
3257 if (inst.operands[i].preind)
3258 {
3259 inst.error = _("cannot combine index with option");
3260 return FAIL;
3261 }
3262 *str = p;
3263 return SUCCESS;
09d92015 3264 }
c19d1205
ZW
3265 else
3266 {
3267 inst.operands[i].postind = 1;
3268 inst.operands[i].writeback = 1;
09d92015 3269
c19d1205
ZW
3270 if (inst.operands[i].preind)
3271 {
3272 inst.error = _("cannot combine pre- and post-indexing");
3273 return FAIL;
3274 }
09d92015 3275
c19d1205
ZW
3276 if (*p == '+') p++;
3277 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3278
c19d1205
ZW
3279 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3280 {
3281 inst.operands[i].imm = reg;
3282 inst.operands[i].immisreg = 1;
a737bd4d 3283
c19d1205
ZW
3284 if (skip_past_comma (&p) == SUCCESS)
3285 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3286 return FAIL;
3287 }
3288 else
3289 {
3290 if (inst.operands[i].negative)
3291 {
3292 inst.operands[i].negative = 0;
3293 p--;
3294 }
3295 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3296 return FAIL;
3297 }
3298 }
a737bd4d
NC
3299 }
3300
c19d1205
ZW
3301 /* If at this point neither .preind nor .postind is set, we have a
3302 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3303 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3304 {
3305 inst.operands[i].preind = 1;
3306 inst.reloc.exp.X_op = O_constant;
3307 inst.reloc.exp.X_add_number = 0;
3308 }
3309 *str = p;
3310 return SUCCESS;
a737bd4d
NC
3311}
3312
c19d1205 3313/* Miscellaneous. */
a737bd4d 3314
c19d1205
ZW
3315/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3316 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3317static int
3318parse_psr (char **str)
09d92015 3319{
c19d1205
ZW
3320 char *p;
3321 unsigned long psr_field;
09d92015 3322
c19d1205
ZW
3323 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3324 feature for ease of use and backwards compatibility. */
3325 p = *str;
3326 if (*p == 's' || *p == 'S')
3327 psr_field = SPSR_BIT;
3328 else if (*p == 'c' || *p == 'C')
3329 psr_field = 0;
3330 else
3331 goto error;
09d92015 3332
c19d1205
ZW
3333 p++;
3334 if (strncasecmp (p, "PSR", 3) != 0)
3335 goto error;
3336 p += 3;
09d92015 3337
c19d1205
ZW
3338 if (*p == '_')
3339 {
3340 /* A suffix follows. */
3341 const struct asm_psr *psr;
3342 char *start;
a737bd4d 3343
c19d1205
ZW
3344 p++;
3345 start = p;
a737bd4d 3346
c19d1205
ZW
3347 do
3348 p++;
3349 while (ISALNUM (*p) || *p == '_');
a737bd4d 3350
c19d1205
ZW
3351 psr = hash_find_n (arm_psr_hsh, start, p - start);
3352 if (!psr)
3353 goto error;
a737bd4d 3354
c19d1205 3355 psr_field |= psr->field;
a737bd4d 3356 }
c19d1205 3357 else
a737bd4d 3358 {
c19d1205
ZW
3359 if (ISALNUM (*p))
3360 goto error; /* Garbage after "[CS]PSR". */
3361
3362 psr_field |= (PSR_c | PSR_f);
a737bd4d 3363 }
c19d1205
ZW
3364 *str = p;
3365 return psr_field;
a737bd4d 3366
c19d1205
ZW
3367 error:
3368 inst.error = _("flag for {c}psr instruction expected");
3369 return FAIL;
a737bd4d
NC
3370}
3371
c19d1205
ZW
3372/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3373 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3374
c19d1205
ZW
3375static int
3376parse_cps_flags (char **str)
a737bd4d 3377{
c19d1205
ZW
3378 int val = 0;
3379 int saw_a_flag = 0;
3380 char *s = *str;
a737bd4d 3381
c19d1205
ZW
3382 for (;;)
3383 switch (*s++)
3384 {
3385 case '\0': case ',':
3386 goto done;
a737bd4d 3387
c19d1205
ZW
3388 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3389 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3390 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3391
c19d1205
ZW
3392 default:
3393 inst.error = _("unrecognized CPS flag");
3394 return FAIL;
3395 }
a737bd4d 3396
c19d1205
ZW
3397 done:
3398 if (saw_a_flag == 0)
a737bd4d 3399 {
c19d1205
ZW
3400 inst.error = _("missing CPS flags");
3401 return FAIL;
a737bd4d 3402 }
a737bd4d 3403
c19d1205
ZW
3404 *str = s - 1;
3405 return val;
a737bd4d
NC
3406}
3407
c19d1205
ZW
3408/* Parse an endian specifier ("BE" or "LE", case insensitive);
3409 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3410
3411static int
c19d1205 3412parse_endian_specifier (char **str)
a737bd4d 3413{
c19d1205
ZW
3414 int little_endian;
3415 char *s = *str;
a737bd4d 3416
c19d1205
ZW
3417 if (strncasecmp (s, "BE", 2))
3418 little_endian = 0;
3419 else if (strncasecmp (s, "LE", 2))
3420 little_endian = 1;
3421 else
a737bd4d 3422 {
c19d1205 3423 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3424 return FAIL;
3425 }
3426
c19d1205 3427 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3428 {
c19d1205 3429 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3430 return FAIL;
3431 }
3432
c19d1205
ZW
3433 *str = s + 2;
3434 return little_endian;
3435}
a737bd4d 3436
c19d1205
ZW
3437/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3438 value suitable for poking into the rotate field of an sxt or sxta
3439 instruction, or FAIL on error. */
3440
3441static int
3442parse_ror (char **str)
3443{
3444 int rot;
3445 char *s = *str;
3446
3447 if (strncasecmp (s, "ROR", 3) == 0)
3448 s += 3;
3449 else
a737bd4d 3450 {
c19d1205 3451 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3452 return FAIL;
3453 }
c19d1205
ZW
3454
3455 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3456 return FAIL;
3457
3458 switch (rot)
a737bd4d 3459 {
c19d1205
ZW
3460 case 0: *str = s; return 0x0;
3461 case 8: *str = s; return 0x1;
3462 case 16: *str = s; return 0x2;
3463 case 24: *str = s; return 0x3;
3464
3465 default:
3466 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3467 return FAIL;
3468 }
c19d1205 3469}
a737bd4d 3470
c19d1205
ZW
3471/* Parse a conditional code (from conds[] below). The value returned is in the
3472 range 0 .. 14, or FAIL. */
3473static int
3474parse_cond (char **str)
3475{
3476 char *p, *q;
3477 const struct asm_cond *c;
a737bd4d 3478
c19d1205
ZW
3479 p = q = *str;
3480 while (ISALPHA (*q))
3481 q++;
a737bd4d 3482
c19d1205
ZW
3483 c = hash_find_n (arm_cond_hsh, p, q - p);
3484 if (!c)
a737bd4d 3485 {
c19d1205 3486 inst.error = _("condition required");
a737bd4d
NC
3487 return FAIL;
3488 }
3489
c19d1205
ZW
3490 *str = q;
3491 return c->value;
3492}
3493
92e90b6e
PB
3494/* Parse the operands of a table branch instruction. Similar to a memory
3495 operand. */
3496static int
3497parse_tb (char **str)
3498{
3499 char * p = *str;
3500 int reg;
3501
3502 if (skip_past_char (&p, '[') == FAIL)
3503 return FAIL;
3504
3505 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3506 {
3507 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3508 return FAIL;
3509 }
3510 inst.operands[0].reg = reg;
3511
3512 if (skip_past_comma (&p) == FAIL)
3513 return FAIL;
3514
3515 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3516 {
3517 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3518 return FAIL;
3519 }
3520 inst.operands[0].imm = reg;
3521
3522 if (skip_past_comma (&p) == SUCCESS)
3523 {
3524 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3525 return FAIL;
3526 if (inst.reloc.exp.X_add_number != 1)
3527 {
3528 inst.error = _("invalid shift");
3529 return FAIL;
3530 }
3531 inst.operands[0].shifted = 1;
3532 }
3533
3534 if (skip_past_char (&p, ']') == FAIL)
3535 {
3536 inst.error = _("']' expected");
3537 return FAIL;
3538 }
3539 *str = p;
3540 return SUCCESS;
3541}
3542
c19d1205
ZW
3543/* Matcher codes for parse_operands. */
3544enum operand_parse_code
3545{
3546 OP_stop, /* end of line */
3547
3548 OP_RR, /* ARM register */
3549 OP_RRnpc, /* ARM register, not r15 */
3550 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3551 OP_RRw, /* ARM register, not r15, optional trailing ! */
3552 OP_RCP, /* Coprocessor number */
3553 OP_RCN, /* Coprocessor register */
3554 OP_RF, /* FPA register */
3555 OP_RVS, /* VFP single precision register */
3556 OP_RVD, /* VFP double precision register */
3557 OP_RVC, /* VFP control register */
3558 OP_RMF, /* Maverick F register */
3559 OP_RMD, /* Maverick D register */
3560 OP_RMFX, /* Maverick FX register */
3561 OP_RMDX, /* Maverick DX register */
3562 OP_RMAX, /* Maverick AX register */
3563 OP_RMDS, /* Maverick DSPSC register */
3564 OP_RIWR, /* iWMMXt wR register */
3565 OP_RIWC, /* iWMMXt wC register */
3566 OP_RIWG, /* iWMMXt wCG register */
3567 OP_RXA, /* XScale accumulator register */
3568
3569 OP_REGLST, /* ARM register list */
3570 OP_VRSLST, /* VFP single-precision register list */
3571 OP_VRDLST, /* VFP double-precision register list */
3572
3573 OP_I7, /* immediate value 0 .. 7 */
3574 OP_I15, /* 0 .. 15 */
3575 OP_I16, /* 1 .. 16 */
3576 OP_I31, /* 0 .. 31 */
3577 OP_I31w, /* 0 .. 31, optional trailing ! */
3578 OP_I32, /* 1 .. 32 */
3579 OP_I63s, /* -64 .. 63 */
3580 OP_I255, /* 0 .. 255 */
3581 OP_Iffff, /* 0 .. 65535 */
3582
3583 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3584 OP_I7b, /* 0 .. 7 */
3585 OP_I15b, /* 0 .. 15 */
3586 OP_I31b, /* 0 .. 31 */
3587
3588 OP_SH, /* shifter operand */
3589 OP_ADDR, /* Memory address expression (any mode) */
3590 OP_EXP, /* arbitrary expression */
3591 OP_EXPi, /* same, with optional immediate prefix */
3592 OP_EXPr, /* same, with optional relocation suffix */
3593
3594 OP_CPSF, /* CPS flags */
3595 OP_ENDI, /* Endianness specifier */
3596 OP_PSR, /* CPSR/SPSR mask for msr */
3597 OP_COND, /* conditional code */
92e90b6e 3598 OP_TB, /* Table branch. */
c19d1205
ZW
3599
3600 OP_RRnpc_I0, /* ARM register or literal 0 */
3601 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3602 OP_RR_EXi, /* ARM register or expression with imm prefix */
3603 OP_RF_IF, /* FPA register or immediate */
3604 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3605
3606 /* Optional operands. */
3607 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3608 OP_oI31b, /* 0 .. 31 */
3609 OP_oIffffb, /* 0 .. 65535 */
3610 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3611
3612 OP_oRR, /* ARM register */
3613 OP_oRRnpc, /* ARM register, not the PC */
3614 OP_oSHll, /* LSL immediate */
3615 OP_oSHar, /* ASR immediate */
3616 OP_oSHllar, /* LSL or ASR immediate */
3617 OP_oROR, /* ROR 0/8/16/24 */
3618
3619 OP_FIRST_OPTIONAL = OP_oI7b
3620};
a737bd4d 3621
c19d1205
ZW
3622/* Generic instruction operand parser. This does no encoding and no
3623 semantic validation; it merely squirrels values away in the inst
3624 structure. Returns SUCCESS or FAIL depending on whether the
3625 specified grammar matched. */
3626static int
ca3f61f7 3627parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
3628{
3629 unsigned const char *upat = pattern;
3630 char *backtrack_pos = 0;
3631 const char *backtrack_error = 0;
3632 int i, val, backtrack_index = 0;
3633
3634#define po_char_or_fail(chr) do { \
3635 if (skip_past_char (&str, chr) == FAIL) \
3636 goto bad_args; \
3637} while (0)
3638
3639#define po_reg_or_fail(regtype) do { \
3640 val = arm_reg_parse (&str, regtype); \
3641 if (val == FAIL) \
3642 { \
3643 inst.error = _(reg_expected_msgs[regtype]); \
3644 goto failure; \
3645 } \
3646 inst.operands[i].reg = val; \
3647 inst.operands[i].isreg = 1; \
3648} while (0)
3649
3650#define po_reg_or_goto(regtype, label) do { \
3651 val = arm_reg_parse (&str, regtype); \
3652 if (val == FAIL) \
3653 goto label; \
3654 \
3655 inst.operands[i].reg = val; \
3656 inst.operands[i].isreg = 1; \
3657} while (0)
3658
3659#define po_imm_or_fail(min, max, popt) do { \
3660 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3661 goto failure; \
3662 inst.operands[i].imm = val; \
3663} while (0)
3664
3665#define po_misc_or_fail(expr) do { \
3666 if (expr) \
3667 goto failure; \
3668} while (0)
3669
3670 skip_whitespace (str);
3671
3672 for (i = 0; upat[i] != OP_stop; i++)
3673 {
3674 if (upat[i] >= OP_FIRST_OPTIONAL)
3675 {
3676 /* Remember where we are in case we need to backtrack. */
3677 assert (!backtrack_pos);
3678 backtrack_pos = str;
3679 backtrack_error = inst.error;
3680 backtrack_index = i;
3681 }
3682
3683 if (i > 0)
3684 po_char_or_fail (',');
3685
3686 switch (upat[i])
3687 {
3688 /* Registers */
3689 case OP_oRRnpc:
3690 case OP_RRnpc:
3691 case OP_oRR:
3692 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3693 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3694 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3695 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3696 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3697 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3698 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3699 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3700 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3701 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3702 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3703 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3704 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3705 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3706 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3707 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3708 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3709
3710 case OP_RRnpcb:
3711 po_char_or_fail ('[');
3712 po_reg_or_fail (REG_TYPE_RN);
3713 po_char_or_fail (']');
3714 break;
a737bd4d 3715
c19d1205
ZW
3716 case OP_RRw:
3717 po_reg_or_fail (REG_TYPE_RN);
3718 if (skip_past_char (&str, '!') == SUCCESS)
3719 inst.operands[i].writeback = 1;
3720 break;
3721
3722 /* Immediates */
3723 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3724 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3725 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3726 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3727 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3728 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3729 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3730 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3731
3732 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3733 case OP_oI7b:
3734 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3735 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3736 case OP_oI31b:
3737 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3738 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3739
3740 /* Immediate variants */
3741 case OP_oI255c:
3742 po_char_or_fail ('{');
3743 po_imm_or_fail (0, 255, TRUE);
3744 po_char_or_fail ('}');
3745 break;
3746
3747 case OP_I31w:
3748 /* The expression parser chokes on a trailing !, so we have
3749 to find it first and zap it. */
3750 {
3751 char *s = str;
3752 while (*s && *s != ',')
3753 s++;
3754 if (s[-1] == '!')
3755 {
3756 s[-1] = '\0';
3757 inst.operands[i].writeback = 1;
3758 }
3759 po_imm_or_fail (0, 31, TRUE);
3760 if (str == s - 1)
3761 str = s;
3762 }
3763 break;
3764
3765 /* Expressions */
3766 case OP_EXPi: EXPi:
3767 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3768 GE_OPT_PREFIX));
3769 break;
3770
3771 case OP_EXP:
3772 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3773 GE_NO_PREFIX));
3774 break;
3775
3776 case OP_EXPr: EXPr:
3777 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3778 GE_NO_PREFIX));
3779 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3780 {
c19d1205
ZW
3781 val = parse_reloc (&str);
3782 if (val == -1)
3783 {
3784 inst.error = _("unrecognized relocation suffix");
3785 goto failure;
3786 }
3787 else if (val != BFD_RELOC_UNUSED)
3788 {
3789 inst.operands[i].imm = val;
3790 inst.operands[i].hasreloc = 1;
3791 }
a737bd4d 3792 }
c19d1205 3793 break;
a737bd4d 3794
c19d1205
ZW
3795 /* Register or expression */
3796 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3797 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 3798
c19d1205
ZW
3799 /* Register or immediate */
3800 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3801 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 3802
c19d1205
ZW
3803 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3804 IF:
3805 if (!is_immediate_prefix (*str))
3806 goto bad_args;
3807 str++;
3808 val = parse_fpa_immediate (&str);
3809 if (val == FAIL)
3810 goto failure;
3811 /* FPA immediates are encoded as registers 8-15.
3812 parse_fpa_immediate has already applied the offset. */
3813 inst.operands[i].reg = val;
3814 inst.operands[i].isreg = 1;
3815 break;
09d92015 3816
c19d1205
ZW
3817 /* Two kinds of register */
3818 case OP_RIWR_RIWC:
3819 {
3820 struct reg_entry *rege = arm_reg_parse_multi (&str);
3821 if (rege->type != REG_TYPE_MMXWR
3822 && rege->type != REG_TYPE_MMXWC
3823 && rege->type != REG_TYPE_MMXWCG)
3824 {
3825 inst.error = _("iWMMXt data or control register expected");
3826 goto failure;
3827 }
3828 inst.operands[i].reg = rege->number;
3829 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3830 }
3831 break;
09d92015 3832
c19d1205
ZW
3833 /* Misc */
3834 case OP_CPSF: val = parse_cps_flags (&str); break;
3835 case OP_ENDI: val = parse_endian_specifier (&str); break;
3836 case OP_oROR: val = parse_ror (&str); break;
3837 case OP_PSR: val = parse_psr (&str); break;
3838 case OP_COND: val = parse_cond (&str); break;
3839
92e90b6e
PB
3840 case OP_TB:
3841 po_misc_or_fail (parse_tb (&str));
3842 break;
3843
c19d1205
ZW
3844 /* Register lists */
3845 case OP_REGLST:
3846 val = parse_reg_list (&str);
3847 if (*str == '^')
3848 {
3849 inst.operands[1].writeback = 1;
3850 str++;
3851 }
3852 break;
09d92015 3853
c19d1205
ZW
3854 case OP_VRSLST:
3855 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3856 break;
09d92015 3857
c19d1205
ZW
3858 case OP_VRDLST:
3859 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3860 break;
a737bd4d 3861
c19d1205
ZW
3862 /* Addressing modes */
3863 case OP_ADDR:
3864 po_misc_or_fail (parse_address (&str, i));
3865 break;
09d92015 3866
c19d1205
ZW
3867 case OP_SH:
3868 po_misc_or_fail (parse_shifter_operand (&str, i));
3869 break;
09d92015 3870
c19d1205
ZW
3871 case OP_oSHll:
3872 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3873 break;
09d92015 3874
c19d1205
ZW
3875 case OP_oSHar:
3876 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3877 break;
09d92015 3878
c19d1205
ZW
3879 case OP_oSHllar:
3880 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3881 break;
09d92015 3882
c19d1205
ZW
3883 default:
3884 as_fatal ("unhandled operand code %d", upat[i]);
3885 }
09d92015 3886
c19d1205
ZW
3887 /* Various value-based sanity checks and shared operations. We
3888 do not signal immediate failures for the register constraints;
3889 this allows a syntax error to take precedence. */
3890 switch (upat[i])
3891 {
3892 case OP_oRRnpc:
3893 case OP_RRnpc:
3894 case OP_RRnpcb:
3895 case OP_RRw:
3896 case OP_RRnpc_I0:
3897 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
3898 inst.error = BAD_PC;
3899 break;
09d92015 3900
c19d1205
ZW
3901 case OP_CPSF:
3902 case OP_ENDI:
3903 case OP_oROR:
3904 case OP_PSR:
3905 case OP_COND:
3906 case OP_REGLST:
3907 case OP_VRSLST:
3908 case OP_VRDLST:
3909 if (val == FAIL)
3910 goto failure;
3911 inst.operands[i].imm = val;
3912 break;
a737bd4d 3913
c19d1205
ZW
3914 default:
3915 break;
3916 }
09d92015 3917
c19d1205
ZW
3918 /* If we get here, this operand was successfully parsed. */
3919 inst.operands[i].present = 1;
3920 continue;
09d92015 3921
c19d1205 3922 bad_args:
09d92015 3923 inst.error = BAD_ARGS;
c19d1205
ZW
3924
3925 failure:
3926 if (!backtrack_pos)
3927 return FAIL;
3928
3929 /* Do not backtrack over a trailing optional argument that
3930 absorbed some text. We will only fail again, with the
3931 'garbage following instruction' error message, which is
3932 probably less helpful than the current one. */
3933 if (backtrack_index == i && backtrack_pos != str
3934 && upat[i+1] == OP_stop)
3935 return FAIL;
3936
3937 /* Try again, skipping the optional argument at backtrack_pos. */
3938 str = backtrack_pos;
3939 inst.error = backtrack_error;
3940 inst.operands[backtrack_index].present = 0;
3941 i = backtrack_index;
3942 backtrack_pos = 0;
09d92015 3943 }
09d92015 3944
c19d1205
ZW
3945 /* Check that we have parsed all the arguments. */
3946 if (*str != '\0' && !inst.error)
3947 inst.error = _("garbage following instruction");
09d92015 3948
c19d1205 3949 return inst.error ? FAIL : SUCCESS;
09d92015
MM
3950}
3951
c19d1205
ZW
3952#undef po_char_or_fail
3953#undef po_reg_or_fail
3954#undef po_reg_or_goto
3955#undef po_imm_or_fail
3956\f
3957/* Shorthand macro for instruction encoding functions issuing errors. */
3958#define constraint(expr, err) do { \
3959 if (expr) \
3960 { \
3961 inst.error = err; \
3962 return; \
3963 } \
3964} while (0)
3965
3966/* Functions for operand encoding. ARM, then Thumb. */
3967
3968#define rotate_left(v, n) (v << n | v >> (32 - n))
3969
3970/* If VAL can be encoded in the immediate field of an ARM instruction,
3971 return the encoded form. Otherwise, return FAIL. */
3972
3973static unsigned int
3974encode_arm_immediate (unsigned int val)
09d92015 3975{
c19d1205
ZW
3976 unsigned int a, i;
3977
3978 for (i = 0; i < 32; i += 2)
3979 if ((a = rotate_left (val, i)) <= 0xff)
3980 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
3981
3982 return FAIL;
09d92015
MM
3983}
3984
c19d1205
ZW
3985/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
3986 return the encoded form. Otherwise, return FAIL. */
3987static unsigned int
3988encode_thumb32_immediate (unsigned int val)
09d92015 3989{
c19d1205 3990 unsigned int a, i;
09d92015 3991
9c3c69f2 3992 if (val <= 0xff)
c19d1205 3993 return val;
a737bd4d 3994
9c3c69f2 3995 for (i = 1; i <= 24; i++)
09d92015 3996 {
9c3c69f2
PB
3997 a = val >> i;
3998 if ((val & ~(0xff << i)) == 0)
3999 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 4000 }
a737bd4d 4001
c19d1205
ZW
4002 a = val & 0xff;
4003 if (val == ((a << 16) | a))
4004 return 0x100 | a;
4005 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4006 return 0x300 | a;
09d92015 4007
c19d1205
ZW
4008 a = val & 0xff00;
4009 if (val == ((a << 16) | a))
4010 return 0x200 | (a >> 8);
a737bd4d 4011
c19d1205 4012 return FAIL;
09d92015 4013}
c19d1205 4014/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
4015
4016static void
c19d1205 4017encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 4018{
c19d1205 4019 switch (pos)
09d92015 4020 {
c19d1205
ZW
4021 case VFP_REG_Sd:
4022 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4023 break;
4024
4025 case VFP_REG_Sn:
4026 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4027 break;
4028
4029 case VFP_REG_Sm:
4030 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4031 break;
4032
4033 default:
4034 abort ();
09d92015 4035 }
09d92015
MM
4036}
4037
c19d1205 4038/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 4039 if any, is handled by md_apply_fix. */
09d92015 4040static void
c19d1205 4041encode_arm_shift (int i)
09d92015 4042{
c19d1205
ZW
4043 if (inst.operands[i].shift_kind == SHIFT_RRX)
4044 inst.instruction |= SHIFT_ROR << 5;
4045 else
09d92015 4046 {
c19d1205
ZW
4047 inst.instruction |= inst.operands[i].shift_kind << 5;
4048 if (inst.operands[i].immisreg)
4049 {
4050 inst.instruction |= SHIFT_BY_REG;
4051 inst.instruction |= inst.operands[i].imm << 8;
4052 }
4053 else
4054 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 4055 }
c19d1205 4056}
09d92015 4057
c19d1205
ZW
4058static void
4059encode_arm_shifter_operand (int i)
4060{
4061 if (inst.operands[i].isreg)
09d92015 4062 {
c19d1205
ZW
4063 inst.instruction |= inst.operands[i].reg;
4064 encode_arm_shift (i);
09d92015 4065 }
c19d1205
ZW
4066 else
4067 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4068}
4069
c19d1205 4070/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4071static void
c19d1205 4072encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4073{
c19d1205
ZW
4074 assert (inst.operands[i].isreg);
4075 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4076
c19d1205 4077 if (inst.operands[i].preind)
09d92015 4078 {
c19d1205
ZW
4079 if (is_t)
4080 {
4081 inst.error = _("instruction does not accept preindexed addressing");
4082 return;
4083 }
4084 inst.instruction |= PRE_INDEX;
4085 if (inst.operands[i].writeback)
4086 inst.instruction |= WRITE_BACK;
09d92015 4087
c19d1205
ZW
4088 }
4089 else if (inst.operands[i].postind)
4090 {
4091 assert (inst.operands[i].writeback);
4092 if (is_t)
4093 inst.instruction |= WRITE_BACK;
4094 }
4095 else /* unindexed - only for coprocessor */
09d92015 4096 {
c19d1205 4097 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4098 return;
4099 }
4100
c19d1205
ZW
4101 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4102 && (((inst.instruction & 0x000f0000) >> 16)
4103 == ((inst.instruction & 0x0000f000) >> 12)))
4104 as_warn ((inst.instruction & LOAD_BIT)
4105 ? _("destination register same as write-back base")
4106 : _("source register same as write-back base"));
09d92015
MM
4107}
4108
c19d1205
ZW
4109/* inst.operands[i] was set up by parse_address. Encode it into an
4110 ARM-format mode 2 load or store instruction. If is_t is true,
4111 reject forms that cannot be used with a T instruction (i.e. not
4112 post-indexed). */
a737bd4d 4113static void
c19d1205 4114encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4115{
c19d1205 4116 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4117
c19d1205 4118 if (inst.operands[i].immisreg)
09d92015 4119 {
c19d1205
ZW
4120 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4121 inst.instruction |= inst.operands[i].imm;
4122 if (!inst.operands[i].negative)
4123 inst.instruction |= INDEX_UP;
4124 if (inst.operands[i].shifted)
4125 {
4126 if (inst.operands[i].shift_kind == SHIFT_RRX)
4127 inst.instruction |= SHIFT_ROR << 5;
4128 else
4129 {
4130 inst.instruction |= inst.operands[i].shift_kind << 5;
4131 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4132 }
4133 }
09d92015 4134 }
c19d1205 4135 else /* immediate offset in inst.reloc */
09d92015 4136 {
c19d1205
ZW
4137 if (inst.reloc.type == BFD_RELOC_UNUSED)
4138 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 4139 }
09d92015
MM
4140}
4141
c19d1205
ZW
4142/* inst.operands[i] was set up by parse_address. Encode it into an
4143 ARM-format mode 3 load or store instruction. Reject forms that
4144 cannot be used with such instructions. If is_t is true, reject
4145 forms that cannot be used with a T instruction (i.e. not
4146 post-indexed). */
4147static void
4148encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4149{
c19d1205 4150 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4151 {
c19d1205
ZW
4152 inst.error = _("instruction does not accept scaled register index");
4153 return;
09d92015 4154 }
a737bd4d 4155
c19d1205 4156 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4157
c19d1205
ZW
4158 if (inst.operands[i].immisreg)
4159 {
4160 inst.instruction |= inst.operands[i].imm;
4161 if (!inst.operands[i].negative)
4162 inst.instruction |= INDEX_UP;
4163 }
4164 else /* immediate offset in inst.reloc */
4165 {
4166 inst.instruction |= HWOFFSET_IMM;
4167 if (inst.reloc.type == BFD_RELOC_UNUSED)
4168 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 4169 }
a737bd4d
NC
4170}
4171
c19d1205
ZW
4172/* inst.operands[i] was set up by parse_address. Encode it into an
4173 ARM-format instruction. Reject all forms which cannot be encoded
4174 into a coprocessor load/store instruction. If wb_ok is false,
4175 reject use of writeback; if unind_ok is false, reject use of
4176 unindexed addressing. If reloc_override is not 0, use it instead
4177 of BFD_ARM_CP_OFF_IMM. */
09d92015 4178
c19d1205
ZW
4179static int
4180encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4181{
c19d1205 4182 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4183
c19d1205 4184 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4185
c19d1205 4186 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4187 {
c19d1205
ZW
4188 assert (!inst.operands[i].writeback);
4189 if (!unind_ok)
4190 {
4191 inst.error = _("instruction does not support unindexed addressing");
4192 return FAIL;
4193 }
4194 inst.instruction |= inst.operands[i].imm;
4195 inst.instruction |= INDEX_UP;
4196 return SUCCESS;
09d92015 4197 }
a737bd4d 4198
c19d1205
ZW
4199 if (inst.operands[i].preind)
4200 inst.instruction |= PRE_INDEX;
a737bd4d 4201
c19d1205 4202 if (inst.operands[i].writeback)
09d92015 4203 {
c19d1205
ZW
4204 if (inst.operands[i].reg == REG_PC)
4205 {
4206 inst.error = _("pc may not be used with write-back");
4207 return FAIL;
4208 }
4209 if (!wb_ok)
4210 {
4211 inst.error = _("instruction does not support writeback");
4212 return FAIL;
4213 }
4214 inst.instruction |= WRITE_BACK;
09d92015 4215 }
a737bd4d 4216
c19d1205
ZW
4217 if (reloc_override)
4218 inst.reloc.type = reloc_override;
09d92015 4219 else
c19d1205 4220 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205
ZW
4221 return SUCCESS;
4222}
a737bd4d 4223
c19d1205
ZW
4224/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4225 Determine whether it can be performed with a move instruction; if
4226 it can, convert inst.instruction to that move instruction and
4227 return 1; if it can't, convert inst.instruction to a literal-pool
4228 load and return 0. If this is not a valid thing to do in the
4229 current context, set inst.error and return 1.
a737bd4d 4230
c19d1205
ZW
4231 inst.operands[i] describes the destination register. */
4232
4233static int
4234move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4235{
4236 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4237 {
c19d1205
ZW
4238 inst.error = _("invalid pseudo operation");
4239 return 1;
09d92015 4240 }
c19d1205 4241 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4242 {
4243 inst.error = _("constant expression expected");
c19d1205 4244 return 1;
09d92015 4245 }
c19d1205 4246 if (inst.reloc.exp.X_op == O_constant)
09d92015 4247 {
c19d1205
ZW
4248 if (thumb_p)
4249 {
4250 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4251 {
4252 /* This can be done with a mov(1) instruction. */
4253 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4254 inst.instruction |= inst.reloc.exp.X_add_number;
4255 return 1;
4256 }
4257 }
4258 else
4259 {
4260 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4261 if (value != FAIL)
4262 {
4263 /* This can be done with a mov instruction. */
4264 inst.instruction &= LITERAL_MASK;
4265 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4266 inst.instruction |= value & 0xfff;
4267 return 1;
4268 }
09d92015 4269
c19d1205
ZW
4270 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4271 if (value != FAIL)
4272 {
4273 /* This can be done with a mvn instruction. */
4274 inst.instruction &= LITERAL_MASK;
4275 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4276 inst.instruction |= value & 0xfff;
4277 return 1;
4278 }
4279 }
09d92015
MM
4280 }
4281
c19d1205
ZW
4282 if (add_to_lit_pool () == FAIL)
4283 {
4284 inst.error = _("literal pool insertion failed");
4285 return 1;
4286 }
4287 inst.operands[1].reg = REG_PC;
4288 inst.operands[1].isreg = 1;
4289 inst.operands[1].preind = 1;
4290 inst.reloc.pc_rel = 1;
4291 inst.reloc.type = (thumb_p
4292 ? BFD_RELOC_ARM_THUMB_OFFSET
4293 : (mode_3
4294 ? BFD_RELOC_ARM_HWLITERAL
4295 : BFD_RELOC_ARM_LITERAL));
4296 return 0;
09d92015
MM
4297}
4298
c19d1205
ZW
4299/* Functions for instruction encoding, sorted by subarchitecture.
4300 First some generics; their names are taken from the conventional
4301 bit positions for register arguments in ARM format instructions. */
09d92015 4302
a737bd4d 4303static void
c19d1205 4304do_noargs (void)
09d92015 4305{
c19d1205 4306}
a737bd4d 4307
c19d1205
ZW
4308static void
4309do_rd (void)
4310{
4311 inst.instruction |= inst.operands[0].reg << 12;
4312}
a737bd4d 4313
c19d1205
ZW
4314static void
4315do_rd_rm (void)
4316{
4317 inst.instruction |= inst.operands[0].reg << 12;
4318 inst.instruction |= inst.operands[1].reg;
4319}
09d92015 4320
c19d1205
ZW
4321static void
4322do_rd_rn (void)
4323{
4324 inst.instruction |= inst.operands[0].reg << 12;
4325 inst.instruction |= inst.operands[1].reg << 16;
4326}
a737bd4d 4327
c19d1205
ZW
4328static void
4329do_rn_rd (void)
4330{
4331 inst.instruction |= inst.operands[0].reg << 16;
4332 inst.instruction |= inst.operands[1].reg << 12;
4333}
09d92015 4334
c19d1205
ZW
4335static void
4336do_rd_rm_rn (void)
4337{
4338 inst.instruction |= inst.operands[0].reg << 12;
4339 inst.instruction |= inst.operands[1].reg;
4340 inst.instruction |= inst.operands[2].reg << 16;
4341}
09d92015 4342
c19d1205
ZW
4343static void
4344do_rd_rn_rm (void)
4345{
4346 inst.instruction |= inst.operands[0].reg << 12;
4347 inst.instruction |= inst.operands[1].reg << 16;
4348 inst.instruction |= inst.operands[2].reg;
4349}
a737bd4d 4350
c19d1205
ZW
4351static void
4352do_rm_rd_rn (void)
4353{
4354 inst.instruction |= inst.operands[0].reg;
4355 inst.instruction |= inst.operands[1].reg << 12;
4356 inst.instruction |= inst.operands[2].reg << 16;
4357}
09d92015 4358
c19d1205
ZW
4359static void
4360do_imm0 (void)
4361{
4362 inst.instruction |= inst.operands[0].imm;
4363}
09d92015 4364
c19d1205
ZW
4365static void
4366do_rd_cpaddr (void)
4367{
4368 inst.instruction |= inst.operands[0].reg << 12;
4369 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4370}
a737bd4d 4371
c19d1205
ZW
4372/* ARM instructions, in alphabetical order by function name (except
4373 that wrapper functions appear immediately after the function they
4374 wrap). */
09d92015 4375
c19d1205
ZW
4376/* This is a pseudo-op of the form "adr rd, label" to be converted
4377 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4378
4379static void
c19d1205 4380do_adr (void)
09d92015 4381{
c19d1205 4382 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4383
c19d1205
ZW
4384 /* Frag hacking will turn this into a sub instruction if the offset turns
4385 out to be negative. */
4386 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 4387 inst.reloc.pc_rel = 1;
2fc8bdac 4388 inst.reloc.exp.X_add_number -= 8;
c19d1205 4389}
b99bd4ef 4390
c19d1205
ZW
4391/* This is a pseudo-op of the form "adrl rd, label" to be converted
4392 into a relative address of the form:
4393 add rd, pc, #low(label-.-8)"
4394 add rd, rd, #high(label-.-8)" */
b99bd4ef 4395
c19d1205
ZW
4396static void
4397do_adrl (void)
4398{
4399 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4400
c19d1205
ZW
4401 /* Frag hacking will turn this into a sub instruction if the offset turns
4402 out to be negative. */
4403 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
4404 inst.reloc.pc_rel = 1;
4405 inst.size = INSN_SIZE * 2;
2fc8bdac 4406 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
4407}
4408
b99bd4ef 4409static void
c19d1205 4410do_arit (void)
b99bd4ef 4411{
c19d1205
ZW
4412 if (!inst.operands[1].present)
4413 inst.operands[1].reg = inst.operands[0].reg;
4414 inst.instruction |= inst.operands[0].reg << 12;
4415 inst.instruction |= inst.operands[1].reg << 16;
4416 encode_arm_shifter_operand (2);
4417}
b99bd4ef 4418
c19d1205
ZW
4419static void
4420do_bfc (void)
4421{
4422 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4423 constraint (msb > 32, _("bit-field extends past end of register"));
4424 /* The instruction encoding stores the LSB and MSB,
4425 not the LSB and width. */
4426 inst.instruction |= inst.operands[0].reg << 12;
4427 inst.instruction |= inst.operands[1].imm << 7;
4428 inst.instruction |= (msb - 1) << 16;
4429}
b99bd4ef 4430
c19d1205
ZW
4431static void
4432do_bfi (void)
4433{
4434 unsigned int msb;
b99bd4ef 4435
c19d1205
ZW
4436 /* #0 in second position is alternative syntax for bfc, which is
4437 the same instruction but with REG_PC in the Rm field. */
4438 if (!inst.operands[1].isreg)
4439 inst.operands[1].reg = REG_PC;
b99bd4ef 4440
c19d1205
ZW
4441 msb = inst.operands[2].imm + inst.operands[3].imm;
4442 constraint (msb > 32, _("bit-field extends past end of register"));
4443 /* The instruction encoding stores the LSB and MSB,
4444 not the LSB and width. */
4445 inst.instruction |= inst.operands[0].reg << 12;
4446 inst.instruction |= inst.operands[1].reg;
4447 inst.instruction |= inst.operands[2].imm << 7;
4448 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4449}
4450
b99bd4ef 4451static void
c19d1205 4452do_bfx (void)
b99bd4ef 4453{
c19d1205
ZW
4454 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4455 _("bit-field extends past end of register"));
4456 inst.instruction |= inst.operands[0].reg << 12;
4457 inst.instruction |= inst.operands[1].reg;
4458 inst.instruction |= inst.operands[2].imm << 7;
4459 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4460}
09d92015 4461
c19d1205
ZW
4462/* ARM V5 breakpoint instruction (argument parse)
4463 BKPT <16 bit unsigned immediate>
4464 Instruction is not conditional.
4465 The bit pattern given in insns[] has the COND_ALWAYS condition,
4466 and it is an error if the caller tried to override that. */
b99bd4ef 4467
c19d1205
ZW
4468static void
4469do_bkpt (void)
4470{
4471 /* Top 12 of 16 bits to bits 19:8. */
4472 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4473
c19d1205
ZW
4474 /* Bottom 4 of 16 bits to bits 3:0. */
4475 inst.instruction |= inst.operands[0].imm & 0xf;
4476}
09d92015 4477
c19d1205
ZW
4478static void
4479encode_branch (int default_reloc)
4480{
4481 if (inst.operands[0].hasreloc)
4482 {
4483 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4484 _("the only suffix valid here is '(plt)'"));
4485 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 4486 }
b99bd4ef 4487 else
c19d1205
ZW
4488 {
4489 inst.reloc.type = default_reloc;
c19d1205 4490 }
2fc8bdac 4491 inst.reloc.pc_rel = 1;
b99bd4ef
NC
4492}
4493
b99bd4ef 4494static void
c19d1205 4495do_branch (void)
b99bd4ef 4496{
c19d1205
ZW
4497 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4498}
b99bd4ef 4499
c19d1205
ZW
4500/* ARM V5 branch-link-exchange instruction (argument parse)
4501 BLX <target_addr> ie BLX(1)
4502 BLX{<condition>} <Rm> ie BLX(2)
4503 Unfortunately, there are two different opcodes for this mnemonic.
4504 So, the insns[].value is not used, and the code here zaps values
4505 into inst.instruction.
4506 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4507
c19d1205
ZW
4508static void
4509do_blx (void)
4510{
4511 if (inst.operands[0].isreg)
b99bd4ef 4512 {
c19d1205
ZW
4513 /* Arg is a register; the opcode provided by insns[] is correct.
4514 It is not illegal to do "blx pc", just useless. */
4515 if (inst.operands[0].reg == REG_PC)
4516 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4517
c19d1205
ZW
4518 inst.instruction |= inst.operands[0].reg;
4519 }
4520 else
b99bd4ef 4521 {
c19d1205
ZW
4522 /* Arg is an address; this instruction cannot be executed
4523 conditionally, and the opcode must be adjusted. */
4524 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 4525 inst.instruction = 0xfa000000;
c19d1205 4526 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4527 }
c19d1205
ZW
4528}
4529
4530static void
4531do_bx (void)
4532{
4533 if (inst.operands[0].reg == REG_PC)
4534 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4535
c19d1205 4536 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4537}
4538
c19d1205
ZW
4539
4540/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4541
4542static void
c19d1205 4543do_bxj (void)
a737bd4d 4544{
c19d1205
ZW
4545 if (inst.operands[0].reg == REG_PC)
4546 as_tsktsk (_("use of r15 in bxj is not really useful"));
4547
4548 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4549}
4550
c19d1205
ZW
4551/* Co-processor data operation:
4552 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4553 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4554static void
4555do_cdp (void)
4556{
4557 inst.instruction |= inst.operands[0].reg << 8;
4558 inst.instruction |= inst.operands[1].imm << 20;
4559 inst.instruction |= inst.operands[2].reg << 12;
4560 inst.instruction |= inst.operands[3].reg << 16;
4561 inst.instruction |= inst.operands[4].reg;
4562 inst.instruction |= inst.operands[5].imm << 5;
4563}
a737bd4d
NC
4564
4565static void
c19d1205 4566do_cmp (void)
a737bd4d 4567{
c19d1205
ZW
4568 inst.instruction |= inst.operands[0].reg << 16;
4569 encode_arm_shifter_operand (1);
a737bd4d
NC
4570}
4571
c19d1205
ZW
4572/* Transfer between coprocessor and ARM registers.
4573 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4574 MRC2
4575 MCR{cond}
4576 MCR2
4577
4578 No special properties. */
09d92015
MM
4579
4580static void
c19d1205 4581do_co_reg (void)
09d92015 4582{
c19d1205
ZW
4583 inst.instruction |= inst.operands[0].reg << 8;
4584 inst.instruction |= inst.operands[1].imm << 21;
4585 inst.instruction |= inst.operands[2].reg << 12;
4586 inst.instruction |= inst.operands[3].reg << 16;
4587 inst.instruction |= inst.operands[4].reg;
4588 inst.instruction |= inst.operands[5].imm << 5;
4589}
09d92015 4590
c19d1205
ZW
4591/* Transfer between coprocessor register and pair of ARM registers.
4592 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4593 MCRR2
4594 MRRC{cond}
4595 MRRC2
b99bd4ef 4596
c19d1205 4597 Two XScale instructions are special cases of these:
09d92015 4598
c19d1205
ZW
4599 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4600 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4601
c19d1205 4602 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4603
c19d1205
ZW
4604static void
4605do_co_reg2c (void)
4606{
4607 inst.instruction |= inst.operands[0].reg << 8;
4608 inst.instruction |= inst.operands[1].imm << 4;
4609 inst.instruction |= inst.operands[2].reg << 12;
4610 inst.instruction |= inst.operands[3].reg << 16;
4611 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4612}
4613
c19d1205
ZW
4614static void
4615do_cpsi (void)
4616{
4617 inst.instruction |= inst.operands[0].imm << 6;
4618 inst.instruction |= inst.operands[1].imm;
4619}
b99bd4ef
NC
4620
4621static void
c19d1205 4622do_it (void)
b99bd4ef 4623{
c19d1205
ZW
4624 /* There is no IT instruction in ARM mode. We
4625 process it but do not generate code for it. */
4626 inst.size = 0;
09d92015 4627}
b99bd4ef 4628
09d92015 4629static void
c19d1205 4630do_ldmstm (void)
ea6ef066 4631{
c19d1205
ZW
4632 int base_reg = inst.operands[0].reg;
4633 int range = inst.operands[1].imm;
ea6ef066 4634
c19d1205
ZW
4635 inst.instruction |= base_reg << 16;
4636 inst.instruction |= range;
ea6ef066 4637
c19d1205
ZW
4638 if (inst.operands[1].writeback)
4639 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4640
c19d1205 4641 if (inst.operands[0].writeback)
ea6ef066 4642 {
c19d1205
ZW
4643 inst.instruction |= WRITE_BACK;
4644 /* Check for unpredictable uses of writeback. */
4645 if (inst.instruction & LOAD_BIT)
09d92015 4646 {
c19d1205
ZW
4647 /* Not allowed in LDM type 2. */
4648 if ((inst.instruction & LDM_TYPE_2_OR_3)
4649 && ((range & (1 << REG_PC)) == 0))
4650 as_warn (_("writeback of base register is UNPREDICTABLE"));
4651 /* Only allowed if base reg not in list for other types. */
4652 else if (range & (1 << base_reg))
4653 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4654 }
4655 else /* STM. */
4656 {
4657 /* Not allowed for type 2. */
4658 if (inst.instruction & LDM_TYPE_2_OR_3)
4659 as_warn (_("writeback of base register is UNPREDICTABLE"));
4660 /* Only allowed if base reg not in list, or first in list. */
4661 else if ((range & (1 << base_reg))
4662 && (range & ((1 << base_reg) - 1)))
4663 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4664 }
ea6ef066 4665 }
a737bd4d
NC
4666}
4667
c19d1205
ZW
4668/* ARMv5TE load-consecutive (argument parse)
4669 Mode is like LDRH.
4670
4671 LDRccD R, mode
4672 STRccD R, mode. */
4673
a737bd4d 4674static void
c19d1205 4675do_ldrd (void)
a737bd4d 4676{
c19d1205
ZW
4677 constraint (inst.operands[0].reg % 2 != 0,
4678 _("first destination register must be even"));
4679 constraint (inst.operands[1].present
4680 && inst.operands[1].reg != inst.operands[0].reg + 1,
4681 _("can only load two consecutive registers"));
4682 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4683 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4684
c19d1205
ZW
4685 if (!inst.operands[1].present)
4686 inst.operands[1].reg = inst.operands[0].reg + 1;
4687
4688 if (inst.instruction & LOAD_BIT)
a737bd4d 4689 {
c19d1205
ZW
4690 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4691 register and the first register written; we have to diagnose
4692 overlap between the base and the second register written here. */
ea6ef066 4693
c19d1205
ZW
4694 if (inst.operands[2].reg == inst.operands[1].reg
4695 && (inst.operands[2].writeback || inst.operands[2].postind))
4696 as_warn (_("base register written back, and overlaps "
4697 "second destination register"));
b05fe5cf 4698
c19d1205
ZW
4699 /* For an index-register load, the index register must not overlap the
4700 destination (even if not write-back). */
4701 else if (inst.operands[2].immisreg
ca3f61f7
NC
4702 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4703 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 4704 as_warn (_("index register overlaps destination register"));
b05fe5cf 4705 }
c19d1205
ZW
4706
4707 inst.instruction |= inst.operands[0].reg << 12;
4708 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4709}
4710
4711static void
c19d1205 4712do_ldrex (void)
b05fe5cf 4713{
c19d1205
ZW
4714 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4715 || inst.operands[1].postind || inst.operands[1].writeback
4716 || inst.operands[1].immisreg || inst.operands[1].shifted
4717 || inst.operands[1].negative,
4718 _("instruction does not accept this addressing mode"));
b05fe5cf 4719
c19d1205 4720 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
b05fe5cf 4721
c19d1205
ZW
4722 constraint (inst.reloc.exp.X_op != O_constant
4723 || inst.reloc.exp.X_add_number != 0,
4724 _("offset must be zero in ARM encoding"));
b05fe5cf 4725
c19d1205
ZW
4726 inst.instruction |= inst.operands[0].reg << 12;
4727 inst.instruction |= inst.operands[1].reg << 16;
4728 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4729}
4730
4731static void
c19d1205 4732do_ldrexd (void)
b05fe5cf 4733{
c19d1205
ZW
4734 constraint (inst.operands[0].reg % 2 != 0,
4735 _("even register required"));
4736 constraint (inst.operands[1].present
4737 && inst.operands[1].reg != inst.operands[0].reg + 1,
4738 _("can only load two consecutive registers"));
4739 /* If op 1 were present and equal to PC, this function wouldn't
4740 have been called in the first place. */
4741 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 4742
c19d1205
ZW
4743 inst.instruction |= inst.operands[0].reg << 12;
4744 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
4745}
4746
4747static void
c19d1205 4748do_ldst (void)
b05fe5cf 4749{
c19d1205
ZW
4750 inst.instruction |= inst.operands[0].reg << 12;
4751 if (!inst.operands[1].isreg)
4752 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 4753 return;
c19d1205 4754 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4755}
4756
4757static void
c19d1205 4758do_ldstt (void)
b05fe5cf 4759{
c19d1205
ZW
4760 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4761 reject [Rn,...]. */
4762 if (inst.operands[1].preind)
b05fe5cf 4763 {
c19d1205
ZW
4764 constraint (inst.reloc.exp.X_op != O_constant ||
4765 inst.reloc.exp.X_add_number != 0,
4766 _("this instruction requires a post-indexed address"));
b05fe5cf 4767
c19d1205
ZW
4768 inst.operands[1].preind = 0;
4769 inst.operands[1].postind = 1;
4770 inst.operands[1].writeback = 1;
b05fe5cf 4771 }
c19d1205
ZW
4772 inst.instruction |= inst.operands[0].reg << 12;
4773 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4774}
b05fe5cf 4775
c19d1205 4776/* Halfword and signed-byte load/store operations. */
b05fe5cf 4777
c19d1205
ZW
4778static void
4779do_ldstv4 (void)
4780{
4781 inst.instruction |= inst.operands[0].reg << 12;
4782 if (!inst.operands[1].isreg)
4783 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 4784 return;
c19d1205 4785 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4786}
4787
4788static void
c19d1205 4789do_ldsttv4 (void)
b05fe5cf 4790{
c19d1205
ZW
4791 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4792 reject [Rn,...]. */
4793 if (inst.operands[1].preind)
b05fe5cf 4794 {
c19d1205
ZW
4795 constraint (inst.reloc.exp.X_op != O_constant ||
4796 inst.reloc.exp.X_add_number != 0,
4797 _("this instruction requires a post-indexed address"));
b05fe5cf 4798
c19d1205
ZW
4799 inst.operands[1].preind = 0;
4800 inst.operands[1].postind = 1;
4801 inst.operands[1].writeback = 1;
b05fe5cf 4802 }
c19d1205
ZW
4803 inst.instruction |= inst.operands[0].reg << 12;
4804 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4805}
b05fe5cf 4806
c19d1205
ZW
4807/* Co-processor register load/store.
4808 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4809static void
4810do_lstc (void)
4811{
4812 inst.instruction |= inst.operands[0].reg << 8;
4813 inst.instruction |= inst.operands[1].reg << 12;
4814 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
4815}
4816
b05fe5cf 4817static void
c19d1205 4818do_mlas (void)
b05fe5cf 4819{
c19d1205
ZW
4820 /* This restriction does not apply to mls (nor to mla in v6, but
4821 that's hard to detect at present). */
4822 if (inst.operands[0].reg == inst.operands[1].reg
4823 && !(inst.instruction & 0x00400000))
4824 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 4825
c19d1205
ZW
4826 inst.instruction |= inst.operands[0].reg << 16;
4827 inst.instruction |= inst.operands[1].reg;
4828 inst.instruction |= inst.operands[2].reg << 8;
4829 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 4830
c19d1205 4831}
b05fe5cf 4832
c19d1205
ZW
4833static void
4834do_mov (void)
4835{
4836 inst.instruction |= inst.operands[0].reg << 12;
4837 encode_arm_shifter_operand (1);
4838}
b05fe5cf 4839
c19d1205
ZW
4840/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4841static void
4842do_mov16 (void)
4843{
4844 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 4845 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
4846 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4847 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 4848}
b99bd4ef
NC
4849
4850static void
c19d1205 4851do_mrs (void)
b99bd4ef 4852{
c19d1205
ZW
4853 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4854 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4855 != (PSR_c|PSR_f),
4856 _("'CPSR' or 'SPSR' expected"));
4857 inst.instruction |= inst.operands[0].reg << 12;
4858 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4859}
b99bd4ef 4860
c19d1205
ZW
4861/* Two possible forms:
4862 "{C|S}PSR_<field>, Rm",
4863 "{C|S}PSR_f, #expression". */
b99bd4ef 4864
c19d1205
ZW
4865static void
4866do_msr (void)
4867{
4868 inst.instruction |= inst.operands[0].imm;
4869 if (inst.operands[1].isreg)
4870 inst.instruction |= inst.operands[1].reg;
4871 else
b99bd4ef 4872 {
c19d1205
ZW
4873 inst.instruction |= INST_IMMEDIATE;
4874 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4875 inst.reloc.pc_rel = 0;
b99bd4ef 4876 }
b99bd4ef
NC
4877}
4878
c19d1205
ZW
4879static void
4880do_mul (void)
a737bd4d 4881{
c19d1205
ZW
4882 if (!inst.operands[2].present)
4883 inst.operands[2].reg = inst.operands[0].reg;
4884 inst.instruction |= inst.operands[0].reg << 16;
4885 inst.instruction |= inst.operands[1].reg;
4886 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 4887
c19d1205
ZW
4888 if (inst.operands[0].reg == inst.operands[1].reg)
4889 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
4890}
4891
c19d1205
ZW
4892/* Long Multiply Parser
4893 UMULL RdLo, RdHi, Rm, Rs
4894 SMULL RdLo, RdHi, Rm, Rs
4895 UMLAL RdLo, RdHi, Rm, Rs
4896 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
4897
4898static void
c19d1205 4899do_mull (void)
b99bd4ef 4900{
c19d1205
ZW
4901 inst.instruction |= inst.operands[0].reg << 12;
4902 inst.instruction |= inst.operands[1].reg << 16;
4903 inst.instruction |= inst.operands[2].reg;
4904 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 4905
c19d1205
ZW
4906 /* rdhi, rdlo and rm must all be different. */
4907 if (inst.operands[0].reg == inst.operands[1].reg
4908 || inst.operands[0].reg == inst.operands[2].reg
4909 || inst.operands[1].reg == inst.operands[2].reg)
4910 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
4911}
b99bd4ef 4912
c19d1205
ZW
4913static void
4914do_nop (void)
4915{
4916 if (inst.operands[0].present)
4917 {
4918 /* Architectural NOP hints are CPSR sets with no bits selected. */
4919 inst.instruction &= 0xf0000000;
4920 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
4921 }
b99bd4ef
NC
4922}
4923
c19d1205
ZW
4924/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
4925 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
4926 Condition defaults to COND_ALWAYS.
4927 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
4928
4929static void
c19d1205 4930do_pkhbt (void)
b99bd4ef 4931{
c19d1205
ZW
4932 inst.instruction |= inst.operands[0].reg << 12;
4933 inst.instruction |= inst.operands[1].reg << 16;
4934 inst.instruction |= inst.operands[2].reg;
4935 if (inst.operands[3].present)
4936 encode_arm_shift (3);
4937}
b99bd4ef 4938
c19d1205 4939/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 4940
c19d1205
ZW
4941static void
4942do_pkhtb (void)
4943{
4944 if (!inst.operands[3].present)
b99bd4ef 4945 {
c19d1205
ZW
4946 /* If the shift specifier is omitted, turn the instruction
4947 into pkhbt rd, rm, rn. */
4948 inst.instruction &= 0xfff00010;
4949 inst.instruction |= inst.operands[0].reg << 12;
4950 inst.instruction |= inst.operands[1].reg;
4951 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
4952 }
4953 else
4954 {
c19d1205
ZW
4955 inst.instruction |= inst.operands[0].reg << 12;
4956 inst.instruction |= inst.operands[1].reg << 16;
4957 inst.instruction |= inst.operands[2].reg;
4958 encode_arm_shift (3);
b99bd4ef
NC
4959 }
4960}
4961
c19d1205
ZW
4962/* ARMv5TE: Preload-Cache
4963
4964 PLD <addr_mode>
4965
4966 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
4967
4968static void
c19d1205 4969do_pld (void)
b99bd4ef 4970{
c19d1205
ZW
4971 constraint (!inst.operands[0].isreg,
4972 _("'[' expected after PLD mnemonic"));
4973 constraint (inst.operands[0].postind,
4974 _("post-indexed expression used in preload instruction"));
4975 constraint (inst.operands[0].writeback,
4976 _("writeback used in preload instruction"));
4977 constraint (!inst.operands[0].preind,
4978 _("unindexed addressing used in preload instruction"));
4979 inst.instruction |= inst.operands[0].reg;
4980 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
4981}
b99bd4ef 4982
c19d1205
ZW
4983static void
4984do_push_pop (void)
4985{
4986 inst.operands[1] = inst.operands[0];
4987 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
4988 inst.operands[0].isreg = 1;
4989 inst.operands[0].writeback = 1;
4990 inst.operands[0].reg = REG_SP;
4991 do_ldmstm ();
4992}
b99bd4ef 4993
c19d1205
ZW
4994/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
4995 word at the specified address and the following word
4996 respectively.
4997 Unconditionally executed.
4998 Error if Rn is R15. */
b99bd4ef 4999
c19d1205
ZW
5000static void
5001do_rfe (void)
5002{
5003 inst.instruction |= inst.operands[0].reg << 16;
5004 if (inst.operands[0].writeback)
5005 inst.instruction |= WRITE_BACK;
5006}
b99bd4ef 5007
c19d1205 5008/* ARM V6 ssat (argument parse). */
b99bd4ef 5009
c19d1205
ZW
5010static void
5011do_ssat (void)
5012{
5013 inst.instruction |= inst.operands[0].reg << 12;
5014 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5015 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5016
c19d1205
ZW
5017 if (inst.operands[3].present)
5018 encode_arm_shift (3);
b99bd4ef
NC
5019}
5020
c19d1205 5021/* ARM V6 usat (argument parse). */
b99bd4ef
NC
5022
5023static void
c19d1205 5024do_usat (void)
b99bd4ef 5025{
c19d1205
ZW
5026 inst.instruction |= inst.operands[0].reg << 12;
5027 inst.instruction |= inst.operands[1].imm << 16;
5028 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5029
c19d1205
ZW
5030 if (inst.operands[3].present)
5031 encode_arm_shift (3);
b99bd4ef
NC
5032}
5033
c19d1205 5034/* ARM V6 ssat16 (argument parse). */
09d92015
MM
5035
5036static void
c19d1205 5037do_ssat16 (void)
09d92015 5038{
c19d1205
ZW
5039 inst.instruction |= inst.operands[0].reg << 12;
5040 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5041 inst.instruction |= inst.operands[2].reg;
09d92015
MM
5042}
5043
c19d1205
ZW
5044static void
5045do_usat16 (void)
a737bd4d 5046{
c19d1205
ZW
5047 inst.instruction |= inst.operands[0].reg << 12;
5048 inst.instruction |= inst.operands[1].imm << 16;
5049 inst.instruction |= inst.operands[2].reg;
5050}
a737bd4d 5051
c19d1205
ZW
5052/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5053 preserving the other bits.
a737bd4d 5054
c19d1205
ZW
5055 setend <endian_specifier>, where <endian_specifier> is either
5056 BE or LE. */
a737bd4d 5057
c19d1205
ZW
5058static void
5059do_setend (void)
5060{
5061 if (inst.operands[0].imm)
5062 inst.instruction |= 0x200;
a737bd4d
NC
5063}
5064
5065static void
c19d1205 5066do_shift (void)
a737bd4d 5067{
c19d1205
ZW
5068 unsigned int Rm = (inst.operands[1].present
5069 ? inst.operands[1].reg
5070 : inst.operands[0].reg);
a737bd4d 5071
c19d1205
ZW
5072 inst.instruction |= inst.operands[0].reg << 12;
5073 inst.instruction |= Rm;
5074 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5075 {
c19d1205
ZW
5076 constraint (inst.operands[0].reg != Rm,
5077 _("source1 and dest must be same register"));
5078 inst.instruction |= inst.operands[2].reg << 8;
5079 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5080 }
5081 else
c19d1205 5082 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5083}
5084
09d92015 5085static void
c19d1205 5086do_smi (void)
09d92015 5087{
c19d1205
ZW
5088 inst.reloc.type = BFD_RELOC_ARM_SMI;
5089 inst.reloc.pc_rel = 0;
09d92015
MM
5090}
5091
09d92015 5092static void
c19d1205 5093do_swi (void)
09d92015 5094{
c19d1205
ZW
5095 inst.reloc.type = BFD_RELOC_ARM_SWI;
5096 inst.reloc.pc_rel = 0;
09d92015
MM
5097}
5098
c19d1205
ZW
5099/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5100 SMLAxy{cond} Rd,Rm,Rs,Rn
5101 SMLAWy{cond} Rd,Rm,Rs,Rn
5102 Error if any register is R15. */
e16bb312 5103
c19d1205
ZW
5104static void
5105do_smla (void)
e16bb312 5106{
c19d1205
ZW
5107 inst.instruction |= inst.operands[0].reg << 16;
5108 inst.instruction |= inst.operands[1].reg;
5109 inst.instruction |= inst.operands[2].reg << 8;
5110 inst.instruction |= inst.operands[3].reg << 12;
5111}
a737bd4d 5112
c19d1205
ZW
5113/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5114 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5115 Error if any register is R15.
5116 Warning if Rdlo == Rdhi. */
a737bd4d 5117
c19d1205
ZW
5118static void
5119do_smlal (void)
5120{
5121 inst.instruction |= inst.operands[0].reg << 12;
5122 inst.instruction |= inst.operands[1].reg << 16;
5123 inst.instruction |= inst.operands[2].reg;
5124 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5125
c19d1205
ZW
5126 if (inst.operands[0].reg == inst.operands[1].reg)
5127 as_tsktsk (_("rdhi and rdlo must be different"));
5128}
a737bd4d 5129
c19d1205
ZW
5130/* ARM V5E (El Segundo) signed-multiply (argument parse)
5131 SMULxy{cond} Rd,Rm,Rs
5132 Error if any register is R15. */
a737bd4d 5133
c19d1205
ZW
5134static void
5135do_smul (void)
5136{
5137 inst.instruction |= inst.operands[0].reg << 16;
5138 inst.instruction |= inst.operands[1].reg;
5139 inst.instruction |= inst.operands[2].reg << 8;
5140}
a737bd4d 5141
c19d1205 5142/* ARM V6 srs (argument parse). */
a737bd4d 5143
c19d1205
ZW
5144static void
5145do_srs (void)
5146{
5147 inst.instruction |= inst.operands[0].imm;
5148 if (inst.operands[0].writeback)
5149 inst.instruction |= WRITE_BACK;
5150}
a737bd4d 5151
c19d1205 5152/* ARM V6 strex (argument parse). */
a737bd4d 5153
c19d1205
ZW
5154static void
5155do_strex (void)
5156{
5157 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5158 || inst.operands[2].postind || inst.operands[2].writeback
5159 || inst.operands[2].immisreg || inst.operands[2].shifted
5160 || inst.operands[2].negative,
5161 _("instruction does not accept this addressing mode"));
e16bb312 5162
c19d1205 5163 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
a737bd4d 5164
c19d1205
ZW
5165 constraint (inst.operands[0].reg == inst.operands[1].reg
5166 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5167
c19d1205
ZW
5168 constraint (inst.reloc.exp.X_op != O_constant
5169 || inst.reloc.exp.X_add_number != 0,
5170 _("offset must be zero in ARM encoding"));
a737bd4d 5171
c19d1205
ZW
5172 inst.instruction |= inst.operands[0].reg << 12;
5173 inst.instruction |= inst.operands[1].reg;
5174 inst.instruction |= inst.operands[2].reg << 16;
5175 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5176}
5177
5178static void
c19d1205 5179do_strexd (void)
e16bb312 5180{
c19d1205
ZW
5181 constraint (inst.operands[1].reg % 2 != 0,
5182 _("even register required"));
5183 constraint (inst.operands[2].present
5184 && inst.operands[2].reg != inst.operands[1].reg + 1,
5185 _("can only store two consecutive registers"));
5186 /* If op 2 were present and equal to PC, this function wouldn't
5187 have been called in the first place. */
5188 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5189
c19d1205
ZW
5190 constraint (inst.operands[0].reg == inst.operands[1].reg
5191 || inst.operands[0].reg == inst.operands[1].reg + 1
5192 || inst.operands[0].reg == inst.operands[3].reg,
5193 BAD_OVERLAP);
e16bb312 5194
c19d1205
ZW
5195 inst.instruction |= inst.operands[0].reg << 12;
5196 inst.instruction |= inst.operands[1].reg;
5197 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5198}
5199
c19d1205
ZW
5200/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5201 extends it to 32-bits, and adds the result to a value in another
5202 register. You can specify a rotation by 0, 8, 16, or 24 bits
5203 before extracting the 16-bit value.
5204 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5205 Condition defaults to COND_ALWAYS.
5206 Error if any register uses R15. */
5207
e16bb312 5208static void
c19d1205 5209do_sxtah (void)
e16bb312 5210{
c19d1205
ZW
5211 inst.instruction |= inst.operands[0].reg << 12;
5212 inst.instruction |= inst.operands[1].reg << 16;
5213 inst.instruction |= inst.operands[2].reg;
5214 inst.instruction |= inst.operands[3].imm << 10;
5215}
e16bb312 5216
c19d1205 5217/* ARM V6 SXTH.
e16bb312 5218
c19d1205
ZW
5219 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5220 Condition defaults to COND_ALWAYS.
5221 Error if any register uses R15. */
e16bb312
NC
5222
5223static void
c19d1205 5224do_sxth (void)
e16bb312 5225{
c19d1205
ZW
5226 inst.instruction |= inst.operands[0].reg << 12;
5227 inst.instruction |= inst.operands[1].reg;
5228 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5229}
c19d1205
ZW
5230\f
5231/* VFP instructions. In a logical order: SP variant first, monad
5232 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5233
5234static void
c19d1205 5235do_vfp_sp_monadic (void)
e16bb312 5236{
c19d1205
ZW
5237 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5238 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5239}
5240
5241static void
c19d1205 5242do_vfp_sp_dyadic (void)
e16bb312 5243{
c19d1205
ZW
5244 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5245 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5246 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5247}
5248
5249static void
c19d1205 5250do_vfp_sp_compare_z (void)
e16bb312 5251{
c19d1205 5252 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5253}
5254
5255static void
c19d1205 5256do_vfp_dp_sp_cvt (void)
e16bb312 5257{
c19d1205
ZW
5258 inst.instruction |= inst.operands[0].reg << 12;
5259 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5260}
5261
5262static void
c19d1205 5263do_vfp_sp_dp_cvt (void)
e16bb312 5264{
c19d1205
ZW
5265 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5266 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5267}
5268
5269static void
c19d1205 5270do_vfp_reg_from_sp (void)
e16bb312 5271{
c19d1205
ZW
5272 inst.instruction |= inst.operands[0].reg << 12;
5273 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5274}
5275
5276static void
c19d1205 5277do_vfp_reg2_from_sp2 (void)
e16bb312 5278{
c19d1205
ZW
5279 constraint (inst.operands[2].imm != 2,
5280 _("only two consecutive VFP SP registers allowed here"));
5281 inst.instruction |= inst.operands[0].reg << 12;
5282 inst.instruction |= inst.operands[1].reg << 16;
5283 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5284}
5285
5286static void
c19d1205 5287do_vfp_sp_from_reg (void)
e16bb312 5288{
c19d1205
ZW
5289 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5290 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5291}
5292
5293static void
c19d1205 5294do_vfp_sp2_from_reg2 (void)
e16bb312 5295{
c19d1205
ZW
5296 constraint (inst.operands[0].imm != 2,
5297 _("only two consecutive VFP SP registers allowed here"));
5298 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5299 inst.instruction |= inst.operands[1].reg << 12;
5300 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5301}
5302
5303static void
c19d1205 5304do_vfp_sp_ldst (void)
e16bb312 5305{
c19d1205
ZW
5306 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5307 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5308}
5309
5310static void
c19d1205 5311do_vfp_dp_ldst (void)
e16bb312 5312{
c19d1205
ZW
5313 inst.instruction |= inst.operands[0].reg << 12;
5314 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5315}
5316
c19d1205 5317
e16bb312 5318static void
c19d1205 5319vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5320{
c19d1205
ZW
5321 if (inst.operands[0].writeback)
5322 inst.instruction |= WRITE_BACK;
5323 else
5324 constraint (ldstm_type != VFP_LDSTMIA,
5325 _("this addressing mode requires base-register writeback"));
5326 inst.instruction |= inst.operands[0].reg << 16;
5327 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5328 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5329}
5330
5331static void
c19d1205 5332vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5333{
c19d1205 5334 int count;
e16bb312 5335
c19d1205
ZW
5336 if (inst.operands[0].writeback)
5337 inst.instruction |= WRITE_BACK;
5338 else
5339 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5340 _("this addressing mode requires base-register writeback"));
e16bb312 5341
c19d1205
ZW
5342 inst.instruction |= inst.operands[0].reg << 16;
5343 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5344
c19d1205
ZW
5345 count = inst.operands[1].imm << 1;
5346 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5347 count += 1;
e16bb312 5348
c19d1205 5349 inst.instruction |= count;
e16bb312
NC
5350}
5351
5352static void
c19d1205 5353do_vfp_sp_ldstmia (void)
e16bb312 5354{
c19d1205 5355 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5356}
5357
5358static void
c19d1205 5359do_vfp_sp_ldstmdb (void)
e16bb312 5360{
c19d1205 5361 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5362}
5363
5364static void
c19d1205 5365do_vfp_dp_ldstmia (void)
e16bb312 5366{
c19d1205 5367 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5368}
5369
5370static void
c19d1205 5371do_vfp_dp_ldstmdb (void)
e16bb312 5372{
c19d1205 5373 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5374}
5375
5376static void
c19d1205 5377do_vfp_xp_ldstmia (void)
e16bb312 5378{
c19d1205
ZW
5379 vfp_dp_ldstm (VFP_LDSTMIAX);
5380}
e16bb312 5381
c19d1205
ZW
5382static void
5383do_vfp_xp_ldstmdb (void)
5384{
5385 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5386}
c19d1205
ZW
5387\f
5388/* FPA instructions. Also in a logical order. */
e16bb312 5389
c19d1205
ZW
5390static void
5391do_fpa_cmp (void)
5392{
5393 inst.instruction |= inst.operands[0].reg << 16;
5394 inst.instruction |= inst.operands[1].reg;
5395}
b99bd4ef
NC
5396
5397static void
c19d1205 5398do_fpa_ldmstm (void)
b99bd4ef 5399{
c19d1205
ZW
5400 inst.instruction |= inst.operands[0].reg << 12;
5401 switch (inst.operands[1].imm)
5402 {
5403 case 1: inst.instruction |= CP_T_X; break;
5404 case 2: inst.instruction |= CP_T_Y; break;
5405 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5406 case 4: break;
5407 default: abort ();
5408 }
b99bd4ef 5409
c19d1205
ZW
5410 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5411 {
5412 /* The instruction specified "ea" or "fd", so we can only accept
5413 [Rn]{!}. The instruction does not really support stacking or
5414 unstacking, so we have to emulate these by setting appropriate
5415 bits and offsets. */
5416 constraint (inst.reloc.exp.X_op != O_constant
5417 || inst.reloc.exp.X_add_number != 0,
5418 _("this instruction does not support indexing"));
b99bd4ef 5419
c19d1205
ZW
5420 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5421 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5422
c19d1205
ZW
5423 if (!(inst.instruction & INDEX_UP))
5424 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5425
c19d1205
ZW
5426 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5427 {
5428 inst.operands[2].preind = 0;
5429 inst.operands[2].postind = 1;
5430 }
5431 }
b99bd4ef 5432
c19d1205 5433 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5434}
c19d1205
ZW
5435\f
5436/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5437
c19d1205
ZW
5438static void
5439do_iwmmxt_tandorc (void)
5440{
5441 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5442}
b99bd4ef 5443
c19d1205
ZW
5444static void
5445do_iwmmxt_textrc (void)
5446{
5447 inst.instruction |= inst.operands[0].reg << 12;
5448 inst.instruction |= inst.operands[1].imm;
5449}
b99bd4ef
NC
5450
5451static void
c19d1205 5452do_iwmmxt_textrm (void)
b99bd4ef 5453{
c19d1205
ZW
5454 inst.instruction |= inst.operands[0].reg << 12;
5455 inst.instruction |= inst.operands[1].reg << 16;
5456 inst.instruction |= inst.operands[2].imm;
5457}
b99bd4ef 5458
c19d1205
ZW
5459static void
5460do_iwmmxt_tinsr (void)
5461{
5462 inst.instruction |= inst.operands[0].reg << 16;
5463 inst.instruction |= inst.operands[1].reg << 12;
5464 inst.instruction |= inst.operands[2].imm;
5465}
b99bd4ef 5466
c19d1205
ZW
5467static void
5468do_iwmmxt_tmia (void)
5469{
5470 inst.instruction |= inst.operands[0].reg << 5;
5471 inst.instruction |= inst.operands[1].reg;
5472 inst.instruction |= inst.operands[2].reg << 12;
5473}
b99bd4ef 5474
c19d1205
ZW
5475static void
5476do_iwmmxt_waligni (void)
5477{
5478 inst.instruction |= inst.operands[0].reg << 12;
5479 inst.instruction |= inst.operands[1].reg << 16;
5480 inst.instruction |= inst.operands[2].reg;
5481 inst.instruction |= inst.operands[3].imm << 20;
5482}
b99bd4ef 5483
c19d1205
ZW
5484static void
5485do_iwmmxt_wmov (void)
5486{
5487 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5488 inst.instruction |= inst.operands[0].reg << 12;
5489 inst.instruction |= inst.operands[1].reg << 16;
5490 inst.instruction |= inst.operands[1].reg;
5491}
b99bd4ef 5492
c19d1205
ZW
5493static void
5494do_iwmmxt_wldstbh (void)
5495{
5496 inst.instruction |= inst.operands[0].reg << 12;
5497 inst.reloc.exp.X_add_number *= 4;
5498 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_CP_OFF_IMM_S2);
b99bd4ef
NC
5499}
5500
c19d1205
ZW
5501static void
5502do_iwmmxt_wldstw (void)
5503{
5504 /* RIWR_RIWC clears .isreg for a control register. */
5505 if (!inst.operands[0].isreg)
5506 {
5507 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5508 inst.instruction |= 0xf0000000;
5509 }
b99bd4ef 5510
c19d1205
ZW
5511 inst.instruction |= inst.operands[0].reg << 12;
5512 encode_arm_cp_address (1, TRUE, TRUE, 0);
5513}
b99bd4ef
NC
5514
5515static void
c19d1205 5516do_iwmmxt_wldstd (void)
b99bd4ef 5517{
c19d1205 5518 inst.instruction |= inst.operands[0].reg << 12;
f2184508 5519 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 5520}
b99bd4ef 5521
c19d1205
ZW
5522static void
5523do_iwmmxt_wshufh (void)
5524{
5525 inst.instruction |= inst.operands[0].reg << 12;
5526 inst.instruction |= inst.operands[1].reg << 16;
5527 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5528 inst.instruction |= (inst.operands[2].imm & 0x0f);
5529}
b99bd4ef 5530
c19d1205
ZW
5531static void
5532do_iwmmxt_wzero (void)
5533{
5534 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5535 inst.instruction |= inst.operands[0].reg;
5536 inst.instruction |= inst.operands[0].reg << 12;
5537 inst.instruction |= inst.operands[0].reg << 16;
5538}
5539\f
5540/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5541 operations first, then control, shift, and load/store. */
b99bd4ef 5542
c19d1205 5543/* Insns like "foo X,Y,Z". */
b99bd4ef 5544
c19d1205
ZW
5545static void
5546do_mav_triple (void)
5547{
5548 inst.instruction |= inst.operands[0].reg << 16;
5549 inst.instruction |= inst.operands[1].reg;
5550 inst.instruction |= inst.operands[2].reg << 12;
5551}
b99bd4ef 5552
c19d1205
ZW
5553/* Insns like "foo W,X,Y,Z".
5554 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5555
c19d1205
ZW
5556static void
5557do_mav_quad (void)
5558{
5559 inst.instruction |= inst.operands[0].reg << 5;
5560 inst.instruction |= inst.operands[1].reg << 12;
5561 inst.instruction |= inst.operands[2].reg << 16;
5562 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5563}
5564
c19d1205
ZW
5565/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5566static void
5567do_mav_dspsc (void)
a737bd4d 5568{
c19d1205
ZW
5569 inst.instruction |= inst.operands[1].reg << 12;
5570}
a737bd4d 5571
c19d1205
ZW
5572/* Maverick shift immediate instructions.
5573 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5574 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5575
c19d1205
ZW
5576static void
5577do_mav_shift (void)
5578{
5579 int imm = inst.operands[2].imm;
a737bd4d 5580
c19d1205
ZW
5581 inst.instruction |= inst.operands[0].reg << 12;
5582 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5583
c19d1205
ZW
5584 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5585 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5586 Bit 4 should be 0. */
5587 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5588
c19d1205
ZW
5589 inst.instruction |= imm;
5590}
5591\f
5592/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5593
c19d1205
ZW
5594/* Xscale multiply-accumulate (argument parse)
5595 MIAcc acc0,Rm,Rs
5596 MIAPHcc acc0,Rm,Rs
5597 MIAxycc acc0,Rm,Rs. */
a737bd4d 5598
c19d1205
ZW
5599static void
5600do_xsc_mia (void)
5601{
5602 inst.instruction |= inst.operands[1].reg;
5603 inst.instruction |= inst.operands[2].reg << 12;
5604}
a737bd4d 5605
c19d1205 5606/* Xscale move-accumulator-register (argument parse)
a737bd4d 5607
c19d1205 5608 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5609
c19d1205
ZW
5610static void
5611do_xsc_mar (void)
5612{
5613 inst.instruction |= inst.operands[1].reg << 12;
5614 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5615}
5616
c19d1205 5617/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5618
c19d1205 5619 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5620
5621static void
c19d1205 5622do_xsc_mra (void)
b99bd4ef 5623{
c19d1205
ZW
5624 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5625 inst.instruction |= inst.operands[0].reg << 12;
5626 inst.instruction |= inst.operands[1].reg << 16;
5627}
5628\f
5629/* Encoding functions relevant only to Thumb. */
b99bd4ef 5630
c19d1205
ZW
5631/* inst.operands[i] is a shifted-register operand; encode
5632 it into inst.instruction in the format used by Thumb32. */
5633
5634static void
5635encode_thumb32_shifted_operand (int i)
5636{
5637 unsigned int value = inst.reloc.exp.X_add_number;
5638 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5639
9c3c69f2
PB
5640 constraint (inst.operands[i].immisreg,
5641 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
5642 inst.instruction |= inst.operands[i].reg;
5643 if (shift == SHIFT_RRX)
5644 inst.instruction |= SHIFT_ROR << 4;
5645 else
b99bd4ef 5646 {
c19d1205
ZW
5647 constraint (inst.reloc.exp.X_op != O_constant,
5648 _("expression too complex"));
5649
5650 constraint (value > 32
5651 || (value == 32 && (shift == SHIFT_LSL
5652 || shift == SHIFT_ROR)),
5653 _("shift expression is too large"));
5654
5655 if (value == 0)
5656 shift = SHIFT_LSL;
5657 else if (value == 32)
5658 value = 0;
5659
5660 inst.instruction |= shift << 4;
5661 inst.instruction |= (value & 0x1c) << 10;
5662 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5663 }
c19d1205 5664}
b99bd4ef 5665
b99bd4ef 5666
c19d1205
ZW
5667/* inst.operands[i] was set up by parse_address. Encode it into a
5668 Thumb32 format load or store instruction. Reject forms that cannot
5669 be used with such instructions. If is_t is true, reject forms that
5670 cannot be used with a T instruction; if is_d is true, reject forms
5671 that cannot be used with a D instruction. */
b99bd4ef 5672
c19d1205
ZW
5673static void
5674encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5675{
5676 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5677
5678 constraint (!inst.operands[i].isreg,
5679 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5680
c19d1205
ZW
5681 inst.instruction |= inst.operands[i].reg << 16;
5682 if (inst.operands[i].immisreg)
b99bd4ef 5683 {
c19d1205
ZW
5684 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5685 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5686 constraint (inst.operands[i].negative,
5687 _("Thumb does not support negative register indexing"));
5688 constraint (inst.operands[i].postind,
5689 _("Thumb does not support register post-indexing"));
5690 constraint (inst.operands[i].writeback,
5691 _("Thumb does not support register indexing with writeback"));
5692 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5693 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5694
c19d1205
ZW
5695 inst.instruction |= inst.operands[1].imm;
5696 if (inst.operands[i].shifted)
b99bd4ef 5697 {
c19d1205
ZW
5698 constraint (inst.reloc.exp.X_op != O_constant,
5699 _("expression too complex"));
9c3c69f2
PB
5700 constraint (inst.reloc.exp.X_add_number < 0
5701 || inst.reloc.exp.X_add_number > 3,
c19d1205 5702 _("shift out of range"));
9c3c69f2 5703 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
5704 }
5705 inst.reloc.type = BFD_RELOC_UNUSED;
5706 }
5707 else if (inst.operands[i].preind)
5708 {
5709 constraint (is_pc && inst.operands[i].writeback,
5710 _("cannot use writeback with PC-relative addressing"));
5711 constraint (is_t && inst.operands[1].writeback,
5712 _("cannot use writeback with this instruction"));
5713
5714 if (is_d)
5715 {
5716 inst.instruction |= 0x01000000;
5717 if (inst.operands[i].writeback)
5718 inst.instruction |= 0x00200000;
b99bd4ef 5719 }
c19d1205 5720 else
b99bd4ef 5721 {
c19d1205
ZW
5722 inst.instruction |= 0x00000c00;
5723 if (inst.operands[i].writeback)
5724 inst.instruction |= 0x00000100;
b99bd4ef 5725 }
c19d1205 5726 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 5727 }
c19d1205 5728 else if (inst.operands[i].postind)
b99bd4ef 5729 {
c19d1205
ZW
5730 assert (inst.operands[i].writeback);
5731 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5732 constraint (is_t, _("cannot use post-indexing with this instruction"));
5733
5734 if (is_d)
5735 inst.instruction |= 0x00200000;
5736 else
5737 inst.instruction |= 0x00000900;
5738 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5739 }
5740 else /* unindexed - only for coprocessor */
5741 inst.error = _("instruction does not accept unindexed addressing");
5742}
5743
5744/* Table of Thumb instructions which exist in both 16- and 32-bit
5745 encodings (the latter only in post-V6T2 cores). The index is the
5746 value used in the insns table below. When there is more than one
5747 possible 16-bit encoding for the instruction, this table always
5748 holds variant (1). */
5749#define T16_32_TAB \
5750 X(adc, 4140, eb400000), \
5751 X(adcs, 4140, eb500000), \
5752 X(add, 1c00, eb000000), \
5753 X(adds, 1c00, eb100000), \
e9f89963 5754 X(adr, 000f, f20f0000), \
c19d1205
ZW
5755 X(and, 4000, ea000000), \
5756 X(ands, 4000, ea100000), \
5757 X(asr, 1000, fa40f000), \
5758 X(asrs, 1000, fa50f000), \
5759 X(bic, 4380, ea200000), \
5760 X(bics, 4380, ea300000), \
5761 X(cmn, 42c0, eb100f00), \
5762 X(cmp, 2800, ebb00f00), \
5763 X(cpsie, b660, f3af8400), \
5764 X(cpsid, b670, f3af8600), \
5765 X(cpy, 4600, ea4f0000), \
5766 X(eor, 4040, ea800000), \
5767 X(eors, 4040, ea900000), \
5768 X(ldmia, c800, e8900000), \
5769 X(ldr, 6800, f8500000), \
5770 X(ldrb, 7800, f8100000), \
5771 X(ldrh, 8800, f8300000), \
5772 X(ldrsb, 5600, f9100000), \
5773 X(ldrsh, 5e00, f9300000), \
5774 X(lsl, 0000, fa00f000), \
5775 X(lsls, 0000, fa10f000), \
5776 X(lsr, 0800, fa20f000), \
5777 X(lsrs, 0800, fa30f000), \
5778 X(mov, 2000, ea4f0000), \
5779 X(movs, 2000, ea5f0000), \
5780 X(mul, 4340, fb00f000), \
5781 X(muls, 4340, ffffffff), /* no 32b muls */ \
5782 X(mvn, 43c0, ea6f0000), \
5783 X(mvns, 43c0, ea7f0000), \
5784 X(neg, 4240, f1c00000), /* rsb #0 */ \
5785 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5786 X(orr, 4300, ea400000), \
5787 X(orrs, 4300, ea500000), \
e9f89963
PB
5788 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
5789 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
5790 X(rev, ba00, fa90f080), \
5791 X(rev16, ba40, fa90f090), \
5792 X(revsh, bac0, fa90f0b0), \
5793 X(ror, 41c0, fa60f000), \
5794 X(rors, 41c0, fa70f000), \
5795 X(sbc, 4180, eb600000), \
5796 X(sbcs, 4180, eb700000), \
5797 X(stmia, c000, e8800000), \
5798 X(str, 6000, f8400000), \
5799 X(strb, 7000, f8000000), \
5800 X(strh, 8000, f8200000), \
5801 X(sub, 1e00, eba00000), \
5802 X(subs, 1e00, ebb00000), \
5803 X(sxtb, b240, fa4ff080), \
5804 X(sxth, b200, fa0ff080), \
5805 X(tst, 4200, ea100f00), \
5806 X(uxtb, b2c0, fa5ff080), \
5807 X(uxth, b280, fa1ff080), \
5808 X(nop, bf00, f3af8000), \
5809 X(yield, bf10, f3af8001), \
5810 X(wfe, bf20, f3af8002), \
5811 X(wfi, bf30, f3af8003), \
5812 X(sev, bf40, f3af9004), /* typo, 8004? */
5813
5814/* To catch errors in encoding functions, the codes are all offset by
5815 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5816 as 16-bit instructions. */
5817#define X(a,b,c) T_MNEM_##a
5818enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5819#undef X
5820
5821#define X(a,b,c) 0x##b
5822static const unsigned short thumb_op16[] = { T16_32_TAB };
5823#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5824#undef X
5825
5826#define X(a,b,c) 0x##c
5827static const unsigned int thumb_op32[] = { T16_32_TAB };
5828#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5829#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5830#undef X
5831#undef T16_32_TAB
5832
5833/* Thumb instruction encoders, in alphabetical order. */
5834
92e90b6e
PB
5835/* ADDW or SUBW. */
5836static void
5837do_t_add_sub_w (void)
5838{
5839 int Rd, Rn;
5840
5841 Rd = inst.operands[0].reg;
5842 Rn = inst.operands[1].reg;
5843
5844 constraint (Rd == 15, _("PC not allowed as destination"));
5845 inst.instruction |= (Rn << 16) | (Rd << 8);
5846 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
5847}
5848
c19d1205
ZW
5849/* Parse an add or subtract instruction. We get here with inst.instruction
5850 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5851
5852static void
5853do_t_add_sub (void)
5854{
5855 int Rd, Rs, Rn;
5856
5857 Rd = inst.operands[0].reg;
5858 Rs = (inst.operands[1].present
5859 ? inst.operands[1].reg /* Rd, Rs, foo */
5860 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5861
5862 if (unified_syntax)
5863 {
5864 if (!inst.operands[2].isreg)
b99bd4ef 5865 {
c19d1205
ZW
5866 /* For an immediate, we always generate a 32-bit opcode;
5867 section relaxation will shrink it later if possible. */
5868 inst.instruction = THUMB_OP32 (inst.instruction);
5869 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
5870 inst.instruction |= inst.operands[0].reg << 8;
5871 inst.instruction |= inst.operands[1].reg << 16;
5872 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 5873 }
c19d1205
ZW
5874 else
5875 {
5876 Rn = inst.operands[2].reg;
5877 /* See if we can do this with a 16-bit instruction. */
5878 if (!inst.operands[2].shifted && inst.size_req != 4)
5879 {
5880 if (Rd <= 7 && Rn <= 7 && Rn <= 7
5881 && (inst.instruction == T_MNEM_adds
5882 || inst.instruction == T_MNEM_subs))
5883 {
5884 inst.instruction = (inst.instruction == T_MNEM_adds
5885 ? T_OPCODE_ADD_R3
5886 : T_OPCODE_SUB_R3);
5887 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
5888 return;
5889 }
b99bd4ef 5890
c19d1205
ZW
5891 if (inst.instruction == T_MNEM_add)
5892 {
5893 if (Rd == Rs)
5894 {
5895 inst.instruction = T_OPCODE_ADD_HI;
5896 inst.instruction |= (Rd & 8) << 4;
5897 inst.instruction |= (Rd & 7);
5898 inst.instruction |= Rn << 3;
5899 return;
5900 }
5901 /* ... because addition is commutative! */
5902 else if (Rd == Rn)
5903 {
5904 inst.instruction = T_OPCODE_ADD_HI;
5905 inst.instruction |= (Rd & 8) << 4;
5906 inst.instruction |= (Rd & 7);
5907 inst.instruction |= Rs << 3;
5908 return;
5909 }
5910 }
5911 }
5912 /* If we get here, it can't be done in 16 bits. */
5913 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
5914 _("shift must be constant"));
5915 inst.instruction = THUMB_OP32 (inst.instruction);
5916 inst.instruction |= Rd << 8;
5917 inst.instruction |= Rs << 16;
5918 encode_thumb32_shifted_operand (2);
5919 }
5920 }
5921 else
5922 {
5923 constraint (inst.instruction == T_MNEM_adds
5924 || inst.instruction == T_MNEM_subs,
5925 BAD_THUMB32);
b99bd4ef 5926
c19d1205 5927 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 5928 {
c19d1205
ZW
5929 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
5930 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
5931 BAD_HIREG);
5932
5933 inst.instruction = (inst.instruction == T_MNEM_add
5934 ? 0x0000 : 0x8000);
5935 inst.instruction |= (Rd << 4) | Rs;
5936 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
5937 return;
5938 }
5939
c19d1205
ZW
5940 Rn = inst.operands[2].reg;
5941 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 5942
c19d1205
ZW
5943 /* We now have Rd, Rs, and Rn set to registers. */
5944 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 5945 {
c19d1205
ZW
5946 /* Can't do this for SUB. */
5947 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
5948 inst.instruction = T_OPCODE_ADD_HI;
5949 inst.instruction |= (Rd & 8) << 4;
5950 inst.instruction |= (Rd & 7);
5951 if (Rs == Rd)
5952 inst.instruction |= Rn << 3;
5953 else if (Rn == Rd)
5954 inst.instruction |= Rs << 3;
5955 else
5956 constraint (1, _("dest must overlap one source register"));
5957 }
5958 else
5959 {
5960 inst.instruction = (inst.instruction == T_MNEM_add
5961 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
5962 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 5963 }
b99bd4ef 5964 }
b99bd4ef
NC
5965}
5966
c19d1205
ZW
5967static void
5968do_t_adr (void)
5969{
e9f89963
PB
5970 if (unified_syntax && inst.size_req != 2)
5971 {
5972 /* Always generate a 32-bit opcode;
5973 section relaxation will shrink it later if possible. */
5974 inst.instruction = THUMB_OP32 (inst.instruction);
5975 inst.instruction |= inst.operands[0].reg << 8;
5976 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
5977 inst.reloc.pc_rel = 1;
5978 }
5979 else
5980 {
5981 inst.instruction = THUMB_OP16 (inst.instruction);
5982 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
5983 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
5984 inst.reloc.pc_rel = 1;
b99bd4ef 5985
e9f89963
PB
5986 inst.instruction |= inst.operands[0].reg << 4;
5987 }
c19d1205 5988}
b99bd4ef 5989
c19d1205
ZW
5990/* Arithmetic instructions for which there is just one 16-bit
5991 instruction encoding, and it allows only two low registers.
5992 For maximal compatibility with ARM syntax, we allow three register
5993 operands even when Thumb-32 instructions are not available, as long
5994 as the first two are identical. For instance, both "sbc r0,r1" and
5995 "sbc r0,r0,r1" are allowed. */
b99bd4ef 5996static void
c19d1205 5997do_t_arit3 (void)
b99bd4ef 5998{
c19d1205 5999 int Rd, Rs, Rn;
b99bd4ef 6000
c19d1205
ZW
6001 Rd = inst.operands[0].reg;
6002 Rs = (inst.operands[1].present
6003 ? inst.operands[1].reg /* Rd, Rs, foo */
6004 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6005 Rn = inst.operands[2].reg;
b99bd4ef 6006
c19d1205 6007 if (unified_syntax)
b99bd4ef 6008 {
c19d1205
ZW
6009 if (!inst.operands[2].isreg)
6010 {
6011 /* For an immediate, we always generate a 32-bit opcode;
6012 section relaxation will shrink it later if possible. */
6013 inst.instruction = THUMB_OP32 (inst.instruction);
6014 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6015 inst.instruction |= Rd << 8;
6016 inst.instruction |= Rs << 16;
6017 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6018 }
6019 else
6020 {
6021 /* See if we can do this with a 16-bit instruction. */
6022 if (THUMB_SETS_FLAGS (inst.instruction)
6023 && !inst.operands[2].shifted
6024 && inst.size_req != 4
6025 && Rd == Rs)
6026 {
6027 inst.instruction = THUMB_OP16 (inst.instruction);
6028 inst.instruction |= Rd;
6029 inst.instruction |= Rn << 3;
6030 return;
6031 }
b99bd4ef 6032
c19d1205
ZW
6033 /* If we get here, it can't be done in 16 bits. */
6034 constraint (inst.operands[2].shifted
6035 && inst.operands[2].immisreg,
6036 _("shift must be constant"));
6037 inst.instruction = THUMB_OP32 (inst.instruction);
6038 inst.instruction |= Rd << 8;
6039 inst.instruction |= Rs << 16;
6040 encode_thumb32_shifted_operand (2);
6041 }
a737bd4d 6042 }
c19d1205 6043 else
b99bd4ef 6044 {
c19d1205
ZW
6045 /* On its face this is a lie - the instruction does set the
6046 flags. However, the only supported mnemonic in this mode
6047 says it doesn't. */
6048 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6049
c19d1205
ZW
6050 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6051 _("unshifted register required"));
6052 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6053 constraint (Rd != Rs,
6054 _("dest and source1 must be the same register"));
a737bd4d 6055
c19d1205
ZW
6056 inst.instruction = THUMB_OP16 (inst.instruction);
6057 inst.instruction |= Rd;
6058 inst.instruction |= Rn << 3;
b99bd4ef 6059 }
a737bd4d 6060}
b99bd4ef 6061
c19d1205
ZW
6062/* Similarly, but for instructions where the arithmetic operation is
6063 commutative, so we can allow either of them to be different from
6064 the destination operand in a 16-bit instruction. For instance, all
6065 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6066 accepted. */
6067static void
6068do_t_arit3c (void)
a737bd4d 6069{
c19d1205 6070 int Rd, Rs, Rn;
b99bd4ef 6071
c19d1205
ZW
6072 Rd = inst.operands[0].reg;
6073 Rs = (inst.operands[1].present
6074 ? inst.operands[1].reg /* Rd, Rs, foo */
6075 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6076 Rn = inst.operands[2].reg;
a737bd4d 6077
c19d1205 6078 if (unified_syntax)
a737bd4d 6079 {
c19d1205 6080 if (!inst.operands[2].isreg)
b99bd4ef 6081 {
c19d1205
ZW
6082 /* For an immediate, we always generate a 32-bit opcode;
6083 section relaxation will shrink it later if possible. */
6084 inst.instruction = THUMB_OP32 (inst.instruction);
6085 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6086 inst.instruction |= Rd << 8;
6087 inst.instruction |= Rs << 16;
6088 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6089 }
c19d1205 6090 else
a737bd4d 6091 {
c19d1205
ZW
6092 /* See if we can do this with a 16-bit instruction. */
6093 if (THUMB_SETS_FLAGS (inst.instruction)
6094 && !inst.operands[2].shifted
6095 && inst.size_req != 4)
a737bd4d 6096 {
c19d1205 6097 if (Rd == Rs)
a737bd4d 6098 {
c19d1205
ZW
6099 inst.instruction = THUMB_OP16 (inst.instruction);
6100 inst.instruction |= Rd;
6101 inst.instruction |= Rn << 3;
6102 return;
a737bd4d 6103 }
c19d1205 6104 if (Rd == Rn)
a737bd4d 6105 {
c19d1205
ZW
6106 inst.instruction = THUMB_OP16 (inst.instruction);
6107 inst.instruction |= Rd;
6108 inst.instruction |= Rs << 3;
6109 return;
a737bd4d
NC
6110 }
6111 }
c19d1205
ZW
6112
6113 /* If we get here, it can't be done in 16 bits. */
6114 constraint (inst.operands[2].shifted
6115 && inst.operands[2].immisreg,
6116 _("shift must be constant"));
6117 inst.instruction = THUMB_OP32 (inst.instruction);
6118 inst.instruction |= Rd << 8;
6119 inst.instruction |= Rs << 16;
6120 encode_thumb32_shifted_operand (2);
a737bd4d 6121 }
b99bd4ef 6122 }
c19d1205
ZW
6123 else
6124 {
6125 /* On its face this is a lie - the instruction does set the
6126 flags. However, the only supported mnemonic in this mode
6127 says it doesn't. */
6128 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6129
c19d1205
ZW
6130 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6131 _("unshifted register required"));
6132 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6133
6134 inst.instruction = THUMB_OP16 (inst.instruction);
6135 inst.instruction |= Rd;
6136
6137 if (Rd == Rs)
6138 inst.instruction |= Rn << 3;
6139 else if (Rd == Rn)
6140 inst.instruction |= Rs << 3;
6141 else
6142 constraint (1, _("dest must overlap one source register"));
6143 }
a737bd4d
NC
6144}
6145
c19d1205
ZW
6146static void
6147do_t_bfc (void)
a737bd4d 6148{
c19d1205
ZW
6149 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6150 constraint (msb > 32, _("bit-field extends past end of register"));
6151 /* The instruction encoding stores the LSB and MSB,
6152 not the LSB and width. */
6153 inst.instruction |= inst.operands[0].reg << 8;
6154 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6155 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6156 inst.instruction |= msb - 1;
b99bd4ef
NC
6157}
6158
c19d1205
ZW
6159static void
6160do_t_bfi (void)
b99bd4ef 6161{
c19d1205 6162 unsigned int msb;
b99bd4ef 6163
c19d1205
ZW
6164 /* #0 in second position is alternative syntax for bfc, which is
6165 the same instruction but with REG_PC in the Rm field. */
6166 if (!inst.operands[1].isreg)
6167 inst.operands[1].reg = REG_PC;
b99bd4ef 6168
c19d1205
ZW
6169 msb = inst.operands[2].imm + inst.operands[3].imm;
6170 constraint (msb > 32, _("bit-field extends past end of register"));
6171 /* The instruction encoding stores the LSB and MSB,
6172 not the LSB and width. */
6173 inst.instruction |= inst.operands[0].reg << 8;
6174 inst.instruction |= inst.operands[1].reg << 16;
6175 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6176 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6177 inst.instruction |= msb - 1;
b99bd4ef
NC
6178}
6179
c19d1205
ZW
6180static void
6181do_t_bfx (void)
b99bd4ef 6182{
c19d1205
ZW
6183 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6184 _("bit-field extends past end of register"));
6185 inst.instruction |= inst.operands[0].reg << 8;
6186 inst.instruction |= inst.operands[1].reg << 16;
6187 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6188 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6189 inst.instruction |= inst.operands[3].imm - 1;
6190}
b99bd4ef 6191
c19d1205
ZW
6192/* ARM V5 Thumb BLX (argument parse)
6193 BLX <target_addr> which is BLX(1)
6194 BLX <Rm> which is BLX(2)
6195 Unfortunately, there are two different opcodes for this mnemonic.
6196 So, the insns[].value is not used, and the code here zaps values
6197 into inst.instruction.
b99bd4ef 6198
c19d1205
ZW
6199 ??? How to take advantage of the additional two bits of displacement
6200 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6201
c19d1205
ZW
6202static void
6203do_t_blx (void)
6204{
6205 if (inst.operands[0].isreg)
6206 /* We have a register, so this is BLX(2). */
6207 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6208 else
6209 {
c19d1205 6210 /* No register. This must be BLX(1). */
2fc8bdac 6211 inst.instruction = 0xf000e800;
c19d1205
ZW
6212 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6213 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6214 }
6215}
6216
c19d1205
ZW
6217static void
6218do_t_branch (void)
b99bd4ef 6219{
c19d1205
ZW
6220 if (unified_syntax && inst.size_req != 2)
6221 {
6222 if (inst.cond == COND_ALWAYS)
6223 {
2fc8bdac 6224 inst.instruction = 0xf000b000;
c19d1205
ZW
6225 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6226 }
6227 else
6228 {
6229 assert (inst.cond != 0xF);
2fc8bdac 6230 inst.instruction = (inst.cond << 22) | 0xf0008000;
c19d1205
ZW
6231 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6232 }
6233 }
b99bd4ef
NC
6234 else
6235 {
c19d1205
ZW
6236 if (inst.cond == COND_ALWAYS)
6237 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6238 else
b99bd4ef 6239 {
2fc8bdac 6240 inst.instruction = 0xd000 | (inst.cond << 8);
c19d1205 6241 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6242 }
b99bd4ef 6243 }
c19d1205
ZW
6244
6245 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6246}
6247
6248static void
c19d1205 6249do_t_bkpt (void)
b99bd4ef 6250{
c19d1205 6251 if (inst.operands[0].present)
b99bd4ef 6252 {
c19d1205
ZW
6253 constraint (inst.operands[0].imm > 255,
6254 _("immediate value out of range"));
6255 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6256 }
b99bd4ef
NC
6257}
6258
6259static void
c19d1205 6260do_t_branch23 (void)
b99bd4ef 6261{
c19d1205 6262 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6263 inst.reloc.pc_rel = 1;
6264
c19d1205
ZW
6265 /* If the destination of the branch is a defined symbol which does not have
6266 the THUMB_FUNC attribute, then we must be calling a function which has
6267 the (interfacearm) attribute. We look for the Thumb entry point to that
6268 function and change the branch to refer to that function instead. */
6269 if ( inst.reloc.exp.X_op == O_symbol
6270 && inst.reloc.exp.X_add_symbol != NULL
6271 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6272 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6273 inst.reloc.exp.X_add_symbol =
6274 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6275}
6276
6277static void
c19d1205 6278do_t_bx (void)
90e4755a 6279{
c19d1205
ZW
6280 inst.instruction |= inst.operands[0].reg << 3;
6281 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6282 should cause the alignment to be checked once it is known. This is
6283 because BX PC only works if the instruction is word aligned. */
6284}
90e4755a 6285
c19d1205
ZW
6286static void
6287do_t_bxj (void)
6288{
6289 if (inst.operands[0].reg == REG_PC)
6290 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6291
c19d1205 6292 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6293}
6294
6295static void
c19d1205 6296do_t_clz (void)
90e4755a 6297{
c19d1205
ZW
6298 inst.instruction |= inst.operands[0].reg << 8;
6299 inst.instruction |= inst.operands[1].reg << 16;
6300 inst.instruction |= inst.operands[1].reg;
6301}
90e4755a 6302
c19d1205
ZW
6303static void
6304do_t_cpsi (void)
6305{
6306 if (unified_syntax
6307 && (inst.operands[1].present || inst.size_req == 4))
90e4755a 6308 {
c19d1205
ZW
6309 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6310 inst.instruction = 0xf3af8000;
6311 inst.instruction |= imod << 9;
6312 inst.instruction |= inst.operands[0].imm << 5;
6313 if (inst.operands[1].present)
6314 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6315 }
c19d1205 6316 else
90e4755a 6317 {
c19d1205
ZW
6318 constraint (inst.operands[1].present,
6319 _("Thumb does not support the 2-argument "
6320 "form of this instruction"));
6321 inst.instruction |= inst.operands[0].imm;
90e4755a 6322 }
90e4755a
RE
6323}
6324
c19d1205
ZW
6325/* THUMB CPY instruction (argument parse). */
6326
90e4755a 6327static void
c19d1205 6328do_t_cpy (void)
90e4755a 6329{
c19d1205 6330 if (inst.size_req == 4)
90e4755a 6331 {
c19d1205
ZW
6332 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6333 inst.instruction |= inst.operands[0].reg << 8;
6334 inst.instruction |= inst.operands[1].reg;
90e4755a 6335 }
c19d1205 6336 else
90e4755a 6337 {
c19d1205
ZW
6338 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6339 inst.instruction |= (inst.operands[0].reg & 0x7);
6340 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6341 }
90e4755a
RE
6342}
6343
90e4755a 6344static void
c19d1205 6345do_t_czb (void)
90e4755a 6346{
c19d1205
ZW
6347 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6348 inst.instruction |= inst.operands[0].reg;
6349 inst.reloc.pc_rel = 1;
6350 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6351}
90e4755a 6352
c19d1205
ZW
6353static void
6354do_t_hint (void)
6355{
6356 if (unified_syntax && inst.size_req == 4)
6357 inst.instruction = THUMB_OP32 (inst.instruction);
6358 else
6359 inst.instruction = THUMB_OP16 (inst.instruction);
6360}
90e4755a 6361
c19d1205
ZW
6362static void
6363do_t_it (void)
6364{
6365 unsigned int cond = inst.operands[0].imm;
6366 if ((cond & 0x1) == 0x0)
90e4755a 6367 {
c19d1205
ZW
6368 unsigned int mask = inst.instruction & 0x000f;
6369 inst.instruction &= 0xfff0;
90e4755a 6370
c19d1205
ZW
6371 if ((mask & 0x7) == 0)
6372 /* no conversion needed */;
6373 else if ((mask & 0x3) == 0)
6374 mask = (~(mask & 0x8) & 0x8) | 0x4;
6375 else if ((mask & 1) == 0)
6376 mask = (~(mask & 0xC) & 0xC) | 0x2;
6377 else
6378 mask = (~(mask & 0xE) & 0xE) | 0x1;
90e4755a 6379
c19d1205
ZW
6380 inst.instruction |= (mask & 0xF);
6381 }
90e4755a 6382
c19d1205
ZW
6383 inst.instruction |= cond << 4;
6384}
90e4755a 6385
c19d1205
ZW
6386static void
6387do_t_ldmstm (void)
6388{
6389 /* This really doesn't seem worth it. */
6390 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6391 _("expression too complex"));
6392 constraint (inst.operands[1].writeback,
6393 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6394
c19d1205
ZW
6395 if (unified_syntax)
6396 {
6397 /* See if we can use a 16-bit instruction. */
6398 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6399 && inst.size_req != 4
6400 && inst.operands[0].reg <= 7
6401 && !(inst.operands[1].imm & ~0xff)
6402 && (inst.instruction == T_MNEM_stmia
6403 ? inst.operands[0].writeback
6404 : (inst.operands[0].writeback
6405 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6406 {
c19d1205
ZW
6407 if (inst.instruction == T_MNEM_stmia
6408 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6409 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6410 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6411 inst.operands[0].reg);
90e4755a 6412
c19d1205
ZW
6413 inst.instruction = THUMB_OP16 (inst.instruction);
6414 inst.instruction |= inst.operands[0].reg << 8;
6415 inst.instruction |= inst.operands[1].imm;
6416 }
6417 else
6418 {
6419 if (inst.operands[1].imm & (1 << 13))
6420 as_warn (_("SP should not be in register list"));
6421 if (inst.instruction == T_MNEM_stmia)
90e4755a 6422 {
c19d1205
ZW
6423 if (inst.operands[1].imm & (1 << 15))
6424 as_warn (_("PC should not be in register list"));
6425 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6426 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6427 inst.operands[0].reg);
90e4755a
RE
6428 }
6429 else
6430 {
c19d1205
ZW
6431 if (inst.operands[1].imm & (1 << 14)
6432 && inst.operands[1].imm & (1 << 15))
6433 as_warn (_("LR and PC should not both be in register list"));
6434 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6435 && inst.operands[0].writeback)
6436 as_warn (_("base register should not be in register list "
6437 "when written back"));
90e4755a 6438 }
c19d1205
ZW
6439 if (inst.instruction < 0xffff)
6440 inst.instruction = THUMB_OP32 (inst.instruction);
6441 inst.instruction |= inst.operands[0].reg << 16;
6442 inst.instruction |= inst.operands[1].imm;
6443 if (inst.operands[0].writeback)
6444 inst.instruction |= WRITE_BACK;
90e4755a
RE
6445 }
6446 }
c19d1205 6447 else
90e4755a 6448 {
c19d1205
ZW
6449 constraint (inst.operands[0].reg > 7
6450 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6451 if (inst.instruction == T_MNEM_stmia)
f03698e6 6452 {
c19d1205
ZW
6453 if (!inst.operands[0].writeback)
6454 as_warn (_("this instruction will write back the base register"));
6455 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6456 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6457 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6458 inst.operands[0].reg);
f03698e6 6459 }
c19d1205 6460 else
90e4755a 6461 {
c19d1205
ZW
6462 if (!inst.operands[0].writeback
6463 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6464 as_warn (_("this instruction will write back the base register"));
6465 else if (inst.operands[0].writeback
6466 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6467 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6468 }
6469
c19d1205
ZW
6470 inst.instruction = THUMB_OP16 (inst.instruction);
6471 inst.instruction |= inst.operands[0].reg << 8;
6472 inst.instruction |= inst.operands[1].imm;
6473 }
6474}
e28cd48c 6475
c19d1205
ZW
6476static void
6477do_t_ldrex (void)
6478{
6479 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6480 || inst.operands[1].postind || inst.operands[1].writeback
6481 || inst.operands[1].immisreg || inst.operands[1].shifted
6482 || inst.operands[1].negative,
6483 _("instruction does not accept this addressing mode"));
e28cd48c 6484
c19d1205
ZW
6485 inst.instruction |= inst.operands[0].reg << 12;
6486 inst.instruction |= inst.operands[1].reg << 16;
6487 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6488}
e28cd48c 6489
c19d1205
ZW
6490static void
6491do_t_ldrexd (void)
6492{
6493 if (!inst.operands[1].present)
1cac9012 6494 {
c19d1205
ZW
6495 constraint (inst.operands[0].reg == REG_LR,
6496 _("r14 not allowed as first register "
6497 "when second register is omitted"));
6498 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6499 }
c19d1205
ZW
6500 constraint (inst.operands[0].reg == inst.operands[1].reg,
6501 BAD_OVERLAP);
b99bd4ef 6502
c19d1205
ZW
6503 inst.instruction |= inst.operands[0].reg << 12;
6504 inst.instruction |= inst.operands[1].reg << 8;
6505 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6506}
6507
6508static void
c19d1205 6509do_t_ldst (void)
b99bd4ef 6510{
c19d1205 6511 if (unified_syntax)
b99bd4ef 6512 {
c19d1205
ZW
6513 /* Generation of 16-bit instructions for anything other than
6514 Rd, [Rn, Ri] is deferred to section relaxation time. */
6515 if (inst.operands[1].isreg && inst.operands[1].immisreg
6516 && !inst.operands[1].shifted && !inst.operands[1].postind
6517 && !inst.operands[1].negative && inst.operands[0].reg <= 7
6518 && inst.operands[1].reg <= 7 && inst.operands[1].imm <= 7
6519 && inst.instruction <= 0xffff)
6520 {
6521 inst.instruction = THUMB_OP16 (inst.instruction);
6522 goto op16;
6523 }
6524
6525 inst.instruction = THUMB_OP32 (inst.instruction);
6526 inst.instruction |= inst.operands[0].reg << 12;
6527 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
6528 return;
6529 }
6530
c19d1205
ZW
6531 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6532
6533 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 6534 {
c19d1205
ZW
6535 /* Only [Rn,Rm] is acceptable. */
6536 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6537 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6538 || inst.operands[1].postind || inst.operands[1].shifted
6539 || inst.operands[1].negative,
6540 _("Thumb does not support this addressing mode"));
6541 inst.instruction = THUMB_OP16 (inst.instruction);
6542 goto op16;
b99bd4ef 6543 }
c19d1205
ZW
6544
6545 inst.instruction = THUMB_OP16 (inst.instruction);
6546 if (!inst.operands[1].isreg)
6547 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6548 return;
b99bd4ef 6549
c19d1205
ZW
6550 constraint (!inst.operands[1].preind
6551 || inst.operands[1].shifted
6552 || inst.operands[1].writeback,
6553 _("Thumb does not support this addressing mode"));
6554 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 6555 {
c19d1205
ZW
6556 constraint (inst.instruction & 0x0600,
6557 _("byte or halfword not valid for base register"));
6558 constraint (inst.operands[1].reg == REG_PC
6559 && !(inst.instruction & THUMB_LOAD_BIT),
6560 _("r15 based store not allowed"));
6561 constraint (inst.operands[1].immisreg,
6562 _("invalid base register for register offset"));
b99bd4ef 6563
c19d1205
ZW
6564 if (inst.operands[1].reg == REG_PC)
6565 inst.instruction = T_OPCODE_LDR_PC;
6566 else if (inst.instruction & THUMB_LOAD_BIT)
6567 inst.instruction = T_OPCODE_LDR_SP;
6568 else
6569 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 6570
c19d1205
ZW
6571 inst.instruction |= inst.operands[0].reg << 8;
6572 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6573 return;
6574 }
90e4755a 6575
c19d1205
ZW
6576 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6577 if (!inst.operands[1].immisreg)
6578 {
6579 /* Immediate offset. */
6580 inst.instruction |= inst.operands[0].reg;
6581 inst.instruction |= inst.operands[1].reg << 3;
6582 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6583 return;
6584 }
90e4755a 6585
c19d1205
ZW
6586 /* Register offset. */
6587 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6588 constraint (inst.operands[1].negative,
6589 _("Thumb does not support this addressing mode"));
90e4755a 6590
c19d1205
ZW
6591 op16:
6592 switch (inst.instruction)
6593 {
6594 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6595 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6596 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6597 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6598 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6599 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6600 case 0x5600 /* ldrsb */:
6601 case 0x5e00 /* ldrsh */: break;
6602 default: abort ();
6603 }
90e4755a 6604
c19d1205
ZW
6605 inst.instruction |= inst.operands[0].reg;
6606 inst.instruction |= inst.operands[1].reg << 3;
6607 inst.instruction |= inst.operands[1].imm << 6;
6608}
90e4755a 6609
c19d1205
ZW
6610static void
6611do_t_ldstd (void)
6612{
6613 if (!inst.operands[1].present)
b99bd4ef 6614 {
c19d1205
ZW
6615 inst.operands[1].reg = inst.operands[0].reg + 1;
6616 constraint (inst.operands[0].reg == REG_LR,
6617 _("r14 not allowed here"));
b99bd4ef 6618 }
c19d1205
ZW
6619 inst.instruction |= inst.operands[0].reg << 12;
6620 inst.instruction |= inst.operands[1].reg << 8;
6621 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6622
b99bd4ef
NC
6623}
6624
c19d1205
ZW
6625static void
6626do_t_ldstt (void)
6627{
6628 inst.instruction |= inst.operands[0].reg << 12;
6629 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6630}
a737bd4d 6631
b99bd4ef 6632static void
c19d1205 6633do_t_mla (void)
b99bd4ef 6634{
c19d1205
ZW
6635 inst.instruction |= inst.operands[0].reg << 8;
6636 inst.instruction |= inst.operands[1].reg << 16;
6637 inst.instruction |= inst.operands[2].reg;
6638 inst.instruction |= inst.operands[3].reg << 12;
6639}
b99bd4ef 6640
c19d1205
ZW
6641static void
6642do_t_mlal (void)
6643{
6644 inst.instruction |= inst.operands[0].reg << 12;
6645 inst.instruction |= inst.operands[1].reg << 8;
6646 inst.instruction |= inst.operands[2].reg << 16;
6647 inst.instruction |= inst.operands[3].reg;
6648}
b99bd4ef 6649
c19d1205
ZW
6650static void
6651do_t_mov_cmp (void)
6652{
6653 if (unified_syntax)
b99bd4ef 6654 {
c19d1205
ZW
6655 int r0off = (inst.instruction == T_MNEM_mov
6656 || inst.instruction == T_MNEM_movs) ? 8 : 16;
6657 if (!inst.operands[1].isreg)
6658 {
6659 /* For an immediate, we always generate a 32-bit opcode;
6660 section relaxation will shrink it later if possible. */
6661 inst.instruction = THUMB_OP32 (inst.instruction);
6662 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6663 inst.instruction |= inst.operands[0].reg << r0off;
6664 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6665 }
6666 else if (inst.size_req == 4
6667 || inst.operands[1].shifted
6668 || (inst.instruction == T_MNEM_movs
6669 && (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)))
6670 {
6671 inst.instruction = THUMB_OP32 (inst.instruction);
6672 inst.instruction |= inst.operands[0].reg << r0off;
6673 encode_thumb32_shifted_operand (1);
6674 }
6675 else
6676 switch (inst.instruction)
6677 {
6678 case T_MNEM_mov:
6679 inst.instruction = T_OPCODE_MOV_HR;
6680 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6681 inst.instruction |= (inst.operands[0].reg & 0x7);
6682 inst.instruction |= inst.operands[1].reg << 3;
6683 break;
b99bd4ef 6684
c19d1205
ZW
6685 case T_MNEM_movs:
6686 /* We know we have low registers at this point.
6687 Generate ADD Rd, Rs, #0. */
6688 inst.instruction = T_OPCODE_ADD_I3;
6689 inst.instruction |= inst.operands[0].reg;
6690 inst.instruction |= inst.operands[1].reg << 3;
6691 break;
6692
6693 case T_MNEM_cmp:
6694 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7)
6695 {
6696 inst.instruction = T_OPCODE_CMP_LR;
6697 inst.instruction |= inst.operands[0].reg;
6698 inst.instruction |= inst.operands[1].reg << 3;
6699 }
6700 else
6701 {
6702 inst.instruction = T_OPCODE_CMP_HR;
6703 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6704 inst.instruction |= (inst.operands[0].reg & 0x7);
6705 inst.instruction |= inst.operands[1].reg << 3;
6706 }
6707 break;
6708 }
b99bd4ef
NC
6709 return;
6710 }
6711
c19d1205
ZW
6712 inst.instruction = THUMB_OP16 (inst.instruction);
6713 if (inst.operands[1].isreg)
b99bd4ef 6714 {
c19d1205 6715 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 6716 {
c19d1205
ZW
6717 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
6718 since a MOV instruction produces unpredictable results. */
6719 if (inst.instruction == T_OPCODE_MOV_I8)
6720 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 6721 else
c19d1205 6722 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 6723
c19d1205
ZW
6724 inst.instruction |= inst.operands[0].reg;
6725 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
6726 }
6727 else
6728 {
c19d1205
ZW
6729 if (inst.instruction == T_OPCODE_MOV_I8)
6730 inst.instruction = T_OPCODE_MOV_HR;
6731 else
6732 inst.instruction = T_OPCODE_CMP_HR;
6733 do_t_cpy ();
b99bd4ef
NC
6734 }
6735 }
c19d1205 6736 else
b99bd4ef 6737 {
c19d1205
ZW
6738 constraint (inst.operands[0].reg > 7,
6739 _("only lo regs allowed with immediate"));
6740 inst.instruction |= inst.operands[0].reg << 8;
6741 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6742 }
6743}
b99bd4ef 6744
c19d1205
ZW
6745static void
6746do_t_mov16 (void)
6747{
6748 inst.instruction |= inst.operands[0].reg << 8;
6749 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
6750 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
6751 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
6752 inst.instruction |= (inst.operands[1].imm & 0x00ff);
6753}
b99bd4ef 6754
c19d1205
ZW
6755static void
6756do_t_mvn_tst (void)
6757{
6758 if (unified_syntax)
6759 {
6760 int r0off = (inst.instruction == T_MNEM_mvn
6761 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
6762 if (!inst.operands[1].isreg)
b99bd4ef 6763 {
c19d1205
ZW
6764 /* For an immediate, we always generate a 32-bit opcode;
6765 section relaxation will shrink it later if possible. */
6766 if (inst.instruction < 0xffff)
6767 inst.instruction = THUMB_OP32 (inst.instruction);
6768 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6769 inst.instruction |= inst.operands[0].reg << r0off;
6770 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6771 }
c19d1205 6772 else
b99bd4ef 6773 {
c19d1205
ZW
6774 /* See if we can do this with a 16-bit instruction. */
6775 if (inst.instruction < 0xffff
6776 && THUMB_SETS_FLAGS (inst.instruction)
6777 && !inst.operands[1].shifted
6778 && inst.operands[0].reg <= 7
6779 && inst.operands[1].reg <= 7
6780 && inst.size_req != 4)
b99bd4ef 6781 {
c19d1205
ZW
6782 inst.instruction = THUMB_OP16 (inst.instruction);
6783 inst.instruction |= inst.operands[0].reg;
6784 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6785 }
c19d1205 6786 else
b99bd4ef 6787 {
c19d1205
ZW
6788 constraint (inst.operands[1].shifted
6789 && inst.operands[1].immisreg,
6790 _("shift must be constant"));
6791 if (inst.instruction < 0xffff)
6792 inst.instruction = THUMB_OP32 (inst.instruction);
6793 inst.instruction |= inst.operands[0].reg << r0off;
6794 encode_thumb32_shifted_operand (1);
b99bd4ef 6795 }
b99bd4ef
NC
6796 }
6797 }
6798 else
6799 {
c19d1205
ZW
6800 constraint (inst.instruction > 0xffff
6801 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
6802 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
6803 _("unshifted register required"));
6804 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6805 BAD_HIREG);
b99bd4ef 6806
c19d1205
ZW
6807 inst.instruction = THUMB_OP16 (inst.instruction);
6808 inst.instruction |= inst.operands[0].reg;
6809 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 6810 }
b99bd4ef
NC
6811}
6812
b05fe5cf 6813static void
c19d1205 6814do_t_mrs (void)
b05fe5cf 6815{
c19d1205
ZW
6816 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
6817 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
6818 != (PSR_c|PSR_f),
6819 _("'CPSR' or 'SPSR' expected"));
6820 inst.instruction |= inst.operands[0].reg << 8;
6821 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
6822}
b05fe5cf 6823
c19d1205
ZW
6824static void
6825do_t_msr (void)
6826{
6827 constraint (!inst.operands[1].isreg,
6828 _("Thumb encoding does not support an immediate here"));
6829 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
6830 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
6831 inst.instruction |= inst.operands[1].reg << 16;
6832}
b05fe5cf 6833
c19d1205
ZW
6834static void
6835do_t_mul (void)
6836{
6837 if (!inst.operands[2].present)
6838 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 6839
c19d1205
ZW
6840 /* There is no 32-bit MULS and no 16-bit MUL. */
6841 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 6842 {
c19d1205
ZW
6843 inst.instruction = THUMB_OP32 (inst.instruction);
6844 inst.instruction |= inst.operands[0].reg << 8;
6845 inst.instruction |= inst.operands[1].reg << 16;
6846 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 6847 }
c19d1205 6848 else
b05fe5cf 6849 {
c19d1205
ZW
6850 constraint (!unified_syntax
6851 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
6852 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6853 BAD_HIREG);
b05fe5cf 6854
c19d1205
ZW
6855 inst.instruction = THUMB_OP16 (inst.instruction);
6856 inst.instruction |= inst.operands[0].reg;
b05fe5cf 6857
c19d1205
ZW
6858 if (inst.operands[0].reg == inst.operands[1].reg)
6859 inst.instruction |= inst.operands[2].reg << 3;
6860 else if (inst.operands[0].reg == inst.operands[2].reg)
6861 inst.instruction |= inst.operands[1].reg << 3;
6862 else
6863 constraint (1, _("dest must overlap one source register"));
6864 }
6865}
b05fe5cf 6866
c19d1205
ZW
6867static void
6868do_t_mull (void)
6869{
6870 inst.instruction |= inst.operands[0].reg << 12;
6871 inst.instruction |= inst.operands[1].reg << 8;
6872 inst.instruction |= inst.operands[2].reg << 16;
6873 inst.instruction |= inst.operands[3].reg;
b05fe5cf 6874
c19d1205
ZW
6875 if (inst.operands[0].reg == inst.operands[1].reg)
6876 as_tsktsk (_("rdhi and rdlo must be different"));
6877}
b05fe5cf 6878
c19d1205
ZW
6879static void
6880do_t_nop (void)
6881{
6882 if (unified_syntax)
6883 {
6884 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 6885 {
c19d1205
ZW
6886 inst.instruction = THUMB_OP32 (inst.instruction);
6887 inst.instruction |= inst.operands[0].imm;
6888 }
6889 else
6890 {
6891 inst.instruction = THUMB_OP16 (inst.instruction);
6892 inst.instruction |= inst.operands[0].imm << 4;
6893 }
6894 }
6895 else
6896 {
6897 constraint (inst.operands[0].present,
6898 _("Thumb does not support NOP with hints"));
6899 inst.instruction = 0x46c0;
6900 }
6901}
b05fe5cf 6902
c19d1205
ZW
6903static void
6904do_t_neg (void)
6905{
6906 if (unified_syntax)
6907 {
6908 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7
6909 || !THUMB_SETS_FLAGS (inst.instruction)
6910 || inst.size_req == 4)
6911 {
6912 inst.instruction = THUMB_OP32 (inst.instruction);
6913 inst.instruction |= inst.operands[0].reg << 8;
6914 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
6915 }
6916 else
6917 {
c19d1205
ZW
6918 inst.instruction = THUMB_OP16 (inst.instruction);
6919 inst.instruction |= inst.operands[0].reg;
6920 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
6921 }
6922 }
6923 else
6924 {
c19d1205
ZW
6925 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
6926 BAD_HIREG);
6927 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6928
6929 inst.instruction = THUMB_OP16 (inst.instruction);
6930 inst.instruction |= inst.operands[0].reg;
6931 inst.instruction |= inst.operands[1].reg << 3;
6932 }
6933}
6934
6935static void
6936do_t_pkhbt (void)
6937{
6938 inst.instruction |= inst.operands[0].reg << 8;
6939 inst.instruction |= inst.operands[1].reg << 16;
6940 inst.instruction |= inst.operands[2].reg;
6941 if (inst.operands[3].present)
6942 {
6943 unsigned int val = inst.reloc.exp.X_add_number;
6944 constraint (inst.reloc.exp.X_op != O_constant,
6945 _("expression too complex"));
6946 inst.instruction |= (val & 0x1c) << 10;
6947 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 6948 }
c19d1205 6949}
b05fe5cf 6950
c19d1205
ZW
6951static void
6952do_t_pkhtb (void)
6953{
6954 if (!inst.operands[3].present)
6955 inst.instruction &= ~0x00000020;
6956 do_t_pkhbt ();
b05fe5cf
ZW
6957}
6958
c19d1205
ZW
6959static void
6960do_t_pld (void)
6961{
6962 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
6963}
b05fe5cf 6964
c19d1205
ZW
6965static void
6966do_t_push_pop (void)
b99bd4ef 6967{
e9f89963
PB
6968 unsigned mask;
6969
c19d1205
ZW
6970 constraint (inst.operands[0].writeback,
6971 _("push/pop do not support {reglist}^"));
6972 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6973 _("expression too complex"));
b99bd4ef 6974
e9f89963
PB
6975 mask = inst.operands[0].imm;
6976 if ((mask & ~0xff) == 0)
c19d1205
ZW
6977 inst.instruction = THUMB_OP16 (inst.instruction);
6978 else if ((inst.instruction == T_MNEM_push
e9f89963 6979 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 6980 || (inst.instruction == T_MNEM_pop
e9f89963 6981 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 6982 {
c19d1205
ZW
6983 inst.instruction = THUMB_OP16 (inst.instruction);
6984 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 6985 mask &= 0xff;
c19d1205
ZW
6986 }
6987 else if (unified_syntax)
6988 {
e9f89963
PB
6989 if (mask & (1 << 13))
6990 inst.error = _("SP not allowed in register list");
c19d1205 6991 if (inst.instruction == T_MNEM_push)
b99bd4ef 6992 {
e9f89963
PB
6993 if (mask & (1 << 15))
6994 inst.error = _("PC not allowed in register list");
c19d1205
ZW
6995 }
6996 else
6997 {
e9f89963
PB
6998 if (mask & (1 << 14)
6999 && mask & (1 << 15))
7000 inst.error = _("LR and PC should not both be in register list");
c19d1205 7001 }
e9f89963
PB
7002 if ((mask & (mask - 1)) == 0)
7003 {
7004 /* Single register push/pop implemented as str/ldr. */
7005 if (inst.instruction == T_MNEM_push)
7006 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7007 else
7008 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7009 mask = ffs(mask) - 1;
7010 mask <<= 12;
7011 }
7012 else
7013 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
7014 }
7015 else
7016 {
7017 inst.error = _("invalid register list to push/pop instruction");
7018 return;
7019 }
b99bd4ef 7020
e9f89963 7021 inst.instruction |= mask;
c19d1205 7022}
b99bd4ef 7023
c19d1205
ZW
7024static void
7025do_t_rbit (void)
7026{
7027 inst.instruction |= inst.operands[0].reg << 8;
7028 inst.instruction |= inst.operands[1].reg << 16;
7029}
b99bd4ef 7030
c19d1205
ZW
7031static void
7032do_t_rev (void)
7033{
7034 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7035 && inst.size_req != 4)
7036 {
7037 inst.instruction = THUMB_OP16 (inst.instruction);
7038 inst.instruction |= inst.operands[0].reg;
7039 inst.instruction |= inst.operands[1].reg << 3;
7040 }
7041 else if (unified_syntax)
7042 {
7043 inst.instruction = THUMB_OP32 (inst.instruction);
7044 inst.instruction |= inst.operands[0].reg << 8;
7045 inst.instruction |= inst.operands[1].reg << 16;
7046 inst.instruction |= inst.operands[1].reg;
7047 }
7048 else
7049 inst.error = BAD_HIREG;
7050}
b99bd4ef 7051
c19d1205
ZW
7052static void
7053do_t_rsb (void)
7054{
7055 int Rd, Rs;
b99bd4ef 7056
c19d1205
ZW
7057 Rd = inst.operands[0].reg;
7058 Rs = (inst.operands[1].present
7059 ? inst.operands[1].reg /* Rd, Rs, foo */
7060 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 7061
c19d1205
ZW
7062 inst.instruction |= Rd << 8;
7063 inst.instruction |= Rs << 16;
7064 if (!inst.operands[2].isreg)
7065 {
7066 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7067 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7068 }
7069 else
7070 encode_thumb32_shifted_operand (2);
7071}
b99bd4ef 7072
c19d1205
ZW
7073static void
7074do_t_setend (void)
7075{
7076 if (inst.operands[0].imm)
7077 inst.instruction |= 0x8;
7078}
b99bd4ef 7079
c19d1205
ZW
7080static void
7081do_t_shift (void)
7082{
7083 if (!inst.operands[1].present)
7084 inst.operands[1].reg = inst.operands[0].reg;
7085
7086 if (unified_syntax)
7087 {
7088 if (inst.operands[0].reg > 7
7089 || inst.operands[1].reg > 7
7090 || !THUMB_SETS_FLAGS (inst.instruction)
7091 || (!inst.operands[2].isreg && inst.instruction == T_MNEM_rors)
7092 || (inst.operands[2].isreg && inst.operands[1].reg != inst.operands[0].reg)
7093 || inst.size_req == 4)
7094 {
7095 if (inst.operands[2].isreg)
b99bd4ef 7096 {
c19d1205
ZW
7097 inst.instruction = THUMB_OP32 (inst.instruction);
7098 inst.instruction |= inst.operands[0].reg << 8;
7099 inst.instruction |= inst.operands[1].reg << 16;
7100 inst.instruction |= inst.operands[2].reg;
7101 }
7102 else
7103 {
7104 inst.operands[1].shifted = 1;
7105 switch (inst.instruction)
7106 {
7107 case T_MNEM_asr:
7108 case T_MNEM_asrs: inst.operands[1].shift_kind = SHIFT_ASR; break;
7109 case T_MNEM_lsl:
7110 case T_MNEM_lsls: inst.operands[1].shift_kind = SHIFT_LSL; break;
7111 case T_MNEM_lsr:
7112 case T_MNEM_lsrs: inst.operands[1].shift_kind = SHIFT_LSR; break;
7113 case T_MNEM_ror:
7114 case T_MNEM_rors: inst.operands[1].shift_kind = SHIFT_ROR; break;
7115 default: abort ();
7116 }
7117
7118 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7119 ? T_MNEM_movs : T_MNEM_mov);
7120 inst.instruction |= inst.operands[0].reg << 8;
7121 encode_thumb32_shifted_operand (1);
7122 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7123 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7124 }
7125 }
7126 else
7127 {
c19d1205 7128 if (inst.operands[2].isreg)
b99bd4ef 7129 {
c19d1205 7130 switch (inst.instruction)
b99bd4ef 7131 {
c19d1205
ZW
7132 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_R; break;
7133 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_R; break;
7134 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_R; break;
7135 case T_MNEM_rors: inst.instruction = T_OPCODE_ROR_R; break;
7136 default: abort ();
b99bd4ef 7137 }
c19d1205
ZW
7138
7139 inst.instruction |= inst.operands[0].reg;
7140 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7141 }
7142 else
7143 {
c19d1205 7144 switch (inst.instruction)
b99bd4ef 7145 {
c19d1205
ZW
7146 case T_MNEM_asrs: inst.instruction = T_OPCODE_ASR_I; break;
7147 case T_MNEM_lsls: inst.instruction = T_OPCODE_LSL_I; break;
7148 case T_MNEM_lsrs: inst.instruction = T_OPCODE_LSR_I; break;
7149 default: abort ();
b99bd4ef 7150 }
c19d1205
ZW
7151 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7152 inst.instruction |= inst.operands[0].reg;
7153 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7154 }
7155 }
c19d1205
ZW
7156 }
7157 else
7158 {
7159 constraint (inst.operands[0].reg > 7
7160 || inst.operands[1].reg > 7, BAD_HIREG);
7161 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7162
c19d1205
ZW
7163 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7164 {
7165 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7166 constraint (inst.operands[0].reg != inst.operands[1].reg,
7167 _("source1 and dest must be same register"));
b99bd4ef 7168
c19d1205
ZW
7169 switch (inst.instruction)
7170 {
7171 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7172 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7173 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7174 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7175 default: abort ();
7176 }
7177
7178 inst.instruction |= inst.operands[0].reg;
7179 inst.instruction |= inst.operands[2].reg << 3;
7180 }
7181 else
b99bd4ef 7182 {
c19d1205
ZW
7183 switch (inst.instruction)
7184 {
7185 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7186 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7187 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7188 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7189 default: abort ();
7190 }
7191 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7192 inst.instruction |= inst.operands[0].reg;
7193 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7194 }
7195 }
b99bd4ef
NC
7196}
7197
7198static void
c19d1205 7199do_t_simd (void)
b99bd4ef 7200{
c19d1205
ZW
7201 inst.instruction |= inst.operands[0].reg << 8;
7202 inst.instruction |= inst.operands[1].reg << 16;
7203 inst.instruction |= inst.operands[2].reg;
7204}
b99bd4ef 7205
c19d1205
ZW
7206static void
7207do_t_smi (void)
7208{
7209 unsigned int value = inst.reloc.exp.X_add_number;
7210 constraint (inst.reloc.exp.X_op != O_constant,
7211 _("expression too complex"));
7212 inst.reloc.type = BFD_RELOC_UNUSED;
7213 inst.instruction |= (value & 0xf000) >> 12;
7214 inst.instruction |= (value & 0x0ff0);
7215 inst.instruction |= (value & 0x000f) << 16;
7216}
b99bd4ef 7217
c19d1205
ZW
7218static void
7219do_t_ssat (void)
7220{
7221 inst.instruction |= inst.operands[0].reg << 8;
7222 inst.instruction |= inst.operands[1].imm - 1;
7223 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7224
c19d1205 7225 if (inst.operands[3].present)
b99bd4ef 7226 {
c19d1205
ZW
7227 constraint (inst.reloc.exp.X_op != O_constant,
7228 _("expression too complex"));
b99bd4ef 7229
c19d1205 7230 if (inst.reloc.exp.X_add_number != 0)
6189168b 7231 {
c19d1205
ZW
7232 if (inst.operands[3].shift_kind == SHIFT_ASR)
7233 inst.instruction |= 0x00200000; /* sh bit */
7234 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7235 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7236 }
c19d1205 7237 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7238 }
b99bd4ef
NC
7239}
7240
0dd132b6 7241static void
c19d1205 7242do_t_ssat16 (void)
0dd132b6 7243{
c19d1205
ZW
7244 inst.instruction |= inst.operands[0].reg << 8;
7245 inst.instruction |= inst.operands[1].imm - 1;
7246 inst.instruction |= inst.operands[2].reg << 16;
7247}
0dd132b6 7248
c19d1205
ZW
7249static void
7250do_t_strex (void)
7251{
7252 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7253 || inst.operands[2].postind || inst.operands[2].writeback
7254 || inst.operands[2].immisreg || inst.operands[2].shifted
7255 || inst.operands[2].negative,
7256 _("instruction does not accept this addressing mode"));
0dd132b6 7257
c19d1205
ZW
7258 inst.instruction |= inst.operands[0].reg << 8;
7259 inst.instruction |= inst.operands[1].reg << 12;
7260 inst.instruction |= inst.operands[2].reg << 16;
7261 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7262}
7263
b99bd4ef 7264static void
c19d1205 7265do_t_strexd (void)
b99bd4ef 7266{
c19d1205
ZW
7267 if (!inst.operands[2].present)
7268 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7269
c19d1205
ZW
7270 constraint (inst.operands[0].reg == inst.operands[1].reg
7271 || inst.operands[0].reg == inst.operands[2].reg
7272 || inst.operands[0].reg == inst.operands[3].reg
7273 || inst.operands[1].reg == inst.operands[2].reg,
7274 BAD_OVERLAP);
b99bd4ef 7275
c19d1205
ZW
7276 inst.instruction |= inst.operands[0].reg;
7277 inst.instruction |= inst.operands[1].reg << 12;
7278 inst.instruction |= inst.operands[2].reg << 8;
7279 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7280}
7281
7282static void
c19d1205 7283do_t_sxtah (void)
b99bd4ef 7284{
c19d1205
ZW
7285 inst.instruction |= inst.operands[0].reg << 8;
7286 inst.instruction |= inst.operands[1].reg << 16;
7287 inst.instruction |= inst.operands[2].reg;
7288 inst.instruction |= inst.operands[3].imm << 4;
7289}
b99bd4ef 7290
c19d1205
ZW
7291static void
7292do_t_sxth (void)
7293{
7294 if (inst.instruction <= 0xffff && inst.size_req != 4
7295 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7296 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7297 {
c19d1205
ZW
7298 inst.instruction = THUMB_OP16 (inst.instruction);
7299 inst.instruction |= inst.operands[0].reg;
7300 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7301 }
c19d1205 7302 else if (unified_syntax)
b99bd4ef 7303 {
c19d1205
ZW
7304 if (inst.instruction <= 0xffff)
7305 inst.instruction = THUMB_OP32 (inst.instruction);
7306 inst.instruction |= inst.operands[0].reg << 8;
7307 inst.instruction |= inst.operands[1].reg;
7308 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7309 }
c19d1205 7310 else
b99bd4ef 7311 {
c19d1205
ZW
7312 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7313 _("Thumb encoding does not support rotation"));
7314 constraint (1, BAD_HIREG);
b99bd4ef 7315 }
c19d1205 7316}
b99bd4ef 7317
c19d1205
ZW
7318static void
7319do_t_swi (void)
7320{
7321 inst.reloc.type = BFD_RELOC_ARM_SWI;
7322}
b99bd4ef 7323
92e90b6e
PB
7324static void
7325do_t_tb (void)
7326{
7327 int half;
7328
7329 half = (inst.instruction & 0x10) != 0;
7330 constraint (inst.operands[0].imm == 15,
7331 _("PC is not a valid index register"));
7332 constraint (!half && inst.operands[0].shifted,
7333 _("instruction does not allow shifted index"));
7334 constraint (half && !inst.operands[0].shifted,
7335 _("instruction requires shifted index"));
7336 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7337}
7338
c19d1205
ZW
7339static void
7340do_t_usat (void)
7341{
7342 inst.instruction |= inst.operands[0].reg << 8;
7343 inst.instruction |= inst.operands[1].imm;
7344 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7345
c19d1205 7346 if (inst.operands[3].present)
b99bd4ef 7347 {
c19d1205
ZW
7348 constraint (inst.reloc.exp.X_op != O_constant,
7349 _("expression too complex"));
7350 if (inst.reloc.exp.X_add_number != 0)
7351 {
7352 if (inst.operands[3].shift_kind == SHIFT_ASR)
7353 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7354
c19d1205
ZW
7355 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7356 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7357 }
7358 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7359 }
b99bd4ef
NC
7360}
7361
7362static void
c19d1205 7363do_t_usat16 (void)
b99bd4ef 7364{
c19d1205
ZW
7365 inst.instruction |= inst.operands[0].reg << 8;
7366 inst.instruction |= inst.operands[1].imm;
7367 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7368}
c19d1205
ZW
7369\f
7370/* Overall per-instruction processing. */
7371
7372/* We need to be able to fix up arbitrary expressions in some statements.
7373 This is so that we can handle symbols that are an arbitrary distance from
7374 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7375 which returns part of an address in a form which will be valid for
7376 a data instruction. We do this by pushing the expression into a symbol
7377 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7378
7379static void
c19d1205
ZW
7380fix_new_arm (fragS * frag,
7381 int where,
7382 short int size,
7383 expressionS * exp,
7384 int pc_rel,
7385 int reloc)
b99bd4ef 7386{
c19d1205 7387 fixS * new_fix;
b99bd4ef 7388
c19d1205 7389 switch (exp->X_op)
b99bd4ef 7390 {
c19d1205
ZW
7391 case O_constant:
7392 case O_symbol:
7393 case O_add:
7394 case O_subtract:
7395 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7396 break;
b99bd4ef 7397
c19d1205
ZW
7398 default:
7399 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7400 pc_rel, reloc);
7401 break;
b99bd4ef
NC
7402 }
7403
c19d1205
ZW
7404 /* Mark whether the fix is to a THUMB instruction, or an ARM
7405 instruction. */
adbaf948 7406 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7407}
7408
7409static void
c19d1205 7410output_inst (const char * str)
b99bd4ef 7411{
c19d1205 7412 char * to = NULL;
b99bd4ef 7413
c19d1205 7414 if (inst.error)
b99bd4ef 7415 {
c19d1205 7416 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
7417 return;
7418 }
c19d1205
ZW
7419 if (inst.size == 0)
7420 return;
b99bd4ef 7421
c19d1205
ZW
7422 to = frag_more (inst.size);
7423
7424 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 7425 {
c19d1205
ZW
7426 assert (inst.size == (2 * THUMB_SIZE));
7427 md_number_to_chars (to, inst.instruction >> 16, THUMB_SIZE);
7428 md_number_to_chars (to + THUMB_SIZE, inst.instruction, THUMB_SIZE);
b99bd4ef 7429 }
c19d1205 7430 else if (inst.size > INSN_SIZE)
b99bd4ef 7431 {
c19d1205
ZW
7432 assert (inst.size == (2 * INSN_SIZE));
7433 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7434 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 7435 }
c19d1205
ZW
7436 else
7437 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 7438
c19d1205
ZW
7439 if (inst.reloc.type != BFD_RELOC_UNUSED)
7440 fix_new_arm (frag_now, to - frag_now->fr_literal,
7441 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7442 inst.reloc.type);
b99bd4ef 7443
c19d1205
ZW
7444#ifdef OBJ_ELF
7445 dwarf2_emit_insn (inst.size);
7446#endif
7447}
b99bd4ef 7448
c19d1205
ZW
7449/* Tag values used in struct asm_opcode's tag field. */
7450enum opcode_tag
7451{
7452 OT_unconditional, /* Instruction cannot be conditionalized.
7453 The ARM condition field is still 0xE. */
7454 OT_unconditionalF, /* Instruction cannot be conditionalized
7455 and carries 0xF in its ARM condition field. */
7456 OT_csuffix, /* Instruction takes a conditional suffix. */
7457 OT_cinfix3, /* Instruction takes a conditional infix,
7458 beginning at character index 3. (In
7459 unified mode, it becomes a suffix.) */
7460 OT_csuf_or_in3, /* Instruction takes either a conditional
7461 suffix or an infix at character index 3.
7462 (In unified mode, a suffix only. */
7463 OT_odd_infix_unc, /* This is the unconditional variant of an
7464 instruction that takes a conditional infix
7465 at an unusual position. In unified mode,
7466 this variant will accept a suffix. */
7467 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7468 are the conditional variants of instructions that
7469 take conditional infixes in unusual positions.
7470 The infix appears at character index
7471 (tag - OT_odd_infix_0). These are not accepted
7472 in unified mode. */
7473};
b99bd4ef 7474
c19d1205
ZW
7475/* Subroutine of md_assemble, responsible for looking up the primary
7476 opcode from the mnemonic the user wrote. STR points to the
7477 beginning of the mnemonic.
7478
7479 This is not simply a hash table lookup, because of conditional
7480 variants. Most instructions have conditional variants, which are
7481 expressed with a _conditional affix_ to the mnemonic. If we were
7482 to encode each conditional variant as a literal string in the opcode
7483 table, it would have approximately 20,000 entries.
7484
7485 Most mnemonics take this affix as a suffix, and in unified syntax,
7486 'most' is upgraded to 'all'. However, in the divided syntax, some
7487 instructions take the affix as an infix, notably the s-variants of
7488 the arithmetic instructions. Of those instructions, all but six
7489 have the infix appear after the third character of the mnemonic.
7490
7491 Accordingly, the algorithm for looking up primary opcodes given
7492 an identifier is:
7493
7494 1. Look up the identifier in the opcode table.
7495 If we find a match, go to step U.
7496
7497 2. Look up the last two characters of the identifier in the
7498 conditions table. If we find a match, look up the first N-2
7499 characters of the identifier in the opcode table. If we
7500 find a match, go to step CE.
7501
7502 3. Look up the fourth and fifth characters of the identifier in
7503 the conditions table. If we find a match, extract those
7504 characters from the identifier, and look up the remaining
7505 characters in the opcode table. If we find a match, go
7506 to step CM.
7507
7508 4. Fail.
7509
7510 U. Examine the tag field of the opcode structure, in case this is
7511 one of the six instructions with its conditional infix in an
7512 unusual place. If it is, the tag tells us where to find the
7513 infix; look it up in the conditions table and set inst.cond
7514 accordingly. Otherwise, this is an unconditional instruction.
7515 Again set inst.cond accordingly. Return the opcode structure.
7516
7517 CE. Examine the tag field to make sure this is an instruction that
7518 should receive a conditional suffix. If it is not, fail.
7519 Otherwise, set inst.cond from the suffix we already looked up,
7520 and return the opcode structure.
7521
7522 CM. Examine the tag field to make sure this is an instruction that
7523 should receive a conditional infix after the third character.
7524 If it is not, fail. Otherwise, undo the edits to the current
7525 line of input and proceed as for case CE. */
7526
7527static const struct asm_opcode *
7528opcode_lookup (char **str)
7529{
7530 char *end, *base;
7531 char *affix;
7532 const struct asm_opcode *opcode;
7533 const struct asm_cond *cond;
7534
7535 /* Scan up to the end of the mnemonic, which must end in white space,
7536 '.' (in unified mode only), or end of string. */
7537 for (base = end = *str; *end != '\0'; end++)
7538 if (*end == ' ' || (unified_syntax && *end == '.'))
7539 break;
b99bd4ef 7540
c19d1205
ZW
7541 if (end == base)
7542 return 0;
b99bd4ef 7543
c19d1205
ZW
7544 /* Handle a possible width suffix. */
7545 if (end[0] == '.')
b99bd4ef 7546 {
c19d1205
ZW
7547 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7548 inst.size_req = 4;
7549 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7550 inst.size_req = 2;
7551 else
7552 return 0;
b99bd4ef 7553
c19d1205 7554 *str = end + 2;
b99bd4ef 7555 }
c19d1205
ZW
7556 else
7557 *str = end;
b99bd4ef 7558
c19d1205
ZW
7559 /* Look for unaffixed or special-case affixed mnemonic. */
7560 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7561 if (opcode)
b99bd4ef 7562 {
c19d1205
ZW
7563 /* step U */
7564 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 7565 {
c19d1205
ZW
7566 inst.cond = COND_ALWAYS;
7567 return opcode;
b99bd4ef 7568 }
b99bd4ef 7569
c19d1205
ZW
7570 if (unified_syntax)
7571 as_warn (_("conditional infixes are deprecated in unified syntax"));
7572 affix = base + (opcode->tag - OT_odd_infix_0);
7573 cond = hash_find_n (arm_cond_hsh, affix, 2);
7574 assert (cond);
b99bd4ef 7575
c19d1205
ZW
7576 inst.cond = cond->value;
7577 return opcode;
7578 }
b99bd4ef 7579
c19d1205
ZW
7580 /* Cannot have a conditional suffix on a mnemonic of less than two
7581 characters. */
7582 if (end - base < 3)
7583 return 0;
b99bd4ef 7584
c19d1205
ZW
7585 /* Look for suffixed mnemonic. */
7586 affix = end - 2;
7587 cond = hash_find_n (arm_cond_hsh, affix, 2);
7588 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7589 if (opcode && cond)
7590 {
7591 /* step CE */
7592 switch (opcode->tag)
7593 {
7594 case OT_cinfix3:
7595 case OT_odd_infix_unc:
7596 if (!unified_syntax)
7597 return 0;
7598 /* else fall through */
7599
7600 case OT_csuffix:
7601 case OT_csuf_or_in3:
7602 inst.cond = cond->value;
7603 return opcode;
7604
7605 case OT_unconditional:
7606 case OT_unconditionalF:
7607 /* delayed diagnostic */
7608 inst.error = BAD_COND;
7609 inst.cond = COND_ALWAYS;
7610 return opcode;
b99bd4ef 7611
c19d1205
ZW
7612 default:
7613 return 0;
7614 }
7615 }
b99bd4ef 7616
c19d1205
ZW
7617 /* Cannot have a usual-position infix on a mnemonic of less than
7618 six characters (five would be a suffix). */
7619 if (end - base < 6)
7620 return 0;
b99bd4ef 7621
c19d1205
ZW
7622 /* Look for infixed mnemonic in the usual position. */
7623 affix = base + 3;
7624 cond = hash_find_n (arm_cond_hsh, affix, 2);
7625 if (cond)
b99bd4ef 7626 {
c19d1205
ZW
7627 char save[2];
7628 memcpy (save, affix, 2);
7629 memmove (affix, affix + 2, (end - affix) - 2);
7630 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
7631 memmove (affix + 2, affix, (end - affix) - 2);
7632 memcpy (affix, save, 2);
b99bd4ef 7633 }
c19d1205 7634 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3))
b99bd4ef 7635 {
c19d1205
ZW
7636 /* step CM */
7637 if (unified_syntax)
7638 as_warn (_("conditional infixes are deprecated in unified syntax"));
7639
7640 inst.cond = cond->value;
7641 return opcode;
b99bd4ef
NC
7642 }
7643
c19d1205 7644 return 0;
b99bd4ef
NC
7645}
7646
c19d1205
ZW
7647void
7648md_assemble (char *str)
b99bd4ef 7649{
c19d1205
ZW
7650 char *p = str;
7651 const struct asm_opcode * opcode;
b99bd4ef 7652
c19d1205
ZW
7653 /* Align the previous label if needed. */
7654 if (last_label_seen != NULL)
b99bd4ef 7655 {
c19d1205
ZW
7656 symbol_set_frag (last_label_seen, frag_now);
7657 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
7658 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
7659 }
7660
c19d1205
ZW
7661 memset (&inst, '\0', sizeof (inst));
7662 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7663
c19d1205
ZW
7664 opcode = opcode_lookup (&p);
7665 if (!opcode)
b99bd4ef 7666 {
c19d1205
ZW
7667 /* It wasn't an instruction, but it might be a register alias of
7668 the form alias .req reg. */
7669 if (!create_register_alias (str, p))
7670 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 7671
b99bd4ef
NC
7672 return;
7673 }
7674
c19d1205 7675 if (thumb_mode)
b99bd4ef 7676 {
c19d1205
ZW
7677 /* Check that this instruction is supported for this CPU. */
7678 if (thumb_mode == 1 && (opcode->tvariant & cpu_variant) == 0)
b99bd4ef 7679 {
c19d1205 7680 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
7681 return;
7682 }
c19d1205
ZW
7683 if (inst.cond != COND_ALWAYS && !unified_syntax
7684 && opcode->tencode != do_t_branch)
b99bd4ef 7685 {
c19d1205 7686 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
7687 return;
7688 }
7689
c19d1205
ZW
7690 mapping_state (MAP_THUMB);
7691 inst.instruction = opcode->tvalue;
7692
7693 if (!parse_operands (p, opcode->operands))
7694 opcode->tencode ();
7695
7696 if (!inst.error)
b99bd4ef 7697 {
c19d1205
ZW
7698 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
7699 inst.size = (inst.instruction > 0xffff ? 4 : 2);
7700 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 7701 {
c19d1205 7702 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
7703 return;
7704 }
7705 }
c19d1205
ZW
7706 }
7707 else
7708 {
7709 /* Check that this instruction is supported for this CPU. */
7710 if ((opcode->avariant & cpu_variant) == 0)
b99bd4ef 7711 {
c19d1205
ZW
7712 as_bad (_("selected processor does not support `%s'"), str);
7713 return;
b99bd4ef 7714 }
c19d1205 7715 if (inst.size_req)
b99bd4ef 7716 {
c19d1205
ZW
7717 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
7718 return;
b99bd4ef
NC
7719 }
7720
c19d1205
ZW
7721 mapping_state (MAP_ARM);
7722 inst.instruction = opcode->avalue;
7723 if (opcode->tag == OT_unconditionalF)
7724 inst.instruction |= 0xF << 28;
7725 else
7726 inst.instruction |= inst.cond << 28;
7727 inst.size = INSN_SIZE;
7728 if (!parse_operands (p, opcode->operands))
7729 opcode->aencode ();
b99bd4ef 7730 }
c19d1205
ZW
7731 output_inst (str);
7732}
b99bd4ef 7733
c19d1205
ZW
7734/* Various frobbings of labels and their addresses. */
7735
7736void
7737arm_start_line_hook (void)
7738{
7739 last_label_seen = NULL;
b99bd4ef
NC
7740}
7741
c19d1205
ZW
7742void
7743arm_frob_label (symbolS * sym)
b99bd4ef 7744{
c19d1205 7745 last_label_seen = sym;
b99bd4ef 7746
c19d1205 7747 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 7748
c19d1205
ZW
7749#if defined OBJ_COFF || defined OBJ_ELF
7750 ARM_SET_INTERWORK (sym, support_interwork);
7751#endif
b99bd4ef 7752
c19d1205
ZW
7753 /* Note - do not allow local symbols (.Lxxx) to be labeled
7754 as Thumb functions. This is because these labels, whilst
7755 they exist inside Thumb code, are not the entry points for
7756 possible ARM->Thumb calls. Also, these labels can be used
7757 as part of a computed goto or switch statement. eg gcc
7758 can generate code that looks like this:
b99bd4ef 7759
c19d1205
ZW
7760 ldr r2, [pc, .Laaa]
7761 lsl r3, r3, #2
7762 ldr r2, [r3, r2]
7763 mov pc, r2
b99bd4ef 7764
c19d1205
ZW
7765 .Lbbb: .word .Lxxx
7766 .Lccc: .word .Lyyy
7767 ..etc...
7768 .Laaa: .word Lbbb
b99bd4ef 7769
c19d1205
ZW
7770 The first instruction loads the address of the jump table.
7771 The second instruction converts a table index into a byte offset.
7772 The third instruction gets the jump address out of the table.
7773 The fourth instruction performs the jump.
b99bd4ef 7774
c19d1205
ZW
7775 If the address stored at .Laaa is that of a symbol which has the
7776 Thumb_Func bit set, then the linker will arrange for this address
7777 to have the bottom bit set, which in turn would mean that the
7778 address computation performed by the third instruction would end
7779 up with the bottom bit set. Since the ARM is capable of unaligned
7780 word loads, the instruction would then load the incorrect address
7781 out of the jump table, and chaos would ensue. */
7782 if (label_is_thumb_function_name
7783 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
7784 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 7785 {
c19d1205
ZW
7786 /* When the address of a Thumb function is taken the bottom
7787 bit of that address should be set. This will allow
7788 interworking between Arm and Thumb functions to work
7789 correctly. */
b99bd4ef 7790
c19d1205 7791 THUMB_SET_FUNC (sym, 1);
b99bd4ef 7792
c19d1205 7793 label_is_thumb_function_name = FALSE;
b99bd4ef 7794 }
b99bd4ef
NC
7795}
7796
c19d1205
ZW
7797int
7798arm_data_in_code (void)
b99bd4ef 7799{
c19d1205 7800 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 7801 {
c19d1205
ZW
7802 *input_line_pointer = '/';
7803 input_line_pointer += 5;
7804 *input_line_pointer = 0;
7805 return 1;
b99bd4ef
NC
7806 }
7807
c19d1205 7808 return 0;
b99bd4ef
NC
7809}
7810
c19d1205
ZW
7811char *
7812arm_canonicalize_symbol_name (char * name)
b99bd4ef 7813{
c19d1205 7814 int len;
b99bd4ef 7815
c19d1205
ZW
7816 if (thumb_mode && (len = strlen (name)) > 5
7817 && streq (name + len - 5, "/data"))
7818 *(name + len - 5) = 0;
b99bd4ef 7819
c19d1205 7820 return name;
b99bd4ef 7821}
c19d1205
ZW
7822\f
7823/* Table of all register names defined by default. The user can
7824 define additional names with .req. Note that all register names
7825 should appear in both upper and lowercase variants. Some registers
7826 also have mixed-case names. */
b99bd4ef 7827
c19d1205
ZW
7828#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
7829#define REGNUM(p,n,t) REGDEF(p##n, n, t)
7830#define REGSET(p,t) \
7831 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
7832 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
7833 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
7834 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 7835
c19d1205 7836static const struct reg_entry reg_names[] =
7ed4c4c5 7837{
c19d1205
ZW
7838 /* ARM integer registers. */
7839 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 7840
c19d1205
ZW
7841 /* ATPCS synonyms. */
7842 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
7843 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
7844 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 7845
c19d1205
ZW
7846 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
7847 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
7848 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 7849
c19d1205
ZW
7850 /* Well-known aliases. */
7851 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
7852 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
7853
7854 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
7855 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
7856
7857 /* Coprocessor numbers. */
7858 REGSET(p, CP), REGSET(P, CP),
7859
7860 /* Coprocessor register numbers. The "cr" variants are for backward
7861 compatibility. */
7862 REGSET(c, CN), REGSET(C, CN),
7863 REGSET(cr, CN), REGSET(CR, CN),
7864
7865 /* FPA registers. */
7866 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
7867 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
7868
7869 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
7870 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
7871
7872 /* VFP SP registers. */
7873 REGSET(s,VFS),
7874 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
7875 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
7876 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
7877 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
7878
7879 REGSET(S,VFS),
7880 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
7881 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
7882 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
7883 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
7884
7885 /* VFP DP Registers. */
7886 REGSET(d,VFD), REGSET(D,VFS),
7887
7888 /* VFP control registers. */
7889 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
7890 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
7891
7892 /* Maverick DSP coprocessor registers. */
7893 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
7894 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
7895
7896 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
7897 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
7898 REGDEF(dspsc,0,DSPSC),
7899
7900 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
7901 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
7902 REGDEF(DSPSC,0,DSPSC),
7903
7904 /* iWMMXt data registers - p0, c0-15. */
7905 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
7906
7907 /* iWMMXt control registers - p1, c0-3. */
7908 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
7909 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
7910 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
7911 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
7912
7913 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
7914 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
7915 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
7916 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
7917 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
7918
7919 /* XScale accumulator registers. */
7920 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
7921};
7922#undef REGDEF
7923#undef REGNUM
7924#undef REGSET
7ed4c4c5 7925
c19d1205
ZW
7926/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
7927 within psr_required_here. */
7928static const struct asm_psr psrs[] =
7929{
7930 /* Backward compatibility notation. Note that "all" is no longer
7931 truly all possible PSR bits. */
7932 {"all", PSR_c | PSR_f},
7933 {"flg", PSR_f},
7934 {"ctl", PSR_c},
7935
7936 /* Individual flags. */
7937 {"f", PSR_f},
7938 {"c", PSR_c},
7939 {"x", PSR_x},
7940 {"s", PSR_s},
7941 /* Combinations of flags. */
7942 {"fs", PSR_f | PSR_s},
7943 {"fx", PSR_f | PSR_x},
7944 {"fc", PSR_f | PSR_c},
7945 {"sf", PSR_s | PSR_f},
7946 {"sx", PSR_s | PSR_x},
7947 {"sc", PSR_s | PSR_c},
7948 {"xf", PSR_x | PSR_f},
7949 {"xs", PSR_x | PSR_s},
7950 {"xc", PSR_x | PSR_c},
7951 {"cf", PSR_c | PSR_f},
7952 {"cs", PSR_c | PSR_s},
7953 {"cx", PSR_c | PSR_x},
7954 {"fsx", PSR_f | PSR_s | PSR_x},
7955 {"fsc", PSR_f | PSR_s | PSR_c},
7956 {"fxs", PSR_f | PSR_x | PSR_s},
7957 {"fxc", PSR_f | PSR_x | PSR_c},
7958 {"fcs", PSR_f | PSR_c | PSR_s},
7959 {"fcx", PSR_f | PSR_c | PSR_x},
7960 {"sfx", PSR_s | PSR_f | PSR_x},
7961 {"sfc", PSR_s | PSR_f | PSR_c},
7962 {"sxf", PSR_s | PSR_x | PSR_f},
7963 {"sxc", PSR_s | PSR_x | PSR_c},
7964 {"scf", PSR_s | PSR_c | PSR_f},
7965 {"scx", PSR_s | PSR_c | PSR_x},
7966 {"xfs", PSR_x | PSR_f | PSR_s},
7967 {"xfc", PSR_x | PSR_f | PSR_c},
7968 {"xsf", PSR_x | PSR_s | PSR_f},
7969 {"xsc", PSR_x | PSR_s | PSR_c},
7970 {"xcf", PSR_x | PSR_c | PSR_f},
7971 {"xcs", PSR_x | PSR_c | PSR_s},
7972 {"cfs", PSR_c | PSR_f | PSR_s},
7973 {"cfx", PSR_c | PSR_f | PSR_x},
7974 {"csf", PSR_c | PSR_s | PSR_f},
7975 {"csx", PSR_c | PSR_s | PSR_x},
7976 {"cxf", PSR_c | PSR_x | PSR_f},
7977 {"cxs", PSR_c | PSR_x | PSR_s},
7978 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
7979 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
7980 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
7981 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
7982 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
7983 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
7984 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
7985 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
7986 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
7987 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
7988 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
7989 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
7990 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
7991 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
7992 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
7993 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
7994 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
7995 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
7996 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
7997 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
7998 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
7999 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8000 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8001 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8002};
8003
8004/* Table of all shift-in-operand names. */
8005static const struct asm_shift_name shift_names [] =
b99bd4ef 8006{
c19d1205
ZW
8007 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8008 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8009 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8010 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8011 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8012 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8013};
b99bd4ef 8014
c19d1205
ZW
8015/* Table of all explicit relocation names. */
8016#ifdef OBJ_ELF
8017static struct reloc_entry reloc_names[] =
8018{
8019 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8020 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8021 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8022 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8023 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8024 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8025 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8026 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8027 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8028 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8029 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8030};
8031#endif
b99bd4ef 8032
c19d1205
ZW
8033/* Table of all conditional affixes. 0xF is not defined as a condition code. */
8034static const struct asm_cond conds[] =
8035{
8036 {"eq", 0x0},
8037 {"ne", 0x1},
8038 {"cs", 0x2}, {"hs", 0x2},
8039 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8040 {"mi", 0x4},
8041 {"pl", 0x5},
8042 {"vs", 0x6},
8043 {"vc", 0x7},
8044 {"hi", 0x8},
8045 {"ls", 0x9},
8046 {"ge", 0xa},
8047 {"lt", 0xb},
8048 {"gt", 0xc},
8049 {"le", 0xd},
8050 {"al", 0xe}
8051};
bfae80f2 8052
c19d1205
ZW
8053/* Table of ARM-format instructions. */
8054
8055/* Macros for gluing together operand strings. N.B. In all cases
8056 other than OPS0, the trailing OP_stop comes from default
8057 zero-initialization of the unspecified elements of the array. */
8058#define OPS0() { OP_stop, }
8059#define OPS1(a) { OP_##a, }
8060#define OPS2(a,b) { OP_##a,OP_##b, }
8061#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8062#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8063#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8064#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8065
8066/* These macros abstract out the exact format of the mnemonic table and
8067 save some repeated characters. */
8068
8069/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8070#define TxCE(mnem, op, top, nops, ops, ae, te) \
8071 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 8072 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8073
8074/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8075 a T_MNEM_xyz enumerator. */
8076#define TCE(mnem, aop, top, nops, ops, ae, te) \
8077 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8078#define tCE(mnem, aop, top, nops, ops, ae, te) \
8079 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8080
8081/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8082 infix after the third character. */
8083#define TxC3(mnem, op, top, nops, ops, ae, te) \
8084 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 8085 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8086#define TC3(mnem, aop, top, nops, ops, ae, te) \
8087 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8088#define tC3(mnem, aop, top, nops, ops, ae, te) \
8089 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8090
8091/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8092 appear in the condition table. */
8093#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8094 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 8095 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8096
8097#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8098 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8099 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8100 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8101 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8102 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8103 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8104 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8105 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8106 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8107 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8108 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8109 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8110 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8111 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8112 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8113 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8114 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8115 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8116 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8117
8118#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8119 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8120#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8121 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8122
8123/* Mnemonic that cannot be conditionalized. The ARM condition-code
8124 field is still 0xE. */
8125#define TUE(mnem, op, top, nops, ops, ae, te) \
8126 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8127 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8128
8129/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8130 condition code field. */
8131#define TUF(mnem, op, top, nops, ops, ae, te) \
8132 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8133 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8134
8135/* ARM-only variants of all the above. */
6a86118a
NC
8136#define CE(mnem, op, nops, ops, ae) \
8137 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8138
8139#define C3(mnem, op, nops, ops, ae) \
8140 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8141
8142#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8143 { #m1 #m2 #m3, OPS##nops ops, \
8144 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8145 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8146
8147#define CM(m1, m2, op, nops, ops, ae) \
8148 xCM_(m1, , m2, op, nops, ops, ae), \
8149 xCM_(m1, eq, m2, op, nops, ops, ae), \
8150 xCM_(m1, ne, m2, op, nops, ops, ae), \
8151 xCM_(m1, cs, m2, op, nops, ops, ae), \
8152 xCM_(m1, hs, m2, op, nops, ops, ae), \
8153 xCM_(m1, cc, m2, op, nops, ops, ae), \
8154 xCM_(m1, ul, m2, op, nops, ops, ae), \
8155 xCM_(m1, lo, m2, op, nops, ops, ae), \
8156 xCM_(m1, mi, m2, op, nops, ops, ae), \
8157 xCM_(m1, pl, m2, op, nops, ops, ae), \
8158 xCM_(m1, vs, m2, op, nops, ops, ae), \
8159 xCM_(m1, vc, m2, op, nops, ops, ae), \
8160 xCM_(m1, hi, m2, op, nops, ops, ae), \
8161 xCM_(m1, ls, m2, op, nops, ops, ae), \
8162 xCM_(m1, ge, m2, op, nops, ops, ae), \
8163 xCM_(m1, lt, m2, op, nops, ops, ae), \
8164 xCM_(m1, gt, m2, op, nops, ops, ae), \
8165 xCM_(m1, le, m2, op, nops, ops, ae), \
8166 xCM_(m1, al, m2, op, nops, ops, ae)
8167
8168#define UE(mnem, op, nops, ops, ae) \
8169 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8170
8171#define UF(mnem, op, nops, ops, ae) \
8172 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8173
c19d1205
ZW
8174#define do_0 0
8175
8176/* Thumb-only, unconditional. */
8177#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8178
8179/* ARM-only, takes either a suffix or a position-3 infix
8180 (for an FPA corner case). */
8181#define C3E(mnem, op, nops, ops, ae) \
8182 { #mnem, OPS##nops ops, OT_csuf_or_in3, 0x##op, 0, ARM_VARIANT, 0, do_##ae, 0 }
bfae80f2 8183
c19d1205 8184static const struct asm_opcode insns[] =
bfae80f2 8185{
c19d1205
ZW
8186#define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8187#define THUMB_VARIANT ARM_EXT_V4T
8188 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8189 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8190 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8191 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8192 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8193 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8194 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8195 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8196 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8197 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8198 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8199 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8200 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8201 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8202 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8203 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8204
8205 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8206 for setting PSR flag bits. They are obsolete in V6 and do not
8207 have Thumb equivalents. */
8208 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8209 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8210 C3(tstp, 110f000, 2, (RR, SH), cmp),
8211 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8212 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8213 C3(cmpp, 150f000, 2, (RR, SH), cmp),
8214 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8215 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8216 C3(cmnp, 170f000, 2, (RR, SH), cmp),
8217
8218 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8219 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8220 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8221 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8222
8223 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8224 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8225 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8226 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8227
8228 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8229 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8230 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8231 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8232
8233 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
2fc8bdac
ZW
8234 TCE(b, a000000, e000, 1, (EXPr), branch, t_branch),
8235 TCE(bl, b000000, f000f800, 1, (EXPr), branch, t_branch23),
bfae80f2 8236
c19d1205 8237 /* Pseudo ops. */
e9f89963 8238 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
8239 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8240 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
8241
8242 /* Thumb-compatibility pseudo ops. */
8243 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8244 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8245 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8246 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8247 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 8248 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
8249 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8250 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8251 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8252 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8253 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8254 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8255
8256#undef THUMB_VARIANT
8257#define THUMB_VARIANT ARM_EXT_V6
2fc8bdac 8258 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
8259
8260 /* V1 instructions with no Thumb analogue prior to V6T2. */
8261#undef THUMB_VARIANT
8262#define THUMB_VARIANT ARM_EXT_V6T2
8263 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8264 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8265 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8266 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8267 C3(teqp, 130f000, 2, (RR, SH), cmp),
8268
8269 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8270 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8271 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8272 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8273
9c3c69f2
PB
8274 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8275 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 8276
9c3c69f2
PB
8277 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8278 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8279
8280 /* V1 instructions with no Thumb analogue at all. */
8281 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8282 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8283
8284 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8285 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8286 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8287 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8288 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8289 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8290 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8291 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8292
8293#undef ARM_VARIANT
8294#define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8295#undef THUMB_VARIANT
8296#define THUMB_VARIANT ARM_EXT_V4T
8297 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8298 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8299
8300#undef THUMB_VARIANT
8301#define THUMB_VARIANT ARM_EXT_V6T2
8302 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8303 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8304
8305 /* Generic coprocessor instructions. */
8306 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8307 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8308 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8309 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8310 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8311 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8312 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8313
8314#undef ARM_VARIANT
8315#define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8316 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8317 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8318
8319#undef ARM_VARIANT
8320#define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8321 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8322 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8323
8324#undef ARM_VARIANT
8325#define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8326 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8327 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8328 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8329 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8330 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8331 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8332 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8333 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8334
8335#undef ARM_VARIANT
8336#define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8337#undef THUMB_VARIANT
8338#define THUMB_VARIANT ARM_EXT_V4T
8339 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8340 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8341 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8342 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8343 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8344 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8345
8346#undef ARM_VARIANT
8347#define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8348 /* ARM Architecture 4T. */
8349 /* Note: bx (and blx) are required on V5, even if the processor does
8350 not support Thumb. */
8351 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8352
8353#undef ARM_VARIANT
8354#define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8355#undef THUMB_VARIANT
8356#define THUMB_VARIANT ARM_EXT_V5T
8357 /* Note: blx has 2 variants; the .value coded here is for
8358 BLX(2). Only this variant has conditional execution. */
8359 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8360 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8361
8362#undef THUMB_VARIANT
8363#define THUMB_VARIANT ARM_EXT_V6T2
8364 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8365 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8366 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8367 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8368 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8369 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8370 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8371 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8372
8373#undef ARM_VARIANT
8374#define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8375 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8376 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8377 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8378 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8379
8380 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8381 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8382
8383 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8384 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8385 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8386 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8387
8388 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8389 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8390 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8391 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8392
8393 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8394 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8395
8396 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8397 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8398 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8399 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8400
8401#undef ARM_VARIANT
8402#define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8403 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8404 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8405 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8406
8407 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8408 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8409
8410#undef ARM_VARIANT
8411#define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8412 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8413
8414#undef ARM_VARIANT
8415#define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8416#undef THUMB_VARIANT
8417#define THUMB_VARIANT ARM_EXT_V6
8418 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8419 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8420 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8421 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8422 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8423 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8424 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8425 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8426 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8427 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8428
8429#undef THUMB_VARIANT
8430#define THUMB_VARIANT ARM_EXT_V6T2
8431 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8432 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8433 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8434 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8435 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8436 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8437 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8438 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8439 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8440 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8441 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8442 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8443 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8444 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8445 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8446 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8447 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8448 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8449 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8450 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8451 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8452 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8453 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8454 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8455 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8456 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8457 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8458 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8459 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8460 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8461 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8462 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8463 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8464 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8465 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8466 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8467 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8468 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8469 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8470 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8471 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8472 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8473 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8474 UF(rfeib, 9900a00, 1, (RRw), rfe),
8475 UF(rfeda, 8100a00, 1, (RRw), rfe),
8476 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8477 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8478 UF(rfefa, 9900a00, 1, (RRw), rfe),
8479 UF(rfeea, 8100a00, 1, (RRw), rfe),
8480 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8481 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8482 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8483 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8484 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8485 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8486 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8487 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8488 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8489 TCE(sel, 68000b0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8490 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8491 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8492 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8493 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8494 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8495 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8496 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8497 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8498 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8499 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8500 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8501 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8502 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8503 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8504 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8505 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8506 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8507 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8508 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8509 UF(srsib, 9cd0500, 1, (I31w), srs),
8510 UF(srsda, 84d0500, 1, (I31w), srs),
8511 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8512 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8513 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8514 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8515 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8516 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8517 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8518 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8519 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8520
8521#undef ARM_VARIANT
8522#define ARM_VARIANT ARM_EXT_V6K
8523#undef THUMB_VARIANT
8524#define THUMB_VARIANT ARM_EXT_V6K
8525 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8526 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8527 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8528 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8529
8530#undef THUMB_VARIANT
8531#define THUMB_VARIANT ARM_EXT_V6T2
8532 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8533 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8534 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8535 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8536 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8537 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8538 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8539
8540#undef ARM_VARIANT
8541#define ARM_VARIANT ARM_EXT_V6Z
8542 TCE(smi, 1600070, f7f08000, 1, (EXPi), smi, t_smi),
8543
8544#undef ARM_VARIANT
8545#define ARM_VARIANT ARM_EXT_V6T2
8546 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8547 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8548 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8549 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8550
8551 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8552 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8553 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8554 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8555
8556 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8557 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8558 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8559 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8560
8561 UT(cbnz, b900, 2, (RR, EXP), t_czb),
8562 UT(cbz, b100, 2, (RR, EXP), t_czb),
8563 /* ARM does not really have an IT instruction. */
8564 TUE(it, 0, bf08, 1, (COND), it, t_it),
8565 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
8566 TUE(ite, 0, bf04, 1, (COND), it, t_it),
8567 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
8568 TUE(itet, 0, bf06, 1, (COND), it, t_it),
8569 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
8570 TUE(itee, 0, bf02, 1, (COND), it, t_it),
8571 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
8572 TUE(itett, 0, bf07, 1, (COND), it, t_it),
8573 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
8574 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
8575 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
8576 TUE(itete, 0, bf05, 1, (COND), it, t_it),
8577 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
8578 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
8579
92e90b6e
PB
8580 /* Thumb2 only instructions. */
8581#undef ARM_VARIANT
8582#define ARM_VARIANT 0
8583
8584 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
8585 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
8586 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
8587 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
8588
c19d1205
ZW
8589#undef ARM_VARIANT
8590#define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
8591 CE(wfs, e200110, 1, (RR), rd),
8592 CE(rfs, e300110, 1, (RR), rd),
8593 CE(wfc, e400110, 1, (RR), rd),
8594 CE(rfc, e500110, 1, (RR), rd),
8595
8596 C3(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
8597 C3(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
8598 C3(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
8599 C3(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
8600
8601 C3(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
8602 C3(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
8603 C3(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
8604 C3(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
8605
8606 C3(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
8607 C3(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
8608 C3(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
8609 C3(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
8610 C3(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
8611 C3(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
8612 C3(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
8613 C3(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
8614 C3(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
8615 C3(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
8616 C3(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
8617 C3(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
8618
8619 C3(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
8620 C3(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
8621 C3(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
8622 C3(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
8623 C3(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
8624 C3(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
8625 C3(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
8626 C3(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
8627 C3(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
8628 C3(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
8629 C3(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
8630 C3(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
8631
8632 C3(abss, e208100, 2, (RF, RF_IF), rd_rm),
8633 C3(abssp, e208120, 2, (RF, RF_IF), rd_rm),
8634 C3(abssm, e208140, 2, (RF, RF_IF), rd_rm),
8635 C3(abssz, e208160, 2, (RF, RF_IF), rd_rm),
8636 C3(absd, e208180, 2, (RF, RF_IF), rd_rm),
8637 C3(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
8638 C3(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
8639 C3(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
8640 C3(abse, e288100, 2, (RF, RF_IF), rd_rm),
8641 C3(absep, e288120, 2, (RF, RF_IF), rd_rm),
8642 C3(absem, e288140, 2, (RF, RF_IF), rd_rm),
8643 C3(absez, e288160, 2, (RF, RF_IF), rd_rm),
8644
8645 C3(rnds, e308100, 2, (RF, RF_IF), rd_rm),
8646 C3(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
8647 C3(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
8648 C3(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
8649 C3(rndd, e308180, 2, (RF, RF_IF), rd_rm),
8650 C3(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
8651 C3(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
8652 C3(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
8653 C3(rnde, e388100, 2, (RF, RF_IF), rd_rm),
8654 C3(rndep, e388120, 2, (RF, RF_IF), rd_rm),
8655 C3(rndem, e388140, 2, (RF, RF_IF), rd_rm),
8656 C3(rndez, e388160, 2, (RF, RF_IF), rd_rm),
8657
8658 C3(sqts, e408100, 2, (RF, RF_IF), rd_rm),
8659 C3(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
8660 C3(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
8661 C3(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
8662 C3(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
8663 C3(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
8664 C3(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
8665 C3(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
8666 C3(sqte, e488100, 2, (RF, RF_IF), rd_rm),
8667 C3(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
8668 C3(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
8669 C3(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
8670
8671 C3(logs, e508100, 2, (RF, RF_IF), rd_rm),
8672 C3(logsp, e508120, 2, (RF, RF_IF), rd_rm),
8673 C3(logsm, e508140, 2, (RF, RF_IF), rd_rm),
8674 C3(logsz, e508160, 2, (RF, RF_IF), rd_rm),
8675 C3(logd, e508180, 2, (RF, RF_IF), rd_rm),
8676 C3(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
8677 C3(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
8678 C3(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
8679 C3(loge, e588100, 2, (RF, RF_IF), rd_rm),
8680 C3(logep, e588120, 2, (RF, RF_IF), rd_rm),
8681 C3(logem, e588140, 2, (RF, RF_IF), rd_rm),
8682 C3(logez, e588160, 2, (RF, RF_IF), rd_rm),
8683
8684 C3(lgns, e608100, 2, (RF, RF_IF), rd_rm),
8685 C3(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
8686 C3(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
8687 C3(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
8688 C3(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
8689 C3(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
8690 C3(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
8691 C3(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
8692 C3(lgne, e688100, 2, (RF, RF_IF), rd_rm),
8693 C3(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
8694 C3(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
8695 C3(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
8696
8697 C3(exps, e708100, 2, (RF, RF_IF), rd_rm),
8698 C3(expsp, e708120, 2, (RF, RF_IF), rd_rm),
8699 C3(expsm, e708140, 2, (RF, RF_IF), rd_rm),
8700 C3(expsz, e708160, 2, (RF, RF_IF), rd_rm),
8701 C3(expd, e708180, 2, (RF, RF_IF), rd_rm),
8702 C3(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
8703 C3(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
8704 C3(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
8705 C3(expe, e788100, 2, (RF, RF_IF), rd_rm),
8706 C3(expep, e788120, 2, (RF, RF_IF), rd_rm),
8707 C3(expem, e788140, 2, (RF, RF_IF), rd_rm),
8708 C3(expdz, e788160, 2, (RF, RF_IF), rd_rm),
8709
8710 C3(sins, e808100, 2, (RF, RF_IF), rd_rm),
8711 C3(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
8712 C3(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
8713 C3(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
8714 C3(sind, e808180, 2, (RF, RF_IF), rd_rm),
8715 C3(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
8716 C3(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
8717 C3(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
8718 C3(sine, e888100, 2, (RF, RF_IF), rd_rm),
8719 C3(sinep, e888120, 2, (RF, RF_IF), rd_rm),
8720 C3(sinem, e888140, 2, (RF, RF_IF), rd_rm),
8721 C3(sinez, e888160, 2, (RF, RF_IF), rd_rm),
8722
8723 C3(coss, e908100, 2, (RF, RF_IF), rd_rm),
8724 C3(cossp, e908120, 2, (RF, RF_IF), rd_rm),
8725 C3(cossm, e908140, 2, (RF, RF_IF), rd_rm),
8726 C3(cossz, e908160, 2, (RF, RF_IF), rd_rm),
8727 C3(cosd, e908180, 2, (RF, RF_IF), rd_rm),
8728 C3(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
8729 C3(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
8730 C3(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
8731 C3(cose, e988100, 2, (RF, RF_IF), rd_rm),
8732 C3(cosep, e988120, 2, (RF, RF_IF), rd_rm),
8733 C3(cosem, e988140, 2, (RF, RF_IF), rd_rm),
8734 C3(cosez, e988160, 2, (RF, RF_IF), rd_rm),
8735
8736 C3(tans, ea08100, 2, (RF, RF_IF), rd_rm),
8737 C3(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
8738 C3(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
8739 C3(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
8740 C3(tand, ea08180, 2, (RF, RF_IF), rd_rm),
8741 C3(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
8742 C3(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
8743 C3(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
8744 C3(tane, ea88100, 2, (RF, RF_IF), rd_rm),
8745 C3(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
8746 C3(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
8747 C3(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
8748
8749 C3(asns, eb08100, 2, (RF, RF_IF), rd_rm),
8750 C3(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
8751 C3(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
8752 C3(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
8753 C3(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
8754 C3(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
8755 C3(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
8756 C3(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
8757 C3(asne, eb88100, 2, (RF, RF_IF), rd_rm),
8758 C3(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
8759 C3(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
8760 C3(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
8761
8762 C3(acss, ec08100, 2, (RF, RF_IF), rd_rm),
8763 C3(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
8764 C3(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
8765 C3(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
8766 C3(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
8767 C3(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
8768 C3(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
8769 C3(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
8770 C3(acse, ec88100, 2, (RF, RF_IF), rd_rm),
8771 C3(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
8772 C3(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
8773 C3(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
8774
8775 C3(atns, ed08100, 2, (RF, RF_IF), rd_rm),
8776 C3(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
8777 C3(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
8778 C3(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
8779 C3(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
8780 C3(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
8781 C3(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
8782 C3(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
8783 C3(atne, ed88100, 2, (RF, RF_IF), rd_rm),
8784 C3(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
8785 C3(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
8786 C3(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
8787
8788 C3(urds, ee08100, 2, (RF, RF_IF), rd_rm),
8789 C3(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
8790 C3(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
8791 C3(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
8792 C3(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
8793 C3(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
8794 C3(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
8795 C3(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
8796 C3(urde, ee88100, 2, (RF, RF_IF), rd_rm),
8797 C3(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
8798 C3(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
8799 C3(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
8800
8801 C3(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
8802 C3(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
8803 C3(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
8804 C3(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
8805 C3(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
8806 C3(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
8807 C3(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
8808 C3(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
8809 C3(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
8810 C3(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
8811 C3(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
8812 C3(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
8813
8814 C3(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
8815 C3(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
8816 C3(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
8817 C3(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
8818 C3(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
8819 C3(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8820 C3(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8821 C3(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8822 C3(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
8823 C3(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
8824 C3(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
8825 C3(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
8826
8827 C3(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
8828 C3(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
8829 C3(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
8830 C3(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
8831 C3(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
8832 C3(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8833 C3(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8834 C3(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8835 C3(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
8836 C3(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
8837 C3(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
8838 C3(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
8839
8840 C3(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
8841 C3(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
8842 C3(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
8843 C3(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
8844 C3(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
8845 C3(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8846 C3(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8847 C3(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8848 C3(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
8849 C3(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
8850 C3(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
8851 C3(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
8852
8853 C3(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
8854 C3(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
8855 C3(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
8856 C3(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
8857 C3(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
8858 C3(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8859 C3(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8860 C3(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8861 C3(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
8862 C3(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
8863 C3(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
8864 C3(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
8865
8866 C3(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
8867 C3(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
8868 C3(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
8869 C3(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
8870 C3(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
8871 C3(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8872 C3(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8873 C3(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8874 C3(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
8875 C3(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
8876 C3(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
8877 C3(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
8878
8879 C3(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
8880 C3(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
8881 C3(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
8882 C3(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
8883 C3(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
8884 C3(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8885 C3(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8886 C3(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8887 C3(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
8888 C3(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
8889 C3(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
8890 C3(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
8891
8892 C3(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
8893 C3(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
8894 C3(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
8895 C3(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
8896 C3(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
8897 C3(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8898 C3(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8899 C3(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8900 C3(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
8901 C3(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
8902 C3(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
8903 C3(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
8904
8905 C3(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
8906 C3(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
8907 C3(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
8908 C3(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
8909 C3(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
8910 C3(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8911 C3(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8912 C3(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8913 C3(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
8914 C3(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
8915 C3(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
8916 C3(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
8917
8918 C3(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
8919 C3(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
8920 C3(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
8921 C3(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
8922 C3(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
8923 C3(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8924 C3(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8925 C3(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8926 C3(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
8927 C3(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
8928 C3(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
8929 C3(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
8930
8931 C3(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
8932 C3(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
8933 C3(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
8934 C3(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
8935 C3(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
8936 C3(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8937 C3(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8938 C3(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8939 C3(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
8940 C3(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
8941 C3(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
8942 C3(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
8943
8944 C3(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8945 C3(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8946 C3(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8947 C3(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8948 C3(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8949 C3(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8950 C3(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8951 C3(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8952 C3(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8953 C3(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8954 C3(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8955 C3(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8956
8957 C3(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8958 C3(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8959 C3(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8960 C3(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8961 C3(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8962 C3(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8963 C3(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8964 C3(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8965 C3(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8966 C3(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8967 C3(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8968 C3(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8969
8970 C3(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
8971 C3(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
8972 C3(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
8973 C3(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
8974 C3(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
8975 C3(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
8976 C3(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
8977 C3(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
8978 C3(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
8979 C3(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
8980 C3(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
8981 C3(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8982
8983 CE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
8984 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8985 CE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
8986 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
8987
8988 C3(flts, e000110, 2, (RF, RR), rn_rd),
8989 C3(fltsp, e000130, 2, (RF, RR), rn_rd),
8990 C3(fltsm, e000150, 2, (RF, RR), rn_rd),
8991 C3(fltsz, e000170, 2, (RF, RR), rn_rd),
8992 C3(fltd, e000190, 2, (RF, RR), rn_rd),
8993 C3(fltdp, e0001b0, 2, (RF, RR), rn_rd),
8994 C3(fltdm, e0001d0, 2, (RF, RR), rn_rd),
8995 C3(fltdz, e0001f0, 2, (RF, RR), rn_rd),
8996 C3(flte, e080110, 2, (RF, RR), rn_rd),
8997 C3(fltep, e080130, 2, (RF, RR), rn_rd),
8998 C3(fltem, e080150, 2, (RF, RR), rn_rd),
8999 C3(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 9000
c19d1205
ZW
9001 /* The implementation of the FIX instruction is broken on some
9002 assemblers, in that it accepts a precision specifier as well as a
9003 rounding specifier, despite the fact that this is meaningless.
9004 To be more compatible, we accept it as well, though of course it
9005 does not set any bits. */
9006 CE(fix, e100110, 2, (RR, RF), rd_rm),
9007 C3(fixp, e100130, 2, (RR, RF), rd_rm),
9008 C3(fixm, e100150, 2, (RR, RF), rd_rm),
9009 C3(fixz, e100170, 2, (RR, RF), rd_rm),
9010 C3(fixsp, e100130, 2, (RR, RF), rd_rm),
9011 C3(fixsm, e100150, 2, (RR, RF), rd_rm),
9012 C3(fixsz, e100170, 2, (RR, RF), rd_rm),
9013 C3(fixdp, e100130, 2, (RR, RF), rd_rm),
9014 C3(fixdm, e100150, 2, (RR, RF), rd_rm),
9015 C3(fixdz, e100170, 2, (RR, RF), rd_rm),
9016 C3(fixep, e100130, 2, (RR, RF), rd_rm),
9017 C3(fixem, e100150, 2, (RR, RF), rd_rm),
9018 C3(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 9019
c19d1205
ZW
9020 /* Instructions that were new with the real FPA, call them V2. */
9021#undef ARM_VARIANT
9022#define ARM_VARIANT FPU_FPA_EXT_V2
9023 CE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9024 C3(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9025 C3(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9026 CE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9027 C3(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9028 C3(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9029
9030#undef ARM_VARIANT
9031#define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
9032 /* Moves and type conversions. */
9033 CE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9034 CE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9035 CE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9036 CE(fmstat, ef1fa10, 0, (), noargs),
9037 CE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9038 CE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9039 CE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9040 CE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9041 CE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9042 CE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9043 CE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9044 CE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
9045
9046 /* Memory operations. */
9047 CE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9048 CE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9049 CE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9050 CE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9051 CE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9052 CE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9053 CE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9054 CE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9055 CE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9056 CE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9057 CE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9058 CE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9059 CE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9060 CE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9061 CE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9062 CE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9063 CE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9064 CE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 9065
c19d1205
ZW
9066 /* Monadic operations. */
9067 CE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9068 CE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9069 CE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
9070
9071 /* Dyadic operations. */
9072 CE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9073 CE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9074 CE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9075 CE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9076 CE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9077 CE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9078 CE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9079 CE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9080 CE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 9081
c19d1205
ZW
9082 /* Comparisons. */
9083 CE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9084 CE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9085 CE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9086 CE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 9087
c19d1205
ZW
9088#undef ARM_VARIANT
9089#define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
9090 /* Moves and type conversions. */
9091 CE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9092 CE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9093 CE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9094 CE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9095 CE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9096 CE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9097 CE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9098 CE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9099 CE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9100 CE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9101 CE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9102 CE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9103 CE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9104
9105 /* Memory operations. */
9106 CE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9107 CE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9108 CE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9109 CE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9110 CE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9111 CE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9112 CE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9113 CE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9114 CE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9115 CE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9116
c19d1205
ZW
9117 /* Monadic operations. */
9118 CE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9119 CE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9120 CE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9121
9122 /* Dyadic operations. */
9123 CE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9124 CE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9125 CE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9126 CE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9127 CE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9128 CE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9129 CE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9130 CE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9131 CE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9132
c19d1205
ZW
9133 /* Comparisons. */
9134 CE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9135 CE(fcmpzd, eb50b40, 1, (RVD), rd),
9136 CE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9137 CE(fcmpezd, eb50bc0, 1, (RVD), rd),
9138
9139#undef ARM_VARIANT
9140#define ARM_VARIANT FPU_VFP_EXT_V2
9141 CE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9142 CE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9143 CE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9144 CE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9145
9146#undef ARM_VARIANT
9147#define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
9148 CE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9149 CE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9150 CE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9151 CE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9152 CE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9153 CE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9154 CE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9155 CE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9156
9157#undef ARM_VARIANT
9158#define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
9159 CE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9160 CE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9161 CE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9162 CE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9163 CE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9164 CE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9165 CE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9166 CE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9167 CE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9168 CE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9169 CE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9170 CE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9171 CE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9172 CE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9173 CE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9174 CE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9175 CE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9176 CE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9177 CE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9178 CE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9179 CE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9180 CE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9181 CE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9182 CE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9183 CE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9184 CE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9185 CE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9186 CE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9187 CE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9188 CE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9189 CE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9190 CE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9191 CE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9192 CE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9193 CE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9194 CE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9195 CE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9196 CE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9197 CE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9198 CE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9199 CE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9200 CE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9201 CE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9202 CE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9203 CE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9204 CE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9205 CE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9206 CE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9207 CE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9208 CE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9209 CE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9210 CE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9211 CE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9212 CE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9213 CE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9214 CE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9215 CE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9216 CE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9217 CE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9218 CE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9219 CE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9220 CE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9221 CE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9222 CE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9223 CE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9224 CE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9225 CE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9226 CE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9227 CE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9228 CE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9229 CE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9230 CE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9231 CE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9232 CE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9233 CE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9234 CE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9235 CE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9236 CE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9237 CE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9238 CE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9239 CE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9240 CE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9241 CE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9242 CE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9243 CE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9244 CE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9245 CE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9246 CE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9247 CE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9248 CE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9249 CE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9250 CE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9251 CE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9252 CE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9253 CE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9254 CE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9255 CE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9256 CE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9257 CE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9258 CE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9259 CE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9260 CE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9261 CE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9262 CE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9263 CE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9264 CE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9265 CE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9266 CE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9267 CE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9268 CE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9269 CE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9270 CE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9271 CE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9272 CE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9273 CE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9274 CE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9275 CE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9276 CE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9277 CE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9278 CE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9279 CE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9280 CE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9281 CE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9282 CE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9283 CE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9284 CE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9285 CE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9286 CE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9287 CE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9288 CE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9289 CE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9290 CE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9291 CE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9292 CE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9293 CE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9294 CE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9295 CE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9296 CE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9297 CE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9298 CE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9299 CE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9300 CE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9301 CE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9302 CE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9303 CE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9304 CE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9305 CE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9306 CE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9307 CE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9308 CE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9309 CE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9310 CE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9311 CE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9312 CE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9313 CE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9314 CE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9315 CE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9316 CE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9317 CE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9318 CE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9319 CE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9320 CE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
9321
9322#undef ARM_VARIANT
9323#define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
9324 CE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9325 CE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9326 CE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9327 CE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9328 CE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9329 CE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9330 CE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9331 CE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9332 CE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9333 CE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9334 CE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9335 CE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9336 CE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9337 CE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9338 CE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9339 CE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9340 CE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9341 CE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9342 CE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9343 CE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9344 CE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9345 CE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9346 CE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9347 CE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9348 CE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9349 CE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9350 CE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9351 CE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9352 CE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9353 CE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9354 CE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9355 CE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9356 CE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9357 CE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9358 CE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9359 CE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9360 CE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9361 CE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9362 CE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9363 CE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9364 CE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9365 CE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9366 CE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9367 CE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9368 CE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9369 CE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9370 CE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9371 CE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9372 CE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9373 CE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9374 CE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9375 CE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9376 CE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9377 CE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9378 CE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9379 CE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9380 CE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9381 CE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9382 CE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9383 CE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9384 CE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9385 CE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9386 CE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9387 CE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9388 CE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9389 CE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9390 CE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9391 CE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9392 CE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9393 CE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9394 CE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9395 CE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9396 CE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9397 CE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9398 CE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9399 CE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9400};
9401#undef ARM_VARIANT
9402#undef THUMB_VARIANT
9403#undef TCE
9404#undef TCM
9405#undef TUE
9406#undef TUF
9407#undef TCC
9408#undef CE
9409#undef CM
9410#undef UE
9411#undef UF
9412#undef UT
9413#undef OPS0
9414#undef OPS1
9415#undef OPS2
9416#undef OPS3
9417#undef OPS4
9418#undef OPS5
9419#undef OPS6
9420#undef do_0
9421\f
9422/* MD interface: bits in the object file. */
bfae80f2 9423
c19d1205
ZW
9424/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9425 for use in the a.out file, and stores them in the array pointed to by buf.
9426 This knows about the endian-ness of the target machine and does
9427 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9428 2 (short) and 4 (long) Floating numbers are put out as a series of
9429 LITTLENUMS (shorts, here at least). */
b99bd4ef 9430
c19d1205
ZW
9431void
9432md_number_to_chars (char * buf, valueT val, int n)
9433{
9434 if (target_big_endian)
9435 number_to_chars_bigendian (buf, val, n);
9436 else
9437 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
9438}
9439
c19d1205
ZW
9440static valueT
9441md_chars_to_number (char * buf, int n)
bfae80f2 9442{
c19d1205
ZW
9443 valueT result = 0;
9444 unsigned char * where = (unsigned char *) buf;
bfae80f2 9445
c19d1205 9446 if (target_big_endian)
b99bd4ef 9447 {
c19d1205
ZW
9448 while (n--)
9449 {
9450 result <<= 8;
9451 result |= (*where++ & 255);
9452 }
b99bd4ef 9453 }
c19d1205 9454 else
b99bd4ef 9455 {
c19d1205
ZW
9456 while (n--)
9457 {
9458 result <<= 8;
9459 result |= (where[n] & 255);
9460 }
bfae80f2 9461 }
b99bd4ef 9462
c19d1205 9463 return result;
bfae80f2 9464}
b99bd4ef 9465
c19d1205 9466/* MD interface: Sections. */
b99bd4ef 9467
c19d1205
ZW
9468int
9469md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
9470 segT segtype ATTRIBUTE_UNUSED)
9471{
9472 as_fatal (_("md_estimate_size_before_relax\n"));
9473 return 1;
9474}
b99bd4ef 9475
c19d1205 9476/* Round up a section size to the appropriate boundary. */
b99bd4ef 9477
c19d1205
ZW
9478valueT
9479md_section_align (segT segment ATTRIBUTE_UNUSED,
9480 valueT size)
9481{
9482#ifdef OBJ_ELF
9483 return size;
9484#else
9485 /* Round all sects to multiple of 4. */
9486 return (size + 3) & ~3;
9487#endif
bfae80f2 9488}
b99bd4ef 9489
c19d1205
ZW
9490/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
9491 of an rs_align_code fragment. */
9492
9493void
9494arm_handle_align (fragS * fragP)
bfae80f2 9495{
c19d1205
ZW
9496 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
9497 static char const thumb_noop[2] = { 0xc0, 0x46 };
9498 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
9499 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
9500
9501 int bytes, fix, noop_size;
9502 char * p;
9503 const char * noop;
bfae80f2 9504
c19d1205 9505 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
9506 return;
9507
c19d1205
ZW
9508 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
9509 p = fragP->fr_literal + fragP->fr_fix;
9510 fix = 0;
bfae80f2 9511
c19d1205
ZW
9512 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
9513 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 9514
c19d1205 9515 if (fragP->tc_frag_data)
a737bd4d 9516 {
c19d1205
ZW
9517 if (target_big_endian)
9518 noop = thumb_bigend_noop;
9519 else
9520 noop = thumb_noop;
9521 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
9522 }
9523 else
9524 {
c19d1205
ZW
9525 if (target_big_endian)
9526 noop = arm_bigend_noop;
9527 else
9528 noop = arm_noop;
9529 noop_size = sizeof (arm_noop);
7ed4c4c5 9530 }
a737bd4d 9531
c19d1205 9532 if (bytes & (noop_size - 1))
7ed4c4c5 9533 {
c19d1205
ZW
9534 fix = bytes & (noop_size - 1);
9535 memset (p, 0, fix);
9536 p += fix;
9537 bytes -= fix;
a737bd4d 9538 }
a737bd4d 9539
c19d1205 9540 while (bytes >= noop_size)
a737bd4d 9541 {
c19d1205
ZW
9542 memcpy (p, noop, noop_size);
9543 p += noop_size;
9544 bytes -= noop_size;
9545 fix += noop_size;
a737bd4d
NC
9546 }
9547
c19d1205
ZW
9548 fragP->fr_fix += fix;
9549 fragP->fr_var = noop_size;
a737bd4d
NC
9550}
9551
c19d1205
ZW
9552/* Called from md_do_align. Used to create an alignment
9553 frag in a code section. */
9554
9555void
9556arm_frag_align_code (int n, int max)
bfae80f2 9557{
c19d1205 9558 char * p;
7ed4c4c5 9559
c19d1205
ZW
9560 /* We assume that there will never be a requirement
9561 to support alignments greater than 32 bytes. */
9562 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
9563 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 9564
c19d1205
ZW
9565 p = frag_var (rs_align_code,
9566 MAX_MEM_FOR_RS_ALIGN_CODE,
9567 1,
9568 (relax_substateT) max,
9569 (symbolS *) NULL,
9570 (offsetT) n,
9571 (char *) NULL);
9572 *p = 0;
9573}
bfae80f2 9574
c19d1205 9575/* Perform target specific initialisation of a frag. */
bfae80f2 9576
c19d1205
ZW
9577void
9578arm_init_frag (fragS * fragP)
9579{
9580 /* Record whether this frag is in an ARM or a THUMB area. */
9581 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
9582}
9583
c19d1205
ZW
9584#ifdef OBJ_ELF
9585/* When we change sections we need to issue a new mapping symbol. */
9586
9587void
9588arm_elf_change_section (void)
bfae80f2 9589{
c19d1205
ZW
9590 flagword flags;
9591 segment_info_type *seginfo;
bfae80f2 9592
c19d1205
ZW
9593 /* Link an unlinked unwind index table section to the .text section. */
9594 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
9595 && elf_linked_to_section (now_seg) == NULL)
9596 elf_linked_to_section (now_seg) = text_section;
9597
9598 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
9599 return;
9600
c19d1205
ZW
9601 flags = bfd_get_section_flags (stdoutput, now_seg);
9602
9603 /* We can ignore sections that only contain debug info. */
9604 if ((flags & SEC_ALLOC) == 0)
9605 return;
bfae80f2 9606
c19d1205
ZW
9607 seginfo = seg_info (now_seg);
9608 mapstate = seginfo->tc_segment_info_data.mapstate;
9609 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
9610}
9611
c19d1205
ZW
9612int
9613arm_elf_section_type (const char * str, size_t len)
e45d0630 9614{
c19d1205
ZW
9615 if (len == 5 && strncmp (str, "exidx", 5) == 0)
9616 return SHT_ARM_EXIDX;
e45d0630 9617
c19d1205
ZW
9618 return -1;
9619}
9620\f
9621/* Code to deal with unwinding tables. */
e45d0630 9622
c19d1205 9623static void add_unwind_adjustsp (offsetT);
e45d0630 9624
c19d1205 9625/* Cenerate and deferred unwind frame offset. */
e45d0630 9626
bfae80f2 9627static void
c19d1205 9628flush_pending_unwind (void)
bfae80f2 9629{
c19d1205 9630 offsetT offset;
bfae80f2 9631
c19d1205
ZW
9632 offset = unwind.pending_offset;
9633 unwind.pending_offset = 0;
9634 if (offset != 0)
9635 add_unwind_adjustsp (offset);
bfae80f2
RE
9636}
9637
c19d1205
ZW
9638/* Add an opcode to this list for this function. Two-byte opcodes should
9639 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
9640 order. */
9641
bfae80f2 9642static void
c19d1205 9643add_unwind_opcode (valueT op, int length)
bfae80f2 9644{
c19d1205
ZW
9645 /* Add any deferred stack adjustment. */
9646 if (unwind.pending_offset)
9647 flush_pending_unwind ();
bfae80f2 9648
c19d1205 9649 unwind.sp_restored = 0;
bfae80f2 9650
c19d1205 9651 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 9652 {
c19d1205
ZW
9653 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
9654 if (unwind.opcodes)
9655 unwind.opcodes = xrealloc (unwind.opcodes,
9656 unwind.opcode_alloc);
9657 else
9658 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 9659 }
c19d1205 9660 while (length > 0)
bfae80f2 9661 {
c19d1205
ZW
9662 length--;
9663 unwind.opcodes[unwind.opcode_count] = op & 0xff;
9664 op >>= 8;
9665 unwind.opcode_count++;
bfae80f2 9666 }
bfae80f2
RE
9667}
9668
c19d1205
ZW
9669/* Add unwind opcodes to adjust the stack pointer. */
9670
bfae80f2 9671static void
c19d1205 9672add_unwind_adjustsp (offsetT offset)
bfae80f2 9673{
c19d1205 9674 valueT op;
bfae80f2 9675
c19d1205 9676 if (offset > 0x200)
bfae80f2 9677 {
c19d1205
ZW
9678 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
9679 char bytes[5];
9680 int n;
9681 valueT o;
bfae80f2 9682
c19d1205
ZW
9683 /* Long form: 0xb2, uleb128. */
9684 /* This might not fit in a word so add the individual bytes,
9685 remembering the list is built in reverse order. */
9686 o = (valueT) ((offset - 0x204) >> 2);
9687 if (o == 0)
9688 add_unwind_opcode (0, 1);
bfae80f2 9689
c19d1205
ZW
9690 /* Calculate the uleb128 encoding of the offset. */
9691 n = 0;
9692 while (o)
9693 {
9694 bytes[n] = o & 0x7f;
9695 o >>= 7;
9696 if (o)
9697 bytes[n] |= 0x80;
9698 n++;
9699 }
9700 /* Add the insn. */
9701 for (; n; n--)
9702 add_unwind_opcode (bytes[n - 1], 1);
9703 add_unwind_opcode (0xb2, 1);
9704 }
9705 else if (offset > 0x100)
bfae80f2 9706 {
c19d1205
ZW
9707 /* Two short opcodes. */
9708 add_unwind_opcode (0x3f, 1);
9709 op = (offset - 0x104) >> 2;
9710 add_unwind_opcode (op, 1);
bfae80f2 9711 }
c19d1205
ZW
9712 else if (offset > 0)
9713 {
9714 /* Short opcode. */
9715 op = (offset - 4) >> 2;
9716 add_unwind_opcode (op, 1);
9717 }
9718 else if (offset < 0)
bfae80f2 9719 {
c19d1205
ZW
9720 offset = -offset;
9721 while (offset > 0x100)
bfae80f2 9722 {
c19d1205
ZW
9723 add_unwind_opcode (0x7f, 1);
9724 offset -= 0x100;
bfae80f2 9725 }
c19d1205
ZW
9726 op = ((offset - 4) >> 2) | 0x40;
9727 add_unwind_opcode (op, 1);
bfae80f2 9728 }
bfae80f2
RE
9729}
9730
c19d1205
ZW
9731/* Finish the list of unwind opcodes for this function. */
9732static void
9733finish_unwind_opcodes (void)
bfae80f2 9734{
c19d1205 9735 valueT op;
bfae80f2 9736
c19d1205 9737 if (unwind.fp_used)
bfae80f2 9738 {
c19d1205
ZW
9739 /* Adjust sp as neccessary. */
9740 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
9741 flush_pending_unwind ();
bfae80f2 9742
c19d1205
ZW
9743 /* After restoring sp from the frame pointer. */
9744 op = 0x90 | unwind.fp_reg;
9745 add_unwind_opcode (op, 1);
9746 }
9747 else
9748 flush_pending_unwind ();
bfae80f2
RE
9749}
9750
bfae80f2 9751
c19d1205
ZW
9752/* Start an exception table entry. If idx is nonzero this is an index table
9753 entry. */
bfae80f2
RE
9754
9755static void
c19d1205 9756start_unwind_section (const segT text_seg, int idx)
bfae80f2 9757{
c19d1205
ZW
9758 const char * text_name;
9759 const char * prefix;
9760 const char * prefix_once;
9761 const char * group_name;
9762 size_t prefix_len;
9763 size_t text_len;
9764 char * sec_name;
9765 size_t sec_name_len;
9766 int type;
9767 int flags;
9768 int linkonce;
bfae80f2 9769
c19d1205 9770 if (idx)
bfae80f2 9771 {
c19d1205
ZW
9772 prefix = ELF_STRING_ARM_unwind;
9773 prefix_once = ELF_STRING_ARM_unwind_once;
9774 type = SHT_ARM_EXIDX;
bfae80f2 9775 }
c19d1205 9776 else
bfae80f2 9777 {
c19d1205
ZW
9778 prefix = ELF_STRING_ARM_unwind_info;
9779 prefix_once = ELF_STRING_ARM_unwind_info_once;
9780 type = SHT_PROGBITS;
bfae80f2
RE
9781 }
9782
c19d1205
ZW
9783 text_name = segment_name (text_seg);
9784 if (streq (text_name, ".text"))
9785 text_name = "";
9786
9787 if (strncmp (text_name, ".gnu.linkonce.t.",
9788 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 9789 {
c19d1205
ZW
9790 prefix = prefix_once;
9791 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
9792 }
9793
c19d1205
ZW
9794 prefix_len = strlen (prefix);
9795 text_len = strlen (text_name);
9796 sec_name_len = prefix_len + text_len;
9797 sec_name = xmalloc (sec_name_len + 1);
9798 memcpy (sec_name, prefix, prefix_len);
9799 memcpy (sec_name + prefix_len, text_name, text_len);
9800 sec_name[prefix_len + text_len] = '\0';
bfae80f2 9801
c19d1205
ZW
9802 flags = SHF_ALLOC;
9803 linkonce = 0;
9804 group_name = 0;
bfae80f2 9805
c19d1205
ZW
9806 /* Handle COMDAT group. */
9807 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 9808 {
c19d1205
ZW
9809 group_name = elf_group_name (text_seg);
9810 if (group_name == NULL)
9811 {
9812 as_bad ("Group section `%s' has no group signature",
9813 segment_name (text_seg));
9814 ignore_rest_of_line ();
9815 return;
9816 }
9817 flags |= SHF_GROUP;
9818 linkonce = 1;
bfae80f2
RE
9819 }
9820
c19d1205 9821 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 9822
c19d1205
ZW
9823 /* Set the setion link for index tables. */
9824 if (idx)
9825 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
9826}
9827
bfae80f2 9828
c19d1205
ZW
9829/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
9830 personality routine data. Returns zero, or the index table value for
9831 and inline entry. */
9832
9833static valueT
9834create_unwind_entry (int have_data)
bfae80f2 9835{
c19d1205
ZW
9836 int size;
9837 addressT where;
9838 char *ptr;
9839 /* The current word of data. */
9840 valueT data;
9841 /* The number of bytes left in this word. */
9842 int n;
bfae80f2 9843
c19d1205 9844 finish_unwind_opcodes ();
bfae80f2 9845
c19d1205
ZW
9846 /* Remember the current text section. */
9847 unwind.saved_seg = now_seg;
9848 unwind.saved_subseg = now_subseg;
bfae80f2 9849
c19d1205 9850 start_unwind_section (now_seg, 0);
bfae80f2 9851
c19d1205 9852 if (unwind.personality_routine == NULL)
bfae80f2 9853 {
c19d1205
ZW
9854 if (unwind.personality_index == -2)
9855 {
9856 if (have_data)
9857 as_bad (_("handerdata in cantunwind frame"));
9858 return 1; /* EXIDX_CANTUNWIND. */
9859 }
bfae80f2 9860
c19d1205
ZW
9861 /* Use a default personality routine if none is specified. */
9862 if (unwind.personality_index == -1)
9863 {
9864 if (unwind.opcode_count > 3)
9865 unwind.personality_index = 1;
9866 else
9867 unwind.personality_index = 0;
9868 }
bfae80f2 9869
c19d1205
ZW
9870 /* Space for the personality routine entry. */
9871 if (unwind.personality_index == 0)
9872 {
9873 if (unwind.opcode_count > 3)
9874 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 9875
c19d1205
ZW
9876 if (!have_data)
9877 {
9878 /* All the data is inline in the index table. */
9879 data = 0x80;
9880 n = 3;
9881 while (unwind.opcode_count > 0)
9882 {
9883 unwind.opcode_count--;
9884 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9885 n--;
9886 }
bfae80f2 9887
c19d1205
ZW
9888 /* Pad with "finish" opcodes. */
9889 while (n--)
9890 data = (data << 8) | 0xb0;
bfae80f2 9891
c19d1205
ZW
9892 return data;
9893 }
9894 size = 0;
9895 }
9896 else
9897 /* We get two opcodes "free" in the first word. */
9898 size = unwind.opcode_count - 2;
9899 }
9900 else
9901 /* An extra byte is required for the opcode count. */
9902 size = unwind.opcode_count + 1;
bfae80f2 9903
c19d1205
ZW
9904 size = (size + 3) >> 2;
9905 if (size > 0xff)
9906 as_bad (_("too many unwind opcodes"));
bfae80f2 9907
c19d1205
ZW
9908 frag_align (2, 0, 0);
9909 record_alignment (now_seg, 2);
9910 unwind.table_entry = expr_build_dot ();
9911
9912 /* Allocate the table entry. */
9913 ptr = frag_more ((size << 2) + 4);
9914 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 9915
c19d1205 9916 switch (unwind.personality_index)
bfae80f2 9917 {
c19d1205
ZW
9918 case -1:
9919 /* ??? Should this be a PLT generating relocation? */
9920 /* Custom personality routine. */
9921 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
9922 BFD_RELOC_ARM_PREL31);
bfae80f2 9923
c19d1205
ZW
9924 where += 4;
9925 ptr += 4;
bfae80f2 9926
c19d1205
ZW
9927 /* Set the first byte to the number of additional words. */
9928 data = size - 1;
9929 n = 3;
9930 break;
bfae80f2 9931
c19d1205
ZW
9932 /* ABI defined personality routines. */
9933 case 0:
9934 /* Three opcodes bytes are packed into the first word. */
9935 data = 0x80;
9936 n = 3;
9937 break;
bfae80f2 9938
c19d1205
ZW
9939 case 1:
9940 case 2:
9941 /* The size and first two opcode bytes go in the first word. */
9942 data = ((0x80 + unwind.personality_index) << 8) | size;
9943 n = 2;
9944 break;
bfae80f2 9945
c19d1205
ZW
9946 default:
9947 /* Should never happen. */
9948 abort ();
9949 }
bfae80f2 9950
c19d1205
ZW
9951 /* Pack the opcodes into words (MSB first), reversing the list at the same
9952 time. */
9953 while (unwind.opcode_count > 0)
9954 {
9955 if (n == 0)
9956 {
9957 md_number_to_chars (ptr, data, 4);
9958 ptr += 4;
9959 n = 4;
9960 data = 0;
9961 }
9962 unwind.opcode_count--;
9963 n--;
9964 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
9965 }
9966
9967 /* Finish off the last word. */
9968 if (n < 4)
9969 {
9970 /* Pad with "finish" opcodes. */
9971 while (n--)
9972 data = (data << 8) | 0xb0;
9973
9974 md_number_to_chars (ptr, data, 4);
9975 }
9976
9977 if (!have_data)
9978 {
9979 /* Add an empty descriptor if there is no user-specified data. */
9980 ptr = frag_more (4);
9981 md_number_to_chars (ptr, 0, 4);
9982 }
9983
9984 return 0;
bfae80f2
RE
9985}
9986
c19d1205
ZW
9987/* Convert REGNAME to a DWARF-2 register number. */
9988
9989int
9990tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 9991{
c19d1205
ZW
9992 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
9993
9994 if (reg == FAIL)
9995 return -1;
9996
9997 return reg;
bfae80f2
RE
9998}
9999
c19d1205
ZW
10000/* Initialize the DWARF-2 unwind information for this procedure. */
10001
10002void
10003tc_arm_frame_initial_instructions (void)
bfae80f2 10004{
c19d1205 10005 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 10006}
c19d1205 10007#endif /* OBJ_ELF */
bfae80f2 10008
bfae80f2 10009
c19d1205 10010/* MD interface: Symbol and relocation handling. */
bfae80f2 10011
2fc8bdac
ZW
10012/* Return the address within the segment that a PC-relative fixup is
10013 relative to. For ARM, PC-relative fixups applied to instructions
10014 are generally relative to the location of the fixup plus 8 bytes.
10015 Thumb branches are offset by 4, and Thumb loads relative to PC
10016 require special handling. */
bfae80f2 10017
c19d1205 10018long
2fc8bdac 10019md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 10020{
2fc8bdac
ZW
10021 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
10022
10023 /* If this is pc-relative and we are going to emit a relocation
10024 then we just want to put out any pipeline compensation that the linker
10025 will need. Otherwise we want to use the calculated base. */
10026 if (fixP->fx_pcrel
10027 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10028 || arm_force_relocation (fixP)))
10029 base = 0;
bfae80f2 10030
c19d1205 10031 switch (fixP->fx_r_type)
bfae80f2 10032 {
2fc8bdac
ZW
10033 /* PC relative addressing on the Thumb is slightly odd as the
10034 bottom two bits of the PC are forced to zero for the
10035 calculation. This happens *after* application of the
10036 pipeline offset. However, Thumb adrl already adjusts for
10037 this, so we need not do it again. */
c19d1205 10038 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 10039 return base & ~3;
c19d1205
ZW
10040
10041 case BFD_RELOC_ARM_THUMB_OFFSET:
10042 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 10043 case BFD_RELOC_ARM_T32_ADD_PC12:
2fc8bdac 10044 return (base + 4) & ~3;
c19d1205 10045
2fc8bdac
ZW
10046 /* Thumb branches are simply offset by +4. */
10047 case BFD_RELOC_THUMB_PCREL_BRANCH7:
10048 case BFD_RELOC_THUMB_PCREL_BRANCH9:
10049 case BFD_RELOC_THUMB_PCREL_BRANCH12:
10050 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10051 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10052 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10053 case BFD_RELOC_THUMB_PCREL_BLX:
10054 return base + 4;
bfae80f2 10055
2fc8bdac
ZW
10056 /* ARM mode branches are offset by +8. However, the Windows CE
10057 loader expects the relocation not to take this into account. */
10058 case BFD_RELOC_ARM_PCREL_BRANCH:
10059 case BFD_RELOC_ARM_PCREL_BLX:
10060 case BFD_RELOC_ARM_PLT32:
c19d1205 10061#ifdef TE_WINCE
2fc8bdac 10062 return base;
c19d1205 10063#else
2fc8bdac 10064 return base + 8;
c19d1205 10065#endif
2fc8bdac
ZW
10066
10067 /* ARM mode loads relative to PC are also offset by +8. Unlike
10068 branches, the Windows CE loader *does* expect the relocation
10069 to take this into account. */
10070 case BFD_RELOC_ARM_OFFSET_IMM:
10071 case BFD_RELOC_ARM_OFFSET_IMM8:
10072 case BFD_RELOC_ARM_HWLITERAL:
10073 case BFD_RELOC_ARM_LITERAL:
10074 case BFD_RELOC_ARM_CP_OFF_IMM:
10075 return base + 8;
10076
10077
10078 /* Other PC-relative relocations are un-offset. */
10079 default:
10080 return base;
10081 }
bfae80f2
RE
10082}
10083
c19d1205
ZW
10084/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
10085 Otherwise we have no need to default values of symbols. */
10086
10087symbolS *
10088md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 10089{
c19d1205
ZW
10090#ifdef OBJ_ELF
10091 if (name[0] == '_' && name[1] == 'G'
10092 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
10093 {
10094 if (!GOT_symbol)
10095 {
10096 if (symbol_find (name))
10097 as_bad ("GOT already in the symbol table");
bfae80f2 10098
c19d1205
ZW
10099 GOT_symbol = symbol_new (name, undefined_section,
10100 (valueT) 0, & zero_address_frag);
10101 }
bfae80f2 10102
c19d1205 10103 return GOT_symbol;
bfae80f2 10104 }
c19d1205 10105#endif
bfae80f2 10106
c19d1205 10107 return 0;
bfae80f2
RE
10108}
10109
55cf6793 10110/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
10111 computed as two separate immediate values, added together. We
10112 already know that this value cannot be computed by just one ARM
10113 instruction. */
10114
10115static unsigned int
10116validate_immediate_twopart (unsigned int val,
10117 unsigned int * highpart)
bfae80f2 10118{
c19d1205
ZW
10119 unsigned int a;
10120 unsigned int i;
bfae80f2 10121
c19d1205
ZW
10122 for (i = 0; i < 32; i += 2)
10123 if (((a = rotate_left (val, i)) & 0xff) != 0)
10124 {
10125 if (a & 0xff00)
10126 {
10127 if (a & ~ 0xffff)
10128 continue;
10129 * highpart = (a >> 8) | ((i + 24) << 7);
10130 }
10131 else if (a & 0xff0000)
10132 {
10133 if (a & 0xff000000)
10134 continue;
10135 * highpart = (a >> 16) | ((i + 16) << 7);
10136 }
10137 else
10138 {
10139 assert (a & 0xff000000);
10140 * highpart = (a >> 24) | ((i + 8) << 7);
10141 }
bfae80f2 10142
c19d1205
ZW
10143 return (a & 0xff) | (i << 7);
10144 }
bfae80f2 10145
c19d1205 10146 return FAIL;
bfae80f2
RE
10147}
10148
c19d1205
ZW
10149static int
10150validate_offset_imm (unsigned int val, int hwse)
10151{
10152 if ((hwse && val > 255) || val > 4095)
10153 return FAIL;
10154 return val;
10155}
bfae80f2 10156
55cf6793 10157/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
10158 negative immediate constant by altering the instruction. A bit of
10159 a hack really.
10160 MOV <-> MVN
10161 AND <-> BIC
10162 ADC <-> SBC
10163 by inverting the second operand, and
10164 ADD <-> SUB
10165 CMP <-> CMN
10166 by negating the second operand. */
bfae80f2 10167
c19d1205
ZW
10168static int
10169negate_data_op (unsigned long * instruction,
10170 unsigned long value)
bfae80f2 10171{
c19d1205
ZW
10172 int op, new_inst;
10173 unsigned long negated, inverted;
bfae80f2 10174
c19d1205
ZW
10175 negated = encode_arm_immediate (-value);
10176 inverted = encode_arm_immediate (~value);
bfae80f2 10177
c19d1205
ZW
10178 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10179 switch (op)
bfae80f2 10180 {
c19d1205
ZW
10181 /* First negates. */
10182 case OPCODE_SUB: /* ADD <-> SUB */
10183 new_inst = OPCODE_ADD;
10184 value = negated;
10185 break;
bfae80f2 10186
c19d1205
ZW
10187 case OPCODE_ADD:
10188 new_inst = OPCODE_SUB;
10189 value = negated;
10190 break;
bfae80f2 10191
c19d1205
ZW
10192 case OPCODE_CMP: /* CMP <-> CMN */
10193 new_inst = OPCODE_CMN;
10194 value = negated;
10195 break;
bfae80f2 10196
c19d1205
ZW
10197 case OPCODE_CMN:
10198 new_inst = OPCODE_CMP;
10199 value = negated;
10200 break;
bfae80f2 10201
c19d1205
ZW
10202 /* Now Inverted ops. */
10203 case OPCODE_MOV: /* MOV <-> MVN */
10204 new_inst = OPCODE_MVN;
10205 value = inverted;
10206 break;
bfae80f2 10207
c19d1205
ZW
10208 case OPCODE_MVN:
10209 new_inst = OPCODE_MOV;
10210 value = inverted;
10211 break;
bfae80f2 10212
c19d1205
ZW
10213 case OPCODE_AND: /* AND <-> BIC */
10214 new_inst = OPCODE_BIC;
10215 value = inverted;
10216 break;
bfae80f2 10217
c19d1205
ZW
10218 case OPCODE_BIC:
10219 new_inst = OPCODE_AND;
10220 value = inverted;
10221 break;
bfae80f2 10222
c19d1205
ZW
10223 case OPCODE_ADC: /* ADC <-> SBC */
10224 new_inst = OPCODE_SBC;
10225 value = inverted;
10226 break;
bfae80f2 10227
c19d1205
ZW
10228 case OPCODE_SBC:
10229 new_inst = OPCODE_ADC;
10230 value = inverted;
10231 break;
bfae80f2 10232
c19d1205
ZW
10233 /* We cannot do anything. */
10234 default:
10235 return FAIL;
b99bd4ef
NC
10236 }
10237
c19d1205
ZW
10238 if (value == (unsigned) FAIL)
10239 return FAIL;
10240
10241 *instruction &= OPCODE_MASK;
10242 *instruction |= new_inst << DATA_OP_SHIFT;
10243 return value;
b99bd4ef
NC
10244}
10245
c19d1205 10246void
55cf6793 10247md_apply_fix (fixS * fixP,
c19d1205
ZW
10248 valueT * valP,
10249 segT seg)
10250{
10251 offsetT value = * valP;
10252 offsetT newval;
10253 unsigned int newimm;
10254 unsigned long temp;
10255 int sign;
10256 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 10257
c19d1205 10258 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 10259
c19d1205
ZW
10260 /* Note whether this will delete the relocation. */
10261 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
10262 fixP->fx_done = 1;
b99bd4ef 10263
adbaf948
ZW
10264 /* On a 64-bit host, silently truncate 'value' to 32 bits for
10265 consistency with the behavior on 32-bit hosts. Remember value
10266 for emit_reloc. */
10267 value &= 0xffffffff;
10268 value ^= 0x80000000;
10269 value -= 0x80000000;
10270
10271 *valP = value;
c19d1205 10272 fixP->fx_addnumber = value;
b99bd4ef 10273
adbaf948
ZW
10274 /* Same treatment for fixP->fx_offset. */
10275 fixP->fx_offset &= 0xffffffff;
10276 fixP->fx_offset ^= 0x80000000;
10277 fixP->fx_offset -= 0x80000000;
10278
c19d1205 10279 switch (fixP->fx_r_type)
b99bd4ef 10280 {
c19d1205
ZW
10281 case BFD_RELOC_NONE:
10282 /* This will need to go in the object file. */
10283 fixP->fx_done = 0;
10284 break;
b99bd4ef 10285
c19d1205
ZW
10286 case BFD_RELOC_ARM_IMMEDIATE:
10287 /* We claim that this fixup has been processed here,
10288 even if in fact we generate an error because we do
10289 not have a reloc for it, so tc_gen_reloc will reject it. */
10290 fixP->fx_done = 1;
b99bd4ef 10291
c19d1205
ZW
10292 if (fixP->fx_addsy
10293 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 10294 {
c19d1205
ZW
10295 as_bad_where (fixP->fx_file, fixP->fx_line,
10296 _("undefined symbol %s used as an immediate value"),
10297 S_GET_NAME (fixP->fx_addsy));
10298 break;
b99bd4ef
NC
10299 }
10300
c19d1205
ZW
10301 newimm = encode_arm_immediate (value);
10302 temp = md_chars_to_number (buf, INSN_SIZE);
10303
10304 /* If the instruction will fail, see if we can fix things up by
10305 changing the opcode. */
10306 if (newimm == (unsigned int) FAIL
10307 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 10308 {
c19d1205
ZW
10309 as_bad_where (fixP->fx_file, fixP->fx_line,
10310 _("invalid constant (%lx) after fixup"),
10311 (unsigned long) value);
10312 break;
b99bd4ef 10313 }
b99bd4ef 10314
c19d1205
ZW
10315 newimm |= (temp & 0xfffff000);
10316 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
10317 break;
b99bd4ef 10318
c19d1205
ZW
10319 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
10320 {
10321 unsigned int highpart = 0;
10322 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 10323
c19d1205
ZW
10324 newimm = encode_arm_immediate (value);
10325 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 10326
c19d1205
ZW
10327 /* If the instruction will fail, see if we can fix things up by
10328 changing the opcode. */
10329 if (newimm == (unsigned int) FAIL
10330 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
10331 {
10332 /* No ? OK - try using two ADD instructions to generate
10333 the value. */
10334 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 10335
c19d1205
ZW
10336 /* Yes - then make sure that the second instruction is
10337 also an add. */
10338 if (newimm != (unsigned int) FAIL)
10339 newinsn = temp;
10340 /* Still No ? Try using a negated value. */
10341 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
10342 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
10343 /* Otherwise - give up. */
10344 else
10345 {
10346 as_bad_where (fixP->fx_file, fixP->fx_line,
10347 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
10348 (long) value);
10349 break;
10350 }
b99bd4ef 10351
c19d1205
ZW
10352 /* Replace the first operand in the 2nd instruction (which
10353 is the PC) with the destination register. We have
10354 already added in the PC in the first instruction and we
10355 do not want to do it again. */
10356 newinsn &= ~ 0xf0000;
10357 newinsn |= ((newinsn & 0x0f000) << 4);
10358 }
b99bd4ef 10359
c19d1205
ZW
10360 newimm |= (temp & 0xfffff000);
10361 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 10362
c19d1205
ZW
10363 highpart |= (newinsn & 0xfffff000);
10364 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
10365 }
10366 break;
b99bd4ef 10367
c19d1205
ZW
10368 case BFD_RELOC_ARM_OFFSET_IMM:
10369 case BFD_RELOC_ARM_LITERAL:
10370 sign = value >= 0;
b99bd4ef 10371
c19d1205
ZW
10372 if (value < 0)
10373 value = - value;
b99bd4ef 10374
c19d1205 10375 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 10376 {
c19d1205
ZW
10377 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
10378 as_bad_where (fixP->fx_file, fixP->fx_line,
10379 _("invalid literal constant: pool needs to be closer"));
10380 else
10381 as_bad_where (fixP->fx_file, fixP->fx_line,
10382 _("bad immediate value for offset (%ld)"),
10383 (long) value);
10384 break;
f03698e6
RE
10385 }
10386
c19d1205
ZW
10387 newval = md_chars_to_number (buf, INSN_SIZE);
10388 newval &= 0xff7ff000;
10389 newval |= value | (sign ? INDEX_UP : 0);
10390 md_number_to_chars (buf, newval, INSN_SIZE);
10391 break;
b99bd4ef 10392
c19d1205
ZW
10393 case BFD_RELOC_ARM_OFFSET_IMM8:
10394 case BFD_RELOC_ARM_HWLITERAL:
10395 sign = value >= 0;
b99bd4ef 10396
c19d1205
ZW
10397 if (value < 0)
10398 value = - value;
b99bd4ef 10399
c19d1205 10400 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 10401 {
c19d1205
ZW
10402 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
10403 as_bad_where (fixP->fx_file, fixP->fx_line,
10404 _("invalid literal constant: pool needs to be closer"));
10405 else
10406 as_bad (_("bad immediate value for half-word offset (%ld)"),
10407 (long) value);
10408 break;
b99bd4ef
NC
10409 }
10410
c19d1205
ZW
10411 newval = md_chars_to_number (buf, INSN_SIZE);
10412 newval &= 0xff7ff0f0;
10413 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
10414 md_number_to_chars (buf, newval, INSN_SIZE);
10415 break;
b99bd4ef 10416
c19d1205
ZW
10417 case BFD_RELOC_ARM_T32_OFFSET_U8:
10418 if (value < 0 || value > 1020 || value % 4 != 0)
10419 as_bad_where (fixP->fx_file, fixP->fx_line,
10420 _("bad immediate value for offset (%ld)"), (long) value);
10421 value /= 4;
b99bd4ef 10422
c19d1205 10423 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
10424 newval |= value;
10425 md_number_to_chars (buf+2, newval, THUMB_SIZE);
10426 break;
b99bd4ef 10427
c19d1205
ZW
10428 case BFD_RELOC_ARM_T32_OFFSET_IMM:
10429 /* This is a complicated relocation used for all varieties of Thumb32
10430 load/store instruction with immediate offset:
10431
10432 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
10433 *4, optional writeback(W)
10434 (doubleword load/store)
10435
10436 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
10437 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
10438 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
10439 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
10440 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
10441
10442 Uppercase letters indicate bits that are already encoded at
10443 this point. Lowercase letters are our problem. For the
10444 second block of instructions, the secondary opcode nybble
10445 (bits 8..11) is present, and bit 23 is zero, even if this is
10446 a PC-relative operation. */
10447 newval = md_chars_to_number (buf, THUMB_SIZE);
10448 newval <<= 16;
10449 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 10450
c19d1205 10451 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 10452 {
c19d1205
ZW
10453 /* Doubleword load/store: 8-bit offset, scaled by 4. */
10454 if (value >= 0)
10455 newval |= (1 << 23);
10456 else
10457 value = -value;
10458 if (value % 4 != 0)
10459 {
10460 as_bad_where (fixP->fx_file, fixP->fx_line,
10461 _("offset not a multiple of 4"));
10462 break;
10463 }
10464 value /= 4;
10465 if (value >= 0xff)
10466 {
10467 as_bad_where (fixP->fx_file, fixP->fx_line,
10468 _("offset out of range"));
10469 break;
10470 }
10471 newval &= ~0xff;
b99bd4ef 10472 }
c19d1205 10473 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 10474 {
c19d1205
ZW
10475 /* PC-relative, 12-bit offset. */
10476 if (value >= 0)
10477 newval |= (1 << 23);
10478 else
10479 value = -value;
10480 if (value >= 0xfff)
10481 {
10482 as_bad_where (fixP->fx_file, fixP->fx_line,
10483 _("offset out of range"));
10484 break;
10485 }
10486 newval &= ~0xfff;
b99bd4ef 10487 }
c19d1205 10488 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 10489 {
c19d1205
ZW
10490 /* Writeback: 8-bit, +/- offset. */
10491 if (value >= 0)
10492 newval |= (1 << 9);
10493 else
10494 value = -value;
10495 if (value >= 0xff)
10496 {
10497 as_bad_where (fixP->fx_file, fixP->fx_line,
10498 _("offset out of range"));
10499 break;
10500 }
10501 newval &= ~0xff;
b99bd4ef 10502 }
c19d1205 10503 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 10504 {
c19d1205
ZW
10505 /* T-instruction: positive 8-bit offset. */
10506 if (value < 0 || value >= 0xff)
b99bd4ef 10507 {
c19d1205
ZW
10508 as_bad_where (fixP->fx_file, fixP->fx_line,
10509 _("offset out of range"));
10510 break;
b99bd4ef 10511 }
c19d1205
ZW
10512 newval &= ~0xff;
10513 newval |= value;
b99bd4ef
NC
10514 }
10515 else
b99bd4ef 10516 {
c19d1205
ZW
10517 /* Positive 12-bit or negative 8-bit offset. */
10518 int limit;
10519 if (value >= 0)
b99bd4ef 10520 {
c19d1205
ZW
10521 newval |= (1 << 23);
10522 limit = 0xfff;
10523 }
10524 else
10525 {
10526 value = -value;
10527 limit = 0xff;
10528 }
10529 if (value > limit)
10530 {
10531 as_bad_where (fixP->fx_file, fixP->fx_line,
10532 _("offset out of range"));
10533 break;
b99bd4ef 10534 }
c19d1205 10535 newval &= ~limit;
b99bd4ef 10536 }
b99bd4ef 10537
c19d1205
ZW
10538 newval |= value;
10539 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
10540 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
10541 break;
404ff6b5 10542
c19d1205
ZW
10543 case BFD_RELOC_ARM_SHIFT_IMM:
10544 newval = md_chars_to_number (buf, INSN_SIZE);
10545 if (((unsigned long) value) > 32
10546 || (value == 32
10547 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
10548 {
10549 as_bad_where (fixP->fx_file, fixP->fx_line,
10550 _("shift expression is too large"));
10551 break;
10552 }
404ff6b5 10553
c19d1205
ZW
10554 if (value == 0)
10555 /* Shifts of zero must be done as lsl. */
10556 newval &= ~0x60;
10557 else if (value == 32)
10558 value = 0;
10559 newval &= 0xfffff07f;
10560 newval |= (value & 0x1f) << 7;
10561 md_number_to_chars (buf, newval, INSN_SIZE);
10562 break;
404ff6b5 10563
c19d1205 10564 case BFD_RELOC_ARM_T32_IMMEDIATE:
92e90b6e 10565 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 10566 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
10567 /* We claim that this fixup has been processed here,
10568 even if in fact we generate an error because we do
10569 not have a reloc for it, so tc_gen_reloc will reject it. */
10570 fixP->fx_done = 1;
404ff6b5 10571
c19d1205
ZW
10572 if (fixP->fx_addsy
10573 && ! S_IS_DEFINED (fixP->fx_addsy))
10574 {
10575 as_bad_where (fixP->fx_file, fixP->fx_line,
10576 _("undefined symbol %s used as an immediate value"),
10577 S_GET_NAME (fixP->fx_addsy));
10578 break;
10579 }
404ff6b5 10580
c19d1205
ZW
10581 newval = md_chars_to_number (buf, THUMB_SIZE);
10582 newval <<= 16;
10583 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 10584
e9f89963
PB
10585 /* FUTURE: Implement analogue of negate_data_op for T32. */
10586 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
10587 newimm = encode_thumb32_immediate (value);
10588 else
92e90b6e 10589 {
e9f89963
PB
10590 /* 12 bit immediate for addw/subw. */
10591 if (value < 0)
10592 {
10593 value = -value;
10594 newval ^= 0x00a00000;
10595 }
92e90b6e
PB
10596 if (value > 0xfff)
10597 newimm = (unsigned int) FAIL;
10598 else
10599 newimm = value;
10600 }
cc8a6dd0 10601
c19d1205 10602 if (newimm == (unsigned int)FAIL)
3631a3c8 10603 {
c19d1205
ZW
10604 as_bad_where (fixP->fx_file, fixP->fx_line,
10605 _("invalid constant (%lx) after fixup"),
10606 (unsigned long) value);
10607 break;
3631a3c8
NC
10608 }
10609
c19d1205
ZW
10610 newval |= (newimm & 0x800) << 15;
10611 newval |= (newimm & 0x700) << 4;
10612 newval |= (newimm & 0x0ff);
cc8a6dd0 10613
c19d1205
ZW
10614 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
10615 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
10616 break;
a737bd4d 10617
c19d1205
ZW
10618 case BFD_RELOC_ARM_SMI:
10619 if (((unsigned long) value) > 0xffff)
10620 as_bad_where (fixP->fx_file, fixP->fx_line,
10621 _("invalid smi expression"));
2fc8bdac 10622 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
10623 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
10624 md_number_to_chars (buf, newval, INSN_SIZE);
10625 break;
a737bd4d 10626
c19d1205 10627 case BFD_RELOC_ARM_SWI:
adbaf948 10628 if (fixP->tc_fix_data != 0)
c19d1205
ZW
10629 {
10630 if (((unsigned long) value) > 0xff)
10631 as_bad_where (fixP->fx_file, fixP->fx_line,
10632 _("invalid swi expression"));
2fc8bdac 10633 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
10634 newval |= value;
10635 md_number_to_chars (buf, newval, THUMB_SIZE);
10636 }
10637 else
10638 {
10639 if (((unsigned long) value) > 0x00ffffff)
10640 as_bad_where (fixP->fx_file, fixP->fx_line,
10641 _("invalid swi expression"));
2fc8bdac 10642 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
10643 newval |= value;
10644 md_number_to_chars (buf, newval, INSN_SIZE);
10645 }
10646 break;
a737bd4d 10647
c19d1205
ZW
10648 case BFD_RELOC_ARM_MULTI:
10649 if (((unsigned long) value) > 0xffff)
10650 as_bad_where (fixP->fx_file, fixP->fx_line,
10651 _("invalid expression in load/store multiple"));
10652 newval = value | md_chars_to_number (buf, INSN_SIZE);
10653 md_number_to_chars (buf, newval, INSN_SIZE);
10654 break;
a737bd4d 10655
c19d1205 10656 case BFD_RELOC_ARM_PCREL_BRANCH:
c19d1205 10657#ifdef OBJ_ELF
2fc8bdac 10658 case BFD_RELOC_ARM_PLT32:
c19d1205 10659#endif
a737bd4d 10660
c19d1205 10661 /* We are going to store value (shifted right by two) in the
2fc8bdac
ZW
10662 instruction, in a 24 bit, signed field. Bits 0 and 1 must be
10663 clear, and bits 26 through 32 either all clear or all set. */
10664 if (value & 0x00000003)
c19d1205 10665 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
10666 _("misaligned branch destination"));
10667 if ((value & (offsetT)0xfe000000) != (offsetT)0
10668 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
10669 as_bad_where (fixP->fx_file, fixP->fx_line,
10670 _("branch out of range"));
a737bd4d 10671
2fc8bdac 10672 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10673 {
2fc8bdac
ZW
10674 newval = md_chars_to_number (buf, INSN_SIZE);
10675 newval |= (value >> 2) & 0x00ffffff;
10676 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 10677 }
c19d1205 10678 break;
a737bd4d 10679
c19d1205 10680 case BFD_RELOC_ARM_PCREL_BLX:
2fc8bdac
ZW
10681 /* BLX allows bit 1 to be set in the branch destination, since
10682 it targets a Thumb instruction which is only required to be
10683 aligned modulo 2. Other constraints are as for B/BL. */
10684 if (value & 0x00000001)
10685 as_bad_where (fixP->fx_file, fixP->fx_line,
10686 _("misaligned BLX destination"));
10687 if ((value & (offsetT)0xfe000000) != (offsetT)0
10688 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
10689 as_bad_where (fixP->fx_file, fixP->fx_line,
10690 _("branch out of range"));
a737bd4d 10691
2fc8bdac
ZW
10692 if (fixP->fx_done || !seg->use_rela_p)
10693 {
10694 offsetT hbit;
10695 hbit = (value >> 1) & 1;
10696 value = (value >> 2) & 0x00ffffff;
a737bd4d 10697
2fc8bdac
ZW
10698 newval = md_chars_to_number (buf, INSN_SIZE);
10699 newval |= value | hbit << 24;
10700 md_number_to_chars (buf, newval, INSN_SIZE);
10701 }
c19d1205 10702 break;
a737bd4d 10703
c19d1205 10704 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
10705 /* CZB can only branch forward. */
10706 if (value & ~0x7e)
10707 as_bad_where (fixP->fx_file, fixP->fx_line,
10708 _("branch out of range"));
a737bd4d 10709
2fc8bdac
ZW
10710 if (fixP->fx_done || !seg->use_rela_p)
10711 {
10712 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205 10713 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
10714 md_number_to_chars (buf, newval, THUMB_SIZE);
10715 }
c19d1205 10716 break;
a737bd4d 10717
c19d1205 10718 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
10719 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
10720 as_bad_where (fixP->fx_file, fixP->fx_line,
10721 _("branch out of range"));
a737bd4d 10722
2fc8bdac
ZW
10723 if (fixP->fx_done || !seg->use_rela_p)
10724 {
10725 newval = md_chars_to_number (buf, THUMB_SIZE);
10726 newval |= (value & 0x1ff) >> 1;
10727 md_number_to_chars (buf, newval, THUMB_SIZE);
10728 }
c19d1205 10729 break;
a737bd4d 10730
c19d1205 10731 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
10732 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
10733 as_bad_where (fixP->fx_file, fixP->fx_line,
10734 _("branch out of range"));
a737bd4d 10735
2fc8bdac
ZW
10736 if (fixP->fx_done || !seg->use_rela_p)
10737 {
10738 newval = md_chars_to_number (buf, THUMB_SIZE);
10739 newval |= (value & 0xfff) >> 1;
10740 md_number_to_chars (buf, newval, THUMB_SIZE);
10741 }
c19d1205 10742 break;
a737bd4d 10743
c19d1205 10744 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
10745 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
10746 as_bad_where (fixP->fx_file, fixP->fx_line,
10747 _("conditional branch out of range"));
404ff6b5 10748
2fc8bdac
ZW
10749 if (fixP->fx_done || !seg->use_rela_p)
10750 {
10751 offsetT newval2;
10752 addressT S, J1, J2, lo, hi;
404ff6b5 10753
2fc8bdac
ZW
10754 S = (value & 0x00100000) >> 20;
10755 J2 = (value & 0x00080000) >> 19;
10756 J1 = (value & 0x00040000) >> 18;
10757 hi = (value & 0x0003f000) >> 12;
10758 lo = (value & 0x00000ffe) >> 1;
6c43fab6 10759
2fc8bdac
ZW
10760 newval = md_chars_to_number (buf, THUMB_SIZE);
10761 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10762 newval |= (S << 10) | hi;
10763 newval2 |= (J1 << 13) | (J2 << 11) | lo;
10764 md_number_to_chars (buf, newval, THUMB_SIZE);
10765 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10766 }
c19d1205 10767 break;
6c43fab6 10768
c19d1205
ZW
10769 case BFD_RELOC_THUMB_PCREL_BLX:
10770 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
10771 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
10772 as_bad_where (fixP->fx_file, fixP->fx_line,
10773 _("branch out of range"));
404ff6b5 10774
2fc8bdac
ZW
10775 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
10776 /* For a BLX instruction, make sure that the relocation is rounded up
10777 to a word boundary. This follows the semantics of the instruction
10778 which specifies that bit 1 of the target address will come from bit
10779 1 of the base address. */
10780 value = (value + 1) & ~ 1;
404ff6b5 10781
2fc8bdac 10782 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10783 {
2fc8bdac
ZW
10784 offsetT newval2;
10785
10786 newval = md_chars_to_number (buf, THUMB_SIZE);
10787 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10788 newval |= (value & 0x7fffff) >> 12;
10789 newval2 |= (value & 0xfff) >> 1;
10790 md_number_to_chars (buf, newval, THUMB_SIZE);
10791 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 10792 }
c19d1205 10793 break;
404ff6b5 10794
c19d1205 10795 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
10796 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
10797 as_bad_where (fixP->fx_file, fixP->fx_line,
10798 _("branch out of range"));
6c43fab6 10799
2fc8bdac
ZW
10800 if (fixP->fx_done || !seg->use_rela_p)
10801 {
10802 offsetT newval2;
10803 addressT S, I1, I2, lo, hi;
6c43fab6 10804
2fc8bdac
ZW
10805 S = (value & 0x01000000) >> 24;
10806 I1 = (value & 0x00800000) >> 23;
10807 I2 = (value & 0x00400000) >> 22;
10808 hi = (value & 0x003ff000) >> 12;
10809 lo = (value & 0x00000ffe) >> 1;
6c43fab6 10810
2fc8bdac
ZW
10811 I1 = !(I1 ^ S);
10812 I2 = !(I2 ^ S);
a737bd4d 10813
2fc8bdac
ZW
10814 newval = md_chars_to_number (buf, THUMB_SIZE);
10815 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
10816 newval |= (S << 10) | hi;
10817 newval2 |= (I1 << 13) | (I2 << 11) | lo;
10818 md_number_to_chars (buf, newval, THUMB_SIZE);
10819 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
10820 }
10821 break;
a737bd4d 10822
2fc8bdac
ZW
10823 case BFD_RELOC_8:
10824 if (fixP->fx_done || !seg->use_rela_p)
10825 md_number_to_chars (buf, value, 1);
c19d1205 10826 break;
a737bd4d 10827
c19d1205 10828 case BFD_RELOC_16:
2fc8bdac 10829 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10830 md_number_to_chars (buf, value, 2);
c19d1205 10831 break;
a737bd4d 10832
c19d1205
ZW
10833#ifdef OBJ_ELF
10834 case BFD_RELOC_ARM_TLS_GD32:
10835 case BFD_RELOC_ARM_TLS_LE32:
10836 case BFD_RELOC_ARM_TLS_IE32:
10837 case BFD_RELOC_ARM_TLS_LDM32:
10838 case BFD_RELOC_ARM_TLS_LDO32:
10839 S_SET_THREAD_LOCAL (fixP->fx_addsy);
10840 /* fall through */
6c43fab6 10841
c19d1205
ZW
10842 case BFD_RELOC_ARM_GOT32:
10843 case BFD_RELOC_ARM_GOTOFF:
10844 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
10845 if (fixP->fx_done || !seg->use_rela_p)
10846 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
10847 break;
10848#endif
6c43fab6 10849
c19d1205
ZW
10850 case BFD_RELOC_RVA:
10851 case BFD_RELOC_32:
10852 case BFD_RELOC_ARM_TARGET1:
10853 case BFD_RELOC_ARM_ROSEGREL32:
10854 case BFD_RELOC_ARM_SBREL32:
10855 case BFD_RELOC_32_PCREL:
2fc8bdac 10856 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 10857 md_number_to_chars (buf, value, 4);
c19d1205 10858 break;
6c43fab6 10859
c19d1205
ZW
10860#ifdef OBJ_ELF
10861 case BFD_RELOC_ARM_PREL31:
2fc8bdac 10862 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
10863 {
10864 newval = md_chars_to_number (buf, 4) & 0x80000000;
10865 if ((value ^ (value >> 1)) & 0x40000000)
10866 {
10867 as_bad_where (fixP->fx_file, fixP->fx_line,
10868 _("rel31 relocation overflow"));
10869 }
10870 newval |= value & 0x7fffffff;
10871 md_number_to_chars (buf, newval, 4);
10872 }
10873 break;
c19d1205 10874#endif
a737bd4d 10875
c19d1205
ZW
10876 case BFD_RELOC_ARM_CP_OFF_IMM:
10877 if (value < -1023 || value > 1023 || (value & 3))
10878 as_bad_where (fixP->fx_file, fixP->fx_line,
10879 _("co-processor offset out of range"));
10880 cp_off_common:
10881 sign = value >= 0;
10882 if (value < 0)
10883 value = -value;
10884 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
10885 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
10886 if (value == 0)
10887 newval &= ~WRITE_BACK;
10888 md_number_to_chars (buf, newval, INSN_SIZE);
10889 break;
a737bd4d 10890
c19d1205
ZW
10891 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
10892 if (value < -255 || value > 255)
10893 as_bad_where (fixP->fx_file, fixP->fx_line,
10894 _("co-processor offset out of range"));
10895 goto cp_off_common;
6c43fab6 10896
c19d1205
ZW
10897 case BFD_RELOC_ARM_THUMB_OFFSET:
10898 newval = md_chars_to_number (buf, THUMB_SIZE);
10899 /* Exactly what ranges, and where the offset is inserted depends
10900 on the type of instruction, we can establish this from the
10901 top 4 bits. */
10902 switch (newval >> 12)
10903 {
10904 case 4: /* PC load. */
10905 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
10906 forced to zero for these loads; md_pcrel_from has already
10907 compensated for this. */
10908 if (value & 3)
10909 as_bad_where (fixP->fx_file, fixP->fx_line,
10910 _("invalid offset, target not word aligned (0x%08lX)"),
10911 (((unsigned int) fixP->fx_frag->fr_address
10912 + (unsigned int) fixP->fx_where) & ~3) + value);
a737bd4d 10913
c19d1205
ZW
10914 if (value & ~0x3fc)
10915 as_bad_where (fixP->fx_file, fixP->fx_line,
10916 _("invalid offset, value too big (0x%08lX)"),
10917 (long) value);
a737bd4d 10918
c19d1205
ZW
10919 newval |= value >> 2;
10920 break;
a737bd4d 10921
c19d1205
ZW
10922 case 9: /* SP load/store. */
10923 if (value & ~0x3fc)
10924 as_bad_where (fixP->fx_file, fixP->fx_line,
10925 _("invalid offset, value too big (0x%08lX)"),
10926 (long) value);
10927 newval |= value >> 2;
10928 break;
6c43fab6 10929
c19d1205
ZW
10930 case 6: /* Word load/store. */
10931 if (value & ~0x7c)
10932 as_bad_where (fixP->fx_file, fixP->fx_line,
10933 _("invalid offset, value too big (0x%08lX)"),
10934 (long) value);
10935 newval |= value << 4; /* 6 - 2. */
10936 break;
a737bd4d 10937
c19d1205
ZW
10938 case 7: /* Byte load/store. */
10939 if (value & ~0x1f)
10940 as_bad_where (fixP->fx_file, fixP->fx_line,
10941 _("invalid offset, value too big (0x%08lX)"),
10942 (long) value);
10943 newval |= value << 6;
10944 break;
a737bd4d 10945
c19d1205
ZW
10946 case 8: /* Halfword load/store. */
10947 if (value & ~0x3e)
10948 as_bad_where (fixP->fx_file, fixP->fx_line,
10949 _("invalid offset, value too big (0x%08lX)"),
10950 (long) value);
10951 newval |= value << 5; /* 6 - 1. */
10952 break;
a737bd4d 10953
c19d1205
ZW
10954 default:
10955 as_bad_where (fixP->fx_file, fixP->fx_line,
10956 "Unable to process relocation for thumb opcode: %lx",
10957 (unsigned long) newval);
10958 break;
10959 }
10960 md_number_to_chars (buf, newval, THUMB_SIZE);
10961 break;
a737bd4d 10962
c19d1205
ZW
10963 case BFD_RELOC_ARM_THUMB_ADD:
10964 /* This is a complicated relocation, since we use it for all of
10965 the following immediate relocations:
a737bd4d 10966
c19d1205
ZW
10967 3bit ADD/SUB
10968 8bit ADD/SUB
10969 9bit ADD/SUB SP word-aligned
10970 10bit ADD PC/SP word-aligned
a737bd4d 10971
c19d1205
ZW
10972 The type of instruction being processed is encoded in the
10973 instruction field:
a737bd4d 10974
c19d1205
ZW
10975 0x8000 SUB
10976 0x00F0 Rd
10977 0x000F Rs
10978 */
10979 newval = md_chars_to_number (buf, THUMB_SIZE);
10980 {
10981 int rd = (newval >> 4) & 0xf;
10982 int rs = newval & 0xf;
10983 int subtract = !!(newval & 0x8000);
a737bd4d 10984
c19d1205
ZW
10985 /* Check for HI regs, only very restricted cases allowed:
10986 Adjusting SP, and using PC or SP to get an address. */
10987 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
10988 || (rs > 7 && rs != REG_SP && rs != REG_PC))
10989 as_bad_where (fixP->fx_file, fixP->fx_line,
10990 _("invalid Hi register with immediate"));
a737bd4d 10991
c19d1205
ZW
10992 /* If value is negative, choose the opposite instruction. */
10993 if (value < 0)
10994 {
10995 value = -value;
10996 subtract = !subtract;
10997 if (value < 0)
10998 as_bad_where (fixP->fx_file, fixP->fx_line,
10999 _("immediate value out of range"));
11000 }
a737bd4d 11001
c19d1205
ZW
11002 if (rd == REG_SP)
11003 {
11004 if (value & ~0x1fc)
11005 as_bad_where (fixP->fx_file, fixP->fx_line,
11006 _("invalid immediate for stack address calculation"));
11007 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11008 newval |= value >> 2;
11009 }
11010 else if (rs == REG_PC || rs == REG_SP)
11011 {
11012 if (subtract || value & ~0x3fc)
11013 as_bad_where (fixP->fx_file, fixP->fx_line,
11014 _("invalid immediate for address calculation (value = 0x%08lX)"),
11015 (unsigned long) value);
11016 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11017 newval |= rd << 8;
11018 newval |= value >> 2;
11019 }
11020 else if (rs == rd)
11021 {
11022 if (value & ~0xff)
11023 as_bad_where (fixP->fx_file, fixP->fx_line,
11024 _("immediate value out of range"));
11025 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11026 newval |= (rd << 8) | value;
11027 }
11028 else
11029 {
11030 if (value & ~0x7)
11031 as_bad_where (fixP->fx_file, fixP->fx_line,
11032 _("immediate value out of range"));
11033 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11034 newval |= rd | (rs << 3) | (value << 6);
11035 }
11036 }
11037 md_number_to_chars (buf, newval, THUMB_SIZE);
11038 break;
a737bd4d 11039
c19d1205
ZW
11040 case BFD_RELOC_ARM_THUMB_IMM:
11041 newval = md_chars_to_number (buf, THUMB_SIZE);
11042 if (value < 0 || value > 255)
11043 as_bad_where (fixP->fx_file, fixP->fx_line,
11044 _("invalid immediate: %ld is too large"),
11045 (long) value);
11046 newval |= value;
11047 md_number_to_chars (buf, newval, THUMB_SIZE);
11048 break;
a737bd4d 11049
c19d1205
ZW
11050 case BFD_RELOC_ARM_THUMB_SHIFT:
11051 /* 5bit shift value (0..32). LSL cannot take 32. */
11052 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11053 temp = newval & 0xf800;
11054 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11055 as_bad_where (fixP->fx_file, fixP->fx_line,
11056 _("invalid shift value: %ld"), (long) value);
11057 /* Shifts of zero must be encoded as LSL. */
11058 if (value == 0)
11059 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11060 /* Shifts of 32 are encoded as zero. */
11061 else if (value == 32)
11062 value = 0;
11063 newval |= value << 6;
11064 md_number_to_chars (buf, newval, THUMB_SIZE);
11065 break;
a737bd4d 11066
c19d1205
ZW
11067 case BFD_RELOC_VTABLE_INHERIT:
11068 case BFD_RELOC_VTABLE_ENTRY:
11069 fixP->fx_done = 0;
11070 return;
6c43fab6 11071
c19d1205
ZW
11072 case BFD_RELOC_UNUSED:
11073 default:
11074 as_bad_where (fixP->fx_file, fixP->fx_line,
11075 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11076 }
6c43fab6
RE
11077}
11078
c19d1205
ZW
11079/* Translate internal representation of relocation info to BFD target
11080 format. */
a737bd4d 11081
c19d1205
ZW
11082arelent *
11083tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11084 fixS * fixp)
a737bd4d 11085{
c19d1205
ZW
11086 arelent * reloc;
11087 bfd_reloc_code_real_type code;
a737bd4d 11088
c19d1205 11089 reloc = xmalloc (sizeof (arelent));
a737bd4d 11090
c19d1205
ZW
11091 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11092 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11093 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 11094
2fc8bdac
ZW
11095 if (fixp->fx_pcrel)
11096 fixp->fx_offset = reloc->address;
c19d1205 11097 reloc->addend = fixp->fx_offset;
a737bd4d 11098
c19d1205 11099 switch (fixp->fx_r_type)
a737bd4d 11100 {
c19d1205
ZW
11101 case BFD_RELOC_8:
11102 if (fixp->fx_pcrel)
11103 {
11104 code = BFD_RELOC_8_PCREL;
11105 break;
11106 }
a737bd4d 11107
c19d1205
ZW
11108 case BFD_RELOC_16:
11109 if (fixp->fx_pcrel)
11110 {
11111 code = BFD_RELOC_16_PCREL;
11112 break;
11113 }
6c43fab6 11114
c19d1205
ZW
11115 case BFD_RELOC_32:
11116 if (fixp->fx_pcrel)
11117 {
11118 code = BFD_RELOC_32_PCREL;
11119 break;
11120 }
a737bd4d 11121
c19d1205
ZW
11122 case BFD_RELOC_NONE:
11123 case BFD_RELOC_ARM_PCREL_BRANCH:
11124 case BFD_RELOC_ARM_PCREL_BLX:
11125 case BFD_RELOC_RVA:
11126 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11127 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11128 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11129 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11130 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11131 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11132 case BFD_RELOC_THUMB_PCREL_BLX:
11133 case BFD_RELOC_VTABLE_ENTRY:
11134 case BFD_RELOC_VTABLE_INHERIT:
11135 code = fixp->fx_r_type;
11136 break;
a737bd4d 11137
c19d1205
ZW
11138 case BFD_RELOC_ARM_LITERAL:
11139 case BFD_RELOC_ARM_HWLITERAL:
11140 /* If this is called then the a literal has
11141 been referenced across a section boundary. */
11142 as_bad_where (fixp->fx_file, fixp->fx_line,
11143 _("literal referenced across section boundary"));
11144 return NULL;
a737bd4d 11145
c19d1205
ZW
11146#ifdef OBJ_ELF
11147 case BFD_RELOC_ARM_GOT32:
11148 case BFD_RELOC_ARM_GOTOFF:
11149 case BFD_RELOC_ARM_PLT32:
11150 case BFD_RELOC_ARM_TARGET1:
11151 case BFD_RELOC_ARM_ROSEGREL32:
11152 case BFD_RELOC_ARM_SBREL32:
11153 case BFD_RELOC_ARM_PREL31:
11154 case BFD_RELOC_ARM_TARGET2:
11155 case BFD_RELOC_ARM_TLS_LE32:
11156 case BFD_RELOC_ARM_TLS_LDO32:
11157 code = fixp->fx_r_type;
11158 break;
a737bd4d 11159
c19d1205
ZW
11160 case BFD_RELOC_ARM_TLS_GD32:
11161 case BFD_RELOC_ARM_TLS_IE32:
11162 case BFD_RELOC_ARM_TLS_LDM32:
11163 /* BFD will include the symbol's address in the addend.
11164 But we don't want that, so subtract it out again here. */
11165 if (!S_IS_COMMON (fixp->fx_addsy))
11166 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11167 code = fixp->fx_r_type;
11168 break;
11169#endif
a737bd4d 11170
c19d1205
ZW
11171 case BFD_RELOC_ARM_IMMEDIATE:
11172 as_bad_where (fixp->fx_file, fixp->fx_line,
11173 _("internal relocation (type: IMMEDIATE) not fixed up"));
11174 return NULL;
a737bd4d 11175
c19d1205
ZW
11176 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11177 as_bad_where (fixp->fx_file, fixp->fx_line,
11178 _("ADRL used for a symbol not defined in the same file"));
11179 return NULL;
a737bd4d 11180
c19d1205
ZW
11181 case BFD_RELOC_ARM_OFFSET_IMM:
11182 if (fixp->fx_addsy != NULL
11183 && !S_IS_DEFINED (fixp->fx_addsy)
11184 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 11185 {
c19d1205
ZW
11186 as_bad_where (fixp->fx_file, fixp->fx_line,
11187 _("undefined local label `%s'"),
11188 S_GET_NAME (fixp->fx_addsy));
11189 return NULL;
a737bd4d
NC
11190 }
11191
c19d1205
ZW
11192 as_bad_where (fixp->fx_file, fixp->fx_line,
11193 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11194 return NULL;
a737bd4d 11195
c19d1205
ZW
11196 default:
11197 {
11198 char * type;
6c43fab6 11199
c19d1205
ZW
11200 switch (fixp->fx_r_type)
11201 {
11202 case BFD_RELOC_NONE: type = "NONE"; break;
11203 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
11204 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
11205 case BFD_RELOC_ARM_SMI: type = "SMI"; break;
11206 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
11207 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
11208 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
11209 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
11210 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
11211 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
11212 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
11213 default: type = _("<unknown>"); break;
11214 }
11215 as_bad_where (fixp->fx_file, fixp->fx_line,
11216 _("cannot represent %s relocation in this object file format"),
11217 type);
11218 return NULL;
11219 }
a737bd4d 11220 }
6c43fab6 11221
c19d1205
ZW
11222#ifdef OBJ_ELF
11223 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
11224 && GOT_symbol
11225 && fixp->fx_addsy == GOT_symbol)
11226 {
11227 code = BFD_RELOC_ARM_GOTPC;
11228 reloc->addend = fixp->fx_offset = reloc->address;
11229 }
11230#endif
6c43fab6 11231
c19d1205 11232 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 11233
c19d1205
ZW
11234 if (reloc->howto == NULL)
11235 {
11236 as_bad_where (fixp->fx_file, fixp->fx_line,
11237 _("cannot represent %s relocation in this object file format"),
11238 bfd_get_reloc_code_name (code));
11239 return NULL;
11240 }
6c43fab6 11241
c19d1205
ZW
11242 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
11243 vtable entry to be used in the relocation's section offset. */
11244 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11245 reloc->address = fixp->fx_offset;
6c43fab6 11246
c19d1205 11247 return reloc;
6c43fab6
RE
11248}
11249
c19d1205 11250/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 11251
c19d1205
ZW
11252void
11253cons_fix_new_arm (fragS * frag,
11254 int where,
11255 int size,
11256 expressionS * exp)
6c43fab6 11257{
c19d1205
ZW
11258 bfd_reloc_code_real_type type;
11259 int pcrel = 0;
6c43fab6 11260
c19d1205
ZW
11261 /* Pick a reloc.
11262 FIXME: @@ Should look at CPU word size. */
11263 switch (size)
11264 {
11265 case 1:
11266 type = BFD_RELOC_8;
11267 break;
11268 case 2:
11269 type = BFD_RELOC_16;
11270 break;
11271 case 4:
11272 default:
11273 type = BFD_RELOC_32;
11274 break;
11275 case 8:
11276 type = BFD_RELOC_64;
11277 break;
11278 }
6c43fab6 11279
c19d1205
ZW
11280 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
11281}
6c43fab6 11282
c19d1205
ZW
11283#if defined OBJ_COFF || defined OBJ_ELF
11284void
11285arm_validate_fix (fixS * fixP)
6c43fab6 11286{
c19d1205
ZW
11287 /* If the destination of the branch is a defined symbol which does not have
11288 the THUMB_FUNC attribute, then we must be calling a function which has
11289 the (interfacearm) attribute. We look for the Thumb entry point to that
11290 function and change the branch to refer to that function instead. */
11291 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
11292 && fixP->fx_addsy != NULL
11293 && S_IS_DEFINED (fixP->fx_addsy)
11294 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 11295 {
c19d1205 11296 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 11297 }
c19d1205
ZW
11298}
11299#endif
6c43fab6 11300
c19d1205
ZW
11301int
11302arm_force_relocation (struct fix * fixp)
11303{
11304#if defined (OBJ_COFF) && defined (TE_PE)
11305 if (fixp->fx_r_type == BFD_RELOC_RVA)
11306 return 1;
11307#endif
6c43fab6 11308
c19d1205
ZW
11309 /* Resolve these relocations even if the symbol is extern or weak. */
11310 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
11311 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
11312 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11313 return 0;
a737bd4d 11314
c19d1205 11315 return generic_force_reloc (fixp);
404ff6b5
AH
11316}
11317
c19d1205
ZW
11318#ifdef OBJ_COFF
11319/* This is a little hack to help the gas/arm/adrl.s test. It prevents
11320 local labels from being added to the output symbol table when they
11321 are used with the ADRL pseudo op. The ADRL relocation should always
11322 be resolved before the binbary is emitted, so it is safe to say that
11323 it is adjustable. */
404ff6b5 11324
c19d1205
ZW
11325bfd_boolean
11326arm_fix_adjustable (fixS * fixP)
404ff6b5 11327{
c19d1205
ZW
11328 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
11329 return 1;
11330 return 0;
404ff6b5 11331}
c19d1205 11332#endif
404ff6b5 11333
c19d1205
ZW
11334#ifdef OBJ_ELF
11335/* Relocations against Thumb function names must be left unadjusted,
11336 so that the linker can use this information to correctly set the
11337 bottom bit of their addresses. The MIPS version of this function
11338 also prevents relocations that are mips-16 specific, but I do not
11339 know why it does this.
404ff6b5 11340
c19d1205
ZW
11341 FIXME:
11342 There is one other problem that ought to be addressed here, but
11343 which currently is not: Taking the address of a label (rather
11344 than a function) and then later jumping to that address. Such
11345 addresses also ought to have their bottom bit set (assuming that
11346 they reside in Thumb code), but at the moment they will not. */
404ff6b5 11347
c19d1205
ZW
11348bfd_boolean
11349arm_fix_adjustable (fixS * fixP)
404ff6b5 11350{
c19d1205
ZW
11351 if (fixP->fx_addsy == NULL)
11352 return 1;
404ff6b5 11353
c19d1205
ZW
11354 if (THUMB_IS_FUNC (fixP->fx_addsy)
11355 && fixP->fx_subsy == NULL)
11356 return 0;
a737bd4d 11357
c19d1205
ZW
11358 /* We need the symbol name for the VTABLE entries. */
11359 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
11360 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
11361 return 0;
404ff6b5 11362
c19d1205
ZW
11363 /* Don't allow symbols to be discarded on GOT related relocs. */
11364 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
11365 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
11366 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
11367 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
11368 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
11369 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
11370 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
11371 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
11372 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
11373 return 0;
a737bd4d 11374
c19d1205 11375 return 1;
a737bd4d 11376}
404ff6b5 11377
c19d1205
ZW
11378const char *
11379elf32_arm_target_format (void)
404ff6b5 11380{
c19d1205
ZW
11381#ifdef TE_SYMBIAN
11382 return (target_big_endian
11383 ? "elf32-bigarm-symbian"
11384 : "elf32-littlearm-symbian");
11385#elif defined (TE_VXWORKS)
11386 return (target_big_endian
11387 ? "elf32-bigarm-vxworks"
11388 : "elf32-littlearm-vxworks");
11389#else
11390 if (target_big_endian)
11391 return "elf32-bigarm";
11392 else
11393 return "elf32-littlearm";
11394#endif
404ff6b5
AH
11395}
11396
c19d1205
ZW
11397void
11398armelf_frob_symbol (symbolS * symp,
11399 int * puntp)
404ff6b5 11400{
c19d1205
ZW
11401 elf_frob_symbol (symp, puntp);
11402}
11403#endif
404ff6b5 11404
c19d1205 11405/* MD interface: Finalization. */
a737bd4d 11406
c19d1205
ZW
11407/* A good place to do this, although this was probably not intended
11408 for this kind of use. We need to dump the literal pool before
11409 references are made to a null symbol pointer. */
a737bd4d 11410
c19d1205
ZW
11411void
11412arm_cleanup (void)
11413{
11414 literal_pool * pool;
a737bd4d 11415
c19d1205
ZW
11416 for (pool = list_of_pools; pool; pool = pool->next)
11417 {
11418 /* Put it at the end of the relevent section. */
11419 subseg_set (pool->section, pool->sub_section);
11420#ifdef OBJ_ELF
11421 arm_elf_change_section ();
11422#endif
11423 s_ltorg (0);
11424 }
404ff6b5
AH
11425}
11426
c19d1205
ZW
11427/* Adjust the symbol table. This marks Thumb symbols as distinct from
11428 ARM ones. */
404ff6b5 11429
c19d1205
ZW
11430void
11431arm_adjust_symtab (void)
404ff6b5 11432{
c19d1205
ZW
11433#ifdef OBJ_COFF
11434 symbolS * sym;
404ff6b5 11435
c19d1205
ZW
11436 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
11437 {
11438 if (ARM_IS_THUMB (sym))
11439 {
11440 if (THUMB_IS_FUNC (sym))
11441 {
11442 /* Mark the symbol as a Thumb function. */
11443 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
11444 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
11445 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 11446
c19d1205
ZW
11447 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
11448 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
11449 else
11450 as_bad (_("%s: unexpected function type: %d"),
11451 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
11452 }
11453 else switch (S_GET_STORAGE_CLASS (sym))
11454 {
11455 case C_EXT:
11456 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
11457 break;
11458 case C_STAT:
11459 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
11460 break;
11461 case C_LABEL:
11462 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
11463 break;
11464 default:
11465 /* Do nothing. */
11466 break;
11467 }
11468 }
a737bd4d 11469
c19d1205
ZW
11470 if (ARM_IS_INTERWORK (sym))
11471 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 11472 }
c19d1205
ZW
11473#endif
11474#ifdef OBJ_ELF
11475 symbolS * sym;
11476 char bind;
404ff6b5 11477
c19d1205 11478 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 11479 {
c19d1205
ZW
11480 if (ARM_IS_THUMB (sym))
11481 {
11482 elf_symbol_type * elf_sym;
404ff6b5 11483
c19d1205
ZW
11484 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
11485 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 11486
c19d1205
ZW
11487 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
11488 {
11489 /* If it's a .thumb_func, declare it as so,
11490 otherwise tag label as .code 16. */
11491 if (THUMB_IS_FUNC (sym))
11492 elf_sym->internal_elf_sym.st_info =
11493 ELF_ST_INFO (bind, STT_ARM_TFUNC);
11494 else
11495 elf_sym->internal_elf_sym.st_info =
11496 ELF_ST_INFO (bind, STT_ARM_16BIT);
11497 }
11498 }
11499 }
11500#endif
404ff6b5
AH
11501}
11502
c19d1205 11503/* MD interface: Initialization. */
404ff6b5 11504
a737bd4d 11505static void
c19d1205 11506set_constant_flonums (void)
a737bd4d 11507{
c19d1205 11508 int i;
404ff6b5 11509
c19d1205
ZW
11510 for (i = 0; i < NUM_FLOAT_VALS; i++)
11511 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
11512 abort ();
a737bd4d 11513}
404ff6b5 11514
c19d1205
ZW
11515void
11516md_begin (void)
a737bd4d 11517{
c19d1205
ZW
11518 unsigned mach;
11519 unsigned int i;
404ff6b5 11520
c19d1205
ZW
11521 if ( (arm_ops_hsh = hash_new ()) == NULL
11522 || (arm_cond_hsh = hash_new ()) == NULL
11523 || (arm_shift_hsh = hash_new ()) == NULL
11524 || (arm_psr_hsh = hash_new ()) == NULL
11525 || (arm_reg_hsh = hash_new ()) == NULL
11526 || (arm_reloc_hsh = hash_new ()) == NULL)
11527 as_fatal (_("virtual memory exhausted"));
11528
11529 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
11530 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
11531 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
11532 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
11533 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
11534 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
11535 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
11536 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
11537 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
11538 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
11539#ifdef OBJ_ELF
11540 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
11541 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
11542#endif
11543
11544 set_constant_flonums ();
404ff6b5 11545
c19d1205
ZW
11546 /* Set the cpu variant based on the command-line options. We prefer
11547 -mcpu= over -march= if both are set (as for GCC); and we prefer
11548 -mfpu= over any other way of setting the floating point unit.
11549 Use of legacy options with new options are faulted. */
11550 if (legacy_cpu != -1)
404ff6b5 11551 {
c19d1205
ZW
11552 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
11553 as_bad (_("use of old and new-style options to set CPU type"));
11554
11555 mcpu_cpu_opt = legacy_cpu;
404ff6b5 11556 }
c19d1205
ZW
11557 else if (mcpu_cpu_opt == -1)
11558 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 11559
c19d1205
ZW
11560 if (legacy_fpu != -1)
11561 {
11562 if (mfpu_opt != -1)
11563 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
11564
11565 mfpu_opt = legacy_fpu;
11566 }
11567 else if (mfpu_opt == -1)
11568 {
c19d1205 11569#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
11570 /* Some environments specify a default FPU. If they don't, infer it
11571 from the processor. */
03b1477f
RE
11572 if (mcpu_fpu_opt != -1)
11573 mfpu_opt = mcpu_fpu_opt;
11574 else
11575 mfpu_opt = march_fpu_opt;
39c2da32
RE
11576#else
11577 mfpu_opt = FPU_DEFAULT;
11578#endif
03b1477f
RE
11579 }
11580
11581 if (mfpu_opt == -1)
11582 {
11583 if (mcpu_cpu_opt == -1)
11584 mfpu_opt = FPU_DEFAULT;
11585 else if (mcpu_cpu_opt & ARM_EXT_V5)
11586 mfpu_opt = FPU_ARCH_VFP_V2;
11587 else
11588 mfpu_opt = FPU_ARCH_FPA;
11589 }
11590
11591 if (mcpu_cpu_opt == -1)
11592 mcpu_cpu_opt = CPU_DEFAULT;
11593
11594 cpu_variant = mcpu_cpu_opt | mfpu_opt;
11595
f17c130b 11596#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 11597 {
7cc69913
NC
11598 unsigned int flags = 0;
11599
11600#if defined OBJ_ELF
11601 flags = meabi_flags;
d507cf36
PB
11602
11603 switch (meabi_flags)
33a392fb 11604 {
d507cf36 11605 case EF_ARM_EABI_UNKNOWN:
7cc69913 11606#endif
d507cf36
PB
11607 /* Set the flags in the private structure. */
11608 if (uses_apcs_26) flags |= F_APCS26;
11609 if (support_interwork) flags |= F_INTERWORK;
11610 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 11611 if (pic_code) flags |= F_PIC;
d507cf36
PB
11612 if ((cpu_variant & FPU_ANY) == FPU_NONE
11613 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
7cc69913
NC
11614 flags |= F_SOFT_FLOAT;
11615
d507cf36
PB
11616 switch (mfloat_abi_opt)
11617 {
11618 case ARM_FLOAT_ABI_SOFT:
11619 case ARM_FLOAT_ABI_SOFTFP:
11620 flags |= F_SOFT_FLOAT;
11621 break;
33a392fb 11622
d507cf36
PB
11623 case ARM_FLOAT_ABI_HARD:
11624 if (flags & F_SOFT_FLOAT)
11625 as_bad (_("hard-float conflicts with specified fpu"));
11626 break;
11627 }
03b1477f 11628
c19d1205 11629 /* Using VFP conventions (even if soft-float). */
7cc69913
NC
11630 if (cpu_variant & FPU_VFP_EXT_NONE)
11631 flags |= F_VFP_FLOAT;
f17c130b 11632
fde78edd 11633#if defined OBJ_ELF
d507cf36
PB
11634 if (cpu_variant & FPU_ARCH_MAVERICK)
11635 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
11636 break;
11637
8cb51566 11638 case EF_ARM_EABI_VER4:
c19d1205 11639 /* No additional flags to set. */
d507cf36
PB
11640 break;
11641
11642 default:
11643 abort ();
11644 }
7cc69913 11645#endif
b99bd4ef
NC
11646 bfd_set_private_flags (stdoutput, flags);
11647
11648 /* We have run out flags in the COFF header to encode the
11649 status of ATPCS support, so instead we create a dummy,
c19d1205 11650 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
11651 if (atpcs)
11652 {
11653 asection * sec;
11654
11655 sec = bfd_make_section (stdoutput, ".arm.atpcs");
11656
11657 if (sec != NULL)
11658 {
11659 bfd_set_section_flags
11660 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
11661 bfd_set_section_size (stdoutput, sec, 0);
11662 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
11663 }
11664 }
7cc69913 11665 }
f17c130b 11666#endif
b99bd4ef
NC
11667
11668 /* Record the CPU type as well. */
11669 switch (cpu_variant & ARM_CPU_MASK)
11670 {
11671 case ARM_2:
11672 mach = bfd_mach_arm_2;
11673 break;
11674
c19d1205 11675 case ARM_3: /* Also ARM_250. */
b99bd4ef
NC
11676 mach = bfd_mach_arm_2a;
11677 break;
11678
c19d1205 11679 case ARM_6: /* Also ARM_7. */
b89dddec
RE
11680 mach = bfd_mach_arm_3;
11681 break;
11682
b99bd4ef 11683 default:
5a6c6817 11684 mach = bfd_mach_arm_unknown;
b99bd4ef 11685 break;
b99bd4ef
NC
11686 }
11687
11688 /* Catch special cases. */
e16bb312
NC
11689 if (cpu_variant & ARM_CEXT_IWMMXT)
11690 mach = bfd_mach_arm_iWMMXt;
11691 else if (cpu_variant & ARM_CEXT_XSCALE)
b99bd4ef 11692 mach = bfd_mach_arm_XScale;
fde78edd
NC
11693 else if (cpu_variant & ARM_CEXT_MAVERICK)
11694 mach = bfd_mach_arm_ep9312;
b99bd4ef
NC
11695 else if (cpu_variant & ARM_EXT_V5E)
11696 mach = bfd_mach_arm_5TE;
11697 else if (cpu_variant & ARM_EXT_V5)
11698 {
b89dddec 11699 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11700 mach = bfd_mach_arm_5T;
11701 else
11702 mach = bfd_mach_arm_5;
11703 }
b89dddec 11704 else if (cpu_variant & ARM_EXT_V4)
b99bd4ef 11705 {
b89dddec 11706 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
11707 mach = bfd_mach_arm_4T;
11708 else
11709 mach = bfd_mach_arm_4;
11710 }
b89dddec 11711 else if (cpu_variant & ARM_EXT_V3M)
b99bd4ef
NC
11712 mach = bfd_mach_arm_3M;
11713
11714 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
11715}
11716
c19d1205 11717/* Command line processing. */
b99bd4ef 11718
c19d1205
ZW
11719/* md_parse_option
11720 Invocation line includes a switch not recognized by the base assembler.
11721 See if it's a processor-specific option.
b99bd4ef 11722
c19d1205
ZW
11723 This routine is somewhat complicated by the need for backwards
11724 compatibility (since older releases of gcc can't be changed).
11725 The new options try to make the interface as compatible as
11726 possible with GCC.
b99bd4ef 11727
c19d1205 11728 New options (supported) are:
b99bd4ef 11729
c19d1205
ZW
11730 -mcpu=<cpu name> Assemble for selected processor
11731 -march=<architecture name> Assemble for selected architecture
11732 -mfpu=<fpu architecture> Assemble for selected FPU.
11733 -EB/-mbig-endian Big-endian
11734 -EL/-mlittle-endian Little-endian
11735 -k Generate PIC code
11736 -mthumb Start in Thumb mode
11737 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 11738
c19d1205 11739 For now we will also provide support for:
b99bd4ef 11740
c19d1205
ZW
11741 -mapcs-32 32-bit Program counter
11742 -mapcs-26 26-bit Program counter
11743 -macps-float Floats passed in FP registers
11744 -mapcs-reentrant Reentrant code
11745 -matpcs
11746 (sometime these will probably be replaced with -mapcs=<list of options>
11747 and -matpcs=<list of options>)
b99bd4ef 11748
c19d1205
ZW
11749 The remaining options are only supported for back-wards compatibility.
11750 Cpu variants, the arm part is optional:
11751 -m[arm]1 Currently not supported.
11752 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
11753 -m[arm]3 Arm 3 processor
11754 -m[arm]6[xx], Arm 6 processors
11755 -m[arm]7[xx][t][[d]m] Arm 7 processors
11756 -m[arm]8[10] Arm 8 processors
11757 -m[arm]9[20][tdmi] Arm 9 processors
11758 -mstrongarm[110[0]] StrongARM processors
11759 -mxscale XScale processors
11760 -m[arm]v[2345[t[e]]] Arm architectures
11761 -mall All (except the ARM1)
11762 FP variants:
11763 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
11764 -mfpe-old (No float load/store multiples)
11765 -mvfpxd VFP Single precision
11766 -mvfp All VFP
11767 -mno-fpu Disable all floating point instructions
b99bd4ef 11768
c19d1205
ZW
11769 The following CPU names are recognized:
11770 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
11771 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
11772 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
11773 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
11774 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
11775 arm10t arm10e, arm1020t, arm1020e, arm10200e,
11776 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 11777
c19d1205 11778 */
b99bd4ef 11779
c19d1205 11780const char * md_shortopts = "m:k";
b99bd4ef 11781
c19d1205
ZW
11782#ifdef ARM_BI_ENDIAN
11783#define OPTION_EB (OPTION_MD_BASE + 0)
11784#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 11785#else
c19d1205
ZW
11786#if TARGET_BYTES_BIG_ENDIAN
11787#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 11788#else
c19d1205
ZW
11789#define OPTION_EL (OPTION_MD_BASE + 1)
11790#endif
b99bd4ef 11791#endif
b99bd4ef 11792
c19d1205 11793struct option md_longopts[] =
b99bd4ef 11794{
c19d1205
ZW
11795#ifdef OPTION_EB
11796 {"EB", no_argument, NULL, OPTION_EB},
11797#endif
11798#ifdef OPTION_EL
11799 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 11800#endif
c19d1205
ZW
11801 {NULL, no_argument, NULL, 0}
11802};
b99bd4ef 11803
c19d1205 11804size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 11805
c19d1205 11806struct arm_option_table
b99bd4ef 11807{
c19d1205
ZW
11808 char *option; /* Option name to match. */
11809 char *help; /* Help information. */
11810 int *var; /* Variable to change. */
11811 int value; /* What to change it to. */
11812 char *deprecated; /* If non-null, print this message. */
11813};
b99bd4ef 11814
c19d1205
ZW
11815struct arm_option_table arm_opts[] =
11816{
11817 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
11818 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
11819 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
11820 &support_interwork, 1, NULL},
11821 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
11822 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
11823 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
11824 1, NULL},
11825 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
11826 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
11827 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
11828 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
11829 NULL},
b99bd4ef 11830
c19d1205
ZW
11831 /* These are recognized by the assembler, but have no affect on code. */
11832 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
11833 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
b99bd4ef 11834
c19d1205
ZW
11835 /* DON'T add any new processors to this list -- we want the whole list
11836 to go away... Add them to the processors table instead. */
11837 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11838 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
11839 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11840 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
11841 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11842 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
11843 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11844 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
11845 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11846 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
11847 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11848 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
11849 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11850 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
11851 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11852 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
11853 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11854 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
11855 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11856 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
11857 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11858 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
11859 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11860 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
11861 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11862 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
11863 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11864 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
11865 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11866 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
11867 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11868 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
11869 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11870 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
11871 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11872 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
11873 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11874 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
11875 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11876 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
11877 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11878 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
11879 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11880 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
11881 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11882 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
11883 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11884 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11885 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11886 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
11887 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11888 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
11889 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11890 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
11891 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11892 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
11893 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11894 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
11895 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11896 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
11897 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11898 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
11899 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11900 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
11901 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11902 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
11903 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11904 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
11905 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
11906 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
11907 N_("use -mcpu=strongarm110")},
11908 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
11909 N_("use -mcpu=strongarm1100")},
11910 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
11911 N_("use -mcpu=strongarm1110")},
11912 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
11913 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
11914 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 11915
c19d1205
ZW
11916 /* Architecture variants -- don't add any more to this list either. */
11917 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11918 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
11919 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11920 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
11921 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11922 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
11923 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11924 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
11925 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11926 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
11927 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11928 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
11929 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11930 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
11931 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11932 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
11933 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
11934 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 11935
c19d1205
ZW
11936 /* Floating point variants -- don't add any more to this list either. */
11937 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
11938 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
11939 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
11940 {"mno-fpu", NULL, &legacy_fpu, 0,
11941 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 11942
c19d1205
ZW
11943 {NULL, NULL, NULL, 0, NULL}
11944};
7ed4c4c5 11945
c19d1205 11946struct arm_cpu_option_table
7ed4c4c5 11947{
c19d1205
ZW
11948 char *name;
11949 int value;
11950 /* For some CPUs we assume an FPU unless the user explicitly sets
11951 -mfpu=... */
11952 int default_fpu;
11953};
7ed4c4c5 11954
c19d1205
ZW
11955/* This list should, at a minimum, contain all the cpu names
11956 recognized by GCC. */
11957static struct arm_cpu_option_table arm_cpus[] =
11958{
11959 {"all", ARM_ANY, FPU_ARCH_FPA},
11960 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA},
11961 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA},
11962 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA},
11963 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA},
11964 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA},
11965 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA},
11966 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA},
11967 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA},
11968 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA},
11969 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA},
11970 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA},
11971 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA},
11972 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA},
11973 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA},
11974 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA},
11975 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA},
11976 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA},
11977 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA},
11978 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA},
11979 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA},
11980 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA},
11981 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA},
11982 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA},
11983 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA},
11984 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA},
11985 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA},
11986 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA},
11987 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA},
11988 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
11989 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA},
11990 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA},
11991 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA},
11992 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA},
11993 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA},
11994 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA},
11995 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA},
11996 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA},
11997 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA},
11998 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA},
11999 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12000 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12001 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12002 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA},
12003 /* For V5 or later processors we default to using VFP; but the user
12004 should really set the FPU type explicitly. */
12005 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12006 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12007 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12008 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12009 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12010 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12011 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12012 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2},
12013 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12014 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12015 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12016 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12017 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1},
12018 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2},
12019 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12020 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2},
12021 {"arm1136js", ARM_ARCH_V6, FPU_NONE},
12022 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE},
12023 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12024 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2},
12025 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2},
12026 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE},
12027 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE},
12028 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2},
12029 /* ??? XSCALE is really an architecture. */
12030 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12031 /* ??? iwmmxt is not a processor. */
12032 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2},
12033 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2},
12034 /* Maverick */
12035 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK},
12036 {NULL, 0, 0}
12037};
7ed4c4c5 12038
c19d1205 12039struct arm_arch_option_table
7ed4c4c5 12040{
c19d1205
ZW
12041 char *name;
12042 int value;
12043 int default_fpu;
12044};
7ed4c4c5 12045
c19d1205
ZW
12046/* This list should, at a minimum, contain all the architecture names
12047 recognized by GCC. */
12048static struct arm_arch_option_table arm_archs[] =
12049{
12050 {"all", ARM_ANY, FPU_ARCH_FPA},
12051 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12052 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12053 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12054 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12055 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12056 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12057 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12058 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12059 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12060 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12061 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12062 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12063 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12064 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12065 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12066 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12067 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12068 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12069 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12070 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12071 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12072 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12073 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12074 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12075 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12076 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12077 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12078 {NULL, 0, 0}
12079};
7ed4c4c5 12080
c19d1205
ZW
12081/* ISA extensions in the co-processor space. */
12082struct arm_option_value_table
12083{
12084 char *name;
12085 int value;
12086};
7ed4c4c5 12087
c19d1205
ZW
12088static struct arm_option_value_table arm_extensions[] =
12089{
12090 {"maverick", ARM_CEXT_MAVERICK},
12091 {"xscale", ARM_CEXT_XSCALE},
12092 {"iwmmxt", ARM_CEXT_IWMMXT},
12093 {NULL, 0}
12094};
7ed4c4c5 12095
c19d1205
ZW
12096/* This list should, at a minimum, contain all the fpu names
12097 recognized by GCC. */
12098static struct arm_option_value_table arm_fpus[] =
12099{
12100 {"softfpa", FPU_NONE},
12101 {"fpe", FPU_ARCH_FPE},
12102 {"fpe2", FPU_ARCH_FPE},
12103 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12104 {"fpa", FPU_ARCH_FPA},
12105 {"fpa10", FPU_ARCH_FPA},
12106 {"fpa11", FPU_ARCH_FPA},
12107 {"arm7500fe", FPU_ARCH_FPA},
12108 {"softvfp", FPU_ARCH_VFP},
12109 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12110 {"vfp", FPU_ARCH_VFP_V2},
12111 {"vfp9", FPU_ARCH_VFP_V2},
12112 {"vfp10", FPU_ARCH_VFP_V2},
12113 {"vfp10-r0", FPU_ARCH_VFP_V1},
12114 {"vfpxd", FPU_ARCH_VFP_V1xD},
12115 {"arm1020t", FPU_ARCH_VFP_V1},
12116 {"arm1020e", FPU_ARCH_VFP_V2},
12117 {"arm1136jfs", FPU_ARCH_VFP_V2},
12118 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12119 {"maverick", FPU_ARCH_MAVERICK},
12120 {NULL, 0}
12121};
7ed4c4c5 12122
c19d1205
ZW
12123static struct arm_option_value_table arm_float_abis[] =
12124{
12125 {"hard", ARM_FLOAT_ABI_HARD},
12126 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12127 {"soft", ARM_FLOAT_ABI_SOFT},
12128 {NULL, 0}
12129};
7ed4c4c5 12130
c19d1205
ZW
12131#ifdef OBJ_ELF
12132/* We only know how to output GNU and ver 4 (AAELF) formats. */
12133static struct arm_option_value_table arm_eabis[] =
12134{
12135 {"gnu", EF_ARM_EABI_UNKNOWN},
12136 {"4", EF_ARM_EABI_VER4},
12137 {NULL, 0}
12138};
12139#endif
7ed4c4c5 12140
c19d1205
ZW
12141struct arm_long_option_table
12142{
12143 char * option; /* Substring to match. */
12144 char * help; /* Help information. */
12145 int (* func) (char * subopt); /* Function to decode sub-option. */
12146 char * deprecated; /* If non-null, print this message. */
12147};
7ed4c4c5
NC
12148
12149static int
c19d1205 12150arm_parse_extension (char * str, int * opt_p)
7ed4c4c5 12151{
c19d1205 12152 while (str != NULL && *str != 0)
7ed4c4c5 12153 {
c19d1205
ZW
12154 struct arm_option_value_table * opt;
12155 char * ext;
12156 int optlen;
7ed4c4c5 12157
c19d1205
ZW
12158 if (*str != '+')
12159 {
12160 as_bad (_("invalid architectural extension"));
12161 return 0;
12162 }
7ed4c4c5 12163
c19d1205
ZW
12164 str++;
12165 ext = strchr (str, '+');
7ed4c4c5 12166
c19d1205
ZW
12167 if (ext != NULL)
12168 optlen = ext - str;
12169 else
12170 optlen = strlen (str);
7ed4c4c5 12171
c19d1205
ZW
12172 if (optlen == 0)
12173 {
12174 as_bad (_("missing architectural extension"));
12175 return 0;
12176 }
7ed4c4c5 12177
c19d1205
ZW
12178 for (opt = arm_extensions; opt->name != NULL; opt++)
12179 if (strncmp (opt->name, str, optlen) == 0)
12180 {
12181 *opt_p |= opt->value;
12182 break;
12183 }
7ed4c4c5 12184
c19d1205
ZW
12185 if (opt->name == NULL)
12186 {
12187 as_bad (_("unknown architectural extnsion `%s'"), str);
12188 return 0;
12189 }
7ed4c4c5 12190
c19d1205
ZW
12191 str = ext;
12192 };
7ed4c4c5 12193
c19d1205
ZW
12194 return 1;
12195}
7ed4c4c5 12196
c19d1205
ZW
12197static int
12198arm_parse_cpu (char * str)
7ed4c4c5 12199{
c19d1205
ZW
12200 struct arm_cpu_option_table * opt;
12201 char * ext = strchr (str, '+');
12202 int optlen;
7ed4c4c5 12203
c19d1205
ZW
12204 if (ext != NULL)
12205 optlen = ext - str;
7ed4c4c5 12206 else
c19d1205 12207 optlen = strlen (str);
7ed4c4c5 12208
c19d1205 12209 if (optlen == 0)
7ed4c4c5 12210 {
c19d1205
ZW
12211 as_bad (_("missing cpu name `%s'"), str);
12212 return 0;
7ed4c4c5
NC
12213 }
12214
c19d1205
ZW
12215 for (opt = arm_cpus; opt->name != NULL; opt++)
12216 if (strncmp (opt->name, str, optlen) == 0)
12217 {
12218 mcpu_cpu_opt = opt->value;
12219 mcpu_fpu_opt = opt->default_fpu;
7ed4c4c5 12220
c19d1205
ZW
12221 if (ext != NULL)
12222 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 12223
c19d1205
ZW
12224 return 1;
12225 }
7ed4c4c5 12226
c19d1205
ZW
12227 as_bad (_("unknown cpu `%s'"), str);
12228 return 0;
7ed4c4c5
NC
12229}
12230
c19d1205
ZW
12231static int
12232arm_parse_arch (char * str)
7ed4c4c5 12233{
c19d1205
ZW
12234 struct arm_arch_option_table *opt;
12235 char *ext = strchr (str, '+');
12236 int optlen;
7ed4c4c5 12237
c19d1205
ZW
12238 if (ext != NULL)
12239 optlen = ext - str;
7ed4c4c5 12240 else
c19d1205 12241 optlen = strlen (str);
7ed4c4c5 12242
c19d1205 12243 if (optlen == 0)
7ed4c4c5 12244 {
c19d1205
ZW
12245 as_bad (_("missing architecture name `%s'"), str);
12246 return 0;
7ed4c4c5
NC
12247 }
12248
7ed4c4c5 12249
c19d1205
ZW
12250 for (opt = arm_archs; opt->name != NULL; opt++)
12251 if (streq (opt->name, str))
12252 {
12253 march_cpu_opt = opt->value;
12254 march_fpu_opt = opt->default_fpu;
7ed4c4c5 12255
c19d1205
ZW
12256 if (ext != NULL)
12257 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 12258
c19d1205
ZW
12259 return 1;
12260 }
12261
12262 as_bad (_("unknown architecture `%s'\n"), str);
12263 return 0;
7ed4c4c5 12264}
eb043451 12265
c19d1205
ZW
12266static int
12267arm_parse_fpu (char * str)
12268{
12269 struct arm_option_value_table * opt;
b99bd4ef 12270
c19d1205
ZW
12271 for (opt = arm_fpus; opt->name != NULL; opt++)
12272 if (streq (opt->name, str))
12273 {
12274 mfpu_opt = opt->value;
12275 return 1;
12276 }
b99bd4ef 12277
c19d1205
ZW
12278 as_bad (_("unknown floating point format `%s'\n"), str);
12279 return 0;
12280}
12281
12282static int
12283arm_parse_float_abi (char * str)
b99bd4ef 12284{
c19d1205 12285 struct arm_option_value_table * opt;
b99bd4ef 12286
c19d1205
ZW
12287 for (opt = arm_float_abis; opt->name != NULL; opt++)
12288 if (streq (opt->name, str))
12289 {
12290 mfloat_abi_opt = opt->value;
12291 return 1;
12292 }
cc8a6dd0 12293
c19d1205
ZW
12294 as_bad (_("unknown floating point abi `%s'\n"), str);
12295 return 0;
12296}
b99bd4ef 12297
c19d1205
ZW
12298#ifdef OBJ_ELF
12299static int
12300arm_parse_eabi (char * str)
12301{
12302 struct arm_option_value_table *opt;
cc8a6dd0 12303
c19d1205
ZW
12304 for (opt = arm_eabis; opt->name != NULL; opt++)
12305 if (streq (opt->name, str))
12306 {
12307 meabi_flags = opt->value;
12308 return 1;
12309 }
12310 as_bad (_("unknown EABI `%s'\n"), str);
12311 return 0;
12312}
12313#endif
cc8a6dd0 12314
c19d1205
ZW
12315struct arm_long_option_table arm_long_opts[] =
12316{
12317 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
12318 arm_parse_cpu, NULL},
12319 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
12320 arm_parse_arch, NULL},
12321 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
12322 arm_parse_fpu, NULL},
12323 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
12324 arm_parse_float_abi, NULL},
12325#ifdef OBJ_ELF
12326 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
12327 arm_parse_eabi, NULL},
12328#endif
12329 {NULL, NULL, 0, NULL}
12330};
cc8a6dd0 12331
c19d1205
ZW
12332int
12333md_parse_option (int c, char * arg)
12334{
12335 struct arm_option_table *opt;
12336 struct arm_long_option_table *lopt;
b99bd4ef 12337
c19d1205 12338 switch (c)
b99bd4ef 12339 {
c19d1205
ZW
12340#ifdef OPTION_EB
12341 case OPTION_EB:
12342 target_big_endian = 1;
12343 break;
12344#endif
cc8a6dd0 12345
c19d1205
ZW
12346#ifdef OPTION_EL
12347 case OPTION_EL:
12348 target_big_endian = 0;
12349 break;
12350#endif
b99bd4ef 12351
c19d1205
ZW
12352 case 'a':
12353 /* Listing option. Just ignore these, we don't support additional
12354 ones. */
12355 return 0;
b99bd4ef 12356
c19d1205
ZW
12357 default:
12358 for (opt = arm_opts; opt->option != NULL; opt++)
12359 {
12360 if (c == opt->option[0]
12361 && ((arg == NULL && opt->option[1] == 0)
12362 || streq (arg, opt->option + 1)))
12363 {
12364#if WARN_DEPRECATED
12365 /* If the option is deprecated, tell the user. */
12366 if (opt->deprecated != NULL)
12367 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
12368 arg ? arg : "", _(opt->deprecated));
12369#endif
b99bd4ef 12370
c19d1205
ZW
12371 if (opt->var != NULL)
12372 *opt->var = opt->value;
cc8a6dd0 12373
c19d1205
ZW
12374 return 1;
12375 }
12376 }
b99bd4ef 12377
c19d1205
ZW
12378 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12379 {
12380 /* These options are expected to have an argument. */
12381 if (c == lopt->option[0]
12382 && arg != NULL
12383 && strncmp (arg, lopt->option + 1,
12384 strlen (lopt->option + 1)) == 0)
12385 {
12386#if WARN_DEPRECATED
12387 /* If the option is deprecated, tell the user. */
12388 if (lopt->deprecated != NULL)
12389 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
12390 _(lopt->deprecated));
12391#endif
b99bd4ef 12392
c19d1205
ZW
12393 /* Call the sup-option parser. */
12394 return lopt->func (arg + strlen (lopt->option) - 1);
12395 }
12396 }
a737bd4d 12397
c19d1205
ZW
12398 return 0;
12399 }
a394c00f 12400
c19d1205
ZW
12401 return 1;
12402}
a394c00f 12403
c19d1205
ZW
12404void
12405md_show_usage (FILE * fp)
a394c00f 12406{
c19d1205
ZW
12407 struct arm_option_table *opt;
12408 struct arm_long_option_table *lopt;
a394c00f 12409
c19d1205 12410 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 12411
c19d1205
ZW
12412 for (opt = arm_opts; opt->option != NULL; opt++)
12413 if (opt->help != NULL)
12414 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 12415
c19d1205
ZW
12416 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
12417 if (lopt->help != NULL)
12418 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 12419
c19d1205
ZW
12420#ifdef OPTION_EB
12421 fprintf (fp, _("\
12422 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
12423#endif
12424
c19d1205
ZW
12425#ifdef OPTION_EL
12426 fprintf (fp, _("\
12427 -EL assemble code for a little-endian cpu\n"));
a737bd4d 12428#endif
c19d1205 12429}