src/Sim/System/EmulationDebugSystem/EmulationDebugSystem.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/EmulationDebugSystem/EmulationDebugSystem.h"
00035 #include "Sim/System/EmulationDebugSystem/EmulationDebugOp.h"
00036 #include "Sim/System/EmulationDebugSystem/DebugStub/DebugStub.h"
00037 #include "Interface/EmulatorIF.h"
00038 
00039 using namespace std;
00040 using namespace boost;
00041 using namespace Onikiri;
00042 
00043 
00044 void EmulationDebugSystem::Run( SystemContext* context )
00045 {
00046     int processCount = context->emulator->GetProcessCount();
00047     if( processCount != 1 ){
00048         THROW_RUNTIME_ERROR( 
00049             "Remote debugging is not supported in the execution of multi processes." 
00050         );
00051     }
00052 
00053     // WX^
00054     ArchitectureStateList& archStateList = context->architectureStateList;
00055 
00056     s64 insnCount = 0;
00057     int curPID = 0;
00058     int terminateProcesses = 0;
00059     vector<u64> opID( processCount );
00060 
00061     m_debugStub = new DebugStub(context, curPID);
00062 
00063     while( insnCount < context->executionInsns ){
00064 
00065         // Decide a thread executed in this iteration.
00066         PC& curThreadPC = archStateList[curPID].pc;
00067 
00068         if( curThreadPC.address == 0 ) {
00069             terminateProcesses++;
00070             if(terminateProcesses >= processCount){
00071                 break;
00072             }
00073             else{
00074                 continue;
00075             }
00076         }
00077 
00078         EmulationDebugOp op( context->emulator->GetMemImage() );
00079 
00080         // PC
00081         std::pair<OpInfo**, int> ops = 
00082             context->emulator->GetOp( curThreadPC );
00083         OpInfo** opInfoArray = ops.first;
00084         int opCount          = ops.second;
00085 
00086         // opInfoArray Sタs
00087         for(int opIndex = 0; opIndex < opCount; opIndex ++){
00088             OpInfo* opInfo = opInfoArray[opIndex];
00089             op.SetPC( curThreadPC );
00090             op.SetTakenPC( Addr(curThreadPC.pid, curThreadPC.tid, curThreadPC.address+4) );
00091             op.SetOpInfo(opInfo);
00092             op.SetTaken(false);
00093 
00094             // \[XIyh
00095             int srcCount = opInfo->GetSrcNum();
00096             for (int i = 0; i < srcCount; i ++) {
00097                 op.SetSrc(i, archStateList[curPID].registerValue[ opInfo->GetSrcOperand(i) ] );
00098             }
00099 
00100             context->emulator->Execute( &op, opInfo );
00101 
00102             // 
00103             int dstCount = opInfo->GetDstNum();
00104             for (int i = 0; i < dstCount; i ++) {
00105                 archStateList[curPID].registerValue[ opInfo->GetDstOperand(i) ] = op.GetDst(i);
00106             }
00107 
00108             ++opID[curPID];
00109         }
00110 
00111         // PC
00112         if (op.GetTaken())
00113             curThreadPC = op.GetTakenPC();
00114         else
00115             curThreadPC.address += SimISAInfo::INSTRUCTION_WORD_BYTE_SIZE;
00116 
00117         insnCount ++;
00118         curPID = (curPID + 1) % processCount;   // Round robin
00119         m_debugStub->OnExec(&op);
00120 
00121     }
00122     
00123     delete m_debugStub;
00124 
00125     context->executedInsns.clear();
00126     context->executedInsns.push_back( insnCount );
00127     context->executedCycles = insnCount;
00128 }
00129 

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