import gdb-1999-12-06 snapshot
[deliverable/binutils-gdb.git] / gdb / i386b-nat.c
CommitLineData
c906108c
SS
1/* Native-dependent code for BSD Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b
JM
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. */
c906108c
SS
20
21#include "defs.h"
22
23#ifdef FETCH_INFERIOR_REGISTERS
24#include <sys/types.h>
25#include <sys/ptrace.h>
26#include <machine/reg.h>
27#include <machine/frame.h>
28#include "inferior.h"
c2d11a7d 29#include "gdbcore.h" /* for registers_fetched() */
c906108c
SS
30
31void
c5aa993b 32fetch_inferior_registers (regno)
c906108c
SS
33 int regno;
34{
35 struct reg inferior_registers;
36
c5aa993b
JM
37 ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) & inferior_registers, 0);
38 memcpy (&registers[REGISTER_BYTE (0)], &inferior_registers, 4 * NUM_REGS);
c906108c
SS
39 registers_fetched ();
40}
41
42void
c5aa993b 43store_inferior_registers (regno)
c906108c
SS
44 int regno;
45{
46 struct reg inferior_registers;
47
c5aa993b
JM
48 memcpy (&inferior_registers, &registers[REGISTER_BYTE (0)], 4 * NUM_REGS);
49 ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) & inferior_registers, 0);
c906108c
SS
50}
51
c5aa993b
JM
52struct md_core
53{
c906108c
SS
54 struct reg intreg;
55 struct fpreg freg;
56};
57
58void
59fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
60 char *core_reg_sect;
61 unsigned core_reg_size;
62 int which;
63 CORE_ADDR ignore;
64{
c5aa993b 65 struct md_core *core_reg = (struct md_core *) core_reg_sect;
c906108c
SS
66
67 /* integer registers */
c5aa993b
JM
68 memcpy (&registers[REGISTER_BYTE (0)], &core_reg->intreg,
69 sizeof (struct reg));
c906108c
SS
70 /* floating point registers */
71 /* XXX */
72}
73
74#else
75
76#include <machine/reg.h>
77
78/* this table must line up with REGISTER_NAMES in tm-i386.h */
79/* symbols like 'tEAX' come from <machine/reg.h> */
c5aa993b 80static int tregmap[] =
c906108c
SS
81{
82 tEAX, tECX, tEDX, tEBX,
83 tESP, tEBP, tESI, tEDI,
84 tEIP, tEFLAGS, tCS, tSS
85};
86
87#ifdef sEAX
c5aa993b 88static int sregmap[] =
c906108c
SS
89{
90 sEAX, sECX, sEDX, sEBX,
91 sESP, sEBP, sESI, sEDI,
92 sEIP, sEFLAGS, sCS, sSS
93};
94#else /* No sEAX */
95
96/* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
97 ones aren't around, use the t* ones for sregmap too. */
98
c5aa993b 99static int sregmap[] =
c906108c
SS
100{
101 tEAX, tECX, tEDX, tEBX,
102 tESP, tEBP, tESI, tEDI,
103 tEIP, tEFLAGS, tCS, tSS
104};
105#endif /* No sEAX */
106
107/* blockend is the value of u.u_ar0, and points to the
108 place where ES is stored. */
109
110int
111i386_register_u_addr (blockend, regnum)
112 int blockend;
113 int regnum;
114{
115 /* The following condition is a kludge to get at the proper register map
116 depending upon the state of pcb_flag.
117 The proper condition would be
118 if (u.u_pcb.pcb_flag & FM_TRAP)
119 but that would require a ptrace call here and wouldn't work
120 for corefiles. */
121
122 if (blockend < 0x1fcc)
123 return (blockend + 4 * tregmap[regnum]);
124 else
125 return (blockend + 4 * sregmap[regnum]);
126}
127
128#endif /* !FETCH_INFERIOR_REGISTERS */
129
130#ifdef FLOAT_INFO
131#include "expression.h"
c5aa993b 132#include "language.h" /* for local_hex_string */
c906108c
SS
133#include "floatformat.h"
134
135#include <sys/param.h>
136#include <sys/dir.h>
137#include <signal.h>
138#include <sys/ioctl.h>
139#include <fcntl.h>
140
141#include <a.out.h>
142
143#include <sys/time.h>
144#include <sys/resource.h>
145#include <sys/uio.h>
c5aa993b 146#define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
c906108c
SS
147#include <sys/user.h>
148#undef curpcb
149#include <sys/file.h>
150#include "gdb_stat.h"
151#include <sys/ptrace.h>
152
c5aa993b 153extern void print_387_control_word (); /* i387-tdep.h */
c906108c
SS
154extern void print_387_status_word ();
155
156#define fpstate save87
157#define U_FPSTATE(u) u.u_pcb.pcb_savefpu
158
c5aa993b
JM
159struct env387
160 {
161 unsigned short control;
162 unsigned short r0;
163 unsigned short status;
164 unsigned short r1;
165 unsigned short tag;
166 unsigned short r2;
167 unsigned long eip;
168 unsigned short code_seg;
169 unsigned short opcode;
170 unsigned long operand;
171 unsigned short operand_seg;
172 unsigned short r3;
173 unsigned char regs[8][10];
174 };
c906108c
SS
175
176static void
177print_387_status (status, ep)
178 unsigned short status;
179 struct env387 *ep;
180{
181 int i;
182 int bothstatus;
183 int top;
184 int fpreg;
c5aa993b 185
c906108c 186 bothstatus = ((status != 0) && (ep->status != 0));
c5aa993b 187 if (status != 0)
c906108c
SS
188 {
189 if (bothstatus)
190 printf_unfiltered ("u: ");
c5aa993b 191 print_387_status_word ((unsigned int) status);
c906108c 192 }
c5aa993b
JM
193
194 if (ep->status != 0)
c906108c
SS
195 {
196 if (bothstatus)
197 printf_unfiltered ("e: ");
c5aa993b 198 print_387_status_word ((unsigned int) ep->status);
c906108c 199 }
c5aa993b
JM
200
201 print_387_control_word ((unsigned int) ep->control);
c906108c 202 printf_unfiltered ("last exception: ");
c5aa993b
JM
203 printf_unfiltered ("opcode %s; ", local_hex_string (ep->opcode));
204 printf_unfiltered ("pc %s:", local_hex_string (ep->code_seg));
205 printf_unfiltered ("%s; ", local_hex_string (ep->eip));
206 printf_unfiltered ("operand %s", local_hex_string (ep->operand_seg));
207 printf_unfiltered (":%s\n", local_hex_string (ep->operand));
c906108c
SS
208
209 top = (ep->status >> 11) & 7;
c5aa993b 210
c906108c 211 printf_unfiltered ("regno tag msb lsb value\n");
c5aa993b 212 for (fpreg = 7; fpreg >= 0; fpreg--)
c906108c
SS
213 {
214 double val;
c906108c 215
c5aa993b
JM
216 printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
217
218 switch ((ep->tag >> (fpreg * 2)) & 3)
c906108c 219 {
c5aa993b
JM
220 case 0:
221 printf_unfiltered ("valid ");
222 break;
223 case 1:
224 printf_unfiltered ("zero ");
225 break;
226 case 2:
227 printf_unfiltered ("trap ");
228 break;
229 case 3:
230 printf_unfiltered ("empty ");
231 break;
c906108c
SS
232 }
233 for (i = 9; i >= 0; i--)
234 printf_unfiltered ("%02x", ep->regs[fpreg][i]);
c5aa993b
JM
235
236 floatformat_to_double (&floatformat_i387_ext, (char *) ep->regs[fpreg],
237 &val);
c906108c
SS
238 printf_unfiltered (" %g\n", val);
239 }
240}
241
242i386_float_info ()
243{
c5aa993b 244 struct user u; /* just for address computations */
c906108c
SS
245 int i;
246 /* fpstate defined in <sys/user.h> */
247 struct fpstate *fpstatep;
248 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
249 unsigned int uaddr;
250 char fpvalid;
251 unsigned int rounded_addr;
252 unsigned int rounded_size;
c5aa993b 253 /*extern int corechan; */
c906108c
SS
254 int skip;
255 extern int inferior_pid;
c5aa993b
JM
256
257 uaddr = (char *) &U_FPSTATE (u) - (char *) &u;
258 if (inferior_pid)
c906108c
SS
259 {
260 int *ip;
c5aa993b 261
c906108c
SS
262 rounded_addr = uaddr & -sizeof (int);
263 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
264 sizeof (int) - 1) / sizeof (int);
265 skip = uaddr - rounded_addr;
c5aa993b
JM
266
267 ip = (int *) buf;
268 for (i = 0; i < rounded_size; i++)
c906108c 269 {
c5aa993b 270 *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t) rounded_addr, 0);
c906108c
SS
271 rounded_addr += sizeof (int);
272 }
c5aa993b
JM
273 }
274 else
c906108c 275 {
c5aa993b 276 printf ("float info: can't do a core file (yet)\n");
c906108c
SS
277 return;
278#if 0
279 if (lseek (corechan, uaddr, 0) < 0)
280 perror_with_name ("seek on core file");
c5aa993b
JM
281 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
282 perror_with_name ("read from core file");
c906108c
SS
283 skip = 0;
284#endif
285 }
c5aa993b
JM
286
287 print_387_status (0, (struct env387 *) buf);
c906108c
SS
288}
289
290int
291kernel_u_size ()
292{
293 return (sizeof (struct user));
294}
295
296#endif
This page took 0.047576 seconds and 4 git commands to generate.