ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
TracePrinter.h
Go to the documentation of this file.
1 /*
2 
3  @copyright
4 
5  <pre>
6 
7  Copyright 2018 Infineon Technologies AG
8 
9  This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10 
11  The initial version of this software has been created with the funding support by the German Federal
12  Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13 
14  Redistribution and use in source and binary forms, with or without modification, are permitted
15  provided that the following conditions are met:
16 
17  1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18  the following disclaimer.
19 
20  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21  and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24  or promote products derived from this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE.
34 
35  </pre>
36 
37  @author Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
43 #include <fstream>
44 #include <iostream>
45 
46 #include "etiss/ETISS.h"
47 
61 {
62  public:
63  // ctor
64  TracePrinter(etiss::uint32 terminateAddr, bool printOnScreen = false, char terminateHit = 1)
65  : CoroutinePlugin(), printOnScreen_(printOnScreen), terminateAddr_(terminateAddr), terminateHit_(terminateHit)
66  {
67  }
68 
69  // dtor
71 
73  {
74  if (printOnScreen_)
75  std::cout << "[INFO] {TracePrinter} : PC = 0x" << std::hex << cpu_->instructionPointer << std::endl;
76 
77  pcTrace_ << "[INFO] {TracePrinter}: PC = 0x" << std::hex << cpu_->instructionPointer << std::endl;
78 
80  {
81  if (++hitTimes_ == terminateHit_)
82  {
83  printLog();
84  return etiss::RETURNCODE::CPUTERMINATED;
85  }
86  }
88  }
89  std::string _getPluginName() const { return std::string("TracePrinter"); }
90 
91  void init(ETISS_CPU *cpu, ETISS_System *system, etiss::CPUArch *arch)
92  {
93  this->cpu_ = cpu;
94  this->system_ = system;
95  this->arch_ = arch;
96  }
97 
98  void cleanup()
99  {
100  cpu_ = nullptr;
101  system_ = nullptr;
102  arch_ = nullptr;
103  }
104 
105  private:
109 
110  std::stringstream pcTrace_;
111  char hitTimes_ = 0;
114  const char terminateHit_;
115 
116  void printLog()
117  {
118  std::ofstream outPcTrace;
119  outPcTrace.open("Trace.log");
120  outPcTrace << pcTrace_.str();
121  outPcTrace.close();
122  }
123 };
etiss_int32 int32
Definition: 386-GCC.h:81
etiss_uint32 uint32
Definition: 386-GCC.h:80
Header file of the ETISS library.
A simple logger dedicated to print PC trace.
Definition: TracePrinter.h:61
ETISS_CPU * cpu_
Definition: TracePrinter.h:106
void cleanup()
this function is called after cpu execution loop (etiss::CPUCore::execute) finished.
Definition: TracePrinter.h:98
ETISS_System * system_
Definition: TracePrinter.h:107
const char terminateHit_
Definition: TracePrinter.h:114
void printLog()
Definition: TracePrinter.h:116
bool printOnScreen_
Definition: TracePrinter.h:112
etiss::int32 execute()
called before a block and may act in the same way as a block
Definition: TracePrinter.h:72
void init(ETISS_CPU *cpu, ETISS_System *system, etiss::CPUArch *arch)
this function is called before the plugin is used in the cpu execution loop (etiss::CPUCore::execute)...
Definition: TracePrinter.h:91
etiss::CPUArch * arch_
Definition: TracePrinter.h:108
std::stringstream pcTrace_
Definition: TracePrinter.h:110
const etiss::uint32 terminateAddr_
Definition: TracePrinter.h:113
std::string _getPluginName() const
Definition: TracePrinter.h:89
TracePrinter(etiss::uint32 terminateAddr, bool printOnScreen=false, char terminateHit=1)
Definition: TracePrinter.h:64
the interface to translate instructions of and processor architecture
Definition: CPUArch.h:162
this plugin will be called before a block is executed.
Definition: Plugin.h:299
MM_EXPORT const int32_t NOERROR
basic cpu state structure needed for execution of any cpu architecture.
Definition: CPU.h:89
etiss_uint64 instructionPointer
pointer to next instruction.
Definition: CPU.h:92
memory access and time synchronization functions.
Definition: System.h:78