Enhanced logging in ALUInstr
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1723 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
#include "aluinstr.hpp"
|
#include "aluinstr.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "bochs.h"
|
#include "bochs.h"
|
||||||
@ -90,12 +92,14 @@ bool BochsALUInstructions::isALUInstruction(bxInstruction_c const *src) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bxInstruction_c BochsALUInstructions::randomEquivalent() const {
|
void BochsALUInstructions::randomEquivalent(bxInstruction_c &result,
|
||||||
|
std::string &details) const {
|
||||||
// find a random member of the same equivalence class
|
// find a random member of the same equivalence class
|
||||||
X86AluClass equClassID = lastInstr.aluClass;
|
X86AluClass equClassID = lastInstr.aluClass;
|
||||||
if (equClassID == ALU_UNDEF) {
|
if (equClassID == ALU_UNDEF) {
|
||||||
// something went wrong - just return the original instruction
|
// something went wrong - just return the original instruction
|
||||||
return lastOrigInstr;
|
result = lastOrigInstr;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstrList const &destList = equivalenceClasses.at(equClassID);
|
InstrList const &destList = equivalenceClasses.at(equClassID);
|
||||||
@ -106,8 +110,16 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const {
|
|||||||
dest = destList[index];
|
dest = destList[index];
|
||||||
} while (memcmp(&dest, &lastInstr, sizeof(BochsALUInstr)) == 0);
|
} while (memcmp(&dest, &lastInstr, sizeof(BochsALUInstr)) == 0);
|
||||||
|
|
||||||
|
// alternative chosen -- now store the necessary details
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Opcode 0x" << std::hex << static_cast<unsigned>(dest.opcode) << std::dec;
|
||||||
|
if (dest.reg < dest.REG_COUNT) oss << " # " << static_cast<unsigned>(dest.reg);
|
||||||
|
if (dest.opcodeRegisterOffset <= dest.REG_COUNT)
|
||||||
|
oss << " # " << static_cast<unsigned>(dest.opcodeRegisterOffset);
|
||||||
|
details = oss.str();
|
||||||
|
|
||||||
// first, copy everything
|
// first, copy everything
|
||||||
bxInstruction_c result = lastOrigInstr;
|
result = lastOrigInstr;
|
||||||
|
|
||||||
// then change what has to be different
|
// then change what has to be different
|
||||||
// execute functions
|
// execute functions
|
||||||
@ -124,12 +136,9 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const {
|
|||||||
if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) {
|
if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) {
|
||||||
result.setRm(dest.opcodeRegisterOffset);
|
result.setRm(dest.opcodeRegisterOffset);
|
||||||
}
|
}
|
||||||
// finally, return the result
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void BochsALUInstructions::printNestedMap() {
|
void BochsALUInstructions::printNestedMap() {
|
||||||
for (EquivClassMap::iterator it = equivalenceClasses.begin();
|
for (EquivClassMap::iterator it = equivalenceClasses.begin();
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "cpu/instr.h"
|
#include "cpu/instr.h"
|
||||||
@ -321,9 +322,10 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Determines a new bxInstruction_c object with an equivalent
|
* Determines a new bxInstruction_c object with an equivalent
|
||||||
* addressing mode.
|
* addressing mode.
|
||||||
* @returns a bxInstruction_c object as described above
|
* @param result the resulting bxInstruction_c object as described above
|
||||||
|
* @param details after completion contains details about \c result
|
||||||
*/
|
*/
|
||||||
bxInstruction_c randomEquivalent() const;
|
void randomEquivalent(bxInstruction_c &result, std::string &details) const;
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Convert a bxInstruction_c object into its matching BochsALUInstr object.
|
* Convert a bxInstruction_c object into its matching BochsALUInstr object.
|
||||||
|
|||||||
@ -377,6 +377,7 @@ bool L4SysExperiment::run() {
|
|||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << "Sent package did not contain the injection location (register offset)" << endl;
|
ss << "Sent package did not contain the injection location (register offset)" << endl;
|
||||||
param.msg.set_details(ss.str());
|
param.msg.set_details(ss.str());
|
||||||
|
m_jc.sendResult(param);
|
||||||
simulator.terminate(30);
|
simulator.terminate(30);
|
||||||
}
|
}
|
||||||
int reg_offset = param.msg.register_offset();
|
int reg_offset = param.msg.register_offset();
|
||||||
@ -540,8 +541,14 @@ bool L4SysExperiment::run() {
|
|||||||
currInstr = simulator.getCurrentInstruction())) {
|
currInstr = simulator.getCurrentInstruction())) {
|
||||||
singleStep();
|
singleStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// store the real injection point
|
||||||
|
param.msg.set_injection_ip(simulator.getRegisterManager().getInstructionPointer());
|
||||||
|
|
||||||
// now exchange it with a random equivalent
|
// now exchange it with a random equivalent
|
||||||
bxInstruction_c newInstr = aluInstrObject.randomEquivalent();
|
bxInstruction_c newInstr;
|
||||||
|
string details;
|
||||||
|
aluInstrObject.randomEquivalent(newInstr, details);
|
||||||
if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) {
|
if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) {
|
||||||
// something went wrong - exit experiment
|
// something went wrong - exit experiment
|
||||||
param.msg.set_resulttype(param.msg.UNKNOWN);
|
param.msg.set_resulttype(param.msg.UNKNOWN);
|
||||||
@ -549,11 +556,15 @@ bool L4SysExperiment::run() {
|
|||||||
simulator.getRegisterManager().getInstructionPointer());
|
simulator.getRegisterManager().getInstructionPointer());
|
||||||
param.msg.set_output(sanitised(output.c_str()));
|
param.msg.set_output(sanitised(output.c_str()));
|
||||||
|
|
||||||
stringstream ss;
|
ostringstream oss;
|
||||||
ss << "Did not hit an ALU instruction - correct the source code please!" << endl;
|
oss << "Did not hit an ALU instruction - correct the source code please!" << endl;
|
||||||
param.msg.set_details(ss.str());
|
param.msg.set_details(oss.str());
|
||||||
|
m_jc.sendResult(param);
|
||||||
simulator.terminate(40);
|
simulator.terminate(40);
|
||||||
}
|
}
|
||||||
|
// record information on the new instruction
|
||||||
|
param.msg.set_details(details);
|
||||||
|
|
||||||
// inject it
|
// inject it
|
||||||
injectInstruction(currInstr, &newInstr);
|
injectInstruction(currInstr, &newInstr);
|
||||||
|
|
||||||
@ -567,7 +578,6 @@ bool L4SysExperiment::run() {
|
|||||||
BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE);
|
BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE);
|
||||||
ev_incomplete.setCounter(static_cast<unsigned>(L4SYS_NUMINSTR * 1.1));
|
ev_incomplete.setCounter(static_cast<unsigned>(L4SYS_NUMINSTR * 1.1));
|
||||||
simulator.addListener(&ev_incomplete);
|
simulator.addListener(&ev_incomplete);
|
||||||
log << calculateTimeout() << endl;
|
|
||||||
TimerListener ev_timeout(calculateTimeout());
|
TimerListener ev_timeout(calculateTimeout());
|
||||||
simulator.addListener(&ev_timeout);
|
simulator.addListener(&ev_timeout);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user