X86ModRMFilters.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //===- X86ModRMFilters.h - Disassembler ModR/M filterss ---------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file is part of the X86 Disassembler Emitter.
  11. // It contains ModR/M filters that determine which values of the ModR/M byte
  12. // are valid for a partiuclar instruction.
  13. // Documentation for the disassembler emitter in general can be found in
  14. // X86DisasemblerEmitter.h.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_UTILS_TABLEGEN_X86MODRMFILTERS_H
  18. #define LLVM_UTILS_TABLEGEN_X86MODRMFILTERS_H
  19. #include "llvm/Support/DataTypes.h"
  20. namespace llvm {
  21. namespace X86Disassembler {
  22. /// ModRMFilter - Abstract base class for clases that recognize patterns in
  23. /// ModR/M bytes.
  24. class ModRMFilter {
  25. virtual void anchor();
  26. public:
  27. /// Destructor - Override as necessary.
  28. virtual ~ModRMFilter() { }
  29. /// isDumb - Indicates whether this filter returns the same value for
  30. /// any value of the ModR/M byte.
  31. ///
  32. /// @result - True if the filter returns the same value for any ModR/M
  33. /// byte; false if not.
  34. virtual bool isDumb() const { return false; }
  35. /// accepts - Indicates whether the filter accepts a particular ModR/M
  36. /// byte value.
  37. ///
  38. /// @result - True if the filter accepts the ModR/M byte; false if not.
  39. virtual bool accepts(uint8_t modRM) const = 0;
  40. };
  41. /// DumbFilter - Accepts any ModR/M byte. Used for instructions that do not
  42. /// require a ModR/M byte or instructions where the entire ModR/M byte is used
  43. /// for operands.
  44. class DumbFilter : public ModRMFilter {
  45. void anchor() override;
  46. public:
  47. bool isDumb() const override {
  48. return true;
  49. }
  50. bool accepts(uint8_t modRM) const override {
  51. return true;
  52. }
  53. };
  54. /// ModFilter - Filters based on the mod bits [bits 7-6] of the ModR/M byte.
  55. /// Some instructions are classified based on whether they are 11 or anything
  56. /// else. This filter performs that classification.
  57. class ModFilter : public ModRMFilter {
  58. void anchor() override;
  59. bool R;
  60. public:
  61. /// Constructor
  62. ///
  63. /// \param r True if the mod bits of the ModR/M byte must be 11; false
  64. /// otherwise. The name r derives from the fact that the mod
  65. /// bits indicate whether the R/M bits [bits 2-0] signify a
  66. /// register or a memory operand.
  67. ModFilter(bool r) :
  68. ModRMFilter(),
  69. R(r) {
  70. }
  71. bool accepts(uint8_t modRM) const override {
  72. return (R == ((modRM & 0xc0) == 0xc0));
  73. }
  74. };
  75. /// ExtendedFilter - Extended opcodes are classified based on the value of the
  76. /// mod field [bits 7-6] and the value of the nnn field [bits 5-3].
  77. class ExtendedFilter : public ModRMFilter {
  78. void anchor() override;
  79. bool R;
  80. uint8_t NNN;
  81. public:
  82. /// Constructor
  83. ///
  84. /// \param r True if the mod field must be set to 11; false otherwise.
  85. /// The name is explained at ModFilter.
  86. /// \param nnn The required value of the nnn field.
  87. ExtendedFilter(bool r, uint8_t nnn) :
  88. ModRMFilter(),
  89. R(r),
  90. NNN(nnn) {
  91. }
  92. bool accepts(uint8_t modRM) const override {
  93. return (((R && ((modRM & 0xc0) == 0xc0)) ||
  94. (!R && ((modRM & 0xc0) != 0xc0))) &&
  95. (((modRM & 0x38) >> 3) == NNN));
  96. }
  97. };
  98. /// ExactFilter - The occasional extended opcode (such as VMCALL or MONITOR)
  99. /// requires the ModR/M byte to have a specific value.
  100. class ExactFilter : public ModRMFilter {
  101. void anchor() override;
  102. uint8_t ModRM;
  103. public:
  104. /// Constructor
  105. ///
  106. /// \param modRM The required value of the full ModR/M byte.
  107. ExactFilter(uint8_t modRM) :
  108. ModRMFilter(),
  109. ModRM(modRM) {
  110. }
  111. bool accepts(uint8_t modRM) const override {
  112. return (ModRM == modRM);
  113. }
  114. };
  115. } // namespace X86Disassembler
  116. } // namespace llvm
  117. #endif