add I$/D$/L2$ simulators
[riscv-isa-sim.git] / riscv / sim.cc
index 9020da4554082c147fecc9f9daf3bdf12ff9ffb9..6d98d8e122e8b776f4e6f58865f7229a91ef34eb 100644 (file)
 # define mmap mmap64
 #endif
 
-sim_t::sim_t(int _nprocs, htif_t* _htif)
-  : htif(_htif),
-    procs(_nprocs),
-    running(false)
+sim_t::sim_t(int _nprocs, int mem_mb, const std::vector<std::string>& args)
+  : htif(new htif_isasim_t(this, args)),
+    procs(_nprocs)
 {
   // allocate target machine's memory, shrinking it as necessary
   // until the allocation succeeds
+  size_t memsz0 = (size_t)mem_mb << 20;
+  if (memsz0 == 0)
+    memsz0 = 1L << (sizeof(size_t) == 8 ? 32 : 30);
 
-  size_t memsz0 = sizeof(size_t) == 8 ? 0x100000000ULL : 0x70000000UL;
   size_t quantum = std::max(PGSIZE, (reg_t)sysconf(_SC_PAGESIZE));
   memsz0 = memsz0/quantum*quantum;
 
@@ -38,8 +39,6 @@ sim_t::sim_t(int _nprocs, htif_t* _htif)
 
   for(size_t i = 0; i < num_cores(); i++)
     procs[i] = new processor_t(this, new mmu_t(mem, memsz), i);
-
-  htif->init(this);
 }
 
 sim_t::~sim_t()
@@ -54,36 +53,28 @@ sim_t::~sim_t()
   munmap(mem, memsz);
 }
 
-void sim_t::set_tohost(reg_t val)
-{
-  fromhost = 0;
-  tohost = val;
-  htif->wait_for_tohost_write();
-}
-
-reg_t sim_t::get_fromhost()
-{
-  htif->wait_for_fromhost_write();
-  return fromhost;
-}
-
 void sim_t::send_ipi(reg_t who)
 {
   if(who < num_cores())
     procs[who]->deliver_ipi();
 }
 
-void sim_t::run(bool debug)
+reg_t sim_t::get_scr(int which)
 {
-  htif->wait_for_start();
-
-  // start core 0
-  send_ipi(0);
+  switch (which)
+  {
+    case 0: return num_cores();
+    case 1: return memsz >> 20;
+    default: return -1;
+  }
+}
 
-  for(running = true; running; )
+void sim_t::run(bool debug)
+{
+  while (!htif->done())
   {
     if(!debug)
-      step_all(100,100,false);
+      step_all(10000, 1000, false);
     else
       interactive();
   }
@@ -91,7 +82,10 @@ void sim_t::run(bool debug)
 
 void sim_t::step_all(size_t n, size_t interleave, bool noisy)
 {
+  htif->tick();
   for(size_t j = 0; j < n; j+=interleave)
+  {
     for(int i = 0; i < (int)num_cores(); i++)
       procs[i]->step(interleave,noisy);
+  }
 }