ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Delegate.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 Marc Greim <marc.greim@mytum.de>, Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
44 
45 namespace etiss
46 {
47 namespace interfaces
48 {
49 
50 Delegate::Delegate(ETISS_System &system, ETISS_CPU &cpu) : system(system), cpu(cpu) {}
51 
53 {
54 #if DEBUG
55  if (time_ps < cpu.cpuTime_ps)
56  {
57  etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
58  }
59 #endif
60 
61  cpu.cpuTime_ps = time_ps;
62 
64 }
65 
66 etiss::int32 Delegate::read(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
67 {
68  // std::cout << "\nread "<<(ibus?"ibus":"dbus")<<" at address 0x" << std::hex << addr << std::dec << std::endl;
69 
70  if (injectedRead)
71  {
72  bool cont = false;
73  bool handleNormal = false;
74 
75  etiss::int32 ret = injectedRead(ibus, time_ps, addr, buf, len, cont, handleNormal);
76 
77  if (!cont)
78  injectedRead = nullptr;
79 
80  if (!handleNormal) // injectedRead may signal that read() should handle this call
81  {
82  if (unlikely(snoopRead))
83  {
84  snoopRead(true, time_ps, addr, buf, len);
85  }
86  return ret;
87  }
88  }
89 
90 #if DEBUG
91  if (time_ps < cpu.cpuTime_ps)
92  {
93  etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
94  }
95 #endif
96 
97  cpu.cpuTime_ps = time_ps;
99 
100  if (ibus)
101  {
102  code = system.iread(system.handle, &cpu, addr, len); // simulate read
103 
104  if ((code == etiss::RETURNCODE::NOERROR) || (code == etiss::RETURNCODE::GDBNOERROR)) // check return code
105  {
106  code = system.dbg_read(system.handle, addr, buf, len); // read data
107  }
108  }
109  else
110  {
111  code = system.dread(system.handle, &cpu, addr, buf, len); // read data
112  }
113 
114  time_ps = cpu.cpuTime_ps;
115 
116  if (unlikely(snoopRead))
117  {
118  snoopRead(false, time_ps, addr, buf, len);
119  }
120 
121  return code;
122 }
123 
124 etiss::int32 Delegate::write(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
125 {
126 
127  if (redirectedWrite)
128  {
129  bool cont = false;
130  bool handleNormal = false;
131 
132  etiss::int32 ret = redirectedWrite(ibus, time_ps, addr, buf, len, cont, handleNormal);
133 
134  if (!cont)
135  redirectedWrite = std::function<bool(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)>();
136 
137  if (!handleNormal) // redirectedWrite may signal that write() should handle this call
138  return ret;
139  }
140 
141 #if DEBUG
142  if (time_ps < cpu.cpuTime_ps)
143  {
144  etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
145  }
146 #endif
147 
148  cpu.cpuTime_ps = time_ps;
150 
151  if (ibus)
152  {
153  code = system.iwrite(system.handle, &cpu, addr, buf, len); // read data
154  }
155  else
156  {
157  code = system.dwrite(system.handle, &cpu, addr, buf, len); // read data
158  }
159 
160  time_ps = cpu.cpuTime_ps;
161 
162  return code;
163 }
164 
165 } // namespace interfaces
166 } // namespace etiss
etiss_int32 int32
Definition: 386-GCC.h:81
static __inline__ uint64_t
Definition: arm_cde.h:31
static __inline__ int32_t
Definition: arm_mve.h:51
static __inline__ uint8_t
Definition: arm_mve.h:323
#define unlikely(x)
Definition: types.h:74
std::function< etiss::int32(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)> injectedRead
if valid then this function will be called by read() instead of performing any action itself
Definition: Delegate.h:102
void syncTime(uint64_t time_ps)
Definition: Delegate.cpp:52
Delegate(ETISS_System &system, ETISS_CPU &cpu)
Definition: Delegate.cpp:50
etiss::int32 read(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles read operations.
Definition: Delegate.cpp:66
ETISS_System & system
Definition: Delegate.h:79
etiss::int32 write(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles write operations.
Definition: Delegate.cpp:124
std::function< etiss::int32(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)> redirectedWrite
Definition: Delegate.h:105
std::function< void(bool injected, const uint64_t &time_ps, uint64_t addr, const uint8_t *buf, unsigned len)> snoopRead
Definition: Delegate.h:108
MM_EXPORT const int32_t NOERROR
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ FATALERROR
Definition: Misc.h:126
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
etiss_uint64 cpuTime_ps
simulation time of cpu
Definition: CPU.h:97
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
etiss_int32(* iread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint32 length)
used to simulate an instruction fetch.
Definition: System.h:84
void * handle
custom handle that will be passed to the functions of this structure
Definition: System.h:116
etiss_int32(* dbg_read)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug read
Definition: System.h:104
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition: System.h:93
void(* syncTime)(void *handle, ETISS_CPU *cpu)
called after a block to synchronize the time
Definition: System.h:114
etiss_int32(* iwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write instruction data over instruction bus
Definition: System.h:88