1 /* Machine-dependent code for host Sun 386i's for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
3 Changes for sun386i by Jean Daniel Fekete (jdf@litp.univ-p6-7.fr),
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #if defined (GDB_TARGET_IS_SUN386)
31 #include <sys/param.h>
35 #include <sys/ioctl.h>
38 #include <sys/ptrace.h>
39 #include <machine/reg.h>
47 fetch_inferior_registers (regno
)
50 struct regs inferior_registers
;
51 struct fp_state inferior_fp_registers
;
52 extern char registers
[];
56 ptrace (PTRACE_GETREGS
, inferior_pid
, &inferior_registers
);
57 ptrace (PTRACE_GETFPREGS
, inferior_pid
, &inferior_fp_registers
);
59 bcopy (&inferior_registers
, registers
, sizeof inferior_registers
);
61 bcopy (inferior_fp_registers
.f_st
,®isters
[REGISTER_BYTE (FP0_REGNUM
)],
62 sizeof inferior_fp_registers
.f_st
);
63 bcopy (&inferior_fp_registers
.f_ctrl
,
64 ®isters
[REGISTER_BYTE (FPC_REGNUM
)],
65 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.f_st
);
68 /* Store our register values back into the inferior.
69 If REGNO is -1, do this for all registers.
70 Otherwise, REGNO specifies which register (so we can save time). */
73 store_inferior_registers (regno
)
76 struct regs inferior_registers
;
77 struct fp_state inferior_fp_registers
;
78 extern char registers
[];
80 bcopy (registers
, &inferior_registers
, 20 * 4);
82 bcopy (®isters
[REGISTER_BYTE (FP0_REGNUM
)],inferior_fp_registers
.f_st
,
83 sizeof inferior_fp_registers
.f_st
);
84 bcopy (®isters
[REGISTER_BYTE (FPC_REGNUM
)],
85 &inferior_fp_registers
.f_ctrl
,
86 sizeof inferior_fp_registers
- sizeof inferior_fp_registers
.f_st
);
89 if (regno
== FP_REGNUM
|| regno
== -1)
90 /* Storing the frame pointer requires a gross hack, in which an
91 instruction that moves eax into ebp gets single-stepped. */
93 int stack
= inferior_registers
.r_reg
[SP_REGNUM
];
94 int stuff
= ptrace (PTRACE_PEEKDATA
, inferior_pid
, stack
);
95 int reg
= inferior_registers
.r_reg
[EAX
];
96 inferior_registers
.r_reg
[EAX
] =
97 inferior_registers
.r_reg
[FP_REGNUM
];
98 ptrace (PTRACE_SETREGS
, inferior_pid
, &inferior_registers
);
99 ptrace (PTRACE_POKEDATA
, inferior_pid
, stack
, 0xc589);
100 ptrace (PTRACE_SINGLESTEP
, inferior_pid
, stack
, 0);
102 ptrace (PTRACE_POKEDATA
, inferior_pid
, stack
, stuff
);
103 inferior_registers
.r_reg
[EAX
] = reg
;
106 ptrace (PTRACE_SETREGS
, inferior_pid
, &inferior_registers
);
107 ptrace (PTRACE_SETFPREGS
, inferior_pid
, &inferior_fp_registers
);
110 /* Machine-dependent code which would otherwise be in core.c */
111 /* Work with core files, for GDB. */
115 core_file_command (filename
, from_tty
)
120 extern char registers
[];
122 /* Discard all vestiges of any previous core file
123 and mark data and stack spaces as empty. */
135 stack_start
= STACK_END_ADDR
;
136 stack_end
= STACK_END_ADDR
;
138 /* Now, if a new core file was specified, open it and digest it. */
142 filename
= tilde_expand (filename
);
143 make_cleanup (free
, filename
);
145 if (have_inferior_p ())
146 error ("To look at a core file, you must kill the inferior with \"kill\".");
147 corechan
= open (filename
, O_RDONLY
, 0);
149 perror_with_name (filename
);
154 val
= myread (corechan
, &corestr
, sizeof corestr
);
156 perror_with_name (filename
);
157 if (corestr
.c_magic
!= CORE_MAGIC
)
158 error ("\"%s\" does not appear to be a core dump file (magic 0x%x, expected 0x%x)",
159 filename
, corestr
.c_magic
, (int) CORE_MAGIC
);
160 else if (sizeof (struct core
) != corestr
.c_len
)
161 error ("\"%s\" has an invalid struct core length (%d, expected %d)",
162 filename
, corestr
.c_len
, (int) sizeof (struct core
));
164 data_start
= exec_data_start
;
165 data_end
= data_start
+ corestr
.c_dsize
;
166 stack_start
= stack_end
- corestr
.c_ssize
;
167 data_offset
= sizeof corestr
;
168 stack_offset
= sizeof corestr
+ corestr
.c_dsize
;
170 bcopy (&corestr
.c_regs
, registers
, sizeof corestr
.c_regs
);
172 bcopy (corestr
.c_fpu
.f_fpstatus
.f_st
,
173 ®isters
[REGISTER_BYTE (FP0_REGNUM
)],
174 sizeof corestr
.c_fpu
.f_fpstatus
.f_st
);
175 bcopy (&corestr
.c_fpu
.f_fpstatus
.f_ctrl
,
176 ®isters
[REGISTER_BYTE (FPC_REGNUM
)],
177 sizeof corestr
.c_fpu
.f_fpstatus
-
178 sizeof corestr
.c_fpu
.f_fpstatus
.f_st
);
180 /* the struct aouthdr of sun coff is not the struct exec stored
182 bcopy (&corestr
.c_aouthdr
, &core_aouthdr
, sizeof (struct exec
));
183 #ifndef COFF_ENCAPSULATE
184 core_aouthdr
.magic
= corestr
.c_aouthdr
.a_info
;
185 core_aouthdr
.vstamp
= /*SUNVERSION*/ 31252;
187 printf ("Core file is from \"%s\".\n", corestr
.c_cmdname
);
188 if (corestr
.c_signo
> 0)
189 printf ("Program terminated with signal %d, %s.\n",
191 corestr
.c_signo
< NSIG
192 ? sys_siglist
[corestr
.c_signo
]
195 if (filename
[0] == '/')
196 corefile
= savestring (filename
, strlen (filename
));
199 corefile
= concat (current_directory
, "/", filename
, NULL
);
202 set_current_frame ( create_new_frame (read_register (FP_REGNUM
),
204 select_frame (get_current_frame (), 0);
209 printf ("No core file now.\n");
212 i387_to_double (from
, to
)
217 /* push extended mode on 387 stack, then pop in double mode
219 * first, set exception masks so no error is generated -
220 * number will be rounded to inf or 0, if necessary
222 asm ("pushl %eax"); /* grab a stack slot */
223 asm ("fstcw (%esp)"); /* get 387 control word */
224 asm ("movl (%esp),%eax"); /* save old value */
225 asm ("orl $0x3f,%eax"); /* mask all exceptions */
227 asm ("fldcw (%esp)"); /* load new value into 387 */
229 asm ("movl 8(%ebp),%eax");
230 asm ("fldt (%eax)"); /* push extended number on 387 stack */
232 asm ("movl 12(%ebp),%eax");
233 asm ("fstpl (%eax)"); /* pop double */
236 asm ("popl %eax"); /* flush modified control word */
237 asm ("fnclex"); /* clear exceptions */
238 asm ("fldcw (%esp)"); /* restore original control word */
239 asm ("popl %eax"); /* flush saved copy */
242 double_to_i387 (from
, to
)
246 /* push double mode on 387 stack, then pop in extended mode
247 * no errors are possible because every 64-bit pattern
248 * can be converted to an extended
250 asm ("movl 8(%ebp),%eax");
253 asm ("movl 12(%ebp),%eax");
254 asm ("fstpt (%eax)");
257 #else /* Not sun386 target. */
259 /* These functions shouldn't be called when we're cross-debugging. */
263 fetch_inferior_registers (regno
)
270 store_inferior_registers (regno
)
277 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
279 unsigned core_reg_size
;
281 unsigned int reg_addr
; /* Unused in this version */
285 #endif /* Not sun386 target. */