/* Intel 387 floating point stuff.
- Copyright (C) 1988, 89, 91, 98, 99, 2000 Free Software Foundation, Inc.
+ Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
This file is part of GDB.
#include "value.h"
#include "gdbcore.h"
#include "floatformat.h"
+#include "regcache.h"
+#include "gdb_assert.h"
+#include "doublest.h"
/* FIXME: Eliminate the next two functions when we have the time to
void double_to_i387 (char *from, char *to);
void
-i387_to_double (from, to)
- char *from;
- char *to;
+i387_to_double (char *from, char *to)
{
floatformat_to_double (&floatformat_i387_ext, from, (double *) to);
}
void
-double_to_i387 (from, to)
- char *from;
- char *to;
+double_to_i387 (char *from, char *to)
{
floatformat_from_double (&floatformat_i387_ext, (double *) from, to);
}
static void print_387_status_bits (unsigned int status);
static void
-print_387_control_bits (control)
- unsigned int control;
+print_387_control_bits (unsigned int control)
{
switch ((control >> 8) & 3)
{
}
void
-print_387_control_word (control)
- unsigned int control;
+print_387_control_word (unsigned int control)
{
printf_filtered ("control %s:", local_hex_string(control & 0xffff));
print_387_control_bits (control);
}
static void
-print_387_status_bits (status)
- unsigned int status;
+print_387_status_bits (unsigned int status)
{
printf_unfiltered (" flags %d%d%d%d; ",
(status & 0x4000) != 0,
}
void
-print_387_status_word (status)
- unsigned int status;
+print_387_status_word (unsigned int status)
{
printf_filtered ("status %s:", local_hex_string (status & 0xffff));
print_387_status_bits (status);
print_i387_value (char *raw)
{
DOUBLEST value;
+ int len = TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT;
+ char *tmp = alloca (len);
- /* Avoid call to floatformat_to_doublest if possible to preserve as
- much information as possible. */
+ /* This code only works on targets where ... */
+ gdb_assert (TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext);
-#ifdef HAVE_LONG_DOUBLE
- if (sizeof (value) == sizeof (long double)
- && HOST_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
- {
- /* Copy straight over, but take care of the padding. */
- memcpy (&value, raw, FPU_REG_RAW_SIZE);
- memset ((char *) &value + FPU_REG_RAW_SIZE, 0,
- sizeof (value) - FPU_REG_RAW_SIZE);
- }
- else
-#endif
- floatformat_to_doublest (&floatformat_i387_ext, raw, &value);
+ /* Take care of the padding. FP reg is 80 bits. The same value in
+ memory is 96 bits. */
+ gdb_assert (FPU_REG_RAW_SIZE < len);
+ memcpy (tmp, raw, FPU_REG_RAW_SIZE);
+ memset (tmp + FPU_REG_RAW_SIZE, 0, len - FPU_REG_RAW_SIZE);
+
+ /* Extract the value as a DOUBLEST. */
+ /* Use extract_floating() rather than floatformat_to_doublest().
+ The latter is lossy in nature. Once GDB gets a host/target
+ independent and non-lossy FP it will become possible to bypass
+ extract_floating() and call floatformat*() directly. Note also
+ the assumptions about TARGET_LONG_DOUBLE above. */
+ value = extract_floating (tmp, len);
/* We try to print 19 digits. The last digit may or may not contain
garbage, but we'd better print one too many. We need enough room
puts_filtered (" ");
printf_filtered (" %s", (status & 0x0080) ? "ES" : " ");
puts_filtered (" ");
- printf_filtered (" %s", (status & 0x0080) ? "SF" : " ");
+ printf_filtered (" %s", (status & 0x0040) ? "SF" : " ");
puts_filtered (" ");
printf_filtered (" %s", (status & 0x0100) ? "C0" : " ");
printf_filtered (" %s", (status & 0x0200) ? "C1" : " ");