* irix5-nat.c (fill_gregset): Replace use of deprecated_registers
[external/binutils.git] / gdb / irix5-nat.c
1 /* Native support for the SGI Iris running IRIX version 5, for GDB.
2
3    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4    1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
5
6    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
7    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
8    Implemented for Irix 4.x by Garrett A. Wollman.
9    Modified for Irix 5.x by Ian Lance Taylor.
10
11    This file is part of GDB.
12
13    This program is free software; you can redistribute it and/or modify
14    it under the terms of the GNU General Public License as published by
15    the Free Software Foundation; either version 2 of the License, or
16    (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21    GNU General Public License for more details.
22
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., 59 Temple Place - Suite 330,
26    Boston, MA 02111-1307, USA.  */
27
28 #include "defs.h"
29 #include "inferior.h"
30 #include "gdbcore.h"
31 #include "target.h"
32 #include "regcache.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
43 static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR);
44
45 /* Size of elements in jmpbuf */
46
47 #define JB_ELEMENT_SIZE 4
48
49 /*
50  * See the comment in m68k-tdep.c regarding the utility of these functions.
51  *
52  * These definitions are from the MIPS SVR4 ABI, so they may work for
53  * any MIPS SVR4 target.
54  */
55
56 void
57 supply_gregset (gregset_t *gregsetp)
58 {
59   int regi;
60   greg_t *regp = &(*gregsetp)[0];
61   int gregoff = sizeof (greg_t) - mips_isa_regsize (current_gdbarch);
62   static char zerobuf[32] = {0};
63
64   for (regi = 0; regi <= CTX_RA; regi++)
65     regcache_raw_supply (current_regcache, regi,
66                          (char *) (regp + regi) + gregoff);
67
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);
76
77   /* Fill inaccessible registers with zero.  */
78   regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->badvaddr, zerobuf);
79 }
80
81 void
82 fill_gregset (gregset_t *gregsetp, int regno)
83 {
84   int regi;
85   greg_t *regp = &(*gregsetp)[0];
86   LONGEST regval;
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         regcache_raw_read_signed (current_regcache, regi, &regval);
96         *(regp + regi) = regval;
97       }
98
99   if ((regno == -1) || (regno == PC_REGNUM))
100     {
101       regcache_raw_read_signed
102         (current_regcache, mips_regnum (current_gdbarch)->pc, &regval);
103       *(regp + CTX_EPC) = regval;
104     }
105
106   if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause))
107     {
108       regcache_raw_read_signed
109         (current_regcache, mips_regnum (current_gdbarch)->cause, &regval);
110       *(regp + CTX_CAUSE) = regval;
111     }
112
113   if ((regno == -1)
114       || (regno == mips_regnum (current_gdbarch)->hi))
115     {
116       regcache_raw_read_signed
117         (current_regcache, mips_regnum (current_gdbarch)->hi, &regval);
118       *(regp + CTX_MDHI) = regval;
119     }
120
121   if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo))
122     {
123       regcache_raw_read_signed
124         (current_regcache, mips_regnum (current_gdbarch)->lo, &regval);
125       *(regp + CTX_MDLO) = regval;
126     }
127 }
128
129 /*
130  * Now we do the same thing for floating-point registers.
131  * We don't bother to condition on FP0_REGNUM since any
132  * reasonable MIPS configuration has an R3010 in it.
133  *
134  * Again, see the comments in m68k-tdep.c.
135  */
136
137 void
138 supply_fpregset (fpregset_t *fpregsetp)
139 {
140   int regi;
141   static char zerobuf[32] = {0};
142
143   /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
144
145   for (regi = 0; regi < 32; regi++)
146     regcache_raw_supply (current_regcache, FP0_REGNUM + regi,
147                          (char *) &fpregsetp->fp_r.fp_regs[regi]);
148
149   regcache_raw_supply (current_regcache,
150                        mips_regnum (current_gdbarch)->fp_control_status,
151                        (char *) &fpregsetp->fp_csr);
152
153   /* FIXME: how can we supply FCRIR?  SGI doesn't tell us. */
154   regcache_raw_supply (current_regcache,
155                        mips_regnum (current_gdbarch)->fp_implementation_revision,
156                        zerobuf);
157 }
158
159 void
160 fill_fpregset (fpregset_t *fpregsetp, int regno)
161 {
162   int regi;
163   char *from, *to;
164
165   /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
166
167   for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
168     {
169       if ((regno == -1) || (regno == regi))
170         {
171           to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
172           regcache_raw_read (current_regcache, regi, to);
173         }
174     }
175
176   if ((regno == -1)
177       || (regno == mips_regnum (current_gdbarch)->fp_control_status))
178     regcache_raw_read (current_regcache,
179                        mips_regnum (current_gdbarch)->fp_control_status, 
180                        &fpregsetp->fp_csr);
181 }
182
183
184 /* Figure out where the longjmp will land.
185    We expect the first arg to be a pointer to the jmp_buf structure from which
186    we extract the pc (JB_PC) that we will land at.  The pc is copied into PC.
187    This routine returns true on success. */
188
189 int
190 get_longjmp_target (CORE_ADDR *pc)
191 {
192   char *buf;
193   CORE_ADDR jb_addr;
194
195   buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
196   jb_addr = read_register (MIPS_A0_REGNUM);
197
198   if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
199                           TARGET_PTR_BIT / TARGET_CHAR_BIT))
200     return 0;
201
202   *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
203
204   return 1;
205 }
206
207 /* Provide registers to GDB from a core file.
208
209    CORE_REG_SECT points to an array of bytes, which were obtained from
210    a core file which BFD thinks might contain register contents. 
211    CORE_REG_SIZE is its size.
212
213    Normally, WHICH says which register set corelow suspects this is:
214      0 --- the general-purpose register set
215      2 --- the floating-point register set
216    However, for Irix 5, WHICH isn't used.
217
218    REG_ADDR is also unused.  */
219
220 static void
221 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
222                       int which, CORE_ADDR reg_addr)
223 {
224   if (core_reg_size == deprecated_register_bytes ())
225     {
226       memcpy ((char *) deprecated_registers, core_reg_sect, core_reg_size);
227     }
228   else if (mips_isa_regsize (current_gdbarch) == 4 &&
229            core_reg_size == (2 * mips_isa_regsize (current_gdbarch)) * NUM_REGS)
230     {
231       /* This is a core file from a N32 executable, 64 bits are saved
232          for all registers.  */
233       char *srcp = core_reg_sect;
234       char *dstp = deprecated_registers;
235       int regno;
236
237       for (regno = 0; regno < NUM_REGS; regno++)
238         {
239           if (regno >= FP0_REGNUM && regno < (FP0_REGNUM + 32))
240             {
241               /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
242                  currently assumes that they are 32 bit.  */
243               *dstp++ = *srcp++;
244               *dstp++ = *srcp++;
245               *dstp++ = *srcp++;
246               *dstp++ = *srcp++;
247               if (register_size (current_gdbarch, regno) == 4)
248                 {
249                   /* copying 4 bytes from eight bytes?
250                      I don't see how this can be right...  */
251                   srcp += 4;
252                 }
253               else
254                 {
255                   /* copy all 8 bytes (sizeof(double)) */
256                   *dstp++ = *srcp++;
257                   *dstp++ = *srcp++;
258                   *dstp++ = *srcp++;
259                   *dstp++ = *srcp++;
260                 }
261             }
262           else
263             {
264               srcp += 4;
265               *dstp++ = *srcp++;
266               *dstp++ = *srcp++;
267               *dstp++ = *srcp++;
268               *dstp++ = *srcp++;
269             }
270         }
271     }
272   else
273     {
274       warning ("wrong size gregset struct in core file");
275       return;
276     }
277
278   deprecated_registers_fetched ();
279 }
280
281 /* Register that we are able to handle irix5 core file formats.
282    This really is bfd_target_unknown_flavour */
283
284 static struct core_fns irix5_core_fns =
285 {
286   bfd_target_unknown_flavour,           /* core_flavour */
287   default_check_format,                 /* check_format */
288   default_core_sniffer,                 /* core_sniffer */
289   fetch_core_registers,                 /* core_read_registers */
290   NULL                                  /* next */
291 };
292
293 void
294 _initialize_core_irix5 (void)
295 {
296   deprecated_add_core_fns (&irix5_core_fns);
297 }