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