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