arm-netbsd-tdep.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Target-dependent code for NetBSD/arm.
  2. Copyright (C) 2002-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 "osabi.h"
  16. #include "arch/arm.h"
  17. #include "arm-netbsd-tdep.h"
  18. #include "netbsd-tdep.h"
  19. #include "arm-tdep.h"
  20. #include "regset.h"
  21. #include "solib-svr4.h"
  22. /* Description of the longjmp buffer. */
  23. #define ARM_NBSD_JB_PC 24
  24. #define ARM_NBSD_JB_ELEMENT_SIZE ARM_INT_REGISTER_SIZE
  25. /* For compatibility with previous implementations of GDB on arm/NetBSD,
  26. override the default little-endian breakpoint. */
  27. static const gdb_byte arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
  28. static const gdb_byte arm_nbsd_arm_be_breakpoint[] = {0xe6, 0x00, 0x00, 0x11};
  29. static const gdb_byte arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
  30. static const gdb_byte arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe};
  31. /* This matches struct reg from NetBSD's sys/arch/arm/include/reg.h:
  32. https://github.com/NetBSD/src/blob/7c13e6e6773bb171f4ed3ed53013e9d24b3c1eac/sys/arch/arm/include/reg.h#L39
  33. */
  34. struct arm_nbsd_reg
  35. {
  36. uint32_t reg[13];
  37. uint32_t sp;
  38. uint32_t lr;
  39. uint32_t pc;
  40. uint32_t cpsr;
  41. };
  42. void
  43. arm_nbsd_supply_gregset (const struct regset *regset, struct regcache *regcache,
  44. int regnum, const void *gregs, size_t len)
  45. {
  46. const arm_nbsd_reg *gregset = static_cast<const arm_nbsd_reg *>(gregs);
  47. gdb_assert (len >= sizeof (arm_nbsd_reg));
  48. /* Integer registers. */
  49. for (int i = ARM_A1_REGNUM; i < ARM_SP_REGNUM; i++)
  50. if (regnum == -1 || regnum == i)
  51. regcache->raw_supply (i, (char *) &gregset->reg[i]);
  52. if (regnum == -1 || regnum == ARM_SP_REGNUM)
  53. regcache->raw_supply (ARM_SP_REGNUM, (char *) &gregset->sp);
  54. if (regnum == -1 || regnum == ARM_LR_REGNUM)
  55. regcache->raw_supply (ARM_LR_REGNUM, (char *) &gregset->lr);
  56. if (regnum == -1 || regnum == ARM_PC_REGNUM)
  57. {
  58. CORE_ADDR r_pc = gdbarch_addr_bits_remove (regcache->arch (), gregset->pc);
  59. regcache->raw_supply (ARM_PC_REGNUM, (char *) &r_pc);
  60. }
  61. if (regnum == -1 || regnum == ARM_PS_REGNUM)
  62. {
  63. if (arm_apcs_32)
  64. regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->cpsr);
  65. else
  66. regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->pc);
  67. }
  68. }
  69. static const struct regset arm_nbsd_regset = {
  70. nullptr,
  71. arm_nbsd_supply_gregset,
  72. /* We don't need a collect function because we only use this reading registers
  73. (via iterate_over_regset_sections and fetch_regs/fetch_register). */
  74. nullptr,
  75. 0
  76. };
  77. static void
  78. arm_nbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  79. iterate_over_regset_sections_cb *cb,
  80. void *cb_data,
  81. const struct regcache *regcache)
  82. {
  83. cb (".reg", sizeof (arm_nbsd_reg), sizeof (arm_nbsd_reg), &arm_nbsd_regset,
  84. NULL, cb_data);
  85. /* cbiesinger/2020-02-12 -- as far as I can tell, ARM/NetBSD does
  86. not write any floating point registers into the core file (tested
  87. with NetBSD 9.1_RC1). When it does, this function will need to read them,
  88. and the arm-netbsd gdbarch will need a core_read_description function
  89. to return the right description for them. */
  90. }
  91. static void
  92. arm_netbsd_init_abi_common (struct gdbarch_info info,
  93. struct gdbarch *gdbarch)
  94. {
  95. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  96. tdep->lowest_pc = 0x8000;
  97. switch (info.byte_order)
  98. {
  99. case BFD_ENDIAN_LITTLE:
  100. tdep->arm_breakpoint = arm_nbsd_arm_le_breakpoint;
  101. tdep->thumb_breakpoint = arm_nbsd_thumb_le_breakpoint;
  102. tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_le_breakpoint);
  103. tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_le_breakpoint);
  104. break;
  105. case BFD_ENDIAN_BIG:
  106. tdep->arm_breakpoint = arm_nbsd_arm_be_breakpoint;
  107. tdep->thumb_breakpoint = arm_nbsd_thumb_be_breakpoint;
  108. tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_be_breakpoint);
  109. tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_be_breakpoint);
  110. break;
  111. default:
  112. internal_error (__FILE__, __LINE__,
  113. _("arm_gdbarch_init: bad byte order for float format"));
  114. }
  115. tdep->jb_pc = ARM_NBSD_JB_PC;
  116. tdep->jb_elt_size = ARM_NBSD_JB_ELEMENT_SIZE;
  117. set_gdbarch_iterate_over_regset_sections
  118. (gdbarch, arm_nbsd_iterate_over_regset_sections);
  119. /* Single stepping. */
  120. set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
  121. }
  122. static void
  123. arm_netbsd_elf_init_abi (struct gdbarch_info info,
  124. struct gdbarch *gdbarch)
  125. {
  126. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  127. arm_netbsd_init_abi_common (info, gdbarch);
  128. nbsd_init_abi (info, gdbarch);
  129. if (tdep->fp_model == ARM_FLOAT_AUTO)
  130. tdep->fp_model = ARM_FLOAT_SOFT_VFP;
  131. /* NetBSD ELF uses SVR4-style shared libraries. */
  132. set_solib_svr4_fetch_link_map_offsets
  133. (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  134. }
  135. void _initialize_arm_netbsd_tdep ();
  136. void
  137. _initialize_arm_netbsd_tdep ()
  138. {
  139. gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_NETBSD,
  140. arm_netbsd_elf_init_abi);
  141. }