qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kele Huang <kele.hwang@gmail.com>
To: qemu-devel@nongnu.org
Cc: Xu Zou <iwatchnima@gmail.com>, Kele Huang <kele.hwang@gmail.com>
Subject: [PATCH v2 1/1] accel/tcg: Fix computing of is_write for mips
Date: Wed, 23 Sep 2020 17:38:00 +0800	[thread overview]
Message-ID: <20200923093800.9845-1-kele.hwang@gmail.com> (raw)
In-Reply-To: <503406>

Detect mips store instructions in cpu_signal_handler for all MIPS
versions, and set is_write if encountering such store instructions.

This fixed the error while dealing with self-modifed code for MIPS.

Signed-off-by: Kele Huang <kele.hwang@gmail.com>
Signed-off-by: Xu Zou <iwatchnima@gmail.com>
---
 accel/tcg/user-exec.c | 51 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
index bb039eb32d..18784516e5 100644
--- a/accel/tcg/user-exec.c
+++ b/accel/tcg/user-exec.c
@@ -710,11 +710,60 @@ int cpu_signal_handler(int host_signum, void *pinfo,
     greg_t pc = uc->uc_mcontext.pc;
     int is_write;
 
-    /* XXX: compute is_write */
     is_write = 0;
+
+    /* Detect store by reading the instruction at the program counter. */
+    uint32_t insn = *(uint32_t *)pc;
+    switch(insn>>29) {
+    case 0x5:
+        switch((insn>>26) & 0x7) {
+        case 0x0: /* SB */
+        case 0x1: /* SH */
+        case 0x2: /* SWL */
+        case 0x3: /* SW */
+        case 0x4: /* SDL */
+        case 0x5: /* SDR */
+        case 0x6: /* SWR */
+            is_write = 1;
+        }
+        break;
+    case 0x7:
+        switch((insn>>26) & 0x7) {
+        case 0x0: /* SC */
+        case 0x1: /* SWC1 */
+        case 0x4: /* SCD */
+        case 0x5: /* SDC1 */
+        case 0x7: /* SD */
+#if !defined(__mips_isa_rev) || __mips_isa_rev < 6
+        case 0x2: /* SWC2 */
+        case 0x6: /* SDC2 */
+#endif
+            is_write = 1;
+        }
+        break;
+    }
+
+    /*
+     * Required in all versions of MIPS64 since MIPS64r1. Not available
+     * in MIPS32r1. Required by MIPS32r2 and subsequent versions of MIPS32.
+     */
+    switch ((insn >> 3) & 0x7) {
+    case 0x1:
+        switch (insn & 0x7) {
+        case 0x0: /* SWXC1 */
+        case 0x1: /* SDXC1 */
+            is_write = 1;
+        }
+        break;
+    }
+
     return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 }
 
+#elif defined(__misp16) || defined(__mips_micromips)
+
+#error "Unsupported encoding"
+
 #elif defined(__riscv)
 
 int cpu_signal_handler(int host_signum, void *pinfo,
-- 
2.17.1



  parent reply	other threads:[~2020-09-23  9:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <503406>
2020-09-10  7:43 ` [PATCH 0/1] accel/tcg: Fix computing is_write for mips Kele Huang
2020-09-10  7:43   ` [PATCH 1/1] " Kele Huang
2020-09-10 17:18     ` Richard Henderson
2020-09-24  8:59       ` Kele Huang
2020-09-23  9:38 ` Kele Huang [this message]
2020-09-23 11:08   ` [PATCH v2 1/1] accel/tcg: Fix computing of " Philippe Mathieu-Daudé
2020-09-24  8:52     ` Kele Huang
2020-09-24 10:01     ` Kele Huang
2020-09-24 14:05   ` Richard Henderson
2020-09-25  8:34     ` Kele Huang

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=20200923093800.9845-1-kele.hwang@gmail.com \
    --to=kele.hwang@gmail.com \
    --cc=iwatchnima@gmail.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).