aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRupert Swarbrick <rswarbrick@gmail.com>2022-04-11 10:47:50 +0100
committerRupert Swarbrick <rswarbrick@lowrisc.org>2022-04-12 11:10:35 +0100
commite4aaed1b7b08998a6b6aefa34f7c575e292dde62 (patch)
treeb3c521ba268aa52adfae14647c469ce15127bb8e
parent0d90f75dc4b5e28b2e3b3f35debaae1169c69d98 (diff)
downloadriscv-isa-sim-e4aaed1b7b08998a6b6aefa34f7c575e292dde62.zip
riscv-isa-sim-e4aaed1b7b08998a6b6aefa34f7c575e292dde62.tar.gz
riscv-isa-sim-e4aaed1b7b08998a6b6aefa34f7c575e292dde62.tar.bz2
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.
-rw-r--r--riscv/sim.cc13
-rw-r--r--spike_main/spike.cc16
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,