gdb/sparc64nbsd-tdep.c - gdb

Global variables defined

Functions defined

Source code

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

  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3.    Based on code contributed by Wasabi Systems, Inc.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "frame.h"
  17. #include "frame-unwind.h"
  18. #include "gdbcore.h"
  19. #include "osabi.h"
  20. #include "regcache.h"
  21. #include "regset.h"
  22. #include "symtab.h"
  23. #include "objfiles.h"
  24. #include "solib-svr4.h"
  25. #include "trad-frame.h"

  26. #include "sparc64-tdep.h"
  27. #include "nbsd-tdep.h"

  28. /* From <machine/reg.h>.  */
  29. const struct sparc_gregmap sparc64nbsd_gregmap =
  30. {
  31.   0 * 8,                        /* "tstate" */
  32.   1 * 8,                        /* %pc */
  33.   2 * 8,                        /* %npc */
  34.   3 * 8,                        /* %y */
  35.   -1,                                /* %fprs */
  36.   -1,
  37.   5 * 8,                        /* %g1 */
  38.   -1,                                /* %l0 */
  39.   4                                /* sizeof (%y) */
  40. };


  41. static void
  42. sparc64nbsd_supply_gregset (const struct regset *regset,
  43.                             struct regcache *regcache,
  44.                             int regnum, const void *gregs, size_t len)
  45. {
  46.   sparc64_supply_gregset (&sparc64nbsd_gregmap, regcache, regnum, gregs);
  47. }

  48. static void
  49. sparc64nbsd_supply_fpregset (const struct regset *regset,
  50.                              struct regcache *regcache,
  51.                              int regnum, const void *fpregs, size_t len)
  52. {
  53.   sparc64_supply_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
  54. }


  55. /* Signal trampolines.  */

  56. /* The following variables describe the location of an on-stack signal
  57.    trampoline.  The current values correspond to the memory layout for
  58.    NetBSD 1.3 and up.  These shouldn't be necessary for NetBSD 2.0 and
  59.    up, since NetBSD uses signal trampolines provided by libc now.  */

  60. static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL;
  61. static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL;

  62. static int
  63. sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
  64. {
  65.   if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end)
  66.     return 1;

  67.   return nbsd_pc_in_sigtramp (pc, name);
  68. }

  69. struct trad_frame_saved_reg *
  70. sparc64nbsd_sigcontext_saved_regs (CORE_ADDR sigcontext_addr,
  71.                                    struct frame_info *this_frame)
  72. {
  73.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  74.   struct trad_frame_saved_reg *saved_regs;
  75.   CORE_ADDR addr, sp;
  76.   int regnum, delta;

  77.   saved_regs = trad_frame_alloc_saved_regs (this_frame);

  78.   /* The registers are saved in bits and pieces scattered all over the
  79.      place.  The code below records their location on the assumption
  80.      that the part of the signal trampoline that saves the state has
  81.      been executed.  */

  82.   saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8;
  83.   saved_regs[SPARC64_PC_REGNUM].addr = sigcontext_addr + 16;
  84.   saved_regs[SPARC64_NPC_REGNUM].addr = sigcontext_addr + 24;
  85.   saved_regs[SPARC64_STATE_REGNUM].addr = sigcontext_addr + 32;
  86.   saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 40;
  87.   saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 48;

  88.   /* The remaining `global' registers and %y are saved in the `local'
  89.      registers.  */
  90.   delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
  91.   for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
  92.     saved_regs[regnum].realreg = regnum + delta;
  93.   saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM;

  94.   /* The remaining `out' registers can be found in the current frame's
  95.      `in' registers.  */
  96.   delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
  97.   for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
  98.     saved_regs[regnum].realreg = regnum + delta;
  99.   saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;

  100.   /* The `local' and `in' registers have been saved in the register
  101.      save area.  */
  102.   addr = saved_regs[SPARC_SP_REGNUM].addr;
  103.   sp = get_frame_memory_unsigned (this_frame, addr, 8);
  104.   for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
  105.        regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
  106.     saved_regs[regnum].addr = addr;

  107.   /* Handle StackGhost.  */
  108.   {
  109.     ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);

  110.     if (wcookie != 0)
  111.       {
  112.         ULONGEST i7;

  113.         addr = saved_regs[SPARC_I7_REGNUM].addr;
  114.         i7 = get_frame_memory_unsigned (this_frame, addr, 8);
  115.         trad_frame_set_value (saved_regs, SPARC_I7_REGNUM, i7 ^ wcookie);
  116.       }
  117.   }

  118.   /* TODO: Handle the floating-point registers.  */

  119.   return saved_regs;
  120. }

  121. static struct sparc_frame_cache *
  122. sparc64nbsd_sigcontext_frame_cache (struct frame_info *this_frame,
  123.                                     void **this_cache)
  124. {
  125.   struct sparc_frame_cache *cache;
  126.   CORE_ADDR addr;

  127.   if (*this_cache)
  128.     return *this_cache;

  129.   cache = sparc_frame_cache (this_frame, this_cache);
  130.   gdb_assert (cache == *this_cache);

  131.   /* If we couldn't find the frame's function, we're probably dealing
  132.      with an on-stack signal trampoline.  */
  133.   if (cache->pc == 0)
  134.     {
  135.       cache->pc = sparc64nbsd_sigtramp_start;

  136.       /* Since we couldn't find the frame's function, the cache was
  137.          initialized under the assumption that we're frameless.  */
  138.       sparc_record_save_insn (cache);
  139.       addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
  140.       if (addr & 1)
  141.         addr += BIAS;
  142.       cache->base = addr;
  143.     }

  144.   /* We find the appropriate instance of `struct sigcontext' at a
  145.      fixed offset in the signal frame.  */
  146.   addr = cache->base + 128 + 8;
  147.   cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, this_frame);

  148.   return cache;
  149. }

  150. static void
  151. sparc64nbsd_sigcontext_frame_this_id (struct frame_info *this_frame,
  152.                                       void **this_cache,
  153.                                       struct frame_id *this_id)
  154. {
  155.   struct sparc_frame_cache *cache =
  156.     sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);

  157.   (*this_id) = frame_id_build (cache->base, cache->pc);
  158. }

  159. static struct value *
  160. sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *this_frame,
  161.                                             void **this_cache, int regnum)
  162. {
  163.   struct sparc_frame_cache *cache =
  164.     sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);

  165.   return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
  166. }

  167. static int
  168. sparc64nbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
  169.                                     struct frame_info *this_frame,
  170.                                     void **this_cache)
  171. {
  172.   CORE_ADDR pc = get_frame_pc (this_frame);
  173.   const char *name;

  174.   find_pc_partial_function (pc, &name, NULL, NULL);
  175.   if (sparc64nbsd_pc_in_sigtramp (pc, name))
  176.     {
  177.       if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
  178.         return 1;
  179.     }

  180.   return 0;
  181. }

  182. static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind =
  183. {
  184.   SIGTRAMP_FRAME,
  185.   default_frame_unwind_stop_reason,
  186.   sparc64nbsd_sigcontext_frame_this_id,
  187.   sparc64nbsd_sigcontext_frame_prev_register,
  188.   NULL,
  189.   sparc64nbsd_sigtramp_frame_sniffer
  190. };


  191. static const struct regset sparc64nbsd_gregset =
  192.   {
  193.     NULL, sparc64nbsd_supply_gregset, NULL
  194.   };

  195. static const struct regset sparc64nbsd_fpregset =
  196.   {
  197.     NULL, sparc64nbsd_supply_fpregset, NULL
  198.   };

  199. static void
  200. sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  201. {
  202.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  203.   tdep->gregset = &sparc64nbsd_gregset;
  204.   tdep->sizeof_gregset = 160;

  205.   tdep->fpregset =  &sparc64nbsd_fpregset;
  206.   tdep->sizeof_fpregset = 272;

  207.   /* Make sure we can single-step "new" syscalls.  */
  208.   tdep->step_trap = sparcnbsd_step_trap;

  209.   frame_unwind_append_unwinder (gdbarch, &sparc64nbsd_sigcontext_frame_unwind);

  210.   sparc64_init_abi (info, gdbarch);

  211.   /* NetBSD/sparc64 has SVR4-style shared libraries.  */
  212.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  213.   set_solib_svr4_fetch_link_map_offsets
  214.     (gdbarch, svr4_lp64_fetch_link_map_offsets);
  215. }


  216. /* Provide a prototype to silence -Wmissing-prototypes.  */
  217. void _initialize_sparc64nbsd_tdep (void);

  218. void
  219. _initialize_sparc64nbsd_tdep (void)
  220. {
  221.   gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
  222.                           GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi);
  223. }