Skip to contentSkip to conversation

Update capstone module

PATCH Superseded Richard Henderson 5 participants 19 messages May 23, 2019 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Update capstone module

There has recently been some good progress in the upstream capstone repository, syncing the instruction sets from the (further) upstream llvm.

In particular, there are Power9 and System z13 instructions. Both of which were missing from our current snapshot and from our (ancient) binutils opcodes snapshots.

r~

Richard Henderson (3):
capstone: Adjust include of capstone.h
capstone: Update to master
capstone: Enable disassembly for s390x

 Makefile                 |  1 +
 include/disas/capstone.h |  4 ++++
 disas.c                  | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c       |  4 ++++
 capstone                 |  2 +-
 configure                |  7 +++++++
 6 files changed, 57 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 capstone: Adjust include of capstone.h

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +6 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
Signature · 1 line
2.17.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

Quoted 3 lines · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

Quoted 36 lines
---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 9 lines
configure +3 -0
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

--
Alex Bennée

Reviewed-by on v1 1/3
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Richard Henderson
Quoted 40 lines · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 9 lines
configure +3 -0
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by Tested-by on v1 1/3
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Richard Henderson
Quoted 40 lines · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 9 lines
configure +3 -0
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Richard Henderson
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

Quoted 37 lines
---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 9 lines
configure +3 -0
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

   https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

Are you suggesting to not include this patch? It is less invasive to distributions that package QEMU but don't package libcapstone.

Quoted 51 lines
Quoted 38 lines
---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
   no)

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 9 lines
configure +3 -0
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

Regards,
Daniel

#7 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Daniel P. Berrangé
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

Quoted 7 lines
Quoted 4 lines
   https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

Are you suggesting to not include this patch? It is less invasive to distributions that package QEMU but don't package libcapstone.

If building against a bundled capstone, we ought to be able to get the right -I flag to not need this. So its just a question of how how much we care about distros who've not fixed the regression.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
configure +1 -0
   no)
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
Quoted 9 lines

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 5 lines
configure +2 -0
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

Regards,
Daniel

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

   https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

But I think it's worth keeping the workaround in the likely event that it takes a while for that to filter through.

Quoted 36 lines
Quoted 36 lines
---
 include/disas/capstone.h | 4 ++++
 configure                | 6 ++++++
 2 files changed, 10 insertions(+)
include/disas/capstone.h +4 -0
index e29068dd97..90631d84a9 100644
@@ -3,7 +3,11 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef CONFIG_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
 
 #else
 
configure +3 -0
index d2fc346302..eec7f061c3 100755
@@ -5021,6 +5021,9 @@ case "$capstone" in
   system)
     QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags capstone)"
     LIBS="$($pkg_config --libs capstone) $LIBS"
+    if check_include capstone/capstone.h; then
+      capstone_capstone_h=yes
+    fi
     ;;
 
Quoted 14 lines

configure if test "$ivshmem" = "yes" ; then · line 7208

Quoted 11 lines
configure +3 -0
   no)
@@ -7197,6 +7200,9 @@ if test "$ivshmem" = "yes" ; then
 fi
 if test "$capstone" != "no" ; then
   echo "CONFIG_CAPSTONE=y" >> $config_host_mak
+  if test "$capstone_capstone_h" != "no" ; then
+    echo "CONFIG_CAPSTONE_CAPSTONE_H=y" >> $config_host_mak
+  fi
 fi
 if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak

Regards,
Daniel

--
Alex Bennée

#9 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

   https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

Heh. And here's me thinking this was an intentional change.

r~

#10 lore raw

Re: [Qemu-devel] [PATCH 1/3] capstone: Adjust include of capstone.h

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · Richard Henderson

Since v4.0, capstone.h has moved to <capstone/capstone.h>.

NB this was a regression bug in capstone pkg-config file which has been fixed upstream

   https://github.com/aquynh/capstone/pull/1276

