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