gdb/mips64obsd-nat.c - gdb

Functions defined

Macros defined

Source code

  1. /* Native-dependent code for OpenBSD/mips64.

  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 "mips-tdep.h"
  22. #include "inf-ptrace.h"
  23. #include "obsd-nat.h"

  24. /* Shorthand for some register numbers used below.  */
  25. #define MIPS_PC_REGNUM        MIPS_EMBED_PC_REGNUM
  26. #define MIPS_FP0_REGNUM        MIPS_EMBED_FP0_REGNUM
  27. #define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32

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

  29. static void
  30. mips64obsd_supply_gregset (struct regcache *regcache, const void *gregs)
  31. {
  32.   const char *regs = gregs;
  33.   int regnum;

  34.   for (regnum = MIPS_ZERO_REGNUM; regnum <= MIPS_PC_REGNUM; regnum++)
  35.     regcache_raw_supply (regcache, regnum, regs + regnum * 8);

  36.   for (regnum = MIPS_FP0_REGNUM; regnum <= MIPS_FSR_REGNUM; regnum++)
  37.     regcache_raw_supply (regcache, regnum, regs + (regnum + 2) * 8);
  38. }

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

  41. static void
  42. mips64obsd_collect_gregset (const struct regcache *regcache,
  43.                             void *gregs, int regnum)
  44. {
  45.   char *regs = gregs;
  46.   int i;

  47.   for (i = MIPS_ZERO_REGNUM; i <= MIPS_PC_REGNUM; i++)
  48.     {
  49.       if (regnum == -1 || regnum == i)
  50.         regcache_raw_collect (regcache, i, regs + i * 8);
  51.     }

  52.   for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++)
  53.     {
  54.       if (regnum == -1 || regnum == i)
  55.         regcache_raw_collect (regcache, i, regs + (i + 2) * 8);
  56.     }
  57. }


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

  60. static void
  61. mips64obsd_fetch_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.   mips64obsd_supply_gregset (regcache, &regs);
  69. }

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

  72. static void
  73. mips64obsd_store_inferior_registers (struct target_ops *ops,
  74.                                      struct regcache *regcache, int regnum)
  75. {
  76.   struct reg regs;

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

  80.   mips64obsd_collect_gregset (regcache, &regs, regnum);

  81.   if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  82.               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  83.     perror_with_name (_("Couldn't write registers"));
  84. }


  85. /* Provide a prototype to silence -Wmissing-prototypes.  */
  86. void _initialize_mips64obsd_nat (void);

  87. void
  88. _initialize_mips64obsd_nat (void)
  89. {
  90.   struct target_ops *t;

  91.   t = inf_ptrace_target ();
  92.   t->to_fetch_registers = mips64obsd_fetch_inferior_registers;
  93.   t->to_store_registers = mips64obsd_store_inferior_registers;
  94.   obsd_add_target (t);
  95. }