ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Logger.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
8#include <cstring>
9#include <iomanip>
10
11namespace etiss
12{
13
14namespace plugin
15{
16
17etiss_int32 log(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
18{
19 auto customH = (Logger::CustomHandle *)handle;
20 if ((addr & customH->mask) != customH->addr)
21 {
22 return customH->origSys->dwrite(customH->origSys->handle, cpu, addr, buf, len);
23 }
24
25 if (len <= 0)
26 return 0;
27
28 if (buf == 0)
29 return 0;
30
31 if (len == 1)
32 std::cout << (char)buf[0];
33 else
34 {
35 // print as different types
36 int iout = 0;
37 int fbuf = 0;
38 std::cout << " <char> ";
39 for (unsigned i = 0; i < len; i++)
40 {
41 iout |= buf[i] << (len - i - 1) * 8;
42 fbuf |= buf[i] << (len - i - 1) * 8;
43 bool isChar = (buf[i] > 32 && buf[i] < 127);
44 if (buf[i] == '\n')
45 std::cout << "\\n";
46 else
47 std::cout << (isChar ? std::string("\033[1;31m") : std::string("")) << std::setw(2) << (char)buf[i]
48 << (isChar ? std::string("\033[0m") : std::string(""));
49 }
50 float *fout = reinterpret_cast<float *>(&fbuf);
51
52 std::cout << std::setfill('0') << std::hex << " | <hex> 0x" << std::setw(8) << iout << std::dec
53 << std::setfill(' ');
54 std::cout << " | <int> " << std::setw(10) << iout;
55 std::cout << " | <float> " << *fout;
56 std::cout << std::endl;
57 }
58
59 std::flush(std::cout);
60
61 return 0;
62}
63
64Logger::Logger(uint64_t addr_value, uint64_t addr_mask)
65{
66 customHandle_.addr = addr_value & addr_mask;
67 customHandle_.mask = addr_mask;
68 if (customHandle_.addr == 0 && customHandle_.mask == 0)
69 {
70 etiss::log(etiss::WARNING, "Logger instantiated with mask and address set to 0. this will redirect all "
71 "read/writes exclusively to this logger instance.");
72 }
73}
74
76{
77 customHandle_.origSys = origSystem;
78
79 ETISS_System wrapInfo = {};
80 wrapInfo.handle = &customHandle_;
81 wrapInfo.dwrite = &log;
82 return wrapInfo;
83}
84
85} // namespace plugin
86
87} // namespace etiss
static __inline__ uint64_t
Definition arm_cde.h:31
uint64_t etiss_uint64
Definition types.h:58
uint32_t etiss_uint32
Definition types.h:55
uint8_t etiss_uint8
Definition types.h:49
int32_t etiss_int32
Definition types.h:54
ETISS_System getWrapInfo(ETISS_System *origSystem) final
Defines which System functions to wrap.
Definition Logger.cpp:75
Logger(uint64_t addr_value, uint64_t addr_mask)
Definition Logger.cpp:64
CustomHandle customHandle_
Definition Logger.h:41
forwards: include/jit/*
Definition Benchmark.h:17
@ WARNING
Definition Misc.h:86
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
memory access and time synchronization functions.
Definition System.h:40
etiss_int32(* dwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write data
Definition System.h:59
void * handle
custom handle that will be passed to the functions of this structure
Definition System.h:78
#define log(__x)
Definition tgmath.h:460