* [RFA] Fix mips32_relative_offset()
@ 2004-11-09 12:57 Mark Kettenis
2004-11-10 14:39 ` Andrew Cagney
0 siblings, 1 reply; 3+ messages in thread
From: Mark Kettenis @ 2004-11-09 12:57 UTC (permalink / raw)
To: gdb-patches
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?
Mark
P.S. Incidentally I think the function should return a LONGEST instead
of CORE_ADDR.
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* mips-tdep.c (mips32_relative_offset): Avoid ussumption that
sizeof(long) == 32.
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 9 Nov 2004 12:51:40 -0000
@@ -881,14 +881,8 @@ mips_fetch_instruction (CORE_ADDR addr)
static CORE_ADDR
mips32_relative_offset (unsigned long inst)
{
- long x;
- x = itype_immediate (inst);
- if (x & 0x8000) /* sign bit set */
- {
- x |= 0xffff0000; /* sign extension */
- }
- x = x << 2;
- return x;
+ long x = ((itype_immediate (inst) ^ 0x8000) - 0x8000);
+ return x << 2;
}
/* Determine whate to set a single step breakpoint while considering
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Fix mips32_relative_offset()
2004-11-09 12:57 [RFA] Fix mips32_relative_offset() Mark Kettenis
@ 2004-11-10 14:39 ` Andrew Cagney
2004-11-10 17:48 ` Mark Kettenis
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2004-11-10 14:39 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches
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.
Andrew
> Index: ChangeLog
> from Mark Kettenis <kettenis@gnu.org>
>
> * mips-tdep.c (mips32_relative_offset): Avoid ussumption that
> sizeof(long) == 32.
>
> 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 9 Nov 2004 12:51:40 -0000
> @@ -881,14 +881,8 @@ mips_fetch_instruction (CORE_ADDR addr)
> static CORE_ADDR
> mips32_relative_offset (unsigned long inst)
> {
> - long x;
> - x = itype_immediate (inst);
> - if (x & 0x8000) /* sign bit set */
> - {
> - x |= 0xffff0000; /* sign extension */
> - }
> - x = x << 2;
> - return x;
> + long x = ((itype_immediate (inst) ^ 0x8000) - 0x8000);
> + return x << 2;
> }
>
> /* Determine whate to set a single step breakpoint while considering
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Fix mips32_relative_offset()
2004-11-10 14:39 ` Andrew Cagney
@ 2004-11-10 17:48 ` Mark Kettenis
0 siblings, 0 replies; 3+ messages in thread
From: Mark Kettenis @ 2004-11-10 17:48 UTC (permalink / raw)
To: cagney; +Cc: gdb-patches
Date: Wed, 10 Nov 2004 09:38:20 -0500
From: Andrew Cagney <cagney@gnu.org>
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 <kettenis@gnu.org>
* 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-11-10 17:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-09 12:57 [RFA] Fix mips32_relative_offset() Mark Kettenis
2004-11-10 14:39 ` Andrew Cagney
2004-11-10 17:48 ` Mark Kettenis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox