qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/3] capstone update
@ 2020-01-08  4:23 Richard Henderson
  2020-01-08  4:23 ` [PULL 1/3] capstone: Update to next Richard Henderson
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Richard Henderson @ 2020-01-08  4:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

The following changes since commit 035eed4c0d257c905a556fa0f4865a0c077b4e7f:

  Merge remote-tracking branch 'remotes/vivier/tags/q800-for-5.0-pull-request' into staging (2020-01-07 17:08:21 +0000)

are available in the Git repository at:

  https://github.com/rth7680/qemu.git tags/pull-cap-20200108

for you to fetch changes up to 7cc3836eac04a3e358b2496fbca704b3ee5197ae:

  capstone: Add skipdata hook for s390x (2020-01-08 14:53:54 +1100)

----------------------------------------------------------------
Update capstone to next

----------------------------------------------------------------
Richard Henderson (3):
      capstone: Update to next
      capstone: Enable disassembly for s390x
      capstone: Add skipdata hook for s390x

 Makefile           |  2 ++
 disas.c            | 40 ++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.c |  4 ++++
 capstone           |  2 +-
 configure          |  2 +-
 5 files changed, 48 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PULL 1/3] capstone: Update to next
  2020-01-08  4:23 [PULL 0/3] capstone update Richard Henderson
@ 2020-01-08  4:23 ` Richard Henderson
  2020-01-08  4:23 ` [PULL 2/3] capstone: Enable disassembly for s390x Richard Henderson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2020-01-08  4:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Philippe Mathieu-Daudé

Update to aaffb38c44fa.  Choose this over the "current" 4.0.1 tag
because next now includes the s390x z13 vector opcodes, and also
the insn tables are now read-only.

Fixes: https://bugs.launchpad.net/qemu/+bug/1826175
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 Makefile  | 1 +
 capstone  | 2 +-
 configure | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6b5ad1121b..12e129ac9d 100644
--- a/Makefile
+++ b/Makefile
@@ -499,6 +499,7 @@ dtc/%: .git-submodule-status
 # Remove all the extra -Warning flags that QEMU uses that Capstone doesn't;
 # no need to annoy QEMU developers with such things.
 CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS))
+CAP_CFLAGS += -I$(SRC_PATH)/capstone/include
 CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM
 CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
diff --git a/capstone b/capstone
index 22ead3e0bf..aaffb38c44 160000
--- a/capstone
+++ b/capstone
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit aaffb38c44fa58f510ba9b6264f7079bfbba4c8e
diff --git a/configure b/configure
index 0ce2c0354a..b3c99728d2 100755
--- a/configure
+++ b/configure
@@ -5068,7 +5068,7 @@ case "$capstone" in
       git_submodules="${git_submodules} capstone"
     fi
     mkdir -p capstone
-    QEMU_CFLAGS="$QEMU_CFLAGS -I\$(SRC_PATH)/capstone/include"
+    QEMU_CFLAGS="$QEMU_CFLAGS -I\$(SRC_PATH)/capstone/include/capstone"
     if test "$mingw32" = "yes"; then
       LIBCAPSTONE=capstone.lib
     else
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 2/3] capstone: Enable disassembly for s390x
  2020-01-08  4:23 [PULL 0/3] capstone update Richard Henderson
  2020-01-08  4:23 ` [PULL 1/3] capstone: Update to next Richard Henderson
