target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
PATCH v2 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/cpu_bits.h | 5 +++++ target/riscv/csr.c | 2 +- 3 files changed, 8 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/cpu_bits.h +5 -0
@@ -532,4 +532,9 @@#define SIP_STIP MIP_STIP#define SIP_SEIP MIP_SEIP +/* mcounteren CSR bits */ +#define MCOUNTEREN_CY 0x1 +#define MCOUNTEREN_TM 0x2 +#define MCOUNTEREN_IR 0x4 +#endif
target/riscv/csr.c +1 -1
@@ -473,7 +473,7 @@ 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; + env->mcounteren = val & ~MCOUNTEREN_TM ;return 0 ; }
Signature · 1 line
2.22.0
Quoted 10 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Signed-off-by Jonathan Behrens <[email protected]>
Alistair
Quoted 51 lines
--- target/riscv/cpu.h | 4 ++-- target/riscv/cpu_bits.h | 5 +++++ target/riscv/csr.c | 2 +- 3 files changed, 8 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/cpu_bits.h +5
-0@@ -532,4 +532,9 @@#define SIP_STIP MIP_STIP#define SIP_SEIP MIP_SEIP +/* mcounteren CSR bits */ +#define MCOUNTEREN_CY 0x1 +#define MCOUNTEREN_TM 0x2 +#define MCOUNTEREN_IR 0x4 +#endif target/riscv/csr.c +1
-2@@ -473,7 +473,7 @@ 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; + env->mcounteren = val & ~MCOUNTEREN_TM ;return 0 ; } --2.22.0
Quoted 11 lines · Alistair Francis
Quoted 9 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>
I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin
Bin, that proposal proved to be somewhat more controversial than I was expecting, since it was different than how currently available hardware worked. This option seemed much more likely to be accepted in the short term.
Jonathan
Quoted 24 lines · Bin Meng
Quoted 11 lines · Alistair Francis
Quoted 9 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin
Ping! What is the status of this patch?
Quoted 34 lines · Jonathan Behrens
Bin, that proposal proved to be somewhat more controversial than I was expecting, since it was different than how currently available hardware worked. This option seemed much more likely to be accepted in the short term.
Jonathan
Quoted 24 lines · Bin Meng
Quoted 11 lines · Alistair Francis
Quoted 9 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin
Quoted 1 line · On Wed, 14 Aug 2019 20:19:39 PDT (-0700), [email protected] wrote:
Ping! What is the status of this patch?
Sorry, I must have lost track of it. I've added it to my patch queue.
Quoted 38 lines
Quoted 34 lines · Jonathan Behrens
Bin, that proposal proved to be somewhat more controversial than I was expecting, since it was different than how currently available hardware worked. This option seemed much more likely to be accepted in the short term.
Jonathan
Quoted 24 lines · Bin Meng
Quoted 11 lines · Alistair Francis
Quoted 9 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin
I was just doubling checking the status of this patch because it conflicts with the "RISC-V TIME CSR for privileged mode" PR that was just sent out, and it seems this never got merged? In any case, perhaps these changes should be rolled into that patch?
Quoted 47 lines · Palmer Dabbelt
Quoted 1 line · On Wed, 14 Aug 2019 20:19:39 PDT (-0700), [email protected] wrote:
Ping! What is the status of this patch?
Sorry, I must have lost track of it. I've added it to my patch queue.
Quoted 13 lines
Quoted 9 lines · Jonathan Behrens
Bin, that proposal proved to be somewhat more controversial than I was expecting, since it was different than how currently available hardware worked. This option seemed much more likely to be accepted in the short term.
Jonathan
On Mon, Jul 1, 2019 at 9:26 PM Bin Meng <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Alistair Francis
Quoted 4 lines · On Mon, Jul 1, 2019 at 8:56 AM <[email protected]> wrote:
From: Jonathan Behrens <[email protected]>
QEMU currently always triggers an illegal instruction exception
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
code attempts to read the time CSR. This is valid behavor, but
only if
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
and 64-bit targets.
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin
Quoted 2 lines · Jonathan Behrens
I was just doubling checking the status of this patch because it conflicts with the "RISC-V TIME CSR for privileged mode" PR that was just sent out, and it seems this never got merged? In any case, perhaps these changes should be rolled into that patch?
I think this should be merged first. @Palmer Dabbelt can you merge this?
Alistair
Quoted 46 lines · Palmer Dabbelt
Quoted 44 lines · On Wed, 14 Aug 2019 20:19:39 PDT (-0700), [email protected] wrote:
Quoted 1 line
Ping! What is the status of this patch?
Sorry, I must have lost track of it. I've added it to my patch queue.
Quoted 38 lines
Quoted 34 lines · Jonathan Behrens
Bin, that proposal proved to be somewhat more controversial than I was expecting, since it was different than how currently available hardware worked. This option seemed much more likely to be accepted in the short term.
Jonathan
Quoted 24 lines · Bin Meng
Quoted 11 lines · Alistair Francis
Quoted 9 lines · On Mon, Jul 1, 2019 at 8:56 AM <[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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jonathan Behrens <[email protected]>Reviewed-by Alistair Francis <[email protected]>I am a little bit lost here. I think we agreed to allow directly read to time CSR when mcounteren.TM is set, no?
Regards,
Bin