Commit | Line | Data |
---|---|---|
07d021a6 | 1 | /* Sequent Symmetry host interface, for GDB when running under Unix. |
7919c3ed | 2 | Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc. |
07d021a6 JG |
3 | |
4 | This file is part of GDB. | |
5 | ||
99a7de40 | 6 | This program is free software; you can redistribute it and/or modify |
07d021a6 | 7 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
07d021a6 | 10 | |
99a7de40 | 11 | This program is distributed in the hope that it will be useful, |
07d021a6 JG |
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 | |
99a7de40 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
07d021a6 | 19 | |
5142120e JG |
20 | /* FIXME, some 387-specific items of use taken from i387-tdep.c -- ought to be |
21 | merged back in. */ | |
07d021a6 JG |
22 | |
23 | #include <stdio.h> | |
24 | #include "defs.h" | |
07d021a6 JG |
25 | #include "frame.h" |
26 | #include "inferior.h" | |
27 | #include "symtab.h" | |
28 | ||
29 | #include <signal.h> | |
30 | #include <sys/param.h> | |
31 | #include <sys/user.h> | |
32 | #include <sys/dir.h> | |
33 | #include <sys/ioctl.h> | |
34 | #include <sys/stat.h> | |
35 | #include "gdbcore.h" | |
36 | #include <fcntl.h> | |
07d021a6 JG |
37 | #include <sgtty.h> |
38 | #define TERMINAL struct sgttyb | |
39 | ||
7919c3ed | 40 | #include "gdbcore.h" |
5142120e | 41 | |
7919c3ed | 42 | void |
07d021a6 JG |
43 | store_inferior_registers(regno) |
44 | int regno; | |
45 | { | |
46 | struct pt_regset regs; | |
47 | int reg_tmp, i; | |
48 | extern char registers[]; | |
49 | ||
50 | #if 0 | |
51 | /* PREPARE_TO_STORE deals with this. */ | |
52 | if (-1 == regno) | |
53 | { | |
54 | #endif | |
55 | regs.pr_eax = *(int *)®isters[REGISTER_BYTE(0)]; | |
56 | regs.pr_ebx = *(int *)®isters[REGISTER_BYTE(5)]; | |
57 | regs.pr_ecx = *(int *)®isters[REGISTER_BYTE(2)]; | |
58 | regs.pr_edx = *(int *)®isters[REGISTER_BYTE(1)]; | |
59 | regs.pr_esi = *(int *)®isters[REGISTER_BYTE(6)]; | |
60 | regs.pr_edi = *(int *)®isters[REGISTER_BYTE(7)]; | |
61 | regs.pr_esp = *(int *)®isters[REGISTER_BYTE(14)]; | |
62 | regs.pr_ebp = *(int *)®isters[REGISTER_BYTE(15)]; | |
63 | regs.pr_eip = *(int *)®isters[REGISTER_BYTE(16)]; | |
64 | regs.pr_flags = *(int *)®isters[REGISTER_BYTE(17)]; | |
65 | for (i = 0; i < 31; i++) { | |
66 | regs.pr_fpa.fpa_regs[i] = | |
67 | *(int *)®isters[REGISTER_BYTE(FP1_REGNUM+i)]; | |
68 | } | |
69 | #if 0 | |
70 | } | |
71 | else | |
72 | { | |
73 | reg_tmp = *(int *)®isters[REGISTER_BYTE(regno)]; | |
74 | ptrace(XPT_RREGS, inferior_pid, ®s, 0); | |
75 | switch (regno) | |
76 | { | |
77 | case 0: | |
78 | regs.pr_eax = *(int *)®isters[REGISTER_BYTE(0)]; | |
79 | break; | |
80 | case 5: | |
81 | regs.pr_ebx = *(int *)®isters[REGISTER_BYTE(5)]; | |
82 | break; | |
83 | case 2: | |
84 | regs.pr_ecx = *(int *)®isters[REGISTER_BYTE(2)]; | |
85 | break; | |
86 | case 1: | |
87 | regs.pr_edx = *(int *)®isters[REGISTER_BYTE(1)]; | |
88 | break; | |
89 | case 6: | |
90 | regs.pr_esi = *(int *)®isters[REGISTER_BYTE(6)]; | |
91 | break; | |
92 | case 7: | |
93 | regs.pr_edi = *(int *)®isters[REGISTER_BYTE(7)]; | |
94 | break; | |
95 | case 15: | |
96 | regs.pr_ebp = *(int *)®isters[REGISTER_BYTE(15)]; | |
97 | break; | |
98 | case 14: | |
99 | regs.pr_esp = *(int *)®isters[REGISTER_BYTE(14)]; | |
100 | break; | |
101 | case 16: | |
102 | regs.pr_eip = *(int *)®isters[REGISTER_BYTE(16)]; | |
103 | break; | |
104 | case 17: | |
105 | regs.pr_flags = *(int *)®isters[REGISTER_BYTE(17)]; | |
106 | break; | |
107 | } | |
108 | } | |
109 | #endif /* 0 */ | |
110 | ptrace(XPT_WREGS, inferior_pid, ®s, 0); | |
111 | } | |
112 | ||
113 | void | |
7919c3ed JG |
114 | fetch_inferior_registers (regno) |
115 | int regno; | |
07d021a6 JG |
116 | { |
117 | int i; | |
118 | struct pt_regset regs; | |
119 | extern char registers[]; | |
120 | ||
121 | registers_fetched (); | |
122 | ||
123 | ptrace(XPT_RREGS, inferior_pid, ®s, 0); | |
124 | *(int *)®isters[REGISTER_BYTE(0)] = regs.pr_eax; | |
125 | *(int *)®isters[REGISTER_BYTE(5)] = regs.pr_ebx; | |
126 | *(int *)®isters[REGISTER_BYTE(2)] = regs.pr_ecx; | |
127 | *(int *)®isters[REGISTER_BYTE(1)] = regs.pr_edx; | |
128 | *(int *)®isters[REGISTER_BYTE(6)] = regs.pr_esi; | |
129 | *(int *)®isters[REGISTER_BYTE(7)] = regs.pr_edi; | |
130 | *(int *)®isters[REGISTER_BYTE(15)] = regs.pr_ebp; | |
131 | *(int *)®isters[REGISTER_BYTE(14)] = regs.pr_esp; | |
132 | *(int *)®isters[REGISTER_BYTE(16)] = regs.pr_eip; | |
133 | *(int *)®isters[REGISTER_BYTE(17)] = regs.pr_flags; | |
134 | for (i = 0; i < FPA_NREGS; i++) { | |
135 | *(int *)®isters[REGISTER_BYTE(FP1_REGNUM+i)] = regs.pr_fpa.fpa_regs[i]; | |
136 | } | |
137 | bcopy(regs.pr_fpu.fpu_stack[0], ®isters[REGISTER_BYTE(3)], 10); | |
138 | bcopy(regs.pr_fpu.fpu_stack[1], ®isters[REGISTER_BYTE(4)], 10); | |
139 | bcopy(regs.pr_fpu.fpu_stack[2], ®isters[REGISTER_BYTE(8)], 10); | |
140 | bcopy(regs.pr_fpu.fpu_stack[3], ®isters[REGISTER_BYTE(9)], 10); | |
141 | bcopy(regs.pr_fpu.fpu_stack[4], ®isters[REGISTER_BYTE(10)], 10); | |
142 | bcopy(regs.pr_fpu.fpu_stack[5], ®isters[REGISTER_BYTE(11)], 10); | |
143 | bcopy(regs.pr_fpu.fpu_stack[6], ®isters[REGISTER_BYTE(12)], 10); | |
144 | bcopy(regs.pr_fpu.fpu_stack[7], ®isters[REGISTER_BYTE(13)], 10); | |
145 | } | |
146 | ||
147 | \f | |
148 | /* Work with core dump and executable files, for GDB. | |
149 | This code would be in core.c if it weren't machine-dependent. */ | |
150 | ||
07d021a6 JG |
151 | void |
152 | core_file_command (filename, from_tty) | |
153 | char *filename; | |
154 | int from_tty; | |
155 | { | |
156 | int val; | |
157 | extern char registers[]; | |
158 | ||
159 | /* Discard all vestiges of any previous core file | |
160 | and mark data and stack spaces as empty. */ | |
161 | ||
162 | if (corefile) | |
163 | free (corefile); | |
164 | corefile = 0; | |
165 | ||
166 | if (corechan >= 0) | |
167 | close (corechan); | |
168 | corechan = -1; | |
169 | ||
170 | data_start = 0; | |
171 | data_end = 0; | |
172 | stack_start = STACK_END_ADDR; | |
173 | stack_end = STACK_END_ADDR; | |
174 | ||
175 | /* Now, if a new core file was specified, open it and digest it. */ | |
176 | ||
177 | if (filename) | |
178 | { | |
179 | filename = tilde_expand (filename); | |
180 | make_cleanup (free, filename); | |
181 | ||
182 | if (have_inferior_p ()) | |
183 | error ("To look at a core file, you must kill the inferior with \"kill\"."); | |
184 | corechan = open (filename, O_RDONLY, 0); | |
185 | if (corechan < 0) | |
186 | perror_with_name (filename); | |
187 | /* 4.2-style (and perhaps also sysV-style) core dump file. */ | |
188 | { | |
189 | struct user u; | |
190 | int reg_offset; | |
191 | ||
192 | val = myread (corechan, &u, sizeof u); | |
193 | if (val < 0) | |
194 | perror_with_name (filename); | |
195 | data_start = exec_data_start; | |
196 | ||
197 | data_end = data_start + NBPG * (u.u_dsize - u.u_tsize); | |
198 | stack_start = stack_end - NBPG * u.u_ssize; | |
199 | data_offset = NBPG * UPAGES; | |
200 | stack_offset = ctob(UPAGES + u.u_dsize - u.u_tsize); | |
201 | reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR; | |
202 | printf("u.u_tsize= %#x, u.u_dsize= %#x, u.u_ssize= %#x, stack_off= %#x\n", | |
203 | u.u_tsize, u.u_dsize, u.u_ssize, stack_offset); | |
204 | ||
205 | core_aouthdr.a_magic = 0; | |
206 | ||
207 | /* Read the register values out of the core file and store | |
208 | them where `read_register' will find them. */ | |
209 | ||
210 | { | |
211 | register int regno; | |
212 | ||
213 | for (regno = 0; regno < NUM_REGS; regno++) | |
214 | { | |
215 | char buf[MAX_REGISTER_RAW_SIZE]; | |
216 | ||
217 | val = lseek (corechan, register_addr (regno, reg_offset), 0); | |
218 | if (val < 0) | |
219 | perror_with_name (filename); | |
220 | ||
221 | val = myread (corechan, buf, sizeof buf); | |
222 | if (val < 0) | |
223 | perror_with_name (filename); | |
224 | supply_register (regno, buf); | |
225 | } | |
226 | } | |
227 | } | |
228 | if (filename[0] == '/') | |
229 | corefile = savestring (filename, strlen (filename)); | |
230 | else | |
231 | { | |
58ae87f6 | 232 | corefile = concat (current_directory, "/", filename, NULL); |
07d021a6 JG |
233 | } |
234 | ||
235 | set_current_frame(create_new_frame(read_register(FP_REGNUM), | |
236 | read_pc())); | |
237 | /* set_current_frame (read_register (FP_REGNUM));*/ | |
238 | select_frame (get_current_frame (), 0); | |
239 | validate_files (); | |
240 | } | |
241 | else if (from_tty) | |
242 | printf ("No core file now.\n"); | |
243 | } | |
244 | ||
5142120e | 245 | /* FIXME: This should be merged with i387-tdep.c as well. */ |
07d021a6 JG |
246 | static |
247 | print_fpu_status(ep) | |
248 | struct pt_regset ep; | |
07d021a6 JG |
249 | { |
250 | int i; | |
251 | int bothstatus; | |
252 | int top; | |
253 | int fpreg; | |
254 | unsigned char *p; | |
255 | ||
256 | printf("80387:"); | |
257 | if (ep.pr_fpu.fpu_ip == 0) { | |
258 | printf(" not in use.\n"); | |
259 | return; | |
260 | } else { | |
261 | printf("\n"); | |
262 | } | |
263 | if (ep.pr_fpu.fpu_status != 0) { | |
264 | print_387_status_word (ep.pr_fpu.fpu_status); | |
265 | } | |
266 | print_387_control_word (ep.pr_fpu.fpu_control); | |
267 | printf ("last exception: "); | |
268 | printf ("opcode 0x%x; ", ep.pr_fpu.fpu_rsvd4); | |
269 | printf ("pc 0x%x:0x%x; ", ep.pr_fpu.fpu_cs, ep.pr_fpu.fpu_ip); | |
270 | printf ("operand 0x%x:0x%x\n", ep.pr_fpu.fpu_data_offset, ep.pr_fpu.fpu_op_sel); | |
271 | ||
272 | top = (ep.pr_fpu.fpu_status >> 11) & 7; | |
273 | ||
274 | printf ("regno tag msb lsb value\n"); | |
275 | for (fpreg = 7; fpreg >= 0; fpreg--) | |
276 | { | |
277 | double val; | |
278 | ||
279 | printf ("%s %d: ", fpreg == top ? "=>" : " ", fpreg); | |
280 | ||
281 | switch ((ep.pr_fpu.fpu_tag >> (fpreg * 2)) & 3) | |
282 | { | |
283 | case 0: printf ("valid "); break; | |
284 | case 1: printf ("zero "); break; | |
285 | case 2: printf ("trap "); break; | |
286 | case 3: printf ("empty "); break; | |
287 | } | |
288 | for (i = 9; i >= 0; i--) | |
289 | printf ("%02x", ep.pr_fpu.fpu_stack[fpreg][i]); | |
290 | ||
291 | i387_to_double (ep.pr_fpu.fpu_stack[fpreg], (char *)&val); | |
292 | printf (" %g\n", val); | |
293 | } | |
294 | if (ep.pr_fpu.fpu_rsvd1) | |
295 | printf ("warning: rsvd1 is 0x%x\n", ep.pr_fpu.fpu_rsvd1); | |
296 | if (ep.pr_fpu.fpu_rsvd2) | |
297 | printf ("warning: rsvd2 is 0x%x\n", ep.pr_fpu.fpu_rsvd2); | |
298 | if (ep.pr_fpu.fpu_rsvd3) | |
299 | printf ("warning: rsvd3 is 0x%x\n", ep.pr_fpu.fpu_rsvd3); | |
300 | if (ep.pr_fpu.fpu_rsvd5) | |
301 | printf ("warning: rsvd5 is 0x%x\n", ep.pr_fpu.fpu_rsvd5); | |
302 | } | |
303 | ||
304 | ||
305 | print_1167_control_word(pcr) | |
306 | unsigned int pcr; | |
307 | ||
308 | { | |
309 | int pcr_tmp; | |
310 | ||
311 | pcr_tmp = pcr & FPA_PCR_MODE; | |
312 | printf("\tMODE= %#x; RND= %#x ", pcr_tmp, pcr_tmp & 12); | |
313 | switch (pcr_tmp & 12) { | |
314 | case 0: | |
315 | printf("RN (Nearest Value)"); | |
316 | break; | |
317 | case 1: | |
318 | printf("RZ (Zero)"); | |
319 | break; | |
320 | case 2: | |
321 | printf("RP (Positive Infinity)"); | |
322 | break; | |
323 | case 3: | |
324 | printf("RM (Negative Infinity)"); | |
325 | break; | |
326 | } | |
327 | printf("; IRND= %d ", pcr_tmp & 2); | |
328 | if (0 == pcr_tmp & 2) { | |
329 | printf("(same as RND)\n"); | |
330 | } else { | |
331 | printf("(toward zero)\n"); | |
332 | } | |
333 | pcr_tmp = pcr & FPA_PCR_EM; | |
334 | printf("\tEM= %#x", pcr_tmp); | |
335 | if (pcr_tmp & FPA_PCR_EM_DM) printf(" DM"); | |
336 | if (pcr_tmp & FPA_PCR_EM_UOM) printf(" UOM"); | |
337 | if (pcr_tmp & FPA_PCR_EM_PM) printf(" PM"); | |
338 | if (pcr_tmp & FPA_PCR_EM_UM) printf(" UM"); | |
339 | if (pcr_tmp & FPA_PCR_EM_OM) printf(" OM"); | |
340 | if (pcr_tmp & FPA_PCR_EM_ZM) printf(" ZM"); | |
341 | if (pcr_tmp & FPA_PCR_EM_IM) printf(" IM"); | |
342 | printf("\n"); | |
343 | pcr_tmp = FPA_PCR_CC; | |
344 | printf("\tCC= %#x", pcr_tmp); | |
345 | if (pcr_tmp & FPA_PCR_20MHZ) printf(" 20MHZ"); | |
346 | if (pcr_tmp & FPA_PCR_CC_Z) printf(" Z"); | |
347 | if (pcr_tmp & FPA_PCR_CC_C2) printf(" C2"); | |
348 | if (pcr_tmp & FPA_PCR_CC_C1) printf(" C1"); | |
349 | switch (pcr_tmp) { | |
350 | case FPA_PCR_CC_Z: | |
351 | printf(" (Equal)"); | |
352 | break; | |
353 | case FPA_PCR_CC_C1: | |
354 | printf(" (Less than)"); | |
355 | break; | |
356 | case 0: | |
357 | printf(" (Greater than)"); | |
358 | break; | |
359 | case FPA_PCR_CC_Z | FPA_PCR_CC_C1 | FPA_PCR_CC_C2: | |
360 | printf(" (Unordered)"); | |
361 | break; | |
362 | default: | |
363 | printf(" (Undefined)"); | |
364 | break; | |
365 | } | |
366 | printf("\n"); | |
367 | pcr_tmp = pcr & FPA_PCR_AE; | |
368 | printf("\tAE= %#x", pcr_tmp); | |
369 | if (pcr_tmp & FPA_PCR_AE_DE) printf(" DE"); | |
370 | if (pcr_tmp & FPA_PCR_AE_UOE) printf(" UOE"); | |
371 | if (pcr_tmp & FPA_PCR_AE_PE) printf(" PE"); | |
372 | if (pcr_tmp & FPA_PCR_AE_UE) printf(" UE"); | |
373 | if (pcr_tmp & FPA_PCR_AE_OE) printf(" OE"); | |
374 | if (pcr_tmp & FPA_PCR_AE_ZE) printf(" ZE"); | |
375 | if (pcr_tmp & FPA_PCR_AE_EE) printf(" EE"); | |
376 | if (pcr_tmp & FPA_PCR_AE_IE) printf(" IE"); | |
377 | printf("\n"); | |
378 | } | |
379 | ||
380 | print_1167_regs(regs) | |
381 | long regs[FPA_NREGS]; | |
382 | ||
383 | { | |
384 | int i; | |
385 | ||
386 | union { | |
387 | double d; | |
388 | long l[2]; | |
389 | } xd; | |
390 | union { | |
391 | float f; | |
392 | long l; | |
393 | } xf; | |
394 | ||
395 | ||
396 | for (i = 0; i < FPA_NREGS; i++) { | |
397 | xf.l = regs[i]; | |
398 | printf("%%fp%d: raw= %#x, single= %f", i+1, regs[i], xf.f); | |
399 | if (!(i & 1)) { | |
400 | printf("\n"); | |
401 | } else { | |
402 | xd.l[1] = regs[i]; | |
403 | xd.l[0] = regs[i+1]; | |
404 | printf(", double= %f\n", xd.d); | |
405 | } | |
406 | } | |
407 | } | |
408 | ||
409 | print_fpa_status(ep) | |
410 | struct pt_regset ep; | |
411 | ||
412 | { | |
413 | ||
414 | printf("WTL 1167:"); | |
415 | if (ep.pr_fpa.fpa_pcr !=0) { | |
416 | printf("\n"); | |
417 | print_1167_control_word(ep.pr_fpa.fpa_pcr); | |
418 | print_1167_regs(ep.pr_fpa.fpa_regs); | |
419 | } else { | |
420 | printf(" not in use.\n"); | |
421 | } | |
422 | } | |
423 | ||
424 | i386_float_info () | |
07d021a6 JG |
425 | { |
426 | char ubuf[UPAGES*NBPG]; | |
427 | struct pt_regset regset; | |
428 | extern int corechan; | |
429 | ||
430 | if (have_inferior_p()) { | |
431 | call_ptrace(XPT_RREGS, inferior_pid, ®set, 0); | |
432 | } else { | |
433 | if (lseek (corechan, 0, 0) < 0) { | |
434 | perror ("seek on core file"); | |
435 | } | |
436 | if (myread (corechan, ubuf, UPAGES*NBPG) < 0) { | |
437 | perror ("read on core file"); | |
438 | } | |
439 | /* only interested in the floating point registers */ | |
440 | regset.pr_fpu = ((struct user *) ubuf)->u_fpusave; | |
441 | regset.pr_fpa = ((struct user *) ubuf)->u_fpasave; | |
442 | } | |
443 | print_fpu_status(regset); | |
444 | print_fpa_status(regset); | |
445 | } |