[PATCH/SPARC] Use generic SPARC ptrace code for FreeBSD/sparc64

Mark Kettenis kettenis@chello.nl
Fri Dec 26 21:12:00 GMT 2003


This gets rid of some duplicated code.

Committed to the SPARC branch.

Mark


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

	* sparc64-nat.c (sparc64_gregset_supplies_p): Return non-zero if
	REGNUM is SPARC64_FPRS_REGNUM.
	* sparc64-tdep.c (sparc64_supply_gregset): Deal with
	SPARC64_FPRS_REGNUM.
	(sparc64_collect_gregset): Likewise.
	* sparc64-tdep.h (r_fprs_offset): New define.
	(sparc64fbsd_gregset): Add define.
	(sparc64fbsd_supply_reg, sparc64fbsd_fill_reg)
	(sparc64fbsd_supply_fpreg, sparc64fbsd_fill_fpreg): Remove
	declarations.
	* sparc64fbsd-nat.c (sparc64fbsd_reg_supplies_p)
	(sparc64fbsd_fpreg_supplies_p): Remove functions.
	(_initialize_sparc64fbsd_nat): Remove initialization of
	sparcbsd_supply_reg, sparcbsd_fill_reg, sparcbsd_supply_fpreg,
	sparcbsd_fill_fpreg, sparcbsd_reg_supplies_p,
	sparcbsd_fpreg_supplies_p.  Initialize sparc_gregset.
	* sparc64fbsd-tdep.c (sparc64fbsd_gregset): New variable.
	(sparc64fbsd_r_global_offset, sparc64fbsd_r_out_offset)
	(sparc64fbsd_r_fprs_offset, sparc64fbsd_r_tnpc_offset)
	(sparc64fbsd_r_tpc_offset, sparc64fbsd_r_tstate_offset)
	(sparc64fbsd_r_y_offset): Remove variables.
	(sparc64fbsd_sizeof_struct_reg, sparc64fbsd_sizeof_struct_fpreg):
	Make static and const.
	(sparc64fbsd_supply_reg, sparc64fbsd_fill_reg)
	(sparc64fbsd_supply_fpreg, sparc64fbsd_fill_fpreg): Remove
	functions.
	(fetch_core_registers): Replace calls to sparc64fbsd_supply_reg
	and sparc64fbsd_supply_fpreg with calls to sparc64_supply_gregset
	and sparc64_supply_fpregset.
	* Makefile.in (sparc64fbsd-nat.o): Update dependencies.
	* config/sparc/fbsd.mh (NATDEPFILES): Remove sparcbsd-nat.o.  Add
	sparc64-nat.o and sparc-nat.o.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.445.2.9
diff -u -p -r1.445.2.9 Makefile.in
--- Makefile.in 15 Dec 2003 20:29:18 -0000 1.445.2.9
+++ Makefile.in 26 Dec 2003 21:11:03 -0000
@@ -2343,7 +2343,7 @@ sparc64-sol2-tdep.o: sparc64-sol2-tdep.c
 sparc64fbsd-tdep.o: sparc64fbsd-tdep.c $(defs_h) $(gdbcore_h) $(osabi_h) \
 	$(regcache_h) $(target_h) $(gdb_string_h) $(sparc64_tdep_h)
 sparc64fbsd-nat.o: sparc64fbsd-nat.c $(defs_h) $(sparc64_tdep_h) \
-	$(sparcbsd_nat_h)
+	$(sparc_nat_h)
 sparc-stub.o: sparc-stub.c
 stabsread.o: stabsread.c $(defs_h) $(gdb_string_h) $(bfd_h) $(gdb_obstack_h) \
 	$(symtab_h) $(gdbtypes_h) $(expression_h) $(symfile_h) $(objfiles_h) \
Index: sparc64-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/Attic/sparc64-nat.c,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 sparc64-nat.c
--- sparc64-nat.c 2 Nov 2003 20:26:32 -0000 1.1.2.1
+++ sparc64-nat.c 26 Dec 2003 21:11:03 -0000
@@ -44,7 +44,8 @@ sparc64_gregset_supplies_p (int regnum)
   if (regnum == SPARC64_PC_REGNUM
       || regnum == SPARC64_NPC_REGNUM
       || regnum == SPARC64_STATE_REGNUM
-      || regnum == SPARC64_Y_REGNUM)
+      || regnum == SPARC64_Y_REGNUM
+      || regnum == SPARC64_FPRS_REGNUM)
     return 1;
 
   return 0;
