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/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
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
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
00081 std::pair<OpInfo**, int> ops =
00082 context->emulator->GetOp( curThreadPC );
00083 OpInfo** opInfoArray = ops.first;
00084 int opCount = ops.second;
00085
00086
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
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
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;
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