]>
Commit | Line | Data |
---|---|---|
8aa13b87 JK |
1 | /* Copyright (C) 1988, 1990 Free Software Foundation, Inc. |
2 | ||
3 | This file is part of GDB. | |
4 | ||
99a7de40 | 5 | This program is free software; you can redistribute it and/or modify |
8aa13b87 | 6 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | |
8aa13b87 | 9 | |
99a7de40 | 10 | This program is distributed in the hope that it will be useful, |
8aa13b87 JK |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
8aa13b87 JK |
18 | |
19 | #include <stdio.h> | |
20 | #include "defs.h" | |
21 | #include "param.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | ||
25 | #ifdef USG | |
26 | #include <sys/types.h> | |
27 | #endif | |
28 | ||
29 | #include <sys/param.h> | |
30 | #include <sys/dir.h> | |
31 | #include <signal.h> | |
32 | #include "gdbcore.h" | |
33 | #include <sys/user.h> | |
8aa13b87 | 34 | |
12f2fd9f | 35 | #ifndef USER /* added to support BCS ptrace_user */ |
8aa13b87 JK |
36 | #define USER ptrace_user |
37 | #endif | |
38 | #include <sys/ioctl.h> | |
39 | #include <fcntl.h> | |
8aa13b87 JK |
40 | #include <sys/file.h> |
41 | #include <sys/stat.h> | |
42 | ||
43 | #include "symtab.h" | |
44 | #include "setjmp.h" | |
45 | #include "value.h" | |
46 | ||
12f2fd9f SC |
47 | #ifdef DELTA88 |
48 | #include <sys/ptrace.h> | |
8aa13b87 | 49 | |
12f2fd9f SC |
50 | /* define offsets to the pc instruction offsets in ptrace_user struct */ |
51 | #define SXIP_OFFSET (char *)&u.pt_sigframe.sig_sxip - (char *)&u | |
52 | #define SNIP_OFFSET (char *)&u.pt_sigframe.sig_snip - (char *)&u | |
53 | #define SFIP_OFFSET (char *)&u.pt_sigframe.sig_sfip - (char *)&u | |
54 | #else | |
55 | /* define offsets to the pc instruction offsets in ptrace_user struct */ | |
56 | #define SXIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sxip - (char *)&u | |
57 | #define SNIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_snip - (char *)&u | |
8aa13b87 | 58 | #define SFIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u |
12f2fd9f SC |
59 | #endif |
60 | ||
8aa13b87 JK |
61 | extern int have_symbol_file_p(); |
62 | ||
63 | extern jmp_buf stack_jmp; | |
64 | ||
65 | extern int errno; | |
66 | extern char registers[REGISTER_BYTES]; | |
67 | \f | |
68 | void | |
69 | fetch_inferior_registers () | |
70 | { | |
71 | register int regno; | |
72 | register unsigned int regaddr; | |
73 | char buf[MAX_REGISTER_RAW_SIZE]; | |
74 | register int i; | |
75 | ||
76 | struct USER u; | |
77 | unsigned int offset; | |
78 | ||
79 | offset = (char *) &u.pt_r0 - (char *) &u; | |
80 | regaddr = offset; /* byte offset to r0;*/ | |
81 | ||
82 | /* offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; */ | |
83 | for (regno = 0; regno < NUM_REGS; regno++) | |
84 | { | |
85 | /*regaddr = register_addr (regno, offset);*/ | |
86 | /* 88k enhancement */ | |
87 | ||
88 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) | |
89 | { | |
90 | *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0); | |
91 | regaddr += sizeof (int); | |
92 | } | |
93 | supply_register (regno, buf); | |
94 | } | |
95 | /* now load up registers 36 - 38; special pc registers */ | |
12f2fd9f | 96 | *(int *) &buf[0] = ptrace (3,inferior_pid,SXIP_OFFSET ,0); |
8aa13b87 | 97 | supply_register (SXIP_REGNUM, buf); |
12f2fd9f | 98 | *(int *) &buf[0] = ptrace (3, inferior_pid,SNIP_OFFSET,0); |
8aa13b87 | 99 | supply_register (SNIP_REGNUM, buf); |
12f2fd9f | 100 | *(int *) &buf[0] = ptrace (3, inferior_pid,SFIP_OFFSET,0); |
8aa13b87 JK |
101 | supply_register (SFIP_REGNUM, buf); |
102 | } | |
103 | ||
104 | /* Store our register values back into the inferior. | |
105 | If REGNO is -1, do this for all registers. | |
106 | Otherwise, REGNO specifies which register (so we can save time). */ | |
107 | ||
108 | store_inferior_registers (regno) | |
109 | int regno; | |
110 | { | |
111 | register unsigned int regaddr; | |
112 | char buf[80]; | |
113 | ||
114 | struct USER u; | |
115 | ||
8aa13b87 JK |
116 | |
117 | unsigned int offset = (char *) &u.pt_r0 - (char *) &u; | |
118 | ||
8aa13b87 JK |
119 | regaddr = offset; |
120 | ||
121 | if (regno >= 0) | |
122 | { | |
123 | /* regaddr = register_addr (regno, offset); */ | |
124 | if (regno < PC_REGNUM) | |
125 | { | |
126 | regaddr = offset + regno * sizeof (int); | |
127 | errno = 0; | |
128 | ptrace (6, inferior_pid, regaddr, read_register (regno)); | |
129 | if (errno != 0) | |
130 | { | |
131 | sprintf (buf, "writing register number %d", regno); | |
132 | perror_with_name (buf); | |
133 | } | |
134 | } | |
135 | else if (regno == SXIP_REGNUM) | |
136 | ptrace (6, inferior_pid, SXIP_OFFSET, read_register(regno)); | |
137 | else if (regno == SNIP_REGNUM) | |
138 | ptrace (6, inferior_pid, SNIP_OFFSET, read_register(regno)); | |
139 | else if (regno == SFIP_REGNUM) | |
140 | ptrace (6, inferior_pid, SFIP_OFFSET, read_register(regno)); | |
141 | else printf ("Bad register number for store_inferior routine\n"); | |
142 | } | |
143 | else { | |
144 | for (regno = 0; regno < NUM_REGS - 3; regno++) | |
145 | { | |
146 | /* regaddr = register_addr (regno, offset); */ | |
147 | errno = 0; | |
148 | regaddr = offset + regno * sizeof (int); | |
149 | ptrace (6, inferior_pid, regaddr, read_register (regno)); | |
150 | if (errno != 0) | |
151 | { | |
152 | sprintf (buf, "writing register number %d", regno); | |
153 | perror_with_name (buf); | |
154 | } | |
155 | } | |
156 | ptrace (6,inferior_pid,SXIP_OFFSET,read_register(SXIP_REGNUM)); | |
157 | ptrace (6,inferior_pid,SNIP_OFFSET,read_register(SNIP_REGNUM)); | |
158 | ptrace (6,inferior_pid,SFIP_OFFSET,read_register(SFIP_REGNUM)); | |
159 | } | |
160 | ||
161 | ||
162 | } | |
163 | ||
164 | #if 0 | |
165 | /* Core files are now a function of BFD. */ | |
166 | \f | |
167 | void | |
168 | core_file_command (filename, from_tty) | |
169 | char *filename; | |
170 | int from_tty; | |
171 | { | |
172 | int val; | |
173 | extern char registers[]; | |
174 | ||
175 | /* Need symbol file and one with tdesc info for corefiles to work */ | |
176 | if (!have_symbol_file_p()) | |
177 | error ("Requires symbol-file and exec-file"); | |
178 | if (!execfile) | |
179 | error ("Requires exec-file and symbol-file"); | |
180 | ||
181 | /* Discard all vestiges of any previous core file | |
182 | and mark data and stack spaces as empty. */ | |
183 | ||
184 | if (corefile) | |
185 | free (corefile); | |
186 | corefile = 0; | |
187 | ||
188 | if (corechan >= 0) | |
189 | close (corechan); | |
190 | corechan = -1; | |
191 | ||
192 | data_start = 0; | |
193 | data_end = 0; | |
194 | stack_start = STACK_END_ADDR; | |
195 | stack_end = STACK_END_ADDR; | |
196 | ||
197 | /* Now, if a new core file was specified, open it and digest it. */ | |
198 | ||
199 | if (filename) | |
200 | { | |
201 | filename = tilde_expand (filename); | |
202 | make_cleanup (free, filename); | |
203 | ||
204 | if (have_inferior_p ()) | |
205 | error ("To look at a core file, you must kill the inferior with \"kill\"."); | |
206 | corechan = open (filename, O_RDONLY, 0); | |
207 | if (corechan < 0) | |
208 | perror_with_name (filename); | |
209 | /* 4.2-style (and perhaps also sysV-style) core dump file. */ | |
210 | { | |
211 | struct USER u; | |
212 | ||
213 | int reg_offset; | |
214 | ||
215 | val = myread (corechan, &u, sizeof u); | |
216 | if (val < 0) | |
217 | perror_with_name (filename); | |
218 | data_start = u.pt_o_data_start; | |
219 | ||
220 | data_end = data_start + u.pt_dsize; | |
221 | stack_start = stack_end - u.pt_ssize; | |
222 | data_offset = u.pt_dataptr; | |
223 | stack_offset = data_offset + u.pt_dsize; | |
224 | ||
225 | #if defined(BCS) | |
226 | #if defined(DGUX) | |
227 | ||
228 | reg_offset = 2048; | |
229 | ||
230 | ||
231 | #endif /* defined (DGUX) */ | |
232 | #else | |
233 | ||
234 | /* original code: */ | |
235 | reg_offset = (int) u.pt_r0 - KERNEL_U_ADDR; | |
236 | ||
237 | #endif /* defined(BCS) */ | |
238 | ||
239 | /* I don't know where to find this info. | |
240 | So, for now, mark it as not available. */ | |
241 | /* N_SET_MAGIC (core_aouthdr, 0); */ | |
242 | bzero ((char *) &core_aouthdr, sizeof core_aouthdr); | |
243 | ||
244 | /* Read the register values out of the core file and store | |
245 | them where `read_register' will find them. */ | |
246 | ||
247 | { | |
248 | register int regno; | |
249 | ||
250 | for (regno = 0; regno < NUM_REGS; regno++) | |
251 | { | |
252 | char buf[MAX_REGISTER_RAW_SIZE]; | |
253 | ||
254 | val = lseek (corechan, register_addr (regno, reg_offset), 0); | |
255 | if (val < 0) | |
256 | perror_with_name (filename); | |
257 | ||
258 | val = myread (corechan, buf, sizeof buf); | |
259 | if (val < 0) | |
260 | perror_with_name (filename); | |
261 | supply_register (regno, buf); | |
262 | } | |
263 | } | |
264 | } | |
265 | if (filename[0] == '/') | |
266 | corefile = savestring (filename, strlen (filename)); | |
267 | else | |
268 | { | |
58ae87f6 | 269 | corefile = concat (current_directory, "/", filename, NULL); |
8aa13b87 JK |
270 | } |
271 | init_tdesc(); | |
272 | current_context = init_dcontext(); | |
273 | set_current_frame ( create_new_frame(get_frame_base (read_pc()), | |
274 | read_pc ())); | |
275 | select_frame (get_current_frame (), 0); | |
276 | validate_files (); | |
277 | } | |
278 | else if (from_tty) | |
279 | printf ("No core file now.\n"); | |
280 | } | |
281 | #endif | |
282 | \f | |
283 | /* blockend is the address of the end of the user structure */ | |
284 | m88k_register_u_addr (blockend, regnum) | |
285 | { | |
286 | struct USER u; | |
287 | int ustart = blockend - sizeof (struct USER); | |
288 | switch (regnum) | |
289 | { | |
290 | case 0: | |
291 | case 1: | |
292 | case 2: | |
293 | case 3: | |
294 | case 4: | |
295 | case 5: | |
296 | case 6: | |
297 | case 7: | |
298 | case 8: | |
299 | case 9: | |
300 | case 10: | |
301 | case 11: | |
302 | case 12: | |
303 | case 13: | |
304 | case 14: | |
305 | case 15: | |
306 | case 16: | |
307 | case 17: | |
308 | case 18: | |
309 | case 19: | |
310 | case 20: | |
311 | case 21: | |
312 | case 22: | |
313 | case 23: | |
314 | case 24: | |
315 | case 25: | |
316 | case 26: | |
317 | case 27: | |
318 | case 28: | |
319 | case 29: | |
320 | case 30: | |
321 | case 31: return (ustart + ((int) &u.pt_r0 - (int) &u) + sizeof(REGISTER_TYPE) * regnum); | |
322 | case PSR_REGNUM: return (ustart + ((int) &u.pt_psr - (int) &u)); | |
323 | case FPSR_REGNUM: return (ustart + ((int) &u.pt_fpsr - (int) &u)); | |
324 | case FPCR_REGNUM: return (ustart + ((int) &u.pt_fpcr - (int) &u)); | |
325 | case SXIP_REGNUM: return (ustart + SXIP_OFFSET); | |
326 | case SNIP_REGNUM: return (ustart + SNIP_OFFSET); | |
327 | case SFIP_REGNUM: return (ustart + SFIP_OFFSET); | |
328 | default: return (blockend + sizeof (REGISTER_TYPE) * regnum); | |
329 | } | |
330 | } |