aarch64-fbsd-tdep.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Target-dependent code for FreeBSD/aarch64.
  2. Copyright (C) 2017-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 "gdbarch.h"
  16. #include "fbsd-tdep.h"
  17. #include "aarch64-tdep.h"
  18. #include "aarch64-fbsd-tdep.h"
  19. #include "osabi.h"
  20. #include "solib-svr4.h"
  21. #include "target.h"
  22. #include "tramp-frame.h"
  23. #include "trad-frame.h"
  24. /* Register maps. */
  25. static const struct regcache_map_entry aarch64_fbsd_gregmap[] =
  26. {
  27. { 30, AARCH64_X0_REGNUM, 8 }, /* x0 ... x29 */
  28. { 1, AARCH64_LR_REGNUM, 8 },
  29. { 1, AARCH64_SP_REGNUM, 8 },
  30. { 1, AARCH64_PC_REGNUM, 8 },
  31. { 1, AARCH64_CPSR_REGNUM, 4 },
  32. { 0 }
  33. };
  34. static const struct regcache_map_entry aarch64_fbsd_fpregmap[] =
  35. {
  36. { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
  37. { 1, AARCH64_FPSR_REGNUM, 4 },
  38. { 1, AARCH64_FPCR_REGNUM, 4 },
  39. { 0 }
  40. };
  41. /* In a signal frame, sp points to a 'struct sigframe' which is
  42. defined as:
  43. struct sigframe {
  44. siginfo_t sf_si;
  45. ucontext_t sf_uc;
  46. };
  47. ucontext_t is defined as:
  48. struct __ucontext {
  49. sigset_t uc_sigmask;
  50. mcontext_t uc_mcontext;
  51. ...
  52. };
  53. The mcontext_t contains the general purpose register set followed
  54. by the floating point register set. The floating point register
  55. set is only valid if the _MC_FP_VALID flag is set in mc_flags. */
  56. #define AARCH64_SIGFRAME_UCONTEXT_OFFSET 80
  57. #define AARCH64_UCONTEXT_MCONTEXT_OFFSET 16
  58. #define AARCH64_MCONTEXT_FPREGS_OFFSET 272
  59. #define AARCH64_MCONTEXT_FLAGS_OFFSET 800
  60. #define AARCH64_MCONTEXT_FLAG_FP_VALID 0x1
  61. /* Implement the "init" method of struct tramp_frame. */
  62. static void
  63. aarch64_fbsd_sigframe_init (const struct tramp_frame *self,
  64. struct frame_info *this_frame,
  65. struct trad_frame_cache *this_cache,
  66. CORE_ADDR func)
  67. {
  68. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  69. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  70. CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
  71. CORE_ADDR mcontext_addr
  72. = (sp
  73. + AARCH64_SIGFRAME_UCONTEXT_OFFSET
  74. + AARCH64_UCONTEXT_MCONTEXT_OFFSET);
  75. gdb_byte buf[4];
  76. trad_frame_set_reg_regmap (this_cache, aarch64_fbsd_gregmap, mcontext_addr,
  77. regcache_map_entry_size (aarch64_fbsd_gregmap));
  78. if (target_read_memory (mcontext_addr + AARCH64_MCONTEXT_FLAGS_OFFSET, buf,
  79. 4) == 0
  80. && (extract_unsigned_integer (buf, 4, byte_order)
  81. & AARCH64_MCONTEXT_FLAG_FP_VALID))
  82. trad_frame_set_reg_regmap (this_cache, aarch64_fbsd_fpregmap,
  83. mcontext_addr + AARCH64_MCONTEXT_FPREGS_OFFSET,
  84. regcache_map_entry_size (aarch64_fbsd_fpregmap));
  85. trad_frame_set_id (this_cache, frame_id_build (sp, func));
  86. }
  87. static const struct tramp_frame aarch64_fbsd_sigframe =
  88. {
  89. SIGTRAMP_FRAME,
  90. 4,
  91. {
  92. {0x910003e0, ULONGEST_MAX}, /* mov x0, sp */
  93. {0x91014000, ULONGEST_MAX}, /* add x0, x0, #SF_UC */
  94. {0xd2803428, ULONGEST_MAX}, /* mov x8, #SYS_sigreturn */
  95. {0xd4000001, ULONGEST_MAX}, /* svc 0x0 */
  96. {TRAMP_SENTINEL_INSN, ULONGEST_MAX}
  97. },
  98. aarch64_fbsd_sigframe_init
  99. };
  100. /* Register set definitions. */
  101. const struct regset aarch64_fbsd_gregset =
  102. {
  103. aarch64_fbsd_gregmap,
  104. regcache_supply_regset, regcache_collect_regset
  105. };
  106. const struct regset aarch64_fbsd_fpregset =
  107. {
  108. aarch64_fbsd_fpregmap,
  109. regcache_supply_regset, regcache_collect_regset
  110. };
  111. /* Implement the "iterate_over_regset_sections" gdbarch method. */
  112. static void
  113. aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  114. iterate_over_regset_sections_cb *cb,
  115. void *cb_data,
  116. const struct regcache *regcache)
  117. {
  118. cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
  119. &aarch64_fbsd_gregset, NULL, cb_data);
  120. cb (".reg2", AARCH64_FBSD_SIZEOF_FPREGSET, AARCH64_FBSD_SIZEOF_FPREGSET,
  121. &aarch64_fbsd_fpregset, NULL, cb_data);
  122. }
  123. /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */
  124. static void
  125. aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  126. {
  127. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  128. /* Generic FreeBSD support. */
  129. fbsd_init_abi (info, gdbarch);
  130. set_solib_svr4_fetch_link_map_offsets (gdbarch,
  131. svr4_lp64_fetch_link_map_offsets);
  132. tramp_frame_prepend_unwinder (gdbarch, &aarch64_fbsd_sigframe);
  133. /* Enable longjmp. */
  134. tdep->jb_pc = 13;
  135. set_gdbarch_iterate_over_regset_sections
  136. (gdbarch, aarch64_fbsd_iterate_over_regset_sections);
  137. }
  138. void _initialize_aarch64_fbsd_tdep ();
  139. void
  140. _initialize_aarch64_fbsd_tdep ()
  141. {
  142. gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_FREEBSD,
  143. aarch64_fbsd_init_abi);
  144. }