daily update
[deliverable/binutils-gdb.git] / gdb / mips-linux-nat.c
index ca7c03d4ff61e32d180f1fef1c2dc268d0b3b4ff..b9f7f1dc638fb8c57329d21e7927053312cf660c 100644 (file)
@@ -1,7 +1,6 @@
 /* Native-dependent code for GNU/Linux on MIPS processors.
 
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 2001-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -37,7 +36,9 @@
 #include <sys/ptrace.h>
 
 #include "features/mips-linux.c"
+#include "features/mips-dsp-linux.c"
 #include "features/mips64-linux.c"
+#include "features/mips64-dsp-linux.c"
 
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 25
@@ -95,6 +96,12 @@ mips_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
     regaddr = FPC_CSR;
   else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
     regaddr = store? (CORE_ADDR) -1 : FPC_EIR;
+  else if (mips_regnum (gdbarch)->dspacc != -1
+          && regno >= mips_regnum (gdbarch)->dspacc
+          && regno < mips_regnum (gdbarch)->dspacc + 6)
+    regaddr = DSP_BASE + (regno - mips_regnum (gdbarch)->dspacc);
+  else if (regno == mips_regnum (gdbarch)->dspctl)
+    regaddr = DSP_CONTROL;
   else if (mips_linux_restart_reg_p (gdbarch) && regno == MIPS_RESTART_REGNUM)
     regaddr = 0;
   else
@@ -130,6 +137,12 @@ mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
     regaddr = MIPS64_FPC_CSR;
   else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
     regaddr = store? (CORE_ADDR) -1 : MIPS64_FPC_EIR;
+  else if (mips_regnum (gdbarch)->dspacc != -1
+          && regno >= mips_regnum (gdbarch)->dspacc
+          && regno < mips_regnum (gdbarch)->dspacc + 6)
+    regaddr = DSP_BASE + (regno - mips_regnum (gdbarch)->dspacc);
+  else if (regno == mips_regnum (gdbarch)->dspctl)
+    regaddr = DSP_CONTROL;
   else if (mips_linux_restart_reg_p (gdbarch) && regno == MIPS_RESTART_REGNUM)
     regaddr = 0;
   else
@@ -182,7 +195,8 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
   if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
     mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *) fpregsetp);
   else
-    mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *) fpregsetp);
+    mips64_supply_fpregset (regcache,
+                           (const mips64_elf_fpregset_t *) fpregsetp);
 }
 
 void
@@ -192,7 +206,8 @@ fill_fpregset (const struct regcache *regcache,
   if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
     mips_fill_fpregset (regcache, (mips_elf_fpregset_t *) fpregsetp, regno);
   else
-    mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *) fpregsetp, regno);
+    mips64_fill_fpregset (regcache,
+                         (mips64_elf_fpregset_t *) fpregsetp, regno);
 }
 
 
@@ -200,10 +215,13 @@ fill_fpregset (const struct regcache *regcache,
    using PTRACE_GETREGS et al.  */
 
 static void
