gdb/gdbserver/linux-mips-low.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* GNU/Linux/MIPS specific low level interface, for the remote server for GDB.
  2.    Copyright (C) 1995-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "server.h"
  15. #include "linux-low.h"

  16. #include <sys/ptrace.h>
  17. #include <endian.h>

  18. #include "nat/mips-linux-watch.h"
  19. #include "gdb_proc_service.h"

  20. /* Defined in auto-generated file mips-linux.c.  */
  21. void init_registers_mips_linux (void);
  22. extern const struct target_desc *tdesc_mips_linux;

  23. /* Defined in auto-generated file mips-dsp-linux.c.  */
  24. void init_registers_mips_dsp_linux (void);
  25. extern const struct target_desc *tdesc_mips_dsp_linux;

  26. /* Defined in auto-generated file mips64-linux.c.  */
  27. void init_registers_mips64_linux (void);
  28. extern const struct target_desc *tdesc_mips64_linux;

  29. /* Defined in auto-generated file mips64-dsp-linux.c.  */
  30. void init_registers_mips64_dsp_linux (void);
  31. extern const struct target_desc *tdesc_mips64_dsp_linux;

  32. #ifdef __mips64
  33. #define tdesc_mips_linux tdesc_mips64_linux
  34. #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
  35. #endif

  36. #ifndef PTRACE_GET_THREAD_AREA
  37. #define PTRACE_GET_THREAD_AREA 25
  38. #endif

  39. #ifdef HAVE_SYS_REG_H
  40. #include <sys/reg.h>
  41. #endif

  42. #define mips_num_regs 73
  43. #define mips_dsp_num_regs 80

  44. #include <asm/ptrace.h>

  45. #ifndef DSP_BASE
  46. #define DSP_BASE 71
  47. #define DSP_CONTROL 77
  48. #endif

  49. union mips_register
  50. {
  51.   unsigned char buf[8];

  52.   /* Deliberately signed, for proper sign extension.  */
  53.   int reg32;
  54.   long long reg64;
  55. };

  56. /* Return the ptrace ``address'' of register REGNO. */

  57. #define mips_base_regs                                                        \
  58.   -11234567,                                        \
  59.   8910, 11, 12, 13, 14, 15,                                        \
  60.   16, 17, 18, 19, 20, 21, 22, 23,                                        \
  61.   24, 25, 26, 27, 28, 29, 30, 31,                                        \
  62.                                                                         \
  63.   -1, MMLO, MMHI, BADVADDR, CAUSE, PC,                                        \
  64.                                                                         \
  65.   FPR_BASE,      FPR_BASE + 1FPR_BASE + 2FPR_BASE + 3,                \
  66.   FPR_BASE + 4FPR_BASE + 5FPR_BASE + 6FPR_BASE + 7,                \
  67.   FPR_BASE + 8FPR_BASE + 9FPR_BASE + 10, FPR_BASE + 11,                \
  68.   FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15,                \
  69.   FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19,                \
  70.   FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23,                \
  71.   FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27,                \
  72.   FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31,                \
  73.   FPC_CSR, FPC_EIR

  74. #define mips_dsp_regs                                                        \
  75.   DSP_BASE,      DSP_BASE + 1DSP_BASE + 2DSP_BASE + 3,                \
  76.   DSP_BASE + 4DSP_BASE + 5,                                                \
  77.   DSP_CONTROL

  78. static int mips_regmap[mips_num_regs] = {
  79.   mips_base_regs,
  80.   0
  81. };

  82. static int mips_dsp_regmap[mips_dsp_num_regs] = {
  83.   mips_base_regs,
  84.   mips_dsp_regs,
  85.   0
  86. };

  87. /* DSP registers are not in any regset and can only be accessed
  88.    individually.  */

  89. static unsigned char mips_dsp_regset_bitmap[(mips_dsp_num_regs + 7) / 8] = {
  90.   0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
  91. };

  92. static int have_dsp = -1;

  93. /* Try peeking at an arbitrarily chosen DSP register and pick the available
  94.    user register set accordingly.  */

  95. static const struct target_desc *
  96. mips_read_description (void)
  97. {
  98.   if (have_dsp < 0)
  99.     {
  100.       int pid = lwpid_of (current_thread);

  101.       errno = 0;
  102.       ptrace (PTRACE_PEEKUSER, pid, DSP_CONTROL, 0);
  103.       switch (errno)
  104.         {
  105.         case 0:
  106.           have_dsp = 1;
  107.           break;
  108.         case EIO:
  109.           have_dsp = 0;
  110.           break;
  111.         default:
  112.           perror_with_name ("ptrace");
  113.           break;
  114.         }
  115.     }

  116.   return have_dsp ? tdesc_mips_dsp_linux : tdesc_mips_linux;
  117. }

  118. static void
  119. mips_arch_setup (void)
  120. {
  121.   current_process ()->tdesc = mips_read_description ();
  122. }

  123. static struct usrregs_info *
  124. get_usrregs_info (void)
  125. {
  126.   const struct regs_info *regs_info = the_low_target.regs_info ();

  127.   return regs_info->usrregs;
  128. }

  129. /* Per-process arch-specific data we want to keep.  */

  130. struct arch_process_info
  131. {
  132.   /* -1 if the kernel and/or CPU do not support watch registers.
  133.       1 if watch_readback is valid and we can read style, num_valid
  134.         and the masks.
  135.       0 if we need to read the watch_readback.  */

  136.   int watch_readback_valid;

  137.   /* Cached watch register read values.  */

  138.   struct pt_watch_regs watch_readback;

  139.   /* Current watchpoint requests for this process.  */

  140.   struct mips_watchpoint *current_watches;

  141.   /* The current set of watch register values for writing the
  142.      registers.  */

  143.   struct pt_watch_regs watch_mirror;
  144. };

  145. /* Per-thread arch-specific data we want to keep.  */

  146. struct arch_lwp_info
  147. {
  148.   /* Non-zero if our copy differs from what's recorded in the thread.  */
  149.   int watch_registers_changed;
  150. };

  151. /* From mips-linux-nat.c.  */

  152. /* Pseudo registers can not be readptrace does not provide a way to
  153.    read (or set) PS_REGNUM, and there's no point in reading or setting
  154.    ZERO_REGNUM.  We also can not set BADVADDR, CAUSE, or FCRIR via
  155.    ptrace().  */

  156. static int
  157. mips_cannot_fetch_register (int regno)
  158. {
  159.   const struct target_desc *tdesc;

  160.   if (get_usrregs_info ()->regmap[regno] == -1)
  161.     return 1;

  162.   tdesc = current_process ()->tdesc;

  163.   if (find_regno (tdesc, "r0") == regno)
  164.     return 1;

  165.   return 0;
  166. }

  167. static int
  168. mips_cannot_store_register (int regno)
  169. {
  170.   const struct target_desc *tdesc;

  171.   if (get_usrregs_info ()->regmap[regno] == -1)
  172.     return 1;

  173.   tdesc = current_process ()->tdesc;

  174.   if (find_regno (tdesc, "r0") == regno)
  175.     return 1;

  176.   if (find_regno (tdesc, "cause") == regno)
  177.     return 1;

  178.   if (find_regno (tdesc, "badvaddr") == regno)
  179.     return 1;

  180.   if (find_regno (tdesc, "fir") == regno)
  181.     return 1;

  182.   return 0;
  183. }

  184. static CORE_ADDR
  185. mips_get_pc (struct regcache *regcache)
  186. {
  187.   union mips_register pc;
  188.   collect_register_by_name (regcache, "pc", pc.buf);
  189.   return register_size (regcache->tdesc, 0) == 4 ? pc.reg32 : pc.reg64;
  190. }

  191. static void
  192. mips_set_pc (struct regcache *regcache, CORE_ADDR pc)
  193. {
  194.   union mips_register newpc;
  195.   if (register_size (regcache->tdesc, 0) == 4)
  196.     newpc.reg32 = pc;
  197.   else
  198.     newpc.reg64 = pc;

  199.   supply_register_by_name (regcache, "pc", newpc.buf);
  200. }

  201. /* Correct in either endianness.  */
  202. static const unsigned int mips_breakpoint = 0x0005000d;
  203. #define mips_breakpoint_len 4

  204. /* We only place breakpoints in empty marker functions, and thread locking
  205.    is outside of the function.  So rather than importing software single-step,
  206.    we can just run until exit.  */
  207. static CORE_ADDR
  208. mips_reinsert_addr (void)
  209. {
  210.   struct regcache *regcache = get_thread_regcache (current_thread, 1);
  211.   union mips_register ra;
  212.   collect_register_by_name (regcache, "r31", ra.buf);
  213.   return register_size (regcache->tdesc, 0) == 4 ? ra.reg32 : ra.reg64;
  214. }

  215. static int
  216. mips_breakpoint_at (CORE_ADDR where)
  217. {
  218.   unsigned int insn;

  219.   (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
  220.   if (insn == mips_breakpoint)
  221.     return 1;

  222.   /* If necessary, recognize more trap instructions here.  GDB only uses the
  223.      one.  */
  224.   return 0;
  225. }

  226. /* Mark the watch registers of lwp, represented by ENTRY, as changed,
  227.    if the lwp's process id is *PID_P.  */

  228. static int
  229. update_watch_registers_callback (struct inferior_list_entry *entry,
  230.                                  void *pid_p)
  231. {
  232.   struct thread_info *thread = (struct thread_info *) entry;
  233.   struct lwp_info *lwp = get_thread_lwp (thread);
  234.   int pid = *(int *) pid_p;

  235.   /* Only update the threads of this process.  */
  236.   if (pid_of (thread) == pid)
  237.     {
  238.       /* The actual update is done later just before resuming the lwp,
  239.          we just mark that the registers need updating.  */
  240.       lwp->arch_private->watch_registers_changed = 1;

  241.       /* If the lwp isn't stopped, force it to momentarily pause, so
  242.          we can update its watch registers.  */
  243.       if (!lwp->stopped)
  244.         linux_stop_lwp (lwp);
  245.     }

  246.   return 0;
  247. }

  248. /* This is the implementation of linux_target_ops method
  249.    new_process.  */

  250. static struct arch_process_info *
  251. mips_linux_new_process (void)
  252. {
  253.   struct arch_process_info *info = xcalloc (1, sizeof (*info));

  254.   return info;
  255. }

  256. /* This is the implementation of linux_target_ops method new_thread.
  257.    Mark the watch registers as changed, so the threads' copies will
  258.    be updated.  */

  259. static struct arch_lwp_info *
  260. mips_linux_new_thread (void)
  261. {
  262.   struct arch_lwp_info *info = xcalloc (1, sizeof (*info));

  263.   info->watch_registers_changed = 1;

  264.   return info;
  265. }

  266. /* This is the implementation of linux_target_ops method
  267.    prepare_to_resume.  If the watch regs have changed, update the
  268.    thread's copies.  */

  269. static void
  270. mips_linux_prepare_to_resume (struct lwp_info *lwp)
  271. {
  272.   ptid_t ptid = ptid_of (get_lwp_thread (lwp));
  273.   struct process_info *proc = find_process_pid (ptid_get_pid (ptid));
  274.   struct arch_process_info *private = proc->private->arch_private;

  275.   if (lwp->arch_private->watch_registers_changed)
  276.     {
  277.       /* Only update the watch registers if we have set or unset a
  278.          watchpoint already.  */
  279.       if (mips_linux_watch_get_num_valid (&private->watch_mirror) > 0)
  280.         {
  281.           /* Write the mirrored watch register values.  */
  282.           int tid = ptid_get_lwp (ptid);

  283.           if (-1 == ptrace (PTRACE_SET_WATCH_REGS, tid,
  284.                             &private->watch_mirror))
  285.             perror_with_name ("Couldn't write watch register");
  286.         }

  287.       lwp->arch_private->watch_registers_changed = 0;
  288.     }
  289. }

  290. static int
  291. mips_supports_z_point_type (char z_type)
  292. {
  293.   switch (z_type)
  294.     {
  295.     case Z_PACKET_WRITE_WP:
  296.     case Z_PACKET_READ_WP:
  297.     case Z_PACKET_ACCESS_WP:
  298.       return 1;
  299.     default:
  300.       return 0;
  301.     }
  302. }

  303. /* This is the implementation of linux_target_ops method
  304.    insert_point.  */

  305. static int
  306. mips_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
  307.                    int len, struct raw_breakpoint *bp)
  308. {
  309.   struct process_info *proc = current_process ();
  310.   struct arch_process_info *private = proc->private->arch_private;
  311.   struct pt_watch_regs regs;
  312.   struct mips_watchpoint *new_watch;
  313.   struct mips_watchpoint **pw;
  314.   int pid;
  315.   long lwpid;
  316.   enum target_hw_bp_type watch_type;
  317.   uint32_t irw;

  318.   lwpid = lwpid_of (current_thread);
  319.   if (!mips_linux_read_watch_registers (lwpid,
  320.                                         &private->watch_readback,
  321.                                         &private->watch_readback_valid,
  322.                                         0))
  323.     return -1;

  324.   if (len <= 0)
  325.     return -1;

  326.   regs = private->watch_readback;
  327.   /* Add the current watches.  */
  328.   mips_linux_watch_populate_regs (private->current_watches, &regs);

  329.   /* Now try to add the new watch.  */
  330.   watch_type = raw_bkpt_type_to_target_hw_bp_type (type);
  331.   irw = mips_linux_watch_type_to_irw (watch_type);
  332.   if (!mips_linux_watch_try_one_watch (&regs, addr, len, irw))
  333.     return -1;

  334.   /* It fit.  Stick it on the end of the list.  */
  335.   new_watch = xmalloc (sizeof (struct mips_watchpoint));
  336.   new_watch->addr = addr;
  337.   new_watch->len = len;
  338.   new_watch->type = watch_type;
  339.   new_watch->next = NULL;

  340.   pw = &private->current_watches;
  341.   while (*pw != NULL)
  342.     pw = &(*pw)->next;
  343.   *pw = new_watch;

  344.   private->watch_mirror = regs;

  345.   /* Only update the threads of this process.  */
  346.   pid = pid_of (proc);
  347.   find_inferior (&all_threads, update_watch_registers_callback, &pid);

  348.   return 0;
  349. }

  350. /* This is the implementation of linux_target_ops method
  351.    remove_point.  */

  352. static int
  353. mips_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
  354.                    int len, struct raw_breakpoint *bp)
  355. {
  356.   struct process_info *proc = current_process ();
  357.   struct arch_process_info *private = proc->private->arch_private;

  358.   int deleted_one;
  359.   int pid;
  360.   enum target_hw_bp_type watch_type;

  361.   struct mips_watchpoint **pw;
  362.   struct mips_watchpoint *w;

  363.   /* Search for a known watch that matches.  Then unlink and free it.  */
  364.   watch_type = raw_bkpt_type_to_target_hw_bp_type (type);
  365.   deleted_one = 0;
  366.   pw = &private->current_watches;
  367.   while ((w = *pw))
  368.     {
  369.       if (w->addr == addr && w->len == len && w->type == watch_type)
  370.         {
  371.           *pw = w->next;
  372.           free (w);
  373.           deleted_one = 1;
  374.           break;
  375.         }
  376.       pw = &(w->next);
  377.     }

  378.   if (!deleted_one)
  379.     return -1/* We don't know about it, fail doing nothing.  */

  380.   /* At this point watch_readback is known to be valid because we
  381.      could not have added the watch without reading it.  */
  382.   gdb_assert (private->watch_readback_valid == 1);

  383.   private->watch_mirror = private->watch_readback;
  384.   mips_linux_watch_populate_regs (private->current_watches,
  385.                                   &private->watch_mirror);

  386.   /* Only update the threads of this process.  */
  387.   pid = pid_of (proc);
  388.   find_inferior (&all_threads, update_watch_registers_callback, &pid);
  389.   return 0;
  390. }

  391. /* This is the implementation of linux_target_ops method
  392.    stopped_by_watchpoint.  The watchhi R and W bits indicate
  393.    the watch register triggered. */

  394. static int
  395. mips_stopped_by_watchpoint (void)
  396. {
  397.   struct process_info *proc = current_process ();
  398.   struct arch_process_info *private = proc->private->arch_private;
  399.   int n;
  400.   int num_valid;
  401.   long lwpid = lwpid_of (current_thread);

  402.   if (!mips_linux_read_watch_registers (lwpid,
  403.                                         &private->watch_readback,
  404.                                         &private->watch_readback_valid,
  405.                                         1))
  406.     return 0;

  407.   num_valid = mips_linux_watch_get_num_valid (&private->watch_readback);

  408.   for (n = 0; n < MAX_DEBUG_REGISTER && n < num_valid; n++)
  409.     if (mips_linux_watch_get_watchhi (&private->watch_readback, n)
  410.         & (R_MASK | W_MASK))
  411.       return 1;

  412.   return 0;
  413. }

  414. /* This is the implementation of linux_target_ops method
  415.    stopped_data_address.  */

  416. static CORE_ADDR
  417. mips_stopped_data_address (void)
  418. {
  419.   struct process_info *proc = current_process ();
  420.   struct arch_process_info *private = proc->private->arch_private;
  421.   int n;
  422.   int num_valid;
  423.   long lwpid = lwpid_of (current_thread);

  424.   /* On MIPS we don't know the low order 3 bits of the data address.
  425.      GDB does not support remote targets that can't report the
  426.      watchpoint address.  So, make our best guess; return the starting
  427.      address of a watchpoint request which overlaps the one that
  428.      triggered.  */

  429.   if (!mips_linux_read_watch_registers (lwpid,
  430.                                         &private->watch_readback,
  431.                                         &private->watch_readback_valid,
  432.                                         0))
  433.     return 0;

  434.   num_valid = mips_linux_watch_get_num_valid (&private->watch_readback);

  435.   for (n = 0; n < MAX_DEBUG_REGISTER && n < num_valid; n++)
  436.     if (mips_linux_watch_get_watchhi (&private->watch_readback, n)
  437.         & (R_MASK | W_MASK))
  438.       {
  439.         CORE_ADDR t_low, t_hi;
  440.         int t_irw;
  441.         struct mips_watchpoint *watch;

  442.         t_low = mips_linux_watch_get_watchlo (&private->watch_readback, n);
  443.         t_irw = t_low & IRW_MASK;
  444.         t_hi = (mips_linux_watch_get_watchhi (&private->watch_readback, n)
  445.                 | IRW_MASK);
  446.         t_low &= ~(CORE_ADDR)t_hi;

  447.         for (watch = private->current_watches;
  448.              watch != NULL;
  449.              watch = watch->next)
  450.           {
  451.             CORE_ADDR addr = watch->addr;
  452.             CORE_ADDR last_byte = addr + watch->len - 1;

  453.             if ((t_irw & mips_linux_watch_type_to_irw (watch->type)) == 0)
  454.               {
  455.                 /* Different type.  */
  456.                 continue;
  457.               }
  458.             /* Check for overlap of even a single byte.  */
  459.             if (last_byte >= t_low && addr <= t_low + t_hi)
  460.               return addr;
  461.           }
  462.       }

  463.   /* Shouldn't happen.  */
  464.   return 0;
  465. }

  466. /* Fetch the thread-local storage pointer for libthread_db.  */

  467. ps_err_e
  468. ps_get_thread_area (const struct ps_prochandle *ph,
  469.                     lwpid_t lwpid, int idx, void **base)
  470. {
  471.   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
  472.     return PS_ERR;

  473.   /* IDX is the bias from the thread pointer to the beginning of the
  474.      thread descriptor.  It has to be subtracted due to implementation
  475.      quirks in libthread_db.  */
  476.   *base = (void *) ((char *)*base - idx);

  477.   return PS_OK;
  478. }

  479. #ifdef HAVE_PTRACE_GETREGS

  480. static void
  481. mips_collect_register (struct regcache *regcache,
  482.                        int use_64bit, int regno, union mips_register *reg)
  483. {
  484.   union mips_register tmp_reg;

  485.   if (use_64bit)
  486.     {
  487.       collect_register (regcache, regno, &tmp_reg.reg64);
  488.       *reg = tmp_reg;
  489.     }
  490.   else
  491.     {
  492.       collect_register (regcache, regno, &tmp_reg.reg32);
  493.       reg->reg64 = tmp_reg.reg32;
  494.     }
  495. }

  496. static void
  497. mips_supply_register (struct regcache *regcache,
  498.                       int use_64bit, int regno, const union mips_register *reg)
  499. {
  500.   int offset = 0;

  501.   /* For big-endian 32-bit targets, ignore the high four bytes of each
  502.      eight-byte slot.  */
  503.   if (__BYTE_ORDER == __BIG_ENDIAN && !use_64bit)
  504.     offset = 4;

  505.   supply_register (regcache, regno, reg->buf + offset);
  506. }

  507. static void
  508. mips_collect_register_32bit (struct regcache *regcache,
  509.                              int use_64bit, int regno, unsigned char *buf)
  510. {
  511.   union mips_register tmp_reg;
  512.   int reg32;

  513.   mips_collect_register (regcache, use_64bit, regno, &tmp_reg);
  514.   reg32 = tmp_reg.reg64;
  515.   memcpy (buf, &reg32, 4);
  516. }

  517. static void
  518. mips_supply_register_32bit (struct regcache *regcache,
  519.                             int use_64bit, int regno, const unsigned char *buf)
  520. {
  521.   union mips_register tmp_reg;
  522.   int reg32;

  523.   memcpy (&reg32, buf, 4);
  524.   tmp_reg.reg64 = reg32;
  525.   mips_supply_register (regcache, use_64bit, regno, &tmp_reg);
  526. }

  527. static void
  528. mips_fill_gregset (struct regcache *regcache, void *buf)
  529. {
  530.   union mips_register *regset = buf;
  531.   int i, use_64bit;
  532.   const struct target_desc *tdesc = regcache->tdesc;

  533.   use_64bit = (register_size (tdesc, 0) == 8);

  534.   for (i = 1; i < 32; i++)
  535.     mips_collect_register (regcache, use_64bit, i, regset + i);

  536.   mips_collect_register (regcache, use_64bit,
  537.                          find_regno (tdesc, "lo"), regset + 32);
  538.   mips_collect_register (regcache, use_64bit,
  539.                          find_regno (tdesc, "hi"), regset + 33);
  540.   mips_collect_register (regcache, use_64bit,
  541.                          find_regno (tdesc, "pc"), regset + 34);
  542.   mips_collect_register (regcache, use_64bit,
  543.                          find_regno (tdesc, "badvaddr"), regset + 35);
  544.   mips_collect_register (regcache, use_64bit,
  545.                          find_regno (tdesc, "status"), regset + 36);
  546.   mips_collect_register (regcache, use_64bit,
  547.                          find_regno (tdesc, "cause"), regset + 37);

  548.   mips_collect_register (regcache, use_64bit,
  549.                          find_regno (tdesc, "restart"), regset + 0);
  550. }

  551. static void
  552. mips_store_gregset (struct regcache *regcache, const void *buf)
  553. {
  554.   const union mips_register *regset = buf;
  555.   int i, use_64bit;

  556.   use_64bit = (register_size (regcache->tdesc, 0) == 8);

  557.   for (i = 0; i < 32; i++)
  558.     mips_supply_register (regcache, use_64bit, i, regset + i);

  559.   mips_supply_register (regcache, use_64bit,
  560.                         find_regno (regcache->tdesc, "lo"), regset + 32);
  561.   mips_supply_register (regcache, use_64bit,
  562.                         find_regno (regcache->tdesc, "hi"), regset + 33);
  563.   mips_supply_register (regcache, use_64bit,
  564.                         find_regno (regcache->tdesc, "pc"), regset + 34);
  565.   mips_supply_register (regcache, use_64bit,
  566.                         find_regno (regcache->tdesc, "badvaddr"), regset + 35);
  567.   mips_supply_register (regcache, use_64bit,
  568.                         find_regno (regcache->tdesc, "status"), regset + 36);
  569.   mips_supply_register (regcache, use_64bit,
  570.                         find_regno (regcache->tdesc, "cause"), regset + 37);

  571.   mips_supply_register (regcache, use_64bit,
  572.                         find_regno (regcache->tdesc, "restart"), regset + 0);
  573. }

  574. static void
  575. mips_fill_fpregset (struct regcache *regcache, void *buf)
  576. {
  577.   union mips_register *regset = buf;
  578.   int i, use_64bit, first_fp, big_endian;

  579.   use_64bit = (register_size (regcache->tdesc, 0) == 8);
  580.   first_fp = find_regno (regcache->tdesc, "f0");
  581.   big_endian = (__BYTE_ORDER == __BIG_ENDIAN);

  582.   /* See GDB for a discussion of this peculiar layout.  */
  583.   for (i = 0; i < 32; i++)
  584.     if (use_64bit)
  585.       collect_register (regcache, first_fp + i, regset[i].buf);
  586.     else
  587.       collect_register (regcache, first_fp + i,
  588.                         regset[i & ~1].buf + 4 * (big_endian != (i & 1)));

  589.   mips_collect_register_32bit (regcache, use_64bit,
  590.                                find_regno (regcache->tdesc, "fcsr"), regset[32].buf);
  591.   mips_collect_register_32bit (regcache, use_64bit,
  592.                                find_regno (regcache->tdesc, "fir"),
  593.                                regset[32].buf + 4);
  594. }

  595. static void
  596. mips_store_fpregset (struct regcache *regcache, const void *buf)
  597. {
  598.   const union mips_register *regset = buf;
  599.   int i, use_64bit, first_fp, big_endian;

  600.   use_64bit = (register_size (regcache->tdesc, 0) == 8);
  601.   first_fp = find_regno (regcache->tdesc, "f0");
  602.   big_endian = (__BYTE_ORDER == __BIG_ENDIAN);

  603.   /* See GDB for a discussion of this peculiar layout.  */
  604.   for (i = 0; i < 32; i++)
  605.     if (use_64bit)
  606.       supply_register (regcache, first_fp + i, regset[i].buf);
  607.     else
  608.       supply_register (regcache, first_fp + i,
  609.                        regset[i & ~1].buf + 4 * (big_endian != (i & 1)));

  610.   mips_supply_register_32bit (regcache, use_64bit,
  611.                               find_regno (regcache->tdesc, "fcsr"),
  612.                               regset[32].buf);
  613.   mips_supply_register_32bit (regcache, use_64bit,
  614.                               find_regno (regcache->tdesc, "fir"),
  615.                               regset[32].buf + 4);
  616. }
  617. #endif /* HAVE_PTRACE_GETREGS */

  618. static struct regset_info mips_regsets[] = {
  619. #ifdef HAVE_PTRACE_GETREGS
  620.   { PTRACE_GETREGS, PTRACE_SETREGS, 0, 38 * 8, GENERAL_REGS,
  621.     mips_fill_gregset, mips_store_gregset },
  622.   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, 0, 33 * 8, FP_REGS,
  623.     mips_fill_fpregset, mips_store_fpregset },
  624. #endif /* HAVE_PTRACE_GETREGS */
  625.   { 0, 0, 0, -1, -1, NULL, NULL }
  626. };

  627. static struct regsets_info mips_regsets_info =
  628.   {
  629.     mips_regsets, /* regsets */
  630.     0, /* num_regsets */
  631.     NULL, /* disabled_regsets */
  632.   };

  633. static struct usrregs_info mips_dsp_usrregs_info =
  634.   {
  635.     mips_dsp_num_regs,
  636.     mips_dsp_regmap,
  637.   };

  638. static struct usrregs_info mips_usrregs_info =
  639.   {
  640.     mips_num_regs,
  641.     mips_regmap,
  642.   };

  643. static struct regs_info dsp_regs_info =
  644.   {
  645.     mips_dsp_regset_bitmap,
  646.     &mips_dsp_usrregs_info,
  647.     &mips_regsets_info
  648.   };

  649. static struct regs_info regs_info =
  650.   {
  651.     NULL, /* regset_bitmap */
  652.     &mips_usrregs_info,
  653.     &mips_regsets_info
  654.   };

  655. static const struct regs_info *
  656. mips_regs_info (void)
  657. {
  658.   if (have_dsp)
  659.     return &dsp_regs_info;
  660.   else
  661.     return &regs_info;
  662. }

  663. struct linux_target_ops the_low_target = {
  664.   mips_arch_setup,
  665.   mips_regs_info,
  666.   mips_cannot_fetch_register,
  667.   mips_cannot_store_register,
  668.   NULL, /* fetch_register */
  669.   mips_get_pc,
  670.   mips_set_pc,
  671.   (const unsigned char *) &mips_breakpoint,
  672.   mips_breakpoint_len,
  673.   mips_reinsert_addr,
  674.   0,
  675.   mips_breakpoint_at,
  676.   mips_supports_z_point_type,
  677.   mips_insert_point,
  678.   mips_remove_point,
  679.   mips_stopped_by_watchpoint,
  680.   mips_stopped_data_address,
  681.   NULL,
  682.   NULL,
  683.   NULL, /* siginfo_fixup */
  684.   mips_linux_new_process,
  685.   mips_linux_new_thread,
  686.   mips_linux_prepare_to_resume
  687. };

  688. void
  689. initialize_low_arch (void)
  690. {
  691.   /* Initialize the Linux target descriptions.  */
  692.   init_registers_mips_linux ();
  693.   init_registers_mips_dsp_linux ();
  694.   init_registers_mips64_linux ();
  695.   init_registers_mips64_dsp_linux ();

  696.   initialize_regsets_info (&mips_regsets_info);
  697. }