Skip to contentSkip to conversation

target/riscv: Set opcode to env->bins for illegal/virtual instruction fault

PATCH Applied Weiwei Li 3 participants 4 messages Mar 30, 2023 – Apr 5, 2023 RISC-V

lore
Share & tools
lore

Weiwei Li

author
#0 lore raw

PATCH 1/1 target/riscv: Set opcode to env->bins for illegal/virtual instruction fault

decode_save_opc() will not work for generate_exception(), since 0 is passed to riscv_raise_exception() as pc in helper_raise_exception(), and bins will not be restored in this case.

---
 target/riscv/insn_trans/trans_rvh.c.inc | 2 ++
 1 file changed, 2 insertions(+)
target/riscv/insn_trans/trans_rvh.c.inc +2 -0
index 9248b48c36..4b730cd492 100644
@@ -20,6 +20,8 @@
 static bool check_access(DisasContext *ctx)
 {
     if (!ctx->hlsx) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env,
+                       offsetof(CPURISCVState, bins));
         if (ctx->virt_enabled) {
             generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT);
         } else {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Weiwei Li

decode_save_opc() will not work for generate_exception(), since 0 is passed to riscv_raise_exception() as pc in helper_raise_exception(), and bins will not be restored in this case.

---

Quoted 16 lines
  target/riscv/insn_trans/trans_rvh.c.inc | 2 ++
  1 file changed, 2 insertions(+)
target/riscv/insn_trans/trans_rvh.c.inc +2 -0
index 9248b48c36..4b730cd492 100644
@@ -20,6 +20,8 @@
  static bool check_access(DisasContext *ctx)
  {
      if (!ctx->hlsx) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env,
+                       offsetof(CPURISCVState, bins));
          if (ctx->virt_enabled) {
              generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT);
          } else {
Acked-by on v1 1/1
#2 lore raw
In reply to Weiwei Li
Quoted 7 lines · Weiwei Li

decode_save_opc() will not work for generate_exception(), since 0 is passed to riscv_raise_exception() as pc in helper_raise_exception(), and bins will not be restored in this case.

Alistair

Quoted 21 lines
---
 target/riscv/insn_trans/trans_rvh.c.inc | 2 ++
 1 file changed, 2 insertions(+)
target/riscv/insn_trans/trans_rvh.c.inc +2 -1
index 9248b48c36..4b730cd492 100644
@@ -20,6 +20,8 @@
 static bool check_access(DisasContext *ctx)
 {
     if (!ctx->hlsx) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env,
+                       offsetof(CPURISCVState, bins));
         if (ctx->virt_enabled) {
             generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT);
         } else {
--

2.25.1

#3 lore raw
In reply to Weiwei Li
Quoted 7 lines · Weiwei Li

decode_save_opc() will not work for generate_exception(), since 0 is passed to riscv_raise_exception() as pc in helper_raise_exception(), and bins will not be restored in this case.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 21 lines
---
 target/riscv/insn_trans/trans_rvh.c.inc | 2 ++
 1 file changed, 2 insertions(+)
target/riscv/insn_trans/trans_rvh.c.inc +2 -1
index 9248b48c36..4b730cd492 100644
@@ -20,6 +20,8 @@
 static bool check_access(DisasContext *ctx)
 {
     if (!ctx->hlsx) {
+        tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env,
+                       offsetof(CPURISCVState, bins));
         if (ctx->virt_enabled) {
             generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT);
         } else {
--

2.25.1