* Check in Fred Fish's changes in these modules. Fred
[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
JK
19
20#include <stdio.h>
21#include "defs.h"
8aa13b87
JK
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
61extern int have_symbol_file_p();
62
63extern jmp_buf stack_jmp;
64
65extern int errno;
66extern char registers[REGISTER_BYTES];
67\f
68void
1ab3bf1b
JG
69fetch_inferior_registers (regno)
70 int regno; /* Original value discarded */
8aa13b87 71{
8aa13b87
JK
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
1ab3bf1b 108void
8aa13b87
JK
109store_inferior_registers (regno)
110 int regno;
111{
112 register unsigned int regaddr;
113 char buf[80];
114
115 struct USER u;
116
8aa13b87
JK
117
118 unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
119
8aa13b87
JK
120 regaddr = offset;
121
122 if (regno >= 0)
123 {
124/* regaddr = register_addr (regno, offset); */
125 if (regno < PC_REGNUM)
126 {
127 regaddr = offset + regno * sizeof (int);
128 errno = 0;
129 ptrace (6, inferior_pid, regaddr, read_register (regno));
130 if (errno != 0)
131 {
132 sprintf (buf, "writing register number %d", regno);
133 perror_with_name (buf);
134 }
135 }
136 else if (regno == SXIP_REGNUM)
137 ptrace (6, inferior_pid, SXIP_OFFSET, read_register(regno));
138 else if (regno == SNIP_REGNUM)
139 ptrace (6, inferior_pid, SNIP_OFFSET, read_register(regno));
140 else if (regno == SFIP_REGNUM)
141 ptrace (6, inferior_pid, SFIP_OFFSET, read_register(regno));
142 else printf ("Bad register number for store_inferior routine\n");
143 }
144 else {
145 for (regno = 0; regno < NUM_REGS - 3; regno++)
146 {
147 /* regaddr = register_addr (regno, offset); */
148 errno = 0;
149 regaddr = offset + regno * sizeof (int);
150 ptrace (6, inferior_pid, regaddr, read_register (regno));
151 if (errno != 0)
152 {
153 sprintf (buf, "writing register number %d", regno);
154 perror_with_name (buf);
155 }
156 }
157 ptrace (6,inferior_pid,SXIP_OFFSET,read_register(SXIP_REGNUM));
158 ptrace (6,inferior_pid,SNIP_OFFSET,read_register(SNIP_REGNUM));
159 ptrace (6,inferior_pid,SFIP_OFFSET,read_register(SFIP_REGNUM));
160 }
161
162
163}
164
165#if 0
166/* Core files are now a function of BFD. */
167\f
168void
169core_file_command (filename, from_tty)
170 char *filename;
171 int from_tty;
172{
173 int val;
174 extern char registers[];
175
176 /* Need symbol file and one with tdesc info for corefiles to work */
177 if (!have_symbol_file_p())
178 error ("Requires symbol-file and exec-file");
179 if (!execfile)
180 error ("Requires exec-file and symbol-file");
181
182 /* Discard all vestiges of any previous core file
183 and mark data and stack spaces as empty. */
184
185 if (corefile)
186 free (corefile);
187 corefile = 0;
188
189 if (corechan >= 0)
190 close (corechan);
191 corechan = -1;
192
193 data_start = 0;
194 data_end = 0;
195 stack_start = STACK_END_ADDR;
196 stack_end = STACK_END_ADDR;
197
198 /* Now, if a new core file was specified, open it and digest it. */
199
200 if (filename)
201 {
202 filename = tilde_expand (filename);
203 make_cleanup (free, filename);
204
205 if (have_inferior_p ())
206 error ("To look at a core file, you must kill the inferior with \"kill\".");
207 corechan = open (filename, O_RDONLY, 0);
208 if (corechan < 0)
209 perror_with_name (filename);
210 /* 4.2-style (and perhaps also sysV-style) core dump file. */
211 {
212 struct USER u;
213
214 int reg_offset;
215
216 val = myread (corechan, &u, sizeof u);
217 if (val < 0)
218 perror_with_name (filename);
219 data_start = u.pt_o_data_start;
220
221 data_end = data_start + u.pt_dsize;
222 stack_start = stack_end - u.pt_ssize;
223 data_offset = u.pt_dataptr;
224 stack_offset = data_offset + u.pt_dsize;
225
226#if defined(BCS)
227#if defined(DGUX)
228
229 reg_offset = 2048;
230
231
232#endif /* defined (DGUX) */
233#else
234
235 /* original code: */
236 reg_offset = (int) u.pt_r0 - KERNEL_U_ADDR;
237
238#endif /* defined(BCS) */
239
240 /* I don't know where to find this info.
241 So, for now, mark it as not available. */
242/* N_SET_MAGIC (core_aouthdr, 0); */
243 bzero ((char *) &core_aouthdr, sizeof core_aouthdr);
244
245 /* Read the register values out of the core file and store
246 them where `read_register' will find them. */
247
248 {
249 register int regno;
250
251 for (regno = 0; regno < NUM_REGS; regno++)
252 {
253 char buf[MAX_REGISTER_RAW_SIZE];
254
255 val = lseek (corechan, register_addr (regno, reg_offset), 0);
256 if (val < 0)
257 perror_with_name (filename);
258
259 val = myread (corechan, buf, sizeof buf);
260 if (val < 0)
261 perror_with_name (filename);
262 supply_register (regno, buf);
263 }
264 }
265 }
266 if (filename[0] == '/')
267 corefile = savestring (filename, strlen (filename));
268 else
269 {
58ae87f6 270 corefile = concat (current_directory, "/", filename, NULL);
8aa13b87
JK
271 }
272 init_tdesc();
273 current_context = init_dcontext();
274 set_current_frame ( create_new_frame(get_frame_base (read_pc()),
275 read_pc ()));
276 select_frame (get_current_frame (), 0);
277 validate_files ();
278 }
279 else if (from_tty)
280 printf ("No core file now.\n");
281}
282#endif
283\f
284/* blockend is the address of the end of the user structure */
285m88k_register_u_addr (blockend, regnum)
286{
287 struct USER u;
288 int ustart = blockend - sizeof (struct USER);
289 switch (regnum)
290 {
291 case 0:
292 case 1:
293 case 2:
294 case 3:
295 case 4:
296 case 5:
297 case 6:
298 case 7:
299 case 8:
300 case 9:
301 case 10:
302 case 11:
303 case 12:
304 case 13:
305 case 14:
306 case 15:
307 case 16:
308 case 17:
309 case 18:
310 case 19:
311 case 20:
312 case 21:
313 case 22:
314 case 23:
315 case 24:
316 case 25:
317 case 26:
318 case 27:
319 case 28:
320 case 29:
321 case 30:
322 case 31: return (ustart + ((int) &u.pt_r0 - (int) &u) + sizeof(REGISTER_TYPE) * regnum);
323 case PSR_REGNUM: return (ustart + ((int) &u.pt_psr - (int) &u));
324 case FPSR_REGNUM: return (ustart + ((int) &u.pt_fpsr - (int) &u));
325 case FPCR_REGNUM: return (ustart + ((int) &u.pt_fpcr - (int) &u));
326 case SXIP_REGNUM: return (ustart + SXIP_OFFSET);
327 case SNIP_REGNUM: return (ustart + SNIP_OFFSET);
328 case SFIP_REGNUM: return (ustart + SFIP_OFFSET);
329 default: return (blockend + sizeof (REGISTER_TYPE) * regnum);
330 }
331}
This page took 0.058048 seconds and 4 git commands to generate.