From e4aaed1b7b08998a6b6aefa34f7c575e292dde62 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Mon, 11 Apr 2022 10:47:50 +0100 Subject: Move the "default hartids" logic from sim.cc into spike.cc This moves another part of the "configuration" out of the generic sim.cc code. --- riscv/sim.cc | 13 +++---------- spike_main/spike.cc | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/riscv/sim.cc b/riscv/sim.cc index 4e3dd40..d285183 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -63,6 +63,8 @@ sim_t::sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_cl remote_bitbang(NULL), debug_module(this, dm_config) { + assert(hartids.size() == cfg->nprocs()); + signal(SIGINT, &handle_signal); sout_.rdbuf(std::cerr.rdbuf()); // debug output goes to stderr by default @@ -77,17 +79,8 @@ sim_t::sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_cl debug_mmu = new mmu_t(this, NULL); - if (! (hartids.empty() || hartids.size() == nprocs())) { - std::cerr << "Number of specified hartids (" - << hartids.size() - << ") doesn't match number of processors (" - << nprocs() << ").\n"; - exit(1); - } - for (size_t i = 0; i < nprocs(); i++) { - int hart_id = hartids.empty() ? i : hartids[i]; - procs[i] = new processor_t(&isa, varch, this, hart_id, halted, + procs[i] = new processor_t(&isa, varch, this, hartids[i], halted, log_file.get(), sout_); } diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 25d7c69..a3c18d1 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -458,6 +458,22 @@ int main(int argc, char** argv) } #endif + if (!hartids.empty()) { + if (cfg.nprocs.overridden() && (cfg.nprocs() != hartids.size())) { + std::cerr << "Number of specified hartids (" + << hartids.size() + << ") doesn't match specified number of processors (" + << cfg.nprocs() << ").\n"; + exit(1); + } + } else { + // Set default set of hartids based on nprocs + hartids.reserve(cfg.nprocs()); + for (size_t i = 0; i < cfg.nprocs(); ++i) { + hartids.push_back(i); + } + } + sim_t s(&cfg, varch, halted, real_time_clint, mems, plugin_devices, htif_args, std::move(hartids), dm_config, log_path, dtb_enabled, dtb_file, -- cgit v1.1