gdb/sparc64obsd-nat.c - gdb

Functions defined

Source code

  1. /* Native-dependent code for OpenBSD/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. #include "obsd-nat.h"

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

  22. static int
  23. sparc64obsd_gregset_supplies_p (struct gdbarch *gdbarch, int regnum)
  24. {
  25.   /* Integer registers.  */
  26.   if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM)
  27.       || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
  28.       || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
  29.       || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
  30.     return 1;

  31.   /* Control registers.  */
  32.   if (regnum == SPARC64_PC_REGNUM
  33.       || regnum == SPARC64_NPC_REGNUM
  34.       || regnum == SPARC64_STATE_REGNUM
  35.       || regnum == SPARC64_Y_REGNUM)
  36.     return 1;

  37.   return 0;
  38. }

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

  40. static int
  41. sparc64obsd_fpregset_supplies_p (struct gdbarch *gdbarch, int regnum)
  42. {
  43.   /* Floating-point registers.  */
  44.   if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
  45.       || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
  46.     return 1;

  47.   /* Control registers.  */
  48.   if (regnum == SPARC64_FSR_REGNUM)
  49.     return 1;

  50.   return 0;
  51. }


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

  53. #include <sys/types.h>
  54. #include <machine/pcb.h>

  55. #include "bsd-kvm.h"

  56. static int
  57. sparc64obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  58. {
  59.   u_int64_t state;
  60.   int regnum;

  61.   /* The following is true for OpenBSD 3.0:

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

  65.   /* The stack pointer shouldn't be zero.  */
  66.   if (pcb->pcb_sp == 0)
  67.     return 0;

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

  73.   regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
  74.   regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);

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

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

  78.   return 1;
  79. }


  80. /* Provide a prototype to silence -Wmissing-prototypes.  */
  81. void _initialize_sparc64obsd_nat (void);

  82. void
  83. _initialize_sparc64obsd_nat (void)
  84. {
  85.   sparc_supply_gregset = sparc64_supply_gregset;
  86.   sparc_collect_gregset = sparc64_collect_gregset;
  87.   sparc_supply_fpregset = sparc64_supply_fpregset;
  88.   sparc_collect_fpregset = sparc64_collect_fpregset;
  89.   sparc_gregset_supplies_p = sparc64obsd_gregset_supplies_p;
  90.   sparc_fpregset_supplies_p = sparc64obsd_fpregset_supplies_p;

  91.   sparc_gregmap = &sparc64nbsd_gregmap;
  92.   sparc_fpregmap = &sparc64_bsd_fpregmap;

  93.   /* Add some extra features to the generic SPARC target.  */
  94.   obsd_add_target (sparc_target ());

  95.   /* Support debugging kernel virtual memory images.  */
  96.   bsd_kvm_add_target (sparc64obsd_supply_pcb);
  97. }