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