bfd/
[deliverable/binutils-gdb.git] / gdb / m68klinux-nat.c
index 82a6124a7aab643be2fcc828272ef86461e4e288..0da875e4c168639e85df370a36013d25f62e2f94 100644 (file)
@@ -1,7 +1,7 @@
 /* Motorola m68k native support for GNU/Linux.
 
-   Copyright 1996, 1998, 2000, 2001, 2002 Free Software Foundation,
-   Inc.
+   Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   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 "frame.h"
 #include "inferior.h"
 #include "language.h"
 #include "gdbcore.h"
+#include "gdb_string.h"
 #include "regcache.h"
+#include "target.h"
+#include "linux-nat.h"
 
-#ifdef USG
-#include <sys/types.h>
-#endif
+#include "m68k-tdep.h"
 
 #include <sys/param.h>
 #include <sys/dir.h>
@@ -51,8 +52,7 @@
 
 #include "target.h"
 \f
-
-/* This table must line up with REGISTER_NAMES in tm-m68k.h */
+/* This table must line up with REGISTER_NAME in "m68k-tdep.c".  */
 static const int regmap[] =
 {
   PT_D0, PT_D1, PT_D2, PT_D3, PT_D4, PT_D5, PT_D6, PT_D7,
@@ -78,7 +78,7 @@ getregs_supplies (int regno)
 int
 getfpregs_supplies (int regno)
 {
-  return FP0_REGNUM <= regno && regno <= FPI_REGNUM;
+  return FP0_REGNUM <= regno && regno <= M68K_FPI_REGNUM;
 }
 
 /* Does the current host support the GETREGS request?  */
@@ -131,30 +131,32 @@ fetch_register (int regno)
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr;
   char mess[128];              /* For messages */
-  register int i;
+  int i;
   unsigned int offset;         /* Offset of registers within the u area.  */
-  char buf[MAX_REGISTER_RAW_SIZE];
+  char buf[MAX_REGISTER_SIZE];
   int tid;
 
   if (CANNOT_FETCH_REGISTER (regno))
     {
-      memset (buf, '\0', REGISTER_RAW_SIZE (regno));   /* Supply zeroes */
-      supply_register (regno, buf);
+      memset (buf, '\0', register_size (current_gdbarch, regno));      /* Supply zeroes */
+      regcache_raw_supply (current_regcache, regno, buf);
       return;
     }
 
   /* Overload thread id onto process id */
-  if ((tid = TIDGET (inferior_ptid)) == 0)
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
     tid = PIDGET (inferior_ptid);      /* no thread id, just use process id */
 
   offset = U_REGS_OFFSET;
 
   regaddr = register_addr (regno, offset);
-  for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+  for (i = 0; i < register_size (current_gdbarch, regno);
+       i += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
-      *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid,
-                                              (PTRACE_ARG3_TYPE) regaddr, 0);
+      *(PTRACE_XFER_TYPE *) &buf[i] = ptrace (PT_READ_U, tid,
+                                             (PTRACE_ARG3_TYPE) regaddr, 0);
       regaddr += sizeof (PTRACE_XFER_TYPE);
       if (errno != 0)
        {
@@ -163,14 +165,14 @@ fetch_register (int regno)
          perror_with_name (mess);
        }
     }
-  supply_register (regno, buf);
+  regcache_raw_supply (current_regcache, regno, buf);
 }
 
 /* Fetch register values from the inferior.
    If REGNO is negative, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time). */
 
