1
1
/* Native support for the SGI Iris running IRIX version 5, for GDB.
3
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4
1998, 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc.
3
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
4
1999, 2000, 2001, 2002, 2004, 2006, 2007 Free Software Foundation, Inc.
6
6
Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
7
7
and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
21
21
GNU General Public License for more details.
23
23
You should have received a copy of the GNU General Public License
24
along with this program; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
Boston, MA 02110-1301, USA. */
24
along with this program. If not, see <http://www.gnu.org/licenses/>. */
29
27
#include "inferior.h"
40
38
#include "gregset.h"
41
39
#include "mips-tdep.h"
43
static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR);
45
/* Size of elements in jmpbuf */
47
#define JB_ELEMENT_SIZE 4
41
static void fetch_core_registers (struct regcache *, char *,
42
unsigned int, int, CORE_ADDR);
50
46
* See the comment in m68k-tdep.c regarding the utility of these functions.
57
supply_gregset (gregset_t *gregsetp)
53
supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
60
greg_t *regp = &(*gregsetp)[0];
56
const greg_t *regp = &(*gregsetp)[0];
61
57
int gregoff = sizeof (greg_t) - mips_isa_regsize (current_gdbarch);
62
58
static char zerobuf[32] = {0};
64
60
for (regi = 0; regi <= CTX_RA; regi++)
65
regcache_raw_supply (current_regcache, regi,
66
(char *) (regp + regi) + gregoff);
61
regcache_raw_supply (regcache, regi,
62
(const char *) (regp + regi) + gregoff);
68
regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->pc,
69
(char *) (regp + CTX_EPC) + gregoff);
70
regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->hi,
71
(char *) (regp + CTX_MDHI) + gregoff);
72
regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->lo,
73
(char *) (regp + CTX_MDLO) + gregoff);
74
regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->cause,
75
(char *) (regp + CTX_CAUSE) + gregoff);
64
regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->pc,
65
(const char *) (regp + CTX_EPC) + gregoff);
66
regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->hi,
67
(const char *) (regp + CTX_MDHI) + gregoff);
68
regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->lo,
69
(const char *) (regp + CTX_MDLO) + gregoff);
70
regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->cause,
71
(const char *) (regp + CTX_CAUSE) + gregoff);
77
73
/* Fill inaccessible registers with zero. */
78
regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->badvaddr, zerobuf);
74
regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->badvaddr, zerobuf);
82
fill_gregset (gregset_t *gregsetp, int regno)
78
fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
85
81
greg_t *regp = &(*gregsetp)[0];
82
gdb_byte buf[MAX_REGISTER_SIZE];
88
84
/* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
89
85
executable, we have to sign extend the registers to 64 bits before
92
88
for (regi = 0; regi <= CTX_RA; regi++)
93
89
if ((regno == -1) || (regno == regi))
95
regcache_raw_read_signed (current_regcache, regi, ®val);
96
*(regp + regi) = regval;
91
size = register_size (current_gdbarch, regi);
92
regcache_raw_collect (regcache, regi, buf);
93
*(regp + regi) = extract_signed_integer (buf, size);
99
if ((regno == -1) || (regno == PC_REGNUM))
96
if ((regno == -1) || (regno == gdbarch_pc_regnum (current_gdbarch)))
101
regcache_raw_read_signed
102
(current_regcache, mips_regnum (current_gdbarch)->pc, ®val);
103
*(regp + CTX_EPC) = regval;
98
regi = mips_regnum (current_gdbarch)->pc;
99
size = register_size (current_gdbarch, regi);
100
regcache_raw_collect (regcache, regi, buf);
101
*(regp + CTX_EPC) = extract_signed_integer (buf, size);
106
104
if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause))
108
regcache_raw_read_signed
109
(current_regcache, mips_regnum (current_gdbarch)->cause, ®val);
110
*(regp + CTX_CAUSE) = regval;
106
regi = mips_regnum (current_gdbarch)->cause;
107
size = register_size (current_gdbarch, regi);
108
regcache_raw_collect (regcache, regi, buf);
109
*(regp + CTX_CAUSE) = extract_signed_integer (buf, size);
114
|| (regno == mips_regnum (current_gdbarch)->hi))
112
if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->hi))
116
regcache_raw_read_signed
117
(current_regcache, mips_regnum (current_gdbarch)->hi, ®val);
118
*(regp + CTX_MDHI) = regval;
114
regi = mips_regnum (current_gdbarch)->hi;
115
size = register_size (current_gdbarch, regi);
116
regcache_raw_collect (regcache, regi, buf);
117
*(regp + CTX_MDHI) = extract_signed_integer (buf, size);
121
120
if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo))
123
regcache_raw_read_signed
124
(current_regcache, mips_regnum (current_gdbarch)->lo, ®val);
125
*(regp + CTX_MDLO) = regval;
122
regi = mips_regnum (current_gdbarch)->lo;
123
size = register_size (current_gdbarch, regi);
124
regcache_raw_collect (regcache, regi, buf);
125
*(regp + CTX_MDLO) = extract_signed_integer (buf, size);
130
130
* Now we do the same thing for floating-point registers.
131
* We don't bother to condition on FP0_REGNUM since any
131
* We don't bother to condition on gdbarch_fp0_regnum since any
132
132
* reasonable MIPS configuration has an R3010 in it.
134
134
* Again, see the comments in m68k-tdep.c.
138
supply_fpregset (fpregset_t *fpregsetp)
138
supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
141
141
static char zerobuf[32] = {0};
144
144
/* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
146
146
for (regi = 0; regi < 32; regi++)
147
regcache_raw_supply (current_regcache, FP0_REGNUM + regi,
148
(char *) &fpregsetp->fp_r.fp_regs[regi]);
147
regcache_raw_supply (regcache, gdbarch_fp0_regnum (current_gdbarch) + regi,
148
(const char *) &fpregsetp->fp_r.fp_regs[regi]);
150
150
/* We can't supply the FSR register directly to the regcache,
151
151
because there is a size issue: On one hand, fpregsetp->fp_csr
155
155
memset (fsrbuf, 0, 4);
156
156
memcpy (fsrbuf + 4, &fpregsetp->fp_csr, 4);
158
regcache_raw_supply (current_regcache,
158
regcache_raw_supply (regcache,
159
159
mips_regnum (current_gdbarch)->fp_control_status,
162
162
/* FIXME: how can we supply FCRIR? SGI doesn't tell us. */
163
regcache_raw_supply (current_regcache,
163
regcache_raw_supply (regcache,
164
164
mips_regnum (current_gdbarch)->fp_implementation_revision,
169
fill_fpregset (fpregset_t *fpregsetp, int regno)
169
fill_fpregset (const struct regcache *regcache, fpregset_t *fpregsetp, int regno)
174
174
/* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
176
for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
176
for (regi = gdbarch_fp0_regnum (current_gdbarch);
177
regi < gdbarch_fp0_regnum (current_gdbarch) + 32; regi++)
178
179
if ((regno == -1) || (regno == regi))
180
to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
181
regcache_raw_read (current_regcache, regi, to);
181
to = (char *) &(fpregsetp->fp_r.fp_regs[regi - gdbarch_fp0_regnum
183
regcache_raw_collect (regcache, regi, to);
192
194
is 32bits long, while the regcache expects a 64bits long buffer.
193
195
So we use a buffer of the correct size and copy the register
194
196
value from that buffer. */
195
regcache_raw_read (current_regcache,
196
mips_regnum (current_gdbarch)->fp_control_status,
197
regcache_raw_collect (regcache,
198
mips_regnum (current_gdbarch)->fp_control_status,
199
201
memcpy (&fpregsetp->fp_csr, fsrbuf + 4, 4);
204
/* Figure out where the longjmp will land.
205
We expect the first arg to be a pointer to the jmp_buf structure from which
206
we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
207
This routine returns true on success. */
210
get_longjmp_target (CORE_ADDR *pc)
215
buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
216
jb_addr = read_register (MIPS_A0_REGNUM);
218
if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
219
TARGET_PTR_BIT / TARGET_CHAR_BIT))
222
*pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
227
206
/* Provide registers to GDB from a core file.
229
208
CORE_REG_SECT points to an array of bytes, which were obtained from
238
217
REG_ADDR is also unused. */
241
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
220
fetch_core_registers (struct regcache *regcache,
221
char *core_reg_sect, unsigned core_reg_size,
242
222
int which, CORE_ADDR reg_addr)
244
224
char *srcp = core_reg_sect;
248
228
/* If regsize is 8, this is a N32 or N64 core file.
249
229
If regsize is 4, this is an O32 core file. */
250
if (core_reg_size != regsize * NUM_REGS)
230
if (core_reg_size != regsize * gdbarch_num_regs (current_gdbarch))
252
232
warning (_("wrong size gregset struct in core file"));
256
for (regno = 0; regno < NUM_REGS; regno++)
236
for (regno = 0; regno < gdbarch_num_regs (current_gdbarch); regno++)
258
regcache_raw_write (current_regcache, regno, srcp);
238
regcache_raw_supply (regcache, regno, srcp);