Fix ERET serialization strategy
authorAndrew Waterman <waterman@cs.berkeley.edu>
Tue, 9 Feb 2016 07:29:41 +0000 (23:29 -0800)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Wed, 2 Mar 2016 20:15:25 +0000 (12:15 -0800)
It was screwing up the commit log.

riscv/decode.h
riscv/execute.cc
riscv/processor.cc

index f8437cae5f178c87c510f5aca039cf2b7c2e7069..f4d6b6ccddb8737a40cbcf64ec8445e5b3a45c83 100644 (file)
@@ -200,18 +200,21 @@ private:
 
 #define set_pc_and_serialize(x) \
   do { set_pc(x); /* check alignment */ \
-       npc = PC_SERIALIZE; \
+       npc = PC_SERIALIZE_AFTER; \
        STATE.pc = (x); \
      } while(0)
 
-#define PC_SERIALIZE 3 /* sentinel value indicating simulator pipeline flush */
+/* Sentinel PC values to serialize simulator pipeline */
+#define PC_SERIALIZE_BEFORE 3
+#define PC_SERIALIZE_AFTER 5
+#define invalid_pc(pc) ((pc) & 1)
 
 /* Convenience wrappers to simplify softfloat code sequences */
 #define f32(x) ((float32_t){(uint32_t)x})
 #define f64(x) ((float64_t){(uint64_t)x})
 
 #define validate_csr(which, write) ({ \
-  if (!STATE.serialized) return PC_SERIALIZE; \
+  if (!STATE.serialized) return PC_SERIALIZE_BEFORE; \
   STATE.serialized = false; \
   unsigned csr_priv = get_field((which), 0x300); \
   unsigned csr_read_only = get_field((which), 0xC00) == 3; \
index a2e71a166702c40b4311e576bde229c1d211782c..014055ba3ecc9f138d54deb959eaf55e4e1de689 100644 (file)
@@ -43,7 +43,7 @@ static reg_t execute_insn(processor_t* p, reg_t pc, insn_fetch_t fetch)
 {
   commit_log_stash_privilege(p->get_state());
   reg_t npc = fetch.func(p, fetch.insn, pc);
-  if (npc != PC_SERIALIZE) {
+  if (!invalid_pc(npc)) {
     commit_log_print_insn(p->get_state(), pc, fetch.insn);
     p->update_histogram(pc);
   }
@@ -59,9 +59,13 @@ void processor_t::step(size_t n)
     mmu_t* _mmu = mmu;
 
     #define advance_pc() \
-     if (unlikely(pc == PC_SERIALIZE)) { \
+     if (unlikely(invalid_pc(pc))) { \
+       switch (pc) { \
+         case PC_SERIALIZE_BEFORE: state.serialized = true; break; \
+         case PC_SERIALIZE_AFTER: instret++; break; \
+         default: abort(); \
+       } \
        pc = state.pc; \
-       state.serialized = true; \
        break; \
      } else { \
        state.pc = pc; \
@@ -70,7 +74,6 @@ void processor_t::step(size_t n)
 
     try
     {
-      check_timer();
       take_interrupt();
 
       if (unlikely(debug))
index a79ee7b635761a7d07d929b845e534c54e163a1f..15036615091f622bc2c870a7a53291306e89a833 100644 (file)
@@ -161,6 +161,8 @@ static int ctz(reg_t val)
 
 void processor_t::take_interrupt()
 {
+  check_timer();
+
   reg_t interrupts = state.mip & state.mie;
 
   reg_t m_interrupts = interrupts & ~state.mideleg;