-void
+static void
 old_fetch_inferior_registers (int regno)
 {
   if (regno >= 0)
@@ -194,10 +196,10 @@ store_register (int regno)
   /* This isn't really an address.  But ptrace thinks of it as one.  */
   CORE_ADDR regaddr;
   char mess[128];              /* For messages */
-  register int i;
+  int i;
   unsigned int offset;         /* Offset of registers within the u area.  */
   int tid;
-  char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+  char buf[MAX_REGISTER_SIZE];
 
   if (CANNOT_STORE_REGISTER (regno))
     {
@@ -205,7 +207,8 @@ store_register (int regno)
     }
 
   /* Overload thread id onto process id */
-  if ((tid = TIDGET (inferior_ptid)) == 0)
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
     tid = PIDGET (inferior_ptid);      /* no thread id, just use process id */
 
   offset = U_REGS_OFFSET;
@@ -213,10 +216,11 @@ store_register (int regno)
   regaddr = register_addr (regno, offset);
 
   /* Put the contents of regno into a local buffer */
-  regcache_collect (regno, buf);
+  regcache_raw_collect (current_regcache, regno, buf);
 
   /* Store the local buffer into the inferior a chunk at the time. */
-  for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+  for (i = 0; i < register_size (current_gdbarch, regno);
+       i += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
       ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
@@ -235,7 +239,7 @@ store_register (int regno)
    If REGNO is negative, do this for all registers.
    Otherwise, REGNO specifies which register (so we can save time).  */
 
-void
+static void
 old_store_inferior_registers (int regno)
 {
   if (regno >= 0)
@@ -275,10 +279,10 @@ supply_gregset (elf_gregset_t *gregsetp)
   elf_greg_t *regp = (elf_greg_t *) gregsetp;
   int regi;
 
-  for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
-    supply_register (regi, (char *) &regp[regmap[regi]]);
-  supply_register (PS_REGNUM, (char *) &regp[PT_SR]);
-  supply_register (PC_REGNUM, (char *) &regp[PT_PC]);
+  for (regi = M68K_D0_REGNUM; regi <= SP_REGNUM; regi++)
+    regcache_raw_supply (current_regcache, regi, (char *) &regp[regmap[regi]]);
+  regcache_raw_supply (current_regcache, PS_REGNUM, (char *) &regp[PT_SR]);
+  regcache_raw_supply (current_regcache, PC_REGNUM, (char *) &regp[PT_PC]);
 }
 
 /* Fill register REGNO (if it is a general-purpose register) in
@@ -291,8 +295,8 @@ fill_gregset (elf_gregset_t *gregsetp, int regno)
   int i;
 
   for (i = 0; i < NUM_GREGS; i++)
-    if ((regno == -1 || regno == i))
-      regcache_collect (i, regp + regmap[i]);
+    if (regno == -1 || regno == i)
+      regcache_raw_collect (current_regcache, i, regp + regmap[i]);
 }
 
 #ifdef HAVE_PTRACE_GETREGS
@@ -315,7 +319,7 @@ fetch_regs (int tid)
          return;
        }
 
-      perror_with_name ("Couldn't get registers");
+      perror_with_name (_("Couldn't get registers"));
     }
 
   supply_gregset (&regs);
@@ -330,12 +334,12 @@ store_regs (int tid, int regno)
   elf_gregset_t regs;
 
   if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
-    perror_with_name ("Couldn't get registers");
+    perror_with_name (_("Couldn't get registers"));
 
   fill_gregset (&regs, regno);
 
   if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
-    perror_with_name ("Couldn't write registers");
+    perror_with_name (_("Couldn't write registers"));
 }
 
 #else
@@ -359,11 +363,15 @@ supply_fpregset (elf_fpregset_t *fpregsetp)
 {
   int regi;
 
-  for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
-    supply_register (regi, FPREG_ADDR (fpregsetp, regi - FP0_REGNUM));
-  supply_register (FPC_REGNUM, (char *) &fpregsetp->fpcntl[0]);
-  supply_register (FPS_REGNUM, (char *) &fpregsetp->fpcntl[1]);
-  supply_register (FPI_REGNUM, (char *) &fpregsetp->fpcntl[2]);
+  for (regi = FP0_REGNUM; regi < FP0_REGNUM + 8; regi++)
+    regcache_raw_supply (current_regcache, regi,
+                        FPREG_ADDR (fpregsetp, regi - FP0_REGNUM));
+  regcache_raw_supply (current_regcache, M68K_FPC_REGNUM,
+                      (char *) &fpregsetp->fpcntl[0]);
+  regcache_raw_supply (current_regcache, M68K_FPS_REGNUM,
+                      (char *) &fpregsetp->fpcntl[1]);
+  regcache_raw_supply (current_regcache, M68K_FPI_REGNUM,
+                      (char *) &fpregsetp->fpcntl[2]);
 }
 
 /* Fill register REGNO (if it is a floating-point register) in
@@ -378,12 +386,14 @@ fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
   /* Fill in the floating-point registers.  */
   for (i = FP0_REGNUM; i < FP0_REGNUM + 8; i++)
     if (regno == -1 || regno == i)
-      regcache_collect (regno, FPREG_ADDR (fpregsetp, regno - FP0_REGNUM));
+      regcache_raw_collect (current_regcache, i,
+                           FPREG_ADDR (fpregsetp, i - FP0_REGNUM));
 
   /* Fill in the floating-point control registers.  */
-  for (i = FPC_REGNUM; i <= FPI_REGNUM; i++)
+  for (i = M68K_FPC_REGNUM; i <= M68K_FPI_REGNUM; i++)
     if (regno == -1 || regno == i)
-      regcache_collect (regno, (char *) &fpregsetp->fpcntl[regno - FPC_REGNUM]);
+      regcache_raw_collect (current_regcache, i,
+                           (char *) &fpregsetp->fpcntl[i - M68K_FPC_REGNUM]);
 }
 
 #ifdef HAVE_PTRACE_GETREGS
@@ -397,7 +407,7 @@ fetch_fpregs (int tid)
   elf_fpregset_t fpregs;
 
   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
-    perror_with_name ("Couldn't get floating point status");
+    perror_with_name (_("Couldn't get floating point status"));
 
   supply_fpregset (&fpregs);
 }
@@ -411,12 +421,12 @@ store_fpregs (int tid, int regno)
   elf_fpregset_t fpregs;
 
   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
-    perror_with_name ("Couldn't get floating point status");
+    perror_with_name (_("Couldn't get floating point status"));
 
   fill_fpregset (&fpregs, regno);
 
   if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
-    perror_with_name ("Couldn't write floating point status");
+    perror_with_name (_("Couldn't write floating point status"));
 }
 
 #else
@@ -434,8 +444,8 @@ static void store_fpregs (int tid, int regno) {}
    this for all registers (including the floating point and SSE
    registers).  */
 
-void
-fetch_inferior_registers (int regno)
+static void
+m68k_linux_fetch_inferior_registers (int regno)
 {
   int tid;
 
@@ -448,7 +458,8 @@ fetch_inferior_registers (int regno)
     }
 
   /* GNU/Linux LWP ID's are process ID's.  */
-  if ((tid = TIDGET (inferior_ptid)) == 0)
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
     tid = PIDGET (inferior_ptid);              /* Not a threaded program.  */
 
   /* Use the PTRACE_GETFPXREGS request whenever possible, since it
@@ -483,14 +494,14 @@ fetch_inferior_registers (int regno)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "Got request for bad register number %d.", regno);
+                 _("Got request for bad register number %d."), regno);
 }
 
 /* Store register REGNO back into the child process.  If REGNO is -1,
    do this for all registers (including the floating point and SSE
    registers).  */
-void
-store_inferior_registers (int regno)
+static void
+m68k_linux_store_inferior_registers (int regno)
 {
   int tid;
 
@@ -503,7 +514,8 @@ store_inferior_registers (int regno)
     }
 
   /* GNU/Linux LWP ID's are process ID's.  */
-  if ((tid = TIDGET (inferior_ptid)) == 0)
+  tid = TIDGET (inferior_ptid);
+  if (tid == 0)
     tid = PIDGET (inferior_ptid);      /* Not a threaded program.  */
 
   /* Use the PTRACE_SETFPREGS requests whenever possible, since it
@@ -529,7 +541,7 @@ store_inferior_registers (int regno)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "Got request to store bad register number %d.", regno);
+                 _("Got request to store bad register number %d."), regno);
 }
 \f
 /* Interpreting register set info found in core files.  */
