PR ld/1567
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b
AM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
b99bd4ef 28#include <string.h>
c19d1205 29#define NO_RELOC 0
b99bd4ef 30#include "as.h"
3882b010 31#include "safe-ctype.h"
b99bd4ef
NC
32
33/* Need TARGET_CPU. */
34#include "config.h"
35#include "subsegs.h"
36#include "obstack.h"
37#include "symbols.h"
38#include "listing.h"
39
f263249b
RE
40#include "opcode/arm.h"
41
b99bd4ef
NC
42#ifdef OBJ_ELF
43#include "elf/arm.h"
44#include "dwarf2dbg.h"
a394c00f 45#include "dw2gencfi.h"
b99bd4ef
NC
46#endif
47
7ed4c4c5 48/* XXX Set this to 1 after the next binutils release. */
03b1477f
RE
49#define WARN_DEPRECATED 0
50
7ed4c4c5
NC
51#ifdef OBJ_ELF
52/* Must be at least the size of the largest unwind opcode (currently two). */
53#define ARM_OPCODE_CHUNK_SIZE 8
54
55/* This structure holds the unwinding state. */
56
57static struct
58{
c19d1205
ZW
59 symbolS * proc_start;
60 symbolS * table_entry;
61 symbolS * personality_routine;
62 int personality_index;
7ed4c4c5 63 /* The segment containing the function. */
c19d1205
ZW
64 segT saved_seg;
65 subsegT saved_subseg;
7ed4c4c5
NC
66 /* Opcodes generated from this function. */
67 unsigned char * opcodes;
c19d1205
ZW
68 int opcode_count;
69 int opcode_alloc;
7ed4c4c5 70 /* The number of bytes pushed to the stack. */
c19d1205 71 offsetT frame_size;
7ed4c4c5
NC
72 /* We don't add stack adjustment opcodes immediately so that we can merge
73 multiple adjustments. We can also omit the final adjustment
74 when using a frame pointer. */
c19d1205 75 offsetT pending_offset;
7ed4c4c5 76 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
77 hold the reg+offset to use when restoring sp from a frame pointer. */
78 offsetT fp_offset;
79 int fp_reg;
7ed4c4c5 80 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 81 unsigned fp_used:1;
7ed4c4c5 82 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 83 unsigned sp_restored:1;
7ed4c4c5
NC
84} unwind;
85
84798bd6
JB
86/* Bit N indicates that an R_ARM_NONE relocation has been output for
87 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
88 emitted only once per section, to save unnecessary bloat. */
89static unsigned int marked_pr_dependency = 0;
90
7ed4c4c5
NC
91#endif /* OBJ_ELF */
92
33a392fb
PB
93enum arm_float_abi
94{
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98};
99
c19d1205 100/* Types of processor to assemble for. */
b89dddec
RE
101#define ARM_1 ARM_ARCH_V1
102#define ARM_2 ARM_ARCH_V2
103#define ARM_3 ARM_ARCH_V2S
104#define ARM_250 ARM_ARCH_V2S
105#define ARM_6 ARM_ARCH_V3
106#define ARM_7 ARM_ARCH_V3
107#define ARM_8 ARM_ARCH_V4
108#define ARM_9 ARM_ARCH_V4T
109#define ARM_STRONG ARM_ARCH_V4
c19d1205 110#define ARM_CPU_MASK 0x0000000f /* XXX? */
b99bd4ef
NC
111
112#ifndef CPU_DEFAULT
113#if defined __XSCALE__
b89dddec 114#define CPU_DEFAULT (ARM_ARCH_XSCALE)
b99bd4ef
NC
115#else
116#if defined __thumb__
c19d1205 117#define CPU_DEFAULT (ARM_ARCH_V5T)
b99bd4ef
NC
118#endif
119#endif
120#endif
121
122#ifndef FPU_DEFAULT
c820d418
MM
123# ifdef TE_LINUX
124# define FPU_DEFAULT FPU_ARCH_FPA
125# elif defined (TE_NetBSD)
126# ifdef OBJ_ELF
127# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
128# else
129 /* Legacy a.out format. */
130# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
131# endif
4e7fd91e
PB
132# elif defined (TE_VXWORKS)
133# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
134# else
135 /* For backwards compatibility, default to FPA. */
136# define FPU_DEFAULT FPU_ARCH_FPA
137# endif
138#endif /* ifndef FPU_DEFAULT */
b99bd4ef 139
c19d1205 140#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 141
03b1477f 142static unsigned long cpu_variant;
ee065d83
PB
143static unsigned long arm_arch_used;
144static unsigned long thumb_arch_used;
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;
ee065d83
PB
165/* Record user cpu selection for object attributes.
166 Zero if no default or user specified CPU. */
167static int selected_cpu = -1;
168/* Must be long enough to hold any of the names in arm_cpus. */
169static char selected_cpu_name[16];
7cc69913 170#ifdef OBJ_ELF
deeaaff8
DJ
171# ifdef EABI_DEFAULT
172static int meabi_flags = EABI_DEFAULT;
173# else
d507cf36 174static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 175# endif
7cc69913 176#endif
b99bd4ef 177
b99bd4ef 178#ifdef OBJ_ELF
c19d1205 179/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
180symbolS * GOT_symbol;
181#endif
182
b99bd4ef
NC
183/* 0: assemble for ARM,
184 1: assemble for Thumb,
185 2: assemble for Thumb even though target CPU does not support thumb
186 instructions. */
187static int thumb_mode = 0;
188
c19d1205
ZW
189/* If unified_syntax is true, we are processing the new unified
190 ARM/Thumb syntax. Important differences from the old ARM mode:
191
192 - Immediate operands do not require a # prefix.
193 - Conditional affixes always appear at the end of the
194 instruction. (For backward compatibility, those instructions
195 that formerly had them in the middle, continue to accept them
196 there.)
197 - The IT instruction may appear, and if it does is validated
198 against subsequent conditional affixes. It does not generate
199 machine code.
200
201 Important differences from the old Thumb mode:
202
203 - Immediate operands do not require a # prefix.
204 - Most of the V6T2 instructions are only available in unified mode.
205 - The .N and .W suffixes are recognized and honored (it is an error
206 if they cannot be honored).
207 - All instructions set the flags if and only if they have an 's' affix.
208 - Conditional affixes may be used. They are validated against
209 preceding IT instructions. Unlike ARM mode, you cannot use a
210 conditional affix except in the scope of an IT instruction. */
211
212static bfd_boolean unified_syntax = FALSE;
b99bd4ef
NC
213
214struct arm_it
215{
c19d1205 216 const char * error;
b99bd4ef 217 unsigned long instruction;
c19d1205
ZW
218 int size;
219 int size_req;
220 int cond;
0110f2b8
PB
221 /* Set to the opcode if the instruction needs relaxation.
222 Zero if the instruction is not relaxed. */
223 unsigned long relax;
b99bd4ef
NC
224 struct
225 {
226 bfd_reloc_code_real_type type;
c19d1205
ZW
227 expressionS exp;
228 int pc_rel;
b99bd4ef 229 } reloc;
b99bd4ef 230
c19d1205
ZW
231 struct
232 {
233 unsigned reg;
ca3f61f7
NC
234 signed int imm;
235 unsigned present : 1; /* Operand present. */
236 unsigned isreg : 1; /* Operand was a register. */
237 unsigned immisreg : 1; /* .imm field is a second register. */
238 unsigned hasreloc : 1; /* Operand has relocation suffix. */
239 unsigned writeback : 1; /* Operand has trailing ! */
240 unsigned preind : 1; /* Preindexed address. */
241 unsigned postind : 1; /* Postindexed address. */
242 unsigned negative : 1; /* Index register was negated. */
243 unsigned shifted : 1; /* Shift applied to operation. */
244 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 245 } operands[6];
b99bd4ef
NC
246};
247
c19d1205 248static struct arm_it inst;
b99bd4ef
NC
249
250#define NUM_FLOAT_VALS 8
251
05d2d07e 252const char * fp_const[] =
b99bd4ef
NC
253{
254 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
255};
256
c19d1205 257/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
258#define MAX_LITTLENUMS 6
259
260LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
261
262#define FAIL (-1)
263#define SUCCESS (0)
264
265#define SUFF_S 1
266#define SUFF_D 2
267#define SUFF_E 3
268#define SUFF_P 4
269
c19d1205
ZW
270#define CP_T_X 0x00008000
271#define CP_T_Y 0x00400000
b99bd4ef 272
c19d1205
ZW
273#define CONDS_BIT 0x00100000
274#define LOAD_BIT 0x00100000
b99bd4ef
NC
275
276#define DOUBLE_LOAD_FLAG 0x00000001
277
278struct asm_cond
279{
c19d1205 280 const char * template;
b99bd4ef
NC
281 unsigned long value;
282};
283
c19d1205 284#define COND_ALWAYS 0xE
b99bd4ef 285
b99bd4ef
NC
286struct asm_psr
287{
b34976b6 288 const char *template;
b99bd4ef
NC
289 unsigned long field;
290};
291
2d2255b5 292/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
293#define SPSR_BIT (1 << 22)
294
c19d1205
ZW
295/* The individual PSR flag bits. */
296#define PSR_c (1 << 16)
297#define PSR_x (1 << 17)
298#define PSR_s (1 << 18)
299#define PSR_f (1 << 19)
b99bd4ef 300
c19d1205 301struct reloc_entry
bfae80f2 302{
c19d1205
ZW
303 char *name;
304 bfd_reloc_code_real_type reloc;
bfae80f2
RE
305};
306
307enum vfp_sp_reg_pos
308{
309 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
310};
311
312enum vfp_ldstm_type
313{
314 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
315};
316
c19d1205
ZW
317/* ARM register categories. This includes coprocessor numbers and various
318 architecture extensions' registers. */
319enum arm_reg_type
bfae80f2 320{
c19d1205
ZW
321 REG_TYPE_RN,
322 REG_TYPE_CP,
323 REG_TYPE_CN,
324 REG_TYPE_FN,
325 REG_TYPE_VFS,
326 REG_TYPE_VFD,
327 REG_TYPE_VFC,
328 REG_TYPE_MVF,
329 REG_TYPE_MVD,
330 REG_TYPE_MVFX,
331 REG_TYPE_MVDX,
332 REG_TYPE_MVAX,
333 REG_TYPE_DSPSC,
334 REG_TYPE_MMXWR,
335 REG_TYPE_MMXWC,
336 REG_TYPE_MMXWCG,
337 REG_TYPE_XSCALE,
bfae80f2
RE
338};
339
6c43fab6
RE
340/* Structure for a hash table entry for a register. */
341struct reg_entry
342{
c19d1205
ZW
343 const char *name;
344 unsigned char number;
345 unsigned char type;
346 unsigned char builtin;
6c43fab6
RE
347};
348
c19d1205
ZW
349/* Diagnostics used when we don't get a register of the expected type. */
350const char *const reg_expected_msgs[] =
351{
352 N_("ARM register expected"),
353 N_("bad or missing co-processor number"),
354 N_("co-processor register expected"),
355 N_("FPA register expected"),
356 N_("VFP single precision register expected"),
357 N_("VFP double precision register expected"),
358 N_("VFP system register expected"),
359 N_("Maverick MVF register expected"),
360 N_("Maverick MVD register expected"),
361 N_("Maverick MVFX register expected"),
362 N_("Maverick MVDX register expected"),
363 N_("Maverick MVAX register expected"),
364 N_("Maverick DSPSC register expected"),
365 N_("iWMMXt data register expected"),
366 N_("iWMMXt control register expected"),
367 N_("iWMMXt scalar register expected"),
368 N_("XScale accumulator register expected"),
6c43fab6
RE
369};
370
c19d1205
ZW
371/* Some well known registers that we refer to directly elsewhere. */
372#define REG_SP 13
373#define REG_LR 14
374#define REG_PC 15
404ff6b5 375
b99bd4ef
NC
376/* ARM instructions take 4bytes in the object file, Thumb instructions
377 take 2: */
c19d1205 378#define INSN_SIZE 4
b99bd4ef
NC
379
380struct asm_opcode
381{
382 /* Basic string to match. */
c19d1205
ZW
383 const char *template;
384
385 /* Parameters to instruction. */
386 unsigned char operands[8];
387
388 /* Conditional tag - see opcode_lookup. */
389 unsigned int tag : 4;
b99bd4ef
NC
390
391 /* Basic instruction code. */
c19d1205 392 unsigned int avalue : 28;
b99bd4ef 393
c19d1205
ZW
394 /* Thumb-format instruction code. */
395 unsigned int tvalue;
b99bd4ef 396
90e4755a 397 /* Which architecture variant provides this instruction. */
c19d1205
ZW
398 unsigned long avariant;
399 unsigned long tvariant;
400
401 /* Function to call to encode instruction in ARM format. */
402 void (* aencode) (void);
b99bd4ef 403
c19d1205
ZW
404 /* Function to call to encode instruction in Thumb format. */
405 void (* tencode) (void);
b99bd4ef
NC
406};
407
a737bd4d
NC
408/* Defines for various bits that we will want to toggle. */
409#define INST_IMMEDIATE 0x02000000
410#define OFFSET_REG 0x02000000
c19d1205 411#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
412#define SHIFT_BY_REG 0x00000010
413#define PRE_INDEX 0x01000000
414#define INDEX_UP 0x00800000
415#define WRITE_BACK 0x00200000
416#define LDM_TYPE_2_OR_3 0x00400000
90e4755a 417
a737bd4d
NC
418#define LITERAL_MASK 0xf000f000
419#define OPCODE_MASK 0xfe1fffff
420#define V4_STR_BIT 0x00000020
90e4755a 421
a737bd4d 422#define DATA_OP_SHIFT 21
90e4755a 423
a737bd4d
NC
424/* Codes to distinguish the arithmetic instructions. */
425#define OPCODE_AND 0
426#define OPCODE_EOR 1
427#define OPCODE_SUB 2
428#define OPCODE_RSB 3
429#define OPCODE_ADD 4
430#define OPCODE_ADC 5
431#define OPCODE_SBC 6
432#define OPCODE_RSC 7
433#define OPCODE_TST 8
434#define OPCODE_TEQ 9
435#define OPCODE_CMP 10
436#define OPCODE_CMN 11
437#define OPCODE_ORR 12
438#define OPCODE_MOV 13
439#define OPCODE_BIC 14
440#define OPCODE_MVN 15
90e4755a 441
a737bd4d
NC
442#define T_OPCODE_MUL 0x4340
443#define T_OPCODE_TST 0x4200
444#define T_OPCODE_CMN 0x42c0
445#define T_OPCODE_NEG 0x4240
446#define T_OPCODE_MVN 0x43c0
90e4755a 447
a737bd4d
NC
448#define T_OPCODE_ADD_R3 0x1800
449#define T_OPCODE_SUB_R3 0x1a00
450#define T_OPCODE_ADD_HI 0x4400
451#define T_OPCODE_ADD_ST 0xb000
452#define T_OPCODE_SUB_ST 0xb080
453#define T_OPCODE_ADD_SP 0xa800
454#define T_OPCODE_ADD_PC 0xa000
455#define T_OPCODE_ADD_I8 0x3000
456#define T_OPCODE_SUB_I8 0x3800
457#define T_OPCODE_ADD_I3 0x1c00
458#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 459
a737bd4d
NC
460#define T_OPCODE_ASR_R 0x4100
461#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
462#define T_OPCODE_LSR_R 0x40c0
463#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
464#define T_OPCODE_ASR_I 0x1000
465#define T_OPCODE_LSL_I 0x0000
466#define T_OPCODE_LSR_I 0x0800
b99bd4ef 467
a737bd4d
NC
468#define T_OPCODE_MOV_I8 0x2000
469#define T_OPCODE_CMP_I8 0x2800
470#define T_OPCODE_CMP_LR 0x4280
471#define T_OPCODE_MOV_HR 0x4600
472#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 473
a737bd4d
NC
474#define T_OPCODE_LDR_PC 0x4800
475#define T_OPCODE_LDR_SP 0x9800
476#define T_OPCODE_STR_SP 0x9000
477#define T_OPCODE_LDR_IW 0x6800
478#define T_OPCODE_STR_IW 0x6000
479#define T_OPCODE_LDR_IH 0x8800
480#define T_OPCODE_STR_IH 0x8000
481#define T_OPCODE_LDR_IB 0x7800
482#define T_OPCODE_STR_IB 0x7000
483#define T_OPCODE_LDR_RW 0x5800
484#define T_OPCODE_STR_RW 0x5000
485#define T_OPCODE_LDR_RH 0x5a00
486#define T_OPCODE_STR_RH 0x5200
487#define T_OPCODE_LDR_RB 0x5c00
488#define T_OPCODE_STR_RB 0x5400
c9b604bd 489
a737bd4d
NC
490#define T_OPCODE_PUSH 0xb400
491#define T_OPCODE_POP 0xbc00
b99bd4ef 492
2fc8bdac 493#define T_OPCODE_BRANCH 0xe000
b99bd4ef 494
a737bd4d 495#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 496#define THUMB_PP_PC_LR 0x0100
c19d1205
ZW
497#define THUMB_LOAD_BIT 0x0800
498
499#define BAD_ARGS _("bad arguments to instruction")
500#define BAD_PC _("r15 not allowed here")
501#define BAD_COND _("instruction cannot be conditional")
502#define BAD_OVERLAP _("registers may not be the same")
503#define BAD_HIREG _("lo register required")
504#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
505
506static struct hash_control *arm_ops_hsh;
507static struct hash_control *arm_cond_hsh;
508static struct hash_control *arm_shift_hsh;
509static struct hash_control *arm_psr_hsh;
510static struct hash_control *arm_reg_hsh;
511static struct hash_control *arm_reloc_hsh;
b99bd4ef 512
b99bd4ef
NC
513/* Stuff needed to resolve the label ambiguity
514 As:
515 ...
516 label: <insn>
517 may differ from:
518 ...
519 label:
c19d1205 520 <insn>
b99bd4ef
NC
521*/
522
523symbolS * last_label_seen;
b34976b6 524static int label_is_thumb_function_name = FALSE;
a737bd4d 525\f
3d0c9500
NC
526/* Literal pool structure. Held on a per-section
527 and per-sub-section basis. */
a737bd4d 528
c19d1205 529#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 530typedef struct literal_pool
b99bd4ef 531{
c19d1205
ZW
532 expressionS literals [MAX_LITERAL_POOL_SIZE];
533 unsigned int next_free_entry;
534 unsigned int id;
535 symbolS * symbol;
536 segT section;
537 subsegT sub_section;
61b5f74b 538 struct literal_pool * next;
3d0c9500 539} literal_pool;
b99bd4ef 540
3d0c9500
NC
541/* Pointer to a linked list of literal pools. */
542literal_pool * list_of_pools = NULL;
e27ec89e
PB
543
544/* State variables for IT block handling. */
545static bfd_boolean current_it_mask = 0;
546static int current_cc;
547
c19d1205
ZW
548\f
549/* Pure syntax. */
b99bd4ef 550
c19d1205
ZW
551/* This array holds the chars that always start a comment. If the
552 pre-processor is disabled, these aren't very useful. */
553const char comment_chars[] = "@";
3d0c9500 554
c19d1205
ZW
555/* This array holds the chars that only start a comment at the beginning of
556 a line. If the line seems to have the form '# 123 filename'
557 .line and .file directives will appear in the pre-processed output. */
558/* Note that input_file.c hand checks for '#' at the beginning of the
559 first line of the input file. This is because the compiler outputs
560 #NO_APP at the beginning of its output. */
561/* Also note that comments like this one will always work. */
562const char line_comment_chars[] = "#";
3d0c9500 563
c19d1205 564const char line_separator_chars[] = ";";
b99bd4ef 565
c19d1205
ZW
566/* Chars that can be used to separate mant
567 from exp in floating point numbers. */
568const char EXP_CHARS[] = "eE";
3d0c9500 569
c19d1205
ZW
570/* Chars that mean this number is a floating point constant. */
571/* As in 0f12.456 */
572/* or 0d1.2345e12 */
b99bd4ef 573
c19d1205 574const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 575
c19d1205
ZW
576/* Prefix characters that indicate the start of an immediate
577 value. */
578#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 579
c19d1205
ZW
580/* Separator character handling. */
581
582#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
583
584static inline int
585skip_past_char (char ** str, char c)
586{
587 if (**str == c)
588 {
589 (*str)++;
590 return SUCCESS;
3d0c9500 591 }
c19d1205
ZW
592 else
593 return FAIL;
594}
595#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 596
c19d1205
ZW
597/* Arithmetic expressions (possibly involving symbols). */
598
599/* Return TRUE if anything in the expression is a bignum. */
600
601static int
602walk_no_bignums (symbolS * sp)
603{
604 if (symbol_get_value_expression (sp)->X_op == O_big)
605 return 1;
606
607 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 608 {
c19d1205
ZW
609 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
610 || (symbol_get_value_expression (sp)->X_op_symbol
611 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
612 }
613
c19d1205 614 return 0;
3d0c9500
NC
615}
616
c19d1205
ZW
617static int in_my_get_expression = 0;
618
619/* Third argument to my_get_expression. */
620#define GE_NO_PREFIX 0
621#define GE_IMM_PREFIX 1
622#define GE_OPT_PREFIX 2
a737bd4d 623
b99bd4ef 624static int
c19d1205 625my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 626{
c19d1205
ZW
627 char * save_in;
628 segT seg;
b99bd4ef 629
c19d1205
ZW
630 /* In unified syntax, all prefixes are optional. */
631 if (unified_syntax)
632 prefix_mode = GE_OPT_PREFIX;
b99bd4ef 633
c19d1205 634 switch (prefix_mode)
b99bd4ef 635 {
c19d1205
ZW
636 case GE_NO_PREFIX: break;
637 case GE_IMM_PREFIX:
638 if (!is_immediate_prefix (**str))
639 {
640 inst.error = _("immediate expression requires a # prefix");
641 return FAIL;
642 }
643 (*str)++;
644 break;
645 case GE_OPT_PREFIX:
646 if (is_immediate_prefix (**str))
647 (*str)++;
648 break;
649 default: abort ();
650 }
b99bd4ef 651
c19d1205 652 memset (ep, 0, sizeof (expressionS));
b99bd4ef 653
c19d1205
ZW
654 save_in = input_line_pointer;
655 input_line_pointer = *str;
656 in_my_get_expression = 1;
657 seg = expression (ep);
658 in_my_get_expression = 0;
659
660 if (ep->X_op == O_illegal)
b99bd4ef 661 {
c19d1205
ZW
662 /* We found a bad expression in md_operand(). */
663 *str = input_line_pointer;
664 input_line_pointer = save_in;
665 if (inst.error == NULL)
666 inst.error = _("bad expression");
667 return 1;
668 }
b99bd4ef 669
c19d1205
ZW
670#ifdef OBJ_AOUT
671 if (seg != absolute_section
672 && seg != text_section
673 && seg != data_section
674 && seg != bss_section
675 && seg != undefined_section)
676 {
677 inst.error = _("bad segment");
678 *str = input_line_pointer;
679 input_line_pointer = save_in;
680 return 1;
b99bd4ef 681 }
c19d1205 682#endif
b99bd4ef 683
c19d1205
ZW
684 /* Get rid of any bignums now, so that we don't generate an error for which
685 we can't establish a line number later on. Big numbers are never valid
686 in instructions, which is where this routine is always called. */
687 if (ep->X_op == O_big
688 || (ep->X_add_symbol
689 && (walk_no_bignums (ep->X_add_symbol)
690 || (ep->X_op_symbol
691 && walk_no_bignums (ep->X_op_symbol)))))
692 {
693 inst.error = _("invalid constant");
694 *str = input_line_pointer;
695 input_line_pointer = save_in;
696 return 1;
697 }
b99bd4ef 698
c19d1205
ZW
699 *str = input_line_pointer;
700 input_line_pointer = save_in;
701 return 0;
b99bd4ef
NC
702}
703
c19d1205
ZW
704/* Turn a string in input_line_pointer into a floating point constant
705 of type TYPE, and store the appropriate bytes in *LITP. The number
706 of LITTLENUMS emitted is stored in *SIZEP. An error message is
707 returned, or NULL on OK.
b99bd4ef 708
c19d1205
ZW
709 Note that fp constants aren't represent in the normal way on the ARM.
710 In big endian mode, things are as expected. However, in little endian
711 mode fp constants are big-endian word-wise, and little-endian byte-wise
712 within the words. For example, (double) 1.1 in big endian mode is
713 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
714 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 715
c19d1205 716 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 717
c19d1205
ZW
718char *
719md_atof (int type, char * litP, int * sizeP)
720{
721 int prec;
722 LITTLENUM_TYPE words[MAX_LITTLENUMS];
723 char *t;
724 int i;
b99bd4ef 725
c19d1205
ZW
726 switch (type)
727 {
728 case 'f':
729 case 'F':
730 case 's':
731 case 'S':
732 prec = 2;
733 break;
b99bd4ef 734
c19d1205
ZW
735 case 'd':
736 case 'D':
737 case 'r':
738 case 'R':
739 prec = 4;
740 break;
b99bd4ef 741
c19d1205
ZW
742 case 'x':
743 case 'X':
744 prec = 6;
745 break;
b99bd4ef 746
c19d1205
ZW
747 case 'p':
748 case 'P':
749 prec = 6;
750 break;
a737bd4d 751
c19d1205
ZW
752 default:
753 *sizeP = 0;
754 return _("bad call to MD_ATOF()");
755 }
b99bd4ef 756
c19d1205
ZW
757 t = atof_ieee (input_line_pointer, type, words);
758 if (t)
759 input_line_pointer = t;
760 *sizeP = prec * 2;
b99bd4ef 761
c19d1205
ZW
762 if (target_big_endian)
763 {
764 for (i = 0; i < prec; i++)
765 {
766 md_number_to_chars (litP, (valueT) words[i], 2);
767 litP += 2;
768 }
769 }
770 else
771 {
772 if (cpu_variant & FPU_ARCH_VFP)
773 for (i = prec - 1; i >= 0; i--)
774 {
775 md_number_to_chars (litP, (valueT) words[i], 2);
776 litP += 2;
777 }
778 else
779 /* For a 4 byte float the order of elements in `words' is 1 0.
780 For an 8 byte float the order is 1 0 3 2. */
781 for (i = 0; i < prec; i += 2)
782 {
783 md_number_to_chars (litP, (valueT) words[i + 1], 2);
784 md_number_to_chars (litP + 2, (valueT) words[i], 2);
785 litP += 4;
786 }
787 }
b99bd4ef 788
c19d1205
ZW
789 return 0;
790}
b99bd4ef 791
c19d1205
ZW
792/* We handle all bad expressions here, so that we can report the faulty
793 instruction in the error message. */
794void
795md_operand (expressionS * expr)
796{
797 if (in_my_get_expression)
798 expr->X_op = O_illegal;
b99bd4ef
NC
799}
800
c19d1205 801/* Immediate values. */
b99bd4ef 802
c19d1205
ZW
803/* Generic immediate-value read function for use in directives.
804 Accepts anything that 'expression' can fold to a constant.
805 *val receives the number. */
806#ifdef OBJ_ELF
807static int
808immediate_for_directive (int *val)
b99bd4ef 809{
c19d1205
ZW
810 expressionS exp;
811 exp.X_op = O_illegal;
b99bd4ef 812
c19d1205
ZW
813 if (is_immediate_prefix (*input_line_pointer))
814 {
815 input_line_pointer++;
816 expression (&exp);
817 }
b99bd4ef 818
c19d1205
ZW
819 if (exp.X_op != O_constant)
820 {
821 as_bad (_("expected #constant"));
822 ignore_rest_of_line ();
823 return FAIL;
824 }
825 *val = exp.X_add_number;
826 return SUCCESS;
b99bd4ef 827}
c19d1205 828#endif
b99bd4ef 829
c19d1205 830/* Register parsing. */
b99bd4ef 831
c19d1205
ZW
832/* Generic register parser. CCP points to what should be the
833 beginning of a register name. If it is indeed a valid register
834 name, advance CCP over it and return the reg_entry structure;
835 otherwise return NULL. Does not issue diagnostics. */
836
837static struct reg_entry *
838arm_reg_parse_multi (char **ccp)
b99bd4ef 839{
c19d1205
ZW
840 char *start = *ccp;
841 char *p;
842 struct reg_entry *reg;
b99bd4ef 843
c19d1205
ZW
844#ifdef REGISTER_PREFIX
845 if (*start != REGISTER_PREFIX)
846 return FAIL;
847 start++;
848#endif
849#ifdef OPTIONAL_REGISTER_PREFIX
850 if (*start == OPTIONAL_REGISTER_PREFIX)
851 start++;
852#endif
b99bd4ef 853
c19d1205
ZW
854 p = start;
855 if (!ISALPHA (*p) || !is_name_beginner (*p))
856 return NULL;
b99bd4ef 857
c19d1205
ZW
858 do
859 p++;
860 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
861
862 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
863
864 if (!reg)
865 return NULL;
866
867 *ccp = p;
868 return reg;
b99bd4ef
NC
869}
870
c19d1205
ZW
871/* As above, but the register must be of type TYPE, and the return
872 value is the register number or NULL. */
873
b99bd4ef 874static int
c19d1205 875arm_reg_parse (char **ccp, enum arm_reg_type type)
b99bd4ef 876{
c19d1205
ZW
877 char *start = *ccp;
878 struct reg_entry *reg = arm_reg_parse_multi (ccp);
b99bd4ef 879
c19d1205
ZW
880 if (reg && reg->type == type)
881 return reg->number;
6057a28f 882
c19d1205
ZW
883 /* Alternative syntaxes are accepted for a few register classes. */
884 switch (type)
885 {
886 case REG_TYPE_MVF:
887 case REG_TYPE_MVD:
888 case REG_TYPE_MVFX:
889 case REG_TYPE_MVDX:
890 /* Generic coprocessor register names are allowed for these. */
891 if (reg->type == REG_TYPE_CN)
892 return reg->number;
893 break;
69b97547 894
c19d1205
ZW
895 case REG_TYPE_CP:
896 /* For backward compatibility, a bare number is valid here. */
897 {
898 unsigned long processor = strtoul (start, ccp, 10);
899 if (*ccp != start && processor <= 15)
900 return processor;
901 }
6057a28f 902
c19d1205
ZW
903 case REG_TYPE_MMXWC:
904 /* WC includes WCG. ??? I'm not sure this is true for all
905 instructions that take WC registers. */
906 if (reg->type == REG_TYPE_MMXWCG)
907 return reg->number;
6057a28f 908 break;
c19d1205 909
6057a28f 910 default:
c19d1205 911 break;
6057a28f
NC
912 }
913
c19d1205
ZW
914 *ccp = start;
915 return FAIL;
916}
69b97547 917
c19d1205
ZW
918/* Parse an ARM register list. Returns the bitmask, or FAIL. */
919static long
920parse_reg_list (char ** strp)
921{
922 char * str = * strp;
923 long range = 0;
924 int another_range;
a737bd4d 925
c19d1205
ZW
926 /* We come back here if we get ranges concatenated by '+' or '|'. */
927 do
6057a28f 928 {
c19d1205 929 another_range = 0;
a737bd4d 930
c19d1205
ZW
931 if (*str == '{')
932 {
933 int in_range = 0;
934 int cur_reg = -1;
a737bd4d 935
c19d1205
ZW
936 str++;
937 do
938 {
939 int reg;
6057a28f 940
c19d1205
ZW
941 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
942 {
943 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
944 return FAIL;
945 }
a737bd4d 946
c19d1205
ZW
947 if (in_range)
948 {
949 int i;
a737bd4d 950
c19d1205
ZW
951 if (reg <= cur_reg)
952 {
953 inst.error = _("bad range in register list");
954 return FAIL;
955 }
40a18ebd 956
c19d1205
ZW
957 for (i = cur_reg + 1; i < reg; i++)
958 {
959 if (range & (1 << i))
960 as_tsktsk
961 (_("Warning: duplicated register (r%d) in register list"),
962 i);
963 else
964 range |= 1 << i;
965 }
966 in_range = 0;
967 }
a737bd4d 968
c19d1205
ZW
969 if (range & (1 << reg))
970 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
971 reg);
972 else if (reg <= cur_reg)
973 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 974
c19d1205
ZW
975 range |= 1 << reg;
976 cur_reg = reg;
977 }
978 while (skip_past_comma (&str) != FAIL
979 || (in_range = 1, *str++ == '-'));
980 str--;
a737bd4d 981
c19d1205
ZW
982 if (*str++ != '}')
983 {
984 inst.error = _("missing `}'");
985 return FAIL;
986 }
987 }
988 else
989 {
990 expressionS expr;
40a18ebd 991
c19d1205
ZW
992 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
993 return FAIL;
40a18ebd 994
c19d1205
ZW
995 if (expr.X_op == O_constant)
996 {
997 if (expr.X_add_number
998 != (expr.X_add_number & 0x0000ffff))
999 {
1000 inst.error = _("invalid register mask");
1001 return FAIL;
1002 }
a737bd4d 1003
c19d1205
ZW
1004 if ((range & expr.X_add_number) != 0)
1005 {
1006 int regno = range & expr.X_add_number;
a737bd4d 1007
c19d1205
ZW
1008 regno &= -regno;
1009 regno = (1 << regno) - 1;
1010 as_tsktsk
1011 (_("Warning: duplicated register (r%d) in register list"),
1012 regno);
1013 }
a737bd4d 1014
c19d1205
ZW
1015 range |= expr.X_add_number;
1016 }
1017 else
1018 {
1019 if (inst.reloc.type != 0)
1020 {
1021 inst.error = _("expression too complex");
1022 return FAIL;
1023 }
a737bd4d 1024
c19d1205
ZW
1025 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1026 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1027 inst.reloc.pc_rel = 0;
1028 }
1029 }
a737bd4d 1030
c19d1205
ZW
1031 if (*str == '|' || *str == '+')
1032 {
1033 str++;
1034 another_range = 1;
1035 }
a737bd4d 1036 }
c19d1205 1037 while (another_range);
a737bd4d 1038
c19d1205
ZW
1039 *strp = str;
1040 return range;
a737bd4d
NC
1041}
1042
c19d1205
ZW
1043/* Parse a VFP register list. If the string is invalid return FAIL.
1044 Otherwise return the number of registers, and set PBASE to the first
1045 register. Double precision registers are matched if DP is nonzero. */
6057a28f 1046
c19d1205 1047static int
ca3f61f7 1048parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
6057a28f 1049{
c19d1205
ZW
1050 int base_reg;
1051 int new_base;
1052 int regtype;
1053 int max_regs;
1054 int count = 0;
1055 int warned = 0;
1056 unsigned long mask = 0;
a737bd4d 1057 int i;
6057a28f 1058
c19d1205
ZW
1059 if (**str != '{')
1060 return FAIL;
6057a28f 1061
c19d1205 1062 (*str)++;
6057a28f 1063
c19d1205 1064 if (dp)
a737bd4d 1065 {
c19d1205
ZW
1066 regtype = REG_TYPE_VFD;
1067 max_regs = 16;
1068 }
1069 else
1070 {
1071 regtype = REG_TYPE_VFS;
1072 max_regs = 32;
1073 }
6057a28f 1074
c19d1205 1075 base_reg = max_regs;
a737bd4d 1076
c19d1205
ZW
1077 do
1078 {
1079 new_base = arm_reg_parse (str, regtype);
1080 if (new_base == FAIL)
a737bd4d 1081 {
c19d1205
ZW
1082 inst.error = gettext (reg_expected_msgs[regtype]);
1083 return FAIL;
1084 }
a737bd4d 1085
c19d1205
ZW
1086 if (new_base < base_reg)
1087 base_reg = new_base;
a737bd4d 1088
c19d1205
ZW
1089 if (mask & (1 << new_base))
1090 {
1091 inst.error = _("invalid register list");
1092 return FAIL;
a737bd4d 1093 }
a737bd4d 1094
c19d1205
ZW
1095 if ((mask >> new_base) != 0 && ! warned)
1096 {
1097 as_tsktsk (_("register list not in ascending order"));
1098 warned = 1;
1099 }
0bbf2aa4 1100
c19d1205
ZW
1101 mask |= 1 << new_base;
1102 count++;
0bbf2aa4 1103
c19d1205
ZW
1104 if (**str == '-') /* We have the start of a range expression */
1105 {
1106 int high_range;
0bbf2aa4 1107
c19d1205 1108 (*str)++;
0bbf2aa4 1109
c19d1205
ZW
1110 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1111 {
1112 inst.error = gettext (reg_expected_msgs[regtype]);
1113 return FAIL;
1114 }
0bbf2aa4 1115
c19d1205
ZW
1116 if (high_range <= new_base)
1117 {
1118 inst.error = _("register range not in ascending order");
1119 return FAIL;
1120 }
0bbf2aa4 1121
c19d1205 1122 for (new_base++; new_base <= high_range; new_base++)
0bbf2aa4 1123 {
c19d1205 1124 if (mask & (1 << new_base))
0bbf2aa4 1125 {
c19d1205
ZW
1126 inst.error = _("invalid register list");
1127 return FAIL;
0bbf2aa4 1128 }
c19d1205
ZW
1129
1130 mask |= 1 << new_base;
1131 count++;
0bbf2aa4 1132 }
0bbf2aa4 1133 }
0bbf2aa4 1134 }
c19d1205 1135 while (skip_past_comma (str) != FAIL);
0bbf2aa4 1136
c19d1205 1137 (*str)++;
0bbf2aa4 1138
c19d1205
ZW
1139 /* Sanity check -- should have raised a parse error above. */
1140 if (count == 0 || count > max_regs)
1141 abort ();
1142
1143 *pbase = base_reg;
1144
1145 /* Final test -- the registers must be consecutive. */
1146 mask >>= base_reg;
1147 for (i = 0; i < count; i++)
1148 {
1149 if ((mask & (1u << i)) == 0)
1150 {
1151 inst.error = _("non-contiguous register range");
1152 return FAIL;
1153 }
1154 }
1155
1156 return count;
b99bd4ef
NC
1157}
1158
c19d1205
ZW
1159/* Parse an explicit relocation suffix on an expression. This is
1160 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1161 arm_reloc_hsh contains no entries, so this function can only
1162 succeed if there is no () after the word. Returns -1 on error,
1163 BFD_RELOC_UNUSED if there wasn't any suffix. */
1164static int
1165parse_reloc (char **str)
b99bd4ef 1166{
c19d1205
ZW
1167 struct reloc_entry *r;
1168 char *p, *q;
b99bd4ef 1169
c19d1205
ZW
1170 if (**str != '(')
1171 return BFD_RELOC_UNUSED;
b99bd4ef 1172
c19d1205
ZW
1173 p = *str + 1;
1174 q = p;
1175
1176 while (*q && *q != ')' && *q != ',')
1177 q++;
1178 if (*q != ')')
1179 return -1;
1180
1181 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1182 return -1;
1183
1184 *str = q + 1;
1185 return r->reloc;
b99bd4ef
NC
1186}
1187
c19d1205
ZW
1188/* Directives: register aliases. */
1189
b99bd4ef 1190static void
c19d1205 1191insert_reg_alias (char *str, int number, int type)
b99bd4ef 1192{
c19d1205
ZW
1193 struct reg_entry *new;
1194 const char *name;
b99bd4ef 1195
c19d1205
ZW
1196 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1197 {
1198 if (new->builtin)
1199 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1200
c19d1205
ZW
1201 /* Only warn about a redefinition if it's not defined as the
1202 same register. */
1203 else if (new->number != number || new->type != type)
1204 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1205
c19d1205
ZW
1206 return;
1207 }
b99bd4ef 1208
c19d1205
ZW
1209 name = xstrdup (str);
1210 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1211
c19d1205
ZW
1212 new->name = name;
1213 new->number = number;
1214 new->type = type;
1215 new->builtin = FALSE;
b99bd4ef 1216
c19d1205
ZW
1217 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1218 abort ();
1219}
b99bd4ef 1220
c19d1205 1221/* Look for the .req directive. This is of the form:
b99bd4ef 1222
c19d1205 1223 new_register_name .req existing_register_name
b99bd4ef 1224
c19d1205
ZW
1225 If we find one, or if it looks sufficiently like one that we want to
1226 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 1227
c19d1205
ZW
1228static int
1229create_register_alias (char * newname, char *p)
1230{
1231 struct reg_entry *old;
1232 char *oldname, *nbuf;
1233 size_t nlen;
b99bd4ef 1234
c19d1205
ZW
1235 /* The input scrubber ensures that whitespace after the mnemonic is
1236 collapsed to single spaces. */
1237 oldname = p;
1238 if (strncmp (oldname, " .req ", 6) != 0)
1239 return 0;
b99bd4ef 1240
c19d1205
ZW
1241 oldname += 6;
1242 if (*oldname == '\0')
1243 return 0;
b99bd4ef 1244
c19d1205
ZW
1245 old = hash_find (arm_reg_hsh, oldname);
1246 if (!old)
b99bd4ef 1247 {
c19d1205
ZW
1248 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1249 return 1;
b99bd4ef
NC
1250 }
1251
c19d1205
ZW
1252 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1253 the desired alias name, and p points to its end. If not, then
1254 the desired alias name is in the global original_case_string. */
1255#ifdef TC_CASE_SENSITIVE
1256 nlen = p - newname;
1257#else
1258 newname = original_case_string;
1259 nlen = strlen (newname);
1260#endif
b99bd4ef 1261
c19d1205
ZW
1262 nbuf = alloca (nlen + 1);
1263 memcpy (nbuf, newname, nlen);
1264 nbuf[nlen] = '\0';
b99bd4ef 1265
c19d1205
ZW
1266 /* Create aliases under the new name as stated; an all-lowercase
1267 version of the new name; and an all-uppercase version of the new
1268 name. */
1269 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 1270
c19d1205
ZW
1271 for (p = nbuf; *p; p++)
1272 *p = TOUPPER (*p);
1273
1274 if (strncmp (nbuf, newname, nlen))
1275 insert_reg_alias (nbuf, old->number, old->type);
1276
1277 for (p = nbuf; *p; p++)
1278 *p = TOLOWER (*p);
1279
1280 if (strncmp (nbuf, newname, nlen))
1281 insert_reg_alias (nbuf, old->number, old->type);
1282
1283 return 1;
b99bd4ef
NC
1284}
1285
c19d1205
ZW
1286/* Should never be called, as .req goes between the alias and the
1287 register name, not at the beginning of the line. */
b99bd4ef 1288static void
c19d1205 1289s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 1290{
c19d1205
ZW
1291 as_bad (_("invalid syntax for .req directive"));
1292}
b99bd4ef 1293
c19d1205
ZW
1294/* The .unreq directive deletes an alias which was previously defined
1295 by .req. For example:
b99bd4ef 1296
c19d1205
ZW
1297 my_alias .req r11
1298 .unreq my_alias */
b99bd4ef
NC
1299
1300static void
c19d1205 1301s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 1302{
c19d1205
ZW
1303 char * name;
1304 char saved_char;
b99bd4ef 1305
c19d1205
ZW
1306 name = input_line_pointer;
1307
1308 while (*input_line_pointer != 0
1309 && *input_line_pointer != ' '
1310 && *input_line_pointer != '\n')
1311 ++input_line_pointer;
1312
1313 saved_char = *input_line_pointer;
1314 *input_line_pointer = 0;
1315
1316 if (!*name)
1317 as_bad (_("invalid syntax for .unreq directive"));
1318 else
1319 {
1320 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1321
1322 if (!reg)
1323 as_bad (_("unknown register alias '%s'"), name);
1324 else if (reg->builtin)
1325 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1326 name);
1327 else
1328 {
1329 hash_delete (arm_reg_hsh, name);
1330 free ((char *) reg->name);
1331 free (reg);
1332 }
1333 }
b99bd4ef 1334
c19d1205 1335 *input_line_pointer = saved_char;
b99bd4ef
NC
1336 demand_empty_rest_of_line ();
1337}
1338
c19d1205
ZW
1339/* Directives: Instruction set selection. */
1340
1341#ifdef OBJ_ELF
1342/* This code is to handle mapping symbols as defined in the ARM ELF spec.
1343 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1344 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1345 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1346
1347static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
1348
1349static void
c19d1205 1350mapping_state (enum mstate state)
b99bd4ef 1351{
a737bd4d 1352 symbolS * symbolP;
c19d1205
ZW
1353 const char * symname;
1354 int type;
b99bd4ef 1355
c19d1205
ZW
1356 if (mapstate == state)
1357 /* The mapping symbol has already been emitted.
1358 There is nothing else to do. */
1359 return;
b99bd4ef 1360
c19d1205 1361 mapstate = state;
b99bd4ef 1362
c19d1205 1363 switch (state)
b99bd4ef 1364 {
c19d1205
ZW
1365 case MAP_DATA:
1366 symname = "$d";
1367 type = BSF_NO_FLAGS;
1368 break;
1369 case MAP_ARM:
1370 symname = "$a";
1371 type = BSF_NO_FLAGS;
1372 break;
1373 case MAP_THUMB:
1374 symname = "$t";
1375 type = BSF_NO_FLAGS;
1376 break;
1377 case MAP_UNDEFINED:
1378 return;
1379 default:
1380 abort ();
1381 }
1382
1383 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1384
1385 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1386 symbol_table_insert (symbolP);
1387 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1388
1389 switch (state)
1390 {
1391 case MAP_ARM:
1392 THUMB_SET_FUNC (symbolP, 0);
1393 ARM_SET_THUMB (symbolP, 0);
1394 ARM_SET_INTERWORK (symbolP, support_interwork);
1395 break;
1396
1397 case MAP_THUMB:
1398 THUMB_SET_FUNC (symbolP, 1);
1399 ARM_SET_THUMB (symbolP, 1);
1400 ARM_SET_INTERWORK (symbolP, support_interwork);
1401 break;
1402
1403 case MAP_DATA:
1404 default:
1405 return;
1406 }
1407}
1408#else
1409#define mapping_state(x) /* nothing */
1410#endif
1411
1412/* Find the real, Thumb encoded start of a Thumb function. */
1413
1414static symbolS *
1415find_real_start (symbolS * symbolP)
1416{
1417 char * real_start;
1418 const char * name = S_GET_NAME (symbolP);
1419 symbolS * new_target;
1420
1421 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1422#define STUB_NAME ".real_start_of"
1423
1424 if (name == NULL)
1425 abort ();
1426
37f6032b
ZW
1427 /* The compiler may generate BL instructions to local labels because
1428 it needs to perform a branch to a far away location. These labels
1429 do not have a corresponding ".real_start_of" label. We check
1430 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1431 the ".real_start_of" convention for nonlocal branches. */
1432 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
1433 return symbolP;
1434
37f6032b 1435 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
1436 new_target = symbol_find (real_start);
1437
1438 if (new_target == NULL)
1439 {
1440 as_warn ("Failed to find real start of function: %s\n", name);
1441 new_target = symbolP;
1442 }
1443
c19d1205
ZW
1444 return new_target;
1445}
1446
1447static void
1448opcode_select (int width)
1449{
1450 switch (width)
1451 {
1452 case 16:
1453 if (! thumb_mode)
1454 {
1455 if (! (cpu_variant & ARM_EXT_V4T))
1456 as_bad (_("selected processor does not support THUMB opcodes"));
1457
1458 thumb_mode = 1;
1459 /* No need to force the alignment, since we will have been
1460 coming from ARM mode, which is word-aligned. */
1461 record_alignment (now_seg, 1);
1462 }
1463 mapping_state (MAP_THUMB);
1464 break;
1465
1466 case 32:
1467 if (thumb_mode)
1468 {
1469 if ((cpu_variant & ARM_ALL) == ARM_EXT_V4T)
1470 as_bad (_("selected processor does not support ARM opcodes"));
1471
1472 thumb_mode = 0;
1473
1474 if (!need_pass_2)
1475 frag_align (2, 0, 0);
1476
1477 record_alignment (now_seg, 1);
1478 }
1479 mapping_state (MAP_ARM);
1480 break;
1481
1482 default:
1483 as_bad (_("invalid instruction size selected (%d)"), width);
1484 }
1485}
1486
1487static void
1488s_arm (int ignore ATTRIBUTE_UNUSED)
1489{
1490 opcode_select (32);
1491 demand_empty_rest_of_line ();
1492}
1493
1494static void
1495s_thumb (int ignore ATTRIBUTE_UNUSED)
1496{
1497 opcode_select (16);
1498 demand_empty_rest_of_line ();
1499}
1500
1501static void
1502s_code (int unused ATTRIBUTE_UNUSED)
1503{
1504 int temp;
1505
1506 temp = get_absolute_expression ();
1507 switch (temp)
1508 {
1509 case 16:
1510 case 32:
1511 opcode_select (temp);
1512 break;
1513
1514 default:
1515 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1516 }
1517}
1518
1519static void
1520s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1521{
1522 /* If we are not already in thumb mode go into it, EVEN if
1523 the target processor does not support thumb instructions.
1524 This is used by gcc/config/arm/lib1funcs.asm for example
1525 to compile interworking support functions even if the
1526 target processor should not support interworking. */
1527 if (! thumb_mode)
1528 {
1529 thumb_mode = 2;
1530 record_alignment (now_seg, 1);
1531 }
1532
1533 demand_empty_rest_of_line ();
1534}
1535
1536static void
1537s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1538{
1539 s_thumb (0);
1540
1541 /* The following label is the name/address of the start of a Thumb function.
1542 We need to know this for the interworking support. */
1543 label_is_thumb_function_name = TRUE;
1544}
1545
1546/* Perform a .set directive, but also mark the alias as
1547 being a thumb function. */
1548
1549static void
1550s_thumb_set (int equiv)
1551{
1552 /* XXX the following is a duplicate of the code for s_set() in read.c
1553 We cannot just call that code as we need to get at the symbol that
1554 is created. */
1555 char * name;
1556 char delim;
1557 char * end_name;
1558 symbolS * symbolP;
1559
1560 /* Especial apologies for the random logic:
1561 This just grew, and could be parsed much more simply!
1562 Dean - in haste. */
1563 name = input_line_pointer;
1564 delim = get_symbol_end ();
1565 end_name = input_line_pointer;
1566 *end_name = delim;
1567
1568 if (*input_line_pointer != ',')
1569 {
1570 *end_name = 0;
1571 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1572 *end_name = delim;
1573 ignore_rest_of_line ();
1574 return;
1575 }
1576
1577 input_line_pointer++;
1578 *end_name = 0;
1579
1580 if (name[0] == '.' && name[1] == '\0')
1581 {
1582 /* XXX - this should not happen to .thumb_set. */
1583 abort ();
1584 }
1585
1586 if ((symbolP = symbol_find (name)) == NULL
1587 && (symbolP = md_undefined_symbol (name)) == NULL)
1588 {
1589#ifndef NO_LISTING
1590 /* When doing symbol listings, play games with dummy fragments living
1591 outside the normal fragment chain to record the file and line info
c19d1205 1592 for this symbol. */
b99bd4ef
NC
1593 if (listing & LISTING_SYMBOLS)
1594 {
1595 extern struct list_info_struct * listing_tail;
a737bd4d 1596 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1597
1598 memset (dummy_frag, 0, sizeof (fragS));
1599 dummy_frag->fr_type = rs_fill;
1600 dummy_frag->line = listing_tail;
1601 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1602 dummy_frag->fr_symbol = symbolP;
1603 }
1604 else
1605#endif
1606 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1607
1608#ifdef OBJ_COFF
1609 /* "set" symbols are local unless otherwise specified. */
1610 SF_SET_LOCAL (symbolP);
1611#endif /* OBJ_COFF */
1612 } /* Make a new symbol. */
1613
1614 symbol_table_insert (symbolP);
1615
1616 * end_name = delim;
1617
1618 if (equiv
1619 && S_IS_DEFINED (symbolP)
1620 && S_GET_SEGMENT (symbolP) != reg_section)
1621 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1622
1623 pseudo_set (symbolP);
1624
1625 demand_empty_rest_of_line ();
1626
c19d1205 1627 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1628
1629 THUMB_SET_FUNC (symbolP, 1);
1630 ARM_SET_THUMB (symbolP, 1);
1631#if defined OBJ_ELF || defined OBJ_COFF
1632 ARM_SET_INTERWORK (symbolP, support_interwork);
1633#endif
1634}
1635
c19d1205 1636/* Directives: Mode selection. */
b99bd4ef 1637
c19d1205
ZW
1638/* .syntax [unified|divided] - choose the new unified syntax
1639 (same for Arm and Thumb encoding, modulo slight differences in what
1640 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1641static void
c19d1205 1642s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1643{
c19d1205
ZW
1644 char *name, delim;
1645
1646 name = input_line_pointer;
1647 delim = get_symbol_end ();
1648
1649 if (!strcasecmp (name, "unified"))
1650 unified_syntax = TRUE;
1651 else if (!strcasecmp (name, "divided"))
1652 unified_syntax = FALSE;
1653 else
1654 {
1655 as_bad (_("unrecognized syntax mode \"%s\""), name);
1656 return;
1657 }
1658 *input_line_pointer = delim;
b99bd4ef
NC
1659 demand_empty_rest_of_line ();
1660}
1661
c19d1205
ZW
1662/* Directives: sectioning and alignment. */
1663
1664/* Same as s_align_ptwo but align 0 => align 2. */
1665
b99bd4ef 1666static void
c19d1205 1667s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1668{
a737bd4d 1669 int temp;
c19d1205
ZW
1670 long temp_fill;
1671 long max_alignment = 15;
b99bd4ef
NC
1672
1673 temp = get_absolute_expression ();
c19d1205
ZW
1674 if (temp > max_alignment)
1675 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1676 else if (temp < 0)
b99bd4ef 1677 {
c19d1205
ZW
1678 as_bad (_("alignment negative. 0 assumed."));
1679 temp = 0;
1680 }
b99bd4ef 1681
c19d1205
ZW
1682 if (*input_line_pointer == ',')
1683 {
1684 input_line_pointer++;
1685 temp_fill = get_absolute_expression ();
b99bd4ef 1686 }
c19d1205
ZW
1687 else
1688 temp_fill = 0;
b99bd4ef 1689
c19d1205
ZW
1690 if (!temp)
1691 temp = 2;
b99bd4ef 1692
c19d1205
ZW
1693 /* Only make a frag if we HAVE to. */
1694 if (temp && !need_pass_2)
1695 frag_align (temp, (int) temp_fill, 0);
1696 demand_empty_rest_of_line ();
1697
1698 record_alignment (now_seg, temp);
b99bd4ef
NC
1699}
1700
c19d1205
ZW
1701static void
1702s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1703{
c19d1205
ZW
1704 /* We don't support putting frags in the BSS segment, we fake it by
1705 marking in_bss, then looking at s_skip for clues. */
1706 subseg_set (bss_section, 0);
1707 demand_empty_rest_of_line ();
1708 mapping_state (MAP_DATA);
1709}
b99bd4ef 1710
c19d1205
ZW
1711static void
1712s_even (int ignore ATTRIBUTE_UNUSED)
1713{
1714 /* Never make frag if expect extra pass. */
1715 if (!need_pass_2)
1716 frag_align (1, 0, 0);
b99bd4ef 1717
c19d1205 1718 record_alignment (now_seg, 1);
b99bd4ef 1719
c19d1205 1720 demand_empty_rest_of_line ();
b99bd4ef
NC
1721}
1722
c19d1205 1723/* Directives: Literal pools. */
a737bd4d 1724
c19d1205
ZW
1725static literal_pool *
1726find_literal_pool (void)
a737bd4d 1727{
c19d1205 1728 literal_pool * pool;
a737bd4d 1729
c19d1205 1730 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1731 {
c19d1205
ZW
1732 if (pool->section == now_seg
1733 && pool->sub_section == now_subseg)
1734 break;
a737bd4d
NC
1735 }
1736
c19d1205 1737 return pool;
a737bd4d
NC
1738}
1739
c19d1205
ZW
1740static literal_pool *
1741find_or_make_literal_pool (void)
a737bd4d 1742{
c19d1205
ZW
1743 /* Next literal pool ID number. */
1744 static unsigned int latest_pool_num = 1;
1745 literal_pool * pool;
a737bd4d 1746
c19d1205 1747 pool = find_literal_pool ();
a737bd4d 1748
c19d1205 1749 if (pool == NULL)
a737bd4d 1750 {
c19d1205
ZW
1751 /* Create a new pool. */
1752 pool = xmalloc (sizeof (* pool));
1753 if (! pool)
1754 return NULL;
a737bd4d 1755
c19d1205
ZW
1756 pool->next_free_entry = 0;
1757 pool->section = now_seg;
1758 pool->sub_section = now_subseg;
1759 pool->next = list_of_pools;
1760 pool->symbol = NULL;
1761
1762 /* Add it to the list. */
1763 list_of_pools = pool;
a737bd4d 1764 }
a737bd4d 1765
c19d1205
ZW
1766 /* New pools, and emptied pools, will have a NULL symbol. */
1767 if (pool->symbol == NULL)
a737bd4d 1768 {
c19d1205
ZW
1769 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1770 (valueT) 0, &zero_address_frag);
1771 pool->id = latest_pool_num ++;
a737bd4d
NC
1772 }
1773
c19d1205
ZW
1774 /* Done. */
1775 return pool;
a737bd4d
NC
1776}
1777
c19d1205
ZW
1778/* Add the literal in the global 'inst'
1779 structure to the relevent literal pool. */
b99bd4ef
NC
1780
1781static int
c19d1205 1782add_to_lit_pool (void)
b99bd4ef 1783{
c19d1205
ZW
1784 literal_pool * pool;
1785 unsigned int entry;
b99bd4ef 1786
c19d1205
ZW
1787 pool = find_or_make_literal_pool ();
1788
1789 /* Check if this literal value is already in the pool. */
1790 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1791 {
c19d1205
ZW
1792 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1793 && (inst.reloc.exp.X_op == O_constant)
1794 && (pool->literals[entry].X_add_number
1795 == inst.reloc.exp.X_add_number)
1796 && (pool->literals[entry].X_unsigned
1797 == inst.reloc.exp.X_unsigned))
1798 break;
1799
1800 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1801 && (inst.reloc.exp.X_op == O_symbol)
1802 && (pool->literals[entry].X_add_number
1803 == inst.reloc.exp.X_add_number)
1804 && (pool->literals[entry].X_add_symbol
1805 == inst.reloc.exp.X_add_symbol)
1806 && (pool->literals[entry].X_op_symbol
1807 == inst.reloc.exp.X_op_symbol))
1808 break;
b99bd4ef
NC
1809 }
1810
c19d1205
ZW
1811 /* Do we need to create a new entry? */
1812 if (entry == pool->next_free_entry)
1813 {
1814 if (entry >= MAX_LITERAL_POOL_SIZE)
1815 {
1816 inst.error = _("literal pool overflow");
1817 return FAIL;
1818 }
1819
1820 pool->literals[entry] = inst.reloc.exp;
1821 pool->next_free_entry += 1;
1822 }
b99bd4ef 1823
c19d1205
ZW
1824 inst.reloc.exp.X_op = O_symbol;
1825 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1826 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1827
c19d1205 1828 return SUCCESS;
b99bd4ef
NC
1829}
1830
c19d1205
ZW
1831/* Can't use symbol_new here, so have to create a symbol and then at
1832 a later date assign it a value. Thats what these functions do. */
e16bb312 1833
c19d1205
ZW
1834static void
1835symbol_locate (symbolS * symbolP,
1836 const char * name, /* It is copied, the caller can modify. */
1837 segT segment, /* Segment identifier (SEG_<something>). */
1838 valueT valu, /* Symbol value. */
1839 fragS * frag) /* Associated fragment. */
1840{
1841 unsigned int name_length;
1842 char * preserved_copy_of_name;
e16bb312 1843
c19d1205
ZW
1844 name_length = strlen (name) + 1; /* +1 for \0. */
1845 obstack_grow (&notes, name, name_length);
1846 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1847
c19d1205
ZW
1848#ifdef tc_canonicalize_symbol_name
1849 preserved_copy_of_name =
1850 tc_canonicalize_symbol_name (preserved_copy_of_name);
1851#endif
b99bd4ef 1852
c19d1205 1853 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1854
c19d1205
ZW
1855 S_SET_SEGMENT (symbolP, segment);
1856 S_SET_VALUE (symbolP, valu);
1857 symbol_clear_list_pointers (symbolP);
b99bd4ef 1858
c19d1205 1859 symbol_set_frag (symbolP, frag);
b99bd4ef 1860
c19d1205
ZW
1861 /* Link to end of symbol chain. */
1862 {
1863 extern int symbol_table_frozen;
b99bd4ef 1864
c19d1205
ZW
1865 if (symbol_table_frozen)
1866 abort ();
1867 }
b99bd4ef 1868
c19d1205 1869 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1870
c19d1205 1871 obj_symbol_new_hook (symbolP);
b99bd4ef 1872
c19d1205
ZW
1873#ifdef tc_symbol_new_hook
1874 tc_symbol_new_hook (symbolP);
1875#endif
1876
1877#ifdef DEBUG_SYMS
1878 verify_symbol_chain (symbol_rootP, symbol_lastP);
1879#endif /* DEBUG_SYMS */
b99bd4ef
NC
1880}
1881
b99bd4ef 1882
c19d1205
ZW
1883static void
1884s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1885{
c19d1205
ZW
1886 unsigned int entry;
1887 literal_pool * pool;
1888 char sym_name[20];
b99bd4ef 1889
c19d1205
ZW
1890 pool = find_literal_pool ();
1891 if (pool == NULL
1892 || pool->symbol == NULL
1893 || pool->next_free_entry == 0)
1894 return;
b99bd4ef 1895
c19d1205 1896 mapping_state (MAP_DATA);
b99bd4ef 1897
c19d1205
ZW
1898 /* Align pool as you have word accesses.
1899 Only make a frag if we have to. */
1900 if (!need_pass_2)
1901 frag_align (2, 0, 0);
b99bd4ef 1902
c19d1205 1903 record_alignment (now_seg, 2);
b99bd4ef 1904
c19d1205 1905 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1906
c19d1205
ZW
1907 symbol_locate (pool->symbol, sym_name, now_seg,
1908 (valueT) frag_now_fix (), frag_now);
1909 symbol_table_insert (pool->symbol);
b99bd4ef 1910
c19d1205 1911 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1912
c19d1205
ZW
1913#if defined OBJ_COFF || defined OBJ_ELF
1914 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1915#endif
6c43fab6 1916
c19d1205
ZW
1917 for (entry = 0; entry < pool->next_free_entry; entry ++)
1918 /* First output the expression in the instruction to the pool. */
1919 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1920
c19d1205
ZW
1921 /* Mark the pool as empty. */
1922 pool->next_free_entry = 0;
1923 pool->symbol = NULL;
b99bd4ef
NC
1924}
1925
c19d1205
ZW
1926#ifdef OBJ_ELF
1927/* Forward declarations for functions below, in the MD interface
1928 section. */
1929static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1930static valueT create_unwind_entry (int);
1931static void start_unwind_section (const segT, int);
1932static void add_unwind_opcode (valueT, int);
1933static void flush_pending_unwind (void);
b99bd4ef 1934
c19d1205 1935/* Directives: Data. */
b99bd4ef 1936
c19d1205
ZW
1937static void
1938s_arm_elf_cons (int nbytes)
1939{
1940 expressionS exp;
b99bd4ef 1941
c19d1205
ZW
1942#ifdef md_flush_pending_output
1943 md_flush_pending_output ();
1944#endif
b99bd4ef 1945
c19d1205 1946 if (is_it_end_of_statement ())
b99bd4ef 1947 {
c19d1205
ZW
1948 demand_empty_rest_of_line ();
1949 return;
b99bd4ef
NC
1950 }
1951
c19d1205
ZW
1952#ifdef md_cons_align
1953 md_cons_align (nbytes);
1954#endif
b99bd4ef 1955
c19d1205
ZW
1956 mapping_state (MAP_DATA);
1957 do
b99bd4ef 1958 {
c19d1205
ZW
1959 int reloc;
1960 char *base = input_line_pointer;
b99bd4ef 1961
c19d1205 1962 expression (& exp);
b99bd4ef 1963
c19d1205
ZW
1964 if (exp.X_op != O_symbol)
1965 emit_expr (&exp, (unsigned int) nbytes);
1966 else
1967 {
1968 char *before_reloc = input_line_pointer;
1969 reloc = parse_reloc (&input_line_pointer);
1970 if (reloc == -1)
1971 {
1972 as_bad (_("unrecognized relocation suffix"));
1973 ignore_rest_of_line ();
1974 return;
1975 }
1976 else if (reloc == BFD_RELOC_UNUSED)
1977 emit_expr (&exp, (unsigned int) nbytes);
1978 else
1979 {
1980 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
1981 int size = bfd_get_reloc_size (howto);
b99bd4ef 1982
2fc8bdac
ZW
1983 if (reloc == BFD_RELOC_ARM_PLT32)
1984 {
1985 as_bad (_("(plt) is only valid on branch targets"));
1986 reloc = BFD_RELOC_UNUSED;
1987 size = 0;
1988 }
1989
c19d1205 1990 if (size > nbytes)
2fc8bdac 1991 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
1992 howto->name, nbytes);
1993 else
1994 {
1995 /* We've parsed an expression stopping at O_symbol.
1996 But there may be more expression left now that we
1997 have parsed the relocation marker. Parse it again.
1998 XXX Surely there is a cleaner way to do this. */
1999 char *p = input_line_pointer;
2000 int offset;
2001 char *save_buf = alloca (input_line_pointer - base);
2002 memcpy (save_buf, base, input_line_pointer - base);
2003 memmove (base + (input_line_pointer - before_reloc),
2004 base, before_reloc - base);
2005
2006 input_line_pointer = base + (input_line_pointer-before_reloc);
2007 expression (&exp);
2008 memcpy (base, save_buf, p - base);
2009
2010 offset = nbytes - size;
2011 p = frag_more ((int) nbytes);
2012 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2013 size, &exp, 0, reloc);
2014 }
2015 }
2016 }
b99bd4ef 2017 }
c19d1205 2018 while (*input_line_pointer++ == ',');
b99bd4ef 2019
c19d1205
ZW
2020 /* Put terminator back into stream. */
2021 input_line_pointer --;
2022 demand_empty_rest_of_line ();
b99bd4ef
NC
2023}
2024
b99bd4ef 2025
c19d1205 2026/* Parse a .rel31 directive. */
b99bd4ef 2027
c19d1205
ZW
2028static void
2029s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2030{
2031 expressionS exp;
2032 char *p;
2033 valueT highbit;
b99bd4ef 2034
c19d1205
ZW
2035 highbit = 0;
2036 if (*input_line_pointer == '1')
2037 highbit = 0x80000000;
2038 else if (*input_line_pointer != '0')
2039 as_bad (_("expected 0 or 1"));
b99bd4ef 2040
c19d1205
ZW
2041 input_line_pointer++;
2042 if (*input_line_pointer != ',')
2043 as_bad (_("missing comma"));
2044 input_line_pointer++;
b99bd4ef 2045
c19d1205
ZW
2046#ifdef md_flush_pending_output
2047 md_flush_pending_output ();
2048#endif
b99bd4ef 2049
c19d1205
ZW
2050#ifdef md_cons_align
2051 md_cons_align (4);
2052#endif
b99bd4ef 2053
c19d1205 2054 mapping_state (MAP_DATA);
b99bd4ef 2055
c19d1205 2056 expression (&exp);
b99bd4ef 2057
c19d1205
ZW
2058 p = frag_more (4);
2059 md_number_to_chars (p, highbit, 4);
2060 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2061 BFD_RELOC_ARM_PREL31);
b99bd4ef 2062
c19d1205 2063 demand_empty_rest_of_line ();
b99bd4ef
NC
2064}
2065
c19d1205 2066/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2067
c19d1205 2068/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2069
c19d1205
ZW
2070static void
2071s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2072{
2073 demand_empty_rest_of_line ();
2074 /* Mark the start of the function. */
2075 unwind.proc_start = expr_build_dot ();
b99bd4ef 2076
c19d1205
ZW
2077 /* Reset the rest of the unwind info. */
2078 unwind.opcode_count = 0;
2079 unwind.table_entry = NULL;
2080 unwind.personality_routine = NULL;
2081 unwind.personality_index = -1;
2082 unwind.frame_size = 0;
2083 unwind.fp_offset = 0;
2084 unwind.fp_reg = 13;
2085 unwind.fp_used = 0;
2086 unwind.sp_restored = 0;
2087}
b99bd4ef 2088
b99bd4ef 2089
c19d1205
ZW
2090/* Parse a handlerdata directive. Creates the exception handling table entry
2091 for the function. */
b99bd4ef 2092
c19d1205
ZW
2093static void
2094s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2095{
2096 demand_empty_rest_of_line ();
2097 if (unwind.table_entry)
2098 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2099
c19d1205
ZW
2100 create_unwind_entry (1);
2101}
a737bd4d 2102
c19d1205 2103/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2104
c19d1205
ZW
2105static void
2106s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2107{
2108 long where;
2109 char *ptr;
2110 valueT val;
f02232aa 2111
c19d1205 2112 demand_empty_rest_of_line ();
f02232aa 2113
c19d1205
ZW
2114 /* Add eh table entry. */
2115 if (unwind.table_entry == NULL)
2116 val = create_unwind_entry (0);
2117 else
2118 val = 0;
f02232aa 2119
c19d1205
ZW
2120 /* Add index table entry. This is two words. */
2121 start_unwind_section (unwind.saved_seg, 1);
2122 frag_align (2, 0, 0);
2123 record_alignment (now_seg, 2);
b99bd4ef 2124
c19d1205
ZW
2125 ptr = frag_more (8);
2126 where = frag_now_fix () - 8;
f02232aa 2127
c19d1205
ZW
2128 /* Self relative offset of the function start. */
2129 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2130 BFD_RELOC_ARM_PREL31);
f02232aa 2131
c19d1205
ZW
2132 /* Indicate dependency on EHABI-defined personality routines to the
2133 linker, if it hasn't been done already. */
2134 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2135 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2136 {
2137 static const char *const name[] = {
2138 "__aeabi_unwind_cpp_pr0",
2139 "__aeabi_unwind_cpp_pr1",
2140 "__aeabi_unwind_cpp_pr2"
2141 };
2142 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2143 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2144 marked_pr_dependency |= 1 << unwind.personality_index;
2145 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2146 = marked_pr_dependency;
2147 }
f02232aa 2148
c19d1205
ZW
2149 if (val)
2150 /* Inline exception table entry. */
2151 md_number_to_chars (ptr + 4, val, 4);
2152 else
2153 /* Self relative offset of the table entry. */
2154 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2155 BFD_RELOC_ARM_PREL31);
f02232aa 2156
c19d1205
ZW
2157 /* Restore the original section. */
2158 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2159}
f02232aa 2160
f02232aa 2161
c19d1205 2162/* Parse an unwind_cantunwind directive. */
b99bd4ef 2163
c19d1205
ZW
2164static void
2165s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2166{
2167 demand_empty_rest_of_line ();
2168 if (unwind.personality_routine || unwind.personality_index != -1)
2169 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2170
c19d1205
ZW
2171 unwind.personality_index = -2;
2172}
b99bd4ef 2173
b99bd4ef 2174
c19d1205 2175/* Parse a personalityindex directive. */
b99bd4ef 2176
c19d1205
ZW
2177static void
2178s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2179{
2180 expressionS exp;
b99bd4ef 2181
c19d1205
ZW
2182 if (unwind.personality_routine || unwind.personality_index != -1)
2183 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2184
c19d1205 2185 expression (&exp);
b99bd4ef 2186
c19d1205
ZW
2187 if (exp.X_op != O_constant
2188 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2189 {
c19d1205
ZW
2190 as_bad (_("bad personality routine number"));
2191 ignore_rest_of_line ();
2192 return;
b99bd4ef
NC
2193 }
2194
c19d1205 2195 unwind.personality_index = exp.X_add_number;
b99bd4ef 2196
c19d1205
ZW
2197 demand_empty_rest_of_line ();
2198}
e16bb312 2199
e16bb312 2200
c19d1205 2201/* Parse a personality directive. */
e16bb312 2202
c19d1205
ZW
2203static void
2204s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2205{
2206 char *name, *p, c;
a737bd4d 2207
c19d1205
ZW
2208 if (unwind.personality_routine || unwind.personality_index != -1)
2209 as_bad (_("duplicate .personality directive"));
a737bd4d 2210
c19d1205
ZW
2211 name = input_line_pointer;
2212 c = get_symbol_end ();
2213 p = input_line_pointer;
2214 unwind.personality_routine = symbol_find_or_make (name);
2215 *p = c;
2216 demand_empty_rest_of_line ();
2217}
e16bb312 2218
e16bb312 2219
c19d1205 2220/* Parse a directive saving core registers. */
e16bb312 2221
c19d1205
ZW
2222static void
2223s_arm_unwind_save_core (void)
e16bb312 2224{
c19d1205
ZW
2225 valueT op;
2226 long range;
2227 int n;
e16bb312 2228
c19d1205
ZW
2229 range = parse_reg_list (&input_line_pointer);
2230 if (range == FAIL)
e16bb312 2231 {
c19d1205
ZW
2232 as_bad (_("expected register list"));
2233 ignore_rest_of_line ();
2234 return;
2235 }
e16bb312 2236
c19d1205 2237 demand_empty_rest_of_line ();
e16bb312 2238
c19d1205
ZW
2239 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2240 into .unwind_save {..., sp...}. We aren't bothered about the value of
2241 ip because it is clobbered by calls. */
2242 if (unwind.sp_restored && unwind.fp_reg == 12
2243 && (range & 0x3000) == 0x1000)
2244 {
2245 unwind.opcode_count--;
2246 unwind.sp_restored = 0;
2247 range = (range | 0x2000) & ~0x1000;
2248 unwind.pending_offset = 0;
2249 }
e16bb312 2250
c19d1205
ZW
2251 /* See if we can use the short opcodes. These pop a block of upto 8
2252 registers starting with r4, plus maybe r14. */
2253 for (n = 0; n < 8; n++)
2254 {
2255 /* Break at the first non-saved register. */
2256 if ((range & (1 << (n + 4))) == 0)
2257 break;
e16bb312 2258 }
c19d1205
ZW
2259 /* See if there are any other bits set. */
2260 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
e16bb312 2261 {
c19d1205
ZW
2262 /* Use the long form. */
2263 op = 0x8000 | ((range >> 4) & 0xfff);
2264 add_unwind_opcode (op, 2);
e16bb312 2265 }
c19d1205 2266 else
0dd132b6 2267 {
c19d1205
ZW
2268 /* Use the short form. */
2269 if (range & 0x4000)
2270 op = 0xa8; /* Pop r14. */
0dd132b6 2271 else
c19d1205
ZW
2272 op = 0xa0; /* Do not pop r14. */
2273 op |= (n - 1);
2274 add_unwind_opcode (op, 1);
2275 }
0dd132b6 2276
c19d1205
ZW
2277 /* Pop r0-r3. */
2278 if (range & 0xf)
2279 {
2280 op = 0xb100 | (range & 0xf);
2281 add_unwind_opcode (op, 2);
0dd132b6
NC
2282 }
2283
c19d1205
ZW
2284 /* Record the number of bytes pushed. */
2285 for (n = 0; n < 16; n++)
2286 {
2287 if (range & (1 << n))
2288 unwind.frame_size += 4;
2289 }
0dd132b6
NC
2290}
2291
c19d1205
ZW
2292
2293/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2294
2295static void
c19d1205 2296s_arm_unwind_save_fpa (int reg)
b99bd4ef 2297{
c19d1205
ZW
2298 expressionS exp;
2299 int num_regs;
2300 valueT op;
b99bd4ef 2301
c19d1205
ZW
2302 /* Get Number of registers to transfer. */
2303 if (skip_past_comma (&input_line_pointer) != FAIL)
2304 expression (&exp);
2305 else
2306 exp.X_op = O_illegal;
b99bd4ef 2307
c19d1205 2308 if (exp.X_op != O_constant)
b99bd4ef 2309 {
c19d1205
ZW
2310 as_bad (_("expected , <constant>"));
2311 ignore_rest_of_line ();
b99bd4ef
NC
2312 return;
2313 }
2314
c19d1205
ZW
2315 num_regs = exp.X_add_number;
2316
2317 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2318 {
c19d1205
ZW
2319 as_bad (_("number of registers must be in the range [1:4]"));
2320 ignore_rest_of_line ();
b99bd4ef
NC
2321 return;
2322 }
2323
c19d1205 2324 demand_empty_rest_of_line ();
b99bd4ef 2325
c19d1205
ZW
2326 if (reg == 4)
2327 {
2328 /* Short form. */
2329 op = 0xb4 | (num_regs - 1);
2330 add_unwind_opcode (op, 1);
2331 }
b99bd4ef
NC
2332 else
2333 {
c19d1205
ZW
2334 /* Long form. */
2335 op = 0xc800 | (reg << 4) | (num_regs - 1);
2336 add_unwind_opcode (op, 2);
b99bd4ef 2337 }
c19d1205 2338 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2339}
2340
c19d1205
ZW
2341
2342/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2343
2344static void
c19d1205 2345s_arm_unwind_save_vfp (void)
b99bd4ef 2346{
c19d1205 2347 int count;
ca3f61f7 2348 unsigned int reg;
c19d1205 2349 valueT op;
b99bd4ef 2350
c19d1205
ZW
2351 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2352 if (count == FAIL)
b99bd4ef 2353 {
c19d1205
ZW
2354 as_bad (_("expected register list"));
2355 ignore_rest_of_line ();
b99bd4ef
NC
2356 return;
2357 }
2358
c19d1205 2359 demand_empty_rest_of_line ();
b99bd4ef 2360
c19d1205 2361 if (reg == 8)
b99bd4ef 2362 {
c19d1205
ZW
2363 /* Short form. */
2364 op = 0xb8 | (count - 1);
2365 add_unwind_opcode (op, 1);
b99bd4ef 2366 }
c19d1205 2367 else
b99bd4ef 2368 {
c19d1205
ZW
2369 /* Long form. */
2370 op = 0xb300 | (reg << 4) | (count - 1);
2371 add_unwind_opcode (op, 2);
b99bd4ef 2372 }
c19d1205
ZW
2373 unwind.frame_size += count * 8 + 4;
2374}
b99bd4ef 2375
b99bd4ef 2376
c19d1205
ZW
2377/* Parse a directive saving iWMMXt data registers. */
2378
2379static void
2380s_arm_unwind_save_mmxwr (void)
2381{
2382 int reg;
2383 int hi_reg;
2384 int i;
2385 unsigned mask = 0;
2386 valueT op;
b99bd4ef 2387
c19d1205
ZW
2388 if (*input_line_pointer == '{')
2389 input_line_pointer++;
b99bd4ef 2390
c19d1205 2391 do
b99bd4ef 2392 {
c19d1205 2393 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2394
c19d1205 2395 if (reg == FAIL)
b99bd4ef 2396 {
c19d1205
ZW
2397 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2398 goto error;
b99bd4ef
NC
2399 }
2400
c19d1205
ZW
2401 if (mask >> reg)
2402 as_tsktsk (_("register list not in ascending order"));
2403 mask |= 1 << reg;
b99bd4ef 2404
c19d1205
ZW
2405 if (*input_line_pointer == '-')
2406 {
2407 input_line_pointer++;
2408 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2409 if (hi_reg == FAIL)
2410 {
2411 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2412 goto error;
2413 }
2414 else if (reg >= hi_reg)
2415 {
2416 as_bad (_("bad register range"));
2417 goto error;
2418 }
2419 for (; reg < hi_reg; reg++)
2420 mask |= 1 << reg;
2421 }
2422 }
2423 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2424
c19d1205
ZW
2425 if (*input_line_pointer == '}')
2426 input_line_pointer++;
b99bd4ef 2427
c19d1205 2428 demand_empty_rest_of_line ();
b99bd4ef 2429
c19d1205
ZW
2430 /* Generate any deferred opcodes becuuse we're going to be looking at
2431 the list. */
2432 flush_pending_unwind ();
b99bd4ef 2433
c19d1205 2434 for (i = 0; i < 16; i++)
b99bd4ef 2435 {
c19d1205
ZW
2436 if (mask & (1 << i))
2437 unwind.frame_size += 8;
b99bd4ef
NC
2438 }
2439
c19d1205
ZW
2440 /* Attempt to combine with a previous opcode. We do this because gcc
2441 likes to output separate unwind directives for a single block of
2442 registers. */
2443 if (unwind.opcode_count > 0)
b99bd4ef 2444 {
c19d1205
ZW
2445 i = unwind.opcodes[unwind.opcode_count - 1];
2446 if ((i & 0xf8) == 0xc0)
2447 {
2448 i &= 7;
2449 /* Only merge if the blocks are contiguous. */
2450 if (i < 6)
2451 {
2452 if ((mask & 0xfe00) == (1 << 9))
2453 {
2454 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2455 unwind.opcode_count--;
2456 }
2457 }
2458 else if (i == 6 && unwind.opcode_count >= 2)
2459 {
2460 i = unwind.opcodes[unwind.opcode_count - 2];
2461 reg = i >> 4;
2462 i &= 0xf;
b99bd4ef 2463
c19d1205
ZW
2464 op = 0xffff << (reg - 1);
2465 if (reg > 0
2466 || ((mask & op) == (1u << (reg - 1))))
2467 {
2468 op = (1 << (reg + i + 1)) - 1;
2469 op &= ~((1 << reg) - 1);
2470 mask |= op;
2471 unwind.opcode_count -= 2;
2472 }
2473 }
2474 }
b99bd4ef
NC
2475 }
2476
c19d1205
ZW
2477 hi_reg = 15;
2478 /* We want to generate opcodes in the order the registers have been
2479 saved, ie. descending order. */
2480 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2481 {
c19d1205
ZW
2482 /* Save registers in blocks. */
2483 if (reg < 0
2484 || !(mask & (1 << reg)))
2485 {
2486 /* We found an unsaved reg. Generate opcodes to save the
2487 preceeding block. */
2488 if (reg != hi_reg)
2489 {
2490 if (reg == 9)
2491 {
2492 /* Short form. */
2493 op = 0xc0 | (hi_reg - 10);
2494 add_unwind_opcode (op, 1);
2495 }
2496 else
2497 {
2498 /* Long form. */
2499 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2500 add_unwind_opcode (op, 2);
2501 }
2502 }
2503 hi_reg = reg - 1;
2504 }
b99bd4ef
NC
2505 }
2506
c19d1205
ZW
2507 return;
2508error:
2509 ignore_rest_of_line ();
b99bd4ef
NC
2510}
2511
2512static void
c19d1205 2513s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2514{
c19d1205
ZW
2515 int reg;
2516 int hi_reg;
2517 unsigned mask = 0;
2518 valueT op;
b99bd4ef 2519
c19d1205
ZW
2520 if (*input_line_pointer == '{')
2521 input_line_pointer++;
b99bd4ef 2522
c19d1205 2523 do
b99bd4ef 2524 {
c19d1205 2525 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2526
c19d1205
ZW
2527 if (reg == FAIL)
2528 {
2529 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2530 goto error;
2531 }
b99bd4ef 2532
c19d1205
ZW
2533 reg -= 8;
2534 if (mask >> reg)
2535 as_tsktsk (_("register list not in ascending order"));
2536 mask |= 1 << reg;
b99bd4ef 2537
c19d1205
ZW
2538 if (*input_line_pointer == '-')
2539 {
2540 input_line_pointer++;
2541 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2542 if (hi_reg == FAIL)
2543 {
2544 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2545 goto error;
2546 }
2547 else if (reg >= hi_reg)
2548 {
2549 as_bad (_("bad register range"));
2550 goto error;
2551 }
2552 for (; reg < hi_reg; reg++)
2553 mask |= 1 << reg;
2554 }
b99bd4ef 2555 }
c19d1205 2556 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2557
c19d1205
ZW
2558 if (*input_line_pointer == '}')
2559 input_line_pointer++;
b99bd4ef 2560
c19d1205
ZW
2561 demand_empty_rest_of_line ();
2562
2563 /* Generate any deferred opcodes becuuse we're going to be looking at
2564 the list. */
2565 flush_pending_unwind ();
b99bd4ef 2566
c19d1205 2567 for (reg = 0; reg < 16; reg++)
b99bd4ef 2568 {
c19d1205
ZW
2569 if (mask & (1 << reg))
2570 unwind.frame_size += 4;
b99bd4ef 2571 }
c19d1205
ZW
2572 op = 0xc700 | mask;
2573 add_unwind_opcode (op, 2);
2574 return;
2575error:
2576 ignore_rest_of_line ();
b99bd4ef
NC
2577}
2578
c19d1205
ZW
2579
2580/* Parse an unwind_save directive. */
2581
b99bd4ef 2582static void
c19d1205 2583s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2584{
c19d1205
ZW
2585 char *peek;
2586 struct reg_entry *reg;
2587 bfd_boolean had_brace = FALSE;
b99bd4ef 2588
c19d1205
ZW
2589 /* Figure out what sort of save we have. */
2590 peek = input_line_pointer;
b99bd4ef 2591
c19d1205 2592 if (*peek == '{')
b99bd4ef 2593 {
c19d1205
ZW
2594 had_brace = TRUE;
2595 peek++;
b99bd4ef
NC
2596 }
2597
c19d1205 2598 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2599
c19d1205 2600 if (!reg)
b99bd4ef 2601 {
c19d1205
ZW
2602 as_bad (_("register expected"));
2603 ignore_rest_of_line ();
b99bd4ef
NC
2604 return;
2605 }
2606
c19d1205 2607 switch (reg->type)
b99bd4ef 2608 {
c19d1205
ZW
2609 case REG_TYPE_FN:
2610 if (had_brace)
2611 {
2612 as_bad (_("FPA .unwind_save does not take a register list"));
2613 ignore_rest_of_line ();
2614 return;
2615 }
2616 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2617 return;
c19d1205
ZW
2618
2619 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2620 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2621 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2622 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2623
2624 default:
2625 as_bad (_(".unwind_save does not support this kind of register"));
2626 ignore_rest_of_line ();
b99bd4ef 2627 }
c19d1205 2628}
b99bd4ef 2629
b99bd4ef 2630
c19d1205
ZW
2631/* Parse an unwind_movsp directive. */
2632
2633static void
2634s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2635{
2636 int reg;
2637 valueT op;
2638
2639 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2640 if (reg == FAIL)
b99bd4ef 2641 {
c19d1205
ZW
2642 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2643 ignore_rest_of_line ();
b99bd4ef
NC
2644 return;
2645 }
c19d1205 2646 demand_empty_rest_of_line ();
b99bd4ef 2647
c19d1205 2648 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2649 {
c19d1205 2650 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2651 return;
2652 }
2653
c19d1205
ZW
2654 if (unwind.fp_reg != REG_SP)
2655 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2656
c19d1205
ZW
2657 /* Generate opcode to restore the value. */
2658 op = 0x90 | reg;
2659 add_unwind_opcode (op, 1);
2660
2661 /* Record the information for later. */
2662 unwind.fp_reg = reg;
2663 unwind.fp_offset = unwind.frame_size;
2664 unwind.sp_restored = 1;
b05fe5cf
ZW
2665}
2666
c19d1205
ZW
2667/* Parse an unwind_pad directive. */
2668
b05fe5cf 2669static void
c19d1205 2670s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2671{
c19d1205 2672 int offset;
b05fe5cf 2673
c19d1205
ZW
2674 if (immediate_for_directive (&offset) == FAIL)
2675 return;
b99bd4ef 2676
c19d1205
ZW
2677 if (offset & 3)
2678 {
2679 as_bad (_("stack increment must be multiple of 4"));
2680 ignore_rest_of_line ();
2681 return;
2682 }
b99bd4ef 2683
c19d1205
ZW
2684 /* Don't generate any opcodes, just record the details for later. */
2685 unwind.frame_size += offset;
2686 unwind.pending_offset += offset;
2687
2688 demand_empty_rest_of_line ();
2689}
2690
2691/* Parse an unwind_setfp directive. */
2692
2693static void
2694s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2695{
c19d1205
ZW
2696 int sp_reg;
2697 int fp_reg;
2698 int offset;
2699
2700 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2701 if (skip_past_comma (&input_line_pointer) == FAIL)
2702 sp_reg = FAIL;
2703 else
2704 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2705
c19d1205
ZW
2706 if (fp_reg == FAIL || sp_reg == FAIL)
2707 {
2708 as_bad (_("expected <reg>, <reg>"));
2709 ignore_rest_of_line ();
2710 return;
2711 }
b99bd4ef 2712
c19d1205
ZW
2713 /* Optional constant. */
2714 if (skip_past_comma (&input_line_pointer) != FAIL)
2715 {
2716 if (immediate_for_directive (&offset) == FAIL)
2717 return;
2718 }
2719 else
2720 offset = 0;
a737bd4d 2721
c19d1205 2722 demand_empty_rest_of_line ();
a737bd4d 2723
c19d1205 2724 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2725 {
c19d1205
ZW
2726 as_bad (_("register must be either sp or set by a previous"
2727 "unwind_movsp directive"));
2728 return;
a737bd4d
NC
2729 }
2730
c19d1205
ZW
2731 /* Don't generate any opcodes, just record the information for later. */
2732 unwind.fp_reg = fp_reg;
2733 unwind.fp_used = 1;
2734 if (sp_reg == 13)
2735 unwind.fp_offset = unwind.frame_size - offset;
2736 else
2737 unwind.fp_offset -= offset;
a737bd4d
NC
2738}
2739
c19d1205
ZW
2740/* Parse an unwind_raw directive. */
2741
2742static void
2743s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2744{
c19d1205
ZW
2745 expressionS exp;
2746 /* This is an arbitary limit. */
2747 unsigned char op[16];
2748 int count;
a737bd4d 2749
c19d1205
ZW
2750 expression (&exp);
2751 if (exp.X_op == O_constant
2752 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2753 {
c19d1205
ZW
2754 unwind.frame_size += exp.X_add_number;
2755 expression (&exp);
2756 }
2757 else
2758 exp.X_op = O_illegal;
a737bd4d 2759
c19d1205
ZW
2760 if (exp.X_op != O_constant)
2761 {
2762 as_bad (_("expected <offset>, <opcode>"));
2763 ignore_rest_of_line ();
2764 return;
2765 }
a737bd4d 2766
c19d1205 2767 count = 0;
a737bd4d 2768
c19d1205
ZW
2769 /* Parse the opcode. */
2770 for (;;)
2771 {
2772 if (count >= 16)
2773 {
2774 as_bad (_("unwind opcode too long"));
2775 ignore_rest_of_line ();
a737bd4d 2776 }
c19d1205 2777 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2778 {
c19d1205
ZW
2779 as_bad (_("invalid unwind opcode"));
2780 ignore_rest_of_line ();
2781 return;
a737bd4d 2782 }
c19d1205 2783 op[count++] = exp.X_add_number;
a737bd4d 2784
c19d1205
ZW
2785 /* Parse the next byte. */
2786 if (skip_past_comma (&input_line_pointer) == FAIL)
2787 break;
a737bd4d 2788
c19d1205
ZW
2789 expression (&exp);
2790 }
b99bd4ef 2791
c19d1205
ZW
2792 /* Add the opcode bytes in reverse order. */
2793 while (count--)
2794 add_unwind_opcode (op[count], 1);
b99bd4ef 2795
c19d1205 2796 demand_empty_rest_of_line ();
b99bd4ef 2797}
ee065d83
PB
2798
2799
2800/* Parse a .eabi_attribute directive. */
2801
2802static void
2803s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
2804{
2805 expressionS exp;
2806 bfd_boolean is_string;
2807 int tag;
2808 unsigned int i = 0;
2809 char *s = NULL;
2810 char saved_char;
2811
2812 expression (& exp);
2813 if (exp.X_op != O_constant)
2814 goto bad;
2815
2816 tag = exp.X_add_number;
2817 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
2818 is_string = 1;
2819 else
2820 is_string = 0;
2821
2822 if (skip_past_comma (&input_line_pointer) == FAIL)
2823 goto bad;
2824 if (tag == 32 || !is_string)
2825 {
2826 expression (& exp);
2827 if (exp.X_op != O_constant)
2828 {
2829 as_bad (_("expected numeric constant"));
2830 ignore_rest_of_line ();
2831 return;
2832 }
2833 i = exp.X_add_number;
2834 }
2835 if (tag == Tag_compatibility
2836 && skip_past_comma (&input_line_pointer) == FAIL)
2837 {
2838 as_bad (_("expected comma"));
2839 ignore_rest_of_line ();
2840 return;
2841 }
2842 if (is_string)
2843 {
2844 skip_whitespace(input_line_pointer);
2845 if (*input_line_pointer != '"')
2846 goto bad_string;
2847 input_line_pointer++;
2848 s = input_line_pointer;
2849 while (*input_line_pointer && *input_line_pointer != '"')
2850 input_line_pointer++;
2851 if (*input_line_pointer != '"')
2852 goto bad_string;
2853 saved_char = *input_line_pointer;
2854 *input_line_pointer = 0;
2855 }
2856 else
2857 {
2858 s = NULL;
2859 saved_char = 0;
2860 }
2861
2862 if (tag == Tag_compatibility)
2863 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
2864 else if (is_string)
2865 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
2866 else
2867 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
2868
2869 if (s)
2870 {
2871 *input_line_pointer = saved_char;
2872 input_line_pointer++;
2873 }
2874 demand_empty_rest_of_line ();
2875 return;
2876bad_string:
2877 as_bad (_("bad string constant"));
2878 ignore_rest_of_line ();
2879 return;
2880bad:
2881 as_bad (_("expected <tag> , <value>"));
2882 ignore_rest_of_line ();
2883}
2884
2885static void s_arm_arch (int);
2886static void s_arm_cpu (int);
2887static void s_arm_fpu (int);
c19d1205 2888#endif /* OBJ_ELF */
b99bd4ef 2889
c19d1205
ZW
2890/* This table describes all the machine specific pseudo-ops the assembler
2891 has to support. The fields are:
2892 pseudo-op name without dot
2893 function to call to execute this pseudo-op
2894 Integer arg to pass to the function. */
b99bd4ef 2895
c19d1205 2896const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2897{
c19d1205
ZW
2898 /* Never called because '.req' does not start a line. */
2899 { "req", s_req, 0 },
2900 { "unreq", s_unreq, 0 },
2901 { "bss", s_bss, 0 },
2902 { "align", s_align, 0 },
2903 { "arm", s_arm, 0 },
2904 { "thumb", s_thumb, 0 },
2905 { "code", s_code, 0 },
2906 { "force_thumb", s_force_thumb, 0 },
2907 { "thumb_func", s_thumb_func, 0 },
2908 { "thumb_set", s_thumb_set, 0 },
2909 { "even", s_even, 0 },
2910 { "ltorg", s_ltorg, 0 },
2911 { "pool", s_ltorg, 0 },
2912 { "syntax", s_syntax, 0 },
2913#ifdef OBJ_ELF
2914 { "word", s_arm_elf_cons, 4 },
2915 { "long", s_arm_elf_cons, 4 },
2916 { "rel31", s_arm_rel31, 0 },
2917 { "fnstart", s_arm_unwind_fnstart, 0 },
2918 { "fnend", s_arm_unwind_fnend, 0 },
2919 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2920 { "personality", s_arm_unwind_personality, 0 },
2921 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2922 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2923 { "save", s_arm_unwind_save, 0 },
2924 { "movsp", s_arm_unwind_movsp, 0 },
2925 { "pad", s_arm_unwind_pad, 0 },
2926 { "setfp", s_arm_unwind_setfp, 0 },
2927 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83
PB
2928 { "cpu", s_arm_cpu, 0 },
2929 { "arch", s_arm_arch, 0 },
2930 { "fpu", s_arm_fpu, 0 },
2931 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
2932#else
2933 { "word", cons, 4},
2934#endif
2935 { "extend", float_cons, 'x' },
2936 { "ldouble", float_cons, 'x' },
2937 { "packed", float_cons, 'p' },
2938 { 0, 0, 0 }
2939};
2940\f
2941/* Parser functions used exclusively in instruction operands. */
b99bd4ef 2942
c19d1205
ZW
2943/* Generic immediate-value read function for use in insn parsing.
2944 STR points to the beginning of the immediate (the leading #);
2945 VAL receives the value; if the value is outside [MIN, MAX]
2946 issue an error. PREFIX_OPT is true if the immediate prefix is
2947 optional. */
b99bd4ef 2948
c19d1205
ZW
2949static int
2950parse_immediate (char **str, int *val, int min, int max,
2951 bfd_boolean prefix_opt)
2952{
2953 expressionS exp;
2954 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2955 if (exp.X_op != O_constant)
b99bd4ef 2956 {
c19d1205
ZW
2957 inst.error = _("constant expression required");
2958 return FAIL;
2959 }
b99bd4ef 2960
c19d1205
ZW
2961 if (exp.X_add_number < min || exp.X_add_number > max)
2962 {
2963 inst.error = _("immediate value out of range");
2964 return FAIL;
2965 }
b99bd4ef 2966
c19d1205
ZW
2967 *val = exp.X_add_number;
2968 return SUCCESS;
2969}
b99bd4ef 2970
c19d1205
ZW
2971/* Returns the pseudo-register number of an FPA immediate constant,
2972 or FAIL if there isn't a valid constant here. */
b99bd4ef 2973
c19d1205
ZW
2974static int
2975parse_fpa_immediate (char ** str)
2976{
2977 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2978 char * save_in;
2979 expressionS exp;
2980 int i;
2981 int j;
b99bd4ef 2982
c19d1205
ZW
2983 /* First try and match exact strings, this is to guarantee
2984 that some formats will work even for cross assembly. */
b99bd4ef 2985
c19d1205
ZW
2986 for (i = 0; fp_const[i]; i++)
2987 {
2988 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 2989 {
c19d1205 2990 char *start = *str;
b99bd4ef 2991
c19d1205
ZW
2992 *str += strlen (fp_const[i]);
2993 if (is_end_of_line[(unsigned char) **str])
2994 return i + 8;
2995 *str = start;
2996 }
2997 }
b99bd4ef 2998
c19d1205
ZW
2999 /* Just because we didn't get a match doesn't mean that the constant
3000 isn't valid, just that it is in a format that we don't
3001 automatically recognize. Try parsing it with the standard
3002 expression routines. */
b99bd4ef 3003
c19d1205 3004 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 3005
c19d1205
ZW
3006 /* Look for a raw floating point number. */
3007 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3008 && is_end_of_line[(unsigned char) *save_in])
3009 {
3010 for (i = 0; i < NUM_FLOAT_VALS; i++)
3011 {
3012 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 3013 {
c19d1205
ZW
3014 if (words[j] != fp_values[i][j])
3015 break;
b99bd4ef
NC
3016 }
3017
c19d1205 3018 if (j == MAX_LITTLENUMS)
b99bd4ef 3019 {
c19d1205
ZW
3020 *str = save_in;
3021 return i + 8;
b99bd4ef
NC
3022 }
3023 }
3024 }
b99bd4ef 3025
c19d1205
ZW
3026 /* Try and parse a more complex expression, this will probably fail
3027 unless the code uses a floating point prefix (eg "0f"). */
3028 save_in = input_line_pointer;
3029 input_line_pointer = *str;
3030 if (expression (&exp) == absolute_section
3031 && exp.X_op == O_big
3032 && exp.X_add_number < 0)
3033 {
3034 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3035 Ditto for 15. */
3036 if (gen_to_words (words, 5, (long) 15) == 0)
3037 {
3038 for (i = 0; i < NUM_FLOAT_VALS; i++)
3039 {
3040 for (j = 0; j < MAX_LITTLENUMS; j++)
3041 {
3042 if (words[j] != fp_values[i][j])
3043 break;
3044 }
b99bd4ef 3045
c19d1205
ZW
3046 if (j == MAX_LITTLENUMS)
3047 {
3048 *str = input_line_pointer;
3049 input_line_pointer = save_in;
3050 return i + 8;
3051 }
3052 }
3053 }
b99bd4ef
NC
3054 }
3055
c19d1205
ZW
3056 *str = input_line_pointer;
3057 input_line_pointer = save_in;
3058 inst.error = _("invalid FPA immediate expression");
3059 return FAIL;
b99bd4ef
NC
3060}
3061
c19d1205
ZW
3062/* Shift operands. */
3063enum shift_kind
b99bd4ef 3064{
c19d1205
ZW
3065 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
3066};
b99bd4ef 3067
c19d1205
ZW
3068struct asm_shift_name
3069{
3070 const char *name;
3071 enum shift_kind kind;
3072};
b99bd4ef 3073
c19d1205
ZW
3074/* Third argument to parse_shift. */
3075enum parse_shift_mode
3076{
3077 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
3078 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
3079 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
3080 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
3081 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
3082};
b99bd4ef 3083
c19d1205
ZW
3084/* Parse a <shift> specifier on an ARM data processing instruction.
3085 This has three forms:
b99bd4ef 3086
c19d1205
ZW
3087 (LSL|LSR|ASL|ASR|ROR) Rs
3088 (LSL|LSR|ASL|ASR|ROR) #imm
3089 RRX
b99bd4ef 3090
c19d1205
ZW
3091 Note that ASL is assimilated to LSL in the instruction encoding, and
3092 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 3093
c19d1205
ZW
3094static int
3095parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 3096{
c19d1205
ZW
3097 const struct asm_shift_name *shift_name;
3098 enum shift_kind shift;
3099 char *s = *str;
3100 char *p = s;
3101 int reg;
b99bd4ef 3102
c19d1205
ZW
3103 for (p = *str; ISALPHA (*p); p++)
3104 ;
b99bd4ef 3105
c19d1205 3106 if (p == *str)
b99bd4ef 3107 {
c19d1205
ZW
3108 inst.error = _("shift expression expected");
3109 return FAIL;
b99bd4ef
NC
3110 }
3111
c19d1205
ZW
3112 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3113
3114 if (shift_name == NULL)
b99bd4ef 3115 {
c19d1205
ZW
3116 inst.error = _("shift expression expected");
3117 return FAIL;
b99bd4ef
NC
3118 }
3119
c19d1205 3120 shift = shift_name->kind;
b99bd4ef 3121
c19d1205
ZW
3122 switch (mode)
3123 {
3124 case NO_SHIFT_RESTRICT:
3125 case SHIFT_IMMEDIATE: break;
b99bd4ef 3126
c19d1205
ZW
3127 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3128 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3129 {
3130 inst.error = _("'LSL' or 'ASR' required");
3131 return FAIL;
3132 }
3133 break;
b99bd4ef 3134
c19d1205
ZW
3135 case SHIFT_LSL_IMMEDIATE:
3136 if (shift != SHIFT_LSL)
3137 {
3138 inst.error = _("'LSL' required");
3139 return FAIL;
3140 }
3141 break;
b99bd4ef 3142
c19d1205
ZW
3143 case SHIFT_ASR_IMMEDIATE:
3144 if (shift != SHIFT_ASR)
3145 {
3146 inst.error = _("'ASR' required");
3147 return FAIL;
3148 }
3149 break;
b99bd4ef 3150
c19d1205
ZW
3151 default: abort ();
3152 }
b99bd4ef 3153
c19d1205
ZW
3154 if (shift != SHIFT_RRX)
3155 {
3156 /* Whitespace can appear here if the next thing is a bare digit. */
3157 skip_whitespace (p);
b99bd4ef 3158
c19d1205
ZW
3159 if (mode == NO_SHIFT_RESTRICT
3160 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3161 {
3162 inst.operands[i].imm = reg;
3163 inst.operands[i].immisreg = 1;
3164 }
3165 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3166 return FAIL;
3167 }
3168 inst.operands[i].shift_kind = shift;
3169 inst.operands[i].shifted = 1;
3170 *str = p;
3171 return SUCCESS;
b99bd4ef
NC
3172}
3173
c19d1205 3174/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3175
c19d1205
ZW
3176 #<immediate>
3177 #<immediate>, <rotate>
3178 <Rm>
3179 <Rm>, <shift>
b99bd4ef 3180
c19d1205
ZW
3181 where <shift> is defined by parse_shift above, and <rotate> is a
3182 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3183 is deferred to md_apply_fix. */
b99bd4ef 3184
c19d1205
ZW
3185static int
3186parse_shifter_operand (char **str, int i)
3187{
3188 int value;
3189 expressionS expr;
b99bd4ef 3190
c19d1205
ZW
3191 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3192 {
3193 inst.operands[i].reg = value;
3194 inst.operands[i].isreg = 1;
b99bd4ef 3195
c19d1205
ZW
3196 /* parse_shift will override this if appropriate */
3197 inst.reloc.exp.X_op = O_constant;
3198 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3199
c19d1205
ZW
3200 if (skip_past_comma (str) == FAIL)
3201 return SUCCESS;
b99bd4ef 3202
c19d1205
ZW
3203 /* Shift operation on register. */
3204 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3205 }
3206
c19d1205
ZW
3207 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3208 return FAIL;
b99bd4ef 3209
c19d1205 3210 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3211 {
c19d1205
ZW
3212 /* #x, y -- ie explicit rotation by Y. */
3213 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3214 return FAIL;
b99bd4ef 3215
c19d1205
ZW
3216 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3217 {
3218 inst.error = _("constant expression expected");
3219 return FAIL;
3220 }
b99bd4ef 3221
c19d1205
ZW
3222 value = expr.X_add_number;
3223 if (value < 0 || value > 30 || value % 2 != 0)
3224 {
3225 inst.error = _("invalid rotation");
3226 return FAIL;
3227 }
3228 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3229 {
3230 inst.error = _("invalid constant");
3231 return FAIL;
3232 }
09d92015 3233
55cf6793 3234 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3235 inst.reloc.exp.X_add_number
3236 = (((inst.reloc.exp.X_add_number << (32 - value))
3237 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3238 }
3239
c19d1205
ZW
3240 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3241 inst.reloc.pc_rel = 0;
3242 return SUCCESS;
09d92015
MM
3243}
3244
c19d1205
ZW
3245/* Parse all forms of an ARM address expression. Information is written
3246 to inst.operands[i] and/or inst.reloc.
09d92015 3247
c19d1205 3248 Preindexed addressing (.preind=1):
09d92015 3249
c19d1205
ZW
3250 [Rn, #offset] .reg=Rn .reloc.exp=offset
3251 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3252 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3253 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3254
c19d1205 3255 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3256
c19d1205 3257 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3258
c19d1205
ZW
3259 [Rn], #offset .reg=Rn .reloc.exp=offset
3260 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3261 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3262 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3263
c19d1205 3264 Unindexed addressing (.preind=0, .postind=0):
09d92015 3265
c19d1205 3266 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3267
c19d1205 3268 Other:
09d92015 3269
c19d1205
ZW
3270 [Rn]{!} shorthand for [Rn,#0]{!}
3271 =immediate .isreg=0 .reloc.exp=immediate
3272 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3273
c19d1205
ZW
3274 It is the caller's responsibility to check for addressing modes not
3275 supported by the instruction, and to set inst.reloc.type. */
3276
3277static int
3278parse_address (char **str, int i)
09d92015 3279{
c19d1205
ZW
3280 char *p = *str;
3281 int reg;
09d92015 3282
c19d1205 3283 if (skip_past_char (&p, '[') == FAIL)
09d92015 3284 {
c19d1205
ZW
3285 if (skip_past_char (&p, '=') == FAIL)
3286 {
3287 /* bare address - translate to PC-relative offset */
3288 inst.reloc.pc_rel = 1;
3289 inst.operands[i].reg = REG_PC;
3290 inst.operands[i].isreg = 1;
3291 inst.operands[i].preind = 1;
3292 }
3293 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3294
c19d1205
ZW
3295 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3296 return FAIL;
09d92015 3297
c19d1205
ZW
3298 *str = p;
3299 return SUCCESS;
09d92015
MM
3300 }
3301
c19d1205 3302 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3303 {
c19d1205
ZW
3304 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3305 return FAIL;
09d92015 3306 }
c19d1205
ZW
3307 inst.operands[i].reg = reg;
3308 inst.operands[i].isreg = 1;
09d92015 3309
c19d1205 3310 if (skip_past_comma (&p) == SUCCESS)
09d92015 3311 {
c19d1205 3312 inst.operands[i].preind = 1;
09d92015 3313
c19d1205
ZW
3314 if (*p == '+') p++;
3315 else if (*p == '-') p++, inst.operands[i].negative = 1;
3316
3317 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3318 {
c19d1205
ZW
3319 inst.operands[i].imm = reg;
3320 inst.operands[i].immisreg = 1;
3321
3322 if (skip_past_comma (&p) == SUCCESS)
3323 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3324 return FAIL;
3325 }
3326 else
3327 {
3328 if (inst.operands[i].negative)
3329 {
3330 inst.operands[i].negative = 0;
3331 p--;
3332 }
3333 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3334 return FAIL;
09d92015
MM
3335 }
3336 }
3337
c19d1205 3338 if (skip_past_char (&p, ']') == FAIL)
09d92015 3339 {
c19d1205
ZW
3340 inst.error = _("']' expected");
3341 return FAIL;
09d92015
MM
3342 }
3343
c19d1205
ZW
3344 if (skip_past_char (&p, '!') == SUCCESS)
3345 inst.operands[i].writeback = 1;
09d92015 3346
c19d1205 3347 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3348 {
c19d1205
ZW
3349 if (skip_past_char (&p, '{') == SUCCESS)
3350 {
3351 /* [Rn], {expr} - unindexed, with option */
3352 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 3353 0, 255, TRUE) == FAIL)
c19d1205 3354 return FAIL;
09d92015 3355
c19d1205
ZW
3356 if (skip_past_char (&p, '}') == FAIL)
3357 {
3358 inst.error = _("'}' expected at end of 'option' field");
3359 return FAIL;
3360 }
3361 if (inst.operands[i].preind)
3362 {
3363 inst.error = _("cannot combine index with option");
3364 return FAIL;
3365 }
3366 *str = p;
3367 return SUCCESS;
09d92015 3368 }
c19d1205
ZW
3369 else
3370 {
3371 inst.operands[i].postind = 1;
3372 inst.operands[i].writeback = 1;
09d92015 3373
c19d1205
ZW
3374 if (inst.operands[i].preind)
3375 {
3376 inst.error = _("cannot combine pre- and post-indexing");
3377 return FAIL;
3378 }
09d92015 3379
c19d1205
ZW
3380 if (*p == '+') p++;
3381 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3382
c19d1205
ZW
3383 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3384 {
3385 inst.operands[i].imm = reg;
3386 inst.operands[i].immisreg = 1;
a737bd4d 3387
c19d1205
ZW
3388 if (skip_past_comma (&p) == SUCCESS)
3389 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3390 return FAIL;
3391 }
3392 else
3393 {
3394 if (inst.operands[i].negative)
3395 {
3396 inst.operands[i].negative = 0;
3397 p--;
3398 }
3399 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3400 return FAIL;
3401 }
3402 }
a737bd4d
NC
3403 }
3404
c19d1205
ZW
3405 /* If at this point neither .preind nor .postind is set, we have a
3406 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3407 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3408 {
3409 inst.operands[i].preind = 1;
3410 inst.reloc.exp.X_op = O_constant;
3411 inst.reloc.exp.X_add_number = 0;
3412 }
3413 *str = p;
3414 return SUCCESS;
a737bd4d
NC
3415}
3416
c19d1205 3417/* Miscellaneous. */
a737bd4d 3418
c19d1205
ZW
3419/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3420 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3421static int
3422parse_psr (char **str)
09d92015 3423{
c19d1205
ZW
3424 char *p;
3425 unsigned long psr_field;
09d92015 3426
c19d1205
ZW
3427 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3428 feature for ease of use and backwards compatibility. */
3429 p = *str;
3430 if (*p == 's' || *p == 'S')
3431 psr_field = SPSR_BIT;
3432 else if (*p == 'c' || *p == 'C')
3433 psr_field = 0;
3434 else
3435 goto error;
09d92015 3436
c19d1205
ZW
3437 p++;
3438 if (strncasecmp (p, "PSR", 3) != 0)
3439 goto error;
3440 p += 3;
09d92015 3441
c19d1205
ZW
3442 if (*p == '_')
3443 {
3444 /* A suffix follows. */
3445 const struct asm_psr *psr;
3446 char *start;
a737bd4d 3447
c19d1205
ZW
3448 p++;
3449 start = p;
a737bd4d 3450
c19d1205
ZW
3451 do
3452 p++;
3453 while (ISALNUM (*p) || *p == '_');
a737bd4d 3454
c19d1205
ZW
3455 psr = hash_find_n (arm_psr_hsh, start, p - start);
3456 if (!psr)
3457 goto error;
a737bd4d 3458
c19d1205 3459 psr_field |= psr->field;
a737bd4d 3460 }
c19d1205 3461 else
a737bd4d 3462 {
c19d1205
ZW
3463 if (ISALNUM (*p))
3464 goto error; /* Garbage after "[CS]PSR". */
3465
3466 psr_field |= (PSR_c | PSR_f);
a737bd4d 3467 }
c19d1205
ZW
3468 *str = p;
3469 return psr_field;
a737bd4d 3470
c19d1205
ZW
3471 error:
3472 inst.error = _("flag for {c}psr instruction expected");
3473 return FAIL;
a737bd4d
NC
3474}
3475
c19d1205
ZW
3476/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3477 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3478
c19d1205
ZW
3479static int
3480parse_cps_flags (char **str)
a737bd4d 3481{
c19d1205
ZW
3482 int val = 0;
3483 int saw_a_flag = 0;
3484 char *s = *str;
a737bd4d 3485
c19d1205
ZW
3486 for (;;)
3487 switch (*s++)
3488 {
3489 case '\0': case ',':
3490 goto done;
a737bd4d 3491
c19d1205
ZW
3492 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3493 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3494 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3495
c19d1205
ZW
3496 default:
3497 inst.error = _("unrecognized CPS flag");
3498 return FAIL;
3499 }
a737bd4d 3500
c19d1205
ZW
3501 done:
3502 if (saw_a_flag == 0)
a737bd4d 3503 {
c19d1205
ZW
3504 inst.error = _("missing CPS flags");
3505 return FAIL;
a737bd4d 3506 }
a737bd4d 3507
c19d1205
ZW
3508 *str = s - 1;
3509 return val;
a737bd4d
NC
3510}
3511
c19d1205
ZW
3512/* Parse an endian specifier ("BE" or "LE", case insensitive);
3513 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3514
3515static int
c19d1205 3516parse_endian_specifier (char **str)
a737bd4d 3517{
c19d1205
ZW
3518 int little_endian;
3519 char *s = *str;
a737bd4d 3520
c19d1205
ZW
3521 if (strncasecmp (s, "BE", 2))
3522 little_endian = 0;
3523 else if (strncasecmp (s, "LE", 2))
3524 little_endian = 1;
3525 else
a737bd4d 3526 {
c19d1205 3527 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3528 return FAIL;
3529 }
3530
c19d1205 3531 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3532 {
c19d1205 3533 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3534 return FAIL;
3535 }
3536
c19d1205
ZW
3537 *str = s + 2;
3538 return little_endian;
3539}
a737bd4d 3540
c19d1205
ZW
3541/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3542 value suitable for poking into the rotate field of an sxt or sxta
3543 instruction, or FAIL on error. */
3544
3545static int
3546parse_ror (char **str)
3547{
3548 int rot;
3549 char *s = *str;
3550
3551 if (strncasecmp (s, "ROR", 3) == 0)
3552 s += 3;
3553 else
a737bd4d 3554 {
c19d1205 3555 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3556 return FAIL;
3557 }
c19d1205
ZW
3558
3559 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3560 return FAIL;
3561
3562 switch (rot)
a737bd4d 3563 {
c19d1205
ZW
3564 case 0: *str = s; return 0x0;
3565 case 8: *str = s; return 0x1;
3566 case 16: *str = s; return 0x2;
3567 case 24: *str = s; return 0x3;
3568
3569 default:
3570 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3571 return FAIL;
3572 }
c19d1205 3573}
a737bd4d 3574
c19d1205
ZW
3575/* Parse a conditional code (from conds[] below). The value returned is in the
3576 range 0 .. 14, or FAIL. */
3577static int
3578parse_cond (char **str)
3579{
3580 char *p, *q;
3581 const struct asm_cond *c;
a737bd4d 3582
c19d1205
ZW
3583 p = q = *str;
3584 while (ISALPHA (*q))
3585 q++;
a737bd4d 3586
c19d1205
ZW
3587 c = hash_find_n (arm_cond_hsh, p, q - p);
3588 if (!c)
a737bd4d 3589 {
c19d1205 3590 inst.error = _("condition required");
a737bd4d
NC
3591 return FAIL;
3592 }
3593
c19d1205
ZW
3594 *str = q;
3595 return c->value;
3596}
3597
92e90b6e
PB
3598/* Parse the operands of a table branch instruction. Similar to a memory
3599 operand. */
3600static int
3601parse_tb (char **str)
3602{
3603 char * p = *str;
3604 int reg;
3605
3606 if (skip_past_char (&p, '[') == FAIL)
3607 return FAIL;
3608
3609 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3610 {
3611 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3612 return FAIL;
3613 }
3614 inst.operands[0].reg = reg;
3615
3616 if (skip_past_comma (&p) == FAIL)
3617 return FAIL;
3618
3619 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3620 {
3621 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3622 return FAIL;
3623 }
3624 inst.operands[0].imm = reg;
3625
3626 if (skip_past_comma (&p) == SUCCESS)
3627 {
3628 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3629 return FAIL;
3630 if (inst.reloc.exp.X_add_number != 1)
3631 {
3632 inst.error = _("invalid shift");
3633 return FAIL;
3634 }
3635 inst.operands[0].shifted = 1;
3636 }
3637
3638 if (skip_past_char (&p, ']') == FAIL)
3639 {
3640 inst.error = _("']' expected");
3641 return FAIL;
3642 }
3643 *str = p;
3644 return SUCCESS;
3645}
3646
c19d1205
ZW
3647/* Matcher codes for parse_operands. */
3648enum operand_parse_code
3649{
3650 OP_stop, /* end of line */
3651
3652 OP_RR, /* ARM register */
3653 OP_RRnpc, /* ARM register, not r15 */
3654 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3655 OP_RRw, /* ARM register, not r15, optional trailing ! */
3656 OP_RCP, /* Coprocessor number */
3657 OP_RCN, /* Coprocessor register */
3658 OP_RF, /* FPA register */
3659 OP_RVS, /* VFP single precision register */
3660 OP_RVD, /* VFP double precision register */
3661 OP_RVC, /* VFP control register */
3662 OP_RMF, /* Maverick F register */
3663 OP_RMD, /* Maverick D register */
3664 OP_RMFX, /* Maverick FX register */
3665 OP_RMDX, /* Maverick DX register */
3666 OP_RMAX, /* Maverick AX register */
3667 OP_RMDS, /* Maverick DSPSC register */
3668 OP_RIWR, /* iWMMXt wR register */
3669 OP_RIWC, /* iWMMXt wC register */
3670 OP_RIWG, /* iWMMXt wCG register */
3671 OP_RXA, /* XScale accumulator register */
3672
3673 OP_REGLST, /* ARM register list */
3674 OP_VRSLST, /* VFP single-precision register list */
3675 OP_VRDLST, /* VFP double-precision register list */
3676
3677 OP_I7, /* immediate value 0 .. 7 */
3678 OP_I15, /* 0 .. 15 */
3679 OP_I16, /* 1 .. 16 */
3680 OP_I31, /* 0 .. 31 */
3681 OP_I31w, /* 0 .. 31, optional trailing ! */
3682 OP_I32, /* 1 .. 32 */
3683 OP_I63s, /* -64 .. 63 */
3684 OP_I255, /* 0 .. 255 */
3685 OP_Iffff, /* 0 .. 65535 */
3686
3687 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3688 OP_I7b, /* 0 .. 7 */
3689 OP_I15b, /* 0 .. 15 */
3690 OP_I31b, /* 0 .. 31 */
3691
3692 OP_SH, /* shifter operand */
3693 OP_ADDR, /* Memory address expression (any mode) */
3694 OP_EXP, /* arbitrary expression */
3695 OP_EXPi, /* same, with optional immediate prefix */
3696 OP_EXPr, /* same, with optional relocation suffix */
3697
3698 OP_CPSF, /* CPS flags */
3699 OP_ENDI, /* Endianness specifier */
3700 OP_PSR, /* CPSR/SPSR mask for msr */
3701 OP_COND, /* conditional code */
92e90b6e 3702 OP_TB, /* Table branch. */
c19d1205
ZW
3703
3704 OP_RRnpc_I0, /* ARM register or literal 0 */
3705 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3706 OP_RR_EXi, /* ARM register or expression with imm prefix */
3707 OP_RF_IF, /* FPA register or immediate */
3708 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3709
3710 /* Optional operands. */
3711 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3712 OP_oI31b, /* 0 .. 31 */
3713 OP_oIffffb, /* 0 .. 65535 */
3714 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3715
3716 OP_oRR, /* ARM register */
3717 OP_oRRnpc, /* ARM register, not the PC */
3718 OP_oSHll, /* LSL immediate */
3719 OP_oSHar, /* ASR immediate */
3720 OP_oSHllar, /* LSL or ASR immediate */
3721 OP_oROR, /* ROR 0/8/16/24 */
3722
3723 OP_FIRST_OPTIONAL = OP_oI7b
3724};
a737bd4d 3725
c19d1205
ZW
3726/* Generic instruction operand parser. This does no encoding and no
3727 semantic validation; it merely squirrels values away in the inst
3728 structure. Returns SUCCESS or FAIL depending on whether the
3729 specified grammar matched. */
3730static int
ca3f61f7 3731parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
3732{
3733 unsigned const char *upat = pattern;
3734 char *backtrack_pos = 0;
3735 const char *backtrack_error = 0;
3736 int i, val, backtrack_index = 0;
3737
3738#define po_char_or_fail(chr) do { \
3739 if (skip_past_char (&str, chr) == FAIL) \
3740 goto bad_args; \
3741} while (0)
3742
3743#define po_reg_or_fail(regtype) do { \
3744 val = arm_reg_parse (&str, regtype); \
3745 if (val == FAIL) \
3746 { \
3747 inst.error = _(reg_expected_msgs[regtype]); \
3748 goto failure; \
3749 } \
3750 inst.operands[i].reg = val; \
3751 inst.operands[i].isreg = 1; \
3752} while (0)
3753
3754#define po_reg_or_goto(regtype, label) do { \
3755 val = arm_reg_parse (&str, regtype); \
3756 if (val == FAIL) \
3757 goto label; \
3758 \
3759 inst.operands[i].reg = val; \
3760 inst.operands[i].isreg = 1; \
3761} while (0)
3762
3763#define po_imm_or_fail(min, max, popt) do { \
3764 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3765 goto failure; \
3766 inst.operands[i].imm = val; \
3767} while (0)
3768
3769#define po_misc_or_fail(expr) do { \
3770 if (expr) \
3771 goto failure; \
3772} while (0)
3773
3774 skip_whitespace (str);
3775
3776 for (i = 0; upat[i] != OP_stop; i++)
3777 {
3778 if (upat[i] >= OP_FIRST_OPTIONAL)
3779 {
3780 /* Remember where we are in case we need to backtrack. */
3781 assert (!backtrack_pos);
3782 backtrack_pos = str;
3783 backtrack_error = inst.error;
3784 backtrack_index = i;
3785 }
3786
3787 if (i > 0)
3788 po_char_or_fail (',');
3789
3790 switch (upat[i])
3791 {
3792 /* Registers */
3793 case OP_oRRnpc:
3794 case OP_RRnpc:
3795 case OP_oRR:
3796 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3797 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3798 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3799 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3800 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3801 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3802 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3803 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3804 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3805 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3806 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3807 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3808 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3809 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3810 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3811 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3812 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3813
3814 case OP_RRnpcb:
3815 po_char_or_fail ('[');
3816 po_reg_or_fail (REG_TYPE_RN);
3817 po_char_or_fail (']');
3818 break;
a737bd4d 3819
c19d1205
ZW
3820 case OP_RRw:
3821 po_reg_or_fail (REG_TYPE_RN);
3822 if (skip_past_char (&str, '!') == SUCCESS)
3823 inst.operands[i].writeback = 1;
3824 break;
3825
3826 /* Immediates */
3827 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3828 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3829 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3830 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3831 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3832 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3833 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3834 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3835
3836 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3837 case OP_oI7b:
3838 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3839 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3840 case OP_oI31b:
3841 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3842 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3843
3844 /* Immediate variants */
3845 case OP_oI255c:
3846 po_char_or_fail ('{');
3847 po_imm_or_fail (0, 255, TRUE);
3848 po_char_or_fail ('}');
3849 break;
3850
3851 case OP_I31w:
3852 /* The expression parser chokes on a trailing !, so we have
3853 to find it first and zap it. */
3854 {
3855 char *s = str;
3856 while (*s && *s != ',')
3857 s++;
3858 if (s[-1] == '!')
3859 {
3860 s[-1] = '\0';
3861 inst.operands[i].writeback = 1;
3862 }
3863 po_imm_or_fail (0, 31, TRUE);
3864 if (str == s - 1)
3865 str = s;
3866 }
3867 break;
3868
3869 /* Expressions */
3870 case OP_EXPi: EXPi:
3871 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3872 GE_OPT_PREFIX));
3873 break;
3874
3875 case OP_EXP:
3876 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3877 GE_NO_PREFIX));
3878 break;
3879
3880 case OP_EXPr: EXPr:
3881 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3882 GE_NO_PREFIX));
3883 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3884 {
c19d1205
ZW
3885 val = parse_reloc (&str);
3886 if (val == -1)
3887 {
3888 inst.error = _("unrecognized relocation suffix");
3889 goto failure;
3890 }
3891 else if (val != BFD_RELOC_UNUSED)
3892 {
3893 inst.operands[i].imm = val;
3894 inst.operands[i].hasreloc = 1;
3895 }
a737bd4d 3896 }
c19d1205 3897 break;
a737bd4d 3898
c19d1205
ZW
3899 /* Register or expression */
3900 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3901 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 3902
c19d1205
ZW
3903 /* Register or immediate */
3904 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3905 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 3906
c19d1205
ZW
3907 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3908 IF:
3909 if (!is_immediate_prefix (*str))
3910 goto bad_args;
3911 str++;
3912 val = parse_fpa_immediate (&str);
3913 if (val == FAIL)
3914 goto failure;
3915 /* FPA immediates are encoded as registers 8-15.
3916 parse_fpa_immediate has already applied the offset. */
3917 inst.operands[i].reg = val;
3918 inst.operands[i].isreg = 1;
3919 break;
09d92015 3920
c19d1205
ZW
3921 /* Two kinds of register */
3922 case OP_RIWR_RIWC:
3923 {
3924 struct reg_entry *rege = arm_reg_parse_multi (&str);
3925 if (rege->type != REG_TYPE_MMXWR
3926 && rege->type != REG_TYPE_MMXWC
3927 && rege->type != REG_TYPE_MMXWCG)
3928 {
3929 inst.error = _("iWMMXt data or control register expected");
3930 goto failure;
3931 }
3932 inst.operands[i].reg = rege->number;
3933 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3934 }
3935 break;
09d92015 3936
c19d1205
ZW
3937 /* Misc */
3938 case OP_CPSF: val = parse_cps_flags (&str); break;
3939 case OP_ENDI: val = parse_endian_specifier (&str); break;
3940 case OP_oROR: val = parse_ror (&str); break;
3941 case OP_PSR: val = parse_psr (&str); break;
3942 case OP_COND: val = parse_cond (&str); break;
3943
92e90b6e
PB
3944 case OP_TB:
3945 po_misc_or_fail (parse_tb (&str));
3946 break;
3947
c19d1205
ZW
3948 /* Register lists */
3949 case OP_REGLST:
3950 val = parse_reg_list (&str);
3951 if (*str == '^')
3952 {
3953 inst.operands[1].writeback = 1;
3954 str++;
3955 }
3956 break;
09d92015 3957
c19d1205
ZW
3958 case OP_VRSLST:
3959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3960 break;
09d92015 3961
c19d1205
ZW
3962 case OP_VRDLST:
3963 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3964 break;
a737bd4d 3965
c19d1205
ZW
3966 /* Addressing modes */
3967 case OP_ADDR:
3968 po_misc_or_fail (parse_address (&str, i));
3969 break;
09d92015 3970
c19d1205
ZW
3971 case OP_SH:
3972 po_misc_or_fail (parse_shifter_operand (&str, i));
3973 break;
09d92015 3974
c19d1205
ZW
3975 case OP_oSHll:
3976 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3977 break;
09d92015 3978
c19d1205
ZW
3979 case OP_oSHar:
3980 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3981 break;
09d92015 3982
c19d1205
ZW
3983 case OP_oSHllar:
3984 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3985 break;
09d92015 3986
c19d1205
ZW
3987 default:
3988 as_fatal ("unhandled operand code %d", upat[i]);
3989 }
09d92015 3990
c19d1205
ZW
3991 /* Various value-based sanity checks and shared operations. We
3992 do not signal immediate failures for the register constraints;
3993 this allows a syntax error to take precedence. */
3994 switch (upat[i])
3995 {
3996 case OP_oRRnpc:
3997 case OP_RRnpc:
3998 case OP_RRnpcb:
3999 case OP_RRw:
4000 case OP_RRnpc_I0:
4001 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
4002 inst.error = BAD_PC;
4003 break;
09d92015 4004
c19d1205
ZW
4005 case OP_CPSF:
4006 case OP_ENDI:
4007 case OP_oROR:
4008 case OP_PSR:
4009 case OP_COND:
4010 case OP_REGLST:
4011 case OP_VRSLST:
4012 case OP_VRDLST:
4013 if (val == FAIL)
4014 goto failure;
4015 inst.operands[i].imm = val;
4016 break;
a737bd4d 4017
c19d1205
ZW
4018 default:
4019 break;
4020 }
09d92015 4021
c19d1205
ZW
4022 /* If we get here, this operand was successfully parsed. */
4023 inst.operands[i].present = 1;
4024 continue;
09d92015 4025
c19d1205 4026 bad_args:
09d92015 4027 inst.error = BAD_ARGS;
c19d1205
ZW
4028
4029 failure:
4030 if (!backtrack_pos)
4031 return FAIL;
4032
4033 /* Do not backtrack over a trailing optional argument that
4034 absorbed some text. We will only fail again, with the
4035 'garbage following instruction' error message, which is
4036 probably less helpful than the current one. */
4037 if (backtrack_index == i && backtrack_pos != str
4038 && upat[i+1] == OP_stop)
4039 return FAIL;
4040
4041 /* Try again, skipping the optional argument at backtrack_pos. */
4042 str = backtrack_pos;
4043 inst.error = backtrack_error;
4044 inst.operands[backtrack_index].present = 0;
4045 i = backtrack_index;
4046 backtrack_pos = 0;
09d92015 4047 }
09d92015 4048
c19d1205
ZW
4049 /* Check that we have parsed all the arguments. */
4050 if (*str != '\0' && !inst.error)
4051 inst.error = _("garbage following instruction");
09d92015 4052
c19d1205 4053 return inst.error ? FAIL : SUCCESS;
09d92015
MM
4054}
4055
c19d1205
ZW
4056#undef po_char_or_fail
4057#undef po_reg_or_fail
4058#undef po_reg_or_goto
4059#undef po_imm_or_fail
4060\f
4061/* Shorthand macro for instruction encoding functions issuing errors. */
4062#define constraint(expr, err) do { \
4063 if (expr) \
4064 { \
4065 inst.error = err; \
4066 return; \
4067 } \
4068} while (0)
4069
4070/* Functions for operand encoding. ARM, then Thumb. */
4071
4072#define rotate_left(v, n) (v << n | v >> (32 - n))
4073
4074/* If VAL can be encoded in the immediate field of an ARM instruction,
4075 return the encoded form. Otherwise, return FAIL. */
4076
4077static unsigned int
4078encode_arm_immediate (unsigned int val)
09d92015 4079{
c19d1205
ZW
4080 unsigned int a, i;
4081
4082 for (i = 0; i < 32; i += 2)
4083 if ((a = rotate_left (val, i)) <= 0xff)
4084 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
4085
4086 return FAIL;
09d92015
MM
4087}
4088
c19d1205
ZW
4089/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
4090 return the encoded form. Otherwise, return FAIL. */
4091static unsigned int
4092encode_thumb32_immediate (unsigned int val)
09d92015 4093{
c19d1205 4094 unsigned int a, i;
09d92015 4095
9c3c69f2 4096 if (val <= 0xff)
c19d1205 4097 return val;
a737bd4d 4098
9c3c69f2 4099 for (i = 1; i <= 24; i++)
09d92015 4100 {
9c3c69f2
PB
4101 a = val >> i;
4102 if ((val & ~(0xff << i)) == 0)
4103 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 4104 }
a737bd4d 4105
c19d1205
ZW
4106 a = val & 0xff;
4107 if (val == ((a << 16) | a))
4108 return 0x100 | a;
4109 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4110 return 0x300 | a;
09d92015 4111
c19d1205
ZW
4112 a = val & 0xff00;
4113 if (val == ((a << 16) | a))
4114 return 0x200 | (a >> 8);
a737bd4d 4115
c19d1205 4116 return FAIL;
09d92015 4117}
c19d1205 4118/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
4119
4120static void
c19d1205 4121encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 4122{
c19d1205 4123 switch (pos)
09d92015 4124 {
c19d1205
ZW
4125 case VFP_REG_Sd:
4126 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4127 break;
4128
4129 case VFP_REG_Sn:
4130 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4131 break;
4132
4133 case VFP_REG_Sm:
4134 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4135 break;
4136
4137 default:
4138 abort ();
09d92015 4139 }
09d92015
MM
4140}
4141
c19d1205 4142/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 4143 if any, is handled by md_apply_fix. */
09d92015 4144static void
c19d1205 4145encode_arm_shift (int i)
09d92015 4146{
c19d1205
ZW
4147 if (inst.operands[i].shift_kind == SHIFT_RRX)
4148 inst.instruction |= SHIFT_ROR << 5;
4149 else
09d92015 4150 {
c19d1205
ZW
4151 inst.instruction |= inst.operands[i].shift_kind << 5;
4152 if (inst.operands[i].immisreg)
4153 {
4154 inst.instruction |= SHIFT_BY_REG;
4155 inst.instruction |= inst.operands[i].imm << 8;
4156 }
4157 else
4158 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 4159 }
c19d1205 4160}
09d92015 4161
c19d1205
ZW
4162static void
4163encode_arm_shifter_operand (int i)
4164{
4165 if (inst.operands[i].isreg)
09d92015 4166 {
c19d1205
ZW
4167 inst.instruction |= inst.operands[i].reg;
4168 encode_arm_shift (i);
09d92015 4169 }
c19d1205
ZW
4170 else
4171 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4172}
4173
c19d1205 4174/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4175static void
c19d1205 4176encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4177{
c19d1205
ZW
4178 assert (inst.operands[i].isreg);
4179 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4180
c19d1205 4181 if (inst.operands[i].preind)
09d92015 4182 {
c19d1205
ZW
4183 if (is_t)
4184 {
4185 inst.error = _("instruction does not accept preindexed addressing");
4186 return;
4187 }
4188 inst.instruction |= PRE_INDEX;
4189 if (inst.operands[i].writeback)
4190 inst.instruction |= WRITE_BACK;
09d92015 4191
c19d1205
ZW
4192 }
4193 else if (inst.operands[i].postind)
4194 {
4195 assert (inst.operands[i].writeback);
4196 if (is_t)
4197 inst.instruction |= WRITE_BACK;
4198 }
4199 else /* unindexed - only for coprocessor */
09d92015 4200 {
c19d1205 4201 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4202 return;
4203 }
4204
c19d1205
ZW
4205 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4206 && (((inst.instruction & 0x000f0000) >> 16)
4207 == ((inst.instruction & 0x0000f000) >> 12)))
4208 as_warn ((inst.instruction & LOAD_BIT)
4209 ? _("destination register same as write-back base")
4210 : _("source register same as write-back base"));
09d92015
MM
4211}
4212
c19d1205
ZW
4213/* inst.operands[i] was set up by parse_address. Encode it into an
4214 ARM-format mode 2 load or store instruction. If is_t is true,
4215 reject forms that cannot be used with a T instruction (i.e. not
4216 post-indexed). */
a737bd4d 4217static void
c19d1205 4218encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4219{
c19d1205 4220 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4221
c19d1205 4222 if (inst.operands[i].immisreg)
09d92015 4223 {
c19d1205
ZW
4224 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4225 inst.instruction |= inst.operands[i].imm;
4226 if (!inst.operands[i].negative)
4227 inst.instruction |= INDEX_UP;
4228 if (inst.operands[i].shifted)
4229 {
4230 if (inst.operands[i].shift_kind == SHIFT_RRX)
4231 inst.instruction |= SHIFT_ROR << 5;
4232 else
4233 {
4234 inst.instruction |= inst.operands[i].shift_kind << 5;
4235 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4236 }
4237 }
09d92015 4238 }
c19d1205 4239 else /* immediate offset in inst.reloc */
09d92015 4240 {
c19d1205
ZW
4241 if (inst.reloc.type == BFD_RELOC_UNUSED)
4242 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 4243 }
09d92015
MM
4244}
4245
c19d1205
ZW
4246/* inst.operands[i] was set up by parse_address. Encode it into an
4247 ARM-format mode 3 load or store instruction. Reject forms that
4248 cannot be used with such instructions. If is_t is true, reject
4249 forms that cannot be used with a T instruction (i.e. not
4250 post-indexed). */
4251static void
4252encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4253{
c19d1205 4254 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4255 {
c19d1205
ZW
4256 inst.error = _("instruction does not accept scaled register index");
4257 return;
09d92015 4258 }
a737bd4d 4259
c19d1205 4260 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4261
c19d1205
ZW
4262 if (inst.operands[i].immisreg)
4263 {
4264 inst.instruction |= inst.operands[i].imm;
4265 if (!inst.operands[i].negative)
4266 inst.instruction |= INDEX_UP;
4267 }
4268 else /* immediate offset in inst.reloc */
4269 {
4270 inst.instruction |= HWOFFSET_IMM;
4271 if (inst.reloc.type == BFD_RELOC_UNUSED)
4272 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 4273 }
a737bd4d
NC
4274}
4275
c19d1205
ZW
4276/* inst.operands[i] was set up by parse_address. Encode it into an
4277 ARM-format instruction. Reject all forms which cannot be encoded
4278 into a coprocessor load/store instruction. If wb_ok is false,
4279 reject use of writeback; if unind_ok is false, reject use of
4280 unindexed addressing. If reloc_override is not 0, use it instead
4281 of BFD_ARM_CP_OFF_IMM. */
09d92015 4282
c19d1205
ZW
4283static int
4284encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4285{
c19d1205 4286 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4287
c19d1205 4288 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4289
c19d1205 4290 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4291 {
c19d1205
ZW
4292 assert (!inst.operands[i].writeback);
4293 if (!unind_ok)
4294 {
4295 inst.error = _("instruction does not support unindexed addressing");
4296 return FAIL;
4297 }
4298 inst.instruction |= inst.operands[i].imm;
4299 inst.instruction |= INDEX_UP;
4300 return SUCCESS;
09d92015 4301 }
a737bd4d 4302
c19d1205
ZW
4303 if (inst.operands[i].preind)
4304 inst.instruction |= PRE_INDEX;
a737bd4d 4305
c19d1205 4306 if (inst.operands[i].writeback)
09d92015 4307 {
c19d1205
ZW
4308 if (inst.operands[i].reg == REG_PC)
4309 {
4310 inst.error = _("pc may not be used with write-back");
4311 return FAIL;
4312 }
4313 if (!wb_ok)
4314 {
4315 inst.error = _("instruction does not support writeback");
4316 return FAIL;
4317 }
4318 inst.instruction |= WRITE_BACK;
09d92015 4319 }
a737bd4d 4320
c19d1205
ZW
4321 if (reloc_override)
4322 inst.reloc.type = reloc_override;
8f06b2d8
PB
4323 else if (thumb_mode)
4324 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
09d92015 4325 else
c19d1205 4326 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205
ZW
4327 return SUCCESS;
4328}
a737bd4d 4329
c19d1205
ZW
4330/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4331 Determine whether it can be performed with a move instruction; if
4332 it can, convert inst.instruction to that move instruction and
4333 return 1; if it can't, convert inst.instruction to a literal-pool
4334 load and return 0. If this is not a valid thing to do in the
4335 current context, set inst.error and return 1.
a737bd4d 4336
c19d1205
ZW
4337 inst.operands[i] describes the destination register. */
4338
4339static int
4340move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4341{
4342 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4343 {
c19d1205
ZW
4344 inst.error = _("invalid pseudo operation");
4345 return 1;
09d92015 4346 }
c19d1205 4347 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4348 {
4349 inst.error = _("constant expression expected");
c19d1205 4350 return 1;
09d92015 4351 }
c19d1205 4352 if (inst.reloc.exp.X_op == O_constant)
09d92015 4353 {
c19d1205
ZW
4354 if (thumb_p)
4355 {
4356 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4357 {
4358 /* This can be done with a mov(1) instruction. */
4359 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4360 inst.instruction |= inst.reloc.exp.X_add_number;
4361 return 1;
4362 }
4363 }
4364 else
4365 {
4366 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4367 if (value != FAIL)
4368 {
4369 /* This can be done with a mov instruction. */
4370 inst.instruction &= LITERAL_MASK;
4371 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4372 inst.instruction |= value & 0xfff;
4373 return 1;
4374 }
09d92015 4375
c19d1205
ZW
4376 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4377 if (value != FAIL)
4378 {
4379 /* This can be done with a mvn instruction. */
4380 inst.instruction &= LITERAL_MASK;
4381 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4382 inst.instruction |= value & 0xfff;
4383 return 1;
4384 }
4385 }
09d92015
MM
4386 }
4387
c19d1205
ZW
4388 if (add_to_lit_pool () == FAIL)
4389 {
4390 inst.error = _("literal pool insertion failed");
4391 return 1;
4392 }
4393 inst.operands[1].reg = REG_PC;
4394 inst.operands[1].isreg = 1;
4395 inst.operands[1].preind = 1;
4396 inst.reloc.pc_rel = 1;
4397 inst.reloc.type = (thumb_p
4398 ? BFD_RELOC_ARM_THUMB_OFFSET
4399 : (mode_3
4400 ? BFD_RELOC_ARM_HWLITERAL
4401 : BFD_RELOC_ARM_LITERAL));
4402 return 0;
09d92015
MM
4403}
4404
c19d1205
ZW
4405/* Functions for instruction encoding, sorted by subarchitecture.
4406 First some generics; their names are taken from the conventional
4407 bit positions for register arguments in ARM format instructions. */
09d92015 4408
a737bd4d 4409static void
c19d1205 4410do_noargs (void)
09d92015 4411{
c19d1205 4412}
a737bd4d 4413
c19d1205
ZW
4414static void
4415do_rd (void)
4416{
4417 inst.instruction |= inst.operands[0].reg << 12;
4418}
a737bd4d 4419
c19d1205
ZW
4420static void
4421do_rd_rm (void)
4422{
4423 inst.instruction |= inst.operands[0].reg << 12;
4424 inst.instruction |= inst.operands[1].reg;
4425}
09d92015 4426
c19d1205
ZW
4427static void
4428do_rd_rn (void)
4429{
4430 inst.instruction |= inst.operands[0].reg << 12;
4431 inst.instruction |= inst.operands[1].reg << 16;
4432}
a737bd4d 4433
c19d1205
ZW
4434static void
4435do_rn_rd (void)
4436{
4437 inst.instruction |= inst.operands[0].reg << 16;
4438 inst.instruction |= inst.operands[1].reg << 12;
4439}
09d92015 4440
c19d1205
ZW
4441static void
4442do_rd_rm_rn (void)
4443{
9a64e435
PB
4444 unsigned Rn = inst.operands[2].reg;
4445 /* Enforce resutrictions on SWP instruction. */
4446 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
4447 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
4448 _("Rn must not overlap other operands"));
c19d1205
ZW
4449 inst.instruction |= inst.operands[0].reg << 12;
4450 inst.instruction |= inst.operands[1].reg;
9a64e435 4451 inst.instruction |= Rn << 16;
c19d1205 4452}
09d92015 4453
c19d1205
ZW
4454static void
4455do_rd_rn_rm (void)
4456{
4457 inst.instruction |= inst.operands[0].reg << 12;
4458 inst.instruction |= inst.operands[1].reg << 16;
4459 inst.instruction |= inst.operands[2].reg;
4460}
a737bd4d 4461
c19d1205
ZW
4462static void
4463do_rm_rd_rn (void)
4464{
4465 inst.instruction |= inst.operands[0].reg;
4466 inst.instruction |= inst.operands[1].reg << 12;
4467 inst.instruction |= inst.operands[2].reg << 16;
4468}
09d92015 4469
c19d1205
ZW
4470static void
4471do_imm0 (void)
4472{
4473 inst.instruction |= inst.operands[0].imm;
4474}
09d92015 4475
c19d1205
ZW
4476static void
4477do_rd_cpaddr (void)
4478{
4479 inst.instruction |= inst.operands[0].reg << 12;
4480 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4481}
a737bd4d 4482
c19d1205
ZW
4483/* ARM instructions, in alphabetical order by function name (except
4484 that wrapper functions appear immediately after the function they
4485 wrap). */
09d92015 4486
c19d1205
ZW
4487/* This is a pseudo-op of the form "adr rd, label" to be converted
4488 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4489
4490static void
c19d1205 4491do_adr (void)
09d92015 4492{
c19d1205 4493 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4494
c19d1205
ZW
4495 /* Frag hacking will turn this into a sub instruction if the offset turns
4496 out to be negative. */
4497 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 4498 inst.reloc.pc_rel = 1;
2fc8bdac 4499 inst.reloc.exp.X_add_number -= 8;
c19d1205 4500}
b99bd4ef 4501
c19d1205
ZW
4502/* This is a pseudo-op of the form "adrl rd, label" to be converted
4503 into a relative address of the form:
4504 add rd, pc, #low(label-.-8)"
4505 add rd, rd, #high(label-.-8)" */
b99bd4ef 4506
c19d1205
ZW
4507static void
4508do_adrl (void)
4509{
4510 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4511
c19d1205
ZW
4512 /* Frag hacking will turn this into a sub instruction if the offset turns
4513 out to be negative. */
4514 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
4515 inst.reloc.pc_rel = 1;
4516 inst.size = INSN_SIZE * 2;
2fc8bdac 4517 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
4518}
4519
b99bd4ef 4520static void
c19d1205 4521do_arit (void)
b99bd4ef 4522{
c19d1205
ZW
4523 if (!inst.operands[1].present)
4524 inst.operands[1].reg = inst.operands[0].reg;
4525 inst.instruction |= inst.operands[0].reg << 12;
4526 inst.instruction |= inst.operands[1].reg << 16;
4527 encode_arm_shifter_operand (2);
4528}
b99bd4ef 4529
c19d1205
ZW
4530static void
4531do_bfc (void)
4532{
4533 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4534 constraint (msb > 32, _("bit-field extends past end of register"));
4535 /* The instruction encoding stores the LSB and MSB,
4536 not the LSB and width. */
4537 inst.instruction |= inst.operands[0].reg << 12;
4538 inst.instruction |= inst.operands[1].imm << 7;
4539 inst.instruction |= (msb - 1) << 16;
4540}
b99bd4ef 4541
c19d1205
ZW
4542static void
4543do_bfi (void)
4544{
4545 unsigned int msb;
b99bd4ef 4546
c19d1205
ZW
4547 /* #0 in second position is alternative syntax for bfc, which is
4548 the same instruction but with REG_PC in the Rm field. */
4549 if (!inst.operands[1].isreg)
4550 inst.operands[1].reg = REG_PC;
b99bd4ef 4551
c19d1205
ZW
4552 msb = inst.operands[2].imm + inst.operands[3].imm;
4553 constraint (msb > 32, _("bit-field extends past end of register"));
4554 /* The instruction encoding stores the LSB and MSB,
4555 not the LSB and width. */
4556 inst.instruction |= inst.operands[0].reg << 12;
4557 inst.instruction |= inst.operands[1].reg;
4558 inst.instruction |= inst.operands[2].imm << 7;
4559 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4560}
4561
b99bd4ef 4562static void
c19d1205 4563do_bfx (void)
b99bd4ef 4564{
c19d1205
ZW
4565 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4566 _("bit-field extends past end of register"));
4567 inst.instruction |= inst.operands[0].reg << 12;
4568 inst.instruction |= inst.operands[1].reg;
4569 inst.instruction |= inst.operands[2].imm << 7;
4570 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4571}
09d92015 4572
c19d1205
ZW
4573/* ARM V5 breakpoint instruction (argument parse)
4574 BKPT <16 bit unsigned immediate>
4575 Instruction is not conditional.
4576 The bit pattern given in insns[] has the COND_ALWAYS condition,
4577 and it is an error if the caller tried to override that. */
b99bd4ef 4578
c19d1205
ZW
4579static void
4580do_bkpt (void)
4581{
4582 /* Top 12 of 16 bits to bits 19:8. */
4583 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4584
c19d1205
ZW
4585 /* Bottom 4 of 16 bits to bits 3:0. */
4586 inst.instruction |= inst.operands[0].imm & 0xf;
4587}
09d92015 4588
c19d1205
ZW
4589static void
4590encode_branch (int default_reloc)
4591{
4592 if (inst.operands[0].hasreloc)
4593 {
4594 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4595 _("the only suffix valid here is '(plt)'"));
4596 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 4597 }
b99bd4ef 4598 else
c19d1205
ZW
4599 {
4600 inst.reloc.type = default_reloc;
c19d1205 4601 }
2fc8bdac 4602 inst.reloc.pc_rel = 1;
b99bd4ef
NC
4603}
4604
b99bd4ef 4605static void
c19d1205 4606do_branch (void)
b99bd4ef 4607{
c19d1205
ZW
4608 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4609}
b99bd4ef 4610
c19d1205
ZW
4611/* ARM V5 branch-link-exchange instruction (argument parse)
4612 BLX <target_addr> ie BLX(1)
4613 BLX{<condition>} <Rm> ie BLX(2)
4614 Unfortunately, there are two different opcodes for this mnemonic.
4615 So, the insns[].value is not used, and the code here zaps values
4616 into inst.instruction.
4617 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4618
c19d1205
ZW
4619static void
4620do_blx (void)
4621{
4622 if (inst.operands[0].isreg)
b99bd4ef 4623 {
c19d1205
ZW
4624 /* Arg is a register; the opcode provided by insns[] is correct.
4625 It is not illegal to do "blx pc", just useless. */
4626 if (inst.operands[0].reg == REG_PC)
4627 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4628
c19d1205
ZW
4629 inst.instruction |= inst.operands[0].reg;
4630 }
4631 else
b99bd4ef 4632 {
c19d1205
ZW
4633 /* Arg is an address; this instruction cannot be executed
4634 conditionally, and the opcode must be adjusted. */
4635 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 4636 inst.instruction = 0xfa000000;
c19d1205 4637 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4638 }
c19d1205
ZW
4639}
4640
4641static void
4642do_bx (void)
4643{
4644 if (inst.operands[0].reg == REG_PC)
4645 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4646
c19d1205 4647 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4648}
4649
c19d1205
ZW
4650
4651/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4652
4653static void
c19d1205 4654do_bxj (void)
a737bd4d 4655{
c19d1205
ZW
4656 if (inst.operands[0].reg == REG_PC)
4657 as_tsktsk (_("use of r15 in bxj is not really useful"));
4658
4659 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4660}
4661
c19d1205
ZW
4662/* Co-processor data operation:
4663 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4664 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4665static void
4666do_cdp (void)
4667{
4668 inst.instruction |= inst.operands[0].reg << 8;
4669 inst.instruction |= inst.operands[1].imm << 20;
4670 inst.instruction |= inst.operands[2].reg << 12;
4671 inst.instruction |= inst.operands[3].reg << 16;
4672 inst.instruction |= inst.operands[4].reg;
4673 inst.instruction |= inst.operands[5].imm << 5;
4674}
a737bd4d
NC
4675
4676static void
c19d1205 4677do_cmp (void)
a737bd4d 4678{
c19d1205
ZW
4679 inst.instruction |= inst.operands[0].reg << 16;
4680 encode_arm_shifter_operand (1);
a737bd4d
NC
4681}
4682
c19d1205
ZW
4683/* Transfer between coprocessor and ARM registers.
4684 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4685 MRC2
4686 MCR{cond}
4687 MCR2
4688
4689 No special properties. */
09d92015
MM
4690
4691static void
c19d1205 4692do_co_reg (void)
09d92015 4693{
c19d1205
ZW
4694 inst.instruction |= inst.operands[0].reg << 8;
4695 inst.instruction |= inst.operands[1].imm << 21;
4696 inst.instruction |= inst.operands[2].reg << 12;
4697 inst.instruction |= inst.operands[3].reg << 16;
4698 inst.instruction |= inst.operands[4].reg;
4699 inst.instruction |= inst.operands[5].imm << 5;
4700}
09d92015 4701
c19d1205
ZW
4702/* Transfer between coprocessor register and pair of ARM registers.
4703 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4704 MCRR2
4705 MRRC{cond}
4706 MRRC2
b99bd4ef 4707
c19d1205 4708 Two XScale instructions are special cases of these:
09d92015 4709
c19d1205
ZW
4710 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4711 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4712
c19d1205 4713 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4714
c19d1205
ZW
4715static void
4716do_co_reg2c (void)
4717{
4718 inst.instruction |= inst.operands[0].reg << 8;
4719 inst.instruction |= inst.operands[1].imm << 4;
4720 inst.instruction |= inst.operands[2].reg << 12;
4721 inst.instruction |= inst.operands[3].reg << 16;
4722 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4723}
4724
c19d1205
ZW
4725static void
4726do_cpsi (void)
4727{
4728 inst.instruction |= inst.operands[0].imm << 6;
4729 inst.instruction |= inst.operands[1].imm;
4730}
b99bd4ef
NC
4731
4732static void
c19d1205 4733do_it (void)
b99bd4ef 4734{
c19d1205
ZW
4735 /* There is no IT instruction in ARM mode. We
4736 process it but do not generate code for it. */
4737 inst.size = 0;
09d92015 4738}
b99bd4ef 4739
09d92015 4740static void
c19d1205 4741do_ldmstm (void)
ea6ef066 4742{
c19d1205
ZW
4743 int base_reg = inst.operands[0].reg;
4744 int range = inst.operands[1].imm;
ea6ef066 4745
c19d1205
ZW
4746 inst.instruction |= base_reg << 16;
4747 inst.instruction |= range;
ea6ef066 4748
c19d1205
ZW
4749 if (inst.operands[1].writeback)
4750 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4751
c19d1205 4752 if (inst.operands[0].writeback)
ea6ef066 4753 {
c19d1205
ZW
4754 inst.instruction |= WRITE_BACK;
4755 /* Check for unpredictable uses of writeback. */
4756 if (inst.instruction & LOAD_BIT)
09d92015 4757 {
c19d1205
ZW
4758 /* Not allowed in LDM type 2. */
4759 if ((inst.instruction & LDM_TYPE_2_OR_3)
4760 && ((range & (1 << REG_PC)) == 0))
4761 as_warn (_("writeback of base register is UNPREDICTABLE"));
4762 /* Only allowed if base reg not in list for other types. */
4763 else if (range & (1 << base_reg))
4764 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4765 }
4766 else /* STM. */
4767 {
4768 /* Not allowed for type 2. */
4769 if (inst.instruction & LDM_TYPE_2_OR_3)
4770 as_warn (_("writeback of base register is UNPREDICTABLE"));
4771 /* Only allowed if base reg not in list, or first in list. */
4772 else if ((range & (1 << base_reg))
4773 && (range & ((1 << base_reg) - 1)))
4774 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4775 }
ea6ef066 4776 }
a737bd4d
NC
4777}
4778
c19d1205
ZW
4779/* ARMv5TE load-consecutive (argument parse)
4780 Mode is like LDRH.
4781
4782 LDRccD R, mode
4783 STRccD R, mode. */
4784
a737bd4d 4785static void
c19d1205 4786do_ldrd (void)
a737bd4d 4787{
c19d1205
ZW
4788 constraint (inst.operands[0].reg % 2 != 0,
4789 _("first destination register must be even"));
4790 constraint (inst.operands[1].present
4791 && inst.operands[1].reg != inst.operands[0].reg + 1,
4792 _("can only load two consecutive registers"));
4793 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4794 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4795
c19d1205
ZW
4796 if (!inst.operands[1].present)
4797 inst.operands[1].reg = inst.operands[0].reg + 1;
4798
4799 if (inst.instruction & LOAD_BIT)
a737bd4d 4800 {
c19d1205
ZW
4801 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4802 register and the first register written; we have to diagnose
4803 overlap between the base and the second register written here. */
ea6ef066 4804
c19d1205
ZW
4805 if (inst.operands[2].reg == inst.operands[1].reg
4806 && (inst.operands[2].writeback || inst.operands[2].postind))
4807 as_warn (_("base register written back, and overlaps "
4808 "second destination register"));
b05fe5cf 4809
c19d1205
ZW
4810 /* For an index-register load, the index register must not overlap the
4811 destination (even if not write-back). */
4812 else if (inst.operands[2].immisreg
ca3f61f7
NC
4813 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4814 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 4815 as_warn (_("index register overlaps destination register"));
b05fe5cf 4816 }
c19d1205
ZW
4817
4818 inst.instruction |= inst.operands[0].reg << 12;
4819 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4820}
4821
4822static void
c19d1205 4823do_ldrex (void)
b05fe5cf 4824{
c19d1205
ZW
4825 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4826 || inst.operands[1].postind || inst.operands[1].writeback
4827 || inst.operands[1].immisreg || inst.operands[1].shifted
4828 || inst.operands[1].negative,
4829 _("instruction does not accept this addressing mode"));
b05fe5cf 4830
c19d1205 4831 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
b05fe5cf 4832
c19d1205
ZW
4833 constraint (inst.reloc.exp.X_op != O_constant
4834 || inst.reloc.exp.X_add_number != 0,
4835 _("offset must be zero in ARM encoding"));
b05fe5cf 4836
c19d1205
ZW
4837 inst.instruction |= inst.operands[0].reg << 12;
4838 inst.instruction |= inst.operands[1].reg << 16;
4839 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4840}
4841
4842static void
c19d1205 4843do_ldrexd (void)
b05fe5cf 4844{
c19d1205
ZW
4845 constraint (inst.operands[0].reg % 2 != 0,
4846 _("even register required"));
4847 constraint (inst.operands[1].present
4848 && inst.operands[1].reg != inst.operands[0].reg + 1,
4849 _("can only load two consecutive registers"));
4850 /* If op 1 were present and equal to PC, this function wouldn't
4851 have been called in the first place. */
4852 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 4853
c19d1205
ZW
4854 inst.instruction |= inst.operands[0].reg << 12;
4855 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
4856}
4857
4858static void
c19d1205 4859do_ldst (void)
b05fe5cf 4860{
c19d1205
ZW
4861 inst.instruction |= inst.operands[0].reg << 12;
4862 if (!inst.operands[1].isreg)
4863 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 4864 return;
c19d1205 4865 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4866}
4867
4868static void
c19d1205 4869do_ldstt (void)
b05fe5cf 4870{
c19d1205
ZW
4871 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4872 reject [Rn,...]. */
4873 if (inst.operands[1].preind)
b05fe5cf 4874 {
c19d1205
ZW
4875 constraint (inst.reloc.exp.X_op != O_constant ||
4876 inst.reloc.exp.X_add_number != 0,
4877 _("this instruction requires a post-indexed address"));
b05fe5cf 4878
c19d1205
ZW
4879 inst.operands[1].preind = 0;
4880 inst.operands[1].postind = 1;
4881 inst.operands[1].writeback = 1;
b05fe5cf 4882 }
c19d1205
ZW
4883 inst.instruction |= inst.operands[0].reg << 12;
4884 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4885}
b05fe5cf 4886
c19d1205 4887/* Halfword and signed-byte load/store operations. */
b05fe5cf 4888
c19d1205
ZW
4889static void
4890do_ldstv4 (void)
4891{
4892 inst.instruction |= inst.operands[0].reg << 12;
4893 if (!inst.operands[1].isreg)
4894 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 4895 return;
c19d1205 4896 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
4897}
4898
4899static void
c19d1205 4900do_ldsttv4 (void)
b05fe5cf 4901{
c19d1205
ZW
4902 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4903 reject [Rn,...]. */
4904 if (inst.operands[1].preind)
b05fe5cf 4905 {
c19d1205
ZW
4906 constraint (inst.reloc.exp.X_op != O_constant ||
4907 inst.reloc.exp.X_add_number != 0,
4908 _("this instruction requires a post-indexed address"));
b05fe5cf 4909
c19d1205
ZW
4910 inst.operands[1].preind = 0;
4911 inst.operands[1].postind = 1;
4912 inst.operands[1].writeback = 1;
b05fe5cf 4913 }
c19d1205
ZW
4914 inst.instruction |= inst.operands[0].reg << 12;
4915 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4916}
b05fe5cf 4917
c19d1205
ZW
4918/* Co-processor register load/store.
4919 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4920static void
4921do_lstc (void)
4922{
4923 inst.instruction |= inst.operands[0].reg << 8;
4924 inst.instruction |= inst.operands[1].reg << 12;
4925 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
4926}
4927
b05fe5cf 4928static void
c19d1205 4929do_mlas (void)
b05fe5cf 4930{
c19d1205
ZW
4931 /* This restriction does not apply to mls (nor to mla in v6, but
4932 that's hard to detect at present). */
4933 if (inst.operands[0].reg == inst.operands[1].reg
4934 && !(inst.instruction & 0x00400000))
4935 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 4936
c19d1205
ZW
4937 inst.instruction |= inst.operands[0].reg << 16;
4938 inst.instruction |= inst.operands[1].reg;
4939 inst.instruction |= inst.operands[2].reg << 8;
4940 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 4941
c19d1205 4942}
b05fe5cf 4943
c19d1205
ZW
4944static void
4945do_mov (void)
4946{
4947 inst.instruction |= inst.operands[0].reg << 12;
4948 encode_arm_shifter_operand (1);
4949}
b05fe5cf 4950
c19d1205
ZW
4951/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4952static void
4953do_mov16 (void)
4954{
4955 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 4956 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
4957 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4958 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 4959}
b99bd4ef
NC
4960
4961static void
c19d1205 4962do_mrs (void)
b99bd4ef 4963{
c19d1205
ZW
4964 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4965 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4966 != (PSR_c|PSR_f),
4967 _("'CPSR' or 'SPSR' expected"));
4968 inst.instruction |= inst.operands[0].reg << 12;
4969 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4970}
b99bd4ef 4971
c19d1205
ZW
4972/* Two possible forms:
4973 "{C|S}PSR_<field>, Rm",
4974 "{C|S}PSR_f, #expression". */
b99bd4ef 4975
c19d1205
ZW
4976static void
4977do_msr (void)
4978{
4979 inst.instruction |= inst.operands[0].imm;
4980 if (inst.operands[1].isreg)
4981 inst.instruction |= inst.operands[1].reg;
4982 else
b99bd4ef 4983 {
c19d1205
ZW
4984 inst.instruction |= INST_IMMEDIATE;
4985 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4986 inst.reloc.pc_rel = 0;
b99bd4ef 4987 }
b99bd4ef
NC
4988}
4989
c19d1205
ZW
4990static void
4991do_mul (void)
a737bd4d 4992{
c19d1205
ZW
4993 if (!inst.operands[2].present)
4994 inst.operands[2].reg = inst.operands[0].reg;
4995 inst.instruction |= inst.operands[0].reg << 16;
4996 inst.instruction |= inst.operands[1].reg;
4997 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 4998
c19d1205
ZW
4999 if (inst.operands[0].reg == inst.operands[1].reg)
5000 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
5001}
5002
c19d1205
ZW
5003/* Long Multiply Parser
5004 UMULL RdLo, RdHi, Rm, Rs
5005 SMULL RdLo, RdHi, Rm, Rs
5006 UMLAL RdLo, RdHi, Rm, Rs
5007 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
5008
5009static void
c19d1205 5010do_mull (void)
b99bd4ef 5011{
c19d1205
ZW
5012 inst.instruction |= inst.operands[0].reg << 12;
5013 inst.instruction |= inst.operands[1].reg << 16;
5014 inst.instruction |= inst.operands[2].reg;
5015 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 5016
c19d1205
ZW
5017 /* rdhi, rdlo and rm must all be different. */
5018 if (inst.operands[0].reg == inst.operands[1].reg
5019 || inst.operands[0].reg == inst.operands[2].reg
5020 || inst.operands[1].reg == inst.operands[2].reg)
5021 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
5022}
b99bd4ef 5023
c19d1205
ZW
5024static void
5025do_nop (void)
5026{
5027 if (inst.operands[0].present)
5028 {
5029 /* Architectural NOP hints are CPSR sets with no bits selected. */
5030 inst.instruction &= 0xf0000000;
5031 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
5032 }
b99bd4ef
NC
5033}
5034
c19d1205
ZW
5035/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
5036 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
5037 Condition defaults to COND_ALWAYS.
5038 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
5039
5040static void
c19d1205 5041do_pkhbt (void)
b99bd4ef 5042{
c19d1205
ZW
5043 inst.instruction |= inst.operands[0].reg << 12;
5044 inst.instruction |= inst.operands[1].reg << 16;
5045 inst.instruction |= inst.operands[2].reg;
5046 if (inst.operands[3].present)
5047 encode_arm_shift (3);
5048}
b99bd4ef 5049
c19d1205 5050/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 5051
c19d1205
ZW
5052static void
5053do_pkhtb (void)
5054{
5055 if (!inst.operands[3].present)
b99bd4ef 5056 {
c19d1205
ZW
5057 /* If the shift specifier is omitted, turn the instruction
5058 into pkhbt rd, rm, rn. */
5059 inst.instruction &= 0xfff00010;
5060 inst.instruction |= inst.operands[0].reg << 12;
5061 inst.instruction |= inst.operands[1].reg;
5062 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5063 }
5064 else
5065 {
c19d1205
ZW
5066 inst.instruction |= inst.operands[0].reg << 12;
5067 inst.instruction |= inst.operands[1].reg << 16;
5068 inst.instruction |= inst.operands[2].reg;
5069 encode_arm_shift (3);
b99bd4ef
NC
5070 }
5071}
5072
c19d1205
ZW
5073/* ARMv5TE: Preload-Cache
5074
5075 PLD <addr_mode>
5076
5077 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
5078
5079static void
c19d1205 5080do_pld (void)
b99bd4ef 5081{
c19d1205
ZW
5082 constraint (!inst.operands[0].isreg,
5083 _("'[' expected after PLD mnemonic"));
5084 constraint (inst.operands[0].postind,
5085 _("post-indexed expression used in preload instruction"));
5086 constraint (inst.operands[0].writeback,
5087 _("writeback used in preload instruction"));
5088 constraint (!inst.operands[0].preind,
5089 _("unindexed addressing used in preload instruction"));
5090 inst.instruction |= inst.operands[0].reg;
5091 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5092}
b99bd4ef 5093
c19d1205
ZW
5094static void
5095do_push_pop (void)
5096{
5097 inst.operands[1] = inst.operands[0];
5098 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
5099 inst.operands[0].isreg = 1;
5100 inst.operands[0].writeback = 1;
5101 inst.operands[0].reg = REG_SP;
5102 do_ldmstm ();
5103}
b99bd4ef 5104
c19d1205
ZW
5105/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
5106 word at the specified address and the following word
5107 respectively.
5108 Unconditionally executed.
5109 Error if Rn is R15. */
b99bd4ef 5110
c19d1205
ZW
5111static void
5112do_rfe (void)
5113{
5114 inst.instruction |= inst.operands[0].reg << 16;
5115 if (inst.operands[0].writeback)
5116 inst.instruction |= WRITE_BACK;
5117}
b99bd4ef 5118
c19d1205 5119/* ARM V6 ssat (argument parse). */
b99bd4ef 5120
c19d1205
ZW
5121static void
5122do_ssat (void)
5123{
5124 inst.instruction |= inst.operands[0].reg << 12;
5125 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5126 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5127
c19d1205
ZW
5128 if (inst.operands[3].present)
5129 encode_arm_shift (3);
b99bd4ef
NC
5130}
5131
c19d1205 5132/* ARM V6 usat (argument parse). */
b99bd4ef
NC
5133
5134static void
c19d1205 5135do_usat (void)
b99bd4ef 5136{
c19d1205
ZW
5137 inst.instruction |= inst.operands[0].reg << 12;
5138 inst.instruction |= inst.operands[1].imm << 16;
5139 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5140
c19d1205
ZW
5141 if (inst.operands[3].present)
5142 encode_arm_shift (3);
b99bd4ef
NC
5143}
5144
c19d1205 5145/* ARM V6 ssat16 (argument parse). */
09d92015
MM
5146
5147static void
c19d1205 5148do_ssat16 (void)
09d92015 5149{
c19d1205
ZW
5150 inst.instruction |= inst.operands[0].reg << 12;
5151 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5152 inst.instruction |= inst.operands[2].reg;
09d92015
MM
5153}
5154
c19d1205
ZW
5155static void
5156do_usat16 (void)
a737bd4d 5157{
c19d1205
ZW
5158 inst.instruction |= inst.operands[0].reg << 12;
5159 inst.instruction |= inst.operands[1].imm << 16;
5160 inst.instruction |= inst.operands[2].reg;
5161}
a737bd4d 5162
c19d1205
ZW
5163/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5164 preserving the other bits.
a737bd4d 5165
c19d1205
ZW
5166 setend <endian_specifier>, where <endian_specifier> is either
5167 BE or LE. */
a737bd4d 5168
c19d1205
ZW
5169static void
5170do_setend (void)
5171{
5172 if (inst.operands[0].imm)
5173 inst.instruction |= 0x200;
a737bd4d
NC
5174}
5175
5176static void
c19d1205 5177do_shift (void)
a737bd4d 5178{
c19d1205
ZW
5179 unsigned int Rm = (inst.operands[1].present
5180 ? inst.operands[1].reg
5181 : inst.operands[0].reg);
a737bd4d 5182
c19d1205
ZW
5183 inst.instruction |= inst.operands[0].reg << 12;
5184 inst.instruction |= Rm;
5185 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5186 {
c19d1205
ZW
5187 constraint (inst.operands[0].reg != Rm,
5188 _("source1 and dest must be same register"));
5189 inst.instruction |= inst.operands[2].reg << 8;
5190 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5191 }
5192 else
c19d1205 5193 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5194}
5195
09d92015 5196static void
3eb17e6b 5197do_smc (void)
09d92015 5198{
3eb17e6b 5199 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 5200 inst.reloc.pc_rel = 0;
09d92015
MM
5201}
5202
09d92015 5203static void
c19d1205 5204do_swi (void)
09d92015 5205{
c19d1205
ZW
5206 inst.reloc.type = BFD_RELOC_ARM_SWI;
5207 inst.reloc.pc_rel = 0;
09d92015
MM
5208}
5209
c19d1205
ZW
5210/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5211 SMLAxy{cond} Rd,Rm,Rs,Rn
5212 SMLAWy{cond} Rd,Rm,Rs,Rn
5213 Error if any register is R15. */
e16bb312 5214
c19d1205
ZW
5215static void
5216do_smla (void)
e16bb312 5217{
c19d1205
ZW
5218 inst.instruction |= inst.operands[0].reg << 16;
5219 inst.instruction |= inst.operands[1].reg;
5220 inst.instruction |= inst.operands[2].reg << 8;
5221 inst.instruction |= inst.operands[3].reg << 12;
5222}
a737bd4d 5223
c19d1205
ZW
5224/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5225 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5226 Error if any register is R15.
5227 Warning if Rdlo == Rdhi. */
a737bd4d 5228
c19d1205
ZW
5229static void
5230do_smlal (void)
5231{
5232 inst.instruction |= inst.operands[0].reg << 12;
5233 inst.instruction |= inst.operands[1].reg << 16;
5234 inst.instruction |= inst.operands[2].reg;
5235 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5236
c19d1205
ZW
5237 if (inst.operands[0].reg == inst.operands[1].reg)
5238 as_tsktsk (_("rdhi and rdlo must be different"));
5239}
a737bd4d 5240
c19d1205
ZW
5241/* ARM V5E (El Segundo) signed-multiply (argument parse)
5242 SMULxy{cond} Rd,Rm,Rs
5243 Error if any register is R15. */
a737bd4d 5244
c19d1205
ZW
5245static void
5246do_smul (void)
5247{
5248 inst.instruction |= inst.operands[0].reg << 16;
5249 inst.instruction |= inst.operands[1].reg;
5250 inst.instruction |= inst.operands[2].reg << 8;
5251}
a737bd4d 5252
c19d1205 5253/* ARM V6 srs (argument parse). */
a737bd4d 5254
c19d1205
ZW
5255static void
5256do_srs (void)
5257{
5258 inst.instruction |= inst.operands[0].imm;
5259 if (inst.operands[0].writeback)
5260 inst.instruction |= WRITE_BACK;
5261}
a737bd4d 5262
c19d1205 5263/* ARM V6 strex (argument parse). */
a737bd4d 5264
c19d1205
ZW
5265static void
5266do_strex (void)
5267{
5268 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5269 || inst.operands[2].postind || inst.operands[2].writeback
5270 || inst.operands[2].immisreg || inst.operands[2].shifted
5271 || inst.operands[2].negative,
5272 _("instruction does not accept this addressing mode"));
e16bb312 5273
c19d1205 5274 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
a737bd4d 5275
c19d1205
ZW
5276 constraint (inst.operands[0].reg == inst.operands[1].reg
5277 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5278
c19d1205
ZW
5279 constraint (inst.reloc.exp.X_op != O_constant
5280 || inst.reloc.exp.X_add_number != 0,
5281 _("offset must be zero in ARM encoding"));
a737bd4d 5282
c19d1205
ZW
5283 inst.instruction |= inst.operands[0].reg << 12;
5284 inst.instruction |= inst.operands[1].reg;
5285 inst.instruction |= inst.operands[2].reg << 16;
5286 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5287}
5288
5289static void
c19d1205 5290do_strexd (void)
e16bb312 5291{
c19d1205
ZW
5292 constraint (inst.operands[1].reg % 2 != 0,
5293 _("even register required"));
5294 constraint (inst.operands[2].present
5295 && inst.operands[2].reg != inst.operands[1].reg + 1,
5296 _("can only store two consecutive registers"));
5297 /* If op 2 were present and equal to PC, this function wouldn't
5298 have been called in the first place. */
5299 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5300
c19d1205
ZW
5301 constraint (inst.operands[0].reg == inst.operands[1].reg
5302 || inst.operands[0].reg == inst.operands[1].reg + 1
5303 || inst.operands[0].reg == inst.operands[3].reg,
5304 BAD_OVERLAP);
e16bb312 5305
c19d1205
ZW
5306 inst.instruction |= inst.operands[0].reg << 12;
5307 inst.instruction |= inst.operands[1].reg;
5308 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5309}
5310
c19d1205
ZW
5311/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5312 extends it to 32-bits, and adds the result to a value in another
5313 register. You can specify a rotation by 0, 8, 16, or 24 bits
5314 before extracting the 16-bit value.
5315 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5316 Condition defaults to COND_ALWAYS.
5317 Error if any register uses R15. */
5318
e16bb312 5319static void
c19d1205 5320do_sxtah (void)
e16bb312 5321{
c19d1205
ZW
5322 inst.instruction |= inst.operands[0].reg << 12;
5323 inst.instruction |= inst.operands[1].reg << 16;
5324 inst.instruction |= inst.operands[2].reg;
5325 inst.instruction |= inst.operands[3].imm << 10;
5326}
e16bb312 5327
c19d1205 5328/* ARM V6 SXTH.
e16bb312 5329
c19d1205
ZW
5330 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5331 Condition defaults to COND_ALWAYS.
5332 Error if any register uses R15. */
e16bb312
NC
5333
5334static void
c19d1205 5335do_sxth (void)
e16bb312 5336{
c19d1205
ZW
5337 inst.instruction |= inst.operands[0].reg << 12;
5338 inst.instruction |= inst.operands[1].reg;
5339 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5340}
c19d1205
ZW
5341\f
5342/* VFP instructions. In a logical order: SP variant first, monad
5343 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5344
5345static void
c19d1205 5346do_vfp_sp_monadic (void)
e16bb312 5347{
c19d1205
ZW
5348 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5349 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5350}
5351
5352static void
c19d1205 5353do_vfp_sp_dyadic (void)
e16bb312 5354{
c19d1205
ZW
5355 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5356 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5357 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5358}
5359
5360static void
c19d1205 5361do_vfp_sp_compare_z (void)
e16bb312 5362{
c19d1205 5363 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5364}
5365
5366static void
c19d1205 5367do_vfp_dp_sp_cvt (void)
e16bb312 5368{
c19d1205
ZW
5369 inst.instruction |= inst.operands[0].reg << 12;
5370 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5371}
5372
5373static void
c19d1205 5374do_vfp_sp_dp_cvt (void)
e16bb312 5375{
c19d1205
ZW
5376 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5377 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5378}
5379
5380static void
c19d1205 5381do_vfp_reg_from_sp (void)
e16bb312 5382{
c19d1205
ZW
5383 inst.instruction |= inst.operands[0].reg << 12;
5384 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5385}
5386
5387static void
c19d1205 5388do_vfp_reg2_from_sp2 (void)
e16bb312 5389{
c19d1205
ZW
5390 constraint (inst.operands[2].imm != 2,
5391 _("only two consecutive VFP SP registers allowed here"));
5392 inst.instruction |= inst.operands[0].reg << 12;
5393 inst.instruction |= inst.operands[1].reg << 16;
5394 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5395}
5396
5397static void
c19d1205 5398do_vfp_sp_from_reg (void)
e16bb312 5399{
c19d1205
ZW
5400 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5401 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5402}
5403
5404static void
c19d1205 5405do_vfp_sp2_from_reg2 (void)
e16bb312 5406{
c19d1205
ZW
5407 constraint (inst.operands[0].imm != 2,
5408 _("only two consecutive VFP SP registers allowed here"));
5409 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5410 inst.instruction |= inst.operands[1].reg << 12;
5411 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5412}
5413
5414static void
c19d1205 5415do_vfp_sp_ldst (void)
e16bb312 5416{
c19d1205
ZW
5417 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5418 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5419}
5420
5421static void
c19d1205 5422do_vfp_dp_ldst (void)
e16bb312 5423{
c19d1205
ZW
5424 inst.instruction |= inst.operands[0].reg << 12;
5425 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5426}
5427
c19d1205 5428
e16bb312 5429static void
c19d1205 5430vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5431{
c19d1205
ZW
5432 if (inst.operands[0].writeback)
5433 inst.instruction |= WRITE_BACK;
5434 else
5435 constraint (ldstm_type != VFP_LDSTMIA,
5436 _("this addressing mode requires base-register writeback"));
5437 inst.instruction |= inst.operands[0].reg << 16;
5438 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5439 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5440}
5441
5442static void
c19d1205 5443vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5444{
c19d1205 5445 int count;
e16bb312 5446
c19d1205
ZW
5447 if (inst.operands[0].writeback)
5448 inst.instruction |= WRITE_BACK;
5449 else
5450 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5451 _("this addressing mode requires base-register writeback"));
e16bb312 5452
c19d1205
ZW
5453 inst.instruction |= inst.operands[0].reg << 16;
5454 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5455
c19d1205
ZW
5456 count = inst.operands[1].imm << 1;
5457 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5458 count += 1;
e16bb312 5459
c19d1205 5460 inst.instruction |= count;
e16bb312
NC
5461}
5462
5463static void
c19d1205 5464do_vfp_sp_ldstmia (void)
e16bb312 5465{
c19d1205 5466 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5467}
5468
5469static void
c19d1205 5470do_vfp_sp_ldstmdb (void)
e16bb312 5471{
c19d1205 5472 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5473}
5474
5475static void
c19d1205 5476do_vfp_dp_ldstmia (void)
e16bb312 5477{
c19d1205 5478 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5479}
5480
5481static void
c19d1205 5482do_vfp_dp_ldstmdb (void)
e16bb312 5483{
c19d1205 5484 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5485}
5486
5487static void
c19d1205 5488do_vfp_xp_ldstmia (void)
e16bb312 5489{
c19d1205
ZW
5490 vfp_dp_ldstm (VFP_LDSTMIAX);
5491}
e16bb312 5492
c19d1205
ZW
5493static void
5494do_vfp_xp_ldstmdb (void)
5495{
5496 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5497}
c19d1205
ZW
5498\f
5499/* FPA instructions. Also in a logical order. */
e16bb312 5500
c19d1205
ZW
5501static void
5502do_fpa_cmp (void)
5503{
5504 inst.instruction |= inst.operands[0].reg << 16;
5505 inst.instruction |= inst.operands[1].reg;
5506}
b99bd4ef
NC
5507
5508static void
c19d1205 5509do_fpa_ldmstm (void)
b99bd4ef 5510{
c19d1205
ZW
5511 inst.instruction |= inst.operands[0].reg << 12;
5512 switch (inst.operands[1].imm)
5513 {
5514 case 1: inst.instruction |= CP_T_X; break;
5515 case 2: inst.instruction |= CP_T_Y; break;
5516 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5517 case 4: break;
5518 default: abort ();
5519 }
b99bd4ef 5520
c19d1205
ZW
5521 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5522 {
5523 /* The instruction specified "ea" or "fd", so we can only accept
5524 [Rn]{!}. The instruction does not really support stacking or
5525 unstacking, so we have to emulate these by setting appropriate
5526 bits and offsets. */
5527 constraint (inst.reloc.exp.X_op != O_constant
5528 || inst.reloc.exp.X_add_number != 0,
5529 _("this instruction does not support indexing"));
b99bd4ef 5530
c19d1205
ZW
5531 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5532 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5533
c19d1205
ZW
5534 if (!(inst.instruction & INDEX_UP))
5535 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5536
c19d1205
ZW
5537 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5538 {
5539 inst.operands[2].preind = 0;
5540 inst.operands[2].postind = 1;
5541 }
5542 }
b99bd4ef 5543
c19d1205 5544 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5545}
c19d1205
ZW
5546\f
5547/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5548
c19d1205
ZW
5549static void
5550do_iwmmxt_tandorc (void)
5551{
5552 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5553}
b99bd4ef 5554
c19d1205
ZW
5555static void
5556do_iwmmxt_textrc (void)
5557{
5558 inst.instruction |= inst.operands[0].reg << 12;
5559 inst.instruction |= inst.operands[1].imm;
5560}
b99bd4ef
NC
5561
5562static void
c19d1205 5563do_iwmmxt_textrm (void)
b99bd4ef 5564{
c19d1205
ZW
5565 inst.instruction |= inst.operands[0].reg << 12;
5566 inst.instruction |= inst.operands[1].reg << 16;
5567 inst.instruction |= inst.operands[2].imm;
5568}
b99bd4ef 5569
c19d1205
ZW
5570static void
5571do_iwmmxt_tinsr (void)
5572{
5573 inst.instruction |= inst.operands[0].reg << 16;
5574 inst.instruction |= inst.operands[1].reg << 12;
5575 inst.instruction |= inst.operands[2].imm;
5576}
b99bd4ef 5577
c19d1205
ZW
5578static void
5579do_iwmmxt_tmia (void)
5580{
5581 inst.instruction |= inst.operands[0].reg << 5;
5582 inst.instruction |= inst.operands[1].reg;
5583 inst.instruction |= inst.operands[2].reg << 12;
5584}
b99bd4ef 5585
c19d1205
ZW
5586static void
5587do_iwmmxt_waligni (void)
5588{
5589 inst.instruction |= inst.operands[0].reg << 12;
5590 inst.instruction |= inst.operands[1].reg << 16;
5591 inst.instruction |= inst.operands[2].reg;
5592 inst.instruction |= inst.operands[3].imm << 20;
5593}
b99bd4ef 5594
c19d1205
ZW
5595static void
5596do_iwmmxt_wmov (void)
5597{
5598 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5599 inst.instruction |= inst.operands[0].reg << 12;
5600 inst.instruction |= inst.operands[1].reg << 16;
5601 inst.instruction |= inst.operands[1].reg;
5602}
b99bd4ef 5603
c19d1205
ZW
5604static void
5605do_iwmmxt_wldstbh (void)
5606{
8f06b2d8 5607 int reloc;
c19d1205
ZW
5608 inst.instruction |= inst.operands[0].reg << 12;
5609 inst.reloc.exp.X_add_number *= 4;
8f06b2d8
PB
5610 if (thumb_mode)
5611 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
5612 else
5613 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
5614 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
5615}
5616
c19d1205
ZW
5617static void
5618do_iwmmxt_wldstw (void)
5619{
5620 /* RIWR_RIWC clears .isreg for a control register. */
5621 if (!inst.operands[0].isreg)
5622 {
5623 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5624 inst.instruction |= 0xf0000000;
5625 }
b99bd4ef 5626
c19d1205
ZW
5627 inst.instruction |= inst.operands[0].reg << 12;
5628 encode_arm_cp_address (1, TRUE, TRUE, 0);
5629}
b99bd4ef
NC
5630
5631static void
c19d1205 5632do_iwmmxt_wldstd (void)
b99bd4ef 5633{
c19d1205 5634 inst.instruction |= inst.operands[0].reg << 12;
f2184508 5635 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 5636}
b99bd4ef 5637
c19d1205
ZW
5638static void
5639do_iwmmxt_wshufh (void)
5640{
5641 inst.instruction |= inst.operands[0].reg << 12;
5642 inst.instruction |= inst.operands[1].reg << 16;
5643 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5644 inst.instruction |= (inst.operands[2].imm & 0x0f);
5645}
b99bd4ef 5646
c19d1205
ZW
5647static void
5648do_iwmmxt_wzero (void)
5649{
5650 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5651 inst.instruction |= inst.operands[0].reg;
5652 inst.instruction |= inst.operands[0].reg << 12;
5653 inst.instruction |= inst.operands[0].reg << 16;
5654}
5655\f
5656/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5657 operations first, then control, shift, and load/store. */
b99bd4ef 5658
c19d1205 5659/* Insns like "foo X,Y,Z". */
b99bd4ef 5660
c19d1205
ZW
5661static void
5662do_mav_triple (void)
5663{
5664 inst.instruction |= inst.operands[0].reg << 16;
5665 inst.instruction |= inst.operands[1].reg;
5666 inst.instruction |= inst.operands[2].reg << 12;
5667}
b99bd4ef 5668
c19d1205
ZW
5669/* Insns like "foo W,X,Y,Z".
5670 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5671
c19d1205
ZW
5672static void
5673do_mav_quad (void)
5674{
5675 inst.instruction |= inst.operands[0].reg << 5;
5676 inst.instruction |= inst.operands[1].reg << 12;
5677 inst.instruction |= inst.operands[2].reg << 16;
5678 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5679}
5680
c19d1205
ZW
5681/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5682static void
5683do_mav_dspsc (void)
a737bd4d 5684{
c19d1205
ZW
5685 inst.instruction |= inst.operands[1].reg << 12;
5686}
a737bd4d 5687
c19d1205
ZW
5688/* Maverick shift immediate instructions.
5689 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5690 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5691
c19d1205
ZW
5692static void
5693do_mav_shift (void)
5694{
5695 int imm = inst.operands[2].imm;
a737bd4d 5696
c19d1205
ZW
5697 inst.instruction |= inst.operands[0].reg << 12;
5698 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5699
c19d1205
ZW
5700 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5701 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5702 Bit 4 should be 0. */
5703 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5704
c19d1205
ZW
5705 inst.instruction |= imm;
5706}
5707\f
5708/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5709
c19d1205
ZW
5710/* Xscale multiply-accumulate (argument parse)
5711 MIAcc acc0,Rm,Rs
5712 MIAPHcc acc0,Rm,Rs
5713 MIAxycc acc0,Rm,Rs. */
a737bd4d 5714
c19d1205
ZW
5715static void
5716do_xsc_mia (void)
5717{
5718 inst.instruction |= inst.operands[1].reg;
5719 inst.instruction |= inst.operands[2].reg << 12;
5720}
a737bd4d 5721
c19d1205 5722/* Xscale move-accumulator-register (argument parse)
a737bd4d 5723
c19d1205 5724 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5725
c19d1205
ZW
5726static void
5727do_xsc_mar (void)
5728{
5729 inst.instruction |= inst.operands[1].reg << 12;
5730 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5731}
5732
c19d1205 5733/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5734
c19d1205 5735 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5736
5737static void
c19d1205 5738do_xsc_mra (void)
b99bd4ef 5739{
c19d1205
ZW
5740 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5741 inst.instruction |= inst.operands[0].reg << 12;
5742 inst.instruction |= inst.operands[1].reg << 16;
5743}
5744\f
5745/* Encoding functions relevant only to Thumb. */
b99bd4ef 5746
c19d1205
ZW
5747/* inst.operands[i] is a shifted-register operand; encode
5748 it into inst.instruction in the format used by Thumb32. */
5749
5750static void
5751encode_thumb32_shifted_operand (int i)
5752{
5753 unsigned int value = inst.reloc.exp.X_add_number;
5754 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5755
9c3c69f2
PB
5756 constraint (inst.operands[i].immisreg,
5757 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
5758 inst.instruction |= inst.operands[i].reg;
5759 if (shift == SHIFT_RRX)
5760 inst.instruction |= SHIFT_ROR << 4;
5761 else
b99bd4ef 5762 {
c19d1205
ZW
5763 constraint (inst.reloc.exp.X_op != O_constant,
5764 _("expression too complex"));
5765
5766 constraint (value > 32
5767 || (value == 32 && (shift == SHIFT_LSL
5768 || shift == SHIFT_ROR)),
5769 _("shift expression is too large"));
5770
5771 if (value == 0)
5772 shift = SHIFT_LSL;
5773 else if (value == 32)
5774 value = 0;
5775
5776 inst.instruction |= shift << 4;
5777 inst.instruction |= (value & 0x1c) << 10;
5778 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5779 }
c19d1205 5780}
b99bd4ef 5781
b99bd4ef 5782
c19d1205
ZW
5783/* inst.operands[i] was set up by parse_address. Encode it into a
5784 Thumb32 format load or store instruction. Reject forms that cannot
5785 be used with such instructions. If is_t is true, reject forms that
5786 cannot be used with a T instruction; if is_d is true, reject forms
5787 that cannot be used with a D instruction. */
b99bd4ef 5788
c19d1205
ZW
5789static void
5790encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5791{
5792 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5793
5794 constraint (!inst.operands[i].isreg,
5795 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5796
c19d1205
ZW
5797 inst.instruction |= inst.operands[i].reg << 16;
5798 if (inst.operands[i].immisreg)
b99bd4ef 5799 {
c19d1205
ZW
5800 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5801 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5802 constraint (inst.operands[i].negative,
5803 _("Thumb does not support negative register indexing"));
5804 constraint (inst.operands[i].postind,
5805 _("Thumb does not support register post-indexing"));
5806 constraint (inst.operands[i].writeback,
5807 _("Thumb does not support register indexing with writeback"));
5808 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5809 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5810
c19d1205
ZW
5811 inst.instruction |= inst.operands[1].imm;
5812 if (inst.operands[i].shifted)
b99bd4ef 5813 {
c19d1205
ZW
5814 constraint (inst.reloc.exp.X_op != O_constant,
5815 _("expression too complex"));
9c3c69f2
PB
5816 constraint (inst.reloc.exp.X_add_number < 0
5817 || inst.reloc.exp.X_add_number > 3,
c19d1205 5818 _("shift out of range"));
9c3c69f2 5819 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
5820 }
5821 inst.reloc.type = BFD_RELOC_UNUSED;
5822 }
5823 else if (inst.operands[i].preind)
5824 {
5825 constraint (is_pc && inst.operands[i].writeback,
5826 _("cannot use writeback with PC-relative addressing"));
5827 constraint (is_t && inst.operands[1].writeback,
5828 _("cannot use writeback with this instruction"));
5829
5830 if (is_d)
5831 {
5832 inst.instruction |= 0x01000000;
5833 if (inst.operands[i].writeback)
5834 inst.instruction |= 0x00200000;
b99bd4ef 5835 }
c19d1205 5836 else
b99bd4ef 5837 {
c19d1205
ZW
5838 inst.instruction |= 0x00000c00;
5839 if (inst.operands[i].writeback)
5840 inst.instruction |= 0x00000100;
b99bd4ef 5841 }
c19d1205 5842 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 5843 }
c19d1205 5844 else if (inst.operands[i].postind)
b99bd4ef 5845 {
c19d1205
ZW
5846 assert (inst.operands[i].writeback);
5847 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5848 constraint (is_t, _("cannot use post-indexing with this instruction"));
5849
5850 if (is_d)
5851 inst.instruction |= 0x00200000;
5852 else
5853 inst.instruction |= 0x00000900;
5854 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5855 }
5856 else /* unindexed - only for coprocessor */
5857 inst.error = _("instruction does not accept unindexed addressing");
5858}
5859
5860/* Table of Thumb instructions which exist in both 16- and 32-bit
5861 encodings (the latter only in post-V6T2 cores). The index is the
5862 value used in the insns table below. When there is more than one
5863 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
5864 holds variant (1).
5865 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
5866#define T16_32_TAB \
5867 X(adc, 4140, eb400000), \
5868 X(adcs, 4140, eb500000), \
5869 X(add, 1c00, eb000000), \
5870 X(adds, 1c00, eb100000), \
0110f2b8
PB
5871 X(addi, 0000, f1000000), \
5872 X(addis, 0000, f1100000), \
5873 X(add_pc,000f, f20f0000), \
5874 X(add_sp,000d, f10d0000), \
e9f89963 5875 X(adr, 000f, f20f0000), \
c19d1205
ZW
5876 X(and, 4000, ea000000), \
5877 X(ands, 4000, ea100000), \
5878 X(asr, 1000, fa40f000), \
5879 X(asrs, 1000, fa50f000), \
0110f2b8
PB
5880 X(b, e000, f000b000), \
5881 X(bcond, d000, f0008000), \
c19d1205
ZW
5882 X(bic, 4380, ea200000), \
5883 X(bics, 4380, ea300000), \
5884 X(cmn, 42c0, eb100f00), \
5885 X(cmp, 2800, ebb00f00), \
5886 X(cpsie, b660, f3af8400), \
5887 X(cpsid, b670, f3af8600), \
5888 X(cpy, 4600, ea4f0000), \
0110f2b8 5889 X(dec_sp,80dd, f1bd0d00), \
c19d1205
ZW
5890 X(eor, 4040, ea800000), \
5891 X(eors, 4040, ea900000), \
0110f2b8 5892 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
5893 X(ldmia, c800, e8900000), \
5894 X(ldr, 6800, f8500000), \
5895 X(ldrb, 7800, f8100000), \
5896 X(ldrh, 8800, f8300000), \
5897 X(ldrsb, 5600, f9100000), \
5898 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
5899 X(ldr_pc,4800, f85f0000), \
5900 X(ldr_pc2,4800, f85f0000), \
5901 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
5902 X(lsl, 0000, fa00f000), \
5903 X(lsls, 0000, fa10f000), \
5904 X(lsr, 0800, fa20f000), \
5905 X(lsrs, 0800, fa30f000), \
5906 X(mov, 2000, ea4f0000), \
5907 X(movs, 2000, ea5f0000), \
5908 X(mul, 4340, fb00f000), \
5909 X(muls, 4340, ffffffff), /* no 32b muls */ \
5910 X(mvn, 43c0, ea6f0000), \
5911 X(mvns, 43c0, ea7f0000), \
5912 X(neg, 4240, f1c00000), /* rsb #0 */ \
5913 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5914 X(orr, 4300, ea400000), \
5915 X(orrs, 4300, ea500000), \
e9f89963
PB
5916 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
5917 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
5918 X(rev, ba00, fa90f080), \
5919 X(rev16, ba40, fa90f090), \
5920 X(revsh, bac0, fa90f0b0), \
5921 X(ror, 41c0, fa60f000), \
5922 X(rors, 41c0, fa70f000), \
5923 X(sbc, 4180, eb600000), \
5924 X(sbcs, 4180, eb700000), \
5925 X(stmia, c000, e8800000), \
5926 X(str, 6000, f8400000), \
5927 X(strb, 7000, f8000000), \
5928 X(strh, 8000, f8200000), \
0110f2b8 5929 X(str_sp,9000, f84d0000), \
c19d1205
ZW
5930 X(sub, 1e00, eba00000), \
5931 X(subs, 1e00, ebb00000), \
0110f2b8
PB
5932 X(subi, 8000, f1a00000), \
5933 X(subis, 8000, f1b00000), \
c19d1205
ZW
5934 X(sxtb, b240, fa4ff080), \
5935 X(sxth, b200, fa0ff080), \
5936 X(tst, 4200, ea100f00), \
5937 X(uxtb, b2c0, fa5ff080), \
5938 X(uxth, b280, fa1ff080), \
5939 X(nop, bf00, f3af8000), \
5940 X(yield, bf10, f3af8001), \
5941 X(wfe, bf20, f3af8002), \
5942 X(wfi, bf30, f3af8003), \
5943 X(sev, bf40, f3af9004), /* typo, 8004? */
5944
5945/* To catch errors in encoding functions, the codes are all offset by
5946 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5947 as 16-bit instructions. */
5948#define X(a,b,c) T_MNEM_##a
5949enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5950#undef X
5951
5952#define X(a,b,c) 0x##b
5953static const unsigned short thumb_op16[] = { T16_32_TAB };
5954#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5955#undef X
5956
5957#define X(a,b,c) 0x##c
5958static const unsigned int thumb_op32[] = { T16_32_TAB };
5959#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5960#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5961#undef X
5962#undef T16_32_TAB
5963
5964/* Thumb instruction encoders, in alphabetical order. */
5965
92e90b6e
PB
5966/* ADDW or SUBW. */
5967static void
5968do_t_add_sub_w (void)
5969{
5970 int Rd, Rn;
5971
5972 Rd = inst.operands[0].reg;
5973 Rn = inst.operands[1].reg;
5974
5975 constraint (Rd == 15, _("PC not allowed as destination"));
5976 inst.instruction |= (Rn << 16) | (Rd << 8);
5977 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
5978}
5979
c19d1205
ZW
5980/* Parse an add or subtract instruction. We get here with inst.instruction
5981 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5982
5983static void
5984do_t_add_sub (void)
5985{
5986 int Rd, Rs, Rn;
5987
5988 Rd = inst.operands[0].reg;
5989 Rs = (inst.operands[1].present
5990 ? inst.operands[1].reg /* Rd, Rs, foo */
5991 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5992
5993 if (unified_syntax)
5994 {
0110f2b8
PB
5995 bfd_boolean flags;
5996 bfd_boolean narrow;
5997 int opcode;
5998
5999 flags = (inst.instruction == T_MNEM_adds
6000 || inst.instruction == T_MNEM_subs);
6001 if (flags)
6002 narrow = (current_it_mask == 0);
6003 else
6004 narrow = (current_it_mask != 0);
c19d1205 6005 if (!inst.operands[2].isreg)
b99bd4ef 6006 {
0110f2b8
PB
6007 opcode = 0;
6008 if (inst.size_req != 4)
6009 {
6010 int add;
6011
6012 add = (inst.instruction == T_MNEM_add
6013 || inst.instruction == T_MNEM_adds);
6014 /* Attempt to use a narrow opcode, with relaxation if
6015 appropriate. */
6016 if (Rd == REG_SP && Rs == REG_SP && !flags)
6017 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
6018 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
6019 opcode = T_MNEM_add_sp;
6020 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
6021 opcode = T_MNEM_add_pc;
6022 else if (Rd <= 7 && Rs <= 7 && narrow)
6023 {
6024 if (flags)
6025 opcode = add ? T_MNEM_addis : T_MNEM_subis;
6026 else
6027 opcode = add ? T_MNEM_addi : T_MNEM_subi;
6028 }
6029 if (opcode)
6030 {
6031 inst.instruction = THUMB_OP16(opcode);
6032 inst.instruction |= (Rd << 4) | Rs;
6033 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6034 if (inst.size_req != 2)
6035 inst.relax = opcode;
6036 }
6037 else
6038 constraint (inst.size_req == 2, BAD_HIREG);
6039 }
6040 if (inst.size_req == 4
6041 || (inst.size_req != 2 && !opcode))
6042 {
6043 /* ??? Convert large immediates to addw/subw. */
6044 inst.instruction = THUMB_OP32 (inst.instruction);
6045 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6046 inst.instruction |= inst.operands[0].reg << 8;
6047 inst.instruction |= inst.operands[1].reg << 16;
6048 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6049 }
b99bd4ef 6050 }
c19d1205
ZW
6051 else
6052 {
6053 Rn = inst.operands[2].reg;
6054 /* See if we can do this with a 16-bit instruction. */
6055 if (!inst.operands[2].shifted && inst.size_req != 4)
6056 {
e27ec89e
PB
6057 if (Rd > 7 || Rs > 7 || Rn > 7)
6058 narrow = FALSE;
6059
6060 if (narrow)
c19d1205 6061 {
e27ec89e
PB
6062 inst.instruction = ((inst.instruction == T_MNEM_adds
6063 || inst.instruction == T_MNEM_add)
c19d1205
ZW
6064 ? T_OPCODE_ADD_R3
6065 : T_OPCODE_SUB_R3);
6066 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6067 return;
6068 }
b99bd4ef 6069
c19d1205
ZW
6070 if (inst.instruction == T_MNEM_add)
6071 {
6072 if (Rd == Rs)
6073 {
6074 inst.instruction = T_OPCODE_ADD_HI;
6075 inst.instruction |= (Rd & 8) << 4;
6076 inst.instruction |= (Rd & 7);
6077 inst.instruction |= Rn << 3;
6078 return;
6079 }
6080 /* ... because addition is commutative! */
6081 else if (Rd == Rn)
6082 {
6083 inst.instruction = T_OPCODE_ADD_HI;
6084 inst.instruction |= (Rd & 8) << 4;
6085 inst.instruction |= (Rd & 7);
6086 inst.instruction |= Rs << 3;
6087 return;
6088 }
6089 }
6090 }
6091 /* If we get here, it can't be done in 16 bits. */
6092 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
6093 _("shift must be constant"));
6094 inst.instruction = THUMB_OP32 (inst.instruction);
6095 inst.instruction |= Rd << 8;
6096 inst.instruction |= Rs << 16;
6097 encode_thumb32_shifted_operand (2);
6098 }
6099 }
6100 else
6101 {
6102 constraint (inst.instruction == T_MNEM_adds
6103 || inst.instruction == T_MNEM_subs,
6104 BAD_THUMB32);
b99bd4ef 6105
c19d1205 6106 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 6107 {
c19d1205
ZW
6108 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
6109 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
6110 BAD_HIREG);
6111
6112 inst.instruction = (inst.instruction == T_MNEM_add
6113 ? 0x0000 : 0x8000);
6114 inst.instruction |= (Rd << 4) | Rs;
6115 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
6116 return;
6117 }
6118
c19d1205
ZW
6119 Rn = inst.operands[2].reg;
6120 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 6121
c19d1205
ZW
6122 /* We now have Rd, Rs, and Rn set to registers. */
6123 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 6124 {
c19d1205
ZW
6125 /* Can't do this for SUB. */
6126 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
6127 inst.instruction = T_OPCODE_ADD_HI;
6128 inst.instruction |= (Rd & 8) << 4;
6129 inst.instruction |= (Rd & 7);
6130 if (Rs == Rd)
6131 inst.instruction |= Rn << 3;
6132 else if (Rn == Rd)
6133 inst.instruction |= Rs << 3;
6134 else
6135 constraint (1, _("dest must overlap one source register"));
6136 }
6137 else
6138 {
6139 inst.instruction = (inst.instruction == T_MNEM_add
6140 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
6141 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 6142 }
b99bd4ef 6143 }
b99bd4ef
NC
6144}
6145
c19d1205
ZW
6146static void
6147do_t_adr (void)
6148{
0110f2b8
PB
6149 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
6150 {
6151 /* Defer to section relaxation. */
6152 inst.relax = inst.instruction;
6153 inst.instruction = THUMB_OP16 (inst.instruction);
6154 inst.instruction |= inst.operands[0].reg << 4;
6155 }
6156 else if (unified_syntax && inst.size_req != 2)
e9f89963 6157 {
0110f2b8 6158 /* Generate a 32-bit opcode. */
e9f89963
PB
6159 inst.instruction = THUMB_OP32 (inst.instruction);
6160 inst.instruction |= inst.operands[0].reg << 8;
6161 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
6162 inst.reloc.pc_rel = 1;
6163 }
6164 else
6165 {
0110f2b8 6166 /* Generate a 16-bit opcode. */
e9f89963
PB
6167 inst.instruction = THUMB_OP16 (inst.instruction);
6168 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6169 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
6170 inst.reloc.pc_rel = 1;
b99bd4ef 6171
e9f89963
PB
6172 inst.instruction |= inst.operands[0].reg << 4;
6173 }
c19d1205 6174}
b99bd4ef 6175
c19d1205
ZW
6176/* Arithmetic instructions for which there is just one 16-bit
6177 instruction encoding, and it allows only two low registers.
6178 For maximal compatibility with ARM syntax, we allow three register
6179 operands even when Thumb-32 instructions are not available, as long
6180 as the first two are identical. For instance, both "sbc r0,r1" and
6181 "sbc r0,r0,r1" are allowed. */
b99bd4ef 6182static void
c19d1205 6183do_t_arit3 (void)
b99bd4ef 6184{
c19d1205 6185 int Rd, Rs, Rn;
b99bd4ef 6186
c19d1205
ZW
6187 Rd = inst.operands[0].reg;
6188 Rs = (inst.operands[1].present
6189 ? inst.operands[1].reg /* Rd, Rs, foo */
6190 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6191 Rn = inst.operands[2].reg;
b99bd4ef 6192
c19d1205 6193 if (unified_syntax)
b99bd4ef 6194 {
c19d1205
ZW
6195 if (!inst.operands[2].isreg)
6196 {
6197 /* For an immediate, we always generate a 32-bit opcode;
6198 section relaxation will shrink it later if possible. */
6199 inst.instruction = THUMB_OP32 (inst.instruction);
6200 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6201 inst.instruction |= Rd << 8;
6202 inst.instruction |= Rs << 16;
6203 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6204 }
6205 else
6206 {
e27ec89e
PB
6207 bfd_boolean narrow;
6208
c19d1205 6209 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6210 if (THUMB_SETS_FLAGS (inst.instruction))
6211 narrow = current_it_mask == 0;
6212 else
6213 narrow = current_it_mask != 0;
6214
6215 if (Rd > 7 || Rn > 7 || Rs > 7)
6216 narrow = FALSE;
6217 if (inst.operands[2].shifted)
6218 narrow = FALSE;
6219 if (inst.size_req == 4)
6220 narrow = FALSE;
6221
6222 if (narrow
c19d1205
ZW
6223 && Rd == Rs)
6224 {
6225 inst.instruction = THUMB_OP16 (inst.instruction);
6226 inst.instruction |= Rd;
6227 inst.instruction |= Rn << 3;
6228 return;
6229 }
b99bd4ef 6230
c19d1205
ZW
6231 /* If we get here, it can't be done in 16 bits. */
6232 constraint (inst.operands[2].shifted
6233 && inst.operands[2].immisreg,
6234 _("shift must be constant"));
6235 inst.instruction = THUMB_OP32 (inst.instruction);
6236 inst.instruction |= Rd << 8;
6237 inst.instruction |= Rs << 16;
6238 encode_thumb32_shifted_operand (2);
6239 }
a737bd4d 6240 }
c19d1205 6241 else
b99bd4ef 6242 {
c19d1205
ZW
6243 /* On its face this is a lie - the instruction does set the
6244 flags. However, the only supported mnemonic in this mode
6245 says it doesn't. */
6246 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6247
c19d1205
ZW
6248 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6249 _("unshifted register required"));
6250 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6251 constraint (Rd != Rs,
6252 _("dest and source1 must be the same register"));
a737bd4d 6253
c19d1205
ZW
6254 inst.instruction = THUMB_OP16 (inst.instruction);
6255 inst.instruction |= Rd;
6256 inst.instruction |= Rn << 3;
b99bd4ef 6257 }
a737bd4d 6258}
b99bd4ef 6259
c19d1205
ZW
6260/* Similarly, but for instructions where the arithmetic operation is
6261 commutative, so we can allow either of them to be different from
6262 the destination operand in a 16-bit instruction. For instance, all
6263 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6264 accepted. */
6265static void
6266do_t_arit3c (void)
a737bd4d 6267{
c19d1205 6268 int Rd, Rs, Rn;
b99bd4ef 6269
c19d1205
ZW
6270 Rd = inst.operands[0].reg;
6271 Rs = (inst.operands[1].present
6272 ? inst.operands[1].reg /* Rd, Rs, foo */
6273 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6274 Rn = inst.operands[2].reg;
a737bd4d 6275
c19d1205 6276 if (unified_syntax)
a737bd4d 6277 {
c19d1205 6278 if (!inst.operands[2].isreg)
b99bd4ef 6279 {
c19d1205
ZW
6280 /* For an immediate, we always generate a 32-bit opcode;
6281 section relaxation will shrink it later if possible. */
6282 inst.instruction = THUMB_OP32 (inst.instruction);
6283 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6284 inst.instruction |= Rd << 8;
6285 inst.instruction |= Rs << 16;
6286 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6287 }
c19d1205 6288 else
a737bd4d 6289 {
e27ec89e
PB
6290 bfd_boolean narrow;
6291
c19d1205 6292 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6293 if (THUMB_SETS_FLAGS (inst.instruction))
6294 narrow = current_it_mask == 0;
6295 else
6296 narrow = current_it_mask != 0;
6297
6298 if (Rd > 7 || Rn > 7 || Rs > 7)
6299 narrow = FALSE;
6300 if (inst.operands[2].shifted)
6301 narrow = FALSE;
6302 if (inst.size_req == 4)
6303 narrow = FALSE;
6304
6305 if (narrow)
a737bd4d 6306 {
c19d1205 6307 if (Rd == Rs)
a737bd4d 6308 {
c19d1205
ZW
6309 inst.instruction = THUMB_OP16 (inst.instruction);
6310 inst.instruction |= Rd;
6311 inst.instruction |= Rn << 3;
6312 return;
a737bd4d 6313 }
c19d1205 6314 if (Rd == Rn)
a737bd4d 6315 {
c19d1205
ZW
6316 inst.instruction = THUMB_OP16 (inst.instruction);
6317 inst.instruction |= Rd;
6318 inst.instruction |= Rs << 3;
6319 return;
a737bd4d
NC
6320 }
6321 }
c19d1205
ZW
6322
6323 /* If we get here, it can't be done in 16 bits. */
6324 constraint (inst.operands[2].shifted
6325 && inst.operands[2].immisreg,
6326 _("shift must be constant"));
6327 inst.instruction = THUMB_OP32 (inst.instruction);
6328 inst.instruction |= Rd << 8;
6329 inst.instruction |= Rs << 16;
6330 encode_thumb32_shifted_operand (2);
a737bd4d 6331 }
b99bd4ef 6332 }
c19d1205
ZW
6333 else
6334 {
6335 /* On its face this is a lie - the instruction does set the
6336 flags. However, the only supported mnemonic in this mode
6337 says it doesn't. */
6338 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6339
c19d1205
ZW
6340 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6341 _("unshifted register required"));
6342 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6343
6344 inst.instruction = THUMB_OP16 (inst.instruction);
6345 inst.instruction |= Rd;
6346
6347 if (Rd == Rs)
6348 inst.instruction |= Rn << 3;
6349 else if (Rd == Rn)
6350 inst.instruction |= Rs << 3;
6351 else
6352 constraint (1, _("dest must overlap one source register"));
6353 }
a737bd4d
NC
6354}
6355
c19d1205
ZW
6356static void
6357do_t_bfc (void)
a737bd4d 6358{
c19d1205
ZW
6359 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6360 constraint (msb > 32, _("bit-field extends past end of register"));
6361 /* The instruction encoding stores the LSB and MSB,
6362 not the LSB and width. */
6363 inst.instruction |= inst.operands[0].reg << 8;
6364 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6365 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6366 inst.instruction |= msb - 1;
b99bd4ef
NC
6367}
6368
c19d1205
ZW
6369static void
6370do_t_bfi (void)
b99bd4ef 6371{
c19d1205 6372 unsigned int msb;
b99bd4ef 6373
c19d1205
ZW
6374 /* #0 in second position is alternative syntax for bfc, which is
6375 the same instruction but with REG_PC in the Rm field. */
6376 if (!inst.operands[1].isreg)
6377 inst.operands[1].reg = REG_PC;
b99bd4ef 6378
c19d1205
ZW
6379 msb = inst.operands[2].imm + inst.operands[3].imm;
6380 constraint (msb > 32, _("bit-field extends past end of register"));
6381 /* The instruction encoding stores the LSB and MSB,
6382 not the LSB and width. */
6383 inst.instruction |= inst.operands[0].reg << 8;
6384 inst.instruction |= inst.operands[1].reg << 16;
6385 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6386 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6387 inst.instruction |= msb - 1;
b99bd4ef
NC
6388}
6389
c19d1205
ZW
6390static void
6391do_t_bfx (void)
b99bd4ef 6392{
c19d1205
ZW
6393 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6394 _("bit-field extends past end of register"));
6395 inst.instruction |= inst.operands[0].reg << 8;
6396 inst.instruction |= inst.operands[1].reg << 16;
6397 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6398 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6399 inst.instruction |= inst.operands[3].imm - 1;
6400}
b99bd4ef 6401
c19d1205
ZW
6402/* ARM V5 Thumb BLX (argument parse)
6403 BLX <target_addr> which is BLX(1)
6404 BLX <Rm> which is BLX(2)
6405 Unfortunately, there are two different opcodes for this mnemonic.
6406 So, the insns[].value is not used, and the code here zaps values
6407 into inst.instruction.
b99bd4ef 6408
c19d1205
ZW
6409 ??? How to take advantage of the additional two bits of displacement
6410 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6411
c19d1205
ZW
6412static void
6413do_t_blx (void)
6414{
6415 if (inst.operands[0].isreg)
6416 /* We have a register, so this is BLX(2). */
6417 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6418 else
6419 {
c19d1205 6420 /* No register. This must be BLX(1). */
2fc8bdac 6421 inst.instruction = 0xf000e800;
c19d1205
ZW
6422 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6423 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6424 }
6425}
6426
c19d1205
ZW
6427static void
6428do_t_branch (void)
b99bd4ef 6429{
0110f2b8
PB
6430 int opcode;
6431 if (inst.cond != COND_ALWAYS)
6432 opcode = T_MNEM_bcond;
6433 else
6434 opcode = inst.instruction;
6435
6436 if (unified_syntax && inst.size_req == 4)
c19d1205 6437 {
0110f2b8 6438 inst.instruction = THUMB_OP32(opcode);
c19d1205 6439 if (inst.cond == COND_ALWAYS)
0110f2b8 6440 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
6441 else
6442 {
6443 assert (inst.cond != 0xF);
0110f2b8 6444 inst.instruction |= inst.cond << 22;
c19d1205
ZW
6445 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6446 }
6447 }
b99bd4ef
NC
6448 else
6449 {
0110f2b8 6450 inst.instruction = THUMB_OP16(opcode);
c19d1205
ZW
6451 if (inst.cond == COND_ALWAYS)
6452 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6453 else
b99bd4ef 6454 {
0110f2b8 6455 inst.instruction |= inst.cond << 8;
c19d1205 6456 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6457 }
0110f2b8
PB
6458 /* Allow section relaxation. */
6459 if (unified_syntax && inst.size_req != 2)
6460 inst.relax = opcode;
b99bd4ef 6461 }
c19d1205
ZW
6462
6463 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6464}
6465
6466static void
c19d1205 6467do_t_bkpt (void)
b99bd4ef 6468{
c19d1205 6469 if (inst.operands[0].present)
b99bd4ef 6470 {
c19d1205
ZW
6471 constraint (inst.operands[0].imm > 255,
6472 _("immediate value out of range"));
6473 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6474 }
b99bd4ef
NC
6475}
6476
6477static void
c19d1205 6478do_t_branch23 (void)
b99bd4ef 6479{
c19d1205 6480 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6481 inst.reloc.pc_rel = 1;
6482
c19d1205
ZW
6483 /* If the destination of the branch is a defined symbol which does not have
6484 the THUMB_FUNC attribute, then we must be calling a function which has
6485 the (interfacearm) attribute. We look for the Thumb entry point to that
6486 function and change the branch to refer to that function instead. */
6487 if ( inst.reloc.exp.X_op == O_symbol
6488 && inst.reloc.exp.X_add_symbol != NULL
6489 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6490 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6491 inst.reloc.exp.X_add_symbol =
6492 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6493}
6494
6495static void
c19d1205 6496do_t_bx (void)
90e4755a 6497{
c19d1205
ZW
6498 inst.instruction |= inst.operands[0].reg << 3;
6499 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6500 should cause the alignment to be checked once it is known. This is
6501 because BX PC only works if the instruction is word aligned. */
6502}
90e4755a 6503
c19d1205
ZW
6504static void
6505do_t_bxj (void)
6506{
6507 if (inst.operands[0].reg == REG_PC)
6508 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6509
c19d1205 6510 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6511}
6512
6513static void
c19d1205 6514do_t_clz (void)
90e4755a 6515{
c19d1205
ZW
6516 inst.instruction |= inst.operands[0].reg << 8;
6517 inst.instruction |= inst.operands[1].reg << 16;
6518 inst.instruction |= inst.operands[1].reg;
6519}
90e4755a 6520
c19d1205
ZW
6521static void
6522do_t_cpsi (void)
6523{
6524 if (unified_syntax
6525 && (inst.operands[1].present || inst.size_req == 4))
90e4755a 6526 {
c19d1205
ZW
6527 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6528 inst.instruction = 0xf3af8000;
6529 inst.instruction |= imod << 9;
6530 inst.instruction |= inst.operands[0].imm << 5;
6531 if (inst.operands[1].present)
6532 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6533 }
c19d1205 6534 else
90e4755a 6535 {
c19d1205
ZW
6536 constraint (inst.operands[1].present,
6537 _("Thumb does not support the 2-argument "
6538 "form of this instruction"));
6539 inst.instruction |= inst.operands[0].imm;
90e4755a 6540 }
90e4755a
RE
6541}
6542
c19d1205
ZW
6543/* THUMB CPY instruction (argument parse). */
6544
90e4755a 6545static void
c19d1205 6546do_t_cpy (void)
90e4755a 6547{
c19d1205 6548 if (inst.size_req == 4)
90e4755a 6549 {
c19d1205
ZW
6550 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6551 inst.instruction |= inst.operands[0].reg << 8;
6552 inst.instruction |= inst.operands[1].reg;
90e4755a 6553 }
c19d1205 6554 else
90e4755a 6555 {
c19d1205
ZW
6556 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6557 inst.instruction |= (inst.operands[0].reg & 0x7);
6558 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6559 }
90e4755a
RE
6560}
6561
90e4755a 6562static void
c19d1205 6563do_t_czb (void)
90e4755a 6564{
c19d1205
ZW
6565 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6566 inst.instruction |= inst.operands[0].reg;
6567 inst.reloc.pc_rel = 1;
6568 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6569}
90e4755a 6570
c19d1205
ZW
6571static void
6572do_t_hint (void)
6573{
6574 if (unified_syntax && inst.size_req == 4)
6575 inst.instruction = THUMB_OP32 (inst.instruction);
6576 else
6577 inst.instruction = THUMB_OP16 (inst.instruction);
6578}
90e4755a 6579
c19d1205
ZW
6580static void
6581do_t_it (void)
6582{
6583 unsigned int cond = inst.operands[0].imm;
e27ec89e
PB
6584
6585 current_it_mask = (inst.instruction & 0xf) | 0x10;
6586 current_cc = cond;
6587
6588 /* If the condition is a negative condition, invert the mask. */
c19d1205 6589 if ((cond & 0x1) == 0x0)
90e4755a 6590 {
c19d1205 6591 unsigned int mask = inst.instruction & 0x000f;
90e4755a 6592
c19d1205
ZW
6593 if ((mask & 0x7) == 0)
6594 /* no conversion needed */;
6595 else if ((mask & 0x3) == 0)
e27ec89e
PB
6596 mask ^= 0x8;
6597 else if ((mask & 0x1) == 0)
6598 mask ^= 0xC;
c19d1205 6599 else
e27ec89e 6600 mask ^= 0xE;
90e4755a 6601
e27ec89e
PB
6602 inst.instruction &= 0xfff0;
6603 inst.instruction |= mask;
c19d1205 6604 }
90e4755a 6605
c19d1205
ZW
6606 inst.instruction |= cond << 4;
6607}
90e4755a 6608
c19d1205
ZW
6609static void
6610do_t_ldmstm (void)
6611{
6612 /* This really doesn't seem worth it. */
6613 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6614 _("expression too complex"));
6615 constraint (inst.operands[1].writeback,
6616 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6617
c19d1205
ZW
6618 if (unified_syntax)
6619 {
6620 /* See if we can use a 16-bit instruction. */
6621 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6622 && inst.size_req != 4
6623 && inst.operands[0].reg <= 7
6624 && !(inst.operands[1].imm & ~0xff)
6625 && (inst.instruction == T_MNEM_stmia
6626 ? inst.operands[0].writeback
6627 : (inst.operands[0].writeback
6628 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6629 {
c19d1205
ZW
6630 if (inst.instruction == T_MNEM_stmia
6631 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6632 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6633 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6634 inst.operands[0].reg);
90e4755a 6635
c19d1205
ZW
6636 inst.instruction = THUMB_OP16 (inst.instruction);
6637 inst.instruction |= inst.operands[0].reg << 8;
6638 inst.instruction |= inst.operands[1].imm;
6639 }
6640 else
6641 {
6642 if (inst.operands[1].imm & (1 << 13))
6643 as_warn (_("SP should not be in register list"));
6644 if (inst.instruction == T_MNEM_stmia)
90e4755a 6645 {
c19d1205
ZW
6646 if (inst.operands[1].imm & (1 << 15))
6647 as_warn (_("PC should not be in register list"));
6648 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6649 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6650 inst.operands[0].reg);
90e4755a
RE
6651 }
6652 else
6653 {
c19d1205
ZW
6654 if (inst.operands[1].imm & (1 << 14)
6655 && inst.operands[1].imm & (1 << 15))
6656 as_warn (_("LR and PC should not both be in register list"));
6657 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6658 && inst.operands[0].writeback)
6659 as_warn (_("base register should not be in register list "
6660 "when written back"));
90e4755a 6661 }
c19d1205
ZW
6662 if (inst.instruction < 0xffff)
6663 inst.instruction = THUMB_OP32 (inst.instruction);
6664 inst.instruction |= inst.operands[0].reg << 16;
6665 inst.instruction |= inst.operands[1].imm;
6666 if (inst.operands[0].writeback)
6667 inst.instruction |= WRITE_BACK;
90e4755a
RE
6668 }
6669 }
c19d1205 6670 else
90e4755a 6671 {
c19d1205
ZW
6672 constraint (inst.operands[0].reg > 7
6673 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6674 if (inst.instruction == T_MNEM_stmia)
f03698e6 6675 {
c19d1205
ZW
6676 if (!inst.operands[0].writeback)
6677 as_warn (_("this instruction will write back the base register"));
6678 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6679 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6680 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6681 inst.operands[0].reg);
f03698e6 6682 }
c19d1205 6683 else
90e4755a 6684 {
c19d1205
ZW
6685 if (!inst.operands[0].writeback
6686 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6687 as_warn (_("this instruction will write back the base register"));
6688 else if (inst.operands[0].writeback
6689 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6690 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6691 }
6692
c19d1205
ZW
6693 inst.instruction = THUMB_OP16 (inst.instruction);
6694 inst.instruction |= inst.operands[0].reg << 8;
6695 inst.instruction |= inst.operands[1].imm;
6696 }
6697}
e28cd48c 6698
c19d1205
ZW
6699static void
6700do_t_ldrex (void)
6701{
6702 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6703 || inst.operands[1].postind || inst.operands[1].writeback
6704 || inst.operands[1].immisreg || inst.operands[1].shifted
6705 || inst.operands[1].negative,
6706 _("instruction does not accept this addressing mode"));
e28cd48c 6707
c19d1205
ZW
6708 inst.instruction |= inst.operands[0].reg << 12;
6709 inst.instruction |= inst.operands[1].reg << 16;
6710 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6711}
e28cd48c 6712
c19d1205
ZW
6713static void
6714do_t_ldrexd (void)
6715{
6716 if (!inst.operands[1].present)
1cac9012 6717 {
c19d1205
ZW
6718 constraint (inst.operands[0].reg == REG_LR,
6719 _("r14 not allowed as first register "
6720 "when second register is omitted"));
6721 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6722 }
c19d1205
ZW
6723 constraint (inst.operands[0].reg == inst.operands[1].reg,
6724 BAD_OVERLAP);
b99bd4ef 6725
c19d1205
ZW
6726 inst.instruction |= inst.operands[0].reg << 12;
6727 inst.instruction |= inst.operands[1].reg << 8;
6728 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6729}
6730
6731static void
c19d1205 6732do_t_ldst (void)
b99bd4ef 6733{
0110f2b8
PB
6734 unsigned long opcode;
6735 int Rn;
6736
6737 opcode = inst.instruction;
c19d1205 6738 if (unified_syntax)
b99bd4ef 6739 {
0110f2b8
PB
6740 if (inst.operands[1].isreg
6741 && !inst.operands[1].writeback
c19d1205
ZW
6742 && !inst.operands[1].shifted && !inst.operands[1].postind
6743 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
6744 && opcode <= 0xffff
6745 && inst.size_req != 4)
c19d1205 6746 {
0110f2b8
PB
6747 /* Insn may have a 16-bit form. */
6748 Rn = inst.operands[1].reg;
6749 if (inst.operands[1].immisreg)
6750 {
6751 inst.instruction = THUMB_OP16 (opcode);
6752 /* [Rn, Ri] */
6753 if (Rn <= 7 && inst.operands[1].imm <= 7)
6754 goto op16;
6755 }
6756 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
6757 && opcode != T_MNEM_ldrsb)
6758 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
6759 || (Rn == REG_SP && opcode == T_MNEM_str))
6760 {
6761 /* [Rn, #const] */
6762 if (Rn > 7)
6763 {
6764 if (Rn == REG_PC)
6765 {
6766 if (inst.reloc.pc_rel)
6767 opcode = T_MNEM_ldr_pc2;
6768 else
6769 opcode = T_MNEM_ldr_pc;
6770 }
6771 else
6772 {
6773 if (opcode == T_MNEM_ldr)
6774 opcode = T_MNEM_ldr_sp;
6775 else
6776 opcode = T_MNEM_str_sp;
6777 }
6778 inst.instruction = inst.operands[0].reg << 8;
6779 }
6780 else
6781 {
6782 inst.instruction = inst.operands[0].reg;
6783 inst.instruction |= inst.operands[1].reg << 3;
6784 }
6785 inst.instruction |= THUMB_OP16 (opcode);
6786 if (inst.size_req == 2)
6787 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6788 else
6789 inst.relax = opcode;
6790 return;
6791 }
c19d1205 6792 }
0110f2b8
PB
6793 /* Definitely a 32-bit variant. */
6794 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
6795 inst.instruction |= inst.operands[0].reg << 12;
6796 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
6797 return;
6798 }
6799
c19d1205
ZW
6800 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6801
6802 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 6803 {
c19d1205
ZW
6804 /* Only [Rn,Rm] is acceptable. */
6805 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6806 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6807 || inst.operands[1].postind || inst.operands[1].shifted
6808 || inst.operands[1].negative,
6809 _("Thumb does not support this addressing mode"));
6810 inst.instruction = THUMB_OP16 (inst.instruction);
6811 goto op16;
b99bd4ef 6812 }
c19d1205
ZW
6813
6814 inst.instruction = THUMB_OP16 (inst.instruction);
6815 if (!inst.operands[1].isreg)
6816 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6817 return;
b99bd4ef 6818
c19d1205
ZW
6819 constraint (!inst.operands[1].preind
6820 || inst.operands[1].shifted
6821 || inst.operands[1].writeback,
6822 _("Thumb does not support this addressing mode"));
6823 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 6824 {
c19d1205
ZW
6825 constraint (inst.instruction & 0x0600,
6826 _("byte or halfword not valid for base register"));
6827 constraint (inst.operands[1].reg == REG_PC
6828 && !(inst.instruction & THUMB_LOAD_BIT),
6829 _("r15 based store not allowed"));
6830 constraint (inst.operands[1].immisreg,
6831 _("invalid base register for register offset"));
b99bd4ef 6832
c19d1205
ZW
6833 if (inst.operands[1].reg == REG_PC)
6834 inst.instruction = T_OPCODE_LDR_PC;
6835 else if (inst.instruction & THUMB_LOAD_BIT)
6836 inst.instruction = T_OPCODE_LDR_SP;
6837 else
6838 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 6839
c19d1205
ZW
6840 inst.instruction |= inst.operands[0].reg << 8;
6841 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6842 return;
6843 }
90e4755a 6844
c19d1205
ZW
6845 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6846 if (!inst.operands[1].immisreg)
6847 {
6848 /* Immediate offset. */
6849 inst.instruction |= inst.operands[0].reg;
6850 inst.instruction |= inst.operands[1].reg << 3;
6851 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6852 return;
6853 }
90e4755a 6854
c19d1205
ZW
6855 /* Register offset. */
6856 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6857 constraint (inst.operands[1].negative,
6858 _("Thumb does not support this addressing mode"));
90e4755a 6859
c19d1205
ZW
6860 op16:
6861 switch (inst.instruction)
6862 {
6863 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6864 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6865 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6866 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6867 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6868 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6869 case 0x5600 /* ldrsb */:
6870 case 0x5e00 /* ldrsh */: break;
6871 default: abort ();
6872 }
90e4755a 6873
c19d1205
ZW
6874 inst.instruction |= inst.operands[0].reg;
6875 inst.instruction |= inst.operands[1].reg << 3;
6876 inst.instruction |= inst.operands[1].imm << 6;
6877}
90e4755a 6878
c19d1205
ZW
6879static void
6880do_t_ldstd (void)
6881{
6882 if (!inst.operands[1].present)
b99bd4ef 6883 {
c19d1205
ZW
6884 inst.operands[1].reg = inst.operands[0].reg + 1;
6885 constraint (inst.operands[0].reg == REG_LR,
6886 _("r14 not allowed here"));
b99bd4ef 6887 }
c19d1205
ZW
6888 inst.instruction |= inst.operands[0].reg << 12;
6889 inst.instruction |= inst.operands[1].reg << 8;
6890 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6891
b99bd4ef
NC
6892}
6893
c19d1205
ZW
6894static void
6895do_t_ldstt (void)
6896{
6897 inst.instruction |= inst.operands[0].reg << 12;
6898 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6899}
a737bd4d 6900
b99bd4ef 6901static void
c19d1205 6902do_t_mla (void)
b99bd4ef 6903{
c19d1205
ZW
6904 inst.instruction |= inst.operands[0].reg << 8;
6905 inst.instruction |= inst.operands[1].reg << 16;
6906 inst.instruction |= inst.operands[2].reg;
6907 inst.instruction |= inst.operands[3].reg << 12;
6908}
b99bd4ef 6909
c19d1205
ZW
6910static void
6911do_t_mlal (void)
6912{
6913 inst.instruction |= inst.operands[0].reg << 12;
6914 inst.instruction |= inst.operands[1].reg << 8;
6915 inst.instruction |= inst.operands[2].reg << 16;
6916 inst.instruction |= inst.operands[3].reg;
6917}
b99bd4ef 6918
c19d1205
ZW
6919static void
6920do_t_mov_cmp (void)
6921{
6922 if (unified_syntax)
b99bd4ef 6923 {
c19d1205
ZW
6924 int r0off = (inst.instruction == T_MNEM_mov
6925 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 6926 unsigned long opcode;
3d388997
PB
6927 bfd_boolean narrow;
6928 bfd_boolean low_regs;
6929
6930 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 6931 opcode = inst.instruction;
3d388997 6932 if (current_it_mask)
0110f2b8 6933 narrow = opcode != T_MNEM_movs;
3d388997 6934 else
0110f2b8 6935 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
6936 if (inst.size_req == 4
6937 || inst.operands[1].shifted)
6938 narrow = FALSE;
6939
c19d1205
ZW
6940 if (!inst.operands[1].isreg)
6941 {
0110f2b8
PB
6942 /* Immediate operand. */
6943 if (current_it_mask == 0 && opcode == T_MNEM_mov)
6944 narrow = 0;
6945 if (low_regs && narrow)
6946 {
6947 inst.instruction = THUMB_OP16 (opcode);
6948 inst.instruction |= inst.operands[0].reg << 8;
6949 if (inst.size_req == 2)
6950 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6951 else
6952 inst.relax = opcode;
6953 }
6954 else
6955 {
6956 inst.instruction = THUMB_OP32 (inst.instruction);
6957 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6958 inst.instruction |= inst.operands[0].reg << r0off;
6959 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6960 }
c19d1205 6961 }
3d388997 6962 else if (!narrow)
c19d1205
ZW
6963 {
6964 inst.instruction = THUMB_OP32 (inst.instruction);
6965 inst.instruction |= inst.operands[0].reg << r0off;
6966 encode_thumb32_shifted_operand (1);
6967 }
6968 else
6969 switch (inst.instruction)
6970 {
6971 case T_MNEM_mov:
6972 inst.instruction = T_OPCODE_MOV_HR;
6973 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6974 inst.instruction |= (inst.operands[0].reg & 0x7);
6975 inst.instruction |= inst.operands[1].reg << 3;
6976 break;
b99bd4ef 6977
c19d1205
ZW
6978 case T_MNEM_movs:
6979 /* We know we have low registers at this point.
6980 Generate ADD Rd, Rs, #0. */
6981 inst.instruction = T_OPCODE_ADD_I3;
6982 inst.instruction |= inst.operands[0].reg;
6983 inst.instruction |= inst.operands[1].reg << 3;
6984 break;
6985
6986 case T_MNEM_cmp:
3d388997 6987 if (low_regs)
c19d1205
ZW
6988 {
6989 inst.instruction = T_OPCODE_CMP_LR;
6990 inst.instruction |= inst.operands[0].reg;
6991 inst.instruction |= inst.operands[1].reg << 3;
6992 }
6993 else
6994 {
6995 inst.instruction = T_OPCODE_CMP_HR;
6996 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6997 inst.instruction |= (inst.operands[0].reg & 0x7);
6998 inst.instruction |= inst.operands[1].reg << 3;
6999 }
7000 break;
7001 }
b99bd4ef
NC
7002 return;
7003 }
7004
c19d1205
ZW
7005 inst.instruction = THUMB_OP16 (inst.instruction);
7006 if (inst.operands[1].isreg)
b99bd4ef 7007 {
c19d1205 7008 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 7009 {
c19d1205
ZW
7010 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
7011 since a MOV instruction produces unpredictable results. */
7012 if (inst.instruction == T_OPCODE_MOV_I8)
7013 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 7014 else
c19d1205 7015 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 7016
c19d1205
ZW
7017 inst.instruction |= inst.operands[0].reg;
7018 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7019 }
7020 else
7021 {
c19d1205
ZW
7022 if (inst.instruction == T_OPCODE_MOV_I8)
7023 inst.instruction = T_OPCODE_MOV_HR;
7024 else
7025 inst.instruction = T_OPCODE_CMP_HR;
7026 do_t_cpy ();
b99bd4ef
NC
7027 }
7028 }
c19d1205 7029 else
b99bd4ef 7030 {
c19d1205
ZW
7031 constraint (inst.operands[0].reg > 7,
7032 _("only lo regs allowed with immediate"));
7033 inst.instruction |= inst.operands[0].reg << 8;
7034 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7035 }
7036}
b99bd4ef 7037
c19d1205
ZW
7038static void
7039do_t_mov16 (void)
7040{
7041 inst.instruction |= inst.operands[0].reg << 8;
7042 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
7043 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
7044 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
7045 inst.instruction |= (inst.operands[1].imm & 0x00ff);
7046}
b99bd4ef 7047
c19d1205
ZW
7048static void
7049do_t_mvn_tst (void)
7050{
7051 if (unified_syntax)
7052 {
7053 int r0off = (inst.instruction == T_MNEM_mvn
7054 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
7055 bfd_boolean narrow;
7056
7057 if (inst.size_req == 4
7058 || inst.instruction > 0xffff
7059 || inst.operands[1].shifted
7060 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7061 narrow = FALSE;
7062 else if (inst.instruction == T_MNEM_cmn)
7063 narrow = TRUE;
7064 else if (THUMB_SETS_FLAGS (inst.instruction))
7065 narrow = (current_it_mask == 0);
7066 else
7067 narrow = (current_it_mask != 0);
7068
c19d1205 7069 if (!inst.operands[1].isreg)
b99bd4ef 7070 {
c19d1205
ZW
7071 /* For an immediate, we always generate a 32-bit opcode;
7072 section relaxation will shrink it later if possible. */
7073 if (inst.instruction < 0xffff)
7074 inst.instruction = THUMB_OP32 (inst.instruction);
7075 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7076 inst.instruction |= inst.operands[0].reg << r0off;
7077 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 7078 }
c19d1205 7079 else
b99bd4ef 7080 {
c19d1205 7081 /* See if we can do this with a 16-bit instruction. */
3d388997 7082 if (narrow)
b99bd4ef 7083 {
c19d1205
ZW
7084 inst.instruction = THUMB_OP16 (inst.instruction);
7085 inst.instruction |= inst.operands[0].reg;
7086 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7087 }
c19d1205 7088 else
b99bd4ef 7089 {
c19d1205
ZW
7090 constraint (inst.operands[1].shifted
7091 && inst.operands[1].immisreg,
7092 _("shift must be constant"));
7093 if (inst.instruction < 0xffff)
7094 inst.instruction = THUMB_OP32 (inst.instruction);
7095 inst.instruction |= inst.operands[0].reg << r0off;
7096 encode_thumb32_shifted_operand (1);
b99bd4ef 7097 }
b99bd4ef
NC
7098 }
7099 }
7100 else
7101 {
c19d1205
ZW
7102 constraint (inst.instruction > 0xffff
7103 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
7104 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
7105 _("unshifted register required"));
7106 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7107 BAD_HIREG);
b99bd4ef 7108
c19d1205
ZW
7109 inst.instruction = THUMB_OP16 (inst.instruction);
7110 inst.instruction |= inst.operands[0].reg;
7111 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7112 }
b99bd4ef
NC
7113}
7114
b05fe5cf 7115static void
c19d1205 7116do_t_mrs (void)
b05fe5cf 7117{
c19d1205
ZW
7118 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7119 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7120 != (PSR_c|PSR_f),
7121 _("'CPSR' or 'SPSR' expected"));
7122 inst.instruction |= inst.operands[0].reg << 8;
7123 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
7124}
b05fe5cf 7125
c19d1205
ZW
7126static void
7127do_t_msr (void)
7128{
7129 constraint (!inst.operands[1].isreg,
7130 _("Thumb encoding does not support an immediate here"));
7131 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
7132 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
7133 inst.instruction |= inst.operands[1].reg << 16;
7134}
b05fe5cf 7135
c19d1205
ZW
7136static void
7137do_t_mul (void)
7138{
7139 if (!inst.operands[2].present)
7140 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 7141
c19d1205
ZW
7142 /* There is no 32-bit MULS and no 16-bit MUL. */
7143 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 7144 {
c19d1205
ZW
7145 inst.instruction = THUMB_OP32 (inst.instruction);
7146 inst.instruction |= inst.operands[0].reg << 8;
7147 inst.instruction |= inst.operands[1].reg << 16;
7148 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 7149 }
c19d1205 7150 else
b05fe5cf 7151 {
c19d1205
ZW
7152 constraint (!unified_syntax
7153 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
7154 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7155 BAD_HIREG);
b05fe5cf 7156
c19d1205
ZW
7157 inst.instruction = THUMB_OP16 (inst.instruction);
7158 inst.instruction |= inst.operands[0].reg;
b05fe5cf 7159
c19d1205
ZW
7160 if (inst.operands[0].reg == inst.operands[1].reg)
7161 inst.instruction |= inst.operands[2].reg << 3;
7162 else if (inst.operands[0].reg == inst.operands[2].reg)
7163 inst.instruction |= inst.operands[1].reg << 3;
7164 else
7165 constraint (1, _("dest must overlap one source register"));
7166 }
7167}
b05fe5cf 7168
c19d1205
ZW
7169static void
7170do_t_mull (void)
7171{
7172 inst.instruction |= inst.operands[0].reg << 12;
7173 inst.instruction |= inst.operands[1].reg << 8;
7174 inst.instruction |= inst.operands[2].reg << 16;
7175 inst.instruction |= inst.operands[3].reg;
b05fe5cf 7176
c19d1205
ZW
7177 if (inst.operands[0].reg == inst.operands[1].reg)
7178 as_tsktsk (_("rdhi and rdlo must be different"));
7179}
b05fe5cf 7180
c19d1205
ZW
7181static void
7182do_t_nop (void)
7183{
7184 if (unified_syntax)
7185 {
7186 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 7187 {
c19d1205
ZW
7188 inst.instruction = THUMB_OP32 (inst.instruction);
7189 inst.instruction |= inst.operands[0].imm;
7190 }
7191 else
7192 {
7193 inst.instruction = THUMB_OP16 (inst.instruction);
7194 inst.instruction |= inst.operands[0].imm << 4;
7195 }
7196 }
7197 else
7198 {
7199 constraint (inst.operands[0].present,
7200 _("Thumb does not support NOP with hints"));
7201 inst.instruction = 0x46c0;
7202 }
7203}
b05fe5cf 7204
c19d1205
ZW
7205static void
7206do_t_neg (void)
7207{
7208 if (unified_syntax)
7209 {
3d388997
PB
7210 bfd_boolean narrow;
7211
7212 if (THUMB_SETS_FLAGS (inst.instruction))
7213 narrow = (current_it_mask == 0);
7214 else
7215 narrow = (current_it_mask != 0);
7216 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7217 narrow = FALSE;
7218 if (inst.size_req == 4)
7219 narrow = FALSE;
7220
7221 if (!narrow)
c19d1205
ZW
7222 {
7223 inst.instruction = THUMB_OP32 (inst.instruction);
7224 inst.instruction |= inst.operands[0].reg << 8;
7225 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
7226 }
7227 else
7228 {
c19d1205
ZW
7229 inst.instruction = THUMB_OP16 (inst.instruction);
7230 inst.instruction |= inst.operands[0].reg;
7231 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
7232 }
7233 }
7234 else
7235 {
c19d1205
ZW
7236 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7237 BAD_HIREG);
7238 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7239
7240 inst.instruction = THUMB_OP16 (inst.instruction);
7241 inst.instruction |= inst.operands[0].reg;
7242 inst.instruction |= inst.operands[1].reg << 3;
7243 }
7244}
7245
7246static void
7247do_t_pkhbt (void)
7248{
7249 inst.instruction |= inst.operands[0].reg << 8;
7250 inst.instruction |= inst.operands[1].reg << 16;
7251 inst.instruction |= inst.operands[2].reg;
7252 if (inst.operands[3].present)
7253 {
7254 unsigned int val = inst.reloc.exp.X_add_number;
7255 constraint (inst.reloc.exp.X_op != O_constant,
7256 _("expression too complex"));
7257 inst.instruction |= (val & 0x1c) << 10;
7258 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 7259 }
c19d1205 7260}
b05fe5cf 7261
c19d1205
ZW
7262static void
7263do_t_pkhtb (void)
7264{
7265 if (!inst.operands[3].present)
7266 inst.instruction &= ~0x00000020;
7267 do_t_pkhbt ();
b05fe5cf
ZW
7268}
7269
c19d1205
ZW
7270static void
7271do_t_pld (void)
7272{
7273 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7274}
b05fe5cf 7275
c19d1205
ZW
7276static void
7277do_t_push_pop (void)
b99bd4ef 7278{
e9f89963
PB
7279 unsigned mask;
7280
c19d1205
ZW
7281 constraint (inst.operands[0].writeback,
7282 _("push/pop do not support {reglist}^"));
7283 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7284 _("expression too complex"));
b99bd4ef 7285
e9f89963
PB
7286 mask = inst.operands[0].imm;
7287 if ((mask & ~0xff) == 0)
c19d1205
ZW
7288 inst.instruction = THUMB_OP16 (inst.instruction);
7289 else if ((inst.instruction == T_MNEM_push
e9f89963 7290 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 7291 || (inst.instruction == T_MNEM_pop
e9f89963 7292 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 7293 {
c19d1205
ZW
7294 inst.instruction = THUMB_OP16 (inst.instruction);
7295 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 7296 mask &= 0xff;
c19d1205
ZW
7297 }
7298 else if (unified_syntax)
7299 {
e9f89963
PB
7300 if (mask & (1 << 13))
7301 inst.error = _("SP not allowed in register list");
c19d1205 7302 if (inst.instruction == T_MNEM_push)
b99bd4ef 7303 {
e9f89963
PB
7304 if (mask & (1 << 15))
7305 inst.error = _("PC not allowed in register list");
c19d1205
ZW
7306 }
7307 else
7308 {
e9f89963
PB
7309 if (mask & (1 << 14)
7310 && mask & (1 << 15))
7311 inst.error = _("LR and PC should not both be in register list");
c19d1205 7312 }
e9f89963
PB
7313 if ((mask & (mask - 1)) == 0)
7314 {
7315 /* Single register push/pop implemented as str/ldr. */
7316 if (inst.instruction == T_MNEM_push)
7317 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7318 else
7319 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7320 mask = ffs(mask) - 1;
7321 mask <<= 12;
7322 }
7323 else
7324 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
7325 }
7326 else
7327 {
7328 inst.error = _("invalid register list to push/pop instruction");
7329 return;
7330 }
b99bd4ef 7331
e9f89963 7332 inst.instruction |= mask;
c19d1205 7333}
b99bd4ef 7334
c19d1205
ZW
7335static void
7336do_t_rbit (void)
7337{
7338 inst.instruction |= inst.operands[0].reg << 8;
7339 inst.instruction |= inst.operands[1].reg << 16;
7340}
b99bd4ef 7341
c19d1205
ZW
7342static void
7343do_t_rev (void)
7344{
7345 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7346 && inst.size_req != 4)
7347 {
7348 inst.instruction = THUMB_OP16 (inst.instruction);
7349 inst.instruction |= inst.operands[0].reg;
7350 inst.instruction |= inst.operands[1].reg << 3;
7351 }
7352 else if (unified_syntax)
7353 {
7354 inst.instruction = THUMB_OP32 (inst.instruction);
7355 inst.instruction |= inst.operands[0].reg << 8;
7356 inst.instruction |= inst.operands[1].reg << 16;
7357 inst.instruction |= inst.operands[1].reg;
7358 }
7359 else
7360 inst.error = BAD_HIREG;
7361}
b99bd4ef 7362
c19d1205
ZW
7363static void
7364do_t_rsb (void)
7365{
7366 int Rd, Rs;
b99bd4ef 7367
c19d1205
ZW
7368 Rd = inst.operands[0].reg;
7369 Rs = (inst.operands[1].present
7370 ? inst.operands[1].reg /* Rd, Rs, foo */
7371 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 7372
c19d1205
ZW
7373 inst.instruction |= Rd << 8;
7374 inst.instruction |= Rs << 16;
7375 if (!inst.operands[2].isreg)
7376 {
7377 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7378 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7379 }
7380 else
7381 encode_thumb32_shifted_operand (2);
7382}
b99bd4ef 7383
c19d1205
ZW
7384static void
7385do_t_setend (void)
7386{
7387 if (inst.operands[0].imm)
7388 inst.instruction |= 0x8;
7389}
b99bd4ef 7390
c19d1205
ZW
7391static void
7392do_t_shift (void)
7393{
7394 if (!inst.operands[1].present)
7395 inst.operands[1].reg = inst.operands[0].reg;
7396
7397 if (unified_syntax)
7398 {
3d388997
PB
7399 bfd_boolean narrow;
7400 int shift_kind;
7401
7402 switch (inst.instruction)
7403 {
7404 case T_MNEM_asr:
7405 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7406 case T_MNEM_lsl:
7407 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7408 case T_MNEM_lsr:
7409 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7410 case T_MNEM_ror:
7411 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7412 default: abort ();
7413 }
7414
7415 if (THUMB_SETS_FLAGS (inst.instruction))
7416 narrow = (current_it_mask == 0);
7417 else
7418 narrow = (current_it_mask != 0);
7419 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7420 narrow = FALSE;
7421 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7422 narrow = FALSE;
7423 if (inst.operands[2].isreg
7424 && (inst.operands[1].reg != inst.operands[0].reg
7425 || inst.operands[2].reg > 7))
7426 narrow = FALSE;
7427 if (inst.size_req == 4)
7428 narrow = FALSE;
7429
7430 if (!narrow)
c19d1205
ZW
7431 {
7432 if (inst.operands[2].isreg)
b99bd4ef 7433 {
c19d1205
ZW
7434 inst.instruction = THUMB_OP32 (inst.instruction);
7435 inst.instruction |= inst.operands[0].reg << 8;
7436 inst.instruction |= inst.operands[1].reg << 16;
7437 inst.instruction |= inst.operands[2].reg;
7438 }
7439 else
7440 {
7441 inst.operands[1].shifted = 1;
3d388997 7442 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
7443 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7444 ? T_MNEM_movs : T_MNEM_mov);
7445 inst.instruction |= inst.operands[0].reg << 8;
7446 encode_thumb32_shifted_operand (1);
7447 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7448 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7449 }
7450 }
7451 else
7452 {
c19d1205 7453 if (inst.operands[2].isreg)
b99bd4ef 7454 {
3d388997 7455 switch (shift_kind)
b99bd4ef 7456 {
3d388997
PB
7457 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7458 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7459 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7460 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 7461 default: abort ();
b99bd4ef 7462 }
c19d1205
ZW
7463
7464 inst.instruction |= inst.operands[0].reg;
7465 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7466 }
7467 else
7468 {
3d388997 7469 switch (shift_kind)
b99bd4ef 7470 {
3d388997
PB
7471 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7472 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7473 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 7474 default: abort ();
b99bd4ef 7475 }
c19d1205
ZW
7476 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7477 inst.instruction |= inst.operands[0].reg;
7478 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7479 }
7480 }
c19d1205
ZW
7481 }
7482 else
7483 {
7484 constraint (inst.operands[0].reg > 7
7485 || inst.operands[1].reg > 7, BAD_HIREG);
7486 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7487
c19d1205
ZW
7488 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7489 {
7490 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7491 constraint (inst.operands[0].reg != inst.operands[1].reg,
7492 _("source1 and dest must be same register"));
b99bd4ef 7493
c19d1205
ZW
7494 switch (inst.instruction)
7495 {
7496 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7497 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7498 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7499 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7500 default: abort ();
7501 }
7502
7503 inst.instruction |= inst.operands[0].reg;
7504 inst.instruction |= inst.operands[2].reg << 3;
7505 }
7506 else
b99bd4ef 7507 {
c19d1205
ZW
7508 switch (inst.instruction)
7509 {
7510 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7511 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7512 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7513 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7514 default: abort ();
7515 }
7516 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7517 inst.instruction |= inst.operands[0].reg;
7518 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7519 }
7520 }
b99bd4ef
NC
7521}
7522
7523static void
c19d1205 7524do_t_simd (void)
b99bd4ef 7525{
c19d1205
ZW
7526 inst.instruction |= inst.operands[0].reg << 8;
7527 inst.instruction |= inst.operands[1].reg << 16;
7528 inst.instruction |= inst.operands[2].reg;
7529}
b99bd4ef 7530
c19d1205 7531static void
3eb17e6b 7532do_t_smc (void)
c19d1205
ZW
7533{
7534 unsigned int value = inst.reloc.exp.X_add_number;
7535 constraint (inst.reloc.exp.X_op != O_constant,
7536 _("expression too complex"));
7537 inst.reloc.type = BFD_RELOC_UNUSED;
7538 inst.instruction |= (value & 0xf000) >> 12;
7539 inst.instruction |= (value & 0x0ff0);
7540 inst.instruction |= (value & 0x000f) << 16;
7541}
b99bd4ef 7542
c19d1205
ZW
7543static void
7544do_t_ssat (void)
7545{
7546 inst.instruction |= inst.operands[0].reg << 8;
7547 inst.instruction |= inst.operands[1].imm - 1;
7548 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7549
c19d1205 7550 if (inst.operands[3].present)
b99bd4ef 7551 {
c19d1205
ZW
7552 constraint (inst.reloc.exp.X_op != O_constant,
7553 _("expression too complex"));
b99bd4ef 7554
c19d1205 7555 if (inst.reloc.exp.X_add_number != 0)
6189168b 7556 {
c19d1205
ZW
7557 if (inst.operands[3].shift_kind == SHIFT_ASR)
7558 inst.instruction |= 0x00200000; /* sh bit */
7559 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7560 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7561 }
c19d1205 7562 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7563 }
b99bd4ef
NC
7564}
7565
0dd132b6 7566static void
c19d1205 7567do_t_ssat16 (void)
0dd132b6 7568{
c19d1205
ZW
7569 inst.instruction |= inst.operands[0].reg << 8;
7570 inst.instruction |= inst.operands[1].imm - 1;
7571 inst.instruction |= inst.operands[2].reg << 16;
7572}
0dd132b6 7573
c19d1205
ZW
7574static void
7575do_t_strex (void)
7576{
7577 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7578 || inst.operands[2].postind || inst.operands[2].writeback
7579 || inst.operands[2].immisreg || inst.operands[2].shifted
7580 || inst.operands[2].negative,
7581 _("instruction does not accept this addressing mode"));
0dd132b6 7582
c19d1205
ZW
7583 inst.instruction |= inst.operands[0].reg << 8;
7584 inst.instruction |= inst.operands[1].reg << 12;
7585 inst.instruction |= inst.operands[2].reg << 16;
7586 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7587}
7588
b99bd4ef 7589static void
c19d1205 7590do_t_strexd (void)
b99bd4ef 7591{
c19d1205
ZW
7592 if (!inst.operands[2].present)
7593 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7594
c19d1205
ZW
7595 constraint (inst.operands[0].reg == inst.operands[1].reg
7596 || inst.operands[0].reg == inst.operands[2].reg
7597 || inst.operands[0].reg == inst.operands[3].reg
7598 || inst.operands[1].reg == inst.operands[2].reg,
7599 BAD_OVERLAP);
b99bd4ef 7600
c19d1205
ZW
7601 inst.instruction |= inst.operands[0].reg;
7602 inst.instruction |= inst.operands[1].reg << 12;
7603 inst.instruction |= inst.operands[2].reg << 8;
7604 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7605}
7606
7607static void
c19d1205 7608do_t_sxtah (void)
b99bd4ef 7609{
c19d1205
ZW
7610 inst.instruction |= inst.operands[0].reg << 8;
7611 inst.instruction |= inst.operands[1].reg << 16;
7612 inst.instruction |= inst.operands[2].reg;
7613 inst.instruction |= inst.operands[3].imm << 4;
7614}
b99bd4ef 7615
c19d1205
ZW
7616static void
7617do_t_sxth (void)
7618{
7619 if (inst.instruction <= 0xffff && inst.size_req != 4
7620 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7621 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7622 {
c19d1205
ZW
7623 inst.instruction = THUMB_OP16 (inst.instruction);
7624 inst.instruction |= inst.operands[0].reg;
7625 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7626 }
c19d1205 7627 else if (unified_syntax)
b99bd4ef 7628 {
c19d1205
ZW
7629 if (inst.instruction <= 0xffff)
7630 inst.instruction = THUMB_OP32 (inst.instruction);
7631 inst.instruction |= inst.operands[0].reg << 8;
7632 inst.instruction |= inst.operands[1].reg;
7633 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7634 }
c19d1205 7635 else
b99bd4ef 7636 {
c19d1205
ZW
7637 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7638 _("Thumb encoding does not support rotation"));
7639 constraint (1, BAD_HIREG);
b99bd4ef 7640 }
c19d1205 7641}
b99bd4ef 7642
c19d1205
ZW
7643static void
7644do_t_swi (void)
7645{
7646 inst.reloc.type = BFD_RELOC_ARM_SWI;
7647}
b99bd4ef 7648
92e90b6e
PB
7649static void
7650do_t_tb (void)
7651{
7652 int half;
7653
7654 half = (inst.instruction & 0x10) != 0;
7655 constraint (inst.operands[0].imm == 15,
7656 _("PC is not a valid index register"));
7657 constraint (!half && inst.operands[0].shifted,
7658 _("instruction does not allow shifted index"));
7659 constraint (half && !inst.operands[0].shifted,
7660 _("instruction requires shifted index"));
7661 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7662}
7663
c19d1205
ZW
7664static void
7665do_t_usat (void)
7666{
7667 inst.instruction |= inst.operands[0].reg << 8;
7668 inst.instruction |= inst.operands[1].imm;
7669 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7670
c19d1205 7671 if (inst.operands[3].present)
b99bd4ef 7672 {
c19d1205
ZW
7673 constraint (inst.reloc.exp.X_op != O_constant,
7674 _("expression too complex"));
7675 if (inst.reloc.exp.X_add_number != 0)
7676 {
7677 if (inst.operands[3].shift_kind == SHIFT_ASR)
7678 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7679
c19d1205
ZW
7680 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7681 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7682 }
7683 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7684 }
b99bd4ef
NC
7685}
7686
7687static void
c19d1205 7688do_t_usat16 (void)
b99bd4ef 7689{
c19d1205
ZW
7690 inst.instruction |= inst.operands[0].reg << 8;
7691 inst.instruction |= inst.operands[1].imm;
7692 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7693}
c19d1205
ZW
7694\f
7695/* Overall per-instruction processing. */
7696
7697/* We need to be able to fix up arbitrary expressions in some statements.
7698 This is so that we can handle symbols that are an arbitrary distance from
7699 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7700 which returns part of an address in a form which will be valid for
7701 a data instruction. We do this by pushing the expression into a symbol
7702 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7703
7704static void
c19d1205
ZW
7705fix_new_arm (fragS * frag,
7706 int where,
7707 short int size,
7708 expressionS * exp,
7709 int pc_rel,
7710 int reloc)
b99bd4ef 7711{
c19d1205 7712 fixS * new_fix;
b99bd4ef 7713
c19d1205 7714 switch (exp->X_op)
b99bd4ef 7715 {
c19d1205
ZW
7716 case O_constant:
7717 case O_symbol:
7718 case O_add:
7719 case O_subtract:
7720 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7721 break;
b99bd4ef 7722
c19d1205
ZW
7723 default:
7724 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7725 pc_rel, reloc);
7726 break;
b99bd4ef
NC
7727 }
7728
c19d1205
ZW
7729 /* Mark whether the fix is to a THUMB instruction, or an ARM
7730 instruction. */
adbaf948 7731 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7732}
7733
0110f2b8
PB
7734/* Create a frg for an instruction requiring relaxation. */
7735static void
7736output_relax_insn (void)
7737{
7738 char * to;
7739 symbolS *sym;
7740 int offset;
7741
7742 switch (inst.reloc.exp.X_op)
7743 {
7744 case O_symbol:
7745 sym = inst.reloc.exp.X_add_symbol;
7746 offset = inst.reloc.exp.X_add_number;
7747 break;
7748 case O_constant:
7749 sym = NULL;
7750 offset = inst.reloc.exp.X_add_number;
7751 break;
7752 default:
7753 sym = make_expr_symbol (&inst.reloc.exp);
7754 offset = 0;
7755 break;
7756 }
7757 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
7758 inst.relax, sym, offset, NULL/*offset, opcode*/);
7759 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
7760
7761#ifdef OBJ_ELF
7762 dwarf2_emit_insn (INSN_SIZE);
7763#endif
7764}
7765
7766/* Write a 32-bit thumb instruction to buf. */
7767static void
7768put_thumb32_insn (char * buf, unsigned long insn)
7769{
7770 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
7771 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
7772}
7773
b99bd4ef 7774static void
c19d1205 7775output_inst (const char * str)
b99bd4ef 7776{
c19d1205 7777 char * to = NULL;
b99bd4ef 7778
c19d1205 7779 if (inst.error)
b99bd4ef 7780 {
c19d1205 7781 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
7782 return;
7783 }
0110f2b8
PB
7784 if (inst.relax) {
7785 output_relax_insn();
7786 return;
7787 }
c19d1205
ZW
7788 if (inst.size == 0)
7789 return;
b99bd4ef 7790
c19d1205
ZW
7791 to = frag_more (inst.size);
7792
7793 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 7794 {
c19d1205 7795 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 7796 put_thumb32_insn (to, inst.instruction);
b99bd4ef 7797 }
c19d1205 7798 else if (inst.size > INSN_SIZE)
b99bd4ef 7799 {
c19d1205
ZW
7800 assert (inst.size == (2 * INSN_SIZE));
7801 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7802 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 7803 }
c19d1205
ZW
7804 else
7805 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 7806
c19d1205
ZW
7807 if (inst.reloc.type != BFD_RELOC_UNUSED)
7808 fix_new_arm (frag_now, to - frag_now->fr_literal,
7809 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7810 inst.reloc.type);
b99bd4ef 7811
c19d1205
ZW
7812#ifdef OBJ_ELF
7813 dwarf2_emit_insn (inst.size);
7814#endif
7815}
b99bd4ef 7816
c19d1205
ZW
7817/* Tag values used in struct asm_opcode's tag field. */
7818enum opcode_tag
7819{
7820 OT_unconditional, /* Instruction cannot be conditionalized.
7821 The ARM condition field is still 0xE. */
7822 OT_unconditionalF, /* Instruction cannot be conditionalized
7823 and carries 0xF in its ARM condition field. */
7824 OT_csuffix, /* Instruction takes a conditional suffix. */
7825 OT_cinfix3, /* Instruction takes a conditional infix,
7826 beginning at character index 3. (In
7827 unified mode, it becomes a suffix.) */
e3cb604e
PB
7828 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
7829 character index 3, even in unified mode. Used for
7830 legacy instructions where suffix and infix forms
7831 may be ambiguous. */
c19d1205 7832 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 7833 suffix or an infix at character index 3. */
c19d1205
ZW
7834 OT_odd_infix_unc, /* This is the unconditional variant of an
7835 instruction that takes a conditional infix
7836 at an unusual position. In unified mode,
7837 this variant will accept a suffix. */
7838 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7839 are the conditional variants of instructions that
7840 take conditional infixes in unusual positions.
7841 The infix appears at character index
7842 (tag - OT_odd_infix_0). These are not accepted
7843 in unified mode. */
7844};
b99bd4ef 7845
c19d1205
ZW
7846/* Subroutine of md_assemble, responsible for looking up the primary
7847 opcode from the mnemonic the user wrote. STR points to the
7848 beginning of the mnemonic.
7849
7850 This is not simply a hash table lookup, because of conditional
7851 variants. Most instructions have conditional variants, which are
7852 expressed with a _conditional affix_ to the mnemonic. If we were
7853 to encode each conditional variant as a literal string in the opcode
7854 table, it would have approximately 20,000 entries.
7855
7856 Most mnemonics take this affix as a suffix, and in unified syntax,
7857 'most' is upgraded to 'all'. However, in the divided syntax, some
7858 instructions take the affix as an infix, notably the s-variants of
7859 the arithmetic instructions. Of those instructions, all but six
7860 have the infix appear after the third character of the mnemonic.
7861
7862 Accordingly, the algorithm for looking up primary opcodes given
7863 an identifier is:
7864
7865 1. Look up the identifier in the opcode table.
7866 If we find a match, go to step U.
7867
7868 2. Look up the last two characters of the identifier in the
7869 conditions table. If we find a match, look up the first N-2
7870 characters of the identifier in the opcode table. If we
7871 find a match, go to step CE.
7872
7873 3. Look up the fourth and fifth characters of the identifier in
7874 the conditions table. If we find a match, extract those
7875 characters from the identifier, and look up the remaining
7876 characters in the opcode table. If we find a match, go
7877 to step CM.
7878
7879 4. Fail.
7880
7881 U. Examine the tag field of the opcode structure, in case this is
7882 one of the six instructions with its conditional infix in an
7883 unusual place. If it is, the tag tells us where to find the
7884 infix; look it up in the conditions table and set inst.cond
7885 accordingly. Otherwise, this is an unconditional instruction.
7886 Again set inst.cond accordingly. Return the opcode structure.
7887
7888 CE. Examine the tag field to make sure this is an instruction that
7889 should receive a conditional suffix. If it is not, fail.
7890 Otherwise, set inst.cond from the suffix we already looked up,
7891 and return the opcode structure.
7892
7893 CM. Examine the tag field to make sure this is an instruction that
7894 should receive a conditional infix after the third character.
7895 If it is not, fail. Otherwise, undo the edits to the current
7896 line of input and proceed as for case CE. */
7897
7898static const struct asm_opcode *
7899opcode_lookup (char **str)
7900{
7901 char *end, *base;
7902 char *affix;
7903 const struct asm_opcode *opcode;
7904 const struct asm_cond *cond;
e3cb604e 7905 char save[2];
c19d1205
ZW
7906
7907 /* Scan up to the end of the mnemonic, which must end in white space,
7908 '.' (in unified mode only), or end of string. */
7909 for (base = end = *str; *end != '\0'; end++)
7910 if (*end == ' ' || (unified_syntax && *end == '.'))
7911 break;
b99bd4ef 7912
c19d1205
ZW
7913 if (end == base)
7914 return 0;
b99bd4ef 7915
c19d1205
ZW
7916 /* Handle a possible width suffix. */
7917 if (end[0] == '.')
b99bd4ef 7918 {
c19d1205
ZW
7919 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7920 inst.size_req = 4;
7921 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7922 inst.size_req = 2;
7923 else
7924 return 0;
b99bd4ef 7925
c19d1205 7926 *str = end + 2;
b99bd4ef 7927 }
c19d1205
ZW
7928 else
7929 *str = end;
b99bd4ef 7930
c19d1205
ZW
7931 /* Look for unaffixed or special-case affixed mnemonic. */
7932 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7933 if (opcode)
b99bd4ef 7934 {
c19d1205
ZW
7935 /* step U */
7936 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 7937 {
c19d1205
ZW
7938 inst.cond = COND_ALWAYS;
7939 return opcode;
b99bd4ef 7940 }
b99bd4ef 7941
c19d1205
ZW
7942 if (unified_syntax)
7943 as_warn (_("conditional infixes are deprecated in unified syntax"));
7944 affix = base + (opcode->tag - OT_odd_infix_0);
7945 cond = hash_find_n (arm_cond_hsh, affix, 2);
7946 assert (cond);
b99bd4ef 7947
c19d1205
ZW
7948 inst.cond = cond->value;
7949 return opcode;
7950 }
b99bd4ef 7951
c19d1205
ZW
7952 /* Cannot have a conditional suffix on a mnemonic of less than two
7953 characters. */
7954 if (end - base < 3)
7955 return 0;
b99bd4ef 7956
c19d1205
ZW
7957 /* Look for suffixed mnemonic. */
7958 affix = end - 2;
7959 cond = hash_find_n (arm_cond_hsh, affix, 2);
7960 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7961 if (opcode && cond)
7962 {
7963 /* step CE */
7964 switch (opcode->tag)
7965 {
e3cb604e
PB
7966 case OT_cinfix3_legacy:
7967 /* Ignore conditional suffixes matched on infix only mnemonics. */
7968 break;
7969
c19d1205
ZW
7970 case OT_cinfix3:
7971 case OT_odd_infix_unc:
7972 if (!unified_syntax)
e3cb604e 7973 return 0;
c19d1205
ZW
7974 /* else fall through */
7975
7976 case OT_csuffix:
7977 case OT_csuf_or_in3:
7978 inst.cond = cond->value;
7979 return opcode;
7980
7981 case OT_unconditional:
7982 case OT_unconditionalF:
7983 /* delayed diagnostic */
7984 inst.error = BAD_COND;
7985 inst.cond = COND_ALWAYS;
7986 return opcode;
b99bd4ef 7987
c19d1205
ZW
7988 default:
7989 return 0;
7990 }
7991 }
b99bd4ef 7992
c19d1205
ZW
7993 /* Cannot have a usual-position infix on a mnemonic of less than
7994 six characters (five would be a suffix). */
7995 if (end - base < 6)
7996 return 0;
b99bd4ef 7997
c19d1205
ZW
7998 /* Look for infixed mnemonic in the usual position. */
7999 affix = base + 3;
8000 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
8001 if (!cond)
8002 return 0;
8003
8004 memcpy (save, affix, 2);
8005 memmove (affix, affix + 2, (end - affix) - 2);
8006 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
8007 memmove (affix + 2, affix, (end - affix) - 2);
8008 memcpy (affix, save, 2);
8009
8010 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
8011 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 8012 {
c19d1205 8013 /* step CM */
e3cb604e 8014 if (unified_syntax && opcode->tag == OT_cinfix3)
c19d1205
ZW
8015 as_warn (_("conditional infixes are deprecated in unified syntax"));
8016
8017 inst.cond = cond->value;
8018 return opcode;
b99bd4ef
NC
8019 }
8020
c19d1205 8021 return 0;
b99bd4ef
NC
8022}
8023
c19d1205
ZW
8024void
8025md_assemble (char *str)
b99bd4ef 8026{
c19d1205
ZW
8027 char *p = str;
8028 const struct asm_opcode * opcode;
b99bd4ef 8029
c19d1205
ZW
8030 /* Align the previous label if needed. */
8031 if (last_label_seen != NULL)
b99bd4ef 8032 {
c19d1205
ZW
8033 symbol_set_frag (last_label_seen, frag_now);
8034 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8035 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
8036 }
8037
c19d1205
ZW
8038 memset (&inst, '\0', sizeof (inst));
8039 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 8040
c19d1205
ZW
8041 opcode = opcode_lookup (&p);
8042 if (!opcode)
b99bd4ef 8043 {
c19d1205
ZW
8044 /* It wasn't an instruction, but it might be a register alias of
8045 the form alias .req reg. */
8046 if (!create_register_alias (str, p))
8047 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 8048
b99bd4ef
NC
8049 return;
8050 }
8051
c19d1205 8052 if (thumb_mode)
b99bd4ef 8053 {
8f06b2d8
PB
8054 unsigned long variant;
8055
8056 variant = cpu_variant;
8057 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
8058 if ((variant & ARM_EXT_V6T2) == 0)
8059 variant &= ARM_ANY;
c19d1205 8060 /* Check that this instruction is supported for this CPU. */
8f06b2d8 8061 if (thumb_mode == 1 && (opcode->tvariant & variant) == 0)
b99bd4ef 8062 {
c19d1205 8063 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
8064 return;
8065 }
c19d1205
ZW
8066 if (inst.cond != COND_ALWAYS && !unified_syntax
8067 && opcode->tencode != do_t_branch)
b99bd4ef 8068 {
c19d1205 8069 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
8070 return;
8071 }
8072
e27ec89e
PB
8073 /* Check conditional suffixes. */
8074 if (current_it_mask)
8075 {
8076 int cond;
8077 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
8078 if (cond != inst.cond)
8079 {
8080 as_bad (_("incorrect condition in IT block"));
8081 return;
8082 }
8083 current_it_mask <<= 1;
8084 current_it_mask &= 0x1f;
8085 }
8086 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
8087 {
8088 as_bad (_("thumb conditional instrunction not in IT block"));
8089 return;
8090 }
8091
c19d1205
ZW
8092 mapping_state (MAP_THUMB);
8093 inst.instruction = opcode->tvalue;
8094
8095 if (!parse_operands (p, opcode->operands))
8096 opcode->tencode ();
8097
e27ec89e
PB
8098 /* Clear current_it_mask at the end of an IT block. */
8099 if (current_it_mask == 0x10)
8100 current_it_mask = 0;
8101
0110f2b8 8102 if (!(inst.error || inst.relax))
b99bd4ef 8103 {
c19d1205
ZW
8104 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
8105 inst.size = (inst.instruction > 0xffff ? 4 : 2);
8106 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 8107 {
c19d1205 8108 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
8109 return;
8110 }
8111 }
ee065d83
PB
8112 thumb_arch_used |= opcode->tvariant;
8113 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
8114 set those bits when Thumb-2 32-bit instuctions are seen. ie.
8115 anything other than bl/blx.
8116 This is overly pessimistic for relaxable instructions. */
8117 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
8118 || inst.relax)
8119 thumb_arch_used |= ARM_EXT_V6T2;
c19d1205
ZW
8120 }
8121 else
8122 {
8123 /* Check that this instruction is supported for this CPU. */
8124 if ((opcode->avariant & cpu_variant) == 0)
b99bd4ef 8125 {
c19d1205
ZW
8126 as_bad (_("selected processor does not support `%s'"), str);
8127 return;
b99bd4ef 8128 }
c19d1205 8129 if (inst.size_req)
b99bd4ef 8130 {
c19d1205
ZW
8131 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
8132 return;
b99bd4ef
NC
8133 }
8134
c19d1205
ZW
8135 mapping_state (MAP_ARM);
8136 inst.instruction = opcode->avalue;
8137 if (opcode->tag == OT_unconditionalF)
8138 inst.instruction |= 0xF << 28;
8139 else
8140 inst.instruction |= inst.cond << 28;
8141 inst.size = INSN_SIZE;
8142 if (!parse_operands (p, opcode->operands))
8143 opcode->aencode ();
ee065d83
PB
8144 /* Arm mode bx is marked as both v4T and v5 because it's still required
8145 on a hypothetical non-thumb v5 core. */
8146 if (opcode->avariant == (ARM_EXT_V4T | ARM_EXT_V5))
8147 arm_arch_used |= ARM_EXT_V4T;
8148 else
8149 arm_arch_used |= opcode->avariant;
b99bd4ef 8150 }
c19d1205
ZW
8151 output_inst (str);
8152}
b99bd4ef 8153
c19d1205
ZW
8154/* Various frobbings of labels and their addresses. */
8155
8156void
8157arm_start_line_hook (void)
8158{
8159 last_label_seen = NULL;
b99bd4ef
NC
8160}
8161
c19d1205
ZW
8162void
8163arm_frob_label (symbolS * sym)
b99bd4ef 8164{
c19d1205 8165 last_label_seen = sym;
b99bd4ef 8166
c19d1205 8167 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 8168
c19d1205
ZW
8169#if defined OBJ_COFF || defined OBJ_ELF
8170 ARM_SET_INTERWORK (sym, support_interwork);
8171#endif
b99bd4ef 8172
c19d1205
ZW
8173 /* Note - do not allow local symbols (.Lxxx) to be labeled
8174 as Thumb functions. This is because these labels, whilst
8175 they exist inside Thumb code, are not the entry points for
8176 possible ARM->Thumb calls. Also, these labels can be used
8177 as part of a computed goto or switch statement. eg gcc
8178 can generate code that looks like this:
b99bd4ef 8179
c19d1205
ZW
8180 ldr r2, [pc, .Laaa]
8181 lsl r3, r3, #2
8182 ldr r2, [r3, r2]
8183 mov pc, r2
b99bd4ef 8184
c19d1205
ZW
8185 .Lbbb: .word .Lxxx
8186 .Lccc: .word .Lyyy
8187 ..etc...
8188 .Laaa: .word Lbbb
b99bd4ef 8189
c19d1205
ZW
8190 The first instruction loads the address of the jump table.
8191 The second instruction converts a table index into a byte offset.
8192 The third instruction gets the jump address out of the table.
8193 The fourth instruction performs the jump.
b99bd4ef 8194
c19d1205
ZW
8195 If the address stored at .Laaa is that of a symbol which has the
8196 Thumb_Func bit set, then the linker will arrange for this address
8197 to have the bottom bit set, which in turn would mean that the
8198 address computation performed by the third instruction would end
8199 up with the bottom bit set. Since the ARM is capable of unaligned
8200 word loads, the instruction would then load the incorrect address
8201 out of the jump table, and chaos would ensue. */
8202 if (label_is_thumb_function_name
8203 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
8204 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 8205 {
c19d1205
ZW
8206 /* When the address of a Thumb function is taken the bottom
8207 bit of that address should be set. This will allow
8208 interworking between Arm and Thumb functions to work
8209 correctly. */
b99bd4ef 8210
c19d1205 8211 THUMB_SET_FUNC (sym, 1);
b99bd4ef 8212
c19d1205 8213 label_is_thumb_function_name = FALSE;
b99bd4ef 8214 }
07a53e5c
RH
8215
8216#ifdef OBJ_ELF
8217 dwarf2_emit_label (sym);
8218#endif
b99bd4ef
NC
8219}
8220
c19d1205
ZW
8221int
8222arm_data_in_code (void)
b99bd4ef 8223{
c19d1205 8224 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 8225 {
c19d1205
ZW
8226 *input_line_pointer = '/';
8227 input_line_pointer += 5;
8228 *input_line_pointer = 0;
8229 return 1;
b99bd4ef
NC
8230 }
8231
c19d1205 8232 return 0;
b99bd4ef
NC
8233}
8234
c19d1205
ZW
8235char *
8236arm_canonicalize_symbol_name (char * name)
b99bd4ef 8237{
c19d1205 8238 int len;
b99bd4ef 8239
c19d1205
ZW
8240 if (thumb_mode && (len = strlen (name)) > 5
8241 && streq (name + len - 5, "/data"))
8242 *(name + len - 5) = 0;
b99bd4ef 8243
c19d1205 8244 return name;
b99bd4ef 8245}
c19d1205
ZW
8246\f
8247/* Table of all register names defined by default. The user can
8248 define additional names with .req. Note that all register names
8249 should appear in both upper and lowercase variants. Some registers
8250 also have mixed-case names. */
b99bd4ef 8251
c19d1205
ZW
8252#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
8253#define REGNUM(p,n,t) REGDEF(p##n, n, t)
8254#define REGSET(p,t) \
8255 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8256 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8257 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8258 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 8259
c19d1205 8260static const struct reg_entry reg_names[] =
7ed4c4c5 8261{
c19d1205
ZW
8262 /* ARM integer registers. */
8263 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 8264
c19d1205
ZW
8265 /* ATPCS synonyms. */
8266 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
8267 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
8268 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 8269
c19d1205
ZW
8270 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
8271 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
8272 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 8273
c19d1205
ZW
8274 /* Well-known aliases. */
8275 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
8276 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
8277
8278 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
8279 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
8280
8281 /* Coprocessor numbers. */
8282 REGSET(p, CP), REGSET(P, CP),
8283
8284 /* Coprocessor register numbers. The "cr" variants are for backward
8285 compatibility. */
8286 REGSET(c, CN), REGSET(C, CN),
8287 REGSET(cr, CN), REGSET(CR, CN),
8288
8289 /* FPA registers. */
8290 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
8291 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
8292
8293 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
8294 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
8295
8296 /* VFP SP registers. */
8297 REGSET(s,VFS),
8298 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
8299 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
8300 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
8301 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
8302
8303 REGSET(S,VFS),
8304 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
8305 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
8306 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
8307 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
8308
8309 /* VFP DP Registers. */
8310 REGSET(d,VFD), REGSET(D,VFS),
8311
8312 /* VFP control registers. */
8313 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
8314 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
8315
8316 /* Maverick DSP coprocessor registers. */
8317 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8318 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8319
8320 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8321 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8322 REGDEF(dspsc,0,DSPSC),
8323
8324 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8325 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8326 REGDEF(DSPSC,0,DSPSC),
8327
8328 /* iWMMXt data registers - p0, c0-15. */
8329 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8330
8331 /* iWMMXt control registers - p1, c0-3. */
8332 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8333 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8334 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8335 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8336
8337 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8338 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8339 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8340 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8341 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8342
8343 /* XScale accumulator registers. */
8344 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8345};
8346#undef REGDEF
8347#undef REGNUM
8348#undef REGSET
7ed4c4c5 8349
c19d1205
ZW
8350/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8351 within psr_required_here. */
8352static const struct asm_psr psrs[] =
8353{
8354 /* Backward compatibility notation. Note that "all" is no longer
8355 truly all possible PSR bits. */
8356 {"all", PSR_c | PSR_f},
8357 {"flg", PSR_f},
8358 {"ctl", PSR_c},
8359
8360 /* Individual flags. */
8361 {"f", PSR_f},
8362 {"c", PSR_c},
8363 {"x", PSR_x},
8364 {"s", PSR_s},
8365 /* Combinations of flags. */
8366 {"fs", PSR_f | PSR_s},
8367 {"fx", PSR_f | PSR_x},
8368 {"fc", PSR_f | PSR_c},
8369 {"sf", PSR_s | PSR_f},
8370 {"sx", PSR_s | PSR_x},
8371 {"sc", PSR_s | PSR_c},
8372 {"xf", PSR_x | PSR_f},
8373 {"xs", PSR_x | PSR_s},
8374 {"xc", PSR_x | PSR_c},
8375 {"cf", PSR_c | PSR_f},
8376 {"cs", PSR_c | PSR_s},
8377 {"cx", PSR_c | PSR_x},
8378 {"fsx", PSR_f | PSR_s | PSR_x},
8379 {"fsc", PSR_f | PSR_s | PSR_c},
8380 {"fxs", PSR_f | PSR_x | PSR_s},
8381 {"fxc", PSR_f | PSR_x | PSR_c},
8382 {"fcs", PSR_f | PSR_c | PSR_s},
8383 {"fcx", PSR_f | PSR_c | PSR_x},
8384 {"sfx", PSR_s | PSR_f | PSR_x},
8385 {"sfc", PSR_s | PSR_f | PSR_c},
8386 {"sxf", PSR_s | PSR_x | PSR_f},
8387 {"sxc", PSR_s | PSR_x | PSR_c},
8388 {"scf", PSR_s | PSR_c | PSR_f},
8389 {"scx", PSR_s | PSR_c | PSR_x},
8390 {"xfs", PSR_x | PSR_f | PSR_s},
8391 {"xfc", PSR_x | PSR_f | PSR_c},
8392 {"xsf", PSR_x | PSR_s | PSR_f},
8393 {"xsc", PSR_x | PSR_s | PSR_c},
8394 {"xcf", PSR_x | PSR_c | PSR_f},
8395 {"xcs", PSR_x | PSR_c | PSR_s},
8396 {"cfs", PSR_c | PSR_f | PSR_s},
8397 {"cfx", PSR_c | PSR_f | PSR_x},
8398 {"csf", PSR_c | PSR_s | PSR_f},
8399 {"csx", PSR_c | PSR_s | PSR_x},
8400 {"cxf", PSR_c | PSR_x | PSR_f},
8401 {"cxs", PSR_c | PSR_x | PSR_s},
8402 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8403 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8404 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8405 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8406 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8407 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8408 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8409 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8410 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8411 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8412 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8413 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8414 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8415 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8416 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8417 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8418 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8419 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8420 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8421 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8422 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8423 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8424 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8425 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8426};
8427
8428/* Table of all shift-in-operand names. */
8429static const struct asm_shift_name shift_names [] =
b99bd4ef 8430{
c19d1205
ZW
8431 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8432 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8433 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8434 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8435 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8436 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8437};
b99bd4ef 8438
c19d1205
ZW
8439/* Table of all explicit relocation names. */
8440#ifdef OBJ_ELF
8441static struct reloc_entry reloc_names[] =
8442{
8443 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8444 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8445 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8446 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8447 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8448 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8449 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8450 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8451 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8452 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8453 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8454};
8455#endif
b99bd4ef 8456
c19d1205
ZW
8457/* Table of all conditional affixes. 0xF is not defined as a condition code. */
8458static const struct asm_cond conds[] =
8459{
8460 {"eq", 0x0},
8461 {"ne", 0x1},
8462 {"cs", 0x2}, {"hs", 0x2},
8463 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8464 {"mi", 0x4},
8465 {"pl", 0x5},
8466 {"vs", 0x6},
8467 {"vc", 0x7},
8468 {"hi", 0x8},
8469 {"ls", 0x9},
8470 {"ge", 0xa},
8471 {"lt", 0xb},
8472 {"gt", 0xc},
8473 {"le", 0xd},
8474 {"al", 0xe}
8475};
bfae80f2 8476
c19d1205
ZW
8477/* Table of ARM-format instructions. */
8478
8479/* Macros for gluing together operand strings. N.B. In all cases
8480 other than OPS0, the trailing OP_stop comes from default
8481 zero-initialization of the unspecified elements of the array. */
8482#define OPS0() { OP_stop, }
8483#define OPS1(a) { OP_##a, }
8484#define OPS2(a,b) { OP_##a,OP_##b, }
8485#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8486#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8487#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8488#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8489
8490/* These macros abstract out the exact format of the mnemonic table and
8491 save some repeated characters. */
8492
8493/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8494#define TxCE(mnem, op, top, nops, ops, ae, te) \
8495 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 8496 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8497
8498/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8499 a T_MNEM_xyz enumerator. */
8500#define TCE(mnem, aop, top, nops, ops, ae, te) \
8501 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8502#define tCE(mnem, aop, top, nops, ops, ae, te) \
8503 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8504
8505/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8506 infix after the third character. */
8507#define TxC3(mnem, op, top, nops, ops, ae, te) \
8508 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 8509 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8510#define TC3(mnem, aop, top, nops, ops, ae, te) \
8511 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8512#define tC3(mnem, aop, top, nops, ops, ae, te) \
8513 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8514
8515/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8516 appear in the condition table. */
8517#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8518 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 8519 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8520
8521#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8522 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8523 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8524 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8525 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8526 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8527 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8528 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8529 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8530 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8531 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8532 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8533 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8534 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8535 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8536 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8537 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8538 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8539 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8540 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8541
8542#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8543 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8544#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8545 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8546
8547/* Mnemonic that cannot be conditionalized. The ARM condition-code
8548 field is still 0xE. */
8549#define TUE(mnem, op, top, nops, ops, ae, te) \
8550 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8551 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8552
8553/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8554 condition code field. */
8555#define TUF(mnem, op, top, nops, ops, ae, te) \
8556 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8557 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8558
8559/* ARM-only variants of all the above. */
6a86118a
NC
8560#define CE(mnem, op, nops, ops, ae) \
8561 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8562
8563#define C3(mnem, op, nops, ops, ae) \
8564 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8565
e3cb604e
PB
8566/* Legacy mnemonics that always have conditional infix after the third
8567 character. */
8568#define CL(mnem, op, nops, ops, ae) \
8569 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8570 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8571
8f06b2d8
PB
8572/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
8573#define cCE(mnem, op, nops, ops, ae) \
8574 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8575
e3cb604e
PB
8576/* Legacy coprocessor instructions where conditional infix and conditional
8577 suffix are ambiguous. For consistency this includes all FPA instructions,
8578 not just the potentially ambiguous ones. */
8579#define cCL(mnem, op, nops, ops, ae) \
8580 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8581 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8582
8583/* Coprocessor, takes either a suffix or a position-3 infix
8584 (for an FPA corner case). */
8585#define C3E(mnem, op, nops, ops, ae) \
8586 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
8587 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 8588
6a86118a
NC
8589#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8590 { #m1 #m2 #m3, OPS##nops ops, \
8591 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8592 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8593
8594#define CM(m1, m2, op, nops, ops, ae) \
8595 xCM_(m1, , m2, op, nops, ops, ae), \
8596 xCM_(m1, eq, m2, op, nops, ops, ae), \
8597 xCM_(m1, ne, m2, op, nops, ops, ae), \
8598 xCM_(m1, cs, m2, op, nops, ops, ae), \
8599 xCM_(m1, hs, m2, op, nops, ops, ae), \
8600 xCM_(m1, cc, m2, op, nops, ops, ae), \
8601 xCM_(m1, ul, m2, op, nops, ops, ae), \
8602 xCM_(m1, lo, m2, op, nops, ops, ae), \
8603 xCM_(m1, mi, m2, op, nops, ops, ae), \
8604 xCM_(m1, pl, m2, op, nops, ops, ae), \
8605 xCM_(m1, vs, m2, op, nops, ops, ae), \
8606 xCM_(m1, vc, m2, op, nops, ops, ae), \
8607 xCM_(m1, hi, m2, op, nops, ops, ae), \
8608 xCM_(m1, ls, m2, op, nops, ops, ae), \
8609 xCM_(m1, ge, m2, op, nops, ops, ae), \
8610 xCM_(m1, lt, m2, op, nops, ops, ae), \
8611 xCM_(m1, gt, m2, op, nops, ops, ae), \
8612 xCM_(m1, le, m2, op, nops, ops, ae), \
8613 xCM_(m1, al, m2, op, nops, ops, ae)
8614
8615#define UE(mnem, op, nops, ops, ae) \
8616 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8617
8618#define UF(mnem, op, nops, ops, ae) \
8619 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8620
c19d1205
ZW
8621#define do_0 0
8622
8623/* Thumb-only, unconditional. */
8624#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8625
c19d1205 8626static const struct asm_opcode insns[] =
bfae80f2 8627{
c19d1205
ZW
8628#define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8629#define THUMB_VARIANT ARM_EXT_V4T
8630 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8631 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8632 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8633 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8634 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8635 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8636 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8637 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8638 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8639 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8640 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8641 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8642 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8643 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8644 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8645 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8646
8647 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8648 for setting PSR flag bits. They are obsolete in V6 and do not
8649 have Thumb equivalents. */
8650 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8651 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8652 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205
ZW
8653 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8654 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 8655 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205
ZW
8656 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8657 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8658 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
8659
8660 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8661 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8662 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8663 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8664
8665 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8666 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8667 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8668 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8669
8670 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8671 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8672 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8673 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8674
8675 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 8676 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
2fc8bdac 8677 TCE(bl, b000000, f000f800, 1, (EXPr), branch, t_branch23),
bfae80f2 8678
c19d1205 8679 /* Pseudo ops. */
e9f89963 8680 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
8681 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8682 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
8683
8684 /* Thumb-compatibility pseudo ops. */
8685 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8686 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8687 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8688 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8689 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 8690 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
8691 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8692 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8693 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8694 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8695 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8696 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8697
8698#undef THUMB_VARIANT
8699#define THUMB_VARIANT ARM_EXT_V6
2fc8bdac 8700 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
8701
8702 /* V1 instructions with no Thumb analogue prior to V6T2. */
8703#undef THUMB_VARIANT
8704#define THUMB_VARIANT ARM_EXT_V6T2
8705 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8706 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8707 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8708 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8709 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
8710
8711 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8712 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8713 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8714 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8715
9c3c69f2
PB
8716 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8717 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 8718
9c3c69f2
PB
8719 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8720 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8721
8722 /* V1 instructions with no Thumb analogue at all. */
8723 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8724 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8725
8726 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8727 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8728 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8729 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8730 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8731 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8732 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8733 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8734
8735#undef ARM_VARIANT
8736#define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8737#undef THUMB_VARIANT
8738#define THUMB_VARIANT ARM_EXT_V4T
8739 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8740 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8741
8742#undef THUMB_VARIANT
8743#define THUMB_VARIANT ARM_EXT_V6T2
8744 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8745 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8746
8747 /* Generic coprocessor instructions. */
8748 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8749 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8750 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8751 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8752 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8753 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8754 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8755
8756#undef ARM_VARIANT
8757#define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8758 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8759 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8760
8761#undef ARM_VARIANT
8762#define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8763 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8764 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8765
8766#undef ARM_VARIANT
8767#define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8768 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8769 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8770 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8771 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8772 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8773 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8774 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8775 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8776
8777#undef ARM_VARIANT
8778#define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8779#undef THUMB_VARIANT
8780#define THUMB_VARIANT ARM_EXT_V4T
8781 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8782 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8783 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8784 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8785 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8786 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8787
8788#undef ARM_VARIANT
8789#define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8790 /* ARM Architecture 4T. */
8791 /* Note: bx (and blx) are required on V5, even if the processor does
8792 not support Thumb. */
8793 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8794
8795#undef ARM_VARIANT
8796#define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8797#undef THUMB_VARIANT
8798#define THUMB_VARIANT ARM_EXT_V5T
8799 /* Note: blx has 2 variants; the .value coded here is for
8800 BLX(2). Only this variant has conditional execution. */
8801 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8802 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8803
8804#undef THUMB_VARIANT
8805#define THUMB_VARIANT ARM_EXT_V6T2
8806 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8807 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8808 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8809 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8810 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8811 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8812 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8813 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8814
8815#undef ARM_VARIANT
8816#define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8817 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8818 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8819 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8820 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8821
8822 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8823 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8824
8825 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8826 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8827 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8828 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8829
8830 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8831 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8832 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8833 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8834
8835 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8836 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8837
8838 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8839 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8840 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8841 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8842
8843#undef ARM_VARIANT
8844#define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8845 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8846 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8847 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8848
8849 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8850 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8851
8852#undef ARM_VARIANT
8853#define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8854 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8855
8856#undef ARM_VARIANT
8857#define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8858#undef THUMB_VARIANT
8859#define THUMB_VARIANT ARM_EXT_V6
8860 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8861 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8862 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8863 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8864 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8865 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8866 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8867 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8868 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8869 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8870
8871#undef THUMB_VARIANT
8872#define THUMB_VARIANT ARM_EXT_V6T2
8873 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8874 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8875 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8876 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8877 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8878 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8879 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8880 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8881 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8882 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8883 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8884 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8885 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8886 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8887 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8888 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8889 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8890 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8891 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8892 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8893 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8894 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8895 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8896 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8897 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8898 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8899 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8900 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8901 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8902 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8903 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8904 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8905 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8906 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8907 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8908 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8909 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8910 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8911 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8912 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8913 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8914 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8915 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8916 UF(rfeib, 9900a00, 1, (RRw), rfe),
8917 UF(rfeda, 8100a00, 1, (RRw), rfe),
8918 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8919 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8920 UF(rfefa, 9900a00, 1, (RRw), rfe),
8921 UF(rfeea, 8100a00, 1, (RRw), rfe),
8922 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8923 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8924 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8925 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8926 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8927 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8928 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8929 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8930 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 8931 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
8932 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8933 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8934 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8935 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8936 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8937 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8938 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8939 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8940 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8941 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8942 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8943 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8944 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8945 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8946 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8947 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8948 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8949 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8950 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8951 UF(srsib, 9cd0500, 1, (I31w), srs),
8952 UF(srsda, 84d0500, 1, (I31w), srs),
8953 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8954 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8955 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8956 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8957 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8958 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8959 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8960 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8961 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8962
8963#undef ARM_VARIANT
8964#define ARM_VARIANT ARM_EXT_V6K
8965#undef THUMB_VARIANT
8966#define THUMB_VARIANT ARM_EXT_V6K
8967 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8968 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8969 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8970 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8971
8972#undef THUMB_VARIANT
8973#define THUMB_VARIANT ARM_EXT_V6T2
8974 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8975 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8976 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8977 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8978 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8979 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8980 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8981
8982#undef ARM_VARIANT
8983#define ARM_VARIANT ARM_EXT_V6Z
3eb17e6b 8984 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
8985
8986#undef ARM_VARIANT
8987#define ARM_VARIANT ARM_EXT_V6T2
8988 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8989 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8990 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8991 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8992
8993 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8994 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8995 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8996 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8997
8998 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8999 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9000 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9001 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9002
9003 UT(cbnz, b900, 2, (RR, EXP), t_czb),
9004 UT(cbz, b100, 2, (RR, EXP), t_czb),
9005 /* ARM does not really have an IT instruction. */
9006 TUE(it, 0, bf08, 1, (COND), it, t_it),
9007 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
9008 TUE(ite, 0, bf04, 1, (COND), it, t_it),
9009 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
9010 TUE(itet, 0, bf06, 1, (COND), it, t_it),
9011 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
9012 TUE(itee, 0, bf02, 1, (COND), it, t_it),
9013 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
9014 TUE(itett, 0, bf07, 1, (COND), it, t_it),
9015 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
9016 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
9017 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
9018 TUE(itete, 0, bf05, 1, (COND), it, t_it),
9019 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
9020 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
9021
92e90b6e
PB
9022 /* Thumb2 only instructions. */
9023#undef ARM_VARIANT
9024#define ARM_VARIANT 0
9025
9026 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9027 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9028 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
9029 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
9030
c19d1205
ZW
9031#undef ARM_VARIANT
9032#define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
9033 cCE(wfs, e200110, 1, (RR), rd),
9034 cCE(rfs, e300110, 1, (RR), rd),
9035 cCE(wfc, e400110, 1, (RR), rd),
9036 cCE(rfc, e500110, 1, (RR), rd),
9037
e3cb604e
PB
9038 cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
9039 cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
9040 cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
9041 cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
9042
9043 cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
9044 cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
9045 cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
9046 cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
9047
9048 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
9049 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
9050 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
9051 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
9052 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
9053 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
9054 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
9055 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
9056 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
9057 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
9058 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
9059 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
9060
9061 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
9062 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
9063 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
9064 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
9065 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
9066 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
9067 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
9068 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
9069 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
9070 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
9071 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
9072 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
9073
9074 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
9075 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
9076 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
9077 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
9078 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
9079 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
9080 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
9081 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
9082 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
9083 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
9084 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
9085 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
9086
9087 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
9088 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
9089 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
9090 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
9091 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
9092 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
9093 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
9094 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
9095 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
9096 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
9097 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
9098 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
9099
9100 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
9101 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
9102 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
9103 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
9104 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
9105 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
9106 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
9107 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
9108 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
9109 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
9110 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
9111 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
9112
9113 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
9114 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
9115 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
9116 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
9117 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
9118 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
9119 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
9120 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
9121 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
9122 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
9123 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
9124 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
9125
9126 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
9127 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
9128 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
9129 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
9130 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
9131 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
9132 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
9133 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
9134 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
9135 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
9136 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
9137 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
9138
9139 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
9140 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
9141 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
9142 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
9143 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
9144 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
9145 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
9146 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
9147 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
9148 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
9149 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
9150 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
9151
9152 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
9153 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
9154 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
9155 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
9156 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
9157 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
9158 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
9159 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
9160 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
9161 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
9162 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
9163 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
9164
9165 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
9166 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
9167 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
9168 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
9169 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
9170 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
9171 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
9172 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
9173 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
9174 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
9175 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
9176 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
9177
9178 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
9179 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
9180 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
9181 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
9182 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
9183 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
9184 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
9185 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
9186 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
9187 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
9188 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
9189 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
9190
9191 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
9192 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
9193 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
9194 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
9195 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
9196 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
9197 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
9198 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
9199 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
9200 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
9201 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
9202 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
9203
9204 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
9205 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
9206 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
9207 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
9208 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
9209 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
9210 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
9211 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
9212 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
9213 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
9214 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
9215 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
9216
9217 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
9218 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
9219 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
9220 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
9221 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
9222 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
9223 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
9224 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
9225 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
9226 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
9227 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
9228 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
9229
9230 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
9231 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
9232 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
9233 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
9234 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
9235 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
9236 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
9237 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
9238 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
9239 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
9240 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
9241 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
9242
9243 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
9244 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
9245 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
9246 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
9247 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
9248 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
9249 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
9250 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
9251 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
9252 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
9253 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
9254 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
9255
9256 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
9257 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
9258 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
9259 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
9260 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
9261 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9262 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9263 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9264 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
9265 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
9266 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
9267 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
9268
9269 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
9270 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
9271 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
9272 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
9273 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
9274 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9275 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9276 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9277 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
9278 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
9279 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
9280 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
9281
9282 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
9283 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
9284 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
9285 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
9286 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
9287 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9288 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9289 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9290 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
9291 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
9292 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
9293 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
9294
9295 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
9296 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
9297 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
9298 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
9299 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
9300 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9301 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9302 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9303 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
9304 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
9305 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
9306 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
9307
9308 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
9309 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
9310 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
9311 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
9312 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
9313 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9314 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9315 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9316 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
9317 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
9318 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
9319 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
9320
9321 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
9322 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
9323 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
9324 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
9325 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
9326 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9327 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9328 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9329 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
9330 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
9331 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
9332 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
9333
9334 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9335 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9336 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9337 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9338 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9339 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9340 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9341 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9342 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9343 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9344 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9345 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9346
9347 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9348 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9349 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9350 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9351 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9352 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9353 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9354 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9355 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9356 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9357 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9358 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9359
9360 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9361 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9362 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9363 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9364 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9365 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9366 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9367 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9368 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9369 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9370 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9371 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9372
9373 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9374 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9375 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9376 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9377 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9378 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9379 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9380 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9381 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9382 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9383 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9384 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9385
9386 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9387 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9388 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9389 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9390 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9391 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9392 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9393 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9394 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9395 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9396 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9397 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9398
9399 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9400 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9401 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9402 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9403 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9404 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9405 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9406 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9407 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9408 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9409 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9410 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9411
9412 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9413 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9414 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9415 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9416 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9417 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9418 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9419 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9420 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9421 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9422 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9423 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
9424
9425 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 9426 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 9427 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
9428 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9429
e3cb604e
PB
9430 cCL(flts, e000110, 2, (RF, RR), rn_rd),
9431 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
9432 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
9433 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
9434 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
9435 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9436 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9437 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9438 cCL(flte, e080110, 2, (RF, RR), rn_rd),
9439 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
9440 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
9441 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 9442
c19d1205
ZW
9443 /* The implementation of the FIX instruction is broken on some
9444 assemblers, in that it accepts a precision specifier as well as a
9445 rounding specifier, despite the fact that this is meaningless.
9446 To be more compatible, we accept it as well, though of course it
9447 does not set any bits. */
8f06b2d8 9448 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
9449 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
9450 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
9451 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
9452 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
9453 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
9454 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
9455 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
9456 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
9457 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
9458 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
9459 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
9460 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 9461
c19d1205
ZW
9462 /* Instructions that were new with the real FPA, call them V2. */
9463#undef ARM_VARIANT
9464#define ARM_VARIANT FPU_FPA_EXT_V2
8f06b2d8 9465 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9466 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9467 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 9468 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9469 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9470 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
9471
9472#undef ARM_VARIANT
9473#define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
9474 /* Moves and type conversions. */
8f06b2d8
PB
9475 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9476 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9477 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9478 cCE(fmstat, ef1fa10, 0, (), noargs),
9479 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9480 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9481 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9482 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9483 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9484 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9485 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9486 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
9487
9488 /* Memory operations. */
8f06b2d8
PB
9489 cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9490 cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9491 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9492 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9493 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9494 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9495 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9496 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9497 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9498 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9499 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9500 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9501 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9502 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9503 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9504 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9505 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9506 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 9507
c19d1205 9508 /* Monadic operations. */
8f06b2d8
PB
9509 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9510 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9511 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
9512
9513 /* Dyadic operations. */
8f06b2d8
PB
9514 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9515 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9516 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9517 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9518 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9519 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9520 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9521 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9522 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 9523
c19d1205 9524 /* Comparisons. */
8f06b2d8
PB
9525 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9526 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9527 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9528 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 9529
c19d1205
ZW
9530#undef ARM_VARIANT
9531#define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
9532 /* Moves and type conversions. */
8f06b2d8
PB
9533 cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9534 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9535 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9536 cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9537 cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9538 cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9539 cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9540 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9541 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9542 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9543 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9544 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9545 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
9546
9547 /* Memory operations. */
8f06b2d8
PB
9548 cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9549 cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9550 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9551 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9552 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9553 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9554 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9555 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9556 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9557 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9558
c19d1205 9559 /* Monadic operations. */
8f06b2d8
PB
9560 cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9561 cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9562 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
c19d1205
ZW
9563
9564 /* Dyadic operations. */
8f06b2d8
PB
9565 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9566 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9567 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9568 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9569 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9570 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9571 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9572 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9573 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9574
c19d1205 9575 /* Comparisons. */
8f06b2d8
PB
9576 cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9577 cCE(fcmpzd, eb50b40, 1, (RVD), rd),
9578 cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9579 cCE(fcmpezd, eb50bc0, 1, (RVD), rd),
c19d1205
ZW
9580
9581#undef ARM_VARIANT
9582#define ARM_VARIANT FPU_VFP_EXT_V2
8f06b2d8
PB
9583 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9584 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9585 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9586 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
c19d1205
ZW
9587
9588#undef ARM_VARIANT
9589#define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
8f06b2d8
PB
9590 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9591 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9592 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9593 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9594 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9595 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9596 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9597 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
9598
9599#undef ARM_VARIANT
9600#define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
8f06b2d8
PB
9601 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9602 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9603 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9604 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9605 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9606 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9607 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9608 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9609 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9610 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9611 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9612 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9613 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9614 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9615 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9616 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9617 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9618 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9619 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9620 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9621 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9622 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9623 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9624 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9625 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9626 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9627 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9628 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9629 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9630 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9631 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9632 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9633 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9634 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9635 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9636 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9637 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9638 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9639 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9640 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9641 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9642 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9643 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9644 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9645 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9646 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9647 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9648 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9649 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9650 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9651 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9652 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9653 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9654 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9655 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9656 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9657 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9658 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9659 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9660 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9661 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9662 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9663 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9664 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9665 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9666 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9667 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9668 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9669 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9670 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9671 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9672 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9673 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9674 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9675 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9676 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9677 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9678 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9679 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9680 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9681 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9682 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9683 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9684 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9685 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9686 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9687 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9688 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9689 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9690 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9691 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9692 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9693 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9694 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9695 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9696 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9697 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9698 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9699 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9700 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9701 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9702 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9703 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9704 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9705 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9706 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9707 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9708 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9709 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9710 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9711 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9712 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9713 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9714 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9715 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9716 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9717 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9718 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9719 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9720 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9721 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9722 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9723 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9724 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9725 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9726 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9727 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9728 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9729 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9730 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9731 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9732 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9733 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9734 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9735 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9736 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9737 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9738 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9739 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9740 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9741 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9742 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9743 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9744 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9745 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9746 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9747 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9748 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9749 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9750 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9751 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9752 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9753 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9754 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9755 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9756 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9757 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9758 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9759 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9760 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9761 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9762 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205
ZW
9763
9764#undef ARM_VARIANT
9765#define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
8f06b2d8
PB
9766 cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9767 cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9768 cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9769 cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9770 cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9771 cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9772 cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9773 cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9774 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9775 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9776 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9777 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9778 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9779 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9780 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9781 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9782 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9783 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9784 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9785 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9786 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9787 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9788 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9789 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9790 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9791 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9792 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9793 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9794 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9795 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9796 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9797 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9798 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9799 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9800 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9801 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9802 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9803 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9804 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9805 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9806 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9807 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9808 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9809 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9810 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9811 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9812 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9813 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9814 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9815 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9816 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9817 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9818 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9819 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9820 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9821 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9822 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9823 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9824 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9825 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9826 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9827 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9828 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9829 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9830 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9831 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9832 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9833 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9834 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9835 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9836 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9837 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9838 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9839 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9840 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9841 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
9842};
9843#undef ARM_VARIANT
9844#undef THUMB_VARIANT
9845#undef TCE
9846#undef TCM
9847#undef TUE
9848#undef TUF
9849#undef TCC
8f06b2d8 9850#undef cCE
e3cb604e
PB
9851#undef cCL
9852#undef C3E
c19d1205
ZW
9853#undef CE
9854#undef CM
9855#undef UE
9856#undef UF
9857#undef UT
9858#undef OPS0
9859#undef OPS1
9860#undef OPS2
9861#undef OPS3
9862#undef OPS4
9863#undef OPS5
9864#undef OPS6
9865#undef do_0
9866\f
9867/* MD interface: bits in the object file. */
bfae80f2 9868
c19d1205
ZW
9869/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9870 for use in the a.out file, and stores them in the array pointed to by buf.
9871 This knows about the endian-ness of the target machine and does
9872 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9873 2 (short) and 4 (long) Floating numbers are put out as a series of
9874 LITTLENUMS (shorts, here at least). */
b99bd4ef 9875
c19d1205
ZW
9876void
9877md_number_to_chars (char * buf, valueT val, int n)
9878{
9879 if (target_big_endian)
9880 number_to_chars_bigendian (buf, val, n);
9881 else
9882 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
9883}
9884
c19d1205
ZW
9885static valueT
9886md_chars_to_number (char * buf, int n)
bfae80f2 9887{
c19d1205
ZW
9888 valueT result = 0;
9889 unsigned char * where = (unsigned char *) buf;
bfae80f2 9890
c19d1205 9891 if (target_big_endian)
b99bd4ef 9892 {
c19d1205
ZW
9893 while (n--)
9894 {
9895 result <<= 8;
9896 result |= (*where++ & 255);
9897 }
b99bd4ef 9898 }
c19d1205 9899 else
b99bd4ef 9900 {
c19d1205
ZW
9901 while (n--)
9902 {
9903 result <<= 8;
9904 result |= (where[n] & 255);
9905 }
bfae80f2 9906 }
b99bd4ef 9907
c19d1205 9908 return result;
bfae80f2 9909}
b99bd4ef 9910
c19d1205 9911/* MD interface: Sections. */
b99bd4ef 9912
0110f2b8
PB
9913/* Estimate the size of a frag before relaxing. Assume everything fits in
9914 2 bytes. */
9915
c19d1205 9916int
0110f2b8 9917md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
9918 segT segtype ATTRIBUTE_UNUSED)
9919{
0110f2b8
PB
9920 fragp->fr_var = 2;
9921 return 2;
9922}
9923
9924/* Convert a machine dependent frag. */
9925
9926void
9927md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
9928{
9929 unsigned long insn;
9930 unsigned long old_op;
9931 char *buf;
9932 expressionS exp;
9933 fixS *fixp;
9934 int reloc_type;
9935 int pc_rel;
9936 int opcode;
9937
9938 buf = fragp->fr_literal + fragp->fr_fix;
9939
9940 old_op = bfd_get_16(abfd, buf);
9941 if (fragp->fr_symbol) {
9942 exp.X_op = O_symbol;
9943 exp.X_add_symbol = fragp->fr_symbol;
9944 } else {
9945 exp.X_op = O_constant;
9946 }
9947 exp.X_add_number = fragp->fr_offset;
9948 opcode = fragp->fr_subtype;
9949 switch (opcode)
9950 {
9951 case T_MNEM_ldr_pc:
9952 case T_MNEM_ldr_pc2:
9953 case T_MNEM_ldr_sp:
9954 case T_MNEM_str_sp:
9955 case T_MNEM_ldr:
9956 case T_MNEM_ldrb:
9957 case T_MNEM_ldrh:
9958 case T_MNEM_str:
9959 case T_MNEM_strb:
9960 case T_MNEM_strh:
9961 if (fragp->fr_var == 4)
9962 {
9963 insn = THUMB_OP32(opcode);
9964 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
9965 {
9966 insn |= (old_op & 0x700) << 4;
9967 }
9968 else
9969 {
9970 insn |= (old_op & 7) << 12;
9971 insn |= (old_op & 0x38) << 13;
9972 }
9973 insn |= 0x00000c00;
9974 put_thumb32_insn (buf, insn);
9975 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9976 }
9977 else
9978 {
9979 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
9980 }
9981 pc_rel = (opcode == T_MNEM_ldr_pc2);
9982 break;
9983 case T_MNEM_adr:
9984 if (fragp->fr_var == 4)
9985 {
9986 insn = THUMB_OP32 (opcode);
9987 insn |= (old_op & 0xf0) << 4;
9988 put_thumb32_insn (buf, insn);
9989 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
9990 }
9991 else
9992 {
9993 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
9994 exp.X_add_number -= 4;
9995 }
9996 pc_rel = 1;
9997 break;
9998 case T_MNEM_mov:
9999 case T_MNEM_movs:
10000 case T_MNEM_cmp:
10001 case T_MNEM_cmn:
10002 if (fragp->fr_var == 4)
10003 {
10004 int r0off = (opcode == T_MNEM_mov
10005 || opcode == T_MNEM_movs) ? 0 : 8;
10006 insn = THUMB_OP32 (opcode);
10007 insn = (insn & 0xe1ffffff) | 0x10000000;
10008 insn |= (old_op & 0x700) << r0off;
10009 put_thumb32_insn (buf, insn);
10010 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10011 }
10012 else
10013 {
10014 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
10015 }
10016 pc_rel = 0;
10017 break;
10018 case T_MNEM_b:
10019 if (fragp->fr_var == 4)
10020 {
10021 insn = THUMB_OP32(opcode);
10022 put_thumb32_insn (buf, insn);
10023 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
10024 }
10025 else
10026 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
10027 pc_rel = 1;
10028 break;
10029 case T_MNEM_bcond:
10030 if (fragp->fr_var == 4)
10031 {
10032 insn = THUMB_OP32(opcode);
10033 insn |= (old_op & 0xf00) << 14;
10034 put_thumb32_insn (buf, insn);
10035 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
10036 }
10037 else
10038 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
10039 pc_rel = 1;
10040 break;
10041 case T_MNEM_add_sp:
10042 case T_MNEM_add_pc:
10043 case T_MNEM_inc_sp:
10044 case T_MNEM_dec_sp:
10045 if (fragp->fr_var == 4)
10046 {
10047 /* ??? Choose between add and addw. */
10048 insn = THUMB_OP32 (opcode);
10049 insn |= (old_op & 0xf0) << 4;
10050 put_thumb32_insn (buf, insn);
10051 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10052 }
10053 else
10054 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10055 pc_rel = 0;
10056 break;
10057
10058 case T_MNEM_addi:
10059 case T_MNEM_addis:
10060 case T_MNEM_subi:
10061 case T_MNEM_subis:
10062 if (fragp->fr_var == 4)
10063 {
10064 insn = THUMB_OP32 (opcode);
10065 insn |= (old_op & 0xf0) << 4;
10066 insn |= (old_op & 0xf) << 16;
10067 put_thumb32_insn (buf, insn);
10068 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10069 }
10070 else
10071 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10072 pc_rel = 0;
10073 break;
10074 default:
10075 abort();
10076 }
10077 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
10078 reloc_type);
10079 fixp->fx_file = fragp->fr_file;
10080 fixp->fx_line = fragp->fr_line;
10081 fragp->fr_fix += fragp->fr_var;
10082}
10083
10084/* Return the size of a relaxable immediate operand instruction.
10085 SHIFT and SIZE specify the form of the allowable immediate. */
10086static int
10087relax_immediate (fragS *fragp, int size, int shift)
10088{
10089 offsetT offset;
10090 offsetT mask;
10091 offsetT low;
10092
10093 /* ??? Should be able to do better than this. */
10094 if (fragp->fr_symbol)
10095 return 4;
10096
10097 low = (1 << shift) - 1;
10098 mask = (1 << (shift + size)) - (1 << shift);
10099 offset = fragp->fr_offset;
10100 /* Force misaligned offsets to 32-bit variant. */
10101 if (offset & low)
10102 return -4;
10103 if (offset & ~mask)
10104 return 4;
10105 return 2;
10106}
10107
10108/* Return the size of a relaxable adr pseudo-instruction or PC-relative
10109 load. */
10110static int
10111relax_adr (fragS *fragp, asection *sec)
10112{
10113 addressT addr;
10114 offsetT val;
10115
10116 /* Assume worst case for symbols not known to be in the same section. */
10117 if (!S_IS_DEFINED(fragp->fr_symbol)
10118 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10119 return 4;
10120
10121 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10122 addr = fragp->fr_address + fragp->fr_fix;
10123 addr = (addr + 4) & ~3;
10124 /* Fix the insn as the 4-byte version if the target address is not
10125 sufficiently aligned. This is prevents an infinite loop when two
10126 instructions have contradictory range/alignment requirements. */
10127 if (val & 3)
10128 return -4;
10129 val -= addr;
10130 if (val < 0 || val > 1020)
10131 return 4;
10132 return 2;
10133}
10134
10135/* Return the size of a relaxable add/sub immediate instruction. */
10136static int
10137relax_addsub (fragS *fragp, asection *sec)
10138{
10139 char *buf;
10140 int op;
10141
10142 buf = fragp->fr_literal + fragp->fr_fix;
10143 op = bfd_get_16(sec->owner, buf);
10144 if ((op & 0xf) == ((op >> 4) & 0xf))
10145 return relax_immediate (fragp, 8, 0);
10146 else
10147 return relax_immediate (fragp, 3, 0);
10148}
10149
10150
10151/* Return the size of a relaxable branch instruction. BITS is the
10152 size of the offset field in the narrow instruction. */
10153
10154static int
10155relax_branch (fragS *fragp, asection *sec, int bits)
10156{
10157 addressT addr;
10158 offsetT val;
10159 offsetT limit;
10160
10161 /* Assume worst case for symbols not known to be in the same section. */
10162 if (!S_IS_DEFINED(fragp->fr_symbol)
10163 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10164 return 4;
10165
10166 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10167 addr = fragp->fr_address + fragp->fr_fix + 4;
10168 val -= addr;
10169
10170 /* Offset is a signed value *2 */
10171 limit = 1 << bits;
10172 if (val >= limit || val < -limit)
10173 return 4;
10174 return 2;
10175}
10176
10177
10178/* Relax a machine dependent frag. This returns the amount by which
10179 the current size of the frag should change. */
10180
10181int
10182arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
10183{
10184 int oldsize;
10185 int newsize;
10186
10187 oldsize = fragp->fr_var;
10188 switch (fragp->fr_subtype)
10189 {
10190 case T_MNEM_ldr_pc2:
10191 newsize = relax_adr(fragp, sec);
10192 break;
10193 case T_MNEM_ldr_pc:
10194 case T_MNEM_ldr_sp:
10195 case T_MNEM_str_sp:
10196 newsize = relax_immediate(fragp, 8, 2);
10197 break;
10198 case T_MNEM_ldr:
10199 case T_MNEM_str:
10200 newsize = relax_immediate(fragp, 5, 2);
10201 break;
10202 case T_MNEM_ldrh:
10203 case T_MNEM_strh:
10204 newsize = relax_immediate(fragp, 5, 1);
10205 break;
10206 case T_MNEM_ldrb:
10207 case T_MNEM_strb:
10208 newsize = relax_immediate(fragp, 5, 0);
10209 break;
10210 case T_MNEM_adr:
10211 newsize = relax_adr(fragp, sec);
10212 break;
10213 case T_MNEM_mov:
10214 case T_MNEM_movs:
10215 case T_MNEM_cmp:
10216 case T_MNEM_cmn:
10217 newsize = relax_immediate(fragp, 8, 0);
10218 break;
10219 case T_MNEM_b:
10220 newsize = relax_branch(fragp, sec, 11);
10221 break;
10222 case T_MNEM_bcond:
10223 newsize = relax_branch(fragp, sec, 8);
10224 break;
10225 case T_MNEM_add_sp:
10226 case T_MNEM_add_pc:
10227 newsize = relax_immediate (fragp, 8, 2);
10228 break;
10229 case T_MNEM_inc_sp:
10230 case T_MNEM_dec_sp:
10231 newsize = relax_immediate (fragp, 7, 2);
10232 break;
10233 case T_MNEM_addi:
10234 case T_MNEM_addis:
10235 case T_MNEM_subi:
10236 case T_MNEM_subis:
10237 newsize = relax_addsub (fragp, sec);
10238 break;
10239 default:
10240 abort();
10241 }
10242 if (newsize < 0)
10243 {
10244 fragp->fr_var = -newsize;
10245 md_convert_frag (sec->owner, sec, fragp);
10246 frag_wane(fragp);
10247 return -(newsize + oldsize);
10248 }
10249 fragp->fr_var = newsize;
10250 return newsize - oldsize;
c19d1205 10251}
b99bd4ef 10252
c19d1205 10253/* Round up a section size to the appropriate boundary. */
b99bd4ef 10254
c19d1205
ZW
10255valueT
10256md_section_align (segT segment ATTRIBUTE_UNUSED,
10257 valueT size)
10258{
10259#ifdef OBJ_ELF
10260 return size;
10261#else
10262 /* Round all sects to multiple of 4. */
10263 return (size + 3) & ~3;
10264#endif
bfae80f2 10265}
b99bd4ef 10266
c19d1205
ZW
10267/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10268 of an rs_align_code fragment. */
10269
10270void
10271arm_handle_align (fragS * fragP)
bfae80f2 10272{
c19d1205
ZW
10273 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
10274 static char const thumb_noop[2] = { 0xc0, 0x46 };
10275 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
10276 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
10277
10278 int bytes, fix, noop_size;
10279 char * p;
10280 const char * noop;
bfae80f2 10281
c19d1205 10282 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
10283 return;
10284
c19d1205
ZW
10285 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
10286 p = fragP->fr_literal + fragP->fr_fix;
10287 fix = 0;
bfae80f2 10288
c19d1205
ZW
10289 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
10290 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 10291
c19d1205 10292 if (fragP->tc_frag_data)
a737bd4d 10293 {
c19d1205
ZW
10294 if (target_big_endian)
10295 noop = thumb_bigend_noop;
10296 else
10297 noop = thumb_noop;
10298 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
10299 }
10300 else
10301 {
c19d1205
ZW
10302 if (target_big_endian)
10303 noop = arm_bigend_noop;
10304 else
10305 noop = arm_noop;
10306 noop_size = sizeof (arm_noop);
7ed4c4c5 10307 }
a737bd4d 10308
c19d1205 10309 if (bytes & (noop_size - 1))
7ed4c4c5 10310 {
c19d1205
ZW
10311 fix = bytes & (noop_size - 1);
10312 memset (p, 0, fix);
10313 p += fix;
10314 bytes -= fix;
a737bd4d 10315 }
a737bd4d 10316
c19d1205 10317 while (bytes >= noop_size)
a737bd4d 10318 {
c19d1205
ZW
10319 memcpy (p, noop, noop_size);
10320 p += noop_size;
10321 bytes -= noop_size;
10322 fix += noop_size;
a737bd4d
NC
10323 }
10324
c19d1205
ZW
10325 fragP->fr_fix += fix;
10326 fragP->fr_var = noop_size;
a737bd4d
NC
10327}
10328
c19d1205
ZW
10329/* Called from md_do_align. Used to create an alignment
10330 frag in a code section. */
10331
10332void
10333arm_frag_align_code (int n, int max)
bfae80f2 10334{
c19d1205 10335 char * p;
7ed4c4c5 10336
c19d1205
ZW
10337 /* We assume that there will never be a requirement
10338 to support alignments greater than 32 bytes. */
10339 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
10340 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 10341
c19d1205
ZW
10342 p = frag_var (rs_align_code,
10343 MAX_MEM_FOR_RS_ALIGN_CODE,
10344 1,
10345 (relax_substateT) max,
10346 (symbolS *) NULL,
10347 (offsetT) n,
10348 (char *) NULL);
10349 *p = 0;
10350}
bfae80f2 10351
c19d1205 10352/* Perform target specific initialisation of a frag. */
bfae80f2 10353
c19d1205
ZW
10354void
10355arm_init_frag (fragS * fragP)
10356{
10357 /* Record whether this frag is in an ARM or a THUMB area. */
10358 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
10359}
10360
c19d1205
ZW
10361#ifdef OBJ_ELF
10362/* When we change sections we need to issue a new mapping symbol. */
10363
10364void
10365arm_elf_change_section (void)
bfae80f2 10366{
c19d1205
ZW
10367 flagword flags;
10368 segment_info_type *seginfo;
bfae80f2 10369
c19d1205
ZW
10370 /* Link an unlinked unwind index table section to the .text section. */
10371 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
10372 && elf_linked_to_section (now_seg) == NULL)
10373 elf_linked_to_section (now_seg) = text_section;
10374
10375 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
10376 return;
10377
c19d1205
ZW
10378 flags = bfd_get_section_flags (stdoutput, now_seg);
10379
10380 /* We can ignore sections that only contain debug info. */
10381 if ((flags & SEC_ALLOC) == 0)
10382 return;
bfae80f2 10383
c19d1205
ZW
10384 seginfo = seg_info (now_seg);
10385 mapstate = seginfo->tc_segment_info_data.mapstate;
10386 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
10387}
10388
c19d1205
ZW
10389int
10390arm_elf_section_type (const char * str, size_t len)
e45d0630 10391{
c19d1205
ZW
10392 if (len == 5 && strncmp (str, "exidx", 5) == 0)
10393 return SHT_ARM_EXIDX;
e45d0630 10394
c19d1205
ZW
10395 return -1;
10396}
10397\f
10398/* Code to deal with unwinding tables. */
e45d0630 10399
c19d1205 10400static void add_unwind_adjustsp (offsetT);
e45d0630 10401
c19d1205 10402/* Cenerate and deferred unwind frame offset. */
e45d0630 10403
bfae80f2 10404static void
c19d1205 10405flush_pending_unwind (void)
bfae80f2 10406{
c19d1205 10407 offsetT offset;
bfae80f2 10408
c19d1205
ZW
10409 offset = unwind.pending_offset;
10410 unwind.pending_offset = 0;
10411 if (offset != 0)
10412 add_unwind_adjustsp (offset);
bfae80f2
RE
10413}
10414
c19d1205
ZW
10415/* Add an opcode to this list for this function. Two-byte opcodes should
10416 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
10417 order. */
10418
bfae80f2 10419static void
c19d1205 10420add_unwind_opcode (valueT op, int length)
bfae80f2 10421{
c19d1205
ZW
10422 /* Add any deferred stack adjustment. */
10423 if (unwind.pending_offset)
10424 flush_pending_unwind ();
bfae80f2 10425
c19d1205 10426 unwind.sp_restored = 0;
bfae80f2 10427
c19d1205 10428 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 10429 {
c19d1205
ZW
10430 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
10431 if (unwind.opcodes)
10432 unwind.opcodes = xrealloc (unwind.opcodes,
10433 unwind.opcode_alloc);
10434 else
10435 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 10436 }
c19d1205 10437 while (length > 0)
bfae80f2 10438 {
c19d1205
ZW
10439 length--;
10440 unwind.opcodes[unwind.opcode_count] = op & 0xff;
10441 op >>= 8;
10442 unwind.opcode_count++;
bfae80f2 10443 }
bfae80f2
RE
10444}
10445
c19d1205
ZW
10446/* Add unwind opcodes to adjust the stack pointer. */
10447
bfae80f2 10448static void
c19d1205 10449add_unwind_adjustsp (offsetT offset)
bfae80f2 10450{
c19d1205 10451 valueT op;
bfae80f2 10452
c19d1205 10453 if (offset > 0x200)
bfae80f2 10454 {
c19d1205
ZW
10455 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
10456 char bytes[5];
10457 int n;
10458 valueT o;
bfae80f2 10459
c19d1205
ZW
10460 /* Long form: 0xb2, uleb128. */
10461 /* This might not fit in a word so add the individual bytes,
10462 remembering the list is built in reverse order. */
10463 o = (valueT) ((offset - 0x204) >> 2);
10464 if (o == 0)
10465 add_unwind_opcode (0, 1);
bfae80f2 10466
c19d1205
ZW
10467 /* Calculate the uleb128 encoding of the offset. */
10468 n = 0;
10469 while (o)
10470 {
10471 bytes[n] = o & 0x7f;
10472 o >>= 7;
10473 if (o)
10474 bytes[n] |= 0x80;
10475 n++;
10476 }
10477 /* Add the insn. */
10478 for (; n; n--)
10479 add_unwind_opcode (bytes[n - 1], 1);
10480 add_unwind_opcode (0xb2, 1);
10481 }
10482 else if (offset > 0x100)
bfae80f2 10483 {
c19d1205
ZW
10484 /* Two short opcodes. */
10485 add_unwind_opcode (0x3f, 1);
10486 op = (offset - 0x104) >> 2;
10487 add_unwind_opcode (op, 1);
bfae80f2 10488 }
c19d1205
ZW
10489 else if (offset > 0)
10490 {
10491 /* Short opcode. */
10492 op = (offset - 4) >> 2;
10493 add_unwind_opcode (op, 1);
10494 }
10495 else if (offset < 0)
bfae80f2 10496 {
c19d1205
ZW
10497 offset = -offset;
10498 while (offset > 0x100)
bfae80f2 10499 {
c19d1205
ZW
10500 add_unwind_opcode (0x7f, 1);
10501 offset -= 0x100;
bfae80f2 10502 }
c19d1205
ZW
10503 op = ((offset - 4) >> 2) | 0x40;
10504 add_unwind_opcode (op, 1);
bfae80f2 10505 }
bfae80f2
RE
10506}
10507
c19d1205
ZW
10508/* Finish the list of unwind opcodes for this function. */
10509static void
10510finish_unwind_opcodes (void)
bfae80f2 10511{
c19d1205 10512 valueT op;
bfae80f2 10513
c19d1205 10514 if (unwind.fp_used)
bfae80f2 10515 {
c19d1205
ZW
10516 /* Adjust sp as neccessary. */
10517 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
10518 flush_pending_unwind ();
bfae80f2 10519
c19d1205
ZW
10520 /* After restoring sp from the frame pointer. */
10521 op = 0x90 | unwind.fp_reg;
10522 add_unwind_opcode (op, 1);
10523 }
10524 else
10525 flush_pending_unwind ();
bfae80f2
RE
10526}
10527
bfae80f2 10528
c19d1205
ZW
10529/* Start an exception table entry. If idx is nonzero this is an index table
10530 entry. */
bfae80f2
RE
10531
10532static void
c19d1205 10533start_unwind_section (const segT text_seg, int idx)
bfae80f2 10534{
c19d1205
ZW
10535 const char * text_name;
10536 const char * prefix;
10537 const char * prefix_once;
10538 const char * group_name;
10539 size_t prefix_len;
10540 size_t text_len;
10541 char * sec_name;
10542 size_t sec_name_len;
10543 int type;
10544 int flags;
10545 int linkonce;
bfae80f2 10546
c19d1205 10547 if (idx)
bfae80f2 10548 {
c19d1205
ZW
10549 prefix = ELF_STRING_ARM_unwind;
10550 prefix_once = ELF_STRING_ARM_unwind_once;
10551 type = SHT_ARM_EXIDX;
bfae80f2 10552 }
c19d1205 10553 else
bfae80f2 10554 {
c19d1205
ZW
10555 prefix = ELF_STRING_ARM_unwind_info;
10556 prefix_once = ELF_STRING_ARM_unwind_info_once;
10557 type = SHT_PROGBITS;
bfae80f2
RE
10558 }
10559
c19d1205
ZW
10560 text_name = segment_name (text_seg);
10561 if (streq (text_name, ".text"))
10562 text_name = "";
10563
10564 if (strncmp (text_name, ".gnu.linkonce.t.",
10565 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 10566 {
c19d1205
ZW
10567 prefix = prefix_once;
10568 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
10569 }
10570
c19d1205
ZW
10571 prefix_len = strlen (prefix);
10572 text_len = strlen (text_name);
10573 sec_name_len = prefix_len + text_len;
10574 sec_name = xmalloc (sec_name_len + 1);
10575 memcpy (sec_name, prefix, prefix_len);
10576 memcpy (sec_name + prefix_len, text_name, text_len);
10577 sec_name[prefix_len + text_len] = '\0';
bfae80f2 10578
c19d1205
ZW
10579 flags = SHF_ALLOC;
10580 linkonce = 0;
10581 group_name = 0;
bfae80f2 10582
c19d1205
ZW
10583 /* Handle COMDAT group. */
10584 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 10585 {
c19d1205
ZW
10586 group_name = elf_group_name (text_seg);
10587 if (group_name == NULL)
10588 {
10589 as_bad ("Group section `%s' has no group signature",
10590 segment_name (text_seg));
10591 ignore_rest_of_line ();
10592 return;
10593 }
10594 flags |= SHF_GROUP;
10595 linkonce = 1;
bfae80f2
RE
10596 }
10597
c19d1205 10598 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 10599
c19d1205
ZW
10600 /* Set the setion link for index tables. */
10601 if (idx)
10602 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
10603}
10604
bfae80f2 10605
c19d1205
ZW
10606/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
10607 personality routine data. Returns zero, or the index table value for
10608 and inline entry. */
10609
10610static valueT
10611create_unwind_entry (int have_data)
bfae80f2 10612{
c19d1205
ZW
10613 int size;
10614 addressT where;
10615 char *ptr;
10616 /* The current word of data. */
10617 valueT data;
10618 /* The number of bytes left in this word. */
10619 int n;
bfae80f2 10620
c19d1205 10621 finish_unwind_opcodes ();
bfae80f2 10622
c19d1205
ZW
10623 /* Remember the current text section. */
10624 unwind.saved_seg = now_seg;
10625 unwind.saved_subseg = now_subseg;
bfae80f2 10626
c19d1205 10627 start_unwind_section (now_seg, 0);
bfae80f2 10628
c19d1205 10629 if (unwind.personality_routine == NULL)
bfae80f2 10630 {
c19d1205
ZW
10631 if (unwind.personality_index == -2)
10632 {
10633 if (have_data)
10634 as_bad (_("handerdata in cantunwind frame"));
10635 return 1; /* EXIDX_CANTUNWIND. */
10636 }
bfae80f2 10637
c19d1205
ZW
10638 /* Use a default personality routine if none is specified. */
10639 if (unwind.personality_index == -1)
10640 {
10641 if (unwind.opcode_count > 3)
10642 unwind.personality_index = 1;
10643 else
10644 unwind.personality_index = 0;
10645 }
bfae80f2 10646
c19d1205
ZW
10647 /* Space for the personality routine entry. */
10648 if (unwind.personality_index == 0)
10649 {
10650 if (unwind.opcode_count > 3)
10651 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 10652
c19d1205
ZW
10653 if (!have_data)
10654 {
10655 /* All the data is inline in the index table. */
10656 data = 0x80;
10657 n = 3;
10658 while (unwind.opcode_count > 0)
10659 {
10660 unwind.opcode_count--;
10661 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10662 n--;
10663 }
bfae80f2 10664
c19d1205
ZW
10665 /* Pad with "finish" opcodes. */
10666 while (n--)
10667 data = (data << 8) | 0xb0;
bfae80f2 10668
c19d1205
ZW
10669 return data;
10670 }
10671 size = 0;
10672 }
10673 else
10674 /* We get two opcodes "free" in the first word. */
10675 size = unwind.opcode_count - 2;
10676 }
10677 else
10678 /* An extra byte is required for the opcode count. */
10679 size = unwind.opcode_count + 1;
bfae80f2 10680
c19d1205
ZW
10681 size = (size + 3) >> 2;
10682 if (size > 0xff)
10683 as_bad (_("too many unwind opcodes"));
bfae80f2 10684
c19d1205
ZW
10685 frag_align (2, 0, 0);
10686 record_alignment (now_seg, 2);
10687 unwind.table_entry = expr_build_dot ();
10688
10689 /* Allocate the table entry. */
10690 ptr = frag_more ((size << 2) + 4);
10691 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 10692
c19d1205 10693 switch (unwind.personality_index)
bfae80f2 10694 {
c19d1205
ZW
10695 case -1:
10696 /* ??? Should this be a PLT generating relocation? */
10697 /* Custom personality routine. */
10698 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
10699 BFD_RELOC_ARM_PREL31);
bfae80f2 10700
c19d1205
ZW
10701 where += 4;
10702 ptr += 4;
bfae80f2 10703
c19d1205
ZW
10704 /* Set the first byte to the number of additional words. */
10705 data = size - 1;
10706 n = 3;
10707 break;
bfae80f2 10708
c19d1205
ZW
10709 /* ABI defined personality routines. */
10710 case 0:
10711 /* Three opcodes bytes are packed into the first word. */
10712 data = 0x80;
10713 n = 3;
10714 break;
bfae80f2 10715
c19d1205
ZW
10716 case 1:
10717 case 2:
10718 /* The size and first two opcode bytes go in the first word. */
10719 data = ((0x80 + unwind.personality_index) << 8) | size;
10720 n = 2;
10721 break;
bfae80f2 10722
c19d1205
ZW
10723 default:
10724 /* Should never happen. */
10725 abort ();
10726 }
bfae80f2 10727
c19d1205
ZW
10728 /* Pack the opcodes into words (MSB first), reversing the list at the same
10729 time. */
10730 while (unwind.opcode_count > 0)
10731 {
10732 if (n == 0)
10733 {
10734 md_number_to_chars (ptr, data, 4);
10735 ptr += 4;
10736 n = 4;
10737 data = 0;
10738 }
10739 unwind.opcode_count--;
10740 n--;
10741 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10742 }
10743
10744 /* Finish off the last word. */
10745 if (n < 4)
10746 {
10747 /* Pad with "finish" opcodes. */
10748 while (n--)
10749 data = (data << 8) | 0xb0;
10750
10751 md_number_to_chars (ptr, data, 4);
10752 }
10753
10754 if (!have_data)
10755 {
10756 /* Add an empty descriptor if there is no user-specified data. */
10757 ptr = frag_more (4);
10758 md_number_to_chars (ptr, 0, 4);
10759 }
10760
10761 return 0;
bfae80f2
RE
10762}
10763
c19d1205
ZW
10764/* Convert REGNAME to a DWARF-2 register number. */
10765
10766int
10767tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 10768{
c19d1205
ZW
10769 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
10770
10771 if (reg == FAIL)
10772 return -1;
10773
10774 return reg;
bfae80f2
RE
10775}
10776
c19d1205
ZW
10777/* Initialize the DWARF-2 unwind information for this procedure. */
10778
10779void
10780tc_arm_frame_initial_instructions (void)
bfae80f2 10781{
c19d1205 10782 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 10783}
c19d1205 10784#endif /* OBJ_ELF */
bfae80f2 10785
bfae80f2 10786
c19d1205 10787/* MD interface: Symbol and relocation handling. */
bfae80f2 10788
2fc8bdac
ZW
10789/* Return the address within the segment that a PC-relative fixup is
10790 relative to. For ARM, PC-relative fixups applied to instructions
10791 are generally relative to the location of the fixup plus 8 bytes.
10792 Thumb branches are offset by 4, and Thumb loads relative to PC
10793 require special handling. */
bfae80f2 10794
c19d1205 10795long
2fc8bdac 10796md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 10797{
2fc8bdac
ZW
10798 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
10799
10800 /* If this is pc-relative and we are going to emit a relocation
10801 then we just want to put out any pipeline compensation that the linker
10802 will need. Otherwise we want to use the calculated base. */
10803 if (fixP->fx_pcrel
10804 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10805 || arm_force_relocation (fixP)))
10806 base = 0;
bfae80f2 10807
c19d1205 10808 switch (fixP->fx_r_type)
bfae80f2 10809 {
2fc8bdac
ZW
10810 /* PC relative addressing on the Thumb is slightly odd as the
10811 bottom two bits of the PC are forced to zero for the
10812 calculation. This happens *after* application of the
10813 pipeline offset. However, Thumb adrl already adjusts for
10814 this, so we need not do it again. */
c19d1205 10815 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 10816 return base & ~3;
c19d1205
ZW
10817
10818 case BFD_RELOC_ARM_THUMB_OFFSET:
10819 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 10820 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 10821 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 10822 return (base + 4) & ~3;
c19d1205 10823
2fc8bdac
ZW
10824 /* Thumb branches are simply offset by +4. */
10825 case BFD_RELOC_THUMB_PCREL_BRANCH7:
10826 case BFD_RELOC_THUMB_PCREL_BRANCH9:
10827 case BFD_RELOC_THUMB_PCREL_BRANCH12:
10828 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10829 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10830 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10831 case BFD_RELOC_THUMB_PCREL_BLX:
10832 return base + 4;
bfae80f2 10833
2fc8bdac
ZW
10834 /* ARM mode branches are offset by +8. However, the Windows CE
10835 loader expects the relocation not to take this into account. */
10836 case BFD_RELOC_ARM_PCREL_BRANCH:
10837 case BFD_RELOC_ARM_PCREL_BLX:
10838 case BFD_RELOC_ARM_PLT32:
c19d1205 10839#ifdef TE_WINCE
2fc8bdac 10840 return base;
c19d1205 10841#else
2fc8bdac 10842 return base + 8;
c19d1205 10843#endif
2fc8bdac
ZW
10844
10845 /* ARM mode loads relative to PC are also offset by +8. Unlike
10846 branches, the Windows CE loader *does* expect the relocation
10847 to take this into account. */
10848 case BFD_RELOC_ARM_OFFSET_IMM:
10849 case BFD_RELOC_ARM_OFFSET_IMM8:
10850 case BFD_RELOC_ARM_HWLITERAL:
10851 case BFD_RELOC_ARM_LITERAL:
10852 case BFD_RELOC_ARM_CP_OFF_IMM:
10853 return base + 8;
10854
10855
10856 /* Other PC-relative relocations are un-offset. */
10857 default:
10858 return base;
10859 }
bfae80f2
RE
10860}
10861
c19d1205
ZW
10862/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
10863 Otherwise we have no need to default values of symbols. */
10864
10865symbolS *
10866md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 10867{
c19d1205
ZW
10868#ifdef OBJ_ELF
10869 if (name[0] == '_' && name[1] == 'G'
10870 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
10871 {
10872 if (!GOT_symbol)
10873 {
10874 if (symbol_find (name))
10875 as_bad ("GOT already in the symbol table");
bfae80f2 10876
c19d1205
ZW
10877 GOT_symbol = symbol_new (name, undefined_section,
10878 (valueT) 0, & zero_address_frag);
10879 }
bfae80f2 10880
c19d1205 10881 return GOT_symbol;
bfae80f2 10882 }
c19d1205 10883#endif
bfae80f2 10884
c19d1205 10885 return 0;
bfae80f2
RE
10886}
10887
55cf6793 10888/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
10889 computed as two separate immediate values, added together. We
10890 already know that this value cannot be computed by just one ARM
10891 instruction. */
10892
10893static unsigned int
10894validate_immediate_twopart (unsigned int val,
10895 unsigned int * highpart)
bfae80f2 10896{
c19d1205
ZW
10897 unsigned int a;
10898 unsigned int i;
bfae80f2 10899
c19d1205
ZW
10900 for (i = 0; i < 32; i += 2)
10901 if (((a = rotate_left (val, i)) & 0xff) != 0)
10902 {
10903 if (a & 0xff00)
10904 {
10905 if (a & ~ 0xffff)
10906 continue;
10907 * highpart = (a >> 8) | ((i + 24) << 7);
10908 }
10909 else if (a & 0xff0000)
10910 {
10911 if (a & 0xff000000)
10912 continue;
10913 * highpart = (a >> 16) | ((i + 16) << 7);
10914 }
10915 else
10916 {
10917 assert (a & 0xff000000);
10918 * highpart = (a >> 24) | ((i + 8) << 7);
10919 }
bfae80f2 10920
c19d1205
ZW
10921 return (a & 0xff) | (i << 7);
10922 }
bfae80f2 10923
c19d1205 10924 return FAIL;
bfae80f2
RE
10925}
10926
c19d1205
ZW
10927static int
10928validate_offset_imm (unsigned int val, int hwse)
10929{
10930 if ((hwse && val > 255) || val > 4095)
10931 return FAIL;
10932 return val;
10933}
bfae80f2 10934
55cf6793 10935/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
10936 negative immediate constant by altering the instruction. A bit of
10937 a hack really.
10938 MOV <-> MVN
10939 AND <-> BIC
10940 ADC <-> SBC
10941 by inverting the second operand, and
10942 ADD <-> SUB
10943 CMP <-> CMN
10944 by negating the second operand. */
bfae80f2 10945
c19d1205
ZW
10946static int
10947negate_data_op (unsigned long * instruction,
10948 unsigned long value)
bfae80f2 10949{
c19d1205
ZW
10950 int op, new_inst;
10951 unsigned long negated, inverted;
bfae80f2 10952
c19d1205
ZW
10953 negated = encode_arm_immediate (-value);
10954 inverted = encode_arm_immediate (~value);
bfae80f2 10955
c19d1205
ZW
10956 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10957 switch (op)
bfae80f2 10958 {
c19d1205
ZW
10959 /* First negates. */
10960 case OPCODE_SUB: /* ADD <-> SUB */
10961 new_inst = OPCODE_ADD;
10962 value = negated;
10963 break;
bfae80f2 10964
c19d1205
ZW
10965 case OPCODE_ADD:
10966 new_inst = OPCODE_SUB;
10967 value = negated;
10968 break;
bfae80f2 10969
c19d1205
ZW
10970 case OPCODE_CMP: /* CMP <-> CMN */
10971 new_inst = OPCODE_CMN;
10972 value = negated;
10973 break;
bfae80f2 10974
c19d1205
ZW
10975 case OPCODE_CMN:
10976 new_inst = OPCODE_CMP;
10977 value = negated;
10978 break;
bfae80f2 10979
c19d1205
ZW
10980 /* Now Inverted ops. */
10981 case OPCODE_MOV: /* MOV <-> MVN */
10982 new_inst = OPCODE_MVN;
10983 value = inverted;
10984 break;
bfae80f2 10985
c19d1205
ZW
10986 case OPCODE_MVN:
10987 new_inst = OPCODE_MOV;
10988 value = inverted;
10989 break;
bfae80f2 10990
c19d1205
ZW
10991 case OPCODE_AND: /* AND <-> BIC */
10992 new_inst = OPCODE_BIC;
10993 value = inverted;
10994 break;
bfae80f2 10995
c19d1205
ZW
10996 case OPCODE_BIC:
10997 new_inst = OPCODE_AND;
10998 value = inverted;
10999 break;
bfae80f2 11000
c19d1205
ZW
11001 case OPCODE_ADC: /* ADC <-> SBC */
11002 new_inst = OPCODE_SBC;
11003 value = inverted;
11004 break;
bfae80f2 11005
c19d1205
ZW
11006 case OPCODE_SBC:
11007 new_inst = OPCODE_ADC;
11008 value = inverted;
11009 break;
bfae80f2 11010
c19d1205
ZW
11011 /* We cannot do anything. */
11012 default:
11013 return FAIL;
b99bd4ef
NC
11014 }
11015
c19d1205
ZW
11016 if (value == (unsigned) FAIL)
11017 return FAIL;
11018
11019 *instruction &= OPCODE_MASK;
11020 *instruction |= new_inst << DATA_OP_SHIFT;
11021 return value;
b99bd4ef
NC
11022}
11023
8f06b2d8
PB
11024/* Read a 32-bit thumb instruction from buf. */
11025static unsigned long
11026get_thumb32_insn (char * buf)
11027{
11028 unsigned long insn;
11029 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
11030 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11031
11032 return insn;
11033}
11034
c19d1205 11035void
55cf6793 11036md_apply_fix (fixS * fixP,
c19d1205
ZW
11037 valueT * valP,
11038 segT seg)
11039{
11040 offsetT value = * valP;
11041 offsetT newval;
11042 unsigned int newimm;
11043 unsigned long temp;
11044 int sign;
11045 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 11046
c19d1205 11047 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 11048
c19d1205
ZW
11049 /* Note whether this will delete the relocation. */
11050 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
11051 fixP->fx_done = 1;
b99bd4ef 11052
adbaf948
ZW
11053 /* On a 64-bit host, silently truncate 'value' to 32 bits for
11054 consistency with the behavior on 32-bit hosts. Remember value
11055 for emit_reloc. */
11056 value &= 0xffffffff;
11057 value ^= 0x80000000;
11058 value -= 0x80000000;
11059
11060 *valP = value;
c19d1205 11061 fixP->fx_addnumber = value;
b99bd4ef 11062
adbaf948
ZW
11063 /* Same treatment for fixP->fx_offset. */
11064 fixP->fx_offset &= 0xffffffff;
11065 fixP->fx_offset ^= 0x80000000;
11066 fixP->fx_offset -= 0x80000000;
11067
c19d1205 11068 switch (fixP->fx_r_type)
b99bd4ef 11069 {
c19d1205
ZW
11070 case BFD_RELOC_NONE:
11071 /* This will need to go in the object file. */
11072 fixP->fx_done = 0;
11073 break;
b99bd4ef 11074
c19d1205
ZW
11075 case BFD_RELOC_ARM_IMMEDIATE:
11076 /* We claim that this fixup has been processed here,
11077 even if in fact we generate an error because we do
11078 not have a reloc for it, so tc_gen_reloc will reject it. */
11079 fixP->fx_done = 1;
b99bd4ef 11080
c19d1205
ZW
11081 if (fixP->fx_addsy
11082 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 11083 {
c19d1205
ZW
11084 as_bad_where (fixP->fx_file, fixP->fx_line,
11085 _("undefined symbol %s used as an immediate value"),
11086 S_GET_NAME (fixP->fx_addsy));
11087 break;
b99bd4ef
NC
11088 }
11089
c19d1205
ZW
11090 newimm = encode_arm_immediate (value);
11091 temp = md_chars_to_number (buf, INSN_SIZE);
11092
11093 /* If the instruction will fail, see if we can fix things up by
11094 changing the opcode. */
11095 if (newimm == (unsigned int) FAIL
11096 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 11097 {
c19d1205
ZW
11098 as_bad_where (fixP->fx_file, fixP->fx_line,
11099 _("invalid constant (%lx) after fixup"),
11100 (unsigned long) value);
11101 break;
b99bd4ef 11102 }
b99bd4ef 11103
c19d1205
ZW
11104 newimm |= (temp & 0xfffff000);
11105 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11106 break;
b99bd4ef 11107
c19d1205
ZW
11108 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11109 {
11110 unsigned int highpart = 0;
11111 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 11112
c19d1205
ZW
11113 newimm = encode_arm_immediate (value);
11114 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 11115
c19d1205
ZW
11116 /* If the instruction will fail, see if we can fix things up by
11117 changing the opcode. */
11118 if (newimm == (unsigned int) FAIL
11119 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
11120 {
11121 /* No ? OK - try using two ADD instructions to generate
11122 the value. */
11123 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 11124
c19d1205
ZW
11125 /* Yes - then make sure that the second instruction is
11126 also an add. */
11127 if (newimm != (unsigned int) FAIL)
11128 newinsn = temp;
11129 /* Still No ? Try using a negated value. */
11130 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
11131 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
11132 /* Otherwise - give up. */
11133 else
11134 {
11135 as_bad_where (fixP->fx_file, fixP->fx_line,
11136 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
11137 (long) value);
11138 break;
11139 }
b99bd4ef 11140
c19d1205
ZW
11141 /* Replace the first operand in the 2nd instruction (which
11142 is the PC) with the destination register. We have
11143 already added in the PC in the first instruction and we
11144 do not want to do it again. */
11145 newinsn &= ~ 0xf0000;
11146 newinsn |= ((newinsn & 0x0f000) << 4);
11147 }
b99bd4ef 11148
c19d1205
ZW
11149 newimm |= (temp & 0xfffff000);
11150 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 11151
c19d1205
ZW
11152 highpart |= (newinsn & 0xfffff000);
11153 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
11154 }
11155 break;
b99bd4ef 11156
c19d1205
ZW
11157 case BFD_RELOC_ARM_OFFSET_IMM:
11158 case BFD_RELOC_ARM_LITERAL:
11159 sign = value >= 0;
b99bd4ef 11160
c19d1205
ZW
11161 if (value < 0)
11162 value = - value;
b99bd4ef 11163
c19d1205 11164 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 11165 {
c19d1205
ZW
11166 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
11167 as_bad_where (fixP->fx_file, fixP->fx_line,
11168 _("invalid literal constant: pool needs to be closer"));
11169 else
11170 as_bad_where (fixP->fx_file, fixP->fx_line,
11171 _("bad immediate value for offset (%ld)"),
11172 (long) value);
11173 break;
f03698e6
RE
11174 }
11175
c19d1205
ZW
11176 newval = md_chars_to_number (buf, INSN_SIZE);
11177 newval &= 0xff7ff000;
11178 newval |= value | (sign ? INDEX_UP : 0);
11179 md_number_to_chars (buf, newval, INSN_SIZE);
11180 break;
b99bd4ef 11181
c19d1205
ZW
11182 case BFD_RELOC_ARM_OFFSET_IMM8:
11183 case BFD_RELOC_ARM_HWLITERAL:
11184 sign = value >= 0;
b99bd4ef 11185
c19d1205
ZW
11186 if (value < 0)
11187 value = - value;
b99bd4ef 11188
c19d1205 11189 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 11190 {
c19d1205
ZW
11191 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
11192 as_bad_where (fixP->fx_file, fixP->fx_line,
11193 _("invalid literal constant: pool needs to be closer"));
11194 else
11195 as_bad (_("bad immediate value for half-word offset (%ld)"),
11196 (long) value);
11197 break;
b99bd4ef
NC
11198 }
11199
c19d1205
ZW
11200 newval = md_chars_to_number (buf, INSN_SIZE);
11201 newval &= 0xff7ff0f0;
11202 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
11203 md_number_to_chars (buf, newval, INSN_SIZE);
11204 break;
b99bd4ef 11205
c19d1205
ZW
11206 case BFD_RELOC_ARM_T32_OFFSET_U8:
11207 if (value < 0 || value > 1020 || value % 4 != 0)
11208 as_bad_where (fixP->fx_file, fixP->fx_line,
11209 _("bad immediate value for offset (%ld)"), (long) value);
11210 value /= 4;
b99bd4ef 11211
c19d1205 11212 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
11213 newval |= value;
11214 md_number_to_chars (buf+2, newval, THUMB_SIZE);
11215 break;
b99bd4ef 11216
c19d1205
ZW
11217 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11218 /* This is a complicated relocation used for all varieties of Thumb32
11219 load/store instruction with immediate offset:
11220
11221 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
11222 *4, optional writeback(W)
11223 (doubleword load/store)
11224
11225 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
11226 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
11227 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
11228 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
11229 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
11230
11231 Uppercase letters indicate bits that are already encoded at
11232 this point. Lowercase letters are our problem. For the
11233 second block of instructions, the secondary opcode nybble
11234 (bits 8..11) is present, and bit 23 is zero, even if this is
11235 a PC-relative operation. */
11236 newval = md_chars_to_number (buf, THUMB_SIZE);
11237 newval <<= 16;
11238 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 11239
c19d1205 11240 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 11241 {
c19d1205
ZW
11242 /* Doubleword load/store: 8-bit offset, scaled by 4. */
11243 if (value >= 0)
11244 newval |= (1 << 23);
11245 else
11246 value = -value;
11247 if (value % 4 != 0)
11248 {
11249 as_bad_where (fixP->fx_file, fixP->fx_line,
11250 _("offset not a multiple of 4"));
11251 break;
11252 }
11253 value /= 4;
11254 if (value >= 0xff)
11255 {
11256 as_bad_where (fixP->fx_file, fixP->fx_line,
11257 _("offset out of range"));
11258 break;
11259 }
11260 newval &= ~0xff;
b99bd4ef 11261 }
c19d1205 11262 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 11263 {
c19d1205
ZW
11264 /* PC-relative, 12-bit offset. */
11265 if (value >= 0)
11266 newval |= (1 << 23);
11267 else
11268 value = -value;
11269 if (value >= 0xfff)
11270 {
11271 as_bad_where (fixP->fx_file, fixP->fx_line,
11272 _("offset out of range"));
11273 break;
11274 }
11275 newval &= ~0xfff;
b99bd4ef 11276 }
c19d1205 11277 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 11278 {
c19d1205
ZW
11279 /* Writeback: 8-bit, +/- offset. */
11280 if (value >= 0)
11281 newval |= (1 << 9);
11282 else
11283 value = -value;
11284 if (value >= 0xff)
11285 {
11286 as_bad_where (fixP->fx_file, fixP->fx_line,
11287 _("offset out of range"));
11288 break;
11289 }
11290 newval &= ~0xff;
b99bd4ef 11291 }
c19d1205 11292 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 11293 {
c19d1205
ZW
11294 /* T-instruction: positive 8-bit offset. */
11295 if (value < 0 || value >= 0xff)
b99bd4ef 11296 {
c19d1205
ZW
11297 as_bad_where (fixP->fx_file, fixP->fx_line,
11298 _("offset out of range"));
11299 break;
b99bd4ef 11300 }
c19d1205
ZW
11301 newval &= ~0xff;
11302 newval |= value;
b99bd4ef
NC
11303 }
11304 else
b99bd4ef 11305 {
c19d1205
ZW
11306 /* Positive 12-bit or negative 8-bit offset. */
11307 int limit;
11308 if (value >= 0)
b99bd4ef 11309 {
c19d1205
ZW
11310 newval |= (1 << 23);
11311 limit = 0xfff;
11312 }
11313 else
11314 {
11315 value = -value;
11316 limit = 0xff;
11317 }
11318 if (value > limit)
11319 {
11320 as_bad_where (fixP->fx_file, fixP->fx_line,
11321 _("offset out of range"));
11322 break;
b99bd4ef 11323 }
c19d1205 11324 newval &= ~limit;
b99bd4ef 11325 }
b99bd4ef 11326
c19d1205
ZW
11327 newval |= value;
11328 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
11329 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
11330 break;
404ff6b5 11331
c19d1205
ZW
11332 case BFD_RELOC_ARM_SHIFT_IMM:
11333 newval = md_chars_to_number (buf, INSN_SIZE);
11334 if (((unsigned long) value) > 32
11335 || (value == 32
11336 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
11337 {
11338 as_bad_where (fixP->fx_file, fixP->fx_line,
11339 _("shift expression is too large"));
11340 break;
11341 }
404ff6b5 11342
c19d1205
ZW
11343 if (value == 0)
11344 /* Shifts of zero must be done as lsl. */
11345 newval &= ~0x60;
11346 else if (value == 32)
11347 value = 0;
11348 newval &= 0xfffff07f;
11349 newval |= (value & 0x1f) << 7;
11350 md_number_to_chars (buf, newval, INSN_SIZE);
11351 break;
404ff6b5 11352
c19d1205 11353 case BFD_RELOC_ARM_T32_IMMEDIATE:
92e90b6e 11354 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 11355 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
11356 /* We claim that this fixup has been processed here,
11357 even if in fact we generate an error because we do
11358 not have a reloc for it, so tc_gen_reloc will reject it. */
11359 fixP->fx_done = 1;
404ff6b5 11360
c19d1205
ZW
11361 if (fixP->fx_addsy
11362 && ! S_IS_DEFINED (fixP->fx_addsy))
11363 {
11364 as_bad_where (fixP->fx_file, fixP->fx_line,
11365 _("undefined symbol %s used as an immediate value"),
11366 S_GET_NAME (fixP->fx_addsy));
11367 break;
11368 }
404ff6b5 11369
c19d1205
ZW
11370 newval = md_chars_to_number (buf, THUMB_SIZE);
11371 newval <<= 16;
11372 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 11373
e9f89963
PB
11374 /* FUTURE: Implement analogue of negate_data_op for T32. */
11375 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
11376 newimm = encode_thumb32_immediate (value);
11377 else
92e90b6e 11378 {
e9f89963
PB
11379 /* 12 bit immediate for addw/subw. */
11380 if (value < 0)
11381 {
11382 value = -value;
11383 newval ^= 0x00a00000;
11384 }
92e90b6e
PB
11385 if (value > 0xfff)
11386 newimm = (unsigned int) FAIL;
11387 else
11388 newimm = value;
11389 }
cc8a6dd0 11390
c19d1205 11391 if (newimm == (unsigned int)FAIL)
3631a3c8 11392 {
c19d1205
ZW
11393 as_bad_where (fixP->fx_file, fixP->fx_line,
11394 _("invalid constant (%lx) after fixup"),
11395 (unsigned long) value);
11396 break;
3631a3c8
NC
11397 }
11398
c19d1205
ZW
11399 newval |= (newimm & 0x800) << 15;
11400 newval |= (newimm & 0x700) << 4;
11401 newval |= (newimm & 0x0ff);
cc8a6dd0 11402
c19d1205
ZW
11403 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
11404 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
11405 break;
a737bd4d 11406
3eb17e6b 11407 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
11408 if (((unsigned long) value) > 0xffff)
11409 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 11410 _("invalid smc expression"));
2fc8bdac 11411 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11412 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
11413 md_number_to_chars (buf, newval, INSN_SIZE);
11414 break;
a737bd4d 11415
c19d1205 11416 case BFD_RELOC_ARM_SWI:
adbaf948 11417 if (fixP->tc_fix_data != 0)
c19d1205
ZW
11418 {
11419 if (((unsigned long) value) > 0xff)
11420 as_bad_where (fixP->fx_file, fixP->fx_line,
11421 _("invalid swi expression"));
2fc8bdac 11422 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
11423 newval |= value;
11424 md_number_to_chars (buf, newval, THUMB_SIZE);
11425 }
11426 else
11427 {
11428 if (((unsigned long) value) > 0x00ffffff)
11429 as_bad_where (fixP->fx_file, fixP->fx_line,
11430 _("invalid swi expression"));
2fc8bdac 11431 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11432 newval |= value;
11433 md_number_to_chars (buf, newval, INSN_SIZE);
11434 }
11435 break;
a737bd4d 11436
c19d1205
ZW
11437 case BFD_RELOC_ARM_MULTI:
11438 if (((unsigned long) value) > 0xffff)
11439 as_bad_where (fixP->fx_file, fixP->fx_line,
11440 _("invalid expression in load/store multiple"));
11441 newval = value | md_chars_to_number (buf, INSN_SIZE);
11442 md_number_to_chars (buf, newval, INSN_SIZE);
11443 break;
a737bd4d 11444
c19d1205 11445 case BFD_RELOC_ARM_PCREL_BRANCH:
c19d1205 11446#ifdef OBJ_ELF
2fc8bdac 11447 case BFD_RELOC_ARM_PLT32:
c19d1205 11448#endif
a737bd4d 11449
c19d1205 11450 /* We are going to store value (shifted right by two) in the
2fc8bdac
ZW
11451 instruction, in a 24 bit, signed field. Bits 0 and 1 must be
11452 clear, and bits 26 through 32 either all clear or all set. */
11453 if (value & 0x00000003)
c19d1205 11454 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
11455 _("misaligned branch destination"));
11456 if ((value & (offsetT)0xfe000000) != (offsetT)0
11457 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11458 as_bad_where (fixP->fx_file, fixP->fx_line,
11459 _("branch out of range"));
a737bd4d 11460
2fc8bdac 11461 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11462 {
2fc8bdac
ZW
11463 newval = md_chars_to_number (buf, INSN_SIZE);
11464 newval |= (value >> 2) & 0x00ffffff;
11465 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 11466 }
c19d1205 11467 break;
a737bd4d 11468
c19d1205 11469 case BFD_RELOC_ARM_PCREL_BLX:
2fc8bdac
ZW
11470 /* BLX allows bit 1 to be set in the branch destination, since
11471 it targets a Thumb instruction which is only required to be
11472 aligned modulo 2. Other constraints are as for B/BL. */
11473 if (value & 0x00000001)
11474 as_bad_where (fixP->fx_file, fixP->fx_line,
11475 _("misaligned BLX destination"));
11476 if ((value & (offsetT)0xfe000000) != (offsetT)0
11477 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11478 as_bad_where (fixP->fx_file, fixP->fx_line,
11479 _("branch out of range"));
a737bd4d 11480
2fc8bdac
ZW
11481 if (fixP->fx_done || !seg->use_rela_p)
11482 {
11483 offsetT hbit;
11484 hbit = (value >> 1) & 1;
11485 value = (value >> 2) & 0x00ffffff;
a737bd4d 11486
2fc8bdac
ZW
11487 newval = md_chars_to_number (buf, INSN_SIZE);
11488 newval |= value | hbit << 24;
11489 md_number_to_chars (buf, newval, INSN_SIZE);
11490 }
c19d1205 11491 break;
a737bd4d 11492
c19d1205 11493 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
11494 /* CZB can only branch forward. */
11495 if (value & ~0x7e)
11496 as_bad_where (fixP->fx_file, fixP->fx_line,
11497 _("branch out of range"));
a737bd4d 11498
2fc8bdac
ZW
11499 if (fixP->fx_done || !seg->use_rela_p)
11500 {
11501 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205 11502 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
11503 md_number_to_chars (buf, newval, THUMB_SIZE);
11504 }
c19d1205 11505 break;
a737bd4d 11506
c19d1205 11507 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
11508 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
11509 as_bad_where (fixP->fx_file, fixP->fx_line,
11510 _("branch out of range"));
a737bd4d 11511
2fc8bdac
ZW
11512 if (fixP->fx_done || !seg->use_rela_p)
11513 {
11514 newval = md_chars_to_number (buf, THUMB_SIZE);
11515 newval |= (value & 0x1ff) >> 1;
11516 md_number_to_chars (buf, newval, THUMB_SIZE);
11517 }
c19d1205 11518 break;
a737bd4d 11519
c19d1205 11520 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
11521 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
11522 as_bad_where (fixP->fx_file, fixP->fx_line,
11523 _("branch out of range"));
a737bd4d 11524
2fc8bdac
ZW
11525 if (fixP->fx_done || !seg->use_rela_p)
11526 {
11527 newval = md_chars_to_number (buf, THUMB_SIZE);
11528 newval |= (value & 0xfff) >> 1;
11529 md_number_to_chars (buf, newval, THUMB_SIZE);
11530 }
c19d1205 11531 break;
a737bd4d 11532
c19d1205 11533 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
11534 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
11535 as_bad_where (fixP->fx_file, fixP->fx_line,
11536 _("conditional branch out of range"));
404ff6b5 11537
2fc8bdac
ZW
11538 if (fixP->fx_done || !seg->use_rela_p)
11539 {
11540 offsetT newval2;
11541 addressT S, J1, J2, lo, hi;
404ff6b5 11542
2fc8bdac
ZW
11543 S = (value & 0x00100000) >> 20;
11544 J2 = (value & 0x00080000) >> 19;
11545 J1 = (value & 0x00040000) >> 18;
11546 hi = (value & 0x0003f000) >> 12;
11547 lo = (value & 0x00000ffe) >> 1;
6c43fab6 11548
2fc8bdac
ZW
11549 newval = md_chars_to_number (buf, THUMB_SIZE);
11550 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11551 newval |= (S << 10) | hi;
11552 newval2 |= (J1 << 13) | (J2 << 11) | lo;
11553 md_number_to_chars (buf, newval, THUMB_SIZE);
11554 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11555 }
c19d1205 11556 break;
6c43fab6 11557
c19d1205
ZW
11558 case BFD_RELOC_THUMB_PCREL_BLX:
11559 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
11560 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
11561 as_bad_where (fixP->fx_file, fixP->fx_line,
11562 _("branch out of range"));
404ff6b5 11563
2fc8bdac
ZW
11564 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
11565 /* For a BLX instruction, make sure that the relocation is rounded up
11566 to a word boundary. This follows the semantics of the instruction
11567 which specifies that bit 1 of the target address will come from bit
11568 1 of the base address. */
11569 value = (value + 1) & ~ 1;
404ff6b5 11570
2fc8bdac 11571 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11572 {
2fc8bdac
ZW
11573 offsetT newval2;
11574
11575 newval = md_chars_to_number (buf, THUMB_SIZE);
11576 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11577 newval |= (value & 0x7fffff) >> 12;
11578 newval2 |= (value & 0xfff) >> 1;
11579 md_number_to_chars (buf, newval, THUMB_SIZE);
11580 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 11581 }
c19d1205 11582 break;
404ff6b5 11583
c19d1205 11584 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
11585 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
11586 as_bad_where (fixP->fx_file, fixP->fx_line,
11587 _("branch out of range"));
6c43fab6 11588
2fc8bdac
ZW
11589 if (fixP->fx_done || !seg->use_rela_p)
11590 {
11591 offsetT newval2;
11592 addressT S, I1, I2, lo, hi;
6c43fab6 11593
2fc8bdac
ZW
11594 S = (value & 0x01000000) >> 24;
11595 I1 = (value & 0x00800000) >> 23;
11596 I2 = (value & 0x00400000) >> 22;
11597 hi = (value & 0x003ff000) >> 12;
11598 lo = (value & 0x00000ffe) >> 1;
6c43fab6 11599
2fc8bdac
ZW
11600 I1 = !(I1 ^ S);
11601 I2 = !(I2 ^ S);
a737bd4d 11602
2fc8bdac
ZW
11603 newval = md_chars_to_number (buf, THUMB_SIZE);
11604 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11605 newval |= (S << 10) | hi;
11606 newval2 |= (I1 << 13) | (I2 << 11) | lo;
11607 md_number_to_chars (buf, newval, THUMB_SIZE);
11608 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11609 }
11610 break;
a737bd4d 11611
2fc8bdac
ZW
11612 case BFD_RELOC_8:
11613 if (fixP->fx_done || !seg->use_rela_p)
11614 md_number_to_chars (buf, value, 1);
c19d1205 11615 break;
a737bd4d 11616
c19d1205 11617 case BFD_RELOC_16:
2fc8bdac 11618 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11619 md_number_to_chars (buf, value, 2);
c19d1205 11620 break;
a737bd4d 11621
c19d1205
ZW
11622#ifdef OBJ_ELF
11623 case BFD_RELOC_ARM_TLS_GD32:
11624 case BFD_RELOC_ARM_TLS_LE32:
11625 case BFD_RELOC_ARM_TLS_IE32:
11626 case BFD_RELOC_ARM_TLS_LDM32:
11627 case BFD_RELOC_ARM_TLS_LDO32:
11628 S_SET_THREAD_LOCAL (fixP->fx_addsy);
11629 /* fall through */
6c43fab6 11630
c19d1205
ZW
11631 case BFD_RELOC_ARM_GOT32:
11632 case BFD_RELOC_ARM_GOTOFF:
11633 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
11634 if (fixP->fx_done || !seg->use_rela_p)
11635 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
11636 break;
11637#endif
6c43fab6 11638
c19d1205
ZW
11639 case BFD_RELOC_RVA:
11640 case BFD_RELOC_32:
11641 case BFD_RELOC_ARM_TARGET1:
11642 case BFD_RELOC_ARM_ROSEGREL32:
11643 case BFD_RELOC_ARM_SBREL32:
11644 case BFD_RELOC_32_PCREL:
2fc8bdac 11645 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11646 md_number_to_chars (buf, value, 4);
c19d1205 11647 break;
6c43fab6 11648
c19d1205
ZW
11649#ifdef OBJ_ELF
11650 case BFD_RELOC_ARM_PREL31:
2fc8bdac 11651 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
11652 {
11653 newval = md_chars_to_number (buf, 4) & 0x80000000;
11654 if ((value ^ (value >> 1)) & 0x40000000)
11655 {
11656 as_bad_where (fixP->fx_file, fixP->fx_line,
11657 _("rel31 relocation overflow"));
11658 }
11659 newval |= value & 0x7fffffff;
11660 md_number_to_chars (buf, newval, 4);
11661 }
11662 break;
c19d1205 11663#endif
a737bd4d 11664
c19d1205 11665 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 11666 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
11667 if (value < -1023 || value > 1023 || (value & 3))
11668 as_bad_where (fixP->fx_file, fixP->fx_line,
11669 _("co-processor offset out of range"));
11670 cp_off_common:
11671 sign = value >= 0;
11672 if (value < 0)
11673 value = -value;
8f06b2d8
PB
11674 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
11675 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
11676 newval = md_chars_to_number (buf, INSN_SIZE);
11677 else
11678 newval = get_thumb32_insn (buf);
11679 newval &= 0xff7fff00;
c19d1205
ZW
11680 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
11681 if (value == 0)
11682 newval &= ~WRITE_BACK;
8f06b2d8
PB
11683 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
11684 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
11685 md_number_to_chars (buf, newval, INSN_SIZE);
11686 else
11687 put_thumb32_insn (buf, newval);
c19d1205 11688 break;
a737bd4d 11689
c19d1205 11690 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 11691 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
11692 if (value < -255 || value > 255)
11693 as_bad_where (fixP->fx_file, fixP->fx_line,
11694 _("co-processor offset out of range"));
11695 goto cp_off_common;
6c43fab6 11696
c19d1205
ZW
11697 case BFD_RELOC_ARM_THUMB_OFFSET:
11698 newval = md_chars_to_number (buf, THUMB_SIZE);
11699 /* Exactly what ranges, and where the offset is inserted depends
11700 on the type of instruction, we can establish this from the
11701 top 4 bits. */
11702 switch (newval >> 12)
11703 {
11704 case 4: /* PC load. */
11705 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
11706 forced to zero for these loads; md_pcrel_from has already
11707 compensated for this. */
11708 if (value & 3)
11709 as_bad_where (fixP->fx_file, fixP->fx_line,
11710 _("invalid offset, target not word aligned (0x%08lX)"),
11711 (((unsigned int) fixP->fx_frag->fr_address
11712 + (unsigned int) fixP->fx_where) & ~3) + value);
a737bd4d 11713
c19d1205
ZW
11714 if (value & ~0x3fc)
11715 as_bad_where (fixP->fx_file, fixP->fx_line,
11716 _("invalid offset, value too big (0x%08lX)"),
11717 (long) value);
a737bd4d 11718
c19d1205
ZW
11719 newval |= value >> 2;
11720 break;
a737bd4d 11721
c19d1205
ZW
11722 case 9: /* SP load/store. */
11723 if (value & ~0x3fc)
11724 as_bad_where (fixP->fx_file, fixP->fx_line,
11725 _("invalid offset, value too big (0x%08lX)"),
11726 (long) value);
11727 newval |= value >> 2;
11728 break;
6c43fab6 11729
c19d1205
ZW
11730 case 6: /* Word load/store. */
11731 if (value & ~0x7c)
11732 as_bad_where (fixP->fx_file, fixP->fx_line,
11733 _("invalid offset, value too big (0x%08lX)"),
11734 (long) value);
11735 newval |= value << 4; /* 6 - 2. */
11736 break;
a737bd4d 11737
c19d1205
ZW
11738 case 7: /* Byte load/store. */
11739 if (value & ~0x1f)
11740 as_bad_where (fixP->fx_file, fixP->fx_line,
11741 _("invalid offset, value too big (0x%08lX)"),
11742 (long) value);
11743 newval |= value << 6;
11744 break;
a737bd4d 11745
c19d1205
ZW
11746 case 8: /* Halfword load/store. */
11747 if (value & ~0x3e)
11748 as_bad_where (fixP->fx_file, fixP->fx_line,
11749 _("invalid offset, value too big (0x%08lX)"),
11750 (long) value);
11751 newval |= value << 5; /* 6 - 1. */
11752 break;
a737bd4d 11753
c19d1205
ZW
11754 default:
11755 as_bad_where (fixP->fx_file, fixP->fx_line,
11756 "Unable to process relocation for thumb opcode: %lx",
11757 (unsigned long) newval);
11758 break;
11759 }
11760 md_number_to_chars (buf, newval, THUMB_SIZE);
11761 break;
a737bd4d 11762
c19d1205
ZW
11763 case BFD_RELOC_ARM_THUMB_ADD:
11764 /* This is a complicated relocation, since we use it for all of
11765 the following immediate relocations:
a737bd4d 11766
c19d1205
ZW
11767 3bit ADD/SUB
11768 8bit ADD/SUB
11769 9bit ADD/SUB SP word-aligned
11770 10bit ADD PC/SP word-aligned
a737bd4d 11771
c19d1205
ZW
11772 The type of instruction being processed is encoded in the
11773 instruction field:
a737bd4d 11774
c19d1205
ZW
11775 0x8000 SUB
11776 0x00F0 Rd
11777 0x000F Rs
11778 */
11779 newval = md_chars_to_number (buf, THUMB_SIZE);
11780 {
11781 int rd = (newval >> 4) & 0xf;
11782 int rs = newval & 0xf;
11783 int subtract = !!(newval & 0x8000);
a737bd4d 11784
c19d1205
ZW
11785 /* Check for HI regs, only very restricted cases allowed:
11786 Adjusting SP, and using PC or SP to get an address. */
11787 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
11788 || (rs > 7 && rs != REG_SP && rs != REG_PC))
11789 as_bad_where (fixP->fx_file, fixP->fx_line,
11790 _("invalid Hi register with immediate"));
a737bd4d 11791
c19d1205
ZW
11792 /* If value is negative, choose the opposite instruction. */
11793 if (value < 0)
11794 {
11795 value = -value;
11796 subtract = !subtract;
11797 if (value < 0)
11798 as_bad_where (fixP->fx_file, fixP->fx_line,
11799 _("immediate value out of range"));
11800 }
a737bd4d 11801
c19d1205
ZW
11802 if (rd == REG_SP)
11803 {
11804 if (value & ~0x1fc)
11805 as_bad_where (fixP->fx_file, fixP->fx_line,
11806 _("invalid immediate for stack address calculation"));
11807 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11808 newval |= value >> 2;
11809 }
11810 else if (rs == REG_PC || rs == REG_SP)
11811 {
11812 if (subtract || value & ~0x3fc)
11813 as_bad_where (fixP->fx_file, fixP->fx_line,
11814 _("invalid immediate for address calculation (value = 0x%08lX)"),
11815 (unsigned long) value);
11816 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11817 newval |= rd << 8;
11818 newval |= value >> 2;
11819 }
11820 else if (rs == rd)
11821 {
11822 if (value & ~0xff)
11823 as_bad_where (fixP->fx_file, fixP->fx_line,
11824 _("immediate value out of range"));
11825 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11826 newval |= (rd << 8) | value;
11827 }
11828 else
11829 {
11830 if (value & ~0x7)
11831 as_bad_where (fixP->fx_file, fixP->fx_line,
11832 _("immediate value out of range"));
11833 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11834 newval |= rd | (rs << 3) | (value << 6);
11835 }
11836 }
11837 md_number_to_chars (buf, newval, THUMB_SIZE);
11838 break;
a737bd4d 11839
c19d1205
ZW
11840 case BFD_RELOC_ARM_THUMB_IMM:
11841 newval = md_chars_to_number (buf, THUMB_SIZE);
11842 if (value < 0 || value > 255)
11843 as_bad_where (fixP->fx_file, fixP->fx_line,
11844 _("invalid immediate: %ld is too large"),
11845 (long) value);
11846 newval |= value;
11847 md_number_to_chars (buf, newval, THUMB_SIZE);
11848 break;
a737bd4d 11849
c19d1205
ZW
11850 case BFD_RELOC_ARM_THUMB_SHIFT:
11851 /* 5bit shift value (0..32). LSL cannot take 32. */
11852 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11853 temp = newval & 0xf800;
11854 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11855 as_bad_where (fixP->fx_file, fixP->fx_line,
11856 _("invalid shift value: %ld"), (long) value);
11857 /* Shifts of zero must be encoded as LSL. */
11858 if (value == 0)
11859 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11860 /* Shifts of 32 are encoded as zero. */
11861 else if (value == 32)
11862 value = 0;
11863 newval |= value << 6;
11864 md_number_to_chars (buf, newval, THUMB_SIZE);
11865 break;
a737bd4d 11866
c19d1205
ZW
11867 case BFD_RELOC_VTABLE_INHERIT:
11868 case BFD_RELOC_VTABLE_ENTRY:
11869 fixP->fx_done = 0;
11870 return;
6c43fab6 11871
c19d1205
ZW
11872 case BFD_RELOC_UNUSED:
11873 default:
11874 as_bad_where (fixP->fx_file, fixP->fx_line,
11875 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11876 }
6c43fab6
RE
11877}
11878
c19d1205
ZW
11879/* Translate internal representation of relocation info to BFD target
11880 format. */
a737bd4d 11881
c19d1205
ZW
11882arelent *
11883tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11884 fixS * fixp)
a737bd4d 11885{
c19d1205
ZW
11886 arelent * reloc;
11887 bfd_reloc_code_real_type code;
a737bd4d 11888
c19d1205 11889 reloc = xmalloc (sizeof (arelent));
a737bd4d 11890
c19d1205
ZW
11891 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11892 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11893 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 11894
2fc8bdac
ZW
11895 if (fixp->fx_pcrel)
11896 fixp->fx_offset = reloc->address;
c19d1205 11897 reloc->addend = fixp->fx_offset;
a737bd4d 11898
c19d1205 11899 switch (fixp->fx_r_type)
a737bd4d 11900 {
c19d1205
ZW
11901 case BFD_RELOC_8:
11902 if (fixp->fx_pcrel)
11903 {
11904 code = BFD_RELOC_8_PCREL;
11905 break;
11906 }
a737bd4d 11907
c19d1205
ZW
11908 case BFD_RELOC_16:
11909 if (fixp->fx_pcrel)
11910 {
11911 code = BFD_RELOC_16_PCREL;
11912 break;
11913 }
6c43fab6 11914
c19d1205
ZW
11915 case BFD_RELOC_32:
11916 if (fixp->fx_pcrel)
11917 {
11918 code = BFD_RELOC_32_PCREL;
11919 break;
11920 }
a737bd4d 11921
c19d1205
ZW
11922 case BFD_RELOC_NONE:
11923 case BFD_RELOC_ARM_PCREL_BRANCH:
11924 case BFD_RELOC_ARM_PCREL_BLX:
11925 case BFD_RELOC_RVA:
11926 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11927 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11928 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11929 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11930 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11931 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11932 case BFD_RELOC_THUMB_PCREL_BLX:
11933 case BFD_RELOC_VTABLE_ENTRY:
11934 case BFD_RELOC_VTABLE_INHERIT:
11935 code = fixp->fx_r_type;
11936 break;
a737bd4d 11937
c19d1205
ZW
11938 case BFD_RELOC_ARM_LITERAL:
11939 case BFD_RELOC_ARM_HWLITERAL:
11940 /* If this is called then the a literal has
11941 been referenced across a section boundary. */
11942 as_bad_where (fixp->fx_file, fixp->fx_line,
11943 _("literal referenced across section boundary"));
11944 return NULL;
a737bd4d 11945
c19d1205
ZW
11946#ifdef OBJ_ELF
11947 case BFD_RELOC_ARM_GOT32:
11948 case BFD_RELOC_ARM_GOTOFF:
11949 case BFD_RELOC_ARM_PLT32:
11950 case BFD_RELOC_ARM_TARGET1:
11951 case BFD_RELOC_ARM_ROSEGREL32:
11952 case BFD_RELOC_ARM_SBREL32:
11953 case BFD_RELOC_ARM_PREL31:
11954 case BFD_RELOC_ARM_TARGET2:
11955 case BFD_RELOC_ARM_TLS_LE32:
11956 case BFD_RELOC_ARM_TLS_LDO32:
11957 code = fixp->fx_r_type;
11958 break;
a737bd4d 11959
c19d1205
ZW
11960 case BFD_RELOC_ARM_TLS_GD32:
11961 case BFD_RELOC_ARM_TLS_IE32:
11962 case BFD_RELOC_ARM_TLS_LDM32:
11963 /* BFD will include the symbol's address in the addend.
11964 But we don't want that, so subtract it out again here. */
11965 if (!S_IS_COMMON (fixp->fx_addsy))
11966 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11967 code = fixp->fx_r_type;
11968 break;
11969#endif
a737bd4d 11970
c19d1205
ZW
11971 case BFD_RELOC_ARM_IMMEDIATE:
11972 as_bad_where (fixp->fx_file, fixp->fx_line,
11973 _("internal relocation (type: IMMEDIATE) not fixed up"));
11974 return NULL;
a737bd4d 11975
c19d1205
ZW
11976 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11977 as_bad_where (fixp->fx_file, fixp->fx_line,
11978 _("ADRL used for a symbol not defined in the same file"));
11979 return NULL;
a737bd4d 11980
c19d1205
ZW
11981 case BFD_RELOC_ARM_OFFSET_IMM:
11982 if (fixp->fx_addsy != NULL
11983 && !S_IS_DEFINED (fixp->fx_addsy)
11984 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 11985 {
c19d1205
ZW
11986 as_bad_where (fixp->fx_file, fixp->fx_line,
11987 _("undefined local label `%s'"),
11988 S_GET_NAME (fixp->fx_addsy));
11989 return NULL;
a737bd4d
NC
11990 }
11991
c19d1205
ZW
11992 as_bad_where (fixp->fx_file, fixp->fx_line,
11993 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11994 return NULL;
a737bd4d 11995
c19d1205
ZW
11996 default:
11997 {
11998 char * type;
6c43fab6 11999
c19d1205
ZW
12000 switch (fixp->fx_r_type)
12001 {
12002 case BFD_RELOC_NONE: type = "NONE"; break;
12003 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
12004 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 12005 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
12006 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
12007 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
12008 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 12009 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
12010 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
12011 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
12012 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
12013 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
12014 default: type = _("<unknown>"); break;
12015 }
12016 as_bad_where (fixp->fx_file, fixp->fx_line,
12017 _("cannot represent %s relocation in this object file format"),
12018 type);
12019 return NULL;
12020 }
a737bd4d 12021 }
6c43fab6 12022
c19d1205
ZW
12023#ifdef OBJ_ELF
12024 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
12025 && GOT_symbol
12026 && fixp->fx_addsy == GOT_symbol)
12027 {
12028 code = BFD_RELOC_ARM_GOTPC;
12029 reloc->addend = fixp->fx_offset = reloc->address;
12030 }
12031#endif
6c43fab6 12032
c19d1205 12033 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 12034
c19d1205
ZW
12035 if (reloc->howto == NULL)
12036 {
12037 as_bad_where (fixp->fx_file, fixp->fx_line,
12038 _("cannot represent %s relocation in this object file format"),
12039 bfd_get_reloc_code_name (code));
12040 return NULL;
12041 }
6c43fab6 12042
c19d1205
ZW
12043 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
12044 vtable entry to be used in the relocation's section offset. */
12045 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12046 reloc->address = fixp->fx_offset;
6c43fab6 12047
c19d1205 12048 return reloc;
6c43fab6
RE
12049}
12050
c19d1205 12051/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 12052
c19d1205
ZW
12053void
12054cons_fix_new_arm (fragS * frag,
12055 int where,
12056 int size,
12057 expressionS * exp)
6c43fab6 12058{
c19d1205
ZW
12059 bfd_reloc_code_real_type type;
12060 int pcrel = 0;
6c43fab6 12061
c19d1205
ZW
12062 /* Pick a reloc.
12063 FIXME: @@ Should look at CPU word size. */
12064 switch (size)
12065 {
12066 case 1:
12067 type = BFD_RELOC_8;
12068 break;
12069 case 2:
12070 type = BFD_RELOC_16;
12071 break;
12072 case 4:
12073 default:
12074 type = BFD_RELOC_32;
12075 break;
12076 case 8:
12077 type = BFD_RELOC_64;
12078 break;
12079 }
6c43fab6 12080
c19d1205
ZW
12081 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
12082}
6c43fab6 12083
c19d1205
ZW
12084#if defined OBJ_COFF || defined OBJ_ELF
12085void
12086arm_validate_fix (fixS * fixP)
6c43fab6 12087{
c19d1205
ZW
12088 /* If the destination of the branch is a defined symbol which does not have
12089 the THUMB_FUNC attribute, then we must be calling a function which has
12090 the (interfacearm) attribute. We look for the Thumb entry point to that
12091 function and change the branch to refer to that function instead. */
12092 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
12093 && fixP->fx_addsy != NULL
12094 && S_IS_DEFINED (fixP->fx_addsy)
12095 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 12096 {
c19d1205 12097 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 12098 }
c19d1205
ZW
12099}
12100#endif
6c43fab6 12101
c19d1205
ZW
12102int
12103arm_force_relocation (struct fix * fixp)
12104{
12105#if defined (OBJ_COFF) && defined (TE_PE)
12106 if (fixp->fx_r_type == BFD_RELOC_RVA)
12107 return 1;
12108#endif
6c43fab6 12109
c19d1205
ZW
12110 /* Resolve these relocations even if the symbol is extern or weak. */
12111 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
12112 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8
PB
12113 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
12114 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
12115 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
12116 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 12117 return 0;
a737bd4d 12118
c19d1205 12119 return generic_force_reloc (fixp);
404ff6b5
AH
12120}
12121
c19d1205
ZW
12122#ifdef OBJ_COFF
12123/* This is a little hack to help the gas/arm/adrl.s test. It prevents
12124 local labels from being added to the output symbol table when they
12125 are used with the ADRL pseudo op. The ADRL relocation should always
12126 be resolved before the binbary is emitted, so it is safe to say that
12127 it is adjustable. */
404ff6b5 12128
c19d1205
ZW
12129bfd_boolean
12130arm_fix_adjustable (fixS * fixP)
404ff6b5 12131{
c19d1205
ZW
12132 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
12133 return 1;
12134 return 0;
404ff6b5 12135}
c19d1205 12136#endif
404ff6b5 12137
c19d1205
ZW
12138#ifdef OBJ_ELF
12139/* Relocations against Thumb function names must be left unadjusted,
12140 so that the linker can use this information to correctly set the
12141 bottom bit of their addresses. The MIPS version of this function
12142 also prevents relocations that are mips-16 specific, but I do not
12143 know why it does this.
404ff6b5 12144
c19d1205
ZW
12145 FIXME:
12146 There is one other problem that ought to be addressed here, but
12147 which currently is not: Taking the address of a label (rather
12148 than a function) and then later jumping to that address. Such
12149 addresses also ought to have their bottom bit set (assuming that
12150 they reside in Thumb code), but at the moment they will not. */
404ff6b5 12151
c19d1205
ZW
12152bfd_boolean
12153arm_fix_adjustable (fixS * fixP)
404ff6b5 12154{
c19d1205
ZW
12155 if (fixP->fx_addsy == NULL)
12156 return 1;
404ff6b5 12157
c19d1205
ZW
12158 if (THUMB_IS_FUNC (fixP->fx_addsy)
12159 && fixP->fx_subsy == NULL)
12160 return 0;
a737bd4d 12161
c19d1205
ZW
12162 /* We need the symbol name for the VTABLE entries. */
12163 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12164 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12165 return 0;
404ff6b5 12166
c19d1205
ZW
12167 /* Don't allow symbols to be discarded on GOT related relocs. */
12168 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
12169 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
12170 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
12171 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
12172 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
12173 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
12174 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
12175 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
12176 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
12177 return 0;
a737bd4d 12178
c19d1205 12179 return 1;
a737bd4d 12180}
404ff6b5 12181
c19d1205
ZW
12182const char *
12183elf32_arm_target_format (void)
404ff6b5 12184{
c19d1205
ZW
12185#ifdef TE_SYMBIAN
12186 return (target_big_endian
12187 ? "elf32-bigarm-symbian"
12188 : "elf32-littlearm-symbian");
12189#elif defined (TE_VXWORKS)
12190 return (target_big_endian
12191 ? "elf32-bigarm-vxworks"
12192 : "elf32-littlearm-vxworks");
12193#else
12194 if (target_big_endian)
12195 return "elf32-bigarm";
12196 else
12197 return "elf32-littlearm";
12198#endif
404ff6b5
AH
12199}
12200
c19d1205
ZW
12201void
12202armelf_frob_symbol (symbolS * symp,
12203 int * puntp)
404ff6b5 12204{
c19d1205
ZW
12205 elf_frob_symbol (symp, puntp);
12206}
12207#endif
404ff6b5 12208
c19d1205 12209/* MD interface: Finalization. */
a737bd4d 12210
c19d1205
ZW
12211/* A good place to do this, although this was probably not intended
12212 for this kind of use. We need to dump the literal pool before
12213 references are made to a null symbol pointer. */
a737bd4d 12214
c19d1205
ZW
12215void
12216arm_cleanup (void)
12217{
12218 literal_pool * pool;
a737bd4d 12219
c19d1205
ZW
12220 for (pool = list_of_pools; pool; pool = pool->next)
12221 {
12222 /* Put it at the end of the relevent section. */
12223 subseg_set (pool->section, pool->sub_section);
12224#ifdef OBJ_ELF
12225 arm_elf_change_section ();
12226#endif
12227 s_ltorg (0);
12228 }
404ff6b5
AH
12229}
12230
c19d1205
ZW
12231/* Adjust the symbol table. This marks Thumb symbols as distinct from
12232 ARM ones. */
404ff6b5 12233
c19d1205
ZW
12234void
12235arm_adjust_symtab (void)
404ff6b5 12236{
c19d1205
ZW
12237#ifdef OBJ_COFF
12238 symbolS * sym;
404ff6b5 12239
c19d1205
ZW
12240 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12241 {
12242 if (ARM_IS_THUMB (sym))
12243 {
12244 if (THUMB_IS_FUNC (sym))
12245 {
12246 /* Mark the symbol as a Thumb function. */
12247 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
12248 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
12249 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 12250
c19d1205
ZW
12251 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
12252 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
12253 else
12254 as_bad (_("%s: unexpected function type: %d"),
12255 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
12256 }
12257 else switch (S_GET_STORAGE_CLASS (sym))
12258 {
12259 case C_EXT:
12260 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
12261 break;
12262 case C_STAT:
12263 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
12264 break;
12265 case C_LABEL:
12266 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
12267 break;
12268 default:
12269 /* Do nothing. */
12270 break;
12271 }
12272 }
a737bd4d 12273
c19d1205
ZW
12274 if (ARM_IS_INTERWORK (sym))
12275 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 12276 }
c19d1205
ZW
12277#endif
12278#ifdef OBJ_ELF
12279 symbolS * sym;
12280 char bind;
404ff6b5 12281
c19d1205 12282 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 12283 {
c19d1205
ZW
12284 if (ARM_IS_THUMB (sym))
12285 {
12286 elf_symbol_type * elf_sym;
404ff6b5 12287
c19d1205
ZW
12288 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
12289 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 12290
c19d1205
ZW
12291 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
12292 {
12293 /* If it's a .thumb_func, declare it as so,
12294 otherwise tag label as .code 16. */
12295 if (THUMB_IS_FUNC (sym))
12296 elf_sym->internal_elf_sym.st_info =
12297 ELF_ST_INFO (bind, STT_ARM_TFUNC);
12298 else
12299 elf_sym->internal_elf_sym.st_info =
12300 ELF_ST_INFO (bind, STT_ARM_16BIT);
12301 }
12302 }
12303 }
12304#endif
404ff6b5
AH
12305}
12306
c19d1205 12307/* MD interface: Initialization. */
404ff6b5 12308
a737bd4d 12309static void
c19d1205 12310set_constant_flonums (void)
a737bd4d 12311{
c19d1205 12312 int i;
404ff6b5 12313
c19d1205
ZW
12314 for (i = 0; i < NUM_FLOAT_VALS; i++)
12315 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
12316 abort ();
a737bd4d 12317}
404ff6b5 12318
c19d1205
ZW
12319void
12320md_begin (void)
a737bd4d 12321{
c19d1205
ZW
12322 unsigned mach;
12323 unsigned int i;
404ff6b5 12324
c19d1205
ZW
12325 if ( (arm_ops_hsh = hash_new ()) == NULL
12326 || (arm_cond_hsh = hash_new ()) == NULL
12327 || (arm_shift_hsh = hash_new ()) == NULL
12328 || (arm_psr_hsh = hash_new ()) == NULL
12329 || (arm_reg_hsh = hash_new ()) == NULL
12330 || (arm_reloc_hsh = hash_new ()) == NULL)
12331 as_fatal (_("virtual memory exhausted"));
12332
12333 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
12334 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
12335 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
12336 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
12337 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
12338 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
12339 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
12340 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
12341 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
12342 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
12343#ifdef OBJ_ELF
12344 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
12345 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
12346#endif
12347
12348 set_constant_flonums ();
404ff6b5 12349
c19d1205
ZW
12350 /* Set the cpu variant based on the command-line options. We prefer
12351 -mcpu= over -march= if both are set (as for GCC); and we prefer
12352 -mfpu= over any other way of setting the floating point unit.
12353 Use of legacy options with new options are faulted. */
12354 if (legacy_cpu != -1)
404ff6b5 12355 {
c19d1205
ZW
12356 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
12357 as_bad (_("use of old and new-style options to set CPU type"));
12358
12359 mcpu_cpu_opt = legacy_cpu;
404ff6b5 12360 }
c19d1205
ZW
12361 else if (mcpu_cpu_opt == -1)
12362 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 12363
c19d1205
ZW
12364 if (legacy_fpu != -1)
12365 {
12366 if (mfpu_opt != -1)
12367 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
12368
12369 mfpu_opt = legacy_fpu;
12370 }
12371 else if (mfpu_opt == -1)
12372 {
c19d1205 12373#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
12374 /* Some environments specify a default FPU. If they don't, infer it
12375 from the processor. */
03b1477f
RE
12376 if (mcpu_fpu_opt != -1)
12377 mfpu_opt = mcpu_fpu_opt;
12378 else
12379 mfpu_opt = march_fpu_opt;
39c2da32
RE
12380#else
12381 mfpu_opt = FPU_DEFAULT;
12382#endif
03b1477f
RE
12383 }
12384
12385 if (mfpu_opt == -1)
12386 {
12387 if (mcpu_cpu_opt == -1)
12388 mfpu_opt = FPU_DEFAULT;
12389 else if (mcpu_cpu_opt & ARM_EXT_V5)
12390 mfpu_opt = FPU_ARCH_VFP_V2;
12391 else
12392 mfpu_opt = FPU_ARCH_FPA;
12393 }
12394
ee065d83
PB
12395#ifdef CPU_DEFAULT
12396 if (mcpu_cpu_opt == -1)
12397 selected_cpu = mcpu_cpu_opt = CPU_DEFAULT;
12398#else
03b1477f 12399 if (mcpu_cpu_opt == -1)
ee065d83
PB
12400 {
12401 mcpu_cpu_opt = ARM_ANY;
12402 selected_cpu = 0;
12403 }
12404 else
12405 selected_cpu = mcpu_cpu_opt;
12406#endif
03b1477f
RE
12407
12408 cpu_variant = mcpu_cpu_opt | mfpu_opt;
12409
ee065d83
PB
12410 arm_arch_used = thumb_arch_used = 0;
12411
f17c130b 12412#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 12413 {
7cc69913
NC
12414 unsigned int flags = 0;
12415
12416#if defined OBJ_ELF
12417 flags = meabi_flags;
d507cf36
PB
12418
12419 switch (meabi_flags)
33a392fb 12420 {
d507cf36 12421 case EF_ARM_EABI_UNKNOWN:
7cc69913 12422#endif
d507cf36
PB
12423 /* Set the flags in the private structure. */
12424 if (uses_apcs_26) flags |= F_APCS26;
12425 if (support_interwork) flags |= F_INTERWORK;
12426 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 12427 if (pic_code) flags |= F_PIC;
d507cf36
PB
12428 if ((cpu_variant & FPU_ANY) == FPU_NONE
12429 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
7cc69913
NC
12430 flags |= F_SOFT_FLOAT;
12431
d507cf36
PB
12432 switch (mfloat_abi_opt)
12433 {
12434 case ARM_FLOAT_ABI_SOFT:
12435 case ARM_FLOAT_ABI_SOFTFP:
12436 flags |= F_SOFT_FLOAT;
12437 break;
33a392fb 12438
d507cf36
PB
12439 case ARM_FLOAT_ABI_HARD:
12440 if (flags & F_SOFT_FLOAT)
12441 as_bad (_("hard-float conflicts with specified fpu"));
12442 break;
12443 }
03b1477f 12444
c19d1205 12445 /* Using VFP conventions (even if soft-float). */
7cc69913
NC
12446 if (cpu_variant & FPU_VFP_EXT_NONE)
12447 flags |= F_VFP_FLOAT;
f17c130b 12448
fde78edd 12449#if defined OBJ_ELF
d507cf36
PB
12450 if (cpu_variant & FPU_ARCH_MAVERICK)
12451 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
12452 break;
12453
8cb51566 12454 case EF_ARM_EABI_VER4:
c19d1205 12455 /* No additional flags to set. */
d507cf36
PB
12456 break;
12457
12458 default:
12459 abort ();
12460 }
7cc69913 12461#endif
b99bd4ef
NC
12462 bfd_set_private_flags (stdoutput, flags);
12463
12464 /* We have run out flags in the COFF header to encode the
12465 status of ATPCS support, so instead we create a dummy,
c19d1205 12466 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
12467 if (atpcs)
12468 {
12469 asection * sec;
12470
12471 sec = bfd_make_section (stdoutput, ".arm.atpcs");
12472
12473 if (sec != NULL)
12474 {
12475 bfd_set_section_flags
12476 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
12477 bfd_set_section_size (stdoutput, sec, 0);
12478 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
12479 }
12480 }
7cc69913 12481 }
f17c130b 12482#endif
b99bd4ef
NC
12483
12484 /* Record the CPU type as well. */
12485 switch (cpu_variant & ARM_CPU_MASK)
12486 {
12487 case ARM_2:
12488 mach = bfd_mach_arm_2;
12489 break;
12490
c19d1205 12491 case ARM_3: /* Also ARM_250. */
b99bd4ef
NC
12492 mach = bfd_mach_arm_2a;
12493 break;
12494
c19d1205 12495 case ARM_6: /* Also ARM_7. */
b89dddec
RE
12496 mach = bfd_mach_arm_3;
12497 break;
12498
b99bd4ef 12499 default:
5a6c6817 12500 mach = bfd_mach_arm_unknown;
b99bd4ef 12501 break;
b99bd4ef
NC
12502 }
12503
12504 /* Catch special cases. */
e16bb312
NC
12505 if (cpu_variant & ARM_CEXT_IWMMXT)
12506 mach = bfd_mach_arm_iWMMXt;
12507 else if (cpu_variant & ARM_CEXT_XSCALE)
b99bd4ef 12508 mach = bfd_mach_arm_XScale;
fde78edd
NC
12509 else if (cpu_variant & ARM_CEXT_MAVERICK)
12510 mach = bfd_mach_arm_ep9312;
b99bd4ef
NC
12511 else if (cpu_variant & ARM_EXT_V5E)
12512 mach = bfd_mach_arm_5TE;
12513 else if (cpu_variant & ARM_EXT_V5)
12514 {
b89dddec 12515 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
12516 mach = bfd_mach_arm_5T;
12517 else
12518 mach = bfd_mach_arm_5;
12519 }
b89dddec 12520 else if (cpu_variant & ARM_EXT_V4)
b99bd4ef 12521 {
b89dddec 12522 if (cpu_variant & ARM_EXT_V4T)
b99bd4ef
NC
12523 mach = bfd_mach_arm_4T;
12524 else
12525 mach = bfd_mach_arm_4;
12526 }
b89dddec 12527 else if (cpu_variant & ARM_EXT_V3M)
b99bd4ef
NC
12528 mach = bfd_mach_arm_3M;
12529
12530 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
12531}
12532
c19d1205 12533/* Command line processing. */
b99bd4ef 12534
c19d1205
ZW
12535/* md_parse_option
12536 Invocation line includes a switch not recognized by the base assembler.
12537 See if it's a processor-specific option.
b99bd4ef 12538
c19d1205
ZW
12539 This routine is somewhat complicated by the need for backwards
12540 compatibility (since older releases of gcc can't be changed).
12541 The new options try to make the interface as compatible as
12542 possible with GCC.
b99bd4ef 12543
c19d1205 12544 New options (supported) are:
b99bd4ef 12545
c19d1205
ZW
12546 -mcpu=<cpu name> Assemble for selected processor
12547 -march=<architecture name> Assemble for selected architecture
12548 -mfpu=<fpu architecture> Assemble for selected FPU.
12549 -EB/-mbig-endian Big-endian
12550 -EL/-mlittle-endian Little-endian
12551 -k Generate PIC code
12552 -mthumb Start in Thumb mode
12553 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 12554
c19d1205 12555 For now we will also provide support for:
b99bd4ef 12556
c19d1205
ZW
12557 -mapcs-32 32-bit Program counter
12558 -mapcs-26 26-bit Program counter
12559 -macps-float Floats passed in FP registers
12560 -mapcs-reentrant Reentrant code
12561 -matpcs
12562 (sometime these will probably be replaced with -mapcs=<list of options>
12563 and -matpcs=<list of options>)
b99bd4ef 12564
c19d1205
ZW
12565 The remaining options are only supported for back-wards compatibility.
12566 Cpu variants, the arm part is optional:
12567 -m[arm]1 Currently not supported.
12568 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
12569 -m[arm]3 Arm 3 processor
12570 -m[arm]6[xx], Arm 6 processors
12571 -m[arm]7[xx][t][[d]m] Arm 7 processors
12572 -m[arm]8[10] Arm 8 processors
12573 -m[arm]9[20][tdmi] Arm 9 processors
12574 -mstrongarm[110[0]] StrongARM processors
12575 -mxscale XScale processors
12576 -m[arm]v[2345[t[e]]] Arm architectures
12577 -mall All (except the ARM1)
12578 FP variants:
12579 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
12580 -mfpe-old (No float load/store multiples)
12581 -mvfpxd VFP Single precision
12582 -mvfp All VFP
12583 -mno-fpu Disable all floating point instructions
b99bd4ef 12584
c19d1205
ZW
12585 The following CPU names are recognized:
12586 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
12587 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
12588 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
12589 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
12590 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
12591 arm10t arm10e, arm1020t, arm1020e, arm10200e,
12592 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 12593
c19d1205 12594 */
b99bd4ef 12595
c19d1205 12596const char * md_shortopts = "m:k";
b99bd4ef 12597
c19d1205
ZW
12598#ifdef ARM_BI_ENDIAN
12599#define OPTION_EB (OPTION_MD_BASE + 0)
12600#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 12601#else
c19d1205
ZW
12602#if TARGET_BYTES_BIG_ENDIAN
12603#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 12604#else
c19d1205
ZW
12605#define OPTION_EL (OPTION_MD_BASE + 1)
12606#endif
b99bd4ef 12607#endif
b99bd4ef 12608
c19d1205 12609struct option md_longopts[] =
b99bd4ef 12610{
c19d1205
ZW
12611#ifdef OPTION_EB
12612 {"EB", no_argument, NULL, OPTION_EB},
12613#endif
12614#ifdef OPTION_EL
12615 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 12616#endif
c19d1205
ZW
12617 {NULL, no_argument, NULL, 0}
12618};
b99bd4ef 12619
c19d1205 12620size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 12621
c19d1205 12622struct arm_option_table
b99bd4ef 12623{
c19d1205
ZW
12624 char *option; /* Option name to match. */
12625 char *help; /* Help information. */
12626 int *var; /* Variable to change. */
12627 int value; /* What to change it to. */
12628 char *deprecated; /* If non-null, print this message. */
12629};
b99bd4ef 12630
c19d1205
ZW
12631struct arm_option_table arm_opts[] =
12632{
12633 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
12634 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
12635 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
12636 &support_interwork, 1, NULL},
12637 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
12638 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
12639 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
12640 1, NULL},
12641 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
12642 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
12643 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
12644 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
12645 NULL},
b99bd4ef 12646
c19d1205
ZW
12647 /* These are recognized by the assembler, but have no affect on code. */
12648 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
12649 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
b99bd4ef 12650
c19d1205
ZW
12651 /* DON'T add any new processors to this list -- we want the whole list
12652 to go away... Add them to the processors table instead. */
12653 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
12654 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
12655 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
12656 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
12657 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
12658 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
12659 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
12660 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
12661 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
12662 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
12663 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
12664 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
12665 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
12666 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
12667 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
12668 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
12669 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
12670 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
12671 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
12672 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
12673 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
12674 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
12675 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
12676 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
12677 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
12678 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
12679 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
12680 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
12681 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
12682 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
12683 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
12684 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
12685 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
12686 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
12687 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
12688 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
12689 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
12690 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
12691 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
12692 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
12693 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
12694 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
12695 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
12696 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
12697 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
12698 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
12699 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12700 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12701 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12702 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12703 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
12704 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
12705 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
12706 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
12707 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12708 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12709 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12710 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12711 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12712 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12713 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12714 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12715 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12716 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12717 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12718 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12719 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12720 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12721 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
12722 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
12723 N_("use -mcpu=strongarm110")},
12724 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
12725 N_("use -mcpu=strongarm1100")},
12726 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
12727 N_("use -mcpu=strongarm1110")},
12728 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
12729 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
12730 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 12731
c19d1205
ZW
12732 /* Architecture variants -- don't add any more to this list either. */
12733 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12734 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12735 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12736 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12737 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12738 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12739 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12740 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12741 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12742 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12743 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12744 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12745 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12746 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12747 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12748 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12749 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
12750 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 12751
c19d1205
ZW
12752 /* Floating point variants -- don't add any more to this list either. */
12753 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
12754 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
12755 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
12756 {"mno-fpu", NULL, &legacy_fpu, 0,
12757 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 12758
c19d1205
ZW
12759 {NULL, NULL, NULL, 0, NULL}
12760};
7ed4c4c5 12761
c19d1205 12762struct arm_cpu_option_table
7ed4c4c5 12763{
c19d1205
ZW
12764 char *name;
12765 int value;
12766 /* For some CPUs we assume an FPU unless the user explicitly sets
12767 -mfpu=... */
12768 int default_fpu;
ee065d83
PB
12769 /* The canonical name of the CPU, or NULL to use NAME converted to upper
12770 case. */
12771 const char *canonical_name;
c19d1205 12772};
7ed4c4c5 12773
c19d1205
ZW
12774/* This list should, at a minimum, contain all the cpu names
12775 recognized by GCC. */
12776static struct arm_cpu_option_table arm_cpus[] =
12777{
ee065d83
PB
12778 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
12779 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
12780 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
12781 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
12782 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
12783 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12784 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12785 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12786 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12787 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12788 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12789 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12790 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12791 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12792 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12793 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12794 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12795 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12796 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12797 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12798 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12799 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12800 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12801 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12802 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12803 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12804 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12805 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12806 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12807 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12808 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12809 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12810 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12811 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12812 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12813 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12814 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12815 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12816 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12817 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
12818 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12819 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12820 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12821 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
12822 /* For V5 or later processors we default to using VFP; but the user
12823 should really set the FPU type explicitly. */
ee065d83
PB
12824 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12825 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12826 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
12827 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
12828 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
12829 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12830 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
12831 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12832 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12833 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
12834 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12835 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12836 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12837 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12838 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12839 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
12840 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12841 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12842 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12843 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
12844 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
12845 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
12846 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
12847 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
12848 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
12849 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
12850 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
12851 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
12852 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
12853 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
12854 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
c19d1205 12855 /* ??? XSCALE is really an architecture. */
ee065d83 12856 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 12857 /* ??? iwmmxt is not a processor. */
ee065d83
PB
12858 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
12859 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 12860 /* Maverick */
ee065d83
PB
12861 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK, "ARM920T"},
12862 {NULL, 0, 0, NULL}
c19d1205 12863};
7ed4c4c5 12864
c19d1205 12865struct arm_arch_option_table
7ed4c4c5 12866{
c19d1205
ZW
12867 char *name;
12868 int value;
12869 int default_fpu;
12870};
7ed4c4c5 12871
c19d1205
ZW
12872/* This list should, at a minimum, contain all the architecture names
12873 recognized by GCC. */
12874static struct arm_arch_option_table arm_archs[] =
12875{
12876 {"all", ARM_ANY, FPU_ARCH_FPA},
12877 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12878 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12879 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12880 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12881 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12882 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12883 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12884 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12885 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12886 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12887 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12888 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12889 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12890 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12891 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12892 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12893 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12894 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12895 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12896 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12897 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12898 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12899 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12900 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12901 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12902 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12903 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12904 {NULL, 0, 0}
12905};
7ed4c4c5 12906
c19d1205
ZW
12907/* ISA extensions in the co-processor space. */
12908struct arm_option_value_table
12909{
12910 char *name;
12911 int value;
12912};
7ed4c4c5 12913
c19d1205
ZW
12914static struct arm_option_value_table arm_extensions[] =
12915{
12916 {"maverick", ARM_CEXT_MAVERICK},
12917 {"xscale", ARM_CEXT_XSCALE},
12918 {"iwmmxt", ARM_CEXT_IWMMXT},
12919 {NULL, 0}
12920};
7ed4c4c5 12921
c19d1205
ZW
12922/* This list should, at a minimum, contain all the fpu names
12923 recognized by GCC. */
12924static struct arm_option_value_table arm_fpus[] =
12925{
12926 {"softfpa", FPU_NONE},
12927 {"fpe", FPU_ARCH_FPE},
12928 {"fpe2", FPU_ARCH_FPE},
12929 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12930 {"fpa", FPU_ARCH_FPA},
12931 {"fpa10", FPU_ARCH_FPA},
12932 {"fpa11", FPU_ARCH_FPA},
12933 {"arm7500fe", FPU_ARCH_FPA},
12934 {"softvfp", FPU_ARCH_VFP},
12935 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12936 {"vfp", FPU_ARCH_VFP_V2},
12937 {"vfp9", FPU_ARCH_VFP_V2},
12938 {"vfp10", FPU_ARCH_VFP_V2},
12939 {"vfp10-r0", FPU_ARCH_VFP_V1},
12940 {"vfpxd", FPU_ARCH_VFP_V1xD},
12941 {"arm1020t", FPU_ARCH_VFP_V1},
12942 {"arm1020e", FPU_ARCH_VFP_V2},
12943 {"arm1136jfs", FPU_ARCH_VFP_V2},
12944 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12945 {"maverick", FPU_ARCH_MAVERICK},
12946 {NULL, 0}
12947};
7ed4c4c5 12948
c19d1205
ZW
12949static struct arm_option_value_table arm_float_abis[] =
12950{
12951 {"hard", ARM_FLOAT_ABI_HARD},
12952 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12953 {"soft", ARM_FLOAT_ABI_SOFT},
12954 {NULL, 0}
12955};
7ed4c4c5 12956
c19d1205
ZW
12957#ifdef OBJ_ELF
12958/* We only know how to output GNU and ver 4 (AAELF) formats. */
12959static struct arm_option_value_table arm_eabis[] =
12960{
12961 {"gnu", EF_ARM_EABI_UNKNOWN},
12962 {"4", EF_ARM_EABI_VER4},
12963 {NULL, 0}
12964};
12965#endif
7ed4c4c5 12966
c19d1205
ZW
12967struct arm_long_option_table
12968{
12969 char * option; /* Substring to match. */
12970 char * help; /* Help information. */
12971 int (* func) (char * subopt); /* Function to decode sub-option. */
12972 char * deprecated; /* If non-null, print this message. */
12973};
7ed4c4c5
NC
12974
12975static int
c19d1205 12976arm_parse_extension (char * str, int * opt_p)
7ed4c4c5 12977{
c19d1205 12978 while (str != NULL && *str != 0)
7ed4c4c5 12979 {
c19d1205
ZW
12980 struct arm_option_value_table * opt;
12981 char * ext;
12982 int optlen;
7ed4c4c5 12983
c19d1205
ZW
12984 if (*str != '+')
12985 {
12986 as_bad (_("invalid architectural extension"));
12987 return 0;
12988 }
7ed4c4c5 12989
c19d1205
ZW
12990 str++;
12991 ext = strchr (str, '+');
7ed4c4c5 12992
c19d1205
ZW
12993 if (ext != NULL)
12994 optlen = ext - str;
12995 else
12996 optlen = strlen (str);
7ed4c4c5 12997
c19d1205
ZW
12998 if (optlen == 0)
12999 {
13000 as_bad (_("missing architectural extension"));
13001 return 0;
13002 }
7ed4c4c5 13003
c19d1205
ZW
13004 for (opt = arm_extensions; opt->name != NULL; opt++)
13005 if (strncmp (opt->name, str, optlen) == 0)
13006 {
13007 *opt_p |= opt->value;
13008 break;
13009 }
7ed4c4c5 13010
c19d1205
ZW
13011 if (opt->name == NULL)
13012 {
13013 as_bad (_("unknown architectural extnsion `%s'"), str);
13014 return 0;
13015 }
7ed4c4c5 13016
c19d1205
ZW
13017 str = ext;
13018 };
7ed4c4c5 13019
c19d1205
ZW
13020 return 1;
13021}
7ed4c4c5 13022
c19d1205
ZW
13023static int
13024arm_parse_cpu (char * str)
7ed4c4c5 13025{
c19d1205
ZW
13026 struct arm_cpu_option_table * opt;
13027 char * ext = strchr (str, '+');
13028 int optlen;
7ed4c4c5 13029
c19d1205
ZW
13030 if (ext != NULL)
13031 optlen = ext - str;
7ed4c4c5 13032 else
c19d1205 13033 optlen = strlen (str);
7ed4c4c5 13034
c19d1205 13035 if (optlen == 0)
7ed4c4c5 13036 {
c19d1205
ZW
13037 as_bad (_("missing cpu name `%s'"), str);
13038 return 0;
7ed4c4c5
NC
13039 }
13040
c19d1205
ZW
13041 for (opt = arm_cpus; opt->name != NULL; opt++)
13042 if (strncmp (opt->name, str, optlen) == 0)
13043 {
13044 mcpu_cpu_opt = opt->value;
13045 mcpu_fpu_opt = opt->default_fpu;
ee065d83
PB
13046 if (opt->canonical_name)
13047 strcpy(selected_cpu_name, opt->canonical_name);
13048 else
13049 {
13050 int i;
13051 for (i = 0; i < optlen; i++)
13052 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13053 selected_cpu_name[i] = 0;
13054 }
7ed4c4c5 13055
c19d1205
ZW
13056 if (ext != NULL)
13057 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 13058
c19d1205
ZW
13059 return 1;
13060 }
7ed4c4c5 13061
c19d1205
ZW
13062 as_bad (_("unknown cpu `%s'"), str);
13063 return 0;
7ed4c4c5
NC
13064}
13065
c19d1205
ZW
13066static int
13067arm_parse_arch (char * str)
7ed4c4c5 13068{
c19d1205
ZW
13069 struct arm_arch_option_table *opt;
13070 char *ext = strchr (str, '+');
13071 int optlen;
7ed4c4c5 13072
c19d1205
ZW
13073 if (ext != NULL)
13074 optlen = ext - str;
7ed4c4c5 13075 else
c19d1205 13076 optlen = strlen (str);
7ed4c4c5 13077
c19d1205 13078 if (optlen == 0)
7ed4c4c5 13079 {
c19d1205
ZW
13080 as_bad (_("missing architecture name `%s'"), str);
13081 return 0;
7ed4c4c5
NC
13082 }
13083
c19d1205
ZW
13084 for (opt = arm_archs; opt->name != NULL; opt++)
13085 if (streq (opt->name, str))
13086 {
13087 march_cpu_opt = opt->value;
13088 march_fpu_opt = opt->default_fpu;
ee065d83 13089 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 13090
c19d1205
ZW
13091 if (ext != NULL)
13092 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 13093
c19d1205
ZW
13094 return 1;
13095 }
13096
13097 as_bad (_("unknown architecture `%s'\n"), str);
13098 return 0;
7ed4c4c5 13099}
eb043451 13100
c19d1205
ZW
13101static int
13102arm_parse_fpu (char * str)
13103{
13104 struct arm_option_value_table * opt;
b99bd4ef 13105
c19d1205
ZW
13106 for (opt = arm_fpus; opt->name != NULL; opt++)
13107 if (streq (opt->name, str))
13108 {
13109 mfpu_opt = opt->value;
13110 return 1;
13111 }
b99bd4ef 13112
c19d1205
ZW
13113 as_bad (_("unknown floating point format `%s'\n"), str);
13114 return 0;
13115}
13116
13117static int
13118arm_parse_float_abi (char * str)
b99bd4ef 13119{
c19d1205 13120 struct arm_option_value_table * opt;
b99bd4ef 13121
c19d1205
ZW
13122 for (opt = arm_float_abis; opt->name != NULL; opt++)
13123 if (streq (opt->name, str))
13124 {
13125 mfloat_abi_opt = opt->value;
13126 return 1;
13127 }
cc8a6dd0 13128
c19d1205
ZW
13129 as_bad (_("unknown floating point abi `%s'\n"), str);
13130 return 0;
13131}
b99bd4ef 13132
c19d1205
ZW
13133#ifdef OBJ_ELF
13134static int
13135arm_parse_eabi (char * str)
13136{
13137 struct arm_option_value_table *opt;
cc8a6dd0 13138
c19d1205
ZW
13139 for (opt = arm_eabis; opt->name != NULL; opt++)
13140 if (streq (opt->name, str))
13141 {
13142 meabi_flags = opt->value;
13143 return 1;
13144 }
13145 as_bad (_("unknown EABI `%s'\n"), str);
13146 return 0;
13147}
13148#endif
cc8a6dd0 13149
c19d1205
ZW
13150struct arm_long_option_table arm_long_opts[] =
13151{
13152 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
13153 arm_parse_cpu, NULL},
13154 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
13155 arm_parse_arch, NULL},
13156 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
13157 arm_parse_fpu, NULL},
13158 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
13159 arm_parse_float_abi, NULL},
13160#ifdef OBJ_ELF
13161 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
13162 arm_parse_eabi, NULL},
13163#endif
13164 {NULL, NULL, 0, NULL}
13165};
cc8a6dd0 13166
c19d1205
ZW
13167int
13168md_parse_option (int c, char * arg)
13169{
13170 struct arm_option_table *opt;
13171 struct arm_long_option_table *lopt;
b99bd4ef 13172
c19d1205 13173 switch (c)
b99bd4ef 13174 {
c19d1205
ZW
13175#ifdef OPTION_EB
13176 case OPTION_EB:
13177 target_big_endian = 1;
13178 break;
13179#endif
cc8a6dd0 13180
c19d1205
ZW
13181#ifdef OPTION_EL
13182 case OPTION_EL:
13183 target_big_endian = 0;
13184 break;
13185#endif
b99bd4ef 13186
c19d1205
ZW
13187 case 'a':
13188 /* Listing option. Just ignore these, we don't support additional
13189 ones. */
13190 return 0;
b99bd4ef 13191
c19d1205
ZW
13192 default:
13193 for (opt = arm_opts; opt->option != NULL; opt++)
13194 {
13195 if (c == opt->option[0]
13196 && ((arg == NULL && opt->option[1] == 0)
13197 || streq (arg, opt->option + 1)))
13198 {
13199#if WARN_DEPRECATED
13200 /* If the option is deprecated, tell the user. */
13201 if (opt->deprecated != NULL)
13202 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13203 arg ? arg : "", _(opt->deprecated));
13204#endif
b99bd4ef 13205
c19d1205
ZW
13206 if (opt->var != NULL)
13207 *opt->var = opt->value;
cc8a6dd0 13208
c19d1205
ZW
13209 return 1;
13210 }
13211 }
b99bd4ef 13212
c19d1205
ZW
13213 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13214 {
13215 /* These options are expected to have an argument. */
13216 if (c == lopt->option[0]
13217 && arg != NULL
13218 && strncmp (arg, lopt->option + 1,
13219 strlen (lopt->option + 1)) == 0)
13220 {
13221#if WARN_DEPRECATED
13222 /* If the option is deprecated, tell the user. */
13223 if (lopt->deprecated != NULL)
13224 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
13225 _(lopt->deprecated));
13226#endif
b99bd4ef 13227
c19d1205
ZW
13228 /* Call the sup-option parser. */
13229 return lopt->func (arg + strlen (lopt->option) - 1);
13230 }
13231 }
a737bd4d 13232
c19d1205
ZW
13233 return 0;
13234 }
a394c00f 13235
c19d1205
ZW
13236 return 1;
13237}
a394c00f 13238
c19d1205
ZW
13239void
13240md_show_usage (FILE * fp)
a394c00f 13241{
c19d1205
ZW
13242 struct arm_option_table *opt;
13243 struct arm_long_option_table *lopt;
a394c00f 13244
c19d1205 13245 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 13246
c19d1205
ZW
13247 for (opt = arm_opts; opt->option != NULL; opt++)
13248 if (opt->help != NULL)
13249 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 13250
c19d1205
ZW
13251 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13252 if (lopt->help != NULL)
13253 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 13254
c19d1205
ZW
13255#ifdef OPTION_EB
13256 fprintf (fp, _("\
13257 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
13258#endif
13259
c19d1205
ZW
13260#ifdef OPTION_EL
13261 fprintf (fp, _("\
13262 -EL assemble code for a little-endian cpu\n"));
a737bd4d 13263#endif
c19d1205 13264}
ee065d83
PB
13265
13266
13267#ifdef OBJ_ELF
13268/* Set the public EABI object attributes. */
13269static void
13270aeabi_set_public_attributes (void)
13271{
13272 int arch;
13273 int flags;
13274
13275 /* Choose the architecture based on the capabilities of the requested cpu
13276 (if any) and/or the instructions actually used. */
13277 flags = mcpu_cpu_opt | arm_arch_used | thumb_arch_used;
13278 if (flags & ARM_EXT_V6T2)
13279 arch = 8;
13280 else if (flags & ARM_EXT_V6Z)
13281 arch = 7;
13282 else if (flags & ARM_EXT_V6K)
13283 arch = 9;
13284 else if (flags & ARM_EXT_V6)
13285 arch = 6;
13286 else if (flags & ARM_EXT_V5E)
13287 arch = 4;
13288 else if (flags & (ARM_EXT_V5 | ARM_EXT_V5T))
13289 arch = 3;
13290 else if (flags & ARM_EXT_V4T)
13291 arch = 2;
13292 else if (flags & ARM_EXT_V4)
13293 arch = 1;
13294 else
13295 arch = 0;
13296
13297 /* Tag_CPU_name. */
13298 if (selected_cpu_name[0])
13299 {
13300 char *p;
13301
13302 p = selected_cpu_name;
13303 if (strncmp(p, "armv", 4) == 0)
13304 {
13305 int i;
13306
13307 p += 4;
13308 for (i = 0; p[i]; i++)
13309 p[i] = TOUPPER (p[i]);
13310 }
13311 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
13312 }
13313 /* Tag_CPU_arch. */
13314 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
13315 /* Tag_ARM_ISA_use. */
13316 if (arm_arch_used)
13317 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
13318 /* Tag_THUMB_ISA_use. */
13319 if (thumb_arch_used)
13320 elf32_arm_add_eabi_attr_int (stdoutput, 9,
13321 (thumb_arch_used & ARM_EXT_V6T2) ? 2 : 1);
13322 /* Tag_VFP_arch. */
13323 if ((arm_arch_used | thumb_arch_used) & FPU_ARCH_VFP_V2)
13324 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
13325 else if ((arm_arch_used | thumb_arch_used) & FPU_ARCH_VFP_V1)
13326 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
13327 /* Tag_WMMX_arch. */
13328 if ((arm_arch_used | thumb_arch_used) & ARM_CEXT_IWMMXT)
13329 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
13330}
13331
13332/* Add the .ARM.attributes section. */
13333void
13334arm_md_end (void)
13335{
13336 segT s;
13337 char *p;
13338 addressT addr;
13339 offsetT size;
13340
13341 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
13342 return;
13343
13344 aeabi_set_public_attributes ();
13345 size = elf32_arm_eabi_attr_size (stdoutput);
13346 s = subseg_new (".ARM.attributes", 0);
13347 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
13348 addr = frag_now_fix ();
13349 p = frag_more (size);
13350 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
13351}
13352
13353
13354/* Parse a .cpu directive. */
13355
13356static void
13357s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
13358{
13359 struct arm_cpu_option_table *opt;
13360 char *name;
13361 char saved_char;
13362
13363 name = input_line_pointer;
13364 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13365 input_line_pointer++;
13366 saved_char = *input_line_pointer;
13367 *input_line_pointer = 0;
13368
13369 /* Skip the first "all" entry. */
13370 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
13371 if (streq (opt->name, name))
13372 {
13373 mcpu_cpu_opt = opt->value;
13374 selected_cpu = mcpu_cpu_opt;
13375 if (opt->canonical_name)
13376 strcpy(selected_cpu_name, opt->canonical_name);
13377 else
13378 {
13379 int i;
13380 for (i = 0; opt->name[i]; i++)
13381 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13382 selected_cpu_name[i] = 0;
13383 }
13384 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13385 *input_line_pointer = saved_char;
13386 demand_empty_rest_of_line ();
13387 return;
13388 }
13389 as_bad (_("unknown cpu `%s'"), name);
13390 *input_line_pointer = saved_char;
13391 ignore_rest_of_line ();
13392}
13393
13394
13395/* Parse a .arch directive. */
13396
13397static void
13398s_arm_arch (int ignored ATTRIBUTE_UNUSED)
13399{
13400 struct arm_arch_option_table *opt;
13401 char saved_char;
13402 char *name;
13403
13404 name = input_line_pointer;
13405 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13406 input_line_pointer++;
13407 saved_char = *input_line_pointer;
13408 *input_line_pointer = 0;
13409
13410 /* Skip the first "all" entry. */
13411 for (opt = arm_archs + 1; opt->name != NULL; opt++)
13412 if (streq (opt->name, name))
13413 {
13414 mcpu_cpu_opt = opt->value;
13415 selected_cpu = mcpu_cpu_opt;
13416 strcpy(selected_cpu_name, opt->name);
13417 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13418 *input_line_pointer = saved_char;
13419 demand_empty_rest_of_line ();
13420 return;
13421 }
13422
13423 as_bad (_("unknown architecture `%s'\n"), name);
13424 *input_line_pointer = saved_char;
13425 ignore_rest_of_line ();
13426}
13427
13428
13429/* Parse a .fpu directive. */
13430
13431static void
13432s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
13433{
13434 struct arm_option_value_table *opt;
13435 char saved_char;
13436 char *name;
13437
13438 name = input_line_pointer;
13439 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13440 input_line_pointer++;
13441 saved_char = *input_line_pointer;
13442 *input_line_pointer = 0;
13443
13444 for (opt = arm_fpus; opt->name != NULL; opt++)
13445 if (streq (opt->name, name))
13446 {
13447 mfpu_opt = opt->value;
13448 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13449 *input_line_pointer = saved_char;
13450 demand_empty_rest_of_line ();
13451 return;
13452 }
13453
13454 as_bad (_("unknown floating point format `%s'\n"), name);
13455 *input_line_pointer = saved_char;
13456 ignore_rest_of_line ();
13457}
13458#endif /* OBJ_ELF */
13459
This page took 1.163799 seconds and 4 git commands to generate.