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.
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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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>
31 fetch_inferior_registers (regno
)
34 struct reg inferior_registers
;
36 ptrace (PT_GETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
37 memcpy (®isters
[REGISTER_BYTE (0)], &inferior_registers
, 4 * NUM_REGS
);
42 store_inferior_registers (regno
)
45 struct reg inferior_registers
;
47 memcpy (&inferior_registers
, ®isters
[REGISTER_BYTE (0)], 4 * NUM_REGS
);
48 ptrace (PT_SETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
58 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, ignore
)
60 unsigned core_reg_size
;
64 struct md_core
*core_reg
= (struct md_core
*) core_reg_sect
;
66 /* integer registers */
67 memcpy (®isters
[REGISTER_BYTE (0)], &core_reg
->intreg
,
69 /* floating point registers */
75 #include <machine/reg.h>
77 /* this table must line up with REGISTER_NAMES in tm-i386.h */
78 /* symbols like 'tEAX' come from <machine/reg.h> */
79 static int tregmap
[] =
81 tEAX
, tECX
, tEDX
, tEBX
,
82 tESP
, tEBP
, tESI
, tEDI
,
83 tEIP
, tEFLAGS
, tCS
, tSS
87 static int sregmap
[] =
89 sEAX
, sECX
, sEDX
, sEBX
,
90 sESP
, sEBP
, sESI
, sEDI
,
91 sEIP
, sEFLAGS
, sCS
, sSS
95 /* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
96 ones aren't around, use the t* ones for sregmap too. */
98 static int sregmap
[] =
100 tEAX
, tECX
, tEDX
, tEBX
,
101 tESP
, tEBP
, tESI
, tEDI
,
102 tEIP
, tEFLAGS
, tCS
, tSS
106 /* blockend is the value of u.u_ar0, and points to the
107 place where ES is stored. */
110 i386_register_u_addr (blockend
, regnum
)
114 /* The following condition is a kludge to get at the proper register map
115 depending upon the state of pcb_flag.
116 The proper condition would be
117 if (u.u_pcb.pcb_flag & FM_TRAP)
118 but that would require a ptrace call here and wouldn't work
121 if (blockend
< 0x1fcc)
122 return (blockend
+ 4 * tregmap
[regnum
]);
124 return (blockend
+ 4 * sregmap
[regnum
]);
127 #endif /* !FETCH_INFERIOR_REGISTERS */
130 #include "expression.h"
131 #include "language.h" /* for local_hex_string */
132 #include "floatformat.h"
134 #include <sys/param.h>
137 #include <sys/ioctl.h>
142 #include <sys/time.h>
143 #include <sys/resource.h>
145 #define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
146 #include <sys/user.h>
148 #include <sys/file.h>
149 #include "gdb_stat.h"
150 #include <sys/ptrace.h>
152 extern void print_387_control_word (); /* i387-tdep.h */
153 extern void print_387_status_word ();
155 #define fpstate save87
156 #define U_FPSTATE(u) u.u_pcb.pcb_savefpu
160 unsigned short control
;
162 unsigned short status
;
167 unsigned short code_seg
;
168 unsigned short opcode
;
169 unsigned long operand
;
170 unsigned short operand_seg
;
172 unsigned char regs
[8][10];
176 print_387_status (status
, ep
)
177 unsigned short status
;
185 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
189 printf_unfiltered ("u: ");
190 print_387_status_word ((unsigned int) status
);
196 printf_unfiltered ("e: ");
197 print_387_status_word ((unsigned int) ep
->status
);
200 print_387_control_word ((unsigned int) ep
->control
);
201 printf_unfiltered ("last exception: ");
202 printf_unfiltered ("opcode %s; ", local_hex_string (ep
->opcode
));
203 printf_unfiltered ("pc %s:", local_hex_string (ep
->code_seg
));
204 printf_unfiltered ("%s; ", local_hex_string (ep
->eip
));
205 printf_unfiltered ("operand %s", local_hex_string (ep
->operand_seg
));
206 printf_unfiltered (":%s\n", local_hex_string (ep
->operand
));
208 top
= (ep
->status
>> 11) & 7;
210 printf_unfiltered ("regno tag msb lsb value\n");
211 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
215 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
217 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
220 printf_unfiltered ("valid ");
223 printf_unfiltered ("zero ");
226 printf_unfiltered ("trap ");
229 printf_unfiltered ("empty ");
232 for (i
= 9; i
>= 0; i
--)
233 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
235 floatformat_to_double (&floatformat_i387_ext
, (char *) ep
->regs
[fpreg
],
237 printf_unfiltered (" %g\n", val
);
243 struct user u
; /* just for address computations */
245 /* fpstate defined in <sys/user.h> */
246 struct fpstate
*fpstatep
;
247 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
250 unsigned int rounded_addr
;
251 unsigned int rounded_size
;
252 /*extern int corechan; */
254 extern int inferior_pid
;
256 uaddr
= (char *) &U_FPSTATE (u
) - (char *) &u
;
261 rounded_addr
= uaddr
& -sizeof (int);
262 rounded_size
= (((uaddr
+ sizeof (struct fpstate
)) - uaddr
) +
263 sizeof (int) - 1) / sizeof (int);
264 skip
= uaddr
- rounded_addr
;
267 for (i
= 0; i
< rounded_size
; i
++)
269 *ip
++ = ptrace (PT_READ_U
, inferior_pid
, (caddr_t
) rounded_addr
, 0);
270 rounded_addr
+= sizeof (int);
275 printf ("float info: can't do a core file (yet)\n");
278 if (lseek (corechan
, uaddr
, 0) < 0)
279 perror_with_name ("seek on core file");
280 if (myread (corechan
, buf
, sizeof (struct fpstate
)) < 0)
281 perror_with_name ("read from core file");
286 print_387_status (0, (struct env387
*) buf
);
292 return (sizeof (struct user
));