aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Zhao <jerryz123@berkeley.edu>2022-10-14 13:40:56 -0700
committerAndrew Waterman <aswaterman@gmail.com>2022-10-16 15:28:35 -0700
commit03be4ae6c7b8e9865083b61427ff9724c7706fcf (patch)
tree2acb7760d9fab257bf2de7b4e0b04d83f72f5d16
parent5cf439b24e945db47edf6e259044c923384ccdfd (diff)
downloadspike-03be4ae6c7b8e9865083b61427ff9724c7706fcf.zip
spike-03be4ae6c7b8e9865083b61427ff9724c7706fcf.tar.gz
spike-03be4ae6c7b8e9865083b61427ff9724c7706fcf.tar.bz2
Add interactive mode commands to read clint mtime/mtimecmp
-rw-r--r--riscv/devices.h2
-rw-r--r--riscv/interactive.cc23
-rw-r--r--riscv/sim.h2
3 files changed, 27 insertions, 0 deletions
diff --git a/riscv/devices.h b/riscv/devices.h
index 8907b87..08e9c45 100644
--- a/riscv/devices.h
+++ b/riscv/devices.h
@@ -59,6 +59,8 @@ class clint_t : public abstract_device_t {
bool store(reg_t addr, size_t len, const uint8_t* bytes);
size_t size() { return CLINT_SIZE; }
void increment(reg_t inc);
+ uint64_t get_mtimecmp(reg_t hartid) { return mtimecmp[hartid]; }
+ uint64_t get_mtime() { return mtime; }
private:
typedef uint64_t mtime_t;
typedef uint64_t mtimecmp_t;
diff --git a/riscv/interactive.cc b/riscv/interactive.cc
index ffc706b..cf95bf6 100644
--- a/riscv/interactive.cc
+++ b/riscv/interactive.cc
@@ -315,6 +315,8 @@ void sim_t::interactive()
funcs["pc"] = &sim_t::interactive_pc;
funcs["mem"] = &sim_t::interactive_mem;
funcs["str"] = &sim_t::interactive_str;
+ funcs["mtime"] = &sim_t::interactive_mtime;
+ funcs["mtimecmp"] = &sim_t::interactive_mtimecmp;
funcs["until"] = &sim_t::interactive_until_silent;
funcs["untiln"] = &sim_t::interactive_until_noisy;
funcs["while"] = &sim_t::interactive_until_silent;
@@ -397,6 +399,8 @@ void sim_t::interactive_help(const std::string& cmd, const std::vector<std::stri
"mem [core] <hex addr> # Show contents of virtual memory <hex addr> in [core] (physical memory <hex addr> if omitted)\n"
"str [core] <hex addr> # Show NUL-terminated C string at virtual address <hex addr> in [core] (physical address <hex addr> if omitted)\n"
"dump # Dump physical memory to binary files\n"
+ "mtime # Show mtime\n"
+ "mtimecmp <core> # Show mtimecmp for <core>\n"
"until reg <core> <reg> <val> # Stop when <reg> in <core> hits <val>\n"
"untiln reg <core> <reg> <val> # Run noisy and stop when <reg> in <core> hits <val>\n"
"until pc <core> <val> # Stop when PC in <core> hits <val>\n"
@@ -788,3 +792,22 @@ void sim_t::interactive_dumpmems(const std::string& cmd, const std::vector<std::
mem_file.close();
}
}
+
+void sim_t::interactive_mtime(const std::string& cmd, const std::vector<std::string>& args)
+{
+ std::ostream out(sout_.rdbuf());
+ out << std::hex << std::setfill('0') << "0x" << std::setw(16)
+ << clint->get_mtime() << std::endl;
+}
+
+void sim_t::interactive_mtimecmp(const std::string& cmd, const std::vector<std::string>& args)
+{
+ if (args.size() != 1)
+ throw trap_interactive();
+
+ processor_t *p = get_core(args[0]);
+ std::ostream out(sout_.rdbuf());
+ out << std::hex << std::setfill('0') << "0x" << std::setw(16)
+ << clint->get_mtimecmp(p->get_id()) << std::endl;
+}
+
diff --git a/riscv/sim.h b/riscv/sim.h
index 5787d5d..c7dbd47 100644
--- a/riscv/sim.h
+++ b/riscv/sim.h
@@ -137,6 +137,8 @@ private:
void interactive_mem(const std::string& cmd, const std::vector<std::string>& args);
void interactive_str(const std::string& cmd, const std::vector<std::string>& args);
void interactive_dumpmems(const std::string& cmd, const std::vector<std::string>& args);
+ void interactive_mtime(const std::string& cmd, const std::vector<std::string>& args);
+ void interactive_mtimecmp(const std::string& cmd, const std::vector<std::string>& args);
void interactive_until(const std::string& cmd, const std::vector<std::string>& args, bool noisy);
void interactive_until_silent(const std::string& cmd, const std::vector<std::string>& args);
void interactive_until_noisy(const std::string& cmd, const std::vector<std::string>& args);