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