gdb/gdbserver/lynx-i386-low.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Copyright (C) 2010-2015 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 "server.h"
  14. #include "lynx-low.h"

  15. #include <stdint.h>
  16. #include <limits.h>
  17. #include <sys/ptrace.h>

  18. /* The following two typedefs are defined in a .h file which is not
  19.    in the standard include path (/sys/include/family/x86/ucontext.h),
  20.    so we just duplicate them here.  */

  21. /* General register context */
  22. typedef struct usr_econtext {

  23.     uint32_t    uec_fault;
  24.     uint32_t    uec_es;
  25.     uint32_t    uec_ds;
  26.     uint32_t    uec_edi;
  27.     uint32_t    uec_esi;
  28.     uint32_t    uec_ebp;
  29.     uint32_t    uec_temp;
  30.     uint32_t    uec_ebx;
  31.     uint32_t    uec_edx;
  32.     uint32_t    uec_ecx;
  33.     uint32_t    uec_eax;
  34.     uint32_t    uec_inum;
  35.     uint32_t    uec_ecode;
  36.     uint32_t    uec_eip;
  37.     uint32_t    uec_cs;
  38.     uint32_t    uec_eflags;
  39.     uint32_t    uec_esp;
  40.     uint32_t    uec_ss;
  41.     uint32_t    uec_fs;
  42.     uint32_t    uec_gs;
  43. } usr_econtext_t;

  44. /* Floating point and SIMD register context */
  45. typedef struct usr_fcontext {
  46.         uint16_t         ufc_control;
  47.         uint16_t         ufc_status;
  48.         uint16_t         ufc_tag;
  49.         uint16_t         ufc_opcode;
  50.         uint8_t         *ufc_inst_off;
  51.         uint32_t         ufc_inst_sel;
  52.         uint8_t         *ufc_data_off;
  53.         uint32_t         ufc_data_sel;
  54.         uint32_t         usse_mxcsr;
  55.         uint32_t         usse_mxcsr_mask;
  56.         struct ufp387_real {
  57.                 uint16_t umant4;
  58.                 uint16_t umant3;
  59.                 uint16_t umant2;
  60.                 uint16_t umant1;
  61.                 uint16_t us_and_e;
  62.                 uint16_t ureserved_1;
  63.                 uint16_t ureserved_2;
  64.                 uint16_t ureserved_3;
  65.         } ufc_reg[8];
  66.         struct uxmm_register {
  67.                 uint16_t uchunk_1;
  68.                 uint16_t uchunk_2;
  69.                 uint16_t uchunk_3;
  70.                 uint16_t uchunk_4;
  71.                 uint16_t uchunk_5;
  72.                 uint16_t uchunk_6;
  73.                 uint16_t uchunk_7;
  74.                 uint16_t uchunk_8;
  75.         } uxmm_reg[8];
  76.         char ureserved[16][14];
  77. } usr_fcontext_t;

  78. /* The index of various registers inside the regcache.  */

  79. enum lynx_i386_gdb_regnum
  80. {
  81.   I386_EAX_REGNUM,
  82.   I386_ECX_REGNUM,
  83.   I386_EDX_REGNUM,
  84.   I386_EBX_REGNUM,
  85.   I386_ESP_REGNUM,
  86.   I386_EBP_REGNUM,
  87.   I386_ESI_REGNUM,
  88.   I386_EDI_REGNUM,
  89.   I386_EIP_REGNUM,
  90.   I386_EFLAGS_REGNUM,
  91.   I386_CS_REGNUM,
  92.   I386_SS_REGNUM,
  93.   I386_DS_REGNUM,
  94.   I386_ES_REGNUM,
  95.   I386_FS_REGNUM,
  96.   I386_GS_REGNUM,
  97.   I386_ST0_REGNUM,
  98.   I386_FCTRL_REGNUM = I386_ST0_REGNUM + 8,
  99.   I386_FSTAT_REGNUM,
  100.   I386_FTAG_REGNUM,
  101.   I386_FISEG_REGNUM,
  102.   I386_FIOFF_REGNUM,
  103.   I386_FOSEG_REGNUM,
  104.   I386_FOOFF_REGNUM,
  105.   I386_FOP_REGNUM,
  106.   I386_XMM0_REGNUM = 32,
  107.   I386_MXCSR_REGNUM = I386_XMM0_REGNUM + 8,
  108.   I386_SENTINEL_REGUM
  109. };

  110. /* Defined in auto-generated file i386.c.  */
  111. extern void init_registers_i386 (void);
  112. extern const struct target_desc *tdesc_i386;

  113. /* The fill_function for the general-purpose register set.  */

  114. static void
  115. lynx_i386_fill_gregset (struct regcache *regcache, char *buf)
  116. {
  117. #define lynx_i386_collect_gp(regnum, fld) \
  118.   collect_register (regcache, regnum, \
  119.                     buf + offsetof (usr_econtext_t, uec_##fld))

  120.   lynx_i386_collect_gp (I386_EAX_REGNUM, eax);
  121.   lynx_i386_collect_gp (I386_ECX_REGNUM, ecx);
  122.   lynx_i386_collect_gp (I386_EDX_REGNUM, edx);
  123.   lynx_i386_collect_gp (I386_EBX_REGNUM, ebx);
  124.   lynx_i386_collect_gp (I386_ESP_REGNUM, esp);
  125.   lynx_i386_collect_gp (I386_EBP_REGNUM, ebp);
  126.   lynx_i386_collect_gp (I386_ESI_REGNUM, esi);
  127.   lynx_i386_collect_gp (I386_EDI_REGNUM, edi);
  128.   lynx_i386_collect_gp (I386_EIP_REGNUM, eip);
  129.   lynx_i386_collect_gp (I386_EFLAGS_REGNUM, eflags);
  130.   lynx_i386_collect_gp (I386_CS_REGNUM, cs);
  131.   lynx_i386_collect_gp (I386_SS_REGNUM, ss);
  132.   lynx_i386_collect_gp (I386_DS_REGNUM, ds);
  133.   lynx_i386_collect_gp (I386_ES_REGNUM, es);
  134.   lynx_i386_collect_gp (I386_FS_REGNUM, fs);
  135.   lynx_i386_collect_gp (I386_GS_REGNUM, gs);
  136. }

  137. /* The store_function for the general-purpose register set.  */

  138. static void
  139. lynx_i386_store_gregset (struct regcache *regcache, const char *buf)
  140. {
  141. #define lynx_i386_supply_gp(regnum, fld) \
  142.   supply_register (regcache, regnum, \
  143.                    buf + offsetof (usr_econtext_t, uec_##fld))

  144.   lynx_i386_supply_gp (I386_EAX_REGNUM, eax);
  145.   lynx_i386_supply_gp (I386_ECX_REGNUM, ecx);
  146.   lynx_i386_supply_gp (I386_EDX_REGNUM, edx);
  147.   lynx_i386_supply_gp (I386_EBX_REGNUM, ebx);
  148.   lynx_i386_supply_gp (I386_ESP_REGNUM, esp);
  149.   lynx_i386_supply_gp (I386_EBP_REGNUM, ebp);
  150.   lynx_i386_supply_gp (I386_ESI_REGNUM, esi);
  151.   lynx_i386_supply_gp (I386_EDI_REGNUM, edi);
  152.   lynx_i386_supply_gp (I386_EIP_REGNUM, eip);
  153.   lynx_i386_supply_gp (I386_EFLAGS_REGNUM, eflags);
  154.   lynx_i386_supply_gp (I386_CS_REGNUM, cs);
  155.   lynx_i386_supply_gp (I386_SS_REGNUM, ss);
  156.   lynx_i386_supply_gp (I386_DS_REGNUM, ds);
  157.   lynx_i386_supply_gp (I386_ES_REGNUM, es);
  158.   lynx_i386_supply_gp (I386_FS_REGNUM, fs);
  159.   lynx_i386_supply_gp (I386_GS_REGNUM, gs);
  160. }

  161. /* Extract the first 16 bits of register REGNUM in the REGCACHE,
  162.    and store these 2 bytes at DEST.

  163.    This is useful to collect certain 16bit registers which are known
  164.    by GDBserver as 32bit registers (such as the Control Register
  165.    for instance).  */

  166. static void
  167. collect_16bit_register (struct regcache *regcache, int regnum, char *dest)
  168. {
  169.   gdb_byte word[4];

  170.   collect_register (regcache, regnum, word);
  171.   memcpy (dest, word, 2);
  172. }

  173. /* The fill_function for the floating-point register set.  */

  174. static void
  175. lynx_i386_fill_fpregset (struct regcache *regcache, char *buf)
  176. {
  177.   int i;

  178.   /* Collect %st0 .. %st7.  */
  179.   for (i = 0; i < 8; i++)
  180.     collect_register (regcache, I386_ST0_REGNUM + i,
  181.                       buf + offsetof (usr_fcontext_t, ufc_reg)
  182.                       + i * sizeof (struct ufp387_real));

  183.   /* Collect the other FPU registers.  */
  184.   collect_16bit_register (regcache, I386_FCTRL_REGNUM,
  185.                           buf + offsetof (usr_fcontext_t, ufc_control));
  186.   collect_16bit_register (regcache, I386_FSTAT_REGNUM,
  187.                           buf + offsetof (usr_fcontext_t, ufc_status));
  188.   collect_16bit_register (regcache, I386_FTAG_REGNUM,
  189.                           buf + offsetof (usr_fcontext_t, ufc_tag));
  190.   collect_register (regcache, I386_FISEG_REGNUM,
  191.                     buf + offsetof (usr_fcontext_t, ufc_inst_sel));
  192.   collect_register (regcache, I386_FIOFF_REGNUM,
  193.                     buf + offsetof (usr_fcontext_t, ufc_inst_off));
  194.   collect_register (regcache, I386_FOSEG_REGNUM,
  195.                     buf + offsetof (usr_fcontext_t, ufc_data_sel));
  196.   collect_register (regcache, I386_FOOFF_REGNUM,
  197.                     buf + offsetof (usr_fcontext_t, ufc_data_off));
  198.   collect_16bit_register (regcache, I386_FOP_REGNUM,
  199.                           buf + offsetof (usr_fcontext_t, ufc_opcode));

  200.   /* Collect the XMM registers.  */
  201.   for (i = 0; i < 8; i++)
  202.     collect_register (regcache, I386_XMM0_REGNUM + i,
  203.                       buf + offsetof (usr_fcontext_t, uxmm_reg)
  204.                       + i * sizeof (struct uxmm_register));
  205.   collect_register (regcache, I386_MXCSR_REGNUM,
  206.                     buf + offsetof (usr_fcontext_t, usse_mxcsr));
  207. }

  208. /* This is the supply counterpart for collect_16bit_register:
  209.    It extracts a 2byte value from BUF, and uses that value to
  210.    set REGNUM's value in the regcache.

  211.    This is useful to supply the value of certain 16bit registers
  212.    which are known by GDBserver as 32bit registers (such as the Control
  213.    Register for instance).  */

  214. static void
  215. supply_16bit_register (struct regcache *regcache, int regnum, const char *buf)
  216. {
  217.   gdb_byte word[4];

  218.   memcpy (word, buf, 2);
  219.   memset (word + 2, 0, 2);
  220.   supply_register (regcache, regnum, word);
  221. }

  222. /* The store_function for the floating-point register set.  */

  223. static void
  224. lynx_i386_store_fpregset (struct regcache *regcache, const char *buf)
  225. {
  226.   int i;

  227.   /* Store the %st0 .. %st7 registers.  */
  228.   for (i = 0; i < 8; i++)
  229.     supply_register (regcache, I386_ST0_REGNUM + i,
  230.                      buf + offsetof (usr_fcontext_t, ufc_reg)
  231.                      + i * sizeof (struct ufp387_real));

  232.   /* Store the other FPU registers.  */
  233.   supply_16bit_register (regcache, I386_FCTRL_REGNUM,
  234.                          buf + offsetof (usr_fcontext_t, ufc_control));
  235.   supply_16bit_register (regcache, I386_FSTAT_REGNUM,
  236.                          buf + offsetof (usr_fcontext_t, ufc_status));
  237.   supply_16bit_register (regcache, I386_FTAG_REGNUM,
  238.                          buf + offsetof (usr_fcontext_t, ufc_tag));
  239.   supply_register (regcache, I386_FISEG_REGNUM,
  240.                    buf + offsetof (usr_fcontext_t, ufc_inst_sel));
  241.   supply_register (regcache, I386_FIOFF_REGNUM,
  242.                    buf + offsetof (usr_fcontext_t, ufc_inst_off));
  243.   supply_register (regcache, I386_FOSEG_REGNUM,
  244.                    buf + offsetof (usr_fcontext_t, ufc_data_sel));
  245.   supply_register (regcache, I386_FOOFF_REGNUM,
  246.                    buf + offsetof (usr_fcontext_t, ufc_data_off));
  247.   supply_16bit_register (regcache, I386_FOP_REGNUM,
  248.                          buf + offsetof (usr_fcontext_t, ufc_opcode));

  249.   /* Store the XMM registers.  */
  250.   for (i = 0; i < 8; i++)
  251.     supply_register (regcache, I386_XMM0_REGNUM + i,
  252.                      buf + offsetof (usr_fcontext_t, uxmm_reg)
  253.                      + i * sizeof (struct uxmm_register));
  254.   supply_register (regcache, I386_MXCSR_REGNUM,
  255.                    buf + offsetof (usr_fcontext_t, usse_mxcsr));
  256. }

  257. /* Implements the lynx_target_ops.arch_setup routine.  */

  258. static void
  259. lynx_i386_arch_setup (void)
  260. {
  261.   init_registers_i386 ();
  262.   lynx_tdesc = tdesc_i386;
  263. }

  264. /* Description of all the x86-lynx register sets.  */

  265. struct lynx_regset_info lynx_target_regsets[] = {
  266.   /* General Purpose Registers.  */
  267.   {PTRACE_GETREGS, PTRACE_SETREGS, sizeof(usr_econtext_t),
  268.    lynx_i386_fill_gregset, lynx_i386_store_gregset},
  269.   /* Floating Point Registers.  */
  270.   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof(usr_fcontext_t),
  271.     lynx_i386_fill_fpregset, lynx_i386_store_fpregset },
  272.   /* End of list marker.  */
  273.   {0, 0, -1, NULL, NULL }
  274. };

  275. /* The lynx_target_ops vector for x86-lynx.  */

  276. struct lynx_target_ops the_low_target = {
  277.   lynx_i386_arch_setup,
  278. };