@ 2020-01-08  4:23 ` Richard Henderson
  2020-01-08  4:23 ` [PULL 3/3] capstone: Add skipdata hook " Richard Henderson
  2020-01-10 16:07 ` [PULL 0/3] capstone update Peter Maydell
  3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2020-01-08  4:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Philippe Mathieu-Daudé

Enable s390x, aka SYSZ, in the git submodule build.
Set the capstone parameters for both s390x host and guest.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 Makefile           | 1 +
 disas.c            | 3 +++
 target/s390x/cpu.c | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/Makefile b/Makefile
index 12e129ac9d..df1c692ccd 100644
--- a/Makefile
+++ b/Makefile
@@ -504,6 +504,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
 
 .PHONY: capstone/all
diff --git a/disas.c b/disas.c
index 3937da6157..845c40fca8 100644
--- a/disas.c
+++ b/disas.c
@@ -660,6 +660,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
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 625daeedd1..1734ad9c3a 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -43,6 +43,7 @@
 #include "sysemu/tcg.h"
 #endif
 #include "fpu/softfloat-helpers.h"
+#include "disas/capstone.h"
 
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
@@ -162,6 +163,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)
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PULL 3/3] capstone: Add skipdata hook for s390x
  2020-01-08  4:23 [PULL 0/3] capstone update Richard Henderson
  2020-01-08  4:23 ` [PULL 1/3] capstone: Update to next Richard Henderson
  2020-01-08  4:23 ` [PULL 2/3] capstone: Enable disassembly for s390x Richard Henderson
@ 2020-01-08  4:23 ` Richard Henderson
  2020-01-10 16:07 ` [PULL 0/3] capstone update Peter Maydell
  3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2020-01-08  4:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Thomas Huth, Philippe Mathieu-Daudé

Capstone assumes any s390x unknown instruction is 2 bytes.
Instead, use the ilen field in the first two bits of
the instruction to stay in sync with the insn stream.

Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/disas.c b/disas.c
index 845c40fca8..1095bad049 100644
--- a/disas.c
+++ b/disas.c
@@ -178,6 +178,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
@@ -208,6 +241,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) {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PULL 0/3] capstone update
  2020-01-08  4:23 [PULL 0/3] capstone update Richard Henderson
                   ` (2 preceding siblings ...)
  2020-01-08  4:23 ` [PULL 3/3] capstone: Add skipdata hook " Richard Henderson
@ 2020-01-10 16:07 ` Peter Maydell
  2020-01-10 16:43   ` Peter Maydell
  2020-01-13 19:53   ` Richard Henderson
  3 siblings, 2 replies; 8+ messages in thread
From: Peter Maydell @ 2020-01-10 16:07 UTC (permalink / raw)
  To: Richard Henderson; +Cc: QEMU Developers

On Wed, 8 Jan 2020 at 04:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The following changes since commit 035eed4c0d257c905a556fa0f4865a0c077b4e7f:
>
>   Merge remote-tracking branch 'remotes/vivier/tags/q800-for-5.0-pull-request' into staging (2020-01-07 17:08:21 +0000)
>
> are available in the Git repository at:
>
>   https://github.com/rth7680/qemu.git tags/pull-cap-20200108
>
> for you to fetch changes up to 7cc3836eac04a3e358b2496fbca704b3ee5197ae:
>
>   capstone: Add skipdata hook for s390x (2020-01-08 14:53:54 +1100)
>
> ----------------------------------------------------------------
> Update capstone to next
>
> ----------------------------------------------------------------
> Richard Henderson (3):
>       capstone: Update to next
>       capstone: Enable disassembly for s390x
>       capstone: Add skipdata hook for s390x

Build failures:

  CC      aarch64-linux-user/disas.o
In file included from
/home/ubuntu/qemu/capstone/include/capstone/capstone.h:302:0,
                 from /home/ubuntu/qemu/include/disas/capstone.h:6,
                 from /home/ubuntu/qemu/disas.c:9:
/home/ubuntu/qemu/capstone/include/capstone/riscv.h:16:10: fatal
error: capstone/platform.h: No such file or directory
 #include "capstone/platform.h"
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

(same on most hosts)

aarch64 host had this complaint instead:

/home/pm/qemu/disas.c:187:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘cap_skipdata_s390x_cb’
 cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
 ^~~~~~~~~~~~~~~~~~~~~
