mips-formats.h 4.2 KB

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