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