i386-sol2-nat.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* Native-dependent code for Solaris x86.
  2. Copyright (C) 1988-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 "regcache.h"
  16. #include <sys/reg.h>
  17. #include <sys/procfs.h>
  18. #include "gregset.h"
  19. #include "target.h"
  20. #include "procfs.h"
  21. /* This file provids the (temporary) glue between the Solaris x86
  22. target dependent code and the machine independent SVR4 /proc
  23. support. */
  24. /* Solaris 10 (Solaris 2.10, SunOS 5.10) and up support two process
  25. data models, the traditional 32-bit data model (ILP32) and the
  26. 64-bit data model (LP64). The format of /proc depends on the data
  27. model of the observer (the controlling process, GDB in our case).
  28. The Solaris header files conveniently define PR_MODEL_NATIVE to the
  29. data model of the controlling process. If its value is
  30. PR_MODEL_LP64, we know that GDB is being compiled as a 64-bit
  31. program.
  32. Note that a 32-bit GDB won't be able to debug a 64-bit target
  33. process using /proc on Solaris. */
  34. #if PR_MODEL_NATIVE == PR_MODEL_LP64
  35. #include "amd64-nat.h"
  36. #include "amd64-tdep.h"
  37. /* Mapping between the general-purpose registers in gregset_t format
  38. and GDB's register cache layout. */
  39. /* From <sys/regset.h>. */
  40. static int amd64_sol2_gregset64_reg_offset[] = {
  41. 14 * 8, /* %rax */
  42. 11 * 8, /* %rbx */
  43. 13 * 8, /* %rcx */
  44. 12 * 8, /* %rdx */
  45. 9 * 8, /* %rsi */
  46. 8 * 8, /* %rdi */
  47. 10 * 8, /* %rbp */
  48. 20 * 8, /* %rsp */
  49. 7 * 8, /* %r8 ... */
  50. 6 * 8,
  51. 5 * 8,
  52. 4 * 8,
  53. 3 * 8,
  54. 2 * 8,
  55. 1 * 8,
  56. 0 * 8, /* ... %r15 */
  57. 17 * 8, /* %rip */
  58. 19 * 8, /* %eflags */
  59. 18 * 8, /* %cs */
  60. 21 * 8, /* %ss */
  61. 25 * 8, /* %ds */
  62. 24 * 8, /* %es */
  63. 22 * 8, /* %fs */
  64. 23 * 8 /* %gs */
  65. };
  66. /* 32-bit registers are provided by Solaris in 64-bit format, so just
  67. give a subset of the list above. */
  68. static int amd64_sol2_gregset32_reg_offset[] = {
  69. 14 * 8, /* %eax */
  70. 13 * 8, /* %ecx */
  71. 12 * 8, /* %edx */
  72. 11 * 8, /* %ebx */
  73. 20 * 8, /* %esp */
  74. 10 * 8, /* %ebp */
  75. 9 * 8, /* %esi */
  76. 8 * 8, /* %edi */
  77. 17 * 8, /* %eip */
  78. 19 * 8, /* %eflags */
  79. 18 * 8, /* %cs */
  80. 21 * 8, /* %ss */
  81. 25 * 8, /* %ds */
  82. 24 * 8, /* %es */
  83. 22 * 8, /* %fs */
  84. 23 * 8 /* %gs */
  85. };
  86. void
  87. supply_gregset (struct regcache *regcache, const prgregset_t *gregs)
  88. {
  89. amd64_supply_native_gregset (regcache, gregs, -1);
  90. }
  91. void
  92. supply_fpregset (struct regcache *regcache, const prfpregset_t *fpregs)
  93. {
  94. amd64_supply_fxsave (regcache, -1, fpregs);
  95. }
  96. void
  97. fill_gregset (const struct regcache *regcache,
  98. prgregset_t *gregs, int regnum)
  99. {
  100. amd64_collect_native_gregset (regcache, gregs, regnum);
  101. }
  102. void
  103. fill_fpregset (const struct regcache *regcache,
  104. prfpregset_t *fpregs, int regnum)
  105. {
  106. amd64_collect_fxsave (regcache, regnum, fpregs);
  107. }
  108. #else /* PR_MODEL_NATIVE != PR_MODEL_LP64 */
  109. #include "i386-tdep.h"
  110. #include "i387-tdep.h"
  111. /* The `/proc' interface divides the target machine's register set up
  112. into two different sets, the general purpose register set (gregset)
  113. and the floating-point register set (fpregset).
  114. The actual structure is, of course, naturally machine dependent, and is
  115. different for each set of registers. For the i386 for example, the
  116. general-purpose register set is typically defined by:
  117. typedef int gregset_t[19]; (in <sys/regset.h>)
  118. #define GS 0 (in <sys/reg.h>)
  119. #define FS 1
  120. ...
  121. #define UESP 17
  122. #define SS 18
  123. and the floating-point set by:
  124. typedef struct fpregset {
  125. union {
  126. struct fpchip_state // fp extension state //
  127. {
  128. int state[27]; // 287/387 saved state //
  129. int status; // status word saved at //
  130. // exception //
  131. } fpchip_state;
  132. struct fp_emul_space // for emulators //
  133. {
  134. char fp_emul[246];
  135. char fp_epad[2];
  136. } fp_emul_space;
  137. int f_fpregs[62]; // union of the above //
  138. } fp_reg_set;
  139. long f_wregs[33]; // saved weitek state //
  140. } fpregset_t;
  141. Incidentally fpchip_state contains the FPU state in the same format
  142. as used by the "fsave" instruction, and that's the only thing we
  143. support here. I don't know how the emulator stores it state. The
  144. Weitek stuff definitely isn't supported.
  145. The routines defined here, provide the packing and unpacking of
  146. gregset_t and fpregset_t formatted data. */
  147. /* Mapping between the general-purpose registers in `/proc'
  148. format and GDB's register array layout. */
  149. static int regmap[] =
  150. {
  151. 11 /* EAX */,
  152. 10 /* ECX */,
  153. 9 /* EDX */,
  154. 8 /* EBX */,
  155. 17 /* UESP */,
  156. 6 /* EBP */,
  157. 5 /* ESI */,
  158. 4 /* EDI */,
  159. 14 /* EIP */,
  160. 16 /* EFL */,
  161. 15 /* CS */,
  162. 18 /* SS */,
  163. 3 /* DS */,
  164. 2 /* ES */,
  165. 1 /* FS */,
  166. 0 /* GS */
  167. };
  168. /* Fill GDB's register array with the general-purpose register values
  169. in *GREGSETP. */
  170. void
  171. supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
  172. {
  173. const greg_t *regp = (const greg_t *) gregsetp;
  174. int regnum;
  175. for (regnum = 0; regnum < I386_NUM_GREGS; regnum++)
  176. regcache->raw_supply (regnum, regp + regmap[regnum]);
  177. }
  178. /* Fill register REGNUM (if it is a general-purpose register) in
  179. *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
  180. do this for all registers. */
  181. void
  182. fill_gregset (const struct regcache *regcache,
  183. gregset_t *gregsetp, int regnum)
  184. {
  185. greg_t *regp = (greg_t *) gregsetp;
  186. int i;
  187. for (i = 0; i < I386_NUM_GREGS; i++)
  188. if (regnum == -1 || regnum == i)
  189. regcache->raw_collect (i, regp + regmap[i]);
  190. }
  191. /* Fill GDB's register array with the floating-point register values in
  192. *FPREGSETP. */
  193. void
  194. supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
  195. {
  196. if (gdbarch_fp0_regnum (regcache->arch ()) == 0)
  197. return;
  198. i387_supply_fsave (regcache, -1, fpregsetp);
  199. }
  200. /* Fill register REGNO (if it is a floating-point register) in
  201. *FPREGSETP with the value in GDB's register array. If REGNO is -1,
  202. do this for all registers. */
  203. void
  204. fill_fpregset (const struct regcache *regcache,
  205. fpregset_t *fpregsetp, int regno)
  206. {
  207. if (gdbarch_fp0_regnum (regcache->arch ()) == 0)
  208. return;
  209. i387_collect_fsave (regcache, regno, fpregsetp);
  210. }
  211. #endif
  212. void _initialize_amd64_sol2_nat ();
  213. void
  214. _initialize_amd64_sol2_nat ()
  215. {
  216. #if PR_MODEL_NATIVE == PR_MODEL_LP64
  217. amd64_native_gregset32_reg_offset = amd64_sol2_gregset32_reg_offset;
  218. amd64_native_gregset32_num_regs =
  219. ARRAY_SIZE (amd64_sol2_gregset32_reg_offset);
  220. amd64_native_gregset64_reg_offset = amd64_sol2_gregset64_reg_offset;
  221. amd64_native_gregset64_num_regs =
  222. ARRAY_SIZE (amd64_sol2_gregset64_reg_offset);
  223. #endif
  224. }