Don't overload illegal instruction trap in interactive code
[riscv-isa-sim.git] / riscv / interactive.cc
index 69f2461d69be40f5f497858df583b88358085910..623c425c7f7f85b63f5a6eeb29506ae2f58de6ef 100644 (file)
@@ -4,7 +4,6 @@
 #include "disasm.h"
 #include "sim.h"
 #include "mmu.h"
-#include "htif.h"
 #include <sys/mman.h>
 #include <termios.h>
 #include <map>
 #include <vector>
 #include <algorithm>
 
+DECLARE_TRAP(-1, interactive)
+
 processor_t *sim_t::get_core(const std::string& i)
 {
   char *ptr;
   unsigned long p = strtoul(i.c_str(), &ptr, 10);
   if (*ptr || p >= num_cores())
-    throw trap_illegal_instruction();
+    throw trap_interactive();
   return get_core(p);
 }
 
@@ -77,7 +78,7 @@ void sim_t::interactive()
   funcs["help"] = &sim_t::interactive_help;
   funcs["h"] = funcs["help"];
 
-  while (!htif->done())
+  while (!done())
   {
     std::cerr << ": " << std::flush;
     std::string s = readline(2);
@@ -100,6 +101,8 @@ void sim_t::interactive()
     {
       if(funcs.count(cmd))
         (this->*funcs[cmd])(cmd, args);
+      else
+        fprintf(stderr, "Unknown command %s\n", cmd.c_str());
     }
     catch(trap_t t) {}
   }
@@ -148,7 +151,7 @@ void sim_t::interactive_run(const std::string& cmd, const std::vector<std::strin
   size_t steps = args.size() ? atoll(args[0].c_str()) : -1;
   ctrlc_pressed = false;
   set_procs_debug(noisy);
-  for (size_t i = 0; i < steps && !ctrlc_pressed && !htif->done(); i++)
+  for (size_t i = 0; i < steps && !ctrlc_pressed && !done(); i++)
     step(1);
 }
 
@@ -160,7 +163,7 @@ void sim_t::interactive_quit(const std::string& cmd, const std::vector<std::stri
 reg_t sim_t::get_pc(const std::vector<std::string>& args)
 {
   if(args.size() != 1)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   processor_t *p = get_core(args[0]);
   return p->state.pc;
@@ -174,7 +177,7 @@ void sim_t::interactive_pc(const std::string& cmd, const std::vector<std::string
 reg_t sim_t::get_reg(const std::vector<std::string>& args)
 {
   if(args.size() != 2)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   processor_t *p = get_core(args[0]);
 
@@ -191,7 +194,7 @@ reg_t sim_t::get_reg(const std::vector<std::string>& args)
   }
 
   if (r >= NXPR)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   return p->state.XPR[r];
 }
@@ -199,14 +202,14 @@ reg_t sim_t::get_reg(const std::vector<std::string>& args)
 reg_t sim_t::get_freg(const std::vector<std::string>& args)
 {
   if(args.size() != 2)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   processor_t *p = get_core(args[0]);
   int r = std::find(fpr_name, fpr_name + NFPR, args[1]) - fpr_name;
   if (r == NFPR)
     r = atoi(args[1].c_str());
   if (r >= NFPR)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   return p->state.FPR[r];
 }
@@ -250,7 +253,7 @@ void sim_t::interactive_fregd(const std::string& cmd, const std::vector<std::str
 reg_t sim_t::get_mem(const std::vector<std::string>& args)
 {
   if(args.size() != 1 && args.size() != 2)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   std::string addr_str = args[0];
   mmu_t* mmu = debug_mmu;
@@ -292,7 +295,7 @@ void sim_t::interactive_mem(const std::string& cmd, const std::vector<std::strin
 void sim_t::interactive_str(const std::string& cmd, const std::vector<std::string>& args)
 {
   if(args.size() != 1)
-    throw trap_illegal_instruction();
+    throw trap_interactive();
 
   reg_t addr = strtol(args[0].c_str(),NULL,16);