src/Sim/System/EmulationTraceSystem/EmulationTraceSystem.cpp

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
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     // WX^
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         // Decide a thread executed in this iteration.
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         // PC
00085         std::pair<OpInfo**, int> ops = 
00086             context->emulator->GetOp( curThreadPC );
00087         OpInfo** opInfoArray = ops.first;
00088         int opCount          = ops.second;
00089 
00090         // opInfoArray Sタs
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             // \[XIyh
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             // o
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             ofs << "Mem: " << hex << op.GetMemAccess().address.address << dec << "/"
00156             << op.GetMemAccess().size << "/"
00157             << (op.GetMemAccess().sign ? "s" : "u") << "/"
00158             << op.GetMemAccess().value;
00159             */
00160             ofs << endl;
00161             ++opID[curPID];
00162         }
00163 
00164         // PC
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;   // Round robin
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 

Onikiri2に対してTue Jun 18 14:34:26 2013に生成されました。  doxygen 1.4.7