LLInst opcode is private now, added accessors and moved a few functions into LLInst
This commit is contained in:
parent
4c7df165ee
commit
32d1b71e79
@ -128,6 +128,7 @@ enum icodeType
|
|||||||
/* LOW_LEVEL icode opcodes */
|
/* LOW_LEVEL icode opcodes */
|
||||||
enum llIcode
|
enum llIcode
|
||||||
{
|
{
|
||||||
|
//iINVALID,
|
||||||
iCBW, /* 0 */
|
iCBW, /* 0 */
|
||||||
iAAA,
|
iAAA,
|
||||||
iAAD,
|
iAAD,
|
||||||
@ -301,3 +302,11 @@ enum operDu
|
|||||||
NONE /* No operation is required on this operand */
|
NONE /* No operation is required on this operand */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* LOW_LEVEL icode, DU flag bits */
|
||||||
|
enum eDuFlags
|
||||||
|
{
|
||||||
|
Cf=1,
|
||||||
|
Sf=2,
|
||||||
|
Zf=4,
|
||||||
|
Df=8
|
||||||
|
};
|
||||||
|
|||||||
@ -175,5 +175,5 @@ int power2 (int);
|
|||||||
|
|
||||||
/* Exported funcions from locident.c */
|
/* Exported funcions from locident.c */
|
||||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
||||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, iICODE);
|
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
|
||||||
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);
|
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);
|
||||||
|
|||||||
@ -11,17 +11,14 @@
|
|||||||
#include <llvm/MC/MCInst.h>
|
#include <llvm/MC/MCInst.h>
|
||||||
#include <llvm/MC/MCAsmInfo.h>
|
#include <llvm/MC/MCAsmInfo.h>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include "state.h" // State depends on INDEXBASE, but later need STATE
|
||||||
//enum condId;
|
//enum condId;
|
||||||
struct LOCAL_ID;
|
|
||||||
|
|
||||||
/* LOW_LEVEL icode, DU flag bits */
|
struct LOCAL_ID;
|
||||||
enum eDuFlags
|
struct BB;
|
||||||
{
|
struct Function;
|
||||||
Cf=1,
|
struct STKFRAME;
|
||||||
Sf=2,
|
struct CIcodeRec;
|
||||||
Zf=4,
|
|
||||||
Df=8
|
|
||||||
};
|
|
||||||
|
|
||||||
/* uint8_t and uint16_t registers */
|
/* uint8_t and uint16_t registers */
|
||||||
static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
|
static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
|
||||||
@ -30,12 +27,6 @@ static const char *const wordReg[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
|||||||
"si", "di", "es", "cs", "ss", "ds",
|
"si", "di", "es", "cs", "ss", "ds",
|
||||||
"", "", "", "", "", "", "", "", "tmp"};
|
"", "", "", "", "", "", "", "", "tmp"};
|
||||||
|
|
||||||
#include "state.h" // State depends on INDEXBASE, but later need STATE
|
|
||||||
|
|
||||||
struct BB;
|
|
||||||
struct Function;
|
|
||||||
struct STKFRAME;
|
|
||||||
|
|
||||||
/* Def/use of flags - low 4 bits represent flags */
|
/* Def/use of flags - low 4 bits represent flags */
|
||||||
struct DU
|
struct DU
|
||||||
{
|
{
|
||||||
@ -100,7 +91,7 @@ struct ExpType : public HlTypeSupport
|
|||||||
|
|
||||||
struct HLTYPE
|
struct HLTYPE
|
||||||
{
|
{
|
||||||
hlIcode opcode; /* hlIcode opcode */
|
hlIcode opcode; /* hlIcode opcode */
|
||||||
ExpType exp; /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
ExpType exp; /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
||||||
AssignType asgn;
|
AssignType asgn;
|
||||||
CallType call;
|
CallType call;
|
||||||
@ -143,6 +134,7 @@ struct HLTYPE
|
|||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
std::string write1HlIcode(Function *pProc, int *numLoc);
|
std::string write1HlIcode(Function *pProc, int *numLoc);
|
||||||
|
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
|
||||||
} ;
|
} ;
|
||||||
/* LOW_LEVEL icode operand record */
|
/* LOW_LEVEL icode operand record */
|
||||||
struct LLOperand //: public llvm::MCOperand
|
struct LLOperand //: public llvm::MCOperand
|
||||||
@ -166,9 +158,9 @@ struct LLInst : public llvm::ilist_node<LLInst>
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
uint32_t flg; /* icode flags */
|
uint32_t flg; /* icode flags */
|
||||||
|
llIcode opcode; /* llIcode instruction */
|
||||||
public:
|
public:
|
||||||
int codeIdx; /* Index into cCode.code */
|
int codeIdx; /* Index into cCode.code */
|
||||||
llIcode opcode; /* llIcode instruction */
|
|
||||||
uint8_t numBytes; /* Number of bytes this instr */
|
uint8_t numBytes; /* Number of bytes this instr */
|
||||||
uint32_t label; /* offset in image (20-bit adr) */
|
uint32_t label; /* offset in image (20-bit adr) */
|
||||||
LLOperand dst; /* destination operand */
|
LLOperand dst; /* destination operand */
|
||||||
@ -189,7 +181,7 @@ public:
|
|||||||
void clrFlags(uint32_t flag) {flg &= ~flag;}
|
void clrFlags(uint32_t flag) {flg &= ~flag;}
|
||||||
|
|
||||||
uint32_t getFlag() const {return flg;}
|
uint32_t getFlag() const {return flg;}
|
||||||
llIcode GetLlOpcode() const { return opcode; }
|
llIcode getOpcode() const { return opcode; }
|
||||||
|
|
||||||
uint32_t GetLlLabel() const { return label;}
|
uint32_t GetLlLabel() const { return label;}
|
||||||
|
|
||||||
@ -229,7 +221,18 @@ public:
|
|||||||
opcode = op;
|
opcode = op;
|
||||||
flg =flags;
|
flg =flags;
|
||||||
}
|
}
|
||||||
|
void setOpcode(llIcode op)
|
||||||
|
{
|
||||||
|
opcode = op;
|
||||||
|
}
|
||||||
void emitGotoLabel(int indLevel);
|
void emitGotoLabel(int indLevel);
|
||||||
|
void findJumpTargets(CIcodeRec &pc);
|
||||||
|
void writeIntComment(std::ostringstream &s);
|
||||||
|
void dis1Line(int loc_ip, int pass);
|
||||||
|
std::ostringstream &strSrc(std::ostringstream &os,bool skip_comma=false);
|
||||||
|
|
||||||
|
void flops(std::ostringstream &out);
|
||||||
|
bool isJmpInst();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
||||||
@ -306,16 +309,21 @@ public:
|
|||||||
const HLTYPE * hl() const { return &m_hl;}
|
const HLTYPE * hl() const { return &m_hl;}
|
||||||
int loc_ip; // used by CICodeRec to number ICODEs
|
int loc_ip; // used by CICodeRec to number ICODEs
|
||||||
|
|
||||||
void writeIntComment(std::ostringstream &s);
|
|
||||||
void setRegDU(uint8_t regi, operDu du_in);
|
void setRegDU(uint8_t regi, operDu du_in);
|
||||||
void invalidate();
|
void invalidate();
|
||||||
void newCallHl();
|
void newCallHl();
|
||||||
void writeDU(int idx);
|
void writeDU(int idx);
|
||||||
condId idType(opLoc sd);
|
condId idType(opLoc sd);
|
||||||
// HLL setting functions
|
// HLL setting functions
|
||||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs); // set this icode to be an assign
|
// set this icode to be an assign
|
||||||
|
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
||||||
|
{
|
||||||
|
type=HIGH_LEVEL;
|
||||||
|
hl()->setAsgn(lhs,rhs);
|
||||||
|
}
|
||||||
void setUnary(hlIcode op, COND_EXPR *exp);
|
void setUnary(hlIcode op, COND_EXPR *exp);
|
||||||
void setJCond(COND_EXPR *cexp);
|
void setJCond(COND_EXPR *cexp);
|
||||||
|
|
||||||
void emitGotoLabel(int indLevel);
|
void emitGotoLabel(int indLevel);
|
||||||
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
|
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
|
||||||
bool valid() {return not invalid;}
|
bool valid() {return not invalid;}
|
||||||
|
|||||||
@ -66,7 +66,7 @@ void ICODE::setRegDU (uint8_t regi, operDu du_in)
|
|||||||
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
||||||
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
||||||
{
|
{
|
||||||
// printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ll()->opcode,pIcode->ll()->opcode);
|
// printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ll()->getOpcode(),pIcode->ll()->getOpcode());
|
||||||
switch (_du)
|
switch (_du)
|
||||||
{
|
{
|
||||||
case eDEF:
|
case eDEF:
|
||||||
|
|||||||
@ -147,20 +147,20 @@ static const char *intOthers[] = {
|
|||||||
|
|
||||||
/* Writes the description of the current interrupt. Appends it to the
|
/* Writes the description of the current interrupt. Appends it to the
|
||||||
* string s. */
|
* string s. */
|
||||||
void ICODE::writeIntComment (std::ostringstream &s)
|
void LLInst::writeIntComment (std::ostringstream &s)
|
||||||
{
|
{
|
||||||
s<<"\t/* ";
|
s<<"\t/* ";
|
||||||
if (ll()->src.op() == 0x21)
|
if (src.op() == 0x21)
|
||||||
{
|
{
|
||||||
s <<int21h[ll()->dst.off];
|
s <<int21h[dst.off];
|
||||||
}
|
}
|
||||||
else if (ll()->src.op() > 0x1F && ll()->src.op() < 0x2F)
|
else if (src.op() > 0x1F && src.op() < 0x2F)
|
||||||
{
|
{
|
||||||
s <<intOthers[ll()->src.op() - 0x20];
|
s <<intOthers[src.op() - 0x20];
|
||||||
}
|
}
|
||||||
else if (ll()->src.op() == 0x2F)
|
else if (src.op() == 0x2F)
|
||||||
{
|
{
|
||||||
switch (ll()->dst.off)
|
switch (dst.off)
|
||||||
{
|
{
|
||||||
case 0x01 :
|
case 0x01 :
|
||||||
s << "Print spooler";
|
s << "Print spooler";
|
||||||
|
|||||||
@ -124,7 +124,7 @@ void Function::elimCondCodes ()
|
|||||||
|
|
||||||
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
|
for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++)
|
||||||
{
|
{
|
||||||
llIcode useAtOp = useAt->ll()->GetLlOpcode();
|
llIcode useAtOp = useAt->ll()->getOpcode();
|
||||||
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ll()->flagDU.u))
|
if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ll()->flagDU.u))
|
||||||
{
|
{
|
||||||
/* Find definition within the same basic block */
|
/* Find definition within the same basic block */
|
||||||
@ -139,7 +139,7 @@ void Function::elimCondCodes ()
|
|||||||
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
if ((useAtOp >= iJB) && (useAtOp <= iJNS))
|
||||||
{
|
{
|
||||||
iICODE befDefAt = (++riICODE(defAt)).base();
|
iICODE befDefAt = (++riICODE(defAt)).base();
|
||||||
switch (defAt->ll()->GetLlOpcode())
|
switch (defAt->ll()->getOpcode())
|
||||||
{
|
{
|
||||||
case iCMP:
|
case iCMP:
|
||||||
rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE);
|
||||||
@ -168,7 +168,7 @@ void Function::elimCondCodes ()
|
|||||||
default:
|
default:
|
||||||
notSup = TRUE;
|
notSup = TRUE;
|
||||||
std::cout << hex<<defAt->loc_ip;
|
std::cout << hex<<defAt->loc_ip;
|
||||||
reportError (JX_NOT_DEF, defAt->ll()->GetLlOpcode());
|
reportError (JX_NOT_DEF, defAt->ll()->getOpcode());
|
||||||
flg |= PROC_ASM; /* generate asm */
|
flg |= PROC_ASM; /* generate asm */
|
||||||
}
|
}
|
||||||
if (! notSup)
|
if (! notSup)
|
||||||
@ -186,11 +186,11 @@ void Function::elimCondCodes ()
|
|||||||
exp = COND_EXPR::boolOp (lhs, rhs, EQUAL);
|
exp = COND_EXPR::boolOp (lhs, rhs, EQUAL);
|
||||||
useAt->setJCond(exp);
|
useAt->setJCond(exp);
|
||||||
}
|
}
|
||||||
// else if (useAt->GetLlOpcode() == iRCL)
|
// else if (useAt->getOpcode() == iRCL)
|
||||||
// {
|
// {
|
||||||
// ICODE &a(*defAt);
|
// ICODE &a(*defAt);
|
||||||
// ICODE &b(*useAt);
|
// ICODE &b(*useAt);
|
||||||
// if(a.GetLlOpcode() == iRCL)
|
// if(a.getOpcode() == iRCL)
|
||||||
// {
|
// {
|
||||||
// if ((b.ll()->flg & NO_SRC) != NO_SRC) /* if there is src op */
|
// if ((b.ll()->flg & NO_SRC) != NO_SRC) /* if there is src op */
|
||||||
// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE);
|
// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE);
|
||||||
@ -206,7 +206,7 @@ void Function::elimCondCodes ()
|
|||||||
{
|
{
|
||||||
ICODE &a(*defAt);
|
ICODE &a(*defAt);
|
||||||
ICODE &b(*useAt);
|
ICODE &b(*useAt);
|
||||||
reportError (NOT_DEF_USE,a.ll()->GetLlOpcode(),b.ll()->GetLlOpcode());
|
reportError (NOT_DEF_USE,a.ll()->getOpcode(),b.ll()->getOpcode());
|
||||||
flg |= PROC_ASM; /* generate asm */
|
flg |= PROC_ASM; /* generate asm */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -228,7 +228,7 @@ void Function::elimCondCodes ()
|
|||||||
else if (defAt == pBB->rend2())
|
else if (defAt == pBB->rend2())
|
||||||
{
|
{
|
||||||
reportError(DEF_NOT_FOUND,useAtOp);
|
reportError(DEF_NOT_FOUND,useAtOp);
|
||||||
//fatalError (DEF_NOT_FOUND, Icode.GetLlOpcode(useAt-1));
|
//fatalError (DEF_NOT_FOUND, Icode.getOpcode(useAt-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -680,13 +680,13 @@ static void processCArg (Function * pp, Function * pProc, ICODE * picode, int nu
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
|
adjustActArgType (exp, pp->args.sym[numArgs].type, pProc);
|
||||||
res = picode->newStkArg (exp, picode->ll()->opcode, pProc);
|
res = picode->newStkArg (exp, picode->ll()->getOpcode(), pProc);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
pp->args.adjustForArgType (numArgs, expType (exp, pProc));
|
pp->args.adjustForArgType (numArgs, expType (exp, pProc));
|
||||||
res = picode->newStkArg (exp, picode->ll()->opcode, pProc);
|
res = picode->newStkArg (exp, picode->ll()->getOpcode(), pProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not update the size of k if the expression was a segment register
|
/* Do not update the size of k if the expression was a segment register
|
||||||
@ -1019,13 +1019,13 @@ void Function::findExps()
|
|||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
adjustActArgType(exp, pp->args.sym[numArgs].type, this);
|
adjustActArgType(exp, pp->args.sym[numArgs].type, this);
|
||||||
res = picode->newStkArg (exp, picode->ll()->opcode, this);
|
res = picode->newStkArg (exp, picode->ll()->getOpcode(), this);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs >0)
|
if (pp->args.numArgs >0)
|
||||||
pp->args.adjustForArgType (numArgs,expType (exp, this));
|
pp->args.adjustForArgType (numArgs,expType (exp, this));
|
||||||
res = picode->newStkArg (exp,picode->ll()->opcode, this);
|
res = picode->newStkArg (exp,picode->ll()->getOpcode(), this);
|
||||||
}
|
}
|
||||||
if (res == FALSE)
|
if (res == FALSE)
|
||||||
k += hlTypeSize (exp, this);
|
k += hlTypeSize (exp, this);
|
||||||
|
|||||||
248
src/disassem.cpp
248
src/disassem.cpp
@ -127,17 +127,14 @@ static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di"
|
|||||||
static const char *szPtr[2] = { "word ptr ", "byte ptr " };
|
static const char *szPtr[2] = { "word ptr ", "byte ptr " };
|
||||||
|
|
||||||
|
|
||||||
static void dis1Line (ICODE &icode, int pass);
|
|
||||||
void dis1LineOp(int i, boolT fWin, char attr, uint16_t *len, Function * pProc);
|
void dis1LineOp(int i, boolT fWin, char attr, uint16_t *len, Function * pProc);
|
||||||
static void formatRM(ostringstream &p, uint32_t flg, const LLOperand &pm);
|
static void formatRM(ostringstream &p, uint32_t flg, const LLOperand &pm);
|
||||||
static ostringstream &strDst(ostringstream &os, uint32_t flg, LLOperand &pm);
|
static ostringstream &strDst(ostringstream &os, uint32_t flg, LLOperand &pm);
|
||||||
static ostringstream &strSrc(ostringstream &os,const LLInst &pc,bool skip_comma=false);
|
|
||||||
|
|
||||||
static char *strHex(uint32_t d);
|
static char *strHex(uint32_t d);
|
||||||
static int checkScanned(uint32_t pcCur);
|
static int checkScanned(uint32_t pcCur);
|
||||||
static void setProc(Function * proc);
|
static void setProc(Function * proc);
|
||||||
static void dispData(uint16_t dataSeg);
|
static void dispData(uint16_t dataSeg);
|
||||||
void flops(LLInst &pIcode, std::ostringstream &out);
|
|
||||||
boolT callArg(uint16_t off, char *temp); /* Check for procedure name */
|
boolT callArg(uint16_t off, char *temp); /* Check for procedure name */
|
||||||
|
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
@ -168,6 +165,27 @@ uint8_t iPS; /* Index into the stack */
|
|||||||
#define dis_show() // Nothing to do unless using Curses
|
#define dis_show() // Nothing to do unless using Curses
|
||||||
|
|
||||||
|
|
||||||
|
void LLInst::findJumpTargets(CIcodeRec &pc)
|
||||||
|
{
|
||||||
|
if (testFlags(I) && ! testFlags(JMP_ICODE) && isJmpInst())
|
||||||
|
{
|
||||||
|
/* Replace the immediate operand with an icode index */
|
||||||
|
iICODE labTgt=pc.labelSrch(src.op());
|
||||||
|
if (labTgt!=pc.end())
|
||||||
|
{
|
||||||
|
src.SetImmediateOp(labTgt->loc_ip);
|
||||||
|
/* This icode is the target of a jump */
|
||||||
|
labTgt->ll()->setFlags(TARGET);
|
||||||
|
setFlags(JMP_ICODE); /* So its not done twice */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This jump cannot be linked to a label */
|
||||||
|
setFlags(NO_LABEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* disassem - Prints a disassembled listing of a procedure.
|
* disassem - Prints a disassembled listing of a procedure.
|
||||||
* pass == 1 generates output on file .a1
|
* pass == 1 generates output on file .a1
|
||||||
@ -214,23 +232,7 @@ void disassem(int pass, Function * ppProc)
|
|||||||
for( ICODE &icode : pc)
|
for( ICODE &icode : pc)
|
||||||
{
|
{
|
||||||
LLInst *ll=icode.ll();
|
LLInst *ll=icode.ll();
|
||||||
if (ll->testFlags(I) && ! ll->testFlags(JMP_ICODE) && JmpInst(ll->opcode))
|
ll->findJumpTargets(pc);
|
||||||
{
|
|
||||||
/* Replace the immediate operand with an icode index */
|
|
||||||
iICODE labTgt=pc.labelSrch(ll->src.op());
|
|
||||||
if (labTgt!=pc.end())
|
|
||||||
{
|
|
||||||
ll->src.SetImmediateOp(labTgt->loc_ip);
|
|
||||||
/* This icode is the target of a jump */
|
|
||||||
labTgt->ll()->setFlags(TARGET);
|
|
||||||
ll->setFlags(JMP_ICODE); /* So its not done twice */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* This jump cannot be linked to a label */
|
|
||||||
ll->setFlags(NO_LABEL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +245,10 @@ void disassem(int pass, Function * ppProc)
|
|||||||
|
|
||||||
/* Loop over array printing each record */
|
/* Loop over array printing each record */
|
||||||
nextInst = 0;
|
nextInst = 0;
|
||||||
std::for_each(pc.begin(),
|
for( ICODE &icode : pc)
|
||||||
pc.end(),
|
{
|
||||||
[pass](ICODE &iter)->void {dis1Line(iter, pass);});
|
icode.ll()->dis1Line(icode.loc_ip,pass);
|
||||||
|
}
|
||||||
|
|
||||||
/* Write procedure epilogue */
|
/* Write procedure epilogue */
|
||||||
if (pass != 3)
|
if (pass != 3)
|
||||||
@ -263,7 +266,7 @@ void disassem(int pass, Function * ppProc)
|
|||||||
* i is index into Icode for this proc *
|
* i is index into Icode for this proc *
|
||||||
* It is assumed that icode i is already scanned *
|
* It is assumed that icode i is already scanned *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void dis1Line(ICODE &icode_iter, int pass)
|
void LLInst::dis1Line(int loc_ip, int pass)
|
||||||
{
|
{
|
||||||
ostringstream oper_stream;
|
ostringstream oper_stream;
|
||||||
ostringstream hex_bytes;
|
ostringstream hex_bytes;
|
||||||
@ -271,21 +274,20 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
|
|
||||||
oper_stream << uppercase;
|
oper_stream << uppercase;
|
||||||
hex_bytes << uppercase;
|
hex_bytes << uppercase;
|
||||||
LLInst &_IcLL(*icode_iter.ll());
|
|
||||||
/* Disassembly stage 1 --
|
/* Disassembly stage 1 --
|
||||||
* Do not try to display NO_CODE entries or synthetic instructions,
|
* Do not try to display NO_CODE entries or synthetic instructions,
|
||||||
* other than JMPs, that have been introduced for def/use analysis. */
|
* other than JMPs, that have been introduced for def/use analysis. */
|
||||||
if ((option.asm1) &&
|
if ((option.asm1) &&
|
||||||
( _IcLL.testFlags(NO_CODE) ||
|
( testFlags(NO_CODE) ||
|
||||||
(_IcLL.testFlags(SYNTHETIC) && (_IcLL.opcode != iJMP))))
|
(testFlags(SYNTHETIC) && (opcode != iJMP))))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (_IcLL.testFlags(NO_CODE))
|
else if (testFlags(NO_CODE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_IcLL.testFlags(TARGET | CASE))
|
if (testFlags(TARGET | CASE))
|
||||||
{
|
{
|
||||||
if (pass == 3)
|
if (pass == 3)
|
||||||
cCode.appendCode("\n"); /* Print to c code buffer */
|
cCode.appendCode("\n"); /* Print to c code buffer */
|
||||||
@ -294,19 +296,19 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find next instruction label and print hex bytes */
|
/* Find next instruction label and print hex bytes */
|
||||||
if (_IcLL.testFlags(SYNTHETIC))
|
if (testFlags(SYNTHETIC))
|
||||||
nextInst = _IcLL.label;
|
nextInst = label;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cb = (uint32_t) _IcLL.numBytes;
|
cb = (uint32_t) numBytes;
|
||||||
nextInst = _IcLL.label + cb;
|
nextInst = label + cb;
|
||||||
|
|
||||||
/* Output hexa code in program image */
|
/* Output hexa code in program image */
|
||||||
if (pass != 3)
|
if (pass != 3)
|
||||||
{
|
{
|
||||||
for (j = 0; j < cb; j++)
|
for (j = 0; j < cb; j++)
|
||||||
{
|
{
|
||||||
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[_IcLL.label + j]);
|
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[label + j]);
|
||||||
}
|
}
|
||||||
hex_bytes << ' ';
|
hex_bytes << ' ';
|
||||||
}
|
}
|
||||||
@ -317,78 +319,78 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
oper_stream << setw(5)<<left; // align for the labels
|
oper_stream << setw(5)<<left; // align for the labels
|
||||||
{
|
{
|
||||||
ostringstream lab_contents;
|
ostringstream lab_contents;
|
||||||
if (readVal(lab_contents, _IcLL.label, 0))
|
if (readVal(lab_contents, label, 0))
|
||||||
{
|
{
|
||||||
lab_contents << ':'; /* Also removes the null */
|
lab_contents << ':'; /* Also removes the null */
|
||||||
}
|
}
|
||||||
else if (_IcLL.testFlags(TARGET)) /* Symbols override Lnn labels */
|
else if (testFlags(TARGET)) /* Symbols override Lnn labels */
|
||||||
{
|
{
|
||||||
/* Print label */
|
/* Print label */
|
||||||
if (pl.count(icode_iter.loc_ip)==0)
|
if (pl.count(loc_ip)==0)
|
||||||
{
|
{
|
||||||
pl[icode_iter.loc_ip] = ++lab;
|
pl[loc_ip] = ++lab;
|
||||||
}
|
}
|
||||||
lab_contents<< "L"<<pl[icode_iter.loc_ip]<<':';
|
lab_contents<< "L"<<pl[loc_ip]<<':';
|
||||||
}
|
}
|
||||||
oper_stream<< lab_contents.str();
|
oper_stream<< lab_contents.str();
|
||||||
}
|
}
|
||||||
if (_IcLL.opcode == iSIGNEX && _IcLL.testFlags(B))
|
if (opcode == iSIGNEX && testFlags(B))
|
||||||
{
|
{
|
||||||
_IcLL.opcode = iCBW;
|
opcode = iCBW;
|
||||||
}
|
}
|
||||||
oper_stream << setw(15) << left <<szOps[_IcLL.opcode];
|
oper_stream << setw(15) << left <<szOps[opcode];
|
||||||
|
|
||||||
switch (_IcLL.opcode)
|
switch (opcode)
|
||||||
{
|
{
|
||||||
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
||||||
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
||||||
strDst(oper_stream,_IcLL.getFlag(), _IcLL.dst);
|
strDst(oper_stream,getFlag(), dst);
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iESC:
|
case iESC:
|
||||||
flops(_IcLL,oper_stream);
|
flops(oper_stream);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iSAR: case iSHL: case iSHR: case iRCL: case iRCR: case iROL:
|
case iSAR: case iSHL: case iSHR: case iRCL: case iRCR: case iROL:
|
||||||
case iROR:
|
case iROR:
|
||||||
strDst(oper_stream,_IcLL.getFlag() | I, _IcLL.dst);
|
strDst(oper_stream,getFlag() | I, dst);
|
||||||
if(_IcLL.testFlags(I))
|
if(testFlags(I))
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream);
|
||||||
else
|
else
|
||||||
oper_stream<<", cl";
|
oper_stream<<", cl";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iINC: case iDEC: case iNEG: case iNOT: case iPOP:
|
case iINC: case iDEC: case iNEG: case iNOT: case iPOP:
|
||||||
strDst(oper_stream,_IcLL.getFlag() | I, _IcLL.dst);
|
strDst(oper_stream,getFlag() | I, dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iPUSH:
|
case iPUSH:
|
||||||
if (_IcLL.testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(src.op());
|
||||||
// strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
// strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strDst(oper_stream,_IcLL.getFlag() | I, _IcLL.dst);
|
strDst(oper_stream,getFlag() | I, dst);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iDIV: case iIDIV: case iMUL: case iIMUL: case iMOD:
|
case iDIV: case iIDIV: case iMUL: case iIMUL: case iMOD:
|
||||||
if (_IcLL.testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
strDst(oper_stream,_IcLL.getFlag(), _IcLL.dst) <<", ";
|
strDst(oper_stream,getFlag(), dst) <<", ";
|
||||||
formatRM(oper_stream, _IcLL.getFlag(), _IcLL.src);
|
formatRM(oper_stream, getFlag(), src);
|
||||||
strSrc(oper_stream,_IcLL);
|
strSrc(oper_stream);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strDst(oper_stream,_IcLL.getFlag() | I, _IcLL.src);
|
strDst(oper_stream,getFlag() | I, src);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iLDS: case iLES: case iBOUND:
|
case iLDS: case iLES: case iBOUND:
|
||||||
strDst(oper_stream,_IcLL.getFlag(), _IcLL.dst)<<", dword ptr";
|
strDst(oper_stream,getFlag(), dst)<<", dword ptr";
|
||||||
strSrc(oper_stream,_IcLL,true);
|
strSrc(oper_stream,true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
@ -400,71 +402,71 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
|
|
||||||
/* Check if there is a symbol here */
|
/* Check if there is a symbol here */
|
||||||
{
|
{
|
||||||
ICODE *lab=pc.GetIcode(_IcLL.src.op());
|
ICODE *lab=pc.GetIcode(src.op());
|
||||||
selectTable(Label);
|
selectTable(Label);
|
||||||
if ((_IcLL.src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
if ((src.op() < (uint32_t)numIcode) && /* Ensure in range */
|
||||||
readVal(oper_stream, lab->ll()->label, 0))
|
readVal(oper_stream, lab->ll()->label, 0))
|
||||||
{
|
{
|
||||||
break; /* Symbolic label. Done */
|
break; /* Symbolic label. Done */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_IcLL.testFlags(NO_LABEL))
|
if (testFlags(NO_LABEL))
|
||||||
{
|
{
|
||||||
//strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
//strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(src.op());
|
||||||
}
|
}
|
||||||
else if (_IcLL.testFlags(I) )
|
else if (testFlags(I) )
|
||||||
{
|
{
|
||||||
j = _IcLL.src.op();
|
j = src.op();
|
||||||
if (pl.count(j)==0) /* Forward jump */
|
if (pl.count(j)==0) /* Forward jump */
|
||||||
{
|
{
|
||||||
pl[j] = ++lab;
|
pl[j] = ++lab;
|
||||||
}
|
}
|
||||||
if (_IcLL.opcode == iJMPF)
|
if (opcode == iJMPF)
|
||||||
{
|
{
|
||||||
oper_stream<<" far ptr ";
|
oper_stream<<" far ptr ";
|
||||||
}
|
}
|
||||||
oper_stream<<"L"<<pl[j];
|
oper_stream<<"L"<<pl[j];
|
||||||
}
|
}
|
||||||
else if (_IcLL.opcode == iJMPF)
|
else if (opcode == iJMPF)
|
||||||
{
|
{
|
||||||
oper_stream<<"dword ptr";
|
oper_stream<<"dword ptr";
|
||||||
strSrc(oper_stream,_IcLL,true);
|
strSrc(oper_stream,true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strDst(oper_stream,I, _IcLL.src);
|
strDst(oper_stream,I, src);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iCALL: case iCALLF:
|
case iCALL: case iCALLF:
|
||||||
if (_IcLL.testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
if((_IcLL.opcode == iCALL))
|
if((opcode == iCALL))
|
||||||
oper_stream<< "near";
|
oper_stream<< "near";
|
||||||
else
|
else
|
||||||
oper_stream<< " far";
|
oper_stream<< " far";
|
||||||
oper_stream<<" ptr "<<(_IcLL.src.proc.proc)->name;
|
oper_stream<<" ptr "<<(src.proc.proc)->name;
|
||||||
}
|
}
|
||||||
else if (_IcLL.opcode == iCALLF)
|
else if (opcode == iCALLF)
|
||||||
{
|
{
|
||||||
oper_stream<<"dword ptr ";
|
oper_stream<<"dword ptr ";
|
||||||
strSrc(oper_stream,_IcLL,true);
|
strSrc(oper_stream,true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strDst(oper_stream,I, _IcLL.src);
|
strDst(oper_stream,I, src);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iENTER:
|
case iENTER:
|
||||||
oper_stream<<strHex(_IcLL.dst.off)<<", ";
|
oper_stream<<strHex(dst.off)<<", ";
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(src.op());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iRET: case iRETF: case iINT:
|
case iRET: case iRETF: case iINT:
|
||||||
if (_IcLL.testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
oper_stream<<strHex(_IcLL.src.op());
|
oper_stream<<strHex(src.op());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -475,46 +477,46 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
case iMOVS: case iREP_MOVS:
|
case iMOVS: case iREP_MOVS:
|
||||||
case iINS: case iREP_INS:
|
case iINS: case iREP_INS:
|
||||||
case iOUTS: case iREP_OUTS:
|
case iOUTS: case iREP_OUTS:
|
||||||
if (_IcLL.src.segOver)
|
if (src.segOver)
|
||||||
{
|
{
|
||||||
bool is_dx_src=(_IcLL.opcode == iOUTS || _IcLL.opcode == iREP_OUTS);
|
bool is_dx_src=(opcode == iOUTS || opcode == iREP_OUTS);
|
||||||
if(is_dx_src)
|
if(is_dx_src)
|
||||||
oper_stream<<"dx, "<<szPtr[_IcLL.getFlag() & B];
|
oper_stream<<"dx, "<<szPtr[getFlag() & B];
|
||||||
else
|
else
|
||||||
oper_stream<<szPtr[_IcLL.getFlag() & B];
|
oper_stream<<szPtr[getFlag() & B];
|
||||||
if (_IcLL.opcode == iLODS ||
|
if (opcode == iLODS ||
|
||||||
_IcLL.opcode == iREP_LODS ||
|
opcode == iREP_LODS ||
|
||||||
_IcLL.opcode == iOUTS ||
|
opcode == iOUTS ||
|
||||||
_IcLL.opcode == iREP_OUTS)
|
opcode == iREP_OUTS)
|
||||||
{
|
{
|
||||||
oper_stream<<szWreg[_IcLL.src.segOver-rAX];
|
oper_stream<<szWreg[src.segOver-rAX];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
oper_stream<<"es:[di], "<<szWreg[_IcLL.src.segOver - rAX];
|
oper_stream<<"es:[di], "<<szWreg[src.segOver - rAX];
|
||||||
}
|
}
|
||||||
oper_stream<<":[si]";
|
oper_stream<<":[si]";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
oper_stream<<(_IcLL.getFlag() & B)? "B": "W";
|
oper_stream<<(getFlag() & B)? "B": "W";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iXLAT:
|
case iXLAT:
|
||||||
if (_IcLL.src.segOver)
|
if (src.segOver)
|
||||||
{
|
{
|
||||||
oper_stream<<" "<<szPtr[1];
|
oper_stream<<" "<<szPtr[1];
|
||||||
oper_stream<<szWreg[_IcLL.src.segOver-rAX]<<":[bx]";
|
oper_stream<<szWreg[src.segOver-rAX]<<":[bx]";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iIN:
|
case iIN:
|
||||||
oper_stream<<(_IcLL.getFlag() & B)?"al, ": "ax, ";
|
oper_stream<<(getFlag() & B)?"al, ": "ax, ";
|
||||||
oper_stream<<(_IcLL.testFlags(I))? strHex(_IcLL.src.op()): "dx";
|
oper_stream<<(testFlags(I))? strHex(src.op()): "dx";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case iOUT:
|
case iOUT:
|
||||||
oper_stream<<(_IcLL.testFlags(I))? strHex(_IcLL.src.op()): "dx";
|
oper_stream<<(testFlags(I))? strHex(src.op()): "dx";
|
||||||
oper_stream<<(_IcLL.getFlag() & B)?", al": ", ax";
|
oper_stream<<(getFlag() & B)?", al": ", ax";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -522,13 +524,13 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
if (_IcLL.testFlags(SYNTHETIC))
|
if (testFlags(SYNTHETIC))
|
||||||
{
|
{
|
||||||
fImpure = FALSE;
|
fImpure = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (j = _IcLL.label, fImpure = 0; j > 0 && j < (int)nextInst; j++)
|
for (j = label, fImpure = 0; j > 0 && j < (int)nextInst; j++)
|
||||||
{
|
{
|
||||||
fImpure |= BITMAP(j, BM_DATA);
|
fImpure |= BITMAP(j, BM_DATA);
|
||||||
}
|
}
|
||||||
@ -538,17 +540,17 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
/* Check for user supplied comment */
|
/* Check for user supplied comment */
|
||||||
selectTable(Comment);
|
selectTable(Comment);
|
||||||
ostringstream cbuf;
|
ostringstream cbuf;
|
||||||
if (readVal(cbuf, _IcLL.label, 0))
|
if (readVal(cbuf, label, 0))
|
||||||
{
|
{
|
||||||
result_stream <<"; "<<cbuf.str();
|
result_stream <<"; "<<cbuf.str();
|
||||||
}
|
}
|
||||||
else if (fImpure || (_IcLL.testFlags(SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES)))
|
else if (fImpure || (testFlags(SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES)))
|
||||||
{
|
{
|
||||||
if (_IcLL.testFlags(CASE))
|
if (testFlags(CASE))
|
||||||
{
|
{
|
||||||
result_stream << ";Case l"<< _IcLL.caseTbl.numEntries;
|
result_stream << ";Case l"<< caseTbl.numEntries;
|
||||||
}
|
}
|
||||||
if (_IcLL.testFlags(SWITCH))
|
if (testFlags(SWITCH))
|
||||||
{
|
{
|
||||||
result_stream << ";Switch ";
|
result_stream << ";Switch ";
|
||||||
}
|
}
|
||||||
@ -556,29 +558,29 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
{
|
{
|
||||||
result_stream << ";Accessed as data ";
|
result_stream << ";Accessed as data ";
|
||||||
}
|
}
|
||||||
if (_IcLL.testFlags(IMPURE))
|
if (testFlags(IMPURE))
|
||||||
{
|
{
|
||||||
result_stream << ";Impure operand ";
|
result_stream << ";Impure operand ";
|
||||||
}
|
}
|
||||||
if (_IcLL.testFlags(SEG_IMMED))
|
if (testFlags(SEG_IMMED))
|
||||||
{
|
{
|
||||||
result_stream << ";Segment constant";
|
result_stream << ";Segment constant";
|
||||||
}
|
}
|
||||||
if (_IcLL.testFlags(TERMINATES))
|
if (testFlags(TERMINATES))
|
||||||
{
|
{
|
||||||
result_stream << ";Exit to DOS";
|
result_stream << ";Exit to DOS";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Comment on iINT icodes */
|
/* Comment on iINT icodes */
|
||||||
if (_IcLL.opcode == iINT)
|
if (opcode == iINT)
|
||||||
icode_iter.writeIntComment(result_stream);
|
writeIntComment(result_stream);
|
||||||
|
|
||||||
/* Display output line */
|
/* Display output line */
|
||||||
if(pass==3)
|
if(pass==3)
|
||||||
{
|
{
|
||||||
/* output to .b code buffer */
|
/* output to .b code buffer */
|
||||||
if (_IcLL.testFlags(SYNTHETIC))
|
if (testFlags(SYNTHETIC))
|
||||||
result_stream<<";Synthetic inst";
|
result_stream<<";Synthetic inst";
|
||||||
if (pass == 3) /* output to .b code buffer */
|
if (pass == 3) /* output to .b code buffer */
|
||||||
cCode.appendCode("%s\n", result_stream.str().c_str());
|
cCode.appendCode("%s\n", result_stream.str().c_str());
|
||||||
@ -586,15 +588,15 @@ static void dis1Line(ICODE &icode_iter, int pass)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (not _IcLL.testFlags(SYNTHETIC) )
|
if (not testFlags(SYNTHETIC) )
|
||||||
{
|
{
|
||||||
/* output to .a1 or .a2 file */
|
/* output to .a1 or .a2 file */
|
||||||
fprintf (fp, "%03ld %06lX %s\n", icode_iter.loc_ip, _IcLL.label, result_stream.str().c_str());
|
fprintf (fp, "%03ld %06lX %s\n", loc_ip, label, result_stream.str().c_str());
|
||||||
}
|
}
|
||||||
else /* SYNTHETIC instruction */
|
else /* SYNTHETIC instruction */
|
||||||
{
|
{
|
||||||
result_stream<<";Synthetic inst";
|
result_stream<<";Synthetic inst";
|
||||||
fprintf (fp, "%03ld %s\n", icode_iter.loc_ip, result_stream.str().c_str());
|
fprintf (fp, "%03ld %s\n", loc_ip, result_stream.str().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,17 +667,17 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* strSrc *
|
* strSrc *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static ostringstream &strSrc(ostringstream &os,const LLInst &l_ins,bool skip_comma)
|
ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma)
|
||||||
{
|
{
|
||||||
static char buf[30] = {", "};
|
static char buf[30] = {", "};
|
||||||
if(false==skip_comma)
|
if(false==skip_comma)
|
||||||
os<<", ";
|
os<<", ";
|
||||||
if (l_ins.testFlags(I))
|
if (testFlags(I))
|
||||||
os<<strHex(l_ins.src.op());
|
os<<strHex(src.op());
|
||||||
else if (l_ins.testFlags(IM_SRC)) /* level 2 */
|
else if (testFlags(IM_SRC)) /* level 2 */
|
||||||
os<<"dx:ax";
|
os<<"dx:ax";
|
||||||
else
|
else
|
||||||
formatRM(os, l_ins.getFlag(), l_ins.src);
|
formatRM(os, getFlag(), src);
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -704,15 +706,15 @@ void interactDis(Function * initProc, int initIC)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handle the floating point opcodes (icode iESC) */
|
/* Handle the floating point opcodes (icode iESC) */
|
||||||
void flops(LLInst &pIcode,std::ostringstream &out)
|
void LLInst::flops(std::ostringstream &out)
|
||||||
{
|
{
|
||||||
char bf[30];
|
char bf[30];
|
||||||
uint8_t op = (uint8_t)pIcode.src.op();
|
uint8_t op = (uint8_t)src.op();
|
||||||
|
|
||||||
/* Note that op is set to the escape number, e.g.
|
/* Note that op is set to the escape number, e.g.
|
||||||
esc 0x38 is FILD */
|
esc 0x38 is FILD */
|
||||||
|
|
||||||
if ((pIcode.dst.regi == 0) || (pIcode.dst.regi >= INDEXBASE))
|
if ((dst.regi == 0) || (dst.regi >= INDEXBASE))
|
||||||
{
|
{
|
||||||
/* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
|
/* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
|
||||||
out<<szFlops1[op]<<' ';
|
out<<szFlops1[op]<<' ';
|
||||||
@ -748,7 +750,7 @@ void flops(LLInst &pIcode,std::ostringstream &out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
formatRM(out, pIcode.getFlag(), pIcode.dst);
|
formatRM(out, getFlag(), dst);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -757,7 +759,7 @@ void flops(LLInst &pIcode,std::ostringstream &out)
|
|||||||
normal opcodes. Because the opcodes are slightly different for
|
normal opcodes. Because the opcodes are slightly different for
|
||||||
this case (e.g. op=04 means FSUB if reg != 3, but FSUBR for
|
this case (e.g. op=04 means FSUB if reg != 3, but FSUBR for
|
||||||
reg == 3), a separate table is used (szFlops2). */
|
reg == 3), a separate table is used (szFlops2). */
|
||||||
int destRegIdx=pIcode.dst.regi - rAX;
|
int destRegIdx=dst.regi - rAX;
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case 0x0C:
|
case 0x0C:
|
||||||
|
|||||||
@ -44,10 +44,10 @@ void Function::createCFG()
|
|||||||
LLInst *ll = pIcode->ll();
|
LLInst *ll = pIcode->ll();
|
||||||
/* Stick a NOWHERE_NODE on the end if we terminate
|
/* Stick a NOWHERE_NODE on the end if we terminate
|
||||||
* with anything other than a ret, jump or terminate */
|
* with anything other than a ret, jump or terminate */
|
||||||
if (ip + 1 == Icode.size() &&
|
if (ip + 1 == Icode.size() and
|
||||||
(not ll->testFlags(TERMINATES)) &&
|
(not ll->testFlags(TERMINATES)) and
|
||||||
ll->opcode != iJMP && ll->opcode != iJMPF &&
|
(not ll->match(iJMP)) and (not ll->match(iJMPF)) and
|
||||||
ll->opcode != iRET && ll->opcode != iRETF)
|
(not ll->match(iRET)) and (not ll->match(iRETF)))
|
||||||
{
|
{
|
||||||
pBB=BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
pBB=BB::Create(start, ip, NOWHERE_NODE, 0, this);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ void Function::createCFG()
|
|||||||
/* Only process icodes that have valid instructions */
|
/* Only process icodes that have valid instructions */
|
||||||
else if (not ll->testFlags(NO_CODE) )
|
else if (not ll->testFlags(NO_CODE) )
|
||||||
{
|
{
|
||||||
switch (ll->opcode) {
|
switch (ll->getOpcode()) {
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
case iJL: case iJLE: case iJGE: case iJG:
|
case iJL: case iJLE: case iJGE: case iJG:
|
||||||
case iJE: case iJNE: case iJS: case iJNS:
|
case iJE: case iJNE: case iJS: case iJNS:
|
||||||
|
|||||||
@ -28,10 +28,9 @@ static char buf[lineSize]; /* Line buffer for hl icode output */
|
|||||||
|
|
||||||
|
|
||||||
/* Places the new HLI_ASSIGN high-level operand in the high-level icode array */
|
/* Places the new HLI_ASSIGN high-level operand in the high-level icode array */
|
||||||
void ICODE::setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
void HLTYPE::setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
||||||
{
|
{
|
||||||
type = HIGH_LEVEL;
|
set(lhs,rhs);
|
||||||
hl()->set(lhs,rhs);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void ICODE::checkHlCall()
|
void ICODE::checkHlCall()
|
||||||
@ -155,7 +154,7 @@ void Function::highLevelGen()
|
|||||||
lhs = COND_EXPR::id (*pIcode, DST, this, i, *pIcode, NONE);
|
lhs = COND_EXPR::id (*pIcode, DST, this, i, *pIcode, NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ll->opcode)
|
switch (ll->getOpcode())
|
||||||
{
|
{
|
||||||
case iADD:
|
case iADD:
|
||||||
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
rhs = COND_EXPR::boolOp (lhs, rhs, ADD);
|
||||||
@ -452,38 +451,34 @@ int power2 (int i)
|
|||||||
* instruction. */
|
* instruction. */
|
||||||
void ICODE::writeDU(int idx)
|
void ICODE::writeDU(int idx)
|
||||||
{
|
{
|
||||||
static char buf[100];
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
memset (buf, ' ', sizeof(buf));
|
|
||||||
buf[0] = '\0';
|
|
||||||
for (i = 0; i < (INDEXBASE-1); i++)
|
|
||||||
{
|
{
|
||||||
if (du.def[i])
|
ostringstream ostr;
|
||||||
{
|
for (int i = 0; i < (INDEXBASE-1); i++)
|
||||||
strcat (buf, allRegs[i]);
|
if (du.def[i])
|
||||||
strcat (buf, " ");
|
ostr << allRegs[i] << " ";
|
||||||
}
|
if (!ostr.str().empty())
|
||||||
|
printf ("Def (reg) = %s\n", ostr.str().c_str());
|
||||||
}
|
}
|
||||||
if (buf[0] != '\0')
|
|
||||||
printf ("Def (reg) = %s\n", buf);
|
|
||||||
|
|
||||||
memset (buf, ' ', sizeof(buf));
|
|
||||||
buf[0] = '\0';
|
|
||||||
for (i = 0; i < INDEXBASE; i++)
|
|
||||||
{
|
{
|
||||||
if (du.use[i])
|
ostringstream ostr;
|
||||||
|
for (int i = 0; i < (INDEXBASE-1); i++)
|
||||||
|
if (du.def[i])
|
||||||
|
ostr << allRegs[i] << " ";
|
||||||
|
if (!ostr.str().empty())
|
||||||
|
printf ("Def (reg) = %s\n", ostr.str().c_str());
|
||||||
|
for (int i = 0; i < INDEXBASE; i++)
|
||||||
{
|
{
|
||||||
strcat (buf, allRegs[i]);
|
if (du.use[i])
|
||||||
strcat (buf, " ");
|
ostr << allRegs[i] << " ";
|
||||||
}
|
}
|
||||||
|
if (!ostr.str().empty())
|
||||||
|
printf ("Use (reg) = %s\n", ostr.str().c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
if (buf[0] != '\0')
|
|
||||||
printf ("Use (reg) = %s\n", buf);
|
|
||||||
|
|
||||||
/* Print du1 chain */
|
/* Print du1 chain */
|
||||||
printf ("# regs defined = %d\n", du1.numRegsDef);
|
printf ("# regs defined = %d\n", du1.numRegsDef);
|
||||||
for (i = 0; i < MAX_REGS_DEF; i++)
|
for (int i = 0; i < MAX_REGS_DEF; i++)
|
||||||
{
|
{
|
||||||
if (du1.used(i))
|
if (du1.used(i))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,9 +19,10 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* JmpInst - Returns TRUE if opcode is a conditional or unconditional jump
|
* JmpInst - Returns TRUE if opcode is a conditional or unconditional jump
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
bool JmpInst(llIcode opcode)
|
bool LLInst::isJmpInst()
|
||||||
{
|
{
|
||||||
switch (opcode) {
|
switch (opcode)
|
||||||
|
{
|
||||||
case iJMP: case iJMPF: case iJCXZ:
|
case iJMP: case iJMPF: case iJCXZ:
|
||||||
case iLOOP: case iLOOPE:case iLOOPNE:
|
case iLOOP: case iLOOPE:case iLOOPNE:
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
@ -77,7 +78,7 @@ void Function::findIdioms()
|
|||||||
typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
||||||
while (pIcode != pEnd)
|
while (pIcode != pEnd)
|
||||||
{
|
{
|
||||||
switch (pIcode->ll()->opcode)
|
switch (pIcode->ll()->getOpcode())
|
||||||
{
|
{
|
||||||
case iDEC: case iINC:
|
case iDEC: case iINC:
|
||||||
if (i18.match(pIcode))
|
if (i18.match(pIcode))
|
||||||
@ -231,7 +232,7 @@ void Function::bindIcodeOff()
|
|||||||
for(ICODE &c : Icode)
|
for(ICODE &c : Icode)
|
||||||
{
|
{
|
||||||
LLInst *ll=c.ll();
|
LLInst *ll=c.ll();
|
||||||
if (ll->testFlags(I) && JmpInst(ll->opcode))
|
if (ll->testFlags(I) && ll->isJmpInst())
|
||||||
{
|
{
|
||||||
iICODE loc=Icode.labelSrch(ll->src.op());
|
iICODE loc=Icode.labelSrch(ll->src.op());
|
||||||
if (loc!=Icode.end())
|
if (loc!=Icode.end())
|
||||||
@ -246,7 +247,7 @@ void Function::bindIcodeOff()
|
|||||||
for(ICODE &icode : Icode)
|
for(ICODE &icode : Icode)
|
||||||
{
|
{
|
||||||
LLInst *ll=icode.ll();
|
LLInst *ll=icode.ll();
|
||||||
if (not JmpInst(ll->opcode))
|
if (not ll->isJmpInst())
|
||||||
continue;
|
continue;
|
||||||
if (ll->testFlags(I) )
|
if (ll->testFlags(I) )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -163,7 +163,7 @@ int Idiom18::action() // action length
|
|||||||
lhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[1], *m_icodes[1], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[1], *m_icodes[1], eUSE);
|
||||||
lhs = COND_EXPR::unary ( m_is_dec ? POST_DEC : POST_INC, lhs);
|
lhs = COND_EXPR::unary ( m_is_dec ? POST_DEC : POST_INC, lhs);
|
||||||
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[1], *m_icodes[3], eUSE);
|
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[1], *m_icodes[3], eUSE);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->getOpcode() - iJB]);
|
||||||
m_icodes[3]->setJCond(expr);
|
m_icodes[3]->setJCond(expr);
|
||||||
|
|
||||||
m_icodes[0]->invalidate();
|
m_icodes[0]->invalidate();
|
||||||
@ -214,7 +214,7 @@ int Idiom19::action()
|
|||||||
lhs = COND_EXPR::id (*m_icodes[1], DST, m_func, m_icodes[0], *m_icodes[1], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[1], DST, m_func, m_icodes[0], *m_icodes[1], eUSE);
|
||||||
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
||||||
rhs = COND_EXPR::idKte (0, 2);
|
rhs = COND_EXPR::idKte (0, 2);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[1]->ll()->opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[1]->ll()->getOpcode() - iJB]);
|
||||||
m_icodes[1]->setJCond(expr);
|
m_icodes[1]->setJCond(expr);
|
||||||
m_icodes[0]->invalidate();
|
m_icodes[0]->invalidate();
|
||||||
return 2;
|
return 2;
|
||||||
@ -303,7 +303,7 @@ int Idiom20::action()
|
|||||||
lhs = COND_EXPR::id (*m_icodes[1], SRC, m_func, m_icodes[0], *m_icodes[0], eUSE);
|
lhs = COND_EXPR::id (*m_icodes[1], SRC, m_func, m_icodes[0], *m_icodes[0], eUSE);
|
||||||
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
lhs = COND_EXPR::unary (m_is_dec ? PRE_DEC : PRE_INC, lhs);
|
||||||
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[0], *m_icodes[3], eUSE);
|
rhs = COND_EXPR::id (*m_icodes[2], SRC, m_func, m_icodes[0], *m_icodes[3], eUSE);
|
||||||
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->opcode - iJB]);
|
expr = COND_EXPR::boolOp (lhs, rhs, condOpJCond[m_icodes[3]->ll()->getOpcode() - iJB]);
|
||||||
m_icodes[3]->setJCond(expr);
|
m_icodes[3]->setJCond(expr);
|
||||||
for(int i=0; i<3; ++i)
|
for(int i=0; i<3; ++i)
|
||||||
m_icodes[i]->invalidate();
|
m_icodes[i]->invalidate();
|
||||||
|
|||||||
@ -126,9 +126,8 @@ bool Idiom10::match(iICODE pIcode)
|
|||||||
|
|
||||||
int Idiom10::action()
|
int Idiom10::action()
|
||||||
{
|
{
|
||||||
m_icodes[0]->ll()->opcode = iCMP;
|
m_icodes[0]->ll()->set(iCMP,I);
|
||||||
m_icodes[0]->ll()->setFlags(I);
|
m_icodes[0]->ll()->src.SetImmediateOp(0); // todo check if proc should be zeroed too
|
||||||
m_icodes[0]->ll()->src.SetImmediateOp(0); // todo check if proc should be zeroed too
|
|
||||||
m_icodes[0]->du.def = 0;
|
m_icodes[0]->du.def = 0;
|
||||||
m_icodes[0]->du1.numRegsDef = 0;
|
m_icodes[0]->du1.numRegsDef = 0;
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
@ -362,7 +362,7 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pPro
|
|||||||
* pProc : ptr to current procedure record
|
* pProc : ptr to current procedure record
|
||||||
* rhs, lhs : return expressions if successful. */
|
* rhs, lhs : return expressions if successful. */
|
||||||
boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
||||||
Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, iICODE atOffset)
|
Function * pProc, Assignment &asgn, iICODE atOffset)
|
||||||
{
|
{
|
||||||
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
|
LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */
|
||||||
// iICODE atOffset(pIcode);
|
// iICODE atOffset(pIcode);
|
||||||
@ -375,17 +375,17 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
|
|||||||
|
|
||||||
if ((longId.h == pmHdst->regi) && (longId.l == pmLdst->regi))
|
if ((longId.h == pmHdst->regi) && (longId.l == pmLdst->regi))
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idLongIdx (i);
|
asgn.lhs = COND_EXPR::idLongIdx (i);
|
||||||
if ( not pIcode->ll()->testFlags(NO_SRC) )
|
if ( not pIcode->ll()->testFlags(NO_SRC) )
|
||||||
{
|
{
|
||||||
rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
asgn.rhs = COND_EXPR::idLong (&pProc->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, atOffset);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((longId.h == pmHsrc->regi) && (longId.l == pmLsrc->regi))
|
else if ((longId.h == pmHsrc->regi) && (longId.l == pmLsrc->regi))
|
||||||
{
|
{
|
||||||
lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
|
asgn.lhs = COND_EXPR::idLong (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
|
||||||
rhs = COND_EXPR::idLongIdx (i);
|
asgn.rhs = COND_EXPR::idLongIdx (i);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -153,12 +153,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy Icode to Proc */
|
/* Copy Icode to Proc */
|
||||||
if ((_Icode.ll()->opcode == iDIV) || (_Icode.ll()->opcode == iIDIV))
|
if ((_Icode.ll()->getOpcode() == iDIV) || (_Icode.ll()->getOpcode() == iIDIV))
|
||||||
{
|
{
|
||||||
/* MOV rTMP, reg */
|
/* MOV rTMP, reg */
|
||||||
eIcode = ICODE();
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ll()->opcode = iMOV;
|
eIcode.ll()->set(iMOV,0);
|
||||||
eIcode.ll()->dst.regi = rTMP;
|
eIcode.ll()->dst.regi = rTMP;
|
||||||
if (ll->testFlags(B) )
|
if (ll->testFlags(B) )
|
||||||
{
|
{
|
||||||
@ -184,19 +184,19 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
/* iMOD */
|
/* iMOD */
|
||||||
eIcode = ICODE();
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ll()->opcode = iMOD;
|
eIcode.ll()->set(iMOD,0);
|
||||||
eIcode.ll()->src = _Icode.ll()->src;
|
eIcode.ll()->src = _Icode.ll()->src;
|
||||||
eIcode.du = _Icode.du;
|
eIcode.du = _Icode.du;
|
||||||
eIcode.ll()->setFlags( ( ll->getFlag() | SYNTHETIC) );
|
eIcode.ll()->setFlags( ( ll->getFlag() | SYNTHETIC) );
|
||||||
eIcode.ll()->label = SynthLab++;
|
eIcode.ll()->label = SynthLab++;
|
||||||
pIcode = Icode.addIcode(&eIcode);
|
pIcode = Icode.addIcode(&eIcode);
|
||||||
}
|
}
|
||||||
else if (_Icode.ll()->opcode == iXCHG)
|
else if (_Icode.ll()->getOpcode() == iXCHG)
|
||||||
{
|
{
|
||||||
/* MOV rTMP, regDst */
|
/* MOV rTMP, regDst */
|
||||||
eIcode = ICODE();
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ll()->opcode = iMOV;
|
eIcode.ll()->set(iMOV,0);
|
||||||
eIcode.ll()->dst.regi = rTMP;
|
eIcode.ll()->dst.regi = rTMP;
|
||||||
eIcode.ll()->src.regi = _Icode.ll()->dst.regi;
|
eIcode.ll()->src.regi = _Icode.ll()->dst.regi;
|
||||||
eIcode.setRegDU( rTMP, eDEF);
|
eIcode.setRegDU( rTMP, eDEF);
|
||||||
@ -207,28 +207,26 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
Icode.addIcode(&eIcode);
|
Icode.addIcode(&eIcode);
|
||||||
|
|
||||||
/* MOV regDst, regSrc */
|
/* MOV regDst, regSrc */
|
||||||
_Icode.ll()->opcode = iMOV;
|
_Icode.ll()->set(iMOV,SYNTHETIC);
|
||||||
ll->setFlags( SYNTHETIC );
|
|
||||||
/* Icode.ll()->label = SynthLab++; */
|
/* Icode.ll()->label = SynthLab++; */
|
||||||
Icode.addIcode(&_Icode);
|
Icode.addIcode(&_Icode);
|
||||||
ll->opcode = iXCHG; /* for next case */
|
ll->setOpcode(iXCHG); /* for next case */
|
||||||
|
|
||||||
/* MOV regSrc, rTMP */
|
/* MOV regSrc, rTMP */
|
||||||
eIcode = ICODE();
|
eIcode = ICODE();
|
||||||
eIcode.type = LOW_LEVEL;
|
eIcode.type = LOW_LEVEL;
|
||||||
eIcode.ll()->opcode = iMOV;
|
eIcode.ll()->set(iMOV,SYNTHETIC);
|
||||||
eIcode.ll()->dst.regi = ll->src.regi;
|
eIcode.ll()->dst.regi = ll->src.regi;
|
||||||
eIcode.ll()->src.regi = rTMP;
|
eIcode.ll()->src.regi = rTMP;
|
||||||
eIcode.setRegDU( eIcode.ll()->dst.regi, eDEF);
|
eIcode.setRegDU( eIcode.ll()->dst.regi, eDEF);
|
||||||
eIcode.setRegDU( rTMP, eUSE);
|
eIcode.setRegDU( rTMP, eUSE);
|
||||||
eIcode.ll()->setFlags(SYNTHETIC);
|
|
||||||
eIcode.ll()->label = SynthLab++;
|
eIcode.ll()->label = SynthLab++;
|
||||||
pIcode = Icode.addIcode(&eIcode);
|
pIcode = Icode.addIcode(&eIcode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pIcode = Icode.addIcode(&_Icode);
|
pIcode = Icode.addIcode(&_Icode);
|
||||||
|
|
||||||
switch (ll->opcode) {
|
switch (ll->getOpcode()) {
|
||||||
/*** Conditional jumps ***/
|
/*** Conditional jumps ***/
|
||||||
case iLOOP: case iLOOPE: case iLOOPNE:
|
case iLOOP: case iLOOPE: case iLOOPNE:
|
||||||
case iJB: case iJBE: case iJAE: case iJA:
|
case iJB: case iJBE: case iJAE: case iJA:
|
||||||
@ -246,15 +244,15 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
/* This sets up range check for indexed JMPs hopefully
|
/* This sets up range check for indexed JMPs hopefully
|
||||||
* Handles JA/JAE for fall through and JB/JBE on branch
|
* Handles JA/JAE for fall through and JB/JBE on branch
|
||||||
*/
|
*/
|
||||||
if (ip > 0 && prev.ll()->opcode == iCMP && (prev.ll()->testFlags(I)))
|
if (ip > 0 && prev.ll()->getOpcode() == iCMP && (prev.ll()->testFlags(I)))
|
||||||
{
|
{
|
||||||
pstate->JCond.immed = (int16_t)prev.ll()->src.op();
|
pstate->JCond.immed = (int16_t)prev.ll()->src.op();
|
||||||
if (ll->opcode == iJA || ll->opcode == iJBE)
|
if (ll->match(iJA) || ll->match(iJBE) )
|
||||||
pstate->JCond.immed++;
|
pstate->JCond.immed++;
|
||||||
if (ll->opcode == iJAE || ll->opcode == iJA)
|
if (ll->getOpcode() == iJAE || ll->getOpcode() == iJA)
|
||||||
pstate->JCond.regi = prev.ll()->dst.regi;
|
pstate->JCond.regi = prev.ll()->dst.regi;
|
||||||
fBranch = (boolT)
|
fBranch = (boolT)
|
||||||
(ll->opcode == iJB || ll->opcode == iJBE);
|
(ll->getOpcode() == iJB || ll->getOpcode() == iJBE);
|
||||||
}
|
}
|
||||||
StCopy = *pstate;
|
StCopy = *pstate;
|
||||||
//memcpy(&StCopy, pstate, sizeof(STATE));
|
//memcpy(&StCopy, pstate, sizeof(STATE));
|
||||||
@ -286,7 +284,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
/*** Returns ***/
|
/*** Returns ***/
|
||||||
case iRET:
|
case iRET:
|
||||||
case iRETF:
|
case iRETF:
|
||||||
this->flg |= (ll->opcode == iRET)? PROC_NEAR:PROC_FAR;
|
this->flg |= (ll->getOpcode() == iRET)? PROC_NEAR:PROC_FAR;
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
case iIRET:
|
case iIRET:
|
||||||
this->flg &= ~TERMINATES;
|
this->flg &= ~TERMINATES;
|
||||||
@ -357,7 +355,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
|
|||||||
if ((psym = lookupAddr(&ll->src, pstate, 4, eDuVal::USE))
|
if ((psym = lookupAddr(&ll->src, pstate, 4, eDuVal::USE))
|
||||||
/* && (Icode.ll()->flg & SEG_IMMED) */ ) {
|
/* && (Icode.ll()->flg & SEG_IMMED) */ ) {
|
||||||
offset = LH(&prog.Image[psym->label]);
|
offset = LH(&prog.Image[psym->label]);
|
||||||
pstate->setState( (ll->opcode == iLDS)? rDS: rES,
|
pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES,
|
||||||
LH(&prog.Image[psym->label + 2]));
|
LH(&prog.Image[psym->label + 2]));
|
||||||
pstate->setState( ll->dst.regi, (int16_t)offset);
|
pstate->setState( ll->dst.regi, (int16_t)offset);
|
||||||
psym->type = TYPE_PTR;
|
psym->type = TYPE_PTR;
|
||||||
@ -393,7 +391,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
|
|||||||
|
|
||||||
if (pIcode.ll()->testFlags(I))
|
if (pIcode.ll()->testFlags(I))
|
||||||
{
|
{
|
||||||
if (pIcode.ll()->opcode == iJMPF)
|
if (pIcode.ll()->getOpcode() == iJMPF)
|
||||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||||
i = pstate->IP = pIcode.ll()->src.op();
|
i = pstate->IP = pIcode.ll()->src.op();
|
||||||
if ((long)i < 0)
|
if ((long)i < 0)
|
||||||
@ -545,7 +543,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
|
/* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
|
||||||
* previous offset into the program image */
|
* previous offset into the program image */
|
||||||
uint32_t tgtAddr=0;
|
uint32_t tgtAddr=0;
|
||||||
if (pIcode.ll()->opcode == iCALLF)
|
if (pIcode.ll()->getOpcode() == iCALLF)
|
||||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
|
||||||
else
|
else
|
||||||
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
|
||||||
@ -595,7 +593,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
|
|||||||
/* Save machine state in localState, load up IP and CS.*/
|
/* Save machine state in localState, load up IP and CS.*/
|
||||||
localState = *pstate;
|
localState = *pstate;
|
||||||
pstate->IP = pIcode.ll()->src.op();
|
pstate->IP = pIcode.ll()->src.op();
|
||||||
if (pIcode.ll()->opcode == iCALLF)
|
if (pIcode.ll()->getOpcode() == iCALLF)
|
||||||
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
|
||||||
x.state = *pstate;
|
x.state = *pstate;
|
||||||
|
|
||||||
@ -1022,7 +1020,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
int cb = pIcode.ll()->testFlags(B) ? 1: 2;
|
int cb = pIcode.ll()->testFlags(B) ? 1: 2;
|
||||||
uint32_t Imm = (pIcode.ll()->testFlags(I));
|
uint32_t Imm = (pIcode.ll()->testFlags(I));
|
||||||
|
|
||||||
switch (pIcode.ll()->opcode) {
|
switch (pIcode.ll()->getOpcode()) {
|
||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
case iSAR: case iSHL: case iSHR:
|
case iSAR: case iSHL: case iSHR:
|
||||||
case iRCL: case iRCR: case iROL: case iROR:
|
case iRCL: case iRCR: case iROL: case iROR:
|
||||||
@ -1096,7 +1094,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
cb = 4;
|
cb = 4;
|
||||||
case iCALL: case iPUSH: case iPOP:
|
case iCALL: case iPUSH: case iPOP:
|
||||||
if (! Imm) {
|
if (! Imm) {
|
||||||
if (pIcode.ll()->opcode == iPOP)
|
if (pIcode.ll()->getOpcode() == iPOP)
|
||||||
def(DST, pIcode, this, pstate, cb, ix);
|
def(DST, pIcode, this, pstate, cb, ix);
|
||||||
else
|
else
|
||||||
use(DST, pIcode, this, pstate, cb, ix);
|
use(DST, pIcode, this, pstate, cb, ix);
|
||||||
@ -1108,7 +1106,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case iLDS: case iLES:
|
case iLDS: case iLES:
|
||||||
pIcode.du.def |= duReg[(pIcode.ll()->opcode == iLDS) ? rDS : rES];
|
pIcode.du.def |= duReg[(pIcode.ll()->getOpcode() == iLDS) ? rDS : rES];
|
||||||
pIcode.du1.numRegsDef++;
|
pIcode.du1.numRegsDef++;
|
||||||
cb = 4;
|
cb = 4;
|
||||||
case iMOV:
|
case iMOV:
|
||||||
@ -1157,7 +1155,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
case iSCAS: case iSTOS: case iINS:
|
case iSCAS: case iSTOS: case iINS:
|
||||||
pIcode.du.def |= duReg[rDI];
|
pIcode.du.def |= duReg[rDI];
|
||||||
pIcode.du1.numRegsDef++;
|
pIcode.du1.numRegsDef++;
|
||||||
if (pIcode.ll()->opcode == iREP_INS || pIcode.ll()->opcode== iINS)
|
if (pIcode.ll()->getOpcode() == iREP_INS || pIcode.ll()->getOpcode()== iINS)
|
||||||
{
|
{
|
||||||
pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[rDX];
|
pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[rDX];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc)
|
|||||||
if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1))
|
if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1))
|
||||||
{
|
{
|
||||||
obb2 = t->edges[THEN].BBptr;
|
obb2 = t->edges[THEN].BBptr;
|
||||||
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
|
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
|
||||||
{
|
{
|
||||||
off = obb2->begin2();//std::distance(iter,obb2->begin2());
|
off = obb2->begin2();//std::distance(iter,obb2->begin2());
|
||||||
*arc = THEN;
|
*arc = THEN;
|
||||||
@ -47,7 +47,7 @@ static bool isLong23 (iICODE iter, BB * pbb, iICODE &off, int *arc)
|
|||||||
else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1))
|
else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1))
|
||||||
{
|
{
|
||||||
obb2 = e->edges[THEN].BBptr;
|
obb2 = e->edges[THEN].BBptr;
|
||||||
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->opcode == iCMP))
|
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
|
||||||
{
|
{
|
||||||
off = obb2->begin2();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
|
off = obb2->begin2();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
|
||||||
*arc = ELSE;
|
*arc = ELSE;
|
||||||
@ -67,8 +67,8 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
|
|||||||
// preincrement because pIcode is not checked here
|
// preincrement because pIcode is not checked here
|
||||||
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
||||||
if ( icodes[1]->ll()->match(iCMP) &&
|
if ( icodes[1]->ll()->match(iCMP) &&
|
||||||
(isJCond (icodes[0]->ll()->opcode)) &&
|
(isJCond (icodes[0]->ll()->getOpcode())) &&
|
||||||
(isJCond (icodes[2]->ll()->opcode)))
|
(isJCond (icodes[2]->ll()->getOpcode())))
|
||||||
{
|
{
|
||||||
off = initial_icode;
|
off = initial_icode;
|
||||||
advance(off,2);
|
advance(off,2);
|
||||||
@ -142,7 +142,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc,
|
|||||||
iICODE atOffset1(atOffset),next1(++iICODE(pIcode));
|
iICODE atOffset1(atOffset),next1(++iICODE(pIcode));
|
||||||
advance(atOffset1,1);
|
advance(atOffset1,1);
|
||||||
/* Create new HLI_JCOND and condition */
|
/* Create new HLI_JCOND and condition */
|
||||||
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ll()->opcode-iJB]);
|
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[atOffset1->ll()->getOpcode()-iJB]);
|
||||||
next1->setJCond(lhs);
|
next1->setJCond(lhs);
|
||||||
next1->copyDU(*pIcode, eUSE, eUSE);
|
next1->copyDU(*pIcode, eUSE, eUSE);
|
||||||
next1->du.use |= atOffset->du.use;
|
next1->du.use |= atOffset->du.use;
|
||||||
@ -177,7 +177,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
|
iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
|
||||||
|
|
||||||
/* Form conditional expression */
|
/* Form conditional expression */
|
||||||
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[icodes[3]->ll()->opcode - iJB]);
|
lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[icodes[3]->ll()->getOpcode() - iJB]);
|
||||||
icodes[1]->setJCond(lhs);
|
icodes[1]->setJCond(lhs);
|
||||||
icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
|
icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
|
||||||
icodes[1]->du.use |= icodes[2]->du.use;
|
icodes[1]->du.use |= icodes[2]->du.use;
|
||||||
@ -198,7 +198,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
assert(iter!=tbb->inEdges.end());
|
assert(iter!=tbb->inEdges.end());
|
||||||
tbb->inEdges.erase(iter);
|
tbb->inEdges.erase(iter);
|
||||||
|
|
||||||
if (icodes[3]->ll()->opcode != iJE)
|
if (icodes[3]->ll()->getOpcode() != iJE)
|
||||||
tbb->inEdges.push_back(pbb); /* iJNE => replace arc */
|
tbb->inEdges.push_back(pbb); /* iJNE => replace arc */
|
||||||
|
|
||||||
/* Modify ELSE out edge of header basic block */
|
/* Modify ELSE out edge of header basic block */
|
||||||
@ -208,7 +208,7 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn
|
|||||||
iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
|
iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
|
||||||
assert(iter!=tbb->inEdges.end());
|
assert(iter!=tbb->inEdges.end());
|
||||||
tbb->inEdges.erase(iter);
|
tbb->inEdges.erase(iter);
|
||||||
if (icodes[3]->ll()->opcode == iJE) /* replace */
|
if (icodes[3]->ll()->getOpcode() == iJE) /* replace */
|
||||||
tbb->inEdges.push_back(pbb);
|
tbb->inEdges.push_back(pbb);
|
||||||
|
|
||||||
/* Update statistics */
|
/* Update statistics */
|
||||||
@ -246,22 +246,19 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
break;
|
break;
|
||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
if (pIcode->ll()->opcode == next1->ll()->opcode)
|
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
||||||
{
|
{
|
||||||
switch (pIcode->ll()->opcode)
|
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
|
||||||
{
|
{
|
||||||
case iMOV:
|
switch (pIcode->ll()->getOpcode())
|
||||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
|
|
||||||
{
|
{
|
||||||
|
case iMOV:
|
||||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||||
next1->invalidate();
|
next1->invalidate();
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case iAND: case iOR: case iXOR:
|
case iAND: case iOR: case iXOR:
|
||||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
|
switch (pIcode->ll()->getOpcode())
|
||||||
{
|
|
||||||
switch (pIcode->ll()->opcode)
|
|
||||||
{
|
{
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND); break;
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND); break;
|
||||||
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR); break;
|
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR); break;
|
||||||
@ -269,27 +266,20 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
}
|
}
|
||||||
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
pIcode->setAsgn(asgn.lhs, asgn.rhs);
|
||||||
next1->invalidate();
|
next1->invalidate();
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case iPUSH:
|
case iPUSH:
|
||||||
if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
|
|
||||||
{
|
|
||||||
pIcode->setUnary( HLI_PUSH, asgn.lhs);
|
pIcode->setUnary( HLI_PUSH, asgn.lhs);
|
||||||
next1->invalidate();
|
next1->invalidate();
|
||||||
}
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
printf("Wild ass checkLongEq success on opcode %d\n",pIcode->ll()->getOpcode());
|
||||||
printf("Wild ass checkLongEq");
|
} /*eos*/
|
||||||
// if (checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, next1) == TRUE)
|
}
|
||||||
// {
|
|
||||||
// printf("Wild ass checkLongEq success on opcode %d\n",pIcode->ll()->opcode);
|
|
||||||
// }
|
|
||||||
} /*eos*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||||
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, l23, &arc)))
|
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode, pIcode->inBB, l23, &arc)))
|
||||||
{
|
{
|
||||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, l23) )
|
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this, asgn, l23) )
|
||||||
{
|
{
|
||||||
@ -299,7 +289,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
|
|
||||||
/* Check for long conditional equality or inequality. This requires
|
/* Check for long conditional equality or inequality. This requires
|
||||||
* 2 CMPs and 2 branches */
|
* 2 CMPs and 2 branches */
|
||||||
else if ((pIcode->ll()->opcode == iCMP) && isLong22 (pIcode, pEnd, l23))
|
else if ((pIcode->ll()->getOpcode() == iCMP) && isLong22 (pIcode, pEnd, l23))
|
||||||
{
|
{
|
||||||
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, l23) )
|
if ( checkLongEq (pLocId.id.longStkId, pIcode, i, this,asgn, l23) )
|
||||||
{
|
{
|
||||||
@ -324,10 +314,10 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
|
|
||||||
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
if (icode.ll()->opcode != next1->ll()->opcode)
|
if (icode.ll()->getOpcode() != next1->ll()->getOpcode())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (icode.ll()->opcode)
|
switch (icode.ll()->getOpcode())
|
||||||
{
|
{
|
||||||
case iMOV:
|
case iMOV:
|
||||||
pmH = &icode.ll()->dst;
|
pmH = &icode.ll()->dst;
|
||||||
@ -368,7 +358,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, next1);
|
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, pIcode/*idx*/, eUSE, next1);
|
||||||
icode.setRegDU( pmH->regi, USE_DEF);
|
icode.setRegDU( pmH->regi, USE_DEF);
|
||||||
switch (icode.ll()->opcode)
|
switch (icode.ll()->getOpcode())
|
||||||
{
|
{
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
||||||
break;
|
break;
|
||||||
@ -404,8 +394,8 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pIcode->ll()->opcode == next1->ll()->opcode)
|
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
||||||
switch (pIcode->ll()->opcode)
|
switch (pIcode->ll()->getOpcode())
|
||||||
{
|
{
|
||||||
case iMOV:
|
case iMOV:
|
||||||
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
if ((pLocId.id.longId.h == pIcode->ll()->src.regi) &&
|
||||||
@ -446,7 +436,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
pIcode->setRegDU( pmH->regi, USE_DEF);
|
pIcode->setRegDU( pmH->regi, USE_DEF);
|
||||||
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
|
asgn.rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode,
|
||||||
LOW_FIRST, pIcode, eUSE, next1);
|
LOW_FIRST, pIcode, eUSE, next1);
|
||||||
switch (pIcode->ll()->opcode) {
|
switch (pIcode->ll()->getOpcode()) {
|
||||||
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
case iAND: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, AND);
|
||||||
break;
|
break;
|
||||||
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
|
case iOR: asgn.rhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, OR);
|
||||||
@ -465,9 +455,9 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
} /* eos */
|
} /* eos */
|
||||||
|
|
||||||
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
/* Check long conditional (i.e. 2 CMPs and 3 branches */
|
||||||
else if ((pIcode->ll()->opcode == iCMP) && (isLong23 (pIcode, pIcode->inBB, long_loc, &arc)))
|
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode, pIcode->inBB, long_loc, &arc)))
|
||||||
{
|
{
|
||||||
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, long_loc))
|
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, long_loc))
|
||||||
{
|
{
|
||||||
// reduce the advance by 1 here (loop increases) ?
|
// reduce the advance by 1 here (loop increases) ?
|
||||||
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, long_loc));
|
advance(pIcode,longJCond23 (asgn.rhs, asgn.lhs, pIcode, arc, long_loc));
|
||||||
@ -478,7 +468,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
* 2 CMPs and 2 branches */
|
* 2 CMPs and 2 branches */
|
||||||
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, long_loc)))
|
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, long_loc)))
|
||||||
{
|
{
|
||||||
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn.rhs, asgn.lhs, long_loc) )
|
if (checkLongRegEq (pLocId.id.longId, pIcode, loc_ident_idx, this, asgn, long_loc) )
|
||||||
{
|
{
|
||||||
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd) - 1);
|
advance(pIcode,longJCond22 (asgn.rhs, asgn.lhs, pIcode,pEnd) - 1);
|
||||||
}
|
}
|
||||||
@ -488,13 +478,13 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
* JX lab
|
* JX lab
|
||||||
* => HLI_JCOND (regH:regL X 0) lab
|
* => HLI_JCOND (regH:regL X 0) lab
|
||||||
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
||||||
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond (next1->ll()->opcode)))
|
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond (next1->ll()->getOpcode())))
|
||||||
{
|
{
|
||||||
if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
|
if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
|
||||||
{
|
{
|
||||||
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
|
||||||
asgn.rhs = COND_EXPR::idKte (0, 4); /* long 0 */
|
asgn.rhs = COND_EXPR::idKte (0, 4); /* long 0 */
|
||||||
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[next1->ll()->opcode - iJB]);
|
asgn.lhs = COND_EXPR::boolOp (asgn.lhs, asgn.rhs, condOpJCond[next1->ll()->getOpcode() - iJB]);
|
||||||
next1->setJCond(asgn.lhs);
|
next1->setJCond(asgn.lhs);
|
||||||
next1->copyDU(*pIcode, eUSE, eUSE);
|
next1->copyDU(*pIcode, eUSE, eUSE);
|
||||||
pIcode->invalidate();
|
pIcode->invalidate();
|
||||||
|
|||||||
@ -352,7 +352,7 @@ eErrorId scan(uint32_t ip, ICODE &p)
|
|||||||
|
|
||||||
} while (stateTable[op].state1 == prefix); /* Loop if prefix */
|
} while (stateTable[op].state1 == prefix); /* Loop if prefix */
|
||||||
|
|
||||||
if (p.ll()->opcode)
|
if (p.ll()->getOpcode())
|
||||||
{
|
{
|
||||||
/* Save bytes of image used */
|
/* Save bytes of image used */
|
||||||
p.ll()->numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
p.ll()->numBytes = (uint8_t)((pInst - prog.Image) - ip);
|
||||||
@ -503,7 +503,7 @@ static void segrm(int i)
|
|||||||
int reg = REG(*pInst) + rES;
|
int reg = REG(*pInst) + rES;
|
||||||
|
|
||||||
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG)))
|
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG)))
|
||||||
pIcode->ll()->opcode = (llIcode)0;
|
pIcode->ll()->setOpcode((llIcode)0); // setCBW because it has that index
|
||||||
else {
|
else {
|
||||||
setAddress(i, FALSE, 0, (int16_t)reg, 0);
|
setAddress(i, FALSE, 0, (int16_t)reg, 0);
|
||||||
rm(i);
|
rm(i);
|
||||||
@ -566,7 +566,7 @@ static void memImp(int i)
|
|||||||
static void memOnly(int )
|
static void memOnly(int )
|
||||||
{
|
{
|
||||||
if ((*pInst & 0xC0) == 0xC0)
|
if ((*pInst & 0xC0) == 0xC0)
|
||||||
pIcode->ll()->opcode = (llIcode)0;
|
pIcode->ll()->setOpcode((llIcode)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -576,7 +576,7 @@ static void memOnly(int )
|
|||||||
static void memReg0(int i)
|
static void memReg0(int i)
|
||||||
{
|
{
|
||||||
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0)
|
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0)
|
||||||
pIcode->ll()->opcode = (llIcode)0;
|
pIcode->ll()->setOpcode((llIcode)0);
|
||||||
else
|
else
|
||||||
rm(i);
|
rm(i);
|
||||||
}
|
}
|
||||||
@ -590,12 +590,12 @@ static void immed(int i)
|
|||||||
static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP};
|
static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP};
|
||||||
static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 };
|
||||||
|
|
||||||
pIcode->ll()->opcode = immedTable[REG(*pInst)];
|
pIcode->ll()->setOpcode(immedTable[REG(*pInst)]) ;
|
||||||
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
||||||
pIcode->ll()->flagDU.d = (Sf | Zf | Cf);
|
pIcode->ll()->flagDU.d = (Sf | Zf | Cf);
|
||||||
rm(i);
|
rm(i);
|
||||||
|
|
||||||
if (pIcode->ll()->opcode == iADD || pIcode->ll()->opcode == iSUB)
|
if (pIcode->ll()->getOpcode() == iADD || pIcode->ll()->getOpcode() == iSUB)
|
||||||
pIcode->ll()->clrFlags(NOT_HLL); /* Allow ADD/SUB SP, immed */
|
pIcode->ll()->clrFlags(NOT_HLL); /* Allow ADD/SUB SP, immed */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ static void shift(int i)
|
|||||||
static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf,
|
||||||
Sf | Zf | Cf, 0, Sf | Zf | Cf};
|
Sf | Zf | Cf, 0, Sf | Zf | Cf};
|
||||||
|
|
||||||
pIcode->ll()->opcode = shiftTable[REG(*pInst)];
|
pIcode->ll()->setOpcode(shiftTable[REG(*pInst)]);
|
||||||
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
pIcode->ll()->flagDU.u = uf[REG(*pInst)];
|
||||||
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
@ -634,13 +634,13 @@ static void trans(int i)
|
|||||||
static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0};
|
||||||
LLInst *ll = pIcode->ll();
|
LLInst *ll = pIcode->ll();
|
||||||
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */
|
||||||
ll->opcode = transTable[REG(*pInst)]; /* valid on bytes */
|
ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */
|
||||||
ll->flagDU.d = df[REG(*pInst)];
|
ll->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
ll->src = pIcode->ll()->dst;
|
ll->src = pIcode->ll()->dst;
|
||||||
if (ll->opcode == iJMP || ll->opcode == iCALL || ll->opcode == iCALLF)
|
if (ll->match(iJMP) || ll->match(iCALL) || ll->match(iCALLF))
|
||||||
ll->setFlags(NO_OPS);
|
ll->setFlags(NO_OPS);
|
||||||
else if (ll->opcode == iINC || ll->opcode == iPUSH || ll->opcode == iDEC)
|
else if (ll->match(iINC) || ll->match(iPUSH) || ll->match(iDEC))
|
||||||
ll->setFlags(NO_SRC);
|
ll->setFlags(NO_SRC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -650,17 +650,18 @@ static void trans(int i)
|
|||||||
arith - Sets up dst and opcode from modrm uint8_t
|
arith - Sets up dst and opcode from modrm uint8_t
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void arith(int i)
|
static void arith(int i)
|
||||||
{ uint8_t opcode;
|
{
|
||||||
|
uint8_t opcode;
|
||||||
static llIcode arithTable[8] =
|
static llIcode arithTable[8] =
|
||||||
{
|
{
|
||||||
(llIcode)iTEST, (llIcode)0, (llIcode)iNOT, (llIcode)iNEG,
|
iTEST , (llIcode)0, iNOT, iNEG,
|
||||||
(llIcode)iMUL, (llIcode)iIMUL, (llIcode)iDIV, (llIcode)iIDIV
|
iMUL , iIMUL, iDIV, iIDIV
|
||||||
};
|
};
|
||||||
static uint8_t df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf,
|
static uint8_t df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf,
|
||||||
Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf,
|
Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf,
|
||||||
Sf | Zf | Cf};
|
Sf | Zf | Cf};
|
||||||
|
opcode = arithTable[REG(*pInst)];
|
||||||
opcode = pIcode->ll()->opcode = arithTable[REG(*pInst)];
|
pIcode->ll()->setOpcode((llIcode)opcode);
|
||||||
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
pIcode->ll()->flagDU.d = df[REG(*pInst)];
|
||||||
rm(i);
|
rm(i);
|
||||||
if (opcode == iTEST)
|
if (opcode == iTEST)
|
||||||
@ -709,7 +710,7 @@ static void data2(int )
|
|||||||
* on the stack. The procedure level is stored in the immediate
|
* on the stack. The procedure level is stored in the immediate
|
||||||
* field. There is no source operand; therefore, the flag flg is
|
* field. There is no source operand; therefore, the flag flg is
|
||||||
* set to NO_OPS. */
|
* set to NO_OPS. */
|
||||||
if (pIcode->ll()->opcode == iENTER)
|
if (pIcode->ll()->getOpcode() == iENTER)
|
||||||
{
|
{
|
||||||
pIcode->ll()->dst.off = getWord();
|
pIcode->ll()->dst.off = getWord();
|
||||||
pIcode->ll()->setFlags(NO_OPS);
|
pIcode->ll()->setFlags(NO_OPS);
|
||||||
@ -776,15 +777,17 @@ static void dispF(int )
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void prefix(int )
|
static void prefix(int )
|
||||||
{
|
{
|
||||||
if (pIcode->ll()->opcode == iREPE || pIcode->ll()->opcode == iREPNE)
|
if (pIcode->ll()->getOpcode() == iREPE || pIcode->ll()->getOpcode() == iREPNE)
|
||||||
RepPrefix = pIcode->ll()->opcode;
|
RepPrefix = pIcode->ll()->getOpcode();
|
||||||
else
|
else
|
||||||
SegPrefix = pIcode->ll()->opcode;
|
SegPrefix = pIcode->ll()->getOpcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void BumpOpcode(llIcode& ic)
|
inline void BumpOpcode(LLInst &ll)
|
||||||
{
|
{
|
||||||
|
llIcode ic = ll.getOpcode();
|
||||||
ic = (llIcode)(((int)ic)+1); // Bump this icode via the int type
|
ic = (llIcode)(((int)ic)+1); // Bump this icode via the int type
|
||||||
|
ll.setOpcode(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -794,14 +797,13 @@ static void strop(int )
|
|||||||
{
|
{
|
||||||
if (RepPrefix)
|
if (RepPrefix)
|
||||||
{
|
{
|
||||||
// pIcode->ll()->opcode += ((pIcode->ll()->opcode == iCMPS ||
|
// pIcode->ll()->getOpcode() += ((pIcode->ll()->getOpcode() == iCMPS ||
|
||||||
// pIcode->ll()->opcode == iSCAS)
|
// pIcode->ll()->getOpcode() == iSCAS)
|
||||||
// && RepPrefix == iREPE)? 2: 1;
|
// && RepPrefix == iREPE)? 2: 1;
|
||||||
if ((pIcode->ll()->opcode == iCMPS || pIcode->ll()->opcode == iSCAS)
|
if ((pIcode->ll()->match(iCMPS) || pIcode->ll()->match(iSCAS) ) && RepPrefix == iREPE)
|
||||||
&& RepPrefix == iREPE)
|
BumpOpcode(*pIcode->ll()); // += 2
|
||||||
BumpOpcode(pIcode->ll()->opcode); // += 2
|
BumpOpcode(*pIcode->ll()); // else += 1
|
||||||
BumpOpcode(pIcode->ll()->opcode); // else += 1
|
if (pIcode->ll()->match(iREP_LODS) )
|
||||||
if (pIcode->ll()->opcode == iREP_LODS)
|
|
||||||
pIcode->ll()->setFlags(NOT_HLL);
|
pIcode->ll()->setFlags(NOT_HLL);
|
||||||
RepPrefix = 0;
|
RepPrefix = 0;
|
||||||
}
|
}
|
||||||
@ -867,8 +869,7 @@ static void checkInt(int )
|
|||||||
/* This is a Borland/Microsoft floating point emulation instruction.
|
/* This is a Borland/Microsoft floating point emulation instruction.
|
||||||
Treat as if it is an ESC opcode */
|
Treat as if it is an ESC opcode */
|
||||||
pIcode->ll()->src.SetImmediateOp(wOp - 0x34);
|
pIcode->ll()->src.SetImmediateOp(wOp - 0x34);
|
||||||
pIcode->ll()->opcode = iESC;
|
pIcode->ll()->set(iESC,FLOAT_OP);
|
||||||
pIcode->ll()->setFlags(FLOAT_OP);
|
|
||||||
|
|
||||||
escop(wOp - 0x34 + 0xD8);
|
escop(wOp - 0x34 + 0xD8);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user