/home/pm/qemu/disas.c:211:17: error: ‘cap_skipdata_s390x_cb’
undeclared here (not in a function); did you mean
‘cap_skipdata_s390x’?
     .callback = cap_skipdata_s390x_cb
                 ^~~~~~~~~~~~~~~~~~~~~
                 cap_skipdata_s390x

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PULL 0/3] capstone update
  2020-01-10 16:07 ` [PULL 0/3] capstone update Peter Maydell
@ 2020-01-10 16:43   ` Peter Maydell
  2020-01-13 19:53   ` Richard Henderson
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2020-01-10 16:43 UTC (permalink / raw)
  To: Richard Henderson; +Cc: QEMU Developers

On Fri, 10 Jan 2020 at 16:07, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Wed, 8 Jan 2020 at 04:23, Richard Henderson
> <richard.henderson@linaro.org> wrote:
> >
> > The following changes since commit 035eed4c0d257c905a556fa0f4865a0c077b4e7f:
> >
> >   Merge remote-tracking branch 'remotes/vivier/tags/q800-for-5.0-pull-request' into staging (2020-01-07 17:08:21 +0000)
> >
> > are available in the Git repository at:
> >
> >   https://github.com/rth7680/qemu.git tags/pull-cap-20200108
> >
> > for you to fetch changes up to 7cc3836eac04a3e358b2496fbca704b3ee5197ae:
> >
> >   capstone: Add skipdata hook for s390x (2020-01-08 14:53:54 +1100)
> >
> > ----------------------------------------------------------------
> > Update capstone to next
> >
> > ----------------------------------------------------------------
> > Richard Henderson (3):
> >       capstone: Update to next
> >       capstone: Enable disassembly for s390x
> >       capstone: Add skipdata hook for s390x
>
> Build failures:
>
>   CC      aarch64-linux-user/disas.o
> In file included from
> /home/ubuntu/qemu/capstone/include/capstone/capstone.h:302:0,
>                  from /home/ubuntu/qemu/include/disas/capstone.h:6,
>                  from /home/ubuntu/qemu/disas.c:9:
> /home/ubuntu/qemu/capstone/include/capstone/riscv.h:16:10: fatal
> error: capstone/platform.h: No such file or directory
>  #include "capstone/platform.h"
>           ^~~~~~~~~~~~~~~~~~~~~
> compilation terminated.
>
> (same on most hosts)
>
> aarch64 host had this complaint instead:
>
> /home/pm/qemu/disas.c:187:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
> ‘__attribute__’ before ‘cap_skipdata_s390x_cb’
>  cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
>  ^~~~~~~~~~~~~~~~~~~~~
> /home/pm/qemu/disas.c:211:17: error: ‘cap_skipdata_s390x_cb’
> undeclared here (not in a function); did you mean
> ‘cap_skipdata_s390x’?
>      .callback = cap_skipdata_s390x_cb
>                  ^~~~~~~~~~~~~~~~~~~~~
>                  cap_skipdata_s390x

...and applying this merge also did something that broke the
build directories such that rolling back to before the merge
to current trunk then failed to build with errors about
missing 'capstone.h'. I had to blow away the build trees and
recreate them.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PULL 0/3] capstone update
  2020-01-10 16:07 ` [PULL 0/3] capstone update Peter Maydell
  2020-01-10 16:43   ` Peter Maydell
@ 2020-01-13 19:53   ` Richard Henderson
  2020-01-14  9:27     ` Peter Maydell
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2020-01-13 19:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

On 1/10/20 6:07 AM, Peter Maydell wrote:
> On Wed, 8 Jan 2020 at 04:23, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> The following changes since commit 035eed4c0d257c905a556fa0f4865a0c077b4e7f:
>>
>>   Merge remote-tracking branch 'remotes/vivier/tags/q800-for-5.0-pull-request' into staging (2020-01-07 17:08:21 +0000)
>>
>> are available in the Git repository at:
>>
>>   https://github.com/rth7680/qemu.git tags/pull-cap-20200108
>>
>> for you to fetch changes up to 7cc3836eac04a3e358b2496fbca704b3ee5197ae:
>>
>>   capstone: Add skipdata hook for s390x (2020-01-08 14:53:54 +1100)
>>
>> ----------------------------------------------------------------
>> Update capstone to next
>>
>> ----------------------------------------------------------------
>> Richard Henderson (3):
>>       capstone: Update to next
>>       capstone: Enable disassembly for s390x
>>       capstone: Add skipdata hook for s390x
> 
> Build failures:
> 
>   CC      aarch64-linux-user/disas.o
> In file included from
> /home/ubuntu/qemu/capstone/include/capstone/capstone.h:302:0,
>                  from /home/ubuntu/qemu/include/disas/capstone.h:6,
>                  from /home/ubuntu/qemu/disas.c:9:
> /home/ubuntu/qemu/capstone/include/capstone/riscv.h:16:10: fatal
> error: capstone/platform.h: No such file or directory
>  #include "capstone/platform.h"
>           ^~~~~~~~~~~~~~~~~~~~~
> compilation terminated.
> 
> (same on most hosts)

This comes from not re-running configure, which changes the CFLAGS for the
build of capstone from git.  Given that the source tree for capstone got
rearranged between 3.x and 4.0, I don't see how I can avoid this.

> aarch64 host had this complaint instead:
> 
> /home/pm/qemu/disas.c:187:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
> ‘__attribute__’ before ‘cap_skipdata_s390x_cb’
>  cap_skipdata_s390x_cb(const uint8_t *code, size_t code_size,
>  ^~~~~~~~~~~~~~~~~~~~~
> /home/pm/qemu/disas.c:211:17: error: ‘cap_skipdata_s390x_cb’
> undeclared here (not in a function); did you mean
> ‘cap_skipdata_s390x’?
>      .callback = cap_skipdata_s390x_cb
>                  ^~~~~~~~~~~~~~~~~~~~~
>                  cap_skipdata_s390x

Hmm.  Replicated on qemu-test.  There seems to have been an api change within
the 3.x series.


r~



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PULL 0/3] capstone update
  2020-01-13 19:53   ` Richard Henderson
