qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Libo Zhou" <zhlb29@foxmail.com>
To: qemu-devel <qemu-devel@nongnu.org>
Subject: Why on earth is this code giving me Segfaults?
Date: Sun, 29 Sep 2019 12:04:09 +0800	[thread overview]
Message-ID: <tencent_76DBE21F6D585D0B6F510084@qq.com> (raw)

Hi All,

I have a custom ISA that's based on MIPS. The LW and SW instructions' opcodes are changed into 0x17(OPC_BGTZL) and 0x1F(OPC_SPECIAL3).

I have made the following changes in target/mips/translate.c:

@@ -29331,7 +29331,11 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)
             decode_opc_special3(env, ctx);
         }
 #else
-        decode_opc_special3(env, ctx);
+        if (ctx->insn_flags & INSN_MYISA) {
+            gen_st(ctx, OPC_SW, rt, rs, imm); /* OPC_MYISA_SW */
+        } else {
+            decode_opc_special3(env, ctx);
+        }
 #endif
         break;
     case OPC_REGIMM:
@@ -29589,6 +29603,8 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)
             }
             /* OPC_BGTZC, OPC_BLTZC, OPC_BLTC */
             gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
+        } else if (ctx->insn_flags & INSN_MYISA) {
+            gen_ld(ctx, OPC_LW, rt, rs, imm); /* OPC_MYISA_LW */
         } else {
             /* OPC_BGTZL */
             gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);

I used gdbstub to singlestep my program, and I found that my sw instruction is working fine, but lw gives me a segfault. I have been stuck on this for a long while, since it looks like I only need to add that one line of gen_ld function. I also tried debugging QEMU wtih gdb, but the segfault wasn't thrown immediately after lw instruction like gdbstub does.

Does anyone have any advice?

Thanks,
Libo Zhou

             reply	other threads:[~2019-09-29  4:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-29  4:04 Libo Zhou [this message]
2019-09-29  7:39 ` Re:Why on earth is this code giving me Segfaults? Libo Zhou

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=tencent_76DBE21F6D585D0B6F510084@qq.com \
    --to=zhlb29@foxmail.com \
    --cc=qemu-devel@nongnu.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).