This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mips-tdep.c: Sign-extend pointers for n32


On Sun, 16 Dec 2007, Daniel Jacobowitz wrote:

> Why just pointers?  I'm not entirely sure what's going on above in the
> float case, but in the integer case this seems clearly wrong.  Zero
> extension is probably "right" for trailing bits of structures but what
> about negative integers?

 You are quite right here -- I have checked the N32 ABI document and it 
says:

"32-bit integer (int) parameters are always sign-extended when passed in 
registers, whether of signed or unsigned type. [This issue does not arise 
in the o32-bit ABI.]"

It does not actually say anything about pointers beyond:

"All pointers and addresses are 32-bit objects. [Under 64, pointers and 
addresses are 64bits.]"

but I gather this is because the document was meant to specify a user mode 
ABI for programs run under IRIX only, so addresses with the bit #31 set 
were not expected to be relevant.

 I have regression-tested the following rewrite of the original patch 
using the mipsisa32-sde-elf target, with the mips-sim-sde64/-mips64/-EB 
and mips-sim-sde64/-mips64/-EL boards, with the results the same as the 
original.

2007-12-19  David Ung  <davidu@mips.com>
            Maciej W. Rozycki  <macro@mips.com>

	* mips-tdep.c (mips_n32n64_push_dummy_call): Sign-extend 32-bit
	pointers and integers as required by the ABI.

 OK to apply?

  Maciej

12741-0.diff
Index: binutils-quilt/src/gdb/mips-tdep.c
===================================================================
--- binutils-quilt.orig/src/gdb/mips-tdep.c	2007-12-19 15:09:31.000000000 +0000
+++ binutils-quilt/src/gdb/mips-tdep.c	2007-12-19 15:10:13.000000000 +0000
@@ -3184,8 +3184,17 @@
 	         purpose register.  */
 	      if (argreg <= MIPS_LAST_ARG_REGNUM)
 		{
-		  LONGEST regval =
-		    extract_unsigned_integer (val, partial_len);
+		  LONGEST regval;
+
+		  /* Sign extend pointers and 32-bit integers;
+		     everything else is taken as is.  */
+
+		  if (partial_len == 4 &&
+		      (typecode == TYPE_CODE_PTR
+		       || typecode == TYPE_CODE_INT))
+		    regval = extract_signed_integer (val, partial_len);
+		  else
+		    regval = extract_unsigned_integer (val, partial_len);
 
 		  /* A non-floating-point argument being passed in a
 		     general register.  If a struct or union, and if


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]