xref: /openbsd-src/gnu/usr.bin/binutils/include/opcode/tic80.h (revision cf2f2c5620d6d9a4fd01930983c4b9a1f76d7aa3)
1f7cc78ecSespie /* tic80.h -- Header file for TI TMS320C80 (MV) opcode table
2*cf2f2c56Smiod    Copyright 1996, 1997, 2003 Free Software Foundation, Inc.
3f7cc78ecSespie    Written by Fred Fish (fnf@cygnus.com), Cygnus Support
4f7cc78ecSespie 
5f7cc78ecSespie This file is part of GDB, GAS, and the GNU binutils.
6f7cc78ecSespie 
7f7cc78ecSespie GDB, GAS, and the GNU binutils are free software; you can redistribute
8f7cc78ecSespie them and/or modify them under the terms of the GNU General Public
9f7cc78ecSespie License as published by the Free Software Foundation; either version
10f7cc78ecSespie 1, or (at your option) any later version.
11f7cc78ecSespie 
12f7cc78ecSespie GDB, GAS, and the GNU binutils are distributed in the hope that they
13f7cc78ecSespie will be useful, but WITHOUT ANY WARRANTY; without even the implied
14f7cc78ecSespie warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15f7cc78ecSespie the GNU General Public License for more details.
16f7cc78ecSespie 
17f7cc78ecSespie You should have received a copy of the GNU General Public License
18f7cc78ecSespie along with this file; see the file COPYING.  If not, write to the Free
19f7cc78ecSespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20f7cc78ecSespie 
21f7cc78ecSespie #ifndef TIC80_H
22f7cc78ecSespie #define TIC80_H
23f7cc78ecSespie 
24f7cc78ecSespie /* The opcode table is an array of struct tic80_opcode.  */
25f7cc78ecSespie 
26f7cc78ecSespie struct tic80_opcode
27f7cc78ecSespie {
28f7cc78ecSespie   /* The opcode name.  */
29f7cc78ecSespie 
30f7cc78ecSespie   const char *name;
31f7cc78ecSespie 
32f7cc78ecSespie   /* The opcode itself.  Those bits which will be filled in with operands
33f7cc78ecSespie      are zeroes.  */
34f7cc78ecSespie 
35f7cc78ecSespie   unsigned long opcode;
36f7cc78ecSespie 
37f7cc78ecSespie   /* The opcode mask.  This is used by the disassembler.  This is a mask
38f7cc78ecSespie      containing ones indicating those bits which must match the opcode
39f7cc78ecSespie      field, and zeroes indicating those bits which need not match (and are
40f7cc78ecSespie      presumably filled in by operands).  */
41f7cc78ecSespie 
42f7cc78ecSespie   unsigned long mask;
43f7cc78ecSespie 
44f7cc78ecSespie   /* Special purpose flags for this opcode. */
45f7cc78ecSespie 
46f7cc78ecSespie   unsigned char flags;
47f7cc78ecSespie 
48f7cc78ecSespie   /* An array of operand codes.  Each code is an index into the operand
49f7cc78ecSespie      table.  They appear in the order which the operands must appear in
50f7cc78ecSespie      assembly code, and are terminated by a zero.  FIXME: Adjust size to
51f7cc78ecSespie      match actual requirements when TIc80 support is complete */
52f7cc78ecSespie 
53f7cc78ecSespie   unsigned char operands[8];
54f7cc78ecSespie };
55f7cc78ecSespie 
56f7cc78ecSespie /* The table itself is sorted by major opcode number, and is otherwise in
57f7cc78ecSespie    the order in which the disassembler should consider instructions.
58f7cc78ecSespie    FIXME: This isn't currently true. */
59f7cc78ecSespie 
60f7cc78ecSespie extern const struct tic80_opcode tic80_opcodes[];
61f7cc78ecSespie extern const int tic80_num_opcodes;
62f7cc78ecSespie 
63f7cc78ecSespie 
64f7cc78ecSespie /* The operands table is an array of struct tic80_operand.  */
65f7cc78ecSespie 
66f7cc78ecSespie struct tic80_operand
67f7cc78ecSespie {
68f7cc78ecSespie   /* The number of bits in the operand.  */
69f7cc78ecSespie 
70f7cc78ecSespie   int bits;
71f7cc78ecSespie 
72f7cc78ecSespie   /* How far the operand is left shifted in the instruction.  */
73f7cc78ecSespie 
74f7cc78ecSespie   int shift;
75f7cc78ecSespie 
76f7cc78ecSespie   /* Insertion function.  This is used by the assembler.  To insert an
77f7cc78ecSespie      operand value into an instruction, check this field.
78f7cc78ecSespie 
79f7cc78ecSespie      If it is NULL, execute
80f7cc78ecSespie          i |= (op & ((1 << o->bits) - 1)) << o->shift;
81f7cc78ecSespie      (i is the instruction which we are filling in, o is a pointer to
82f7cc78ecSespie      this structure, and op is the opcode value; this assumes twos
83f7cc78ecSespie      complement arithmetic).
84f7cc78ecSespie 
85f7cc78ecSespie      If this field is not NULL, then simply call it with the
86f7cc78ecSespie      instruction and the operand value.  It will return the new value
87f7cc78ecSespie      of the instruction.  If the ERRMSG argument is not NULL, then if
88f7cc78ecSespie      the operand value is illegal, *ERRMSG will be set to a warning
89f7cc78ecSespie      string (the operand will be inserted in any case).  If the
90f7cc78ecSespie      operand value is legal, *ERRMSG will be unchanged (most operands
91f7cc78ecSespie      can accept any value).  */
92f7cc78ecSespie 
93*cf2f2c56Smiod   unsigned long (*insert)
94*cf2f2c56Smiod     (unsigned long instruction, long op, const char **errmsg);
95f7cc78ecSespie 
96f7cc78ecSespie   /* Extraction function.  This is used by the disassembler.  To
97f7cc78ecSespie      extract this operand type from an instruction, check this field.
98f7cc78ecSespie 
99f7cc78ecSespie      If it is NULL, compute
100f7cc78ecSespie          op = ((i) >> o->shift) & ((1 << o->bits) - 1);
101f7cc78ecSespie 	 if ((o->flags & TIC80_OPERAND_SIGNED) != 0
102f7cc78ecSespie 	     && (op & (1 << (o->bits - 1))) != 0)
103f7cc78ecSespie 	   op -= 1 << o->bits;
104f7cc78ecSespie      (i is the instruction, o is a pointer to this structure, and op
105f7cc78ecSespie      is the result; this assumes twos complement arithmetic).
106f7cc78ecSespie 
107f7cc78ecSespie      If this field is not NULL, then simply call it with the
108f7cc78ecSespie      instruction value.  It will return the value of the operand.  If
109f7cc78ecSespie      the INVALID argument is not NULL, *INVALID will be set to
110f7cc78ecSespie      non-zero if this operand type can not actually be extracted from
111f7cc78ecSespie      this operand (i.e., the instruction does not match).  If the
112f7cc78ecSespie      operand is valid, *INVALID will not be changed.  */
113f7cc78ecSespie 
114*cf2f2c56Smiod   long (*extract) (unsigned long instruction, int *invalid);
115f7cc78ecSespie 
116f7cc78ecSespie   /* One bit syntax flags.  */
117f7cc78ecSespie 
118f7cc78ecSespie   unsigned long flags;
119f7cc78ecSespie };
120f7cc78ecSespie 
121f7cc78ecSespie /* Elements in the table are retrieved by indexing with values from
122f7cc78ecSespie    the operands field of the tic80_opcodes table.  */
123f7cc78ecSespie 
124f7cc78ecSespie extern const struct tic80_operand tic80_operands[];
125f7cc78ecSespie 
126f7cc78ecSespie 
127f7cc78ecSespie /* Values defined for the flags field of a struct tic80_operand.
128f7cc78ecSespie 
129f7cc78ecSespie    Note that flags for all predefined symbols, such as the general purpose
130f7cc78ecSespie    registers (ex: r10), control registers (ex: FPST), condition codes (ex:
131f7cc78ecSespie    eq0.b), bit numbers (ex: gt.b), etc are large enough that they can be
132f7cc78ecSespie    or'd into an int where the lower bits contain the actual numeric value
133f7cc78ecSespie    that correponds to this predefined symbol.  This way a single int can
134f7cc78ecSespie    contain both the value of the symbol and it's type.
135f7cc78ecSespie  */
136f7cc78ecSespie 
137f7cc78ecSespie /* This operand must be an even register number.  Floating point numbers
138f7cc78ecSespie    for example are stored in even/odd register pairs. */
139f7cc78ecSespie 
140f7cc78ecSespie #define TIC80_OPERAND_EVEN	(1 << 0)
141f7cc78ecSespie 
142f7cc78ecSespie /* This operand must be an odd register number and must be one greater than
143f7cc78ecSespie    the register number of the previous operand.  I.E. the second register in
144f7cc78ecSespie    an even/odd register pair. */
145f7cc78ecSespie 
146f7cc78ecSespie #define TIC80_OPERAND_ODD	(1 << 1)
147f7cc78ecSespie 
148f7cc78ecSespie /* This operand takes signed values.  */
149f7cc78ecSespie 
150f7cc78ecSespie #define TIC80_OPERAND_SIGNED	(1 << 2)
151f7cc78ecSespie 
152f7cc78ecSespie /* This operand may be either a predefined constant name or a numeric value.
153f7cc78ecSespie    An example would be a condition code like "eq0.b" which has the numeric
154f7cc78ecSespie    value 0x2. */
155f7cc78ecSespie 
156f7cc78ecSespie #define TIC80_OPERAND_NUM	(1 << 3)
157f7cc78ecSespie 
158f7cc78ecSespie /* This operand should be wrapped in parentheses rather than separated
159f7cc78ecSespie    from the previous one by a comma.  This is used for various
160f7cc78ecSespie    instructions, like the load and store instructions, which want
161f7cc78ecSespie    their operands to look like "displacement(reg)" */
162f7cc78ecSespie 
163f7cc78ecSespie #define TIC80_OPERAND_PARENS	(1 << 4)
164f7cc78ecSespie 
165f7cc78ecSespie /* This operand is a PC relative branch offset.  The disassembler prints
166f7cc78ecSespie    these symbolically if possible.  Note that the offsets are taken as word
167f7cc78ecSespie    offsets. */
168f7cc78ecSespie 
169f7cc78ecSespie #define TIC80_OPERAND_PCREL	(1 << 5)
170f7cc78ecSespie 
171f7cc78ecSespie /* This flag is a hint to the disassembler for using hex as the prefered
172f7cc78ecSespie    printing format, even for small positive or negative immediate values.
173f7cc78ecSespie    Normally values in the range -999 to 999 are printed as signed decimal
174f7cc78ecSespie    values and other values are printed in hex. */
175f7cc78ecSespie 
176f7cc78ecSespie #define TIC80_OPERAND_BITFIELD	(1 << 6)
177f7cc78ecSespie 
178f7cc78ecSespie /* This operand may have a ":m" modifier specified by bit 17 in a short
179f7cc78ecSespie    immediate form instruction. */
180f7cc78ecSespie 
181f7cc78ecSespie #define TIC80_OPERAND_M_SI	(1 << 7)
182f7cc78ecSespie 
183f7cc78ecSespie /* This operand may have a ":m" modifier specified by bit 15 in a long
184f7cc78ecSespie    immediate or register form instruction. */
185f7cc78ecSespie 
186f7cc78ecSespie #define TIC80_OPERAND_M_LI	(1 << 8)
187f7cc78ecSespie 
188f7cc78ecSespie /* This operand may have a ":s" modifier specified in bit 11 in a long
189f7cc78ecSespie    immediate or register form instruction. */
190f7cc78ecSespie 
191f7cc78ecSespie #define TIC80_OPERAND_SCALED	(1 << 9)
192f7cc78ecSespie 
193f7cc78ecSespie /* This operand is a floating point value */
194f7cc78ecSespie 
195f7cc78ecSespie #define TIC80_OPERAND_FLOAT	(1 << 10)
196f7cc78ecSespie 
197f7cc78ecSespie /* This operand is an byte offset from a base relocation. The lower
198f7cc78ecSespie  two bits of the final relocated address are ignored when the value is
199f7cc78ecSespie  written to the program counter. */
200f7cc78ecSespie 
201f7cc78ecSespie #define TIC80_OPERAND_BASEREL	(1 << 11)
202f7cc78ecSespie 
203f7cc78ecSespie /* This operand is an "endmask" field for a shift instruction.
204f7cc78ecSespie    It is treated special in that it can have values of 0-32,
205f7cc78ecSespie    where 0 and 32 result in the same instruction.  The assembler
206f7cc78ecSespie    must be able to accept both endmask values.  This disassembler
207f7cc78ecSespie    has no way of knowing from the instruction which value was
208f7cc78ecSespie    given at assembly time, so it just uses '0'. */
209f7cc78ecSespie 
210f7cc78ecSespie #define TIC80_OPERAND_ENDMASK	(1 << 12)
211f7cc78ecSespie 
212f7cc78ecSespie /* This operand is one of the 32 general purpose registers.
213f7cc78ecSespie    The disassembler prints these with a leading 'r'. */
214f7cc78ecSespie 
215f7cc78ecSespie #define TIC80_OPERAND_GPR	(1 << 27)
216f7cc78ecSespie 
217f7cc78ecSespie /* This operand is a floating point accumulator register.
218f7cc78ecSespie    The disassembler prints these with a leading 'a'. */
219f7cc78ecSespie 
220f7cc78ecSespie #define TIC80_OPERAND_FPA	( 1 << 28)
221f7cc78ecSespie 
222f7cc78ecSespie /* This operand is a control register number, either numeric or
223f7cc78ecSespie    symbolic (like "EIF", "EPC", etc).
224f7cc78ecSespie    The disassembler prints these symbolically. */
225f7cc78ecSespie 
226f7cc78ecSespie #define TIC80_OPERAND_CR	(1 << 29)
227f7cc78ecSespie 
228f7cc78ecSespie /* This operand is a condition code, either numeric or
229f7cc78ecSespie    symbolic (like "eq0.b", "ne0.w", etc).
230f7cc78ecSespie    The disassembler prints these symbolically. */
231f7cc78ecSespie 
232f7cc78ecSespie #define TIC80_OPERAND_CC	(1 << 30)
233f7cc78ecSespie 
234f7cc78ecSespie /* This operand is a bit number, either numeric or
235f7cc78ecSespie    symbolic (like "eq.b", "or.f", etc).
236f7cc78ecSespie    The disassembler prints these symbolically.
237f7cc78ecSespie    Note that they appear in the instruction in 1's complement relative
238f7cc78ecSespie    to the values given in the manual. */
239f7cc78ecSespie 
240f7cc78ecSespie #define TIC80_OPERAND_BITNUM	(1 << 31)
241f7cc78ecSespie 
242f7cc78ecSespie /* This mask is used to strip operand bits from an int that contains
243f7cc78ecSespie    both operand bits and a numeric value in the lsbs. */
244f7cc78ecSespie 
245f7cc78ecSespie #define TIC80_OPERAND_MASK	(TIC80_OPERAND_GPR | TIC80_OPERAND_FPA | TIC80_OPERAND_CR | TIC80_OPERAND_CC | TIC80_OPERAND_BITNUM)
246f7cc78ecSespie 
247f7cc78ecSespie 
248f7cc78ecSespie /* Flag bits for the struct tic80_opcode flags field. */
249f7cc78ecSespie 
250f7cc78ecSespie #define TIC80_VECTOR		01	/* Is a vector instruction */
251f7cc78ecSespie #define TIC80_NO_R0_DEST	02	/* Register r0 cannot be a destination register */
252f7cc78ecSespie 
253f7cc78ecSespie 
254f7cc78ecSespie /* The opcodes library contains a table that allows translation from predefined
255f7cc78ecSespie    symbol names to numeric values, and vice versa. */
256f7cc78ecSespie 
257f7cc78ecSespie /* Structure to hold information about predefined symbols.  */
258f7cc78ecSespie 
259f7cc78ecSespie struct predefined_symbol
260f7cc78ecSespie {
261f7cc78ecSespie   char *name;		/* name to recognize */
262f7cc78ecSespie   int value;
263f7cc78ecSespie };
264f7cc78ecSespie 
265f7cc78ecSespie #define PDS_NAME(pdsp) ((pdsp) -> name)
266f7cc78ecSespie #define PDS_VALUE(pdsp) ((pdsp) -> value)
267f7cc78ecSespie 
268*cf2f2c56Smiod /* Translation array.  */
269*cf2f2c56Smiod extern const struct predefined_symbol tic80_predefined_symbols[];
270*cf2f2c56Smiod /* How many members in the array.  */
271*cf2f2c56Smiod extern const int tic80_num_predefined_symbols;
272f7cc78ecSespie 
273*cf2f2c56Smiod /* Translate value to symbolic name.  */
274*cf2f2c56Smiod const char *tic80_value_to_symbol (int val, int class);
275f7cc78ecSespie 
276*cf2f2c56Smiod /* Translate symbolic name to value.  */
277*cf2f2c56Smiod int tic80_symbol_to_value (char *name, int class);
278*cf2f2c56Smiod 
279*cf2f2c56Smiod const struct predefined_symbol *tic80_next_predefined_symbol
280*cf2f2c56Smiod   (const struct predefined_symbol *);
281f7cc78ecSespie 
282f7cc78ecSespie #endif /* TIC80_H */
283