OpenASIP 2.2
Loading...
Searching...
No Matches
SimulatorFrontend.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2010 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 SimulatorFrontend.hh
26 *
27 * Declaration of SimulatorFrontend class
28 *
29 * @author Pekka Jääskeläinen 2005-2010 (pjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#ifndef TTA_SIMULATOR_FRONTEND
34#define TTA_SIMULATOR_FRONTEND
35
36#include <fstream>
37#include <string>
38#include <iostream>
39#include <ostream>
40#include <ctime>
41
42#include <set>
43
44#include "Exception.hh"
46#include "RemoteController.hh"
47#include "SimulatorConstants.hh"
48#include "BaseType.hh"
49#include "CallPathTracker.hh"
50
51class SimValue;
52class StateData;
53class MachineState;
54class POMDisassembler;
56class ExecutionTrace;
58class MemorySystem;
60class RFAccessTracker;
61class BusTracker;
65namespace TPEF {
66 class Binary;
67}
68
69namespace TTAProgram {
70 class Program;
71 class Procedure;
72}
73
74namespace TTAMachine {
75 class AddressSpace;
76}
77
78/**
79 * Frontend to simulator functionality.
80 *
81 * User interfaces use this class as the access point to simulation
82 * functionality. It acts as a "facade" hiding the complexity of simulator
83 * engine. Error messages of exceptions thrown by the methods of this
84 * class are generated using SimulatorTextGenerator, thus they can be used
85 * in user interfaces directly.
86 *
87 */
89public:
90
91 /// The severities of runtime errors.
92 typedef enum {
93 RES_MINOR, ///< Minor runtime error, no abort necessary.
94 RES_FATAL ///< Fatal runtime error, there is a serious error in the
95 /// simulated program, thus it makes no sense to go on
96 /// with the simulation.
98
99 /// Which type of simulation this SimulatorFrontend controls or connects to.
100 typedef enum {
101 SIM_NORMAL, ///< Default, interpreted simulation (debugging engine).
102 SIM_COMPILED, ///< Compiled, faster simulation.
103 SIM_REMOTE, ///< Remote debugger, not a simulator at all
104 SIM_CUSTOM, ///< User-implemented remote HW debugger
105 SIM_OTA ///< Simulation with operation-triggered implicit data
106 /// transports.
108
110 virtual ~SimulatorFrontend();
111
112 virtual void loadProgram(const std::string& fileName);
113
114 virtual void loadMachine(const std::string& fileName);
115
117
119
120 void loadProcessorConfiguration(const std::string& fileName);
121
122 const TTAMachine::Machine& machine() const;
123 const TTAProgram::Program& program() const;
124
125 const SimValue& stateValue(std::string searchString);
126
127 StateData& state(std::string searchString);
128
129 MachineState& machineState(int core=-1);
130
131 virtual void next(int count = 1);
132 virtual void step(double count = 1);
133 virtual void run();
134
135 virtual void runUntil(UIntWord address);
136
137 void prepareToStop(StopReason reason);
138 unsigned int stopReasonCount() const;
139 StopReason stopReason(unsigned int index) const;
140 bool stoppedByUser() const;
141 virtual void killSimulation();
142
144 MemorySystem& memorySystem(int coreId=-1);
145
146 bool isSimulationInitialized() const;
147 bool isSimulationRunning() const;
148 bool isSimulationStopped() const;
149 bool isProgramLoaded() const;
150 bool isMachineLoaded() const;
151 bool hasSimulationEnded() const;
152
153 bool isCompiledSimulation() const;
154 bool isTCEDebugger() const;
155 bool isCustomDebugger() const;
157 leaveCompiledDirty_ = dirty;
158 }
159
160 bool executionTracing() const;
161 bool busTracing() const;
162 bool rfAccessTracing() const;
163 bool procedureTransferTracing() const;
164 bool profileDataSaving() const;
165 bool utilizationDataSaving() const;
166 bool staticCompilation() const;
167
168 const RFAccessTracker& rfAccessTracker() const;
169
170 void setCompiledSimulation(bool value);
171 void setExecutionTracing(bool value);
172 void setBusTracing(bool value);
173 void setRFAccessTracing(bool value);
174 void setProcedureTransferTracing(bool value);
175 void setProfileDataSaving(bool value);
176 void setUtilizationDataSaving(bool value);
177 void forceTraceDBFileName(const std::string& fileName) {
178 forcedTraceDBFileName_ = fileName;
179 }
180 void setTimeout(unsigned int value);
181 void setStaticCompilation(bool value);
182
183 std::ostream& outputStream();
184 void setOutputStream(std::ostream& stream);
185
186 std::string disassembleInstruction(UIntWord instructionAddress) const;
187
188 std::string programLocationDescription() const;
190 virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const;
193
194 virtual std::string registerFileValue(
195 const std::string& rfName,
196 int registerIndex = -1);
197
199 const std::string& iuName,
200 int index = -1);
201
202 virtual SimValue FUPortValue(
203 const std::string& fuName,
204 const std::string& portName);
205
206 StateData& findRegister(const std::string& rfName, int registerIndex);
207
209
210 StateData& findPort(const std::string& fuName, const std::string& portName);
211
212 const UtilizationStats& utilizationStatistics(int core=-1);
215 InstructionAddress address) const;
216
217 bool automaticFinishImpossible() const;
218
219 void setFUResourceConflictDetection(bool value);
220 bool fuResourceConflictDetection() const;
221
222 void setNextInstructionPrinting(bool value);
223 bool nextInstructionPrinting() const;
224
225 void setSimulationTimeStatistics(bool value);
226 bool simulationTimeStatistics() const;
227
228 ExecutionTrace* lastTraceDB(int core=-1);
229
230 void setMemoryAccessTracking(bool value);
231 bool memoryAccessTracking() const;
232 void finishSimulation();
233
236
237 void setDetailedSimulation(bool val)
238 { detailedSimulation_ = val; }
239
241
243
244 double lastRunTime() const;
245
247 RuntimeErrorSeverity severity, const std::string& description);
248 std::string programErrorReport(
249 RuntimeErrorSeverity severity, std::size_t index);
250 std::size_t programErrorReportCount(
251 RuntimeErrorSeverity severity);
253
254 friend void timeoutThread(unsigned int timeout, SimulatorFrontend* simFE);
255
256 int selectedCore() const {
257 return 0;
258 }
259 void selectCore(int core) {
260 if (core != 0) {
261 abortWithError("WiP.");
262 }
263 }
264 bool compareState(SimulatorFrontend& other, std::ostream* differences=NULL);
265
266 std::size_t callHistoryLength() const { return callHistoryLength_; }
267 void setCallHistoryLength(std::size_t length);
268 const CallPathTracker& callPathTracker(int core=-1) const;
269 void initializeDataMemories(const TTAMachine::AddressSpace* onlyOne=NULL);
270
271protected:
272 virtual void initializeSimulation();
273
274 void initializeTracing();
275 void initializeDisassembler() const;
278 bool hasStopReason(StopReason reason) const;
279
280 void startTimer();
281 void stopTimer();
282
284
285 /// A type for storing a program error description.
286 typedef std::pair<RuntimeErrorSeverity, std::string>
288 /// Container for simulated program error descriptions.
289 typedef std::vector<ProgramErrorDescription> ProgramErrorDescriptionList;
290
291 /// Machine to run simulation with.
293 /// If simulation is initialized, this contains a pointer to the
294 /// simulation controller.
296 /// Is the machine owned by SimulatorFrontend or by the client?
298 /// Program to be simulated.
300 /// The source file of the program to be simulated. Used to generate
301 /// the file name of the trace data base.
302 std::string programFileName_;
303 /// Is the program owned by SimulatorFrontend or by the client?
305 /// Type of "backend" this Frontend has
307 /// The disassembler used to print out instructions. This is
308 /// initialized on demand.
310 /// Is execution tracing, i.e., storing the executed instruction
311 /// addresses to the trace database, enabled.
313 /// Is bus tracing, i.e., storing the values of buses in each
314 /// clock cycle enabled.
316 /// Is register file (concurrent) access tracking enabled.
318 /// Is procedure transfer access tracking enabled.
320 /// Is saving of profile data to TraceDB enabled.
322 /// Is saving of utilization data to TraceDB enabled.
324 /// The database to use for execution trace data.
325 std::vector<ExecutionTrace*> traceDBs_;
326 /// Whether traceDB at index is owned by simulator
327 /// (or taken away by client using lastTraceDB())
328 std::vector<bool> traceDBOwned_;
329
330 /// The simple execution tracker for storing trace of executed
331 /// instructions.
332 std::vector<ExecutionTracker*> executionTrackers_;
333
334 /// The tracker for saving bus trace.
335 std::vector<BusTracker*> busTrackers_;
336
337 /// The register file access tracker.
338 std::vector<RFAccessTracker*> rfAccessTrackers_;
339
340 /// The procedure transfer tracker.
341 std::vector<ProcedureTransferTracker*> procedureTransferTrackers_;
342
343 /// The breakpoint manager to be used to bookkeep breakpoints.
345
346 /// Processor utilization statistics.
347 std::vector<UtilizationStats*> utilizationStats_;
348
349 /// The source TPEF file.
351 /// If this is enabled before initialization, FU resource conflicts are
352 /// detected (slows down simulation).
354 /// If true, the next simulated instructions is printed to stdout when
355 /// simulation stops.
357 /// True if the simulation time statistics should be printed out
359 /// True if the compiled simulation should use static compilation
361 /// Flag that indicates is the trace file name set by user.
363 /// Default output stream
364 std::ostream* outputStream_;
365
366 /// If this is enabled before initialization, memory access tracking is
367 /// enabled. (slows down simulation)
369 /// Per simulation instance of SimulationEventHandler.
371 /// The cycle count of the last non-interrupted simulation phase.
373 /// The wall clock time of the last non-interrupted simulation phase in
374 /// seconds.
376 /// The time of the last simulation start. Used to compute simulation speed.
377 std::time_t startTime_;
378 /// The cycle count when the latest simulation was started. Used to
379 /// compute simulation speed.
381 /// Simulation timeout in seconds
382 unsigned int simulationTimeout_;
383 /// Runtime error reports.
385 /// True in case the compilation simulation should not cleanup at
386 /// destruction the engine source files.
388 /// The length of call history to store in memory for the commands that
389 /// need it.
391 /// The call path trackers for each core, in case tracking is enabled.
392 std::vector<CallPathTracker*> callPathTrackers_;
393 /// If set, forces the SQLite filename of trace DB to this name.
395 /// The simulation models of the memories in the currently loaded machine
396 /// for each core.
397 std::vector<MemorySystem*> memorySystems_;
398 /// Set to true in case the memories should be set to zero at reset.
400 /// Set to true in case should build a detailed model which simulates
401 /// FU stages, possibly with an external system-level model.
403};
404#endif
#define abortWithError(message)
long long CycleCount
Type for storing simulation cycle counts.
Definition BaseType.hh:187
Word UIntWord
Definition BaseType.hh:144
UInt32 InstructionAddress
Definition BaseType.hh:175
CycleCount ClockCycleCount
Alias for ClockCycleCount.
StopReason
The reasons to stop simulation.
bool hasSimulationEnded() const
virtual void initializeSimulation()
void setFUResourceConflictDetection(bool value)
void initializeDataMemories(const TTAMachine::AddressSpace *onlyOne=NULL)
TTASimulationController * simCon_
If simulation is initialized, this contains a pointer to the simulation controller.
bool compareState(SimulatorFrontend &other, std::ostream *differences=NULL)
POMDisassembler * disassembler_
The disassembler used to print out instructions. This is initialized on demand.
const TTAProgram::Procedure & currentProcedure() const
bool simulationTimeStatistics() const
std::size_t callHistoryLength() const
SimulationEventHandler & eventHandler()
void setCallHistoryLength(std::size_t length)
bool automaticFinishImpossible() const
ExecutionTrace * lastTraceDB(int core=-1)
SimulationType
Which type of simulation this SimulatorFrontend controls or connects to.
@ SIM_REMOTE
Remote debugger, not a simulator at all.
@ SIM_CUSTOM
User-implemented remote HW debugger.
@ SIM_OTA
Simulation with operation-triggered implicit data transports.
@ SIM_COMPILED
Compiled, faster simulation.
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
std::vector< ProgramErrorDescription > ProgramErrorDescriptionList
Container for simulated program error descriptions.
bool saveUtilizationData_
Is saving of utilization data to TraceDB enabled.
std::ostream * outputStream_
Default output stream.
virtual void loadMachine(const std::string &fileName)
virtual void runUntil(UIntWord address)
bool traceFileNameSetByUser_
Flag that indicates is the trace file name set by user.
const TTAMachine::Machine & machine() const
const UtilizationStats & utilizationStatistics(int core=-1)
void setOutputStream(std::ostream &stream)
void setMemoryAccessTracking(bool value)
double lastRunTime() const
std::vector< MemorySystem * > memorySystems_
The simulation models of the memories in the currently loaded machine for each core.
void setSimulationTimeStatistics(bool value)
virtual std::string registerFileValue(const std::string &rfName, int registerIndex=-1)
std::vector< CallPathTracker * > callPathTrackers_
The call path trackers for each core, in case tracking is enabled.
bool busTracing_
Is bus tracing, i.e., storing the values of buses in each clock cycle enabled.
bool printNextInstruction_
If true, the next simulated instructions is printed to stdout when simulation stops.
bool isCustomDebugger() const
virtual SimValue immediateUnitRegisterValue(const std::string &iuName, int index=-1)
bool executionTracing_
Is execution tracing, i.e., storing the executed instruction addresses to the trace database,...
void setDetailedSimulation(bool val)
bool staticCompilation() const
ClockCycleCount cycleCount() const
bool memoryAccessTracking() const
bool utilizationDataSaving() const
CycleCount startCycleCount_
The cycle count when the latest simulation was started. Used to compute simulation speed.
void loadProcessorConfiguration(const std::string &fileName)
void setCompiledSimulation(bool value)
void setProfileDataSaving(bool value)
std::ostream & outputStream()
bool isSimulationInitialized() const
unsigned int stopReasonCount() const
void forceTraceDBFileName(const std::string &fileName)
void setNextInstructionPrinting(bool value)
const ExecutableInstruction & lastExecInstruction() const
bool programOwnedByFrontend_
Is the program owned by SimulatorFrontend or by the client?
SimulationType currentBackend_
Type of "backend" this Frontend has.
void reportSimulatedProgramError(RuntimeErrorSeverity severity, const std::string &description)
std::string disassembleInstruction(UIntWord instructionAddress) const
MachineState & machineState(int core=-1)
ProgramErrorDescriptionList programErrorReports_
Runtime error reports.
void setUtilizationDataSaving(bool value)
bool fuResourceConflictDetection() const
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
double lastRunTime_
The wall clock time of the last non-interrupted simulation phase in seconds.
StopReason stopReason(unsigned int index) const
bool procedureTransferTracing_
Is procedure transfer access tracking enabled.
bool isSimulationStopped() const
ClockCycleCount lastRunCycleCount_
The cycle count of the last non-interrupted simulation phase.
bool profileDataSaving() const
std::string programFileName_
The source file of the program to be simulated. Used to generate the file name of the trace data base...
friend void timeoutThread(unsigned int timeout, SimulatorFrontend *simFE)
std::vector< UtilizationStats * > utilizationStats_
Processor utilization statistics.
std::vector< ExecutionTrace * > traceDBs_
The database to use for execution trace data.
std::size_t programErrorReportCount(RuntimeErrorSeverity severity)
bool detailedSimulation_
Set to true in case should build a detailed model which simulates FU stages, possibly with an externa...
bool staticCompilation_
True if the compiled simulation should use static compilation.
void setControllerForMemories(RemoteController *con)
void initializeDisassembler() const
const TTAProgram::Program * currentProgram_
Program to be simulated.
const TTAMachine::Machine * currentMachine_
Machine to run simulation with.
const CallPathTracker & callPathTracker(int core=-1) const
bool saveProfileData_
Is saving of profile data to TraceDB enabled.
std::string forcedTraceDBFileName_
If set, forces the SQLite filename of trace DB to this name.
std::time_t startTime_
The time of the last simulation start. Used to compute simulation speed.
bool hasStopReason(StopReason reason) const
void setStaticCompilation(bool value)
void setRFAccessTracing(bool value)
void setBusTracing(bool value)
virtual void next(int count=1)
const TTAProgram::Program & program() const
TPEF::Binary * tpef_
The source TPEF file.
StopPointManager & stopPointManager()
const RFAccessTracker & rfAccessTracker() const
CycleCount lastRunCycleCount() const
void setTimeout(unsigned int value)
bool zeroFillMemoriesOnReset_
Set to true in case the memories should be set to zero at reset.
RuntimeErrorSeverity
The severities of runtime errors.
@ RES_FATAL
Fatal runtime error, there is a serious error in the simulated program, thus it makes no sense to go ...
@ RES_MINOR
Minor runtime error, no abort necessary.
StateData & findPort(const std::string &fuName, const std::string &portName)
bool memoryAccessTracking_
If this is enabled before initialization, memory access tracking is enabled. (slows down simulation)
bool executionTracing() const
StopPointManager * stopPointManager_
The breakpoint manager to be used to bookkeep breakpoints.
StateData & state(std::string searchString)
std::vector< bool > traceDBOwned_
Whether traceDB at index is owned by simulator (or taken away by client using lastTraceDB())
void setCompiledSimulationLeaveDirty(bool dirty)
std::string programLocationDescription() const
void selectCore(int core)
void setZeroFillMemoriesOnReset(bool val)
virtual void loadProgram(const std::string &fileName)
virtual void step(double count=1)
const ExecutableInstruction & executableInstructionAt(InstructionAddress address) const
bool isSimulationRunning() const
void setProcedureTransferTracing(bool value)
std::vector< BusTracker * > busTrackers_
The tracker for saving bus trace.
bool leaveCompiledDirty_
True in case the compilation simulation should not cleanup at destruction the engine source files.
virtual void killSimulation()
std::size_t callHistoryLength_
The length of call history to store in memory for the commands that need it.
bool procedureTransferTracing() const
StateData & findRegister(const std::string &rfName, int registerIndex)
bool machineOwnedByFrontend_
Is the machine owned by SimulatorFrontend or by the client?
std::vector< ProcedureTransferTracker * > procedureTransferTrackers_
The procedure transfer tracker.
StateData & findBooleanRegister()
const SimValue & stateValue(std::string searchString)
MemorySystem & memorySystem(int coreId=-1)
virtual SimValue FUPortValue(const std::string &fuName, const std::string &portName)
void setExecutionTracing(bool value)
std::vector< ExecutionTracker * > executionTrackers_
The simple execution tracker for storing trace of executed instructions.
SimulationEventHandler * eventHandler_
Per simulation instance of SimulationEventHandler.
bool printSimulationTimeStatistics_
True if the simulation time statistics should be printed out.
std::vector< RFAccessTracker * > rfAccessTrackers_
The register file access tracker.
bool fuResourceConflictDetection_
If this is enabled before initialization, FU resource conflicts are detected (slows down simulation).
InstructionAddress programCounter() const
bool nextInstructionPrinting() const
unsigned int simulationTimeout_
Simulation timeout in seconds.
bool isCompiledSimulation() const
std::string programErrorReport(RuntimeErrorSeverity severity, std::size_t index)
void prepareToStop(StopReason reason)
std::pair< RuntimeErrorSeverity, std::string > ProgramErrorDescription
A type for storing a program error description.
bool rfAccessTracing_
Is register file (concurrent) access tracking enabled.