ROSE 0.11.145.192
Disassembler/Mips.h
1/* Disassembly specific to the MIPS architecture */
2#ifndef ROSE_BinaryAnalysis_Disassembler_Mips_H
3#define ROSE_BinaryAnalysis_Disassembler_Mips_H
4#include <featureTests.h>
5#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/Disassembler/Base.h>
7
8#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
9#include <Rose/BinaryAnalysis/ByteOrder.h>
10#include <Rose/BinaryAnalysis/InstructionEnumsMips.h>
11
12#include <SageBuilderAsm.h>
13
14namespace Rose {
15namespace BinaryAnalysis {
16namespace Disassembler {
17
37class Mips: public Base {
38public:
40 using Ptr = MipsPtr;
41
42protected:
43 explicit Mips(const Architecture::BaseConstPtr&);
44
45public:
50
51 virtual Base::Ptr clone() const override;
52 virtual SgAsmInstruction *disassembleOne(const MemoryMap::Ptr&, rose_addr_t start_va,
53 AddressSet *successors=NULL) override;
54 virtual size_t nDelaySlots(MipsInstructionKind);
56 SgAsmMipsInstruction *makeUnknownInstruction(rose_addr_t insn_va, unsigned opcode) const;
57
64 class Decoder {
65 public:
66 enum Architecture { Release1, Release2, Release3, Micro };
67 Decoder(Architecture arch, unsigned match, unsigned mask): arch(arch), match(match), mask(mask) {}
68 virtual ~Decoder() {}
69 Architecture arch; // architecture where this instruction was introduced
70 unsigned match; // value of compared bits
71 unsigned mask; // bits of 'match' that will be compared
72 typedef Mips D;
73 virtual SgAsmMipsInstruction *operator()(rose_addr_t insn_va, const D *d, unsigned insn_bits) = 0;
74 };
75
79 Decoder *find_idis(rose_addr_t insn_va, unsigned insn_bits) const;
80
84 void insert_idis(Decoder*, bool replace=false);
85
90 SgAsmMipsInstruction *disassemble_insn(Address insn_va, unsigned insn_bits, const std::vector<uint8_t> &bytes) const;
91
92
94 // The following functions are used by the various instruction-specific Mips32 subclasses.
95
97 SgAsmMipsInstruction *makeInstruction(rose_addr_t insn_va, MipsInstructionKind,
98 SgAsmExpression *arg1=NULL, SgAsmExpression *arg2=NULL,
99 SgAsmExpression *arg3=NULL, SgAsmExpression *arg4=NULL) const;
100
102 SgAsmType* makeType(MipsDataFormat) const;
103
105 SgAsmRegisterReferenceExpression *makeRegister(rose_addr_t insn_va, unsigned regnum) const;
106
108 SgAsmRegisterReferenceExpression *makeFpRegister(rose_addr_t insn_va, unsigned regnum, MipsDataFormat) const;
109
111 SgAsmRegisterReferenceExpression *makeCp0Register(rose_addr_t insn_va, unsigned regnum, unsigned sel) const;
112
115
119 SgAsmRegisterReferenceExpression *makeFpccRegister(rose_addr_t insn_va, unsigned cc) const;
120
123
126
128 SgAsmRegisterReferenceExpression *makeShadowRegister(rose_addr_t insn_va, unsigned regnum) const;
129
132 SgAsmIntegerValueExpression *makeImmediate8(unsigned value, size_t bit_offset, size_t nbits) const;
133
136 SgAsmIntegerValueExpression *makeImmediate16(unsigned value, size_t bit_offset, size_t nbits) const;
137
140 SgAsmIntegerValueExpression *makeImmediate32(unsigned value, size_t bit_offset, size_t nbits) const;
141
145 SgAsmIntegerValueExpression *makeBranchTargetRelative(rose_addr_t insn_va, unsigned offset16, size_t bit_offset,
146 size_t nbits) const;
147
151 SgAsmIntegerValueExpression *makeBranchTargetAbsolute(rose_addr_t insn_va, unsigned insn_index, size_t bit_offset,
152 size_t nbits) const;
153
157 SgAsmBinaryAdd *makeRegisterOffset(rose_addr_t insn_va, unsigned gprnum, unsigned offset16) const;
158
160 SgAsmBinaryAdd *makeRegisterIndexed(rose_addr_t insn_va, unsigned base_gprnum, unsigned index_gprnum) const;
161
164
166
167protected:
168 void init();
169
170protected:
173 std::vector<Decoder*> idis_table;
174};
175
176} // namespace
177} // namespace
178} // namespace
179
180#endif
181#endif
Virtual base class for instruction disassemblers.
Interface for disassembling a single instruction.
SgAsmRegisterReferenceExpression * makeHwRegister(unsigned regnum) const
Create a new register reference for a hardware register.
SgAsmMipsInstruction * makeInstruction(rose_addr_t insn_va, MipsInstructionKind, SgAsmExpression *arg1=NULL, SgAsmExpression *arg2=NULL, SgAsmExpression *arg3=NULL, SgAsmExpression *arg4=NULL) const
Create a new instruction.
void insert_idis(Decoder *, bool replace=false)
Insert an instruction-specific disassembler.
std::vector< Decoder * > idis_table
Table of instruction-specific disassemblers.
SgAsmRegisterReferenceExpression * makeFpccRegister(rose_addr_t insn_va, unsigned cc) const
Create a new floating point condition flag register reference expression.
SgAsmType * makeType(MipsDataFormat) const
Create a ROSE type form a MIPS data format.
SgAsmBinaryAdd * makeRegisterIndexed(rose_addr_t insn_va, unsigned base_gprnum, unsigned index_gprnum) const
Build a register index expression.
static Ptr instance(const Architecture::BaseConstPtr &)
Allocating constructor for MIPS decoder.
SgAsmRegisterReferenceExpression * makeCp2Register(unsigned regnum) const
Create a new register reference for Coprocessor 2.
SgAsmIntegerValueExpression * makeImmediate8(unsigned value, size_t bit_offset, size_t nbits) const
Create a new 8-bit value expression from an 8-bit value.
SgAsmMemoryReferenceExpression * makeMemoryReference(SgAsmExpression *addr, SgAsmType *type) const
Build a memory reference expression.
SgAsmIntegerValueExpression * makeBranchTargetAbsolute(rose_addr_t insn_va, unsigned insn_index, size_t bit_offset, size_t nbits) const
Create a 32-bit branch address from an instruction index value.
SgAsmRegisterReferenceExpression * makeFpRegister(rose_addr_t insn_va, unsigned regnum, MipsDataFormat) const
Create a new floating point register reference expression.
SgAsmRegisterReferenceExpression * makeRegister(rose_addr_t insn_va, unsigned regnum) const
Create a new general purpose register reference expression.
virtual Base::Ptr clone() const override
Creates a new copy of a disassembler.
SgAsmRegisterReferenceExpression * makeCp0Register(rose_addr_t insn_va, unsigned regnum, unsigned sel) const
Create a new register reference for Coprocessor 0.
Decoder * find_idis(rose_addr_t insn_va, unsigned insn_bits) const
Find an instruction-specific disassembler.
SgAsmRegisterReferenceExpression * makeShadowRegister(rose_addr_t insn_va, unsigned regnum) const
Create a new register reference for a shadow GPR.
SgAsmIntegerValueExpression * makeBranchTargetRelative(rose_addr_t insn_va, unsigned offset16, size_t bit_offset, size_t nbits) const
Create a 32-bit PC-relative branch target address from a 16-bit offset.
virtual SgAsmInstruction * makeUnknownInstruction(const Exception &) override
Makes an unknown instruction from an exception.
SgAsmIntegerValueExpression * makeImmediate32(unsigned value, size_t bit_offset, size_t nbits) const
Create a new 32-bit value expression from a 32-bit value.
SgAsmBinaryAdd * makeRegisterOffset(rose_addr_t insn_va, unsigned gprnum, unsigned offset16) const
Build an expression for an offset from a register.
SgAsmRegisterReferenceExpression * makeCp2ccRegister(unsigned cc) const
Create a new register reference for a COP2 condition code.
virtual SgAsmInstruction * disassembleOne(const MemoryMap::Ptr &, rose_addr_t start_va, AddressSet *successors=NULL) override
This is the lowest level disassembly function and is implemented in the architecture-specific subclas...
SgAsmMipsInstruction * disassemble_insn(Address insn_va, unsigned insn_bits, const std::vector< uint8_t > &bytes) const
Disassemble a single instruction.
SgAsmIntegerValueExpression * makeImmediate16(unsigned value, size_t bit_offset, size_t nbits) const
Create a new 16-bit value expression from a 16-bit value.
Reference-counting intrusive smart pointer.
Expression that adds two operands.
Base class for expressions.
Base class for machine instructions.
Base class for integer values.
Reference to memory locations.
Represents one MIPS machine instruction.
Base class for references to a machine register.
Base class for binary types.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.