Home | History | Annotate | Line # | Download | only in opcode
      1   1.1  christos /* mips.h.  Mips opcode list for GDB, the GNU debugger.
      2  1.10  christos    Copyright (C) 1993-2025 Free Software Foundation, Inc.
      3   1.1  christos    Contributed by Ralph Campbell and OSF
      4   1.1  christos    Commented and modified by Ian Lance Taylor, Cygnus Support
      5   1.1  christos 
      6   1.1  christos    This file is part of GDB, GAS, and the GNU binutils.
      7   1.1  christos 
      8   1.1  christos    GDB, GAS, and the GNU binutils are free software; you can redistribute
      9   1.1  christos    them and/or modify them under the terms of the GNU General Public
     10   1.1  christos    License as published by the Free Software Foundation; either version 3,
     11   1.1  christos    or (at your option) any later version.
     12   1.1  christos 
     13   1.1  christos    GDB, GAS, and the GNU binutils are distributed in the hope that they
     14   1.1  christos    will be useful, but WITHOUT ANY WARRANTY; without even the implied
     15   1.1  christos    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     16   1.1  christos    the GNU General Public License for more details.
     17   1.1  christos 
     18   1.1  christos    You should have received a copy of the GNU General Public License
     19   1.1  christos    along with this file; see the file COPYING3.  If not, write to the Free
     20   1.1  christos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
     21   1.1  christos    MA 02110-1301, USA.  */
     22   1.1  christos 
     23   1.1  christos #ifndef _MIPS_H_
     24   1.1  christos #define _MIPS_H_
     25   1.1  christos 
     26   1.1  christos #include "bfd.h"
     27   1.1  christos 
     28   1.5  christos #ifdef __cplusplus
     29   1.5  christos extern "C" {
     30   1.5  christos #endif
     31   1.5  christos 
     32   1.1  christos /* These are bit masks and shift counts to use to access the various
     33   1.1  christos    fields of an instruction.  To retrieve the X field of an
     34   1.1  christos    instruction, use the expression
     35   1.1  christos 	(i >> OP_SH_X) & OP_MASK_X
     36   1.1  christos    To set the same field (to j), use
     37   1.1  christos 	i = (i &~ (OP_MASK_X << OP_SH_X)) | (j << OP_SH_X)
     38   1.1  christos 
     39   1.1  christos    Make sure you use fields that are appropriate for the instruction,
     40   1.1  christos    of course.
     41   1.1  christos 
     42   1.1  christos    The 'i' format uses OP, RS, RT and IMMEDIATE.
     43   1.1  christos 
     44   1.1  christos    The 'j' format uses OP and TARGET.
     45   1.1  christos 
     46   1.1  christos    The 'r' format uses OP, RS, RT, RD, SHAMT and FUNCT.
     47   1.1  christos 
     48   1.1  christos    The 'b' format uses OP, RS, RT and DELTA.
     49   1.1  christos 
     50   1.1  christos    The floating point 'i' format uses OP, RS, RT and IMMEDIATE.
     51   1.1  christos 
     52   1.1  christos    The floating point 'r' format uses OP, FMT, FT, FS, FD and FUNCT.
     53   1.1  christos 
     54   1.1  christos    A breakpoint instruction uses OP, CODE and SPEC (10 bits of the
     55   1.1  christos    breakpoint instruction are not defined; Kane says the breakpoint
     56   1.1  christos    code field in BREAK is 20 bits; yet MIPS assemblers and debuggers
     57   1.1  christos    only use ten bits).  An optional two-operand form of break/sdbbp
     58   1.1  christos    allows the lower ten bits to be set too, and MIPS32 and later
     59   1.7  christos    architectures allow 20 bits to be set with a single operand for
     60   1.7  christos    the sdbbp instruction (using CODE20).
     61   1.1  christos 
     62   1.1  christos    The syscall instruction uses CODE20.
     63   1.1  christos 
     64   1.1  christos    The general coprocessor instructions use COPZ.  */
     65   1.1  christos 
     66   1.1  christos #define OP_MASK_OP		0x3f
     67   1.1  christos #define OP_SH_OP		26
     68   1.1  christos #define OP_MASK_RS		0x1f
     69   1.1  christos #define OP_SH_RS		21
     70   1.1  christos #define OP_MASK_BCC		0x7
     71   1.1  christos #define OP_SH_BCC		18
     72   1.1  christos #define OP_MASK_RT		0x1f
     73   1.1  christos #define OP_SH_RT		16
     74   1.1  christos #define OP_MASK_RD		0x1f
     75   1.1  christos #define OP_SH_RD		11
     76   1.1  christos #define OP_MASK_IMMEDIATE	0xffff
     77   1.1  christos #define OP_SH_IMMEDIATE		0
     78   1.3  christos 
     79   1.1  christos /* Values in the 'VSEL' field.  */
     80   1.1  christos #define MDMX_FMTSEL_IMM_QH	0x1d
     81   1.1  christos #define MDMX_FMTSEL_IMM_OB	0x1e
     82   1.1  christos #define MDMX_FMTSEL_VEC_QH	0x15
     83   1.1  christos #define MDMX_FMTSEL_VEC_OB	0x16
     84   1.1  christos 
     85   1.3  christos /* Enumerates the various types of MIPS operand.  */
     86   1.3  christos enum mips_operand_type {
     87   1.3  christos   /* Described by mips_int_operand.  */
     88   1.3  christos   OP_INT,
     89   1.3  christos 
     90   1.3  christos   /* Described by mips_mapped_int_operand.  */
     91   1.3  christos   OP_MAPPED_INT,
     92   1.3  christos 
     93   1.3  christos   /* Described by mips_msb_operand.  */
     94   1.3  christos   OP_MSB,
     95   1.3  christos 
     96   1.3  christos   /* Described by mips_reg_operand.  */
     97   1.3  christos   OP_REG,
     98   1.3  christos 
     99   1.3  christos   /* Like OP_REG, but can be omitted if the register is the same as the
    100   1.3  christos      previous operand.  */
    101   1.3  christos   OP_OPTIONAL_REG,
    102   1.3  christos 
    103   1.3  christos   /* Described by mips_reg_pair_operand.  */
    104   1.3  christos   OP_REG_PAIR,
    105   1.3  christos 
    106   1.3  christos   /* Described by mips_pcrel_operand.  */
    107   1.3  christos   OP_PCREL,
    108   1.3  christos 
    109   1.3  christos   /* A performance register.  The field is 5 bits in size, but the supported
    110   1.3  christos      values are much more restricted.  */
    111   1.3  christos   OP_PERF_REG,
    112   1.3  christos 
    113   1.3  christos   /* The final operand in a microMIPS ADDIUSP instruction.  It mostly acts
    114   1.3  christos      as a normal 9-bit signed offset that is multiplied by four, but there
    115   1.3  christos      are four special cases:
    116   1.3  christos 
    117   1.3  christos      -2 * 4 => -258 * 4
    118   1.3  christos      -1 * 4 => -257 * 4
    119   1.3  christos       0 * 4 =>  256 * 4
    120   1.3  christos       1 * 4 =>  257 * 4.  */
    121   1.3  christos   OP_ADDIUSP_INT,
    122   1.3  christos 
    123   1.3  christos   /* The target of a (D)CLO or (D)CLZ instruction.  The operand spans two
    124   1.3  christos      5-bit register fields, both of which must be set to the destination
    125   1.3  christos      register.  */
    126   1.3  christos   OP_CLO_CLZ_DEST,
    127   1.3  christos 
    128   1.3  christos   /* A register list for a microMIPS LWM or SWM instruction.  The operand
    129   1.3  christos      size determines whether the 16-bit or 32-bit encoding is required.  */
    130   1.3  christos   OP_LWM_SWM_LIST,
    131   1.3  christos 
    132   1.3  christos   /* The register list for an emulated MIPS16 ENTRY or EXIT instruction.  */
    133   1.3  christos   OP_ENTRY_EXIT_LIST,
    134   1.3  christos 
    135   1.3  christos   /* The register list and frame size for a MIPS16 SAVE or RESTORE
    136   1.3  christos      instruction.  */
    137   1.3  christos   OP_SAVE_RESTORE_LIST,
    138   1.3  christos 
    139   1.3  christos   /* A 10-bit field VVVVVNNNNN used for octobyte and quadhalf instructions:
    140   1.3  christos 
    141   1.3  christos      V      Meaning
    142   1.3  christos      -----  -------
    143   1.3  christos      0EEE0  8 copies of $vN[E], OB format
    144   1.3  christos      0EE01  4 copies of $vN[E], QH format
    145   1.3  christos      10110  all 8 elements of $vN, OB format
    146   1.3  christos      10101  all 4 elements of $vN, QH format
    147   1.3  christos      11110  8 copies of immediate N, OB format
    148   1.3  christos      11101  4 copies of immediate N, QH format.  */
    149   1.3  christos   OP_MDMX_IMM_REG,
    150   1.3  christos 
    151   1.3  christos   /* A register operand that must match the destination register.  */
    152   1.3  christos   OP_REPEAT_DEST_REG,
    153   1.3  christos 
    154   1.3  christos   /* A register operand that must match the previous register.  */
    155   1.3  christos   OP_REPEAT_PREV_REG,
    156   1.3  christos 
    157   1.3  christos   /* $pc, which has no encoding in the architectural instruction.  */
    158   1.3  christos   OP_PC,
    159   1.3  christos 
    160   1.6  christos   /* $28, which has no encoding in the MIPS16e architectural instruction.  */
    161   1.6  christos   OP_REG28,
    162   1.6  christos 
    163   1.3  christos   /* A 4-bit XYZW channel mask or 2-bit XYZW index; the size determines
    164   1.3  christos      which.  */
    165   1.3  christos   OP_VU0_SUFFIX,
    166   1.3  christos 
    167   1.3  christos   /* Like OP_VU0_SUFFIX, but used when the operand's value has already
    168   1.3  christos      been set.  Any suffix used here must match the previous value.  */
    169   1.3  christos   OP_VU0_MATCH_SUFFIX,
    170   1.3  christos 
    171   1.3  christos   /* An index selected by an integer, e.g. [1].  */
    172   1.3  christos   OP_IMM_INDEX,
    173   1.3  christos 
    174   1.3  christos   /* An index selected by a register, e.g. [$2].  */
    175   1.3  christos   OP_REG_INDEX,
    176   1.3  christos 
    177   1.3  christos   /* The operand spans two 5-bit register fields, both of which must be set to
    178   1.3  christos      the source register.  */
    179   1.3  christos   OP_SAME_RS_RT,
    180   1.3  christos 
    181   1.3  christos   /* Described by mips_prev_operand.  */
    182   1.3  christos   OP_CHECK_PREV,
    183   1.3  christos 
    184   1.3  christos   /* A register operand that must not be zero.  */
    185   1.3  christos   OP_NON_ZERO_REG
    186   1.3  christos };
    187   1.3  christos 
    188   1.3  christos /* Enumerates the types of MIPS register.  */
    189   1.3  christos enum mips_reg_operand_type {
    190   1.3  christos   /* General registers $0-$31.  Software names like $at can also be used.  */
    191   1.3  christos   OP_REG_GP,
    192   1.3  christos 
    193   1.3  christos   /* Floating-point registers $f0-$f31.  */
    194   1.3  christos   OP_REG_FP,
    195   1.3  christos 
    196   1.3  christos   /* Coprocessor condition code registers $cc0-$cc7.  FPU condition codes
    197   1.3  christos      can also be written $fcc0-$fcc7.  */
    198   1.3  christos   OP_REG_CCC,
    199   1.3  christos 
    200   1.3  christos   /* FPRs used in a vector capacity.  They can be written $f0-$f31
    201   1.3  christos      or $v0-$v31, although the latter form is not used for the VR5400
    202   1.3  christos      vector instructions.  */
    203   1.3  christos   OP_REG_VEC,
    204   1.3  christos 
    205   1.3  christos   /* DSP accumulator registers $ac0-$ac3.  */
    206   1.3  christos   OP_REG_ACC,
    207   1.3  christos 
    208   1.3  christos   /* Coprocessor registers $0-$31.  Mnemonic names like c0_cause can
    209   1.3  christos      also be used in some contexts.  */
    210   1.3  christos   OP_REG_COPRO,
    211   1.3  christos 
    212   1.8  christos   /* Coprocessor control registers $0-$31.  Mnemonic names like c1_fcsr can
    213   1.8  christos      also be used in some contexts.  */
    214   1.8  christos   OP_REG_CONTROL,
    215   1.8  christos 
    216   1.3  christos   /* Hardware registers $0-$31.  Mnemonic names like hwr_cpunum can
    217   1.3  christos      also be used in some contexts.  */
    218   1.3  christos   OP_REG_HW,
    219   1.3  christos 
    220   1.3  christos   /* Floating-point registers $vf0-$vf31.  */
    221   1.3  christos   OP_REG_VF,
    222   1.3  christos 
    223   1.3  christos   /* Integer registers $vi0-$vi31.  */
    224   1.3  christos   OP_REG_VI,
    225   1.3  christos 
    226   1.3  christos   /* R5900 VU0 registers $I, $Q, $R and $ACC.  */
    227   1.3  christos   OP_REG_R5900_I,
    228   1.3  christos   OP_REG_R5900_Q,
    229   1.3  christos   OP_REG_R5900_R,
    230   1.3  christos   OP_REG_R5900_ACC,
    231   1.3  christos 
    232   1.3  christos   /* MSA registers $w0-$w31.  */
    233   1.3  christos   OP_REG_MSA,
    234   1.3  christos 
    235   1.3  christos   /* MSA control registers $0-$31.  */
    236   1.3  christos   OP_REG_MSA_CTRL
    237   1.3  christos };
    238   1.3  christos 
    239   1.3  christos /* Base class for all operands.  */
    240   1.3  christos struct mips_operand
    241   1.3  christos {
    242   1.3  christos   /* The type of the operand.  */
    243   1.3  christos   enum mips_operand_type type;
    244   1.3  christos 
    245   1.3  christos   /* The operand occupies SIZE bits of the instruction, starting at LSB.  */
    246   1.3  christos   unsigned short size;
    247   1.3  christos   unsigned short lsb;
    248   1.3  christos };
    249   1.3  christos 
    250   1.3  christos /* Describes an integer operand with a regular encoding pattern.  */
    251   1.3  christos struct mips_int_operand
    252   1.3  christos {
    253   1.3  christos   struct mips_operand root;
    254   1.3  christos 
    255   1.3  christos   /* The low ROOT.SIZE bits of MAX_VAL encodes (MAX_VAL + BIAS) << SHIFT.
    256   1.3  christos      The cyclically previous field value encodes 1 << SHIFT less than that,
    257   1.3  christos      and so on.  E.g.
    258   1.3  christos 
    259   1.3  christos      - for { { T, 4, L }, 14, 0, 0 }, field values 0...14 encode themselves,
    260   1.3  christos        but 15 encodes -1.
    261   1.3  christos 
    262   1.3  christos      - { { T, 8, L }, 127, 0, 2 } is a normal signed 8-bit operand that is
    263   1.3  christos        shifted left two places.
    264   1.3  christos 
    265   1.3  christos      - { { T, 3, L }, 8, 0, 0 } is a normal unsigned 3-bit operand except
    266   1.3  christos        that 0 encodes 8.
    267   1.3  christos 
    268   1.3  christos      - { { ... }, 0, 1, 3 } means that N encodes (N + 1) << 3.  */
    269   1.3  christos   unsigned int max_val;
    270   1.3  christos   int bias;
    271   1.3  christos   unsigned int shift;
    272   1.3  christos 
    273   1.3  christos   /* True if the operand should be printed as hex rather than decimal.  */
    274   1.8  christos   bool print_hex;
    275   1.3  christos };
    276   1.3  christos 
    277   1.3  christos /* Uses a lookup table to describe a small integer operand.  */
    278   1.3  christos struct mips_mapped_int_operand
    279   1.3  christos {
    280   1.3  christos   struct mips_operand root;
    281   1.3  christos 
    282   1.3  christos   /* Maps each encoding value to the integer that it represents.  */
    283   1.3  christos   const int *int_map;
    284   1.3  christos 
    285   1.3  christos   /* True if the operand should be printed as hex rather than decimal.  */
    286   1.8  christos   bool print_hex;
    287   1.3  christos };
    288   1.3  christos 
    289   1.3  christos /* An operand that encodes the most significant bit position of a bitfield.
    290   1.3  christos    Given a bitfield that spans bits [MSB, LSB], some operands of this type
    291   1.3  christos    encode MSB directly while others encode MSB - LSB.  Each operand of this
    292   1.3  christos    type is preceded by an integer operand that specifies LSB.
    293   1.3  christos 
    294   1.3  christos    The assembly form varies between instructions.  For some instructions,
    295   1.3  christos    such as EXT, the operand is written as the bitfield size.  For others,
    296   1.3  christos    such as EXTS, it is written in raw MSB - LSB form.  */
    297   1.3  christos struct mips_msb_operand
    298   1.3  christos {
    299   1.3  christos   struct mips_operand root;
    300   1.3  christos 
    301   1.3  christos   /* The assembly-level operand encoded by a field value of 0.  */
    302   1.3  christos   int bias;
    303   1.3  christos 
    304   1.3  christos   /* True if the operand encodes MSB directly, false if it encodes
    305   1.3  christos      MSB - LSB.  */
    306   1.8  christos   bool add_lsb;
    307   1.3  christos 
    308   1.3  christos   /* The maximum value of MSB + 1.  */
    309   1.3  christos   unsigned int opsize;
    310   1.3  christos };
    311   1.3  christos 
    312   1.3  christos /* Describes a single register operand.  */
    313   1.3  christos struct mips_reg_operand
    314   1.3  christos {
    315   1.3  christos   struct mips_operand root;
    316   1.3  christos 
    317   1.3  christos   /* The type of register.  */
    318   1.3  christos   enum mips_reg_operand_type reg_type;
    319   1.3  christos 
    320   1.3  christos   /* If nonnull, REG_MAP[N] gives the register associated with encoding N,
    321   1.3  christos      otherwise the encoding is the same as the register number.  */
    322   1.3  christos   const unsigned char *reg_map;
    323   1.3  christos };
    324   1.3  christos 
    325   1.3  christos /* Describes an operand that which must match a condition based on the
    326   1.3  christos    previous operand.  */
    327   1.3  christos struct mips_check_prev_operand
    328   1.3  christos {
    329   1.3  christos   struct mips_operand root;
    330   1.3  christos 
    331   1.8  christos   bool greater_than_ok;
    332   1.8  christos   bool less_than_ok;
    333   1.8  christos   bool equal_ok;
    334   1.8  christos   bool zero_ok;
    335   1.3  christos };
    336   1.3  christos 
    337   1.3  christos /* Describes an operand that encodes a pair of registers.  */
    338   1.3  christos struct mips_reg_pair_operand
    339   1.3  christos {
    340   1.3  christos   struct mips_operand root;
    341   1.3  christos 
    342   1.3  christos   /* The type of register.  */
    343   1.3  christos   enum mips_reg_operand_type reg_type;
    344   1.3  christos 
    345   1.3  christos   /* Encoding N represents REG1_MAP[N], REG2_MAP[N].  */
    346   1.3  christos   unsigned char *reg1_map;
    347   1.3  christos   unsigned char *reg2_map;
    348   1.3  christos };
    349   1.3  christos 
    350   1.3  christos /* Describes an operand that is calculated relative to a base PC.
    351   1.3  christos    The base PC is usually the address of the following instruction,
    352   1.3  christos    but the rules for MIPS16 instructions like ADDIUPC are more complicated.  */
    353   1.3  christos struct mips_pcrel_operand
    354   1.3  christos {
    355   1.3  christos   /* Encodes the offset.  */
    356   1.3  christos   struct mips_int_operand root;
    357   1.3  christos 
    358   1.3  christos   /* The low ALIGN_LOG2 bits of the base PC are cleared to give PC',
    359   1.3  christos      which is then added to the offset encoded by ROOT.  */
    360   1.3  christos   unsigned int align_log2 : 8;
    361   1.3  christos 
    362   1.3  christos   /* If INCLUDE_ISA_BIT, the ISA bit of the original base PC is then
    363   1.3  christos      reinstated.  This is true for jumps and branches and false for
    364   1.3  christos      PC-relative data instructions.  */
    365   1.3  christos   unsigned int include_isa_bit : 1;
    366   1.3  christos 
    367   1.3  christos   /* If FLIP_ISA_BIT, the ISA bit of the result is inverted.
    368   1.3  christos      This is true for JALX and false otherwise.  */
    369   1.3  christos   unsigned int flip_isa_bit : 1;
    370   1.3  christos };
    371   1.3  christos 
    372   1.3  christos /* Return true if the assembly syntax allows OPERAND to be omitted.  */
    373   1.3  christos 
    374   1.8  christos static inline bool
    375   1.3  christos mips_optional_operand_p (const struct mips_operand *operand)
    376   1.3  christos {
    377   1.3  christos   return (operand->type == OP_OPTIONAL_REG
    378   1.3  christos 	  || operand->type == OP_REPEAT_PREV_REG);
    379   1.3  christos }
    380   1.3  christos 
    381   1.3  christos /* Return a version of INSN in which the field specified by OPERAND
    382   1.3  christos    has value UVAL.  */
    383   1.3  christos 
    384   1.3  christos static inline unsigned int
    385   1.3  christos mips_insert_operand (const struct mips_operand *operand, unsigned int insn,
    386   1.3  christos 		     unsigned int uval)
    387   1.3  christos {
    388   1.3  christos   unsigned int mask;
    389   1.3  christos 
    390   1.3  christos   mask = (1 << operand->size) - 1;
    391   1.3  christos   insn &= ~(mask << operand->lsb);
    392   1.3  christos   insn |= (uval & mask) << operand->lsb;
    393   1.3  christos   return insn;
    394   1.3  christos }
    395   1.3  christos 
    396   1.3  christos /* Extract OPERAND from instruction INSN.  */
    397   1.3  christos 
    398   1.3  christos static inline unsigned int
    399   1.3  christos mips_extract_operand (const struct mips_operand *operand, unsigned int insn)
    400   1.3  christos {
    401   1.3  christos   return (insn >> operand->lsb) & ((1 << operand->size) - 1);
    402   1.3  christos }
    403   1.3  christos 
    404   1.3  christos /* UVAL is the value encoded by OPERAND.  Return it in signed form.  */
    405   1.3  christos 
    406   1.3  christos static inline int
    407   1.3  christos mips_signed_operand (const struct mips_operand *operand, unsigned int uval)
    408   1.3  christos {
    409   1.3  christos   unsigned int sign_bit, mask;
    410   1.3  christos 
    411   1.3  christos   mask = (1 << operand->size) - 1;
    412   1.3  christos   sign_bit = 1 << (operand->size - 1);
    413   1.3  christos   return ((uval + sign_bit) & mask) - sign_bit;
    414   1.3  christos }
    415   1.3  christos 
    416   1.3  christos /* Return the integer that OPERAND encodes as UVAL.  */
    417   1.3  christos 
    418   1.3  christos static inline int
    419   1.3  christos mips_decode_int_operand (const struct mips_int_operand *operand,
    420   1.3  christos 			 unsigned int uval)
    421   1.3  christos {
    422   1.3  christos   uval |= (operand->max_val - uval) & -(1 << operand->root.size);
    423   1.3  christos   uval += operand->bias;
    424   1.3  christos   uval <<= operand->shift;
    425   1.3  christos   return uval;
    426   1.3  christos }
    427   1.3  christos 
    428   1.3  christos /* Return the maximum value that can be encoded by OPERAND.  */
    429   1.3  christos 
    430   1.3  christos static inline int
    431   1.3  christos mips_int_operand_max (const struct mips_int_operand *operand)
    432   1.3  christos {
    433   1.3  christos   return (operand->max_val + operand->bias) << operand->shift;
    434   1.3  christos }
    435   1.3  christos 
    436   1.3  christos /* Return the minimum value that can be encoded by OPERAND.  */
    437   1.3  christos 
    438   1.3  christos static inline int
    439   1.3  christos mips_int_operand_min (const struct mips_int_operand *operand)
    440   1.3  christos {
    441   1.3  christos   unsigned int mask;
    442   1.3  christos 
    443   1.3  christos   mask = (1 << operand->root.size) - 1;
    444   1.3  christos   return mips_int_operand_max (operand) - (mask << operand->shift);
    445   1.3  christos }
    446   1.3  christos 
    447   1.3  christos /* Return the register that OPERAND encodes as UVAL.  */
    448   1.3  christos 
    449   1.3  christos static inline int
    450   1.3  christos mips_decode_reg_operand (const struct mips_reg_operand *operand,
    451   1.3  christos 			 unsigned int uval)
    452   1.3  christos {
    453   1.3  christos   if (operand->reg_map)
    454   1.3  christos     uval = operand->reg_map[uval];
    455   1.3  christos   return uval;
    456   1.3  christos }
    457   1.3  christos 
    458   1.3  christos /* PC-relative operand OPERAND has value UVAL and is relative to BASE_PC.
    459   1.3  christos    Return the address that it encodes.  */
    460   1.3  christos 
    461   1.3  christos static inline bfd_vma
    462   1.3  christos mips_decode_pcrel_operand (const struct mips_pcrel_operand *operand,
    463   1.3  christos 			   bfd_vma base_pc, unsigned int uval)
    464   1.3  christos {
    465   1.3  christos   bfd_vma addr;
    466   1.3  christos 
    467   1.3  christos   addr = base_pc & -(1 << operand->align_log2);
    468   1.3  christos   addr += mips_decode_int_operand (&operand->root, uval);
    469   1.3  christos   if (operand->include_isa_bit)
    470   1.3  christos     addr |= base_pc & 1;
    471   1.3  christos   if (operand->flip_isa_bit)
    472   1.3  christos     addr ^= 1;
    473   1.3  christos   return addr;
    474   1.3  christos }
    475   1.3  christos 
    476   1.1  christos /* This structure holds information for a particular instruction.  */
    477   1.1  christos 
    478   1.1  christos struct mips_opcode
    479   1.1  christos {
    480   1.1  christos   /* The name of the instruction.  */
    481   1.1  christos   const char *name;
    482   1.1  christos   /* A string describing the arguments for this instruction.  */
    483   1.1  christos   const char *args;
    484   1.1  christos   /* The basic opcode for the instruction.  When assembling, this
    485   1.1  christos      opcode is modified by the arguments to produce the actual opcode
    486   1.1  christos      that is used.  If pinfo is INSN_MACRO, then this is 0.  */
    487   1.1  christos   unsigned long match;
    488   1.1  christos   /* If pinfo is not INSN_MACRO, then this is a bit mask for the
    489   1.1  christos      relevant portions of the opcode when disassembling.  If the
    490   1.1  christos      actual opcode anded with the match field equals the opcode field,
    491   1.1  christos      then we have found the correct instruction.  If pinfo is
    492   1.1  christos      INSN_MACRO, then this field is the macro identifier.  */
    493   1.1  christos   unsigned long mask;
    494   1.1  christos   /* For a macro, this is INSN_MACRO.  Otherwise, it is a collection
    495   1.1  christos      of bits describing the instruction, notably any relevant hazard
    496   1.1  christos      information.  */
    497   1.1  christos   unsigned long pinfo;
    498   1.1  christos   /* A collection of additional bits describing the instruction. */
    499   1.1  christos   unsigned long pinfo2;
    500   1.1  christos   /* A collection of bits describing the instruction sets of which this
    501   1.1  christos      instruction or macro is a member. */
    502   1.1  christos   unsigned long membership;
    503   1.3  christos   /* A collection of bits describing the ASE of which this instruction
    504   1.3  christos      or macro is a member.  */
    505   1.3  christos   unsigned long ase;
    506   1.1  christos   /* A collection of bits describing the instruction sets of which this
    507   1.1  christos      instruction or macro is not a member.  */
    508   1.1  christos   unsigned long exclusions;
    509   1.1  christos };
    510   1.1  christos 
    511   1.6  christos /* Return true if MO is an instruction that requires 32-bit encoding.  */
    512   1.6  christos 
    513   1.8  christos static inline bool
    514   1.6  christos mips_opcode_32bit_p (const struct mips_opcode *mo)
    515   1.6  christos {
    516   1.6  christos   return mo->mask >> 16 != 0;
    517   1.6  christos }
    518   1.6  christos 
    519  1.10  christos /* These are the characters which may appear in the args field of a
    520  1.10  christos    regular MIPS instruction.  They appear in the order in which the fields
    521  1.10  christos    appear when the instruction is used.  Commas and parentheses in the
    522  1.10  christos    args string are ignored when assembling, and written into the output
    523   1.1  christos    when disassembling.
    524   1.1  christos 
    525  1.10  christos    "1" 5-bit SYNC type at bit 6.
    526  1.10  christos    "<" 5-bit shift amount at bit 6 (SHAMT).
    527  1.10  christos    ">" Shift amount between 32 and 63, stored after subtracting 32, at bit 6
    528  1.10  christos        (SHAMT).
    529  1.10  christos    "a" 26-bit target address at bit 0 (TARGET).
    530  1.10  christos    "+i" Likewise, but flips bit 0.
    531  1.10  christos    "b" 5-bit base register at bit 21 (RS).
    532  1.10  christos    "c" 10-bit breakpoint code at bit 16.
    533  1.10  christos    "d" 5-bit destination register at bit 11 (RD).
    534  1.10  christos    "h" 5-bit PREFX hint at bit 11.
    535  1.10  christos    "i" 16-bit unsigned immediate at bit 0 (IMMEDIATE).
    536  1.10  christos    "j" 16-bit signed immediate at bit 0 (DELTA).
    537  1.10  christos    "k" 5-bit CACHE opcode in target register position at bit 16.
    538  1.10  christos    "o" 16-bit signed offset at bit 0 (DELTA).
    539  1.10  christos    "p" 16-bit PC relative branch target address at bit 0 (DELTA).
    540  1.10  christos    "q" 10-bit extra breakpoint code at bit 6.
    541  1.10  christos    "r" 5-bit same register used as both source and target at bit 21 (RS).
    542  1.10  christos    "s" 5-bit source register at bit 21 (RS).
    543  1.10  christos    "t" 5-bit target register at bit 16 (RT).
    544  1.10  christos    "u" 16-bit upper 16 bits of address at bit 0 (IMMEDIATE).
    545  1.10  christos    "v" 5-bit same register used as both source and destination at bit 21 (RS).
    546  1.10  christos    "w" 5-bit same register used as both target and destination at bit 16 (RT).
    547  1.10  christos    "U" 5-bit same destination register at both bit 11 and 16 (both RD and RT)
    548  1.10  christos        (used by CLO and CLZ).
    549  1.10  christos    "C" 25-bit coprocessor function code at bit 0.
    550  1.10  christos    "B" 20-bit syscall/breakpoint function code at bit 6.
    551  1.10  christos    "J" 19-bit WAIT function code at bit 6.
    552  1.10  christos    "x" Accept and ignore register name.
    553  1.10  christos    "z" Must be zero register.
    554  1.10  christos    "K" 5-bit Hardware Register (RDHWR instruction) at bit 11 (RD).
    555  1.10  christos    "+A" 5-bit INS/EXT/DINS/DEXT/DINSM/DEXTM position at bit 6,
    556  1.10  christos 	which becomes LSB (SHAMT).
    557   1.1  christos 	Enforces: 0 <= pos < 32.
    558  1.10  christos    "+B" 5-bit INS/DINS size at bit 11, which becomes MSB.
    559   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
    560   1.1  christos 	Enforces: 0 < (pos+size) <= 32.
    561  1.10  christos    "+C" 5-bit EXT/DEXT size at bit 11, which becomes MSBD.
    562   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
    563   1.1  christos 	Enforces: 0 < (pos+size) <= 32.
    564  1.10  christos 	(Also used by DEXT w/ different limits, but limits for
    565   1.1  christos 	that are checked by the M_DEXT macro.)
    566  1.10  christos    "+E" 5-bit DINSU/DEXTU position at bit 6, which becomes LSB-32 (SHAMT).
    567   1.1  christos 	Enforces: 32 <= pos < 64.
    568  1.10  christos    "+F" 5-bit DINSM/DINSU size at bit 11, which becomes MSB-32.
    569   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
    570   1.1  christos 	Enforces: 32 < (pos+size) <= 64.
    571  1.10  christos    "+G" 5-bit DEXTM size at bit 11, which becomes MSBD-32.
    572   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
    573   1.1  christos 	Enforces: 32 < (pos+size) <= 64.
    574  1.10  christos    "+H" 5-bit DEXTU size at bit 11, which becomes MSBD.
    575   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
    576   1.1  christos 	Enforces: 32 < (pos+size) <= 64.
    577   1.1  christos 
    578   1.1  christos    Floating point instructions:
    579  1.10  christos    "D" 5-bit destination register at bit 6 (FD).
    580  1.10  christos    "M" 3-bit compare condition code at bit 8 (only used for mips4 and up).
    581  1.10  christos    "N" 3-bit branch condition code at bit 18 (only used for mips4 and up).
    582  1.10  christos    "S" 5-bit fs source 1 register at bit 11 (FS).
    583  1.10  christos    "T" 5-bit ft source 2 register at bit 16 (FT).
    584  1.10  christos    "R" 5-bit fr source 3 register at bit 21 (FR).
    585  1.10  christos    "V" 5-bit same register used as floating source and destination at bit 11
    586  1.10  christos        (FS).
    587  1.10  christos    "W" 5-bit same register used as floating target and destination at bit 16
    588  1.10  christos        (FT).
    589   1.1  christos 
    590   1.1  christos    Coprocessor instructions:
    591  1.10  christos    "E" 5-bit target register at bit 16 (RT).
    592  1.10  christos    "G" 5-bit destination register at bit 11 (RD).
    593  1.10  christos    "H" 3-bit sel field for (D)MTC* and (D)MFC* at bit 0.
    594  1.10  christos    "P" 5-bit performance-monitor register at bit 1.
    595  1.10  christos    "e" 3-bit vector register byte specifier at bit 22.
    596  1.10  christos    "g" 5-bit control destination register at bit 11 (RD).
    597  1.10  christos    "%" 3-bit immediate vr5400 vector alignment operand at bit 21.
    598   1.1  christos 
    599   1.1  christos    Macro instructions:
    600  1.10  christos    "A" General 32-bit expression.
    601  1.10  christos    "I" 32-bit immediate (value placed in imm_expr).
    602  1.10  christos    "F" 64-bit floating point constant in .rdata.
    603  1.10  christos    "L" 64-bit floating point constant in .lit8.
    604  1.10  christos    "f" 32-bit floating point constant.
    605  1.10  christos    "l" 32-bit floating point constant in .lit4.
    606   1.1  christos 
    607   1.3  christos    MDMX and VR5400 instruction operands (note that while these use the
    608   1.3  christos    FP register fields, the MDMX instructions accept both $fN and $vN names
    609   1.3  christos    for the registers):
    610  1.10  christos    "O" 3-bit alignment offset at bit 21.
    611  1.10  christos    "Q" 10-bit vector/scalar/immediate source at bit 16.
    612  1.10  christos    "X" 5-bit destination register at bit 6 (FD).
    613  1.10  christos    "Y" 5-bit source register at bit 11 (FS).
    614  1.10  christos    "Z" 5-bit source register at bit 16 (FT).
    615   1.3  christos 
    616   1.3  christos    R5900 VU0 Macromode instructions:
    617  1.10  christos    "+5" 5-bit floating point register at bit 6 (FD).
    618  1.10  christos    "+6" 5-bit floating point register at bit 11 (FS).
    619  1.10  christos    "+7" 5-bit floating point register at bit 16 (FT).
    620  1.10  christos    "+8" 5-bit integer register at bit 6 (FD).
    621  1.10  christos    "+9" 5-bit integer register at bit 11 (FS).
    622  1.10  christos    "+0" 5-bit integer register at bit 16 (FT).
    623  1.10  christos    "+K" Match an existing 4-bit channel mask starting at bit 21.
    624  1.10  christos    "+L" 2-bit channel index starting at bit 21.
    625  1.10  christos    "+M" 2-bit channel index starting at bit 23.
    626  1.10  christos    "+N" Match an existing 2-bit channel index starting at bit 0.
    627  1.10  christos    "+f" 15-bit immediate for VCALLMS at bit 6.
    628  1.10  christos    "+g" 5-bit signed immediate for VIADDI at bit 6.
    629  1.10  christos    "+m" $ACC register (syntax only).
    630  1.10  christos    "+q" $Q register (syntax only).
    631  1.10  christos    "+r" $R register (syntax only).
    632  1.10  christos    "+y" $I register (syntax only).
    633  1.10  christos    "#+" "++" decorator in ($reg++) sequence.
    634  1.10  christos    "#-" "--" decorator in (--$reg) sequence.
    635   1.1  christos 
    636   1.1  christos    DSP ASE usage:
    637  1.10  christos    "2" 2-bit unsigned immediate for byte align at bit 11.
    638  1.10  christos    "3" 3-bit unsigned immediate at bit 21.
    639  1.10  christos    "4" 4-bit unsigned immediate at bit 21.
    640  1.10  christos    "5" 8-bit unsigned immediate at bit 16.
    641  1.10  christos    "6" 5-bit unsigned immediate at bit 21 (RS).
    642  1.10  christos    "7" 2-bit DSP accumulator register at bit 11.
    643  1.10  christos    "8" 6-bit unsigned immediate at bit 11.
    644  1.10  christos    "9" 2-bit DSP accumulator register at bit 21.
    645  1.10  christos    "0" 6-bit signed immediate at bit 20.
    646  1.10  christos    ":" 7-bit signed immediate at bit 19.
    647  1.10  christos    "'" 6-bit unsigned immediate at bit 16.
    648  1.10  christos    "@" 10-bit signed immediate at bit 16.
    649   1.1  christos 
    650   1.1  christos    MT ASE usage:
    651  1.10  christos    "!" 1-bit usermode flag at bit 5.
    652  1.10  christos    "$" 1-bit load high flag at bit 4.
    653  1.10  christos    "*" 2-bit DSP/SmartMIPS accumulator register at bit 18.
    654  1.10  christos    "&" 2-bit DSP/SmartMIPS accumulator register at bit 13.
    655  1.10  christos    "y" 5-bit control target register at bit 16 (RT).
    656   1.1  christos 
    657   1.1  christos    MCU ASE usage:
    658  1.10  christos    "~" 12-bit offset at bit 0.
    659  1.10  christos    "\" 3-bit position for ASET and ACLR at bit 12.
    660   1.1  christos 
    661   1.3  christos    VIRT ASE usage:
    662  1.10  christos    "+J" 10-bit HYPCALL code at bit 11.
    663   1.3  christos 
    664   1.1  christos    UDI immediates:
    665  1.10  christos    "+1" UDI immediate bits 6-10.
    666  1.10  christos    "+2" UDI immediate bits 6-15.
    667  1.10  christos    "+3" UDI immediate bits 6-20.
    668  1.10  christos    "+4" UDI immediate bits 6-25.
    669   1.1  christos 
    670   1.1  christos    Octeon:
    671  1.10  christos    "+x" Bit index field of BBITx at bit 16.
    672  1.10  christos 	Enforces: 0 <= index < 32.
    673  1.10  christos    "+X" Bit index field of BBITx aliasing BBITx32 at bit 16.
    674  1.10  christos 	Matches if 32 <= index < 64, otherwise skips to next candidate.
    675  1.10  christos    "+p" Position field of CINS/CINS32/EXTS/EXTS32 at bit 6.
    676  1.10  christos 	Enforces 0 <= pos < 32.
    677  1.10  christos    "+P" Position field of CINS/EXTS aliasing CINS32/EXTS32 at bit 6.
    678  1.10  christos 	Matches if 32 <= pos < 64, otherwise skips to next candidate.
    679  1.10  christos    "+Q" Immediate field of SEQI/SNEI at bit 6.
    680  1.10  christos 	Enforces -512 <= imm < 512.
    681  1.10  christos    "+s" Length-minus-one field of CINS32/EXTS32 at bit 11.
    682  1.10  christos 	Requires MSB position of the field to be <= 31.
    683  1.10  christos    "+S" Length-minus-one field of CINS/EXTS at bit 11.
    684  1.10  christos 	Requires MSB position of the field to be <= 63.
    685   1.1  christos 
    686   1.7  christos    Loongson-ext ASE:
    687  1.10  christos    "+a" 8-bit signed offset at bit 6.
    688  1.10  christos    "+b" 8-bit signed offset at bit 3.
    689  1.10  christos    "+c" 9-bit signed offset at bit 6.
    690  1.10  christos    "+z" 5-bit rz register at bit 0.
    691  1.10  christos    "+Z" 5-bit fz register at bit 0.
    692   1.1  christos 
    693   1.6  christos    interAptiv MR2:
    694  1.10  christos    "-m" Register list for SAVE/RESTORE instruction.
    695   1.6  christos 
    696   1.3  christos    Enhanced VA Scheme:
    697  1.10  christos    "+j" 9-bit signed offset at bit 7.
    698   1.3  christos 
    699   1.3  christos    MSA Extension:
    700  1.10  christos    "+d" 5-bit MSA register at bit 6 (FD).
    701  1.10  christos    "+e" 5-bit MSA register at bit 11 (FS).
    702  1.10  christos    "+h" 5-bit MSA register at bit 16 (FT).
    703  1.10  christos    "+k" 5-bit GPR at bit 6.
    704  1.10  christos    "+l" 5-bit MSA control register at bit 6.
    705  1.10  christos    "+n" 5-bit MSA control register at bit 11.
    706  1.10  christos    "+o" 4-bit vector element index at bit 16.
    707  1.10  christos    "+u" 3-bit vector element index at bit 16.
    708  1.10  christos    "+v" 2-bit vector element index at bit 16.
    709  1.10  christos    "+w" 1-bit vector element index at bit 16.
    710  1.10  christos    "+T" (-512 .. 511) << 0 at bit 16.
    711  1.10  christos    "+U" (-512 .. 511) << 1 at bit 16.
    712  1.10  christos    "+V" (-512 .. 511) << 2 at bit 16.
    713  1.10  christos    "+W" (-512 .. 511) << 3 at bit 16.
    714  1.10  christos    "+~" 2-bit LSA/DLSA shift amount from 1 to 4 at bit 6.
    715  1.10  christos    "+!" 3-bit unsigned bit position at bit 16.
    716  1.10  christos    "+@" 4-bit unsigned bit position at bit 16.
    717  1.10  christos    "+#" 6-bit unsigned bit position at bit 16.
    718  1.10  christos    "+$" 5-bit unsigned immediate at bit 16.
    719  1.10  christos    "+%" 5-bit signed immediate at bit 16.
    720  1.10  christos    "+^" 10-bit signed immediate at bit 11.
    721  1.10  christos    "+&" 0 vector element index.
    722  1.10  christos    "+*" 5-bit register vector element index at bit 16.
    723  1.10  christos    "+|" 8-bit mask at bit 16.
    724   1.3  christos 
    725   1.3  christos    MIPS R6:
    726  1.10  christos    "+:" 11-bit mask at bit 0.
    727  1.10  christos    "+'" 26-bit PC relative branch target address at bit 0.
    728  1.10  christos    "+"" 21-bit PC relative branch target address at bit 0.
    729  1.10  christos    "+;" 5-bit same register at both bit 16 and 21 (both RT and RS).
    730  1.10  christos    "+I" 2-bit unsigned bit position at bit 6.
    731  1.10  christos    "+O" 3-bit unsigned bit position at bit 6.
    732  1.10  christos    "+R" Must be program counter.
    733  1.10  christos    "-a" (-262144 .. 262143) << 2 at bit 0.
    734  1.10  christos    "-b" (-131072 .. 131071) << 3 at bit 0.
    735  1.10  christos    "-d" Same as destination register GP.
    736  1.10  christos    "-s" 5-bit source register at bit 21 (RS) not $0.
    737  1.10  christos    "-t" 5-bit target register at bit 16 (RT) not $0
    738  1.10  christos    "-u" 5-bit target register at bit 16 (RT) greater than RS.
    739  1.10  christos    "-v" 5-bit target register at bit 16 (RT) not $0 not RS.
    740  1.10  christos    "-w" 5-bit target register at bit 16 (RT) less than or equal to RS.
    741  1.10  christos    "-x" 5-bit source register at bit 21 (RS) greater than RT.
    742  1.10  christos    "-y" 5-bit source register at bit 21 (RS) not $0 less than RT.
    743  1.10  christos    "-A" Symbolic offset (-262144 .. 262143) << 2 at bit 0.
    744  1.10  christos    "-B" Symbolic offset (-131072 .. 131071) << 3 at bit 0.
    745   1.3  christos 
    746   1.6  christos    GINV ASE usage:
    747  1.10  christos    "+\" 2-bit Global TLB invalidate type at bit 8.
    748   1.6  christos 
    749   1.1  christos    Other:
    750  1.10  christos    "()" Parens surrounding optional value.
    751  1.10  christos    ","  Separates operands.
    752   1.1  christos    "+"  Start of extension sequence.
    753  1.10  christos    "-"  Start of extension sequence.
    754   1.1  christos 
    755   1.1  christos    Characters used so far, for quick reference when adding more:
    756   1.1  christos    "1234567890"
    757   1.3  christos    "%[]<>(),+-:'@!#$*&\~"
    758   1.1  christos    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    759   1.8  christos    "abcdef hijkl  opqrstuvwxyz"
    760   1.1  christos 
    761   1.1  christos    Extension character sequences used so far ("+" followed by the
    762   1.1  christos    following), for quick reference when adding more:
    763   1.3  christos    "1234567890"
    764   1.6  christos    "~!@#$%^&*|:'";\"
    765  1.10  christos    "ABC EFGHIJKLMNOPQRSTUVWX Z"
    766  1.10  christos    "abcdefghijklmnopqrs uvwxyz"
    767   1.3  christos 
    768   1.3  christos    Extension character sequences used so far ("-" followed by the
    769   1.3  christos    following), for quick reference when adding more:
    770  1.10  christos    "AB                        "
    771  1.10  christos    "ab d        m     stuvwxy "
    772   1.1  christos */
    773   1.1  christos 
    774   1.1  christos /* These are the bits which may be set in the pinfo field of an
    775   1.1  christos    instructions, if it is not equal to INSN_MACRO.  */
    776   1.1  christos 
    777   1.3  christos /* Writes to operand number N.  */
    778   1.3  christos #define INSN_WRITE_SHIFT            0
    779   1.3  christos #define INSN_WRITE_1                0x00000001
    780   1.3  christos #define INSN_WRITE_2                0x00000002
    781   1.3  christos #define INSN_WRITE_ALL              0x00000003
    782   1.3  christos /* Reads from operand number N.  */
    783   1.3  christos #define INSN_READ_SHIFT             2
    784   1.3  christos #define INSN_READ_1                 0x00000004
    785   1.3  christos #define INSN_READ_2                 0x00000008
    786   1.3  christos #define INSN_READ_3                 0x00000010
    787   1.3  christos #define INSN_READ_4                 0x00000020
    788   1.3  christos #define INSN_READ_ALL               0x0000003c
    789   1.1  christos /* Modifies general purpose register 31.  */
    790   1.3  christos #define INSN_WRITE_GPR_31           0x00000040
    791   1.1  christos /* Modifies coprocessor condition code.  */
    792   1.3  christos #define INSN_WRITE_COND_CODE        0x00000080
    793   1.1  christos /* Reads coprocessor condition code.  */
    794   1.3  christos #define INSN_READ_COND_CODE         0x00000100
    795   1.1  christos /* TLB operation.  */
    796   1.3  christos #define INSN_TLB                    0x00000200
    797   1.1  christos /* Reads coprocessor register other than floating point register.  */
    798   1.3  christos #define INSN_COP                    0x00000400
    799   1.3  christos /* Instruction loads value from memory.  */
    800   1.3  christos #define INSN_LOAD_MEMORY	    0x00000800
    801   1.3  christos /* Instruction loads value from coprocessor, (may require delay).  */
    802   1.3  christos #define INSN_LOAD_COPROC	    0x00001000
    803   1.1  christos /* Instruction has unconditional branch delay slot.  */
    804   1.3  christos #define INSN_UNCOND_BRANCH_DELAY    0x00002000
    805   1.1  christos /* Instruction has conditional branch delay slot.  */
    806   1.3  christos #define INSN_COND_BRANCH_DELAY      0x00004000
    807   1.1  christos /* Conditional branch likely: if branch not taken, insn nullified.  */
    808   1.3  christos #define INSN_COND_BRANCH_LIKELY	    0x00008000
    809   1.3  christos /* Moves to coprocessor register, (may require delay).  */
    810   1.3  christos #define INSN_COPROC_MOVE            0x00010000
    811   1.1  christos /* Loads coprocessor register from memory, requiring delay.  */
    812   1.3  christos #define INSN_COPROC_MEMORY_DELAY    0x00020000
    813   1.1  christos /* Reads the HI register.  */
    814   1.3  christos #define INSN_READ_HI		    0x00040000
    815   1.1  christos /* Reads the LO register.  */
    816   1.3  christos #define INSN_READ_LO		    0x00080000
    817   1.1  christos /* Modifies the HI register.  */
    818   1.3  christos #define INSN_WRITE_HI		    0x00100000
    819   1.1  christos /* Modifies the LO register.  */
    820   1.3  christos #define INSN_WRITE_LO		    0x00200000
    821   1.1  christos /* Not to be placed in a branch delay slot, either architecturally
    822   1.1  christos    or for ease of handling (such as with instructions that take a trap).  */
    823   1.3  christos #define INSN_NO_DELAY_SLOT	    0x00400000
    824   1.1  christos /* Instruction stores value into memory.  */
    825   1.3  christos #define INSN_STORE_MEMORY	    0x00800000
    826   1.1  christos /* Instruction uses single precision floating point.  */
    827   1.3  christos #define FP_S			    0x01000000
    828   1.1  christos /* Instruction uses double precision floating point.  */
    829   1.3  christos #define FP_D			    0x02000000
    830   1.1  christos /* Instruction is part of the tx39's integer multiply family.    */
    831   1.3  christos #define INSN_MULT                   0x04000000
    832   1.3  christos /* Reads general purpose register 24.  */
    833   1.3  christos #define INSN_READ_GPR_24            0x08000000
    834   1.3  christos /* Writes to general purpose register 24.  */
    835   1.3  christos #define INSN_WRITE_GPR_24           0x10000000
    836   1.3  christos /* A user-defined instruction.  */
    837   1.3  christos #define INSN_UDI                    0x20000000
    838   1.1  christos /* Instruction is actually a macro.  It should be ignored by the
    839   1.1  christos    disassembler, and requires special treatment by the assembler.  */
    840   1.1  christos #define INSN_MACRO                  0xffffffff
    841   1.1  christos 
    842   1.1  christos /* These are the bits which may be set in the pinfo2 field of an
    843   1.1  christos    instruction. */
    844   1.1  christos 
    845   1.1  christos /* Instruction is a simple alias (I.E. "move" for daddu/addu/or) */
    846   1.1  christos #define	INSN2_ALIAS		    0x00000001
    847   1.1  christos /* Instruction reads MDMX accumulator. */
    848   1.1  christos #define INSN2_READ_MDMX_ACC	    0x00000002
    849   1.1  christos /* Instruction writes MDMX accumulator. */
    850   1.1  christos #define INSN2_WRITE_MDMX_ACC	    0x00000004
    851   1.1  christos /* Macro uses single-precision floating-point instructions.  This should
    852   1.1  christos    only be set for macros.  For instructions, FP_S in pinfo carries the
    853   1.1  christos    same information.  */
    854   1.1  christos #define INSN2_M_FP_S		    0x00000008
    855   1.1  christos /* Macro uses double-precision floating-point instructions.  This should
    856   1.1  christos    only be set for macros.  For instructions, FP_D in pinfo carries the
    857   1.1  christos    same information.  */
    858   1.1  christos #define INSN2_M_FP_D		    0x00000010
    859   1.1  christos /* Instruction has a branch delay slot that requires a 16-bit instruction.  */
    860   1.3  christos #define INSN2_BRANCH_DELAY_16BIT    0x00000020
    861   1.1  christos /* Instruction has a branch delay slot that requires a 32-bit instruction.  */
    862   1.3  christos #define INSN2_BRANCH_DELAY_32BIT    0x00000040
    863   1.3  christos /* Writes to the stack pointer ($29).  */
    864   1.3  christos #define INSN2_WRITE_SP		    0x00000080
    865   1.3  christos /* Reads from the stack pointer ($29).  */
    866   1.3  christos #define INSN2_READ_SP		    0x00000100
    867   1.1  christos /* Reads the RA ($31) register.  */
    868   1.3  christos #define INSN2_READ_GPR_31	    0x00000200
    869   1.1  christos /* Reads the program counter ($pc).  */
    870   1.3  christos #define INSN2_READ_PC		    0x00000400
    871   1.1  christos /* Is an unconditional branch insn. */
    872   1.3  christos #define INSN2_UNCOND_BRANCH	    0x00000800
    873   1.1  christos /* Is a conditional branch insn. */
    874   1.3  christos #define INSN2_COND_BRANCH	    0x00001000
    875   1.3  christos /* Reads from $16.  This is true of the MIPS16 0x6500 nop.  */
    876   1.3  christos #define INSN2_READ_GPR_16           0x00002000
    877   1.3  christos /* Has an "\.x?y?z?w?" suffix based on mips_vu0_channel_mask.  */
    878   1.3  christos #define INSN2_VU0_CHANNEL_SUFFIX    0x00004000
    879   1.3  christos /* Instruction has a forbidden slot.  */
    880   1.3  christos #define INSN2_FORBIDDEN_SLOT        0x00008000
    881   1.6  christos /* Opcode table entry is for a short MIPS16 form only.  An extended
    882   1.6  christos    encoding may still exist, but with a separate opcode table entry
    883   1.6  christos    required.  In disassembly the presence of this flag in an otherwise
    884   1.6  christos    successful match against an extended instruction encoding inhibits
    885   1.6  christos    matching against any subsequent short table entry even if it does
    886   1.6  christos    not have this flag set.  A table entry matching the full extended
    887   1.6  christos    encoding is needed or otherwise the final EXTEND entry will apply,
    888   1.6  christos    for the disassembly of the prefix only.  */
    889   1.6  christos #define INSN2_SHORT_ONLY	    0x00010000
    890   1.1  christos 
    891   1.1  christos /* Masks used to mark instructions to indicate which MIPS ISA level
    892   1.1  christos    they were introduced in.  INSN_ISA_MASK masks an enumeration that
    893   1.1  christos    specifies the base ISA level(s).  The remainder of a 32-bit
    894   1.1  christos    word constructed using these macros is a bitmask of the remaining
    895  1.10  christos    INSN_* values below, as indicated by INSN_CHIP_MASK.  */
    896   1.1  christos 
    897   1.3  christos #define INSN_ISA_MASK		  0x0000001ful
    898   1.1  christos 
    899   1.1  christos /* We cannot start at zero due to ISA_UNKNOWN below.  */
    900   1.1  christos #define INSN_ISA1                 1
    901   1.1  christos #define INSN_ISA2                 2
    902   1.1  christos #define INSN_ISA3                 3
    903   1.1  christos #define INSN_ISA4                 4
    904   1.1  christos #define INSN_ISA5                 5
    905   1.1  christos #define INSN_ISA32                6
    906   1.1  christos #define INSN_ISA32R2              7
    907   1.3  christos #define INSN_ISA32R3              8
    908   1.3  christos #define INSN_ISA32R5              9
    909   1.3  christos #define INSN_ISA32R6              10
    910   1.3  christos #define INSN_ISA64                11
    911   1.3  christos #define INSN_ISA64R2              12
    912   1.3  christos #define INSN_ISA64R3              13
    913   1.3  christos #define INSN_ISA64R5              14
    914   1.3  christos #define INSN_ISA64R6              15
    915   1.1  christos /* Below this point the INSN_* values correspond to combinations of ISAs.
    916   1.1  christos    They are only for use in the opcodes table to indicate membership of
    917   1.1  christos    a combination of ISAs that cannot be expressed using the usual inclusion
    918   1.1  christos    ordering on the above INSN_* values.  */
    919   1.3  christos #define INSN_ISA3_32              16
    920   1.3  christos #define INSN_ISA3_32R2            17
    921   1.3  christos #define INSN_ISA4_32              18
    922   1.3  christos #define INSN_ISA4_32R2            19
    923   1.3  christos #define INSN_ISA5_32R2            20
    924   1.3  christos 
    925   1.3  christos /* The R6 definitions shown below state that they support all previous ISAs.
    926   1.3  christos    This is not actually true as some instructions are removed in R6.
    927   1.3  christos    The problem is that the removed instructions in R6 come from different
    928   1.3  christos    ISAs.  One approach to solve this would be to describe in the membership
    929   1.3  christos    field of the opcode table the different ISAs an instruction belongs to.
    930   1.3  christos    This would require us to create a large amount of different ISA
    931   1.3  christos    combinations which is hard to manage.  A cleaner approach (which is
    932   1.3  christos    implemented here) is to say that R6 is an extension of R5 and then to
    933   1.3  christos    deal with the removed instructions by adding instruction exclusions
    934   1.3  christos    for R6 in the opcode table.  */
    935   1.3  christos 
    936   1.3  christos /* Bit INSN_ISA<X> - 1 of INSN_UPTO<Y> is set if ISA Y includes ISA X.  */
    937   1.3  christos 
    938   1.3  christos #define ISAF(X) (1 << (INSN_ISA##X - 1))
    939   1.3  christos #define INSN_UPTO1    ISAF(1)
    940   1.3  christos #define INSN_UPTO2    INSN_UPTO1 | ISAF(2)
    941   1.3  christos #define INSN_UPTO3    INSN_UPTO2 | ISAF(3) | ISAF(3_32) | ISAF(3_32R2)
    942   1.3  christos #define INSN_UPTO4    INSN_UPTO3 | ISAF(4) | ISAF(4_32) | ISAF(4_32R2)
    943   1.3  christos #define INSN_UPTO5    INSN_UPTO4 | ISAF(5) | ISAF(5_32R2)
    944   1.3  christos #define INSN_UPTO32   INSN_UPTO2 | ISAF(32) | ISAF(3_32) | ISAF(4_32)
    945   1.3  christos #define INSN_UPTO32R2 INSN_UPTO32 | ISAF(32R2) \
    946   1.3  christos 			| ISAF(3_32R2) | ISAF(4_32R2) | ISAF(5_32R2)
    947   1.3  christos #define INSN_UPTO32R3 INSN_UPTO32R2 | ISAF(32R3)
    948   1.3  christos #define INSN_UPTO32R5 INSN_UPTO32R3 | ISAF(32R5)
    949   1.3  christos #define INSN_UPTO32R6 INSN_UPTO32R5 | ISAF(32R6)
    950   1.3  christos #define INSN_UPTO64   INSN_UPTO5 | ISAF(64) | ISAF(32)
    951   1.3  christos #define INSN_UPTO64R2 INSN_UPTO64 | ISAF(64R2) | ISAF(32R2)
    952   1.3  christos #define INSN_UPTO64R3 INSN_UPTO64R2 | ISAF(64R3) | ISAF(32R3)
    953   1.3  christos #define INSN_UPTO64R5 INSN_UPTO64R3 | ISAF(64R5) | ISAF(32R5)
    954   1.3  christos #define INSN_UPTO64R6 INSN_UPTO64R5 | ISAF(64R6) | ISAF(32R6)
    955   1.3  christos 
    956   1.3  christos /* The same information in table form: bit INSN_ISA<X> - 1 of index
    957   1.3  christos    INSN_UPTO<Y> - 1 is set if ISA Y includes ISA X.  */
    958   1.3  christos static const unsigned int mips_isa_table[] = {
    959   1.3  christos   INSN_UPTO1,
    960   1.3  christos   INSN_UPTO2,
    961   1.3  christos   INSN_UPTO3,
    962   1.3  christos   INSN_UPTO4,
    963   1.3  christos   INSN_UPTO5,
    964   1.3  christos   INSN_UPTO32,
    965   1.3  christos   INSN_UPTO32R2,
    966   1.3  christos   INSN_UPTO32R3,
    967   1.3  christos   INSN_UPTO32R5,
    968   1.3  christos   INSN_UPTO32R6,
    969   1.3  christos   INSN_UPTO64,
    970   1.3  christos   INSN_UPTO64R2,
    971   1.3  christos   INSN_UPTO64R3,
    972   1.3  christos   INSN_UPTO64R5,
    973   1.3  christos   INSN_UPTO64R6
    974   1.3  christos };
    975   1.3  christos #undef ISAF
    976   1.1  christos 
    977   1.1  christos /* Masks used for Chip specific instructions.  */
    978  1.10  christos #define INSN_CHIP_MASK		0x01ffffe0
    979   1.1  christos 
    980   1.1  christos /* MIPS R4650 instruction.  */
    981  1.10  christos #define INSN_4650		0x00000020
    982   1.1  christos /* LSI R4010 instruction.  */
    983  1.10  christos #define INSN_4010		0x00000040
    984   1.1  christos /* NEC VR4100 instruction.  */
    985  1.10  christos #define INSN_4100		0x00000080
    986   1.1  christos /* Toshiba R3900 instruction.  */
    987  1.10  christos #define INSN_3900		0x00000100
    988   1.1  christos /* MIPS R10000 instruction.  */
    989  1.10  christos #define INSN_10000		0x00000200
    990   1.1  christos /* Broadcom SB-1 instruction.  */
    991  1.10  christos #define INSN_SB1		0x00000400
    992   1.1  christos /* NEC VR4111/VR4181 instruction.  */
    993  1.10  christos #define INSN_4111		0x00000800
    994   1.1  christos /* NEC VR4120 instruction.  */
    995  1.10  christos #define INSN_4120		0x00001000
    996   1.1  christos /* NEC VR5400 instruction.  */
    997  1.10  christos #define INSN_5400		0x00002000
    998   1.1  christos /* NEC VR5500 instruction.  */
    999  1.10  christos #define INSN_5500		0x00004000
   1000  1.10  christos /* MIPS R5900 instruction.  */
   1001  1.10  christos #define INSN_5900		0x00008000
   1002   1.1  christos /* ST Microelectronics Loongson 2E.  */
   1003  1.10  christos #define INSN_LOONGSON_2E	0x00010000
   1004   1.1  christos /* ST Microelectronics Loongson 2F.  */
   1005  1.10  christos #define INSN_LOONGSON_2F	0x00020000
   1006  1.10  christos /* Cavium Networks Octeon instructions.  */
   1007  1.10  christos #define INSN_OCTEON		0x00040000
   1008  1.10  christos #define INSN_OCTEONP		0x00080000
   1009  1.10  christos #define INSN_OCTEON2		0x00100000
   1010  1.10  christos #define INSN_OCTEON3		0x00200000
   1011  1.10  christos /* RMI XLR instruction.  */
   1012  1.10  christos #define INSN_XLR		0x00400000
   1013   1.6  christos /* Imagination interAptiv MR2.  */
   1014  1.10  christos #define INSN_INTERAPTIV_MR2	0x00800000
   1015   1.9  christos /* Sony PSP Allegrex instruction.  */
   1016  1.10  christos #define INSN_ALLEGREX		0x01000000
   1017   1.1  christos 
   1018   1.3  christos /* DSP ASE */
   1019   1.3  christos #define ASE_DSP			0x00000001
   1020   1.3  christos #define ASE_DSP64		0x00000002
   1021   1.3  christos /* DSP R2 ASE  */
   1022   1.3  christos #define ASE_DSPR2		0x00000004
   1023   1.3  christos /* Enhanced VA Scheme */
   1024   1.3  christos #define ASE_EVA			0x00000008
   1025   1.1  christos /* MCU (MicroController) ASE */
   1026   1.3  christos #define ASE_MCU			0x00000010
   1027   1.3  christos /* MDMX ASE */
   1028   1.3  christos #define ASE_MDMX		0x00000020
   1029   1.3  christos /* MIPS-3D ASE */
   1030   1.3  christos #define ASE_MIPS3D		0x00000040
   1031   1.3  christos /* MT ASE */
   1032   1.3  christos #define ASE_MT			0x00000080
   1033   1.3  christos /* SmartMIPS ASE  */
   1034   1.3  christos #define ASE_SMARTMIPS		0x00000100
   1035   1.3  christos /* Virtualization ASE */
   1036   1.3  christos #define ASE_VIRT		0x00000200
   1037   1.3  christos #define ASE_VIRT64		0x00000400
   1038   1.3  christos /* MSA Extension  */
   1039   1.3  christos #define ASE_MSA			0x00000800
   1040   1.3  christos #define ASE_MSA64		0x00001000
   1041   1.3  christos /* eXtended Physical Address (XPA) Extension.  */
   1042   1.3  christos #define ASE_XPA			0x00002000
   1043   1.6  christos /* DSP R3 Module.  */
   1044   1.5  christos #define ASE_DSPR3		0x00004000
   1045   1.6  christos /* MIPS16e2 ASE.  */
   1046   1.6  christos #define ASE_MIPS16E2		0x00008000
   1047   1.6  christos /* MIPS16e2 MT ASE instructions.  */
   1048   1.6  christos #define ASE_MIPS16E2_MT		0x00010000
   1049   1.6  christos /* The Virtualization ASE has eXtended Physical Addressing (XPA)
   1050   1.6  christos    instructions which are only valid when both ASEs are enabled.  */
   1051   1.6  christos #define ASE_XPA_VIRT		0x00020000
   1052   1.6  christos /* Cyclic redundancy check (CRC) ASE.  */
   1053   1.6  christos #define ASE_CRC			0x00040000
   1054   1.6  christos #define ASE_CRC64		0x00080000
   1055   1.6  christos /* Global INValidate Extension.  */
   1056   1.6  christos #define ASE_GINV		0x00100000
   1057   1.7  christos /* Loongson MultiMedia extensions Instructions (MMI).  */
   1058   1.7  christos #define ASE_LOONGSON_MMI	0x00200000
   1059   1.7  christos /* Loongson Content Address Memory (CAM).  */
   1060   1.7  christos #define ASE_LOONGSON_CAM	0x00400000
   1061   1.7  christos /* Loongson EXTensions (EXT) instructions.  */
   1062   1.7  christos #define ASE_LOONGSON_EXT	0x00800000
   1063   1.7  christos /* Loongson EXTensions R2 (EXT2) instructions.  */
   1064   1.7  christos #define ASE_LOONGSON_EXT2	0x01000000
   1065   1.7  christos /* The Enhanced VA Scheme (EVA) extension has instructions which are
   1066   1.7  christos    only valid for the R6 ISA.  */
   1067   1.7  christos #define ASE_EVA_R6		0x02000000
   1068   1.1  christos 
   1069   1.1  christos /* MIPS ISA defines, use instead of hardcoding ISA level.  */
   1070   1.1  christos 
   1071   1.1  christos #define       ISA_UNKNOWN     0               /* Gas internal use.  */
   1072   1.1  christos #define       ISA_MIPS1       INSN_ISA1
   1073   1.1  christos #define       ISA_MIPS2       INSN_ISA2
   1074   1.1  christos #define       ISA_MIPS3       INSN_ISA3
   1075   1.1  christos #define       ISA_MIPS4       INSN_ISA4
   1076   1.1  christos #define       ISA_MIPS5       INSN_ISA5
   1077   1.1  christos 
   1078   1.1  christos #define       ISA_MIPS32      INSN_ISA32
   1079   1.1  christos #define       ISA_MIPS64      INSN_ISA64
   1080   1.1  christos 
   1081   1.1  christos #define       ISA_MIPS32R2    INSN_ISA32R2
   1082   1.3  christos #define       ISA_MIPS32R3    INSN_ISA32R3
   1083   1.3  christos #define       ISA_MIPS32R5    INSN_ISA32R5
   1084   1.1  christos #define       ISA_MIPS64R2    INSN_ISA64R2
   1085   1.3  christos #define       ISA_MIPS64R3    INSN_ISA64R3
   1086   1.3  christos #define       ISA_MIPS64R5    INSN_ISA64R5
   1087   1.1  christos 
   1088   1.3  christos #define       ISA_MIPS32R6    INSN_ISA32R6
   1089   1.3  christos #define       ISA_MIPS64R6    INSN_ISA64R6
   1090   1.1  christos 
   1091   1.1  christos /* CPU defines, use instead of hardcoding processor number. Keep this
   1092   1.1  christos    in sync with bfd/archures.c in order for machine selection to work.  */
   1093   1.1  christos #define CPU_UNKNOWN	0               /* Gas internal use.  */
   1094   1.1  christos #define CPU_R3000	3000
   1095   1.1  christos #define CPU_R3900	3900
   1096   1.1  christos #define CPU_R4000	4000
   1097   1.1  christos #define CPU_R4010	4010
   1098   1.1  christos #define CPU_VR4100	4100
   1099   1.1  christos #define CPU_R4111	4111
   1100   1.1  christos #define CPU_VR4120	4120
   1101   1.1  christos #define CPU_R4300	4300
   1102   1.1  christos #define CPU_R4400	4400
   1103   1.1  christos #define CPU_R4600	4600
   1104   1.1  christos #define CPU_R4650	4650
   1105   1.1  christos #define CPU_R5000	5000
   1106   1.1  christos #define CPU_VR5400	5400
   1107   1.1  christos #define CPU_VR5500	5500
   1108   1.3  christos #define CPU_R5900	5900
   1109   1.1  christos #define CPU_R6000	6000
   1110   1.1  christos #define CPU_RM7000	7000
   1111   1.1  christos #define CPU_R8000	8000
   1112   1.1  christos #define CPU_RM9000	9000
   1113   1.1  christos #define CPU_R10000	10000
   1114   1.1  christos #define CPU_R12000	12000
   1115   1.1  christos #define CPU_R14000	14000
   1116   1.1  christos #define CPU_R16000	16000
   1117   1.1  christos #define CPU_MIPS16	16
   1118   1.1  christos #define CPU_MIPS32	32
   1119   1.1  christos #define CPU_MIPS32R2	33
   1120   1.3  christos #define CPU_MIPS32R3	34
   1121   1.3  christos #define CPU_MIPS32R5	36
   1122   1.3  christos #define CPU_MIPS32R6	37
   1123   1.1  christos #define CPU_MIPS5       5
   1124   1.1  christos #define CPU_MIPS64      64
   1125   1.1  christos #define CPU_MIPS64R2	65
   1126   1.3  christos #define CPU_MIPS64R3	66
   1127   1.3  christos #define CPU_MIPS64R5	68
   1128   1.3  christos #define CPU_MIPS64R6	69
   1129   1.9  christos #define CPU_ALLEGREX	10111431	/* octal 'AL', 31. */
   1130   1.1  christos #define CPU_SB1         12310201        /* octal 'SB', 01.  */
   1131   1.1  christos #define CPU_LOONGSON_2E 3001
   1132   1.1  christos #define CPU_LOONGSON_2F 3002
   1133   1.7  christos #define CPU_GS464	3003
   1134   1.7  christos #define CPU_GS464E	3004
   1135   1.7  christos #define CPU_GS264E	3005
   1136   1.1  christos #define CPU_OCTEON	6501
   1137   1.1  christos #define CPU_OCTEONP	6601
   1138   1.1  christos #define CPU_OCTEON2	6502
   1139   1.3  christos #define CPU_OCTEON3	6503
   1140   1.1  christos #define CPU_XLR     	887682   	/* decimal 'XLR'   */
   1141   1.6  christos #define CPU_INTERAPTIV_MR2 736550	/* decimal 'IA2'  */
   1142   1.1  christos 
   1143   1.1  christos /* Return true if the given CPU is included in INSN_* mask MASK.  */
   1144   1.1  christos 
   1145   1.8  christos static inline bool
   1146   1.1  christos cpu_is_member (int cpu, unsigned int mask)
   1147   1.1  christos {
   1148   1.1  christos   switch (cpu)
   1149   1.1  christos     {
   1150   1.1  christos     case CPU_R4650:
   1151   1.1  christos     case CPU_RM7000:
   1152   1.1  christos     case CPU_RM9000:
   1153   1.1  christos       return (mask & INSN_4650) != 0;
   1154   1.1  christos 
   1155   1.1  christos     case CPU_R4010:
   1156   1.1  christos       return (mask & INSN_4010) != 0;
   1157   1.1  christos 
   1158   1.1  christos     case CPU_VR4100:
   1159   1.1  christos       return (mask & INSN_4100) != 0;
   1160   1.1  christos 
   1161   1.1  christos     case CPU_R3900:
   1162   1.1  christos       return (mask & INSN_3900) != 0;
   1163   1.1  christos 
   1164   1.1  christos     case CPU_R10000:
   1165   1.1  christos     case CPU_R12000:
   1166   1.1  christos     case CPU_R14000:
   1167   1.1  christos     case CPU_R16000:
   1168   1.1  christos       return (mask & INSN_10000) != 0;
   1169   1.1  christos 
   1170   1.1  christos     case CPU_SB1:
   1171   1.1  christos       return (mask & INSN_SB1) != 0;
   1172   1.1  christos 
   1173   1.1  christos     case CPU_R4111:
   1174   1.1  christos       return (mask & INSN_4111) != 0;
   1175   1.1  christos 
   1176   1.1  christos     case CPU_VR4120:
   1177   1.1  christos       return (mask & INSN_4120) != 0;
   1178   1.1  christos 
   1179   1.1  christos     case CPU_VR5400:
   1180   1.1  christos       return (mask & INSN_5400) != 0;
   1181   1.1  christos 
   1182   1.1  christos     case CPU_VR5500:
   1183   1.1  christos       return (mask & INSN_5500) != 0;
   1184   1.1  christos 
   1185   1.3  christos     case CPU_R5900:
   1186   1.3  christos       return (mask & INSN_5900) != 0;
   1187   1.3  christos 
   1188   1.1  christos     case CPU_LOONGSON_2E:
   1189   1.1  christos       return (mask & INSN_LOONGSON_2E) != 0;
   1190   1.1  christos 
   1191   1.1  christos     case CPU_LOONGSON_2F:
   1192   1.1  christos       return (mask & INSN_LOONGSON_2F) != 0;
   1193   1.1  christos 
   1194   1.1  christos     case CPU_OCTEON:
   1195   1.1  christos       return (mask & INSN_OCTEON) != 0;
   1196   1.1  christos 
   1197   1.1  christos     case CPU_OCTEONP:
   1198   1.1  christos       return (mask & INSN_OCTEONP) != 0;
   1199   1.1  christos 
   1200   1.1  christos     case CPU_OCTEON2:
   1201   1.1  christos       return (mask & INSN_OCTEON2) != 0;
   1202   1.1  christos 
   1203   1.3  christos     case CPU_OCTEON3:
   1204   1.3  christos       return (mask & INSN_OCTEON3) != 0;
   1205   1.3  christos 
   1206   1.1  christos     case CPU_XLR:
   1207   1.1  christos       return (mask & INSN_XLR) != 0;
   1208   1.1  christos 
   1209   1.6  christos     case CPU_INTERAPTIV_MR2:
   1210   1.6  christos       return (mask & INSN_INTERAPTIV_MR2) != 0;
   1211   1.6  christos 
   1212   1.9  christos     case CPU_ALLEGREX:
   1213   1.9  christos       return (mask & INSN_ALLEGREX) != 0;
   1214   1.9  christos 
   1215   1.8  christos     default:
   1216   1.8  christos       return false;
   1217   1.8  christos     }
   1218   1.8  christos }
   1219   1.8  christos 
   1220   1.8  christos /* Return true if the given ISA is included in INSN_* mask MASK.  */
   1221   1.8  christos 
   1222   1.8  christos static inline bool
   1223   1.8  christos isa_is_member (int isa, unsigned int mask)
   1224   1.8  christos {
   1225   1.8  christos   isa &= INSN_ISA_MASK;
   1226   1.8  christos   mask &= INSN_ISA_MASK;
   1227   1.3  christos 
   1228   1.8  christos   if (isa == 0)
   1229   1.8  christos     return false;
   1230   1.3  christos 
   1231   1.8  christos   if (mask == 0)
   1232   1.8  christos     return false;
   1233   1.8  christos 
   1234   1.8  christos   if (((mips_isa_table[isa - 1] >> (mask - 1)) & 1) == 0)
   1235   1.8  christos     return false;
   1236   1.8  christos 
   1237   1.8  christos   return true;
   1238   1.1  christos }
   1239   1.1  christos 
   1240   1.1  christos /* Test for membership in an ISA including chip specific ISAs.  INSN
   1241   1.1  christos    is pointer to an element of the opcode table; ISA is the specified
   1242   1.1  christos    ISA/ASE bitmask to test against; and CPU is the CPU specific ISA to
   1243   1.1  christos    test, or zero if no CPU specific ISA test is desired.  Return true
   1244   1.1  christos    if instruction INSN is available to the given ISA and CPU. */
   1245   1.1  christos 
   1246   1.8  christos static inline bool
   1247   1.3  christos opcode_is_member (const struct mips_opcode *insn, int isa, int ase, int cpu)
   1248   1.1  christos {
   1249   1.8  christos   /* Test for ISA level exclusion.  */
   1250   1.8  christos   if (isa_is_member (isa, insn->exclusions))
   1251   1.8  christos     return false;
   1252   1.8  christos 
   1253   1.8  christos   /* Test for processor-specific exclusion.  */
   1254   1.8  christos   if (cpu_is_member (cpu, insn->exclusions))
   1255   1.8  christos     return false;
   1256   1.8  christos 
   1257   1.8  christos   /* Test for ISA level compatibility.  */
   1258   1.8  christos   if (isa_is_member (isa, insn->membership))
   1259   1.8  christos     return true;
   1260   1.8  christos 
   1261   1.8  christos   /* Test for ASE compatibility.  */
   1262   1.8  christos   if ((ase & insn->ase) != 0)
   1263   1.8  christos     return true;
   1264   1.8  christos 
   1265   1.8  christos   /* Test for processor-specific extensions.  */
   1266   1.8  christos   if (cpu_is_member (cpu, insn->membership))
   1267   1.8  christos     return true;
   1268   1.8  christos 
   1269   1.8  christos   return false;
   1270   1.1  christos }
   1271   1.1  christos 
   1272   1.1  christos /* This is a list of macro expanded instructions.
   1273   1.1  christos 
   1274   1.1  christos    _I appended means immediate
   1275   1.3  christos    _A appended means target address of a jump
   1276   1.3  christos    _AB appended means address with (possibly zero) base register
   1277   1.1  christos    _D appended means 64 bit floating point constant
   1278   1.1  christos    _S appended means 32 bit floating point constant.  */
   1279   1.1  christos 
   1280   1.1  christos enum
   1281   1.1  christos {
   1282   1.1  christos   M_ABS,
   1283   1.1  christos   M_ACLR_AB,
   1284   1.1  christos   M_ADD_I,
   1285   1.1  christos   M_ADDU_I,
   1286   1.1  christos   M_AND_I,
   1287   1.1  christos   M_ASET_AB,
   1288   1.1  christos   M_BALIGN,
   1289   1.1  christos   M_BC1FL,
   1290   1.1  christos   M_BC1TL,
   1291   1.1  christos   M_BC2FL,
   1292   1.1  christos   M_BC2TL,
   1293   1.1  christos   M_BEQ,
   1294   1.1  christos   M_BEQ_I,
   1295   1.1  christos   M_BEQL,
   1296   1.1  christos   M_BEQL_I,
   1297   1.1  christos   M_BGE,
   1298   1.1  christos   M_BGEL,
   1299   1.1  christos   M_BGE_I,
   1300   1.1  christos   M_BGEL_I,
   1301   1.1  christos   M_BGEU,
   1302   1.1  christos   M_BGEUL,
   1303   1.1  christos   M_BGEU_I,
   1304   1.1  christos   M_BGEUL_I,
   1305   1.1  christos   M_BGEZ,
   1306   1.1  christos   M_BGEZL,
   1307   1.1  christos   M_BGEZALL,
   1308   1.1  christos   M_BGT,
   1309   1.1  christos   M_BGTL,
   1310   1.1  christos   M_BGT_I,
   1311   1.1  christos   M_BGTL_I,
   1312   1.1  christos   M_BGTU,
   1313   1.1  christos   M_BGTUL,
   1314   1.1  christos   M_BGTU_I,
   1315   1.1  christos   M_BGTUL_I,
   1316   1.1  christos   M_BGTZ,
   1317   1.1  christos   M_BGTZL,
   1318   1.1  christos   M_BLE,
   1319   1.1  christos   M_BLEL,
   1320   1.1  christos   M_BLE_I,
   1321   1.1  christos   M_BLEL_I,
   1322   1.1  christos   M_BLEU,
   1323   1.1  christos   M_BLEUL,
   1324   1.1  christos   M_BLEU_I,
   1325   1.1  christos   M_BLEUL_I,
   1326   1.1  christos   M_BLEZ,
   1327   1.1  christos   M_BLEZL,
   1328   1.1  christos   M_BLT,
   1329   1.1  christos   M_BLTL,
   1330   1.1  christos   M_BLT_I,
   1331   1.1  christos   M_BLTL_I,
   1332   1.1  christos   M_BLTU,
   1333   1.1  christos   M_BLTUL,
   1334   1.1  christos   M_BLTU_I,
   1335   1.1  christos   M_BLTUL_I,
   1336   1.1  christos   M_BLTZ,
   1337   1.1  christos   M_BLTZL,
   1338   1.1  christos   M_BLTZALL,
   1339   1.1  christos   M_BNE,
   1340   1.1  christos   M_BNEL,
   1341   1.1  christos   M_BNE_I,
   1342   1.1  christos   M_BNEL_I,
   1343   1.1  christos   M_CACHE_AB,
   1344   1.3  christos   M_CACHEE_AB,
   1345   1.1  christos   M_DABS,
   1346   1.1  christos   M_DADD_I,
   1347   1.1  christos   M_DADDU_I,
   1348   1.1  christos   M_DDIV_3,
   1349   1.1  christos   M_DDIV_3I,
   1350   1.1  christos   M_DDIVU_3,
   1351   1.1  christos   M_DDIVU_3I,
   1352   1.1  christos   M_DIV_3,
   1353   1.1  christos   M_DIV_3I,
   1354   1.1  christos   M_DIVU_3,
   1355   1.1  christos   M_DIVU_3I,
   1356   1.1  christos   M_DLA_AB,
   1357   1.1  christos   M_DLCA_AB,
   1358   1.1  christos   M_DLI,
   1359   1.1  christos   M_DMUL,
   1360   1.1  christos   M_DMUL_I,
   1361   1.1  christos   M_DMULO,
   1362   1.1  christos   M_DMULO_I,
   1363   1.1  christos   M_DMULOU,
   1364   1.1  christos   M_DMULOU_I,
   1365   1.1  christos   M_DREM_3,
   1366   1.1  christos   M_DREM_3I,
   1367   1.1  christos   M_DREMU_3,
   1368   1.1  christos   M_DREMU_3I,
   1369   1.1  christos   M_DSUB_I,
   1370   1.1  christos   M_DSUBU_I,
   1371   1.1  christos   M_DSUBU_I_2,
   1372   1.1  christos   M_JR_S,
   1373   1.1  christos   M_J_S,
   1374   1.1  christos   M_J_A,
   1375   1.1  christos   M_JALR_S,
   1376   1.1  christos   M_JALR_DS,
   1377   1.1  christos   M_JAL_1,
   1378   1.1  christos   M_JAL_2,
   1379   1.1  christos   M_JAL_A,
   1380   1.1  christos   M_JALS_1,
   1381   1.1  christos   M_JALS_2,
   1382   1.1  christos   M_JALS_A,
   1383   1.3  christos   M_JRADDIUSP,
   1384   1.3  christos   M_JRC,
   1385   1.1  christos   M_L_DAB,
   1386   1.1  christos   M_LA_AB,
   1387   1.1  christos   M_LB_AB,
   1388   1.3  christos   M_LBE_AB,
   1389   1.1  christos   M_LBU_AB,
   1390   1.3  christos   M_LBUE_AB,
   1391   1.1  christos   M_LCA_AB,
   1392   1.1  christos   M_LD_AB,
   1393   1.1  christos   M_LDC1_AB,
   1394   1.1  christos   M_LDC2_AB,
   1395   1.3  christos   M_LQC2_AB,
   1396   1.1  christos   M_LDC3_AB,
   1397   1.1  christos   M_LDL_AB,
   1398   1.1  christos   M_LDM_AB,
   1399   1.1  christos   M_LDP_AB,
   1400   1.1  christos   M_LDR_AB,
   1401   1.1  christos   M_LH_AB,
   1402   1.3  christos   M_LHE_AB,
   1403   1.1  christos   M_LHU_AB,
   1404   1.3  christos   M_LHUE_AB,
   1405   1.1  christos   M_LI,
   1406   1.1  christos   M_LI_D,
   1407   1.1  christos   M_LI_DD,
   1408   1.1  christos   M_LI_S,
   1409   1.1  christos   M_LI_SS,
   1410   1.1  christos   M_LL_AB,
   1411   1.1  christos   M_LLD_AB,
   1412   1.7  christos   M_LLDP_AB,
   1413   1.3  christos   M_LLE_AB,
   1414   1.7  christos   M_LLWP_AB,
   1415   1.7  christos   M_LLWPE_AB,
   1416   1.3  christos   M_LQ_AB,
   1417   1.1  christos   M_LW_AB,
   1418   1.3  christos   M_LWE_AB,
   1419   1.1  christos   M_LWC0_AB,
   1420   1.1  christos   M_LWC1_AB,
   1421   1.1  christos   M_LWC2_AB,
   1422   1.1  christos   M_LWC3_AB,
   1423   1.1  christos   M_LWL_AB,
   1424   1.3  christos   M_LWLE_AB,
   1425   1.1  christos   M_LWM_AB,
   1426   1.1  christos   M_LWP_AB,
   1427   1.1  christos   M_LWR_AB,
   1428   1.3  christos   M_LWRE_AB,
   1429   1.1  christos   M_LWU_AB,
   1430   1.1  christos   M_MSGSND,
   1431   1.1  christos   M_MSGLD,
   1432   1.1  christos   M_MSGLD_T,
   1433   1.1  christos   M_MSGWAIT,
   1434   1.1  christos   M_MSGWAIT_T,
   1435   1.1  christos   M_MOVE,
   1436   1.3  christos   M_MOVEP,
   1437   1.1  christos   M_MUL,
   1438   1.1  christos   M_MUL_I,
   1439   1.1  christos   M_MULO,
   1440   1.1  christos   M_MULO_I,
   1441   1.1  christos   M_MULOU,
   1442   1.1  christos   M_MULOU_I,
   1443   1.1  christos   M_NOR_I,
   1444   1.1  christos   M_OR_I,
   1445   1.1  christos   M_PREF_AB,
   1446   1.3  christos   M_PREFE_AB,
   1447   1.1  christos   M_REM_3,
   1448   1.1  christos   M_REM_3I,
   1449   1.1  christos   M_REMU_3,
   1450   1.1  christos   M_REMU_3I,
   1451   1.1  christos   M_DROL,
   1452   1.1  christos   M_ROL,
   1453   1.1  christos   M_DROL_I,
   1454   1.1  christos   M_ROL_I,
   1455   1.1  christos   M_DROR,
   1456   1.1  christos   M_ROR,
   1457   1.1  christos   M_DROR_I,
   1458   1.1  christos   M_ROR_I,
   1459   1.1  christos   M_S_DA,
   1460   1.1  christos   M_S_DAB,
   1461   1.1  christos   M_S_S,
   1462   1.1  christos   M_SAA_AB,
   1463   1.1  christos   M_SAAD_AB,
   1464   1.1  christos   M_SC_AB,
   1465   1.1  christos   M_SCD_AB,
   1466   1.7  christos   M_SCDP_AB,
   1467   1.3  christos   M_SCE_AB,
   1468   1.7  christos   M_SCWP_AB,
   1469   1.7  christos   M_SCWPE_AB,
   1470   1.1  christos   M_SD_AB,
   1471   1.1  christos   M_SDC1_AB,
   1472   1.1  christos   M_SDC2_AB,
   1473   1.3  christos   M_SQC2_AB,
   1474   1.1  christos   M_SDC3_AB,
   1475   1.1  christos   M_SDL_AB,
   1476   1.1  christos   M_SDM_AB,
   1477   1.1  christos   M_SDP_AB,
   1478   1.1  christos   M_SDR_AB,
   1479   1.1  christos   M_SEQ,
   1480   1.1  christos   M_SEQ_I,
   1481   1.1  christos   M_SGE,
   1482   1.1  christos   M_SGE_I,
   1483   1.1  christos   M_SGEU,
   1484   1.1  christos   M_SGEU_I,
   1485   1.1  christos   M_SGT,
   1486   1.1  christos   M_SGT_I,
   1487   1.1  christos   M_SGTU,
   1488   1.1  christos   M_SGTU_I,
   1489   1.1  christos   M_SLE,
   1490   1.1  christos   M_SLE_I,
   1491   1.1  christos   M_SLEU,
   1492   1.1  christos   M_SLEU_I,
   1493   1.1  christos   M_SLT_I,
   1494   1.1  christos   M_SLTU_I,
   1495   1.1  christos   M_SNE,
   1496   1.1  christos   M_SNE_I,
   1497   1.1  christos   M_SB_AB,
   1498   1.3  christos   M_SBE_AB,
   1499   1.1  christos   M_SH_AB,
   1500   1.3  christos   M_SHE_AB,
   1501   1.3  christos   M_SQ_AB,
   1502   1.1  christos   M_SW_AB,
   1503   1.3  christos   M_SWE_AB,
   1504   1.1  christos   M_SWC0_AB,
   1505   1.1  christos   M_SWC1_AB,
   1506   1.1  christos   M_SWC2_AB,
   1507   1.1  christos   M_SWC3_AB,
   1508   1.1  christos   M_SWL_AB,
   1509   1.3  christos   M_SWLE_AB,
   1510   1.1  christos   M_SWM_AB,
   1511   1.1  christos   M_SWP_AB,
   1512   1.1  christos   M_SWR_AB,
   1513   1.3  christos   M_SWRE_AB,
   1514   1.1  christos   M_SUB_I,
   1515   1.1  christos   M_SUBU_I,
   1516   1.1  christos   M_SUBU_I_2,
   1517   1.1  christos   M_TEQ_I,
   1518   1.1  christos   M_TGE_I,
   1519   1.1  christos   M_TGEU_I,
   1520   1.1  christos   M_TLT_I,
   1521   1.1  christos   M_TLTU_I,
   1522   1.1  christos   M_TNE_I,
   1523   1.1  christos   M_TRUNCWD,
   1524   1.1  christos   M_TRUNCWS,
   1525   1.3  christos   M_ULD_AB,
   1526   1.3  christos   M_ULH_AB,
   1527   1.3  christos   M_ULHU_AB,
   1528   1.3  christos   M_ULW_AB,
   1529   1.3  christos   M_USH_AB,
   1530   1.3  christos   M_USW_AB,
   1531   1.3  christos   M_USD_AB,
   1532   1.1  christos   M_XOR_I,
   1533   1.1  christos   M_COP0,
   1534   1.1  christos   M_COP1,
   1535   1.1  christos   M_COP2,
   1536   1.1  christos   M_COP3,
   1537   1.1  christos   M_NUM_MACROS
   1538   1.1  christos };
   1539   1.1  christos 
   1540   1.1  christos 
   1541   1.1  christos /* The order of overloaded instructions matters.  Label arguments and
   1542   1.1  christos    register arguments look the same. Instructions that can have either
   1543   1.1  christos    for arguments must apear in the correct order in this table for the
   1544   1.1  christos    assembler to pick the right one. In other words, entries with
   1545   1.1  christos    immediate operands must apear after the same instruction with
   1546   1.1  christos    registers.
   1547   1.1  christos 
   1548   1.1  christos    Many instructions are short hand for other instructions (i.e., The
   1549   1.1  christos    jal <register> instruction is short for jalr <register>).  */
   1550   1.1  christos 
   1551   1.3  christos extern const struct mips_operand mips_vu0_channel_mask;
   1552   1.3  christos extern const struct mips_operand *decode_mips_operand (const char *);
   1553   1.1  christos extern const struct mips_opcode mips_builtin_opcodes[];
   1554   1.1  christos extern const int bfd_mips_num_builtin_opcodes;
   1555   1.1  christos extern struct mips_opcode *mips_opcodes;
   1556   1.1  christos extern int bfd_mips_num_opcodes;
   1557   1.1  christos #define NUMOPCODES bfd_mips_num_opcodes
   1558   1.1  christos 
   1559   1.1  christos 
   1560   1.1  christos /* The rest of this file adds definitions for the mips16 TinyRISC
   1562   1.1  christos    processor.  */
   1563   1.1  christos 
   1564   1.1  christos /* These are the bitmasks and shift counts used for the different
   1565   1.1  christos    fields in the instruction formats.  Other than OP, no masks are
   1566   1.1  christos    provided for the fixed portions of an instruction, since they are
   1567   1.1  christos    not needed.
   1568   1.1  christos 
   1569   1.1  christos    The I format uses IMM11.
   1570   1.1  christos 
   1571   1.1  christos    The RI format uses RX and IMM8.
   1572   1.1  christos 
   1573   1.1  christos    The RR format uses RX, and RY.
   1574   1.1  christos 
   1575   1.1  christos    The RRI format uses RX, RY, and IMM5.
   1576   1.1  christos 
   1577   1.1  christos    The RRR format uses RX, RY, and RZ.
   1578   1.1  christos 
   1579   1.1  christos    The RRI_A format uses RX, RY, and IMM4.
   1580   1.1  christos 
   1581   1.1  christos    The SHIFT format uses RX, RY, and SHAMT.
   1582   1.1  christos 
   1583   1.1  christos    The I8 format uses IMM8.
   1584   1.1  christos 
   1585   1.1  christos    The I8_MOVR32 format uses RY and REGR32.
   1586   1.1  christos 
   1587   1.1  christos    The IR_MOV32R format uses REG32R and MOV32Z.
   1588   1.1  christos 
   1589   1.1  christos    The I64 format uses IMM8.
   1590   1.1  christos 
   1591   1.1  christos    The RI64 format uses RY and IMM5.
   1592   1.1  christos    */
   1593   1.1  christos 
   1594   1.1  christos #define MIPS16OP_MASK_RX	0x7
   1595   1.1  christos #define MIPS16OP_SH_RX		8
   1596   1.1  christos #define MIPS16OP_MASK_RY	0x7
   1597   1.1  christos #define MIPS16OP_SH_RY		5
   1598   1.1  christos #define MIPS16OP_MASK_RZ	0x7
   1599  1.10  christos #define MIPS16OP_SH_RZ		2
   1600  1.10  christos 
   1601  1.10  christos /* These are the characters which may appears in the args field of a
   1602  1.10  christos    MIPS16 instruction.  They appear in the order in which the fields
   1603  1.10  christos    appear when the instruction is used.  Commas and parentheses in the
   1604  1.10  christos    args string are ignored when assembling, and written into the output
   1605  1.10  christos    when disassembling.
   1606  1.10  christos 
   1607  1.10  christos    "y" 3-bit register at bit 5 (RY).
   1608  1.10  christos    "x" 3-bit register at bit 8 (RX).
   1609  1.10  christos    "z" 3-bit register at bit 2 (RZ).
   1610  1.10  christos    "Z" 3-bit register at bit 0 (MOV32Z).
   1611  1.10  christos    "v" 3-bit same register as source and destination at bit 8 (RX).
   1612  1.10  christos    "w" 3-bit same register as source and destination at bit 5 (RY).
   1613  1.10  christos    "." Zero register ($0).
   1614  1.10  christos    "S" Stack pointer ($sp or $29).
   1615  1.10  christos    "P" Program counter.
   1616  1.10  christos    "R" Return address register ($ra or $31).
   1617  1.10  christos    "X" 5-bit MIPS register at bit 0 (REGR32).
   1618  1.10  christos    "Y" 5-bit shuffled MIPS register at bit 3 (REG32R).
   1619  1.10  christos    "0" 5-bit ASMACRO p0 immediate.
   1620  1.10  christos    "1" 3-bit ASMACRO p1 immediate.
   1621  1.10  christos    "2" 3-bit ASMACRO p2 immediate.
   1622  1.10  christos    "3" 5-bit ASMACRO p3 immediate.
   1623  1.10  christos    "4" 3-bit ASMACRO p4 immediate.
   1624  1.10  christos    "6" 6-bit unsigned break code at bit 5.
   1625  1.10  christos    "a" 26-bit jump address.
   1626  1.10  christos    "i" Likewise, but flips bit 0.
   1627  1.10  christos    "e" 11-bit extension value.
   1628  1.10  christos    "l" Register list for ENTRY instruction.
   1629  1.10  christos    "L" Register list for EXIT instruction.
   1630  1.10  christos    ">" 5-bit SYNC code.
   1631  1.10  christos    "9" 9-bit signed immediate.
   1632  1.10  christos    "G" global pointer ($gp or $28).
   1633  1.10  christos    "N" 5-bit coprocessor register.
   1634  1.10  christos    "O" 3-bit sel field for MFC0/MTC0.
   1635  1.10  christos    "Q" 5-bit hardware register.
   1636  1.10  christos    "T" 5-bit CACHE opcode or PREF hint.
   1637   1.6  christos    "b" 5-bit INS/EXT position, which becomes LSB.
   1638  1.10  christos        Enforces: 0 <= pos < 32.
   1639   1.6  christos    "c" 5-bit INS size, which becomes MSB.
   1640   1.6  christos        Requires that "b" occurs first to set position.
   1641  1.10  christos        Enforces: 0 < (pos+size) <= 32.
   1642   1.6  christos    "d" 5-bit EXT size, which becomes MSBD.
   1643   1.6  christos        Requires that "b" occurs first to set position.
   1644  1.10  christos        Enforces: 0 < (pos+size) <= 32.
   1645  1.10  christos    "n" 2-bit immediate (1 .. 4).
   1646  1.10  christos    "o" 5-bit unsigned immediate * 16.
   1647  1.10  christos    "r" 3-bit register.
   1648  1.10  christos    "s" 3-bit ASMACRO select immediate.
   1649   1.1  christos    "u" 16-bit unsigned immediate.
   1650  1.10  christos 
   1651   1.3  christos    "I" An immediate value used for macros.
   1652   1.1  christos 
   1653   1.1  christos    The remaining codes may be extended.  Except as otherwise noted,
   1654  1.10  christos    the full extended operand is a 16 bit signed value.
   1655  1.10  christos    "<" 3-bit unsigned shift count * 1 at bit 2 (SHAMT) (full 5-bit unsigned).
   1656  1.10  christos    "[" 3-bit unsigned shift count * 1 at bit 2 (SHAMT) (full 6-bit unsigned).
   1657  1.10  christos    "]" 3-bit unsigned shift count * 1 at bit 8 (RX) (full 6-bit unsigned).
   1658  1.10  christos    "5" 5-bit unsigned immediate * 1 at bit 0 (IMM5).
   1659  1.10  christos    "F" 4-bit signed immediate * 1 a bit 0 (IMM4) (full 15-bit signed).
   1660  1.10  christos    "H" 5-bit unsigned immediate * 2 at bit 0 (IMM5).
   1661  1.10  christos    "W" 5-bit unsigned immediate * 4 at bit 0 (IMM5).
   1662  1.10  christos    "D" 5-bit unsigned immediate * 8 at bit 0 (IMM5).
   1663  1.10  christos    "j" 5-bit signed immediate * 1 at bit 0 (IMM5).
   1664  1.10  christos    "8" 8-bit unsigned immediate * 1 at bit 0 (IMM8).
   1665  1.10  christos    "V" 8-bit unsigned immediate * 4 at bit 0 (IMM8).
   1666  1.10  christos    "C" 8-bit unsigned immediate * 8 at bit 0 (IMM8).
   1667  1.10  christos    "U" 8-bit unsigned immediate * 1 at bit 0 (IMM8) (full 16-bit unsigned).
   1668  1.10  christos    "k" 8-bit signed immediate * 1 at bit 0 (IMM8).
   1669  1.10  christos    "K" 8-bit signed immediate * 8 at bit 0 (IMM8).
   1670  1.10  christos    "p" 8-bit conditional branch address at bit 0 (IMM8).
   1671  1.10  christos    "q" 11-bit branch address at bit 0 (IMM11).
   1672  1.10  christos    "A" 8-bit PC relative address * 4 at bit 0 (IMM8).
   1673  1.10  christos    "B" 5-bit PC relative address * 8 at bit 0 (IMM5).
   1674  1.10  christos    "E" 5-bit PC relative address * 4 at bit 0 (IMM5).
   1675   1.5  christos    "m" 7-bit register list for SAVE/RESTORE instruction (18-bit extended).
   1676   1.5  christos 
   1677   1.6  christos    Characters used so far, for quick reference when adding more:
   1678   1.6  christos    "0123456 89"
   1679   1.6  christos    ".[]<>"
   1680   1.6  christos    "ABCDEFGHI KL NOPQRSTUVWXYZ"
   1681   1.1  christos    "abcde   ijklmnopqrs uvwxyz"
   1682   1.1  christos   */
   1683   1.1  christos 
   1684   1.1  christos /* Save/restore encoding for the args field when all 4 registers are
   1685   1.6  christos    either saved as arguments or saved/restored as statics.  */
   1686   1.6  christos #define MIPS_SVRS_ALL_ARGS    0xe
   1687   1.1  christos #define MIPS_SVRS_ALL_STATICS 0xb
   1688   1.1  christos 
   1689   1.1  christos /* The following flags have the same value for the mips16 opcode
   1690   1.1  christos    table:
   1691   1.1  christos 
   1692   1.1  christos    INSN_ISA3
   1693   1.1  christos 
   1694   1.1  christos    INSN_UNCOND_BRANCH_DELAY
   1695   1.1  christos    INSN_COND_BRANCH_DELAY
   1696   1.1  christos    INSN_COND_BRANCH_LIKELY (never used)
   1697   1.1  christos    INSN_READ_HI
   1698   1.1  christos    INSN_READ_LO
   1699   1.1  christos    INSN_WRITE_HI
   1700   1.1  christos    INSN_WRITE_LO
   1701   1.1  christos    INSN_TRAP
   1702   1.1  christos    FP_D (never used)
   1703   1.1  christos    */
   1704   1.8  christos 
   1705   1.1  christos extern const struct mips_operand *decode_mips16_operand (char, bool);
   1706   1.1  christos extern const struct mips_opcode mips16_opcodes[];
   1707   1.1  christos extern const int bfd_mips16_num_opcodes;
   1708   1.1  christos 
   1709   1.1  christos /* These are the bit masks and shift counts used for the different fields
   1710   1.1  christos    in the microMIPS instruction formats.  No masks are provided for the
   1711   1.1  christos    fixed portions of an instruction, since they are not needed.  */
   1712   1.1  christos 
   1713   1.1  christos #define MICROMIPSOP_MASK_RS		0x1f
   1714   1.1  christos #define MICROMIPSOP_SH_RS		16
   1715   1.1  christos #define MICROMIPSOP_MASK_RT		0x1f
   1716   1.1  christos #define MICROMIPSOP_SH_RT		21
   1717   1.1  christos #define MICROMIPSOP_MASK_RD		0x1f
   1718   1.1  christos #define MICROMIPSOP_SH_RD		11
   1719   1.1  christos #define MICROMIPSOP_MASK_BCC		0x7
   1720   1.1  christos #define MICROMIPSOP_SH_BCC		18
   1721   1.1  christos #define MICROMIPSOP_MASK_MD		0x7
   1722   1.1  christos #define MICROMIPSOP_SH_MD		7
   1723   1.1  christos #define MICROMIPSOP_MASK_MJ		0x1f
   1724  1.10  christos #define MICROMIPSOP_SH_MJ		0
   1725  1.10  christos 
   1726  1.10  christos /* These are the characters which may appears in the args field of a
   1727  1.10  christos    microMIPS instruction.  They appear in the order in which the fields
   1728  1.10  christos    appear when the instruction is used.  Commas and parentheses in the
   1729   1.1  christos    args string are ignored when assembling, and written into the output
   1730   1.1  christos    when disassembling.
   1731   1.1  christos 
   1732   1.1  christos    The followings are for 16-bit microMIPS instructions.
   1733  1.10  christos 
   1734  1.10  christos    "ma" Must be $28.
   1735  1.10  christos    "mc" 3-bit registers 2-7, 16, 17 at bit 4.
   1736  1.10  christos 	The same register used as both source and target.
   1737  1.10  christos    "md" 3-bit registers 2-7, 16, 17 at bit 7.
   1738  1.10  christos    "me" 3-bit registers 2-7, 16, 17 at bit 1.
   1739  1.10  christos 	The same register used as both source and target.
   1740  1.10  christos    "mf" 3-bit registers 2-7, 16, 17 at bit 3.
   1741  1.10  christos    "mg" 3-bit registers 2-7, 16, 17 at bit 0.
   1742  1.10  christos    "mh" 3-bit register pair at bit 7.
   1743  1.10  christos    "mj" 5-bit registers at bit 0.
   1744  1.10  christos    "ml" 3-bit registers 2-7, 16, 17 at bit 4.
   1745  1.10  christos    "mm" 3-bit registers 0, 2, 3, 16-20 at bit 1.
   1746  1.10  christos    "mn" 3-bit registers 0, 2, 3, 16-20 at bit 4.
   1747  1.10  christos    "mp" 5-bit registers at bit 5.
   1748  1.10  christos    "mq" 3-bit registers 0, 2-7, 17 at bit 7.
   1749  1.10  christos    "mr" Must be program counter.
   1750  1.10  christos    "ms" Must be $29.
   1751  1.10  christos    "mt" Must be the same as the previous register.
   1752  1.10  christos    "mx" Must be the same as the destination register.
   1753  1.10  christos    "my" Must be $31.
   1754   1.1  christos    "mz" Must be $0.
   1755  1.10  christos 
   1756  1.10  christos    "mA" 7-bit immediate (-64 .. 63) << 2 at bit 0.
   1757   1.1  christos    "mB" 3-bit immediate (-1, 1, 4, 8, 12, 16, 20, 24) at bit 1.
   1758  1.10  christos    "mC" 4-bit immediate (1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 128, 255,
   1759  1.10  christos 	32768, 65535) at bit 0.
   1760  1.10  christos    "mD" 10-bit branch address (-512 .. 511) << 1 at bit 0.
   1761  1.10  christos    "mE" 7-bit branch address (-64 .. 63) << 1 at bit 0.
   1762  1.10  christos    "mF" 4-bit immediate (0 .. 15) at bit 0.
   1763  1.10  christos    "mG" 4-bit immediate (-1 .. 14) at bit 0.
   1764  1.10  christos    "mH" 4-bit immediate (0 .. 15) << 1 at bit 0.
   1765  1.10  christos    "mI" 7-bit immediate (-1 .. 126) at bit 0.
   1766  1.10  christos    "mJ" 4-bit immediate (0 .. 15) << 2 at bit 0.
   1767  1.10  christos    "mL" 4-bit immediate (0 .. 15) at bit 0.
   1768  1.10  christos    "mM" 3-bit immediate (1 .. 8) at bit 1.
   1769  1.10  christos    "mN" 2-bit immediate (0 .. 3) for register list at bit 4.
   1770  1.10  christos    "mO" 4-bit immediate (0 .. 15) at bit 0.
   1771  1.10  christos    "mP" 5-bit immediate (0 .. 31) << 2 at bit 0.
   1772  1.10  christos    "mU" 5-bit immediate (0 .. 31) << 2 at bit 0.
   1773  1.10  christos    "mW" 6-bit immediate (0 .. 63) << 2 at bit 1.
   1774  1.10  christos    "mX" 4-bit immediate (-8 .. 7) at bit 1.
   1775  1.10  christos    "mY" 9-bit immediate (-258 .. -3, 2 .. 257) << 2 at bit 1.
   1776   1.1  christos    "mZ" Must be zero.
   1777   1.1  christos 
   1778   1.1  christos    In most cases 32-bit microMIPS instructions use the same characters
   1779   1.1  christos    as MIPS (with ADDIUPC being a notable exception, but there are some
   1780   1.1  christos    others too).
   1781  1.10  christos 
   1782  1.10  christos    "." 10-bit signed offset/number at bit 6.
   1783  1.10  christos    "1" 5-bit SYNC type at bit 16.
   1784  1.10  christos    "<" 5-bit shift amount at bit 11.
   1785  1.10  christos    ">" Shift amount between 32 and 63, stored after subtracting 3, at bit 11.
   1786  1.10  christos    "\" 3-bit position for ASET and ACLR at bit 21.
   1787  1.10  christos    "|" 4-bit trap code at bit 12.
   1788  1.10  christos    "~" 12-bit signed offset at bit 0.
   1789  1.10  christos    "a" 26-bit target address at bit 0.
   1790  1.10  christos    "+i" Likewise, but flips bit 0.
   1791  1.10  christos    "b" 5-bit base register at bit 16 (RS).
   1792  1.10  christos    "c" 10-bit higher breakpoint code at bit 16.
   1793  1.10  christos    "d" 5-bit destination register at bit 11 (RD).
   1794  1.10  christos    "h" 5-bit PREFX hint at bit 11.
   1795  1.10  christos    "i" 16-bit unsigned immediate at bit 0.
   1796  1.10  christos    "j" 16-bit signed immediate at bit 0.
   1797  1.10  christos    "k" 5-bit CACHE opcode in target register position at bit 21.
   1798  1.10  christos    "n" 5-bit register list for 32-bit LWM/SWM instruction at bit 21 (RT).
   1799  1.10  christos    "o" 16-bit signed offset at bit 0.
   1800  1.10  christos    "p" 16-bit PC-relative branch target address at bit 0.
   1801  1.10  christos    "q" 10-bit lower breakpoint code at bit 6.
   1802  1.10  christos    "r" 5-bit same register used as both source and target at bit 16 (RS).
   1803  1.10  christos    "s" 5-bit source register at bit 16 (RS).
   1804  1.10  christos    "t" 5-bit target register at bit 21 (RT).
   1805  1.10  christos    "u" 16-bit upper 16 bits of address at bit 0.
   1806  1.10  christos    "v" 5-bit same register used as both source and destination at bit 16 (RS).
   1807  1.10  christos    "w" 5-bit same register used as both target and destination at bit 21 (RT).
   1808  1.10  christos    "x" 5-bit source 3 register for ALNV.PS at bit 6.
   1809  1.10  christos    "z" Must be zero register.
   1810  1.10  christos    "C" 23-bit coprocessor function code at bit 3.
   1811   1.1  christos    "K" 5-bit Hardware Register (RDHWR instruction) at bit 16 (RS).
   1812  1.10  christos 
   1813  1.10  christos    "+A" 5-bit INS/EXT/DINS/DEXT/DINSM/DEXTM position at bit 6,
   1814   1.1  christos 	which becomes LSB.
   1815  1.10  christos 	Enforces: 0 <= pos < 32.
   1816   1.1  christos    "+B" 5-bit INS/DINS size at bit 11, which becomes MSB.
   1817   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
   1818  1.10  christos 	Enforces: 0 < (pos+size) <= 32.
   1819   1.1  christos    "+C" 5-bit EXT/DEXT size at bit 11, which becomes MSBD.
   1820   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
   1821   1.1  christos 	Enforces: 0 < (pos+size) <= 32.
   1822   1.1  christos 	(Also used by DEXT w/ different limits, but limits for
   1823  1.10  christos 	that are checked by the M_DEXT macro.)
   1824   1.1  christos    "+E" 5-bit DINSU/DEXTU position at bit 6, which becomes LSB-32.
   1825  1.10  christos 	Enforces: 32 <= pos < 64.
   1826   1.1  christos    "+F" 5-bit DINSM/DINSU size at bit 11., which becomes MSB-32.
   1827   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
   1828  1.10  christos 	Enforces: 32 < (pos+size) <= 64.
   1829   1.1  christos    "+G" 5-bit DEXTM size at bit 11, which becomes MSBD-32.
   1830   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
   1831  1.10  christos 	Enforces: 32 < (pos+size) <= 64.
   1832   1.1  christos    "+H" 5-bit DEXTU size at bit 11, which becomes MSBD.
   1833   1.1  christos 	Requires that "+A" or "+E" occur first to set position.
   1834  1.10  christos 	Enforces: 32 < (pos+size) <= 64.
   1835   1.1  christos    "+J" 10-bit SYSCALL/WAIT/SDBBP/HYPCALL function code at bit 16.
   1836   1.1  christos 
   1837  1.10  christos    PC-relative addition (ADDIUPC) instruction:
   1838  1.10  christos    "mQ" 23-bit offset (-4194304 .. 4194303) << 2 at bit 0.
   1839   1.1  christos    "mb" 3-bit MIPS registers 2-7, 16, 17 at bit 23.
   1840   1.1  christos 
   1841  1.10  christos    Floating point instructions:
   1842  1.10  christos    "D" 5-bit destination register at bit 11 (FD).
   1843  1.10  christos    "M" 3-bit compare condition code at bit 13 (CCC).
   1844  1.10  christos    "N" 3-bit branch condition code at bit 18 (BCC).
   1845  1.10  christos    "R" 5-bit fr source 3 register at bit 6 (FR).
   1846  1.10  christos    "S" 5-bit fs source 1 register at bit 16 (FS).
   1847   1.1  christos    "T" 5-bit ft source 2 register at bit 21 (FT).
   1848  1.10  christos    "V" 5-bit same register used as floating source and destination or target
   1849   1.1  christos        at bit 16 (FS).
   1850   1.1  christos 
   1851  1.10  christos    Coprocessor instructions:
   1852  1.10  christos    "E" 5-bit target register at bit 21 (RT).
   1853  1.10  christos    "G" 5-bit source register at bit 16 (RS).
   1854  1.10  christos    "H" 3-bit sel field for (D)MTC* and (D)MFC* at bit 11.
   1855   1.1  christos    "g" 5-bit control source register at bit 16 (RS).
   1856   1.1  christos 
   1857  1.10  christos    Macro instructions:
   1858   1.1  christos    "A" General 32-bit expression.
   1859  1.10  christos    "I" 32-bit immediate (value placed in imm_expr).
   1860  1.10  christos    "F" 64-bit floating point constant in .rdata.
   1861  1.10  christos    "L" 64-bit floating point constant in .lit8.
   1862  1.10  christos    "f" 32-bit floating point constant.
   1863   1.1  christos    "l" 32-bit floating point constant in .lit4.
   1864   1.1  christos 
   1865  1.10  christos    DSP ASE usage:
   1866  1.10  christos    "2" 2-bit unsigned immediate for byte align at bit 14.
   1867  1.10  christos    "3" 3-bit unsigned immediate at bit 13.
   1868  1.10  christos    "4" 4-bit unsigned immediate at bit 12.
   1869  1.10  christos    "5" 8-bit unsigned immediate at bit 13.
   1870  1.10  christos    "6" 5-bit unsigned immediate at bit 16 (RS).
   1871  1.10  christos    "7" 2-bit DSP accumulator register at bit 14.
   1872  1.10  christos    "8" 6-bit unsigned immediate at bit 14.
   1873  1.10  christos    "0" 6-bit signed immediate at bit 16.
   1874  1.10  christos    "@" 10-bit signed immediate at bit 16.
   1875   1.1  christos    "^" 5-bit unsigned immediate at bit 11 (RD).
   1876   1.3  christos 
   1877  1.10  christos    microMIPS Enhanced VA Scheme:
   1878   1.3  christos    "+j" 9-bit signed offset in bit 0.
   1879   1.3  christos 
   1880  1.10  christos    MSA Extension:
   1881  1.10  christos    "+d" 5-bit MSA register at bit 6 (FD).
   1882  1.10  christos    "+e" 5-bit MSA register at bit 11 (FS).
   1883  1.10  christos    "+h" 5-bit MSA register at bit 16 (FT).
   1884  1.10  christos    "+k" 5-bit GPR at bit 6.
   1885  1.10  christos    "+l" 5-bit MSA control register at bit 6.
   1886  1.10  christos    "+n" 5-bit MSA control register at bit 11.
   1887  1.10  christos    "+o" 4-bit vector element index at bit 16.
   1888  1.10  christos    "+u" 3-bit vector element index at bit 16.
   1889  1.10  christos    "+v" 2-bit vector element index at bit 16.
   1890  1.10  christos    "+w" 1-bit vector element index at bit 16.
   1891  1.10  christos    "+x" 5-bit shift amount at bit 16.
   1892  1.10  christos    "+T" (-512 .. 511) << 0 at bit 16.
   1893  1.10  christos    "+U" (-512 .. 511) << 1 at bit 16.
   1894  1.10  christos    "+V" (-512 .. 511) << 2 at bit 16.
   1895  1.10  christos    "+W" (-512 .. 511) << 3 at bit 16.
   1896  1.10  christos    "+~" 2-bit LSA/DLSA shift amount from 1 to 4 at bit 6.
   1897  1.10  christos    "+!" 3-bit unsigned bit position at bit 16.
   1898  1.10  christos    "+@" 4-bit unsigned bit position at bit 16.
   1899  1.10  christos    "+#" 6-bit unsigned bit position at bit 16.
   1900  1.10  christos    "+$" 5-bit unsigned immediate at bit 16.
   1901  1.10  christos    "+%" 5-bit signed immediate at bit 16.
   1902  1.10  christos    "+^" 10-bit signed immediate at bit 11.
   1903  1.10  christos    "+&" 0 vector element index.
   1904  1.10  christos    "+*" 5-bit register vector element index at bit 16.
   1905  1.10  christos    "+|" 8-bit mask at bit 16.
   1906  1.10  christos 
   1907  1.10  christos    MT ASE usage:
   1908  1.10  christos    "!" 1-bit usermode flag at bit 10.
   1909  1.10  christos    "$" 1-bit load high flag at bit 9.
   1910  1.10  christos    "*" 2-bit DSP accumulator register at bit 23.
   1911  1.10  christos    "&" 2-bit DSP accumulator register at bit 18.
   1912  1.10  christos    "J" 3-bit MFTR and MTTR sel at bit 4.
   1913   1.3  christos    "y" 5-bit control target register at bit 21 (RT).
   1914   1.1  christos 
   1915  1.10  christos    Other:
   1916  1.10  christos    "()" Parens surrounding optional value.
   1917  1.10  christos    ","  Separates operands.
   1918  1.10  christos    "m"  Start of microMIPS extension sequence.
   1919  1.10  christos    "+"  Start of extension sequence.
   1920   1.1  christos    "-"  Start of extension sequence.
   1921   1.1  christos 
   1922   1.1  christos    Characters used so far, for quick reference when adding more:
   1923  1.10  christos    "12345678 0"
   1924  1.10  christos    "<>(),+-.@!$&*\^|~"
   1925  1.10  christos    "ABCDEFGHIJKLMN   RST V    "
   1926   1.1  christos    "abcd fghijklmnopqrstuvwxyz"
   1927   1.1  christos 
   1928   1.1  christos    Extension character sequences used so far ("m" followed by the
   1929   1.1  christos    following), for quick reference when adding more:
   1930   1.1  christos    ""
   1931   1.1  christos    ""
   1932   1.1  christos    " BCDEFGHIJ LMNOPQ   U WXYZ"
   1933   1.3  christos    " bcdefghij lmn pq st   xyz"
   1934  1.10  christos 
   1935  1.10  christos    Extension character sequences used so far ("+" followed by the
   1936  1.10  christos    following), for quick reference when adding more:
   1937  1.10  christos    ""
   1938  1.10  christos    "~!@#$%^&*|"
   1939  1.10  christos    "ABC EFGH J         TUVW   "
   1940  1.10  christos    "   de  hijkl no     uvwx  "
   1941   1.3  christos 
   1942   1.3  christos    Extension character sequences used so far ("-" followed by the
   1943   1.3  christos    following), for quick reference when adding more:
   1944   1.3  christos    ""
   1945   1.3  christos    ""
   1946   1.1  christos    <none so far>
   1947   1.1  christos */
   1948   1.3  christos 
   1949   1.1  christos extern const struct mips_operand *decode_micromips_operand (const char *);
   1950   1.1  christos extern const struct mips_opcode micromips_opcodes[];
   1951   1.1  christos extern const int bfd_micromips_num_opcodes;
   1952   1.1  christos 
   1953   1.1  christos /* A NOP insn impemented as "or at,at,zero".
   1954   1.1  christos    Used to implement -mfix-loongson2f.  */
   1955   1.1  christos #define LOONGSON2F_NOP_INSN	0x00200825
   1956   1.5  christos 
   1957   1.5  christos #ifdef __cplusplus
   1958   1.5  christos }
   1959   1.5  christos #endif
   1960   1.1  christos 
   1961                 #endif /* _MIPS_H_ */
   1962