daily update
[deliverable/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
SS
55{
56 register int regi;
57 register greg_t *regp = &(*gregsetp)[0];
58 int gregoff = sizeof (greg_t) - MIPS_REGSIZE;
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
c5aa993b
JM
64 supply_register (PC_REGNUM, (char *) (regp + CTX_EPC) + gregoff);
65 supply_register (HI_REGNUM, (char *) (regp + CTX_MDHI) + gregoff);
66 supply_register (LO_REGNUM, (char *) (regp + CTX_MDLO) + gregoff);
67 supply_register (CAUSE_REGNUM, (char *) (regp + CTX_CAUSE) + gregoff);
c906108c
SS
68
69 /* Fill inaccessible registers with zero. */
70 supply_register (BADVADDR_REGNUM, zerobuf);
71}
72
73void
fba45db2 74fill_gregset (gregset_t *gregsetp, int regno)
c906108c
SS
75{
76 int regi;
77 register greg_t *regp = &(*gregsetp)[0];
78
79 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
80 executable, we have to sign extend the registers to 64 bits before
81 filling in the gregset structure. */
82
83 for (regi = 0; regi <= CTX_RA; regi++)
84 if ((regno == -1) || (regno == regi))
85 *(regp + regi) =
524d7c18 86 extract_signed_integer (&deprecated_registers[REGISTER_BYTE (regi)],
c906108c
SS
87 REGISTER_RAW_SIZE (regi));
88
89 if ((regno == -1) || (regno == PC_REGNUM))
90 *(regp + CTX_EPC) =
524d7c18 91 extract_signed_integer (&deprecated_registers[REGISTER_BYTE (PC_REGNUM)],
c906108c
SS
92 REGISTER_RAW_SIZE (PC_REGNUM));
93
94 if ((regno == -1) || (regno == CAUSE_REGNUM))
95 *(regp + CTX_CAUSE) =
524d7c18 96 extract_signed_integer (&deprecated_registers[REGISTER_BYTE (CAUSE_REGNUM)],
c906108c
SS
97 REGISTER_RAW_SIZE (CAUSE_REGNUM));
98
99 if ((regno == -1) || (regno == HI_REGNUM))
100 *(regp + CTX_MDHI) =
524d7c18 101 extract_signed_integer (&deprecated_registers[REGISTER_BYTE (HI_REGNUM)],
c906108c
SS
102 REGISTER_RAW_SIZE (HI_REGNUM));
103
104 if ((regno == -1) || (regno == LO_REGNUM))
105 *(regp + CTX_MDLO) =
524d7c18 106 extract_signed_integer (&deprecated_registers[REGISTER_BYTE (LO_REGNUM)],
c906108c
SS
107 REGISTER_RAW_SIZE (LO_REGNUM));
108}
109
110/*
111 * Now we do the same thing for floating-point registers.
112 * We don't bother to condition on FP0_REGNUM since any
113 * reasonable MIPS configuration has an R3010 in it.
114 *
115 * Again, see the comments in m68k-tdep.c.
116 */
117
118void
fba45db2 119supply_fpregset (fpregset_t *fpregsetp)
c906108c
SS
120{
121 register int regi;
466d7106 122 static char zerobuf[32] = {0};
c906108c
SS
123
124 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
125
126 for (regi = 0; regi < 32; regi++)
127 supply_register (FP0_REGNUM + regi,
c5aa993b 128 (char *) &fpregsetp->fp_r.fp_regs[regi]);
c906108c 129
c5aa993b 130 supply_register (FCRCS_REGNUM, (char *) &fpregsetp->fp_csr);
c906108c
SS
131
132 /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */
133 supply_register (FCRIR_REGNUM, zerobuf);
134}
135
136void
fba45db2 137fill_fpregset (fpregset_t *fpregsetp, int regno)
c906108c
SS
138{
139 int regi;
140 char *from, *to;
141
142 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
143
144 for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
145 {
146 if ((regno == -1) || (regno == regi))
147 {
524d7c18 148 from = (char *) &deprecated_registers[REGISTER_BYTE (regi)];
c906108c 149 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
c5aa993b 150 memcpy (to, from, REGISTER_RAW_SIZE (regi));
c906108c
SS
151 }
152 }
153
154 if ((regno == -1) || (regno == FCRCS_REGNUM))
524d7c18 155 fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[REGISTER_BYTE (FCRCS_REGNUM)];
c906108c
SS
156}
157
158
159/* Figure out where the longjmp will land.
160 We expect the first arg to be a pointer to the jmp_buf structure from which
161 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
162 This routine returns true on success. */
163
164int
fba45db2 165get_longjmp_target (CORE_ADDR *pc)
c906108c 166{
35fc8285 167 char *buf;
c906108c
SS
168 CORE_ADDR jb_addr;
169
35fc8285 170 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
171 jb_addr = read_register (A0_REGNUM);
172
173 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
174 TARGET_PTR_BIT / TARGET_CHAR_BIT))
175 return 0;
176
7c0b4a20 177 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
c906108c
SS
178
179 return 1;
180}
181
16bce26c
KB
182/* Provide registers to GDB from a core file.
183
184 CORE_REG_SECT points to an array of bytes, which were obtained from
185 a core file which BFD thinks might contain register contents.
186 CORE_REG_SIZE is its size.
187
188 Normally, WHICH says which register set corelow suspects this is:
189 0 --- the general-purpose register set
190 2 --- the floating-point register set
191 However, for Irix 5, WHICH isn't used.
192
193 REG_ADDR is also unused. */
194
c906108c 195static void
16bce26c
KB
196fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
197 int which, CORE_ADDR reg_addr)
c906108c 198{
b8b527c5 199 if (core_reg_size == DEPRECATED_REGISTER_BYTES)
c906108c 200 {
524d7c18 201 memcpy ((char *) deprecated_registers, core_reg_sect, core_reg_size);
c906108c
SS
202 }
203 else if (MIPS_REGSIZE == 4 &&
204 core_reg_size == (2 * MIPS_REGSIZE) * NUM_REGS)
205 {
206 /* This is a core file from a N32 executable, 64 bits are saved
c5aa993b 207 for all registers. */
c906108c 208 char *srcp = core_reg_sect;
524d7c18 209 char *dstp = deprecated_registers;
c906108c
SS
210 int regno;
211
212 for (regno = 0; regno < NUM_REGS; regno++)
213 {
214 if (regno >= FP0_REGNUM && regno < (FP0_REGNUM + 32))
215 {
216 /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
c5aa993b 217 currently assumes that they are 32 bit. */
c906108c
SS
218 *dstp++ = *srcp++;
219 *dstp++ = *srcp++;
220 *dstp++ = *srcp++;
221 *dstp++ = *srcp++;
c5aa993b 222 if (REGISTER_RAW_SIZE (regno) == 4)
c906108c
SS
223 {
224 /* copying 4 bytes from eight bytes?
225 I don't see how this can be right... */
c5aa993b 226 srcp += 4;
c906108c
SS
227 }
228 else
229 {
230 /* copy all 8 bytes (sizeof(double)) */
231 *dstp++ = *srcp++;
232 *dstp++ = *srcp++;
233 *dstp++ = *srcp++;
234 *dstp++ = *srcp++;
235 }
236 }
237 else
238 {
239 srcp += 4;
240 *dstp++ = *srcp++;
241 *dstp++ = *srcp++;
242 *dstp++ = *srcp++;
243 *dstp++ = *srcp++;
244 }
245 }
246 }
247 else
248 {
249 warning ("wrong size gregset struct in core file");
250 return;
251 }
252
2b9e5f3f 253 deprecated_registers_fetched ();
c906108c 254}
c5aa993b 255
c906108c
SS
256/* Register that we are able to handle irix5 core file formats.
257 This really is bfd_target_unknown_flavour */
258
259static struct core_fns irix5_core_fns =
260{
2acceee2
JM
261 bfd_target_unknown_flavour, /* core_flavour */
262 default_check_format, /* check_format */
263 default_core_sniffer, /* core_sniffer */
264 fetch_core_registers, /* core_read_registers */
265 NULL /* next */
c906108c
SS
266};
267
268void
fba45db2 269_initialize_core_irix5 (void)
c906108c
SS
270{
271 add_core_fns (&irix5_core_fns);
272}
This page took 0.331158 seconds and 4 git commands to generate.