qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
@ 2019-07-01 15:46 jonathan
  2019-07-01 20:54 ` Alistair Francis
  0 siblings, 1 reply; 8+ messages in thread
From: jonathan @ 2019-07-01 15:46 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Sagar Karandikar, Jonathan Behrens, Palmer Dabbelt,
	open list:All patches CC here, Alistair Francis,
	Bastian Koppelmann

From: Jonathan Behrens <jonathan@fintelia.io>

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 <jonathan@fintelia.io>
---
 target/riscv/cpu.h      | 4 ++--
 target/riscv/cpu_bits.h | 5 +++++
 target/riscv/csr.c      | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 0adb307f32..2d0cbe9c78 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -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;
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 11f971ad5d..0ea1e1caf5 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -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
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index e0d4586760..8425a6d2bd 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-07-01 15:46 [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren jonathan
@ 2019-07-01 20:54 ` Alistair Francis
  2019-07-02  1:26   ` Bin Meng
  0 siblings, 1 reply; 8+ messages in thread
From: Alistair Francis @ 2019-07-01 20:54 UTC (permalink / raw)
  To: Jonathan Behrens
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Palmer Dabbelt, open list:All patches CC here, Alistair Francis

On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
>
> From: Jonathan Behrens <jonathan@fintelia.io>
>
> 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 <jonathan@fintelia.io>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/cpu.h      | 4 ++--
>  target/riscv/cpu_bits.h | 5 +++++
>  target/riscv/csr.c      | 2 +-
>  3 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 0adb307f32..2d0cbe9c78 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -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;
> diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> index 11f971ad5d..0ea1e1caf5 100644
> --- a/target/riscv/cpu_bits.h
> +++ b/target/riscv/cpu_bits.h
> @@ -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
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index e0d4586760..8425a6d2bd 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -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
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-07-01 20:54 ` Alistair Francis
@ 2019-07-02  1:26   ` Bin Meng
  2019-07-03 18:02     ` Jonathan Behrens
  0 siblings, 1 reply; 8+ messages in thread
From: Bin Meng @ 2019-07-02  1:26 UTC (permalink / raw)
  To: Alistair Francis
  Cc: open list:RISC-V, Sagar Karandikar, Jonathan Behrens,
	Palmer Dabbelt, open list:All patches CC here, Alistair Francis,
	Bastian Koppelmann

On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com> wrote:
>
> On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
> >
> > From: Jonathan Behrens <jonathan@fintelia.io>
> >
> > 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 <jonathan@fintelia.io>
>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-07-02  1:26   ` Bin Meng
@ 2019-07-03 18:02     ` Jonathan Behrens
  2019-08-15  3:19       ` Jonathan Behrens
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Behrens @ 2019-07-03 18:02 UTC (permalink / raw)
  To: Bin Meng
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Palmer Dabbelt, open list:All patches CC here, Alistair Francis,
	Alistair Francis

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 <bmeng.cn@gmail.com> wrote:

> On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com>
> wrote:
> >
> > On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
> > >
> > > From: Jonathan Behrens <jonathan@fintelia.io>
> > >
> > > 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 <jonathan@fintelia.io>
> >
> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> >
>
> 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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-07-03 18:02     ` Jonathan Behrens
@ 2019-08-15  3:19       ` Jonathan Behrens
  2019-08-21 17:37         ` Palmer Dabbelt
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Behrens @ 2019-08-15  3:19 UTC (permalink / raw)
  To: open list:RISC-V
  Cc: Sagar Karandikar, Bastian Koppelmann, Palmer Dabbelt,
	open list:All patches CC here, Alistair Francis,
	Alistair Francis, Bin Meng

Ping! What is the status of this patch?

On Wed, Jul 3, 2019 at 2:02 PM Jonathan Behrens <jonathan@fintelia.io>
wrote:

