sh-netbsd-nat.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Native-dependent code for NetBSD/sh.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Wasabi Systems, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "inferior.h"
  17. #include <sys/types.h>
  18. #include <sys/ptrace.h>
  19. #include <machine/reg.h>
  20. #include "sh-tdep.h"
  21. #include "inf-ptrace.h"
  22. #include "netbsd-nat.h"
  23. #include "regcache.h"
  24. struct sh_nbsd_nat_target final : public nbsd_nat_target
  25. {
  26. void fetch_registers (struct regcache *, int) override;
  27. void store_registers (struct regcache *, int) override;
  28. };
  29. static sh_nbsd_nat_target the_sh_nbsd_nat_target;
  30. /* Determine if PT_GETREGS fetches this register. */
  31. #define GETREGS_SUPPLIES(gdbarch, regno) \
  32. (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
  33. || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
  34. || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
  35. || (regno) == SR_REGNUM)
  36. /* Sizeof `struct reg' in <machine/reg.h>. */
  37. #define SHNBSD_SIZEOF_GREGS (21 * 4)
  38. void
  39. sh_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
  40. {
  41. pid_t pid = regcache->ptid ().pid ();
  42. int lwp = regcache->ptid ().lwp ();
  43. if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
  44. {
  45. struct reg inferior_registers;
  46. if (ptrace (PT_GETREGS, pid,
  47. (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
  48. perror_with_name (_("Couldn't get registers"));
  49. sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno,
  50. (char *) &inferior_registers,
  51. SHNBSD_SIZEOF_GREGS);
  52. if (regno != -1)
  53. return;
  54. }
  55. }
  56. void
  57. sh_nbsd_nat_target::store_registers (struct regcache *regcache, int regno)
  58. {
  59. pid_t pid = regcache->ptid ().pid ();
  60. int lwp = regcache->ptid ().lwp ();
  61. if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
  62. {
  63. struct reg inferior_registers;
  64. if (ptrace (PT_GETREGS, pid,
  65. (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
  66. perror_with_name (_("Couldn't get registers"));
  67. sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno,
  68. (char *) &inferior_registers,
  69. SHNBSD_SIZEOF_GREGS);
  70. if (ptrace (PT_SETREGS, pid,
  71. (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
  72. perror_with_name (_("Couldn't set registers"));
  73. if (regno != -1)
  74. return;
  75. }
  76. }
  77. void _initialize_shnbsd_nat ();
  78. void
  79. _initialize_shnbsd_nat ()
  80. {
  81. add_inf_child_target (&the_sh_nbsd_nat_target);
  82. }