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