mips-netbsd-nat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Native-dependent code for MIPS systems running NetBSD.
  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 "target.h"
  20. #include <sys/types.h>
  21. #include <sys/ptrace.h>
  22. #include <machine/reg.h>
  23. #include "mips-tdep.h"
  24. #include "mips-netbsd-tdep.h"
  25. #include "netbsd-nat.h"
  26. #include "inf-ptrace.h"
  27. class mips_nbsd_nat_target final : public nbsd_nat_target
  28. {
  29. void fetch_registers (struct regcache *, int) override;
  30. void store_registers (struct regcache *, int) override;
  31. };
  32. static mips_nbsd_nat_target the_mips_nbsd_nat_target;
  33. /* Determine if PT_GETREGS fetches this register. */
  34. static int
  35. getregs_supplies (struct gdbarch *gdbarch, int regno)
  36. {
  37. return ((regno) >= MIPS_ZERO_REGNUM
  38. && (regno) <= gdbarch_pc_regnum (gdbarch));
  39. }
  40. void
  41. mips_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
  42. {
  43. pid_t pid = regcache->ptid ().pid ();
  44. struct gdbarch *gdbarch = regcache->arch ();
  45. if (regno == -1 || getregs_supplies (gdbarch, regno))
  46. {
  47. struct reg regs;
  48. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  49. perror_with_name (_("Couldn't get registers"));
  50. mipsnbsd_supply_reg (regcache, (char *) &regs, regno);
  51. if (regno != -1)
  52. return;
  53. }
  54. if (regno == -1
  55. || regno >= gdbarch_fp0_regnum (regcache->arch ()))
  56. {
  57. struct fpreg fpregs;
  58. if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  59. perror_with_name (_("Couldn't get floating point status"));
  60. mipsnbsd_supply_fpreg (regcache, (char *) &fpregs, regno);
  61. }
  62. }
  63. void
  64. mips_nbsd_nat_target::store_registers (struct regcache *regcache, int regno)
  65. {
  66. pid_t pid = regcache->ptid ().pid ();
  67. struct gdbarch *gdbarch = regcache->arch ();
  68. if (regno == -1 || getregs_supplies (gdbarch, regno))
  69. {
  70. struct reg regs;
  71. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  72. perror_with_name (_("Couldn't get registers"));
  73. mipsnbsd_fill_reg (regcache, (char *) &regs, regno);
  74. if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  75. perror_with_name (_("Couldn't write registers"));
  76. if (regno != -1)
  77. return;
  78. }
  79. if (regno == -1
  80. || regno >= gdbarch_fp0_regnum (regcache->arch ()))
  81. {
  82. struct fpreg fpregs;
  83. if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  84. perror_with_name (_("Couldn't get floating point status"));
  85. mipsnbsd_fill_fpreg (regcache, (char *) &fpregs, regno);
  86. if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  87. perror_with_name (_("Couldn't write floating point status"));
  88. }
  89. }
  90. void _initialize_mipsnbsd_nat ();
  91. void
  92. _initialize_mipsnbsd_nat ()
  93. {
  94. add_inf_child_target (&the_mips_nbsd_nat_target);
  95. }