* gdb.texinfo (Target Description Format): Add version attribute
[deliverable/binutils-gdb.git] / gdb / hppa-linux-nat.c
index caea9aad7abd71cd627b1e171db92390540e8a20..6897e9f24c46cab8e916669c01803ebe7f1cb220 100644 (file)
@@ -1,5 +1,6 @@
-/* Functions specific to running gdb native on HPPA running Linux.
-   Copyright 2004 Free Software Foundation, Inc.
+/* Functions specific to running GDB native on HPPA running GNU/Linux.
+
+   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
    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.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 #include "defs.h"
 #include "gdbcore.h"
 #include "regcache.h"
 #include "gdb_string.h"
+#include "inferior.h"
+#include "target.h"
+#include "linux-nat.h"
 
 #include <sys/procfs.h>
-#include <string.h>
+#include <sys/ptrace.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,43)
+#include <asm/offset.h>
+#else
 #include <asm/offsets.h>
+#endif
 
 #include "hppa-tdep.h"
 
@@ -143,13 +153,13 @@ static const int u_offsets[] =
     PT_FR31, PT_FR31 + 4,
   };
 
-CORE_ADDR
-register_addr (int regno, CORE_ADDR blockend)
+static CORE_ADDR
+hppa_linux_register_addr (int regno, CORE_ADDR blockend)
 {
   CORE_ADDR addr;
 
-  if ((unsigned) regno >= NUM_REGS)
-    error ("Invalid register number %d.", regno);
+  if ((unsigned) regno >= gdbarch_num_regs (current_gdbarch))
+    error (_("Invalid register number %d."), regno);
 
   if (u_offsets[regno] == -1)
     addr = 0;
@@ -201,37 +211,131 @@ static const int greg_map[] =
     HPPA_CCR_REGNUM, HPPA_EIEM_REGNUM,
   };
 
+
+
+/* Fetch one register.  */
+
+static void
+fetch_register (struct regcache *regcache, int regno)
+{
+  int tid;
+  int val;
+
+  if (gdbarch_cannot_fetch_register (current_gdbarch, regno))
+    {
+      regcache_raw_supply (regcache, regno, NULL);
+      return;
+    }
+
+  /* GNU/Linux LWP ID's are process ID's.  */
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
+    tid = PIDGET (inferior_ptid); /* Not a threaded program.  */
+
+  errno = 0;
+  val = ptrace (PTRACE_PEEKUSER, tid, hppa_linux_register_addr (regno, 0), 0);
+  if (errno != 0)
+    error (_("Couldn't read register %s (#%d): %s."), 
+          gdbarch_register_name (current_gdbarch, regno),
+          regno, safe_strerror (errno));
+
+  regcache_raw_supply (regcache, regno, &val);
+}
+
+/* Store one register. */
+
+static void
+store_register (const struct regcache *regcache, int regno)
+{
+  int tid;
+  int val;
+
+  if (gdbarch_cannot_store_register (current_gdbarch, regno))
+    return;
+
+  /* GNU/Linux LWP ID's are process ID's.  */
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
+    tid = PIDGET (inferior_ptid); /* Not a threaded program.  */
+
+  errno = 0;
+  regcache_raw_collect (regcache, regno, &val);
+  ptrace (PTRACE_POKEUSER, tid, hppa_linux_register_addr (regno, 0), val);
+  if (errno != 0)
+    error (_("Couldn't write register %s (#%d): %s."),
+          gdbarch_register_name (current_gdbarch, regno),
+          regno, safe_strerror (errno));
+}
+
+/* Fetch registers from the child process.  Fetch all registers if
+   regno == -1, otherwise fetch all general registers or all floating
+   point registers depending upon the value of regno.  */
+
+static void
+hppa_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
+{
+  if (-1 == regno)
+    {
+      for (regno = 0; regno < gdbarch_num_regs (current_gdbarch); regno++)
+        fetch_register (regcache, regno);
+    }
+  else 
+    {
+      fetch_register (regcache, regno);
+    }
+}
+
+/* Store registers back into the inferior.  Store all registers if
+   regno == -1, otherwise store all general registers or all floating
+   point registers depending upon the value of regno.  */
+
+static void
+hppa_linux_store_inferior_registers (struct regcache *regcache, int regno)
+{
+  if (-1 == regno)
+    {
+      for (regno = 0; regno < gdbarch_num_regs (current_gdbarch); regno++)
+       store_register (regcache, regno);
+    }
+  else
+    {
+      store_register (regcache, regno);
+    }
+}
+
+/* Fill GDB's register array with the general-purpose register values
+   in *gregsetp.  */
+
 void
