2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
29 #include <sys/types.h>
32 #include <sys/param.h>
36 #include <sys/ioctl.h>
43 #include "ieee-float.h"
45 extern void print_387_control_word (); /* i387-tdep.h */
46 extern void print_387_status_word ();
48 extern struct ext_format ext_format_i387
;
50 /* this table must line up with REGISTER_NAMES in m-i386.h */
51 /* symbols like 'EAX' come from <sys/reg.h> */
60 /* blockend is the value of u.u_ar0, and points to the
61 * place where GS is stored
63 i386_register_u_addr (blockend
, regnum
)
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
70 if (regnum
>= FP0_REGNUM
&& regnum
<= FP7_REGNUM
)
74 ubase
= blockend
+ 4 * (SS
+ 1) - KSTKSZ
;
75 fpstate
= ubase
+ ((char *)&u
.u_fpstate
- (char *)&u
);
76 return (fpstate
+ 0x1c + 10 * (regnum
- FP0_REGNUM
));
80 return (blockend
+ 4 * regmap
[regnum
]);
86 unsigned short control
;
88 unsigned short status
;
93 unsigned short code_seg
;
94 unsigned short opcode
;
95 unsigned long operand
;
96 unsigned short operand_seg
;
98 unsigned char regs
[8][10];
102 print_387_status (status
, ep
)
103 unsigned short status
;
112 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
117 print_387_status_word (status
);
124 print_387_status_word (ep
->status
);
127 print_387_control_word (ep
->control
);
128 printf ("last exception: ");
129 printf ("opcode %s; ", local_hex_string(ep
->opcode
));
130 printf ("pc %s:", local_hex_string(ep
->code_seg
));
131 printf ("%s; ", local_hex_string(ep
->eip
));
132 printf ("operand %s", local_hex_string(ep
->operand_seg
));
133 printf (":%s\n", local_hex_string(ep
->operand
));
135 top
= (ep
->status
>> 11) & 7;
137 printf ("regno tag msb lsb value\n");
138 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
142 printf ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
144 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
146 case 0: printf ("valid "); break;
147 case 1: printf ("zero "); break;
148 case 2: printf ("trap "); break;
149 case 3: printf ("empty "); break;
151 for (i
= 9; i
>= 0; i
--)
152 printf ("%02x", ep
->regs
[fpreg
][i
]);
154 ieee_extended_to_double (&ext_format_i387
, (char *)ep
->regs
[fpreg
],
156 printf (" %g\n", val
);
159 printf ("warning: reserved0 is %s\n", local_hex_string(ep
->r0
));
161 printf ("warning: reserved1 is %s\n", local_hex_string(ep
->r1
));
163 printf ("warning: reserved2 is %s\n", local_hex_string(ep
->r2
));
165 printf ("warning: reserved3 is %s\n", local_hex_string(ep
->r3
));
169 #define U_FPSTATE(u) u.u_fpstate
174 struct user u
; /* just for address computations */
176 /* fpstate defined in <sys/user.h> */
177 struct fpstate
*fpstatep
;
178 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
181 unsigned int rounded_addr
;
182 unsigned int rounded_size
;
186 uaddr
= (char *)&u
.u_fpvalid
- (char *)&u
;
187 if (have_inferior_p())
192 rounded_addr
= uaddr
& -sizeof (int);
193 data
= ptrace (3, inferior_pid
, rounded_addr
, 0);
194 mask
= 0xff << ((uaddr
- rounded_addr
) * 8);
196 fpvalid
= ((data
& mask
) != 0);
200 if (lseek (corechan
, uaddr
, 0) < 0)
201 perror ("seek on core file");
202 if (myread (corechan
, &fpvalid
, 1) < 0)
203 perror ("read on core file");
209 printf ("no floating point status saved\n");
213 uaddr
= (char *)&U_FPSTATE(u
) - (char *)&u
;
214 if (have_inferior_p ())
218 rounded_addr
= uaddr
& -sizeof (int);
219 rounded_size
= (((uaddr
+ sizeof (struct fpstate
)) - uaddr
) +
220 sizeof (int) - 1) / sizeof (int);
221 skip
= uaddr
- rounded_addr
;
224 for (i
= 0; i
< rounded_size
; i
++)
226 *ip
++ = ptrace (3, inferior_pid
, rounded_addr
, 0);
227 rounded_addr
+= sizeof (int);
232 if (lseek (corechan
, uaddr
, 0) < 0)
233 perror_with_name ("seek on core file");
234 if (myread (corechan
, buf
, sizeof (struct fpstate
)) < 0)
235 perror_with_name ("read from core file");
239 fpstatep
= (struct fpstate
*)(buf
+ skip
);
240 print_387_status (fpstatep
->status
, (struct env387
*)fpstatep
->state
);