add dynamic plugin loading

This commit is contained in:
Eyck Jentzsch 2021-10-12 14:24:55 +02:00
parent 1d13c8196e
commit 0ea4cba1ca
4 changed files with 73 additions and 9 deletions

View File

@ -40,11 +40,17 @@ set(LIB_SOURCES
) )
if(WITH_LLVM) if(WITH_LLVM)
set(LIB_SOURCES ${LIB_SOURCES} FILE(GLOB TGC_LLVM_SOURCES
src/vm/llvm/fp_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/vm/llvm/vm_*.cpp
#src/vm/llvm/vm_tgf_b.cpp
#src/vm/llvm/vm_tgf_c.cpp
) )
list(APPEND LIB_SOURCES ${TGC_LLVM_SOURCES})
endif()
if(WITH_TCC)
FILE(GLOB TGC_TCC_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/vm/tcc/vm_*.cpp
)
list(APPEND LIB_SOURCES ${TGC_TCC_SOURCES})
endif() endif()
# Define the library # Define the library

View File

@ -48,6 +48,9 @@
#include <util/range_lut.h> #include <util/range_lut.h>
#include <memory> #include <memory>
namespace iss {
class vm_plugin;
}
namespace sysc { namespace sysc {
class tlm_dmi_ext : public tlm::tlm_dmi { class tlm_dmi_ext : public tlm::tlm_dmi {
@ -99,6 +102,8 @@ public:
cci::cci_param<uint32_t> mhartid{"mhartid", 0}; cci::cci_param<uint32_t> mhartid{"mhartid", 0};
cci::cci_param<std::string> plugins{"plugins", ""};
core_complex(sc_core::sc_module_name const& name); core_complex(sc_core::sc_module_name const& name);
#else #else
@ -122,6 +127,8 @@ public:
scml_property<uint32_t> mhartid{"mhartid", 0}; scml_property<uint32_t> mhartid{"mhartid", 0};
scml_property<std::string> plugins{"plugins", ""};
core_complex(sc_core::sc_module_name const& name) core_complex(sc_core::sc_module_name const& name)
: sc_module(name) : sc_module(name)
, local_irq_i{"local_irq_i", 16} , local_irq_i{"local_irq_i", 16}
@ -185,6 +192,8 @@ protected:
std::unique_ptr<scc::tick2time> t2t; std::unique_ptr<scc::tick2time> t2t;
private: private:
void init(); void init();
std::vector<iss::vm_plugin *> plugin_list;
}; };
} /* namespace SiFive */ } /* namespace SiFive */
} /* namespace sysc */ } /* namespace sysc */

View File

