1 //===- X86ModRMFilters.h - Disassembler ModR/M filterss ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
16 //===----------------------------------------------------------------------===//
18 #ifndef X86MODRMFILTERS_H
19 #define X86MODRMFILTERS_H
21 #include "llvm/Support/DataTypes.h"
25 namespace X86Disassembler {
27 /// ModRMFilter - Abstract base class for clases that recognize patterns in
30 virtual void anchor();
32 /// Destructor - Override as necessary.
33 virtual ~ModRMFilter() { }
35 /// isDumb - Indicates whether this filter returns the same value for
36 /// any value of the ModR/M byte.
38 /// @result - True if the filter returns the same value for any ModR/M
39 /// byte; false if not.
40 virtual bool isDumb() const { return false; }
42 /// accepts - Indicates whether the filter accepts a particular ModR/M
45 /// @result - True if the filter accepts the ModR/M byte; false if not.
46 virtual bool accepts(uint8_t modRM) const = 0;
49 /// DumbFilter - Accepts any ModR/M byte. Used for instructions that do not
50 /// require a ModR/M byte or instructions where the entire ModR/M byte is used
52 class DumbFilter : public ModRMFilter {
53 virtual void anchor();
59 bool accepts(uint8_t modRM) const {
64 /// ModFilter - Filters based on the mod bits [bits 7-6] of the ModR/M byte.
65 /// Some instructions are classified based on whether they are 11 or anything
66 /// else. This filter performs that classification.
67 class ModFilter : public ModRMFilter {
68 virtual void anchor();
73 /// \param r True if the mod bits of the ModR/M byte must be 11; false
74 /// otherwise. The name r derives from the fact that the mod
75 /// bits indicate whether the R/M bits [bits 2-0] signify a
76 /// register or a memory operand.
82 bool accepts(uint8_t modRM) const {
83 return (R == ((modRM & 0xc0) == 0xc0));
87 /// AddRegEscapeFilter - Some escape opcodes have one of the register operands
88 /// added to the ModR/M byte, meaning that a range of eight ModR/M values
89 /// maps to a single instruction. Such instructions require the ModR/M byte
90 /// to fall between 0xc0 and 0xff.
91 class AddRegEscapeFilter : public ModRMFilter {
92 virtual void anchor();
97 /// \param modRM The value of the ModR/M byte when the register operand
98 /// refers to the first register in the register set.
99 AddRegEscapeFilter(uint8_t modRM) : ModRM(modRM) {
102 bool accepts(uint8_t modRM) const {
103 return (modRM >= ModRM && modRM < ModRM + 8);
107 /// ExtendedFilter - Extended opcodes are classified based on the value of the
108 /// mod field [bits 7-6] and the value of the nnn field [bits 5-3].
109 class ExtendedFilter : public ModRMFilter {
110 virtual void anchor();
116 /// \param r True if the mod field must be set to 11; false otherwise.
117 /// The name is explained at ModFilter.
118 /// \param nnn The required value of the nnn field.
119 ExtendedFilter(bool r, uint8_t nnn) :
125 bool accepts(uint8_t modRM) const {
126 return (((R && ((modRM & 0xc0) == 0xc0)) ||
127 (!R && ((modRM & 0xc0) != 0xc0))) &&
128 (((modRM & 0x38) >> 3) == NNN));
132 /// ExactFilter - The occasional extended opcode (such as VMCALL or MONITOR)
133 /// requires the ModR/M byte to have a specific value.
134 class ExactFilter : public ModRMFilter {
135 virtual void anchor();
140 /// \param modRM The required value of the full ModR/M byte.
141 ExactFilter(uint8_t modRM) :
146 bool accepts(uint8_t modRM) const {
147 return (ModRM == modRM);
151 } // namespace X86Disassembler