2002-04-25 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / i386v4-nat.c
CommitLineData
c906108c 1/* Native-dependent code for SVR4 Unix running on i386's, for GDB.
b6ba6518
KB
2 Copyright 1988, 1989, 1991, 1992, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include "value.h"
7a292a7a 24#include "inferior.h"
4e052eda 25#include "regcache.h"
c906108c
SS
26
27#ifdef HAVE_SYS_REG_H
28#include <sys/reg.h>
29#endif
69824b4e 30#include "i387-nat.h"
c906108c
SS
31
32
33#ifdef HAVE_SYS_PROCFS_H
34
35#include <sys/procfs.h>
36
c60c0f5f
MS
37/* Prototypes for supply_gregset etc. */
38#include "gregset.h"
39
c906108c 40/* The /proc interface divides the target machine's register set up into
c5aa993b
JM
41 two different sets, the general register set (gregset) and the floating
42 point register set (fpregset). For each set, there is an ioctl to get
43 the current register set and another ioctl to set the current values.
44
45 The actual structure passed through the ioctl interface is, of course,
46 naturally machine dependent, and is different for each set of registers.
47 For the i386 for example, the general register set is typically defined
48 by:
49
50 typedef int gregset_t[19]; (in <sys/regset.h>)
51
52 #define GS 0 (in <sys/reg.h>)
53 #define FS 1
54 ...
55 #define UESP 17
56 #define SS 18
57
58 and the floating point set by:
59
60 typedef struct fpregset
61 {
62 union
63 {
64 struct fpchip_state // fp extension state //
65 {
66 int state[27]; // 287/387 saved state //
67 int status; // status word saved at exception //
68 } fpchip_state;
69 struct fp_emul_space // for emulators //
70 {
71 char fp_emul[246];
72 char fp_epad[2];
73 } fp_emul_space;
74 int f_fpregs[62]; // union of the above //
75 } fp_reg_set;
76 long f_wregs[33]; // saved weitek state //
77 } fpregset_t;
78
79 These routines provide the packing and unpacking of gregset_t and
80 fpregset_t formatted data.
c906108c
SS
81
82 */
83
84#ifdef HAVE_GREGSET_T
85
86/* This is a duplicate of the table in i386-xdep.c. */
87
c5aa993b 88static int regmap[] =
c906108c
SS
89{
90 EAX, ECX, EDX, EBX,
91 UESP, EBP, ESI, EDI,
92 EIP, EFL, CS, SS,
93 DS, ES, FS, GS,
94};
95
96/* Prototypes for local functions */
97
a14ed312 98void fill_gregset (gregset_t *, int);
c906108c 99
a14ed312 100void supply_gregset (gregset_t *);
c906108c 101
a14ed312 102void supply_fpregset (fpregset_t *);
c906108c 103
a14ed312 104void fill_fpregset (fpregset_t *, int);
c906108c
SS
105
106
107/* FIXME: These routine absolutely depends upon (NUM_REGS - NUM_FREGS)
c5aa993b
JM
108 being less than or equal to the number of registers that can be stored
109 in a gregset_t. Note that with the current scheme there will typically
110 be more registers actually stored in a gregset_t that what we know
111 about. This is bogus and should be fixed. */
c906108c
SS
112
113/* Given a pointer to a general register set in /proc format (gregset_t *),
c5aa993b
JM
114 unpack the register contents and supply them as gdb's idea of the current
115 register values. */
c906108c
SS
116
117void
fba45db2 118supply_gregset (gregset_t *gregsetp)
c906108c
SS
119{
120 register int regi;
121 register greg_t *regp = (greg_t *) gregsetp;
122 extern int regmap[];
123
c5aa993b 124 for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++)
c906108c
SS
125 {
126 supply_register (regi, (char *) (regp + regmap[regi]));
127 }
128}
129
130void
fba45db2 131fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
132{
133 int regi;
134 register greg_t *regp = (greg_t *) gregsetp;
c906108c
SS
135 extern int regmap[];
136
c5aa993b 137 for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++)
c906108c
SS
138 {
139 if ((regno == -1) || (regno == regi))
140 {
141 *(regp + regmap[regi]) = *(int *) &registers[REGISTER_BYTE (regi)];
142 }
143 }
144}
145
c5aa993b 146#endif /* HAVE_GREGSET_T */
c906108c 147
14164c30 148#if defined (HAVE_FPREGSET_T)
c906108c
SS
149
150/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
151 (fpregset_t *), unpack the register contents and supply them as gdb's
152 idea of the current floating point register values. */
c906108c 153
14164c30 154/* FIXME: Assumes that fpregsetp contains an i387 FSAVE area. */
14164c30
PS
155#if !defined(FPREGSET_FSAVE_OFFSET)
156#define FPREGSET_FSAVE_OFFSET 0
157#endif
14164c30 158
c5aa993b 159void
fba45db2 160supply_fpregset (fpregset_t *fpregsetp)
c906108c 161{
14164c30
PS
162 if (NUM_FREGS == 0)
163 return;
14164c30 164
34588f23 165 i387_supply_fsave ((char *) fpregsetp + FPREGSET_FSAVE_OFFSET);
c906108c
SS
166}
167
168/* Given a pointer to a floating point register set in /proc format
c5aa993b
JM
169 (fpregset_t *), update the register specified by REGNO from gdb's idea
170 of the current floating point register set. If REGNO is -1, update
171 them all. */
c906108c
SS
172
173void
fba45db2 174fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c 175{
14164c30
PS
176 if (NUM_FREGS == 0)
177 return;
34588f23
MK
178
179 i387_fill_fsave ((char *) fpregsetp + FPREGSET_FSAVE_OFFSET, regno);
c906108c
SS
180}
181
14164c30 182#endif /* defined (HAVE_FPREGSET_T) */
c906108c 183
c5aa993b 184#endif /* HAVE_SYS_PROCFS_H */
This page took 0.172826 seconds and 4 git commands to generate.