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