alpha-bsd-nat.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Native-dependent code for Alpha BSD's.
  2. Copyright (C) 2000-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. /* We define this to get types like register_t. */
  15. #define _KERNTYPES
  16. #include "defs.h"
  17. #include "inferior.h"
  18. #include "regcache.h"
  19. #include "alpha-tdep.h"
  20. #include "alpha-bsd-tdep.h"
  21. #include "inf-ptrace.h"
  22. #include "netbsd-nat.h"
  23. #include <sys/types.h>
  24. #include <sys/ptrace.h>
  25. #include <machine/reg.h>
  26. struct alpha_bsd_nat_target final : public nbsd_nat_target
  27. {
  28. void fetch_registers (struct regcache *, int) override;
  29. void store_registers (struct regcache *, int) override;
  30. };
  31. static alpha_bsd_nat_target the_alpha_bsd_nat_target;
  32. /* Determine if PT_GETREGS fetches this register. */
  33. static int
  34. getregs_supplies (int regno)
  35. {
  36. return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
  37. || regno >= ALPHA_PC_REGNUM);
  38. }
  39. /* Fetch register REGNO from the inferior. If REGNO is -1, do this
  40. for all registers (including the floating point registers). */
  41. void
  42. alpha_bsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
  43. {
  44. int lwp = regcache->ptid ().lwp ();
  45. if (regno == -1 || getregs_supplies (regno))
  46. {
  47. struct reg gregs;
  48. if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
  49. (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
  50. perror_with_name (_("Couldn't get registers"));
  51. alphabsd_supply_reg (regcache, (char *) &gregs, regno);
  52. if (regno != -1)
  53. return;
  54. }
  55. if (regno == -1
  56. || regno >= gdbarch_fp0_regnum (regcache->arch ()))
  57. {
  58. struct fpreg fpregs;
  59. if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
  60. (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
  61. perror_with_name (_("Couldn't get floating point status"));
  62. alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
  63. }
  64. }
  65. /* Store register REGNO back into the inferior. If REGNO is -1, do
  66. this for all registers (including the floating point registers). */
  67. void
  68. alpha_bsd_nat_target::store_registers (struct regcache *regcache, int regno)
  69. {
  70. int lwp = regcache->ptid ().lwp ();
  71. if (regno == -1 || getregs_supplies (regno))
  72. {
  73. struct reg gregs;
  74. if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
  75. (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
  76. perror_with_name (_("Couldn't get registers"));
  77. alphabsd_fill_reg (regcache, (char *) &gregs, regno);
  78. if (ptrace (PT_SETREGS, regcache->ptid ().pid (),
  79. (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
  80. perror_with_name (_("Couldn't write registers"));
  81. if (regno != -1)
  82. return;
  83. }
  84. if (regno == -1
  85. || regno >= gdbarch_fp0_regnum (regcache->arch ()))
  86. {
  87. struct fpreg fpregs;
  88. if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
  89. (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
  90. perror_with_name (_("Couldn't get floating point status"));
  91. alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
  92. if (ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
  93. (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
  94. perror_with_name (_("Couldn't write floating point status"));
  95. }
  96. }
  97. /* Support for debugging kernel virtual memory images. */
  98. #include <sys/signal.h>
  99. #include <machine/pcb.h>
  100. #include "bsd-kvm.h"
  101. static int
  102. alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  103. {
  104. int regnum;
  105. /* The following is true for OpenBSD 3.9:
  106. The pcb contains the register state at the context switch inside
  107. cpu_switch(). */
  108. /* The stack pointer shouldn't be zero. */
  109. if (pcb->pcb_hw.apcb_ksp == 0)
  110. return 0;
  111. regcache->raw_supply (ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
  112. for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
  113. regcache->raw_supply (regnum, &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
  114. regcache->raw_supply (ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
  115. return 1;
  116. }
  117. void _initialize_alphabsd_nat ();
  118. void
  119. _initialize_alphabsd_nat ()
  120. {
  121. add_inf_child_target (&the_alpha_bsd_nat_target);
  122. /* Support debugging kernel virtual memory images. */
  123. bsd_kvm_add_target (alphabsd_supply_pcb);
  124. }