gdb/sparc64nbsd-nat.c - gdb

Functions defined

Source code

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

  2.    Copyright (C) 2003-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 "gdbcore.h"
  16. #include "regcache.h"
  17. #include "target.h"

  18. #include "sparc64-tdep.h"
  19. #include "sparc-nat.h"

  20. /* NetBSD is different from the other OSes that support both SPARC and
  21.    UltraSPARC in that the result of ptrace(2) depends on whether the
  22.    traced process is 32-bit or 64-bit.  */

  23. static void
  24. sparc64nbsd_supply_gregset (const struct sparc_gregmap *gregmap,
  25.                             struct regcache *regcache,
  26.                             int regnum, const void *gregs)
  27. {
  28.   int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);

  29.   if (sparc32)
  30.     sparc32_supply_gregset (&sparc32nbsd_gregmap, regcache, regnum, gregs);
  31.   else
  32.     sparc64_supply_gregset (&sparc64nbsd_gregmap, regcache, regnum, gregs);
  33. }

  34. static void
  35. sparc64nbsd_collect_gregset (const struct sparc_gregmap *gregmap,
  36.                              const struct regcache *regcache,
  37.                              int regnum, void *gregs)
  38. {
  39.   int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);

  40.   if (sparc32)
  41.     sparc32_collect_gregset (&sparc32nbsd_gregmap, regcache, regnum, gregs);
  42.   else
  43.     sparc64_collect_gregset (&sparc64nbsd_gregmap, regcache, regnum, gregs);
  44. }

  45. static void
  46. sparc64nbsd_supply_fpregset (const struct sparc_fpregmap *fpregmap,
  47.                              struct regcache *regcache,
  48.                              int regnum, const void *fpregs)
  49. {
  50.   int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);

  51.   if (sparc32)
  52.     sparc32_supply_fpregset (&sparc32_bsd_fpregmap, regcache, regnum, fpregs);
  53.   else
  54.     sparc64_supply_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
  55. }

  56. static void
  57. sparc64nbsd_collect_fpregset (const struct sparc_fpregmap *fpregmap,
  58.                               const struct regcache *regcache,
  59.                               int regnum, void *fpregs)
  60. {
  61.   int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);

  62.   if (sparc32)
  63.     sparc32_collect_fpregset (&sparc32_bsd_fpregmap, regcache, regnum, fpregs);
  64.   else
  65.     sparc64_collect_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
  66. }

  67. /* Determine whether `gregset_t' contains register REGNUM.  */

  68. static int
  69. sparc64nbsd_gregset_supplies_p (struct gdbarch *gdbarch, int regnum)
  70. {
  71.   if (gdbarch_ptr_bit (gdbarch) == 32)
  72.     return sparc32_gregset_supplies_p (gdbarch, regnum);

  73.   /* Integer registers.  */
  74.   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM)
  75.       || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
  76.       || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
  77.       || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
  78.     return 1;

  79.   /* Control registers.  */
  80.   if (regnum == SPARC64_PC_REGNUM
  81.       || regnum == SPARC64_NPC_REGNUM
  82.       || regnum == SPARC64_STATE_REGNUM
  83.       || regnum == SPARC64_Y_REGNUM)
  84.     return 1;

  85.   return 0;
  86. }

  87. /* Determine whether `fpregset_t' contains register REGNUM.  */

  88. static int
  89. sparc64nbsd_fpregset_supplies_p (struct gdbarch *gdbarch, int regnum)
  90. {
  91.   if (gdbarch_ptr_bit (gdbarch) == 32)
  92.     return sparc32_fpregset_supplies_p (gdbarch, regnum);

  93.   /* Floating-point registers.  */
  94.   if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
  95.       || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
  96.     return 1;

  97.   /* Control registers.  */
  98.   if (regnum == SPARC64_FSR_REGNUM)
  99.     return 1;

  100.   return 0;
  101. }


  102. /* Support for debugging kernel virtual memory images.  */

  103. #include <sys/types.h>
  104. #include <machine/pcb.h>

  105. #include "bsd-kvm.h"

  106. static int
  107. sparc64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  108. {
  109.   u_int64_t state;
  110.   int regnum;

  111.   /* The following is true for NetBSD 1.6.2:

  112.      The pcb contains %sp and %pc, %pstate and %cwp.  From this
  113.      information we reconstruct the register state as it would look
  114.      when we just returned from cpu_switch().  */

  115.   /* The stack pointer shouldn't be zero.  */
  116.   if (pcb->pcb_sp == 0)
  117.     return 0;

  118.   /* If the program counter is zero, this is probably a core dump, and
  119.      we can get %pc from the stack.  */
  120.   if (pcb->pcb_pc == 0)
  121.       read_memory(pcb->pcb_sp + BIAS - 176 + (11 * 8),
  122.                   (gdb_byte *)&pcb->pcb_pc, sizeof pcb->pcb_pc);

  123.   regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
  124.   regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);

  125.   state = pcb->pcb_pstate << 8 | pcb->pcb_cwp;
  126.   regcache_raw_supply (regcache, SPARC64_STATE_REGNUM, &state);

  127.   sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);

  128.   return 1;
  129. }


  130. /* Provide a prototype to silence -Wmissing-prototypes.  */
  131. void _initialize_sparc64nbsd_nat (void);

  132. void
  133. _initialize_sparc64nbsd_nat (void)
  134. {
  135.   sparc_supply_gregset = sparc64nbsd_supply_gregset;
  136.   sparc_collect_gregset = sparc64nbsd_collect_gregset;
  137.   sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
  138.   sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
  139.   sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
  140.   sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;

  141.   /* We've got nothing to add to the generic SPARC target.  */
  142.   add_target (sparc_target ());

  143.   /* Support debugging kernel virtual memory images.  */
  144.   bsd_kvm_add_target (sparc64nbsd_supply_pcb);
  145. }