-mips64_linux_regsets_fetch_registers (struct regcache *regcache, int regno)
+mips64_linux_regsets_fetch_registers (struct target_ops *ops,
+                                     struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  int is_fp;
+  int is_fp, is_dsp;
+  int have_dsp;
+  int regi;
   int tid;
 
   if (regno >= mips_regnum (gdbarch)->fp0
@@ -216,11 +234,23 @@ mips64_linux_regsets_fetch_registers (struct regcache *regcache, int regno)
   else
     is_fp = 0;
 
+  /* DSP registers are optional and not a part of any set.  */
+  have_dsp = mips_regnum (gdbarch)->dspctl != -1;
+  if (!have_dsp)
+    is_dsp = 0;
+  else if (regno >= mips_regnum (gdbarch)->dspacc
+      && regno < mips_regnum (gdbarch)->dspacc + 6)
+    is_dsp = 1;
+  else if (regno == mips_regnum (gdbarch)->dspctl)
+    is_dsp = 1;
+  else
+    is_dsp = 0;
+
   tid = ptid_get_lwp (inferior_ptid);
   if (tid == 0)
     tid = ptid_get_pid (inferior_ptid);
 
-  if (regno == -1 || !is_fp)
+  if (regno == -1 || (!is_fp && !is_dsp))
     {
       mips64_elf_gregset_t regs;
 
@@ -256,16 +286,30 @@ mips64_linux_regsets_fetch_registers (struct regcache *regcache, int regno)
       mips64_supply_fpregset (regcache,
                              (const mips64_elf_fpregset_t *) &fp_regs);
     }
+
+  if (is_dsp)
+    super_fetch_registers (ops, regcache, regno);
+  else if (regno == -1 && have_dsp)
+    {
+      for (regi = mips_regnum (gdbarch)->dspacc;
+          regi < mips_regnum (gdbarch)->dspacc + 6;
+          regi++)
+       super_fetch_registers (ops, regcache, regi);
+      super_fetch_registers (ops, regcache, mips_regnum (gdbarch)->dspctl);
+    }
 }
 
 /* Store REGNO (or all registers if REGNO == -1) to the target
    using PTRACE_SETREGS et al.  */
 
 static void
-mips64_linux_regsets_store_registers (const struct regcache *regcache, int regno)
+mips64_linux_regsets_store_registers (struct target_ops *ops,
+                                     struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
-  int is_fp;
+  int is_fp, is_dsp;
+  int have_dsp;
+  int regi;
   int tid;
 
   if (regno >= mips_regnum (gdbarch)->fp0
@@ -278,11 +322,23 @@ mips64_linux_regsets_store_registers (const struct regcache *regcache, int regno
   else
     is_fp = 0;
 
+  /* DSP registers are optional and not a part of any set.  */
+  have_dsp = mips_regnum (gdbarch)->dspctl != -1;
+  if (!have_dsp)
+    is_dsp = 0;
+  if (regno >= mips_regnum (gdbarch)->dspacc
+      && regno < mips_regnum (gdbarch)->dspacc + 6)
+    is_dsp = 1;
+  else if (regno == mips_regnum (gdbarch)->dspctl)
+    is_dsp = 1;
+  else
+    is_dsp = 0;
+
   tid = ptid_get_lwp (inferior_ptid);
   if (tid == 0)
     tid = ptid_get_pid (inferior_ptid);
 
-  if (regno == -1 || !is_fp)
+  if (regno == -1 || (!is_fp && !is_dsp))
     {
       mips64_elf_gregset_t regs;
 
@@ -309,6 +365,17 @@ mips64_linux_regsets_store_registers (const struct regcache *regcache, int regno
                  (PTRACE_TYPE_ARG3) &fp_regs) == -1)
        perror_with_name (_("Couldn't set FP registers"));
     }
+
+  if (is_dsp)
+    super_store_registers (ops, regcache, regno);
+  else if (regno == -1 && have_dsp)
+    {
+      for (regi = mips_regnum (gdbarch)->dspacc;
+          regi < mips_regnum (gdbarch)->dspacc + 6;
+          regi++)
+       super_store_registers (ops, regcache, regi);
+      super_store_registers (ops, regcache, mips_regnum (gdbarch)->dspctl);
+    }
 }
 
 /* Fetch REGNO (or all registers if REGNO == -1) from the target
@@ -320,7 +387,7 @@ mips64_linux_fetch_registers (struct target_ops *ops,
 {
   /* Unless we already know that PTRACE_GETREGS does not work, try it.  */
   if (have_ptrace_regsets)
-    mips64_linux_regsets_fetch_registers (regcache, regnum);
+    mips64_linux_regsets_fetch_registers (ops, regcache, regnum);
 
   /* If we know, or just found out, that PTRACE_GETREGS does not work, fall
      back to PTRACE_PEEKUSER.  */
@@ -337,7 +404,7 @@ mips64_linux_store_registers (struct target_ops *ops,
 {
   /* Unless we already know that PTRACE_GETREGS does not work, try it.  */
   if (have_ptrace_regsets)
-    mips64_linux_regsets_store_registers (regcache, regnum);
+    mips64_linux_regsets_store_registers (ops, regcache, regnum);
 
   /* If we know, or just found out, that PTRACE_GETREGS does not work, fall
      back to PTRACE_PEEKUSER.  */
@@ -360,12 +427,37 @@ mips_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
 static const struct target_desc *
 mips_linux_read_description (struct target_ops *ops)
 {
+  static int have_dsp = -1;
+
+  if (have_dsp < 0)
+    {
+      int tid;
+
+      tid = ptid_get_lwp (inferior_ptid);
+      if (tid == 0)
+       tid = ptid_get_pid (inferior_ptid);
+
+      ptrace (PTRACE_PEEKUSER, tid, DSP_CONTROL, 0);
+      switch (errno)
+       {
+       case 0:
+         have_dsp = 1;
+         break;
+       case EIO:
+         have_dsp = 0;
+         break;
+       default:
+         perror_with_name (_("Couldn't check DSP support"));
+         break;
+       }
+    }
+
   /* Report that target registers are a size we know for sure
      that we can get from ptrace.  */
   if (_MIPS_SIM == _ABIO32)
-    return tdesc_mips_linux;
+    return have_dsp ? tdesc_mips_dsp_linux : tdesc_mips_linux;
   else
-    return tdesc_mips64_linux;
+    return have_dsp ? tdesc_mips64_dsp_linux : tdesc_mips64_linux;
 }
 
 #ifndef PTRACE_GET_WATCH_REGS
@@ -393,12 +485,12 @@ enum pt_watch_style {
 
 #define MAX_DEBUG_REGISTER 8
 
-/* A value of zero in a watchlo indicates that it is available. */
+/* A value of zero in a watchlo indicates that it is available.  */
 
 struct mips32_watch_regs
 {
   uint32_t watchlo[MAX_DEBUG_REGISTER];
-  /* Lower 16 bits of watchhi. */
+  /* Lower 16 bits of watchhi.  */
   uint16_t watchhi[MAX_DEBUG_REGISTER];
   /* Valid mask and I R W bits.
    * bit 0 -- 1 if W bit is usable.
@@ -595,7 +687,8 @@ mips_show_dr (const char *func, CORE_ADDR addr,
 
   puts_unfiltered (func);
   if (addr || len)
-    printf_unfiltered (" (addr=0x%s, len=%d, type=%s)", paddr (addr), len,
+    printf_unfiltered (" (addr=%s, len=%d, type=%s)",
+                      paddress (target_gdbarch, addr), len,
                       type == hw_write ? "data-write"
                       : (type == hw_read ? "data-read"
                          : (type == hw_access ? "data-read/write"
@@ -604,9 +697,11 @@ mips_show_dr (const char *func, CORE_ADDR addr,
   puts_unfiltered (":\n");
 
   for (i = 0; i < MAX_DEBUG_REGISTER; i++)
-    printf_unfiltered ("\tDR%d: lo=0x%s, hi=0x%s\n",
-                      i, paddr (get_watchlo (&watch_mirror, i)),
-                      paddr (get_watchhi (&watch_mirror, i)));
+    printf_unfiltered ("\tDR%d: lo=%s, hi=%s\n", i,
+                      paddress (target_gdbarch,
+                                get_watchlo (&watch_mirror, i)),
+                      paddress (target_gdbarch,
+                                get_watchhi (&watch_mirror, i)));
 }
 
 /* Return 1 if watch registers are usable.  Cached information is used
@@ -707,7 +802,7 @@ mips_linux_can_use_hw_breakpoint (int type, int cnt, int ot)
 
 /* Target to_stopped_by_watchpoint implementation.  Return 1 if
    stopped by watchpoint.  The watchhi R and W bits indicate the watch
-   register triggered. */
+   register triggered.  */
 
 static int
 mips_linux_stopped_by_watchpoint (void)
@@ -865,12 +960,11 @@ static int
 write_watchpoint_regs (void)
 {
   struct lwp_info *lp;
-  ptid_t ptid;
   int tid;
 
-  ALL_LWPS (lp, ptid)
+  ALL_LWPS (lp)
     {
-      tid = ptid_get_lwp (ptid);
+      tid = ptid_get_lwp (lp->ptid);
       if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1)
        perror_with_name (_("Couldn't write debug register"));
     }
@@ -881,14 +975,14 @@ write_watchpoint_regs (void)
  register values for the new thread.  */
 
 static void
-mips_linux_new_thread (ptid_t ptid)
+mips_linux_new_thread (struct lwp_info *lp)
 {
   int tid;
 
   if (!mips_linux_read_watch_registers (0))
     return;
 
-  tid = ptid_get_lwp (ptid);
+  tid = ptid_get_lwp (lp->ptid);
   if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1)
     perror_with_name (_("Couldn't write debug register"));
 }
@@ -923,7 +1017,8 @@ populate_regs_from_watches (struct pt_watch_regs *regs)
    watch.  Return zero on success.  */
 
 static int
-mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type)
+mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
+                             struct expression *cond)
 {
   struct pt_watch_regs regs;
   struct mips_watchpoint *new_watch;
@@ -972,7 +1067,8 @@ mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type)
    Return zero on success.  */
 
 static int
-mips_linux_remove_watchpoint (CORE_ADDR addr, int len, int type)
+mips_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
+                             struct expression *cond)
 {
   int retval;
   int deleted_one;
@@ -1082,5 +1178,7 @@ triggers a breakpoint or watchpoint."),
 
   /* Initialize the standard target descriptions.  */
   initialize_tdesc_mips_linux ();
+  initialize_tdesc_mips_dsp_linux ();
   initialize_tdesc_mips64_linux ();
+  initialize_tdesc_mips64_dsp_linux ();
 }
This page took 0.028565 seconds and 4 git commands to generate.