@ -60,6 +60,10 @@ using tgc_d_xrb_mac_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_d_xrb_
#include <iss/log_categories.h> #include <iss/log_categories.h>
#include <iss/plugin/cycle_estimate.h> #include <iss/plugin/cycle_estimate.h>
#include <iss/plugin/instruction_count.h> #include <iss/plugin/instruction_count.h>
#include <iss/plugin/loader.h>
#if defined(HAS_LUA)
#include <iss/plugin/lua.h>
#endif
namespace po = boost::program_options; namespace po = boost::program_options;
@ -171,12 +175,20 @@ int main(int argc, char *argv[]) {
auto *ce_plugin = new iss::plugin::cycle_estimate(filename); auto *ce_plugin = new iss::plugin::cycle_estimate(filename);
vm->register_plugin(*ce_plugin); vm->register_plugin(*ce_plugin);
plugin_list.push_back(ce_plugin); plugin_list.push_back(ce_plugin);
} else {
std::array<char const*, 1> a{{filename.c_str()}};
iss::plugin::loader l(plugin_name, {{"initPlugin"}});
auto* plugin = l.call_function<iss::vm_plugin*>("initPlugin", a.size(), a.data());
if(plugin){
vm->register_plugin(*plugin);
plugin_list.push_back(plugin);
} else { } else {
LOG(ERR) << "Unknown plugin name: " << plugin_name << ", valid names are 'ce', 'ic'" << std::endl; LOG(ERR) << "Unknown plugin name: " << plugin_name << ", valid names are 'ce', 'ic'" << std::endl;
return 127; return 127;
} }
} }
} }
}
if (clim.count("disass")) { if (clim.count("disass")) {
vm->setDisassEnabled(true); vm->setDisassEnabled(true);
LOGGER(disass)::reporting_level() = logging::INFO; LOGGER(disass)::reporting_level() = logging::INFO;

View File

@ -37,6 +37,7 @@
#include "iss/debugger/target_adapter_if.h" #include "iss/debugger/target_adapter_if.h"
#include "iss/iss.h" #include "iss/iss.h"
#include "iss/vm_types.h" #include "iss/vm_types.h"
#include <iss/plugin/loader.h>
#include "sysc/core_complex.h" #include "sysc/core_complex.h"
#ifdef CORE_TGC_B #ifdef CORE_TGC_B
#include "iss/arch/riscv_hart_m_p.h" #include "iss/arch/riscv_hart_m_p.h"
@ -56,10 +57,13 @@ using tgc_d_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_d, iss::arch::
#include "iss/arch/tgc_d_xrb_mac.h" #include "iss/arch/tgc_d_xrb_mac.h"
using tgc_d_xrb_mac_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_d_xrb_mac, iss::arch::FEAT_PMP>; using tgc_d_xrb_mac_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_d_xrb_mac, iss::arch::FEAT_PMP>;
#endif #endif
#include "scc/report.h" #include <scc/report.h>
#include <util/ities.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <array> #include <array>
#include <iss/plugin/cycle_estimate.h>
#include <iss/plugin/instruction_count.h>
// clang-format on // clang-format on
#define STR(X) #X #define STR(X) #X
@ -380,6 +384,8 @@ void core_complex::init(){
core_complex::~core_complex(){ core_complex::~core_complex(){
delete cpu; delete cpu;
delete trc; delete trc;
for (auto *p : plugin_list)
delete p;
} }
void core_complex::trace(sc_trace_file *trf) const {} void core_complex::trace(sc_trace_file *trf) const {}
@ -391,6 +397,37 @@ void core_complex::before_end_of_elaboration() {
cpu->create_cpu(GET_PROP_VALUE(core_type), GET_PROP_VALUE(backend), GET_PROP_VALUE(gdb_server_port), GET_PROP_VALUE(mhartid)); cpu->create_cpu(GET_PROP_VALUE(core_type), GET_PROP_VALUE(backend), GET_PROP_VALUE(gdb_server_port), GET_PROP_VALUE(mhartid));
sc_assert(cpu->vm!=nullptr); sc_assert(cpu->vm!=nullptr);
cpu->vm->setDisassEnabled(GET_PROP_VALUE(enable_disass) || trc->m_db != nullptr); cpu->vm->setDisassEnabled(GET_PROP_VALUE(enable_disass) || trc->m_db != nullptr);
if (GET_PROP_VALUE(core_type).length()) {
auto p = util::split(GET_PROP_VALUE(plugins), ';');
for (std::string const& opt_val : p) {
std::string plugin_name=opt_val;
std::string filename{"cycles.txt"};
std::size_t found = opt_val.find('=');
if (found != std::string::npos) {
plugin_name = opt_val.substr(0, found);
filename = opt_val.substr(found + 1, opt_val.size());
}
if (plugin_name == "ic") {
auto *plugin = new iss::plugin::instruction_count(filename);
cpu->vm->register_plugin(*plugin);
plugin_list.push_back(plugin);
} else if (plugin_name == "ce") {
auto *plugin = new iss::plugin::cycle_estimate(filename);
cpu->vm->register_plugin(*plugin);
plugin_list.push_back(plugin);
} else {
std::array<char const*, 1> a{{filename.c_str()}};
iss::plugin::loader l(plugin_name, {{"initPlugin"}});
auto* plugin = l.call_function<iss::vm_plugin*>("initPlugin", a.size(), a.data());
if(plugin){
cpu->vm->register_plugin(*plugin);
plugin_list.push_back(plugin);
} else
SCCERR(SCMOD) << "Unknown plugin '" << plugin_name << "' or plugin not found";
}
}
}
} }
void core_complex::start_of_simulation() { void core_complex::start_of_simulation() {