* inf-ptrace.c: Reorder functions.
[deliverable/binutils-gdb.git] / gdb / i386v4-nat.c
1 /* Native-dependent code for Unix SVR4 running on i386's.
2
3 Copyright 1988, 1989, 1991, 1992, 1996, 1997, 1998, 1999, 2000,
4 2001, 2002, 2004
5 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
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.
13
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.
18
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. */
23
24 #include "defs.h"
25 #include "value.h"
26 #include "inferior.h"
27 #include "regcache.h"
28
29 #ifdef HAVE_SYS_REG_H
30 #include <sys/reg.h>
31 #endif
32
33 #include "i386-tdep.h"
34 #include "i387-tdep.h"
35
36 #ifdef HAVE_SYS_PROCFS_H
37
38 #include <sys/procfs.h>
39
40 /* We must not compile this code for 64-bit Solaris x86. */
41 #if !defined (PR_MODEL_NATIVE) || (PR_MODEL_NATIVE == PR_MODEL_ILP32)
42
43 #include "gregset.h"
44
45 /* The `/proc' interface divides the target machine's register set up
46 into two different sets, the general purpose register set (gregset)
47 and the floating-point register set (fpregset). For each set,
48 there is an ioctl to get the current register set and another ioctl
49 to set the current values.
50
51 The actual structure passed through the ioctl interface is, of
52 course, naturally machine dependent, and is different for each set
53 of registers. For the i386 for example, the general-purpose
54 register set is typically defined by:
55
56 typedef int gregset_t[19]; (in <sys/regset.h>)
57
58 #define GS 0 (in <sys/reg.h>)
59 #define FS 1
60 ...
61 #define UESP 17
62 #define SS 18
63
64 and the floating-point set by:
65
66 typedef struct fpregset {
67 union {
68 struct fpchip_state // fp extension state //
69 {
70 int state[27]; // 287/387 saved state //
71 int status; // status word saved at //
72 // exception //
73 } fpchip_state;
74 struct fp_emul_space // for emulators //
75 {
76 char fp_emul[246];
77 char fp_epad[2];
78 } fp_emul_space;
79 int f_fpregs[62]; // union of the above //
80 } fp_reg_set;
81 long f_wregs[33]; // saved weitek state //
82 } fpregset_t;
83
84 Incidentally fpchip_state contains the FPU state in the same format
85 as used by the "fsave" instruction, and that's the only thing we
86 support here. I don't know how the emulator stores it state. The
87 Weitek stuff definitely isn't supported.
88
89 The routines defined here, provide the packing and unpacking of
90 gregset_t and fpregset_t formatted data. */
91
92 #ifdef HAVE_GREGSET_T
93
94 /* Mapping between the general-purpose registers in `/proc'
95 format and GDB's register array layout. */
96 static int regmap[] =
97 {
98 EAX, ECX, EDX, EBX,
99 UESP, EBP, ESI, EDI,
100 EIP, EFL, CS, SS,
101 DS, ES, FS, GS
102 };
103
104 /* Fill GDB's register array with the general-purpose register values
105 in *GREGSETP. */
106
107 void
108 supply_gregset (gregset_t *gregsetp)
109 {
110 greg_t *regp = (greg_t *) gregsetp;
111 int regnum;
112
113 for (regnum = 0; regnum < I386_NUM_GREGS; regnum++)
114 regcache_raw_supply (current_regcache, regnum, regp + regmap[regnum]);
115 }
116
117 /* Fill register REGNUM (if it is a general-purpose register) in
118 *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
119 do this for all registers. */
120
121 void
122 fill_gregset (gregset_t *gregsetp, int regnum)
123 {
124 greg_t *regp = (greg_t *) gregsetp;
125 int i;
126
127 for (i = 0; i < I386_NUM_GREGS; i++)
128 if (regnum == -1 || regnum == i)
129 regcache_raw_collect (current_regcache, i, regp + regmap[i]);
130 }
131
132 #endif /* HAVE_GREGSET_T */
133
134 #ifdef HAVE_FPREGSET_T
135
136 /* Fill GDB's register array with the floating-point register values in
137 *FPREGSETP. */
138
139 void
140 supply_fpregset (fpregset_t *fpregsetp)
141 {
142 if (FP0_REGNUM == 0)
143 return;
144
145 i387_supply_fsave (current_regcache, -1, fpregsetp);
146 }
147
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. */
151
152 void
153 fill_fpregset (fpregset_t *fpregsetp, int regno)
154 {
155 if (FP0_REGNUM == 0)
156 return;
157
158 i387_fill_fsave ((char *) fpregsetp, regno);
159 }
160
161 #endif /* HAVE_FPREGSET_T */
162
163 #endif /* not 64-bit. */
164
165 #endif /* HAVE_SYS_PROCFS_H */
This page took 0.031713 seconds and 4 git commands to generate.