1 /* Sequent Symmetry host interface, for GDB when running under Unix.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
20 /* many 387-specific items of use taken from i386-dep.c */
30 #include <sys/param.h>
33 #include <sys/ioctl.h>
38 static long i386_get_frame_setup ();
39 static i386_follow_jump ();
42 #define TERMINAL struct sgttyb
44 store_inferior_registers(regno
)
47 struct pt_regset regs
;
49 extern char registers
[];
52 /* PREPARE_TO_STORE deals with this. */
56 regs
.pr_eax
= *(int *)®isters
[REGISTER_BYTE(0)];
57 regs
.pr_ebx
= *(int *)®isters
[REGISTER_BYTE(5)];
58 regs
.pr_ecx
= *(int *)®isters
[REGISTER_BYTE(2)];
59 regs
.pr_edx
= *(int *)®isters
[REGISTER_BYTE(1)];
60 regs
.pr_esi
= *(int *)®isters
[REGISTER_BYTE(6)];
61 regs
.pr_edi
= *(int *)®isters
[REGISTER_BYTE(7)];
62 regs
.pr_esp
= *(int *)®isters
[REGISTER_BYTE(14)];
63 regs
.pr_ebp
= *(int *)®isters
[REGISTER_BYTE(15)];
64 regs
.pr_eip
= *(int *)®isters
[REGISTER_BYTE(16)];
65 regs
.pr_flags
= *(int *)®isters
[REGISTER_BYTE(17)];
66 for (i
= 0; i
< 31; i
++) {
67 regs
.pr_fpa
.fpa_regs
[i
] =
68 *(int *)®isters
[REGISTER_BYTE(FP1_REGNUM
+i
)];
74 reg_tmp
= *(int *)®isters
[REGISTER_BYTE(regno
)];
75 ptrace(XPT_RREGS
, inferior_pid
, ®s
, 0);
79 regs
.pr_eax
= *(int *)®isters
[REGISTER_BYTE(0)];
82 regs
.pr_ebx
= *(int *)®isters
[REGISTER_BYTE(5)];
85 regs
.pr_ecx
= *(int *)®isters
[REGISTER_BYTE(2)];
88 regs
.pr_edx
= *(int *)®isters
[REGISTER_BYTE(1)];
91 regs
.pr_esi
= *(int *)®isters
[REGISTER_BYTE(6)];
94 regs
.pr_edi
= *(int *)®isters
[REGISTER_BYTE(7)];
97 regs
.pr_ebp
= *(int *)®isters
[REGISTER_BYTE(15)];
100 regs
.pr_esp
= *(int *)®isters
[REGISTER_BYTE(14)];
103 regs
.pr_eip
= *(int *)®isters
[REGISTER_BYTE(16)];
106 regs
.pr_flags
= *(int *)®isters
[REGISTER_BYTE(17)];
111 ptrace(XPT_WREGS
, inferior_pid
, ®s
, 0);
115 fetch_inferior_registers()
118 struct pt_regset regs
;
119 extern char registers
[];
121 registers_fetched ();
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
];
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);
148 /* Work with core dump and executable files, for GDB.
149 This code would be in core.c if it weren't machine-dependent. */
154 core_file_command (filename
, from_tty
)
159 extern char registers
[];
161 /* Discard all vestiges of any previous core file
162 and mark data and stack spaces as empty. */
174 stack_start
= STACK_END_ADDR
;
175 stack_end
= STACK_END_ADDR
;
177 /* Now, if a new core file was specified, open it and digest it. */
181 filename
= tilde_expand (filename
);
182 make_cleanup (free
, filename
);
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);
188 perror_with_name (filename
);
189 /* 4.2-style (and perhaps also sysV-style) core dump file. */
194 val
= myread (corechan
, &u
, sizeof u
);
196 perror_with_name (filename
);
197 data_start
= exec_data_start
;
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
);
207 core_aouthdr
.a_magic
= 0;
209 /* Read the register values out of the core file and store
210 them where `read_register' will find them. */
215 for (regno
= 0; regno
< NUM_REGS
; regno
++)
217 char buf
[MAX_REGISTER_RAW_SIZE
];
219 val
= lseek (corechan
, register_addr (regno
, reg_offset
), 0);
221 perror_with_name (filename
);
223 val
= myread (corechan
, buf
, sizeof buf
);
225 perror_with_name (filename
);
226 supply_register (regno
, buf
);
230 if (filename
[0] == '/')
231 corefile
= savestring (filename
, strlen (filename
));
234 corefile
= concat (current_directory
, "/", filename
);
237 set_current_frame(create_new_frame(read_register(FP_REGNUM
),
239 /* set_current_frame (read_register (FP_REGNUM));*/
240 select_frame (get_current_frame (), 0);
244 printf ("No core file now.\n");
247 /* from i386-dep.c */
249 print_387_control_word (control
)
250 unsigned short control
;
252 printf ("control 0x%04x: ", control
);
253 printf ("compute to ");
254 switch ((control
>> 8) & 3)
256 case 0: printf ("24 bits; "); break;
257 case 1: printf ("(bad); "); break;
258 case 2: printf ("53 bits; "); break;
259 case 3: printf ("64 bits; "); break;
262 switch ((control
>> 10) & 3)
264 case 0: printf ("NEAREST; "); break;
265 case 1: printf ("DOWN; "); break;
266 case 2: printf ("UP; "); break;
267 case 3: printf ("CHOP; "); break;
272 if (control
& 0x0001) printf (" INVALID");
273 if (control
& 0x0002) printf (" DENORM");
274 if (control
& 0x0004) printf (" DIVZ");
275 if (control
& 0x0008) printf (" OVERF");
276 if (control
& 0x0010) printf (" UNDERF");
277 if (control
& 0x0020) printf (" LOS");
281 if (control
& 0xe080) printf ("warning: reserved bits on 0x%x\n",
286 print_387_status_word (status
)
287 unsigned short status
;
289 printf ("status %#04x: ", status
);
291 printf ("exceptions:"); /* exception names match <machine/fpu.h> */
292 if (status
& 0x0001) printf (" FLTINV");
293 if (status
& 0x0002) printf (" FLTDEN");
294 if (status
& 0x0004) printf (" FLTDIV");
295 if (status
& 0x0008) printf (" FLTOVF");
296 if (status
& 0x0010) printf (" FLTUND");
297 if (status
& 0x0020) printf (" FLTPRE");
298 if (status
& 0x0040) printf (" FLTSTK");
301 printf ("flags: %d%d%d%d; ",
302 (status
& 0x4000) != 0,
303 (status
& 0x0400) != 0,
304 (status
& 0x0200) != 0,
305 (status
& 0x0100) != 0);
307 printf ("top %d\n", (status
>> 11) & 7);
322 if (ep
.pr_fpu
.fpu_ip
== 0) {
323 printf(" not in use.\n");
328 if (ep
.pr_fpu
.fpu_status
!= 0) {
329 print_387_status_word (ep
.pr_fpu
.fpu_status
);
331 print_387_control_word (ep
.pr_fpu
.fpu_control
);
332 printf ("last exception: ");
333 printf ("opcode 0x%x; ", ep
.pr_fpu
.fpu_rsvd4
);
334 printf ("pc 0x%x:0x%x; ", ep
.pr_fpu
.fpu_cs
, ep
.pr_fpu
.fpu_ip
);
335 printf ("operand 0x%x:0x%x\n", ep
.pr_fpu
.fpu_data_offset
, ep
.pr_fpu
.fpu_op_sel
);
337 top
= (ep
.pr_fpu
.fpu_status
>> 11) & 7;
339 printf ("regno tag msb lsb value\n");
340 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
344 printf ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
346 switch ((ep
.pr_fpu
.fpu_tag
>> (fpreg
* 2)) & 3)
348 case 0: printf ("valid "); break;
349 case 1: printf ("zero "); break;
350 case 2: printf ("trap "); break;
351 case 3: printf ("empty "); break;
353 for (i
= 9; i
>= 0; i
--)
354 printf ("%02x", ep
.pr_fpu
.fpu_stack
[fpreg
][i
]);
356 i387_to_double (ep
.pr_fpu
.fpu_stack
[fpreg
], (char *)&val
);
357 printf (" %g\n", val
);
359 if (ep
.pr_fpu
.fpu_rsvd1
)
360 printf ("warning: rsvd1 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd1
);
361 if (ep
.pr_fpu
.fpu_rsvd2
)
362 printf ("warning: rsvd2 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd2
);
363 if (ep
.pr_fpu
.fpu_rsvd3
)
364 printf ("warning: rsvd3 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd3
);
365 if (ep
.pr_fpu
.fpu_rsvd5
)
366 printf ("warning: rsvd5 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd5
);
370 print_1167_control_word(pcr
)
376 pcr_tmp
= pcr
& FPA_PCR_MODE
;
377 printf("\tMODE= %#x; RND= %#x ", pcr_tmp
, pcr_tmp
& 12);
378 switch (pcr_tmp
& 12) {
380 printf("RN (Nearest Value)");
386 printf("RP (Positive Infinity)");
389 printf("RM (Negative Infinity)");
392 printf("; IRND= %d ", pcr_tmp
& 2);
393 if (0 == pcr_tmp
& 2) {
394 printf("(same as RND)\n");
396 printf("(toward zero)\n");
398 pcr_tmp
= pcr
& FPA_PCR_EM
;
399 printf("\tEM= %#x", pcr_tmp
);
400 if (pcr_tmp
& FPA_PCR_EM_DM
) printf(" DM");
401 if (pcr_tmp
& FPA_PCR_EM_UOM
) printf(" UOM");
402 if (pcr_tmp
& FPA_PCR_EM_PM
) printf(" PM");
403 if (pcr_tmp
& FPA_PCR_EM_UM
) printf(" UM");
404 if (pcr_tmp
& FPA_PCR_EM_OM
) printf(" OM");
405 if (pcr_tmp
& FPA_PCR_EM_ZM
) printf(" ZM");
406 if (pcr_tmp
& FPA_PCR_EM_IM
) printf(" IM");
408 pcr_tmp
= FPA_PCR_CC
;
409 printf("\tCC= %#x", pcr_tmp
);
410 if (pcr_tmp
& FPA_PCR_20MHZ
) printf(" 20MHZ");
411 if (pcr_tmp
& FPA_PCR_CC_Z
) printf(" Z");
412 if (pcr_tmp
& FPA_PCR_CC_C2
) printf(" C2");
413 if (pcr_tmp
& FPA_PCR_CC_C1
) printf(" C1");
419 printf(" (Less than)");
422 printf(" (Greater than)");
424 case FPA_PCR_CC_Z
| FPA_PCR_CC_C1
| FPA_PCR_CC_C2
:
425 printf(" (Unordered)");
428 printf(" (Undefined)");
432 pcr_tmp
= pcr
& FPA_PCR_AE
;
433 printf("\tAE= %#x", pcr_tmp
);
434 if (pcr_tmp
& FPA_PCR_AE_DE
) printf(" DE");
435 if (pcr_tmp
& FPA_PCR_AE_UOE
) printf(" UOE");
436 if (pcr_tmp
& FPA_PCR_AE_PE
) printf(" PE");
437 if (pcr_tmp
& FPA_PCR_AE_UE
) printf(" UE");
438 if (pcr_tmp
& FPA_PCR_AE_OE
) printf(" OE");
439 if (pcr_tmp
& FPA_PCR_AE_ZE
) printf(" ZE");
440 if (pcr_tmp
& FPA_PCR_AE_EE
) printf(" EE");
441 if (pcr_tmp
& FPA_PCR_AE_IE
) printf(" IE");
445 print_1167_regs(regs
)
446 long regs
[FPA_NREGS
];
461 for (i
= 0; i
< FPA_NREGS
; i
++) {
463 printf("%%fp%d: raw= %#x, single= %f", i
+1, regs
[i
], xf
.f
);
469 printf(", double= %f\n", xd
.d
);
480 if (ep
.pr_fpa
.fpa_pcr
!=0) {
482 print_1167_control_word(ep
.pr_fpa
.fpa_pcr
);
483 print_1167_regs(ep
.pr_fpa
.fpa_regs
);
485 printf(" not in use.\n");
492 char ubuf
[UPAGES
*NBPG
];
493 struct pt_regset regset
;
496 if (have_inferior_p()) {
497 call_ptrace(XPT_RREGS
, inferior_pid
, ®set
, 0);
499 if (lseek (corechan
, 0, 0) < 0) {
500 perror ("seek on core file");
502 if (myread (corechan
, ubuf
, UPAGES
*NBPG
) < 0) {
503 perror ("read on core file");
505 /* only interested in the floating point registers */
506 regset
.pr_fpu
= ((struct user
*) ubuf
)->u_fpusave
;
507 regset
.pr_fpa
= ((struct user
*) ubuf
)->u_fpasave
;
509 print_fpu_status(regset
);
510 print_fpa_status(regset
);
513 i387_to_double (from
, to
)
518 /* push extended mode on 387 stack, then pop in double mode
520 * first, set exception masks so no error is generated -
521 * number will be rounded to inf or 0, if necessary
523 asm ("pushl %eax"); /* grab a stack slot */
524 asm ("fstcw (%esp)"); /* get 387 control word */
525 asm ("movl (%esp),%eax"); /* save old value */
526 asm ("orl $0x3f,%eax"); /* mask all exceptions */
528 asm ("fldcw (%esp)"); /* load new value into 387 */
530 asm ("movl 8(%ebp),%eax");
531 asm ("fldt (%eax)"); /* push extended number on 387 stack */
533 asm ("movl 12(%ebp),%eax");
534 asm ("fstpl (%eax)"); /* pop double */
537 asm ("popl %eax"); /* flush modified control word */
538 asm ("fnclex"); /* clear exceptions */
539 asm ("fldcw (%esp)"); /* restore original control word */
540 asm ("popl %eax"); /* flush saved copy */
543 double_to_i387 (from
, to
)
547 /* push double mode on 387 stack, then pop in extended mode
548 * no errors are possible because every 64-bit pattern
549 * can be converted to an extended
551 asm ("movl 8(%ebp),%eax");
554 asm ("movl 12(%ebp),%eax");
555 asm ("fstpt (%eax)");
This page took 0.047679 seconds and 4 git commands to generate.