Ghidra Decompiler Analysis Engine
|
Go to the documentation of this file.
21 #ifndef __CPUI_TRANSLATE__
22 #define __CPUI_TRANSLATE__
68 const string &getName(
void)
const {
return spaceName; }
69 uint4 getSize(
void)
const {
return size; }
107 static const uint1 *
unpackOffset(
const uint1 *ptr,uintb &off);
131 virtual void dump(
const Address &addr,
const string &mnem,
const string &body)=0;
173 bool hasbaseregister;
174 bool isNegativeStack;
177 void setBaseRegister(
const VarnodeData &data,int4 origSize,
bool stackGrowth);
186 virtual void saveXml(ostream &s)
const;
197 vector<VarnodeData> pieces;
200 int4 numPieces(
void)
const {
return pieces.
size(); }
201 bool isFloatExtension(
void)
const {
return (pieces.size() == 1); }
202 const VarnodeData &getPiece(int4 i)
const {
return pieces[i]; }
203 const VarnodeData &getUnified(
void)
const {
return unified; }
219 vector<AddrSpace *> baselist;
220 vector<AddressResolver *> resolvelist;
221 map<string,AddrSpace *> name2Space;
222 map<int4,AddrSpace *> shortcut2Space;
232 set<JoinRecord *,JoinRecordCompare> splitset;
233 vector<JoinRecord *> splitlist;
295 bool target_isbigendian;
384 virtual void getAllRegisters(map<VarnodeData,string> ®list)
const=0;
492 return defaultcodespace;
501 return defaultdataspace;
509 return constantspace;
519 return Address(constantspace,val);
529 return Address(constantspace,(uintb)(uintp)spc);
537 return baselist.size();
554 target_isbigendian = val;
565 if (val>unique_base) unique_base = val;
573 return target_isbigendian;
virtual string getRegisterName(AddrSpace *base, uintb off, int4 size) const =0
Get the name of a register given its location.
AddrSpaceManager(void)
Construct an empty address space manager.
Definition: translate.cc:178
virtual void getAllRegisters(map< VarnodeData, string > ®list) const =0
Get a list of all register names and the corresponding location.
AddrSpace * restoreXmlSpace(const Element *el, const Translate *trans)
Add a space to the model based an on XML tag.
Definition: translate.cc:200
void restoreXmlOp(const Element *el, const AddrSpaceManager *trans)
Emit pcode directly from an XML tag.
Definition: translate.cc:894
virtual int4 printAssembly(AssemblyEmit &emit, const Address &baseaddr) const =0
Disassemble a single machine instruction.
Abstract class for emitting pcode to an application.
Definition: translate.hh:76
void insertResolver(AddrSpace *spc, AddressResolver *rsolv)
Override the base resolver for a space.
Definition: translate.cc:413
JoinRecord * findJoin(uintb offset) const
Find JoinRecord for offset in the join space.
Definition: translate.cc:689
A region where processor data is stored.
Definition: space.hh:73
void copySpaces(const AddrSpaceManager *op2)
Copy spaces from another manager.
Definition: translate.cc:387
virtual int4 oneInstruction(PcodeEmit &emit, const Address &baseaddr) const =0
Transform a single machine instruction into pcode.
int4 alignment
Byte modulo on which instructions are aligned.
Definition: translate.hh:298
The lowest level error generated by the decompiler.
Definition: error.hh:44
Exception for encountering unimplemented pcode.
Definition: translate.hh:35
uint4 getAddrSize(void) const
Get the size of the space.
Definition: space.hh:335
Address constructJoinAddress(const Translate *translate, const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz)
Build a logical whole from register pairs.
Definition: translate.cc:760
const uint1 * restorePackedOp(const Address &addr, const uint1 *ptr, const AddrSpaceManager *trans)
Emit pcode directly from a packed byte stream.
Definition: translate.cc:984
virtual void allowContextSet(bool val) const
Toggle whether disassembly is allowed to affect context.
Definition: translate.hh:347
AddrSpace * getConstantSpace(void) const
Get the constant space.
Definition: translate.hh:508
Abstract class for emitting disassembly to an application.
Definition: translate.hh:118
virtual void registerContext(const string &name, int4 sbit, int4 ebit)
Add a new context variable to the model for this processor.
Definition: translate.hh:328
void truncateSpace(const TruncationTag &tag)
Mark a space as truncated from its original size.
Definition: translate.cc:719
Address getConstant(uintb val) const
Get a constant encoded as an Address.
Definition: translate.hh:518
Address createConstFromSpace(AddrSpace *spc) const
Create a constant address encoding an address space.
Definition: translate.hh:528
void setDefaultFloatFormats(void)
If no explicit float formats, set up default formats.
Definition: translate.cc:862
int4 numSpaces(void) const
Get the number of address spaces for this processor.
Definition: translate.hh:536
A record describing how logical values are split.
Definition: translate.hh:195
static const uint1 * unpackOffset(const uint1 *ptr, uintb &off)
Helper function for unpacking an offset from a pcode byte stream.
Definition: translate.cc:934
AddrSpace * getJoinSpace(void) const
Get the joining space.
Definition: translate.hh:461
virtual void restoreXml(const Element *el)
Recover the details of this space from XML.
Definition: translate.cc:114
void markNearPointers(AddrSpace *spc, int4 size)
Mark that given space can be accessed with near pointers.
Definition: translate.cc:521
Comparator for JoinRecord objects.
Definition: translate.hh:209
void setUniqueBase(uintm val)
Set the base offset for new temporary registers.
Definition: translate.hh:564
SpacebaseSpace(AddrSpaceManager *m, const Translate *t, const string &nm, int4 ind, int4 sz, AddrSpace *base, int4 dl)
Definition: translate.cc:38
virtual void setContextDefault(const string &name, uintm val)
Set the default value for a particular context variable.
Definition: translate.hh:337
AddrSpace * getSpaceByShortcut(char sc) const
Get address space from its shortcut.
Definition: translate.cc:548
AddrSpace * getSpace(int4 i) const
Get an address space via its index.
Definition: translate.hh:545
Support for decoding different floating-point formats.
void assignShortcut(AddrSpace *spc)
Select a shortcut character for a new space.
Definition: translate.cc:461
static const uint1 * unpackVarnodeData(const uint1 *ptr, VarnodeData &v, const AddrSpaceManager *trans)
Helper function for unpacking a varnode from a pcode byte stream.
Definition: translate.cc:956
An XML element. A node in the DOM tree.
Definition: xml.hh:150
void setBigEndian(bool val)
Set general endianness to big if val is true.
Definition: translate.hh:553
virtual int4 numSpacebase(void) const
Number of base registers associated with this space.
Definition: translate.cc:83
Abstract class for converting native constants to addresses.
Definition: translate.hh:140
bool operator<(const JoinRecord &op2) const
Compare records lexigraphically by pieces.
Definition: translate.cc:158
AddrSpace * getUniqueSpace(void) const
Get the temporary register space for this processor.
Definition: translate.hh:482
Exception for bad instruction data.
Definition: translate.hh:50
uint4 size
The number of bytes in the location.
Definition: pcoderaw.hh:36
Address constructFloatExtensionAddress(const Address &realaddr, int4 realsize, int4 logicalsize)
Build a logically lower precision storage location for a bigger floating point register.
Definition: translate.cc:735
AddrSpace * getDefaultCodeSpace(void) const
Get the default address space of this processor.
Definition: translate.hh:491
JoinRecord * findJoinInternal(uintb offset) const
Find JoinRecord for offset in the join space.
Definition: translate.cc:665
void setDefaultDataSpace(int4 index)
Set the default address space for data.
Definition: translate.cc:268
Translate(void)
Constructor for the translator.
Definition: translate.cc:851
Object for describing how a space should be truncated.
Definition: translate.hh:63
int4 instruction_length
Definition: translate.hh:36
virtual void dump(const Address &addr, OpCode opc, VarnodeData *outvar, VarnodeData *vars, int4 isize)=0
The main pcode emit method.
virtual void getUserOpNames(vector< string > &res) const =0
Get a list of all user-defined pcode ops.
void renormalizeJoinAddress(Address &addr, int4 size)
Make sure a possibly offset join address has a proper JoinRecord.
Definition: translate.cc:813
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
AddrSpace * getIopSpace(void) const
Get the internal pcode op space.
Definition: translate.hh:443
A virtual space stack space.
Definition: translate.hh:170
virtual int4 instructionLength(const Address &baseaddr) const =0
Get the length of a machine instruction.
virtual void addRegister(const string &nm, AddrSpace *base, uintb offset, int4 size)=0
Add a named register to the model for this processor.
void setInferPtrBounds(const Range &range)
Set the range of addresses that can be inferred as pointers.
Definition: translate.cc:427
void setDefaultCodeSpace(int4 index)
Set the default address space (for code)
Definition: translate.cc:254
Address resolveConstant(AddrSpace *spc, uintb val, int4 sz, const Address &point, uintb &fullEncoding) const
Resolve a native constant into an Address.
Definition: translate.cc:572
void restoreXml(const Element *el)
Restore this from XML.
Definition: translate.cc:20
AddrSpace * getDefaultDataSpace(void) const
Get the default address space where data is stored.
Definition: translate.hh:500
The interface to a translation engine for a processor.
Definition: translate.hh:294
virtual void saveXml(ostream &s) const
Write the details of this space as XML.
Definition: translate.cc:105
JoinRecord * findAddJoin(const vector< VarnodeData > &pieces, uint4 logicalsize)
Get (or create) JoinRecord for pieces.
Definition: translate.cc:614
A contiguous range of bytes in some address space.
Definition: address.hh:161
AddrSpace * getStackSpace(void) const
Get the stack space for this processor.
Definition: translate.hh:470
virtual Address resolve(uintb val, int4 sz, const Address &point, uintb &fullEncoding)=0
Virtual destructor
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
void insertSpace(AddrSpace *spc)
Add a new address space to the model.
Definition: translate.cc:297
virtual const VarnodeData & getRegister(const string &nm) const =0
Get a register as VarnodeData given its name.
UnimplError(const string &s, int4 l)
Constructor.
Definition: translate.hh:41
virtual const VarnodeData & getSpacebaseFull(int4 i) const
Return original spacebase register before truncation.
Definition: translate.cc:97
void setReverseJustified(AddrSpace *spc)
Set reverse justified property on this space.
Definition: translate.cc:283
AddrSpace * getNextSpaceInOrder(AddrSpace *spc) const
Get the next contiguous address space.
Definition: translate.cc:591
AddrSpace * getSpaceByName(const string &nm) const
Get address space by name.
Definition: translate.cc:534
virtual AddrSpace * getContain(void) const
Return this space's containing space (if any)
Definition: space.hh:487
virtual void dump(const Address &addr, const string &mnem, const string &body)=0
The main disassembly emitting method.
AddrSpace * getFspecSpace(void) const
Get the internal callspec space.
Definition: translate.hh:452
void addSpacebasePointer(SpacebaseSpace *basespace, const VarnodeData &ptrdata, int4 truncSize, bool stackGrowth)
Set the base register of a spacebase space.
Definition: translate.cc:404
Data defining a specific memory location.
Definition: pcoderaw.hh:33
vector< FloatFormat > floatformats
Floating point formats utilized by the processor.
Definition: translate.hh:299
Raw descriptions of varnodes and p-code ops.
virtual ~AddrSpaceManager(void)
Destroy the manager.
Definition: translate.cc:436
A container for parsed XML documents.
Definition: xml.hh:249
void restoreXmlSpaces(const Element *el, const Translate *trans)
Restore address spaces in the model from an XML tag.
Definition: translate.cc:228
virtual const VarnodeData & getSpacebase(int4 i) const
Get a base register that creates this virtual space.
Definition: translate.cc:89
Address getEquivalentAddress(uintb offset, int4 &pos) const
Given offset in join space, get equivalent address of piece.
Definition: translate.cc:127
A manager for different address spaces.
Definition: translate.hh:218
int4 getDefaultSize(void) const
Get size of addresses for the default space.
Definition: translate.hh:434
int4 getAlignment(void) const
Get the instruction alignment for the processor.
Definition: translate.hh:582
uintm getUniqueBase(void) const
Get the base offset for new temporary registers.
Definition: translate.hh:592
void setDeadcodeDelay(AddrSpace *spc, int4 delaydelta)
Set the deadcodedelay for a specific space.
Definition: translate.cc:711
virtual bool stackGrowsNegative(void) const
Return true if a stack in this space grows negative.
Definition: translate.hh:184
bool isBigEndian(void) const
Is the processor big endian?
Definition: translate.hh:572
virtual void initialize(DocumentStorage &store)=0
Initialize the translator given XML configuration documents.
const FloatFormat * getFloatFormat(int4 size) const
Get format for a particular floating point encoding.
Definition: translate.cc:877
BadDataError(const string &s)
Constructor.
Definition: translate.hh:54