Index: sparc64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc64-tdep.c,v
retrieving revision 1.3.4.4
diff -u -p -r1.3.4.4 sparc64-tdep.c
--- sparc64-tdep.c 21 Dec 2003 23:13:59 -0000 1.3.4.4
+++ sparc64-tdep.c 26 Dec 2003 21:11:04 -0000
@@ -1205,6 +1205,11 @@ sparc64_supply_gregset (const struct spa
 		  regs + gregset->r_y_offset, gregset->r_y_size);
 	  regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf);
 	}
+
+      if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
+	  && gregset->r_fprs_offset != -1)
+	regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM,
+			     regs + gregset->r_fprs_offset);
     }
 
   if (regnum == SPARC_G0_REGNUM || regnum == -1)
@@ -1316,6 +1321,12 @@ sparc64_collect_gregset (const struct sp
 	  memcpy (regs + gregset->r_y_offset,
 		  buf + 8 - gregset->r_y_size, gregset->r_y_size);
 	}
+
+      if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
+	  && gregset->r_fprs_offset != -1)
+	regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM,
+			      regs + gregset->r_fprs_offset);
+
     }
 
   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
Index: sparc64-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/sparc64-tdep.h,v
retrieving revision 1.2.6.2
diff -u -p -r1.2.6.2 sparc64-tdep.h
--- sparc64-tdep.h 2 Nov 2003 20:26:32 -0000 1.2.6.2
+++ sparc64-tdep.h 26 Dec 2003 21:11:04 -0000
@@ -29,6 +29,9 @@
 /* UltraSPARC doesn't have %psr.  */
 #define r_tstate_offset r_psr_offset
 
+/* UltraSPARC doesn't have %wim either.  */
+#define r_fprs_offset r_wim_offset
+
 /* Register numbers of various important registers.  */
 
 enum sparc64_regnum
@@ -91,11 +94,9 @@ extern const struct sparc_gregset sparc6
 extern void sparc64_sol2_init_abi (struct gdbarch_info info,
 				   struct gdbarch *gdbarch);
 
-/* Functions exported from sparc64fbsd-tdep.c.  */
+/* Variables exported from sparc64fbsd-tdep.c.  */
 
-extern void sparc64fbsd_supply_reg (const char *regs, int regnum);
-extern void sparc64fbsd_fill_reg (char *regs, int regnum);
-extern void sparc64fbsd_supply_fpreg (const char *regs, int regnum);
-extern void sparc64fbsd_fill_fpreg (char *regs, int regnum);
+/* Register offsets for FreeBSD/sparc64.  */
+extern const struct sparc_gregset sparc64fbsd_gregset;
 
 #endif /* sparc64-tdep.h */
Index: sparc64fbsd-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc64fbsd-nat.c,v
retrieving revision 1.2
diff -u -p -r1.2 sparc64fbsd-nat.c
--- sparc64fbsd-nat.c 22 Aug 2003 18:52:50 -0000 1.2
+++ sparc64fbsd-nat.c 26 Dec 2003 21:11:04 -0000
@@ -22,47 +22,7 @@
 #include "defs.h"
 
 #include "sparc64-tdep.h"
