* gregset.h (struct regcache): Add forward declaration.
[deliverable/binutils-gdb.git] / gdb / i386v4-nat.c
CommitLineData
40e20472
MK
1/* Native-dependent code for Unix SVR4 running on i386's.
2
6aba47ca
DJ
3 Copyright (C) 1988, 1989, 1991, 1992, 1996, 1997, 1998, 1999, 2000, 2001,
4 2002, 2004, 2007 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b
JM
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
197e01b6
EZ
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "value.h"
7a292a7a 25#include "inferior.h"
4e052eda 26#include "regcache.h"
c906108c
SS
27
28#ifdef HAVE_SYS_REG_H
29#include <sys/reg.h>
30#endif
31
fcc9bf01
MK
32#include "i386-tdep.h"
33#include "i387-tdep.h"
c906108c
SS
34
35#ifdef HAVE_SYS_PROCFS_H
36
37#include <sys/procfs.h>
38
f69c55b2
MK
39/* We must not compile this code for 64-bit Solaris x86. */
40#if !defined (PR_MODEL_NATIVE) || (PR_MODEL_NATIVE == PR_MODEL_ILP32)
41
c60c0f5f
MS
42#include "gregset.h"
43
fcc9bf01
MK
44/* The `/proc' interface divides the target machine's register set up
45 into two different sets, the general purpose register set (gregset)
46 and the floating-point register set (fpregset). For each set,
47 there is an ioctl to get the current register set and another ioctl
48 to set the current values.
c5aa993b 49
fcc9bf01
MK
50 The actual structure passed through the ioctl interface is, of
51 course, naturally machine dependent, and is different for each set
52 of registers. For the i386 for example, the general-purpose
53 register set is typically defined by:
c5aa993b
JM
54
55 typedef int gregset_t[19]; (in <sys/regset.h>)
56
57 #define GS 0 (in <sys/reg.h>)
58 #define FS 1
59 ...
60 #define UESP 17
61 #define SS 18
62
fcc9bf01
MK
63 and the floating-point set by:
64
65 typedef struct fpregset {
66 union {
67 struct fpchip_state // fp extension state //
68 {
69 int state[27]; // 287/387 saved state //
70 int status; // status word saved at //
71 // exception //
72 } fpchip_state;
73 struct fp_emul_space // for emulators //
74 {
75 char fp_emul[246];
76 char fp_epad[2];
77 } fp_emul_space;
78 int f_fpregs[62]; // union of the above //
79 } fp_reg_set;
80 long f_wregs[33]; // saved weitek state //
c5aa993b
JM
81 } fpregset_t;
82
fcc9bf01
MK
83 Incidentally fpchip_state contains the FPU state in the same format
84 as used by the "fsave" instruction, and that's the only thing we
85 support here. I don't know how the emulator stores it state. The
86 Weitek stuff definitely isn't supported.
c906108c 87
fcc9bf01
MK
88 The routines defined here, provide the packing and unpacking of
89 gregset_t and fpregset_t formatted data. */
c906108c
SS
90
91#ifdef HAVE_GREGSET_T
92
fcc9bf01
MK
93/* Mapping between the general-purpose registers in `/proc'
94 format and GDB's register array layout. */
c5aa993b 95static int regmap[] =
c906108c
SS
96{
97 EAX, ECX, EDX, EBX,
98 UESP, EBP, ESI, EDI,
99 EIP, EFL, CS, SS,
40e20472 100 DS, ES, FS, GS
c906108c
SS
101};
102
fcc9bf01
MK
103/* Fill GDB's register array with the general-purpose register values
104 in *GREGSETP. */
c906108c
SS
105
106void
7f7fe91e 107supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
c906108c 108{
7f7fe91e 109 const greg_t *regp = (const greg_t *) gregsetp;
40e20472 110 int regnum;
fcc9bf01 111
40e20472 112 for (regnum = 0; regnum < I386_NUM_GREGS; regnum++)
7f7fe91e 113 regcache_raw_supply (regcache, regnum, regp + regmap[regnum]);
c906108c
SS
114}
115
40e20472
MK
116/* Fill register REGNUM (if it is a general-purpose register) in
117 *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
fcc9bf01
MK
118 do this for all registers. */
119
c906108c 120void
7f7fe91e
UW
121fill_gregset (const struct regcache *regcache,
122 gregset_t *gregsetp, int regnum)
c906108c 123{
fcc9bf01
MK
124 greg_t *regp = (greg_t *) gregsetp;
125 int i;
126
127 for (i = 0; i < I386_NUM_GREGS; i++)
40e20472 128 if (regnum == -1 || regnum == i)
7f7fe91e 129 regcache_raw_collect (regcache, i, regp + regmap[i]);
c906108c
SS
130}
131
c5aa993b 132#endif /* HAVE_GREGSET_T */
c906108c 133
fcc9bf01 134#ifdef HAVE_FPREGSET_T
c906108c 135
fcc9bf01
MK
136/* Fill GDB's register array with the floating-point register values in
137 *FPREGSETP. */
14164c30 138
c5aa993b 139void
7f7fe91e 140supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
c906108c 141{
fcc9bf01 142 if (FP0_REGNUM == 0)
14164c30 143 return;
14164c30 144
7f7fe91e 145 i387_supply_fsave (regcache, -1, fpregsetp);
c906108c
SS
146}
147
fcc9bf01
MK
148/* Fill register REGNO (if it is a floating-point register) in
149 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
150 do this for all registers. */
c906108c
SS
151
152void
7f7fe91e
UW
153fill_fpregset (const struct regcache *regcache,
154 fpregset_t *fpregsetp, int regno)
c906108c 155{
fcc9bf01 156 if (FP0_REGNUM == 0)
14164c30 157 return;
34588f23 158
7f7fe91e 159 i387_collect_fsave (regcache, regno, fpregsetp);
c906108c
SS
160}
161
fcc9bf01 162#endif /* HAVE_FPREGSET_T */
c906108c 163
f69c55b2
MK
164#endif /* not 64-bit. */
165
c5aa993b 166#endif /* HAVE_SYS_PROCFS_H */
This page took 0.616406 seconds and 4 git commands to generate.