ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Logger.cpp
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 
44 #include <cstring>
45 #include <iomanip>
46 
47 namespace etiss
48 {
49 
50 namespace plugin
51 {
52 
53 etiss_int32 log(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
54 {
55  auto customH = (Logger::CustomHandle *)handle;
56  if ((addr & customH->mask) != customH->addr)
57  {
58  return customH->origSys->dwrite(customH->origSys->handle, cpu, addr, buf, len);
59  }
60 
61  if (len <= 0)
62  return 0;
63 
64  if (buf == 0)
65  return 0;
66 
67  if (len == 1)
68  std::cout << (char)buf[0];
69  else
70  {
71  // print as different types
72  int iout = 0;
73  int fbuf = 0;
74  std::cout << " <char> ";
75  for (unsigned i = 0; i < len; i++)
76  {
77  iout |= buf[i] << (len - i - 1) * 8;
78  fbuf |= buf[i] << (len - i - 1) * 8;
79  bool isChar = (buf[i] > 32 && buf[i] < 127);
80  if (buf[i] == '\n')
81  std::cout << "\\n";
82  else
83  std::cout << (isChar ? std::string("\033[1;31m") : std::string("")) << std::setw(2) << (char)buf[i]
84  << (isChar ? std::string("\033[0m") : std::string(""));
85  }
86  float *fout = reinterpret_cast<float *>(&fbuf);
87 
88  std::cout << std::setfill('0') << std::hex << " | <hex> 0x" << std::setw(8) << iout << std::dec
89  << std::setfill(' ');
90  std::cout << " | <int> " << std::setw(10) << iout;
91  std::cout << " | <float> " << *fout;
92  std::cout << std::endl;
93  }
94 
95  std::flush(std::cout);
96 
97  return 0;
98 }
99 
100 Logger::Logger(uint64_t addr_value, uint64_t addr_mask)
101 {
102  customHandle_.addr = addr_value & addr_mask;
103  customHandle_.mask = addr_mask;
104  if (customHandle_.addr == 0 && customHandle_.mask == 0)
105  {
106  etiss::log(etiss::WARNING, "Logger instantiated with mask and address set to 0. this will redirect all "
107  "read/writes exclusively to this logger instance.");
108  }
109 }
110 
112 {
113  customHandle_.origSys = origSystem;
114 
115  ETISS_System wrapInfo = {};
116  wrapInfo.handle = &customHandle_;
117  wrapInfo.dwrite = &log;
118  return wrapInfo;
119 }
120 
121 } // namespace plugin
122 
123 } // namespace etiss
static __inline__ uint64_t
Definition: arm_cde.h:31
uint64_t etiss_uint64
Definition: types.h:96
uint32_t etiss_uint32
Definition: types.h:93
uint8_t etiss_uint8
Definition: types.h:87
int32_t etiss_int32
Definition: types.h:92
ETISS_System getWrapInfo(ETISS_System *origSystem) final
Defines which System functions to wrap.
Definition: Logger.cpp:111
Logger(uint64_t addr_value, uint64_t addr_mask)
Definition: Logger.cpp:100
CustomHandle customHandle_
Definition: Logger.h:77
etiss_int32 log(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
Definition: Logger.cpp:53
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ WARNING
Definition: Misc.h:128
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125
basic cpu state structure needed for execution of any cpu architecture.
Definition: CPU.h:89
memory access and time synchronization functions.
Definition: System.h:78
etiss_int32(* dwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write data
Definition: System.h:97
void * handle
custom handle that will be passed to the functions of this structure
Definition: System.h:116