]> Git Repo - binutils.git/blob - gdb/i386b-nat.c
2000-02-15 Jason Molenda ([email protected])
[binutils.git] / gdb / i386b-nat.c
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.
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., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22
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>
28 #include "inferior.h"
29 #include "gdbcore.h" /* for registers_fetched() */
30
31 void
32 fetch_inferior_registers (regno)
33      int regno;
34 {
35   struct reg inferior_registers;
36
37   ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) & inferior_registers, 0);
38   memcpy (&registers[REGISTER_BYTE (0)], &inferior_registers, 4 * NUM_REGS);
39   registers_fetched ();
40 }
41
42 void
43 store_inferior_registers (regno)
44      int regno;
45 {
46   struct reg inferior_registers;
47
48   memcpy (&inferior_registers, &registers[REGISTER_BYTE (0)], 4 * NUM_REGS);
49   ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) & inferior_registers, 0);
50 }
51
52 struct md_core
53 {
54   struct reg intreg;
55   struct fpreg freg;
56 };
57
58 void
59 fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
60      char *core_reg_sect;
61      unsigned core_reg_size;
62      int which;
63      CORE_ADDR ignore;
64 {
65   struct md_core *core_reg = (struct md_core *) core_reg_sect;
66
67   /* integer registers */
68   memcpy (&registers[REGISTER_BYTE (0)], &core_reg->intreg,
69           sizeof (struct reg));
70   /* floating point registers */
71   /* XXX */
72 }
73
74 #else
75
76 #include <machine/reg.h>
77
78 /* this table must line up with REGISTER_NAMES in tm-i386.h */
79 /* symbols like 'tEAX' come from <machine/reg.h> */
80 static int tregmap[] =
81 {
82   tEAX, tECX, tEDX, tEBX,
83   tESP, tEBP, tESI, tEDI,
84   tEIP, tEFLAGS, tCS, tSS
85 };
86
87 #ifdef sEAX
88 static int sregmap[] =
89 {
90   sEAX, sECX, sEDX, sEBX,
91   sESP, sEBP, sESI, sEDI,
92   sEIP, sEFLAGS, sCS, sSS
93 };
94 #else /* No sEAX */
95
96 /* FreeBSD has decided to collapse the s* and t* symbols.  So if the s*
97    ones aren't around, use the t* ones for sregmap too.  */
98
99 static int sregmap[] =
100 {
101   tEAX, tECX, tEDX, tEBX,
102   tESP, tEBP, tESI, tEDI,
103   tEIP, tEFLAGS, tCS, tSS
104 };
105 #endif /* No sEAX */
106
107 /* blockend is the value of u.u_ar0, and points to the
108    place where ES is stored.  */
109
110 int
111 i386_register_u_addr (blockend, regnum)
112      int blockend;
113      int regnum;
114 {
115   /* The following condition is a kludge to get at the proper register map
116      depending upon the state of pcb_flag.
117      The proper condition would be
118      if (u.u_pcb.pcb_flag & FM_TRAP)
119      but that would require a ptrace call here and wouldn't work
120      for corefiles.  */
121
122   if (blockend < 0x1fcc)
123     return (blockend + 4 * tregmap[regnum]);
124   else
125     return (blockend + 4 * sregmap[regnum]);
126 }
127
128 #endif /* !FETCH_INFERIOR_REGISTERS */
129
130 #ifdef FLOAT_INFO
131 #include "expression.h"
132 #include "language.h"           /* for local_hex_string */
133 #include "floatformat.h"
134
135 #include <sys/param.h>
136 #include <sys/dir.h>
137 #include <signal.h>
138 #include <sys/ioctl.h>
139 #include <fcntl.h>
140
141 #include <a.out.h>
142
143 #include <sys/time.h>
144 #include <sys/resource.h>
145 #include <sys/uio.h>
146 #define curpcb Xcurpcb          /* XXX avoid leaking declaration from pcb.h */
147 #include <sys/user.h>
148 #undef curpcb
149 #include <sys/file.h>
150 #include "gdb_stat.h"
151 #include <sys/ptrace.h>
152
153 extern void print_387_control_word ();  /* i387-tdep.h */
154 extern void print_387_status_word ();
155
156 #define fpstate         save87
157 #define U_FPSTATE(u)    u.u_pcb.pcb_savefpu
158
159 struct env387
160   {
161     unsigned short control;
162     unsigned short r0;
163     unsigned short status;
164     unsigned short r1;
165     unsigned short tag;
166     unsigned short r2;
167     unsigned long eip;
168     unsigned short code_seg;
169     unsigned short opcode;
170     unsigned long operand;
171     unsigned short operand_seg;
172     unsigned short r3;
173     unsigned char regs[8][10];
174   };
175
176 static void
177 print_387_status (status, ep)
178      unsigned short status;
179      struct env387 *ep;
180 {
181   int i;
182   int bothstatus;
183   int top;
184   int fpreg;
185
186   bothstatus = ((status != 0) && (ep->status != 0));
187   if (status != 0)
188     {
189       if (bothstatus)
190         printf_unfiltered ("u: ");
191       print_387_status_word ((unsigned int) status);
192     }
193
194   if (ep->status != 0)
195     {
196       if (bothstatus)
197         printf_unfiltered ("e: ");
198       print_387_status_word ((unsigned int) ep->status);
199     }
200
201   print_387_control_word ((unsigned int) ep->control);
202   printf_unfiltered ("last exception: ");
203   printf_unfiltered ("opcode %s; ", local_hex_string (ep->opcode));
204   printf_unfiltered ("pc %s:", local_hex_string (ep->code_seg));
205   printf_unfiltered ("%s; ", local_hex_string (ep->eip));
206   printf_unfiltered ("operand %s", local_hex_string (ep->operand_seg));
207   printf_unfiltered (":%s\n", local_hex_string (ep->operand));
208
209   top = (ep->status >> 11) & 7;
210
211   printf_unfiltered ("regno     tag  msb              lsb  value\n");
212   for (fpreg = 7; fpreg >= 0; fpreg--)
213     {
214       double val;
215
216       printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : "  ", fpreg);
217
218       switch ((ep->tag >> (fpreg * 2)) & 3)
219         {
220         case 0:
221           printf_unfiltered ("valid ");
222           break;
223         case 1:
224           printf_unfiltered ("zero  ");
225           break;
226         case 2:
227           printf_unfiltered ("trap  ");
228           break;
229         case 3:
230           printf_unfiltered ("empty ");
231           break;
232         }
233       for (i = 9; i >= 0; i--)
234         printf_unfiltered ("%02x", ep->regs[fpreg][i]);
235
236       floatformat_to_double (&floatformat_i387_ext, (char *) ep->regs[fpreg],
237                              &val);
238       printf_unfiltered ("  %g\n", val);
239     }
240 }
241
242 i386_float_info ()
243 {
244   struct user u;                /* just for address computations */
245   int i;
246   /* fpstate defined in <sys/user.h> */
247   struct fpstate *fpstatep;
248   char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
249   unsigned int uaddr;
250   char fpvalid;
251   unsigned int rounded_addr;
252   unsigned int rounded_size;
253   /*extern int corechan; */
254   int skip;
255   extern int inferior_pid;
256
257   uaddr = (char *) &U_FPSTATE (u) - (char *) &u;
258   if (inferior_pid)
259     {
260       int *ip;
261
262       rounded_addr = uaddr & -sizeof (int);
263       rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
264                       sizeof (int) - 1) / sizeof (int);
265       skip = uaddr - rounded_addr;
266
267       ip = (int *) buf;
268       for (i = 0; i < rounded_size; i++)
269         {
270           *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t) rounded_addr, 0);
271           rounded_addr += sizeof (int);
272         }
273     }
274   else
275     {
276       printf ("float info: can't do a core file (yet)\n");
277       return;
278 #if 0
279       if (lseek (corechan, uaddr, 0) < 0)
280         perror_with_name ("seek on core file");
281       if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
282           perror_with_name ("read from core file");
283       skip = 0;
284 #endif
285     }
286
287   print_387_status (0, (struct env387 *) buf);
288 }
289
290 int
291 kernel_u_size ()
292 {
293   return (sizeof (struct user));
294 }
295
296 #endif
This page took 0.04176 seconds and 4 git commands to generate.