Blame include/opcode/tic80.h

Packit bbfece
/* tic80.h -- Header file for TI TMS320C80 (MV) opcode table
Packit bbfece
   Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit bbfece
   Written by Fred Fish (fnf@cygnus.com), Cygnus Support
Packit bbfece
Packit bbfece
   This file is part of GDB, GAS, and the GNU binutils.
Packit bbfece
Packit bbfece
   GDB, GAS, and the GNU binutils are free software; you can redistribute
Packit bbfece
   them and/or modify them under the terms of the GNU General Public
Packit bbfece
   License as published by the Free Software Foundation; either version 3,
Packit bbfece
   or (at your option) any later version.
Packit bbfece
Packit bbfece
   GDB, GAS, and the GNU binutils are distributed in the hope that they
Packit bbfece
   will be useful, but WITHOUT ANY WARRANTY; without even the implied
Packit bbfece
   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
Packit bbfece
   the GNU General Public License for more details.
Packit bbfece
Packit bbfece
   You should have received a copy of the GNU General Public License
Packit bbfece
   along with this file; see the file COPYING3.  If not, write to the Free
Packit bbfece
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
Packit bbfece
   MA 02110-1301, USA.  */
Packit bbfece
Packit bbfece
#ifndef TIC80_H
Packit bbfece
#define TIC80_H
Packit bbfece
Packit bbfece
/* The opcode table is an array of struct tic80_opcode.  */
Packit bbfece
Packit bbfece
struct tic80_opcode
Packit bbfece
{
Packit bbfece
  /* The opcode name.  */
Packit bbfece
Packit bbfece
  const char *name;
Packit bbfece
Packit bbfece
  /* The opcode itself.  Those bits which will be filled in with operands
Packit bbfece
     are zeroes.  */
Packit bbfece
Packit bbfece
  unsigned long opcode;
Packit bbfece
Packit bbfece
  /* The opcode mask.  This is used by the disassembler.  This is a mask
Packit bbfece
     containing ones indicating those bits which must match the opcode
Packit bbfece
     field, and zeroes indicating those bits which need not match (and are
Packit bbfece
     presumably filled in by operands).  */
Packit bbfece
Packit bbfece
  unsigned long mask;
Packit bbfece
Packit bbfece
  /* Special purpose flags for this opcode. */
Packit bbfece
Packit bbfece
  unsigned char flags;
Packit bbfece
Packit bbfece
  /* An array of operand codes.  Each code is an index into the operand
Packit bbfece
     table.  They appear in the order which the operands must appear in
Packit bbfece
     assembly code, and are terminated by a zero.  FIXME: Adjust size to
Packit bbfece
     match actual requirements when TIc80 support is complete */
Packit bbfece
Packit bbfece
  unsigned char operands[8];
Packit bbfece
};
Packit bbfece
Packit bbfece
/* The table itself is sorted by major opcode number, and is otherwise in
Packit bbfece
   the order in which the disassembler should consider instructions.
Packit bbfece
   FIXME: This isn't currently true. */
Packit bbfece
Packit bbfece
extern const struct tic80_opcode tic80_opcodes[];
Packit bbfece
extern const int tic80_num_opcodes;
Packit bbfece
Packit bbfece

