ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
InstructionSpecificAddressCallback.cpp
Go to the documentation of this file.
1 
54 
55 extern "C"
56 {
58  {
61 #if DEBUG
62  if (this_ == 0)
63  {
64  etiss::log(etiss::ERROR, "InstructionSpecificAddressCallback_callback called with nullptr.");
65  return false;
66  }
67  if (data_->this_ == 0)
68  {
69  etiss::log(etiss::ERROR, "InstructionSpecificAddressCallback_callback called with uninitialized struct.");
70  }
71 #endif
72  return ((etiss::plugin::InstructionSpecificAddressCallback *)(data_->this_))->callback();
73  }
74 }
75 
76 using namespace etiss::plugin;
77 
79 {
80  pluginData_.state_ = 0;
81  pluginData_.this_ = this;
82 }
84 
86 {
87  block.fileglobalCode().insert("extern int InstructionSpecificAddressCallback_callback(void *);\n");
88  block.functionglobalCode().insert(" if ( (*(uint32_t*)(" + getPointerCode() +
89  ")) != " + etiss::toString(pluginData_.state_) +
90  ") return ETISS_RETURNCODE_RELOADCURRENTBLOCK;\n"); // add print function
91 }
92 
94 {
96  vis.foreach ([this](etiss::instr::InstructionSet &set) {
97  set.foreach ([this](etiss::instr::Instruction &instr) {
98  instr.addCallback(
100  if (this->callbackAddresses().find(ic.current_address_) != this->callbackAddresses().end())
101  {
102  std::stringstream ss;
103  ss << " if ( (*(uint32_t*)(" << getPointerCode()
104  << ")) != " << etiss::toString(pluginData_.state_) << ")\n"
105  << " return ETISS_RETURNCODE_RELOADCURRENTBLOCK;";
106  cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
107 
108  ss.str("");
109  ss.clear();
110  ss << " uint32_t callbackCalled = InstructionSpecificAddressCallback_callback("
111  << getPointerCode() << ");";
112  // cs.append(CodePart::APPENDEDREQUIRED).code() = ss.str();
113  cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
114 
115  ss.str("");
116  ss.clear();
117  ss << " if(callbackCalled)\n"
118  << " return ETISS_RETURNCODE_NOERROR;";
119  // cs.append(CodePart::APPENDEDRETURNINGREQUIRED).code() = ss.str();
120  cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
121  }
122  return true;
123  },
124  0);
125  if (callbackOnInstruction(instr))
126  {
127  instr.addCallback(
129  std::stringstream ss;
130  ss << " InstructionSpecificAddressCallback_callback(";
131  ss << getPointerCode();
132  ss << ");";
133  cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
134  return true;
135  },
136  0);
137  }
138  });
139  });
140  });
141 }
142 
144 {
145  return "InstructionSpecificAddressCallback";
146 }
147 
149 {
150  return (void *)&pluginData_;
151 }
int InstructionSpecificAddressCallback_callback(void *this_)
contains a simple plugin to print instructions
A list of CodeSets.
Definition: CodePart.h:570
std::set< std::string > & functionglobalCode()
Definition: CodePart.h:605
std::set< std::string > & fileglobalCode()
Definition: CodePart.h:604
@ PREINITIALDEBUGRETURNING
Definition: CodePart.h:397
A set of CodeParts.
Definition: CodePart.h:437
void append(const CodePart &part, CodePart::TYPE type)
Definition: CodePart.h:450
std::string getPointerCode() const
returns a C code expression that allows to get or assign a pointer to the variable assigned to this t...
Definition: Plugin.cpp:101
stores a bit vector
Definition: Instruction.h:161
this class contains parameters that persist in between instruction lookpus/translation within a trans...
Definition: Instruction.h:337
uint64_t current_address_
start address of current instruction
Definition: Instruction.h:366
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
Definition: Instruction.h:442
void foreach(std::function< void(Instruction &)> func)
holds information and translation callbacks for an instruction.
Definition: Instruction.h:393
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
holds etiss::instr::VariableInstructionSet instances for different modes.
Definition: Instruction.h:562
void foreach(std::function< void(VariableInstructionSet &)> call)
holds etiss::instr::InstructionSet instances with different bit widths.
Definition: Instruction.h:500
void foreach(std::function< void(InstructionSet &)> func)
a simple plugin that prints the instruction and address when an instruction is executed
virtual void initCodeBlock(etiss::CodeBlock &block) const
called before instructions are translated for the code block
virtual void finalizeInstrSet(etiss::instr::ModedInstructionSet &) const
called after all instructions have been added to allow last changes
virtual void * getPluginHandle()
called to get the handle that is available in translated code via getPoinerCode()....
virtual bool callbackOnInstruction(etiss::instr::Instruction &instr) const
implement to return true to call InstructionSpecificAddressCallback::callback whenever that etiss::in...
std::string toString(const T &val)
conversion of type T to std::string.
Definition: Misc.h:174
@ ERROR
Definition: Misc.h:127
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125