]> Git Repo - binutils.git/blob - gdb/sun386-xdep.c
* lmode_inferior_valid, lmode_ours_valid: New static vars.
[binutils.git] / gdb / sun386-xdep.c
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 ([email protected]),
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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
21
22 #if defined (GDB_TARGET_IS_SUN386)
23
24 #include "defs.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "gdbcore.h"
28
29 #include <sys/param.h>
30 #include <sys/dir.h>
31 #include <sys/user.h>
32 #include <signal.h>
33 #include <sys/ioctl.h>
34 #include <fcntl.h>
35
36 #include <sys/ptrace.h>
37 #include <machine/reg.h>
38
39 #include <sys/file.h>
40 #include <sys/stat.h>
41 #include <sys/core.h>
42
43 \f
44 void
45 fetch_inferior_registers (regno)
46      int regno;
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,
55           (PTRACE_ARG3_TYPE) &inferior_registers);
56   ptrace (PTRACE_GETFPREGS, inferior_pid,
57           (PTRACE_ARG3_TYPE) &inferior_fp_registers);
58
59   bcopy (&inferior_registers, registers, sizeof inferior_registers);
60
61   bcopy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
62          sizeof inferior_fp_registers.f_st);
63   bcopy (&inferior_fp_registers.f_ctrl,
64          &registers[REGISTER_BYTE (FPC_REGNUM)],
65          sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
66 }
67
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).  */
71
72 void
73 store_inferior_registers (regno)
74      int regno;
75 {
76   struct regs inferior_registers;
77   struct fp_state inferior_fp_registers;
78   extern char registers[];
79
80   bcopy (registers, &inferior_registers, 20 * 4);
81
82   bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
83          sizeof inferior_fp_registers.f_st);
84   bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
85          &inferior_fp_registers.f_ctrl,
86          sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
87   
88 #ifdef PTRACE_FP_BUG
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.  */
92     {
93       int stack = inferior_registers.r_reg[SP_REGNUM];
94       int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
95                           (PTRACE_ARG3_TYPE) stack);
96       int reg = inferior_registers.r_reg[EAX];
97       inferior_registers.r_reg[EAX] =
98         inferior_registers.r_reg[FP_REGNUM];
99       ptrace (PTRACE_SETREGS, inferior_pid, 
100               (PTRACE_ARG3_TYPE) &inferior_registers);
101       ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
102               0xc589);
103       ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack,
104               0);
105       wait (0);
106       ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack,
107               stuff);
108       inferior_registers.r_reg[EAX] = reg;
109     }
110 #endif
111   ptrace (PTRACE_SETREGS, inferior_pid,
112           (PTRACE_ARG3_TYPE) &inferior_registers);
113   ptrace (PTRACE_SETFPREGS, inferior_pid,
114           (PTRACE_ARG3_TYPE) &inferior_fp_registers);
115 }
116
117 /* Machine-dependent code which would otherwise be in core.c */
118 /* Work with core files, for GDB. */
119
120 \f
121 void
122 core_file_command (filename, from_tty)
123      char *filename;
124      int from_tty;
125 {
126   int val;
127   extern char registers[];
128
129   /* Discard all vestiges of any previous core file
130      and mark data and stack spaces as empty.  */
131
132   if (corefile)
133     free (corefile);
134   corefile = 0;
135
136   if (corechan >= 0)
137     close (corechan);
138   corechan = -1;
139
140   data_start = 0;
141   data_end = 0;
142   stack_start = STACK_END_ADDR;
143   stack_end = STACK_END_ADDR;
144
145   /* Now, if a new core file was specified, open it and digest it.  */
146
147   if (filename)
148     {
149       filename = tilde_expand (filename);
150       make_cleanup (free, filename);
151       
152       if (have_inferior_p ())
153         error ("To look at a core file, you must kill the inferior with \"kill\".");
154       corechan = open (filename, O_RDONLY, 0);
155       if (corechan < 0)
156         perror_with_name (filename);
157
158       {
159         struct core corestr;
160
161         val = myread (corechan, &corestr, sizeof corestr);
162         if (val < 0)
163           perror_with_name (filename);
164         if (corestr.c_magic != CORE_MAGIC)
165           error ("\"%s\" does not appear to be a core dump file (magic 0x%x, expected 0x%x)",
166                  filename, corestr.c_magic, (int) CORE_MAGIC);
167         else if (sizeof (struct core) != corestr.c_len)
168           error ("\"%s\" has an invalid struct core length (%d, expected %d)",
169                  filename, corestr.c_len, (int) sizeof (struct core));
170
171         data_start = exec_data_start;
172         data_end = data_start + corestr.c_dsize;
173         stack_start = stack_end - corestr.c_ssize;
174         data_offset = sizeof corestr;
175         stack_offset = sizeof corestr + corestr.c_dsize;
176
177         bcopy (&corestr.c_regs, registers, sizeof corestr.c_regs);
178
179         bcopy (corestr.c_fpu.f_fpstatus.f_st,
180                &registers[REGISTER_BYTE (FP0_REGNUM)],
181                sizeof corestr.c_fpu.f_fpstatus.f_st);
182         bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl,
183                &registers[REGISTER_BYTE (FPC_REGNUM)],
184                sizeof corestr.c_fpu.f_fpstatus -
185                sizeof corestr.c_fpu.f_fpstatus.f_st);
186
187         /* the struct aouthdr of sun coff is not the struct exec stored
188            in the core file. */
189         bcopy (&corestr.c_aouthdr, &core_aouthdr, sizeof (struct exec));
190 #ifndef COFF_ENCAPSULATE
191         core_aouthdr.magic = corestr.c_aouthdr.a_info;
192         core_aouthdr.vstamp = /*SUNVERSION*/ 31252;
193 #endif
194         printf ("Core file is from \"%s\".\n", corestr.c_cmdname);
195         if (corestr.c_signo > 0)
196           printf ("Program terminated with signal %d, %s.\n",
197                   corestr.c_signo, safe_strsignal (corestr.c_signo));
198       }
199       if (filename[0] == '/')
200         corefile = savestring (filename, strlen (filename));
201       else
202         {
203           corefile = concat (current_directory, "/", filename, NULL);
204         }
205
206       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
207                                             read_pc ()));
208       select_frame (get_current_frame (), 0);
209
210       validate_files ();
211     }
212   else if (from_tty)
213     printf ("No core file now.\n");
214 }
215
216 i387_to_double (from, to)
217      char *from;
218      char *to;
219 {
220   long *lp;
221   /* push extended mode on 387 stack, then pop in double mode
222    *
223    * first, set exception masks so no error is generated -
224    * number will be rounded to inf or 0, if necessary 
225    */
226   asm ("pushl %eax");           /* grab a stack slot */
227   asm ("fstcw (%esp)");         /* get 387 control word */
228   asm ("movl (%esp),%eax");     /* save old value */
229   asm ("orl $0x3f,%eax");               /* mask all exceptions */
230   asm ("pushl %eax");
231   asm ("fldcw (%esp)");         /* load new value into 387 */
232   
233   asm ("movl 8(%ebp),%eax");
234   asm ("fldt (%eax)");          /* push extended number on 387 stack */
235   asm ("fwait");
236   asm ("movl 12(%ebp),%eax");
237   asm ("fstpl (%eax)");         /* pop double */
238   asm ("fwait");
239   
240   asm ("popl %eax");            /* flush modified control word */
241   asm ("fnclex");                       /* clear exceptions */
242   asm ("fldcw (%esp)");         /* restore original control word */
243   asm ("popl %eax");            /* flush saved copy */
244 }
245
246 double_to_i387 (from, to)
247      char *from;
248      char *to;
249 {
250   /* push double mode on 387 stack, then pop in extended mode
251    * no errors are possible because every 64-bit pattern
252    * can be converted to an extended
253    */
254   asm ("movl 8(%ebp),%eax");
255   asm ("fldl (%eax)");
256   asm ("fwait");
257   asm ("movl 12(%ebp),%eax");
258   asm ("fstpt (%eax)");
259   asm ("fwait");
260 }
261 #else /* Not sun386 target.  */
262
263 /* These functions shouldn't be called when we're cross-debugging.  */
264
265 /* ARGSUSED */
266 void
267 fetch_inferior_registers (regno)
268      int regno;
269 {
270 }
271
272 /* ARGSUSED */
273 void
274 store_inferior_registers (regno)
275      int regno;
276 {
277 }
278
279 /* ARGSUSED */
280 void
281 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
282      char *core_reg_sect;
283      unsigned core_reg_size;
284      int which;
285      unsigned int reg_addr;     /* Unused in this version */
286 {
287 }
288
289 #endif /* Not sun386 target.  */
This page took 0.040107 seconds and 4 git commands to generate.