* xm-sun3os4.h, xm-sun4os4.h: Enable HAVE_MMAP.
[deliverable/binutils-gdb.git] / gdb / i386-xdep.c
1 /* Intel 386 stuff.
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include "defs.h"
22 #include "frame.h"
23 #include "inferior.h"
24 #include "language.h"
25 #include "gdbcore.h"
26
27 #ifdef USG
28 #include <sys/types.h>
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/dir.h>
33 #include <signal.h>
34 #include <sys/user.h>
35 #include <sys/ioctl.h>
36 #include <fcntl.h>
37
38 #include <sys/file.h>
39 #include <sys/stat.h>
40
41 #include <sys/reg.h>
42 #include "ieee-float.h"
43
44 #include "target.h"
45
46 extern struct ext_format ext_format_i387;
47 \f
48 /* this table must line up with REGISTER_NAMES in m-i386.h */
49 /* symbols like 'EAX' come from <sys/reg.h> */
50 static int regmap[] =
51 {
52 EAX, ECX, EDX, EBX,
53 UESP, EBP, ESI, EDI,
54 EIP, EFL, CS, SS,
55 DS, ES, FS, GS,
56 };
57
58 /* blockend is the value of u.u_ar0, and points to the
59 * place where GS is stored
60 */
61
62 int
63 i386_register_u_addr (blockend, regnum)
64 int blockend;
65 int regnum;
66 {
67 #if 0
68 /* this will be needed if fp registers are reinstated */
69 /* for now, you can look at them with 'info float'
70 * sys5 wont let you change them with ptrace anyway
71 */
72 if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM)
73 {
74 int ubase, fpstate;
75 struct user u;
76 ubase = blockend + 4 * (SS + 1) - KSTKSZ;
77 fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u);
78 return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM));
79 }
80 else
81 #endif
82 return (blockend + 4 * regmap[regnum]);
83
84 }
85
86 #if 0
87 /* mauro@olympus 1991.10.20 -- compiling the following code causes
88 undefined symbols at link time, specifically: corechan, have_inferior_p */
89 struct env387
90 {
91 unsigned short control;
92 unsigned short r0;
93 unsigned short status;
94 unsigned short r1;
95 unsigned short tag;
96 unsigned short r2;
97 unsigned long eip;
98 unsigned short code_seg;
99 unsigned short opcode;
100 unsigned long operand;
101 unsigned short operand_seg;
102 unsigned short r3;
103 unsigned char regs[8][10];
104 };
105
106 static
107 print_387_status (status, ep)
108 unsigned short status;
109 struct env387 *ep;
110 {
111 int i;
112 int bothstatus;
113 int top;
114 int fpreg;
115 unsigned char *p;
116
117 bothstatus = ((status != 0) && (ep->status != 0));
118 if (status != 0)
119 {
120 if (bothstatus)
121 printf ("u: ");
122 print_387_status_word (status);
123 }
124
125 if (ep->status != 0)
126 {
127 if (bothstatus)
128 printf ("e: ");
129 print_387_status_word (ep->status);
130 }
131
132 print_387_control_word (ep->control);
133 printf ("last exception: ");
134 printf ("opcode %s; ", local_hex_string(ep->opcode));
135 printf ("pc %s:", local_hex_string(ep->code_seg));
136 printf ("%s; ", local_hex_string(ep->eip));
137 printf ("operand %s", local_hex_string(ep->operand_seg));
138 printf (":%s\n", local_hex_string(ep->operand));
139
140 top = (ep->status >> 11) & 7;
141
142 printf ("regno tag msb lsb value\n");
143 for (fpreg = 7; fpreg >= 0; fpreg--)
144 {
145 double val;
146
147 printf ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
148
149 switch ((ep->tag >> (fpreg * 2)) & 3)
150 {
151 case 0: printf ("valid "); break;
152 case 1: printf ("zero "); break;
153 case 2: printf ("trap "); break;
154 case 3: printf ("empty "); break;
155 }
156 for (i = 9; i >= 0; i--)
157 printf ("%02x", ep->regs[fpreg][i]);
158
159 ieee_extended_to_double (&ext_format_i387, (char *)ep->regs[fpreg],
160 &val);
161 printf (" %g\n", val);
162 }
163 if (ep->r0)
164 printf ("warning: reserved0 is %s\n", local_hex_string(ep->r0));
165 if (ep->r1)
166 printf ("warning: reserved1 is %s\n", local_hex_string(ep->r1));
167 if (ep->r2)
168 printf ("warning: reserved2 is %s\n", local_hex_string(ep->r2));
169 if (ep->r3)
170 printf ("warning: reserved3 is %s\n", local_hex_string(ep->r3));
171 }
172
173 #ifndef U_FPSTATE
174 #define U_FPSTATE(u) u.u_fpstate
175 #endif
176
177 i386_float_info ()
178 {
179 struct user u; /* just for address computations */
180 int i;
181 /* fpstate defined in <sys/user.h> */
182 struct fpstate *fpstatep;
183 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
184 unsigned int uaddr;
185 char fpvalid = 0;
186 unsigned int rounded_addr;
187 unsigned int rounded_size;
188 extern int corechan;
189 int skip;
190
191 uaddr = (char *)&u.u_fpvalid - (char *)&u;
192 if (target_has_execution)
193 {
194 unsigned int data;
195 unsigned int mask;
196
197 rounded_addr = uaddr & -sizeof (int);
198 data = ptrace (3, inferior_pid, rounded_addr, 0);
199 mask = 0xff << ((uaddr - rounded_addr) * 8);
200
201 fpvalid = ((data & mask) != 0);
202 }
203 #if 0
204 else
205 {
206 if (lseek (corechan, uaddr, 0) < 0)
207 perror ("seek on core file");
208 if (myread (corechan, &fpvalid, 1) < 0)
209 perror ("read on core file");
210
211 }
212 #endif /* no core support yet */
213
214 if (fpvalid == 0)
215 {
216 printf ("no floating point status saved\n");
217 return;
218 }
219
220 uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
221 if (target_has_execution)
222 {
223 int *ip;
224
225 rounded_addr = uaddr & -sizeof (int);
226 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
227 sizeof (int) - 1) / sizeof (int);
228 skip = uaddr - rounded_addr;
229
230 ip = (int *)buf;
231 for (i = 0; i < rounded_size; i++)
232 {
233 *ip++ = ptrace (3, inferior_pid, rounded_addr, 0);
234 rounded_addr += sizeof (int);
235 }
236 }
237 #if 0
238 else
239 {
240 if (lseek (corechan, uaddr, 0) < 0)
241 perror_with_name ("seek on core file");
242 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
243 perror_with_name ("read from core file");
244 skip = 0;
245 }
246 #endif /* 0 */
247
248 fpstatep = (struct fpstate *)(buf + skip);
249 print_387_status (fpstatep->status, (struct env387 *)fpstatep->state);
250 }
251 #endif /* mauro@olympus 1991.10.20 */
This page took 0.034346 seconds and 4 git commands to generate.