netbsd-i386-low.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/i386.h"
  20. #include "x86-tdesc.h"
  21. #include "tdesc.h"
  22. /* The index of various registers inside the regcache. */
  23. enum netbsd_i386_gdb_regnum
  24. {
  25. I386_EAX_REGNUM, /* %eax */
  26. I386_ECX_REGNUM, /* %ecx */
  27. I386_EDX_REGNUM, /* %edx */
  28. I386_EBX_REGNUM, /* %ebx */
  29. I386_ESP_REGNUM, /* %esp */
  30. I386_EBP_REGNUM, /* %ebp */
  31. I386_ESI_REGNUM, /* %esi */
  32. I386_EDI_REGNUM, /* %edi */
  33. I386_EIP_REGNUM, /* %eip */
  34. I386_EFLAGS_REGNUM, /* %eflags */
  35. I386_CS_REGNUM, /* %cs */
  36. I386_SS_REGNUM, /* %ss */
  37. I386_DS_REGNUM, /* %ds */
  38. I386_ES_REGNUM, /* %es */
  39. I386_FS_REGNUM, /* %fs */
  40. I386_GS_REGNUM, /* %gs */
  41. I386_ST0_REGNUM /* %st(0) */
  42. };
  43. /* The fill_function for the general-purpose register set. */
  44. static void
  45. netbsd_i386_fill_gregset (struct regcache *regcache, char *buf)
  46. {
  47. struct reg *r = (struct reg *) buf;
  48. #define netbsd_i386_collect_gp(regnum, fld) do { \
  49. collect_register (regcache, regnum, &r->r_##fld); \
  50. } while (0)
  51. netbsd_i386_collect_gp (I386_EAX_REGNUM, eax);
  52. netbsd_i386_collect_gp (I386_EBX_REGNUM, ebx);
  53. netbsd_i386_collect_gp (I386_ECX_REGNUM, ecx);
  54. netbsd_i386_collect_gp (I386_EDX_REGNUM, edx);
  55. netbsd_i386_collect_gp (I386_ESP_REGNUM, esp);
  56. netbsd_i386_collect_gp (I386_EBP_REGNUM, ebp);
  57. netbsd_i386_collect_gp (I386_ESI_REGNUM, esi);
  58. netbsd_i386_collect_gp (I386_EDI_REGNUM, edi);
  59. netbsd_i386_collect_gp (I386_EIP_REGNUM, eip);
  60. netbsd_i386_collect_gp (I386_EFLAGS_REGNUM, eflags);
  61. netbsd_i386_collect_gp (I386_CS_REGNUM, cs);
  62. netbsd_i386_collect_gp (I386_SS_REGNUM, ss);
  63. netbsd_i386_collect_gp (I386_DS_REGNUM, ds);
  64. netbsd_i386_collect_gp (I386_ES_REGNUM, es);
  65. netbsd_i386_collect_gp (I386_FS_REGNUM, fs);
  66. netbsd_i386_collect_gp (I386_GS_REGNUM, gs);
  67. }
  68. /* The store_function for the general-purpose register set. */
  69. static void
  70. netbsd_i386_store_gregset (struct regcache *regcache, const char *buf)
  71. {
  72. struct reg *r = (struct reg *) buf;
  73. #define netbsd_i386_supply_gp(regnum, fld) do { \
  74. supply_register (regcache, regnum, &r->r_##fld); \
  75. } while(0)
  76. netbsd_i386_supply_gp (I386_EAX_REGNUM, eax);
  77. netbsd_i386_supply_gp (I386_EBX_REGNUM, ebx);
  78. netbsd_i386_supply_gp (I386_ECX_REGNUM, ecx);
  79. netbsd_i386_supply_gp (I386_EDX_REGNUM, edx);
  80. netbsd_i386_supply_gp (I386_ESP_REGNUM, esp);
  81. netbsd_i386_supply_gp (I386_EBP_REGNUM, ebp);
  82. netbsd_i386_supply_gp (I386_ESI_REGNUM, esi);
  83. netbsd_i386_supply_gp (I386_EDI_REGNUM, edi);
  84. netbsd_i386_supply_gp (I386_EIP_REGNUM, eip);
  85. netbsd_i386_supply_gp (I386_EFLAGS_REGNUM, eflags);
  86. netbsd_i386_supply_gp (I386_CS_REGNUM, cs);
  87. netbsd_i386_supply_gp (I386_SS_REGNUM, ss);
  88. netbsd_i386_supply_gp (I386_DS_REGNUM, ds);
  89. netbsd_i386_supply_gp (I386_ES_REGNUM, es);
  90. netbsd_i386_supply_gp (I386_FS_REGNUM, fs);
  91. netbsd_i386_supply_gp (I386_GS_REGNUM, gs);
  92. }
  93. /* Description of all the x86-netbsd register sets. */
  94. static const struct netbsd_regset_info netbsd_target_regsets[] =
  95. {
  96. /* General Purpose Registers. */
  97. {PT_GETREGS, PT_SETREGS, sizeof (struct reg),
  98. netbsd_i386_fill_gregset, netbsd_i386_store_gregset},
  99. /* End of list marker. */
  100. {0, 0, -1, NULL, NULL }
  101. };
  102. /* NetBSD target op definitions for the amd64 architecture. */
  103. class netbsd_i386_target : public netbsd_process_target
  104. {
  105. public:
  106. const netbsd_regset_info *get_regs_info () override;
  107. void low_arch_setup () override;
  108. };
  109. const netbsd_regset_info *
  110. netbsd_i386_target::get_regs_info ()
  111. {
  112. return netbsd_target_regsets;
  113. }
  114. /* Initialize the target description for the architecture of the
  115. inferior. */
  116. void
  117. netbsd_i386_target::low_arch_setup ()
  118. {
  119. target_desc *tdesc
  120. = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false);
  121. init_target_desc (tdesc, i386_expedite_regs);
  122. current_process ()->tdesc = tdesc;
  123. }
  124. /* The singleton target ops object. */
  125. static netbsd_i386_target the_netbsd_i386_target;
  126. /* The NetBSD target ops object. */
  127. netbsd_process_target *the_netbsd_target = &the_netbsd_i386_target;