mips-fbsd-nat.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Native-dependent code for FreeBSD/mips.
  2. Copyright (C) 2017-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 "inferior.h"
  16. #include "regcache.h"
  17. #include "target.h"
  18. #include <sys/types.h>
  19. #include <sys/ptrace.h>
  20. #include <machine/reg.h>
  21. #include "fbsd-nat.h"
  22. #include "mips-tdep.h"
  23. #include "mips-fbsd-tdep.h"
  24. #include "inf-ptrace.h"
  25. struct mips_fbsd_nat_target final : public fbsd_nat_target
  26. {
  27. void fetch_registers (struct regcache *, int) override;
  28. void store_registers (struct regcache *, int) override;
  29. };
  30. static mips_fbsd_nat_target the_mips_fbsd_nat_target;
  31. /* Determine if PT_GETREGS fetches REGNUM. */
  32. static bool
  33. getregs_supplies (struct gdbarch *gdbarch, int regnum)
  34. {
  35. return (regnum >= MIPS_ZERO_REGNUM
  36. && regnum <= mips_regnum (gdbarch)->pc);
  37. }
  38. /* Determine if PT_GETFPREGS fetches REGNUM. */
  39. static bool
  40. getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
  41. {
  42. return (regnum >= mips_regnum (gdbarch)->fp0
  43. && regnum <= mips_regnum (gdbarch)->fp_implementation_revision);
  44. }
  45. /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
  46. for all registers. */
  47. void
  48. mips_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
  49. {
  50. pid_t pid = get_ptrace_pid (regcache->ptid ());
  51. struct gdbarch *gdbarch = regcache->arch ();
  52. if (regnum == -1 || getregs_supplies (gdbarch, regnum))
  53. {
  54. struct reg regs;
  55. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  56. perror_with_name (_("Couldn't get registers"));
  57. mips_fbsd_supply_gregs (regcache, regnum, &regs, sizeof (register_t));
  58. }
  59. if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
  60. {
  61. struct fpreg fpregs;
  62. if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  63. perror_with_name (_("Couldn't get floating point status"));
  64. mips_fbsd_supply_fpregs (regcache, regnum, &fpregs,
  65. sizeof (f_register_t));
  66. }
  67. }
  68. /* Store register REGNUM back into the inferior. If REGNUM is -1, do
  69. this for all registers. */
  70. void
  71. mips_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
  72. {
  73. pid_t pid = get_ptrace_pid (regcache->ptid ());
  74. struct gdbarch *gdbarch = regcache->arch ();
  75. if (regnum == -1 || getregs_supplies (gdbarch, regnum))
  76. {
  77. struct reg regs;
  78. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  79. perror_with_name (_("Couldn't get registers"));
  80. mips_fbsd_collect_gregs (regcache, regnum, (char *) &regs,
  81. sizeof (register_t));
  82. if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  83. perror_with_name (_("Couldn't write registers"));
  84. }
  85. if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
  86. {
  87. struct fpreg fpregs;
  88. if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  89. perror_with_name (_("Couldn't get floating point status"));
  90. mips_fbsd_collect_fpregs (regcache, regnum, (char *) &fpregs,
  91. sizeof (f_register_t));
  92. if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  93. perror_with_name (_("Couldn't write floating point status"));
  94. }
  95. }
  96. void _initialize_mips_fbsd_nat ();
  97. void
  98. _initialize_mips_fbsd_nat ()
  99. {
  100. add_inf_child_target (&the_mips_fbsd_nat_target);
  101. }