From d58ee30d172f6848edb1b3b225cc90c2143dc750 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Tue, 12 Feb 2013 22:59:14 -0800 Subject: [PATCH] make HTIF interactions deterministic; fix race --- riscv/htif.cc | 16 ++++++++++------ riscv/htif.h | 2 +- riscv/sim.cc | 5 ++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/riscv/htif.cc b/riscv/htif.cc index c7ba8fc..64ef40a 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -1,5 +1,4 @@ #include "htif.h" -#include "common.h" #include "sim.h" #include #include @@ -84,8 +83,9 @@ void htif_isasim_t::tick_once() memcpy(&val, p.get_payload(), sizeof(val)); if (regno == PCR_RESET) { - reset = val & 1; - sim->procs[coreid]->reset(reset); + if (reset && !(val & 1)) + reset = false; + sim->procs[coreid]->reset(val & 1); } else { @@ -100,8 +100,12 @@ void htif_isasim_t::tick_once() seqno++; } -void htif_isasim_t::stop() +bool htif_isasim_t::done() { - htif_t::stop(); - exit(exit_code()); + if (reset) + return false; + for (size_t i = 0; i < sim->num_cores(); i++) + if (sim->procs[i]->running()) + return false; + return true; } diff --git a/riscv/htif.h b/riscv/htif.h index 0d8d1b7..034743a 100644 --- a/riscv/htif.h +++ b/riscv/htif.h @@ -16,7 +16,7 @@ class htif_isasim_t : public htif_pthread_t public: htif_isasim_t(sim_t* _sim, const std::vector& args); void tick(); - void stop(); + bool done(); private: sim_t* sim; diff --git a/riscv/sim.cc b/riscv/sim.cc index 31c91ae..6d98d8e 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -49,7 +49,6 @@ sim_t::~sim_t() delete procs[i]; delete pmmu; } - delete htif; delete mmu; munmap(mem, memsz); } @@ -72,10 +71,10 @@ reg_t sim_t::get_scr(int which) void sim_t::run(bool debug) { - while (1) + while (!htif->done()) { if(!debug) - step_all(1000, 1000, false); + step_all(10000, 1000, false); else interactive(); } -- 2.30.2