From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8006C07E95 for ; Sat, 10 Jul 2021 15:02:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E945261248 for ; Sat, 10 Jul 2021 15:02:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E945261248 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2EUi-0005um-Mq for qemu-devel@archiver.kernel.org; Sat, 10 Jul 2021 11:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2ESj-0004Tk-QP for qemu-devel@nongnu.org; Sat, 10 Jul 2021 11:00:16 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:33653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2ESg-0006rG-P6 for qemu-devel@nongnu.org; Sat, 10 Jul 2021 11:00:13 -0400 Received: by mail-pg1-x529.google.com with SMTP id 37so13132959pgq.0 for ; Sat, 10 Jul 2021 08:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pbUS5zBcn7GWg3pEUnXUL/wEJn67PeEAHEfQxo5y/+o=; b=OKIThW/g8y8u+ELEXPaJivD3sRd+TKMn3lYOu2Gb/s9aVbSleITJUzueIhY/R0Ccku UlKamc2yI3WNAv9Qps0roZHVOdtk3EX3f8RYKmBX0m0qcX9GwGBZPd1xZByMUWOnRcA2 eruECBUDdpEw6d86KzpL2uvD9A8laPB/xBFwf76xQP53SGTmdM7usF6rUXgQ6YSKhrSo P38m2tTuG4goTHkvX0h/XbSEHVChjM9l07TRzuW2ro0+EAMjsYnUXnoRB8vcmkZsKwqA +Cqyu6wKj+5Xem64Tie2rHFQqPcAILpeeXO6DQUxT3KoY2ptW2+/jghi/SYoixxVKpP8 Lo/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pbUS5zBcn7GWg3pEUnXUL/wEJn67PeEAHEfQxo5y/+o=; b=ja5PSsZKLHtCbHeXDzZGN/gURUPzBdCEL3bfpWrYvgq5z8aVhkq71qdeYrfhcumASv YOKA9/nP9RZX9SYDR/CCV8KV5qbf5INZyOweIQfkeyQoAH/tRfIwwLXY7sHvyjX57/i7 dOcFjIP3SgSwpnLL4+Inie6rcs5RxZe0676ONFMmDfUWNTLZH9cK5x9ykOLgT/GHsPCe CI34Ss8JOpiqbKv0y80IMmcxsQegemaPRyEAfaE8zsqL6wOjLgOH8T/f1XlHD1aC61Z5 kaavDTwjnc7Qgoz7kEJKhESw1DVvxDDHVqCUvoA6PSU4y89ncOAWIgTjtnJ6a+hc6P/X GD+Q== X-Gm-Message-State: AOAM532hyMZ5E2n9cSjRHre7xjo+8c8HFKSVT2c3RSewqTj1IAiVnaZj JQXnyVagzHJSW270GtGb6Z6FKmg7qaCZkw== X-Google-Smtp-Source: ABdhPJwpq4Ai0eVsJteSrX7iLes3PXJ/lPM5guZwd2UuhGEyooe38/b+H2P0mFTEnaDioCyXaSV9Zg== X-Received: by 2002:a63:4f62:: with SMTP id p34mr10920137pgl.283.1625929208532; Sat, 10 Jul 2021 08:00:08 -0700 (PDT) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com. [209.85.216.44]) by smtp.gmail.com with ESMTPSA id l11sm1420304pjw.45.2021.07.10.08.00.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Jul 2021 08:00:07 -0700 (PDT) Received: by mail-pj1-f44.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso7767342pjp.2; Sat, 10 Jul 2021 08:00:07 -0700 (PDT) X-Received: by 2002:a17:90a:17cd:: with SMTP id q71mr25501547pja.47.1625929207395; Sat, 10 Jul 2021 08:00:07 -0700 (PDT) MIME-Version: 1.0 References: <20210409074857.166082-1-zhiwei_liu@c-sky.com> <20210409074857.166082-9-zhiwei_liu@c-sky.com> In-Reply-To: <20210409074857.166082-9-zhiwei_liu@c-sky.com> From: Frank Chang Date: Sat, 10 Jul 2021 22:59:56 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 08/11] target/riscv: Update CSR xnxti in CLIC mode To: LIU Zhiwei Content-Type: multipart/alternative; boundary="000000000000d63ae205c6c6247c" Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=frank.chang@sifive.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Palmer Dabbelt , Alistair Francis , "open list:RISC-V" , "qemu-devel@nongnu.org Developers" , wxy194768@alibaba-inc.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000d63ae205c6c6247c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable LIU Zhiwei =E6=96=BC 2021=E5=B9=B44=E6=9C=889=E6=97= =A5 =E9=80=B1=E4=BA=94 =E4=B8=8B=E5=8D=883:52=E5=AF=AB=E9=81=93=EF=BC=9A > The CSR can be used by software to service the next horizontal interrupt > when it has greater level than the saved interrupt context > (held in xcause`.pil`) and greater level than the interrupt threshold of > the corresponding privilege mode, > > Signed-off-by: LIU Zhiwei > --- > target/riscv/cpu_bits.h | 16 ++++++ > target/riscv/csr.c | 114 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 130 insertions(+) > > diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h > index 7922097776..494e41edc9 100644 > --- a/target/riscv/cpu_bits.h > +++ b/target/riscv/cpu_bits.h > @@ -166,6 +166,7 @@ > #define CSR_MCAUSE 0x342 > #define CSR_MTVAL 0x343 > #define CSR_MIP 0x344 > +#define CSR_MNXTI 0x345 /* clic-spec-draft */ > #define CSR_MINTSTATUS 0x346 /* clic-spec-draft */ > #define CSR_MINTTHRESH 0x347 /* clic-spec-draft */ > > @@ -187,6 +188,7 @@ > #define CSR_SCAUSE 0x142 > #define CSR_STVAL 0x143 > #define CSR_SIP 0x144 > +#define CSR_SNXTI 0x145 /* clic-spec-draft */ > #define CSR_SINTSTATUS 0x146 /* clic-spec-draft */ > #define CSR_SINTTHRESH 0x147 /* clic-spec-draft */ > > @@ -596,10 +598,24 @@ > #define MINTSTATUS_SIL 0x0000ff00 /* sil[7:0] */ > #define MINTSTATUS_UIL 0x000000ff /* uil[7:0] */ > > +/* mcause */ > +#define MCAUSE_MINHV 0x40000000 /* minhv */ > +#define MCAUSE_MPP 0x30000000 /* mpp[1:0] */ > +#define MCAUSE_MPIE 0x08000000 /* mpie */ > +#define MCAUSE_MPIL 0x00ff0000 /* mpil[7:0] */ > +#define MCAUSE_EXCCODE 0x00000fff /* exccode[11:0] *= / > + > /* sintstatus */ > #define SINTSTATUS_SIL 0x0000ff00 /* sil[7:0] */ > #define SINTSTATUS_UIL 0x000000ff /* uil[7:0] */ > > +/* scause */ > +#define SCAUSE_SINHV 0x40000000 /* sinhv */ > +#define SCAUSE_SPP 0x10000000 /* spp */ > +#define SCAUSE_SPIE 0x08000000 /* spie */ > +#define SCAUSE_SPIL 0x00ff0000 /* spil[7:0] */ > +#define SCAUSE_EXCCODE 0x00000fff /* exccode[11:0] *= / > + > /* MIE masks */ > #define MIE_SEIE (1 << IRQ_S_EXT) > #define MIE_UEIE (1 << IRQ_U_EXT) > diff --git a/target/riscv/csr.c b/target/riscv/csr.c > index e12222b77f..72cba080bf 100644 > --- a/target/riscv/csr.c > +++ b/target/riscv/csr.c > @@ -774,6 +774,80 @@ static int rmw_mip(CPURISCVState *env, int csrno, > target_ulong *ret_value, > return 0; > } > > +static bool get_xnxti_status(CPURISCVState *env) > +{ > + CPUState *cs =3D env_cpu(env); > + int clic_irq, clic_priv, clic_il, pil; > + > + if (!env->exccode) { /* No interrupt */ > + return false; > + } > + /* The system is not in a CLIC mode */ > + if (!riscv_clic_is_clic_mode(env)) { > + return false; > + } else { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + > + if (env->priv =3D=3D PRV_M) { > + pil =3D MAX(get_field(env->mcause, MCAUSE_MPIL), > env->mintthresh); > + } else if (env->priv =3D=3D PRV_S) { > + pil =3D MAX(get_field(env->scause, SCAUSE_SPIL), > env->sintthresh); > + } else { > + qemu_log_mask(LOG_GUEST_ERROR, > + "CSR: rmw xnxti with unsupported mode\n"); > + exit(1); > + } > + > + if ((clic_priv !=3D env->priv) || /* No horizontal interrupt */ > + (clic_il <=3D pil) || /* No higher level interrupt */ > + (riscv_clic_shv_interrupt(env->clic, clic_priv, cs->cpu_inde= x, > + clic_irq))) { /* CLIC vector mode = */ > + return false; > + } else { > + return true; > + } > + } > +} > + > +static int rmw_mnxti(CPURISCVState *env, int csrno, target_ulong > *ret_value, > + target_ulong new_value, target_ulong write_mask) > +{ > + int clic_priv, clic_il, clic_irq; > + bool ready; > + CPUState *cs =3D env_cpu(env); > + if (write_mask) { > + env->mstatus |=3D new_value & (write_mask & 0b11111); > This won't work for CSRRCI instruction. new_value is assigned to 0 for CSRRCI operation. Should be: target_ulong mask =3D write_mask & 0b11111; env->mstatus =3D (env->mstatus & ~mask) | (new_value & mask); > + } > + > + qemu_mutex_lock_iothread(); > + ready =3D get_xnxti_status(env); > + if (ready) { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + if (write_mask) { > + bool edge =3D riscv_clic_edge_triggered(env->clic, clic_priv= , > + cs->cpu_index, > clic_irq); > + if (edge) { > + riscv_clic_clean_pending(env->clic, clic_priv, > + cs->cpu_index, clic_irq); > + } > + env->mintstatus =3D set_field(env->mintstatus, > + MINTSTATUS_MIL, clic_il); > + env->mcause =3D set_field(env->mcause, MCAUSE_EXCCODE, > clic_irq); > + } > + if (ret_value) { > + *ret_value =3D (env->mtvt & ~0x3f) + sizeof(target_ulong) * > clic_irq; > + } > + } else { > + if (ret_value) { > + *ret_value =3D 0; > + } > + } > + qemu_mutex_unlock_iothread(); > + return 0; > +} > + > static int read_mintstatus(CPURISCVState *env, int csrno, target_ulong > *val) > { > *val =3D env->mintstatus; > @@ -982,6 +1056,44 @@ static int rmw_sip(CPURISCVState *env, int csrno, > target_ulong *ret_value, > return ret; > } > > +static int rmw_snxti(CPURISCVState *env, int csrno, target_ulong > *ret_value, > + target_ulong new_value, target_ulong write_mask) > +{ > + int clic_priv, clic_il, clic_irq; > + bool ready; > + CPUState *cs =3D env_cpu(env); > + if (write_mask) { > + env->mstatus |=3D new_value & (write_mask & 0b11111); > Same to rmw_mnxti() Regards, Frank Chang > + } > + > + qemu_mutex_lock_iothread(); > + ready =3D get_xnxti_status(env); > + if (ready) { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + if (write_mask) { > + bool edge =3D riscv_clic_edge_triggered(env->clic, clic_priv= , > + cs->cpu_index, > clic_irq); > + if (edge) { > + riscv_clic_clean_pending(env->clic, clic_priv, > + cs->cpu_index, clic_irq); > + } > + env->mintstatus =3D set_field(env->mintstatus, > + MINTSTATUS_SIL, clic_il); > + env->scause =3D set_field(env->scause, SCAUSE_EXCCODE, > clic_irq); > + } > + if (ret_value) { > + *ret_value =3D (env->stvt & ~0x3f) + sizeof(target_ulong) * > clic_irq; > + } > + } else { > + if (ret_value) { > + *ret_value =3D 0; > + } > + } > + qemu_mutex_unlock_iothread(); > + return 0; > +} > + > static int read_sintstatus(CPURISCVState *env, int csrno, target_ulong > *val) > { > target_ulong mask =3D SINTSTATUS_SIL | SINTSTATUS_UIL; > @@ -1755,6 +1867,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { > > /* Machine Mode Core Level Interrupt Controller */ > [CSR_MTVT] =3D { "mtvt", clic, read_mtvt, write_mtvt }, > + [CSR_MNXTI] =3D { "mnxti", clic, NULL, NULL, rmw_mnxti }, > [CSR_MINTSTATUS] =3D { "mintstatus", clic, read_mintstatus }, > [CSR_MINTTHRESH] =3D { "mintthresh", clic, read_mintthresh, > write_mintthresh }, > @@ -1766,6 +1879,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { > > /* Supervisor Mode Core Level Interrupt Controller */ > [CSR_STVT] =3D { "stvt", clic, read_stvt, write_stvt }, > + [CSR_SNXTI] =3D { "snxti", clic, NULL, NULL, rmw_snxti }, > > #endif /* !CONFIG_USER_ONLY */ > }; > -- > 2.25.1 > > > --000000000000d63ae205c6c6247c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
LIU Zhiwei <zhiwei_liu@c-sky.com> =E6=96=BC 2021=E5=B9=B44=E6=9C= =889=E6=97=A5 =E9=80=B1=E4=BA=94 =E4=B8=8B=E5=8D=883:52=E5=AF=AB=E9=81=93= =EF=BC=9A
The CSR can be used by software to service the next ho= rizontal interrupt
when it has greater level than the saved interrupt context
(held in xcause`.pil`) and greater level than the interrupt threshold of the corresponding privilege mode,

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
=C2=A0target/riscv/cpu_bits.h |=C2=A0 16 ++++++
=C2=A0target/riscv/csr.c=C2=A0 =C2=A0 =C2=A0 | 114 ++++++++++++++++++++++++= ++++++++++++++++
=C2=A02 files changed, 130 insertions(+)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 7922097776..494e41edc9 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -166,6 +166,7 @@
=C2=A0#define CSR_MCAUSE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x342
=C2=A0#define CSR_MTVAL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x343
=C2=A0#define CSR_MIP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x344<= br> +#define CSR_MNXTI=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x345 /* clic-sp= ec-draft */
=C2=A0#define CSR_MINTSTATUS=C2=A0 =C2=A0 =C2=A0 0x346 /* clic-spec-draft *= /
=C2=A0#define CSR_MINTTHRESH=C2=A0 =C2=A0 =C2=A0 0x347 /* clic-spec-draft *= /

