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