From patchwork Thu May 23 02:42:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164929 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1622243ili; Wed, 22 May 2019 19:53:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyG76/hso8WmuKmHVWVy7pkgUCRS4dUuQ9PIqjQPmYqdT4yw+6xc6ttIMMBB2wwe0eeC2jk X-Received: by 2002:a17:906:4d57:: with SMTP id b23mr73536273ejv.254.1558579984379; Wed, 22 May 2019 19:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558579984; cv=none; d=google.com; s=arc-20160816; b=luW7qcGl1o8pcduc9QsEeQ6BXvDtFBYT89Cw+2iGNfQJrPqa95s1s+32gbeBqO63S0 A5wrOJtm6NdYbu7qpdyhXrjHka7iIJ+sAXHxGflt1sCZm5X0udqeG1fOEbfpSYiB/Eke da0YwA7Blnz6iy60pWRl3AAE393lbtjY3SJqbFKOSOd8M7Ug5xpq6+ebtoEBsMa/Mya1 8u9SoatvRH6feX/VqqTbn8GlEgrn4oxdBRAPuou/L0/K4fdWLD+AEHuE+AaRyAHw0iSg 4F20K4gJ4zfp+Do44A89X2DHq5tu9v3+AA3GdM8J02Hyfegi1OJoBj8uMKZz1HCNu30T wf0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=L3cNq6YyAPNbUfiuj9aFVufaRYm1fCVGRTm5ygWeeXI=; b=Q6Gjq9oRe+wvjyUIordwBHSBSecyj/6e26gnNOQuImFGvdA5U6QpMkS2zNXZWzGf0J 6xrUYpELADosfzhoA1UU7z4HN6ug1xs4ZcT0/uI7H0rg4nG3fIWThKfDRHXycTqN7VxL zenH+GXRS6H1U0nU3K+VvhN3ZtEOZ0D3RREvFAJF/8gyK/g0YDTWvzVzi1fsa/jFIlmF MfNkxgemUdQ+CjqO5L+ya/KQCPvvKn7oUKXOU36476gJqcdr22v3ZaEtwo980++CTG1E GSsANlWLmSomBl7Qfg3rjm0/mZvXZqagG6r+okZmP33PHYEC+MgKOi9RicwIKXRcDXaB IZ3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q6HrrMrN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k17si10178176ejs.208.2019.05.22.19.53.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 19:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q6HrrMrN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTdqp-0007Zy-9n for patch@linaro.org; Wed, 22 May 2019 22:53:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTdoW-0005Qx-Ru for qemu-devel@nongnu.org; Wed, 22 May 2019 22:50:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTdgh-0001t3-PM for qemu-devel@nongnu.org; Wed, 22 May 2019 22:42:36 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:34879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTdgh-0001sk-K9 for qemu-devel@nongnu.org; Wed, 22 May 2019 22:42:35 -0400 Received: by mail-yw1-xc41.google.com with SMTP id k128so1694639ywf.2 for ; Wed, 22 May 2019 19:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L3cNq6YyAPNbUfiuj9aFVufaRYm1fCVGRTm5ygWeeXI=; b=Q6HrrMrNJm0cOKjwpnwqAoomARUSCbZGpMi0xgXEFi7ApLzsyuwOUpM5iBvxQVZLjx q05Nm4mxKwjOIYIVVOIHxSaIGhQ4Rh2Lw8yoLxt0Qg3mvBARtO/wr9pu8I0iqSpTP8Ar 9WIZxgf7N5p534yFFn/zq4h2cwr25/Oscq8HR/sHx/fofuiPiPrMmSmRPNR+MZ73hVJ2 +aOMghSmJihsscwxiU436jekxvCOZZJMEIBLYg/Gbd+hG7ZCqnWkBUXbUKIJepFZ7kXM 2cV5+EG/s1UUoRfg3PVawhn6SSHe2lzhcsOoj07qY1kdOo6aPtG+8Y4orAyFbCWGEkur RLLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L3cNq6YyAPNbUfiuj9aFVufaRYm1fCVGRTm5ygWeeXI=; b=Y5KofZMQaAH3oOg1mQzT+CiyQvy+yfBK8j6DuBVWO59guvWGhvymB3/MScJ8Awozr7 ymnqY/6L1DtGpCXwOGSlqWAmGMI+S15dGLxjaE8yIeUPWjbZU6biuNB0hlFnT8yTqj4B xqsab/II0wgvcVLOAmgMnTFWFxjPh796G5/y2y0MIE5JCkeKwa4zNJIbWwAaY/GtJb4C +L0NJNRsUzAeCFiWtjBBCNcmCRguUlxFmHm6XRfUJ3KB3/d5J4HFYieHJivkVmM3pojC Glx4RmZvpV7Z8vGmtiHLbLSPCfDscwE7a0d61R3lMt6EAMZyvF1aA2njZ/xu8SblubjO kUkA== X-Gm-Message-State: APjAAAWPeWN1tVZ+MB+vlDdhf4WEsVCv7U0jdO/7rFN7+l21C9xm+bvl PXrwvkAbK4wikTIFlqhlkibn6O2ZL2c= X-Received: by 2002:a81:3c83:: with SMTP id j125mr21399048ywa.226.1558579354836; Wed, 22 May 2019 19:42:34 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id n12sm7559320ywn.81.2019.05.22.19.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 19:42:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 22:42:29 -0400 Message-Id: <20190523024229.1158-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523024229.1158-1-richard.henderson@linaro.org> References: <20190523024229.1158-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c41 Subject: [Qemu-devel] [PATCH 3/3] capstone: Enable disassembly for s390x X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- Makefile | 1 + disas.c | 40 ++++++++++++++++++++++++++++++++++++++++ target/s390x/cpu.c | 4 ++++ 3 files changed, 45 insertions(+) -- 2.17.1 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)