Move floating-point code to new function in i387-tdep.c.
* i387-tdep.c (i387_register_to_value, i387_value_to_register):
New functions containing code moved here from i386-tdep.c.
* i387-tdep.h: Add opaque declaration for `struct type'.
(i387_register_to_value, i387_value_to_register): New prototypes.
* x86-64-tdep.c (x86_64_convert_register_p): New function.
(x86_64_init_abi): Set convert_register_p, register_to_value and
value_to_register here.
+2003-06-15 Mark Kettenis <kettenis@gnu.org>
+
+ * i386-tdep.c (i386_register_to_value, i386_value_to_register):
+ Move floating-point code to new function in i387-tdep.c.
+ * i387-tdep.c (i387_register_to_value, i387_value_to_register):
+ New functions containing code moved here from i386-tdep.c.
+ * i387-tdep.h: Add opaque declaration for `struct type'.
+ (i387_register_to_value, i387_value_to_register): New prototypes.
+ * x86-64-tdep.c (x86_64_convert_register_p): New function.
+ (x86_64_init_abi): Set convert_register_p, register_to_value and
+ value_to_register here.
+
2003-06-14 Andrew Cagney <cagney@redhat.com>
* mips-tdep.c (mips_register_to_value): Make static.
if (i386_fp_regnum_p (regnum))
{
- char from[I386_MAX_REGISTER_SIZE];
-
- /* We only support floating-point values. */
- if (TYPE_CODE (type) != TYPE_CODE_FLT)
- {
- warning ("Cannot convert floating-point register value "
- "to non-floating-point type.");
- return;
- }
-
- /* Convert to TYPE. This should be a no-op if TYPE is
- equivalent to the extended floating-point format used by the
- FPU. */
- frame_read_register (frame, regnum, from);
- convert_typed_floating (from, builtin_type_i387_ext, to, type);
+ i387_register_to_value (frame, regnum, type, to);
+ return;
}
- else
- {
- gdb_assert (TYPE_LENGTH (type) == 8);
- /* Read the first part. */
- gdb_assert (register_size (current_gdbarch, regnum) == 4);
- frame_read_register (frame, regnum, (char *) to + 0);
+ gdb_assert (TYPE_LENGTH (type) == 8);
- /* Read the second part. */
- regnum = i386_next_regnum (regnum);
- gdb_assert (regnum != -1);
- gdb_assert (register_size (current_gdbarch, regnum));
- frame_read_register (frame, regnum, (char *) to + 4);
- }
+ /* Read the first part. */
+ gdb_assert (register_size (current_gdbarch, regnum) == 4);
+ frame_read_register (frame, regnum, (char *) to + 0);
+
+ /* Read the second part. */
+ regnum = i386_next_regnum (regnum);
+ gdb_assert (regnum != -1);
+ gdb_assert (register_size (current_gdbarch, regnum));
+ frame_read_register (frame, regnum, (char *) to + 4);
}
/* Write the contents FROM of a value of type TYPE into register
{
if (i386_fp_regnum_p (regnum))
{
- char to[I386_MAX_REGISTER_SIZE];
+ i387_value_to_register (frame, regnum, type, from);
+ return;
+ }
- /* 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.");
- return;
- }
+ gdb_assert (TYPE_LENGTH (type) == 8);
- /* 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);
- put_frame_register (frame, regnum, to);
- }
- else
- {
- gdb_assert (TYPE_LENGTH (type) == 8);
-
- /* Write the first part. */
- gdb_assert (register_size (current_gdbarch, regnum) == 4);
- put_frame_register (frame, regnum, (const char *) from + 0);
-
- /* Write the second part. */
- regnum = i386_next_regnum (regnum);
- gdb_assert (regnum != -1);
- gdb_assert (register_size (current_gdbarch, regnum) == 4);
- put_frame_register (frame, regnum, (const char *) from + 4);
- }
+ /* Write the first part. */
+ gdb_assert (register_size (current_gdbarch, regnum) == 4);
+ put_frame_register (frame, regnum, (const char *) from + 0);
+
+ /* Write the second part. */
+ regnum = i386_next_regnum (regnum);
+ gdb_assert (regnum != -1);
+ gdb_assert (register_size (current_gdbarch, regnum) == 4);
+ put_frame_register (frame, regnum, (const char *) from + 4);
}
\f
fprintf_filtered (file, "Opcode: %s\n",
local_hex_string_custom (fop ? (fop | 0xd800) : 0, "04"));
}
+\f
+
+/* Read a value of type TYPE from register REGNUM in frame FRAME, and
+ return its contents in TO. */
+
+void
+i387_register_to_value (struct frame_info *frame, int regnum,
+ struct type *type, void *to)
+{
+ char from[I386_MAX_REGISTER_SIZE];
+
+ gdb_assert (i386_fp_regnum_p (regnum));
+
+ /* We only support floating-point values. */
+ if (TYPE_CODE (type) != TYPE_CODE_FLT)
+ {
+ warning ("Cannot convert floating-point register value "
+ "to non-floating-point type.");
+ return;
+ }
+
+ /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
+ the extended floating-point format used by the FPU. */
+ frame_read_register (frame, regnum, from);
+ convert_typed_floating (from, builtin_type_i387_ext, to, type);
+}
+
+/* Write the contents FROM of a value of type TYPE into register
+ REGNUM in frame FRAME. */
+
+void
+i387_value_to_register (struct frame_info *frame, int regnum,
+ struct type *type, const void *from)
+{
+ char to[I386_MAX_REGISTER_SIZE];
+
+ gdb_assert (i386_fp_regnum_p (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.");
+ return;
+ }
+
+ /* 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);
+ put_frame_register (frame, regnum, to);
+}
+\f
/* FIXME: kettenis/2000-05-21: Right now more than a few i386 targets
define their own routines to manage the floating-point registers in
struct gdbarch;
struct ui_file;
struct frame_info;
+struct type;
/* Print out the i387 floating point state. */
struct frame_info *frame,
const char *args);
+/* Read a value of type TYPE from register REGNUM in frame FRAME, and
+ return its contents in TO. */
+
+extern void i387_register_to_value (struct frame_info *frame, int regnum,
+ struct type *type, void *to);
+
+/* Write the contents FROM of a value of type TYPE into register
+ REGNUM in frame FRAME. */
+
+extern void i387_value_to_register (struct frame_info *frame, int regnum,
+ struct type *type, const void *from);
+
/* Fill register REGNUM in GDB's register array with the appropriate
value from *FSAVE. This function masks off any of the reserved
bits in *FSAVE. */
return regnum;
}
+
+/* Return nonzero if a value of type TYPE stored in register REGNUM
+ needs any special handling. */
+
+static int
+x86_64_convert_register_p (int regnum, struct type *type)
+{
+ return i386_fp_regnum_p (regnum);
+}
\f
/* The returning of values is done according to the special algorithm.
/* Call dummy code. */
set_gdbarch_push_dummy_call (gdbarch, x86_64_push_dummy_call);
+ set_gdbarch_convert_register_p (gdbarch, x86_64_convert_register_p);
+ set_gdbarch_register_to_value (gdbarch, i387_register_to_value);
+ set_gdbarch_value_to_register (gdbarch, i387_value_to_register);
+
set_gdbarch_extract_return_value (gdbarch, x86_64_extract_return_value);
set_gdbarch_store_return_value (gdbarch, x86_64_store_return_value);
/* Override, since this is handled by x86_64_extract_return_value. */