m68k-bsd-tdep.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Target-dependent code for Motorola 68000 BSD's.
  2. Copyright (C) 2004-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 "arch-utils.h"
  16. #include "frame.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 "gdbtypes.h"
  23. #include "m68k-tdep.h"
  24. #include "solib-svr4.h"
  25. /* Core file support. */
  26. /* Sizeof `struct reg' in <machine/reg.h>. */
  27. #define M68KBSD_SIZEOF_GREGS (18 * 4)
  28. /* Sizeof `struct fpreg' in <machine/reg.h. */
  29. #define M68KBSD_SIZEOF_FPREGS (((8 * 3) + 3) * 4)
  30. int
  31. m68kbsd_fpreg_offset (struct gdbarch *gdbarch, int regnum)
  32. {
  33. int fp_len = TYPE_LENGTH (gdbarch_register_type (gdbarch, regnum));
  34. if (regnum >= M68K_FPC_REGNUM)
  35. return 8 * fp_len + (regnum - M68K_FPC_REGNUM) * 4;
  36. return (regnum - M68K_FP0_REGNUM) * fp_len;
  37. }
  38. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  39. in the floating-point register set REGSET to register cache
  40. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  41. static void
  42. m68kbsd_supply_fpregset (const struct regset *regset,
  43. struct regcache *regcache,
  44. int regnum, const void *fpregs, size_t len)
  45. {
  46. struct gdbarch *gdbarch = regcache->arch ();
  47. const gdb_byte *regs = (const gdb_byte *) fpregs;
  48. int i;
  49. gdb_assert (len >= M68KBSD_SIZEOF_FPREGS);
  50. for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++)
  51. {
  52. if (regnum == i || regnum == -1)
  53. regcache->raw_supply (i, regs + m68kbsd_fpreg_offset (gdbarch, i));
  54. }
  55. }
  56. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  57. in the general-purpose register set REGSET to register cache
  58. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  59. static void
  60. m68kbsd_supply_gregset (const struct regset *regset,
  61. struct regcache *regcache,
  62. int regnum, const void *gregs, size_t len)
  63. {
  64. const gdb_byte *regs = (const gdb_byte *) gregs;
  65. int i;
  66. gdb_assert (len >= M68KBSD_SIZEOF_GREGS);
  67. for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++)
  68. {
  69. if (regnum == i || regnum == -1)
  70. regcache->raw_supply (i, regs + i * 4);
  71. }
  72. if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS)
  73. {
  74. regs += M68KBSD_SIZEOF_GREGS;
  75. len -= M68KBSD_SIZEOF_GREGS;
  76. m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len);
  77. }
  78. }
  79. /* Motorola 68000 register sets. */
  80. static const struct regset m68kbsd_gregset =
  81. {
  82. NULL,
  83. m68kbsd_supply_gregset,
  84. NULL,
  85. REGSET_VARIABLE_SIZE
  86. };
  87. static const struct regset m68kbsd_fpregset =
  88. {
  89. NULL,
  90. m68kbsd_supply_fpregset
  91. };
  92. /* Iterate over core file register note sections. */
  93. static void
  94. m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  95. iterate_over_regset_sections_cb *cb,
  96. void *cb_data,
  97. const struct regcache *regcache)
  98. {
  99. cb (".reg", M68KBSD_SIZEOF_GREGS, M68KBSD_SIZEOF_GREGS, &m68kbsd_gregset,
  100. NULL, cb_data);
  101. cb (".reg2", M68KBSD_SIZEOF_FPREGS, M68KBSD_SIZEOF_FPREGS, &m68kbsd_fpregset,
  102. NULL, cb_data);
  103. }
  104. static void
  105. m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  106. {
  107. m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  108. tdep->jb_pc = 5;
  109. tdep->jb_elt_size = 4;
  110. set_gdbarch_decr_pc_after_break (gdbarch, 2);
  111. set_gdbarch_iterate_over_regset_sections
  112. (gdbarch, m68kbsd_iterate_over_regset_sections);
  113. /* NetBSD ELF uses the SVR4 ABI. */
  114. m68k_svr4_init_abi (info, gdbarch);
  115. tdep->struct_return = pcc_struct_return;
  116. /* NetBSD ELF uses SVR4-style shared libraries. */
  117. set_solib_svr4_fetch_link_map_offsets
  118. (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  119. }
  120. void _initialize_m68kbsd_tdep ();
  121. void
  122. _initialize_m68kbsd_tdep ()
  123. {
  124. gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD,
  125. m68kbsd_init_abi);
  126. }