From e30c9c90efa415a493ba2984a777bf53d1b8cbca Mon Sep 17 00:00:00 2001 From: Elmar Melcher Date: Fri, 2 Jul 2021 11:03:27 -0300 Subject: [PATCH] declare socket properties in sim_t --- riscv/debug_module.cc | 2 +- riscv/interactive.cc | 4 ++-- riscv/processor.h | 2 +- riscv/sim.cc | 8 +++++++- riscv/sim.h | 38 +++++++++++++++++++++++++++++++++++++- spike_main/spike.cc | 11 ++++++++++- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index 920166c7..0a0bf1f6 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -1,10 +1,10 @@ #include +#include "sim.h" #include "debug_module.h" #include "debug_defines.h" #include "opcodes.h" #include "mmu.h" -#include "sim.h" #include "debug_rom/debug_rom.h" #include "debug_rom_defines.h" diff --git a/riscv/interactive.cc b/riscv/interactive.cc index 5ed87d38..81809b35 100644 --- a/riscv/interactive.cc +++ b/riscv/interactive.cc @@ -1,8 +1,8 @@ // See LICENSE for license details. +#include "sim.h" #include "decode.h" #include "disasm.h" -#include "sim.h" #include "mmu.h" #include #include @@ -422,7 +422,7 @@ void sim_t::interactive_until(const std::string& cmd, const std::vectorget_max_xlen(); if (max_xlen == 32) val &= 0xFFFFFFFF; - + std::vector args2; args2 = std::vector(args.begin()+1,args.end()-1); diff --git a/riscv/processor.h b/riscv/processor.h index 3d05009b..b1845617 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -448,7 +448,7 @@ private: bool halt_on_reset; std::vector extension_table; std::vector impl_table; - + entropy_source es; // Crypto ISE Entropy source. std::vector instructions; diff --git a/riscv/sim.cc b/riscv/sim.cc index 1418af48..7b1e6693 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -36,7 +36,11 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, std::vector const hartids, const debug_module_config_t &dm_config, const char *log_path, - bool dtb_enabled, const char *dtb_file) + bool dtb_enabled, const char *dtb_file +#ifdef HAVE_BOOST_ASIO + , io_service *io_service_ptr_ctor, tcp::acceptor *acceptor_ptr_ctor // option -s +#endif + ) : htif_t(args), mems(mems), plugin_devices(plugin_devices), @@ -48,6 +52,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, dtb_file(dtb_file ? dtb_file : ""), dtb_enabled(dtb_enabled), log_file(log_path), + sout(nullptr), current_step(0), current_proc(0), debug(false), @@ -57,6 +62,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, debug_module(this, dm_config) { signal(SIGINT, &handle_signal); + sout.rdbuf(cerr.rdbuf()); // debug output goes to stderr by default for (auto& x : mems) bus.add_device(x.first, x.second); diff --git a/riscv/sim.h b/riscv/sim.h index 1c47ce75..274361c6 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -3,6 +3,24 @@ #ifndef _RISCV_SIM_H #define _RISCV_SIM_H +#include "config.h" + +#ifdef HAVE_BOOST_ASIO +#include +#include +#include +// namespace boost::asio does not work for all environments +using boost::asio::ip::tcp; +using boost::asio::io_service; +using boost::asio::streambuf; +// using boost::asio::write does not work either +using boost::asio::transfer_all; +using boost::asio::buffer_cast; +using boost::erase_all; +using boost::regex; +using boost::regex_replace; +#endif + #include "debug_module.h" #include "devices.h" #include "log_file.h" @@ -16,6 +34,10 @@ #include #include +using std::ostream; +using std::string; +using std::cerr; + class mmu_t; class remote_bitbang_t; @@ -30,7 +52,11 @@ public: std::vector> plugin_devices, const std::vector& args, const std::vector hartids, const debug_module_config_t &dm_config, const char *log_path, - bool dtb_enabled, const char *dtb_file); + bool dtb_enabled, const char *dtb_file +#ifdef HAVE_BOOST_ASIO + , io_service *io_service_ptr_ctor, tcp::acceptor *acceptor_ptr_ctor // option -s +#endif + ); ~sim_t(); // run the simulation to completion @@ -75,6 +101,16 @@ private: bus_t bus; log_file_t log_file; +#ifdef HAVE_BOOST_ASIO + // the following are needed for command socket interface + boost::asio::io_service *io_service_ptr; + tcp::acceptor *acceptor_ptr; + tcp::socket *socket_ptr; + string rin(streambuf *bout_ptr); // read input command string + void wout(streambuf *bout_ptr); // write output to socket +#endif + ostream sout; // used for socket and terminal interface + processor_t* get_core(const std::string& i); void step(size_t n); // step through simulation static const size_t INTERLEAVE = 5000; diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 50c4aa86..cfd2cd74 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -395,9 +395,18 @@ int main(int argc, char** argv) } } +#ifdef HAVE_BOOST_ASIO + boost::asio::io_service *io_service_ptr = NULL; // needed for socket command interface option -s + tcp::acceptor *acceptor_ptr = NULL; +#endif + sim_t s(isa, priv, varch, nprocs, halted, real_time_clint, initrd_start, initrd_end, bootargs, start_pc, mems, plugin_devices, htif_args, - std::move(hartids), dm_config, log_path, dtb_enabled, dtb_file); + std::move(hartids), dm_config, log_path, dtb_enabled, dtb_file +#ifdef HAVE_BOOST_ASIO + , io_service_ptr, acceptor_ptr +#endif + ); std::unique_ptr remote_bitbang((remote_bitbang_t *) NULL); std::unique_ptr jtag_dtm( new jtag_dtm_t(&s.debug_module, dmi_rti));