Home | History | Annotate | Download | only in opcodes
      1 /* mips-formats.h
      2    Copyright (C) 2013-2014 Free Software Foundation, Inc.
      3 
      4    This library is free software; you can redistribute it and/or modify
      5    it under the terms of the GNU General Public License as published by
      6    the Free Software Foundation; either version 3, or (at your option)
      7    any later version.
      8 
      9    It is distributed in the hope that it will be useful, but WITHOUT
     10    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     11    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     12    License for more details.
     13 
     14    You should have received a copy of the GNU General Public License
     15    along with this program; see the file COPYING3. If not,
     16    see <http://www.gnu.org/licenses/>.  */
     17 
     18 /* For ARRAY_SIZE.  */
     19 #include "libiberty.h"
     20 
     21 #define INT_ADJ(SIZE, LSB, MAX_VAL, SHIFT, PRINT_HEX) \
     22   { \
     23     static const struct mips_int_operand op = { \
     24       { OP_INT, SIZE, LSB }, MAX_VAL, 0, SHIFT, PRINT_HEX \
     25     }; \
     26     return &op.root; \
     27   }
     28 
     29 #define UINT(SIZE, LSB) \
     30   INT_ADJ(SIZE, LSB, (1 << (SIZE)) - 1, 0, FALSE)
     31 
     32 #define SINT(SIZE, LSB) \
     33   INT_ADJ(SIZE, LSB, (1 << ((SIZE) - 1)) - 1, 0, FALSE)
     34 
     35 #define HINT(SIZE, LSB) \
     36   INT_ADJ(SIZE, LSB, (1 << (SIZE)) - 1, 0, TRUE)
     37 
     38 #define BIT(SIZE, LSB, BIAS) \
     39   { \
     40     static const struct mips_int_operand op = { \
     41       { OP_INT, SIZE, LSB }, (1 << (SIZE)) - 1, BIAS, 0, TRUE \
     42     }; \
     43     return &op.root; \
     44   }
     45 
     46 #define MAPPED_INT(SIZE, LSB, MAP, PRINT_HEX) \
     47   { \
     48     typedef char ATTRIBUTE_UNUSED \
     49       static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     50     static const struct mips_mapped_int_operand op = { \
     51       { OP_MAPPED_INT, SIZE, LSB }, MAP, PRINT_HEX \
     52     }; \
     53     return &op.root; \
     54   }
     55 
     56 #define MAPPED_STRING(SIZE, LSB, MAP, ALLOW_CONSTANTS) \
     57   { \
     58     typedef char ATTRIBUTE_UNUSED \
     59       static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     60     static const struct mips_mapped_string_operand op = { \
     61       { OP_MAPPED_STRING, SIZE, LSB }, MAP, ALLOW_CONSTANTS \
     62     }; \
     63     return &op.root; \
     64   }
     65 
     66 #define MSB(SIZE, LSB, BIAS, ADD_LSB, OPSIZE) \
     67   { \
     68     static const struct mips_msb_operand op = { \
     69       { OP_MSB, SIZE, LSB }, BIAS, ADD_LSB, OPSIZE \
     70     }; \
     71     return &op.root; \
     72   }
     73 
     74 #define REG(SIZE, LSB, BANK) \
     75   { \
     76     static const struct mips_reg_operand op = { \
     77       { OP_REG, SIZE, LSB }, OP_REG_##BANK, 0 \
     78     }; \
     79     return &op.root; \
     80   }
     81 
     82 #define OPTIONAL_REG(SIZE, LSB, BANK) \
     83   { \
     84     static const struct mips_reg_operand op = { \
     85       { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, 0 \
     86     }; \
     87     return &op.root; \
     88   }
     89 
     90 #define MAPPED_REG(SIZE, LSB, BANK, MAP) \
     91   { \
     92     typedef char ATTRIBUTE_UNUSED \
     93       static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
     94     static const struct mips_reg_operand op = { \
     95       { OP_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
     96     }; \
     97     return &op.root; \
     98   }
     99 
    100 #define OPTIONAL_MAPPED_REG(SIZE, LSB, BANK, MAP) \
    101   { \
    102     typedef char ATTRIBUTE_UNUSED \
    103       static_assert[(1 << (SIZE)) == ARRAY_SIZE (MAP)]; \
    104     static const struct mips_reg_operand op = { \
    105       { OP_OPTIONAL_REG, SIZE, LSB }, OP_REG_##BANK, MAP \
    106     }; \
    107     return &op.root; \
    108   }
    109 
    110 #define REG_PAIR(SIZE, LSB, BANK, MAP) \
    111   { \
    112     typedef char ATTRIBUTE_UNUSED \
    113       static_assert1[(1 << (SIZE)) == ARRAY_SIZE (MAP##1)]; \
    114     typedef char ATTRIBUTE_UNUSED \
    115       static_assert2[(1 << (SIZE)) == ARRAY_SIZE (MAP##2)]; \
    116     static const struct mips_reg_pair_operand op = { \
    117       { OP_REG_PAIR, SIZE, LSB }, OP_REG_##BANK, MAP##1, MAP##2 \
    118     }; \
    119     return &op.root; \
    120   }
    121 
    122 #define PCREL(SIZE, LSB, IS_SIGNED, SHIFT, ALIGN_LOG2, INCLUDE_ISA_BIT, \
    123               FLIP_ISA_BIT) \
    124   { \
    125     static const struct mips_pcrel_operand op = { \
    126       { { OP_PCREL, SIZE, LSB }, \
    127 	(1 << ((SIZE) - (IS_SIGNED))) - 1, 0, SHIFT, TRUE }, \
    128       ALIGN_LOG2, INCLUDE_ISA_BIT, FLIP_ISA_BIT \
    129     }; \
    130     return &op.root.root; \
    131   }
    132 
    133 #define JUMP(SIZE, LSB, SHIFT) \
    134   PCREL (SIZE, LSB, FALSE, SHIFT, SIZE + SHIFT, TRUE, FALSE)
    135 
    136 #define JALX(SIZE, LSB, SHIFT) \
    137   PCREL (SIZE, LSB, FALSE, SHIFT, SIZE + SHIFT, TRUE, TRUE)
    138 
    139 #define BRANCH(SIZE, LSB, SHIFT) \
    140   PCREL (SIZE, LSB, TRUE, SHIFT, 0, TRUE, FALSE)
    141 
    142 #define SPECIAL(SIZE, LSB, TYPE) \
    143   { \
    144     static const struct mips_operand op = { OP_##TYPE, SIZE, LSB }; \
    145     return &op; \
    146   }
    147 
    148 #define PREV_CHECK(SIZE, LSB, GT_OK, LT_OK, EQ_OK, ZERO_OK) \
    149   { \
    150     static const struct mips_check_prev_operand op = { \
    151       { OP_CHECK_PREV, SIZE, LSB }, GT_OK, LT_OK, EQ_OK, ZERO_OK \
    152     }; \
    153     return &op.root; \
    154   }
    155