Moved the position of the #### lines so that the makefile fragments
[deliverable/binutils-gdb.git] / gdb / sun386-xdep.c
CommitLineData
dd3b648e
RP
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),
4 C2V Paris, April 89.
5
6This file is part of GDB.
7
99a7de40 8This program is free software; you can redistribute it and/or modify
dd3b648e 9it under the terms of the GNU General Public License as published by
99a7de40
JG
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
dd3b648e 12
99a7de40 13This program is distributed in the hope that it will be useful,
dd3b648e
RP
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
99a7de40
JG
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
dd3b648e 21
f0ca24b9
JK
22#if defined (GDB_TARGET_IS_SUN386)
23
dd3b648e
RP
24#include <stdio.h>
25#include "defs.h"
dd3b648e
RP
26#include "frame.h"
27#include "inferior.h"
28#include "signame.h"
29#include "gdbcore.h"
30
31#include <sys/param.h>
32#include <sys/dir.h>
33#include <sys/user.h>
34#include <signal.h>
35#include <sys/ioctl.h>
36#include <fcntl.h>
37
38#include <sys/ptrace.h>
39#include <machine/reg.h>
40
41#include <sys/file.h>
42#include <sys/stat.h>
43#include <sys/core.h>
44\f
45void
46fetch_inferior_registers ()
47{
48 struct regs inferior_registers;
49 struct fp_state inferior_fp_registers;
50 extern char registers[];
51
52 registers_fetched ();
53
54 ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers);
55 ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers);
56
57 bcopy (&inferior_registers, registers, sizeof inferior_registers);
58
59 bcopy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
60 sizeof inferior_fp_registers.f_st);
61 bcopy (&inferior_fp_registers.f_ctrl,
62 &registers[REGISTER_BYTE (FPC_REGNUM)],
63 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
64}
65
66/* Store our register values back into the inferior.
67 If REGNO is -1, do this for all registers.
68 Otherwise, REGNO specifies which register (so we can save time). */
69
70store_inferior_registers (regno)
71 int regno;
72{
73 struct regs inferior_registers;
74 struct fp_state inferior_fp_registers;
75 extern char registers[];
76
77 bcopy (registers, &inferior_registers, 20 * 4);
78
79 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
80 sizeof inferior_fp_registers.f_st);
81 bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
82 &inferior_fp_registers.f_ctrl,
83 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
84
85#ifdef PTRACE_FP_BUG
86 if (regno == FP_REGNUM || regno == -1)
87 /* Storing the frame pointer requires a gross hack, in which an
88 instruction that moves eax into ebp gets single-stepped. */
89 {
90 int stack = inferior_registers.r_reg[SP_REGNUM];
91 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid, stack);
92 int reg = inferior_registers.r_reg[EAX];
93 inferior_registers.r_reg[EAX] =
94 inferior_registers.r_reg[FP_REGNUM];
95 ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
96 ptrace (PTRACE_POKEDATA, inferior_pid, stack, 0xc589);
97 ptrace (PTRACE_SINGLESTEP, inferior_pid, stack, 0);
98 wait (0);
99 ptrace (PTRACE_POKEDATA, inferior_pid, stack, stuff);
100 inferior_registers.r_reg[EAX] = reg;
101 }
102#endif
103 ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
104 ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers);
105}
106
107/* Machine-dependent code which would otherwise be in core.c */
108/* Work with core files, for GDB. */
109
110\f
111void
112core_file_command (filename, from_tty)
113 char *filename;
114 int from_tty;
115{
116 int val;
117 extern char registers[];
118
119 /* Discard all vestiges of any previous core file
120 and mark data and stack spaces as empty. */
121
122 if (corefile)
123 free (corefile);
124 corefile = 0;
125
126 if (corechan >= 0)
127 close (corechan);
128 corechan = -1;
129
130 data_start = 0;
131 data_end = 0;
132 stack_start = STACK_END_ADDR;
133 stack_end = STACK_END_ADDR;
134
135 /* Now, if a new core file was specified, open it and digest it. */
136
137 if (filename)
138 {
139 filename = tilde_expand (filename);
140 make_cleanup (free, filename);
141
142 if (have_inferior_p ())
143 error ("To look at a core file, you must kill the inferior with \"kill\".");
144 corechan = open (filename, O_RDONLY, 0);
145 if (corechan < 0)
146 perror_with_name (filename);
147
148 {
149 struct core corestr;
150
151 val = myread (corechan, &corestr, sizeof corestr);
152 if (val < 0)
153 perror_with_name (filename);
154 if (corestr.c_magic != CORE_MAGIC)
155 error ("\"%s\" does not appear to be a core dump file (magic 0x%x, expected 0x%x)",
156 filename, corestr.c_magic, (int) CORE_MAGIC);
157 else if (sizeof (struct core) != corestr.c_len)
158 error ("\"%s\" has an invalid struct core length (%d, expected %d)",
159 filename, corestr.c_len, (int) sizeof (struct core));
160
161 data_start = exec_data_start;
162 data_end = data_start + corestr.c_dsize;
163 stack_start = stack_end - corestr.c_ssize;
164 data_offset = sizeof corestr;
165 stack_offset = sizeof corestr + corestr.c_dsize;
166
167 bcopy (&corestr.c_regs, registers, sizeof corestr.c_regs);
168
169 bcopy (corestr.c_fpu.f_fpstatus.f_st,
170 &registers[REGISTER_BYTE (FP0_REGNUM)],
171 sizeof corestr.c_fpu.f_fpstatus.f_st);
172 bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl,
173 &registers[REGISTER_BYTE (FPC_REGNUM)],
174 sizeof corestr.c_fpu.f_fpstatus -
175 sizeof corestr.c_fpu.f_fpstatus.f_st);
176
177 /* the struct aouthdr of sun coff is not the struct exec stored
178 in the core file. */
179 bcopy (&corestr.c_aouthdr, &core_aouthdr, sizeof (struct exec));
180#ifndef COFF_ENCAPSULATE
181 core_aouthdr.magic = corestr.c_aouthdr.a_info;
182 core_aouthdr.vstamp = /*SUNVERSION*/ 31252;
183#endif
184 printf ("Core file is from \"%s\".\n", corestr.c_cmdname);
185 if (corestr.c_signo > 0)
186 printf ("Program terminated with signal %d, %s.\n",
187 corestr.c_signo,
188 corestr.c_signo < NSIG
189 ? sys_siglist[corestr.c_signo]
190 : "(undocumented)");
191 }
192 if (filename[0] == '/')
193 corefile = savestring (filename, strlen (filename));
194 else
195 {
58ae87f6 196 corefile = concat (current_directory, "/", filename, NULL);
dd3b648e
RP
197 }
198
199 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
200 read_pc ()));
201 select_frame (get_current_frame (), 0);
202
203 validate_files ();
204 }
205 else if (from_tty)
206 printf ("No core file now.\n");
207}
208
209i387_to_double (from, to)
210 char *from;
211 char *to;
212{
213 long *lp;
214 /* push extended mode on 387 stack, then pop in double mode
215 *
216 * first, set exception masks so no error is generated -
217 * number will be rounded to inf or 0, if necessary
218 */
219 asm ("pushl %eax"); /* grab a stack slot */
220 asm ("fstcw (%esp)"); /* get 387 control word */
221 asm ("movl (%esp),%eax"); /* save old value */
222 asm ("orl $0x3f,%eax"); /* mask all exceptions */
223 asm ("pushl %eax");
224 asm ("fldcw (%esp)"); /* load new value into 387 */
225
226 asm ("movl 8(%ebp),%eax");
227 asm ("fldt (%eax)"); /* push extended number on 387 stack */
228 asm ("fwait");
229 asm ("movl 12(%ebp),%eax");
230 asm ("fstpl (%eax)"); /* pop double */
231 asm ("fwait");
232
233 asm ("popl %eax"); /* flush modified control word */
234 asm ("fnclex"); /* clear exceptions */
235 asm ("fldcw (%esp)"); /* restore original control word */
236 asm ("popl %eax"); /* flush saved copy */
237}
238
239double_to_i387 (from, to)
240 char *from;
241 char *to;
242{
243 /* push double mode on 387 stack, then pop in extended mode
244 * no errors are possible because every 64-bit pattern
245 * can be converted to an extended
246 */
247 asm ("movl 8(%ebp),%eax");
248 asm ("fldl (%eax)");
249 asm ("fwait");
250 asm ("movl 12(%ebp),%eax");
251 asm ("fstpt (%eax)");
252 asm ("fwait");
253}
f0ca24b9
JK
254#else /* Not sun386 target. */
255
256/* These functions shouldn't be called when we're cross-debugging. */
257
258void
259fetch_inferior_registers ()
260{
261}
262
263/* ARGSUSED */
264store_inferior_registers (regno)
265 int regno;
266{
267}
268
269/* ARGSUSED */
270void
271fetch_core_registers (core_reg_sect, core_reg_size, which)
272 char *core_reg_sect;
273 unsigned core_reg_size;
274 int which;
275{
276}
277
278#endif /* Not sun386 target. */
This page took 0.053956 seconds and 4 git commands to generate.