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