1 /* Native-dependent code for SVR4 Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1996, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
30 #ifdef HAVE_SYS_PROCFS_H
32 #include <sys/procfs.h>
34 /* Prototypes for supply_gregset etc. */
37 /* The /proc interface divides the target machine's register set up into
38 two different sets, the general register set (gregset) and the floating
39 point register set (fpregset). For each set, there is an ioctl to get
40 the current register set and another ioctl to set the current values.
42 The actual structure passed through the ioctl interface is, of course,
43 naturally machine dependent, and is different for each set of registers.
44 For the i386 for example, the general register set is typically defined
47 typedef int gregset_t[19]; (in <sys/regset.h>)
49 #define GS 0 (in <sys/reg.h>)
55 and the floating point set by:
57 typedef struct fpregset
61 struct fpchip_state // fp extension state //
63 int state[27]; // 287/387 saved state //
64 int status; // status word saved at exception //
66 struct fp_emul_space // for emulators //
71 int f_fpregs[62]; // union of the above //
73 long f_wregs[33]; // saved weitek state //
76 These routines provide the packing and unpacking of gregset_t and
77 fpregset_t formatted data.
83 /* This is a duplicate of the table in i386-xdep.c. */
93 /* Prototypes for local functions */
95 void fill_gregset PARAMS ((gregset_t *, int));
97 void supply_gregset PARAMS ((gregset_t *));
99 void supply_fpregset PARAMS ((fpregset_t *));
101 void fill_fpregset PARAMS ((fpregset_t *, int));
104 /* FIXME: These routine absolutely depends upon (NUM_REGS - NUM_FREGS)
105 being less than or equal to the number of registers that can be stored
106 in a gregset_t. Note that with the current scheme there will typically
107 be more registers actually stored in a gregset_t that what we know
108 about. This is bogus and should be fixed. */
110 /* Given a pointer to a general register set in /proc format (gregset_t *),
111 unpack the register contents and supply them as gdb's idea of the current
115 supply_gregset (gregsetp)
119 register greg_t *regp = (greg_t *) gregsetp;
122 for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++)
124 supply_register (regi, (char *) (regp + regmap[regi]));
129 fill_gregset (gregsetp, regno)
134 register greg_t *regp = (greg_t *) gregsetp;
137 for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++)
139 if ((regno == -1) || (regno == regi))
141 *(regp + regmap[regi]) = *(int *) ®isters[REGISTER_BYTE (regi)];
146 #endif /* HAVE_GREGSET_T */
148 #if defined (HAVE_FPREGSET_T)
150 /* Given a pointer to a floating point register set in /proc format
151 (fpregset_t *), unpack the register contents and supply them as gdb's
152 idea of the current floating point register values. */
154 /* FIXME: Assumes that fpregsetp contains an i387 FSAVE area. */
155 static const int freg_offset_map[] =
157 #if !defined(FPREGSET_FSAVE_OFFSET)
158 #define FPREGSET_FSAVE_OFFSET 0
160 FPREGSET_FSAVE_OFFSET + 28 + 0 * 10,
161 FPREGSET_FSAVE_OFFSET + 28 + 1 * 10,
162 FPREGSET_FSAVE_OFFSET + 28 + 2 * 10,
163 FPREGSET_FSAVE_OFFSET + 28 + 3 * 10,
164 FPREGSET_FSAVE_OFFSET + 28 + 4 * 10,
165 FPREGSET_FSAVE_OFFSET + 28 + 5 * 10,
166 FPREGSET_FSAVE_OFFSET + 28 + 6 * 10,
167 FPREGSET_FSAVE_OFFSET + 28 + 7 * 10,
168 FPREGSET_FSAVE_OFFSET + 0,
169 FPREGSET_FSAVE_OFFSET + 4,
170 FPREGSET_FSAVE_OFFSET + 8,
171 FPREGSET_FSAVE_OFFSET + 16,
172 FPREGSET_FSAVE_OFFSET + 12,
173 FPREGSET_FSAVE_OFFSET + 24,
174 FPREGSET_FSAVE_OFFSET + 20,
175 FPREGSET_FSAVE_OFFSET + 16
179 supply_fpregset (fpregsetp)
180 fpregset_t *fpregsetp;
186 for (regi = FP0_REGNUM; regi <= LAST_FPU_CTRL_REGNUM; regi++)
190 char *from = (char *) fpregsetp + freg_offset_map[regi - FP0_REGNUM];
192 if (regi == FCS_REGNUM)
194 tval = extract_unsigned_integer (from, 4) & 0xffff;
195 store_unsigned_integer (tbuf, 4, tval);
196 supply_register (regi, tbuf);
198 else if (regi == FOP_REGNUM)
200 tval = (extract_unsigned_integer (from, 4) >> 16) & ((1 << 11) - 1);
201 store_unsigned_integer (tbuf, 4, tval);
202 supply_register (regi, tbuf);
205 supply_register (regi, from);
209 /* Given a pointer to a floating point register set in /proc format
210 (fpregset_t *), update the register specified by REGNO from gdb's idea
211 of the current floating point register set. If REGNO is -1, update
215 fill_fpregset (fpregsetp, regno)
216 fpregset_t *fpregsetp;
223 for (regi = FP0_REGNUM; regi <= LAST_FPU_CTRL_REGNUM; regi++)
225 if ((regno == -1) || (regno == regi))
227 char *to = (char *) fpregsetp + freg_offset_map[regi - FP0_REGNUM];
228 char *from = (char *) ®isters[REGISTER_BYTE (regi)];
232 if (regi == FCS_REGNUM)
234 valto = extract_unsigned_integer (to, 4);
235 valfrom = extract_unsigned_integer (from, 4);
236 valto = (valto & ~0xffff) | (valfrom & 0xffff);
237 store_unsigned_integer (to, 4, valto);
239 else if (regi == FOP_REGNUM)
241 valto = extract_unsigned_integer (to, 4);
242 valfrom = extract_unsigned_integer (from, 4);
243 valto = (valto & 0xffff) | ((valfrom & ((1 << 11) - 1)) << 16);
244 store_unsigned_integer (to, 4, valto);
248 memcpy (to, from, REGISTER_RAW_SIZE (regi));
254 #endif /* defined (HAVE_FPREGSET_T) */
256 #endif /* HAVE_SYS_PROCFS_H */