aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChih-Min Chao <chihmin.chao@sifive.com>2020-04-23 19:19:29 -0700
committerChih-Min Chao <chihmin.chao@sifive.com>2020-05-19 19:56:53 -0700
commit1def3e9a740a609f4363c96c153ab96699a38671 (patch)
treea816d054464d308a1964bffe1560124ae5a2e240
parent877a8069db245018b8c2449cb44e76a48d216c5e (diff)
downloadriscv-isa-sim-1def3e9a740a609f4363c96c153ab96699a38671.zip
riscv-isa-sim-1def3e9a740a609f4363c96c153ab96699a38671.tar.gz
riscv-isa-sim-1def3e9a740a609f4363c96c153ab96699a38671.tar.bz2
fdt: restructure dtb create and config flow
1. pass dtb option from constructor 2. separate dtb generation from rom initialization 3. setup clint base from dtb Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
-rw-r--r--riscv/sim.cc53
-rw-r--r--riscv/sim.h14
-rw-r--r--spike_main/spike.cc4
3 files changed, 51 insertions, 20 deletions
diff --git a/riscv/sim.cc b/riscv/sim.cc
index ac527a8..18df394 100644
--- a/riscv/sim.cc
+++ b/riscv/sim.cc
@@ -34,14 +34,25 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch,
const std::vector<std::string>& args,
std::vector<int> const hartids,
const debug_module_config_t &dm_config,
- const char *log_path)
- : htif_t(args), mems(mems), plugin_devices(plugin_devices),
+ const char *log_path,
+ bool dtb_enabled, const char *dtb_file)
+ : htif_t(args),
+ mems(mems),
+ plugin_devices(plugin_devices),
procs(std::max(nprocs, size_t(1))),
- initrd_start(initrd_start), initrd_end(initrd_end), start_pc(start_pc),
+ initrd_start(initrd_start),
+ initrd_end(initrd_end),
+ start_pc(start_pc),
+ dtb_file(dtb_file ? dtb_file : ""),
+ dtb_enabled(dtb_enabled),
log_file(log_path),
- current_step(0), current_proc(0), debug(false), histogram_enabled(false),
- log(false), dtb_enabled(true),
- remote_bitbang(NULL), debug_module(this, dm_config)
+ current_step(0),
+ current_proc(0),
+ debug(false),
+ histogram_enabled(false),
+ log(false),
+ remote_bitbang(NULL),
+ debug_module(this, dm_config)
{
signal(SIGINT, &handle_signal);
@@ -69,8 +80,15 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch,
log_file.get());
}
+ make_dtb();
+
clint.reset(new clint_t(procs, CPU_HZ / INSNS_PER_RTC_TICK, real_time_clint));
- bus.add_device(CLINT_BASE, clint.get());
+ reg_t clint_base;
+ if (fdt_parse_clint((void *)dtb.c_str(), &clint_base, "riscv,clint0")) {
+ bus.add_device(CLINT_BASE, clint.get());
+ } else {
+ bus.add_device(clint_base, clint.get());
+ }
}
sim_t::~sim_t()
@@ -191,6 +209,25 @@ bool sim_t::mmio_store(reg_t addr, size_t len, const uint8_t* bytes)
void sim_t::make_dtb()
{
+ if (!dtb_file.empty()) {
+ std::ifstream fin(dtb_file.c_str(), std::ios::binary);
+ if (!fin.good()) {
+ std::cerr << "can't find dtb file: " << dtb_file << std::endl;
+ exit(-1);
+ }
+
+ std::stringstream strstream;
+ strstream << fin.rdbuf();
+
+ dtb = strstream.str();
+ } else {
+ dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, initrd_start, initrd_end, procs, mems);
+ dtb = dts_compile(dts);
+ }
+}
+
+void sim_t::set_rom()
+{
const int reset_vec_size = 8;
start_pc = start_pc == reg_t(-1) ? get_entry_point() : start_pc;
@@ -252,7 +289,7 @@ char* sim_t::addr_to_mem(reg_t addr) {
void sim_t::reset()
{
if (dtb_enabled)
- make_dtb();
+ set_rom();
}
void sim_t::idle()
diff --git a/riscv/sim.h b/riscv/sim.h
index 0cf518d..eee24e5 100644
--- a/riscv/sim.h
+++ b/riscv/sim.h
@@ -29,7 +29,8 @@ public:
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,
- const debug_module_config_t &dm_config, const char *log_path);
+ const debug_module_config_t &dm_config, const char *log_path,
+ bool dtb_enabled, const char *dtb_file);
~sim_t();
// run the simulation to completion
@@ -46,13 +47,6 @@ public:
void configure_log(bool enable_log, bool enable_commitlog);
void set_procs_debug(bool value);
- void set_dtb_enabled(bool value) {
- this->dtb_enabled = value;
- }
- void set_dtb_file(const char* value) {
- if (value)
- this->dtb_file = value;
- }
void set_remote_bitbang(remote_bitbang_t* remote_bitbang) {
this->remote_bitbang = remote_bitbang;
}
@@ -72,7 +66,9 @@ private:
reg_t initrd_end;
reg_t start_pc;
std::string dts;
+ std::string dtb;
std::string dtb_file;
+ bool dtb_enabled;
std::unique_ptr<rom_device_t> boot_rom;
std::unique_ptr<clint_t> clint;
bus_t bus;
@@ -88,7 +84,6 @@ private:
bool debug;
bool histogram_enabled; // provide a histogram of PCs
bool log;
- bool dtb_enabled;
remote_bitbang_t* remote_bitbang;
// memory-mapped I/O routines
@@ -96,6 +91,7 @@ private:
bool mmio_load(reg_t addr, size_t len, uint8_t* bytes);
bool mmio_store(reg_t addr, size_t len, const uint8_t* bytes);
void make_dtb();
+ void set_rom();
// presents a prompt for introspection into the simulation
void interactive();
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index d88f5b8..da3e22c 100644
--- a/spike_main/spike.cc
+++ b/spike_main/spike.cc
@@ -312,7 +312,7 @@ int main(int argc, char** argv)
sim_t s(isa, priv, varch, nprocs, halted, real_time_clint,
initrd_start, initrd_end, start_pc, mems, plugin_devices, htif_args,
- std::move(hartids), dm_config, log_path);
+ std::move(hartids), dm_config, log_path, dtb_enabled, dtb_file);
std::unique_ptr<remote_bitbang_t> remote_bitbang((remote_bitbang_t *) NULL);
std::unique_ptr<jtag_dtm_t> jtag_dtm(
new jtag_dtm_t(&s.debug_module, dmi_rti));
@@ -320,8 +320,6 @@ int main(int argc, char** argv)
remote_bitbang.reset(new remote_bitbang_t(rbb_port, &(*jtag_dtm)));
s.set_remote_bitbang(&(*remote_bitbang));
}
- s.set_dtb_enabled(dtb_enabled);
- s.set_dtb_file(dtb_file);
if (dump_dts) {
printf("%s", s.get_dts());