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