Fix single step over csrw instructions. (#57)
authorTim Newsome <tim@sifive.com>
Wed, 13 Jul 2016 20:26:09 +0000 (13:26 -0700)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Wed, 13 Jul 2016 20:26:09 +0000 (13:26 -0700)
csrw instructions instantly return if the PC isn't serialized. Take note
of this, and don't enter debug mode until the instruction we just
executed actually completed.

riscv/execute.cc

index e2e72d69ef244fdd79836b2bbddd60af3017feee..20567afb078e332dc45aa0e0778c98c676d27d9b 100644 (file)
@@ -97,18 +97,22 @@ void processor_t::step(size_t n)
         {
           if (unlikely(state.single_step == state.STEP_STEPPING)) {
             state.single_step = state.STEP_STEPPED;
-          } else if (unlikely(state.single_step == state.STEP_STEPPED)) {
-            state.single_step = state.STEP_NONE;
-            enter_debug_mode(DCSR_CAUSE_STEP);
-            // enter_debug_mode changed state.pc, so we can't just continue.
-            break;
           }
 
           insn_fetch_t fetch = mmu->load_insn(pc);
           if (debug && !state.serialized)
             disasm(fetch.insn);
           pc = execute_insn(this, pc, fetch);
+          bool serialize_before = (pc == PC_SERIALIZE_BEFORE);
+
           advance_pc();
+
+          if (unlikely(state.single_step == state.STEP_STEPPED) && !serialize_before) {
+            state.single_step = state.STEP_NONE;
+            enter_debug_mode(DCSR_CAUSE_STEP);
+            // enter_debug_mode changed state.pc, so we can't just continue.
+            break;
+          }
         }
       }
       else while (instret < n)