From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Andrew Burgess <aburgess@redhat.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] sim: riscv: Fix Zicsr and fence instructions
Date: Mon, 29 Apr 2024 15:30:43 +0200 [thread overview]
Message-ID: <AS8P193MB1285CA0505EA26BDAEDD5366E41B2@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <87il00pjwg.fsf@redhat.com>
On 4/29/24 12:01, Andrew Burgess wrote:
> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>
>> The Zicsr instructions were totally broken, and
>> some instructions like fence.tso were missing.
>>
>> Since the test coverage is not very good, add some
>> basic tests for fence and csrrw instructions.
>> ---
>> sim/riscv/sim-main.c | 74 ++++++++++++++++++++++++++++++++-----
>> sim/testsuite/riscv/fence.s | 17 +++++++++
>> sim/testsuite/riscv/zicsr.s | 24 ++++++++++++
>> 3 files changed, 106 insertions(+), 9 deletions(-)
>> create mode 100644 sim/testsuite/riscv/fence.s
>> create mode 100644 sim/testsuite/riscv/zicsr.s
>>
>> diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c
>> index 1815d7f2a6c..69007d3108e 100644
>> --- a/sim/riscv/sim-main.c
>> +++ b/sim/riscv/sim-main.c
>> @@ -535,37 +535,57 @@ execute_i (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op)
>> break;
>>
>> case MATCH_CSRRC:
>> - TRACE_INSN (cpu, "csrrc");
>> + TRACE_INSN (cpu, "csrrc %s, %#x, %s;",
>> + rd_name, csr, rs1_name);
>> switch (csr)
>> {
>> #define DECLARE_CSR(name, num, ...) \
>> case num: \
>> - store_rd (cpu, rd, \
>> - fetch_csr (cpu, #name, num, &riscv_cpu->csr.name)); \
>> + tmp = fetch_csr (cpu, #name, num, &riscv_cpu->csr.name); \
>> store_csr (cpu, #name, num, &riscv_cpu->csr.name, \
>> - riscv_cpu->csr.name & !riscv_cpu->regs[rs1]); \
>> + riscv_cpu->csr.name & ~riscv_cpu->regs[rs1]); \
>> + store_rd (cpu, rd, tmp); \
>
> I know that store_csr doesn't support many CSRs, and doesn't do any
> checks for things like writing to read-only CSRs, but ....
>
> ... I think it might be worth adding a check here for rs1 == x0. The
> docs say:
>
> For both CSRRS and CSRRC, if rs1=x0, then the instruction will not
> write to the CSR at all, and so shall not cause any of the side
> effects that might otherwise occur on a CSR write, such as raising
> illegal instruction exceptions on accesses to read-only CSRs.
>
> Adding these checks now might mean things "just work" if we add support
> for more CSRs at a later date.
>
Yeah, good point.
will add those checks and send a v2 version.
Thanks
Bernd.
prev parent reply other threads:[~2024-04-29 13:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 4:38 Bernd Edlinger
2024-04-29 10:01 ` Andrew Burgess
2024-04-29 13:30 ` Bernd Edlinger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P193MB1285CA0505EA26BDAEDD5366E41B2@AS8P193MB1285.EURP193.PROD.OUTLOOK.COM \
--to=bernd.edlinger@hotmail.de \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).