14#ifndef ETISS_INTERFACES_DELEGATE_H
15#define ETISS_INTERFACES_DELEGATE_H
18#include "etiss/jit/ReturnCode.h"
25template <
typename T,
unsigned align>
31 return ((((((t & 0xaaaaaaaa) >> 1) | ((t & 0x55555555) << 1)) & 0xcccccccc) >> 2) |
32 (((((t & 0xaaaaaaaa) >> 1) | ((t & 0x55555555) << 1)) & 0x33333333)
62 unsigned ,
bool & ,
bool & )>
65 unsigned ,
bool & ,
bool & )>
73 unsigned bytewidth,
bool swapBitOrder_ =
false>
80 static_assert(std::is_integral<T>::value,
"sel_rwop needs an integral type for the select signal");
81 static_assert(bytewidth > 0,
"bytewidth cannot be 0");
84 return (delg.*rwop)(ibus, time_ps, addr, buf, 0);
89 if (
likely(sel_i == ((1 << bytewidth) - 1)))
91 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth);
98 if ((sel_i == ((1 << (bytewidth >> 1)) - 1)) && (bytewidth > 1))
100 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 1);
102 else if ((sel_i == ((1 << (bytewidth >> 2)) - 1)) && (bytewidth > 3))
104 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 2);
109 if ((sel_i == ((1 << (bytewidth >> 1)) - 1)) && (bytewidth > 1))
111 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 1);
113 else if ((sel_i == ((1 << (bytewidth >> 2)) - 1)) && (bytewidth > 3))
115 return (delg.*rwop)(ibus, time_ps, addr, buf, bytewidth >> 2);
126 static_assert(std::is_pod<T>::value,
"SimpleInstructionInjector<T> requires T to be a pod type");
136 template <
class InputIt>
147 void setHelper(
unsigned index, std::function<std::list<T>(T)> func)
149 genHelpers.insert(std::make_pair(index, func));
158 std::list<T> tmp = fnc->second(val);
160 append(tmp.begin(), tmp.end());
167 std::list<T> oldbuf =
buffer;
168 for (
unsigned i = 0; i < count; i++)
170 buffer.insert(
buffer.end(), oldbuf.begin(), oldbuf.end());
179 std::map<uint64_t, T> refetchcompensation;
181 bool &continu,
bool &handleNormal)
mutable
184 handleNormal =
false;
189 return etiss::RETURNCODE::GENERALERROR;
192 if (len !=
sizeof(T))
195 "SimpleInstructionInjector detected an instruction read access of invalid length");
196 return etiss::RETURNCODE::IBUS_READ_ERROR;
204 auto refetch = refetchcompensation.find(addr);
205 if (refetch != refetchcompensation.end())
207 *((T *)buf) = refetch->second;
208 return etiss::RETURNCODE::NOERROR;
219 return etiss::RETURNCODE::IBUS_READ_ERROR;
222 *((T *)buf) =
buffer.front();
224 refetchcompensation.insert(std::pair<uint64_t, T>(addr,
buffer.front()));
227 continu =
buffer.size() != 0;
237 return etiss::RETURNCODE::NOERROR;
246 for (
auto iter =
buffer.begin(); iter !=
buffer.end(); iter++)
249 for (
size_t i = 0; i < (
sizeof(T) >> 1); i++)
251 ((
char *)&(*iter))[i] = ((
char *)&tmp)[
sizeof(T) - 1 - i];
252 ((
char *)&(*iter))[
sizeof(T) - 1 - i] = ((
char *)&tmp)[i];
266 std::map<unsigned, std::function<std::list<T>(T)>>
genHelpers;
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)
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
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)
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()
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::list< uint64_t > & injectionAddresses()
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)
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.