gdb/hppaobsd-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for OpenBSD/hppa

  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 "osabi.h"
  16. #include "regcache.h"
  17. #include "regset.h"

  18. #include "hppa-tdep.h"
  19. #include "hppabsd-tdep.h"

  20. /* Core file support.  */

  21. /* Sizeof `struct reg' in <machine/reg.h>.  */
  22. #define HPPAOBSD_SIZEOF_GREGS        (34 * 4) /* OpenBSD 5.1 and earlier.  */
  23. #define HPPANBSD_SIZEOF_GREGS        (46 * 4) /* NetBSD and OpenBSD 5.2 and later.  */

  24. /* Sizeof `struct fpreg' in <machine/reg.h>.  */
  25. #define HPPAOBSD_SIZEOF_FPREGS        (32 * 8)

  26. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  27.    in the general-purpose register set REGSET to register cache
  28.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  29. static void
  30. hppaobsd_supply_gregset (const struct regset *regset,
  31.                          struct regcache *regcache,
  32.                          int regnum, const void *gregs, size_t len)
  33. {
  34.   gdb_byte zero[4] = { 0 };
  35.   const gdb_byte *regs = gregs;
  36.   size_t offset;
  37.   int i;

  38.   gdb_assert (len >= HPPAOBSD_SIZEOF_GREGS);

  39.   if (regnum == -1 || regnum == HPPA_R0_REGNUM)
  40.     regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero);
  41.   for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4)
  42.     {
  43.       if (regnum == -1 || regnum == i)
  44.         regcache_raw_supply (regcache, i, regs + offset);
  45.     }

  46.   if (len >= HPPANBSD_SIZEOF_GREGS)
  47.     {
  48.       if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
  49.         regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
  50.       if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
  51.         regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
  52.       if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
  53.         regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
  54.       if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
  55.         regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
  56.       if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  57.         regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
  58.       if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  59.         regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
  60.       if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
  61.         regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
  62.       if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
  63.         regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
  64.       if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
  65.         regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
  66.       if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
  67.         regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
  68.       if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
  69.         regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
  70.       if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
  71.         regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
  72.       if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
  73.         regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
  74.       if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
  75.         regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
  76.       if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
  77.         regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
  78.       if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
  79.         regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
  80.     }
  81.   else
  82.     {
  83.       if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
  84.         regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
  85.       if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  86.         regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
  87.       if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  88.         regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
  89.     }
  90. }

  91. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  92.    in the floating-point register set REGSET to register cache
  93.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  94. static void
  95. hppaobsd_supply_fpregset (const struct regset *regset,
  96.                           struct regcache *regcache,
  97.                           int regnum, const void *fpregs, size_t len)
  98. {
  99.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  100.   const gdb_byte *regs = fpregs;
  101.   int i;

  102.   gdb_assert (len >= HPPAOBSD_SIZEOF_FPREGS);

  103.   for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i++)
  104.     {
  105.       if (regnum == i || regnum == -1)
  106.         regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4);
  107.     }
  108. }

  109. /* OpenBSD/hppa register sets.  */

  110. static const struct regset hppaobsd_gregset =
  111. {
  112.   NULL,
  113.   hppaobsd_supply_gregset
  114. };

  115. static const struct regset hppaobsd_fpregset =
  116. {
  117.   NULL,
  118.   hppaobsd_supply_fpregset
  119. };

  120. /* Iterate over supported core file register note sections. */

  121. static void
  122. hppaobsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  123.                                        iterate_over_regset_sections_cb *cb,
  124.                                        void *cb_data,
  125.                                        const struct regcache *regcache)
  126. {
  127.   cb (".reg", HPPAOBSD_SIZEOF_GREGS, &hppaobsd_gregset, NULL, cb_data);
  128.   cb (".reg2", HPPAOBSD_SIZEOF_FPREGS, &hppaobsd_fpregset, NULL, cb_data);
  129. }


  130. static void
  131. hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  132. {
  133.   /* Obviously OpenBSD is BSD-based.  */
  134.   hppabsd_init_abi (info, gdbarch);

  135.   /* Core file support.  */
  136.   set_gdbarch_iterate_over_regset_sections
  137.     (gdbarch, hppaobsd_iterate_over_regset_sections);
  138. }


  139. /* OpenBSD uses uses the traditional NetBSD core file format, even for
  140.    ports that use ELF.  */
  141. #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF

  142. static enum gdb_osabi
  143. hppaobsd_core_osabi_sniffer (bfd *abfd)
  144. {
  145.   if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
  146.     return GDB_OSABI_NETBSD_CORE;

  147.   return GDB_OSABI_UNKNOWN;
  148. }


  149. /* Provide a prototype to silence -Wmissing-prototypes.  */
  150. void _initialize_hppabsd_tdep (void);

  151. void
  152. _initialize_hppabsd_tdep (void)
  153. {
  154.   /* BFD doesn't set a flavour for NetBSD style a.out core files.  */
  155.   gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour,
  156.                                   hppaobsd_core_osabi_sniffer);

  157.   gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF,
  158.                           hppaobsd_init_abi);
  159. }