support added for predicated instructions that are not executed

This commit is contained in:
Rajshekar K K 2021-01-20 11:50:21 +05:30
parent 98a305645d
commit fa8251d31d
11 changed files with 534 additions and 417 deletions

View File

@ -505,7 +505,7 @@ VOID BarrierInit(ADDRINT first_arg, ADDRINT val, UINT32 encode, THREADID tid) {
}
}
/*** This function is called on every instruction ***/
VOID printip(THREADID tid, VOID *ip, char *asmString) {
VOID printip(THREADID tid, VOID *ip, char *asmString, bool predicateInsnNotExecuted) {
if(outOfROIPhase)
{
@ -612,8 +612,17 @@ VOID printip(THREADID tid, VOID *ip, char *asmString) {
uint64_t nip = MASK & (uint64_t) ip;
if(traceMethod==SharedMemory) {
while (tst->analysisFn(tid, nip, INSTRUCTION, 1) == -1) {
PIN_Yield();
if(predicateInsnNotExecuted)
{
while (tst->analysisFn(tid, nip, PREDICATE_INSN_NOT_EXECUTED, 1) == -1) {
PIN_Yield();
}
}
else
{
while (tst->analysisFn(tid, nip, INSTRUCTION, 1) == -1) {
PIN_Yield();
}
}
} else if(traceMethod==File) {
while (tst->analysisFnAssembly(tid, nip, ASSEMBLY, asmString) == -1) {
@ -674,7 +683,7 @@ VOID Instruction(INS ins, VOID *v) {
asmChar = (char *)asmString->c_str();
}
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_THREAD_ID, IARG_INST_PTR, IARG_PTR, asmChar, IARG_END);
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_THREAD_ID, IARG_INST_PTR, IARG_PTR, asmChar, IARG_EXECUTING, IARG_END);
UINT32 memOperands = INS_MemoryOperandCount(ins);

View File

@ -31,5 +31,7 @@
#define PARENT_SPAWN 35
#define CHILD_START 36
#define PREDICATE_INSN_NOT_EXECUTED 37
const char* findType(int type);

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,8 @@ public class DynamicInstructionBuffer implements Encoding
private long ip;
private boolean predicateInsnNotExecuted;
public DynamicInstructionBuffer()
{
memRead = new long[64];
@ -59,6 +61,8 @@ public class DynamicInstructionBuffer implements Encoding
branchAddress = -1;
predicateInsnNotExecuted = false;
ip = arrayListPacket.get(0).ip;
int numAssemblyPackets = 0;
@ -100,6 +104,10 @@ public class DynamicInstructionBuffer implements Encoding
branchTaken = false;
branchAddress = p.tgt;
break;
case (PREDICATE_INSN_NOT_EXECUTED):
predicateInsnNotExecuted = true;
break;
case (ASSEMBLY):
numAssemblyPackets++;
@ -190,4 +198,8 @@ public class DynamicInstructionBuffer implements Encoding
boolean readAuthenticBranch = branchInformationRead==false && branchAddress!=-1;
return readAuthenticBranch;
}
public boolean isPredicateInsnNotExecuted() {
return predicateInsnNotExecuted;
}
}

View File

@ -204,6 +204,7 @@ public class RunnableThread implements Encoding, Runnable {
iNew.setDestinationOperandMemValue(Long.parseLong(splited[i+2]));
iNew.setBranchTargetAddress(Long.parseLong(splited[i+3]));
iNew.setBranchTaken(Boolean.parseBoolean(splited[i+4]));
iNew.setPredicateAndNotExecuted(Boolean.parseBoolean(splited[i+7]));
//iNew.setSerialNo(Long.parseLong(splited[i+6]));
}
}
@ -833,7 +834,7 @@ public class RunnableThread implements Encoding, Runnable {
}
if (pnew.value!=INSTRUCTION && !(pnew.value>6 && pnew.value<26) && pnew.value!=Encoding.ASSEMBLY ) {
if (pnew.value!=INSTRUCTION && !(pnew.value>6 && pnew.value<26) && pnew.value!=Encoding.ASSEMBLY && pnew.value!=Encoding.PREDICATE_INSN_NOT_EXECUTED ) {
// just append the packet to outstanding packetList for current instruction pointer
thread.packetList.add(pnew);

View File

@ -41,5 +41,7 @@ public interface Encoding {
static final int CPL_SWITCH = 34;
static final int PARENT_SPAWN = 35;
static final int CHILD_START = 36;
static final int PREDICATE_INSN_NOT_EXECUTED = 37;
}

View File

@ -9,7 +9,7 @@ public class IntegerALU implements DynamicInstructionHandler
public int handle(int microOpIndex,
Instruction microOp, DynamicInstructionBuffer dynamicInstructionBuffer)
{
//nothing to be done in such cases
microOp.setPredicateAndNotExecuted(dynamicInstructionBuffer.isPredicateInsnNotExecuted());
return ++microOpIndex;
}
}

View File

@ -44,7 +44,9 @@ public class ConditionalMove implements X86StaticInstructionHandler
(operand2.isIntegerRegisterOperand() || operand2.isImmediateOperand()) &&
(operand3==null))
{
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(operand2, Registers.getEFlagsRegister(), operand1));
Operand temp = Registers.getTempIntReg(tempRegisterNum);
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(Registers.getEFlagsRegister(), operand1, temp));
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(operand2, temp, operand1));
}
//if operand1 = register and operand2 = memory - load
@ -52,8 +54,10 @@ public class ConditionalMove implements X86StaticInstructionHandler
operand2.isMemoryOperand() &&
operand3==null)
{
Operand temp = Registers.getTempIntReg(tempRegisterNum);
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(Registers.getEFlagsRegister(), operand1, temp));
Operand sourceOperand = OperandTranslator.processSourceMemoryOperand(operand2, instructionArrayList, tempRegisterNum, true);
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(sourceOperand, Registers.getEFlagsRegister(), operand1));
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(sourceOperand, temp, operand1));
}
// //if operand1 = memory and operand2 = memory - store

