sparc64-netbsd-nat.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Native-dependent code for NetBSD/sparc64.
  2. Copyright (C) 2003-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 "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 (regcache->arch ()) == 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 (regcache->arch ()) == 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 (regcache->arch ()) == 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 (regcache->arch ()) == 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 (SPARC_SP_REGNUM, &pcb->pcb_sp);
  124. regcache->raw_supply (SPARC64_PC_REGNUM, &pcb->pcb_pc);
  125. state = pcb->pcb_pstate << 8 | pcb->pcb_cwp;
  126. regcache->raw_supply (SPARC64_STATE_REGNUM, &state);
  127. sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
  128. return 1;
  129. }
  130. /* We've got nothing to add to the generic SPARC target. */
  131. static sparc_target<inf_ptrace_target> the_sparc64_nbsd_nat_target;
  132. void _initialize_sparc64nbsd_nat ();
  133. void
  134. _initialize_sparc64nbsd_nat ()
  135. {
  136. sparc_supply_gregset = sparc64nbsd_supply_gregset;
  137. sparc_collect_gregset = sparc64nbsd_collect_gregset;
  138. sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
  139. sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
  140. sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
  141. sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
  142. add_inf_child_target (&the_sparc64_nbsd_nat_target);
  143. /* Support debugging kernel virtual memory images. */
  144. bsd_kvm_add_target (sparc64nbsd_supply_pcb);
  145. }