diff options
author | Jerry Zhao <jerryz123@berkeley.edu> | 2023-12-03 17:13:36 -0800 |
---|---|---|
committer | Jerry Zhao <jerryz123@berkeley.edu> | 2023-12-03 17:13:36 -0800 |
commit | 5d641a31dfa4f1531781bb56d27c39f9ef47c441 (patch) | |
tree | 9203fcd892e975a50b212c6ddc38492a1c1787dc | |
parent | 10dd730785d56fe233e77b0e4183d45604c4967b (diff) | |
download | riscv-isa-sim-device_flags.zip riscv-isa-sim-device_flags.tar.gz riscv-isa-sim-device_flags.tar.bz2 |
Allow device flags after --device cmdline argdevice_flags
-rw-r--r-- | riscv/abstract_device.h | 6 | ||||
-rw-r--r-- | spike_main/spike.cc | 20 |
2 files changed, 22 insertions, 4 deletions
diff --git a/riscv/abstract_device.h b/riscv/abstract_device.h index f2a90fa..002e5a0 100644 --- a/riscv/abstract_device.h +++ b/riscv/abstract_device.h @@ -26,6 +26,12 @@ public: virtual abstract_device_t* parse_from_fdt(const void* fdt, const sim_t* sim, reg_t* base) const = 0; virtual std::string generate_dts(const sim_t* sim) const = 0; virtual ~device_factory_t() {} + virtual void set_flags(const std::string flags) { + if (flags.size() > 0) { + fprintf(stderr, "Flags were passed to a device_factory which does not support flags\n"); + exit(-1); + } + }; }; // Type for holding all registered MMIO plugins by name. diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 8fd9104..5b0f175 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -52,6 +52,7 @@ static void help(int exit_code = 1) fprintf(stderr, " --big-endian Use a big-endian memory system.\n"); fprintf(stderr, " --misaligned Support misaligned memory accesses\n"); fprintf(stderr, " --device=<name> Attach MMIO plugin device from an --extlib library\n"); + fprintf(stderr, " Device-specific flags can also be passed with --device=<name>,args\n"); fprintf(stderr, " --log-cache-miss Generate a log of cache miss\n"); fprintf(stderr, " --log-commits Generate a log of commits info\n"); fprintf(stderr, " --extension=<name> Specify RoCC Extension\n"); @@ -374,11 +375,22 @@ int main(int argc, char** argv) /*default_trigger_count=*/4); auto const device_parser = [&plugin_device_factories](const char *s) { - const std::string name(s); - if (name.empty()) throw std::runtime_error("Plugin name is empty."); - auto it = mmio_device_map().find(name); - if (it == mmio_device_map().end()) throw std::runtime_error("Plugin \"" + name + "\" not found in loaded extlibs."); + const std::string arg(s); + std::string device_name; + std::string device_flags; + size_t comma_idx = arg.find(','); + if (comma_idx != std::string::npos) { + device_name = arg; + device_flags = ""; + } else { + device_name = arg.substr(0, comma_idx); + device_flags = arg.substr(comma_idx + 1); + } + if (device_name.empty()) throw std::runtime_error("Plugin name is empty."); + auto it = mmio_device_map().find(device_name); + if (it == mmio_device_map().end()) throw std::runtime_error("Plugin \"" + device_name + "\" not found in loaded extlibs."); plugin_device_factories.push_back(it->second); + it->second->set_flags(device_flags); }; option_parser_t parser; |