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 /spike_main | |
parent | 1fea2afbf46d2641d77f2db3d6108e0897431a84 (diff) | |
download | riscv-isa-sim-b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735.zip riscv-isa-sim-b742ddc66fd4ccb6cec98cbd8ebb705fe93ca735.tar.gz riscv-isa-sim-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 'spike_main')
-rw-r--r-- | spike_main/spike.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc index efef96d..6fb952d 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -1,5 +1,6 @@ // See LICENSE for license details. +#include "cfg.h" #include "sim.h" #include "mmu.h" #include "remote_bitbang.h" @@ -221,8 +222,6 @@ int main(int argc, char** argv) size_t nprocs = 1; const char* kernel = NULL; reg_t kernel_offset, kernel_size; - size_t initrd_size; - reg_t initrd_start = 0, initrd_end = 0; const char* bootargs = NULL; reg_t start_pc = reg_t(-1); std::vector<std::pair<reg_t, mem_t*>> mems; @@ -254,6 +253,7 @@ int main(int argc, char** argv) .support_impebreak = true }; std::vector<int> hartids; + cfg_t cfg(/*default_initrd_bounds=*/std::make_pair((reg_t)0, (reg_t)0)); auto const hartids_parser = [&](const char *s) { std::string const str(s); @@ -409,11 +409,12 @@ int main(int argc, char** argv) } if (initrd && check_file_exists(initrd)) { - initrd_size = get_file_size(initrd); + size_t initrd_size = get_file_size(initrd); for (auto& m : mems) { if (initrd_size && (initrd_size + 0x1000) < m.second->size()) { - initrd_end = m.first + m.second->size() - 0x1000; - initrd_start = initrd_end - initrd_size; + reg_t initrd_end = m.first + m.second->size() - 0x1000; + reg_t initrd_start = initrd_end - initrd_size; + cfg.initrd_bounds = std::make_pair(initrd_start, initrd_end); read_file_bytes(initrd, 0, m.second, initrd_start - m.first, initrd_size); break; } @@ -443,8 +444,8 @@ int main(int argc, char** argv) } #endif - sim_t s(isa, priv, varch, nprocs, halted, real_time_clint, - initrd_start, initrd_end, bootargs, start_pc, mems, plugin_devices, htif_args, + sim_t s(&cfg, isa, priv, varch, nprocs, halted, real_time_clint, + bootargs, start_pc, 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, |