hppa-obsd-tdep.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* Target-dependent code for OpenBSD/hppa
  2. Copyright (C) 2004-2022 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 "hppa-bsd-tdep.h"
  20. #include "gdbarch.h"
  21. /* Core file support. */
  22. /* Sizeof `struct reg' in <machine/reg.h>. */
  23. #define HPPAOBSD_SIZEOF_GREGS (34 * 4) /* OpenBSD 5.1 and earlier. */
  24. #define HPPANBSD_SIZEOF_GREGS (46 * 4) /* NetBSD and OpenBSD 5.2 and later. */
  25. /* Sizeof `struct fpreg' in <machine/reg.h>. */
  26. #define HPPAOBSD_SIZEOF_FPREGS (32 * 8)
  27. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  28. in the general-purpose register set REGSET to register cache
  29. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  30. static void
  31. hppaobsd_supply_gregset (const struct regset *regset,
  32. struct regcache *regcache,
  33. int regnum, const void *gregs, size_t len)
  34. {
  35. gdb_byte zero[4] = { 0 };
  36. const gdb_byte *regs = (const gdb_byte *) gregs;
  37. size_t offset;
  38. int i;
  39. gdb_assert (len >= HPPAOBSD_SIZEOF_GREGS);
  40. if (regnum == -1 || regnum == HPPA_R0_REGNUM)
  41. regcache->raw_supply (HPPA_R0_REGNUM, &zero);
  42. for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4)
  43. {
  44. if (regnum == -1 || regnum == i)
  45. regcache->raw_supply (i, regs + offset);
  46. }
  47. if (len >= HPPANBSD_SIZEOF_GREGS)
  48. {
  49. if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
  50. regcache->raw_supply (HPPA_IPSW_REGNUM, regs);
  51. if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
  52. regcache->raw_supply (HPPA_SAR_REGNUM, regs + 32 * 4);
  53. if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
  54. regcache->raw_supply (HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
  55. if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
  56. regcache->raw_supply (HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
  57. if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  58. regcache->raw_supply (HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
  59. if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  60. regcache->raw_supply (HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
  61. if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
  62. regcache->raw_supply (HPPA_SR0_REGNUM, regs + 37 * 4);
  63. if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
  64. regcache->raw_supply (HPPA_SR1_REGNUM, regs + 38 * 4);
  65. if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
  66. regcache->raw_supply (HPPA_SR2_REGNUM, regs + 39 * 4);
  67. if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
  68. regcache->raw_supply (HPPA_SR3_REGNUM, regs + 40 * 4);
  69. if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
  70. regcache->raw_supply (HPPA_SR4_REGNUM, regs + 41 * 4);
  71. if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
  72. regcache->raw_supply (HPPA_SR5_REGNUM, regs + 42 * 4);
  73. if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
  74. regcache->raw_supply (HPPA_SR6_REGNUM, regs + 43 * 4);
  75. if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
  76. regcache->raw_supply (HPPA_SR7_REGNUM, regs + 44 * 4);
  77. if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
  78. regcache->raw_supply (HPPA_CR26_REGNUM, regs + 45 * 4);
  79. if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
  80. regcache->raw_supply (HPPA_CR27_REGNUM, regs + 46 * 4);
  81. }
  82. else
  83. {
  84. if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
  85. regcache->raw_supply (HPPA_SAR_REGNUM, regs);
  86. if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
  87. regcache->raw_supply (HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
  88. if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
  89. regcache->raw_supply (HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
  90. }
  91. }
  92. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  93. in the floating-point register set REGSET to register cache
  94. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  95. static void
  96. hppaobsd_supply_fpregset (const struct regset *regset,
  97. struct regcache *regcache,
  98. int regnum, const void *fpregs, size_t len)
  99. {
  100. const gdb_byte *regs = (const gdb_byte *) 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 (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. NULL,
  115. REGSET_VARIABLE_SIZE
  116. };
  117. static const struct regset hppaobsd_fpregset =
  118. {
  119. NULL,
  120. hppaobsd_supply_fpregset
  121. };
  122. /* Iterate over supported core file register note sections. */
  123. static void
  124. hppaobsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  125. iterate_over_regset_sections_cb *cb,
  126. void *cb_data,
  127. const struct regcache *regcache)
  128. {
  129. cb (".reg", HPPAOBSD_SIZEOF_GREGS, HPPAOBSD_SIZEOF_GREGS, &hppaobsd_gregset,
  130. NULL, cb_data);
  131. cb (".reg2", HPPAOBSD_SIZEOF_FPREGS, HPPAOBSD_SIZEOF_FPREGS,
  132. &hppaobsd_fpregset, NULL, cb_data);
  133. }
  134. static void
  135. hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  136. {
  137. /* Obviously OpenBSD is BSD-based. */
  138. hppabsd_init_abi (info, gdbarch);
  139. /* Core file support. */
  140. set_gdbarch_iterate_over_regset_sections
  141. (gdbarch, hppaobsd_iterate_over_regset_sections);
  142. }
  143. void _initialize_hppabsd_tdep ();
  144. void
  145. _initialize_hppabsd_tdep ()
  146. {
  147. gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD,
  148. hppaobsd_init_abi);
  149. }