]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/irix5-nat.c
2003-11-16 Andrew Cagney <cagney@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / irix5-nat.c
CommitLineData
c906108c 1/* Native support for the SGI Iris running IRIX version 5, for GDB.
b6ba6518 2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
dabbe2c0 3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
5 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6 Implemented for Irix 4.x by Garrett A. Wollman.
7 Modified for Irix 5.x by Ian Lance Taylor.
8
c5aa993b 9 This file is part of GDB.
c906108c 10
c5aa993b
JM
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
c906108c 15
c5aa993b
JM
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
c906108c 20
c5aa993b
JM
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
c906108c
SS
25
26#include "defs.h"
27#include "inferior.h"
28#include "gdbcore.h"
29#include "target.h"
4e052eda 30#include "regcache.h"
c906108c
SS
31
32#include "gdb_string.h"
33#include <sys/time.h>
34#include <sys/procfs.h>
35#include <setjmp.h> /* For JB_XXX. */
36
c60c0f5f
MS
37/* Prototypes for supply_gregset etc. */
38#include "gregset.h"
39
a14ed312 40static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR);
c906108c
SS
41
42/* Size of elements in jmpbuf */
43
44#define JB_ELEMENT_SIZE 4
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
c5aa993b 53void
fba45db2 54supply_gregset (gregset_t *gregsetp)
c906108c 55{
52f0bd74
AC
56 int regi;
57 greg_t *regp = &(*gregsetp)[0];
4246e332 58 int gregoff = sizeof (greg_t) - mips_regsize (current_gdbarch);
466d7106 59 static char zerobuf[32] = {0};
c906108c 60
c5aa993b
JM
61 for (regi = 0; regi <= CTX_RA; regi++)
62 supply_register (regi, (char *) (regp + regi) + gregoff);
c906108c 63
56cea623
AC
64 supply_register (mips_regnum (current_gdbarch)->pc,
65 (char *) (regp + CTX_EPC) + gregoff);
66 supply_register (mips_regnum (current_gdbarch)->hi,
67 (char *) (regp + CTX_MDHI) + gregoff);
68 supply_register (mips_regnum (current_gdbarch)->lo,
69 (char *) (regp + CTX_MDLO) + gregoff);
70 supply_register (mips_regnum (current_gdbarch)->cause,
71 (char *) (regp + CTX_CAUSE) + gregoff);
c906108c
SS
72
73 /* Fill inaccessible registers with zero. */
56cea623 74 supply_register (mips_regnum (current_gdbarch)->badvaddr, zerobuf);
c906108c
SS
75}
76
77void
fba45db2 78fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
79{
80 int regi;
52f0bd74 81 greg_t *regp = &(*gregsetp)[0];
c906108c
SS
82
83 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
84 executable, we have to sign extend the registers to 64 bits before
85 filling in the gregset structure. */
86
87 for (regi = 0; regi <= CTX_RA; regi++)
88 if ((regno == -1) || (regno == regi))
89 *(regp + regi) =
62700349 90 extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)],
12c266ea 91 DEPRECATED_REGISTER_RAW_SIZE (regi));
c906108c
SS
92
93 if ((regno == -1) || (regno == PC_REGNUM))
94 *(regp + CTX_EPC) =
56cea623
AC
95 extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)],
96 DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->pc));
c906108c 97
56cea623 98 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause))
c906108c 99 *(regp + CTX_CAUSE) =
56cea623
AC
100 extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->cause)],
101 DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->cause));
c906108c 102
56cea623
AC
103 if ((regno == -1)
104 || (regno == mips_regnum (current_gdbarch)->hi))
c906108c 105 *(regp + CTX_MDHI) =
56cea623
AC
106 extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)],
107 DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->hi));
c906108c 108
56cea623 109 if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo))
c906108c 110 *(regp + CTX_MDLO) =
56cea623
AC
111 extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)],
112 DEPRECATED_REGISTER_RAW_SIZE (mips_regnum (current_gdbarch)->lo));
c906108c
SS
113}
114
115/*
116 * Now we do the same thing for floating-point registers.
117 * We don't bother to condition on FP0_REGNUM since any
118 * reasonable MIPS configuration has an R3010 in it.
119 *
120 * Again, see the comments in m68k-tdep.c.
121 */
122
123void
fba45db2 124supply_fpregset (fpregset_t *fpregsetp)
c906108c 125{
52f0bd74 126 int regi;
466d7106 127 static char zerobuf[32] = {0};
c906108c
SS
128
129 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
130
131 for (regi = 0; regi < 32; regi++)
132 supply_register (FP0_REGNUM + regi,
c5aa993b 133 (char *) &fpregsetp->fp_r.fp_regs[regi]);
c906108c 134
56cea623
AC
135 supply_register (mips_regnum (current_gdbarch)->fp_control_status,
136 (char *) &fpregsetp->fp_csr);
c906108c 137
56cea623
AC
138 /* FIXME: how can we supply FCRIR? SGI doesn't tell us. */
139 supply_register (mips_regnum (current_gdbarch)->fp_implementation_revision,
140 zerobuf);
c906108c
SS
141}
142
143void
fba45db2 144fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c
SS
145{
146 int regi;
147 char *from, *to;
148
149 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
150
151 for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
152 {
153 if ((regno == -1) || (regno == regi))
154 {
62700349 155 from = (char *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)];
c906108c 156 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
12c266ea 157 memcpy (to, from, DEPRECATED_REGISTER_RAW_SIZE (regi));
c906108c
SS
158 }
159 }
160
56cea623
AC
161 if ((regno == -1)
162 || (regno == mips_regnum (current_gdbarch)->fp_control_status))
163 fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)];
c906108c
SS
164}
165
166
167/* Figure out where the longjmp will land.
168 We expect the first arg to be a pointer to the jmp_buf structure from which
169 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
170 This routine returns true on success. */
171
172int
fba45db2 173get_longjmp_target (CORE_ADDR *pc)
c906108c 174{
35fc8285 175 char *buf;
c906108c
SS
176 CORE_ADDR jb_addr;
177
35fc8285 178 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
179 jb_addr = read_register (A0_REGNUM);
180
181 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
182 TARGET_PTR_BIT / TARGET_CHAR_BIT))
183 return 0;
184
7c0b4a20 185 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
186
187 return 1;
188}
189
16bce26c
KB
190/* Provide registers to GDB from a core file.
191
192 CORE_REG_SECT points to an array of bytes, which were obtained from
193 a core file which BFD thinks might contain register contents.
194 CORE_REG_SIZE is its size.
195
196 Normally, WHICH says which register set corelow suspects this is:
197 0 --- the general-purpose register set
198 2 --- the floating-point register set
199 However, for Irix 5, WHICH isn't used.
200
201 REG_ADDR is also unused. */
202
c906108c 203static void
16bce26c
KB
204fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
205 int which, CORE_ADDR reg_addr)
c906108c 206{
b8b527c5 207 if (core_reg_size == DEPRECATED_REGISTER_BYTES)
c906108c 208 {
524d7c18 209 memcpy ((char *) deprecated_registers, core_reg_sect, core_reg_size);
c906108c 210 }
4246e332
AC
211 else if (mips_regsize (current_gdbarch) == 4 &&
212 core_reg_size == (2 * mips_regsize (current_gdbarch)) * NUM_REGS)
c906108c
SS
213 {
214 /* This is a core file from a N32 executable, 64 bits are saved
c5aa993b 215 for all registers. */
c906108c 216 char *srcp = core_reg_sect;
524d7c18 217 char *dstp = deprecated_registers;
c906108c
SS
218 int regno;
219
220 for (regno = 0; regno < NUM_REGS; regno++)
221 {
222 if (regno >= FP0_REGNUM && regno < (FP0_REGNUM + 32))
223 {
224 /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
c5aa993b 225 currently assumes that they are 32 bit. */
c906108c
SS
226 *dstp++ = *srcp++;
227 *dstp++ = *srcp++;
228 *dstp++ = *srcp++;
229 *dstp++ = *srcp++;
12c266ea 230 if (DEPRECATED_REGISTER_RAW_SIZE (regno) == 4)
c906108c
SS
231 {
232 /* copying 4 bytes from eight bytes?
233 I don't see how this can be right... */
c5aa993b 234 srcp += 4;
c906108c
SS
235 }
236 else
237 {
238 /* copy all 8 bytes (sizeof(double)) */
239 *dstp++ = *srcp++;
240 *dstp++ = *srcp++;
241 *dstp++ = *srcp++;
242 *dstp++ = *srcp++;
243 }
244 }
245 else
246 {
247 srcp += 4;
248 *dstp++ = *srcp++;
249 *dstp++ = *srcp++;
250 *dstp++ = *srcp++;
251 *dstp++ = *srcp++;
252 }
253 }
254 }
255 else
256 {
257 warning ("wrong size gregset struct in core file");
258 return;
259 }
260
2b9e5f3f 261 deprecated_registers_fetched ();
c906108c 262}
c5aa993b 263
c906108c
SS
264/* Register that we are able to handle irix5 core file formats.
265 This really is bfd_target_unknown_flavour */
266
267static struct core_fns irix5_core_fns =
268{
2acceee2
JM
269 bfd_target_unknown_flavour, /* core_flavour */
270 default_check_format, /* check_format */
271 default_core_sniffer, /* core_sniffer */
272 fetch_core_registers, /* core_read_registers */
273 NULL /* next */
c906108c
SS
274};
275
276void
fba45db2 277_initialize_core_irix5 (void)
c906108c
SS
278{
279 add_core_fns (&irix5_core_fns);
280}