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]
Other format: [Raw text]

[PATCH/SPARC] Add NetBSD/sparc64 target & native support


This is completely untested, but I hope it does work.

Committed to the SPARC branch,

Mark


Index: ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>
 
	* sparc64-tdep.h (sparc64nbsd_gregset): Add extern declaration.
	* sparc64nbsd-nat.c: Rewrite.
	* sparc64nbsd-tdep.c: New file.
	* configure.tgt: Add sparc64-*-netbsd*.
	* configure.host: Add sparc64-*-netbsd*.
	* Makefile.in (ALLDEPFILES): Add sparc64nbsd-tdep.c and
	sparc64nbsd-nat.c.
	(sparc64nbsd-tdep.o, sparc64nbsd-nat.o): New dependencies.
	* config/sparc/nbsd64.mh (NATDEPFILES): Add sparc-nat.o.
	* config/sparc/nbsd64.mt (TDEPFILES): Add sparc64-tdep.o and
	sparc64nbsd-tdep.o.
	(TM_FILE): Set to tm-nbsd.h.
	* config/sparc/tm-nbsd64.h: Remove file.

Index: configure.host
===================================================================
RCS file: /cvs/src/src/gdb/configure.host,v
retrieving revision 1.57.4.6
diff -u -p -r1.57.4.6 configure.host
--- configure.host 15 Dec 2003 20:27:14 -0000 1.57.4.6
+++ configure.host 26 Dec 2003 23:41:14 -0000
@@ -136,6 +136,7 @@ sparc-*-netbsdaout*)	gdb_host_nbsdaout ;
 sparc-*-netbsd*)	gdb_host=nbsdaout ;;
 sparc64-*-freebsd*)	gdb_host=fbsd ;;
 sparc64-*-linux*)	gdb_host=linux64 ;;
+sparc64-*-netbsd*)	gdb_host=nbsd64 ;;
 sparc-*-solaris2* | sparcv9-*-solaris2* | sparc64-*-solaris2*)
 			gdb_host=sol2
 			;;
Index: configure.tgt
===================================================================
RCS file: /cvs/src/src/gdb/configure.tgt,v
retrieving revision 1.116.4.6
diff -u -p -r1.116.4.6 configure.tgt
--- configure.tgt 15 Dec 2003 20:00:31 -0000 1.116.4.6
+++ configure.tgt 26 Dec 2003 23:41:14 -0000
@@ -212,6 +212,7 @@ sparc-*-solaris2* | sparcv9-*-solaris2* 
 			;;
 sparc-*-*)		gdb_target=sparc ;;
 sparc64-*-linux*)	gdb_target=linux64 ;;
+sparc64-*-netbsd*)	gdb_target=nbsd64 ;;
 
 xstormy16-*-*)          gdb_target=xstormy16 ;;
 
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.445.2.11
diff -u -p -r1.445.2.11 Makefile.in
--- Makefile.in 26 Dec 2003 21:19:58 -0000 1.445.2.11
+++ Makefile.in 26 Dec 2003 23:41:15 -0000
@@ -2342,6 +2342,11 @@ sparc64fbsd-tdep.o: sparc64fbsd-tdep.c $
 	$(regcache_h) $(target_h) $(gdb_string_h) $(sparc64_tdep_h)
 sparc64fbsd-nat.o: sparc64fbsd-nat.c $(defs_h) $(sparc64_tdep_h) \
 	$(sparc_nat_h)
