Support RV32 RDTIMEH/RDCYCLEH/RDINSTRETH
authorAndrew Waterman <waterman@eecs.berkeley.edu>
Tue, 18 Mar 2014 21:38:07 +0000 (14:38 -0700)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Tue, 18 Mar 2014 21:38:07 +0000 (14:38 -0700)
riscv/encoding.h
riscv/insns/csrrc.h
riscv/insns/csrrci.h
riscv/insns/csrrs.h
riscv/insns/csrrsi.h
riscv/insns/csrrw.h
riscv/insns/csrrwi.h
riscv/processor.cc

index 55306997d3b5c318b82e16f4e637642a7d889601..6a56236b83847a0d985084aa21d5dc99b2295f68 100644 (file)
 #define CSR_UARCH13 0xccd
 #define CSR_UARCH14 0xcce
 #define CSR_UARCH15 0xccf
+#define CSR_COUNTH 0x586
+#define CSR_CYCLEH 0xc80
+#define CSR_TIMEH 0xc81
+#define CSR_INSTRETH 0xc82
 #define CAUSE_MISALIGNED_FETCH 0x0
 #define CAUSE_FAULT_FETCH 0x1
 #define CAUSE_ILLEGAL_INSTRUCTION 0x2
@@ -668,6 +672,10 @@ DECLARE_CSR(uarch12, CSR_UARCH12)
 DECLARE_CSR(uarch13, CSR_UARCH13)
 DECLARE_CSR(uarch14, CSR_UARCH14)
 DECLARE_CSR(uarch15, CSR_UARCH15)
+DECLARE_CSR(counth, CSR_COUNTH)
+DECLARE_CSR(cycleh, CSR_CYCLEH)
+DECLARE_CSR(timeh, CSR_TIMEH)
+DECLARE_CSR(instreth, CSR_INSTRETH)
 #endif
 #ifdef DECLARE_CAUSE
 DECLARE_CAUSE("fflags", CAUSE_FFLAGS)
@@ -712,4 +720,8 @@ DECLARE_CAUSE("uarch12", CAUSE_UARCH12)
 DECLARE_CAUSE("uarch13", CAUSE_UARCH13)
 DECLARE_CAUSE("uarch14", CAUSE_UARCH14)
 DECLARE_CAUSE("uarch15", CAUSE_UARCH15)
+DECLARE_CAUSE("counth", CAUSE_COUNTH)
+DECLARE_CAUSE("cycleh", CAUSE_CYCLEH)
+DECLARE_CAUSE("timeh", CAUSE_TIMEH)
+DECLARE_CAUSE("instreth", CAUSE_INSTRETH)
 #endif
index 8ca7c4173783806ed54e91389e658dc7216f93dd..b5d9e480cba6edae43cc44790f836dbf42e14e8d 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), true);
-WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) & ~RS1));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, p->get_pcr(csr) & ~RS1)));
index fc980569e61fbc28940e2bf6cb734744f4061a6d..6c6312535197d6757d0e464139fd60b9491111d9 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), true);
-WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) & ~(reg_t)insn.rs1()));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, p->get_pcr(csr) & ~(reg_t)insn.rs1())));
index 60ac6b3b650f148d2947373887cc72e5c588659a..ba315d41fa121c5f514ee5d83dba226e977de590 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), insn.rs1() != 0);
-WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) | RS1));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, p->get_pcr(csr) | RS1)));
index db6fcd05157365429c46e5dd79a6f044a6fe01b5..827d2d081c7268243bf77850de183fbe0ca424b5 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), true);
-WRITE_RD(p->set_pcr(csr, p->get_pcr(csr) | insn.rs1()));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, p->get_pcr(csr) | insn.rs1())));
index 4b16773d6cbc02dce6c20756412b322f4c983157..94793e2911879b020477f725a99af7db31ff3c30 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), true);
-WRITE_RD(p->set_pcr(csr, RS1));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, RS1)));
index ff20833782b59476502db4dae0c7f051222e1d4d..b8ec5f5f90d6c7797908c1fe28ea9e83ed478edf 100644 (file)
@@ -1,2 +1,2 @@
 int csr = validate_csr(insn.csr(), true);
-WRITE_RD(p->set_pcr(csr, insn.rs1()));
+WRITE_RD(sext_xprlen(p->set_pcr(csr, insn.rs1())));
index 39848b48c991d3440689bf91eb37aac6d171cd62..f47c8e50d03620f712c3e8ec922b9d1f3e147ba3 100644 (file)
@@ -233,12 +233,12 @@ reg_t processor_t::set_pcr(int which, reg_t val)
     case CSR_EVEC:
       state.evec = val & ~3;
       break;
-    case CSR_CYCLE:
-    case CSR_TIME:
-    case CSR_INSTRET:
     case CSR_COUNT:
       state.count = val;
       break;
+    case CSR_COUNTH:
+      state.count = (val << 32) | (uint32_t)state.count;
+      break;
     case CSR_COMPARE:
       set_interrupt(IRQ_TIMER, false);
       state.compare = val;
@@ -299,6 +299,13 @@ reg_t processor_t::get_pcr(int which)
     case CSR_INSTRET:
     case CSR_COUNT:
       return state.count;
+    case CSR_CYCLEH:
+    case CSR_TIMEH:
+    case CSR_INSTRETH:
+    case CSR_COUNTH:
+      if (rv64)
+        break;
+      return state.count >> 32;
     case CSR_COMPARE:
       return state.compare;
     case CSR_CAUSE:
@@ -327,9 +334,8 @@ reg_t processor_t::get_pcr(int which)
     case CSR_FROMHOST:
       sim->get_htif()->tick(); // not necessary, but faster
       return state.fromhost;
-    default:
-      throw trap_illegal_instruction();
   }
+  throw trap_illegal_instruction();
 }
 
 void processor_t::set_interrupt(int which, bool on)