netbsd-amd64-low.cc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* Copyright (C) 2020-2022 Free Software Foundation, Inc.
  2. This file is part of GDB.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <sys/types.h>
  14. #include <sys/ptrace.h>
  15. #include <limits.h>
  16. #include "server.h"
  17. #include "netbsd-low.h"
  18. #include "gdbsupport/x86-xstate.h"
  19. #include "arch/amd64.h"
  20. #include "x86-tdesc.h"
  21. #include "tdesc.h"
  22. /* The index of various registers inside the regcache. */
  23. enum netbsd_x86_64_gdb_regnum
  24. {
  25. AMD64_RAX_REGNUM, /* %rax */
  26. AMD64_RBX_REGNUM, /* %rbx */
  27. AMD64_RCX_REGNUM, /* %rcx */
  28. AMD64_RDX_REGNUM, /* %rdx */
  29. AMD64_RSI_REGNUM, /* %rsi */
  30. AMD64_RDI_REGNUM, /* %rdi */
  31. AMD64_RBP_REGNUM, /* %rbp */
  32. AMD64_RSP_REGNUM, /* %rsp */
  33. AMD64_R8_REGNUM, /* %r8 */
  34. AMD64_R9_REGNUM, /* %r9 */
  35. AMD64_R10_REGNUM, /* %r10 */
  36. AMD64_R11_REGNUM, /* %r11 */
  37. AMD64_R12_REGNUM, /* %r12 */
  38. AMD64_R13_REGNUM, /* %r13 */
  39. AMD64_R14_REGNUM, /* %r14 */
  40. AMD64_R15_REGNUM, /* %r15 */
  41. AMD64_RIP_REGNUM, /* %rip */
  42. AMD64_EFLAGS_REGNUM, /* %eflags */
  43. AMD64_CS_REGNUM, /* %cs */
  44. AMD64_SS_REGNUM, /* %ss */
  45. AMD64_DS_REGNUM, /* %ds */
  46. AMD64_ES_REGNUM, /* %es */
  47. AMD64_FS_REGNUM, /* %fs */
  48. AMD64_GS_REGNUM, /* %gs */
  49. AMD64_ST0_REGNUM = 24, /* %st0 */
  50. AMD64_ST1_REGNUM, /* %st1 */
  51. AMD64_FCTRL_REGNUM = AMD64_ST0_REGNUM + 8,
  52. AMD64_FSTAT_REGNUM = AMD64_ST0_REGNUM + 9,
  53. AMD64_FTAG_REGNUM = AMD64_ST0_REGNUM + 10,
  54. AMD64_XMM0_REGNUM = 40, /* %xmm0 */
  55. AMD64_XMM1_REGNUM, /* %xmm1 */
  56. AMD64_MXCSR_REGNUM = AMD64_XMM0_REGNUM + 16,
  57. AMD64_YMM0H_REGNUM, /* %ymm0h */
  58. AMD64_YMM15H_REGNUM = AMD64_YMM0H_REGNUM + 15,
  59. AMD64_BND0R_REGNUM = AMD64_YMM15H_REGNUM + 1,
  60. AMD64_BND3R_REGNUM = AMD64_BND0R_REGNUM + 3,
  61. AMD64_BNDCFGU_REGNUM,
  62. AMD64_BNDSTATUS_REGNUM,
  63. AMD64_XMM16_REGNUM,
  64. AMD64_XMM31_REGNUM = AMD64_XMM16_REGNUM + 15,
  65. AMD64_YMM16H_REGNUM,
  66. AMD64_YMM31H_REGNUM = AMD64_YMM16H_REGNUM + 15,
  67. AMD64_K0_REGNUM,
  68. AMD64_K7_REGNUM = AMD64_K0_REGNUM + 7,
  69. AMD64_ZMM0H_REGNUM,
  70. AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31,
  71. AMD64_PKRU_REGNUM,
  72. AMD64_FSBASE_REGNUM,
  73. AMD64_GSBASE_REGNUM
  74. };
  75. /* The fill_function for the general-purpose register set. */
  76. static void
  77. netbsd_x86_64_fill_gregset (struct regcache *regcache, char *buf)
  78. {
  79. struct reg *r = (struct reg *) buf;
  80. #define netbsd_x86_64_collect_gp(regnum, fld) do { \
  81. collect_register (regcache, regnum, &r->regs[_REG_##fld]); \
  82. } while (0)
  83. netbsd_x86_64_collect_gp (AMD64_RAX_REGNUM, RAX);
  84. netbsd_x86_64_collect_gp (AMD64_RBX_REGNUM, RBX);
  85. netbsd_x86_64_collect_gp (AMD64_RCX_REGNUM, RCX);
  86. netbsd_x86_64_collect_gp (AMD64_RDX_REGNUM, RDX);
  87. netbsd_x86_64_collect_gp (AMD64_RSI_REGNUM, RSI);
  88. netbsd_x86_64_collect_gp (AMD64_RDI_REGNUM, RDI);
  89. netbsd_x86_64_collect_gp (AMD64_RBP_REGNUM, RBP);
  90. netbsd_x86_64_collect_gp (AMD64_RSP_REGNUM, RSP);
  91. netbsd_x86_64_collect_gp (AMD64_R8_REGNUM, R8);
  92. netbsd_x86_64_collect_gp (AMD64_R9_REGNUM, R9);
  93. netbsd_x86_64_collect_gp (AMD64_R10_REGNUM, R10);
  94. netbsd_x86_64_collect_gp (AMD64_R11_REGNUM, R11);
  95. netbsd_x86_64_collect_gp (AMD64_R12_REGNUM, R12);
  96. netbsd_x86_64_collect_gp (AMD64_R13_REGNUM, R13);
  97. netbsd_x86_64_collect_gp (AMD64_R14_REGNUM, R14);
  98. netbsd_x86_64_collect_gp (AMD64_R15_REGNUM, R15);
  99. netbsd_x86_64_collect_gp (AMD64_RIP_REGNUM, RIP);
  100. netbsd_x86_64_collect_gp (AMD64_EFLAGS_REGNUM, RFLAGS);
  101. netbsd_x86_64_collect_gp (AMD64_CS_REGNUM, CS);
  102. netbsd_x86_64_collect_gp (AMD64_SS_REGNUM, SS);
  103. netbsd_x86_64_collect_gp (AMD64_DS_REGNUM, DS);
  104. netbsd_x86_64_collect_gp (AMD64_ES_REGNUM, ES);
  105. netbsd_x86_64_collect_gp (AMD64_FS_REGNUM, FS);
  106. netbsd_x86_64_collect_gp (AMD64_GS_REGNUM, GS);
  107. }
  108. /* The store_function for the general-purpose register set. */
  109. static void
  110. netbsd_x86_64_store_gregset (struct regcache *regcache, const char *buf)
  111. {
  112. struct reg *r = (struct reg *) buf;
  113. #define netbsd_x86_64_supply_gp(regnum, fld) do { \
  114. supply_register (regcache, regnum, &r->regs[_REG_##fld]); \
  115. } while(0)
  116. netbsd_x86_64_supply_gp (AMD64_RAX_REGNUM, RAX);
  117. netbsd_x86_64_supply_gp (AMD64_RBX_REGNUM, RBX);
  118. netbsd_x86_64_supply_gp (AMD64_RCX_REGNUM, RCX);
  119. netbsd_x86_64_supply_gp (AMD64_RDX_REGNUM, RDX);
  120. netbsd_x86_64_supply_gp (AMD64_RSI_REGNUM, RSI);
  121. netbsd_x86_64_supply_gp (AMD64_RDI_REGNUM, RDI);
  122. netbsd_x86_64_supply_gp (AMD64_RBP_REGNUM, RBP);
  123. netbsd_x86_64_supply_gp (AMD64_RSP_REGNUM, RSP);
  124. netbsd_x86_64_supply_gp (AMD64_R8_REGNUM, R8);
  125. netbsd_x86_64_supply_gp (AMD64_R9_REGNUM, R9);
  126. netbsd_x86_64_supply_gp (AMD64_R10_REGNUM, R10);
  127. netbsd_x86_64_supply_gp (AMD64_R11_REGNUM, R11);
  128. netbsd_x86_64_supply_gp (AMD64_R12_REGNUM, R12);
  129. netbsd_x86_64_supply_gp (AMD64_R13_REGNUM, R13);
  130. netbsd_x86_64_supply_gp (AMD64_R14_REGNUM, R14);
  131. netbsd_x86_64_supply_gp (AMD64_R15_REGNUM, R15);
  132. netbsd_x86_64_supply_gp (AMD64_RIP_REGNUM, RIP);
  133. netbsd_x86_64_supply_gp (AMD64_EFLAGS_REGNUM, RFLAGS);
  134. netbsd_x86_64_supply_gp (AMD64_CS_REGNUM, CS);
  135. netbsd_x86_64_supply_gp (AMD64_SS_REGNUM, SS);
  136. netbsd_x86_64_supply_gp (AMD64_DS_REGNUM, DS);
  137. netbsd_x86_64_supply_gp (AMD64_ES_REGNUM, ES);
  138. netbsd_x86_64_supply_gp (AMD64_FS_REGNUM, FS);
  139. netbsd_x86_64_supply_gp (AMD64_GS_REGNUM, GS);
  140. }
  141. /* Description of all the x86-netbsd register sets. */
  142. static const struct netbsd_regset_info netbsd_target_regsets[] =
  143. {
  144. /* General Purpose Registers. */
  145. {PT_GETREGS, PT_SETREGS, sizeof (struct reg),
  146. netbsd_x86_64_fill_gregset, netbsd_x86_64_store_gregset},
  147. /* End of list marker. */
  148. {0, 0, -1, NULL, NULL }
  149. };
  150. /* NetBSD target op definitions for the amd64 architecture. */
  151. class netbsd_amd64_target : public netbsd_process_target
  152. {
  153. protected:
  154. const netbsd_regset_info *get_regs_info () override;
  155. void low_arch_setup () override;
  156. };
  157. /* Return the information to access registers. */
  158. const netbsd_regset_info *
  159. netbsd_amd64_target::get_regs_info ()
  160. {
  161. return netbsd_target_regsets;
  162. }
  163. /* Architecture-specific setup for the current process. */
  164. void
  165. netbsd_amd64_target::low_arch_setup ()
  166. {
  167. target_desc *tdesc
  168. = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false);
  169. init_target_desc (tdesc, amd64_expedite_regs);
  170. current_process ()->tdesc = tdesc;
  171. }
  172. /* The singleton target ops object. */
  173. static netbsd_amd64_target the_netbsd_amd64_target;
  174. /* The NetBSD target ops object. */
  175. netbsd_process_target *the_netbsd_target = &the_netbsd_amd64_target;