vax-bsd-nat.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Native-dependent code for modern VAX BSD's.
  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. /* 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 "target.h"
  20. #include <sys/types.h>
  21. #include <sys/ptrace.h>
  22. #include <machine/reg.h>
  23. #include "vax-tdep.h"
  24. #include "inf-ptrace.h"
  25. #include "netbsd-nat.h"
  26. struct vax_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 vax_bsd_nat_target the_vax_bsd_nat_target;
  32. /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
  33. static void
  34. vaxbsd_supply_gregset (struct regcache *regcache, const void *gregs)
  35. {
  36. const gdb_byte *regs = (const gdb_byte *)gregs;
  37. int regnum;
  38. for (regnum = 0; regnum < VAX_NUM_REGS; regnum++)
  39. regcache->raw_supply (regnum, regs + regnum * 4);
  40. }
  41. /* Collect the general-purpose registers from REGCACHE and store them
  42. in GREGS. */
  43. static void
  44. vaxbsd_collect_gregset (const struct regcache *regcache,
  45. void *gregs, int regnum)
  46. {
  47. gdb_byte *regs = (void *)gregs;
  48. int i;
  49. for (i = 0; i <= VAX_NUM_REGS; i++)
  50. {
  51. if (regnum == -1 || regnum == i)
  52. regcache->raw_collect (i, regs + i * 4);
  53. }
  54. }
  55. /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
  56. for all registers. */
  57. void
  58. vax_bsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
  59. {
  60. struct reg regs;
  61. pid_t pid = regcache->ptid ().pid ();
  62. int lwp = regcache->ptid ().lwp ();
  63. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
  64. perror_with_name (_("Couldn't get registers"));
  65. vaxbsd_supply_gregset (regcache, &regs);
  66. }
  67. /* Store register REGNUM back into the inferior. If REGNUM is -1, do
  68. this for all registers. */
  69. void
  70. vax_bsd_nat_target::store_registers (struct regcache *regcache, int regnum)
  71. {
  72. struct reg regs;
  73. pid_t pid = regcache->ptid ().pid ();
  74. int lwp = regcache->ptid ().lwp ();
  75. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
  76. perror_with_name (_("Couldn't get registers"));
  77. vaxbsd_collect_gregset (regcache, &regs, regnum);
  78. if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
  79. perror_with_name (_("Couldn't write registers"));
  80. }
  81. /* Support for debugging kernel virtual memory images. */
  82. #include <machine/pcb.h>
  83. #include "bsd-kvm.h"
  84. static int
  85. vaxbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  86. {
  87. int regnum;
  88. /* The following is true for OpenBSD 3.5:
  89. The pcb contains the register state at the context switch inside
  90. cpu_switch(). */
  91. /* The stack pointer shouldn't be zero. */
  92. if (pcb->KSP == 0)
  93. return 0;
  94. for (regnum = VAX_R0_REGNUM; regnum < VAX_AP_REGNUM; regnum++)
  95. regcache->raw_supply (regnum, &pcb->R[regnum - VAX_R0_REGNUM]);
  96. regcache->raw_supply (VAX_AP_REGNUM, &pcb->AP);
  97. regcache->raw_supply (VAX_FP_REGNUM, &pcb->FP);
  98. regcache->raw_supply (VAX_SP_REGNUM, &pcb->KSP);
  99. regcache->raw_supply (VAX_PC_REGNUM, &pcb->PC);
  100. regcache->raw_supply (VAX_PS_REGNUM, &pcb->PSL);
  101. return 1;
  102. }
  103. void _initialize_vaxbsd_nat ();
  104. void
  105. _initialize_vaxbsd_nat ()
  106. {
  107. add_inf_child_target (&the_vax_bsd_nat_target);
  108. /* Support debugging kernel virtual memory images. */
  109. bsd_kvm_add_target (vaxbsd_supply_pcb);
  110. }