Subversion Repositories Kolibri OS

Rev

Rev 5191 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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