@ 2020-01-14  9:27     ` Peter Maydell
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2020-01-14  9:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: QEMU Developers

On Mon, 13 Jan 2020 at 19:53, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 1/10/20 6:07 AM, Peter Maydell wrote:
> > On Wed, 8 Jan 2020 at 04:23, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >>
> >> The following changes since commit 035eed4c0d257c905a556fa0f4865a0c077b4e7f:
> >>
> >>   Merge remote-tracking branch 'remotes/vivier/tags/q800-for-5.0-pull-request' into staging (2020-01-07 17:08:21 +0000)
> >>
> >> are available in the Git repository at:
> >>
> >>   https://github.com/rth7680/qemu.git tags/pull-cap-20200108
> >>
> >> for you to fetch changes up to 7cc3836eac04a3e358b2496fbca704b3ee5197ae:
> >>
> >>   capstone: Add skipdata hook for s390x (2020-01-08 14:53:54 +1100)
> >>
> >> ----------------------------------------------------------------
> >> Update capstone to next
> >>
> >> ----------------------------------------------------------------
> >> Richard Henderson (3):
> >>       capstone: Update to next
> >>       capstone: Enable disassembly for s390x
> >>       capstone: Add skipdata hook for s390x
> >
> > Build failures:
> >
> >   CC      aarch64-linux-user/disas.o
> > In file included from
> > /home/ubuntu/qemu/capstone/include/capstone/capstone.h:302:0,
> >                  from /home/ubuntu/qemu/include/disas/capstone.h:6,
> >                  from /home/ubuntu/qemu/disas.c:9:
> > /home/ubuntu/qemu/capstone/include/capstone/riscv.h:16:10: fatal
> > error: capstone/platform.h: No such file or directory
> >  #include "capstone/platform.h"
> >           ^~~~~~~~~~~~~~~~~~~~~
> > compilation terminated.
> >
> > (same on most hosts)
>
> This comes from not re-running configure, which changes the CFLAGS for the
> build of capstone from git.  Given that the source tree for capstone got
> rearranged between 3.x and 4.0, I don't see how I can avoid this.

Hmm, shouldn't the update to 'configure' in this merge cause Make
to rerun configure, though ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-14  9:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08  4:23 [PULL 0/3] capstone update Richard Henderson
2020-01-08  4:23 ` [PULL 1/3] capstone: Update to next Richard Henderson
2020-01-08  4:23 ` [PULL 2/3] capstone: Enable disassembly for s390x Richard Henderson
2020-01-08  4:23 ` [PULL 3/3] capstone: Add skipdata hook " Richard Henderson
2020-01-10 16:07 ` [PULL 0/3] capstone update Peter Maydell
2020-01-10 16:43   ` Peter Maydell
2020-01-13 19:53   ` Richard Henderson
2020-01-14  9:27     ` Peter Maydell

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).