mips64-obsd-nat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Native-dependent code for OpenBSD/mips64.
  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. #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 "mips-tdep.h"
  22. #include "inf-ptrace.h"
  23. #include "obsd-nat.h"
  24. /* Shorthand for some register numbers used below. */
  25. #define MIPS_PC_REGNUM MIPS_EMBED_PC_REGNUM
  26. #define MIPS_FP0_REGNUM MIPS_EMBED_FP0_REGNUM
  27. #define MIPS_FSR_REGNUM MIPS_EMBED_FP0_REGNUM + 32
  28. struct mips64_obsd_nat_target final : public obsd_nat_target
  29. {
  30. void fetch_registers (struct regcache *, int) override;
  31. void store_registers (struct regcache *, int) override;
  32. };
  33. static mips64_obsd_nat_target the_mips64_obsd_nat_target;
  34. /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
  35. static void
  36. mips64obsd_supply_gregset (struct regcache *regcache, const void *gregs)
  37. {
  38. const char *regs = gregs;
  39. int regnum;
  40. for (regnum = MIPS_ZERO_REGNUM; regnum <= MIPS_PC_REGNUM; regnum++)
  41. regcache->raw_supply (regnum, regs + regnum * 8);
  42. for (regnum = MIPS_FP0_REGNUM; regnum <= MIPS_FSR_REGNUM; regnum++)
  43. regcache->raw_supply (regnum, regs + (regnum + 2) * 8);
  44. }
  45. /* Collect the general-purpose registers from REGCACHE and store them
  46. in GREGS. */
  47. static void
  48. mips64obsd_collect_gregset (const struct regcache *regcache,
  49. void *gregs, int regnum)
  50. {
  51. char *regs = gregs;
  52. int i;
  53. for (i = MIPS_ZERO_REGNUM; i <= MIPS_PC_REGNUM; i++)
  54. {
  55. if (regnum == -1 || regnum == i)
  56. regcache->raw_collect (i, regs + i * 8);
  57. }
  58. for (i = MIPS_FP0_REGNUM; i <= MIPS_FSR_REGNUM; i++)
  59. {
  60. if (regnum == -1 || regnum == i)
  61. regcache->raw_collect (i, regs + (i + 2) * 8);
  62. }
  63. }
  64. /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
  65. for all registers. */
  66. void
  67. mips64_obsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
  68. {
  69. struct reg regs;
  70. pid_t pid = regcache->ptid ().pid ();
  71. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  72. perror_with_name (_("Couldn't get registers"));
  73. mips64obsd_supply_gregset (regcache, &regs);
  74. }
  75. /* Store register REGNUM back into the inferior. If REGNUM is -1, do
  76. this for all registers. */
  77. static void
  78. mips64_obsd_nat_target::store_registers (struct regcache *regcache, int regnum)
  79. {
  80. struct reg regs;
  81. pid_t pid = regcache->ptid ().pid ();
  82. if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  83. perror_with_name (_("Couldn't get registers"));
  84. mips64obsd_collect_gregset (regcache, &regs, regnum);
  85. if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  86. perror_with_name (_("Couldn't write registers"));
  87. }
  88. void _initialize_mips64obsd_nat ();
  89. void
  90. _initialize_mips64obsd_nat ()
  91. {
  92. add_inf_child_target (&the_mips64_obsd_nat_target);
  93. }