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;
step(steps, noisy);
}
-void sim_t::interactive_run_proc_noisy(const std::string& cmd, const std::vector<std::string>& args)
-{
- interactive_run_proc(cmd,args,true);
-}
-
-void sim_t::interactive_run_proc_silent(const std::string& cmd, const std::vector<std::string>& args)
-{
- interactive_run_proc(cmd,args,false);
-}
-
-void sim_t::interactive_run_proc(const std::string& cmd, const std::vector<std::string>& 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<std::string>& args)
{
- exit(0);
+ stop();
}
reg_t sim_t::get_pc(const std::vector<std::string>& args)
# define mmap mmap64
#endif
-sim_t::sim_t(int _nprocs, int mem_mb, const std::vector<std::string>& args)
+sim_t::sim_t(size_t _nprocs, size_t mem_mb, const std::vector<std::string>& 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
{
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);
}
}
{
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();
+}
class sim_t
{
public:
- sim_t(int _nprocs, int mem_mb, const std::vector<std::string>& htif_args);
+ sim_t(size_t _nprocs, size_t mem_mb, const std::vector<std::string>& 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);
std::vector<processor_t*> 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();
void interactive_run(const std::string& cmd, const std::vector<std::string>& args, bool noisy);
void interactive_run_noisy(const std::string& cmd, const std::vector<std::string>& args);
void interactive_run_silent(const std::string& cmd, const std::vector<std::string>& args);
- void interactive_run_proc(const std::string& cmd, const std::vector<std::string>& args, bool noisy);
- void interactive_run_proc_noisy(const std::string& cmd, const std::vector<std::string>& args);
- void interactive_run_proc_silent(const std::string& cmd, const std::vector<std::string>& args);
void interactive_reg(const std::string& cmd, const std::vector<std::string>& args);
void interactive_fregs(const std::string& cmd, const std::vector<std::string>& args);
void interactive_fregd(const std::string& cmd, const std::vector<std::string>& args);
if (dc) s.get_core(i)->get_mmu()->register_memtracer(&*dc);
}
- s.run(debug);
+ s.set_debug(debug);
+ s.run();
}