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