1 |
578 |
markom |
/* Native-dependent Motorola 88xxx support for GDB, the GNU Debugger.
|
2 |
|
|
Copyright 1988, 1990, 1991, 1992, 1993, 1995, 1999, 2000, 2001
|
3 |
|
|
Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
This file is part of GDB.
|
6 |
|
|
|
7 |
|
|
This program is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
10 |
|
|
(at your option) any later version.
|
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful,
|
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
GNU General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with this program; if not, write to the Free Software
|
19 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
20 |
|
|
Boston, MA 02111-1307, USA. */
|
21 |
|
|
|
22 |
|
|
#include "defs.h"
|
23 |
|
|
#include "frame.h"
|
24 |
|
|
#include "inferior.h"
|
25 |
|
|
#include "regcache.h"
|
26 |
|
|
|
27 |
|
|
#include <sys/types.h>
|
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 "gdb_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 |
|
|
|
66 |
|
|
void
|
67 |
|
|
fetch_inferior_registers (int regno)
|
68 |
|
|
{
|
69 |
|
|
register unsigned int regaddr;
|
70 |
|
|
char buf[MAX_REGISTER_RAW_SIZE];
|
71 |
|
|
register int i;
|
72 |
|
|
|
73 |
|
|
struct USER u;
|
74 |
|
|
unsigned int offset;
|
75 |
|
|
|
76 |
|
|
offset = (char *) &u.pt_r0 - (char *) &u;
|
77 |
|
|
regaddr = offset; /* byte offset to r0; */
|
78 |
|
|
|
79 |
|
|
/* offset = ptrace (3, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) offset, 0) - KERNEL_U_ADDR; */
|
80 |
|
|
for (regno = 0; regno < NUM_REGS; regno++)
|
81 |
|
|
{
|
82 |
|
|
/*regaddr = register_addr (regno, offset); */
|
83 |
|
|
/* 88k enhancement */
|
84 |
|
|
|
85 |
|
|
for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
|
86 |
|
|
{
|
87 |
|
|
*(int *) &buf[i] = ptrace (3, PIDGET (inferior_ptid),
|
88 |
|
|
(PTRACE_ARG3_TYPE) regaddr, 0);
|
89 |
|
|
regaddr += sizeof (int);
|
90 |
|
|
}
|
91 |
|
|
supply_register (regno, buf);
|
92 |
|
|
}
|
93 |
|
|
/* now load up registers 36 - 38; special pc registers */
|
94 |
|
|
*(int *) &buf[0] = ptrace (3, PIDGET (inferior_ptid),
|
95 |
|
|
(PTRACE_ARG3_TYPE) SXIP_OFFSET, 0);
|
96 |
|
|
supply_register (SXIP_REGNUM, buf);
|
97 |
|
|
*(int *) &buf[0] = ptrace (3, PIDGET (inferior_ptid),
|
98 |
|
|
(PTRACE_ARG3_TYPE) SNIP_OFFSET, 0);
|
99 |
|
|
supply_register (SNIP_REGNUM, buf);
|
100 |
|
|
*(int *) &buf[0] = ptrace (3, PIDGET (inferior_ptid),
|
101 |
|
|
(PTRACE_ARG3_TYPE) SFIP_OFFSET, 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 |
|
|
void
|
110 |
|
|
store_inferior_registers (int regno)
|
111 |
|
|
{
|
112 |
|
|
register unsigned int regaddr;
|
113 |
|
|
char buf[80];
|
114 |
|
|
|
115 |
|
|
struct USER u;
|
116 |
|
|
|
117 |
|
|
unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
|
118 |
|
|
|
119 |
|
|
regaddr = offset;
|
120 |
|
|
|
121 |
|
|
/* Don't try to deal with EXIP_REGNUM or ENIP_REGNUM, because I think either
|
122 |
|
|
svr3 doesn't run on an 88110, or the kernel isolates the different (not
|
123 |
|
|
completely sure this is true, but seems to be. */
|
124 |
|
|
if (regno >= 0)
|
125 |
|
|
{
|
126 |
|
|
/* regaddr = register_addr (regno, offset); */
|
127 |
|
|
if (regno < PC_REGNUM)
|
128 |
|
|
{
|
129 |
|
|
regaddr = offset + regno * sizeof (int);
|
130 |
|
|
errno = 0;
|
131 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
132 |
|
|
(PTRACE_ARG3_TYPE) regaddr, read_register (regno));
|
133 |
|
|
if (errno != 0)
|
134 |
|
|
{
|
135 |
|
|
sprintf (buf, "writing register number %d", regno);
|
136 |
|
|
perror_with_name (buf);
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
else if (regno == SXIP_REGNUM)
|
140 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
141 |
|
|
(PTRACE_ARG3_TYPE) SXIP_OFFSET, read_register (regno));
|
142 |
|
|
else if (regno == SNIP_REGNUM)
|
143 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
144 |
|
|
(PTRACE_ARG3_TYPE) SNIP_OFFSET, read_register (regno));
|
145 |
|
|
else if (regno == SFIP_REGNUM)
|
146 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
147 |
|
|
(PTRACE_ARG3_TYPE) SFIP_OFFSET, read_register (regno));
|
148 |
|
|
else
|
149 |
|
|
printf_unfiltered ("Bad register number for store_inferior routine\n");
|
150 |
|
|
}
|
151 |
|
|
else
|
152 |
|
|
{
|
153 |
|
|
for (regno = 0; regno < PC_REGNUM; regno++)
|
154 |
|
|
{
|
155 |
|
|
/* regaddr = register_addr (regno, offset); */
|
156 |
|
|
errno = 0;
|
157 |
|
|
regaddr = offset + regno * sizeof (int);
|
158 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
159 |
|
|
(PTRACE_ARG3_TYPE) 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, PIDGET (inferior_ptid),
|
167 |
|
|
(PTRACE_ARG3_TYPE) SXIP_OFFSET, read_register (SXIP_REGNUM));
|
168 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
169 |
|
|
(PTRACE_ARG3_TYPE) SNIP_OFFSET, read_register (SNIP_REGNUM));
|
170 |
|
|
ptrace (6, PIDGET (inferior_ptid),
|
171 |
|
|
(PTRACE_ARG3_TYPE) SFIP_OFFSET, read_register (SFIP_REGNUM));
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
/* blockend is the address of the end of the user structure */
|
177 |
|
|
m88k_register_u_addr (int blockend, int regnum)
|
178 |
|
|
{
|
179 |
|
|
struct USER u;
|
180 |
|
|
int ustart = blockend - sizeof (struct USER);
|
181 |
|
|
switch (regnum)
|
182 |
|
|
{
|
183 |
|
|
case 0:
|
184 |
|
|
case 1:
|
185 |
|
|
case 2:
|
186 |
|
|
case 3:
|
187 |
|
|
case 4:
|
188 |
|
|
case 5:
|
189 |
|
|
case 6:
|
190 |
|
|
case 7:
|
191 |
|
|
case 8:
|
192 |
|
|
case 9:
|
193 |
|
|
case 10:
|
194 |
|
|
case 11:
|
195 |
|
|
case 12:
|
196 |
|
|
case 13:
|
197 |
|
|
case 14:
|
198 |
|
|
case 15:
|
199 |
|
|
case 16:
|
200 |
|
|
case 17:
|
201 |
|
|
case 18:
|
202 |
|
|
case 19:
|
203 |
|
|
case 20:
|
204 |
|
|
case 21:
|
205 |
|
|
case 22:
|
206 |
|
|
case 23:
|
207 |
|
|
case 24:
|
208 |
|
|
case 25:
|
209 |
|
|
case 26:
|
210 |
|
|
case 27:
|
211 |
|
|
case 28:
|
212 |
|
|
case 29:
|
213 |
|
|
case 30:
|
214 |
|
|
case 31:
|
215 |
|
|
return (ustart + ((int) &u.pt_r0 - (int) &u) + REGISTER_SIZE * regnum);
|
216 |
|
|
case PSR_REGNUM:
|
217 |
|
|
return (ustart + ((int) &u.pt_psr - (int) &u));
|
218 |
|
|
case FPSR_REGNUM:
|
219 |
|
|
return (ustart + ((int) &u.pt_fpsr - (int) &u));
|
220 |
|
|
case FPCR_REGNUM:
|
221 |
|
|
return (ustart + ((int) &u.pt_fpcr - (int) &u));
|
222 |
|
|
case SXIP_REGNUM:
|
223 |
|
|
return (ustart + SXIP_OFFSET);
|
224 |
|
|
case SNIP_REGNUM:
|
225 |
|
|
return (ustart + SNIP_OFFSET);
|
226 |
|
|
case SFIP_REGNUM:
|
227 |
|
|
return (ustart + SFIP_OFFSET);
|
228 |
|
|
default:
|
229 |
|
|
if (regnum < NUM_REGS)
|
230 |
|
|
/* The register is one of those which is not defined...
|
231 |
|
|
give it zero */
|
232 |
|
|
return (ustart + ((int) &u.pt_r0 - (int) &u));
|
233 |
|
|
else
|
234 |
|
|
return (blockend + REGISTER_SIZE * regnum);
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
#ifdef USE_PROC_FS
|
239 |
|
|
|
240 |
|
|
#include <sys/procfs.h>
|
241 |
|
|
|
242 |
|
|
/* Prototypes for supply_gregset etc. */
|
243 |
|
|
#include "gregset.h"
|
244 |
|
|
|
245 |
|
|
/* Given a pointer to a general register set in /proc format (gregset_t *),
|
246 |
|
|
unpack the register contents and supply them as gdb's idea of the current
|
247 |
|
|
register values. */
|
248 |
|
|
|
249 |
|
|
void
|
250 |
|
|
supply_gregset (gregset_t *gregsetp)
|
251 |
|
|
{
|
252 |
|
|
register int regi;
|
253 |
|
|
register greg_t *regp = (greg_t *) gregsetp;
|
254 |
|
|
|
255 |
|
|
for (regi = 0; regi <= SP_REGNUM; regi++)
|
256 |
|
|
supply_register (regi, (char *) (regp + regi));
|
257 |
|
|
|
258 |
|
|
supply_register (SXIP_REGNUM, (char *) (regp + R_XIP));
|
259 |
|
|
supply_register (SNIP_REGNUM, (char *) (regp + R_NIP));
|
260 |
|
|
supply_register (SFIP_REGNUM, (char *) (regp + R_FIP));
|
261 |
|
|
supply_register (PSR_REGNUM, (char *) (regp + R_PSR));
|
262 |
|
|
supply_register (FPSR_REGNUM, (char *) (regp + R_FPSR));
|
263 |
|
|
supply_register (FPCR_REGNUM, (char *) (regp + R_FPCR));
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
void
|
267 |
|
|
fill_gregset (gregset_t *gregsetp, int regno)
|
268 |
|
|
{
|
269 |
|
|
int regi;
|
270 |
|
|
register greg_t *regp = (greg_t *) gregsetp;
|
271 |
|
|
|
272 |
|
|
for (regi = 0; regi <= R_R31; regi++)
|
273 |
|
|
if ((regno == -1) || (regno == regi))
|
274 |
|
|
*(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
|
275 |
|
|
|
276 |
|
|
if ((regno == -1) || (regno == SXIP_REGNUM))
|
277 |
|
|
*(regp + R_XIP) = *(int *) ®isters[REGISTER_BYTE (SXIP_REGNUM)];
|
278 |
|
|
if ((regno == -1) || (regno == SNIP_REGNUM))
|
279 |
|
|
*(regp + R_NIP) = *(int *) ®isters[REGISTER_BYTE (SNIP_REGNUM)];
|
280 |
|
|
if ((regno == -1) || (regno == SFIP_REGNUM))
|
281 |
|
|
*(regp + R_FIP) = *(int *) ®isters[REGISTER_BYTE (SFIP_REGNUM)];
|
282 |
|
|
if ((regno == -1) || (regno == PSR_REGNUM))
|
283 |
|
|
*(regp + R_PSR) = *(int *) ®isters[REGISTER_BYTE (PSR_REGNUM)];
|
284 |
|
|
if ((regno == -1) || (regno == FPSR_REGNUM))
|
285 |
|
|
*(regp + R_FPSR) = *(int *) ®isters[REGISTER_BYTE (FPSR_REGNUM)];
|
286 |
|
|
if ((regno == -1) || (regno == FPCR_REGNUM))
|
287 |
|
|
*(regp + R_FPCR) = *(int *) ®isters[REGISTER_BYTE (FPCR_REGNUM)];
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
#endif /* USE_PROC_FS */
|