View File

@ -19,7 +19,7 @@ public class ConditionalSet implements X86StaticInstructionHandler
operand2==null && operand3==null)
{
instructionArrayList.appendInstruction(Instruction.getIntALUInstruction(Registers.getEFlagsRegister(),
Operand.getImmediateOperand(), operand1));
operand1, operand1));
}
else if(operand1.isMemoryOperand())

View File

@ -44,11 +44,14 @@ public class Instruction implements Serializable
private long serialNo;
private int threadID;
private boolean isPredicateAndNotExecuted;
public Instruction()
{
this.sourceOperand1 = null;
this.sourceOperand2 = null;
this.destinationOperand = null;
isPredicateAndNotExecuted = false;
}
public void clear()
@ -57,6 +60,7 @@ public class Instruction implements Serializable
this.sourceOperand1 = null;
this.sourceOperand2 = null;
this.destinationOperand = null;
isPredicateAndNotExecuted = false;
}
public Instruction(OperationType type, Operand sourceOperand1,
@ -66,6 +70,7 @@ public class Instruction implements Serializable
this.sourceOperand1 = sourceOperand1;
this.sourceOperand2 = sourceOperand2;
this.destinationOperand = destinationOperand;
isPredicateAndNotExecuted = false;
}
private void set(OperationType type, Operand sourceOperand1,
@ -75,6 +80,7 @@ public class Instruction implements Serializable
this.sourceOperand1 = sourceOperand1;
this.sourceOperand2 = sourceOperand2;
this.destinationOperand = destinationOperand;
isPredicateAndNotExecuted = false;
}
// /* our clone constructor */
@ -123,6 +129,8 @@ public class Instruction implements Serializable
this.serialNo = sourceInstruction.serialNo;
this.threadID = sourceInstruction.threadID;
this.isPredicateAndNotExecuted = sourceInstruction.isPredicateAndNotExecuted;
}
public static Instruction getIntALUInstruction(Operand sourceOperand1, Operand sourceOperand2, Operand destinationOperand)
@ -492,6 +500,14 @@ public class Instruction implements Serializable
this.destinationOperandMemValue = destinationOperandMemValue;
}
public boolean isPredicateAndNotExecuted() {
return isPredicateAndNotExecuted;
}
public void setPredicateAndNotExecuted(boolean isPredicateAndNotExecuted) {
this.isPredicateAndNotExecuted = isPredicateAndNotExecuted;
}
/**
* strInstruction method returns the instruction information in a string.
* @return String describing the instruction

View File

@ -448,7 +448,7 @@ public class ReorderBuffer extends SimulationElement{
else bw.write(" null null null");
bw.write(" "+tmp.getSourceOperand1MemValue()+" "+
tmp.getSourceOperand2MemValue()+" "+tmp.getDestinationOperandMemValue()+" "+
tmp.getBranchTargetAddress()+" "+tmp.isBranchTaken()+" "+tmp.getThreadID()+" "+tmp.getSerialNo()+"\n");
tmp.getBranchTargetAddress()+" "+tmp.isBranchTaken()+" "+tmp.getThreadID()+" "+tmp.getSerialNo()+" "+tmp.isPredicateAndNotExecuted()+"\n");
}
catch(Exception e)
{