From: Andrew Waterman Date: Sat, 13 Jul 2013 01:23:05 +0000 (-0700) Subject: Exit cleanly from debug console X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=790db6c910927a1d5318e55d7d5232164430616d;p=riscv-isa-sim.git Exit cleanly from debug console --- diff --git a/riscv/interactive.cc b/riscv/interactive.cc index da8e5bd..fc993e5 100644 --- a/riscv/interactive.cc +++ b/riscv/interactive.cc @@ -58,8 +58,6 @@ void sim_t::interactive() funcs["r"] = &sim_t::interactive_run_noisy; funcs["rs"] = &sim_t::interactive_run_silent; - funcs["rp"] = &sim_t::interactive_run_proc_noisy; - funcs["rps"] = &sim_t::interactive_run_proc_silent; funcs["reg"] = &sim_t::interactive_reg; funcs["fregs"] = &sim_t::interactive_fregs; funcs["fregd"] = &sim_t::interactive_fregd; @@ -93,32 +91,9 @@ void sim_t::interactive_run(const std::string& cmd, const std::vector& args) -{ - interactive_run_proc(cmd,args,true); -} - -void sim_t::interactive_run_proc_silent(const std::string& cmd, const std::vector& args) -{ - interactive_run_proc(cmd,args,false); -} - -void sim_t::interactive_run_proc(const std::string& cmd, const std::vector& a, bool noisy) -{ - if(a.size() == 0) - return; - - int p = atoi(a[0].c_str()); - if(p >= (int)num_cores()) - return; - - size_t steps = a.size() > 1 ? atoll(a[1].c_str()) : -1; - procs[p]->step(steps, noisy); -} - void sim_t::interactive_quit(const std::string& cmd, const std::vector& args) { - exit(0); + stop(); } reg_t sim_t::get_pc(const std::vector& args) diff --git a/riscv/sim.cc b/riscv/sim.cc index 8df943c..2044235 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -13,9 +13,9 @@ # define mmap mmap64 #endif -sim_t::sim_t(int _nprocs, int mem_mb, const std::vector& args) +sim_t::sim_t(size_t _nprocs, size_t mem_mb, const std::vector& args) : htif(new htif_isasim_t(this, args)), - procs(_nprocs), current_step(0), current_proc(0) + procs(_nprocs), current_step(0), current_proc(0), debug(false) { // allocate target machine's memory, shrinking it as necessary // until the allocation succeeds @@ -68,20 +68,20 @@ reg_t sim_t::get_scr(int which) { switch (which) { - case 0: return num_cores(); + case 0: return procs.size(); case 1: return memsz >> 20; default: return -1; } } -void sim_t::run(bool debug) +void sim_t::run() { while (!htif->done()) { - if(!debug) - step(INTERLEAVE, false); - else + if (debug) interactive(); + else + step(INTERLEAVE, false); } } @@ -99,8 +99,15 @@ void sim_t::step(size_t n, bool noisy) { current_step = 0; procs[current_proc]->mmu.yield_load_reservation(); - if (++current_proc == num_cores()) + if (++current_proc == procs.size()) current_proc = 0; } } } + +void sim_t::stop() +{ + procs[0]->tohost = 1; + while (!htif->done()) + htif->tick(); +} diff --git a/riscv/sim.h b/riscv/sim.h index ed0bda9..b1e0206 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -15,11 +15,13 @@ class htif_isasim_t; class sim_t { public: - sim_t(int _nprocs, int mem_mb, const std::vector& htif_args); + sim_t(size_t _nprocs, size_t mem_mb, const std::vector& htif_args); ~sim_t(); // run the simulation to completion - void run(bool debug); + void run(); + void stop(); + void set_debug(bool value) { debug = value; } // deliver an IPI to a specific processor void send_ipi(reg_t who); @@ -39,9 +41,10 @@ private: std::vector procs; void step(size_t n, bool noisy); // step through simulation - static const size_t INTERLEAVE = 5000; + static const size_t INTERLEAVE = 1000; size_t current_step; size_t current_proc; + bool debug; // presents a prompt for introspection into the simulation void interactive(); @@ -51,9 +54,6 @@ private: void interactive_run(const std::string& cmd, const std::vector& args, bool noisy); void interactive_run_noisy(const std::string& cmd, const std::vector& args); void interactive_run_silent(const std::string& cmd, const std::vector& args); - void interactive_run_proc(const std::string& cmd, const std::vector& args, bool noisy); - void interactive_run_proc_noisy(const std::string& cmd, const std::vector& args); - void interactive_run_proc_silent(const std::string& cmd, const std::vector& args); void interactive_reg(const std::string& cmd, const std::vector& args); void interactive_fregs(const std::string& cmd, const std::vector& args); void interactive_fregd(const std::string& cmd, const std::vector& args); diff --git a/riscv/spike.cc b/riscv/spike.cc index c9b755d..8fbe25b 100644 --- a/riscv/spike.cc +++ b/riscv/spike.cc @@ -58,5 +58,6 @@ int main(int argc, char** argv) if (dc) s.get_core(i)->get_mmu()->register_memtracer(&*dc); } - s.run(debug); + s.set_debug(debug); + s.run(); }