Add iInvalid enum value for invalid instructions

Various cleanups.
This commit is contained in:
nemerle 2017-02-13 13:24:54 +01:00
parent d7acc8cd4d
commit d6af9c1555
11 changed files with 584 additions and 594 deletions

View File

@ -99,7 +99,7 @@ enum icodeType
/* LOW_LEVEL icode opcodes */ /* LOW_LEVEL icode opcodes */
enum llIcode enum llIcode
{ {
//iINVALID, iINVALID=-1,
iCBW, /* 0 */ iCBW, /* 0 */
iAAA, iAAA,
iAAD, iAAD,

View File

@ -313,7 +313,7 @@ struct LLOperand
struct LLInst struct LLInst
{ {
protected: protected:
uint32_t m_opcode; // Low level opcode identifier llIcode m_opcode; // Low level opcode identifier
uint32_t flg; /* icode flags */ uint32_t flg; /* icode flags */
LLOperand m_src; /* source operand */ LLOperand m_src; /* source operand */
public: public:
@ -326,8 +326,8 @@ public:
std::vector<uint32_t> caseTbl2; std::vector<uint32_t> caseTbl2;
int hllLabNum; /* label # for hll codegen */ int hllLabNum; /* label # for hll codegen */
uint32_t getOpcode() const { return m_opcode;} llIcode getOpcode() const { return m_opcode;}
void setOpcode(uint32_t op) { m_opcode=op; } void setOpcode(uint32_t op) { m_opcode=(llIcode)op; }
bool conditionalJump() bool conditionalJump()
{ {
return (getOpcode() >= iJB) and (getOpcode() < iJCXZ); return (getOpcode() >= iJB) and (getOpcode() < iJCXZ);

View File

@ -28,7 +28,7 @@ struct LLInst;
typedef std::list<ICODE>::iterator iICODE; typedef std::list<ICODE>::iterator iICODE;
struct IDX_ARRAY : public std::vector<iICODE> struct IDX_ARRAY : public std::vector<iICODE>
{ {
bool inList(iICODE idx) bool inList(iICODE idx) const
{ {
return std::find(begin(),end(),idx)!=end(); return std::find(begin(),end(),idx)!=end();
} }

View File

@ -54,7 +54,7 @@ public:
ilFunction createFunction(FunctionType *f, const QString & name); ilFunction createFunction(FunctionType *f, const QString & name);
bool valid(ilFunction iter); bool valid(ilFunction iter);
int getSymIdxByAdd(uint32_t adr); int getSymIdxByAddr(uint32_t adr);
bool validSymIdx(size_t idx); bool validSymIdx(size_t idx);
size_t symbolSize(size_t idx); size_t symbolSize(size_t idx);
hlType symbolType(size_t idx); hlType symbolType(size_t idx);

View File

@ -13,6 +13,7 @@
#include "project.h" #include "project.h"
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QDebug>
#include <boost/range.hpp> #include <boost/range.hpp>
#include <boost/range/adaptor/filtered.hpp> #include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
@ -29,12 +30,15 @@ using namespace boost::adaptors;
extern int strSize (const uint8_t *, char); extern int strSize (const uint8_t *, char);
extern char *cChar(uint8_t c); extern char *cChar(uint8_t c);
namespace
{
// Conditional operator symbols in C. Index by condOp enumeration type // Conditional operator symbols in C. Index by condOp enumeration type
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ", constexpr const char * condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
" & ", " | ", " ^ ", " ~ ", " & ", " | ", " ^ ", " ~ ",
" + ", " - ", " * ", " / ", " + ", " - ", " * ", " / ",
" >> ", " << ", " % ", " && ", " || " }; " >> ", " << ", " % ", " && ", " || " };
/* Size of hl types */
constexpr const int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
/* Local expression stack */ /* Local expression stack */
//typedef struct _EXP_STK { //typedef struct _EXP_STK {
@ -43,13 +47,13 @@ static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ",
//} EXP_STK; - for local expression stack //} EXP_STK; - for local expression stack
/* Returns the integer i in C hexadecimal format */ /* Returns the integer i in C hexadecimal format */
static const char *hexStr (uint16_t i) const char *hexStr (uint16_t i)
{ {
static char buf[10]; static char buf[10];
sprintf (buf, "%s%x", (i > 9) ? "0x" : "", i); sprintf (buf, "%s%x", (i > 9) ? "0x" : "", i);
return (buf); return buf;
}
} }
/* Sets the du record for registers according to the du flag */ /* Sets the du record for registers according to the du flag */
void ICODE::setRegDU (eReg regi, operDu du_in) void ICODE::setRegDU (eReg regi, operDu du_in)
@ -124,7 +128,7 @@ GlobalVariable::GlobalVariable(int16_t segValue, int16_t off)
valid = true; valid = true;
ident.idType = GLOB_VAR; ident.idType = GLOB_VAR;
adr = opAdr(segValue, off); adr = opAdr(segValue, off);
auto i=Project::get()->getSymIdxByAdd(adr); auto i=Project::get()->getSymIdxByAddr(adr);
if ( not Project::get()->validSymIdx(i) ) if ( not Project::get()->validSymIdx(i) )
{ {
printf ("Error, glob var not found in symtab\n"); printf ("Error, glob var not found in symtab\n");
@ -136,7 +140,7 @@ GlobalVariable::GlobalVariable(int16_t segValue, int16_t off)
QString GlobalVariable::walkCondExpr(Function *, int *) const QString GlobalVariable::walkCondExpr(Function *, int *) const
{ {
if(valid) if(valid)
return Project::get()->symtab[globIdx].name; return Project::get()->symbolName(globIdx);
return "INVALID GlobalVariable"; return "INVALID GlobalVariable";
} }
@ -344,7 +348,6 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
newExp = AstIdent::Other (pm.seg, pm.regi, pm.off); newExp = AstIdent::Other (pm.seg, pm.regi, pm.off);
/**** check long ops, indexed global var *****/ /**** check long ops, indexed global var *****/
} }
else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */ else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */
{ {
if ((pm.seg == rDS) and (pm.regi > INDEX_BP_DI)) /* dereference */ if ((pm.seg == rDS) and (pm.regi > INDEX_BP_DI)) /* dereference */
@ -367,7 +370,7 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
else else
newExp = AstIdent::Other (pm.seg, pm.regi, 0); newExp = AstIdent::Other (pm.seg, pm.regi, 0);
} }
return (newExp); return newExp;
} }
@ -377,31 +380,28 @@ condId LLInst::idType(opLoc sd) const
const LLOperand &pm((sd == SRC) ? src() : m_dst); const LLOperand &pm((sd == SRC) ? src() : m_dst);
if ((sd == SRC) and testFlags(I)) if ((sd == SRC) and testFlags(I))
return (CONSTANT); return CONSTANT;
else if (pm.regi == 0) else if (pm.regi == 0)
return (GLOB_VAR); return GLOB_VAR;
else if ( pm.isReg() ) else if ( pm.isReg() )
return (REGISTER); return REGISTER;
else if ((pm.seg == rSS) and (pm.regi == INDEX_BP)) else if ((pm.seg == rSS) and (pm.regi == INDEX_BP)) // TODO: this assumes BP-based function frames !
{ {
//TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ? //TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ?
if (pm.off >= 0) if (pm.off >= 0)
return (PARAM); return PARAM;
else return LOCAL_VAR;
return (LOCAL_VAR);
} }
else else
return (OTHER); return OTHER;
} }
/* Size of hl types */
int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4};
int Expr::hlTypeSize(Function * pproc) const int Expr::hlTypeSize(Function * pproc) const
{ {
if (this == nullptr) if (this == nullptr)
return (2); /* for TYPE_UNKNOWN */ return 2; /* for TYPE_UNKNOWN */
fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type); fprintf(stderr,"hlTypeSize queried for Unkown type %d \n",m_type);
return 2; // CC: is this correct? return 2; // CC: is this correct?
} }
@ -436,11 +436,11 @@ int AstIdent::hlTypeSize(Function *pproc) const
case PARAM: case PARAM:
return (hlSize[pproc->args[ident.idNode.paramIdx].type]); return (hlSize[pproc->args[ident.idNode.paramIdx].type]);
case STRING: case STRING:
return (2); return 2;
case LONG_VAR: case LONG_VAR:
return (4); return 4;
case OTHER: case OTHER:
return (2); return 2;
default: default:
assert(false); assert(false);
return -1; return -1;
@ -593,6 +593,10 @@ QString AstIdent::walkCondExpr(Function *pProc, int *numLoc) const
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]"; o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]";
else if (id->id.longGlb.regi == rBX) else if (id->id.longGlb.regi == rBX)
o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]"; o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]";
else {
qCritical() << "AstIdent::walkCondExpr unhandled LONG_VAR in GLB_FRAME";
assert(false);
}
} }
break; break;
case OTHER: case OTHER:
@ -665,9 +669,6 @@ QString UnaryOperator::walkCondExpr(Function *pProc, int *numLoc) const
/* Walks the conditional expression tree and returns the result on a string */ /* Walks the conditional expression tree and returns the result on a string */
/* Changes the boolean conditional operator at the root of this expression */ /* Changes the boolean conditional operator at the root of this expression */
void BinaryOperator::changeBoolOp (condOp newOp) void BinaryOperator::changeBoolOp (condOp newOp)
{ {
@ -798,9 +799,8 @@ Expr *BinaryOperator::insertSubTreeLongReg(Expr *_expr, int longIdx)
Expr *AstIdent::insertSubTreeLongReg(Expr *_expr, int longIdx) Expr *AstIdent::insertSubTreeLongReg(Expr *_expr, int longIdx)
{ {
if (ident.idNode.longIdx == longIdx) if (ident.idNode.longIdx == longIdx)
{
return _expr; return _expr;
}
return nullptr; return nullptr;
} }
@ -816,7 +816,7 @@ Expr *BinaryOperator::clone() const
Expr *BinaryOperator::inverse() const Expr *BinaryOperator::inverse() const
{ {
static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL, constexpr static condOp invCondOp[] = {GREATER, GREATER_EQUAL, NOT_EQUAL, EQUAL,
LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY, LESS_EQUAL, LESS, DUMMY,DUMMY,DUMMY,DUMMY,
DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY, DUMMY,
DUMMY, DBL_OR, DBL_AND}; DUMMY, DBL_OR, DBL_AND};
@ -848,20 +848,18 @@ Expr *AstIdent::performLongRemoval(eReg regi, LOCAL_ID *locId)
{ {
eReg otherRegi; /* high or low part of long register */ eReg otherRegi; /* high or low part of long register */
if (ident.idType == LONG_VAR) if (ident.idType != LONG_VAR)
{
otherRegi = locId->getPairedRegisterAt(ident.idNode.longIdx,regi);
delete this;
return new RegisterNode(locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi),WORD_REG,locId);
}
return this; return this;
otherRegi = locId->getPairedRegisterAt(ident.idNode.longIdx,regi);
bool long_was_signed = locId->id_arr[ident.idNode.longIdx].isSigned();
delete this;
return new RegisterNode(locId->newByteWordReg(long_was_signed ? TYPE_WORD_SIGN : TYPE_WORD_UNSIGN,otherRegi),WORD_REG,locId);
} }
QString Constant::walkCondExpr(Function *, int *) const QString Constant::walkCondExpr(Function *, int *) const
{ {
if (kte.kte < 1000) if (kte.kte < 1000)
return QString::number(kte.kte); return QString::number(kte.kte);
else
return "0x" + QString::number(kte.kte,16); return "0x" + QString::number(kte.kte,16);
} }
@ -870,8 +868,6 @@ int Constant::hlTypeSize(Function *) const
return kte.size; return kte.size;
} }
QString FuncNode::walkCondExpr(Function *pProc, int *numLoc) const QString FuncNode::walkCondExpr(Function *pProc, int *numLoc) const
{ {
return pProc->writeCall(call.proc,*call.args, numLoc); return pProc->writeCall(call.proc,*call.args, numLoc);

View File

@ -158,9 +158,9 @@ void Project::writeGlobSymTable()
else { /* first defined */ else { /* first defined */
switch (sym.size) { switch (sym.size) {
case 1: ostr<<"uint8_t\t"; break; case 1: ostr<<"uint8_t\t"; break;
case 2: ostr<<"int\t"; break; case 2: ostr<<"int16_t\t"; break;
case 4: if (sym.type == TYPE_PTR) case 4: if (sym.type == TYPE_PTR)
ostr<<"int\t*"; ostr<<"int32_t\t*";
else else
ostr<<"char\t*"; ostr<<"char\t*";
break; break;

View File

@ -735,7 +735,7 @@ int C_CallingConvention::processCArg (Function * callee, Function * pProc, ICODE
callee->args.adjustForArgType (numArgs, _exp->expType (pProc)); callee->args.adjustForArgType (numArgs, _exp->expType (pProc));
} }
} }
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), 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
* in a near call */ * in a near call */
if (res == false) if (res == false)
@ -850,7 +850,7 @@ void Pascal_CallingConvention::processHLI(Function *func,Expr *_exp, iICODE pico
{ {
if (pp->args.numArgs > 0) if (pp->args.numArgs > 0)
_exp = func->adjustActArgType(_exp, pp->args[numArgs].type); _exp = func->adjustActArgType(_exp, pp->args[numArgs].type);
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), func); res = picode->newStkArg (_exp, picode->ll()->getOpcode(), func);
} }
else /* user function */ else /* user function */
{ {
@ -863,7 +863,7 @@ void Pascal_CallingConvention::processHLI(Function *func,Expr *_exp, iICODE pico
else else
pp->args.adjustForArgType (numArgs,_exp->expType (func)); pp->args.adjustForArgType (numArgs,_exp->expType (func));
} }
res = picode->newStkArg (_exp,(llIcode)picode->ll()->getOpcode(), func); res = picode->newStkArg (_exp, picode->ll()->getOpcode(), func);
} }
if (res == false) if (res == false)
k += _exp->hlTypeSize (func); k += _exp->hlTypeSize (func);

