This is the third and final batch of makefile changes this round.
[deliverable/binutils-gdb.git] / gdb / m88k-xdep.c
CommitLineData
7d9884b9
JG
1/* Host-dependent Motorola 88xxx support for GDB, the GNU Debugger.
2 Copyright 1988, 1990, 1991 Free Software Foundation, Inc.
8aa13b87
JK
3
4This file is part of GDB.
5
99a7de40 6This program is free software; you can redistribute it and/or modify
8aa13b87 7it under the terms of the GNU General Public License as published by
99a7de40
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
8aa13b87 10
99a7de40 11This program is distributed in the hope that it will be useful,
8aa13b87
JK
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
99a7de40
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
8aa13b87 19
8aa13b87 20#include "defs.h"
8aa13b87
JK
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>
8aa13b87 33
12f2fd9f 34#ifndef USER /* added to support BCS ptrace_user */
8aa13b87
JK
35#define USER ptrace_user
36#endif
37#include <sys/ioctl.h>
38#include <fcntl.h>
8aa13b87
JK
39#include <sys/file.h>
40#include <sys/stat.h>
41
42#include "symtab.h"
43#include "setjmp.h"
44#include "value.h"
45
12f2fd9f
SC
46#ifdef DELTA88
47#include <sys/ptrace.h>
8aa13b87 48
12f2fd9f
SC
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
8aa13b87 57#define SFIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u
12f2fd9f
SC
58#endif
59
8aa13b87
JK
60extern int have_symbol_file_p();
61
62extern jmp_buf stack_jmp;
63
64extern int errno;
65extern char registers[REGISTER_BYTES];
66\f
67void
1ab3bf1b
JG
68fetch_inferior_registers (regno)
69 int regno; /* Original value discarded */
8aa13b87 70{
8aa13b87
JK
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, 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, regaddr, 0);
90 regaddr += sizeof (int);
91 }
92 supply_register (regno, buf);
93 }
94 /* now load up registers 36 - 38; special pc registers */
12f2fd9f 95 *(int *) &buf[0] = ptrace (3,inferior_pid,SXIP_OFFSET ,0);
8aa13b87 96 supply_register (SXIP_REGNUM, buf);
12f2fd9f 97 *(int *) &buf[0] = ptrace (3, inferior_pid,SNIP_OFFSET,0);
8aa13b87 98 supply_register (SNIP_REGNUM, buf);
12f2fd9f 99 *(int *) &buf[0] = ptrace (3, inferior_pid,SFIP_OFFSET,0);
8aa13b87
JK
100 supply_register (SFIP_REGNUM, buf);
101}
102
103/* Store our register values back into the inferior.
104 If REGNO is -1, do this for all registers.
105 Otherwise, REGNO specifies which register (so we can save time). */
106
1ab3bf1b 107void
8aa13b87
JK
108store_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
167void
168core_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 */
284m88k_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}
This page took 0.058629 seconds and 4 git commands to generate.