1 |
24 |
jeremybenn |
/* Native support for the SGI Iris running IRIX version 5, for GDB.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
|
4 |
|
|
1999, 2000, 2001, 2002, 2004, 2006, 2007, 2008
|
5 |
|
|
Free Software Foundation, Inc.
|
6 |
|
|
|
7 |
|
|
Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
|
8 |
|
|
and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
|
9 |
|
|
Implemented for Irix 4.x by Garrett A. Wollman.
|
10 |
|
|
Modified for Irix 5.x by Ian Lance Taylor.
|
11 |
|
|
|
12 |
|
|
This file is part of GDB.
|
13 |
|
|
|
14 |
|
|
This program is free software; you can redistribute it and/or modify
|
15 |
|
|
it under the terms of the GNU General Public License as published by
|
16 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
17 |
|
|
(at your option) any later version.
|
18 |
|
|
|
19 |
|
|
This program is distributed in the hope that it will be useful,
|
20 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
|
|
GNU General Public License for more details.
|
23 |
|
|
|
24 |
|
|
You should have received a copy of the GNU General Public License
|
25 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
26 |
|
|
|
27 |
|
|
#include "defs.h"
|
28 |
|
|
#include "inferior.h"
|
29 |
|
|
#include "gdbcore.h"
|
30 |
|
|
#include "target.h"
|
31 |
|
|
#include "regcache.h"
|
32 |
|
|
|
33 |
|
|
#include "gdb_string.h"
|
34 |
|
|
#include <sys/time.h>
|
35 |
|
|
#include <sys/procfs.h>
|
36 |
|
|
#include <setjmp.h> /* For JB_XXX. */
|
37 |
|
|
|
38 |
|
|
/* Prototypes for supply_gregset etc. */
|
39 |
|
|
#include "gregset.h"
|
40 |
|
|
#include "mips-tdep.h"
|
41 |
|
|
|
42 |
|
|
static void fetch_core_registers (struct regcache *, char *,
|
43 |
|
|
unsigned int, int, CORE_ADDR);
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
/*
|
47 |
|
|
* See the comment in m68k-tdep.c regarding the utility of these functions.
|
48 |
|
|
*
|
49 |
|
|
* These definitions are from the MIPS SVR4 ABI, so they may work for
|
50 |
|
|
* any MIPS SVR4 target.
|
51 |
|
|
*/
|
52 |
|
|
|
53 |
|
|
void
|
54 |
|
|
supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
|
55 |
|
|
{
|
56 |
|
|
int regi;
|
57 |
|
|
const greg_t *regp = &(*gregsetp)[0];
|
58 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
59 |
|
|
int gregoff = sizeof (greg_t) - mips_isa_regsize (gdbarch);
|
60 |
|
|
static char zerobuf[32] = {0};
|
61 |
|
|
|
62 |
|
|
for (regi = 0; regi <= CTX_RA; regi++)
|
63 |
|
|
regcache_raw_supply (regcache, regi,
|
64 |
|
|
(const char *) (regp + regi) + gregoff);
|
65 |
|
|
|
66 |
|
|
regcache_raw_supply (regcache, mips_regnum (gdbarch)->pc,
|
67 |
|
|
(const char *) (regp + CTX_EPC) + gregoff);
|
68 |
|
|
regcache_raw_supply (regcache, mips_regnum (gdbarch)->hi,
|
69 |
|
|
(const char *) (regp + CTX_MDHI) + gregoff);
|
70 |
|
|
regcache_raw_supply (regcache, mips_regnum (gdbarch)->lo,
|
71 |
|
|
(const char *) (regp + CTX_MDLO) + gregoff);
|
72 |
|
|
regcache_raw_supply (regcache, mips_regnum (gdbarch)->cause,
|
73 |
|
|
(const char *) (regp + CTX_CAUSE) + gregoff);
|
74 |
|
|
|
75 |
|
|
/* Fill inaccessible registers with zero. */
|
76 |
|
|
regcache_raw_supply (regcache, mips_regnum (gdbarch)->badvaddr, zerobuf);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
void
|
80 |
|
|
fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
|
81 |
|
|
{
|
82 |
|
|
int regi, size;
|
83 |
|
|
greg_t *regp = &(*gregsetp)[0];
|
84 |
|
|
gdb_byte buf[MAX_REGISTER_SIZE];
|
85 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
86 |
|
|
|
87 |
|
|
/* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
|
88 |
|
|
executable, we have to sign extend the registers to 64 bits before
|
89 |
|
|
filling in the gregset structure. */
|
90 |
|
|
|
91 |
|
|
for (regi = 0; regi <= CTX_RA; regi++)
|
92 |
|
|
if ((regno == -1) || (regno == regi))
|
93 |
|
|
{
|
94 |
|
|
size = register_size (gdbarch, regi);
|
95 |
|
|
regcache_raw_collect (regcache, regi, buf);
|
96 |
|
|
*(regp + regi) = extract_signed_integer (buf, size);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
if ((regno == -1) || (regno == gdbarch_pc_regnum (gdbarch)))
|
100 |
|
|
{
|
101 |
|
|
regi = mips_regnum (gdbarch)->pc;
|
102 |
|
|
size = register_size (gdbarch, regi);
|
103 |
|
|
regcache_raw_collect (regcache, regi, buf);
|
104 |
|
|
*(regp + CTX_EPC) = extract_signed_integer (buf, size);
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
if ((regno == -1) || (regno == mips_regnum (gdbarch)->cause))
|
108 |
|
|
{
|
109 |
|
|
regi = mips_regnum (gdbarch)->cause;
|
110 |
|
|
size = register_size (gdbarch, regi);
|
111 |
|
|
regcache_raw_collect (regcache, regi, buf);
|
112 |
|
|
*(regp + CTX_CAUSE) = extract_signed_integer (buf, size);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
if ((regno == -1) || (regno == mips_regnum (gdbarch)->hi))
|
116 |
|
|
{
|
117 |
|
|
regi = mips_regnum (gdbarch)->hi;
|
118 |
|
|
size = register_size (gdbarch, regi);
|
119 |
|
|
regcache_raw_collect (regcache, regi, buf);
|
120 |
|
|
*(regp + CTX_MDHI) = extract_signed_integer (buf, size);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
if ((regno == -1) || (regno == mips_regnum (gdbarch)->lo))
|
124 |
|
|
{
|
125 |
|
|
regi = mips_regnum (gdbarch)->lo;
|
126 |
|
|
size = register_size (gdbarch, regi);
|
127 |
|
|
regcache_raw_collect (regcache, regi, buf);
|
128 |
|
|
*(regp + CTX_MDLO) = extract_signed_integer (buf, size);
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/*
|
133 |
|
|
* Now we do the same thing for floating-point registers.
|
134 |
|
|
* We don't bother to condition on gdbarch_fp0_regnum since any
|
135 |
|
|
* reasonable MIPS configuration has an R3010 in it.
|
136 |
|
|
*
|
137 |
|
|
* Again, see the comments in m68k-tdep.c.
|
138 |
|
|
*/
|
139 |
|
|
|
140 |
|
|
void
|
141 |
|
|
supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
|
142 |
|
|
{
|
143 |
|
|
int regi;
|
144 |
|
|
static char zerobuf[32] = {0};
|
145 |
|
|
char fsrbuf[8];
|
146 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
147 |
|
|
|
148 |
|
|
/* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
|
149 |
|
|
|
150 |
|
|
for (regi = 0; regi < 32; regi++)
|
151 |
|
|
regcache_raw_supply (regcache, gdbarch_fp0_regnum (gdbarch) + regi,
|
152 |
|
|
(const char *) &fpregsetp->fp_r.fp_regs[regi]);
|
153 |
|
|
|
154 |
|
|
/* We can't supply the FSR register directly to the regcache,
|
155 |
|
|
because there is a size issue: On one hand, fpregsetp->fp_csr
|
156 |
|
|
is 32bits long, while the regcache expects a 64bits long value.
|
157 |
|
|
So we use a buffer of the correct size and copy into it the register
|
158 |
|
|
value at the proper location. */
|
159 |
|
|
memset (fsrbuf, 0, 4);
|
160 |
|
|
memcpy (fsrbuf + 4, &fpregsetp->fp_csr, 4);
|
161 |
|
|
|
162 |
|
|
regcache_raw_supply (regcache,
|
163 |
|
|
mips_regnum (gdbarch)->fp_control_status, fsrbuf);
|
164 |
|
|
|
165 |
|
|
/* FIXME: how can we supply FCRIR? SGI doesn't tell us. */
|
166 |
|
|
regcache_raw_supply (regcache,
|
167 |
|
|
mips_regnum (gdbarch)->fp_implementation_revision,
|
168 |
|
|
zerobuf);
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
void
|
172 |
|
|
fill_fpregset (const struct regcache *regcache, fpregset_t *fpregsetp, int regno)
|
173 |
|
|
{
|
174 |
|
|
int regi;
|
175 |
|
|
char *from, *to;
|
176 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
177 |
|
|
|
178 |
|
|
/* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
|
179 |
|
|
|
180 |
|
|
for (regi = gdbarch_fp0_regnum (gdbarch);
|
181 |
|
|
regi < gdbarch_fp0_regnum (gdbarch) + 32; regi++)
|
182 |
|
|
{
|
183 |
|
|
if ((regno == -1) || (regno == regi))
|
184 |
|
|
{
|
185 |
|
|
to = (char *) &(fpregsetp->fp_r.fp_regs[regi - gdbarch_fp0_regnum
|
186 |
|
|
(gdbarch)]);
|
187 |
|
|
regcache_raw_collect (regcache, regi, to);
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
if (regno == -1
|
192 |
|
|
|| regno == mips_regnum (gdbarch)->fp_control_status)
|
193 |
|
|
{
|
194 |
|
|
char fsrbuf[8];
|
195 |
|
|
|
196 |
|
|
/* We can't fill the FSR register directly from the regcache,
|
197 |
|
|
because there is a size issue: On one hand, fpregsetp->fp_csr
|
198 |
|
|
is 32bits long, while the regcache expects a 64bits long buffer.
|
199 |
|
|
So we use a buffer of the correct size and copy the register
|
200 |
|
|
value from that buffer. */
|
201 |
|
|
regcache_raw_collect (regcache,
|
202 |
|
|
mips_regnum (gdbarch)->fp_control_status, fsrbuf);
|
203 |
|
|
|
204 |
|
|
memcpy (&fpregsetp->fp_csr, fsrbuf + 4, 4);
|
205 |
|
|
}
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
/* Provide registers to GDB from a core file.
|
210 |
|
|
|
211 |
|
|
CORE_REG_SECT points to an array of bytes, which were obtained from
|
212 |
|
|
a core file which BFD thinks might contain register contents.
|
213 |
|
|
CORE_REG_SIZE is its size.
|
214 |
|
|
|
215 |
|
|
Normally, WHICH says which register set corelow suspects this is:
|
216 |
|
|
|
217 |
|
|
2 --- the floating-point register set
|
218 |
|
|
However, for Irix 5, WHICH isn't used.
|
219 |
|
|
|
220 |
|
|
REG_ADDR is also unused. */
|
221 |
|
|
|
222 |
|
|
static void
|
223 |
|
|
fetch_core_registers (struct regcache *regcache,
|
224 |
|
|
char *core_reg_sect, unsigned core_reg_size,
|
225 |
|
|
int which, CORE_ADDR reg_addr)
|
226 |
|
|
{
|
227 |
|
|
char *srcp = core_reg_sect;
|
228 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
229 |
|
|
int regsize = mips_isa_regsize (gdbarch);
|
230 |
|
|
int regno;
|
231 |
|
|
|
232 |
|
|
/* If regsize is 8, this is a N32 or N64 core file.
|
233 |
|
|
If regsize is 4, this is an O32 core file. */
|
234 |
|
|
if (core_reg_size != regsize * gdbarch_num_regs (gdbarch))
|
235 |
|
|
{
|
236 |
|
|
warning (_("wrong size gregset struct in core file"));
|
237 |
|
|
return;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
|
241 |
|
|
{
|
242 |
|
|
regcache_raw_supply (regcache, regno, srcp);
|
243 |
|
|
srcp += regsize;
|
244 |
|
|
}
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
/* Register that we are able to handle irix5 core file formats.
|
248 |
|
|
This really is bfd_target_unknown_flavour */
|
249 |
|
|
|
250 |
|
|
static struct core_fns irix5_core_fns =
|
251 |
|
|
{
|
252 |
|
|
bfd_target_unknown_flavour, /* core_flavour */
|
253 |
|
|
default_check_format, /* check_format */
|
254 |
|
|
default_core_sniffer, /* core_sniffer */
|
255 |
|
|
fetch_core_registers, /* core_read_registers */
|
256 |
|
|
NULL /* next */
|
257 |
|
|
};
|
258 |
|
|
|
259 |
|
|
void
|
260 |
|
|
_initialize_core_irix5 (void)
|
261 |
|
|
{
|
262 |
|
|
deprecated_add_core_fns (&irix5_core_fns);
|
263 |
|
|
}
|