From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoDru-0007Co-Pk for qemu-devel@nongnu.org; Mon, 09 Jul 2012 09:19:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoDro-0008WG-5W for qemu-devel@nongnu.org; Mon, 09 Jul 2012 09:19:14 -0400 Message-ID: <4FFADA47.4050507@suse.de> Date: Mon, 09 Jul 2012 15:19:03 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1340636155-26426-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1340636155-26426-1-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] disas: Fix printing of addresses in disassembly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Alexander Graf , qemu-ppc , qemu-devel@nongnu.org, patches@linaro.org Am 25.06.2012 16:55, schrieb Peter Maydell: > 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 >=20 > (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.) >=20 > Signed-off-by: Peter Maydell > --- > disas.c | 19 +++++++++++++++++++ > 1 files changed, 19 insertions(+), 0 deletions(-) >=20 > 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 disassem= ble_info *info) > (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr); > } > =20 > +/* Print address in hex, truncated to the width of a target virtual ad= dress. */ > +static void > +generic_print_target_address(bfd_vma addr, struct disassemble_info *in= fo) > +{ > + uint64_t mask =3D ~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 addr= ess. */ > +static void > +generic_print_host_address(bfd_vma addr, struct disassemble_info *info= ) > +{ > + uint64_t mask =3D ~0ULL >> (64 - (sizeof(void *) * 8)); > + generic_print_address(addr & mask, info); > +} > + > /* Just return the given address. */ > =20 > int As usual the inversion and subtracted shift are a bit confusing at first, but the algorithm looks okay. I wonder if TARGET_VIRT_ADDR_SPACE_BITS is the correct factor to use here though? Might sizeof(target_phys_addr_t) * 8 be safer? I'm thinking of the possibility of having an alias in the 64-bit address space point into the actual 36/48/... virtual address space. I have a ppc64 ld instruction in mind, for which a full 64-bit register would be set up that could not fully be represented in the virtual address space. But maybe I'm misunderstanding what exactly these functions are being assigned for below... Andreas > @@ -154,6 +170,7 @@ void target_disas(FILE *out, target_ulong code, tar= get_ulong size, int flags) > disasm_info.read_memory_func =3D target_read_memory; > disasm_info.buffer_vma =3D code; > disasm_info.buffer_length =3D size; > + disasm_info.print_address_func =3D generic_print_target_address; > =20 > #ifdef TARGET_WORDS_BIGENDIAN > disasm_info.endian =3D BFD_ENDIAN_BIG; > @@ -274,6 +291,7 @@ void disas(FILE *out, void *code, unsigned long siz= e) > int (*print_insn)(bfd_vma pc, disassemble_info *info); > =20 > INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); > + disasm_info.print_address_func =3D generic_print_host_address; > =20 > disasm_info.buffer =3D code; > disasm_info.buffer_vma =3D (uintptr_t)code; > @@ -386,6 +404,7 @@ void monitor_disas(Monitor *mon, CPUArchState *env, > monitor_disas_env =3D env; > monitor_disas_is_physical =3D is_physical; > disasm_info.read_memory_func =3D monitor_read_memory; > + disasm_info.print_address_func =3D generic_print_target_address; > =20 > disasm_info.buffer_vma =3D pc; > =20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg