This is the mail archive of the gdb-patches@sources.redhat.com 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]

[PATCH] Use convert_typed_floating in i386-tdep.c


The new convert_typed_floating functions allows me to remove some
nasty bits of code in i386-tdep.c.  As a bonus this changes the type
of the floating-point registers.  We no longer lie to GDB about their
contents.  They're still marked as convertable though, since core GDB
doesn't know how to do that yet.

Checked in.

Mark

Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* i386-tdep.c (i386_extract_return_value): Use
	convert_typed_floating to extract floating-point value from
	register buffer.
	(i386_store_return_value): Use convert_typed_floating to store
	floating-point return balue in register buffer
	(i386_register_virtual_type): Change type of floating-point
	registers to builtin_type_i387_ext.
	(i386_register_convert_to_virtual): Use convert_typed_floating to
	do the conversion.
	(i386_register_convert_to_raw): Likewise.

Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.39
diff -u -p -r1.39 i386-tdep.c
--- i386-tdep.c 2001/10/21 17:19:37 1.39
+++ i386-tdep.c 2001/10/29 23:48:34
@@ -869,26 +869,12 @@ i386_extract_return_value (struct type *
 	  return;
 	}
 
-      /* Floating-point return values can be found in %st(0).  */
-      if (len == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT
-	  && TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
-	{
-	  /* Copy straight over, but take care of the padding.  */
-	  memcpy (valbuf, &regbuf[REGISTER_BYTE (FP0_REGNUM)],
-		  FPU_REG_RAW_SIZE);
-	  memset (valbuf + FPU_REG_RAW_SIZE, 0, len - FPU_REG_RAW_SIZE);
-	}
-      else
-	{
-	  /* Convert the extended floating-point number found in
-             %st(0) to the desired type.  This is probably not exactly
-             how it would happen on the target itself, but it is the
-             best we can do.  */
-	  DOUBLEST val;
-	  floatformat_to_doublest (&floatformat_i387_ext,
-				   &regbuf[REGISTER_BYTE (FP0_REGNUM)], &val);
-	  store_floating (valbuf, TYPE_LENGTH (type), val);
-	}
+      /* Floating-point return values can be found in %st(0).  Convert
+	 its contents to the desired type.  This is probably not
+	 exactly how it would happen on the target itself, but it is
+	 the best we can do.  */
+      convert_typed_floating (&regbuf[REGISTER_BYTE (FP0_REGNUM)],
+			      builtin_type_i387_ext, valbuf, type);
     }
   else
     {
@@ -928,6 +914,7 @@ i386_store_return_value (struct type *ty
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     {
       unsigned int fstat;
+      char buf[FPU_REG_RAW_SIZE];
 
       if (NUM_FREGS == 0)
 	{
@@ -939,27 +926,13 @@ i386_store_return_value (struct type *ty
          storing the return value in %st(0), we have to simulate the
          state of the FPU at function return point.  */
 
-      if (len == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT
-	  && TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
-	{
-	  /* Copy straight over.  */
-	  write_register_bytes (REGISTER_BYTE (FP0_REGNUM), valbuf,
-				FPU_REG_RAW_SIZE);
-	}
-      else
-	{
-	  char buf[FPU_REG_RAW_SIZE];
-	  DOUBLEST val;
-
-	  /* Convert the value found in VALBUF to the extended
-             floating-point format used by the FPU.  This is probably
-             not exactly how it would happen on the target itself, but
-             it is the best we can do.  */
-	  val = extract_floating (valbuf, TYPE_LENGTH (type));
-	  floatformat_from_doublest (&floatformat_i387_ext, &val, buf);
-	  write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
-				FPU_REG_RAW_SIZE);
-	}
+      /* Convert the value found in VALBUF to the extended
+	 floating-point format used by the FPU.  This is probably
+	 not exactly how it would happen on the target itself, but
+	 it is the best we can do.  */
+      convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
+      write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
+			    FPU_REG_RAW_SIZE);
 
       /* Set the top of the floating-point register stack to 7.  The
          actual value doesn't really matter, but 7 is what a normal
@@ -1017,7 +990,7 @@ i386_register_virtual_type (int regnum)
     return lookup_pointer_type (builtin_type_void);
 
   if (IS_FP_REGNUM (regnum))
-    return builtin_type_long_double;
+    return builtin_type_i387_ext;
 
   if (IS_SSE_REGNUM (regnum))
     return builtin_type_v4sf;
@@ -1044,8 +1017,7 @@ void
 i386_register_convert_to_virtual (int regnum, struct type *type,
 				  char *from, char *to)
 {
-  char buf[12];
-  DOUBLEST d;
+  gdb_assert (IS_FP_REGNUM (regnum));
 
   /* We only support floating-point values.  */
   if (TYPE_CODE (type) != TYPE_CODE_FLT)
@@ -1056,14 +1028,9 @@ i386_register_convert_to_virtual (int re
       return;
     }
 
-  /* First add the necessary padding.  */
-  memcpy (buf, from, FPU_REG_RAW_SIZE);
-  memset (buf + FPU_REG_RAW_SIZE, 0, sizeof buf - FPU_REG_RAW_SIZE);
-
-  /* Convert to TYPE.  This should be a no-op, if TYPE is equivalent
-     to the extended floating-point format used by the FPU.  */
-  d = extract_floating (buf, sizeof buf);
-  store_floating (to, TYPE_LENGTH (type), d);
+  /* Convert to TYPE.  This should be a no-op if TYPE is equivalent to
+     the extended floating-point format used by the FPU.  */
+  convert_typed_floating (from, builtin_type_i387_ext, to, type);
 }
 
 /* Convert data from virtual format with type TYPE in buffer FROM to
@@ -1073,11 +1040,20 @@ void
 i386_register_convert_to_raw (struct type *type, int regnum,
 			      char *from, char *to)
 {
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT
-	      && TYPE_LENGTH (type) == 12);
+  gdb_assert (IS_FP_REGNUM (regnum));
+
+  /* We only support floating-point values.  */
+  if (TYPE_CODE (type) != TYPE_CODE_FLT)
+    {
+      warning ("Cannot convert non-floating-point type "
+	       "to floating-point register value.");
+      memset (to, 0, TYPE_LENGTH (type));
+      return;
+    }
 
-  /* Simply omit the two unused bytes.  */
-  memcpy (to, from, FPU_REG_RAW_SIZE);
+  /* Convert from TYPE.  This should be a no-op if TYPE is equivalent
+     to the extended floating-point format used by the FPU.  */
+  convert_typed_floating (from, type, to, builtin_type_i387_ext);
 }
      
 


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