ppc-netbsd-tdep.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* Target-dependent code for NetBSD/powerpc.
  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 "gdbtypes.h"
  17. #include "osabi.h"
  18. #include "regcache.h"
  19. #include "regset.h"
  20. #include "trad-frame.h"
  21. #include "tramp-frame.h"
  22. #include "ppc-tdep.h"
  23. #include "netbsd-tdep.h"
  24. #include "ppc-tdep.h"
  25. #include "solib-svr4.h"
  26. /* Register offsets from <machine/reg.h>. */
  27. static ppc_reg_offsets ppcnbsd_reg_offsets;
  28. /* Core file support. */
  29. /* NetBSD/powerpc register sets. */
  30. const struct regset ppcnbsd_gregset =
  31. {
  32. &ppcnbsd_reg_offsets,
  33. ppc_supply_gregset
  34. };
  35. const struct regset ppcnbsd_fpregset =
  36. {
  37. &ppcnbsd_reg_offsets,
  38. ppc_supply_fpregset
  39. };
  40. /* Iterate over core file register note sections. */
  41. static void
  42. ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  43. iterate_over_regset_sections_cb *cb,
  44. void *cb_data,
  45. const struct regcache *regcache)
  46. {
  47. cb (".reg", 148, 148, &ppcnbsd_gregset, NULL, cb_data);
  48. cb (".reg2", 264, 264, &ppcnbsd_fpregset, NULL, cb_data);
  49. }
  50. /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
  51. convention but, 1.6 switched to the below broken convention. For
  52. the moment use the broken convention. Ulgh! */
  53. static enum return_value_convention
  54. ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function,
  55. struct type *valtype, struct regcache *regcache,
  56. gdb_byte *readbuf, const gdb_byte *writebuf)
  57. {
  58. #if 0
  59. if ((valtype->code () == TYPE_CODE_STRUCT
  60. || valtype->code () == TYPE_CODE_UNION)
  61. && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
  62. && valtype->is_vector ())
  63. && !(TYPE_LENGTH (valtype) == 1
  64. || TYPE_LENGTH (valtype) == 2
  65. || TYPE_LENGTH (valtype) == 4
  66. || TYPE_LENGTH (valtype) == 8))
  67. return RETURN_VALUE_STRUCT_CONVENTION;
  68. else
  69. #endif
  70. return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
  71. regcache, readbuf, writebuf);
  72. }
  73. /* Signal trampolines. */
  74. extern const struct tramp_frame ppcnbsd2_sigtramp;
  75. static void
  76. ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
  77. struct frame_info *this_frame,
  78. struct trad_frame_cache *this_cache,
  79. CORE_ADDR func)
  80. {
  81. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  82. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  83. CORE_ADDR addr, base;
  84. int i;
  85. base = get_frame_register_unsigned (this_frame,
  86. gdbarch_sp_regnum (gdbarch));
  87. if (self == &ppcnbsd2_sigtramp)
  88. addr = base + 0x10 + 2 * tdep->wordsize;
  89. else
  90. addr = base + 0x18 + 2 * tdep->wordsize;
  91. for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
  92. {
  93. int regnum = i + tdep->ppc_gp0_regnum;
  94. trad_frame_set_reg_addr (this_cache, regnum, addr);
  95. }
  96. trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr);
  97. addr += tdep->wordsize;
  98. trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr);
  99. addr += tdep->wordsize;
  100. trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr);
  101. addr += tdep->wordsize;
  102. trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr);
  103. addr += tdep->wordsize;
  104. trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch),
  105. addr); /* SRR0? */
  106. addr += tdep->wordsize;
  107. /* Construct the frame ID using the function start. */
  108. trad_frame_set_id (this_cache, frame_id_build (base, func));
  109. }
  110. static const struct tramp_frame ppcnbsd_sigtramp =
  111. {
  112. SIGTRAMP_FRAME,
  113. 4,
  114. {
  115. { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
  116. { 0x4e800021, ULONGEST_MAX }, /* blrl */
  117. { 0x38610018, ULONGEST_MAX }, /* addi r3,r1,24 */
  118. { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
  119. { 0x44000002, ULONGEST_MAX }, /* sc */
  120. { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
  121. { 0x44000002, ULONGEST_MAX }, /* sc */
  122. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  123. },
  124. ppcnbsd_sigtramp_cache_init
  125. };
  126. /* NetBSD 2.0 introduced a slightly different signal trampoline. */
  127. const struct tramp_frame ppcnbsd2_sigtramp =
  128. {
  129. SIGTRAMP_FRAME,
  130. 4,
  131. {
  132. { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
  133. { 0x4e800021, ULONGEST_MAX }, /* blrl */
  134. { 0x38610010, ULONGEST_MAX }, /* addi r3,r1,16 */
  135. { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
  136. { 0x44000002, ULONGEST_MAX }, /* sc */
  137. { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
  138. { 0x44000002, ULONGEST_MAX }, /* sc */
  139. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  140. },
  141. ppcnbsd_sigtramp_cache_init
  142. };
  143. static void
  144. ppcnbsd_init_abi (struct gdbarch_info info,
  145. struct gdbarch *gdbarch)
  146. {
  147. nbsd_init_abi (info, gdbarch);
  148. /* For NetBSD, this is an on again, off again thing. Some systems
  149. do use the broken struct convention, and some don't. */
  150. set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
  151. /* NetBSD uses SVR4-style shared libraries. */
  152. set_solib_svr4_fetch_link_map_offsets
  153. (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  154. set_gdbarch_iterate_over_regset_sections
  155. (gdbarch, ppcnbsd_iterate_over_regset_sections);
  156. tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
  157. tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
  158. }
  159. void _initialize_ppcnbsd_tdep ();
  160. void
  161. _initialize_ppcnbsd_tdep ()
  162. {
  163. gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD,
  164. ppcnbsd_init_abi);
  165. /* Avoid initializing the register offsets again if they were
  166. already initialized by ppc-netbsd-nat.c. */
  167. if (ppcnbsd_reg_offsets.pc_offset == 0)
  168. {
  169. /* General-purpose registers. */
  170. ppcnbsd_reg_offsets.r0_offset = 0;
  171. ppcnbsd_reg_offsets.gpr_size = 4;
  172. ppcnbsd_reg_offsets.xr_size = 4;
  173. ppcnbsd_reg_offsets.lr_offset = 128;
  174. ppcnbsd_reg_offsets.cr_offset = 132;
  175. ppcnbsd_reg_offsets.xer_offset = 136;
  176. ppcnbsd_reg_offsets.ctr_offset = 140;
  177. ppcnbsd_reg_offsets.pc_offset = 144;
  178. ppcnbsd_reg_offsets.ps_offset = -1;
  179. ppcnbsd_reg_offsets.mq_offset = -1;
  180. /* Floating-point registers. */
  181. ppcnbsd_reg_offsets.f0_offset = 0;
  182. ppcnbsd_reg_offsets.fpscr_offset = 256;
  183. ppcnbsd_reg_offsets.fpscr_size = 4;
  184. }
  185. }