From 970466e6ebcf4957f131fde8b62ca10fb70b2bd6 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Thu, 24 Mar 2022 22:00:46 +0000 Subject: [PATCH] Move start_pc into cfg_t --- riscv/cfg.h | 2 ++ riscv/sim.cc | 5 ++--- riscv/sim.h | 3 +-- spike_main/spike.cc | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/riscv/cfg.h b/riscv/cfg.h index e844738b..1e08f80e 100644 --- a/riscv/cfg.h +++ b/riscv/cfg.h @@ -2,6 +2,7 @@ #ifndef _RISCV_CFG_H #define _RISCV_CFG_H +#include #include "decode.h" #include "mmu.h" #include @@ -70,6 +71,7 @@ public: cfg_arg_t isa; cfg_arg_t priv; cfg_arg_t> mem_layout; + std::optional start_pc; }; #endif diff --git a/riscv/sim.cc b/riscv/sim.cc index 90fa210a..4e3dd409 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -29,7 +29,7 @@ static void handle_signal(int sig) } sim_t::sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_clint, - reg_t start_pc, std::vector> mems, + std::vector> mems, std::vector> plugin_devices, const std::vector& args, std::vector const hartids, @@ -46,7 +46,6 @@ sim_t::sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_cl mems(mems), plugin_devices(plugin_devices), procs(std::max(cfg->nprocs(), size_t(1))), - start_pc(start_pc), dtb_file(dtb_file ? dtb_file : ""), dtb_enabled(dtb_enabled), log_file(log_path), @@ -334,7 +333,7 @@ void sim_t::set_rom() { const int reset_vec_size = 8; - start_pc = start_pc == reg_t(-1) ? get_entry_point() : start_pc; + reg_t start_pc = cfg->start_pc.value_or(get_entry_point()); uint32_t reset_vec[reset_vec_size] = { 0x297, // auipc t0,0x0 diff --git a/riscv/sim.h b/riscv/sim.h index fc20a2c8..6acc4409 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -33,7 +33,7 @@ class sim_t : public htif_t, public simif_t { public: sim_t(const cfg_t *cfg, const char* varch, bool halted, bool real_time_clint, - reg_t start_pc, std::vector> mems, + std::vector> mems, std::vector> plugin_devices, const std::vector& args, const std::vector hartids, const debug_module_config_t &dm_config, const char *log_path, @@ -76,7 +76,6 @@ private: mmu_t* debug_mmu; // debug port into main memory std::vector procs; std::pair initrd_range; - reg_t start_pc; std::string dts; std::string dtb; std::string dtb_file; diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 3080efbd..7791fbfc 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -232,7 +232,6 @@ int main(int argc, char** argv) bool real_time_clint = false; const char* kernel = NULL; reg_t kernel_offset, kernel_size; - reg_t start_pc = reg_t(-1); std::vector> plugin_devices; std::unique_ptr ic; std::unique_ptr dc; @@ -335,7 +334,7 @@ int main(int argc, char** argv) // I wanted to use --halted, but for some reason that doesn't work. parser.option('H', 0, 0, [&](const char* s){halted = true;}); parser.option(0, "rbb-port", 1, [&](const char* s){use_rbb = true; rbb_port = atoul_safe(s);}); - parser.option(0, "pc", 1, [&](const char* s){start_pc = strtoull(s, 0, 0);}); + parser.option(0, "pc", 1, [&](const char* s){cfg.start_pc = strtoull(s, 0, 0);}); parser.option(0, "hartids", 1, hartids_parser); parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));}); parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));}); @@ -457,7 +456,7 @@ int main(int argc, char** argv) #endif sim_t s(&cfg, varch, halted, real_time_clint, - start_pc, mems, plugin_devices, htif_args, + mems, plugin_devices, htif_args, std::move(hartids), dm_config, log_path, dtb_enabled, dtb_file, #ifdef HAVE_BOOST_ASIO io_service_ptr, acceptor_ptr,