From patchwork Mon Sep 14 00:01:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249755 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1203711ilg; Sun, 13 Sep 2020 17:09:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdjvLN9CARZQkOXECgWCE7V0jXrkpNK2w8suG7X2IHtp+XYMyh1NiyhGx282F3Kt2M8Q4J X-Received: by 2002:a25:5cf:: with SMTP id 198mr16818497ybf.409.1600042199851; Sun, 13 Sep 2020 17:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600042199; cv=none; d=google.com; s=arc-20160816; b=cOICE7Ql7NSRBRXt7F5EOELa2qfTH13DvFcEH/ZZXBMSTaARj+th017r/6oFyLEblG oPeJto0LS0gtoTxZSAmihoitOFOKhvcjNjYJRn/nsFAUFhk/Bc/wC1tFsEVH/RYqkOBT Qzn80QNzfpK5dK8xLRtRNAERqM7OQGVDNS9w7ybiRHOq/9kr860PN3Hh4yijeK7H6QDg ag9VRtDLx9fqEe1lTrNwtT+qwIOc1lLDeK3NQSBz0Kf/XrDvwxMetpazgVT2u5UPWO6a 6EX3CGaXSG4jzcajM17puRLs6XGB1BoVfZ9xSPQxbYKqWTtRN/zaykM3Gfcc1BYpIue8 48iw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=dH5SseIkwQFz56LTSJeIH301hvqrwY4ZUarSrz6cb46DvXfWDlHJwclGdkr82nwu6Q iLAnFIRgoDmmR1Ax+6bBka/nWSpagEfv7OV8vFlvBV1NTFxLwZOyKXBOoh9zl1Ligu/G UgbF+2RYajZ7JJZnJGLHf4kVEtXxdGRcH0PbKP1hCZBGMOUp7w2gMDY/O22AVePdFOQk 4UK6RvrKZmifa/XmcXEHryaq2lQ0QXD6LwrZ+0r2QBEkmp3ZVVEgmIymcIEvT4Nppa9T 8E5yDnD3dL5hlV8b4Gg2nGIdX4K3ItY8mRdG3ARasZLdFsQ7UUT6+468U8a9w3AQdULo er2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZfVnAuEZ; 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 w8si8734618ybw.299.2020.09.13.17.09.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:09:59 -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=ZfVnAuEZ; 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 ([::1]:53868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHc4F-0004ap-D9 for patch@linaro.org; Sun, 13 Sep 2020 20:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwh-0002rR-Jh for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:11 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:43546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwf-0004Cv-Jq for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:11 -0400 Received: by mail-pg1-x543.google.com with SMTP id t14so10060415pgl.10 for ; Sun, 13 Sep 2020 17:02:09 -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 :mime-version:content-transfer-encoding; bh=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=ZfVnAuEZNFZuQPDiVwW+EdPFbdJntGLKtnjL4Pmw7INWhZy67p0KuaF6q61TALlmIB /jw1W32K042JP20cA0R5GagqbHh/NE5pbEpNdRfP7yi90VCqa7NGXvRWudcLuUozBY/l QGNxZY7G5XVOxOIlUpe0caDrVDT2YxqGOFZ1zlKykDBC4HhiY6wpoa+9bu5q7lNmwCaj ckOjUnifKTjV3f+y2vaIpLDs75IRc26Dl6FbKdD2zZ7bTxa+cWKct1nBXPdRq0iXZv/A 6472h1zZDUx04Ur4WiZwPbTLddbZpnv1vdNkE3xsFhmPyNjF8q+k6hZXHzXsMKHxjbUL 0CIw== 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:mime-version:content-transfer-encoding; bh=FHMdFNxA5DgdfHwVaO5Ocox79qcbsSZjeiufIYJ4nxY=; b=feEokkIZ+XS8g2h40LkuuKC61EWpDblh9lapi1fpOHOo2fRQsZlTZ68La013F8fz67 LzZSC2W5D5Kf7jWyWiEJTTxbcWbS3GFyRMaKui7Uhe5NUGnkZsJ3drD4tDYDtTQgZBXP i3JP3uuvN7km8D7QMjWpjYZ4lJrrM6l5Q+byH083J1Ebv1Yre4qZ3RvD1vNOManKtrpR Bp2FYKP7cnBzkubV19W2i1kbcgXdYUb5q1/LnYLeCJxXEeFv3Jk6T//uC99KghKCdaV9 MqNr0avyIXjuK+SZXPexNaq/AbzcGc8pVpDk/USLITtDF4BbP1BUt2wJ7PHVu3+E8NIE JvPg== X-Gm-Message-State: AOAM533LV/x4sJB3tpImI8I08VDzHg1AkpXW+kmKRxTux21pLPme9q3N PFuY2o6ofmYjut3V8wypJsPMQ0CKgCXeog== X-Received: by 2002:a17:902:8e86:b029:d1:9be4:b49d with SMTP id bg6-20020a1709028e86b02900d19be4b49dmr11920941plb.22.1600041727906; Sun, 13 Sep 2020 17:02:07 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:02:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 10/11] disas/capstone: Add skipdata hook for s390x Date: Sun, 13 Sep 2020 17:01:52 -0700 Message-Id: <20200914000153.1725632-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" It is always possible to tell the length of an insn, even if the actual insn is unknown. Skip the correct number of bytes, so that we stay in sync with the instruction stream. Signed-off-by: Richard Henderson --- disas/capstone.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/disas/capstone.c b/disas/capstone.c index b48f83958d..0a9ef9c892 100644 --- a/disas/capstone.c +++ b/disas/capstone.c @@ -16,6 +16,39 @@ */ 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. * @@ -42,13 +75,20 @@ 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_X86) { + switch (info->cap_arch) { + case CS_ARCH_SYSZ: + cs_option(*handle, CS_OPT_SKIPDATA_SETUP, + (uintptr_t)&cap_skipdata_s390x); + break; + + case CS_ARCH_X86: /* * We don't care about errors (if for some reason the library * is compiled without AT&T syntax); the user will just have * to deal with the Intel syntax. */ cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); + break; } /* Allocate temp space for cs_disasm_iter. */