@@ -561,7 +573,7 @@ fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
     {
     case 0:
       if (core_reg_size != sizeof (gregset))
-       warning ("Wrong size gregset in core file.");
+       warning (_("Wrong size gregset in core file."));
       else
        {
          memcpy (&gregset, core_reg_sect, sizeof (gregset));
@@ -571,7 +583,7 @@ fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
 
     case 2:
       if (core_reg_size != sizeof (fpregset))
-       warning ("Wrong size fpregset in core file.");
+       warning (_("Wrong size fpregset in core file."));
       else
        {
          memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
@@ -594,103 +606,6 @@ kernel_u_size (void)
   return (sizeof (struct user));
 }
 \f
-/* Check whether insn1 and insn2 are parts of a signal trampoline.  */
-
-#define IS_SIGTRAMP(insn1, insn2)                                      \
-  (/* addaw #20,sp; moveq #119,d0; trap #0 */                          \
-   (insn1 == 0xdefc0014 && insn2 == 0x70774e40)                                \
-   /* moveq #119,d0; trap #0 */                                                \
-   || insn1 == 0x70774e40)
-
-#define IS_RT_SIGTRAMP(insn1, insn2)                                   \
-  (/* movel #173,d0; trap #0 */                                                \
-   (insn1 == 0x203c0000 && insn2 == 0x00ad4e40)                                \
-   /* moveq #82,d0; notb d0; trap #0 */                                        \
-   || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
-
-/* Return non-zero if PC points into the signal trampoline.  For the sake
-   of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
-   signal trampolines.  */
-
-int
-m68k_linux_in_sigtramp (CORE_ADDR pc)
-{
-  CORE_ADDR sp;
-  char buf[12];
-  unsigned long insn0, insn1, insn2;
-
-  if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
-    return 0;
-  insn1 = extract_unsigned_integer (buf + 4, 4);
-  insn2 = extract_unsigned_integer (buf + 8, 4);
-  if (IS_SIGTRAMP (insn1, insn2))
-    return 1;
-  if (IS_RT_SIGTRAMP (insn1, insn2))
-    return 2;
-
-  insn0 = extract_unsigned_integer (buf, 4);
-  if (IS_SIGTRAMP (insn0, insn1))
-    return 1;
-  if (IS_RT_SIGTRAMP (insn0, insn1))
-    return 2;
-
-  insn0 = (insn0 << 16) | (insn1 >> 16);
-  insn1 = (insn1 << 16) | (insn2 >> 16);
-  if (IS_SIGTRAMP (insn0, insn1))
-    return 1;
-  if (IS_RT_SIGTRAMP (insn0, insn1))
-    return 2;
-
-  return 0;
-}
-
-/* Offset to saved PC in sigcontext, from <asm/sigcontext.h>.  */
-#define SIGCONTEXT_PC_OFFSET 26
-
-/* Offset to saved PC in ucontext, from <asm/ucontext.h>.  */
-#define UCONTEXT_PC_OFFSET 88
-
-/* Get saved user PC for sigtramp from sigcontext or ucontext.  */
-
-static CORE_ADDR
-m68k_linux_sigtramp_saved_pc (struct frame_info *frame)
-{
-  CORE_ADDR sigcontext_addr;
-  char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
-  int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
-  int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
-
-  /* Get sigcontext address, it is the third parameter on the stack.  */
-  if (frame->next)
-    sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
-                                          + FRAME_ARGS_SKIP
-                                          + sigcontext_offs,
-                                          ptrbytes);
-  else
-    sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
-                                          + sigcontext_offs,
-                                          ptrbytes);
-
-  /* Don't cause a memory_error when accessing sigcontext in case the
-     stack layout has changed or the stack is corrupt.  */
-  if (m68k_linux_in_sigtramp (frame->pc) == 2)
-    target_read_memory (sigcontext_addr + UCONTEXT_PC_OFFSET, buf, ptrbytes);
-  else
-    target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
-  return extract_unsigned_integer (buf, ptrbytes);
-}
-
-/* Return the saved program counter for FRAME.  */
-
-CORE_ADDR
-m68k_linux_frame_saved_pc (struct frame_info *frame)
-{
-  if (frame->signal_handler_caller)
-    return m68k_linux_sigtramp_saved_pc (frame);
-
-  return read_memory_integer (frame->frame + 4, 4);
-}
-\f
 /* Register that we are able to handle GNU/Linux ELF core file
    formats.  */
 
@@ -703,8 +618,22 @@ static struct core_fns linux_elf_core_fns =
   NULL                                 /* next */
 };
 
+void _initialize_m68k_linux_nat (void);
+
 void
-_initialize_m68k_linux_nat ()
+_initialize_m68k_linux_nat (void)
 {
-  add_core_fns (&linux_elf_core_fns);
+  struct target_ops *t;
+
+  /* Fill in the generic GNU/Linux methods.  */
+  t = linux_target ();
+
+  /* Add our register access methods.  */
+  t->to_fetch_registers = m68k_linux_fetch_inferior_registers;
+  t->to_store_registers = m68k_linux_store_inferior_registers;
+
+  /* Register the target.  */
+  linux_nat_add_target (t);
+
+  deprecated_add_core_fns (&linux_elf_core_fns);
 }
This page took 0.030498 seconds and 4 git commands to generate.