ROSE  0.9.9.139
DisassemblerArm.h
1 /* Disassembly specific to the ARM architecture. */
2 
3 #ifndef ROSE_DISASSEMBLER_ARM_H
4 #define ROSE_DISASSEMBLER_ARM_H
5 
6 namespace Rose {
7 namespace BinaryAnalysis {
8 
11 public:
13  : decodeUnconditionalInstructions(true), ip(0), insn(0), cond(arm_cond_unknown) {
14  init();
15  }
16 
17  DisassemblerArm(const DisassemblerArm& other)
18  : Disassembler(other), decodeUnconditionalInstructions(other.decodeUnconditionalInstructions),
19  ip(other.ip), insn(other.insn), cond(other.cond) {
20  }
21 
22  virtual ~DisassemblerArm() {}
23 
24  virtual Disassembler *clone() const {
25  return new DisassemblerArm(*this);
26  }
27 
28  virtual bool canDisassemble(SgAsmGenericHeader*) const;
29  virtual Unparser::BasePtr unparser() const;
30  virtual SgAsmInstruction *disassembleOne(const MemoryMap::Ptr &map, rose_addr_t start_va, AddressSet *successors=NULL);
31  virtual void assembleOne(SgAsmInstruction*, SgUnsignedCharList&) {abort();}
32  virtual SgAsmInstruction *makeUnknownInstruction(const Exception&);
33 
34 private:
38  class ExceptionArm: public Exception {
39  public:
40  ExceptionArm(const std::string &mesg, const DisassemblerArm *d, size_t bit=0)
41  : Exception(mesg, d->ip) {
42  /* Convert four-byte instruction to little-endian buffer. FIXME: assumes little-endian ARM system */
43  bytes.push_back(d->insn & 0xff);
44  bytes.push_back((d->insn>>8) & 0xff);
45  bytes.push_back((d->insn>>16) & 0xff);
46  bytes.push_back((d->insn>>24) & 0xff);
47  this->bit = bit;
48  }
49  };
50 
51  static SgAsmArmInstruction *makeInstructionWithoutOperands(uint32_t address, const std::string& mnemonic, int condPos,
52  ArmInstructionKind kind, ArmInstructionCondition cond,
53  uint32_t insn);
54  SgAsmRegisterReferenceExpression *makeRegister(uint8_t reg) const;
55  SgAsmRegisterReferenceExpression *makePsrFields(bool useSPSR, uint8_t fields) const;
56  SgAsmRegisterReferenceExpression *makePsr(bool useSPSR) const;
57 
58  SgAsmExpression *makeRotatedImmediate() const;
59  SgAsmExpression *makeShifterField() const;
60  SgAsmArmInstruction *makeDataProcInstruction(uint8_t opcode, bool s, SgAsmExpression* rn, SgAsmExpression* rd,
61  SgAsmExpression* rhsOperand);
62  SgAsmIntegerValueExpression *makeSplit8bitOffset() const;
63  SgAsmIntegerValueExpression *makeBranchTarget() const;
64  SgAsmExpression *decodeMemoryAddress(SgAsmExpression* rn) const;
65  SgAsmArmInstruction *decodeMediaInstruction() const;
66  SgAsmArmInstruction *decodeMultiplyInstruction() const;
67  SgAsmArmInstruction *decodeExtraLoadStores() const;
68  SgAsmArmInstruction *decodeMiscInstruction() const;
69  SgAsmArmInstruction *disassemble();
70 
72  void init();
73 
75  void startInstruction(rose_addr_t start_va, uint32_t c) {
76  ip = start_va;
77  insn = c;
78  cond = arm_cond_unknown;
79  }
80 
81  /* Per-instruction data members (mostly set by startInstruction()) */
82  bool decodeUnconditionalInstructions;
83  uint32_t ip;
84  uint32_t insn;
85  ArmInstructionCondition cond;
86 };
87 
88 } // namespace
89 } // namespace
90 
91 #endif
Base class for references to a machine register.
Base class for machine instructions.
virtual Disassembler * clone() const
Creates a new copy of a disassembler.
virtual bool canDisassemble(SgAsmGenericHeader *) const
Predicate determining the suitability of a disassembler for a specific file header.
Main namespace for the ROSE library.
Base class for container file headers.
Base class for integer values.
Base class for expressions.
Represents one ARM machine instruction.
virtual Unparser::BasePtr unparser() const
Unparser.
Disassembler for the ARM architecture.
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:41
virtual SgAsmInstruction * disassembleOne(const MemoryMap::Ptr &map, rose_addr_t start_va, AddressSet *successors=NULL)
This is the lowest level disassembly function and is implemented in the architecture-specific subclas...
std::set< rose_addr_t > AddressSet
An AddressSet contains virtual addresses (alternatively, relative virtual addresses) for such things ...
Definition: Disassembler.h:82
virtual SgAsmInstruction * makeUnknownInstruction(const Exception &)
Makes an unknown instruction from an exception.