From: Alistair Francis <alistair23@gmail.com>
To: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
Cc: Alistair Francis <alistair.francis@wdc.com>,
Richard Henderson <richard.henderson@linaro.org>,
"open list:RISC-V" <qemu-riscv@nongnu.org>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [PATCH] target/riscv: Prevent lost illegal instruction exceptions
Date: Fri, 19 Mar 2021 09:52:54 -0400 [thread overview]
Message-ID: <CAKmqyKMp3aRCjRq2_c+_uybSS_GZDip8C3hoH5an=5a1A+1Lew@mail.gmail.com> (raw)
In-Reply-To: <20210316150354.1948265-1-georg.kotheimer@kernkonzept.com>
On Tue, Mar 16, 2021 at 11:05 AM Georg Kotheimer
<georg.kotheimer@kernkonzept.com> wrote:
>
> When decode_insn16() fails, we fall back to decode_RV32_64C() for
> further compressed instruction decoding. However, prior to this change,
> we did not raise an illegal instruction exception, if decode_RV32_64C()
> fails to decode the instruction. This means that we skipped illegal
> compressed instructions instead of raising an illegal instruction
> exception.
>
> Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/translate.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/target/riscv/translate.c b/target/riscv/translate.c
> index 0f28b5f41e..8c00734252 100644
> --- a/target/riscv/translate.c
> +++ b/target/riscv/translate.c
> @@ -537,7 +537,7 @@ static void gen_set_rm(DisasContext *ctx, int rm)
> tcg_temp_free_i32(t0);
> }
>
> -static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
> +static bool decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
> {
> uint8_t funct3 = extract16(opcode, 13, 3);
> uint8_t rd_rs2 = GET_C_RS2S(opcode);
> @@ -554,7 +554,7 @@ static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
> gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s,
> GET_C_LW_IMM(opcode));
> #endif
> - break;
> + return true;
> case 7:
> #if defined(TARGET_RISCV64)
> /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/
> @@ -565,18 +565,21 @@ static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
> gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2,
> GET_C_LW_IMM(opcode));
> #endif
> - break;
> + return true;
> + default:
> + return false;
> }
> }
>
> -static void decode_RV32_64C(DisasContext *ctx, uint16_t opcode)
> +static bool decode_RV32_64C(DisasContext *ctx, uint16_t opcode)
> {
> uint8_t op = extract16(opcode, 0, 2);
>
> switch (op) {
> case 0:
> - decode_RV32_64C0(ctx, opcode);
> - break;
> + return decode_RV32_64C0(ctx, opcode);
> + default:
> + return false;
> }
> }
>
> @@ -780,7 +783,9 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
> ctx->pc_succ_insn = ctx->base.pc_next + 2;
> if (!decode_insn16(ctx, opcode)) {
> /* fall back to old decoder */
> - decode_RV32_64C(ctx, opcode);
> + if (!decode_RV32_64C(ctx, opcode)) {
> + gen_exception_illegal(ctx);
> + }
> }
> }
> } else {
> --
> 2.30.1
>
>
next prev parent reply other threads:[~2021-03-19 13:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 15:03 [PATCH] target/riscv: Prevent lost illegal instruction exceptions Georg Kotheimer
2021-03-19 13:52 ` Alistair Francis [this message]
2021-03-19 15:22 ` Richard Henderson
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='CAKmqyKMp3aRCjRq2_c+_uybSS_GZDip8C3hoH5an=5a1A+1Lew@mail.gmail.com' \
--to=alistair23@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=georg.kotheimer@kernkonzept.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.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 NNTP newsgroup(s).