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, Boston, MA 02111-1307, USA. */
22 #ifdef FETCH_INFERIOR_REGISTERS
23 #include <sys/types.h>
24 #include <sys/ptrace.h>
25 #include <machine/reg.h>
26 #include <machine/frame.h>
30 fetch_inferior_registers(regno)
33 struct reg inferior_registers;
35 ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &inferior_registers, 0);
36 memcpy (®isters[REGISTER_BYTE (0)], &inferior_registers, 4*NUM_REGS);
41 store_inferior_registers(regno)
44 struct reg inferior_registers;
46 memcpy (&inferior_registers, ®isters[REGISTER_BYTE (0)], 4*NUM_REGS);
47 ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &inferior_registers, 0);
56 fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
58 unsigned core_reg_size;
62 struct md_core *core_reg = (struct md_core *)core_reg_sect;
64 /* integer registers */
65 memcpy(®isters[REGISTER_BYTE (0)], &core_reg->intreg,
67 /* floating point registers */
73 #include <machine/reg.h>
75 /* Some systems don't provide all the registers on a trap. Use SS as a
91 /* These tables map between the registers on a trap frame, and the register
92 order used by the rest of GDB. */
93 /* this table must line up with REGISTER_NAMES in tm-i386.h */
94 /* symbols like 'tEAX' come from <machine/reg.h> */
95 static int tregmap[] =
97 tEAX, tECX, tEDX, tEBX,
98 tESP, tEBP, tESI, tEDI,
99 tEIP, tEFLAGS, tCS, tSS,
104 static int sregmap[] =
106 sEAX, sECX, sEDX, sEBX,
107 sESP, sEBP, sESI, sEDI,
108 sEIP, sEFLAGS, sCS, sSS
112 /* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
113 ones aren't around, use the t* ones for sregmap too. */
115 static int sregmap[] =
117 tEAX, tECX, tEDX, tEBX,
118 tESP, tEBP, tESI, tEDI,
119 tEIP, tEFLAGS, tCS, tSS,
124 /* blockend is the value of u.u_ar0, and points to the
125 place where ES is stored. */
128 i386_register_u_addr (blockend, regnum)
132 /* The following condition is a kludge to get at the proper register map
133 depending upon the state of pcb_flag.
134 The proper condition would be
135 if (u.u_pcb.pcb_flag & FM_TRAP)
136 but that would require a ptrace call here and wouldn't work
139 if (blockend < 0x1fcc)
140 return (blockend + 4 * tregmap[regnum]);
142 return (blockend + 4 * sregmap[regnum]);
145 #endif /* !FETCH_INFERIOR_REGISTERS */
148 #include "expression.h"
149 #include "language.h" /* for local_hex_string */
150 #include "floatformat.h"
152 #include <sys/param.h>
154 #include <sys/ioctl.h>
159 #include <sys/time.h>
160 #include <sys/resource.h>
162 #define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
163 #include <sys/user.h>
165 #include <sys/file.h>
166 #include "gdb_stat.h"
167 #include <sys/ptrace.h>
169 extern void print_387_control_word (); /* i387-tdep.h */
170 extern void print_387_status_word ();
172 #define fpstate save87
173 #define U_FPSTATE(u) u.u_pcb.pcb_savefpu
176 i387_to_double (from, to)
181 /* push extended mode on 387 stack, then pop in double mode
183 * first, set exception masks so no error is generated -
184 * number will be rounded to inf or 0, if necessary
186 asm ("pushl %eax"); /* grab a stack slot */
187 asm ("fstcw (%esp)"); /* get 387 control word */
188 asm ("movl (%esp),%eax"); /* save old value */
189 asm ("orl $0x3f,%eax"); /* mask all exceptions */
191 asm ("fldcw (%esp)"); /* load new value into 387 */
193 asm ("movl 8(%ebp),%eax");
194 asm ("fldt (%eax)"); /* push extended number on 387 stack */
196 asm ("movl 12(%ebp),%eax");
197 asm ("fstpl (%eax)"); /* pop double */
200 asm ("popl %eax"); /* flush modified control word */
201 asm ("fnclex"); /* clear exceptions */
202 asm ("fldcw (%esp)"); /* restore original control word */
203 asm ("popl %eax"); /* flush saved copy */
208 unsigned short control;
210 unsigned short status;
215 unsigned short code_seg;
216 unsigned short opcode;
217 unsigned long operand;
218 unsigned short operand_seg;
220 unsigned char regs[8][10];
224 print_387_status (status, ep)
225 unsigned short status;
233 bothstatus = ((status != 0) && (ep->status != 0));
237 printf_unfiltered ("u: ");
238 print_387_status_word ((unsigned int)status);
244 printf_unfiltered ("e: ");
245 print_387_status_word ((unsigned int)ep->status);
248 print_387_control_word ((unsigned int)ep->control);
249 printf_unfiltered ("last instruction: ");
250 printf_unfiltered ("opcode %s; ", local_hex_string(ep->opcode));
251 printf_unfiltered ("pc %s:", local_hex_string(ep->code_seg));
252 printf_unfiltered ("%s; ", local_hex_string(ep->eip));
253 printf_unfiltered ("operand %s", local_hex_string(ep->operand_seg));
254 printf_unfiltered (":%s\n", local_hex_string(ep->operand));
256 top = (ep->status >> 11) & 7;
258 printf_unfiltered (" regno tag msb lsb value\n");
259 for (fpreg = 7; fpreg >= 0; fpreg--)
264 /* The physical regno `fpreg' is only relevant as an index into the
265 * tag word. Logical `%st' numbers are required for indexing ep->regs.
267 st_regno = (fpreg + 8 - top) & 7;
269 printf_unfiltered ("%%st(%d) %s ", st_regno, fpreg == top ? "=>" : " ");
271 switch ((ep->tag >> (fpreg * 2)) & 3)
273 case 0: printf_unfiltered ("valid "); break;
274 case 1: printf_unfiltered ("zero "); break;
275 case 2: printf_unfiltered ("trap "); break;
276 case 3: printf_unfiltered ("empty "); break;
278 for (i = 9; i >= 0; i--)
279 printf_unfiltered ("%02x", ep->regs[st_regno][i]);
281 i387_to_double((char *) ep->regs[st_regno], (char *) &val);
282 printf_unfiltered (" %g\n", val);
289 struct user u; /* just for address computations */
291 /* fpstate defined in <sys/user.h> */
292 struct fpstate *fpstatep;
293 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
296 unsigned int rounded_addr;
297 unsigned int rounded_size;
298 /*extern int corechan;*/
300 extern int inferior_pid;
302 uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
307 rounded_addr = uaddr & -sizeof (int);
308 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
309 sizeof (int) - 1) / sizeof (int);
310 skip = uaddr - rounded_addr;
313 for (i = 0; i < rounded_size; i++)
315 *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0);
316 rounded_addr += sizeof (int);
321 printf("float info: can't do a core file (yet)\n");
324 if (lseek (corechan, uaddr, 0) < 0)
325 perror_with_name ("seek on core file");
326 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
327 perror_with_name ("read from core file");
333 fpstatep = (struct fpstate *)(buf + skip);
334 print_387_status (fpstatep->sv_ex_sw, (struct env387 *)fpstatep);
336 print_387_status (0, (struct env387 *)buf);
339 #endif /* FLOAT_INFO */
344 return (sizeof (struct user));
347 #ifdef SETUP_ARBITRARY_FRAME
350 setup_arbitrary_frame (argc, argv)
355 error ("i386 frame specifications require two arguments: sp and pc");
357 return create_new_frame (argv[0], argv[1]);
359 #endif /* SETUP_ARBITRARY_FRAME */