From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3768 invoked by alias); 10 Nov 2004 17:48:42 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 3734 invoked from network); 10 Nov 2004 17:48:35 -0000 Received: from unknown (HELO walton.sibelius.xs4all.nl) (82.92.89.47) by sourceware.org with SMTP; 10 Nov 2004 17:48:35 -0000 Received: from elgar.sibelius.xs4all.nl (elgar.sibelius.xs4all.nl [192.168.0.2]) by walton.sibelius.xs4all.nl (8.13.0/8.13.0) with ESMTP id iAAHmVai025981; Wed, 10 Nov 2004 18:48:31 +0100 (CET) Received: from elgar.sibelius.xs4all.nl (localhost [127.0.0.1]) by elgar.sibelius.xs4all.nl (8.12.6p3/8.12.6) with ESMTP id iAAHmUet094880; Wed, 10 Nov 2004 18:48:30 +0100 (CET) (envelope-from kettenis@elgar.sibelius.xs4all.nl) Received: (from kettenis@localhost) by elgar.sibelius.xs4all.nl (8.12.6p3/8.12.6/Submit) id iAAHmUF2094877; Wed, 10 Nov 2004 18:48:30 +0100 (CET) Date: Wed, 10 Nov 2004 17:48:00 -0000 Message-Id: <200411101748.iAAHmUF2094877@elgar.sibelius.xs4all.nl> From: Mark Kettenis To: cagney@gnu.org CC: gdb-patches@sources.redhat.com In-reply-to: <419227DC.4070201@gnu.org> (message from Andrew Cagney on Wed, 10 Nov 2004 09:38:20 -0500) Subject: Re: [RFA] Fix mips32_relative_offset() References: <200411091256.iA9CujKE090590@elgar.sibelius.xs4all.nl> <419227DC.4070201@gnu.org> X-SW-Source: 2004-11/txt/msg00200.txt.bz2 Date: Wed, 10 Nov 2004 09:38:20 -0500 From: Andrew Cagney Mark Kettenis wrote: > The current code assumes that sizeof(long) == 32, which obviously > isn't true on LP64 platforms. The attached patch fixes that by using > the sign-extension idiom that's also used for SPARC. It still assumes > that a long can hold a 18-bit signed integer, but ISO C guarantees > that it can. > > OK? Yes. > P.S. Incidentally I think the function should return a LONGEST instead > of CORE_ADDR. and take a ULONGEST as input. If you want to do that, ok. Thanks, I committed the attached. Mark Index: ChangeLog from Mark Kettenis * mips-tdep.c (mips32_relative_offset): Change return type to LONGEST, change argument type to ULONGEST. Fix sign-extension. Index: mips-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/mips-tdep.c,v retrieving revision 1.362 diff -u -p -r1.362 mips-tdep.c --- mips-tdep.c 31 Oct 2004 21:51:58 -0000 1.362 +++ mips-tdep.c 10 Nov 2004 17:45:32 -0000 @@ -878,17 +878,10 @@ mips_fetch_instruction (CORE_ADDR addr) #define rtype_shamt(x) ((x >> 6) & 0x1f) #define rtype_funct(x) (x & 0x3f) -static CORE_ADDR -mips32_relative_offset (unsigned long inst) +static LONGEST +mips32_relative_offset (ULONGEST inst) { - long x; - x = itype_immediate (inst); - if (x & 0x8000) /* sign bit set */ - { - x |= 0xffff0000; /* sign extension */ - } - x = x << 2; - return x; + return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2; } /* Determine whate to set a single step breakpoint while considering