Packit bbfece
/* The operands table is an array of struct tic80_operand.  */
Packit bbfece
Packit bbfece
struct tic80_operand
Packit bbfece
{
Packit bbfece
  /* The number of bits in the operand.  */
Packit bbfece
Packit bbfece
  int bits;
Packit bbfece
Packit bbfece
  /* How far the operand is left shifted in the instruction.  */
Packit bbfece
Packit bbfece
  int shift;
Packit bbfece
Packit bbfece
  /* Insertion function.  This is used by the assembler.  To insert an
Packit bbfece
     operand value into an instruction, check this field.
Packit bbfece
Packit bbfece
     If it is NULL, execute
Packit bbfece
         i |= (op & ((1 << o->bits) - 1)) << o->shift;
Packit bbfece
     (i is the instruction which we are filling in, o is a pointer to
Packit bbfece
     this structure, and op is the opcode value; this assumes twos
Packit bbfece
     complement arithmetic).
Packit bbfece
Packit bbfece
     If this field is not NULL, then simply call it with the
Packit bbfece
     instruction and the operand value.  It will return the new value
Packit bbfece
     of the instruction.  If the ERRMSG argument is not NULL, then if
Packit bbfece
     the operand value is illegal, *ERRMSG will be set to a warning
Packit bbfece
     string (the operand will be inserted in any case).  If the
Packit bbfece
     operand value is legal, *ERRMSG will be unchanged (most operands
Packit bbfece
     can accept any value).  */
Packit bbfece
Packit bbfece
  unsigned long (*insert)
Packit bbfece
    (unsigned long instruction, long op, const char **errmsg);
Packit bbfece
Packit bbfece
  /* Extraction function.  This is used by the disassembler.  To
Packit bbfece
     extract this operand type from an instruction, check this field.
Packit bbfece
Packit bbfece
     If it is NULL, compute
Packit bbfece
         op = ((i) >> o->shift) & ((1 << o->bits) - 1);
Packit bbfece
	 if ((o->flags & TIC80_OPERAND_SIGNED) != 0
Packit bbfece
	     && (op & (1 << (o->bits - 1))) != 0)
Packit bbfece
	   op -= 1 << o->bits;
Packit bbfece
     (i is the instruction, o is a pointer to this structure, and op
Packit bbfece
     is the result; this assumes twos complement arithmetic).
Packit bbfece
Packit bbfece
     If this field is not NULL, then simply call it with the
Packit bbfece
     instruction value.  It will return the value of the operand.  If
Packit bbfece
     the INVALID argument is not NULL, *INVALID will be set to
Packit bbfece
     non-zero if this operand type can not actually be extracted from
Packit bbfece
     this operand (i.e., the instruction does not match).  If the
Packit bbfece
     operand is valid, *INVALID will not be changed.  */
Packit bbfece
Packit bbfece
  long (*extract) (unsigned long instruction, int *invalid);
Packit bbfece
Packit bbfece
  /* One bit syntax flags.  */
Packit bbfece
Packit bbfece
  unsigned long flags;
Packit bbfece
};
Packit bbfece
Packit bbfece
/* Elements in the table are retrieved by indexing with values from
Packit bbfece
   the operands field of the tic80_opcodes table.  */
Packit bbfece
Packit bbfece
extern const struct tic80_operand tic80_operands[];
Packit bbfece
Packit bbfece

Packit bbfece
/* Values defined for the flags field of a struct tic80_operand.
Packit bbfece
Packit bbfece
   Note that flags for all predefined symbols, such as the general purpose
Packit bbfece
   registers (ex: r10), control registers (ex: FPST), condition codes (ex:
Packit bbfece
   eq0.b), bit numbers (ex: gt.b), etc are large enough that they can be
Packit bbfece
   or'd into an int where the lower bits contain the actual numeric value
Packit bbfece
   that correponds to this predefined symbol.  This way a single int can
Packit bbfece
   contain both the value of the symbol and it's type.
Packit bbfece
 */
Packit bbfece
Packit bbfece
/* This operand must be an even register number.  Floating point numbers
Packit bbfece
   for example are stored in even/odd register pairs. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_EVEN	(1 << 0)
Packit bbfece
Packit bbfece
/* This operand must be an odd register number and must be one greater than
Packit bbfece
   the register number of the previous operand.  I.E. the second register in
Packit bbfece
   an even/odd register pair. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_ODD	(1 << 1)
Packit bbfece
Packit bbfece
/* This operand takes signed values.  */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_SIGNED	(1 << 2)
Packit bbfece
Packit bbfece
/* This operand may be either a predefined constant name or a numeric value.
Packit bbfece
   An example would be a condition code like "eq0.b" which has the numeric
Packit bbfece
   value 0x2. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_NUM	(1 << 3)
Packit bbfece
Packit bbfece
/* This operand should be wrapped in parentheses rather than separated
Packit bbfece
   from the previous one by a comma.  This is used for various
Packit bbfece
   instructions, like the load and store instructions, which want
Packit bbfece
   their operands to look like "displacement(reg)" */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_PARENS	(1 << 4)
