diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-02-19 00:02:11 +0000 |
---|---|---|
committer | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-03-18 15:30:41 +0000 |
commit | b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735 (patch) | |
tree | a5c2f32b7c7996732f72b8142971610eb68f2a67 /riscv | |
parent | 1fea2afbf46d2641d77f2db3d6108e0897431a84 (diff) | |
download | spike-b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735.zip spike-b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735.tar.gz spike-b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735.tar.bz2 |
Initial step towards factoring out command line configuration
This commit defines a "cfg_t" structure, which currently just holds
the initrd address range. It will be augmented in future commits to
hold other configuration arguments as well.
To represent a configuration argument, we define an arg_t base class.
This holds a current value, together with a flag that tells us whether
the value has been updated from the default. The idea is that in
future we're going to use that flag when reading a DTB file: if an
argument has actually been specified on the command line, we need to
take it into account; if not, we can ignore the default and use the
DTB file's supplied value.
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/cfg.h | 38 | ||||
-rw-r--r-- | riscv/riscv.mk.in | 1 | ||||
-rw-r--r-- | riscv/sim.cc | 14 | ||||
-rw-r--r-- | riscv/sim.h | 11 |
4 files changed, 53 insertions, 11 deletions
diff --git a/riscv/cfg.h b/riscv/cfg.h new file mode 100644 index 0000000..bee5051 --- /dev/null +++ b/riscv/cfg.h @@ -0,0 +1,38 @@ +// See LICENSE for license details. +#ifndef _RISCV_CFG_H +#define _RISCV_CFG_H + +#include "decode.h" + +template <typename T> +class cfg_arg_t { +public: + cfg_arg_t(T default_val) + : value(default_val), was_set(false) {} + + bool overridden() const { return was_set; } + + T operator()() const { return value; } + + T operator=(const T v) { + value = v; + was_set = true; + return value; + } + +private: + T value; + bool was_set; +}; + +class cfg_t +{ +public: + cfg_t(std::pair<reg_t, reg_t> default_initrd_bounds) + : initrd_bounds(default_initrd_bounds) + {} + + cfg_arg_t<std::pair<reg_t, reg_t>> initrd_bounds; +}; + +#endif diff --git a/riscv/riscv.mk.in b/riscv/riscv.mk.in index a160bb8..a803b2a 100644 --- a/riscv/riscv.mk.in +++ b/riscv/riscv.mk.in @@ -14,6 +14,7 @@ riscv_hdrs = \ devices.h \ dts.h \ mmu.h \ + cfg.h \ processor.h \ sim.h \ simif.h \ diff --git a/riscv/sim.cc b/riscv/sim.cc index 064a493..9bfa17a 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -28,9 +28,9 @@ static void handle_signal(int sig) signal(sig, &handle_signal); } -sim_t::sim_t(const char* isa_string, const char* priv, const char* varch, - size_t nprocs, bool halted, bool real_time_clint, - reg_t initrd_start, reg_t initrd_end, const char* bootargs, +sim_t::sim_t(const cfg_t *cfg, + const char* isa_string, const char* priv, const char* varch, + size_t nprocs, bool halted, bool real_time_clint, const char* bootargs, reg_t start_pc, std::vector<std::pair<reg_t, mem_t*>> mems, std::vector<std::pair<reg_t, abstract_device_t*>> plugin_devices, const std::vector<std::string>& args, @@ -44,11 +44,10 @@ sim_t::sim_t(const char* isa_string, const char* priv, const char* varch, FILE *cmd_file) // needed for command line option --cmd : htif_t(args), isa(isa_string, priv), + cfg(cfg), mems(mems), plugin_devices(plugin_devices), procs(std::max(nprocs, size_t(1))), - initrd_start(initrd_start), - initrd_end(initrd_end), bootargs(bootargs), start_pc(start_pc), dtb_file(dtb_file ? dtb_file : ""), @@ -312,7 +311,10 @@ void sim_t::make_dtb() dtb = strstream.str(); } else { - dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, initrd_start, initrd_end, bootargs, procs, mems); + std::pair<reg_t, reg_t> initrd_bounds = cfg->initrd_bounds(); + dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, + initrd_bounds.first, initrd_bounds.second, + bootargs, procs, mems); dtb = dts_compile(dts); } diff --git a/riscv/sim.h b/riscv/sim.h index 518d75e..31c9254 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -11,6 +11,7 @@ #include <boost/asio.hpp> #endif +#include "cfg.h" #include "debug_module.h" #include "devices.h" #include "log_file.h" @@ -31,9 +32,9 @@ class remote_bitbang_t; class sim_t : public htif_t, public simif_t { public: - sim_t(const char* isa, const char* priv, const char* varch, size_t _nprocs, - bool halted, bool real_time_clint, - reg_t initrd_start, reg_t initrd_end, const char* bootargs, + sim_t(const cfg_t *cfg, + const char* isa, const char* priv, const char* varch, size_t _nprocs, + bool halted, bool real_time_clint, const char* bootargs, reg_t start_pc, std::vector<std::pair<reg_t, mem_t*>> mems, std::vector<std::pair<reg_t, abstract_device_t*>> plugin_devices, const std::vector<std::string>& args, const std::vector<int> hartids, @@ -71,12 +72,12 @@ public: private: isa_parser_t isa; + const cfg_t * const cfg; std::vector<std::pair<reg_t, mem_t*>> mems; std::vector<std::pair<reg_t, abstract_device_t*>> plugin_devices; mmu_t* debug_mmu; // debug port into main memory std::vector<processor_t*> procs; - reg_t initrd_start; - reg_t initrd_end; + std::pair<reg_t, reg_t> initrd_range; const char* bootargs; reg_t start_pc; std::string dts; |