diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-08-26 19:58:09 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-08-26 19:58:09 -0700 |
commit | 08a6142a0413fe9c6aa86ce58a73f169ab030c7e (patch) | |
tree | 401b28351b3859c62f8f38c9041046146ad212b0 /machine/emulation.c | |
parent | f73dee6f2cc37cafc4b6949dac9ac2d71cf84d10 (diff) | |
download | pk-08a6142a0413fe9c6aa86ce58a73f169ab030c7e.zip pk-08a6142a0413fe9c6aa86ce58a73f169ab030c7e.tar.gz pk-08a6142a0413fe9c6aa86ce58a73f169ab030c7e.tar.bz2 |
Update to new counter spec
Diffstat (limited to 'machine/emulation.c')
-rw-r--r-- | machine/emulation.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/machine/emulation.c b/machine/emulation.c index ad74fb4..ae99908 100644 --- a/machine/emulation.c +++ b/machine/emulation.c @@ -88,37 +88,22 @@ void __attribute__((noinline)) truly_illegal_insn(uintptr_t* regs, uintptr_t mca static inline int emulate_read_csr(int num, uintptr_t mstatus, uintptr_t* result) { + uintptr_t counteren = + EXTRACT_FIELD(mstatus, MSTATUS_MPP) == PRV_U ? read_csr(mucounteren) : + read_csr(mscounteren); + switch (num) { case CSR_TIME: - *result = *mtime + HLS()->utime_delta; - return 0; - case CSR_CYCLE: - *result = read_csr(mcycle) + HLS()->ucycle_delta; - return 0; - case CSR_INSTRET: - *result = read_csr(minstret) + HLS()->uinstret_delta; - return 0; - case CSR_STIME: - *result = *mtime + HLS()->stime_delta; - return 0; - case CSR_SCYCLE: - *result = read_csr(mcycle) + HLS()->scycle_delta; - return 0; - case CSR_SINSTRET: - *result = read_csr(minstret) + HLS()->sinstret_delta; + if ((counteren >> (CSR_TIME - CSR_CYCLE)) & 1) + return -1; + *result = *mtime; return 0; #ifdef __riscv32 case CSR_TIMEH: - *result = (*mtime + HLS()->stime_delta) >> 32; - return 0; - case CSR_CYCLEH: - *result = (((uint64_t)read_csr(mcycleh) << 32) + read_csr(mcycle) - + HLS()->scycle_delta) >> 32; - return 0; - case CSR_INSTRETH: - *result = (((uint64_t)read_csr(minstreth) << 32) + read_csr(minstret) - + HLS()->sinstret_delta) >> 32; + if ((counteren >> (CSR_TIME - CSR_CYCLE)) & 1) + return -1; + *result = *mtime >> 32; return 0; #endif #if !defined(__riscv_hard_float) && defined(PK_ENABLE_FP_EMULATION) |