ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Delegate.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 "etiss/jit/System.h"
9
10namespace etiss
11{
12namespace interfaces
13{
14
15Delegate::Delegate(ETISS_System &system, ETISS_CPU &cpu) : system(system), cpu(cpu) {}
16
18{
19#if DEBUG
20 if (time_ps < cpu.cpuTime_ps)
21 {
22 etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
23 }
24#endif
25
26 cpu.cpuTime_ps = time_ps;
27
29}
30
31etiss::int32 Delegate::read(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
32{
33 // std::cout << "\nread "<<(ibus?"ibus":"dbus")<<" at address 0x" << std::hex << addr << std::dec << std::endl;
34
35 if (injectedRead)
36 {
37 bool cont = false;
38 bool handleNormal = false;
39
40 etiss::int32 ret = injectedRead(ibus, time_ps, addr, buf, len, cont, handleNormal);
41
42 if (!cont)
43 injectedRead = nullptr;
44
45 if (!handleNormal) // injectedRead may signal that read() should handle this call
46 {
48 {
49 snoopRead(true, time_ps, addr, buf, len);
50 }
51 return ret;
52 }
53 }
54
55#if DEBUG
56 if (time_ps < cpu.cpuTime_ps)
57 {
58 etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
59 }
60#endif
61
62 cpu.cpuTime_ps = time_ps;
63 int32_t code = etiss::RETURNCODE::NOERROR;
64
65 if (ibus)
66 {
67 code = system.iread(system.handle, &cpu, addr, len); // simulate read
68
69 if ((code == etiss::RETURNCODE::NOERROR) || (code == etiss::RETURNCODE::GDBNOERROR)) // check return code
70 {
71 code = system.dbg_read(system.handle, addr, buf, len); // read data
72 }
73 }
74 else
75 {
76 code = system.dread(system.handle, &cpu, addr, buf, len); // read data
77 }
78
79 time_ps = cpu.cpuTime_ps;
80
82 {
83 snoopRead(false, time_ps, addr, buf, len);
84 }
85
86 return code;
87}
88
89etiss::int32 Delegate::write(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
90{
91
93 {
94 bool cont = false;
95 bool handleNormal = false;
96
97 etiss::int32 ret = redirectedWrite(ibus, time_ps, addr, buf, len, cont, handleNormal);
98
99 if (!cont)
100 redirectedWrite = std::function<bool(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)>();
101
102 if (!handleNormal) // redirectedWrite may signal that write() should handle this call
103 return ret;
104 }
105
106#if DEBUG
107 if (time_ps < cpu.cpuTime_ps)
108 {
109 etiss::log(etiss::FATALERROR, "The cpu simulation time went backwards");
110 }
111#endif
112
113 cpu.cpuTime_ps = time_ps;
114 int32_t code = etiss::RETURNCODE::NOERROR;
115
116 if (ibus)
117 {
118 code = system.iwrite(system.handle, &cpu, addr, buf, len); // read data
119 }
120 else
121 {
122 code = system.dwrite(system.handle, &cpu, addr, buf, len); // read data
123 }
124
125 time_ps = cpu.cpuTime_ps;
126
127 return code;
128}
129
130} // namespace interfaces
131} // namespace etiss
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:36
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:63
void syncTime(uint64_t time_ps)
Definition Delegate.cpp:17
Delegate(ETISS_System &system, ETISS_CPU &cpu)
Definition Delegate.cpp:15
etiss::int32 read(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles read operations.
Definition Delegate.cpp:31
ETISS_System & system
Definition Delegate.h:40
etiss::int32 write(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles write operations.
Definition Delegate.cpp:89
std::function< etiss::int32(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)> redirectedWrite
Definition Delegate.h:66
std::function< void(bool injected, const uint64_t &time_ps, uint64_t addr, const uint8_t *buf, unsigned len)> snoopRead
Definition Delegate.h:69
forwards: include/jit/*
Definition Benchmark.h:17
@ FATALERROR
Definition Misc.h:84
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
etiss_uint64 cpuTime_ps
simulation time of cpu
Definition CPU.h:59
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
etiss_int32(* iread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint32 length)
used to simulate an instruction fetch.
Definition System.h:46
void * handle
custom handle that will be passed to the functions of this structure
Definition System.h:78
etiss_int32(* dbg_read)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug read
Definition System.h:66
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition System.h:55
void(* syncTime)(void *handle, ETISS_CPU *cpu)
called after a block to synchronize the time
Definition System.h:76
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:50