OpenASIP  2.0
OTASimulationController.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2016 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file OTASimulationController.cc
26  *
27  * @author Pekka Jääskeläinen 2016 (pjaaskel-no.spam-cs.tut.fi)
28  * @note rating: red
29  */
30 
32 #include "Machine.hh"
33 #include "MachineState.hh"
34 #include "SimulatorFrontend.hh"
35 #include "InstructionMemory.hh"
36 #include "ExecutableInstruction.hh"
37 #include "MemorySystem.hh"
39 
41  SimulatorFrontend& frontend,
45 }
46 
48 }
49 
50 
51 void
53 
54  const unsigned int core = 0;
56  //InstructionMemory& imem = *instructionMemories_[core];
59 
61 
62  if (!gcu.isIdle()) {
63  gcu.endClock();
64  }
65 
69 
70  gcu.programCounter() += pcAdd;
71  if (!gcu.isIdle())
72  gcu.advanceClock();
73 
75 }
76 
77 /**
78  * Simulates an instruction cycle, both its explicit and implicit instructions.
79  */
80 bool
82 
83  std::vector<InstructionAddress> lastExecutedInstructions =
85 
86  bool finished = false;
87 
88  int finishedCoreCount = 0;
89 
90  const unsigned int core = 0;
94  const InstructionAddress pc = gcu.programCounter();
95 
96  try {
98 
99  bool exitPoint = false;
100  if (imem.hasInstructionAt(pc)) {
101  ExecutableInstruction& instruction = imem.instructionAt(pc);
102  instruction.execute();
103 
104  lastExecutedInstructions[core] = pc;
105 
107 
108  if (imem.hasImplicitInstructionsAt(pc)) {
109  const auto& implInstructions = imem.implicitInstructionsAt(pc);
110  for (size_t i = 0; i < implInstructions.size(); ++i) {
111  ExecutableInstruction& implInstruction =
112  *implInstructions.at(i);
113  implInstruction.execute();
114  exitPoint |= implInstruction.isExitPoint();
116  }
117  }
118 
119  exitPoint |= instruction.isExitPoint();
120  }
121 
122  // check if the instruction was a return point from the program or
123  // the next executed instruction would be sequentially over the
124  // instruction space (PC+1 would overflow out of the program)
125  if (exitPoint ||
128  ++finishedCoreCount;
129  }
130  } catch (const Exception& e) {
133  e.errorMessage());
135  return false;
136  }
137 
138  if (finishedCoreCount > 0)
139  finished = true;
140 
142 
143  lastExecutedInstruction_ = lastExecutedInstructions;
144 
145  // this is the instruction count in case of OTA
146  ++clockCount_;
147 
148  if (finished) {
150  stopRequested_ = true;
151  return false;
152  }
153 
156  return true;
157 }
TTASimulationController::memorySystem
virtual MemorySystem & memorySystem(int coreId=-1)
Definition: TTASimulationController.cc:171
TTAProgram::Program
Definition: Program.hh:63
ExecutableInstruction
Definition: ExecutableInstruction.hh:49
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
InstructionMemory::hasInstructionAt
bool hasInstructionAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:117
ExecutableInstruction::execute
void execute()
GCUState
Definition: GCUState.hh:46
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
FUState::endClock
virtual void endClock()
Definition: FUState.cc:122
InstructionMemory::implicitInstructionsAt
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:128
MachineState::gcuState
GCUState & gcuState()
Definition: MachineState.cc:103
MachineState::clearBuses
void clearBuses()
InstructionMemory.hh
GCUState::programCounter
InstructionAddress & programCounter()
MachineState::setFinished
void setFinished(bool finished=true)
Definition: MachineState.hh:106
TTASimulationController::prepareToStop
virtual void prepareToStop(StopReason reason)
Definition: TTASimulationController.cc:90
MachineState::endClockOfAllFUStates
void endClockOfAllFUStates()
MemorySystem.hh
InstructionMemory
Definition: InstructionMemory.hh:54
MemorySystem::advanceClockOfLocalMemories
void advanceClockOfLocalMemories()
MachineState::advanceClockOfAllFUStates
void advanceClockOfAllFUStates()
TTASimulationController::state_
SimulationStatus state_
The current state of the simulation.
Definition: TTASimulationController.hh:147
SimulationEventHandler.hh
TTASimulationController::frontend_
SimulatorFrontend & frontend_
Reference to the simulator frontend.
Definition: TTASimulationController.hh:135
SimulationController::instructionMemories_
std::vector< InstructionMemory * > instructionMemories_
The instruction memory models of cores.
Definition: SimulationController.hh:92
MachineState
Definition: MachineState.hh:61
MemorySystem::advanceClockOfSharedMemories
void advanceClockOfSharedMemories()
TTASimulationController::STA_FINISHED
@ STA_FINISHED
Simulation ended after executing the last instruction.
Definition: TTASimulationController.hh:77
InstructionMemory::instructionAt
ExecutableInstruction & instructionAt(InstructionAddress address)
SimulationEventHandler::SE_CYCLE_END
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
Definition: SimulationEventHandler.hh:50
TTASimulationController::lastExecutedInstruction_
std::vector< InstructionAddress > lastExecutedInstruction_
The address of the last executed instruction.
Definition: TTASimulationController.hh:151
TTASimulationController::stopRequested_
bool stopRequested_
Flag indicating that simulation should stop.
Definition: TTASimulationController.hh:142
OTASimulationController::OTASimulationController
OTASimulationController(SimulatorFrontend &frontend, const TTAMachine::Machine &machine, const TTAProgram::Program &program)
Definition: OTASimulationController.cc:40
SRE_RUNTIME_ERROR
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
Definition: SimulatorConstants.hh:68
SimulatorFrontend::RES_FATAL
@ RES_FATAL
Fatal runtime error, there is a serious error in the simulated program, thus it makes no sense to go ...
Definition: SimulatorFrontend.hh:95
FUState::isIdle
bool isIdle()
Machine.hh
Exception
Definition: Exception.hh:54
GCUState::advanceClock
virtual void advanceClock()
Definition: GCUState.cc:98
OTASimulationController.hh
MemorySystem
Definition: MemorySystem.hh:55
ExecutableInstruction::isExitPoint
bool isExitPoint() const
SimulatorFrontend.hh
OTASimulationController::advanceMachineCycle
void advanceMachineCycle(unsigned pcAdd)
Definition: OTASimulationController.cc:52
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTASimulationController::clockCount_
ClockCycleCount clockCount_
How many clock cycles have been simulated.
Definition: TTASimulationController.hh:149
InstructionMemory::hasImplicitInstructionsAt
bool hasImplicitInstructionsAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:123
OTASimulationController::~OTASimulationController
virtual ~OTASimulationController()
Definition: OTASimulationController.cc:47
TTASimulationController::firstIllegalInstructionIndex_
InstructionAddress firstIllegalInstructionIndex_
The index of the first illegal instruction in the instruction sequence.
Definition: TTASimulationController.hh:158
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
MachineState.hh
ExecutableInstruction.hh
SimulationController::machineStates_
MachineStateContainer machineStates_
The machine state models for the simulated cores.
Definition: SimulationController.hh:90
SimulationController
Definition: SimulationController.hh:46
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
Informer::handleEvent
void handleEvent(int event)
SimulationController::machineState
virtual MachineState & machineState(int core=-1)
Definition: SimulationController.cc:145
SimulatorFrontend::reportSimulatedProgramError
void reportSimulatedProgramError(RuntimeErrorSeverity severity, const std::string &description)
Definition: SimulatorFrontend.cc:2304
MachineState::advanceClockOfAllGuardStates
void advanceClockOfAllGuardStates()
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
OTASimulationController::simulateCycle
virtual bool simulateCycle()
Definition: OTASimulationController.cc:81
TTAMachine::Machine
Definition: Machine.hh:73
SimulationEventHandler::SE_NEW_INSTRUCTION
@ SE_NEW_INSTRUCTION
Generated before executing a new instructon.
Definition: SimulationEventHandler.hh:48