ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DisassemblerArm Class Reference

Disassembler for the ARM architecture. More...

#include <DisassemblerArm.h>

Inheritance diagram for DisassemblerArm:
Collaboration diagram for DisassemblerArm:

Classes

class  ExceptionArm
 Same as Disassembler::Exception except with a different constructor for ease of use in DisassemblerArm. More...
 

Public Member Functions

 DisassemblerArm ()
 
 DisassemblerArm (const DisassemblerArm &other)
 
virtual ~DisassemblerArm ()
 
virtual Disassemblerclone () const
 Creates a new copy of a disassembler. More...
 
virtual bool can_disassemble (SgAsmGenericHeader *) const
 See Disassembler::can_disassemble. More...
 
virtual SgAsmInstructiondisassembleOne (const MemoryMap *map, rose_addr_t start_va, AddressSet *successors=NULL)
 See Disassembler::disassembleOne. More...
 
virtual void assembleOne (SgAsmInstruction *, SgUnsignedCharList &)
 See Disassembler::assembleOne. More...
 
virtual SgAsmInstructionmake_unknown_instruction (const Exception &)
 See Disassembler::can_disassemble. 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 RegisterDictionaryget_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 Partitionerget_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...
 
SgAsmInstructiondisassembleOne (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...
 

Private Member Functions

SgAsmArmRegisterReferenceExpressionmakeRegister (uint8_t reg) const
 Creates a general-purpose register reference expression. More...
 
SgAsmArmRegisterReferenceExpressionmakePsrFields (bool useSPSR, uint8_t fields) const
 Create a reference to one of the program status registers. More...
 
SgAsmArmRegisterReferenceExpressionmakePsr (bool useSPSR) const
 
SgAsmExpressionmakeRotatedImmediate () const
 
SgAsmExpressionmakeShifterField () const
 Decode last 12 bits and bit 25 (I) More...
 
SgAsmArmInstructionmakeDataProcInstruction (uint8_t opcode, bool s, SgAsmExpression *rn, SgAsmExpression *rd, SgAsmExpression *rhsOperand)
 
SgAsmIntegerValueExpressionmakeSplit8bitOffset () const
 
SgAsmIntegerValueExpressionmakeBranchTarget () const
 
SgAsmExpressiondecodeMemoryAddress (SgAsmExpression *rn) const
 
SgAsmArmInstructiondecodeMediaInstruction () const
 
SgAsmArmInstructiondecodeMultiplyInstruction () const
 
SgAsmArmInstructiondecodeExtraLoadStores () const
 
SgAsmArmInstructiondecodeMiscInstruction () const
 
SgAsmArmInstructiondisassemble ()
 
void init ()
 Initialize instances of this class. More...
 
void startInstruction (rose_addr_t start_va, uint32_t c)
 Resets disassembler state to beginning of an instruction. More...
 

Static Private Member Functions

static SgAsmArmInstructionmakeInstructionWithoutOperands (uint32_t address, const std::string &mnemonic, int condPos, ArmInstructionKind kind, ArmInstructionCondition cond, uint32_t insn)
 

Private Attributes

bool decodeUnconditionalInstructions
 set by init() More...
 
uint32_t ip
 instruction pointer More...
 
uint32_t insn
 4-byte instruction word More...
 
ArmInstructionCondition cond
 

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_tAddressSet
 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 Disassemblerlookup (SgAsmGenericHeader *)
 Finds a suitable disassembler. More...
 
static Disassemblerlookup (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...
 
- Protected Attributes inherited from Disassembler
const RegisterDictionaryp_registers
 Description of registers available for this platform. More...
 
class Partitionerp_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...
 
- 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...
 

Detailed Description

Disassembler for the ARM architecture.

Most of the useful disassembly methods can be found in the superclass.

Definition at line 7 of file DisassemblerArm.h.

Constructor & Destructor Documentation

DisassemblerArm::DisassemblerArm ( )
inline

Definition at line 9 of file DisassemblerArm.h.

References init().

Referenced by clone().

DisassemblerArm::DisassemblerArm ( const DisassemblerArm other)
inline

Definition at line 14 of file DisassemblerArm.h.

virtual DisassemblerArm::~DisassemblerArm ( )
inlinevirtual

Definition at line 19 of file DisassemblerArm.h.

Member Function Documentation

virtual Disassembler* DisassemblerArm::clone ( ) const
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 21 of file DisassemblerArm.h.

References DisassemblerArm().

bool DisassemblerArm::can_disassemble ( SgAsmGenericHeader header) const
virtual
SgAsmInstruction * DisassemblerArm::disassembleOne ( const MemoryMap map,
rose_addr_t  start_va,
AddressSet successors = NULL 
)
virtual
virtual void DisassemblerArm::assembleOne ( SgAsmInstruction ,
SgUnsignedCharList  
)
inlinevirtual

See Disassembler::assembleOne.

Definition at line 32 of file DisassemblerArm.h.

SgAsmArmInstruction * DisassemblerArm::makeInstructionWithoutOperands ( uint32_t  address,
const std::string &  mnemonic,
int  condPos,
ArmInstructionKind  kind,
ArmInstructionCondition  cond,
uint32_t  insn 
)
staticprivate
SgAsmArmRegisterReferenceExpression * DisassemblerArm::makeRegister ( uint8_t  reg) const
private
SgAsmArmRegisterReferenceExpression * DisassemblerArm::makePsrFields ( bool  useSPSR,
uint8_t  fields 
) const
private

Create a reference to one of the program status registers.

If useSPSR is true then create a reference to the saved program status register, otherwise create a reference to the current program status register. The fields is a 4-bit mask indicating which individual fields of the register are selected.

The field bits are 0x01 => c control field mask bit 0x02 => x extension field mask bit 0x04 => s status field mask bit 0x08 => f flags field mask bit

Definition at line 121 of file DisassemblerArm.C.

References Disassembler::get_registers(), RegisterDictionary::lookup(), name, and SgAsmArmRegisterReferenceExpression::set_psr_mask().

Referenced by decodeMiscInstruction(), disassemble(), and makePsr().

SgAsmArmRegisterReferenceExpression * DisassemblerArm::makePsr ( bool  useSPSR) const
private

Definition at line 134 of file DisassemblerArm.C.

References makePsrFields().

Referenced by decodeMiscInstruction().

SgAsmExpression * DisassemblerArm::makeRotatedImmediate ( ) const
private

Definition at line 141 of file DisassemblerArm.C.

References insn, and SageBuilderAsm::makeDWordValue().

Referenced by disassemble(), and makeShifterField().

SgAsmArmInstruction * DisassemblerArm::makeDataProcInstruction ( uint8_t  opcode,
bool  s,
SgAsmExpression rn,
SgAsmExpression rd,
SgAsmExpression rhsOperand 
)
private

Definition at line 195 of file DisassemblerArm.C.

References cfgUtils::add, MAKE_INSN2, and MAKE_INSN3.

Referenced by disassemble().

SgAsmIntegerValueExpression * DisassemblerArm::makeSplit8bitOffset ( ) const
private

Definition at line 238 of file DisassemblerArm.C.

References insn, and SageBuilderAsm::makeDWordValue().

Referenced by decodeExtraLoadStores().

SgAsmIntegerValueExpression * DisassemblerArm::makeBranchTarget ( ) const
private

Definition at line 247 of file DisassemblerArm.C.

References insn, ip, and SageBuilderAsm::makeDWordValue().

Referenced by disassemble().

SgAsmArmInstruction * DisassemblerArm::decodeMediaInstruction ( ) const
private

Definition at line 282 of file DisassemblerArm.C.

References insn, and StringUtility::intToHex().

Referenced by disassemble().

SgAsmArmInstruction * DisassemblerArm::decodeMultiplyInstruction ( ) const
private

Definition at line 289 of file DisassemblerArm.C.

References insn, MAKE_INSN3, MAKE_INSN4, and makeRegister().

Referenced by disassemble().

SgAsmArmInstruction * DisassemblerArm::decodeMiscInstruction ( ) const
private
void DisassemblerArm::init ( )
private
void DisassemblerArm::startInstruction ( rose_addr_t  start_va,
uint32_t  c 
)
inlineprivate

Resets disassembler state to beginning of an instruction.

Definition at line 78 of file DisassemblerArm.h.

References cond, insn, and ip.

Referenced by disassembleOne().

Member Data Documentation

bool DisassemblerArm::decodeUnconditionalInstructions
private

set by init()

Definition at line 85 of file DisassemblerArm.h.

Referenced by disassemble(), and init().

uint32_t DisassemblerArm::ip
private

instruction pointer

Definition at line 86 of file DisassemblerArm.h.

Referenced by makeBranchTarget(), and startInstruction().

ArmInstructionCondition DisassemblerArm::cond
private

Definition at line 88 of file DisassemblerArm.h.

Referenced by disassemble(), and startInstruction().


The documentation for this class was generated from the following files: