From patchwork Mon Sep 14 23:02:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 303960 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2026921ilg; Mon, 14 Sep 2020 16:09:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLDaFVNTdZIpV0nLrSxr5sJUdjlVXzUheqeJ1FwgIP4m16TAaVFNgT7YZQtWKqk+4SVNq1 X-Received: by 2002:a0c:cb83:: with SMTP id p3mr15609056qvk.121.1600124963681; Mon, 14 Sep 2020 16:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600124963; cv=none; d=google.com; s=arc-20160816; b=Ugah0ngZahAkHJ0FCntL0lMnpqbzvX8ODuDku80slYi5Xa2jGXgj4cnwYEKOvh8/mu EGI0COSoUkYXI/s/qjzX14d2MF9DBzCYAQIoZMzxxYlAKxEK7J9QXHqICPANb8wB57lI ltXFHbnZgGbuR1giuuyKIpDzlxg+Ws9nm4O1nIw/HSQYt48YW+rrsxWuQ5wCHEOER7TV GhIwTtgd1LQ82cVT281v5PeF+5tvROSF7vtJtqVFyogLMQ/cOnW3kyL259HaPqbb4dE9 y1qSIzoh26ZPOwYTpU37B8Gkta1nxdB71J2Ra0D3yge4+y53fQZ2PG1BGzO08S3KqcXa LBcQ== 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=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=E7v46Dq0toA9e743SM9KV50NvzLDoET7VvHsyDqwFNF6oyBEYXkmpqHDjhekHz+Q04 1mKlTn86l+0QAHwtwilT5Xj6csnxnBqGngoar/Vzy90K7ntTRxB/HmYpJBjGX/SH/7ti kmeYzRQLRkeQsg06OvMDHaYPhyXhVW8JAV4I+CwvQLG2Cvr4dmaNRsRzfQHEFcc8eqSi 9tWiFQdPpNTuHLLxlOABFr/oMWxlgeVICUcE8sQHTtnVKATy1syUF9Ar8P0gZ8uTKb5M aCPyez+WaJ2ojUTVbQs1TfXi9drUmo4baEgjjAcDohWC7KeF9S3JioZXDUZm8XjI93nd vVkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Th4OCI3q; 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 h64si7493333qtd.383.2020.09.14.16.09.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Sep 2020 16:09:23 -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=Th4OCI3q; 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]:51474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHxb9-0001K3-8n for patch@linaro.org; Mon, 14 Sep 2020 19:09:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHxUT-0001Fs-BR for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:29 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHxUR-0006dA-K4 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 19:02:29 -0400 Received: by mail-pg1-x544.google.com with SMTP id f2so946995pgd.3 for ; Mon, 14 Sep 2020 16:02:27 -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=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=Th4OCI3qADxjsSfJUw/86xhbPR6CQPEiJ8mwbAe+GZ1aT0NJAhOZhLIlRoOKlagqxB EUgK7oiYCvSbhXUbGz+cFTNpC596n/F3PQmKuPuE8DcQzfXskd9tmnEFyAzyIdaI8b13 Bky66TQHA5pVM7Lk73wPBWfCaFW4tvJPLFivXivRr2xu66lxwMpAQdLQw9qaRTyEIC3G i95BgHjWKcOP6aL9VJHka1PctpRkiKC1GgZPUnHdtJcu0ygeu8ES8tarQ/NRqqKUvnwo UoAvNVMrnMAxWhzE9IKASohK3ucGOgjItWJNnLlY6Ns3hvtjzZLI13wOfZ/2ko5S30h8 kkkw== 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=hfLGTzL8Kx9EX3rC/1RV7M0Ql1gkiftzaDe5UPaelEg=; b=M5SQUfHPTrcGATKIenrF9BlgznOAtiAbzx9PKlTGoKA5x7/WLoXeoy18IzT4edNlPp pDr8IV59bubB+rYZ0Q2D9yYDkAK3AcxhycxiNEn4pq9Cy9QOzCyrudHlJodIu+85i83w LNUwoKC3A2e8TpQHaHv2/2DpqNfMyQ+HzMyZILeX3D4tFJpNrTX+jDY+vtVbfQ3SUnXz XhTHHjcZ7csAsdFjFftHmB/H5GmU1xYOElDYwRUYwASduFfwa1cwEa7LcxIyO1pyD97+ BKTtzWtso5Xz9ErEOomOgWsiIbfF3xKV6/ajdBEBQu6LCTLFkg3a37sEdwVxa3oczhbg Ixrg== X-Gm-Message-State: AOAM531MSNFGDDfSaRbxBdJfwejtxvclYDqJpZ8cIuFTG9j7hcnj0W11 42gH1vziX1ZTL3yBGjFdZnm+sqa+Joz6rA== X-Received: by 2002:a63:28c:: with SMTP id 134mr12388204pgc.385.1600124545945; Mon, 14 Sep 2020 16:02:25 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm9106076pgt.16.2020.09.14.16.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 16:02:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/10] disas/capstone: Add skipdata hook for s390x Date: Mon, 14 Sep 2020 16:02:10 -0700 Message-Id: <20200914230210.2185860-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914230210.2185860-1-richard.henderson@linaro.org> References: <20200914230210.2185860-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::544; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x544.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, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- disas/capstone.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.25.1 Acked-by: Thomas Huth 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. */