> 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 <bmeng.cn@gmail.com> wrote:
>
>> On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com>
>> wrote:
>> >
>> > On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
>> > >
>> > > From: Jonathan Behrens <jonathan@fintelia.io>
>> > >
>> > > 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 <jonathan@fintelia.io>
>> >
>> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> >
>>
>> 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
>>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-08-15  3:19       ` Jonathan Behrens
@ 2019-08-21 17:37         ` Palmer Dabbelt
  2020-01-21 13:05           ` Jonathan Behrens
  0 siblings, 1 reply; 8+ messages in thread
From: Palmer Dabbelt @ 2019-08-21 17:37 UTC (permalink / raw)
  To: jonathan
  Cc: qemu-riscv, sagark, Bastian Koppelmann, qemu-devel,
	Alistair Francis, alistair23, bmeng.cn

On Wed, 14 Aug 2019 20:19:39 PDT (-0700), jonathan@fintelia.io 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.

>
> On Wed, Jul 3, 2019 at 2:02 PM Jonathan Behrens <jonathan@fintelia.io>
> wrote:
>
>> 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 <bmeng.cn@gmail.com> wrote:
>>
>>> On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com>
>>> wrote:
>>> >
>>> > On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
>>> > >
>>> > > From: Jonathan Behrens <jonathan@fintelia.io>
>>> > >
>>> > > 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 <jonathan@fintelia.io>
>>> >
>>> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>>> >
>>>
>>> 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
>>>
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2019-08-21 17:37         ` Palmer Dabbelt
@ 2020-01-21 13:05           ` Jonathan Behrens
  2020-01-21 22:26             ` Alistair Francis
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Behrens @ 2020-01-21 13:05 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	qemu-devel@nongnu.org Developers, Alistair Francis,
	Alistair Francis, Bin Meng

[-- Attachment #1: Type: text/plain, Size: 1883 bytes --]

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?

On Wed, Aug 21, 2019 at 1:37 PM Palmer Dabbelt <palmer@sifive.com> wrote:

> On Wed, 14 Aug 2019 20:19:39 PDT (-0700), jonathan@fintelia.io 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.
>
> >
> > On Wed, Jul 3, 2019 at 2:02 PM Jonathan Behrens <jonathan@fintelia.io>
> > wrote:
> >
> >> 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 <bmeng.cn@gmail.com> wrote:
> >>
> >>> On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com>
> >>> wrote:
> >>> >
> >>> > On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
> >>> > >
> >>> > > From: Jonathan Behrens <jonathan@fintelia.io>
> >>> > >
> >>> > > 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 <jonathan@fintelia.io>
> >>> >
> >>> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> >>> >
> >>>
> >>> 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
> >>>
> >>
>

[-- Attachment #2: Type: text/html, Size: 3176 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren
  2020-01-21 13:05           ` Jonathan Behrens
@ 2020-01-21 22:26             ` Alistair Francis
  0 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2020-01-21 22:26 UTC (permalink / raw)
  To: Jonathan Behrens, Palmer Dabbelt
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	qemu-devel@nongnu.org Developers, Alistair Francis, Bin Meng

On Tue, Jan 21, 2020 at 11:05 PM Jonathan Behrens <jonathan@fintelia.io> wrote:
>
> 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

>
> On Wed, Aug 21, 2019 at 1:37 PM Palmer Dabbelt <palmer@sifive.com> wrote:
>>
>> On Wed, 14 Aug 2019 20:19:39 PDT (-0700), jonathan@fintelia.io 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.
>>
>> >
>> > On Wed, Jul 3, 2019 at 2:02 PM Jonathan Behrens <jonathan@fintelia.io>
>> > wrote:
>> >
>> >> 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 <bmeng.cn@gmail.com> wrote:
>> >>
>> >>> On Tue, Jul 2, 2019 at 8:20 AM Alistair Francis <alistair23@gmail.com>
>> >>> wrote:
>> >>> >
>> >>> > On Mon, Jul 1, 2019 at 8:56 AM <jonathan@fintelia.io> wrote:
>> >>> > >
>> >>> > > From: Jonathan Behrens <jonathan@fintelia.io>
>> >>> > >
>> >>> > > 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 <jonathan@fintelia.io>
>> >>> >
>> >>> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> >>> >
>> >>>
>> >>> 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
>> >>>
>> >>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-21 22:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 15:46 [Qemu-devel] [PATCH v2] target/riscv: Hardwire mcounter.TM and upper bits of [m|s]counteren jonathan
2019-07-01 20:54 ` Alistair Francis
2019-07-02  1:26   ` Bin Meng
2019-07-03 18:02     ` Jonathan Behrens
2019-08-15  3:19       ` Jonathan Behrens
2019-08-21 17:37         ` Palmer Dabbelt
2020-01-21 13:05           ` Jonathan Behrens
2020-01-21 22:26             ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).