In Fedora we pulled in the fix to our v4.0 builds and I'd suggest other distros should do the same

It seems this fix is present in the tagged 4.0 release.

This would have only been present if a distro packaged snapshots. At least one may have done so, based on

https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg00329.html

but there's no further information to go on.

I've checked Fedora 30 and Debian Buster, which are the only two I could immediately identify that shipped 4.0.1, as opposed to some 3.x version. Both have the pkg-config bug fixed.

Since I cannot test any fixup path, I'm going to drop this patch entirely.

r~

#11 lore raw

PATCH 2/3 capstone: Update to master

In reply to Richard Henderson

Update to fbb20ea83c5a. Choose this over the 4.0.1 tag because master now includes the s390x z13 vector opcodes.

---
 capstone  | 2 +-
 configure | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
capstone +1 -1
index 22ead3e0bf..fbb20ea83c 160000
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit fbb20ea83c5af4f29b40c17fbadb1f71b0a08fae
configure +1 -0
index eec7f061c3..a2e4636a34 100755
@@ -5016,6 +5016,7 @@ case "$capstone" in
       LIBCAPSTONE=libcapstone.a
     fi
     LIBS="-L\$(BUILD_DIR)/capstone -lcapstone $LIBS"
+    capstone_capstone_h=yes
     ;;
 
   system)
Signature · 1 line
2.17.1
Acked-by on v1 2/3
#12 lore raw

Re: [Qemu-devel] [PATCH 2/3] capstone: Update to master

Quoted 22 lines · Richard Henderson

Update to fbb20ea83c5a. Choose this over the 4.0.1 tag because master now includes the s390x z13 vector opcodes.

---
 capstone  | 2 +-
 configure | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
capstone +1 -1
index 22ead3e0bf..fbb20ea83c 160000
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit fbb20ea83c5af4f29b40c17fbadb1f71b0a08fae
configure +0 -0
index eec7f061c3..a2e4636a34 100755

configure case "$capstone" in · line 5022

Quoted 7 lines
configure +1 -0
@@ -5016,6 +5016,7 @@ case "$capstone" in
       LIBCAPSTONE=libcapstone.a
     fi
     LIBS="-L\$(BUILD_DIR)/capstone -lcapstone $LIBS"
+    capstone_capstone_h=yes
     ;;
 
   system)
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by Tested-by on v1 2/3
#13 lore raw

Re: [Qemu-devel] [PATCH 2/3] capstone: Update to master

In reply to Richard Henderson
Quoted 2 lines · Richard Henderson

Update to fbb20ea83c5a. Choose this over the 4.0.1 tag because master now includes the s390x z13 vector opcodes.

Cool! I was watching few fixed issues on the capstone repo, which are now fixed in QEMU too :)

Various riscv/arm64 improvement too.

Quoted 1 line
Quoted 25 lines
---
 capstone  | 2 +-
 configure | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
capstone +1 -1
index 22ead3e0bf..fbb20ea83c 160000
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit fbb20ea83c5af4f29b40c17fbadb1f71b0a08fae
configure +1 -0
index eec7f061c3..a2e4636a34 100755
@@ -5016,6 +5016,7 @@ case "$capstone" in
       LIBCAPSTONE=libcapstone.a
     fi
     LIBS="-L\$(BUILD_DIR)/capstone -lcapstone $LIBS"
+    capstone_capstone_h=yes
     ;;
 
   system)
#14 lore raw

PATCH 3/3 capstone: Enable disassembly for s390x

In reply to Richard Henderson

Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Install a skipdata hook to keep capstone in sync with the instruction stream for unknown opcodes.

---
 Makefile           |  1 +
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 3 files changed, 45 insertions(+)
Makefile +1 -0
index 155f066a20..a37e872825 100644
@@ -477,6 +477,7 @@ CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
 CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
