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
31 /// Destructor - Override as necessary.
32 virtual ~ModRMFilter() { }
34 /// isDumb - Indicates whether this filter returns the same value for
35 /// any value of the ModR/M byte.
37 /// @result - True if the filter returns the same value for any ModR/M
38 /// byte; false if not.
39 virtual bool isDumb() const { return false; }
41 /// accepts - Indicates whether the filter accepts a particular ModR/M
44 /// @result - True if the filter accepts the ModR/M byte; false if not.
45 virtual bool accepts(uint8_t modRM
) const = 0;
48 /// DumbFilter - Accepts any ModR/M byte. Used for instructions that do not
49 /// require a ModR/M byte or instructions where the entire ModR/M byte is used
51 class DumbFilter
: public ModRMFilter
{
57 bool accepts(uint8_t modRM
) const {
62 /// ModFilter - Filters based on the mod bits [bits 7-6] of the ModR/M byte.
63 /// Some instructions are classified based on whether they are 11 or anything
64 /// else. This filter performs that classification.
65 class ModFilter
: public ModRMFilter
{
71 /// @r - True if the mod bits of the ModR/M byte must be 11; false
72 /// otherwise. The name r derives from the fact that the mod
73 /// bits indicate whether the R/M bits [bits 2-0] signify a
74 /// register or a memory operand.
80 bool accepts(uint8_t modRM
) const {
81 if (R
== ((modRM
& 0xc0) == 0xc0))
88 /// EscapeFilter - Filters escape opcodes, which are classified in two ways. If
89 /// the ModR/M byte is between 0xc0 and 0xff, then there is one slot for each
90 /// possible value. Otherwise, there is one instruction for each value of the
91 /// nnn field [bits 5-3], known elsewhere as the reg field.
92 class EscapeFilter
: public ModRMFilter
{
99 /// @c0_ff - True if the ModR/M byte must fall between 0xc0 and 0xff;
101 /// @nnn_or_modRM - If c0_ff is true, the required value of the entire ModR/M
102 /// byte. If c0_ff is false, the required value of the nnn
104 EscapeFilter(bool c0_ff
, uint8_t nnn_or_modRM
) :
107 NNN_or_ModRM(nnn_or_modRM
) {
110 bool accepts(uint8_t modRM
) const {
111 if ((C0_FF
&& modRM
>= 0xc0 && (modRM
== NNN_or_ModRM
)) ||
112 (!C0_FF
&& modRM
< 0xc0 && ((modRM
& 0x38) >> 3) == NNN_or_ModRM
))
119 /// AddRegEscapeFilter - Some escape opcodes have one of the register operands
120 /// added to the ModR/M byte, meaning that a range of eight ModR/M values
121 /// maps to a single instruction. Such instructions require the ModR/M byte
122 /// to fall between 0xc0 and 0xff.
123 class AddRegEscapeFilter
: public ModRMFilter
{
129 /// @modRM - The value of the ModR/M byte when the register operand
130 /// refers to the first register in the register set.
131 AddRegEscapeFilter(uint8_t modRM
) : ModRM(modRM
) {
134 bool accepts(uint8_t modRM
) const {
135 if (modRM
>= ModRM
&& modRM
< ModRM
+ 8)
142 /// ExtendedFilter - Extended opcodes are classified based on the value of the
143 /// mod field [bits 7-6] and the value of the nnn field [bits 5-3].
144 class ExtendedFilter
: public ModRMFilter
{
151 /// @r - True if the mod field must be set to 11; false otherwise.
152 /// The name is explained at ModFilter.
153 /// @nnn - The required value of the nnn field.
154 ExtendedFilter(bool r
, uint8_t nnn
) :
160 bool accepts(uint8_t modRM
) const {
161 if (((R
&& ((modRM
& 0xc0) == 0xc0)) ||
162 (!R
&& ((modRM
& 0xc0) != 0xc0))) &&
163 (((modRM
& 0x38) >> 3) == NNN
))
170 /// ExactFilter - The occasional extended opcode (such as VMCALL or MONITOR)
171 /// requires the ModR/M byte to have a specific value.
172 class ExactFilter
: public ModRMFilter
179 /// @modRM - The required value of the full ModR/M byte.
180 ExactFilter(uint8_t modRM
) :
185 bool accepts(uint8_t modRM
) const {
193 } // namespace X86Disassembler