* dummy-frame.c (deprecated_pc_in_call_dummy): Add GDBARCH parameter,
[deliverable/binutils-gdb.git] / gdb / irix5-nat.c
... / ...
CommitLineData
1/* 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, 2009
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#include "procfs.h"
33
34#include "gdb_string.h"
35#include <sys/time.h>
36#include <sys/procfs.h>
37#include <setjmp.h> /* For JB_XXX. */
38
39/* Prototypes for supply_gregset etc. */
40#include "gregset.h"
41#include "mips-tdep.h"
42
43static void fetch_core_registers (struct regcache *, char *,
44 unsigned int, int, CORE_ADDR);
45
46
47/*
48 * See the comment in m68k-tdep.c regarding the utility of these functions.
49 *
50 * These definitions are from the MIPS SVR4 ABI, so they may work for
51 * any MIPS SVR4 target.
52 */
53
54void
55supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
56{
57 int regi;
58 const greg_t *regp = &(*gregsetp)[0];
59 struct gdbarch *gdbarch = get_regcache_arch (regcache);
60 int gregoff = sizeof (greg_t) - mips_isa_regsize (gdbarch);
61 static char zerobuf[32] = {0};
62
63 for (regi = 0; regi <= CTX_RA; regi++)
64 regcache_raw_supply (regcache, regi,
65 (const char *) (regp + regi) + gregoff);
66
67 regcache_raw_supply (regcache, mips_regnum (gdbarch)->pc,
68 (const char *) (regp + CTX_EPC) + gregoff);
69 regcache_raw_supply (regcache, mips_regnum (gdbarch)->hi,
70 (const char *) (regp + CTX_MDHI) + gregoff);
71 regcache_raw_supply (regcache, mips_regnum (gdbarch)->lo,
72 (const char *) (regp + CTX_MDLO) + gregoff);
73 regcache_raw_supply (regcache, mips_regnum (gdbarch)->cause,
74 (const char *) (regp + CTX_CAUSE) + gregoff);
75
76 /* Fill inaccessible registers with zero. */
77 regcache_raw_supply (regcache, mips_regnum (gdbarch)->badvaddr, zerobuf);
78}
79
80void
81fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
82{
83 int regi, size;
84 greg_t *regp = &(*gregsetp)[0];
85 gdb_byte buf[MAX_REGISTER_SIZE];
86 struct gdbarch *gdbarch = get_regcache_arch (regcache);
87
88 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
89 executable, we have to sign extend the registers to 64 bits before
90 filling in the gregset structure. */
91
92 for (regi = 0; regi <= CTX_RA; regi++)
93 if ((regno == -1) || (regno == regi))
94 {
95 size = register_size (gdbarch, regi);
96 regcache_raw_collect (regcache, regi, buf);
97 *(regp + regi) = extract_signed_integer (buf, size);
98 }
99
100 if ((regno == -1) || (regno == gdbarch_pc_regnum (gdbarch)))
101 {
102 regi = mips_regnum (gdbarch)->pc;
103 size = register_size (gdbarch, regi);
104 regcache_raw_collect (regcache, regi, buf);
105 *(regp + CTX_EPC) = extract_signed_integer (buf, size);
106 }
107
108 if ((regno == -1) || (regno == mips_regnum (gdbarch)->cause))
109 {
110 regi = mips_regnum (gdbarch)->cause;
111 size = register_size (gdbarch, regi);
112 regcache_raw_collect (regcache, regi, buf);
113 *(regp + CTX_CAUSE) = extract_signed_integer (buf, size);
114 }
115
116 if ((regno == -1) || (regno == mips_regnum (gdbarch)->hi))
117 {
118 regi = mips_regnum (gdbarch)->hi;
119 size = register_size (gdbarch, regi);
120 regcache_raw_collect (regcache, regi, buf);
121 *(regp + CTX_MDHI) = extract_signed_integer (buf, size);
122 }
123
124 if ((regno == -1) || (regno == mips_regnum (gdbarch)->lo))
125 {
126 regi = mips_regnum (gdbarch)->lo;
127 size = register_size (gdbarch, regi);
128 regcache_raw_collect (regcache, regi, buf);
129 *(regp + CTX_MDLO) = extract_signed_integer (buf, size);
130 }
131}
132
133/*
134 * Now we do the same thing for floating-point registers.
135 * We don't bother to condition on gdbarch_fp0_regnum since any
136 * reasonable MIPS configuration has an R3010 in it.
137 *
138 * Again, see the comments in m68k-tdep.c.
139 */
140
141void
142supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
143{
144 int regi;
145 static char zerobuf[32] = {0};
146 char fsrbuf[8];
147 struct gdbarch *gdbarch = get_regcache_arch (regcache);
148
149 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
150
151 for (regi = 0; regi < 32; regi++)
152 regcache_raw_supply (regcache, gdbarch_fp0_regnum (gdbarch) + regi,
153 (const char *) &fpregsetp->fp_r.fp_regs[regi]);
154
155 /* We can't supply the FSR register directly to the regcache,
156 because there is a size issue: On one hand, fpregsetp->fp_csr
157 is 32bits long, while the regcache expects a 64bits long value.
158 So we use a buffer of the correct size and copy into it the register
159 value at the proper location. */
160 memset (fsrbuf, 0, 4);
161 memcpy (fsrbuf + 4, &fpregsetp->fp_csr, 4);
162
163 regcache_raw_supply (regcache,
164 mips_regnum (gdbarch)->fp_control_status, fsrbuf);
165
166 /* FIXME: how can we supply FCRIR? SGI doesn't tell us. */
167 regcache_raw_supply (regcache,
168 mips_regnum (gdbarch)->fp_implementation_revision,
169 zerobuf);
170}
171
172void
173fill_fpregset (const struct regcache *regcache, fpregset_t *fpregsetp, int regno)
174{
175 int regi;
176 char *from, *to;
177 struct gdbarch *gdbarch = get_regcache_arch (regcache);
178
179 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
180
181 for (regi = gdbarch_fp0_regnum (gdbarch);
182 regi < gdbarch_fp0_regnum (gdbarch) + 32; regi++)
183 {
184 if ((regno == -1) || (regno == regi))
185 {
186 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - gdbarch_fp0_regnum
187 (gdbarch)]);
188 regcache_raw_collect (regcache, regi, to);
189 }
190 }
191
192 if (regno == -1
193 || regno == mips_regnum (gdbarch)->fp_control_status)
194 {
195 char fsrbuf[8];
196
197 /* We can't fill the FSR register directly from the regcache,
198 because there is a size issue: On one hand, fpregsetp->fp_csr
199 is 32bits long, while the regcache expects a 64bits long buffer.
200 So we use a buffer of the correct size and copy the register
201 value from that buffer. */
202 regcache_raw_collect (regcache,
203 mips_regnum (gdbarch)->fp_control_status, fsrbuf);
204
205 memcpy (&fpregsetp->fp_csr, fsrbuf + 4, 4);
206 }
207}
208
209
210/* Provide registers to GDB from a core file.
211
212 CORE_REG_SECT points to an array of bytes, which were obtained from
213 a core file which BFD thinks might contain register contents.
214 CORE_REG_SIZE is its size.
215
216 Normally, WHICH says which register set corelow suspects this is:
217 0 --- the general-purpose register set
218 2 --- the floating-point register set
219 However, for Irix 5, WHICH isn't used.
220
221 REG_ADDR is also unused. */
222
223static void
224fetch_core_registers (struct regcache *regcache,
225 char *core_reg_sect, unsigned core_reg_size,
226 int which, CORE_ADDR reg_addr)
227{
228 char *srcp = core_reg_sect;
229 struct gdbarch *gdbarch = get_regcache_arch (regcache);
230 int regsize = mips_isa_regsize (gdbarch);
231 int regno;
232
233 /* If regsize is 8, this is a N32 or N64 core file.
234 If regsize is 4, this is an O32 core file. */
235 if (core_reg_size != regsize * gdbarch_num_regs (gdbarch))
236 {
237 warning (_("wrong size gregset struct in core file"));
238 return;
239 }
240
241 for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
242 {
243 regcache_raw_supply (regcache, regno, srcp);
244 srcp += regsize;
245 }
246}
247
248/* Register that we are able to handle irix5 core file formats.
249 This really is bfd_target_unknown_flavour */
250
251static struct core_fns irix5_core_fns =
252{
253 bfd_target_unknown_flavour, /* core_flavour */
254 default_check_format, /* check_format */
255 default_core_sniffer, /* core_sniffer */
256 fetch_core_registers, /* core_read_registers */
257 NULL /* next */
258};
259
260/* Provide a prototype to silence -Wmissing-prototypes. */
261extern initialize_file_ftype _initialize_irix5_nat;
262
263void
264_initialize_irix5_nat (void)
265{
266 struct target_ops *t;
267
268 t = procfs_target ();
269 procfs_use_watchpoints (t);
270 add_target (t);
271
272 deprecated_add_core_fns (&irix5_core_fns);
273}
This page took 0.024802 seconds and 4 git commands to generate.