-#include "sparcbsd-nat.h"
-
-/* Determine whether `struct reg' contains register REGNUM.  */
-
-static int
-sparc64fbsd_reg_supplies_p (int regnum)
-{
-  /* Integer registers.  */
-  if ((regnum >= SPARC_G0_REGNUM && regnum <= SPARC_G7_REGNUM)
-      || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
-      || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
-      || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
-    return 1;
-
-  /* Control registers.  */
-  if (regnum == SPARC64_PC_REGNUM
-      || regnum == SPARC64_NPC_REGNUM
-      || regnum == SPARC64_STATE_REGNUM
-      || regnum == SPARC64_FPRS_REGNUM
-      || regnum == SPARC64_Y_REGNUM)
-    return 1;
-
-  return 0;
-}
-
-/* Determine whether `struct fpreg' contains register REGNUM.  */
-
-static int
-sparc64fbsd_fpreg_supplies_p (int regnum)
-{
-  /* Floating-point registers.  */
-  if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
-      || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
-    return 1;
-
-  /* Control registers.  */
-  if (regnum == SPARC64_FSR_REGNUM)
-    return 1;
-
-  return 0;
-}
+#include "sparc-nat.h"
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 void _initialize_sparc64fbsd_nat (void);
@@ -70,11 +30,5 @@ void _initialize_sparc64fbsd_nat (void);
 void
 _initialize_sparc64fbsd_nat (void)
 {
-  sparcbsd_supply_reg = sparc64fbsd_supply_reg;
-  sparcbsd_fill_reg = sparc64fbsd_fill_reg;
-  sparcbsd_supply_fpreg = sparc64fbsd_supply_fpreg;
-  sparcbsd_fill_fpreg = sparc64fbsd_fill_fpreg;
-
-  sparcbsd_reg_supplies_p = sparc64fbsd_reg_supplies_p;
-  sparcbsd_fpreg_supplies_p = sparc64fbsd_fpreg_supplies_p;
+  sparc_gregset = &sparc64fbsd_gregset;
 }
Index: sparc64fbsd-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc64fbsd-tdep.c,v
retrieving revision 1.2.6.1
diff -u -p -r1.2.6.1 sparc64fbsd-tdep.c
--- sparc64fbsd-tdep.c 18 Oct 2003 18:25:46 -0000 1.2.6.1
+++ sparc64fbsd-tdep.c 26 Dec 2003 21:11:04 -0000
@@ -30,158 +30,24 @@
 #include "sparc64-tdep.h"
 
 /* From <machine/reg.h>.  */
-
-/* Offset of registers in `struct reg'.  */
-int sparc64fbsd_r_global_offset = (0 * 8);
-int sparc64fbsd_r_out_offset = (8 * 8);
-int sparc64fbsd_r_fprs_offset = (16 * 8);
-int sparc64fbsd_r_tnpc_offset = (24 * 8);
-int sparc64fbsd_r_tpc_offset = (25 * 8);
-int sparc64fbsd_r_tstate_offset = (26 * 8);
-int sparc64fbsd_r_y_offset = (28 * 8);
-
-/* Size of `struct reg' and `struct fpreg'.  */
-int sparc64fbsd_sizeof_struct_reg = 256;
-int sparc64fbsd_sizeof_struct_fpreg = 272;
-
-void
-sparc64fbsd_supply_reg (const char *regs, int regnum)
-{
-  char buf[8];
-  int i;
-
-  if (regnum == SPARC64_PC_REGNUM || regnum == -1)
-    supply_register (SPARC64_PC_REGNUM, regs + sparc64fbsd_r_tpc_offset);
-
-  if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
-    supply_register (SPARC64_NPC_REGNUM, regs + sparc64fbsd_r_tnpc_offset);
-
-  if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
-    supply_register (SPARC64_STATE_REGNUM, regs + sparc64fbsd_r_tstate_offset);
-
-  if (regnum == SPARC64_FPRS_REGNUM || regnum == -1)
-    supply_register (SPARC64_FPRS_REGNUM, regs + sparc64fbsd_r_fprs_offset);
-
-  if (regnum == SPARC64_Y_REGNUM || regnum == -1)
-    supply_register (SPARC64_Y_REGNUM, regs + sparc64fbsd_r_y_offset);
-
-  if ((regnum >= SPARC_G0_REGNUM && regnum <= SPARC_G7_REGNUM) || regnum == -1)
-    {
-      if (regnum == SPARC_G0_REGNUM || regnum == -1)
-	supply_register (SPARC_G0_REGNUM, NULL); /* %g0 is always zero.  */
-      for (i = SPARC_G1_REGNUM; i <= SPARC_G7_REGNUM; i++)
-	{
-	  if (regnum == i || regnum == -1)
-	    supply_register (i, (regs + sparc64fbsd_r_global_offset
-				 + ((i - SPARC_G0_REGNUM) * 8)));
-	}
-    }
-
-  if ((regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
-    {
-      for (i = SPARC_O0_REGNUM; i <= SPARC_O7_REGNUM; i++)
-	{
-	  if (regnum == i || regnum == -1)
-	    supply_register (i, (regs + sparc64fbsd_r_out_offset
-				 + ((i - SPARC_O0_REGNUM) * 8)));
-        }
-    }
-
-  /* Inputs and Locals are stored onto the stack by by the kernel.  */
-  if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
-    {
-      ULONGEST sp;
-
-      regcache_cooked_read_unsigned (current_regcache, SPARC_SP_REGNUM, &sp);
-      sparc_supply_rwindow (current_regcache, sp, regnum);
-    }
-}
-
-void
-sparc64fbsd_fill_reg (char *regs, int regnum)
+const struct sparc_gregset sparc64fbsd_gregset =
 {
-  char buf[8];
-  int i;
-
-  if (regnum == SPARC64_PC_REGNUM || regnum == -1)
-    regcache_collect (SPARC64_PC_REGNUM, regs + sparc64fbsd_r_tpc_offset);
-
-  if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
-    regcache_collect (SPARC64_NPC_REGNUM, regs + sparc64fbsd_r_tnpc_offset);
-
-  if (regnum == SPARC64_FPRS_REGNUM || regnum == -1)
-    regcache_collect (SPARC64_FPRS_REGNUM, regs + sparc64fbsd_r_fprs_offset);
-
-  if (regnum == SPARC64_Y_REGNUM || regnum == -1)
-    regcache_collect (SPARC64_Y_REGNUM, regs + sparc64fbsd_r_y_offset);
-
-  if ((regnum >= SPARC_G0_REGNUM && regnum <= SPARC_G7_REGNUM) || regnum == -1)
-    {
-      /* %g0 is always zero.  */
-      for (i = SPARC_G1_REGNUM; i <= SPARC_G7_REGNUM; i++)
-	{
-	  if (regnum == i || regnum == -1)
-	    regcache_collect (i, (regs + sparc64fbsd_r_global_offset
-				  + ((i - SPARC_G0_REGNUM) * 8)));
-	}
-    }
-
-  if ((regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
-    {
-      for (i = SPARC_O0_REGNUM; i <= SPARC_O7_REGNUM; i++)
-	{
-	  if (regnum == i || regnum == -1)
-	    regcache_collect (i, (regs + sparc64fbsd_r_out_offset
-				  + ((i - SPARC_O0_REGNUM) * 8)));
-        }
-    }
-
-  /* Responsibility for the stack regs is pushed off onto the caller.  */
-}
-
-void
-sparc64fbsd_supply_fpreg (const char *fpregs, int regnum)
-{
-  int i;
-
-  for (i = 0; i < 32; i++)
-    {
-      if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
-	supply_register (SPARC_F0_REGNUM + i, fpregs + (i * 4));
-    }
-
-  for (i = 0; i < 16; i++)
-    {
-      if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
-	supply_register (SPARC64_F32_REGNUM + i, fpregs + (32 * 4) + (i * 8));
-    }
-
-  if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
-    supply_register (SPARC64_FSR_REGNUM, fpregs + (32 * 4) + (16 * 8));
-}
-
-void
-sparc64fbsd_fill_fpreg (char *fpregs, int regnum)
-{
-  int i;
-
-  for (i = 0; i < 32; i++)
-    {
-      if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
-	regcache_collect (SPARC_F0_REGNUM + i, fpregs + (i * 4));
-    }
-
-  for (i = 0; i < 16; i++)
-    {
-      if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
-	regcache_collect (SPARC64_F32_REGNUM + i, fpregs + (32 * 4) + (i * 8));
-    }
-
-  if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
-    regcache_collect (SPARC64_FSR_REGNUM, fpregs + (32 * 4) + (16 * 8));
-}
+  26 * 8,			/* "tstate" */
+  25 * 8,			/* %pc */
+  24 * 8,			/* %npc */
+  28 * 8,			/* %y */
+  16 * 8,			/* %fprs */
+  -1,
+  1 * 8,			/* %g1 */
+  -1,				/* %l0 */
+  8				/* sizeof (%y) */
+};
 
 
+/* Size of `struct reg' and `struct fpreg'.  */
+static const int sparc64fbsd_sizeof_struct_reg = 256;
+static const int sparc64fbsd_sizeof_struct_fpreg = 272;
+
 static void
 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
                       CORE_ADDR ignore)
@@ -192,14 +58,15 @@ fetch_core_registers (char *core_reg_sec
       if (core_reg_size != sparc64fbsd_sizeof_struct_reg)
 	warning ("Wrong size register set in core file.");
       else
-	sparc64fbsd_supply_reg (core_reg_sect, -1);
+	sparc64_supply_gregset (&sparc64fbsd_gregset, current_regcache,
+				-1, core_reg_sect);
       break;
 
     case 2:  /* Floating pointer registers */
       if (core_reg_size != sparc64fbsd_sizeof_struct_fpreg)
 	warning ("Wrong size FP register set in core file.");
       else
-	sparc64fbsd_supply_fpreg (core_reg_sect, -1);
+	sparc64_supply_fpregset (current_regcache, -1, core_reg_sect);
       break;
 
     default:
Index: config/sparc/fbsd.mh
===================================================================
RCS file: /cvs/src/src/gdb/config/sparc/fbsd.mh,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 fbsd.mh
--- config/sparc/fbsd.mh 18 Oct 2003 18:25:46 -0000 1.3.4.1
+++ config/sparc/fbsd.mh 26 Dec 2003 21:11:04 -0000
@@ -1,5 +1,5 @@
 # Host: FreeBSD/sparc64
-NATDEPFILES= sparc64fbsd-nat.o sparcbsd-nat.o \
+NATDEPFILES= sparc64fbsd-nat.o sparc64-nat.o sparc-nat.o \
 	fork-child.o infptrace.o inftarg.o \
 	solib.o solib-svr4.o solib-legacy.o
 NAT_FILE= nm-fbsd.h



More information about the Gdb-patches mailing list