target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
PATCH 1/1 target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
From: Jonathan Behrens <[email protected]>
QEMU currently always triggers an illegal instruction exception when code
attempts to read the time CSR. This is valid behavor, but only if the TM bit in
mcounteren is hardwired to zero. This change also corrects mcounteren and scounteren CSRs to be 32-bits on both 32-bit and 64-bit targets.
--- target/riscv/cpu.h | 4 ++-- target/riscv/csr.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
target/riscv/cpu.h +2 -2
@@ -151,8 +151,8 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ -target_ulong scounteren; -target_ulong mcounteren; +uint32_t scounteren; +uint32_t mcounteren;target_ulong sscratch;target_ulong mscratch;
target/riscv/csr.c +2 -1
@@ -473,7 +473,8 @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)if (env->priv_ver <PRIV_VERSION_1_10_0 ) {return -1 ; } - env->mcounteren = val; +/* mcounteren.TM is hardwired to zero, all other bits are writable */ + env->mcounteren = val & ~(1 << (CSR_TIME &31 ));return 0 ; }
Signature · 1 line
2.22.0
Quoted 7 lines · On Fri, Jun 28, 2019 at 1:12 PM <[email protected]> wrote:
From: Jonathan Behrens <[email protected]>
QEMU currently always triggers an illegal instruction exception when code
attempts to read the time CSR. This is valid behavor, but only if the TM bit in
mcounteren is hardwired to zero. This change also corrects mcounteren and scounteren CSRs to be 32-bits on both 32-bit and 64-bit targets.
Thanks for the patch.
Can you wrap your commit message at ~70 lines?
Quoted 27 lines
Signed-off-by Jonathan Behrens <[email protected]>--- target/riscv/cpu.h | 4 ++-- target/riscv/csr.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)target/riscv/cpu.h +2
-2@@ -151,8 +151,8 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ -target_ulong scounteren; -target_ulong mcounteren; +uint32_t scounteren; +uint32_t mcounteren;target_ulong sscratch;target_ulong mscratch;target/riscv/csr.c +0
-0
target/riscv/csr.c static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) · line 477
Quoted 6 lines
target/riscv/csr.c +2
-1@@ -473,7 +473,8 @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)if (env->priv_ver <PRIV_VERSION_1_10_0 ) {return -1 ; } - env->mcounteren = val; +/* mcounteren.TM is hardwired to zero, all other bits are writable */ + env->mcounteren = val & ~(1 << (CSR_TIME &31 ));
Isn't CSR_TIME & 31 just 0? Can this just be changed 1 << 1 or even better add a macro?
Otherwise this patch looks good :)
Alistair
Quoted 6 lines
target/riscv/csr.c +0
-1return 0 ; } --2.22.0
Quoted 1 line
Can you wrap your commit message at ~70 lines?
Sure.
Quoted 1 line
Isn't
CSR_TIME& 31 just 0? Can this just be changed 1 << 1 or even
better add a macro?
Any of those options work. Unless anyone feels strongly otherwise, I'll add macros for the bits associated with the three named counters but not the remaining 29 unnamed "high performance counters".
Quoted 65 lines · Alistair Francis
Quoted 5 lines · On Fri, Jun 28, 2019 at 1:12 PM <[email protected]> wrote:
From: Jonathan Behrens <[email protected]>
QEMU currently always triggers an illegal instruction exception when code attempts to read the time CSR. This is valid behavor, but only if the TM
bit in
Quoted 1 line
mcounteren is hardwired to zero. This change also corrects mcounteren
and scounteren CSRs to be 32-bits on both
Quoted 1 line
32-bit and 64-bit targets.
Thanks for the patch.
Can you wrap your commit message at ~70 lines?
target/riscv/csr.c static int write_mcounteren(CPURISCVState *env, int
Quoted 27 lines
Signed-off-by Jonathan Behrens <[email protected]>--- target/riscv/cpu.h | 4 ++-- target/riscv/csr.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)target/riscv/cpu.h +2
-2@@ -151,8 +151,8 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ -target_ulong scounteren; -target_ulong mcounteren; +uint32_t scounteren; +uint32_t mcounteren;target_ulong sscratch;target_ulong mscratch;target/riscv/csr.c +0
-0@@ -473,7 +473,8 @@ static int write_mcounteren(CPURISCVState *env, intcsrno,
target_ulongval)target/riscv/csr.c static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)
Quoted 5 lines
target/riscv/csr.c +1
-1if (env->priv_ver <PRIV_VERSION_1_10_0 ) {return -1 ; } - env->mcounteren = val; +/* mcounteren.TM is hardwired to zero, all other bits are writable */
target/riscv/csr.c static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) · line 477
Quoted 1 line
target/riscv/csr.c +1
-0+ env->mcounteren = val & ~(1 << (CSR_TIME &31 ));Isn't
CSR_TIME& 31 just 0? Can this just be changed 1 << 1 or even better add a macro?Otherwise this patch looks good :)
Alistair
Quoted 6 lines
target/riscv/csr.c +0
-1return 0 ; } --2.22.0
Quoted 8 lines · Jonathan Behrens
Quoted 2 lines
Can you wrap your commit message at ~70 lines?
Sure.
Quoted 1 line
Isn't
CSR_TIME& 31 just 0? Can this just be changed 1 << 1 or even better add a macro?Any of those options work. Unless anyone feels strongly otherwise, I'll add macros for the bits associated with the three named counters but not the remaining 29 unnamed "high performance counters".
Yep, sounds good.
Alistair
Quoted 63 lines · Alistair Francis
Quoted 61 lines · On Fri, Jun 28, 2019 at 1:12 PM <[email protected]> wrote:
Quoted 7 lines
From: Jonathan Behrens <[email protected]>
QEMU currently always triggers an illegal instruction exception when code
attempts to read the time CSR. This is valid behavor, but only if the TM bit in
mcounteren is hardwired to zero. This change also corrects mcounteren and scounteren CSRs to be 32-bits on both 32-bit and 64-bit targets.Thanks for the patch.
Can you wrap your commit message at ~70 lines?
Quoted 27 lines
Signed-off-by Jonathan Behrens <[email protected]>--- target/riscv/cpu.h | 4 ++-- target/riscv/csr.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)target/riscv/cpu.h +2
-2@@ -151,8 +151,8 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ -target_ulong scounteren; -target_ulong mcounteren; +uint32_t scounteren; +uint32_t mcounteren;target_ulong sscratch;target_ulong mscratch;target/riscv/csr.c +0
-0target/riscv/csr.c static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) · line 477
Quoted 6 lines
target/riscv/csr.c +2
-1@@ -473,7 +473,8 @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)if (env->priv_ver <PRIV_VERSION_1_10_0 ) {return -1 ; } - env->mcounteren = val; +/* mcounteren.TM is hardwired to zero, all other bits are writable */ + env->mcounteren = val & ~(1 << (CSR_TIME &31 ));Isn't
CSR_TIME& 31 just 0? Can this just be changed 1 << 1 or even better add a macro?Otherwise this patch looks good :)
Alistair
Quoted 6 lines
target/riscv/csr.c +0
-1return 0 ; } --2.22.0