ROSE
0.9.6a
|
#include <DisassemblerMips.h>
Classes | |
class | Mips32 |
Interface for disassembling a single instruction. More... | |
Public Member Functions | |
DisassemblerMips () | |
virtual DisassemblerMips * | clone () const |
Creates a new copy of a disassembler. More... | |
virtual bool | can_disassemble (SgAsmGenericHeader *) const |
Predicate determining the suitability of a disassembler for a specific file header. More... | |
virtual SgAsmInstruction * | disassembleOne (const MemoryMap *, rose_addr_t start_va, AddressSet *successors=NULL) |
This is the lowest level disassembly function and is implemented in the architecture-specific subclasses. More... | |
virtual SgAsmInstruction * | make_unknown_instruction (const Disassembler::Exception &) |
Makes an unknown instruction from an exception. More... | |
Mips32 * | find_idis (unsigned insn_bits) |
Find an instruction-specific disassembler. More... | |
void | insert_idis (Mips32 *, bool replace=false) |
Insert an instruction-specific disassembler. More... | |
SgAsmMipsInstruction * | disassemble_insn (unsigned insn_bits) |
Disassemble a single instruction. More... | |
rose_addr_t | get_ip () const |
Obtain the virtual address for the instruction being disassembled. More... | |
SgAsmMipsInstruction * | makeInstruction (MipsInstructionKind, const std::string &mnemonic, SgAsmExpression *arg1=NULL, SgAsmExpression *arg2=NULL, SgAsmExpression *arg3=NULL, SgAsmExpression *arg4=NULL) |
Create a new instruction. More... | |
SgAsmMipsRegisterReferenceExpression * | makeRegister (unsigned regnum) |
Create a new general purpose register reference expression. More... | |
SgAsmMipsRegisterReferenceExpression * | makeFpRegister (unsigned regnum) |
Create a new floating point register reference expression. More... | |
SgAsmMipsRegisterReferenceExpression * | makeCp0Register (unsigned regnum, unsigned sel) |
Create a new register reference for Coprocessor 0. More... | |
SgAsmMipsRegisterReferenceExpression * | makeCp2Register (unsigned regnum) |
Create a new register reference for Coprocessor 2. More... | |
SgAsmMipsRegisterReferenceExpression * | makeFpccRegister (unsigned cc) |
Create a new floating point condition flag register reference expression. More... | |
SgAsmMipsRegisterReferenceExpression * | makeCp2ccRegister (unsigned cc) |
Create a new register reference for a COP2 condition code. More... | |
SgAsmMipsRegisterReferenceExpression * | makeHwRegister (unsigned regnum) |
Create a new register reference for a hardware register. More... | |
SgAsmMipsRegisterReferenceExpression * | makeShadowRegister (unsigned regnum) |
Create a new register reference for a shadow GPR. More... | |
SgAsmIntegerValueExpression * | makeImmediate8 (unsigned value, size_t bit_offset, size_t nbits) |
Create a new 8-bit value expression from an 8-bit value. More... | |
SgAsmIntegerValueExpression * | makeImmediate16 (unsigned value, size_t bit_offset, size_t nbits) |
Create a new 16-bit value expression from a 16-bit value. More... | |
SgAsmIntegerValueExpression * | makeImmediate32 (unsigned value, size_t bit_offset, size_t nbits) |
Create a new 32-bit value expression from a 32-bit value. More... | |
SgAsmIntegerValueExpression * | makeBranchTargetRelative (unsigned offset16, size_t bit_offset, size_t nbits) |
Create a 32-bit PC-relative branch target address from a 16-bit offset. More... | |
SgAsmIntegerValueExpression * | makeBranchTargetAbsolute (unsigned insn_index, size_t bit_offset, size_t nbits) |
Create a 32-bit branch address from an instruction index value. More... | |
SgAsmBinaryAdd * | makeRegisterOffset (unsigned gprnum, unsigned offset16) |
Build an expression for an offset from a register. More... | |
SgAsmBinaryAdd * | makeRegisterIndexed (unsigned base_gprnum, unsigned index_gprnum) |
Build a register index expression. More... | |
SgAsmMemoryReferenceExpression * | makeMemoryReference (SgAsmExpression *addr, SgAsmType *type) |
Build a memory reference expression. More... | |
Public Member Functions inherited from Disassembler | |
Disassembler () | |
Disassembler (const Disassembler &other) | |
virtual | ~Disassembler () |
void | disassemble (SgAsmInterpretation *, AddressSet *successors=NULL, BadMap *bad=NULL) |
This high-level method disassembles instructions belonging to part of a file described by an executable file header as indicated by the specified interpretation. More... | |
void | set_registers (const RegisterDictionary *rdict) |
Specifies the registers available on this architecture. More... | |
const RegisterDictionary * | get_registers () const |
Returns the dictionary used for looking up register names. More... | |
void | set_partitioner (class Partitioner *p) |
Specifies the instruction partitioner to use when partitioning instructions into functions. More... | |
class Partitioner * | get_partitioner () const |
Returns the partitioner object set by set_partitioner(). More... | |
void | set_search (unsigned bits) |
Specifies the heuristics used when searching for instructions. More... | |
unsigned | get_search () const |
Returns a bit mask of SearchHeuristic bits representing which heuristics would be used when searching for instructions. More... | |
void | set_wordsize (size_t) |
Specifies the word size for the SEARCH_WORDS heuristic. More... | |
size_t | get_wordsize () const |
Returns the word size used by the SEARCH_WORDS heuristic. More... | |
void | set_alignment (size_t) |
Specifies the alignment for the SEARCH_WORDS heuristic. More... | |
size_t | get_alignment () const |
Returns the alignment used by the SEARCH_WORDS heuristic. More... | |
void | set_sex (ByteOrder::Endianness sex) |
Specifies the byte order for the SEARCH_WORDS heuristic. More... | |
ByteOrder::Endianness | get_sex () const |
Returns the byte order used by the SEARCH_WORDS heuristic. More... | |
void | set_debug (FILE *f) |
Sends disassembler diagnostics to the specified output stream. More... | |
FILE * | get_debug () const |
Returns the file currently used for debugging; null implies no debugging. More... | |
size_t | get_ndisassembled () const |
Returns the number of instructions successfully disassembled. More... | |
void | set_protection (unsigned bitvec) |
Normally the disassembler will only read memory when the execute permission is turned on for the memory. More... | |
unsigned | get_protection () const |
Returns a bit vector describing which bits must be enabled in the MemoryMap in order for the disassembler to read from that memory. More... | |
void | set_progress_reporting (FILE *, unsigned min_interval) |
Set progress reporting properties. More... | |
SgAsmInstruction * | disassembleOne (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL) |
Similar in functionality to the disassembleOne method that takes a MemoryMap argument, except the content buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBlock (const MemoryMap *map, rose_addr_t start_va, AddressSet *successors=NULL, InstructionMap *cache=NULL) |
Like the disassembleOne method except it disassembles a basic block's worth of instructions beginning at the specified virtual address. More... | |
InstructionMap | disassembleBlock (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL, InstructionMap *cache=NULL) |
Similar in functionality to the disassembleBlock method that takes a MemoryMap argument, except the supplied buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBuffer (const MemoryMap *map, size_t start_va, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions from the content buffer beginning at the specified virtual address and including all instructions that are direct or indirect successors of the first instruction. More... | |
InstructionMap | disassembleBuffer (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL, BadMap *bad=NULL) |
Similar in functionality to the disassembleBuffer methods that take a MemoryMap argument, except the supplied buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBuffer (const MemoryMap *map, AddressSet workset, AddressSet *successors=NULL, BadMap *bad=NULL) |
Similar in functionality to the disassembleBuffer methods that take a single starting virtual address, except this one tries to disassemble from all the addresses specified in the workset. More... | |
InstructionMap | disassembleSection (SgAsmGenericSection *section, rose_addr_t section_va, rose_addr_t start_offset, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions in the specified section by assuming that it's mapped to a particular starting address. More... | |
InstructionMap | disassembleInterp (SgAsmInterpretation *interp, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions in a particular binary interpretation. More... | |
void | search_following (AddressSet *worklist, const InstructionMap &bb, rose_addr_t bb_va, const MemoryMap *map, const InstructionMap &tried) |
Adds the address following a basic block to the list of addresses that should be disassembled. More... | |
void | search_immediate (AddressSet *worklist, const InstructionMap &bb, const MemoryMap *map, const InstructionMap &tried) |
Adds values of immediate operands to the list of addresses that should be disassembled. More... | |
void | search_words (AddressSet *worklist, const MemoryMap *map, const InstructionMap &tried) |
Adds all word-aligned values to work list, provided they specify a virtual address in the map . More... | |
void | search_next_address (AddressSet *worklist, rose_addr_t start_va, const MemoryMap *map, const InstructionMap &insns, const InstructionMap &tried, bool avoid_overlaps) |
Finds the lowest virtual address, greater than or equal to start_va , which does not correspond to a previous disassembly attempt as evidenced by its presence in the supplied instructions or bad map. More... | |
void | search_function_symbols (AddressSet *worklist, const MemoryMap *, SgAsmGenericHeader *) |
Adds addresses that correspond to function symbols. More... | |
void | update_progress (SgAsmInstruction *) |
Updates progress information. More... | |
void | progress (FILE *, const char *fmt,...) const __attribute__((format(printf |
Conditionally prints a progress report. More... | |
void | mark_referenced_instructions (SgAsmInterpretation *, const MemoryMap *, const InstructionMap &) |
Marks parts of the file that correspond to instructions as having been referenced. More... | |
AddressSet | get_block_successors (const InstructionMap &, bool *complete) |
Calculates the successor addresses of a basic block and adds them to a successors set. More... | |
Protected Member Functions | |
void | init () |
Protected Attributes | |
std::vector< Mips32 * > | idis_table |
Table of instruction-specific disassemblers. More... | |
rose_addr_t | insn_va |
Address of instruction currently being disassembled. More... | |
Protected Attributes inherited from Disassembler | |
const RegisterDictionary * | p_registers |
Description of registers available for this platform. More... | |
class Partitioner * | p_partitioner |
Used for placing instructions into blocks and functions. More... | |
unsigned | p_search |
Mask of SearchHeuristic bits specifying instruction searching. More... | |
FILE * | p_debug |
Set to non-null to get debugging info. More... | |
size_t | p_wordsize |
Word size used by SEARCH_WORDS. More... | |
ByteOrder::Endianness | p_sex |
Byte order for SEARCH_WORDS. More... | |
size_t | p_alignment |
Word alignment constraint for SEARCH_WORDS (0 and 1 imply byte). More... | |
size_t | p_ndisassembled |
Total number of instructions disassembled by disassembleBlock() More... | |
unsigned | p_protection |
Memory protection bits that must be set to disassemble. More... | |
Additional Inherited Members | |
Public Types inherited from Disassembler | |
enum | SearchHeuristic { SEARCH_FOLLOWING = 0x0001, SEARCH_IMMEDIATE = 0x0002, SEARCH_WORDS = 0x0004, SEARCH_ALLBYTES = 0x0008, SEARCH_UNUSED = 0x0010, SEARCH_NONEXE = 0x0020, SEARCH_DEADEND = 0x0040, SEARCH_UNKNOWN = 0x0080, SEARCH_FUNCSYMS = 0x0100, SEARCH_DEFAULT = 0x0101 } |
Heuristics used to find instructions to disassemble. More... | |
typedef std::set< rose_addr_t > | AddressSet |
An AddressSet contains virtual addresses (alternatively, relative virtual addresses) for such things as specifying which virtual addresses should be disassembled. More... | |
typedef Map< rose_addr_t, SgAsmInstruction * > | InstructionMap |
The InstructionMap is a mapping from (absolute) virtual address to disassembled instruction. More... | |
typedef Map< rose_addr_t, Exception > | BadMap |
The BadMap is a mapping from (absolute) virtual address to information about a failed disassembly attempt at that address. More... | |
Static Public Member Functions inherited from Disassembler | |
static unsigned | parse_switches (const std::string &s, unsigned initial=SEARCH_DEFAULT) |
Given a string (presumably from the ROSE command-line), parse it and return the bit vector describing which search heuristics should be employed by the disassembler. More... | |
static void | register_subclass (Disassembler *) |
Register a disassembler instance. More... | |
static Disassembler * | lookup (SgAsmGenericHeader *) |
Finds a suitable disassembler. More... | |
static Disassembler * | lookup (SgAsmInterpretation *) |
Finds a suitable disassembler. More... | |
static void | disassembleInterpretation (SgAsmInterpretation *) |
This class method is for backward compatibility with the disassembleInterpretation() function in the old Disassembler namespace. More... | |
Static Protected Attributes inherited from Disassembler | |
static std::vector < Disassembler * > | disassemblers |
List of disassembler subclasses. More... | |
static time_t | progress_interval = 10 |
Minimum interval between progress reports. More... | |
static time_t | progress_time = 0 |
Time of last report, or zero if no report has been generated. More... | |
static FILE * | progress_file = stderr |
File to which reports are made. More... | |
static RTS_mutex_t | class_mutex = RTS_MUTEX_INITIALIZER(RTS_LAYER_DISASSEMBLER_CLASS) |
Mutex for class-wide thread safety. More... | |
Definition at line 9 of file DisassemblerMips.h.
|
inline |
|
inlinevirtual |
Creates a new copy of a disassembler.
The new copy has all the same settings as the original.
Thread safety: The thread safety of this virtual method depends on the implementation in the subclass.
Implements Disassembler.
Definition at line 12 of file DisassemblerMips.h.
References DisassemblerMips().
|
virtual |
Predicate determining the suitability of a disassembler for a specific file header.
If this disassembler is capable of disassembling machine code described by the specified file header, then this predicate returns true, otherwise it returns false.
Thread safety: The thread safety of this virtual method depends on the implementation in the subclass.
Implements Disassembler.
|
virtual |
This is the lowest level disassembly function and is implemented in the architecture-specific subclasses.
It disassembles one instruction at the specified virtual address. The map
is a mapping from virtual addresses to buffer and enables instructions to span file segments that are mapped contiguously in virtual memory by the loader but which might not be contiguous in the file. The instruction's successor virtual addresses are added to the optional successor set (note that successors of an individual instruction can also be obtained via SgAsmInstruction::get_successors). If the instruction cannot be disassembled then an exception is thrown and the successors set is not modified.
Thread safety: The safety of this method depends on its implementation in the subclass. In any case, no other thread can be modifying the MemoryMap or successors set at the same time.
Implements Disassembler.
|
virtual |
Makes an unknown instruction from an exception.
Thread safety: The safety of this method depends on its implementation in the subclass.
Implements Disassembler.
Mips32* DisassemblerMips::find_idis | ( | unsigned | insn_bits) |
Find an instruction-specific disassembler.
Using the specified instruction bits, search for and return an instruction-specific disassembler. Returns null if no appropriate disassembler can be found. Instruction-specific disassemblers know how to disassemble specific instruction types (or groups of closely related instructions).
void DisassemblerMips::insert_idis | ( | Mips32 * | , |
bool | replace = false |
||
) |
Insert an instruction-specific disassembler.
If replace
is false (the default) then the table must not already contain an entry that has the same mask
and match
values. The pointers are managed by the caller and must not be deleted while they are in the table.
SgAsmMipsInstruction* DisassemblerMips::disassemble_insn | ( | unsigned | insn_bits) |
Disassemble a single instruction.
Given the bits of a MIPS32 instruction, attempt to disassemble the instruction. If the bits can be disassembled, then a new SgAsmMipsInstruction is returned, otherwise it returns the null pointer. It may also throw an exception if a valid instruction-specific disassembler can be found but the instruction is malformed.
|
inline |
Obtain the virtual address for the instruction being disassembled.
Definition at line 56 of file DisassemblerMips.h.
References insn_va.
SgAsmMipsInstruction* DisassemblerMips::makeInstruction | ( | MipsInstructionKind | , |
const std::string & | mnemonic, | ||
SgAsmExpression * | arg1 = NULL , |
||
SgAsmExpression * | arg2 = NULL , |
||
SgAsmExpression * | arg3 = NULL , |
||
SgAsmExpression * | arg4 = NULL |
||
) |
Create a new instruction.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeRegister | ( | unsigned | regnum) |
Create a new general purpose register reference expression.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeFpRegister | ( | unsigned | regnum) |
Create a new floating point register reference expression.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeCp0Register | ( | unsigned | regnum, |
unsigned | sel | ||
) |
Create a new register reference for Coprocessor 0.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeCp2Register | ( | unsigned | regnum) |
Create a new register reference for Coprocessor 2.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeFpccRegister | ( | unsigned | cc) |
Create a new floating point condition flag register reference expression.
The return value is a reference to one of the bits from the FCSR register. If cc
is zero then bit 23 is referenced, otherwise bit 24+cc is referenced. The cc
value must be zero through seven, inclusive.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeCp2ccRegister | ( | unsigned | cc) |
Create a new register reference for a COP2 condition code.
See COP2ConditionCode() in the MIPS reference manual.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeHwRegister | ( | unsigned | regnum) |
Create a new register reference for a hardware register.
See the RDHWR instruction documentation.
SgAsmMipsRegisterReferenceExpression* DisassemblerMips::makeShadowRegister | ( | unsigned | regnum) |
Create a new register reference for a shadow GPR.
SgAsmIntegerValueExpression* DisassemblerMips::makeImmediate8 | ( | unsigned | value, |
size_t | bit_offset, | ||
size_t | nbits | ||
) |
Create a new 8-bit value expression from an 8-bit value.
The bit_offset
and nbits
indicate where the value originally came from in the instruction.
SgAsmIntegerValueExpression* DisassemblerMips::makeImmediate16 | ( | unsigned | value, |
size_t | bit_offset, | ||
size_t | nbits | ||
) |
Create a new 16-bit value expression from a 16-bit value.
The bit_offset
and nbits
indicate where the value originally came from in the instruction.
SgAsmIntegerValueExpression* DisassemblerMips::makeImmediate32 | ( | unsigned | value, |
size_t | bit_offset, | ||
size_t | nbits | ||
) |
Create a new 32-bit value expression from a 32-bit value.
The bit_offset
and nbits
indicate where the value originally came from in the instruction.
SgAsmIntegerValueExpression* DisassemblerMips::makeBranchTargetRelative | ( | unsigned | offset16, |
size_t | bit_offset, | ||
size_t | nbits | ||
) |
Create a 32-bit PC-relative branch target address from a 16-bit offset.
The bit_offset
and nbits
indicate where the value originally came from in the instruction (usually 0 and 16, respectively). The return address is the address of the delay slot plus four times the signed offset16
.
SgAsmIntegerValueExpression* DisassemblerMips::makeBranchTargetAbsolute | ( | unsigned | insn_index, |
size_t | bit_offset, | ||
size_t | nbits | ||
) |
Create a 32-bit branch address from an instruction index value.
The returned value is the insn_index
(nbits
wide) multiplied by four and then combined with the address of the delay slot. They are combined such that the low-order nbits+2
bits are from the product and the upper bits are from the delay slot address.
SgAsmBinaryAdd* DisassemblerMips::makeRegisterOffset | ( | unsigned | gprnum, |
unsigned | offset16 | ||
) |
Build an expression for an offset from a register.
The return value is GPR[regnum]+signExtend(offset) expressed as an SgAsmBinaryAdd expression whose first operand is the register reference expression and second operand is the sign-extended offset.
SgAsmBinaryAdd* DisassemblerMips::makeRegisterIndexed | ( | unsigned | base_gprnum, |
unsigned | index_gprnum | ||
) |
Build a register index expression.
The returned value is makeRegister(base_gprnum)+makeRegister(index_gprnum).
SgAsmMemoryReferenceExpression* DisassemblerMips::makeMemoryReference | ( | SgAsmExpression * | addr, |
SgAsmType * | type | ||
) |
Build a memory reference expression.
|
protected |
Referenced by DisassemblerMips().
|
protected |
Table of instruction-specific disassemblers.
This is the table of instruction-specific disassemblers consulted by find_idis().
Definition at line 130 of file DisassemblerMips.h.
|
protected |
Address of instruction currently being disassembled.
This is set each time disassembleOne() is called.
Definition at line 133 of file DisassemblerMips.h.
Referenced by get_ip().