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),
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #include <sys/param.h>
32 #include <sys/ioctl.h>
35 #include <sys/ptrace.h>
36 #include <machine/reg.h>
43 /* Machine-dependent code which would otherwise be in corefile.c */
44 /* Work with core files, for GDB. */
48 core_file_command (filename, from_tty)
54 /* Discard all vestiges of any previous core file
55 and mark data and stack spaces as empty. */
67 stack_start = STACK_END_ADDR;
68 stack_end = STACK_END_ADDR;
70 /* Now, if a new core file was specified, open it and digest it. */
74 filename = tilde_expand (filename);
75 make_cleanup (free, filename);
77 if (have_inferior_p ())
78 error ("To look at a core file, you must kill the program with \"kill\".");
79 corechan = open (filename, O_RDONLY, 0);
81 perror_with_name (filename);
86 val = myread (corechan, &corestr, sizeof corestr);
88 perror_with_name (filename);
89 if (corestr.c_magic != CORE_MAGIC)
90 error ("\"%s\" does not appear to be a core dump file (magic 0x%x, expected 0x%x)",
91 filename, corestr.c_magic, (int) CORE_MAGIC);
92 else if (sizeof (struct core) != corestr.c_len)
93 error ("\"%s\" has an invalid struct core length (%d, expected %d)",
94 filename, corestr.c_len, (int) sizeof (struct core));
96 data_start = exec_data_start;
97 data_end = data_start + corestr.c_dsize;
98 stack_start = stack_end - corestr.c_ssize;
99 data_offset = sizeof corestr;
100 stack_offset = sizeof corestr + corestr.c_dsize;
102 memcpy (registers, &corestr.c_regs, sizeof corestr.c_regs);
104 memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)],
105 corestr.c_fpu.f_fpstatus.f_st,
106 sizeof corestr.c_fpu.f_fpstatus.f_st);
107 memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
108 &corestr.c_fpu.f_fpstatus.f_ctrl,
109 sizeof corestr.c_fpu.f_fpstatus -
110 sizeof corestr.c_fpu.f_fpstatus.f_st);
112 /* the struct aouthdr of sun coff is not the struct exec stored
114 memcpy (&core_aouthdr, &corestr.c_aouthdr, sizeof (struct exec));
115 #ifndef COFF_ENCAPSULATE
116 core_aouthdr.magic = corestr.c_aouthdr.a_info;
117 core_aouthdr.vstamp = /*SUNVERSION */ 31252;
119 printf_unfiltered ("Core file is from \"%s\".\n", corestr.c_cmdname);
120 if (corestr.c_signo > 0)
121 printf_unfiltered ("Program terminated with signal %d, %s.\n",
122 corestr.c_signo, safe_strsignal (corestr.c_signo));
124 if (filename[0] == '/')
125 corefile = savestring (filename, strlen (filename));
128 corefile = concat (current_directory, "/", filename, NULL);
131 flush_cached_frames ();
132 select_frame (get_current_frame (), 0);
137 printf_unfiltered ("No core file now.\n");
140 i387_to_double (from, to)
145 /* push extended mode on 387 stack, then pop in double mode
147 * first, set exception masks so no error is generated -
148 * number will be rounded to inf or 0, if necessary
150 asm ("pushl %eax"); /* grab a stack slot */
151 asm ("fstcw (%esp)"); /* get 387 control word */
152 asm ("movl (%esp),%eax"); /* save old value */
153 asm ("orl $0x3f,%eax"); /* mask all exceptions */
155 asm ("fldcw (%esp)"); /* load new value into 387 */
157 asm ("movl 8(%ebp),%eax");
158 asm ("fldt (%eax)"); /* push extended number on 387 stack */
160 asm ("movl 12(%ebp),%eax");
161 asm ("fstpl (%eax)"); /* pop double */
164 asm ("popl %eax"); /* flush modified control word */
165 asm ("fnclex"); /* clear exceptions */
166 asm ("fldcw (%esp)"); /* restore original control word */
167 asm ("popl %eax"); /* flush saved copy */
170 double_to_i387 (from, to)
174 /* push double mode on 387 stack, then pop in extended mode
175 * no errors are possible because every 64-bit pattern
176 * can be converted to an extended
178 asm ("movl 8(%ebp),%eax");
181 asm ("movl 12(%ebp),%eax");
182 asm ("fstpt (%eax)");
187 fetch_inferior_registers (regno)
190 struct regs inferior_registers;
191 struct fp_state inferior_fp_registers;
193 registers_fetched ();
195 ptrace (PTRACE_GETREGS, inferior_pid,
196 (PTRACE_ARG3_TYPE) & inferior_registers);
197 ptrace (PTRACE_GETFPREGS, inferior_pid,
198 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
200 memcpy (registers, &inferior_registers, sizeof inferior_registers);
202 memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], inferior_fp_registers.f_st,
203 sizeof inferior_fp_registers.f_st);
204 memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
205 &inferior_fp_registers.f_ctrl,
206 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
209 /* Store our register values back into the inferior.
210 If REGNO is -1, do this for all registers.
211 Otherwise, REGNO specifies which register (so we can save time). */
214 store_inferior_registers (regno)
217 struct regs inferior_registers;
218 struct fp_state inferior_fp_registers;
220 memcpy (&inferior_registers, registers, 20 * 4);
222 memcpy (inferior_fp_registers.f_st,
223 ®isters[REGISTER_BYTE (FP0_REGNUM)],
224 sizeof inferior_fp_registers.f_st);
225 memcpy (&inferior_fp_registers.f_ctrl,
226 ®isters[REGISTER_BYTE (FPC_REGNUM)],
227 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
230 if (regno == FP_REGNUM || regno == -1)
231 /* Storing the frame pointer requires a gross hack, in which an
232 instruction that moves eax into ebp gets single-stepped. */
234 int stack = inferior_registers.r_reg[SP_REGNUM];
235 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
236 (PTRACE_ARG3_TYPE) stack);
237 int reg = inferior_registers.r_reg[EAX];
238 inferior_registers.r_reg[EAX] =
239 inferior_registers.r_reg[FP_REGNUM];
240 ptrace (PTRACE_SETREGS, inferior_pid,
241 (PTRACE_ARG3_TYPE) & inferior_registers);
242 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
244 ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack,
247 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
249 inferior_registers.r_reg[EAX] = reg;
252 ptrace (PTRACE_SETREGS, inferior_pid,
253 (PTRACE_ARG3_TYPE) & inferior_registers);
254 ptrace (PTRACE_SETFPREGS, inferior_pid,
255 (PTRACE_ARG3_TYPE) & inferior_fp_registers);