OpenASIP 2.2
Loading...
Searching...
No Matches
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"
37#include "MemorySystem.hh"
39
46
49
50
51void
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 */
80bool
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}
UInt32 InstructionAddress
Definition BaseType.hh:175
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
find Finds info of the inner loops in the false
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
std::string errorMessage() const
Definition Exception.cc:123
bool isExitPoint() const
virtual void endClock()
Definition FUState.cc:122
bool isIdle()
virtual void advanceClock()
Definition GCUState.cc:98
InstructionAddress & programCounter()
void handleEvent(int event)
ExecutableInstruction & instructionAt(InstructionAddress address)
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
bool hasInstructionAt(InstructionAddress addr) const
bool hasImplicitInstructionsAt(InstructionAddress addr) const
void endClockOfAllFUStates()
void advanceClockOfAllFUStates()
void advanceClockOfAllGuardStates()
void clearBuses()
GCUState & gcuState()
void setFinished(bool finished=true)
void advanceClockOfSharedMemories()
void advanceClockOfLocalMemories()
OTASimulationController(SimulatorFrontend &frontend, const TTAMachine::Machine &machine, const TTAProgram::Program &program)
void advanceMachineCycle(unsigned pcAdd)
MachineStateContainer machineStates_
The machine state models for the simulated cores.
std::vector< InstructionMemory * > instructionMemories_
The instruction memory models of cores.
virtual MachineState & machineState(int core=-1)
@ SE_NEW_INSTRUCTION
Generated before executing a new instructon.
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
SimulationEventHandler & eventHandler()
void reportSimulatedProgramError(RuntimeErrorSeverity severity, const std::string &description)
@ RES_FATAL
Fatal runtime error, there is a serious error in the simulated program, thus it makes no sense to go ...
MemorySystem & memorySystem(int coreId=-1)
std::vector< InstructionAddress > lastExecutedInstruction_
The address of the last executed instruction.
bool stopRequested_
Flag indicating that simulation should stop.
virtual void prepareToStop(StopReason reason)
@ STA_FINISHED
Simulation ended after executing the last instruction.
InstructionAddress firstIllegalInstructionIndex_
The index of the first illegal instruction in the instruction sequence.
SimulationStatus state_
The current state of the simulation.
ClockCycleCount clockCount_
How many clock cycles have been simulated.
SimulatorFrontend & frontend_
Reference to the simulator frontend.
virtual MemorySystem & memorySystem(int coreId=-1)