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