ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
InstructionSpecificAddressCallback.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.
16#include "etiss/Instruction.h"
17
18extern "C"
19{
21 {
24#if DEBUG
25 if (this_ == 0)
26 {
27 etiss::log(etiss::ERROR, "InstructionSpecificAddressCallback_callback called with nullptr.");
28 return false;
29 }
30 if (data_->this_ == 0)
31 {
32 etiss::log(etiss::ERROR, "InstructionSpecificAddressCallback_callback called with uninitialized struct.");
33 }
34#endif
35 return ((etiss::plugin::InstructionSpecificAddressCallback *)(data_->this_))->callback();
36 }
37}
38
39using namespace etiss::plugin;
40
47
49{
50 block.fileglobalCode().insert("extern int InstructionSpecificAddressCallback_callback(void *);\n");
51 block.functionglobalCode().insert(" if ( (*(uint32_t*)(" + getPointerCode() +
53 ") return ETISS_RETURNCODE_RELOADCURRENTBLOCK;\n"); // add print function
54}
55
57{
58 mis.foreach (
60 {
61 vis.foreach (
63 {
64 set.foreach (
65 [this](etiss::instr::Instruction &instr)
66 {
67 instr.addCallback(
70 {
71 if (this->callbackAddresses().find(ic.current_address_) !=
72 this->callbackAddresses().end())
73 {
74 std::stringstream ss;
75 ss << " if ( (*(uint32_t*)(" << getPointerCode()
76 << ")) != " << etiss::toString(pluginData_.state_) << ")\n"
77 << " return ETISS_RETURNCODE_RELOADCURRENTBLOCK;";
78 cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
79
80 ss.str("");
81 ss.clear();
82 ss << " uint32_t callbackCalled" << uid_
83 << " = InstructionSpecificAddressCallback_callback(" << getPointerCode()
84 << ");";
85 // cs.append(CodePart::APPENDEDREQUIRED).code() = ss.str();
86 cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
87
88 ss.str("");
89 ss.clear();
90 ss << " if(callbackCalled" << uid_ << ")\n"
91 << " return ETISS_RETURNCODE_NOERROR;";
92 // cs.append(CodePart::APPENDEDRETURNINGREQUIRED).code() = ss.str();
93 cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
94 }
95 return true;
96 },
97 0);
98 if (callbackOnInstruction(instr))
99 {
100 instr.addCallback(
103 {
104 std::stringstream ss;
105 ss << " InstructionSpecificAddressCallback_callback(";
106 ss << getPointerCode();
107 ss << ");";
108 cs.append(CodePart::PREINITIALDEBUGRETURNING).code() = ss.str();
109 return true;
110 },
111 0);
112 }
113 });
114 });
115 });
116}
117
119{
120 return "InstructionSpecificAddressCallback";
121}
122
int InstructionSpecificAddressCallback_callback(void *this_)
contains a simple plugin to print instructions
contains container classes to store instruction definitions + translation functions and build a trans...
A list of CodeSets.
Definition CodePart.h:532
std::set< std::string > & functionglobalCode()
Definition CodePart.h:567
std::set< std::string > & fileglobalCode()
Definition CodePart.h:566
@ PREINITIALDEBUGRETURNING
Definition CodePart.h:359
A set of CodeParts.
Definition CodePart.h:399
void append(const CodePart &part, CodePart::TYPE type)
Definition CodePart.h:412
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:63
stores a bit vector
this class contains parameters that persist in between instruction lookpus/translation within a trans...
uint64_t current_address_
start address of current instruction
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
void foreach(std::function< void(Instruction &)> func)
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 >())
holds etiss::instr::VariableInstructionSet instances for different modes.
void foreach(std::function< void(VariableInstructionSet &)> call)
holds etiss::instr::InstructionSet instances with different bit widths.
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:133
@ ERROR
Definition Misc.h:85
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94