Home | History | Annotate | Line # | Download | only in opcode
arc.h revision 1.3
      1  1.1  christos /* Opcode table for the ARC.
      2  1.3  christos    Copyright 1994-2015 Free Software Foundation, Inc.
      3  1.3  christos 
      4  1.3  christos    Contributed by Claudiu Zissulescu (claziss (at) synopsys.com)
      5  1.1  christos 
      6  1.1  christos    This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
      7  1.1  christos    the GNU Binutils.
      8  1.1  christos 
      9  1.1  christos    GAS/GDB is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3, or (at your option)
     12  1.1  christos    any later version.
     13  1.1  christos 
     14  1.1  christos    GAS/GDB is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.3  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with GAS or GDB; see the file COPYING3.  If not, write to
     21  1.1  christos    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
     22  1.1  christos    MA 02110-1301, USA.  */
     23  1.1  christos 
     24  1.3  christos #ifndef OPCODE_ARC_H
     25  1.3  christos #define OPCODE_ARC_H
     26  1.3  christos 
     27  1.3  christos #define MAX_INSN_ARGS	     6
     28  1.3  christos #define MAX_INSN_FLGS	     3
     29  1.3  christos 
     30  1.3  christos /* Instruction Class.  */
     31  1.3  christos typedef enum
     32  1.3  christos   {
     33  1.3  christos     ARITH,
     34  1.3  christos     AUXREG,
     35  1.3  christos     BRANCH,
     36  1.3  christos     CONTROL,
     37  1.3  christos     DSP,
     38  1.3  christos     FLOAT,
     39  1.3  christos     INVALID,
     40  1.3  christos     JUMP,
     41  1.3  christos     KERNEL,
     42  1.3  christos     LOGICAL,
     43  1.3  christos     MEMORY,
     44  1.3  christos   } insn_class_t;
     45  1.3  christos 
     46  1.3  christos /* Instruction Subclass.  */
     47  1.3  christos typedef enum
     48  1.3  christos   {
     49  1.3  christos     NONE,
     50  1.3  christos     CVT,
     51  1.3  christos     BTSCN,
     52  1.3  christos     CD1,
     53  1.3  christos     CD2,
     54  1.3  christos     DIV,
     55  1.3  christos     DP,
     56  1.3  christos     MPY1E,
     57  1.3  christos     MPY6E,
     58  1.3  christos     MPY7E,
     59  1.3  christos     MPY8E,
     60  1.3  christos     MPY9E,
     61  1.3  christos     SHFT1,
     62  1.3  christos     SHFT2,
     63  1.3  christos     SWAP,
     64  1.3  christos     SP
     65  1.3  christos   } insn_subclass_t;
     66  1.3  christos 
     67  1.3  christos /* Flags class.  */
     68  1.3  christos typedef enum
     69  1.3  christos   {
     70  1.3  christos     FNONE,
     71  1.3  christos     CND,  /* Conditional flags.  */
     72  1.3  christos     WBM,  /* Write-back modes.  */
     73  1.3  christos     FLG,  /* F Flag.  */
     74  1.3  christos     SBP,  /* Static branch prediction.  */
     75  1.3  christos     DLY,  /* Delay slot.  */
     76  1.3  christos     DIF,  /* Bypass caches.  */
     77  1.3  christos     SGX,  /* Sign extend modes.  */
     78  1.3  christos     SZM   /* Data size modes.  */
     79  1.3  christos   } flag_class_t;
     80  1.3  christos 
     81  1.3  christos /* The opcode table is an array of struct arc_opcode.  */
     82  1.3  christos struct arc_opcode
     83  1.3  christos {
     84  1.3  christos   /* The opcode name.  */
     85  1.3  christos   const char *name;
     86  1.3  christos 
     87  1.3  christos   /* The opcode itself.  Those bits which will be filled in with
     88  1.3  christos      operands are zeroes.  */
     89  1.3  christos   unsigned opcode;
     90  1.3  christos 
     91  1.3  christos   /* The opcode mask.  This is used by the disassembler.  This is a
     92  1.3  christos      mask containing ones indicating those bits which must match the
     93  1.3  christos      opcode field, and zeroes indicating those bits which need not
     94  1.3  christos      match (and are presumably filled in by operands).  */
     95  1.3  christos   unsigned mask;
     96  1.3  christos 
     97  1.3  christos   /* One bit flags for the opcode.  These are primarily used to
     98  1.3  christos      indicate specific processors and environments support the
     99  1.3  christos      instructions.  The defined values are listed below.  */
    100  1.3  christos   unsigned cpu;
    101  1.3  christos 
    102  1.3  christos   /* The instruction class.  This is used by gdb.  */
    103  1.3  christos   insn_class_t class;
    104  1.3  christos 
    105  1.3  christos   /* The instruction subclass.  */
    106  1.3  christos   insn_subclass_t subclass;
    107  1.3  christos 
    108  1.3  christos   /* An array of operand codes.  Each code is an index into the
    109  1.3  christos      operand table.  They appear in the order which the operands must
    110  1.3  christos      appear in assembly code, and are terminated by a zero.  */
    111  1.3  christos   unsigned char operands[MAX_INSN_ARGS + 1];
    112  1.3  christos 
    113  1.3  christos   /* An array of flag codes.  Each code is an index into the flag
    114  1.3  christos      table.  They appear in the order which the flags must appear in
    115  1.3  christos      assembly code, and are terminated by a zero.  */
    116  1.3  christos   unsigned char flags[MAX_INSN_FLGS + 1];
    117  1.1  christos };
    118  1.1  christos 
    119  1.3  christos /* The table itself is sorted by major opcode number, and is otherwise
    120  1.3  christos    in the order in which the disassembler should consider
    121  1.3  christos    instructions.  */
    122  1.3  christos extern const struct arc_opcode arc_opcodes[];
    123  1.3  christos extern const unsigned arc_num_opcodes;
    124  1.3  christos 
    125  1.3  christos /* CPU Availability.  */
    126  1.3  christos #define ARC_OPCODE_ARC600   0x0001  /* ARC 600 specific insns.  */
    127  1.3  christos #define ARC_OPCODE_ARC700   0x0002  /* ARC 700 specific insns.  */
    128  1.3  christos #define ARC_OPCODE_ARCv2EM  0x0004  /* ARCv2 EM specific insns.  */
    129  1.3  christos #define ARC_OPCODE_ARCv2HS  0x0008  /* ARCv2 HS specific insns.  */
    130  1.3  christos 
    131  1.3  christos /* CPU extensions.  */
    132  1.3  christos #define ARC_EA       0x0001
    133  1.3  christos #define ARC_CD       0x0001    /* Mutual exclusive with EA.  */
    134  1.3  christos #define ARC_LLOCK    0x0002
    135  1.3  christos #define ARC_ATOMIC   0x0002    /* Mutual exclusive with LLOCK.  */
    136  1.3  christos #define ARC_MPY      0x0004
    137  1.3  christos #define ARC_MULT     0x0004
    138  1.3  christos 
    139  1.3  christos /* Floating point support.  */
    140  1.3  christos #define ARC_DPFP     0x0010
    141  1.3  christos #define ARC_SPFP     0x0020
    142  1.3  christos #define ARC_FPU      0x0030
    143  1.3  christos 
    144  1.3  christos /* NORM & SWAP.  */
    145  1.3  christos #define ARC_SWAP     0x0100
    146  1.3  christos #define ARC_NORM     0x0200
    147  1.3  christos #define ARC_BSCAN    0x0200
    148  1.3  christos 
    149  1.3  christos /* A7 specific.  */
    150  1.3  christos #define ARC_UIX      0x1000
    151  1.3  christos #define ARC_TSTAMP   0x1000
    152  1.3  christos 
    153  1.3  christos /* A6 specific.  */
    154  1.3  christos #define ARC_VBFDW    0x1000
    155  1.3  christos #define ARC_BARREL   0x1000
    156  1.3  christos #define ARC_DSPA     0x1000
    157  1.3  christos 
    158  1.3  christos /* EM specific.  */
    159  1.3  christos #define ARC_SHIFT    0x1000
    160  1.3  christos 
    161  1.3  christos /* V2 specific.  */
    162  1.3  christos #define ARC_INTR     0x1000
    163  1.3  christos #define ARC_DIV      0x1000
    164  1.3  christos 
    165  1.3  christos /* V1 specific.  */
    166  1.3  christos #define ARC_XMAC     0x1000
    167  1.3  christos #define ARC_CRC      0x1000
    168  1.3  christos 
    169  1.3  christos /* Base architecture -- all cpus.  */
    170  1.3  christos #define ARC_OPCODE_BASE				\
    171  1.3  christos   (ARC_OPCODE_ARC600 | ARC_OPCODE_ARC700	\
    172  1.3  christos    | ARC_OPCODE_ARCv2EM | ARC_OPCODE_ARCv2HS)
    173  1.3  christos 
    174  1.3  christos /* A macro to check for short instructions.  */
    175  1.3  christos #define ARC_SHORT(mask)				\
    176  1.3  christos   (((mask) & 0xFFFF0000) ? 0 : 1)
    177  1.3  christos 
    178  1.3  christos /* The operands table is an array of struct arc_operand.  */
    179  1.3  christos struct arc_operand
    180  1.3  christos {
    181  1.3  christos   /* The number of bits in the operand.  */
    182  1.3  christos   unsigned int bits;
    183  1.3  christos 
    184  1.3  christos   /* How far the operand is left shifted in the instruction.  */
    185  1.3  christos   unsigned int shift;
    186  1.3  christos 
    187  1.3  christos   /* The default relocation type for this operand.  */
    188  1.3  christos   signed int default_reloc;
    189  1.3  christos 
    190  1.3  christos   /* One bit syntax flags.  */
    191  1.3  christos   unsigned int flags;
    192  1.3  christos 
    193  1.3  christos   /* Insertion function.  This is used by the assembler.  To insert an
    194  1.3  christos      operand value into an instruction, check this field.
    195  1.3  christos 
    196  1.3  christos      If it is NULL, execute
    197  1.3  christos 	 i |= (op & ((1 << o->bits) - 1)) << o->shift;
    198  1.3  christos      (i is the instruction which we are filling in, o is a pointer to
    199  1.3  christos      this structure, and op is the opcode value; this assumes twos
    200  1.3  christos      complement arithmetic).
    201  1.3  christos 
    202  1.3  christos      If this field is not NULL, then simply call it with the
    203  1.3  christos      instruction and the operand value.	 It will return the new value
    204  1.3  christos      of the instruction.  If the ERRMSG argument is not NULL, then if
    205  1.3  christos      the operand value is illegal, *ERRMSG will be set to a warning
    206  1.3  christos      string (the operand will be inserted in any case).	 If the
    207  1.3  christos      operand value is legal, *ERRMSG will be unchanged (most operands
    208  1.3  christos      can accept any value).  */
    209  1.3  christos   unsigned (*insert) (unsigned instruction, int op, const char **errmsg);
    210  1.3  christos 
    211  1.3  christos   /* Extraction function.  This is used by the disassembler.  To
    212  1.3  christos      extract this operand type from an instruction, check this field.
    213  1.3  christos 
    214  1.3  christos      If it is NULL, compute
    215  1.3  christos 	 op = ((i) >> o->shift) & ((1 << o->bits) - 1);
    216  1.3  christos 	 if ((o->flags & ARC_OPERAND_SIGNED) != 0
    217  1.3  christos 	     && (op & (1 << (o->bits - 1))) != 0)
    218  1.3  christos 	   op -= 1 << o->bits;
    219  1.3  christos      (i is the instruction, o is a pointer to this structure, and op
    220  1.3  christos      is the result; this assumes twos complement arithmetic).
    221  1.3  christos 
    222  1.3  christos      If this field is not NULL, then simply call it with the
    223  1.3  christos      instruction value.	 It will return the value of the operand.  If
    224  1.3  christos      the INVALID argument is not NULL, *INVALID will be set to
    225  1.3  christos      TRUE if this operand type can not actually be extracted from
    226  1.3  christos      this operand (i.e., the instruction does not match).  If the
    227  1.3  christos      operand is valid, *INVALID will not be changed.  */
    228  1.3  christos   int (*extract) (unsigned instruction, bfd_boolean *invalid);
    229  1.1  christos };
    230  1.1  christos 
    231  1.3  christos /* Elements in the table are retrieved by indexing with values from
    232  1.3  christos    the operands field of the arc_opcodes table.  */
    233  1.3  christos extern const struct arc_operand arc_operands[];
    234  1.3  christos extern const unsigned arc_num_operands;
    235  1.3  christos extern const unsigned arc_Toperand;
    236  1.3  christos extern const unsigned arc_NToperand;
    237  1.3  christos 
    238  1.3  christos /* Values defined for the flags field of a struct arc_operand.  */
    239  1.3  christos 
    240  1.3  christos /* This operand does not actually exist in the assembler input.  This
    241  1.3  christos    is used to support extended mnemonics, for which two operands fields
    242  1.3  christos    are identical.  The assembler should call the insert function with
    243  1.3  christos    any op value.  The disassembler should call the extract function,
    244  1.3  christos    ignore the return value, and check the value placed in the invalid
    245  1.3  christos    argument.  */
    246  1.3  christos #define ARC_OPERAND_FAKE	0x0001
    247  1.3  christos 
    248  1.3  christos /* This operand names an integer register.  */
    249  1.3  christos #define ARC_OPERAND_IR		0x0002
    250  1.3  christos 
    251  1.3  christos /* This operand takes signed values.  */
    252  1.3  christos #define ARC_OPERAND_SIGNED	0x0004
    253  1.3  christos 
    254  1.3  christos /* This operand takes unsigned values.  This exists primarily so that
    255  1.3  christos    a flags value of 0 can be treated as end-of-arguments.  */
    256  1.3  christos #define ARC_OPERAND_UNSIGNED	0x0008
    257  1.3  christos 
    258  1.3  christos /* This operand takes long immediate values.  */
    259  1.3  christos #define ARC_OPERAND_LIMM	0x0010
    260  1.3  christos 
    261  1.3  christos /* This operand is identical like the previous one.  */
    262  1.3  christos #define ARC_OPERAND_DUPLICATE   0x0020
    263  1.3  christos 
    264  1.3  christos /* This operand is PC relative.  Used for internal relocs.  */
    265  1.3  christos #define ARC_OPERAND_PCREL       0x0040
    266  1.3  christos 
    267  1.3  christos /* This operand is truncated.  The truncation is done accordingly to
    268  1.3  christos    operand alignment attribute.  */
    269  1.3  christos #define ARC_OPERAND_TRUNCATE    0x0080
    270  1.3  christos 
    271  1.3  christos /* This operand is 16bit aligned.  */
    272  1.3  christos #define ARC_OPERAND_ALIGNED16   0x0100
    273  1.3  christos 
    274  1.3  christos /* This operand is 32bit aligned.  */
    275  1.3  christos #define ARC_OPERAND_ALIGNED32   0x0200
    276  1.3  christos 
    277  1.3  christos /* This operand can be ignored by matching process if it is not
    278  1.3  christos    present.  */
    279  1.3  christos #define ARC_OPERAND_IGNORE      0x0400
    280  1.3  christos 
    281  1.3  christos /* Don't check the range when matching.	 */
    282  1.3  christos #define ARC_OPERAND_NCHK	0x0800
    283  1.3  christos 
    284  1.3  christos /* Mark the braket possition.  */
    285  1.3  christos #define ARC_OPERAND_BRAKET      0x1000
    286  1.3  christos 
    287  1.3  christos /* Mask for selecting the type for typecheck purposes.  */
    288  1.3  christos #define ARC_OPERAND_TYPECHECK_MASK		\
    289  1.3  christos   (ARC_OPERAND_IR |				\
    290  1.3  christos    ARC_OPERAND_LIMM | ARC_OPERAND_SIGNED | 	\
    291  1.3  christos    ARC_OPERAND_UNSIGNED | ARC_OPERAND_BRAKET)
    292  1.3  christos 
    293  1.3  christos /* The flags structure.  */
    294  1.3  christos struct arc_flag_operand
    295  1.3  christos {
    296  1.3  christos   /* The flag name.  */
    297  1.3  christos   const char *name;
    298  1.3  christos 
    299  1.3  christos   /* The flag code.  */
    300  1.3  christos   unsigned code;
    301  1.3  christos 
    302  1.3  christos   /* The number of bits in the operand.  */
    303  1.3  christos   unsigned int bits;
    304  1.3  christos 
    305  1.3  christos   /* How far the operand is left shifted in the instruction.  */
    306  1.3  christos   unsigned int shift;
    307  1.3  christos 
    308  1.3  christos   /* Available for disassembler.  */
    309  1.3  christos   unsigned char favail;
    310  1.1  christos };
    311  1.1  christos 
    312  1.3  christos /* The flag operands table.  */
    313  1.3  christos extern const struct arc_flag_operand arc_flag_operands[];
    314  1.3  christos extern const unsigned arc_num_flag_operands;
    315  1.3  christos 
    316  1.3  christos /* The flag's class structure.  */
    317  1.3  christos struct arc_flag_class
    318  1.3  christos {
    319  1.3  christos   /* Flag class.  */
    320  1.3  christos   flag_class_t class;
    321  1.1  christos 
    322  1.3  christos   /* List of valid flags (codes).  */
    323  1.3  christos   unsigned flags[256];
    324  1.3  christos };
    325  1.1  christos 
    326  1.3  christos extern const struct arc_flag_class arc_flag_classes[];
    327  1.1  christos 
    328  1.3  christos /* Structure for special cases.  */
    329  1.3  christos struct arc_flag_special
    330  1.3  christos {
    331  1.3  christos   /* Name of special case instruction.  */
    332  1.3  christos   const char *name;
    333  1.1  christos 
    334  1.3  christos   /* List of flags applicable for special case instruction.  */
    335  1.3  christos   unsigned flags[32];
    336  1.3  christos };
    337  1.1  christos 
    338  1.3  christos extern const struct arc_flag_special arc_flag_special_cases[];
    339  1.3  christos extern const unsigned arc_num_flag_special;
    340  1.1  christos 
    341  1.3  christos /* Relocation equivalence structure.  */
    342  1.3  christos struct arc_reloc_equiv_tab
    343  1.3  christos {
    344  1.3  christos   const char * name;	   /* String to lookup.  */
    345  1.3  christos   const char * mnemonic;   /* Extra matching condition.  */
    346  1.3  christos   unsigned     flagcode;   /* Extra matching condition.  */
    347  1.3  christos   signed int   oldreloc;   /* Old relocation.  */
    348  1.3  christos   signed int   newreloc;   /* New relocation.  */
    349  1.3  christos };
    350  1.1  christos 
    351  1.3  christos extern const struct arc_reloc_equiv_tab arc_reloc_equiv[];
    352  1.3  christos extern const unsigned arc_num_equiv_tab;
    353  1.1  christos 
    354  1.3  christos /* Structure for operand operations for pseudo/alias instructions.  */
    355  1.3  christos struct arc_operand_operation
    356  1.3  christos {
    357  1.3  christos   /* The index for operand from operand array.  */
    358  1.3  christos   unsigned operand_idx;
    359  1.3  christos 
    360  1.3  christos   /* Defines if it needs the operand inserted by the assembler or
    361  1.3  christos      whether this operand comes from the pseudo instruction's
    362  1.3  christos      operands.  */
    363  1.3  christos   unsigned char needs_insert;
    364  1.3  christos 
    365  1.3  christos   /* Count we have to add to the operand.  Use negative number to
    366  1.3  christos      subtract from the operand.  Also use this number to add to 0 if
    367  1.3  christos      the operand needs to be inserted (i.e. needs_insert == 1).  */
    368  1.3  christos   int count;
    369  1.3  christos 
    370  1.3  christos   /* Index of the operand to swap with.  To be done AFTER applying
    371  1.3  christos      inc_count.  */
    372  1.3  christos   unsigned swap_operand_idx;
    373  1.3  christos };
    374  1.1  christos 
    375  1.3  christos /* Structure for pseudo/alias instructions.  */
    376  1.3  christos struct arc_pseudo_insn
    377  1.3  christos {
    378  1.3  christos   /* Mnemonic for pseudo/alias insn.  */
    379  1.3  christos   const char *mnemonic_p;
    380  1.3  christos 
    381  1.3  christos   /* Mnemonic for real instruction.  */
    382  1.3  christos   const char *mnemonic_r;
    383  1.1  christos 
    384  1.3  christos   /* Flag that will have to be added (if any).  */
    385  1.3  christos   const char *flag_r;
    386  1.1  christos 
    387  1.3  christos   /* Amount of operands.  */
    388  1.3  christos   unsigned operand_cnt;
    389  1.1  christos 
    390  1.3  christos   /* Array of operand operations.  */
    391  1.3  christos   struct arc_operand_operation operand[6];
    392  1.1  christos };
    393  1.1  christos 
    394  1.3  christos extern const struct arc_pseudo_insn arc_pseudo_insns[];
    395  1.3  christos extern const unsigned arc_num_pseudo_insn;
    396  1.1  christos 
    397  1.3  christos /* Structure for AUXILIARY registers.  */
    398  1.3  christos struct arc_aux_reg
    399  1.3  christos {
    400  1.3  christos   /* Register address.  */
    401  1.3  christos   int address;
    402  1.1  christos 
    403  1.3  christos  /* Register name.  */
    404  1.3  christos   const char *name;
    405  1.1  christos 
    406  1.3  christos   /* Size of the string.  */
    407  1.3  christos   size_t length;
    408  1.3  christos };
    409  1.3  christos 
    410  1.3  christos extern const struct arc_aux_reg arc_aux_regs[];
    411  1.3  christos extern const unsigned arc_num_aux_regs;
    412  1.3  christos 
    413  1.3  christos #endif /* OPCODE_ARC_H */
    414