tilegx-linux-nat.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Native-dependent code for GNU/Linux TILE-Gx.
  2. Copyright (C) 2012-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 "gdbcore.h"
  17. #include "regcache.h"
  18. #include "linux-nat.h"
  19. #include "inf-ptrace.h"
  20. #include "nat/gdb_ptrace.h"
  21. #include <sys/procfs.h>
  22. /* Defines ps_err_e, struct ps_prochandle. */
  23. #include "gdb_proc_service.h"
  24. /* Prototypes for supply_gregset etc. */
  25. #include "gregset.h"
  26. class tilegx_linux_nat_target final : public linux_nat_target
  27. {
  28. public:
  29. /* Add our register access methods. */
  30. void fetch_registers (struct regcache *, int) override;
  31. void store_registers (struct regcache *, int) override;
  32. };
  33. static tilegx_linux_nat_target the_tilegx_linux_nat_target;
  34. /* The register sets used in GNU/Linux ELF core-dumps are identical to
  35. the register sets in `struct user' that is used for a.out
  36. core-dumps, and is also used by `ptrace'. The corresponding types
  37. are `elf_gregset_t' for the general-purpose registers (with
  38. `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
  39. for the floating-point registers.
  40. Those types used to be available under the names `gregset_t' and
  41. `fpregset_t' too, and this file used those names in the past. But
  42. those names are now used for the register sets used in the
  43. `mcontext_t' type, and have a different size and layout. */
  44. /* Mapping between the general-purpose registers in `struct user'
  45. format and GDB's register array layout. Note that we map the
  46. first 56 registers (0 thru 55) one-to-one. GDB maps the pc to
  47. slot 64, but ptrace returns it in slot 56. */
  48. static const int regmap[] =
  49. {
  50. 0, 1, 2, 3, 4, 5, 6, 7,
  51. 8, 9, 10, 11, 12, 13, 14, 15,
  52. 16, 17, 18, 19, 20, 21, 22, 23,
  53. 24, 25, 26, 27, 28, 29, 30, 31,
  54. 32, 33, 34, 35, 36, 37, 38, 39,
  55. 40, 41, 42, 43, 44, 45, 46, 47,
  56. 48, 49, 50, 51, 52, 53, 54, 55,
  57. -1, -1, -1, -1, -1, -1, -1, -1,
  58. 56, 58
  59. };
  60. /* Transfering the general-purpose registers between GDB, inferiors
  61. and core files. */
  62. /* Fill GDB's register array with the general-purpose register values
  63. in *GREGSETP. */
  64. void
  65. supply_gregset (struct regcache* regcache,
  66. const elf_gregset_t *gregsetp)
  67. {
  68. elf_greg_t *regp = (elf_greg_t *) gregsetp;
  69. int i;
  70. for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
  71. if (regmap[i] >= 0)
  72. regcache->raw_supply (i, regp + regmap[i]);
  73. }
  74. /* Fill registers in *GREGSETPS with the values in GDB's
  75. register array. */
  76. void
  77. fill_gregset (const struct regcache* regcache,
  78. elf_gregset_t *gregsetp, int regno)
  79. {
  80. elf_greg_t *regp = (elf_greg_t *) gregsetp;
  81. int i;
  82. for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
  83. if (regmap[i] >= 0)
  84. regcache->raw_collect (i, regp + regmap[i]);
  85. }
  86. /* Transfering floating-point registers between GDB, inferiors and cores. */
  87. /* Fill GDB's register array with the floating-point register values in
  88. *FPREGSETP. */
  89. void
  90. supply_fpregset (struct regcache *regcache,
  91. const elf_fpregset_t *fpregsetp)
  92. {
  93. /* NOTE: There are no floating-point registers for TILE-Gx. */
  94. }
  95. /* Fill register REGNO (if it is a floating-point register) in
  96. *FPREGSETP with the value in GDB's register array. If REGNO is -1,
  97. do this for all registers. */
  98. void
  99. fill_fpregset (const struct regcache *regcache,
  100. elf_fpregset_t *fpregsetp, int regno)
  101. {
  102. /* NOTE: There are no floating-point registers for TILE-Gx. */
  103. }
  104. /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
  105. for all registers. */
  106. void
  107. tilegx_linux_nat_target::fetch_registers (struct regcache *regcache,
  108. int regnum)
  109. {
  110. elf_gregset_t regs;
  111. pid_t tid = get_ptrace_pid (regcache->ptid ());
  112. if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  113. perror_with_name (_("Couldn't get registers"));
  114. supply_gregset (regcache, (const elf_gregset_t *)&regs);
  115. }
  116. /* Store register REGNUM back into the inferior. If REGNUM is -1, do
  117. this for all registers. */
  118. void
  119. tilegx_linux_nat_target::store_registers (struct regcache *regcache,
  120. int regnum)
  121. {
  122. elf_gregset_t regs;
  123. pid_t tid = get_ptrace_pid (regcache->ptid ());
  124. if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  125. perror_with_name (_("Couldn't get registers"));
  126. fill_gregset (regcache, &regs, regnum);
  127. if (ptrace (PTRACE_SETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  128. perror_with_name (_("Couldn't write registers"));
  129. }
  130. void _initialize_tile_linux_nat ();
  131. void
  132. _initialize_tile_linux_nat ()
  133. {
  134. linux_target = &the_tilegx_linux_nat_target;
  135. add_inf_child_target (&the_tilegx_linux_nat_target);
  136. }