This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Fix amd64 register conversion
- From: Mark Kettenis <kettenis at chello dot nl>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 15 Jun 2003 13:03:48 +0200 (CEST)
- Subject: Fix amd64 register conversion
Here's the fix I promised Andrew to bring amd64 back in sync with the
i386 with respect to the register conversion functions.
Checked in.
Mark
Index: ChangeLog
from 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.
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.156
diff -u -p -r1.156 i386-tdep.c
--- i386-tdep.c 15 Jun 2003 00:27:54 -0000 1.156
+++ i386-tdep.c 15 Jun 2003 11:00:08 -0000
@@ -1392,36 +1392,21 @@ i386_register_to_value (struct frame_inf
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);
-
- /* 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);
- }
+ 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);
+
+ /* 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
@@ -1433,36 +1418,21 @@ i386_value_to_register (struct frame_inf
{
if (i386_fp_regnum_p (regnum))
{
- char to[I386_MAX_REGISTER_SIZE];
-
- /* 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);
+ i387_value_to_register (frame, regnum, type, from);
+ return;
}
- 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);
- }
+ 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);
}
Index: i387-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i387-tdep.c,v
retrieving revision 1.31
diff -u -p -r1.31 i387-tdep.c
--- i387-tdep.c 15 Jun 2003 00:27:54 -0000 1.31
+++ i387-tdep.c 15 Jun 2003 11:00:08 -0000
@@ -282,6 +282,58 @@ i387_print_float_info (struct gdbarch *g
fprintf_filtered (file, "Opcode: %s\n",
local_hex_string_custom (fop ? (fop | 0xd800) : 0, "04"));
}
+
+
+/* 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);
+}
+
/* FIXME: kettenis/2000-05-21: Right now more than a few i386 targets
define their own routines to manage the floating-point registers in
Index: i387-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/i387-tdep.h,v
retrieving revision 1.4
diff -u -p -r1.4 i387-tdep.h
--- i387-tdep.h 12 Apr 2003 17:41:25 -0000 1.4
+++ i387-tdep.h 15 Jun 2003 11:00:08 -0000
@@ -24,6 +24,7 @@
struct gdbarch;
struct ui_file;
struct frame_info;
+struct type;
/* Print out the i387 floating point state. */
@@ -31,6 +32,18 @@ extern void i387_print_float_info (struc
struct ui_file *file,
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
Index: x86-64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/x86-64-tdep.c,v
retrieving revision 1.78
diff -u -p -r1.78 x86-64-tdep.c
--- x86-64-tdep.c 13 Jun 2003 20:37:28 -0000 1.78
+++ x86-64-tdep.c 15 Jun 2003 11:00:09 -0000
@@ -208,6 +208,15 @@ x86_64_dwarf_reg_to_regnum (int reg)
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);
+}
/* The returning of values is done according to the special algorithm.
@@ -1177,6 +1186,10 @@ x86_64_init_abi (struct gdbarch_info inf
/* 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);