52 #ifndef ETISS_INTERFACES_DELEGATE_H
53 #define ETISS_INTERFACES_DELEGATE_H
56 #include "etiss/jit/ReturnCode.h"
57 #include "etiss/jit/System.h"
64 template <
typename T,
unsigned align>
70 return ((((((t & 0xaaaaaaaa) >> 1) | ((t & 0x55555555) << 1)) & 0xcccccccc) >> 2) |
71 (((((t & 0xaaaaaaaa) >> 1) | ((t & 0x55555555) << 1)) & 0x33333333)
101 unsigned ,
bool & ,
bool & )>
104 unsigned ,
bool & ,
bool & )>
112 unsigned bytewidth,
bool swapBitOrder_ =
false>
119 static_assert(std::is_integral<T>::value,
"sel_rwop needs an integral type for the select signal");
123 return (delg.*rwop)(ibus, time_ps, addr, buf, 0);
128 if (
likely(sel_i == ((1 << bytewidth) - 1)))
130 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth);
137 if ((sel_i == ((1 << (bytewidth >> 1)) - 1)) && (bytewidth > 1))
139 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 1);
141 else if ((sel_i == ((1 << (bytewidth >> 2)) - 1)) && (bytewidth > 3))
143 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 2);
148 if ((sel_i == ((1 << (bytewidth >> 1)) - 1)) && (bytewidth > 1))
150 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 1);
152 else if ((sel_i == ((1 << (bytewidth >> 2)) - 1)) && (bytewidth > 3))
154 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 2);
162 template <
typename T>
165 static_assert(std::is_pod<T>::value,
"SimpleInstructionInjector<T> requires T to be a pod type");
175 template <
class InputIt>
186 void setHelper(
unsigned index, std::function<std::list<T>(T)> func)
188 genHelpers.insert(std::make_pair(index, func));
197 std::list<T> tmp = fnc->second(val);
199 append(tmp.begin(), tmp.end());
206 std::list<T> oldbuf =
buffer;
207 for (
unsigned i = 0; i < count; i++)
209 buffer.insert(
buffer.end(), oldbuf.begin(), oldbuf.end());
218 std::map<uint64_t, T> refetchcompensation;
220 bool &continu,
bool &handleNormal)
mutable {
222 handleNormal =
false;
227 return etiss::RETURNCODE::GENERALERROR;
230 if (len !=
sizeof(T))
233 "SimpleInstructionInjector detected an instruction read access of invalid length");
234 return etiss::RETURNCODE::IBUS_READ_ERROR;
242 auto refetch = refetchcompensation.find(addr);
243 if (refetch != refetchcompensation.end())
245 *((T *)buf) = refetch->second;
257 return etiss::RETURNCODE::IBUS_READ_ERROR;
260 *((T *)buf) =
buffer.front();
262 refetchcompensation.insert(std::pair<uint64_t, T>(addr,
buffer.front()));
265 continu =
buffer.size() != 0;
284 for (
auto iter =
buffer.begin(); iter !=
buffer.end(); iter++)
287 for (
size_t i = 0; i < (
sizeof(T) >> 1); i++)
289 ((
char *)&(*iter))[i] = ((
char *)&tmp)[
sizeof(T) - 1 - i];
290 ((
char *)&(*iter))[
sizeof(T) - 1 - i] = ((
char *)&tmp)[i];
304 std::map<unsigned, std::function<std::list<T>(T)>>
genHelpers;
#define static_assert(x, y)
general configuration and logging
static __inline__ uint32_t
static __inline__ uint64_t
static __inline__ uint8_t
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
void syncTime(uint64_t time_ps)
Delegate(ETISS_System &system, ETISS_CPU &cpu)
etiss::int32 read(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles read operations.
etiss::int32 write(bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, unsigned len)
handles write operations.
std::function< etiss::int32(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)> redirectedWrite
std::function< void(bool injected, const uint64_t &time_ps, uint64_t addr, const uint8_t *buf, unsigned len)> snoopRead
std::list< uint64_t > & injectionAddresses()
bool appendWithHelper(unsigned helper, T val)
bool useRefetchCompensation_
bool logInjectionAddresses_
void swapEndianness()
swaps the endianness of all stored buffer values
SimpleInstructionInjector(bool useRefetchCompensation=true)
std::list< uint64_t > injectionAddresses_
void logInjectionAddresses(bool val)
void setHelper(unsigned index, std::function< std::list< T >(T)> func)
Adds a function with an unique ID to the SimpleInstructionInjector.
void append(InputIt first, InputIt last)
void appendRepetitions(unsigned count)
std::map< unsigned, std::function< std::list< T >T)> > genHelpers
std::function< etiss::int32(bool, uint64_t &, uint64_t, uint8_t *, unsigned, bool &, bool &)> toFunction()
bool logInjectionAddresses()
CONSTEXPR uint32_t swapBitOrder< uint32_t, 4 >(uint32_t t)
bool sel_rwop(Delegate &delg, bool ibus, uint64_t &time_ps, uint64_t addr, uint8_t *buf, T sel_i)
this function handles read writes in case of busses that have a fixed output with and a select signal...
CONSTEXPR T swapBitOrder(T t)
MM_EXPORT const int32_t NOERROR
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
void log(Verbosity level, std::string msg)
write log message at the given level.
basic cpu state structure needed for execution of any cpu architecture.
memory access and time synchronization functions.