@@ -187,6 +188,7 @@
=C2=A0#define CSR_SCAUSE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x142
=C2=A0#define CSR_STVAL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x143
=C2=A0#define CSR_SIP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x144<= br> +#define CSR_SNXTI=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x145 /* clic-sp= ec-draft */
=C2=A0#define CSR_SINTSTATUS=C2=A0 =C2=A0 =C2=A0 0x146 /* clic-spec-draft *= /
=C2=A0#define CSR_SINTTHRESH=C2=A0 =C2=A0 =C2=A0 0x147 /* clic-spec-draft *= /

@@ -596,10 +598,24 @@
=C2=A0#define MINTSTATUS_SIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x0000ff00 /* sil[7:0] */
=C2=A0#define MINTSTATUS_UIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x000000ff /* uil[7:0] */

+/* mcause */
+#define MCAUSE_MINHV=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x40000000 /* minhv */
+#define MCAUSE_MPP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x30000000 /* mpp[1:0] */
+#define MCAUSE_MPIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x08000000 /* mpie */
+#define MCAUSE_MPIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00ff0000 /* mpil[7:0] */
+#define MCAUSE_EXCCODE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00x00000fff /* exccode[11:0] */
+
=C2=A0/* sintstatus */
=C2=A0#define SINTSTATUS_SIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x0000ff00 /* sil[7:0] */
=C2=A0#define SINTSTATUS_UIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x000000ff /* uil[7:0] */

