When gdb connects, jump to Debug ROM and segfault.
authorTim Newsome <tim@sifive.com>
Fri, 22 Apr 2016 22:10:23 +0000 (15:10 -0700)
committerTim Newsome <tim@sifive.com>
Mon, 23 May 2016 19:12:10 +0000 (12:12 -0700)
riscv/decode.h
riscv/execute.cc
riscv/gdbserver.cc
riscv/processor.cc
riscv/processor.h

index 784c71785e1ab83313ca832cc004989e5be7d6ad..d1254ee7289579d1b7fdab50d0ddb8c8a05353d0 100644 (file)
@@ -229,9 +229,14 @@ private:
  * automatically generated. */
 /* TODO */
 #include "/media/sf_tnewsome/Synced/SiFive/debug-spec/core_registers.tex.h"
+#define DCSR_CAUSE_NONE         0
 #define DCSR_CAUSE_SWBP         1
+#define DCSR_CAUSE_HWBP         2
+#define DCSR_CAUSE_DEBUGINT     3
+#define DCSR_CAUSE_STEPPED      4
 #define DCSR_CAUSE_HALT         5
 
-#define DEBUG_ROM_ENTRY         0x800
+#define DEBUG_RAM               0xfffffc00       // TODO: 0x400
+#define DEBUG_ROM_ENTRY         0xfffff800       // TODO: 0x800
 
 #endif
index 8b8c902b6603c26069b62657b826fe8e535579f9..1796c3884ba2a2d2761ddd7512dada25c7cd4b92 100644 (file)
@@ -53,6 +53,10 @@ static reg_t execute_insn(processor_t* p, reg_t pc, insn_fetch_t fetch)
 // fetch/decode/execute loop
 void processor_t::step(size_t n)
 {
+  if (state.dcsr.debugint && state.dcsr.cause == DCSR_CAUSE_NONE) {
+    enter_debug_mode(DCSR_CAUSE_DEBUGINT);
+  }
+
   while (n > 0) {
     size_t instret = 0;
     reg_t pc = state.pc;
index 0fe5365c805eea0e00ed1b9924b5a534914d7294..1d5c9ce2642b41452fa821531b35d46ed42b9b6c 100644 (file)
@@ -141,7 +141,7 @@ void gdbserver_t::accept()
 
     // gdb wants the core to be halted when it attaches.
     processor_t *p = sim->get_core(0);
-    // TODO p->set_halted(true, HR_ATTACHED);
+    p->set_debug_int();
   }
 }
 
index df9a724056ecdc26f4c5f7dd38d0a808ef1ea539..4ef8e0216ce88449d64be63bc45b55282bd53fbf 100644 (file)
@@ -119,6 +119,11 @@ void state_t::reset()
   load_reservation = -1;
 }
 
+void processor_t::set_debug_int()
+{
+  state.dcsr.debugint = true;
+}
+
 void processor_t::set_debug(bool value)
 {
   debug = value;
index 8ac8507c8705998480fcbe1dadedffbbb1117da7..1eabee4fabdbb5c511b233eeb8bb14c0933a6cd0 100644 (file)
@@ -90,15 +90,6 @@ struct state_t
 #endif
 };
 
-typedef enum {
-      HR_NONE,
-      HR_STEPPED,       // A single step was completed
-      HR_SWBP,          // sbreak was executed
-      HR_INTERRUPT,     // Execution interrupted by debugger
-      HR_CMDLINE,       // Command line requested that the processor start halted
-      HR_ATTACHED       // Halted because a debugger attached
-} halt_reason_t;
-
 // this class represents one processor in a RISC-V machine.
 class processor_t : public abstract_device_t
 {
@@ -106,6 +97,7 @@ public:
   processor_t(const char* isa, sim_t* sim, uint32_t id);
   ~processor_t();
 
+  void set_debug_int();
   void set_debug(bool value);
   void set_histogram(bool value);
   void reset(bool value);