aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--riscv/encoding.h12
-rw-r--r--riscv/entropy_source.h57
-rw-r--r--riscv/processor.cc25
3 files changed, 27 insertions, 67 deletions
diff --git a/riscv/encoding.h b/riscv/encoding.h
index fa30993..2c331a6 100644
--- a/riscv/encoding.h
+++ b/riscv/encoding.h
@@ -1035,10 +1035,6 @@
#define MASK_FCVT_H_L 0xfff0007f
#define MATCH_FCVT_H_LU 0xd4300053
#define MASK_FCVT_H_LU 0xfff0007f
-#define MATCH_POLLENTROPY 0xf1500073
-#define MASK_POLLENTROPY 0xfffff07f
-#define MATCH_GETNOISE 0x7a900073
-#define MASK_GETNOISE 0xfffff07f
#define MATCH_SM4ED 0x30000033
#define MASK_SM4ED 0x3e00707f
#define MATCH_SM4KS 0x34000033
@@ -3013,8 +3009,7 @@
#define CSR_MARCHID 0xf12
#define CSR_MIMPID 0xf13
#define CSR_MHARTID 0xf14
-#define CSR_MENTROPY 0xf15
-#define CSR_MNOISE 0x7a9
+#define CSR_SENTROPY 0x546
#define CSR_HTIMEDELTAH 0x615
#define CSR_CYCLEH 0xc80
#define CSR_TIMEH 0xc81
@@ -3477,8 +3472,6 @@ DECLARE_INSN(fcvt_l_h, MATCH_FCVT_L_H, MASK_FCVT_L_H)
DECLARE_INSN(fcvt_lu_h, MATCH_FCVT_LU_H, MASK_FCVT_LU_H)
DECLARE_INSN(fcvt_h_l, MATCH_FCVT_H_L, MASK_FCVT_H_L)
DECLARE_INSN(fcvt_h_lu, MATCH_FCVT_H_LU, MASK_FCVT_H_LU)
-DECLARE_INSN(pollentropy, MATCH_POLLENTROPY, MASK_POLLENTROPY)
-DECLARE_INSN(getnoise, MATCH_GETNOISE, MASK_GETNOISE)
DECLARE_INSN(sm4ed, MATCH_SM4ED, MASK_SM4ED)
DECLARE_INSN(sm4ks, MATCH_SM4KS, MASK_SM4KS)
DECLARE_INSN(sm3p0, MATCH_SM3P0, MASK_SM3P0)
@@ -4573,8 +4566,7 @@ DECLARE_CSR(mvendorid, CSR_MVENDORID)
DECLARE_CSR(marchid, CSR_MARCHID)
DECLARE_CSR(mimpid, CSR_MIMPID)
DECLARE_CSR(mhartid, CSR_MHARTID)
-DECLARE_CSR(mentropy, CSR_MENTROPY)
-DECLARE_CSR(mnoise, CSR_MNOISE)
+DECLARE_CSR(sentropy, CSR_SENTROPY)
DECLARE_CSR(htimedeltah, CSR_HTIMEDELTAH)
DECLARE_CSR(cycleh, CSR_CYCLEH)
DECLARE_CSR(timeh, CSR_TIMEH)
diff --git a/riscv/entropy_source.h b/riscv/entropy_source.h
index 7b4635f..8ae3ddd 100644
--- a/riscv/entropy_source.h
+++ b/riscv/entropy_source.h
@@ -11,10 +11,10 @@ class entropy_source {
public:
- // Valid return codes for OPST bits [31:30] when reading mentropy.
+ // Valid return codes for OPST bits [31:30] when reading sentropy.
static const uint32_t OPST_BIST = 0x0 << 30;
- static const uint32_t OPST_ES16 = 0x1 << 30;
- static const uint32_t OPST_WAIT = 0x2 << 30;
+ static const uint32_t OPST_WAIT = 0x1 << 30;
+ static const uint32_t OPST_ES16 = 0x2 << 30;
static const uint32_t OPST_DEAD = 0x3 << 30;
//
@@ -27,27 +27,28 @@ public:
}
//
- // mentropy register
+ // sentropy register
// ------------------------------------------------------------
- void set_mentropy(reg_t val) {
- // Always ignore writes to mentropy.
- // This CSR *must never* accept write values, it is strictly read only.
+ void set_sentropy(reg_t val) {
+ // Always ignore writes to sentropy.
+ // This CSR is strictly read only. It occupies a RW CSR address
+ // to handle the side-effect of the changing seed value on a read.
}
//
- // The format of mentropy is described in Table 3 / Section 4.1 of
+ // The format of sentropy is described in Section 4.1 of
// the scalar cryptography specification.
- reg_t get_mentropy() {
+ reg_t get_sentropy() {
uint32_t result = 0;
- // Currently, always return ES16 (i.e. good randomness) unless in
- // noise capture mode. In the future, we can more realistically model
- // things like WAIT states, BIST warm up and maybe scriptable entry
- // into the DEAD state, but until then, this is the bare minimum.
- uint32_t return_status = noise_capture_mode ? OPST_BIST : OPST_ES16;
+ // Currently, always return ES16 (i.e. good randomness) In the future, we
+ // can more realistically model things like WAIT states, BIST warm up and
+ // maybe scriptable entry into the DEAD state, but until then, this is
+ // the bare minimum.
+ uint32_t return_status = OPST_ES16;
if(return_status == OPST_ES16) {
@@ -83,37 +84,9 @@ public:
}
//
- // mnoise register
- // ------------------------------------------------------------
-
-
- void set_mnoise(reg_t val) {
- // Almost all of the behaviour for mnoise is vendor specific,
- // except for bit 31.
- int new_noisemode = (val >> 31) & 0x1;
- noise_capture_mode = new_noisemode == 1;
- }
-
-
- reg_t get_mnoise() {
- reg_t to_return = 0;
-
- if(this -> noise_capture_mode) {
- // Set bit 31 indicating we are in noise capture mode.
- to_return |= 0x1 << 31;
- }
-
- return to_return;
- }
-
- //
// Utility / support variables and functions.
// ------------------------------------------------------------
- // The ES is in noise capture mode?
- // If so, then get_mentropy must always return OPST_BIST.
- bool noise_capture_mode = false;
-
// The file to read entropy from.
std::string randomness_source = "/dev/urandom";
diff --git a/riscv/processor.cc b/riscv/processor.cc
index 655dd18..309f4da 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -905,11 +905,8 @@ void processor_t::set_csr(int which, reg_t val)
switch (which)
{
- case CSR_MENTROPY:
- es.set_mentropy(val);
- break;
- case CSR_MNOISE:
- es.set_mnoise(val);
+ case CSR_SENTROPY:
+ es.set_sentropy(val);
break;
case CSR_FFLAGS:
dirty_fp_state;
@@ -1396,8 +1393,7 @@ void processor_t::set_csr(int which, reg_t val)
case CSR_DPC:
case CSR_DSCRATCH0:
case CSR_DSCRATCH1:
- case CSR_MENTROPY:
- case CSR_MNOISE:
+ case CSR_SENTROPY:
LOG_CSR(which);
break;
}
@@ -1462,14 +1458,13 @@ reg_t processor_t::get_csr(int which, insn_t insn, bool write, bool peek)
switch (which)
{
- case CSR_MENTROPY:
- if(!supports_extension('K'))
- break;
- ret(es.get_mentropy());
- case CSR_MNOISE:
- if(!supports_extension('K'))
- break;
- ret(es.get_mnoise());
+ case CSR_SENTROPY:
+ if (!supports_extension('K'))
+ break;
+ /* Read-only access disallowed due to wipe-on-read side effect */
+ if (!write)
+ break;
+ ret(es.get_sentropy());
case CSR_FFLAGS:
require_fp;
if (!supports_extension('F'))