Message ID | 20190523024229.1158-4-richard.henderson@linaro.org |
---|---|
State | New |
Headers | show |
Series | Update capstone module | expand |
On 23.05.19 04:42, Richard Henderson wrote: > 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. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > Makefile | 1 + > disas.c | 40 ++++++++++++++++++++++++++++++++++++++++ > target/s390x/cpu.c | 4 ++++ > 3 files changed, 45 insertions(+) > > diff --git a/Makefile b/Makefile > index 155f066a20..a37e872825 100644 > --- a/Makefile > +++ b/Makefile > @@ -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 > diff --git a/disas.c b/disas.c > index 41ad0102e2..c1ecd2d769 100644 > --- a/disas.c > +++ b/disas.c > @@ -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; return (code[offset] >> 6) << 1; ? -- Thanks, David / dhildenb
On 5/23/19 4:27 AM, David Hildenbrand wrote: > On 23.05.19 04:42, Richard Henderson wrote: >> 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. >> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >> --- >> Makefile | 1 + >> disas.c | 40 ++++++++++++++++++++++++++++++++++++++++ >> target/s390x/cpu.c | 4 ++++ >> 3 files changed, 45 insertions(+) >> >> diff --git a/Makefile b/Makefile >> index 155f066a20..a37e872825 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -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 >> diff --git a/disas.c b/disas.c >> index 41ad0102e2..c1ecd2d769 100644 >> --- a/disas.c >> +++ b/disas.c >> @@ -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; > > return (code[offset] >> 6) << 1; ? Doesn't work for 1. Anyway, with the comment I wanted to match get_ilen() exactly. r~
On 5/22/19 10:42 PM, Richard Henderson wrote: > 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. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > 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~
On 5/23/19 3:26 PM, Richard Henderson wrote: > On 5/22/19 10:42 PM, Richard Henderson wrote: >> 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. >> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >> --- >> 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. Bah. What I meant is the skipdata hook portion of the patch. I'll split out the bare "enable s390" portion for v2. r~
diff --git a/Makefile b/Makefile index 155f066a20..a37e872825 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/disas.c b/disas.c index 41ad0102e2..c1ecd2d769 100644 --- a/disas.c +++ b/disas.c @@ -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 diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index b1df63d82c..553571d86b 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -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)
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. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- Makefile | 1 + disas.c | 40 ++++++++++++++++++++++++++++++++++++++++ target/s390x/cpu.c | 4 ++++ 3 files changed, 45 insertions(+) -- 2.17.1