From: Andrew Waterman Date: Sat, 13 Jul 2013 01:42:27 +0000 (-0700) Subject: Eliminate infinite loop in debug mode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9299f2f74547023d39fe0b4b8154e35730e70b96;p=riscv-isa-sim.git Eliminate infinite loop in debug mode --- diff --git a/riscv/htif.cc b/riscv/htif.cc index 0512b6f..fc90375 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -106,8 +106,5 @@ bool htif_isasim_t::done() { if (reset) return false; - for (size_t i = 0; i < sim->num_cores(); i++) - if (sim->procs[i]->running()) - return false; - return true; + return !sim->running(); } diff --git a/riscv/sim.cc b/riscv/sim.cc index 2044235..8fafa51 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -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; diff --git a/riscv/sim.h b/riscv/sim.h index b1e0206..2bc69f0 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -20,6 +20,7 @@ public: // run the simulation to completion void run(); + bool running(); void stop(); void set_debug(bool value) { debug = value; }