+CAP_CFLAGS += -DCAPSTONE_HAS_SYSZ
 CAP_CFLAGS += -DCAPSTONE_HAS_X86
 
 subdir-capstone: .git-submodule-status
disas.c +40 -0
index 41ad0102e2..c1ecd2d769 100644
@@ -179,6 +179,39 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
    to share this across calls and across host vs target disassembly.  */
 static __thread cs_insn *cap_insn;
 
+/*
+ * The capstone library always skips 2 bytes for S390X.
+ * This is less than ideal, since we can tell from the first two bits
+ * the size of the insn and thus stay in sync with the insn stream.
+ */
+static size_t CAPSTONE_API
+cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
+                      size_t offset, void *user_data)
+{
+    size_t ilen;
+
+    /* See get_ilen() in target/s390x/internal.h.  */
+    switch (code[offset] >> 6) {
+    case 0:
+        ilen = 2;
+        break;
+    case 1:
+    case 2:
+        ilen = 4;
+        break;
+    default:
+        ilen = 6;
+        break;
+    }
+
+    return ilen;
+}
+
+static const cs_opt_skipdata cap_skipdata_s390x = {
+    .mnemonic = ".byte",
+    .callback = cap_skipdata_s390x_cb
+};
+
 /* Initialize the Capstone library.  */
 /* ??? It would be nice to cache this.  We would need one handle for the
    host and one for the target.  For most targets we can reset specific
@@ -209,6 +242,10 @@ static cs_err cap_disas_start(disassemble_info *info, csh *handle)
 
     /* "Disassemble" unknown insns as ".byte W,X,Y,Z".  */
     cs_option(*handle, CS_OPT_SKIPDATA, CS_OPT_ON);