Packit bbfece
Packit bbfece
/* This operand is a PC relative branch offset.  The disassembler prints
Packit bbfece
   these symbolically if possible.  Note that the offsets are taken as word
Packit bbfece
   offsets. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_PCREL	(1 << 5)
Packit bbfece
Packit bbfece
/* This flag is a hint to the disassembler for using hex as the prefered
Packit bbfece
   printing format, even for small positive or negative immediate values.
Packit bbfece
   Normally values in the range -999 to 999 are printed as signed decimal
Packit bbfece
   values and other values are printed in hex. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_BITFIELD	(1 << 6)
Packit bbfece
Packit bbfece
/* This operand may have a ":m" modifier specified by bit 17 in a short
Packit bbfece
   immediate form instruction. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_M_SI	(1 << 7)
Packit bbfece
Packit bbfece
/* This operand may have a ":m" modifier specified by bit 15 in a long
Packit bbfece
   immediate or register form instruction. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_M_LI	(1 << 8)
Packit bbfece
Packit bbfece
/* This operand may have a ":s" modifier specified in bit 11 in a long
Packit bbfece
   immediate or register form instruction. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_SCALED	(1 << 9)
Packit bbfece
Packit bbfece
/* This operand is a floating point value */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_FLOAT	(1 << 10)
Packit bbfece
Packit bbfece
/* This operand is an byte offset from a base relocation. The lower
Packit bbfece
 two bits of the final relocated address are ignored when the value is
Packit bbfece
 written to the program counter. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_BASEREL	(1 << 11)
Packit bbfece
Packit bbfece
/* This operand is an "endmask" field for a shift instruction.
Packit bbfece
   It is treated special in that it can have values of 0-32,
Packit bbfece
   where 0 and 32 result in the same instruction.  The assembler
Packit bbfece
   must be able to accept both endmask values.  This disassembler
Packit bbfece
   has no way of knowing from the instruction which value was 
Packit bbfece
   given at assembly time, so it just uses '0'. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_ENDMASK	(1 << 12)
Packit bbfece
Packit bbfece
/* This operand is one of the 32 general purpose registers.
Packit bbfece
   The disassembler prints these with a leading 'r'. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_GPR	(1 << 27)
Packit bbfece
Packit bbfece
/* This operand is a floating point accumulator register.
Packit bbfece
   The disassembler prints these with a leading 'a'. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_FPA	( 1 << 28)
Packit bbfece
Packit bbfece
/* This operand is a control register number, either numeric or
Packit bbfece
   symbolic (like "EIF", "EPC", etc).
Packit bbfece
   The disassembler prints these symbolically. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_CR	(1 << 29)
Packit bbfece
Packit bbfece
/* This operand is a condition code, either numeric or
Packit bbfece
   symbolic (like "eq0.b", "ne0.w", etc).
Packit bbfece
   The disassembler prints these symbolically. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_CC	(1 << 30)
Packit bbfece
Packit bbfece
/* This operand is a bit number, either numeric or
Packit bbfece
   symbolic (like "eq.b", "or.f", etc).
Packit bbfece
   The disassembler prints these symbolically.
Packit bbfece
   Note that they appear in the instruction in 1's complement relative
Packit bbfece
   to the values given in the manual. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_BITNUM	(1 << 31)
Packit bbfece
Packit bbfece
/* This mask is used to strip operand bits from an int that contains
Packit bbfece
   both operand bits and a numeric value in the lsbs. */
Packit bbfece
Packit bbfece
#define TIC80_OPERAND_MASK	(TIC80_OPERAND_GPR | TIC80_OPERAND_FPA | TIC80_OPERAND_CR | TIC80_OPERAND_CC | TIC80_OPERAND_BITNUM)
Packit bbfece
Packit bbfece

Packit bbfece
/* Flag bits for the struct tic80_opcode flags field. */
Packit bbfece
Packit bbfece
#define TIC80_VECTOR		01	/* Is a vector instruction */
Packit bbfece
#define TIC80_NO_R0_DEST	02	/* Register r0 cannot be a destination register */
Packit bbfece
Packit bbfece

Packit bbfece
/* The opcodes library contains a table that allows translation from predefined
Packit bbfece
   symbol names to numeric values, and vice versa. */
Packit bbfece
Packit bbfece
/* Structure to hold information about predefined symbols.  */
Packit bbfece
Packit bbfece
struct predefined_symbol
Packit bbfece
{
Packit bbfece
  char *name;		/* name to recognize */
Packit bbfece
  int value;
Packit bbfece
};
Packit bbfece
Packit bbfece
#define PDS_NAME(pdsp) ((pdsp) -> name)
Packit bbfece
#define PDS_VALUE(pdsp) ((pdsp) -> value)
Packit bbfece
Packit bbfece
/* Translation array.  */
Packit bbfece
extern const struct predefined_symbol tic80_predefined_symbols[];
Packit bbfece
/* How many members in the array.  */
Packit bbfece
extern const int tic80_num_predefined_symbols;
Packit bbfece
Packit bbfece
/* Translate value to symbolic name.  */
Packit bbfece
const char *tic80_value_to_symbol (int val, int class);
Packit bbfece
Packit bbfece
/* Translate symbolic name to value.  */
Packit bbfece
int tic80_symbol_to_value (char *name, int class);
Packit bbfece
Packit bbfece
const struct predefined_symbol *tic80_next_predefined_symbol
Packit bbfece
  (const struct predefined_symbol *);
Packit bbfece
Packit bbfece
#endif /* TIC80_H */