-supply_gregset (gdb_gregset_t *gregsetp)
+supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
 {
   int i;
-  greg_t *regp = (elf_greg_t *) gregsetp;
+  const greg_t *regp = (const elf_greg_t *) gregsetp;
 
   for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++, regp++)
     {
       int regno = greg_map[i];
-      int size = register_size (current_gdbarch, regno);
-      /* When running a 64 bit kernel, a greg_t may be larger than the
-        actual register, so just pick off the LS bits of big-endian word.  */
-      supply_register (regno, ((char *) (regp + 1)) - size);
+      regcache_raw_supply (regcache, regno, regp);
     }
 }
 
+/* Fill register regno (if it is a general-purpose register) in
+   *gregsetp with the appropriate value from GDB's register array.
+   If regno is -1, do this for all registers.  */
+
 void
-fill_gregset (gdb_gregset_t *gregsetp, int regno)
+fill_gregset (const struct regcache *regcache,
+             gdb_gregset_t *gregsetp, int regno)
 {
   int i;
-  greg_t *regp = (greg_t *) gregsetp;
 
-  memset (gregsetp, 0, sizeof (*gregsetp));
-  for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++, regp++)
+  for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++)
     {
-      int regi = greg_map[i];
+      int mregno = greg_map[i];
 
-      if (regno == -1 || regi == regno)
+      if (regno == -1 || regno == mregno)
        {
-         int rawsize = register_size (current_gdbarch, regi);
-         regcache_collect (regi, ((char *) (regp + 1)) - rawsize);
+          regcache_raw_collect(regcache, mregno, &(*gregsetp)[i]);
        }
     }
 }
@@ -241,16 +345,16 @@ fill_gregset (gdb_gregset_t *gregsetp, int regno)
    idea of the current floating point register values. */
 
 void
-supply_fpregset (gdb_fpregset_t *fpregsetp)
+supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
 {
-  register int regi;
-  char *from;
+  int regi;
+  const char *from;
 
   for (regi = 0; regi <= 31; regi++)
     {
-      from = (char *) &((*fpregsetp)[regi]);
-      supply_register (2*regi + HPPA_FP0_REGNUM, from);
-      supply_register (2*regi + HPPA_FP0_REGNUM + 1, from + 4);
+      from = (const char *) &((*fpregsetp)[regi]);
+      regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM, from);
+      regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM + 1, from + 4);
     }
 }
 
@@ -260,20 +364,36 @@ supply_fpregset (gdb_fpregset_t *fpregsetp)
    them all. */
 
 void
-fill_fpregset (gdb_fpregset_t *fpregsetp, int regno)
+fill_fpregset (const struct regcache *regcache,
+              gdb_fpregset_t *fpregsetp, int regno)
 {
   int i;
 
-  for (i = 0; i < NUM_REGS; i++)
+  for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32 * 2; i++)
    {
-    if (regno == -1 || regno == i)
-      {
-        /* Gross.  fpregset_t is double, registers[x] has single
-          precision reg.  */
-        char *to = (char *) &((*fpregsetp)[(i - HPPA_FP0_REGNUM) / 2]);
-        if ((i - HPPA_FP0_REGNUM) & 1)
-         to += 4;
-        regcache_collect (i, to);
-      }
+      /* Gross.  fpregset_t is double, registers[x] has single
+        precision reg.  */
+      char *to = (char *) &((*fpregsetp)[(i - HPPA_FP0_REGNUM) / 2]);
+      if ((i - HPPA_FP0_REGNUM) & 1)
+       to += 4;
+      regcache_raw_collect (regcache, i, to);
    }
 }
+
+void _initialize_hppa_linux_nat (void);
+
+void
+_initialize_hppa_linux_nat (void)
+{
+  struct target_ops *t;
+
+  /* Fill in the generic GNU/Linux methods.  */
+  t = linux_target ();
+
+  /* Add our register access methods.  */
+  t->to_fetch_registers = hppa_linux_fetch_inferior_registers;
+  t->to_store_registers = hppa_linux_store_inferior_registers;
+
+  /* Register the target.  */
+  linux_nat_add_target (t);
+}
This page took 0.026957 seconds and 4 git commands to generate.