amd64-netbsd-tdep.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Target-dependent code for NetBSD/amd64.
  2. Copyright (C) 2003-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 "gdbcore.h"
  18. #include "osabi.h"
  19. #include "symtab.h"
  20. #include "amd64-tdep.h"
  21. #include "gdbsupport/x86-xstate.h"
  22. #include "netbsd-tdep.h"
  23. #include "solib-svr4.h"
  24. /* Support for signal handlers. */
  25. /* Return whether THIS_FRAME corresponds to a NetBSD sigtramp
  26. routine. */
  27. static int
  28. amd64nbsd_sigtramp_p (struct frame_info *this_frame)
  29. {
  30. CORE_ADDR pc = get_frame_pc (this_frame);
  31. const char *name;
  32. find_pc_partial_function (pc, &name, NULL, NULL);
  33. return nbsd_pc_in_sigtramp (pc, name);
  34. }
  35. /* Assuming THIS_FRAME corresponds to a NetBSD sigtramp routine,
  36. return the address of the associated mcontext structure. */
  37. static CORE_ADDR
  38. amd64nbsd_mcontext_addr (struct frame_info *this_frame)
  39. {
  40. CORE_ADDR addr;
  41. /* The register %r15 points at `struct ucontext' upon entry of a
  42. signal trampoline. */
  43. addr = get_frame_register_unsigned (this_frame, AMD64_R15_REGNUM);
  44. /* The mcontext structure lives as offset 56 in `struct ucontext'. */
  45. return addr + 56;
  46. }
  47. /* NetBSD 2.0 or later. */
  48. /* Mapping between the general-purpose registers in `struct reg'
  49. format and GDB's register cache layout. */
  50. /* From <machine/reg.h>. */
  51. int amd64nbsd_r_reg_offset[] =
  52. {
  53. 14 * 8, /* %rax */
  54. 13 * 8, /* %rbx */
  55. 3 * 8, /* %rcx */
  56. 2 * 8, /* %rdx */
  57. 1 * 8, /* %rsi */
  58. 0 * 8, /* %rdi */
  59. 12 * 8, /* %rbp */
  60. 24 * 8, /* %rsp */
  61. 4 * 8, /* %r8 .. */
  62. 5 * 8,
  63. 6 * 8,
  64. 7 * 8,
  65. 8 * 8,
  66. 9 * 8,
  67. 10 * 8,
  68. 11 * 8, /* ... %r15 */
  69. 21 * 8, /* %rip */
  70. 23 * 8, /* %eflags */
  71. 22 * 8, /* %cs */
  72. 25 * 8, /* %ss */
  73. 18 * 8, /* %ds */
  74. 17 * 8, /* %es */
  75. 16 * 8, /* %fs */
  76. 15 * 8 /* %gs */
  77. };
  78. static void
  79. amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  80. {
  81. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  82. /* Initialize general-purpose register set details first. */
  83. tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
  84. tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
  85. tdep->sizeof_gregset = 26 * 8;
  86. amd64_init_abi (info, gdbarch,
  87. amd64_target_description (X86_XSTATE_SSE_MASK, true));
  88. nbsd_init_abi (info, gdbarch);
  89. tdep->jb_pc_offset = 7 * 8;
  90. /* NetBSD has its own convention for signal trampolines. */
  91. tdep->sigtramp_p = amd64nbsd_sigtramp_p;
  92. tdep->sigcontext_addr = amd64nbsd_mcontext_addr;
  93. tdep->sc_reg_offset = amd64nbsd_r_reg_offset;
  94. tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
  95. /* NetBSD uses SVR4-style shared libraries. */
  96. set_solib_svr4_fetch_link_map_offsets
  97. (gdbarch, svr4_lp64_fetch_link_map_offsets);
  98. }
  99. void _initialize_amd64nbsd_tdep ();
  100. void
  101. _initialize_amd64nbsd_tdep ()
  102. {
  103. /* The NetBSD/amd64 native dependent code makes this assumption. */
  104. gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);
  105. gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
  106. GDB_OSABI_NETBSD, amd64nbsd_init_abi);
  107. }