gdb/m88kbsd-nat.c - gdb

Functions defined

Source code

  1. /* Native-dependent code for Motorola 88000 BSD's.

  2.    Copyright (C) 2004-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 "defs.h"
  15. #include "inferior.h"
  16. #include "regcache.h"
  17. #include "target.h"

  18. #include <sys/types.h>
  19. #include <sys/ptrace.h>
  20. #include <machine/reg.h>

  21. #include "m88k-tdep.h"
  22. #include "inf-ptrace.h"

  23. /* Supply the general-purpose registers stored in GREGS to REGCACHE.  */

  24. static void
  25. m88kbsd_supply_gregset (struct regcache *regcache, const void *gregs)
  26. {
  27.   const char *regs = gregs;
  28.   int regnum;

  29.   for (regnum = 0; regnum < M88K_NUM_REGS; regnum++)
  30.     regcache_raw_supply (regcache, regnum, regs + regnum * 4);
  31. }

  32. /* Collect the general-purpose registers from REGCACHE and store them
  33.    in GREGS.  */

  34. static void
  35. m88kbsd_collect_gregset (const struct regcache *regcache,
  36.                          void *gregs, int regnum)
  37. {
  38.   char *regs = gregs;
  39.   int i;

  40.   for (i = 0; i < M88K_NUM_REGS; i++)
  41.     {
  42.       if (regnum == -1 || regnum == i)
  43.         regcache_raw_collect (regcache, i, regs + i * 4);
  44.     }
  45. }


  46. /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
  47.    for all registers.  */

  48. static void
  49. m88kbsd_fetch_inferior_registers (struct target_ops *ops,
  50.                                   struct regcache *regcache, int regnum)
  51. {
  52.   struct reg regs;

  53.   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  54.               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  55.     perror_with_name (_("Couldn't get registers"));

  56.   m88kbsd_supply_gregset (regcache, &regs);
  57. }

  58. /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
  59.    this for all registers.  */

  60. static void
  61. m88kbsd_store_inferior_registers (struct target_ops *ops,
  62.                                   struct regcache *regcache, int regnum)
  63. {
  64.   struct reg regs;

  65.   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  66.               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  67.     perror_with_name (_("Couldn't get registers"));

  68.   m88kbsd_collect_gregset (regcache, &regs, regnum);

  69.   if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  70.               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  71.     perror_with_name (_("Couldn't write registers"));
  72. }


  73. /* Provide a prototype to silence -Wmissing-prototypes.  */
  74. void _initialize_m88kbsd_nat (void);

  75. void
  76. _initialize_m88kbsd_nat (void)
  77. {
  78.   struct target_ops *t;

  79.   t = inf_ptrace_target ();
  80.   t->to_fetch_registers = m88kbsd_fetch_inferior_registers;
  81.   t->to_store_registers = m88kbsd_store_inferior_registers;
  82.   add_target (t);
  83. }