+sparc64nbsd-tdep.o: sparc64nbsd-tdep.c $(defs_h) $(gdbcore_h) $(osabi_h) \
+	$(regcache_h) $(solib_svr4_h) $(gdb_string_h) $(sparc64_tdep_h) \
+	$(nbsd_tdep_h)
+sparc64nbsd-nat.o: sparc64nbsd-nat.c $(defs_h) $(sparc64_tdep_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-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/sparc64-tdep.h,v
retrieving revision 1.2.6.3
diff -u -p -r1.2.6.3 sparc64-tdep.h
--- sparc64-tdep.h 26 Dec 2003 21:12:07 -0000 1.2.6.3
+++ sparc64-tdep.h 26 Dec 2003 23:41:15 -0000
@@ -99,4 +99,9 @@ extern void sparc64_sol2_init_abi (struc
 /* Register offsets for FreeBSD/sparc64.  */
 extern const struct sparc_gregset sparc64fbsd_gregset;
 
+/* Variables exported from sparc64nbsd-tdep.c.  */
+
+/* Register offsets for NetBSD/sparc64.  */
+extern const struct sparc_gregset sparc64nbsd_gregset;
+
 #endif /* sparc64-tdep.h */
Index: sparc64nbsd-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc64nbsd-nat.c,v
retrieving revision 1.2
diff -u -p -r1.2 sparc64nbsd-nat.c
--- sparc64nbsd-nat.c 7 Jul 2003 15:56:08 -0000 1.2
+++ sparc64nbsd-nat.c 26 Dec 2003 23:41:15 -0000
@@ -1,4 +1,5 @@
-/* Native-dependent code for UltraSPARC systems running NetBSD.
+/* Native-dependent code for NetBSD/sparc64.
+
    Copyright 2002, 2003 Free Software Foundation, Inc.
    Contributed by Wasabi Systems, Inc.
 
@@ -20,189 +21,73 @@
    Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
-#include "inferior.h"
-#include "regcache.h"
 
-#include "sparc-tdep.h"
-#include "sparcnbsd-tdep.h"
+#include "sparc64-tdep.h"
+#include "sparc-nat.h"
 
-#include <sys/types.h>
-#include <sys/ptrace.h>
-#include <machine/reg.h>
-
-/* NOTE: We don't bother with any of the deferred_store nonsense; it
-   makes things a lot more complicated than they need to be.  */
-
-/* Determine if PT_GETREGS fetches this register.  */
-static int
-getregs_supplies (int regno)
+/* NetBSD is different from the other OSes that support both SPARC and
+   UltraSPARC in that the result of ptrace(2) depends on whether the
+   traced process is 32-bit or 64-bit.  */
+
+static void
+sparc64nbsd_supply_gregset (const struct sparc_gregset *gregset,
+			    struct regcache *regcache,
+			    int regnum, const void *gregs)
 {
-  /* FIXME: PS_REGNUM for 32-bit code.  */
-  return (regno == TSTATE_REGNUM
-	  || regno == PC_REGNUM
-	  || regno == NPC_REGNUM
-	  || regno == Y_REGNUM
-	  || (regno >= G0_REGNUM && regno <= G7_REGNUM)
-	  || (regno >= O0_REGNUM && regno <= O7_REGNUM)
-	  /* stack regs (handled by sparcnbsd_supply_reg)  */
-	  || (regno >= L0_REGNUM && regno <= I7_REGNUM));
+  int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
+
+  if (sparc32)
+    sparc32_supply_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
+  else
+    sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
 }
 
-/* Determine if PT_GETFPREGS fetches this register.  */
-static int
-getfpregs_supplies (int regno)
+static void
+sparc64nbsd_collect_gregset (const struct sparc_gregset *gregset,
+			     const struct regcache *regcache,
+			     int regnum, void *gregs)
 {
-  return ((regno >= FP0_REGNUM && regno <= (FP0_REGNUM + 47))
-	  || regno == FPS_REGNUM);
+  int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
+
+  if (sparc32)
+    sparc32_collect_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
+  else
+    sparc64_collect_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
 }
 
-void
-fetch_inferior_registers (int regno)
+static void
+sparc64nbsd_supply_fpregset (struct regcache *regcache,
+			     int regnum, const void *fpregs)
+{
+  int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
+
+  if (sparc32)
+    sparc32_supply_fpregset (regcache, regnum, fpregs);
+  else
+    sparc64_supply_fpregset (regcache, regnum, fpregs);
+}
+
+static void
+sparc64nbsd_collect_fpregset (const struct regcache *regcache,
+			      int regnum, void *fpregs)
 {
-  /* We don't use deferred stores.  */
-  if (deferred_stores)
-    internal_error (__FILE__, __LINE__,
-		    "fetch_inferior_registers: deferred stores pending");
-
-  if (regno == -1 || getregs_supplies (regno))
-    {
-      union {
-	struct reg32 regs32;
-	struct reg64 regs64;
-      } regs;
-
-      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
-        perror_with_name ("Couldn't get registers");
-
-      if (gdbarch_ptr_bit (current_gdbarch) == 32)
-        sparcnbsd_supply_reg32 ((char *) &regs.regs32, regno);
-      else
-	sparcnbsd_supply_reg64 ((char *) &regs.regs64, regno);
-      if (regno != -1)
-	return;
-    }
-
-  if (regno == -1 || getfpregs_supplies (regno))
-    {
-      union {
-        struct fpreg32 fpregs32;
-	struct fpreg64 fpregs64;
-      } fpregs;
-
-      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-        perror_with_name ("Couldn't get floating point registers");
-
-      if (gdbarch_ptr_bit (current_gdbarch) == 32)
-        sparcnbsd_supply_fpreg32 ((char *) &fpregs.fpregs32, regno);
-      else
-        sparcnbsd_supply_fpreg64 ((char *) &fpregs.fpregs64, regno);
-      if (regno != -1)
-	return;
-    }
+  int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
+
+  if (sparc32)
+    sparc32_collect_fpregset (regcache, regnum, fpregs);
+  else
+    sparc64_collect_fpregset (regcache, regnum, fpregs);
 }
 
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+void _initialize_sparcnbsd_nat (void);
+
 void
-store_inferior_registers (int regno)
+_initialize_sparcnbsd_nat (void)
 {
-  /* We don't use deferred stores.  */
-  if (deferred_stores)
-    internal_error (__FILE__, __LINE__,
-		    "store_inferior_registers: deferred stores pending");
-
-  if (regno == -1 || getregs_supplies (regno))
-    {
-      union {
-	struct reg32 regs32;
-	struct reg64 regs64;
-      } regs;
-
-      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
-	perror_with_name ("Couldn't get registers");
-
-      if (gdbarch_ptr_bit (current_gdbarch) == 32)
-        sparcnbsd_fill_reg32 ((char *) &regs.regs32, regno);
-      else
-	sparcnbsd_fill_reg64 ((char *) &regs.regs64, regno);
-
-      if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &regs, 0) == -1)
-	perror_with_name ("Couldn't write registers");
-
-      /* Deal with the stack regs.  */
-      if (regno == -1 || regno == SP_REGNUM
-	  || (regno >= L0_REGNUM && regno <= I7_REGNUM))
-	{
-	  CORE_ADDR sp = read_register (SP_REGNUM);
-	  int i;
-	  char buf[8];
-
-	  if (sp & 1)
-	    {
-	      /* Registers are 64-bit.  */
-	      sp += 2047;
-
-	      for (i = L0_REGNUM; i <= I7_REGNUM; i++)
-		{
-		  if (regno == -1 || regno == SP_REGNUM || regno == i)
-		    {
-		      regcache_collect (i, buf);
-		      target_write_memory (sp + ((i - L0_REGNUM) * 8),
-					   buf, sizeof (buf));
-		    }
-		}
-            }
-	  else
-	    {
-	      /* Registers are 32-bit.  Toss any sign-extension of the stack
-		 pointer.
-
-		 FIXME: We don't currently handle 32-bit code in a binary
-		 that indicated LP64.  Do we have to care about that?  */
-              if (gdbarch_ptr_bit (current_gdbarch) != 32)
-		internal_error
-		    (__FILE__, __LINE__,
-		    "store_inferior_registers: 32-bit code in 64-bit inferior");
-
-	      sp &= 0xffffffffUL;
-	      for (i = L0_REGNUM; i <= I7_REGNUM; i++)
-	        {
-	          if (regno == -1 || regno == SP_REGNUM || regno == i)
-		    {
-		      regcache_collect (i, buf);
-		      target_write_memory (sp + ((i - L0_REGNUM) * 4), buf, 4);
-		    }
-		}
-	    }
-	}
-
-      if (regno != -1)
-	return;
-    }
-
-  if (regno == -1 || getfpregs_supplies (regno))
-    {
-      union {
-	struct fpreg32 fpregs32;
-	struct fpreg64 fpregs64;
-      } fpregs;
-
-      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-	perror_with_name ("Couldn't get floating point registers");
-
-      if (gdbarch_ptr_bit (current_gdbarch) == 32)
-        sparcnbsd_fill_fpreg32 ((char *) &fpregs.fpregs32, regno);
-      else
-	sparcnbsd_fill_fpreg64 ((char *) &fpregs.fpregs64, regno);
-      
-      if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
-		  (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-	perror_with_name ("Couldn't write floating point registers");
-
-      if (regno != -1)
-	return;
-    }
+  sparc_supply_gregset = sparc64nbsd_supply_gregset;
+  sparc_collect_gregset = sparc64nbsd_collect_gregset;
+  sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
+  sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
 }
Index: sparc64nbsd-tdep.c
===================================================================
RCS file: sparc64nbsd-tdep.c
diff -N sparc64nbsd-tdep.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sparc64nbsd-tdep.c 26 Dec 2003 23:41:15 -0000
@@ -0,0 +1,109 @@
+/* Target-dependent code for NetBSD/sparc64.
+
+   Copyright 2002, 2003 Free Software Foundation, Inc.
+   Contributed by Wasabi Systems, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include "defs.h"
+#include "gdbcore.h"
+#include "osabi.h"
+#include "regcache.h"
+#include "solib-svr4.h"
+
+#include "gdb_string.h"
+
+#include "sparc64-tdep.h"
+#include "nbsd-tdep.h"
+
+const struct sparc_gregset sparc64nbsd_gregset =
+{
+  0 * 8,			/* "tstate" */
+  1 * 8,			/* %pc */
+  2 * 8,			/* %npc */
+  3 * 8,			/* %y */
+  -1,				/* %fprs */
+  -1,
+  5 * 8,			/* %g1 */
+  -1,				/* %l0 */
+  4				/* sizeof (%y) */
+};
+
+/* Size of `struct reg' and `struct fpreg'.  */
+static const int sparc64nbsd_sizeof_struct_reg = 160;
+static const int sparc64nbsd_sizeof_struct_fpreg = 272;
+
+static void
+fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
+                      CORE_ADDR ignore)
+{
+  switch (which)
+    {
+    case 0:  /* Integer registers */
+      if (core_reg_size != sparc64nbsd_sizeof_struct_reg)
+	warning ("Wrong size register set in core file.");
+      else
+	sparc64_supply_gregset (&sparc64nbsd_gregset, current_regcache,
+				-1, core_reg_sect);
+      break;
+
+    case 2:  /* Floating pointer registers */
+      if (core_reg_size != sparc64nbsd_sizeof_struct_fpreg)
+	warning ("Wrong size FP register set in core file.");
+      else
+	sparc64_supply_fpregset (current_regcache, -1, core_reg_sect);
+      break;
+
+    default:
+      /* Don't know what kind of register request this is; just ignore it.  */
+      break;
+    }
+}
+
+static struct core_fns sparc64nbsd_core_fns =
+{
+  bfd_target_elf_flavour,		/* core_flavour */
+  default_check_format,			/* check_format */
+  default_core_sniffer,			/* core_sniffer */
+  fetch_core_registers,			/* core_read_registers */
+  NULL
+};
+
+static void
+sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  sparc64_init_abi (info, gdbarch);
+
+  set_gdbarch_pc_in_sigtramp (gdbarch, nbsd_pc_in_sigtramp);
+
+  set_solib_svr4_fetch_link_map_offsets
+    (gdbarch, nbsd_lp64_solib_svr4_fetch_link_map_offsets);
+}
+
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+void _initialize_sparc64nbsd_tdep (void);
+
+void
+_initialize_sparc64nbsd_tdep (void)
+{
+  gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
+			  GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi);
+
+  add_core_fns (&sparc64nbsd_core_fns);
+}
Index: config/sparc/nbsd64.mh
===================================================================
RCS file: /cvs/src/src/gdb/config/sparc/nbsd64.mh,v
retrieving revision 1.1
diff -u -p -r1.1 nbsd64.mh
--- config/sparc/nbsd64.mh 31 May 2002 00:59:15 -0000 1.1
+++ config/sparc/nbsd64.mh 26 Dec 2003 23:41:15 -0000
@@ -1,3 +1,4 @@
-# Host: UltraSPARC running NetBSD
-NATDEPFILES= fork-child.o infptrace.o inftarg.o sparc64nbsd-nat.o
+# Host: NetBSD/sparc64
+NATDEPFILES= sparc-nat.o sparc64nbsd-nat.o \
+	fork-child.o infptrace.o inftarg.o
 NAT_FILE= nm-nbsd.h
