diff options
-rw-r--r-- | riscv/processor.cc | 2 | ||||
-rw-r--r-- | riscv/processor.h | 4 | ||||
-rw-r--r-- | riscv/sim.cc | 2 | ||||
-rw-r--r-- | spike_main/spike-log-parser.cc | 2 | ||||
-rw-r--r-- | spike_main/spike.cc | 25 |
5 files changed, 31 insertions, 4 deletions
diff --git a/riscv/processor.cc b/riscv/processor.cc index 309f4da..2ea04b1 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -24,7 +24,7 @@ processor_t::processor_t(const char* isa, const char* priv, const char* varch, simif_t* sim, uint32_t id, bool halt_on_reset, - FILE* log_file) + FILE* log_file, ostream *sout_ptr_ctor) : debug(false), halt_request(HR_NONE), sim(sim), id(id), xlen(0), histogram_enabled(false), log_commits_enabled(false), log_file(log_file), halt_on_reset(halt_on_reset), diff --git a/riscv/processor.h b/riscv/processor.h index b184561..76e482d 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -14,6 +14,7 @@ #include "debug_rom_defines.h" #include "entropy_source.h" +using std::ostream; class processor_t; class mmu_t; @@ -273,7 +274,7 @@ class processor_t : public abstract_device_t public: processor_t(const char* isa, const char* priv, const char* varch, simif_t* sim, uint32_t id, bool halt_on_reset, - FILE *log_file); + FILE *log_file, ostream *sout_ptr); // because of command line option --log and -s we need both ~processor_t(); void set_debug(bool value); @@ -445,6 +446,7 @@ private: bool histogram_enabled; bool log_commits_enabled; FILE *log_file; + ostream *sout_ptr; // needed for socket command interface -s, also used for -d and -l, but not for --log bool halt_on_reset; std::vector<bool> extension_table; std::vector<bool> impl_table; diff --git a/riscv/sim.cc b/riscv/sim.cc index 7b1e669..3c37c44 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -85,7 +85,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, for (size_t i = 0; i < nprocs; i++) { int hart_id = hartids.empty() ? i : hartids[i]; procs[i] = new processor_t(isa, priv, varch, this, hart_id, halted, - log_file.get()); + log_file.get(), &sout); } make_dtb(); diff --git a/spike_main/spike-log-parser.cc b/spike_main/spike-log-parser.cc index d174afc..80a590b 100644 --- a/spike_main/spike-log-parser.cc +++ b/spike_main/spike-log-parser.cc @@ -27,7 +27,7 @@ int main(int argc, char** argv) parser.option(0, "isa", 1, [&](const char* s){isa = s;}); parser.parse(argv); - processor_t p(isa, DEFAULT_PRIV, DEFAULT_VARCH, 0, 0, false, nullptr); + processor_t p(isa, DEFAULT_PRIV, DEFAULT_VARCH, 0, 0, false, nullptr, nullptr); if (extension) { p.register_extension(extension()); } diff --git a/spike_main/spike.cc b/spike_main/spike.cc index cfd2cd7..43431a6 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -15,6 +15,8 @@ #include <fstream> #include "../VERSION" +using std::string; + static void help(int exit_code = 1) { fprintf(stderr, "Spike RISC-V ISA Simulator " SPIKE_VERSION "\n\n"); @@ -27,6 +29,9 @@ static void help(int exit_code = 1) fprintf(stderr, " -d Interactive debug mode\n"); fprintf(stderr, " -g Track histogram of PCs\n"); fprintf(stderr, " -l Generate a log of execution\n"); +#ifdef HAVE_BOOST_ASIO + fprintf(stderr, " -s Command I/O via socket (use with -d)\n"); +#endif fprintf(stderr, " -h, --help Print this help message\n"); fprintf(stderr, " -H Start halted, allowing a debugger to connect\n"); fprintf(stderr, " --isa=<name> RISC-V ISA string [default %s]\n", DEFAULT_ISA); @@ -208,6 +213,7 @@ int main(int argc, char** argv) bool halted = false; bool histogram = false; bool log = false; + bool socket = false; // command line option -s bool dump_dts = false; bool dtb_enabled = true; bool real_time_clint = false; @@ -308,6 +314,9 @@ int main(int argc, char** argv) parser.option('d', 0, 0, [&](const char* s){debug = true;}); parser.option('g', 0, 0, [&](const char* s){histogram = true;}); parser.option('l', 0, 0, [&](const char* s){log = true;}); +#ifdef HAVE_BOOST_ASIO + parser.option('s', 0, 0, [&](const char* s){socket = true;}); +#endif parser.option('p', 0, 1, [&](const char* s){nprocs = atoul_nonzero_safe(s);}); parser.option('m', 0, 1, [&](const char* s){mems = make_mems(s);}); // I wanted to use --halted, but for some reason that doesn't work. @@ -398,6 +407,22 @@ 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; + if (socket) { // if command line option -s is set + try + { // create socket server + io_service_ptr = new boost::asio::io_service; + acceptor_ptr = new tcp::acceptor(*io_service_ptr, tcp::endpoint(tcp::v4(), 0)); + // aceptor is created passing argument port=0, so O.S. will choose a free port + string name = boost::asio::ip::host_name(); + std::cout << "Listening for debug commands on " << name.substr(0,name.find('.')) + << " port " << acceptor_ptr->local_endpoint().port() << " ." << std::endl; + // at the end, add space and some other character for convenience of javascript .split(" ") + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + } + } #endif sim_t s(isa, priv, varch, nprocs, halted, real_time_clint, |