Zero-extend all CSR writes
authorAndrew Waterman <waterman@cs.berkeley.edu>
Tue, 9 Feb 2016 22:26:06 +0000 (14:26 -0800)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Wed, 2 Mar 2016 20:15:25 +0000 (12:15 -0800)
This fixes an RV32 HTIF issue.

riscv/processor.cc

index 15036615091f622bc2c870a7a53291306e89a833..b1980c60630c0d43e8182fb8401b9a05245e2903 100644 (file)
@@ -255,6 +255,7 @@ static bool validate_vm(int max_xlen, reg_t vm)
 
 void processor_t::set_csr(int which, reg_t val)
 {
+  val = zext_xlen(val);
   reg_t all_ints = MIP_SSIP | MIP_MSIP | MIP_STIP | MIP_MTIP | (1UL << IRQ_HOST);
   reg_t s_ints = MIP_SSIP | MIP_STIP;
   switch (which)
@@ -283,7 +284,7 @@ void processor_t::set_csr(int which, reg_t val)
     case CSR_TIMEW:
       val -= sim->rtc;
       if (xlen == 32)
-        state.sutime_delta = (uint32_t)val | (state.sutime_delta >> 32 << 32);
+        state.sutime_delta = val | (state.sutime_delta >> 32 << 32);
       else
         state.sutime_delta = val;
       break;
@@ -295,7 +296,7 @@ void processor_t::set_csr(int which, reg_t val)
     case CSR_INSTRETW:
       val -= state.minstret;
       if (xlen == 32)
-        state.suinstret_delta = (uint32_t)val | (state.suinstret_delta >> 32 << 32);
+        state.suinstret_delta = val | (state.suinstret_delta >> 32 << 32);
       else
         state.suinstret_delta = val;
       break;
@@ -371,7 +372,7 @@ void processor_t::set_csr(int which, reg_t val)
     }
     case CSR_SEPC: state.sepc = val; break;
     case CSR_STVEC: state.stvec = val >> 2 << 2; break;
-    case CSR_SPTBR: state.sptbr = zext_xlen(val & -PGSIZE); break;
+    case CSR_SPTBR: state.sptbr = val & -PGSIZE; break;
     case CSR_SSCRATCH: state.sscratch = val; break;
     case CSR_SCAUSE: state.scause = val; break;
     case CSR_SBADADDR: state.sbadaddr = val; break;