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