00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <pch.h>
00033
00034 #include "Sim/System/EmulationTraceSystem/EmulationTraceSystem.h"
00035 #include "Sim/System/EmulationSystem/EmulationOp.h"
00036 #include "Emu/EmulatorFactory.h"
00037
00038 using namespace std;
00039 using namespace boost;
00040 using namespace Onikiri;
00041
00042
00043 void EmulationTraceSystem::Run( SystemContext* context )
00044 {
00045 int processCount = context->emulator->GetProcessCount();
00046
00047 vector<ofstream*> ofsList;
00048 ofsList.resize( processCount );
00049 for( int pid = 0; pid < processCount; pid++ ){
00050 String fileName =
00051 g_env.GetHostWorkPath() + "./emulator." + lexical_cast<String>(pid) + ".log";
00052 ofsList[pid] = new ofstream( fileName );
00053 }
00054
00055
00056 ArchitectureStateList& archStateList = context->architectureStateList;
00057
00058 s64 totalInsnCount = 0;
00059 vector<s64> insnCount;
00060 insnCount.resize( processCount, 0 );
00061
00062 int curPID = 0;
00063 int terminateProcesses = 0;
00064 vector<u64> opID( processCount );
00065
00066 while( totalInsnCount < context->executionInsns ){
00067
00068
00069 PC& curThreadPC = archStateList[curPID].pc;
00070
00071 if( curThreadPC.address == 0 ) {
00072 terminateProcesses++;
00073 if(terminateProcesses >= processCount){
00074 break;
00075 }
00076 else{
00077 continue;
00078 }
00079 }
00080
00081 ofstream& ofs = *ofsList[curPID];
00082 EmulationOp op( context->emulator->GetMemImage() );
00083
00084
00085 std::pair<OpInfo**, int> ops =
00086 context->emulator->GetOp( curThreadPC );
00087 OpInfo** opInfoArray = ops.first;
00088 int opCount = ops.second;
00089
00090
00091 for(int opIndex = 0; opIndex < opCount; opIndex ++){
00092 OpInfo* opInfo = opInfoArray[opIndex];
00093 op.SetPC( curThreadPC );
00094 op.SetTakenPC( Addr(curThreadPC.pid, curThreadPC.tid, curThreadPC.address+4) );
00095 op.SetOpInfo(opInfo);
00096 op.SetTaken(false);
00097
00098
00099 int srcCount = opInfo->GetSrcNum();
00100 for (int i = 0; i < srcCount; i ++) {
00101 op.SetSrc(i, archStateList[curPID].registerValue[ opInfo->GetSrcOperand(i) ] );
00102 }
00103
00104 context->emulator->Execute( &op, opInfo );
00105 context->emulator->Commit( &op, opInfo );
00106
00107
00108 int dstCount = opInfo->GetDstNum();
00109 for (int i = 0; i < dstCount; i ++) {
00110 archStateList[curPID].registerValue[ opInfo->GetDstOperand(i) ] = op.GetDst(i);
00111 }
00112
00113
00114 ofs << "ID: " << opID[curPID] << "\tPC: " << curThreadPC.pid << "/" << hex << curThreadPC.address << dec << "[" << opIndex << "]\t";
00115 for (int i = 0; i < opInfo->GetDstNum(); ++i) {
00116 ofs << "d" << i << ": " << opInfo->GetDstOperand(i) << "\t";
00117 }
00118 for (int i = opInfo->GetDstNum(); i < SimISAInfo::MAX_DST_REG_COUNT; ++i) {
00119 ofs << "d" << i << ": -1" << "\t";
00120 }
00121
00122 for (int i = 0; i < opInfo->GetSrcNum(); ++i) {
00123 ofs << "s" << i << ": " << opInfo->GetSrcOperand(i) << "\t";
00124 }
00125 for (int i = opInfo->GetSrcNum(); i < SimISAInfo::MAX_SRC_REG_COUNT; ++i) {
00126 ofs << "s" << i << ": -1" << "\t";
00127 }
00128
00129 ofs << "TPC: " << op.GetTakenPC().pid << "/" << hex << op.GetTakenPC().address << dec << "(" << ( op.GetTaken() ? "t" : "n" ) << ")\t";
00130
00131
00132 for (int i = 0; i < opInfo->GetDstNum(); ++i) {
00133 if( opInfo->GetDstOperand(i) != -1 ) {
00134 ofs << "r" << opInfo->GetDstOperand(i) << "= " << hex << op.GetDst(i) << dec << "\t";
00135 }else {
00136 ofs << "r_= 0\t" ;
00137 }
00138 }
00139 for (int i = opInfo->GetDstNum(); i < SimISAInfo::MAX_DST_REG_COUNT; ++i) {
00140 ofs << "r_= 0\t" ;
00141 }
00142
00143 for (int i = 0; i < opInfo->GetSrcNum(); ++i) {
00144 if( opInfo->GetSrcOperand(i) != -1 ) {
00145 ofs << "r" << opInfo->GetSrcOperand(i) << "= " << hex << op.GetSrc(i) << dec << "\t";
00146 }else {
00147 ofs << "r_= 0\t" ;
00148 }
00149 }
00150 for (int i = opInfo->GetSrcNum(); i < SimISAInfo::MAX_SRC_REG_COUNT; ++i) {
00151 ofs << "r_= 0\t" ;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 ofs << endl;
00161 ++opID[curPID];
00162 }
00163
00164
00165 if (op.GetTaken())
00166 curThreadPC = op.GetTakenPC();
00167 else
00168 curThreadPC.address += SimISAInfo::INSTRUCTION_WORD_BYTE_SIZE;
00169
00170 totalInsnCount++;
00171 insnCount[ curPID ]++;
00172 curPID = (curPID + 1) % processCount;
00173 }
00174
00175 for( int pid = 0; pid < processCount; pid++ ){
00176 ofsList[pid]->close();
00177 delete ofsList[pid];
00178 }
00179
00180 context->executedInsns = insnCount;
00181 context->executedCycles = 0;
00182 }
00183