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