+    if (info->cap_arch == CS_ARCH_SYSZ) {
+        cs_option(*handle, CS_OPT_SKIPDATA_SETUP,
+                  (uintptr_t)&cap_skipdata_s390x);
+    }
 
     /* Allocate temp space for cs_disasm_iter.  */
     if (cap_insn == NULL) {
@@ -551,6 +588,9 @@ void disas(FILE *out, void *code, unsigned long size)
     print_insn = print_insn_m68k;
 #elif defined(__s390__)
     print_insn = print_insn_s390;
+    s.info.cap_arch = CS_ARCH_SYSZ;
+    s.info.cap_insn_unit = 2;
+    s.info.cap_insn_split = 6;
 #elif defined(__hppa__)
     print_insn = print_insn_hppa;
 #endif
target/s390x/cpu.c +4 -0
index b1df63d82c..553571d86b 100644
@@ -41,6 +41,7 @@
 #include "sysemu/sysemu.h"
 #endif
 #include "fpu/softfloat.h"
+#include "disas/capstone.h"
 
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
@@ -175,6 +176,9 @@ static void s390_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 {
     info->mach = bfd_mach_s390_64;
     info->print_insn = print_insn_s390;
+    info->cap_arch = CS_ARCH_SYSZ;
+    info->cap_insn_unit = 2;
+    info->cap_insn_split = 6;
 }
 
 static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
Signature · 1 line
2.17.1
#15 lore raw

Re: [Qemu-devel] [PATCH 3/3] capstone: Enable disassembly for s390x

Quoted 48 lines · Richard Henderson

Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Install a skipdata hook to keep capstone in sync with the instruction stream for unknown opcodes.

---
 Makefile           |  1 +
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 3 files changed, 45 insertions(+)
Makefile +1 -0
index 155f066a20..a37e872825 100644
@@ -477,6 +477,7 @@ CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
 CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
+CAP_CFLAGS += -DCAPSTONE_HAS_SYSZ
 CAP_CFLAGS += -DCAPSTONE_HAS_X86
 
 subdir-capstone: .git-submodule-status
disas.c +16 -0
index 41ad0102e2..c1ecd2d769 100644
@@ -179,6 +179,39 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
    to share this across calls and across host vs target disassembly.  */
 static __thread cs_insn *cap_insn;
 
+/*
+ * The capstone library always skips 2 bytes for S390X.
+ * This is less than ideal, since we can tell from the first two bits
+ * the size of the insn and thus stay in sync with the insn stream.
+ */
+static size_t CAPSTONE_API
+cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
+                      size_t offset, void *user_data)
+{
+    size_t ilen;
+
+    /* See get_ilen() in target/s390x/internal.h.  */
+    switch (code[offset] >> 6) {
+    case 0:
+        ilen = 2;
+        break;

disas.c static int print_insn_od_target(bfd_vma pc, disassemble_info *info) · line 207

Quoted 10 lines
disas.c +10 -0
+    case 1:
+    case 2:
+        ilen = 4;
+        break;
+    default:
+        ilen = 6;
+        break;
+    }
+
+    return ilen;

return (code[offset] >> 6) << 1; ?

Signature · 3 lines
Thanks,

David / dhildenb
#16 lore raw

Re: [Qemu-devel] [PATCH 3/3] capstone: Enable disassembly for s390x

Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Richard Henderson

Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Install a skipdata hook to keep capstone in sync with the instruction stream for unknown opcodes.

---
 Makefile           |  1 +
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 3 files changed, 45 insertions(+)
Makefile +1 -0
index 155f066a20..a37e872825 100644
@@ -477,6 +477,7 @@ CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
 CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
+CAP_CFLAGS += -DCAPSTONE_HAS_SYSZ
 CAP_CFLAGS += -DCAPSTONE_HAS_X86
 
 subdir-capstone: .git-submodule-status
disas.c +20 -0
index 41ad0102e2..c1ecd2d769 100644
@@ -179,6 +179,39 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
    to share this across calls and across host vs target disassembly.  */
 static __thread cs_insn *cap_insn;
 
+/*
+ * The capstone library always skips 2 bytes for S390X.
+ * This is less than ideal, since we can tell from the first two bits
+ * the size of the insn and thus stay in sync with the insn stream.
+ */
+static size_t CAPSTONE_API
+cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
+                      size_t offset, void *user_data)
+{
+    size_t ilen;
+
+    /* See get_ilen() in target/s390x/internal.h.  */
+    switch (code[offset] >> 6) {
+    case 0:
+        ilen = 2;
+        break;
+    case 1:
+    case 2:
+        ilen = 4;
+        break;
Quoted 8 lines

disas.c static int print_insn_od_target(bfd_vma pc, disassemble_info *info) · line 207

Quoted 6 lines
disas.c +6 -0
+    default:
+        ilen = 6;
+        break;
+    }
+
+    return ilen;

return (code[offset] >> 6) << 1; ?

Doesn't work for 1. Anyway, with the comment I wanted to match get_ilen() exactly.

r~

#17 lore raw

Re: [Qemu-devel] [PATCH 3/3] capstone: Enable disassembly for s390x

In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Install a skipdata hook to keep capstone in sync with the instruction stream for unknown opcodes.

---
 Makefile           |  1 +
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 3 files changed, 45 insertions(+)

I'm going to put this patch on hold for now, as I'm trying to get this fixed upstream. If that fails, I'll re-introduce it here.

r~

#18 lore raw

Re: [Qemu-devel] [PATCH 3/3] capstone: Enable disassembly for s390x

Quoted 13 lines · Richard Henderson
Quoted 11 lines · Richard Henderson

Enable s390x, aka SYSZ, in the git submodule build. Set the capstone parameters for both s390x host and guest. Install a skipdata hook to keep capstone in sync with the instruction stream for unknown opcodes.

---
 Makefile           |  1 +
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 3 files changed, 45 insertions(+)
Quoted 2 lines

I'm going to put this patch on hold for now, as I'm trying to get this fixed upstream. If that fails, I'll re-introduce it here.

Bah. What I meant is the skipdata hook portion of the patch. I'll split out the bare "enable s390" portion for v2.

r~