59 #ifndef ETISS_INCLUDE_INSTRUCTION_H_
60 #define ETISS_INCLUDE_INSTRUCTION_H_
72 #include <boost/dynamic_bitset.hpp>
105 for (
unsigned i = 0; i <
intcount_; i++)
d_[i] = 0;
116 throw std::runtime_error(
"operator= called with incompatible bit array");
155 typedef std::set<Instruction*>
Node;
163 typedef boost::dynamic_bitset<>
super;
165 using super::dynamic_bitset;
195 static std::vector<BitArray>
permutate(
const BitArray& input, std::vector<size_type> indexes);
219 BitArrayRange(
unsigned endindex_included,
unsigned startindex_included);
276 template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>
::type>
283 OPCode(
unsigned width,
const T code,
const T mask) :
code_(width, code & mask),
mask_(width, mask)
286 if ((code & mask) != code)
290 if (width != 16 && width != 32 && width != 64 && width != 128 && width != 256)
293 "[width must be given in bits and is usually 16,32,64,128,256 bits long]");
355 unsigned &
ufield(std::string name);
356 template <
typename T>
377 std::map<void *, std::map<std::string, uint64_t>>
403 enum class BUILTINGROUP :
uint32_t {
404 CPUTIMEUPDATE = 1 << 0
415 template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>
::type>
420 virtual std::string
print(std::string indent,
I pos,
unsigned pfillwidth,
bool printunused =
false);
422 uint32_t builtinGroups,
const std::set<uint32_t> &groups = std::set<uint32_t>());
457 template <
typename T>
469 std::string
print(std::string prefix,
bool printunused =
false);
473 void foreach (std::function<
void(
Instruction &)> func);
480 std::map<const OPCode *, Instruction *, etiss::instr::less>
instrmap_;
502 std::map<unsigned, InstructionSet *>
ismap_;
524 template <
typename T>
528 unsigned bytes = bits >> 3;
529 if (bytes * 8 != bits)
532 throw std::runtime_error();
535 return open(bits).
open<T>(bits, code, mask, std::string(name));
540 std::string
print(std::string prefix = std::string());
566 std::map<uint32_t, VariableInstructionSet *>
vismap_;
585 template <
typename T>
588 return open(
mode, width).
open<T>(bits, code, mask, instrname);
598 std::string
print(std::string prefix = std::string());
608 template <
typename... T>
619 const std::string name_;
620 template <
typename... T>
623 add(class1, otherclasses...);
641 template <
typename... T>
656 template <
typename... T>
681 std::set<InstructionDefinition *>
defs_;
695 for (
auto iter =
defs_.begin(); iter !=
defs_.end(); iter++)
720 template <
typename T>
736 "Instruction defined without a function callback: ") +
750 #if __cplusplus >= 201103L
756 template <
typename T_>
792 const char *
s,
bool *good = 0)
797 unsigned shifted = 0;
808 if (
s[pos] >=
'0' &&
s[pos] <=
'9')
810 tmp = tmp * 10 +
s[pos] -
'0';
812 else if (
s[pos] ==
'x' ||
s[pos] ==
'x')
817 for (
unsigned i = 0; i < tmp; i++)
818 mask = (mask << 1) | 1;
822 else if (
s[pos] ==
' ' ||
s[pos] ==
'\t')
836 if (
s[pos] >=
'0' &&
s[pos] <=
'9')
838 tmp = tmp * 16 +
s[pos] -
'0';
840 else if (
s[pos] >=
'a' &&
s[pos] <=
'f')
842 tmp = tmp * 16 +
s[pos] + 10 -
'a';
844 else if (
s[pos] >=
'A' &&
s[pos] <=
'F')
846 tmp = tmp * 16 +
s[pos] + 10 -
'A';
848 else if (
s[pos] ==
' ' ||
s[pos] ==
'\t' ||
s[pos] == 0)
851 ret = ret | (tmp & mask);
863 }
while (
s[pos++] != 0);
classes to hold code and additional information used for optimization of instruction translations
general configuration and logging
#define etiss_del_como(CLASS)
#define etiss_log(LEVEL, MSG)
__device__ __2f16 float bool s
static __inline__ uint32_t
static __inline__ uint64_t
Marker interface for toString() support.
Reading through it will only return bits within the range.
BitArray::size_type end()
lowest bit of the range (included).
BitArray::size_type start()
highest bit of the range (included)
etiss_del_como(BitArrayRange) private BitArray::size_type endpos
void write(BitArray &ba, I val)
write the bit from the passed value starting at the lsb to the range.
I read(const BitArray &ba)
reads bits from the range to the return value starting at the lsb.
BitArrayRange(unsigned endindex_included, unsigned startindex_included)
static std::vector< BitArray > permutate(const BitArray &input, std::vector< size_type > indexes)
permutates the given input at the specified indexes.
void set_value(size_type width, unsigned long value)
change the value the object is holding
BitArray get_range(size_type end, size_type start) const
get the interval [end, start]
unsigned byteCount() const
std::string to_string() const
string representation of the BitArray
unsigned intCount() const
boost::dynamic_bitset super
void set_range(unsigned long val, size_type end, size_type start)
set the value to the interval [end, start]
Buffer for reading data from memory while instructions are being fetched.
Buffer & operator=(const Buffer &o)
Buffer(unsigned intcount)
unsigned internalBufferSize()
Buffer & operator=(Buffer &&o)
Buffer(unsigned intcount, I val)
char * internalBuffer()
get the internal buffer
void recoverFromEndianness(unsigned alignment, endian_t endianness)
changes byte positions as needed to resove endiannes incompabilities after using the internal buffer ...
maps to VariableInstructionSet
void addTo(VariableInstructionSet &set, bool &ok)
void add(InstructionGroup &group, T &... args)
const std::string unsigned InstructionGroup T & othergroups
etiss_del_como(InstructionClass) template< typename... T > InstructionClass(unsigned mode
std::set< InstructionGroup * > groups_
const std::string unsigned width
const std::string unsigned InstructionGroup & group1
maps to ModedInstructionSet
void add(InstructionClass &klass, T &... args)
etiss_del_como(InstructionCollection) const std InstructionCollection(const std::string &name, InstructionClass &class1, T &... otherclasses)
void addTo(ModedInstructionSet &set, bool &ok)
std::set< InstructionClass * > classes_
this class contains parameters that persist in between instruction lookpus/translation within a trans...
std::map< std::string, unsigned > ufields_
additional fields that can be used by any plugin/architecture.
uint64_t & ufield(const T &plugin, std::string name)
returns a persistent field
uint64_t current_local_address_
address within the current block
bool is_not_default_width_
if true the this instruction is not as long as the width of the variable instruction set
bool force_block_end_
if true then the block ends after the current instruction.
unsigned & ufield(std::string name)
std::map< void *, std::map< std::string, uint64_t > > lufields_
additonal fields that are local (private) to a plugin/architecture.
bool instr_width_fully_evaluated_
if true the length_updater_ function will be called again after instr_width_ bits are available
uint64_t current_address_
start address of current instruction
etiss_del_como(InstructionContext) inline InstructionContext()
instruction context is initialized by etiss::Translation class
bool force_append_next_instr_
if true then the block will continue with the next instruction and cannot be terminated
const std::string T T mask
const std::string T T std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> uint32_t builtinGroups
void addTo(Instruction &set, bool &ok)
std::string toString() const
const std::string T T std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback
const std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback_
const std::string T T std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> uint32_t std::function< std::string(BitArray &, Instruction &)> ASMprinter
InstructionGroup & group_
const std::function< std::string(BitArray &, Instruction &)> ASMprinter_
etiss_del_como(InstructionDefinition) template< typename T > InstructionDefinition(InstructionGroup &ig
const uint32_t builtinGroups_
std::string toString() const
etiss_del_como(InstructionGroup) inline InstructionGroup(const std
void addTo(InstructionSet &set, bool &ok)
std::set< InstructionDefinition * > defs_
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
Instruction & getInvalid()
etiss_del_como(InstructionSet) VariableInstructionSet &parent_
std::map< const OPCode *, Instruction *, etiss::instr::less > instrmap_
Instruction * resolve(Node *node, BitArray &instr)
Instruction * get(const OPCode &key)
std::string print(std::string prefix, bool printunused=false)
Instruction * resolve(BitArray &instr)
Instruction & open(T code, T val, const std::string &name)
bool compile(Node *node, BitArray code, Instruction *instr)
std::string toString() const
Instruction * create(const OPCode &key, const std::string &name)
Instruction & open(const OPCode &key, const std::string &name)
InstructionSet(VariableInstructionSet &parent, unsigned width, const std::string &name, unsigned c_size=4)
const unsigned chunk_size
holds information and translation callbacks for an instruction.
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
std::set< uint32_t > & presentGroups()
bool translate(BitArray &, CodeSet &cs, InstructionContext &context)
uint32_t & presentBuiltinGroups()
void setASMPrinter(std::function< std::string(BitArray &, Instruction &)> printer)
Instruction(unsigned width, const T code, const T mask, const std::string &name)
std::function< std::string(BitArray &, Instruction &)> printer_
static std::string printASMSimple(BitArray &ba, Instruction &instr)
Instruction(const OPCode &opc, const std::string &name)
virtual std::string print(std::string indent, I pos, unsigned pfillwidth, bool printunused=false)
std::string printASM(BitArray &)
std::set< uint32_t > groups_
std::list< std::tuple< std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)>, uint32_t, std::set< uint32_t > > > callbacks_
etiss_del_como(Instruction) enum class BUILTINGROUP const BitArray::size_type width
std::string toString() const
holds etiss::instr::VariableInstructionSet instances for different modes.
std::string print(std::string prefix=std::string())
uint32_t getMode(VariableInstructionSet &vis)
std::map< uint32_t, std::string > modetostring_
Instruction & open(uint32_t mode, unsigned width, unsigned bits, T code, T mask, const char *instrname)
VariableInstructionSet * create(uint32_t mode, unsigned width, const std::string &name=std::string())
std::map< VariableInstructionSet *, uint32_t > invvismap_
VariableInstructionSet & open(uint32_t mode, unsigned width, const std::string &name=std::string())
const std::string archname_
uint32_t getMode(VariableInstructionSet *vis)
std::map< std::string, uint32_t > stringtomode_
VariableInstructionSet * get(uint32_t mode)
std::map< uint32_t, VariableInstructionSet * > vismap_
defines the relevant bits and their value to identify an instruction.
bool operator!=(const OPCode &o) const
OPCode(unsigned width, const T code, const T mask)
ctor that uses integral values for mask and code
bool operator==(const OPCode &o) const
bool operator<(const OPCode &o) const
comparison operator for map/sets.
holds etiss::instr::InstructionSet instances with different bit widths.
Instruction & open(unsigned bits, T code, T mask, const char *name)
InstructionSet & open(unsigned width, const std::string &name=std::string())
std::string print(std::string prefix=std::string())
InstructionSet * get(unsigned width)
const std::string archname_
std::map< unsigned, InstructionSet * > ismap_
InstructionSet * createMain(const std::string &name=std::string())
unsigned const std::string & archname
InstructionSet * create(unsigned width, const std::string &name=std::string())
InstructionSet & openMain(const std::string &name=std::string())
etiss_del_como(VariableInstructionSet) VariableInstructionSet(ModedInstructionSet &
std::function< void(VariableInstructionSet &, InstructionContext &, BitArray &)> length_updater_
ModedInstructionSet & parent_
InstructionSet * getMain()
std::set< Instruction * > Node
Holding unique instruction sets code chunks after permutation.
BitArray::size_type size_type
std::enable_if< std::is_integral< T_ >::value, typename std::make_unsigned< T_ >::type >::type parse_i(const char *s, bool *good=0)
this parser basically allows to write as a string hexadecimal values which will be appended as if it ...
uint32_t parse_i32(const char *s)
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
std::string toString(const T &val)
conversion of type T to std::string.
endian_t
Enumeration type for the endianness.
void log(Verbosity level, std::string msg)
write log message at the given level.
calls operator< of the objects.
bool operator()(const OPCode *const &o1, const OPCode *const &o2) const