Handle CSR permissions correctly
authorAndrew Waterman <waterman@eecs.berkeley.edu>
Fri, 24 Jan 2014 09:08:40 +0000 (01:08 -0800)
committerAndrew Waterman <waterman@eecs.berkeley.edu>
Fri, 24 Jan 2014 09:08:40 +0000 (01:08 -0800)
riscv/decode.h
riscv/processor.cc

index 4abd9f9c7cc61df60dbb7a7903fbd2a33a93f297..ceaf492f8ce7695e7139a06a5fdc30efbeff1244 100644 (file)
@@ -169,11 +169,12 @@ private:
      } while(0)
 
 #define validate_csr(which, write) ({ \
-  int write_priv = ((which) >> 10) & 3; \
-  int read_priv = ((which) >> 8) & 3; \
-  if ((which) == CSR_FCSR || (which) == CSR_FFLAGS || (which) == CSR_FRM) \
-    require_fp; \
-  if (read_priv > 0 || (write_priv > 0 && (write))) require_supervisor; \
+  unsigned my_priv = (p->get_state()->sr & SR_S) ? 1 : 0; \
+  unsigned read_priv = ((which) >> 10) & 3; \
+  unsigned write_priv = (((which) >> 8) & 3); \
+  if (read_priv == 3) read_priv = write_priv, write_priv = -1; \
+  if (my_priv < ((write) ? write_priv : read_priv)) \
+    throw trap_privileged_instruction(); \
   (which); })
 
 #endif
index 067288ce1bff25810408028a197079b51573e7b4..05fee796324440de4d3fcb7b38b2d67d8bfc060a 100644 (file)
@@ -318,6 +318,9 @@ reg_t processor_t::get_pcr(int which)
       return state.cause;
     case CSR_PTBR:
       return state.ptbr;
+    case CSR_SEND_IPI:
+    case CSR_CLEAR_IPI:
+      return 0;
     case CSR_ASID:
       return 0;
     case CSR_FATC:
@@ -338,7 +341,7 @@ reg_t processor_t::get_pcr(int which)
       sim->get_htif()->tick(); // not necessary, but faster
       return state.fromhost;
     default:
-      return -1;
+      throw trap_illegal_instruction();
   }
 }