gdb/i386v4-nat.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Native-dependent code for Unix SVR4 running on i386's.

  2.    Copyright (C) 1988-2015 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 "value.h"
  16. #include "inferior.h"
  17. #include "regcache.h"

  18. #ifdef HAVE_SYS_REG_H
  19. #include <sys/reg.h>
  20. #endif

  21. #include "i386-tdep.h"
  22. #include "i387-tdep.h"

  23. #ifdef HAVE_SYS_PROCFS_H

  24. #include <sys/procfs.h>

  25. /* We must not compile this code for 64-bit Solaris x86.  */
  26. #if !defined (PR_MODEL_NATIVE) || (PR_MODEL_NATIVE == PR_MODEL_ILP32)

  27. #include "gregset.h"

  28. /* The `/proc' interface divides the target machine's register set up
  29.    into two different sets, the general purpose register set (gregset)
  30.    and the floating-point register set (fpregset).  For each set,
  31.    there is an ioctl to get the current register set and another ioctl
  32.    to set the current values.

  33.    The actual structure passed through the ioctl interface is, of
  34.    course, naturally machine dependent, and is different for each set
  35.    of registers.  For the i386 for example, the general-purpose
  36.    register set is typically defined by:

  37.    typedef int gregset_t[19];           (in <sys/regset.h>)

  38.    #define GS   0                       (in <sys/reg.h>)
  39.    #define FS   1
  40.    ...
  41.    #define UESP 17
  42.    #define SS   18

  43.    and the floating-point set by:

  44.    typedef struct fpregset   {
  45.            union {
  46.                    struct fpchip_state            // fp extension state //
  47.                    {
  48.                            int     state[27];     // 287/387 saved state //
  49.                            int     status;        // status word saved at //
  50.                                                   // exception //
  51.                    } fpchip_state;
  52.                    struct fp_emul_space           // for emulators //
  53.                    {
  54.                            char    fp_emul[246];
  55.                            char    fp_epad[2];
  56.                    } fp_emul_space;
  57.                    int     f_fpregs[62];          // union of the above //
  58.            } fp_reg_set;
  59.            long            f_wregs[33];           // saved weitek state //
  60.    } fpregset_t;

  61.    Incidentally fpchip_state contains the FPU state in the same format
  62.    as used by the "fsave" instruction, and that's the only thing we
  63.    support here.  I don't know how the emulator stores it state.  The
  64.    Weitek stuff definitely isn't supported.

  65.    The routines defined here, provide the packing and unpacking of
  66.    gregset_t and fpregset_t formatted data.  */

  67. #ifdef HAVE_GREGSET_T

  68. /* Mapping between the general-purpose registers in `/proc'
  69.    format and GDB's register array layout.  */
  70. static int regmap[] =
  71. {
  72.   EAX, ECX, EDX, EBX,
  73.   UESP, EBP, ESI, EDI,
  74.   EIP, EFL, CS, SS,
  75.   DS, ES, FS, GS
  76. };

  77. /* Fill GDB's register array with the general-purpose register values
  78.    in *GREGSETP.  */

  79. void
  80. supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
  81. {
  82.   const greg_t *regp = (const greg_t *) gregsetp;
  83.   int regnum;

  84.   for (regnum = 0; regnum < I386_NUM_GREGS; regnum++)
  85.     regcache_raw_supply (regcache, regnum, regp + regmap[regnum]);
  86. }

  87. /* Fill register REGNUM (if it is a general-purpose register) in
  88.    *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
  89.    do this for all registers.  */

  90. void
  91. fill_gregset (const struct regcache *regcache,
  92.               gregset_t *gregsetp, int regnum)
  93. {
  94.   greg_t *regp = (greg_t *) gregsetp;
  95.   int i;

  96.   for (i = 0; i < I386_NUM_GREGS; i++)
  97.     if (regnum == -1 || regnum == i)
  98.       regcache_raw_collect (regcache, i, regp + regmap[i]);
  99. }

  100. #endif /* HAVE_GREGSET_T */

  101. #ifdef HAVE_FPREGSET_T

  102. /* Fill GDB's register array with the floating-point register values in
  103.    *FPREGSETP.  */

  104. void
  105. supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
  106. {
  107.   if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) == 0)
  108.     return;

  109.   i387_supply_fsave (regcache, -1, fpregsetp);
  110. }

  111. /* Fill register REGNO (if it is a floating-point register) in
  112.    *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
  113.    do this for all registers.  */

  114. void
  115. fill_fpregset (const struct regcache *regcache,
  116.                fpregset_t *fpregsetp, int regno)
  117. {
  118.   if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) == 0)
  119.     return;

  120.   i387_collect_fsave (regcache, regno, fpregsetp);
  121. }

  122. #endif /* HAVE_FPREGSET_T */

  123. #endif /* not 64-bit.  */

  124. #endif /* HAVE_SYS_PROCFS_H */