This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / sun386-nat.c
1 /* Native support for Sun 386i's for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Changes for sun386i by Jean Daniel Fekete (jdf@litp.univ-p6-7.fr),
4 C2V Paris, April 89.
5
6 This file is part of GDB.
7
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.
12
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.
17
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "gdbcore.h"
26
27 #include <sys/param.h>
28 #include <sys/dir.h>
29 #include <sys/user.h>
30 #include <signal.h>
31 #include <sys/ioctl.h>
32 #include <fcntl.h>
33
34 #include <sys/ptrace.h>
35 #include <machine/reg.h>
36
37 #include <sys/file.h>
38 #include "gdb_stat.h"
39 #include <sys/core.h>
40
41 \f
42 /* Machine-dependent code which would otherwise be in corefile.c */
43 /* Work with core files, for GDB. */
44
45 \f
46 void
47 core_file_command (filename, from_tty)
48 char *filename;
49 int from_tty;
50 {
51 int val;
52
53 /* Discard all vestiges of any previous core file
54 and mark data and stack spaces as empty. */
55
56 if (corefile)
57 free (corefile);
58 corefile = 0;
59
60 if (corechan >= 0)
61 close (corechan);
62 corechan = -1;
63
64 data_start = 0;
65 data_end = 0;
66 stack_start = STACK_END_ADDR;
67 stack_end = STACK_END_ADDR;
68
69 /* Now, if a new core file was specified, open it and digest it. */
70
71 if (filename)
72 {
73 filename = tilde_expand (filename);
74 make_cleanup (free, filename);
75
76 if (have_inferior_p ())
77 error ("To look at a core file, you must kill the program with \"kill\".");
78 corechan = open (filename, O_RDONLY, 0);
79 if (corechan < 0)
80 perror_with_name (filename);
81
82 {
83 struct core corestr;
84
85 val = myread (corechan, &corestr, sizeof corestr);
86 if (val < 0)
87 perror_with_name (filename);
88 if (corestr.c_magic != CORE_MAGIC)
89 error ("\"%s\" does not appear to be a core dump file (magic 0x%x, expected 0x%x)",
90 filename, corestr.c_magic, (int) CORE_MAGIC);
91 else if (sizeof (struct core) != corestr.c_len)
92 error ("\"%s\" has an invalid struct core length (%d, expected %d)",
93 filename, corestr.c_len, (int) sizeof (struct core));
94
95 data_start = exec_data_start;
96 data_end = data_start + corestr.c_dsize;
97 stack_start = stack_end - corestr.c_ssize;
98 data_offset = sizeof corestr;
99 stack_offset = sizeof corestr + corestr.c_dsize;
100
101 memcpy (registers, &corestr.c_regs, sizeof corestr.c_regs);
102
103 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
104 corestr.c_fpu.f_fpstatus.f_st,
105 sizeof corestr.c_fpu.f_fpstatus.f_st);
106 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
107 &corestr.c_fpu.f_fpstatus.f_ctrl,
108 sizeof corestr.c_fpu.f_fpstatus -
109 sizeof corestr.c_fpu.f_fpstatus.f_st);
110
111 /* the struct aouthdr of sun coff is not the struct exec stored
112 in the core file. */
113 memcpy (&core_aouthdr, &corestr.c_aouthdr, sizeof (struct exec));
114 #ifndef COFF_ENCAPSULATE
115 core_aouthdr.magic = corestr.c_aouthdr.a_info;
116 core_aouthdr.vstamp = /*SUNVERSION*/ 31252;
117 #endif
118 printf_unfiltered ("Core file is from \"%s\".\n", corestr.c_cmdname);
119 if (corestr.c_signo > 0)
120 printf_unfiltered ("Program terminated with signal %d, %s.\n",
121 corestr.c_signo, safe_strsignal (corestr.c_signo));
122 }
123 if (filename[0] == '/')
124 corefile = savestring (filename, strlen (filename));
125 else
126 {
127 corefile = concat (current_directory, "/", filename, NULL);
128 }
129
130 flush_cached_frames ();
131 select_frame (get_current_frame (), 0);
132
133 validate_files ();
134 }
135 else if (from_tty)
136 printf_unfiltered ("No core file now.\n");
137 }
138
139 i387_to_double (from, to)
140 char *from;
141 char *to;
142 {
143 long *lp;
144 /* push extended mode on 387 stack, then pop in double mode
145 *
146 * first, set exception masks so no error is generated -
147 * number will be rounded to inf or 0, if necessary
148 */
149 asm ("pushl %eax"); /* grab a stack slot */
150 asm ("fstcw (%esp)"); /* get 387 control word */
151 asm ("movl (%esp),%eax"); /* save old value */
152 asm ("orl $0x3f,%eax"); /* mask all exceptions */
153 asm ("pushl %eax");
154 asm ("fldcw (%esp)"); /* load new value into 387 */
155
156 asm ("movl 8(%ebp),%eax");
157 asm ("fldt (%eax)"); /* push extended number on 387 stack */
158 asm ("fwait");
159 asm ("movl 12(%ebp),%eax");
160 asm ("fstpl (%eax)"); /* pop double */
161 asm ("fwait");
162
163 asm ("popl %eax"); /* flush modified control word */
164 asm ("fnclex"); /* clear exceptions */
165 asm ("fldcw (%esp)"); /* restore original control word */
166 asm ("popl %eax"); /* flush saved copy */
167 }
168
169 double_to_i387 (from, to)
170 char *from;
171 char *to;
172 {
173 /* push double mode on 387 stack, then pop in extended mode
174 * no errors are possible because every 64-bit pattern
175 * can be converted to an extended
176 */
177 asm ("movl 8(%ebp),%eax");
178 asm ("fldl (%eax)");
179 asm ("fwait");
180 asm ("movl 12(%ebp),%eax");
181 asm ("fstpt (%eax)");
182 asm ("fwait");
183 }
184
185 void
186 fetch_inferior_registers (regno)
187 int regno;
188 {
189 struct regs inferior_registers;
190 struct fp_state inferior_fp_registers;
191
192 registers_fetched ();
193
194 ptrace (PTRACE_GETREGS, inferior_pid,
195 (PTRACE_ARG3_TYPE) &inferior_registers);
196 ptrace (PTRACE_GETFPREGS, inferior_pid,
197 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
198
199 memcpy (registers, &inferior_registers, sizeof inferior_registers);
200
201 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
202 sizeof inferior_fp_registers.f_st);
203 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
204 &inferior_fp_registers.f_ctrl,
205 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
206 }
207
208 /* Store our register values back into the inferior.
209 If REGNO is -1, do this for all registers.
210 Otherwise, REGNO specifies which register (so we can save time). */
211
212 void
213 store_inferior_registers (regno)
214 int regno;
215 {
216 struct regs inferior_registers;
217 struct fp_state inferior_fp_registers;
218
219 memcpy (&inferior_registers, registers, 20 * 4);
220
221 memcpy (inferior_fp_registers.f_st,
222 &registers[REGISTER_BYTE (FP0_REGNUM)],
223 sizeof inferior_fp_registers.f_st);
224 memcpy (&inferior_fp_registers.f_ctrl,
225 &registers[REGISTER_BYTE (FPC_REGNUM)],
226 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
227
228 #ifdef PTRACE_FP_BUG
229 if (regno == FP_REGNUM || regno == -1)
230 /* Storing the frame pointer requires a gross hack, in which an
231 instruction that moves eax into ebp gets single-stepped. */
232 {
233 int stack = inferior_registers.r_reg[SP_REGNUM];
234 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
235 (PTRACE_ARG3_TYPE) stack);
236 int reg = inferior_registers.r_reg[EAX];
237 inferior_registers.r_reg[EAX] =
238 inferior_registers.r_reg[FP_REGNUM];
239 ptrace (PTRACE_SETREGS, inferior_pid,
240 (PTRACE_ARG3_TYPE) &inferior_registers);
241 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
242 0xc589);
243 ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack,
244 0);
245 wait (0);
246 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
247 stuff);
248 inferior_registers.r_reg[EAX] = reg;
249 }
250 #endif
251 ptrace (PTRACE_SETREGS, inferior_pid,
252 (PTRACE_ARG3_TYPE) &inferior_registers);
253 ptrace (PTRACE_SETFPREGS, inferior_pid,
254 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
255 }
This page took 0.035434 seconds and 5 git commands to generate.