View File

@ -75,8 +75,7 @@ eReg ID::getPairedRegister(eReg first) const {
* ix : index into icode array where this var is used */ * ix : index into icode array where this var is used */
void LOCAL_ID::newIdent(hlType t, frameType f) void LOCAL_ID::newIdent(hlType t, frameType f)
{ {
ID newid(t,f); id_arr.emplace_back(t,f);
id_arr.push_back(newid);
} }
@ -92,9 +91,8 @@ int LOCAL_ID::newByteWordReg(hlType t, eReg regi)
return found-id_arr.begin(); return found-id_arr.begin();
/* Not in table, create new identifier */ /* Not in table, create new identifier */
newIdent (t, REG_FRAME); newIdent (t, REG_FRAME);
int idx = id_arr.size() - 1; id_arr.back().id.regi = regi;
id_arr[idx].id.regi = regi; return id_arr.size() - 1;
return (idx);
} }

View File

@ -5,12 +5,11 @@
#include "CallGraph.h" #include "CallGraph.h"
#include "project.h" #include "project.h"
#include "Procedure.h" #include "Procedure.h"
using namespace std; using namespace std;
//Project g_proj;
QString asm1_name, asm2_name; /* Assembler output filenames */ QString asm1_name, asm2_name; /* Assembler output filenames */
SYMTAB symtab; /* Global symbol table */
STATS stats; /* cfg statistics */ STATS stats; /* cfg statistics */
//PROG prog; /* programs fields */
OPTION option; /* Command line options */ OPTION option; /* Command line options */
Project *Project::s_instance = nullptr; Project *Project::s_instance = nullptr;
Project::Project() : callGraph(nullptr) Project::Project() : callGraph(nullptr)
@ -50,7 +49,7 @@ ilFunction Project::findByEntry(uint32_t entry)
/* Search procedure list for one with appropriate entry point */ /* Search procedure list for one with appropriate entry point */
ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(), ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(),
[entry](const Function &f) { return f.procEntry==entry; }); [entry](const Function &f) { return f.procEntry==entry; });
return iter; return iter;
} }
ilFunction Project::createFunction(FunctionType *f,const QString &name) ilFunction Project::createFunction(FunctionType *f,const QString &name)
@ -59,7 +58,7 @@ ilFunction Project::createFunction(FunctionType *f,const QString &name)
return (++pProcList.rbegin()).base(); return (++pProcList.rbegin()).base();
} }
int Project::getSymIdxByAdd(uint32_t adr) int Project::getSymIdxByAddr(uint32_t adr)
{ {
size_t i; size_t i;
for (i = 0; i < symtab.size(); i++) for (i = 0; i < symtab.size(); i++)
@ -98,8 +97,6 @@ Project *Project::get()
s_instance=new Project; s_instance=new Project;
return s_instance; return s_instance;
} }
SourceMachine *Project::machine() SourceMachine *Project::machine()
{ {
return nullptr; return nullptr;

View File

@ -69,8 +69,8 @@ static bool 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) and if ( icodes[1]->ll()->match(iCMP) and
(isJCond ((llIcode)icodes[0]->ll()->getOpcode())) and (isJCond (icodes[0]->ll()->getOpcode())) and
(isJCond ((llIcode)icodes[2]->ll()->getOpcode()))) (isJCond (icodes[2]->ll()->getOpcode())))
{ {
off = initial_icode; off = initial_icode;
advance(off,2); advance(off,2);
@ -500,7 +500,7 @@ 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) and (next1 != pEnd) and (isJCond ((llIcode)next1->ll()->getOpcode()))) else if (pIcode->ll()->match(iOR) and (next1 != pEnd) and (isJCond (next1->ll()->getOpcode())))
{ {
if (pLocId.longId().srcDstRegMatch(pIcode,pIcode)) if (pLocId.longId().srcDstRegMatch(pIcode,pIcode))
{ {

View File

@ -19,7 +19,6 @@
#define S_EXT 0x000200 /* sign extend */ #define S_EXT 0x000200 /* sign extend */
#define OP386 0x000400 /* 386 op-code */ #define OP386 0x000400 /* 386 op-code */
#define NSP 0x000800 /* NOT_HLL if SP is src or dst */ #define NSP 0x000800 /* NOT_HLL if SP is src or dst */
// defined in Enums.h #define ICODEMASK 0xFF00FF /* Masks off parser flags */
static void rm(int i); static void rm(int i);
static void modrm(int i); static void modrm(int i);
@ -51,15 +50,15 @@ static void none1(int i);
static void none2(int i); static void none2(int i);
static void checkInt(int i); static void checkInt(int i);
#define iZERO (llIcode)0 // For neatness
#define IC llIcode #define IC llIcode
static struct { struct StateTabelEntry {
void (*state1)(int); void (*state1)(int);
void (*state2)(int); void (*state2)(int);
uint32_t flg; uint32_t flg;
llIcode opcode; llIcode opcode;
} stateTable[] = { };
static const StateTabelEntry stateTable[] = {
{ modrm, none2, B , iADD }, /* 00 */ { modrm, none2, B , iADD }, /* 00 */
{ modrm, none2, 0 , iADD }, /* 01 */ { modrm, none2, 0 , iADD }, /* 01 */
{ modrm, none2, TO_REG | B , iADD }, /* 02 */ { modrm, none2, TO_REG | B , iADD }, /* 02 */
@ -75,7 +74,7 @@ static struct {
{ data1, axImp, B , iOR }, /* 0C */ { data1, axImp, B , iOR }, /* 0C */
{ data2, axImp, 0 , iOR }, /* 0D */ { data2, axImp, 0 , iOR }, /* 0D */
{ segop, none2, NO_SRC , iPUSH }, /* 0E */ { segop, none2, NO_SRC , iPUSH }, /* 0E */
{ none1, none2, OP386 , iZERO }, /* 0F */ { none1, none2, OP386 , iINVALID }, /* 0F */
{ modrm, none2, B , iADC }, /* 10 */ { modrm, none2, B , iADC }, /* 10 */
{ modrm, none2, NSP , iADC }, /* 11 */ { modrm, none2, NSP , iADC }, /* 11 */
{ modrm, none2, TO_REG | B , iADC }, /* 12 */ { modrm, none2, TO_REG | B , iADC }, /* 12 */
@ -159,11 +158,11 @@ static struct {
{ none1, none2, NOT_HLL | NO_OPS , iPUSHA}, /* 60 */ { none1, none2, NOT_HLL | NO_OPS , iPUSHA}, /* 60 */
{ none1, none2, NOT_HLL | NO_OPS , iPOPA }, /* 61 */ { none1, none2, NOT_HLL | NO_OPS , iPOPA }, /* 61 */
{ memOnly, modrm, TO_REG | NSP , iBOUND}, /* 62 */ { memOnly, modrm, TO_REG | NSP , iBOUND}, /* 62 */
{ none1, none2, OP386 , iZERO }, /* 63 */ { none1, none2, OP386 , iINVALID }, /* 63 */
{ none1, none2, OP386 , iZERO }, /* 64 */ { none1, none2, OP386 , iINVALID }, /* 64 */
{ none1, none2, OP386 , iZERO }, /* 65 */ { none1, none2, OP386 , iINVALID }, /* 65 */
{ none1, none2, OP386 , iZERO }, /* 66 */ { none1, none2, OP386 , iINVALID }, /* 66 */
{ none1, none2, OP386 , iZERO }, /* 67 */ { none1, none2, OP386 , iINVALID }, /* 67 */
{ data2, none2, NO_SRC , iPUSH }, /* 68 */ { data2, none2, NO_SRC , iPUSH }, /* 68 */
{ modrm, data2, TO_REG | NSP , iIMUL }, /* 69 */ { modrm, data2, TO_REG | NSP , iIMUL }, /* 69 */
{ data1, none2, S_EXT | NO_SRC , iPUSH }, /* 6A */ { data1, none2, S_EXT | NO_SRC , iPUSH }, /* 6A */
@ -188,10 +187,10 @@ static struct {
{ dispS, none2, 0 , iJGE }, /* 7D */ { dispS, none2, 0 , iJGE }, /* 7D */
{ dispS, none2, 0 , iJLE }, /* 7E */ { dispS, none2, 0 , iJLE }, /* 7E */
{ dispS, none2, 0 , iJG }, /* 7F */ { dispS, none2, 0 , iJG }, /* 7F */
{ immed, data1, B , iZERO }, /* 80 */ { immed, data1, B , iINVALID }, /* 80 */
{ immed, data2, NSP , iZERO }, /* 81 */ { immed, data2, NSP , iINVALID }, /* 81 */
{ immed, data1, B , iZERO }, /* 82 */ /* ?? */ { immed, data1, B , iINVALID }, /* 82 */ /* ?? */
{ immed, data1, NSP | S_EXT , iZERO }, /* 83 */ { immed, data1, NSP | S_EXT , iINVALID }, /* 83 */
{ modrm, none2, TO_REG | B , iTEST }, /* 84 */ { modrm, none2, TO_REG | B , iTEST }, /* 84 */
{ modrm, none2, TO_REG | NSP , iTEST }, /* 85 */ { modrm, none2, TO_REG | NSP , iTEST }, /* 85 */
{ modrm, none2, TO_REG | B , iXCHG }, /* 86 */ { modrm, none2, TO_REG | B , iXCHG }, /* 86 */
@ -252,8 +251,8 @@ static struct {
{ regop, data2, 0 , iMOV }, /* BD */ { regop, data2, 0 , iMOV }, /* BD */
{ regop, data2, 0 , iMOV }, /* BE */ { regop, data2, 0 , iMOV }, /* BE */
{ regop, data2, 0 , iMOV }, /* BF */ { regop, data2, 0 , iMOV }, /* BF */
{ shift, data1, B , iZERO }, /* C0 */ { shift, data1, B , iINVALID }, /* C0 */
{ shift, data1, NSP | SRC_B , iZERO }, /* C1 */ { shift, data1, NSP | SRC_B , iINVALID }, /* C1 */
{ data2, none2, 0 , iRET }, /* C2 */ { data2, none2, 0 , iRET }, /* C2 */
{ none1, none2, NO_OPS , iRET }, /* C3 */ { none1, none2, NO_OPS , iRET }, /* C3 */
{ memOnly, modrm, TO_REG | NSP , iLES }, /* C4 */ { memOnly, modrm, TO_REG | NSP , iLES }, /* C4 */
@ -268,13 +267,13 @@ static struct {
{ data1,checkInt, NOT_HLL , iINT }, /* CD */ { data1,checkInt, NOT_HLL , iINT }, /* CD */
{ none1, none2, NOT_HLL | NO_OPS , iINTO }, /* CE */ { none1, none2, NOT_HLL | NO_OPS , iINTO }, /* CE */
{ none1, none2, NOT_HLL | NO_OPS , iIRET }, /* Cf */ { none1, none2, NOT_HLL | NO_OPS , iIRET }, /* Cf */
{ shift, const1, B , iZERO }, /* D0 */ { shift, const1, B , iINVALID }, /* D0 */
{ shift, const1, SRC_B , iZERO }, /* D1 */ { shift, const1, SRC_B , iINVALID }, /* D1 */
{ shift, none1, B , iZERO }, /* D2 */ { shift, none1, B , iINVALID }, /* D2 */
{ shift, none1, SRC_B , iZERO }, /* D3 */ { shift, none1, SRC_B , iINVALID }, /* D3 */
{ data1, axImp, NOT_HLL , iAAM }, /* D4 */ { data1, axImp, NOT_HLL , iAAM }, /* D4 */
{ data1, axImp, NOT_HLL , iAAD }, /* D5 */ { data1, axImp, NOT_HLL , iAAD }, /* D5 */
{ none1, none2, 0 , iZERO }, /* D6 */ { none1, none2, 0 , iINVALID }, /* D6 */
{ memImp, axImp, NOT_HLL | B| IM_OPS , iXLAT }, /* D7 */ { memImp, axImp, NOT_HLL | B| IM_OPS , iXLAT }, /* D7 */
{ escop, none2, FLOAT_OP , iESC }, /* D8 */ { escop, none2, FLOAT_OP , iESC }, /* D8 */
{ escop, none2, FLOAT_OP , iESC }, /* D9 */ { escop, none2, FLOAT_OP , iESC }, /* D9 */
@ -301,21 +300,21 @@ static struct {
{ none1, axImp, NOT_HLL | B|NO_SRC , iOUT }, /* EE */ { none1, axImp, NOT_HLL | B|NO_SRC , iOUT }, /* EE */
{ none1, axImp, NOT_HLL | NO_SRC , iOUT }, /* EF */ { none1, axImp, NOT_HLL | NO_SRC , iOUT }, /* EF */
{ none1, none2, NOT_HLL | NO_OPS , iLOCK }, /* F0 */ { none1, none2, NOT_HLL | NO_OPS , iLOCK }, /* F0 */
{ none1, none2, 0 , iZERO }, /* F1 */ { none1, none2, 0 , iINVALID }, /* F1 */
{ prefix, none2, 0 , iREPNE}, /* F2 */ { prefix, none2, 0 , iREPNE}, /* F2 */
{ prefix, none2, 0 , iREPE }, /* F3 */ { prefix, none2, 0 , iREPE }, /* F3 */
{ none1, none2, NOT_HLL | NO_OPS , iHLT }, /* F4 */ { none1, none2, NOT_HLL | NO_OPS , iHLT }, /* F4 */
{ none1, none2, NO_OPS , iCMC }, /* F5 */ { none1, none2, NO_OPS , iCMC }, /* F5 */
{ arith, none1, B , iZERO }, /* F6 */ { arith, none1, B , iINVALID }, /* F6 */
{ arith, none1, NSP , iZERO }, /* F7 */ { arith, none1, NSP , iINVALID }, /* F7 */
{ none1, none2, NO_OPS , iCLC }, /* F8 */ { none1, none2, NO_OPS , iCLC }, /* F8 */
{ none1, none2, NO_OPS , iSTC }, /* F9 */ { none1, none2, NO_OPS , iSTC }, /* F9 */
{ none1, none2, NOT_HLL | NO_OPS , iCLI }, /* FA */ { none1, none2, NOT_HLL | NO_OPS , iCLI }, /* FA */
{ none1, none2, NOT_HLL | NO_OPS , iSTI }, /* FB */ { none1, none2, NOT_HLL | NO_OPS , iSTI }, /* FB */
{ none1, none2, NO_OPS , iCLD }, /* FC */ { none1, none2, NO_OPS , iCLD }, /* FC */
{ none1, none2, NO_OPS , iSTD }, /* FD */ { none1, none2, NO_OPS , iSTD }, /* FD */
{ trans, none1, B , iZERO }, /* FE */ { trans, none1, B , iINVALID }, /* FE */
{ trans, none1, NSP , iZERO } /* FF */ { trans, none1, NSP , iINVALID } /* FF */
} ; } ;
static uint16_t SegPrefix, RepPrefix; static uint16_t SegPrefix, RepPrefix;
@ -571,7 +570,7 @@ eErrorId scan(uint32_t ip, ICODE &p)
} }
// LLOperand conv = convertOperand(*p.insn.get_dest()); // LLOperand conv = convertOperand(*p.insn.get_dest());
// assert(conv==p.ll()->dst); // assert(conv==p.ll()->dst);
if (p.ll()->getOpcode()) if (p.ll()->getOpcode()!=iINVALID)
{ {
/* 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);
@ -787,7 +786,7 @@ static void memImp(int i)
static void memOnly(int ) static void memOnly(int )
{ {
if ((*pInst & 0xC0) == 0xC0) if ((*pInst & 0xC0) == 0xC0)
pIcode->ll()->setOpcode((llIcode)0); pIcode->ll()->setOpcode(iINVALID);
} }
@ -797,7 +796,7 @@ static void memOnly(int )
static void memReg0(int i) static void memReg0(int i)
{ {
if (REG(*pInst) or (*pInst & 0xC0) == 0xC0) if (REG(*pInst) or (*pInst & 0xC0) == 0xC0)
pIcode->ll()->setOpcode((llIcode)0); pIcode->ll()->setOpcode(iINVALID);
else else
rm(i); rm(i);
} }
@ -841,8 +840,8 @@ static void trans(int i)
{ {
static llIcode transTable[8] = static llIcode transTable[8] =
{ {
(llIcode)iINC, iDEC, (llIcode)iCALL, (llIcode)iCALLF, iINC, iDEC, iCALL, iCALLF,
(llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0 iJMP, iJMPF,iPUSH, (llIcode)0
}; };
LLInst *ll = pIcode->ll(); LLInst *ll = pIcode->ll();
// if(transTable[REG(*pInst)]==iPUSH) { // if(transTable[REG(*pInst)]==iPUSH) {
@ -868,7 +867,7 @@ static void arith(int i)
uint8_t opcode; uint8_t opcode;
static llIcode arithTable[8] = static llIcode arithTable[8] =
{ {
iTEST, (llIcode)0, iNOT, iNEG, iTEST, iINVALID, iNOT, iNEG,
iMUL , iIMUL, iDIV, iIDIV iMUL , iIMUL, iDIV, iIDIV
}; };
opcode = arithTable[REG(*pInst)]; opcode = arithTable[REG(*pInst)];
@ -985,7 +984,7 @@ static void dispF(int i)
****************************************************************************/ ****************************************************************************/
static void prefix(int ) static void prefix(int )
{ {
if (pIcode->ll()->getOpcode() == iREPE or pIcode->ll()->getOpcode() == iREPNE) if ((pIcode->ll()->getOpcode() == iREPE) or (pIcode->ll()->getOpcode() == iREPNE))
RepPrefix = pIcode->ll()->getOpcode(); RepPrefix = pIcode->ll()->getOpcode();
else else
SegPrefix = pIcode->ll()->getOpcode(); SegPrefix = pIcode->ll()->getOpcode();
@ -993,7 +992,7 @@ static void prefix(int )
inline void BumpOpcode(LLInst &ll) inline void BumpOpcode(LLInst &ll)
{ {
llIcode ic((llIcode)ll.getOpcode()); 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); ll.setOpcode(ic);
} }