From patchwork Wed Oct 25 12:30:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 117117 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1692526edm; Wed, 25 Oct 2017 05:33:31 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S4mD5pNj05GoPDt3ziG77aQ6BRC9Ng8KtYlnZ46JOnKwFjQ3ry23pRlH2ghoHR1hZrlac5 X-Received: by 10.129.131.135 with SMTP id t129mr12735482ywf.33.1508934811061; Wed, 25 Oct 2017 05:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508934811; cv=none; d=google.com; s=arc-20160816; b=QarXDriubPgVRcHT7ksSV5RikaH8iTa5TO2YmAG3pwk6m+SgXm6sTvV/jvOsfGTmDq 2/qw3Av5eatAZf4SFz7YZrV0Z3E++3f5ki5Gn/R1lwI0QvkjHvbWDJNXkVV3x/yE1Emn Fdl+WteECK9ldLxceA3ST9Qc42d766mbSCiU87GphtB+SqShLqy5p8wIMKXskr27z2bs cv8RPGsC0xAUSvf1Ei3zxnfKXZAwTjVci/Y6W8EQ082OVwAXU/gDYC1S7AnldOldGuDk FlKlT/Y9AhLgXxZHuPbQapvnmWnpTl2TjbXuOwV8GqUotSD1SOhD+rSeYC85KqRB34xS kgZQ== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=FPw5KVv+Tsf7CBiTC6hfJzOj5/5ZiPY8tXYLV5ut1kM=; b=iT1KarwpHdUpmUJfvXg9Qx8C6wqHecq+2z3+P74T75yQk3Qhm0ucD2bE1UFY6kN+1f nwXv3wFeemEkX02UnPvLYH6xzm8a4KlCzVvR82rZzQMCq5UG8s/GNdNmL+rnB4iq7vw/ q0d8TlIzvxg4VlanOe0n9BGr8mc3p8ba1lGG3I6iaoXYNkHLWCcBMdVzLnC9g9gvxaGK NybJ23CKL6L/beUEBvhmfgMne23hOGRKqB/6JXyLAeodzWaB4dbEdGfBxvb6UAPFoLSD YQrJFKqJTx+0m9vqufcggn328971ZuwxFp0EelCpbf0ngqRpuMGerD7TxE+TCHEbQwZU uvqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ax6dlokO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h24si412321ybj.340.2017.10.25.05.33.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 05:33:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ax6dlokO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:48089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7KsE-0000PR-D9 for patch@linaro.org; Wed, 25 Oct 2017 08:33:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Kq1-0007Vu-72 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 08:31:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7Kpw-00080n-QG for qemu-devel@nongnu.org; Wed, 25 Oct 2017 08:31:13 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:51742) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7Kpw-0007zn-F6 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 08:31:08 -0400 Received: by mail-wm0-x244.google.com with SMTP id b9so1634896wmh.0 for ; Wed, 25 Oct 2017 05:31:08 -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=FPw5KVv+Tsf7CBiTC6hfJzOj5/5ZiPY8tXYLV5ut1kM=; b=Ax6dlokO2Z1fHmWe9EwrBgUJVX84eJOyshA080kFBTQITAaQ85NqLv0/HYFvrKo+Xa eXCmXWoIHT2kPihUvBBcselJft1dZm9eEFHRr90fP8NSuynisncrh0y08FH24lSNv420 OFIguk9l7WDHs2ZePUCvpRmIkdonU81vNe97k= 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=FPw5KVv+Tsf7CBiTC6hfJzOj5/5ZiPY8tXYLV5ut1kM=; b=jyCd+kVHNyU+GdUFKdhP3lZGzYxUE4oUtatorCqNX2zBm9OmHLVhbvTxVYnC1hGu0c Ll2Fu4RzDCckXHcQyYXCqXoDsznKQdtm+n/uSyhI8bw0KieTIC4c/aRgm5KpHZfT01RW HDdNhXyhsuQbrjIwP52MRqD5BJw6iUjJBxrmeJs9by0k0u8bR1A6jpbqYcL6+SWvEb93 A/2VkosF3uKKVKvJMzRd0ipngTiQfZirnvXElmNa9fk4UYG+0ZvCfwZEI20oxGTcCU4X aahgd4VKgW2wtl56mPPEG2nm3zz6wmZ6h14F4m7yKnNvOEhIvnvRZJV5DzgbXyBH56pD Hu2w== X-Gm-Message-State: AMCzsaWY6psyEuE6rjsvOA/lplnB7CdW2Iqf1bDoiU7FTsgLG/UIvnON Gs8/NUvn3WwMDNklnPgn52Sn9xRnu5k= X-Received: by 10.28.141.194 with SMTP id p185mr1718637wmd.149.1508934667147; Wed, 25 Oct 2017 05:31:07 -0700 (PDT) Received: from cloudburst.twiddle.net ([62.168.35.105]) by smtp.gmail.com with ESMTPSA id 61sm2263446wrg.58.2017.10.25.05.31.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 05:31:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 14:30:48 +0200 Message-Id: <20171025123056.3165-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171025123056.3165-1-richard.henderson@linaro.org> References: <20171025123056.3165-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 03/11] target/arm: Move BE32 disassembler fixup 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The Capstone disassembler has its own big-endian fixup. Doing this twice does not work, of course. Move our current fixup from target/arm/cpu.c to disas/arm.c. This makes read_memory_inner_func unused and can be removed. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/disas/bfd.h | 7 ------- disas/arm.c | 21 ++++++++++++++++----- target/arm/cpu.c | 19 ------------------- 3 files changed, 16 insertions(+), 31 deletions(-) -- 2.13.6 diff --git a/include/disas/bfd.h b/include/disas/bfd.h index d99da68267..2852f80ed6 100644 --- a/include/disas/bfd.h +++ b/include/disas/bfd.h @@ -307,12 +307,6 @@ typedef struct disassemble_info { (bfd_vma memaddr, bfd_byte *myaddr, int length, struct disassemble_info *info); - /* A place to stash the real read_memory_func if read_memory_func wants to - do some funky address arithmetic or similar (e.g. for ARM BE32 mode). */ - int (*read_memory_inner_func) - (bfd_vma memaddr, bfd_byte *myaddr, int length, - struct disassemble_info *info); - /* Function which should be called if we get an error that we can't recover from. STATUS is the errno value from read_memory_func and MEMADDR is the address that we were trying to read. INFO is a @@ -479,7 +473,6 @@ int generic_symbol_at_address(bfd_vma, struct disassemble_info *); (INFO).buffer_vma = 0, \ (INFO).buffer_length = 0, \ (INFO).read_memory_func = buffer_read_memory, \ - (INFO).read_memory_inner_func = NULL, \ (INFO).memory_error_func = perror_memory, \ (INFO).print_address_func = generic_print_address, \ (INFO).print_insn = NULL, \ diff --git a/disas/arm.c b/disas/arm.c index 27396dd3e1..9967c45990 100644 --- a/disas/arm.c +++ b/disas/arm.c @@ -70,6 +70,17 @@ static void floatformat_to_double (unsigned char *data, double *dest) *dest = u.f; } +static int arm_read_memory(bfd_vma memaddr, bfd_byte *b, int length, + struct disassemble_info *info) +{ + assert((info->flags & INSN_ARM_BE32) == 0 || length == 2 || length == 4); + + if ((info->flags & INSN_ARM_BE32) != 0 && length == 2) { + memaddr ^= 2; + } + return info->read_memory_func(memaddr, b, length, info); +} + /* End of qemu specific additions. */ struct opcode32 @@ -3810,7 +3821,7 @@ find_ifthen_state (bfd_vma pc, struct disassemble_info *info, return; } addr -= 2; - status = info->read_memory_func (addr, (bfd_byte *)b, 2, info); + status = arm_read_memory (addr, (bfd_byte *)b, 2, info); if (status) return; @@ -3882,7 +3893,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info) info->bytes_per_chunk = size; printer = print_insn_data; - status = info->read_memory_func (pc, (bfd_byte *)b, size, info); + status = arm_read_memory (pc, (bfd_byte *)b, size, info); given = 0; if (little) for (i = size - 1; i >= 0; i--) @@ -3899,7 +3910,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info) info->bytes_per_chunk = 4; size = 4; - status = info->read_memory_func (pc, (bfd_byte *)b, 4, info); + status = arm_read_memory (pc, (bfd_byte *)b, 4, info); if (little) given = (b[0]) | (b[1] << 8) | (b[2] << 16) | ((unsigned)b[3] << 24); else @@ -3915,7 +3926,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info) info->bytes_per_chunk = 2; size = 2; - status = info->read_memory_func (pc, (bfd_byte *)b, 2, info); + status = arm_read_memory (pc, (bfd_byte *)b, 2, info); if (little) given = (b[0]) | (b[1] << 8); else @@ -3929,7 +3940,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info) || (given & 0xF800) == 0xF000 || (given & 0xF800) == 0xE800) { - status = info->read_memory_func (pc + 2, (bfd_byte *)b, 2, info); + status = arm_read_memory (pc + 2, (bfd_byte *)b, 2, info); if (little) given = (b[0]) | (b[1] << 8) | (given << 16); else diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 88578f360e..82dad0b721 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -473,21 +473,6 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info) return print_insn_arm(pc | 1, info); } -static int arm_read_memory_func(bfd_vma memaddr, bfd_byte *b, - int length, struct disassemble_info *info) -{ - assert(info->read_memory_inner_func); - assert((info->flags & INSN_ARM_BE32) == 0 || length == 2 || length == 4); - - if ((info->flags & INSN_ARM_BE32) != 0 && length == 2) { - assert(info->endian == BFD_ENDIAN_LITTLE); - return info->read_memory_inner_func(memaddr ^ 2, (bfd_byte *)b, 2, - info); - } else { - return info->read_memory_inner_func(memaddr, b, length, info); - } -} - static void arm_disas_set_info(CPUState *cpu, disassemble_info *info) { ARMCPU *ac = ARM_CPU(cpu); @@ -513,10 +498,6 @@ static void arm_disas_set_info(CPUState *cpu, disassemble_info *info) info->endian = BFD_ENDIAN_BIG; #endif } - if (info->read_memory_inner_func == NULL) { - info->read_memory_inner_func = info->read_memory_func; - info->read_memory_func = arm_read_memory_func; - } info->flags &= ~INSN_ARM_BE32; if (arm_sctlr_b(env)) { info->flags |= INSN_ARM_BE32;