From patchwork Mon Jun 25 14:55:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9602 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id CD32623EE2 for ; Mon, 25 Jun 2012 14:55:59 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9C795A18499 for ; Mon, 25 Jun 2012 14:55:59 +0000 (UTC) Received: by ghbz12 with SMTP id z12so3128930ghb.11 for ; Mon, 25 Jun 2012 07:55:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=AhOvuQTi5vDNwcaO9rsLbTRPYD55Th1qBIzOwGIKQyk=; b=FwMgSrEqhBqndsglC6PccdcdpQu0DorcnZUCWSed1MLPcODb6iwL5/ZxM4ZbTvttRw 4NJZAqkReqx+BZC2gTwyYXM5Jfj42l2RvHF7Ro+f+GH3HhLnizkMpaAp7ZjWq/HpG+ha GtETKHU4YsX7uBGrvk6xydepyDRG1o/uInb73w+rHRG/+sqPbjyL/HiNuQ+IARBfZ7Zp BuZNyM11dmSHWEirtPZ0V+9LLR7bbmb4OegDUv+Y/+tjenbvziBMJMC9sRpr1qhoa4ec W64lGnLDhDa26QWI1QrCzxcrTLoYK3cWPa/riZHtOqrxBLEATWv/M8D3xS4dUjgraQGD qLCw== Received: by 10.42.155.73 with SMTP id t9mr5694554icw.48.1340636158845; Mon, 25 Jun 2012 07:55:58 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp49890ibb; Mon, 25 Jun 2012 07:55:58 -0700 (PDT) Received: by 10.216.240.79 with SMTP id d57mr4237774wer.3.1340636157630; Mon, 25 Jun 2012 07:55:57 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id c73si16550088wec.20.2012.06.25.07.55.57 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jun 2012 07:55:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SjAhn-0006sf-93; Mon, 25 Jun 2012 15:55:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH] disas: Fix printing of addresses in disassembly Date: Mon, 25 Jun 2012 15:55:55 +0100 Message-Id: <1340636155-26426-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQnLP6PuYAPrr8gNBbUYot4FcEQt2+E6ccfjkPLHsJ1Y3uObZvKS8mKqWJWQj2+XKb88Y+3I In our disassembly code, the bfd_vma type is always 64 bits, even if the target's virtual address width is only 32 bits. This means that when we print out addresses we need to truncate them to 32 bits, to avoid odd output which has incorrectly sign-extended a value to 64 bits, for instance this ARM example: 0x80479a60: e59f4088 ldr r4, [pc, #136] ; 0xffffffff80479a4f (It would also be possible to truncate before passing the address to info->print_address_func(), but truncating in the final print function is the same approach that binutils takes to this problem.) Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber --- disas.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/disas.c b/disas.c index 93d8d30..7b2acc9 100644 --- a/disas.c +++ b/disas.c @@ -64,6 +64,22 @@ generic_print_address (bfd_vma addr, struct disassemble_info *info) (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr); } +/* Print address in hex, truncated to the width of a target virtual address. */ +static void +generic_print_target_address(bfd_vma addr, struct disassemble_info *info) +{ + uint64_t mask = ~0ULL >> (64 - TARGET_VIRT_ADDR_SPACE_BITS); + generic_print_address(addr & mask, info); +} + +/* Print address in hex, truncated to the width of a host virtual address. */ +static void +generic_print_host_address(bfd_vma addr, struct disassemble_info *info) +{ + uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8)); + generic_print_address(addr & mask, info); +} + /* Just return the given address. */ int @@ -154,6 +170,7 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags) disasm_info.read_memory_func = target_read_memory; disasm_info.buffer_vma = code; disasm_info.buffer_length = size; + disasm_info.print_address_func = generic_print_target_address; #ifdef TARGET_WORDS_BIGENDIAN disasm_info.endian = BFD_ENDIAN_BIG; @@ -274,6 +291,7 @@ void disas(FILE *out, void *code, unsigned long size) int (*print_insn)(bfd_vma pc, disassemble_info *info); INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); + disasm_info.print_address_func = generic_print_host_address; disasm_info.buffer = code; disasm_info.buffer_vma = (uintptr_t)code; @@ -386,6 +404,7 @@ void monitor_disas(Monitor *mon, CPUArchState *env, monitor_disas_env = env; monitor_disas_is_physical = is_physical; disasm_info.read_memory_func = monitor_read_memory; + disasm_info.print_address_func = generic_print_target_address; disasm_info.buffer_vma = pc;