sparc64-obsd-nat.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Native-dependent code for OpenBSD/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. #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 (SPARC_SP_REGNUM, &pcb->pcb_sp);
  74. regcache->raw_supply (SPARC64_PC_REGNUM, &pcb->pcb_pc);
  75. state = pcb->pcb_pstate << 8 | pcb->pcb_cwp;
  76. regcache->raw_supply (SPARC64_STATE_REGNUM, &state);
  77. sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
  78. return 1;
  79. }
  80. /* Add some extra features to the generic SPARC target. */
  81. static sparc_target<obsd_nat_target> the_sparc64_obsd_nat_target;
  82. void _initialize_sparc64obsd_nat ();
  83. void
  84. _initialize_sparc64obsd_nat ()
  85. {
  86. sparc_supply_gregset = sparc64_supply_gregset;
  87. sparc_collect_gregset = sparc64_collect_gregset;
  88. sparc_supply_fpregset = sparc64_supply_fpregset;
  89. sparc_collect_fpregset = sparc64_collect_fpregset;
  90. sparc_gregset_supplies_p = sparc64obsd_gregset_supplies_p;
  91. sparc_fpregset_supplies_p = sparc64obsd_fpregset_supplies_p;
  92. sparc_gregmap = &sparc64nbsd_gregmap;
  93. sparc_fpregmap = &sparc64_bsd_fpregmap;
  94. /* Add some extra features to the generic SPARC target. */
  95. add_inf_child_target (&the_sparc64_obsd_nat_target);
  96. /* Support debugging kernel virtual memory images. */
  97. bsd_kvm_add_target (sparc64obsd_supply_pcb);
  98. }