Eliminate infinite loop in debug mode
[riscv-isa-sim.git] / riscv / sim.cc
index 2044235e68a85e499ad655723b6c32becd84c2ee..8fafa511069a868db2016aab5f81ad8c42f1c940 100644 (file)
@@ -90,6 +90,8 @@ void sim_t::step(size_t n, bool noisy)
   for (size_t i = 0, steps = 0; i < n; i += steps)
   {
     htif->tick();
+    if (!running())
+      break;
 
     steps = std::min(n - i, INTERLEAVE - current_step);
     procs[current_proc]->step(steps, noisy);
@@ -105,6 +107,14 @@ void sim_t::step(size_t n, bool noisy)
   }
 }
 
+bool sim_t::running()
+{
+  for (size_t i = 0; i < procs.size(); i++)
+    if (procs[i]->running())
+      return true;
+  return false;
+}
+
 void sim_t::stop()
 {
   procs[0]->tohost = 1;