gdb/hppanbsd-nat.c - gdb

Functions defined

Source code

  1. /* Native-dependent code for NetBSD/hppa.

  2.    Copyright (C) 2008-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 <sys/types.h>
  18. #include <sys/ptrace.h>
  19. #include <machine/reg.h>

  20. #include "hppa-tdep.h"
  21. #include "inf-ptrace.h"

  22. #include "nbsd-nat.h"

  23. static int
  24. hppanbsd_gregset_supplies_p (int regnum)
  25. {
  26.   return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
  27.           (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
  28.           regnum == HPPA_IPSW_REGNUM ||
  29.           (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
  30. }

  31. static int
  32. hppanbsd_fpregset_supplies_p (int regnum)
  33. {
  34.   return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
  35. }

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

  37. static void
  38. hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
  39. {
  40.   const char *regs = gregs;
  41.   const int *r = gregs;
  42.   int regnum;

  43.   for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
  44.     regcache_raw_supply (regcache, regnum, regs + regnum * 4);

  45.   regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
  46.   regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
  47.   regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
  48.   regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
  49.   regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
  50.   regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
  51.   regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
  52.   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
  53.   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
  54.   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
  55.   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
  56. }

  57. /* Supply the floating-point registers stored in FPREGS to REGCACHE.  */

  58. static void
  59. hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
  60. {
  61.   const char *regs = fpregs;
  62.   int regnum;

  63.   for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
  64.        regnum += 2, regs += 8)
  65.     {
  66.       regcache_raw_supply (regcache, regnum, regs);
  67.       regcache_raw_supply (regcache, regnum + 1, regs + 4);
  68.     }
  69. }

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

  72. static void
  73. hppanbsd_collect_gregset (const struct regcache *regcache,
  74.                           void *gregs, int regnum)
  75. {
  76.   char *regs = gregs;
  77.   int *r = gregs;
  78.   int i;

  79.   for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
  80.     {
  81.       if (regnum == -1 || regnum == i)
  82.         regcache_raw_collect (regcache, i, regs + i * 4);
  83.     }

  84.   if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
  85.     regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
  86.   if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  87.     regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
  88.   if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  89.     regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);

  90.   if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
  91.     regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
  92.   if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
  93.     regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
  94.   if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
  95.     regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
  96.   if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  97.     regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
  98.   if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  99.     regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
  100.   if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
  101.     regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
  102.   if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
  103.     regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
  104.   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
  105.     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
  106.   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
  107.     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
  108.   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
  109.     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
  110.   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
  111.     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
  112. }

  113. /* Collect the floating-point registers from REGCACHE and store them
  114.    in FPREGS.  */

  115. static void
  116. hppanbsd_collect_fpregset (struct regcache *regcache,
  117.                           void *fpregs, int regnum)
  118. {
  119.   char *regs = fpregs;
  120.   int i;

  121.   for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
  122.     {
  123.       if (regnum == -1 || regnum == i || regnum == i + 1)
  124.         {
  125.           regcache_raw_collect (regcache, i, regs);
  126.           regcache_raw_collect (regcache, i + 1, regs + 4);
  127.         }
  128.     }
  129. }


  130. /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
  131.    for all registers (including the floating-point registers).  */

  132. static void
  133. hppanbsd_fetch_registers (struct target_ops *ops,
  134.                           struct regcache *regcache, int regnum)

  135. {
  136.   if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
  137.     {
  138.       struct reg regs;

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

  142.       hppanbsd_supply_gregset (regcache, &regs);
  143.     }

  144.   if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
  145.     {
  146.       struct fpreg fpregs;

  147.       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
  148.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  149.         perror_with_name (_("Couldn't get floating point status"));

  150.       hppanbsd_supply_fpregset (regcache, &fpregs);
  151.     }
  152. }

  153. /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
  154.    this for all registers (including the floating-point registers).  */

  155. static void
  156. hppanbsd_store_registers (struct target_ops *ops,
  157.                           struct regcache *regcache, int regnum)
  158. {
  159.   if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
  160.     {
  161.       struct reg regs;

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

  165.       hppanbsd_collect_gregset (regcache, &regs, regnum);

  166.       if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  167.                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  168.         perror_with_name (_("Couldn't write registers"));
  169.     }

  170.   if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
  171.     {
  172.       struct fpreg fpregs;

  173.       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
  174.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  175.         perror_with_name (_("Couldn't get floating point status"));

  176.       hppanbsd_collect_fpregset (regcache, &fpregs, regnum);

  177.       if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
  178.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  179.         perror_with_name (_("Couldn't write floating point status"));
  180.     }
  181. }


  182. /* Provide a prototype to silence -Wmissing-prototypes.  */
  183. void _initialize_hppanbsd_nat (void);

  184. void
  185. _initialize_hppanbsd_nat (void)
  186. {
  187.   struct target_ops *t;

  188.   /* Add some extra features to the ptrace target.  */
  189.   t = inf_ptrace_target ();

  190.   t->to_fetch_registers = hppanbsd_fetch_registers;
  191.   t->to_store_registers = hppanbsd_store_registers;

  192.   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;

  193.   add_target (t);
  194. }