arm-none-tdep.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* none on ARM target support.
  2. Copyright (C) 2020-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 "arm-tdep.h"
  16. #include "arch-utils.h"
  17. #include "regcache.h"
  18. #include "elf-bfd.h"
  19. #include "regset.h"
  20. #include "user-regs.h"
  21. #ifdef HAVE_ELF
  22. #include "elf-none-tdep.h"
  23. #endif
  24. /* Core file and register set support. */
  25. #define ARM_NONE_SIZEOF_GREGSET (18 * ARM_INT_REGISTER_SIZE)
  26. /* Support VFP register format. */
  27. #define ARM_NONE_SIZEOF_VFP (32 * 8 + 4)
  28. /* The index to access CPSR in user_regs as defined in GLIBC. */
  29. #define ARM_NONE_CPSR_GREGNUM 16
  30. /* Supply register REGNUM from buffer GREGS_BUF (length LEN bytes) into
  31. REGCACHE. If REGNUM is -1 then supply all registers. The set of
  32. registers that this function will supply is limited to the general
  33. purpose registers.
  34. The layout of the registers here is based on the ARM GNU/Linux
  35. layout. */
  36. static void
  37. arm_none_supply_gregset (const struct regset *regset,
  38. struct regcache *regcache,
  39. int regnum, const void *gregs_buf, size_t len)
  40. {
  41. struct gdbarch *gdbarch = regcache->arch ();
  42. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  43. const gdb_byte *gregs = (const gdb_byte *) gregs_buf;
  44. for (int regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
  45. if (regnum == -1 || regnum == regno)
  46. regcache->raw_supply (regno, gregs + ARM_INT_REGISTER_SIZE * regno);
  47. if (regnum == ARM_PS_REGNUM || regnum == -1)
  48. {
  49. if (arm_apcs_32)
  50. regcache->raw_supply (ARM_PS_REGNUM,
  51. gregs + ARM_INT_REGISTER_SIZE
  52. * ARM_NONE_CPSR_GREGNUM);
  53. else
  54. regcache->raw_supply (ARM_PS_REGNUM,
  55. gregs + ARM_INT_REGISTER_SIZE * ARM_PC_REGNUM);
  56. }
  57. if (regnum == ARM_PC_REGNUM || regnum == -1)
  58. {
  59. gdb_byte pc_buf[ARM_INT_REGISTER_SIZE];
  60. CORE_ADDR reg_pc
  61. = extract_unsigned_integer (gregs + ARM_INT_REGISTER_SIZE
  62. * ARM_PC_REGNUM,
  63. ARM_INT_REGISTER_SIZE, byte_order);
  64. reg_pc = gdbarch_addr_bits_remove (gdbarch, reg_pc);
  65. store_unsigned_integer (pc_buf, ARM_INT_REGISTER_SIZE, byte_order,
  66. reg_pc);
  67. regcache->raw_supply (ARM_PC_REGNUM, pc_buf);
  68. }
  69. }
  70. /* Collect register REGNUM from REGCACHE and place it into buffer GREGS_BUF
  71. (length LEN bytes). If REGNUM is -1 then collect all registers. The
  72. set of registers that this function will collect is limited to the
  73. general purpose registers.
  74. The layout of the registers here is based on the ARM GNU/Linux
  75. layout. */
  76. static void
  77. arm_none_collect_gregset (const struct regset *regset,
  78. const struct regcache *regcache,
  79. int regnum, void *gregs_buf, size_t len)
  80. {
  81. gdb_byte *gregs = (gdb_byte *) gregs_buf;
  82. for (int regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
  83. if (regnum == -1 || regnum == regno)
  84. regcache->raw_collect (regno,
  85. gregs + ARM_INT_REGISTER_SIZE * regno);
  86. if (regnum == ARM_PS_REGNUM || regnum == -1)
  87. {
  88. if (arm_apcs_32)
  89. regcache->raw_collect (ARM_PS_REGNUM,
  90. gregs + ARM_INT_REGISTER_SIZE
  91. * ARM_NONE_CPSR_GREGNUM);
  92. else
  93. regcache->raw_collect (ARM_PS_REGNUM,
  94. gregs + ARM_INT_REGISTER_SIZE * ARM_PC_REGNUM);
  95. }
  96. if (regnum == ARM_PC_REGNUM || regnum == -1)
  97. regcache->raw_collect (ARM_PC_REGNUM,
  98. gregs + ARM_INT_REGISTER_SIZE * ARM_PC_REGNUM);
  99. }
  100. /* Supply VFP registers from REGS_BUF into REGCACHE. */
  101. static void
  102. arm_none_supply_vfp (const struct regset *regset,
  103. struct regcache *regcache,
  104. int regnum, const void *regs_buf, size_t len)
  105. {
  106. const gdb_byte *regs = (const gdb_byte *) regs_buf;
  107. if (regnum == ARM_FPSCR_REGNUM || regnum == -1)
  108. regcache->raw_supply (ARM_FPSCR_REGNUM, regs + 32 * 8);
  109. for (int regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++)
  110. if (regnum == -1 || regnum == regno)
  111. regcache->raw_supply (regno, regs + (regno - ARM_D0_REGNUM) * 8);
  112. }
  113. /* Collect VFP registers from REGCACHE into REGS_BUF. */
  114. static void
  115. arm_none_collect_vfp (const struct regset *regset,
  116. const struct regcache *regcache,
  117. int regnum, void *regs_buf, size_t len)
  118. {
  119. gdb_byte *regs = (gdb_byte *) regs_buf;
  120. if (regnum == ARM_FPSCR_REGNUM || regnum == -1)
  121. regcache->raw_collect (ARM_FPSCR_REGNUM, regs + 32 * 8);
  122. for (int regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++)
  123. if (regnum == -1 || regnum == regno)
  124. regcache->raw_collect (regno, regs + (regno - ARM_D0_REGNUM) * 8);
  125. }
  126. /* The general purpose register set. */
  127. static const struct regset arm_none_gregset =
  128. {
  129. nullptr, arm_none_supply_gregset, arm_none_collect_gregset
  130. };
  131. /* The VFP register set. */
  132. static const struct regset arm_none_vfpregset =
  133. {
  134. nullptr, arm_none_supply_vfp, arm_none_collect_vfp
  135. };
  136. /* Iterate over core file register note sections. */
  137. static void
  138. arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
  139. iterate_over_regset_sections_cb *cb,
  140. void *cb_data,
  141. const struct regcache *regcache)
  142. {
  143. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  144. cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
  145. &arm_none_gregset, nullptr, cb_data);
  146. if (tdep->vfp_register_count > 0)
  147. cb (".reg-arm-vfp", ARM_NONE_SIZEOF_VFP, ARM_NONE_SIZEOF_VFP,
  148. &arm_none_vfpregset, "VFP floating-point", cb_data);
  149. }
  150. /* Initialize ARM bare-metal ABI info. */
  151. static void
  152. arm_none_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  153. {
  154. #ifdef HAVE_ELF
  155. elf_none_init_abi (gdbarch);
  156. #endif
  157. /* Iterate over registers for reading and writing bare metal ARM core
  158. files. */
  159. set_gdbarch_iterate_over_regset_sections
  160. (gdbarch, arm_none_iterate_over_regset_sections);
  161. }
  162. /* Initialize ARM bare-metal target support. */
  163. void _initialize_arm_none_tdep ();
  164. void
  165. _initialize_arm_none_tdep ()
  166. {
  167. gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_NONE,
  168. arm_none_init_abi);
  169. }