Index: config/sparc/nbsd64.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/sparc/nbsd64.mt,v
retrieving revision 1.1
diff -u -p -r1.1 nbsd64.mt
--- config/sparc/nbsd64.mt 31 May 2002 00:59:15 -0000 1.1
+++ config/sparc/nbsd64.mt 26 Dec 2003 23:41:15 -0000
@@ -1,4 +1,5 @@
-# Target: UltraSPARC running NetBSD
-TDEPFILES= sparc-tdep.o sparcnbsd-tdep.o nbsd-tdep.o corelow.o solib.o \
-	solib-svr4.o
-TM_FILE= tm-nbsd64.h
+# Target: NetBSD/sparc64
+TDEPFILES= sparc64-tdep.o sparc64nbsd-tdep.o \
+	sparc-tdep.o sparcnbsd-tdep.o nbsd-tdep.o \
+	corelow.o solib.o solib-svr4.o
+TM_FILE= tm-nbsd.h
Index: config/sparc/tm-nbsd64.h
===================================================================
RCS file: config/sparc/tm-nbsd64.h
diff -N config/sparc/tm-nbsd64.h
--- config/sparc/tm-nbsd64.h 31 May 2002 00:59:15 -0000 1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@
-/* Macro definitions for UltraSPARC running under NetBSD.
-   Copyright 1994, 2002 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-#ifndef TM_NBSD64_H
-#define TM_NBSD64_H
-
-#include "sparc/tm-sp64.h" /* sets GDB_MULTI_ARCH */
-#include "solib.h"
-
-#endif /* TM_NBSD64_H */


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