add I$/D$/L2$ simulators
[riscv-isa-sim.git] / riscv / sim.h
index 6d2ac9be43aa46ea5724bc4b357267e7a12f694d..aed4e87f67dc39db4db8f5b70dfafc6727ba9d7e 100644 (file)
@@ -4,43 +4,71 @@
 #include <vector>
 #include <string>
 #include "processor.h"
+#include "mmu.h"
 
-const int MEMSIZE = 0x7D000000;
+class htif_isasim_t;
 
+// this class encapsulates the processors and memory in a RISC-V machine.
 class sim_t
 {
 public:
-  sim_t(int _nprocs, size_t _memsz);
+  sim_t(int _nprocs, int mem_mb, const std::vector<std::string>& htif_args);
   ~sim_t();
-  void load_elf(const char* fn);
+
+  // run the simulation to completion
   void run(bool debug);
 
-private:
-  processor_t* procs;
-  int nprocs;
+  // deliver an IPI to a specific processor
+  void send_ipi(reg_t who);
 
-  char* mem;
-  size_t memsz;
+  // returns the number of processors in this simulator
+  size_t num_cores() { return procs.size(); }
+  processor_t* get_core(size_t i) { return procs[i]; }
 
-  void step_all(size_t n, size_t interleave, bool noisy);
+  // read one of the system control registers
+  reg_t get_scr(int which);
 
-  void interactive_quit(const std::vector<std::string>& args);
+private:
+  htif_isasim_t* htif;
 
-  void interactive_run(const std::vector<std::string>& args, bool noisy);
-  void interactive_run_noisy(const std::vector<std::string>& args);
-  void interactive_run_silent(const std::vector<std::string>& args);
+  // main memory, shared between processors
+  char* mem;
+  size_t memsz; // memory size in bytes
+  mmu_t* mmu; // debug port into main memory
+
+  // processors
+  std::vector<processor_t*> procs;
 
-  void interactive_run_proc(const std::vector<std::string>& args, bool noisy);
-  void interactive_run_proc_noisy(const std::vector<std::string>& args);
-  void interactive_run_proc_silent(const std::vector<std::string>& args);
+  // run each processor for n instructions; interleave instructions are
+  // run on a processor before moving on to the next processor.
+  // interleave must divide n.
+  // if noisy, print out the instructions as they execute.
+  void step_all(size_t n, size_t interleave, bool noisy);
 
-  void interactive_reg(const std::vector<std::string>& args);
-  void interactive_mem(const std::vector<std::string>& args);
-  void interactive_until(const std::vector<std::string>& args);
+  // presents a prompt for introspection into the simulation
+  void interactive();
 
+  // functions that help implement interactive()
+  void interactive_quit(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_run(const std::string& cmd, const std::vector<std::string>& args, bool noisy);
+  void interactive_run_noisy(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_run_silent(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_run_proc(const std::string& cmd, const std::vector<std::string>& args, bool noisy);
+  void interactive_run_proc_noisy(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_run_proc_silent(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_reg(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_fregs(const std::string& cmd, const std::vector<std::string>& args);
+  void interactive_fregd(const std::string& cmd, const std::vector<std::string>& args);
+  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_until(const std::string& cmd, const std::vector<std::string>& args);
   reg_t get_reg(const std::vector<std::string>& args);
+  reg_t get_freg(const std::vector<std::string>& args);
   reg_t get_mem(const std::vector<std::string>& args);
   reg_t get_pc(const std::vector<std::string>& args);
+  reg_t get_tohost(const std::vector<std::string>& args);
+
+  friend class htif_isasim_t;
 };
 
 #endif