Browse Source

declare socket properties in processor_t

pull/700/head
Elmar Melcher 5 years ago
committed by emelcher
parent
commit
a5243f4520
  1. 2
      riscv/processor.cc
  2. 4
      riscv/processor.h
  3. 2
      riscv/sim.cc
  4. 2
      spike_main/spike-log-parser.cc
  5. 25
      spike_main/spike.cc

2
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),

4
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;

2
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();

2
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());
}

25
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,

Loading…
Cancel
Save