+/* scause */
+#define SCAUSE_SINHV=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x40000000 /* sinhv */
+#define SCAUSE_SPP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x10000000 /* spp */
+#define SCAUSE_SPIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x08000000 /* spie */
+#define SCAUSE_SPIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00ff0000 /* spil[7:0] */
+#define SCAUSE_EXCCODE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00x00000fff /* exccode[11:0] */
+
=C2=A0/* MIE masks */
=C2=A0#define MIE_SEIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(1 << IRQ_S_EXT)
=C2=A0#define MIE_UEIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(1 << IRQ_U_EXT)
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index e12222b77f..72cba080bf 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -774,6 +774,80 @@ static int rmw_mip(CPURISCVState *env, int csrno, targ= et_ulong *ret_value,
=C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0}

+static bool get_xnxti_status(CPURISCVState *env)
+{
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 int clic_irq, clic_priv, clic_il, pil;
+
+=C2=A0 =C2=A0 if (!env->exccode) { /* No interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 /* The system is not in a CLIC mode */
+=C2=A0 =C2=A0 if (!riscv_clic_is_clic_mode(env)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (env->priv =3D=3D PRV_M) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pil =3D MAX(get_field(env->mc= ause, MCAUSE_MPIL), env->mintthresh);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (env->priv =3D=3D PRV_S) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pil =3D MAX(get_field(env->sc= ause, SCAUSE_SPIL), env->sintthresh);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qemu_log_mask(LOG_GUEST_ERROR, +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "CSR: rmw xnxti with unsupported mode\n");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 exit(1);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ((clic_priv !=3D env->priv) || /* No hor= izontal interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (clic_il <=3D pil) || /* No h= igher level interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (riscv_clic_shv_interrupt(env-&g= t;clic, clic_priv, cs->cpu_index,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clic_irq))) { /= * CLIC vector mode */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+}
+
+static int rmw_mnxti(CPURISCVState *env, int csrno, target_ulong *ret_valu= e,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0target_ulong new_value, target_ulong write_mask)
+{
+=C2=A0 =C2=A0 int clic_priv, clic_il, clic_irq;
+=C2=A0 =C2=A0 bool ready;
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mstatus |=3D new_value & (write_ma= sk & 0b11111);

This won't work = for CSRRCI instruction.
new_value is assigned to 0 for CSRRCI ope= ration.

Should be:
target_ulong mask =3D= write_mask & 0b11111;
env->mstatus =3D (env->mstat= us & ~mask) | (new_value & mask);
=C2=A0
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 qemu_mutex_lock_iothread();
+=C2=A0 =C2=A0 ready =3D get_xnxti_status(env);
+=C2=A0 =C2=A0 if (ready) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool edge =3D riscv_clic_edge_tr= iggered(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 cs->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (edge) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_clean_p= ending(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cs= ->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mintstatus =3D set_field= (env->mintstatus,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MINTSTAT= US_MIL, clic_il);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mcause =3D set_field(env= ->mcause, MCAUSE_EXCCODE, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D (env->mtvt &am= p; ~0x3f) + sizeof(target_ulong) * clic_irq;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D 0;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 qemu_mutex_unlock_iothread();
+=C2=A0 =C2=A0 return 0;
+}
+
=C2=A0static int read_mintstatus(CPURISCVState *env, int csrno, target_ulon= g *val)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0*val =3D env->mintstatus;
@@ -982,6 +1056,44 @@ static int rmw_sip(CPURISCVState *env, int csrno, tar= get_ulong *ret_value,
=C2=A0 =C2=A0 =C2=A0return ret;
=C2=A0}

+static int rmw_snxti(CPURISCVState *env, int csrno, target_ulong *ret_valu= e,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0target_ulong new_value, target_ulong write_mask)
+{
+=C2=A0 =C2=A0 int clic_priv, clic_il, clic_irq;
+=C2=A0 =C2=A0 bool ready;
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mstatus |=3D new_value & (write_ma= sk & 0b11111);

Same to rmw_mnxti()<= /div>

Regards,
Frank Chang
=C2=A0
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 qemu_mutex_lock_iothread();
+=C2=A0 =C2=A0 ready =3D get_xnxti_status(env);
+=C2=A0 =C2=A0 if (ready) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool edge =3D riscv_clic_edge_tr= iggered(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 cs->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (edge) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_clean_p= ending(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cs= ->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mintstatus =3D set_field= (env->mintstatus,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MINTSTAT= US_SIL, clic_il);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->scause =3D set_field(env= ->scause, SCAUSE_EXCCODE, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D (env->stvt &am= p; ~0x3f) + sizeof(target_ulong) * clic_irq;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D 0;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 qemu_mutex_unlock_iothread();
+=C2=A0 =C2=A0 return 0;
+}
+
=C2=A0static int read_sintstatus(CPURISCVState *env, int csrno, target_ulon= g *val)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0target_ulong mask =3D SINTSTATUS_SIL | SINTSTATUS_UIL;<= br> @@ -1755,6 +1867,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D {
=C2=A0 =C2=A0 =C2=A0/* Machine Mode Core Level Interrupt Controller */
=C2=A0 =C2=A0 =C2=A0[CSR_MTVT] =3D { "mtvt", clic,=C2=A0 read_mtv= t,=C2=A0 write_mtvt=C2=A0 =C2=A0 =C2=A0 },
+=C2=A0 =C2=A0 [CSR_MNXTI] =3D { "mnxti", clic,=C2=A0 NULL,=C2=A0= NULL,=C2=A0 rmw_mnxti=C2=A0 =C2=A0},
=C2=A0 =C2=A0 =C2=A0[CSR_MINTSTATUS] =3D { "mintstatus", clic,=C2= =A0 read_mintstatus },
=C2=A0 =C2=A0 =C2=A0[CSR_MINTTHRESH] =3D { "mintthresh", clic,=C2= =A0 read_mintthresh,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 write_mintthresh },
@@ -1766,6 +1879,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D {
=C2=A0 =C2=A0 =C2=A0/* Supervisor Mode Core Level Interrupt Controller */ =C2=A0 =C2=A0 =C2=A0[CSR_STVT] =3D { "stvt", clic,=C2=A0 read_stv= t, write_stvt=C2=A0 =C2=A0 =C2=A0 =C2=A0},
+=C2=A0 =C2=A0 [CSR_SNXTI] =3D { "snxti", clic,=C2=A0 NULL,=C2=A0= NULL,=C2=A0 rmw_snxti=C2=A0 =C2=A0},

=C2=A0#endif /* !CONFIG_USER_ONLY */
=C2=A0};
--
2.25.1


--000000000000d63ae205c6c6247c-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m2ESq-0004U7-Mq for mharc-qemu-riscv@gnu.org; Sat, 10 Jul 2021 11:00:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2ESj-0004Tl-Rl for qemu-riscv@nongnu.org; Sat, 10 Jul 2021 11:00:19 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:35377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2ESg-0006rE-PR for qemu-riscv@nongnu.org; Sat, 10 Jul 2021 11:00:12 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d12so11659980pfj.2 for ; Sat, 10 Jul 2021 08:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pbUS5zBcn7GWg3pEUnXUL/wEJn67PeEAHEfQxo5y/+o=; b=OKIThW/g8y8u+ELEXPaJivD3sRd+TKMn3lYOu2Gb/s9aVbSleITJUzueIhY/R0Ccku UlKamc2yI3WNAv9Qps0roZHVOdtk3EX3f8RYKmBX0m0qcX9GwGBZPd1xZByMUWOnRcA2 eruECBUDdpEw6d86KzpL2uvD9A8laPB/xBFwf76xQP53SGTmdM7usF6rUXgQ6YSKhrSo P38m2tTuG4goTHkvX0h/XbSEHVChjM9l07TRzuW2ro0+EAMjsYnUXnoRB8vcmkZsKwqA +Cqyu6wKj+5Xem64Tie2rHFQqPcAILpeeXO6DQUxT3KoY2ptW2+/jghi/SYoixxVKpP8 Lo/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pbUS5zBcn7GWg3pEUnXUL/wEJn67PeEAHEfQxo5y/+o=; b=qdqf9UHRp9Xl8b9fzxyUJvKvyB60r3rNlpRD+eu+LYn9T3dWAKgW44boNpzY2ZrUrx 4xtrUa/pEupTfLdFrsQmVk/FcypTqWSSMr7Ue2FY6STY5tdxcoHjqzE8fD6Qt1pS4JHZ k14Xcq6qy1Ytx7sOBrgPcD221P6TwN+aEGbMJFkWj+GbvfFjXJ/Fa7rnJMB5OUecEp0F 7dHQVyYqgkf35kDX8lJ+ntZ4KD2dyAjQTbBDTcAyPyT5W93vfuydyF5/ef+pbamnxqs8 eteBouj/kSoWn4eBr76JHQyXbOgiTai5EhDuPV6tky+8s0vxJm/zo9O63YkI4bdyEfDP 3PYw== X-Gm-Message-State: AOAM532R8LvkjHO9d/Yyk1MtIEHjvlt0dcMiDAUVEtC9Fr1tgmABGWh2 ImeIEb7Q9a/lH7iw+4zb6wdgGulj34KlIQ== X-Google-Smtp-Source: ABdhPJwpq4Ai0eVsJteSrX7iLes3PXJ/lPM5guZwd2UuhGEyooe38/b+H2P0mFTEnaDioCyXaSV9Zg== X-Received: by 2002:a63:4f62:: with SMTP id p34mr10920137pgl.283.1625929208532; Sat, 10 Jul 2021 08:00:08 -0700 (PDT) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com. [209.85.216.44]) by smtp.gmail.com with ESMTPSA id l11sm1420304pjw.45.2021.07.10.08.00.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Jul 2021 08:00:07 -0700 (PDT) Received: by mail-pj1-f44.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso7767342pjp.2; Sat, 10 Jul 2021 08:00:07 -0700 (PDT) X-Received: by 2002:a17:90a:17cd:: with SMTP id q71mr25501547pja.47.1625929207395; Sat, 10 Jul 2021 08:00:07 -0700 (PDT) MIME-Version: 1.0 References: <20210409074857.166082-1-zhiwei_liu@c-sky.com> <20210409074857.166082-9-zhiwei_liu@c-sky.com> In-Reply-To: <20210409074857.166082-9-zhiwei_liu@c-sky.com> From: Frank Chang Date: Sat, 10 Jul 2021 22:59:56 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 08/11] target/riscv: Update CSR xnxti in CLIC mode To: LIU Zhiwei Cc: "qemu-devel@nongnu.org Developers" , "open list:RISC-V" , Palmer Dabbelt , Alistair Francis , wxy194768@alibaba-inc.com Content-Type: multipart/alternative; boundary="000000000000d63ae205c6c6247c" Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=frank.chang@sifive.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Jul 2021 15:00:19 -0000 --000000000000d63ae205c6c6247c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable LIU Zhiwei =E6=96=BC 2021=E5=B9=B44=E6=9C=889=E6=97= =A5 =E9=80=B1=E4=BA=94 =E4=B8=8B=E5=8D=883:52=E5=AF=AB=E9=81=93=EF=BC=9A > The CSR can be used by software to service the next horizontal interrupt > when it has greater level than the saved interrupt context > (held in xcause`.pil`) and greater level than the interrupt threshold of > the corresponding privilege mode, > > Signed-off-by: LIU Zhiwei > --- > target/riscv/cpu_bits.h | 16 ++++++ > target/riscv/csr.c | 114 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 130 insertions(+) > > diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h > index 7922097776..494e41edc9 100644 > --- a/target/riscv/cpu_bits.h > +++ b/target/riscv/cpu_bits.h > @@ -166,6 +166,7 @@ > #define CSR_MCAUSE 0x342 > #define CSR_MTVAL 0x343 > #define CSR_MIP 0x344 > +#define CSR_MNXTI 0x345 /* clic-spec-draft */ > #define CSR_MINTSTATUS 0x346 /* clic-spec-draft */ > #define CSR_MINTTHRESH 0x347 /* clic-spec-draft */ > > @@ -187,6 +188,7 @@ > #define CSR_SCAUSE 0x142 > #define CSR_STVAL 0x143 > #define CSR_SIP 0x144 > +#define CSR_SNXTI 0x145 /* clic-spec-draft */ > #define CSR_SINTSTATUS 0x146 /* clic-spec-draft */ > #define CSR_SINTTHRESH 0x147 /* clic-spec-draft */ > > @@ -596,10 +598,24 @@ > #define MINTSTATUS_SIL 0x0000ff00 /* sil[7:0] */ > #define MINTSTATUS_UIL 0x000000ff /* uil[7:0] */ > > +/* mcause */ > +#define MCAUSE_MINHV 0x40000000 /* minhv */ > +#define MCAUSE_MPP 0x30000000 /* mpp[1:0] */ > +#define MCAUSE_MPIE 0x08000000 /* mpie */ > +#define MCAUSE_MPIL 0x00ff0000 /* mpil[7:0] */ > +#define MCAUSE_EXCCODE 0x00000fff /* exccode[11:0] *= / > + > /* sintstatus */ > #define SINTSTATUS_SIL 0x0000ff00 /* sil[7:0] */ > #define SINTSTATUS_UIL 0x000000ff /* uil[7:0] */ > > +/* scause */ > +#define SCAUSE_SINHV 0x40000000 /* sinhv */ > +#define SCAUSE_SPP 0x10000000 /* spp */ > +#define SCAUSE_SPIE 0x08000000 /* spie */ > +#define SCAUSE_SPIL 0x00ff0000 /* spil[7:0] */ > +#define SCAUSE_EXCCODE 0x00000fff /* exccode[11:0] *= / > + > /* MIE masks */ > #define MIE_SEIE (1 << IRQ_S_EXT) > #define MIE_UEIE (1 << IRQ_U_EXT) > diff --git a/target/riscv/csr.c b/target/riscv/csr.c > index e12222b77f..72cba080bf 100644 > --- a/target/riscv/csr.c > +++ b/target/riscv/csr.c > @@ -774,6 +774,80 @@ static int rmw_mip(CPURISCVState *env, int csrno, > target_ulong *ret_value, > return 0; > } > > +static bool get_xnxti_status(CPURISCVState *env) > +{ > + CPUState *cs =3D env_cpu(env); > + int clic_irq, clic_priv, clic_il, pil; > + > + if (!env->exccode) { /* No interrupt */ > + return false; > + } > + /* The system is not in a CLIC mode */ > + if (!riscv_clic_is_clic_mode(env)) { > + return false; > + } else { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + > + if (env->priv =3D=3D PRV_M) { > + pil =3D MAX(get_field(env->mcause, MCAUSE_MPIL), > env->mintthresh); > + } else if (env->priv =3D=3D PRV_S) { > + pil =3D MAX(get_field(env->scause, SCAUSE_SPIL), > env->sintthresh); > + } else { > + qemu_log_mask(LOG_GUEST_ERROR, > + "CSR: rmw xnxti with unsupported mode\n"); > + exit(1); > + } > + > + if ((clic_priv !=3D env->priv) || /* No horizontal interrupt */ > + (clic_il <=3D pil) || /* No higher level interrupt */ > + (riscv_clic_shv_interrupt(env->clic, clic_priv, cs->cpu_inde= x, > + clic_irq))) { /* CLIC vector mode = */ > + return false; > + } else { > + return true; > + } > + } > +} > + > +static int rmw_mnxti(CPURISCVState *env, int csrno, target_ulong > *ret_value, > + target_ulong new_value, target_ulong write_mask) > +{ > + int clic_priv, clic_il, clic_irq; > + bool ready; > + CPUState *cs =3D env_cpu(env); > + if (write_mask) { > + env->mstatus |=3D new_value & (write_mask & 0b11111); > This won't work for CSRRCI instruction. new_value is assigned to 0 for CSRRCI operation. Should be: target_ulong mask =3D write_mask & 0b11111; env->mstatus =3D (env->mstatus & ~mask) | (new_value & mask); > + } > + > + qemu_mutex_lock_iothread(); > + ready =3D get_xnxti_status(env); > + if (ready) { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + if (write_mask) { > + bool edge =3D riscv_clic_edge_triggered(env->clic, clic_priv= , > + cs->cpu_index, > clic_irq); > + if (edge) { > + riscv_clic_clean_pending(env->clic, clic_priv, > + cs->cpu_index, clic_irq); > + } > + env->mintstatus =3D set_field(env->mintstatus, > + MINTSTATUS_MIL, clic_il); > + env->mcause =3D set_field(env->mcause, MCAUSE_EXCCODE, > clic_irq); > + } > + if (ret_value) { > + *ret_value =3D (env->mtvt & ~0x3f) + sizeof(target_ulong) * > clic_irq; > + } > + } else { > + if (ret_value) { > + *ret_value =3D 0; > + } > + } > + qemu_mutex_unlock_iothread(); > + return 0; > +} > + > static int read_mintstatus(CPURISCVState *env, int csrno, target_ulong > *val) > { > *val =3D env->mintstatus; > @@ -982,6 +1056,44 @@ static int rmw_sip(CPURISCVState *env, int csrno, > target_ulong *ret_value, > return ret; > } > > +static int rmw_snxti(CPURISCVState *env, int csrno, target_ulong > *ret_value, > + target_ulong new_value, target_ulong write_mask) > +{ > + int clic_priv, clic_il, clic_irq; > + bool ready; > + CPUState *cs =3D env_cpu(env); > + if (write_mask) { > + env->mstatus |=3D new_value & (write_mask & 0b11111); > Same to rmw_mnxti() Regards, Frank Chang > + } > + > + qemu_mutex_lock_iothread(); > + ready =3D get_xnxti_status(env); > + if (ready) { > + riscv_clic_decode_exccode(env->exccode, &clic_priv, &clic_il, > + &clic_irq); > + if (write_mask) { > + bool edge =3D riscv_clic_edge_triggered(env->clic, clic_priv= , > + cs->cpu_index, > clic_irq); > + if (edge) { > + riscv_clic_clean_pending(env->clic, clic_priv, > + cs->cpu_index, clic_irq); > + } > + env->mintstatus =3D set_field(env->mintstatus, > + MINTSTATUS_SIL, clic_il); > + env->scause =3D set_field(env->scause, SCAUSE_EXCCODE, > clic_irq); > + } > + if (ret_value) { > + *ret_value =3D (env->stvt & ~0x3f) + sizeof(target_ulong) * > clic_irq; > + } > + } else { > + if (ret_value) { > + *ret_value =3D 0; > + } > + } > + qemu_mutex_unlock_iothread(); > + return 0; > +} > + > static int read_sintstatus(CPURISCVState *env, int csrno, target_ulong > *val) > { > target_ulong mask =3D SINTSTATUS_SIL | SINTSTATUS_UIL; > @@ -1755,6 +1867,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { > > /* Machine Mode Core Level Interrupt Controller */ > [CSR_MTVT] =3D { "mtvt", clic, read_mtvt, write_mtvt }, > + [CSR_MNXTI] =3D { "mnxti", clic, NULL, NULL, rmw_mnxti }, > [CSR_MINTSTATUS] =3D { "mintstatus", clic, read_mintstatus }, > [CSR_MINTTHRESH] =3D { "mintthresh", clic, read_mintthresh, > write_mintthresh }, > @@ -1766,6 +1879,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { > > /* Supervisor Mode Core Level Interrupt Controller */ > [CSR_STVT] =3D { "stvt", clic, read_stvt, write_stvt }, > + [CSR_SNXTI] =3D { "snxti", clic, NULL, NULL, rmw_snxti }, > > #endif /* !CONFIG_USER_ONLY */ > }; > -- > 2.25.1 > > > --000000000000d63ae205c6c6247c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
LIU Zhiwei <zhiwei_liu@c-sky.com> =E6=96=BC 2021=E5=B9=B44=E6=9C= =889=E6=97=A5 =E9=80=B1=E4=BA=94 =E4=B8=8B=E5=8D=883:52=E5=AF=AB=E9=81=93= =EF=BC=9A
The CSR can be used by software to service the next ho= rizontal interrupt
when it has greater level than the saved interrupt context
(held in xcause`.pil`) and greater level than the interrupt threshold of the corresponding privilege mode,

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
=C2=A0target/riscv/cpu_bits.h |=C2=A0 16 ++++++
=C2=A0target/riscv/csr.c=C2=A0 =C2=A0 =C2=A0 | 114 ++++++++++++++++++++++++= ++++++++++++++++
=C2=A02 files changed, 130 insertions(+)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 7922097776..494e41edc9 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -166,6 +166,7 @@
=C2=A0#define CSR_MCAUSE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x342
=C2=A0#define CSR_MTVAL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x343
=C2=A0#define CSR_MIP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x344<= br> +#define CSR_MNXTI=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x345 /* clic-sp= ec-draft */
=C2=A0#define CSR_MINTSTATUS=C2=A0 =C2=A0 =C2=A0 0x346 /* clic-spec-draft *= /
=C2=A0#define CSR_MINTTHRESH=C2=A0 =C2=A0 =C2=A0 0x347 /* clic-spec-draft *= /

@@ -187,6 +188,7 @@
=C2=A0#define CSR_SCAUSE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x142
=C2=A0#define CSR_STVAL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x143
=C2=A0#define CSR_SIP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x144<= br> +#define CSR_SNXTI=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x145 /* clic-sp= ec-draft */
=C2=A0#define CSR_SINTSTATUS=C2=A0 =C2=A0 =C2=A0 0x146 /* clic-spec-draft *= /
=C2=A0#define CSR_SINTTHRESH=C2=A0 =C2=A0 =C2=A0 0x147 /* clic-spec-draft *= /

@@ -596,10 +598,24 @@
=C2=A0#define MINTSTATUS_SIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x0000ff00 /* sil[7:0] */
=C2=A0#define MINTSTATUS_UIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x000000ff /* uil[7:0] */

+/* mcause */
+#define MCAUSE_MINHV=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x40000000 /* minhv */
+#define MCAUSE_MPP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x30000000 /* mpp[1:0] */
+#define MCAUSE_MPIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x08000000 /* mpie */
+#define MCAUSE_MPIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00ff0000 /* mpil[7:0] */
+#define MCAUSE_EXCCODE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00x00000fff /* exccode[11:0] */
+
=C2=A0/* sintstatus */
=C2=A0#define SINTSTATUS_SIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x0000ff00 /* sil[7:0] */
=C2=A0#define SINTSTATUS_UIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x000000ff /* uil[7:0] */

+/* scause */
+#define SCAUSE_SINHV=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x40000000 /* sinhv */
+#define SCAUSE_SPP=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00x10000000 /* spp */
+#define SCAUSE_SPIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x08000000 /* spie */
+#define SCAUSE_SPIL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00ff0000 /* spil[7:0] */
+#define SCAUSE_EXCCODE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A00x00000fff /* exccode[11:0] */
+
=C2=A0/* MIE masks */
=C2=A0#define MIE_SEIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(1 << IRQ_S_EXT)
=C2=A0#define MIE_UEIE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(1 << IRQ_U_EXT)
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index e12222b77f..72cba080bf 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -774,6 +774,80 @@ static int rmw_mip(CPURISCVState *env, int csrno, targ= et_ulong *ret_value,
=C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0}

+static bool get_xnxti_status(CPURISCVState *env)
+{
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 int clic_irq, clic_priv, clic_il, pil;
+
+=C2=A0 =C2=A0 if (!env->exccode) { /* No interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 /* The system is not in a CLIC mode */
+=C2=A0 =C2=A0 if (!riscv_clic_is_clic_mode(env)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (env->priv =3D=3D PRV_M) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pil =3D MAX(get_field(env->mc= ause, MCAUSE_MPIL), env->mintthresh);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else if (env->priv =3D=3D PRV_S) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pil =3D MAX(get_field(env->sc= ause, SCAUSE_SPIL), env->sintthresh);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qemu_log_mask(LOG_GUEST_ERROR, +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "CSR: rmw xnxti with unsupported mode\n");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 exit(1);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ((clic_priv !=3D env->priv) || /* No hor= izontal interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (clic_il <=3D pil) || /* No h= igher level interrupt */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (riscv_clic_shv_interrupt(env-&g= t;clic, clic_priv, cs->cpu_index,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clic_irq))) { /= * CLIC vector mode */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return false;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+}
+
+static int rmw_mnxti(CPURISCVState *env, int csrno, target_ulong *ret_valu= e,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0target_ulong new_value, target_ulong write_mask)
+{
+=C2=A0 =C2=A0 int clic_priv, clic_il, clic_irq;
+=C2=A0 =C2=A0 bool ready;
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mstatus |=3D new_value & (write_ma= sk & 0b11111);

This won't work = for CSRRCI instruction.
new_value is assigned to 0 for CSRRCI ope= ration.

Should be:
target_ulong mask =3D= write_mask & 0b11111;
env->mstatus =3D (env->mstat= us & ~mask) | (new_value & mask);
=C2=A0
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 qemu_mutex_lock_iothread();
+=C2=A0 =C2=A0 ready =3D get_xnxti_status(env);
+=C2=A0 =C2=A0 if (ready) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool edge =3D riscv_clic_edge_tr= iggered(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 cs->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (edge) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_clean_p= ending(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cs= ->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mintstatus =3D set_field= (env->mintstatus,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MINTSTAT= US_MIL, clic_il);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mcause =3D set_field(env= ->mcause, MCAUSE_EXCCODE, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D (env->mtvt &am= p; ~0x3f) + sizeof(target_ulong) * clic_irq;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D 0;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 qemu_mutex_unlock_iothread();
+=C2=A0 =C2=A0 return 0;
+}
+
=C2=A0static int read_mintstatus(CPURISCVState *env, int csrno, target_ulon= g *val)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0*val =3D env->mintstatus;
@@ -982,6 +1056,44 @@ static int rmw_sip(CPURISCVState *env, int csrno, tar= get_ulong *ret_value,
=C2=A0 =C2=A0 =C2=A0return ret;
=C2=A0}

+static int rmw_snxti(CPURISCVState *env, int csrno, target_ulong *ret_valu= e,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0target_ulong new_value, target_ulong write_mask)
+{
+=C2=A0 =C2=A0 int clic_priv, clic_il, clic_irq;
+=C2=A0 =C2=A0 bool ready;
+=C2=A0 =C2=A0 CPUState *cs =3D env_cpu(env);
+=C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mstatus |=3D new_value & (write_ma= sk & 0b11111);

Same to rmw_mnxti()<= /div>

Regards,
Frank Chang
=C2=A0
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 qemu_mutex_lock_iothread();
+=C2=A0 =C2=A0 ready =3D get_xnxti_status(env);
+=C2=A0 =C2=A0 if (ready) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_decode_exccode(env->exccode, &am= p;clic_priv, &clic_il,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (write_mask) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool edge =3D riscv_clic_edge_tr= iggered(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 cs->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (edge) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 riscv_clic_clean_p= ending(env->clic, clic_priv,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cs= ->cpu_index, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->mintstatus =3D set_field= (env->mintstatus,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 MINTSTAT= US_SIL, clic_il);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 env->scause =3D set_field(env= ->scause, SCAUSE_EXCCODE, clic_irq);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D (env->stvt &am= p; ~0x3f) + sizeof(target_ulong) * clic_irq;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret_value) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *ret_value =3D 0;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 qemu_mutex_unlock_iothread();
+=C2=A0 =C2=A0 return 0;
+}
+
=C2=A0static int read_sintstatus(CPURISCVState *env, int csrno, target_ulon= g *val)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0target_ulong mask =3D SINTSTATUS_SIL | SINTSTATUS_UIL;<= br> @@ -1755,6 +1867,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D {
=C2=A0 =C2=A0 =C2=A0/* Machine Mode Core Level Interrupt Controller */
=C2=A0 =C2=A0 =C2=A0[CSR_MTVT] =3D { "mtvt", clic,=C2=A0 read_mtv= t,=C2=A0 write_mtvt=C2=A0 =C2=A0 =C2=A0 },
+=C2=A0 =C2=A0 [CSR_MNXTI] =3D { "mnxti", clic,=C2=A0 NULL,=C2=A0= NULL,=C2=A0 rmw_mnxti=C2=A0 =C2=A0},
=C2=A0 =C2=A0 =C2=A0[CSR_MINTSTATUS] =3D { "mintstatus", clic,=C2= =A0 read_mintstatus },
=C2=A0 =C2=A0 =C2=A0[CSR_MINTTHRESH] =3D { "mintthresh", clic,=C2= =A0 read_mintthresh,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 write_mintthresh },
@@ -1766,6 +1879,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D {
=C2=A0 =C2=A0 =C2=A0/* Supervisor Mode Core Level Interrupt Controller */ =C2=A0 =C2=A0 =C2=A0[CSR_STVT] =3D { "stvt", clic,=C2=A0 read_stv= t, write_stvt=C2=A0 =C2=A0 =C2=A0 =C2=A0},
+=C2=A0 =C2=A0 [CSR_SNXTI] =3D { "snxti", clic,=C2=A0 NULL,=C2=A0= NULL,=C2=A0 rmw_snxti=C2=A0 =C2=A0},

=C2=A0#endif /* !CONFIG_USER_ONLY */
=C2=A0};
--
2.25.1


--000000000000d63ae205c6c6247c--