xref: /openbsd-src/gnu/usr.bin/binutils/include/opcode/arc.h (revision cf2f2c5620d6d9a4fd01930983c4b9a1f76d7aa3)
1f7cc78ecSespie /* Opcode table for the ARC.
2*cf2f2c56Smiod    Copyright 1994, 1995, 1997, 2001, 2002, 2003
3*cf2f2c56Smiod    Free Software Foundation, Inc.
4f7cc78ecSespie    Contributed by Doug Evans (dje@cygnus.com).
5f7cc78ecSespie 
6f7cc78ecSespie    This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
7f7cc78ecSespie    the GNU Binutils.
8f7cc78ecSespie 
9f7cc78ecSespie    GAS/GDB is free software; you can redistribute it and/or modify
10f7cc78ecSespie    it under the terms of the GNU General Public License as published by
11f7cc78ecSespie    the Free Software Foundation; either version 2, or (at your option)
12f7cc78ecSespie    any later version.
13f7cc78ecSespie 
14f7cc78ecSespie    GAS/GDB is distributed in the hope that it will be useful,
15f7cc78ecSespie    but WITHOUT ANY WARRANTY; without even the implied warranty of
16f7cc78ecSespie    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
17f7cc78ecSespie    GNU General Public License for more details.
18f7cc78ecSespie 
19f7cc78ecSespie    You should have received a copy of the GNU General Public License
20f7cc78ecSespie    along with GAS or GDB; see the file COPYING.	If not, write to
21*cf2f2c56Smiod    the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
22*cf2f2c56Smiod    MA 02111-1307, USA.  */
235f210c2aSfgsch 
24f7cc78ecSespie 
25f7cc78ecSespie /* List of the various cpu types.
26f7cc78ecSespie    The tables currently use bit masks to say whether the instruction or
27f7cc78ecSespie    whatever is supported by a particular cpu.  This lets us have one entry
28f7cc78ecSespie    apply to several cpus.
29f7cc78ecSespie 
305f210c2aSfgsch    The `base' cpu must be 0. The cpu type is treated independently of
315f210c2aSfgsch    endianness. The complete `mach' number includes endianness.
32f7cc78ecSespie    These values are internal to opcodes/bfd/binutils/gas.  */
335f210c2aSfgsch #define ARC_MACH_5 0
345f210c2aSfgsch #define ARC_MACH_6 1
355f210c2aSfgsch #define ARC_MACH_7 2
365f210c2aSfgsch #define ARC_MACH_8 4
375f210c2aSfgsch 
38f7cc78ecSespie /* Additional cpu values can be inserted here and ARC_MACH_BIG moved down.  */
395f210c2aSfgsch #define ARC_MACH_BIG 16
40f7cc78ecSespie 
41f7cc78ecSespie /* Mask of number of bits necessary to record cpu type.  */
425f210c2aSfgsch #define ARC_MACH_CPU_MASK (ARC_MACH_BIG - 1)
435f210c2aSfgsch 
44f7cc78ecSespie /* Mask of number of bits necessary to record cpu type + endianness.  */
455f210c2aSfgsch #define ARC_MACH_MASK ((ARC_MACH_BIG << 1) - 1)
46f7cc78ecSespie 
47f7cc78ecSespie /* Type to denote an ARC instruction (at least a 32 bit unsigned int).  */
485f210c2aSfgsch 
49f7cc78ecSespie typedef unsigned int arc_insn;
50f7cc78ecSespie 
51f7cc78ecSespie struct arc_opcode {
52f7cc78ecSespie   char *syntax;              /* syntax of insn  */
53f7cc78ecSespie   unsigned long mask, value; /* recognize insn if (op&mask) == value  */
54f7cc78ecSespie   int flags;                 /* various flag bits  */
55f7cc78ecSespie 
56f7cc78ecSespie /* Values for `flags'.  */
57f7cc78ecSespie 
58f7cc78ecSespie /* Return CPU number, given flag bits.  */
59f7cc78ecSespie #define ARC_OPCODE_CPU(bits) ((bits) & ARC_MACH_CPU_MASK)
605f210c2aSfgsch 
61f7cc78ecSespie /* Return MACH number, given flag bits.  */
62f7cc78ecSespie #define ARC_OPCODE_MACH(bits) ((bits) & ARC_MACH_MASK)
635f210c2aSfgsch 
64f7cc78ecSespie /* First opcode flag bit available after machine mask.  */
655f210c2aSfgsch #define ARC_OPCODE_FLAG_START (ARC_MACH_MASK + 1)
665f210c2aSfgsch 
67f7cc78ecSespie /* This insn is a conditional branch.  */
68f7cc78ecSespie #define ARC_OPCODE_COND_BRANCH (ARC_OPCODE_FLAG_START)
695f210c2aSfgsch #define SYNTAX_3OP             (ARC_OPCODE_COND_BRANCH << 1)
705f210c2aSfgsch #define SYNTAX_LENGTH          (SYNTAX_3OP                 )
715f210c2aSfgsch #define SYNTAX_2OP             (SYNTAX_3OP             << 1)
725f210c2aSfgsch #define OP1_MUST_BE_IMM        (SYNTAX_2OP             << 1)
735f210c2aSfgsch #define OP1_IMM_IMPLIED        (OP1_MUST_BE_IMM        << 1)
745f210c2aSfgsch #define SYNTAX_VALID           (OP1_IMM_IMPLIED        << 1)
75f7cc78ecSespie 
765f210c2aSfgsch #define I(x) (((x) & 31) << 27)
775f210c2aSfgsch #define A(x) (((x) & ARC_MASK_REG) << ARC_SHIFT_REGA)
785f210c2aSfgsch #define B(x) (((x) & ARC_MASK_REG) << ARC_SHIFT_REGB)
795f210c2aSfgsch #define C(x) (((x) & ARC_MASK_REG) << ARC_SHIFT_REGC)
805f210c2aSfgsch #define R(x,b,m) (((x) & (m)) << (b)) /* value X, mask M, at bit B */
815f210c2aSfgsch 
825f210c2aSfgsch /* These values are used to optimize assembly and disassembly.  Each insn
835f210c2aSfgsch    is on a list of related insns (same first letter for assembly, same
845f210c2aSfgsch    insn code for disassembly).  */
855f210c2aSfgsch 
865f210c2aSfgsch   struct arc_opcode *next_asm;	/* Next instr to try during assembly.  */
875f210c2aSfgsch   struct arc_opcode *next_dis;	/* Next instr to try during disassembly.  */
88f7cc78ecSespie 
89f7cc78ecSespie /* Macros to create the hash values for the lists.  */
90f7cc78ecSespie #define ARC_HASH_OPCODE(string) \
91f7cc78ecSespie   ((string)[0] >= 'a' && (string)[0] <= 'z' ? (string)[0] - 'a' : 26)
92f7cc78ecSespie #define ARC_HASH_ICODE(insn) \
93f7cc78ecSespie   ((unsigned int) (insn) >> 27)
94f7cc78ecSespie 
95f7cc78ecSespie  /* Macros to access `next_asm', `next_dis' so users needn't care about the
96f7cc78ecSespie     underlying mechanism.  */
97f7cc78ecSespie #define ARC_OPCODE_NEXT_ASM(op) ((op)->next_asm)
98f7cc78ecSespie #define ARC_OPCODE_NEXT_DIS(op) ((op)->next_dis)
99f7cc78ecSespie };
100f7cc78ecSespie 
1015f210c2aSfgsch /* this is an "insert at front" linked list per Metaware spec
1025f210c2aSfgsch    that new definitions override older ones.  */
103d2201f2fSdrahn extern struct arc_opcode *arc_ext_opcodes;
1045f210c2aSfgsch 
105f7cc78ecSespie struct arc_operand_value {
106f7cc78ecSespie   char *name;          /* eg: "eq"  */
107f7cc78ecSespie   short value;         /* eg: 1  */
108f7cc78ecSespie   unsigned char type;  /* index into `arc_operands'  */
109f7cc78ecSespie   unsigned char flags; /* various flag bits  */
110f7cc78ecSespie 
111f7cc78ecSespie /* Values for `flags'.  */
112f7cc78ecSespie 
113f7cc78ecSespie /* Return CPU number, given flag bits.  */
114f7cc78ecSespie #define ARC_OPVAL_CPU(bits) ((bits) & ARC_MACH_CPU_MASK)
115f7cc78ecSespie /* Return MACH number, given flag bits.  */
116f7cc78ecSespie #define ARC_OPVAL_MACH(bits) ((bits) & ARC_MACH_MASK)
117f7cc78ecSespie };
118f7cc78ecSespie 
1195f210c2aSfgsch struct arc_ext_operand_value {
1205f210c2aSfgsch   struct arc_ext_operand_value *next;
1215f210c2aSfgsch   struct arc_operand_value operand;
122d2201f2fSdrahn };
123d2201f2fSdrahn 
124d2201f2fSdrahn extern struct arc_ext_operand_value *arc_ext_operands;
1255f210c2aSfgsch 
126f7cc78ecSespie struct arc_operand {
127f7cc78ecSespie /* One of the insn format chars.  */
128f7cc78ecSespie   unsigned char fmt;
129f7cc78ecSespie 
130f7cc78ecSespie /* The number of bits in the operand (may be unused for a modifier).  */
131f7cc78ecSespie   unsigned char bits;
132f7cc78ecSespie 
133f7cc78ecSespie /* How far the operand is left shifted in the instruction, or
134f7cc78ecSespie    the modifier's flag bit (may be unused for a modifier.  */
135f7cc78ecSespie   unsigned char shift;
136f7cc78ecSespie 
137f7cc78ecSespie /* Various flag bits.  */
138f7cc78ecSespie   int flags;
139f7cc78ecSespie 
140f7cc78ecSespie /* Values for `flags'.  */
141f7cc78ecSespie 
142f7cc78ecSespie /* This operand is a suffix to the opcode.  */
143f7cc78ecSespie #define ARC_OPERAND_SUFFIX 1
144f7cc78ecSespie 
145f7cc78ecSespie /* This operand is a relative branch displacement.  The disassembler
146f7cc78ecSespie    prints these symbolically if possible.  */
147f7cc78ecSespie #define ARC_OPERAND_RELATIVE_BRANCH 2
148f7cc78ecSespie 
149f7cc78ecSespie /* This operand is an absolute branch address.  The disassembler
150f7cc78ecSespie    prints these symbolically if possible.  */
151f7cc78ecSespie #define ARC_OPERAND_ABSOLUTE_BRANCH 4
152f7cc78ecSespie 
153f7cc78ecSespie /* This operand is an address.  The disassembler
154f7cc78ecSespie    prints these symbolically if possible.  */
155f7cc78ecSespie #define ARC_OPERAND_ADDRESS 8
156f7cc78ecSespie 
157f7cc78ecSespie /* This operand is a long immediate value.  */
158f7cc78ecSespie #define ARC_OPERAND_LIMM 0x10
159f7cc78ecSespie 
160f7cc78ecSespie /* This operand takes signed values.  */
161f7cc78ecSespie #define ARC_OPERAND_SIGNED 0x20
162f7cc78ecSespie 
163f7cc78ecSespie /* This operand takes signed values, but also accepts a full positive
164f7cc78ecSespie    range of values.  That is, if bits is 16, it takes any value from
165f7cc78ecSespie    -0x8000 to 0xffff.  */
166f7cc78ecSespie #define ARC_OPERAND_SIGNOPT 0x40
167f7cc78ecSespie 
168f7cc78ecSespie /* This operand should be regarded as a negative number for the
169f7cc78ecSespie    purposes of overflow checking (i.e., the normal most negative
170f7cc78ecSespie    number is disallowed and one more than the normal most positive
171f7cc78ecSespie    number is allowed).  This flag will only be set for a signed
172f7cc78ecSespie    operand.  */
173f7cc78ecSespie #define ARC_OPERAND_NEGATIVE 0x80
174f7cc78ecSespie 
175f7cc78ecSespie /* This operand doesn't really exist.  The program uses these operands
176f7cc78ecSespie    in special ways.  */
177f7cc78ecSespie #define ARC_OPERAND_FAKE 0x100
178f7cc78ecSespie 
1795f210c2aSfgsch /* separate flags operand for j and jl instructions  */
1805f210c2aSfgsch #define ARC_OPERAND_JUMPFLAGS 0x200
1815f210c2aSfgsch 
1825f210c2aSfgsch /* allow warnings and errors to be issued after call to insert_xxxxxx  */
1835f210c2aSfgsch #define ARC_OPERAND_WARN  0x400
1845f210c2aSfgsch #define ARC_OPERAND_ERROR 0x800
1855f210c2aSfgsch 
1865f210c2aSfgsch /* this is a load operand */
1875f210c2aSfgsch #define ARC_OPERAND_LOAD  0x8000
1885f210c2aSfgsch 
1895f210c2aSfgsch /* this is a store operand */
1905f210c2aSfgsch #define ARC_OPERAND_STORE 0x10000
1915f210c2aSfgsch 
192f7cc78ecSespie /* Modifier values.  */
193f7cc78ecSespie /* A dot is required before a suffix.  Eg: .le  */
194f7cc78ecSespie #define ARC_MOD_DOT 0x1000
195f7cc78ecSespie 
196f7cc78ecSespie /* A normal register is allowed (not used, but here for completeness).  */
197f7cc78ecSespie #define ARC_MOD_REG 0x2000
198f7cc78ecSespie 
199f7cc78ecSespie /* An auxiliary register name is expected.  */
200f7cc78ecSespie #define ARC_MOD_AUXREG 0x4000
201f7cc78ecSespie 
202f7cc78ecSespie /* Sum of all ARC_MOD_XXX bits.  */
203f7cc78ecSespie #define ARC_MOD_BITS 0x7000
204f7cc78ecSespie 
205f7cc78ecSespie /* Non-zero if the operand type is really a modifier.  */
206f7cc78ecSespie #define ARC_MOD_P(X) ((X) & ARC_MOD_BITS)
207f7cc78ecSespie 
2085f210c2aSfgsch /* enforce read/write only register restrictions  */
2095f210c2aSfgsch #define ARC_REGISTER_READONLY    0x01
2105f210c2aSfgsch #define ARC_REGISTER_WRITEONLY   0x02
2115f210c2aSfgsch #define ARC_REGISTER_NOSHORT_CUT 0x04
2125f210c2aSfgsch 
213f7cc78ecSespie /* Insertion function.  This is used by the assembler.  To insert an
214f7cc78ecSespie    operand value into an instruction, check this field.
215f7cc78ecSespie 
216f7cc78ecSespie    If it is NULL, execute
217f7cc78ecSespie    i |= (p & ((1 << o->bits) - 1)) << o->shift;
218f7cc78ecSespie    (I is the instruction which we are filling in, O is a pointer to
219f7cc78ecSespie    this structure, and OP is the opcode value; this assumes twos
220f7cc78ecSespie    complement arithmetic).
221f7cc78ecSespie 
222f7cc78ecSespie    If this field is not NULL, then simply call it with the
223f7cc78ecSespie    instruction and the operand value.  It will return the new value
224f7cc78ecSespie    of the instruction.  If the ERRMSG argument is not NULL, then if
225f7cc78ecSespie    the operand value is illegal, *ERRMSG will be set to a warning
226f7cc78ecSespie    string (the operand will be inserted in any case).  If the
227f7cc78ecSespie    operand value is legal, *ERRMSG will be unchanged.
228f7cc78ecSespie 
229f7cc78ecSespie    REG is non-NULL when inserting a register value.  */
230f7cc78ecSespie 
231*cf2f2c56Smiod   arc_insn (*insert)
232*cf2f2c56Smiod     (arc_insn insn, const struct arc_operand *operand, int mods,
233*cf2f2c56Smiod      const struct arc_operand_value *reg, long value, const char **errmsg);
234f7cc78ecSespie 
235f7cc78ecSespie /* Extraction function.  This is used by the disassembler.  To
236f7cc78ecSespie    extract this operand type from an instruction, check this field.
237f7cc78ecSespie 
238f7cc78ecSespie    If it is NULL, compute
239f7cc78ecSespie      op = ((i) >> o->shift) & ((1 << o->bits) - 1);
240f7cc78ecSespie      if ((o->flags & ARC_OPERAND_SIGNED) != 0
241f7cc78ecSespie           && (op & (1 << (o->bits - 1))) != 0)
242f7cc78ecSespie        op -= 1 << o->bits;
243f7cc78ecSespie    (I is the instruction, O is a pointer to this structure, and OP
244f7cc78ecSespie    is the result; this assumes twos complement arithmetic).
245f7cc78ecSespie 
246f7cc78ecSespie    If this field is not NULL, then simply call it with the
247f7cc78ecSespie    instruction value.  It will return the value of the operand.  If
248f7cc78ecSespie    the INVALID argument is not NULL, *INVALID will be set to
249f7cc78ecSespie    non-zero if this operand type can not actually be extracted from
250f7cc78ecSespie    this operand (i.e., the instruction does not match).  If the
251f7cc78ecSespie    operand is valid, *INVALID will not be changed.
252f7cc78ecSespie 
253f7cc78ecSespie    INSN is a pointer to an array of two `arc_insn's.  The first element is
254f7cc78ecSespie    the insn, the second is the limm if present.
255f7cc78ecSespie 
256f7cc78ecSespie    Operands that have a printable form like registers and suffixes have
257f7cc78ecSespie    their struct arc_operand_value pointer stored in OPVAL.  */
258f7cc78ecSespie 
259*cf2f2c56Smiod   long (*extract)
260*cf2f2c56Smiod     (arc_insn *insn, const struct arc_operand *operand, int mods,
261*cf2f2c56Smiod      const struct arc_operand_value **opval, int *invalid);
262f7cc78ecSespie };
263f7cc78ecSespie 
2645f210c2aSfgsch /* Bits that say what version of cpu we have. These should be passed to
2655f210c2aSfgsch    arc_init_opcode_tables. At present, all there is is the cpu type.  */
266f7cc78ecSespie 
267f7cc78ecSespie /* CPU number, given value passed to `arc_init_opcode_tables'.  */
268f7cc78ecSespie #define ARC_HAVE_CPU(bits) ((bits) & ARC_MACH_CPU_MASK)
269f7cc78ecSespie /* MACH number, given value passed to `arc_init_opcode_tables'.  */
270f7cc78ecSespie #define ARC_HAVE_MACH(bits) ((bits) & ARC_MACH_MASK)
271f7cc78ecSespie 
272f7cc78ecSespie /* Special register values:  */
273f7cc78ecSespie #define ARC_REG_SHIMM_UPDATE 61
274f7cc78ecSespie #define ARC_REG_SHIMM 63
275f7cc78ecSespie #define ARC_REG_LIMM 62
276f7cc78ecSespie 
277f7cc78ecSespie /* Non-zero if REG is a constant marker.  */
278f7cc78ecSespie #define ARC_REG_CONSTANT_P(REG) ((REG) >= 61)
279f7cc78ecSespie 
280f7cc78ecSespie /* Positions and masks of various fields:  */
281f7cc78ecSespie #define ARC_SHIFT_REGA 21
282f7cc78ecSespie #define ARC_SHIFT_REGB 15
283f7cc78ecSespie #define ARC_SHIFT_REGC 9
284f7cc78ecSespie #define ARC_MASK_REG 63
285f7cc78ecSespie 
286f7cc78ecSespie /* Delay slot types.  */
287f7cc78ecSespie #define ARC_DELAY_NONE 0   /* no delay slot */
288f7cc78ecSespie #define ARC_DELAY_NORMAL 1 /* delay slot in both cases */
289f7cc78ecSespie #define ARC_DELAY_JUMP 2   /* delay slot only if branch taken */
290f7cc78ecSespie 
291f7cc78ecSespie /* Non-zero if X will fit in a signed 9 bit field.  */
292f7cc78ecSespie #define ARC_SHIMM_CONST_P(x) ((long) (x) >= -256 && (long) (x) <= 255)
293f7cc78ecSespie 
294f7cc78ecSespie extern const struct arc_operand arc_operands[];
295f7cc78ecSespie extern const int arc_operand_count;
2965f210c2aSfgsch extern struct arc_opcode arc_opcodes[];
297f7cc78ecSespie extern const int arc_opcodes_count;
298f7cc78ecSespie extern const struct arc_operand_value arc_suffixes[];
299f7cc78ecSespie extern const int arc_suffixes_count;
300f7cc78ecSespie extern const struct arc_operand_value arc_reg_names[];
301f7cc78ecSespie extern const int arc_reg_names_count;
302f7cc78ecSespie extern unsigned char arc_operand_map[];
303f7cc78ecSespie 
304f7cc78ecSespie /* Utility fns in arc-opc.c.  */
305*cf2f2c56Smiod int arc_get_opcode_mach (int, int);
3065f210c2aSfgsch 
307f7cc78ecSespie /* `arc_opcode_init_tables' must be called before `arc_xxx_supported'.  */
308*cf2f2c56Smiod void arc_opcode_init_tables (int);
309*cf2f2c56Smiod void arc_opcode_init_insert (void);
310*cf2f2c56Smiod void arc_opcode_init_extract (void);
311*cf2f2c56Smiod const struct arc_opcode *arc_opcode_lookup_asm (const char *);
312*cf2f2c56Smiod const struct arc_opcode *arc_opcode_lookup_dis (unsigned int);
313*cf2f2c56Smiod int arc_opcode_limm_p (long *);
3145f210c2aSfgsch const struct arc_operand_value *arc_opcode_lookup_suffix
315*cf2f2c56Smiod   (const struct arc_operand *type, int value);
316*cf2f2c56Smiod int arc_opcode_supported (const struct arc_opcode *);
317*cf2f2c56Smiod int arc_opval_supported (const struct arc_operand_value *);
318*cf2f2c56Smiod int arc_limm_fixup_adjust (arc_insn);
319*cf2f2c56Smiod int arc_insn_is_j (arc_insn);
320*cf2f2c56Smiod int arc_insn_not_jl (arc_insn);
321*cf2f2c56Smiod int arc_operand_type (int);
322*cf2f2c56Smiod struct arc_operand_value *get_ext_suffix (char *);
323*cf2f2c56Smiod int arc_get_noshortcut_flag (void);
324