Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native support for the SGI Iris running IRIX version 5, for GDB. |
1b13c4f6 | 2 | |
6aba47ca DJ |
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. | |
1b13c4f6 | 5 | |
c906108c SS |
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 | ||
c5aa993b | 11 | This file is part of GDB. |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b JM |
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. | |
c906108c | 22 | |
c5aa993b JM |
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 | |
197e01b6 EZ |
25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
27 | |
28 | #include "defs.h" | |
29 | #include "inferior.h" | |
30 | #include "gdbcore.h" | |
31 | #include "target.h" | |
4e052eda | 32 | #include "regcache.h" |
c906108c SS |
33 | |
34 | #include "gdb_string.h" | |
35 | #include <sys/time.h> | |
36 | #include <sys/procfs.h> | |
37 | #include <setjmp.h> /* For JB_XXX. */ | |
38 | ||
c60c0f5f MS |
39 | /* Prototypes for supply_gregset etc. */ |
40 | #include "gregset.h" | |
b639a770 | 41 | #include "mips-tdep.h" |
c60c0f5f | 42 | |
9eefc95f UW |
43 | static void fetch_core_registers (struct regcache *, char *, |
44 | unsigned int, int, CORE_ADDR); | |
c906108c SS |
45 | |
46 | /* Size of elements in jmpbuf */ | |
47 | ||
48 | #define JB_ELEMENT_SIZE 4 | |
49 | ||
50 | /* | |
51 | * See the comment in m68k-tdep.c regarding the utility of these functions. | |
52 | * | |
53 | * These definitions are from the MIPS SVR4 ABI, so they may work for | |
54 | * any MIPS SVR4 target. | |
55 | */ | |
56 | ||
c5aa993b | 57 | void |
7f7fe91e | 58 | supply_gregset (struct regcache *regcache, const gregset_t *gregsetp) |
c906108c | 59 | { |
52f0bd74 | 60 | int regi; |
7f7fe91e | 61 | const greg_t *regp = &(*gregsetp)[0]; |
1b13c4f6 | 62 | int gregoff = sizeof (greg_t) - mips_isa_regsize (current_gdbarch); |
466d7106 | 63 | static char zerobuf[32] = {0}; |
c906108c | 64 | |
c5aa993b | 65 | for (regi = 0; regi <= CTX_RA; regi++) |
7f7fe91e UW |
66 | regcache_raw_supply (regcache, regi, |
67 | (const char *) (regp + regi) + gregoff); | |
68 | ||
69 | regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->pc, | |
70 | (const char *) (regp + CTX_EPC) + gregoff); | |
71 | regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->hi, | |
72 | (const char *) (regp + CTX_MDHI) + gregoff); | |
73 | regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->lo, | |
74 | (const char *) (regp + CTX_MDLO) + gregoff); | |
75 | regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->cause, | |
76 | (const char *) (regp + CTX_CAUSE) + gregoff); | |
c906108c SS |
77 | |
78 | /* Fill inaccessible registers with zero. */ | |
7f7fe91e | 79 | regcache_raw_supply (regcache, mips_regnum (current_gdbarch)->badvaddr, zerobuf); |
c906108c SS |
80 | } |
81 | ||
82 | void | |
7f7fe91e | 83 | fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno) |
c906108c | 84 | { |
6a1872e4 | 85 | int regi, size; |
52f0bd74 | 86 | greg_t *regp = &(*gregsetp)[0]; |
6a1872e4 | 87 | gdb_byte buf[MAX_REGISTER_SIZE]; |
c906108c SS |
88 | |
89 | /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32 | |
90 | executable, we have to sign extend the registers to 64 bits before | |
91 | filling in the gregset structure. */ | |
92 | ||
93 | for (regi = 0; regi <= CTX_RA; regi++) | |
94 | if ((regno == -1) || (regno == regi)) | |
44ed547b | 95 | { |
6a1872e4 | 96 | size = register_size (current_gdbarch, regi); |
7f7fe91e | 97 | regcache_raw_collect (regcache, regi, buf); |
6a1872e4 | 98 | *(regp + regi) = extract_signed_integer (buf, size); |
44ed547b | 99 | } |
c906108c SS |
100 | |
101 | if ((regno == -1) || (regno == PC_REGNUM)) | |
44ed547b | 102 | { |
6a1872e4 UW |
103 | regi = mips_regnum (current_gdbarch)->pc; |
104 | size = register_size (current_gdbarch, regi); | |
7f7fe91e | 105 | regcache_raw_collect (regcache, regi, buf); |
6a1872e4 | 106 | *(regp + CTX_EPC) = extract_signed_integer (buf, size); |
44ed547b | 107 | } |
c906108c | 108 | |
56cea623 | 109 | if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause)) |
44ed547b | 110 | { |
6a1872e4 UW |
111 | regi = mips_regnum (current_gdbarch)->cause; |
112 | size = register_size (current_gdbarch, regi); | |
7f7fe91e | 113 | regcache_raw_collect (regcache, regi, buf); |
6a1872e4 | 114 | *(regp + CTX_CAUSE) = extract_signed_integer (buf, size); |
44ed547b | 115 | } |
c906108c | 116 | |
6a1872e4 | 117 | if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->hi)) |
44ed547b | 118 | { |
6a1872e4 UW |
119 | regi = mips_regnum (current_gdbarch)->hi; |
120 | size = register_size (current_gdbarch, regi); | |
7f7fe91e | 121 | regcache_raw_collect (regcache, regi, buf); |
6a1872e4 | 122 | *(regp + CTX_MDHI) = extract_signed_integer (buf, size); |
44ed547b | 123 | } |
c906108c | 124 | |
56cea623 | 125 | if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo)) |
44ed547b | 126 | { |
6a1872e4 UW |
127 | regi = mips_regnum (current_gdbarch)->lo; |
128 | size = register_size (current_gdbarch, regi); | |
7f7fe91e | 129 | regcache_raw_collect (regcache, regi, buf); |
6a1872e4 | 130 | *(regp + CTX_MDLO) = extract_signed_integer (buf, size); |
44ed547b | 131 | } |
c906108c SS |
132 | } |
133 | ||
134 | /* | |
135 | * Now we do the same thing for floating-point registers. | |
136 | * We don't bother to condition on FP0_REGNUM since any | |
137 | * reasonable MIPS configuration has an R3010 in it. | |
138 | * | |
139 | * Again, see the comments in m68k-tdep.c. | |
140 | */ | |
141 | ||
142 | void | |
7f7fe91e | 143 | supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp) |
c906108c | 144 | { |
52f0bd74 | 145 | int regi; |
466d7106 | 146 | static char zerobuf[32] = {0}; |
6d1eba4c | 147 | char fsrbuf[8]; |
c906108c SS |
148 | |
149 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
150 | ||
151 | for (regi = 0; regi < 32; regi++) | |
7f7fe91e UW |
152 | regcache_raw_supply (regcache, FP0_REGNUM + regi, |
153 | (const char *) &fpregsetp->fp_r.fp_regs[regi]); | |
c906108c | 154 | |
6d1eba4c JB |
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 | ||
7f7fe91e | 163 | regcache_raw_supply (regcache, |
23a6d369 | 164 | mips_regnum (current_gdbarch)->fp_control_status, |
6d1eba4c | 165 | fsrbuf); |
c906108c | 166 | |
56cea623 | 167 | /* FIXME: how can we supply FCRIR? SGI doesn't tell us. */ |
7f7fe91e | 168 | regcache_raw_supply (regcache, |
23a6d369 AC |
169 | mips_regnum (current_gdbarch)->fp_implementation_revision, |
170 | zerobuf); | |
c906108c SS |
171 | } |
172 | ||
173 | void | |
7f7fe91e | 174 | fill_fpregset (const struct regcache *regcache, fpregset_t *fpregsetp, int regno) |
c906108c SS |
175 | { |
176 | int regi; | |
177 | char *from, *to; | |
178 | ||
179 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
180 | ||
181 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) | |
182 | { | |
183 | if ((regno == -1) || (regno == regi)) | |
184 | { | |
c906108c | 185 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); |
7f7fe91e | 186 | regcache_raw_collect (regcache, regi, to); |
c906108c SS |
187 | } |
188 | } | |
189 | ||
6d1eba4c JB |
190 | if (regno == -1 |
191 | || regno == mips_regnum (current_gdbarch)->fp_control_status) | |
192 | { | |
193 | char fsrbuf[8]; | |
194 | ||
195 | /* We can't fill the FSR register directly from the regcache, | |
196 | because there is a size issue: On one hand, fpregsetp->fp_csr | |
197 | is 32bits long, while the regcache expects a 64bits long buffer. | |
198 | So we use a buffer of the correct size and copy the register | |
199 | value from that buffer. */ | |
7f7fe91e | 200 | regcache_raw_collect (regcache, |
6a1872e4 UW |
201 | mips_regnum (current_gdbarch)->fp_control_status, |
202 | fsrbuf); | |
6d1eba4c JB |
203 | |
204 | memcpy (&fpregsetp->fp_csr, fsrbuf + 4, 4); | |
205 | } | |
c906108c SS |
206 | } |
207 | ||
208 | ||
209 | /* Figure out where the longjmp will land. | |
210 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
211 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
212 | This routine returns true on success. */ | |
213 | ||
214 | int | |
fba45db2 | 215 | get_longjmp_target (CORE_ADDR *pc) |
c906108c | 216 | { |
35fc8285 | 217 | char *buf; |
c906108c SS |
218 | CORE_ADDR jb_addr; |
219 | ||
35fc8285 | 220 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
613e114f | 221 | jb_addr = read_register (MIPS_A0_REGNUM); |
c906108c SS |
222 | |
223 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, | |
224 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
225 | return 0; | |
226 | ||
7c0b4a20 | 227 | *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
228 | |
229 | return 1; | |
230 | } | |
231 | ||
16bce26c KB |
232 | /* Provide registers to GDB from a core file. |
233 | ||
234 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
235 | a core file which BFD thinks might contain register contents. | |
236 | CORE_REG_SIZE is its size. | |
237 | ||
238 | Normally, WHICH says which register set corelow suspects this is: | |
239 | 0 --- the general-purpose register set | |
240 | 2 --- the floating-point register set | |
241 | However, for Irix 5, WHICH isn't used. | |
242 | ||
243 | REG_ADDR is also unused. */ | |
244 | ||
c906108c | 245 | static void |
9eefc95f UW |
246 | fetch_core_registers (struct regcache *regcache, |
247 | char *core_reg_sect, unsigned core_reg_size, | |
16bce26c | 248 | int which, CORE_ADDR reg_addr) |
c906108c | 249 | { |
f6e1bffc | 250 | char *srcp = core_reg_sect; |
f58b68aa | 251 | int regsize = mips_isa_regsize (current_gdbarch); |
f6e1bffc JB |
252 | int regno; |
253 | ||
f58b68aa DJ |
254 | /* If regsize is 8, this is a N32 or N64 core file. |
255 | If regsize is 4, this is an O32 core file. */ | |
f57d151a | 256 | if (core_reg_size != regsize * gdbarch_num_regs (current_gdbarch)) |
c906108c | 257 | { |
8a3fe4f8 | 258 | warning (_("wrong size gregset struct in core file")); |
c906108c SS |
259 | return; |
260 | } | |
f58b68aa | 261 | |
f57d151a | 262 | for (regno = 0; regno < gdbarch_num_regs (current_gdbarch); regno++) |
f58b68aa | 263 | { |
9eefc95f | 264 | regcache_raw_supply (regcache, regno, srcp); |
f58b68aa DJ |
265 | srcp += regsize; |
266 | } | |
c906108c | 267 | } |
c5aa993b | 268 | |
c906108c SS |
269 | /* Register that we are able to handle irix5 core file formats. |
270 | This really is bfd_target_unknown_flavour */ | |
271 | ||
272 | static struct core_fns irix5_core_fns = | |
273 | { | |
2acceee2 JM |
274 | bfd_target_unknown_flavour, /* core_flavour */ |
275 | default_check_format, /* check_format */ | |
276 | default_core_sniffer, /* core_sniffer */ | |
277 | fetch_core_registers, /* core_read_registers */ | |
278 | NULL /* next */ | |
c906108c SS |
279 | }; |
280 | ||
281 | void | |
fba45db2 | 282 | _initialize_core_irix5 (void) |
c906108c | 283 | { |
00e32a35 | 284 | deprecated_add_core_fns (&irix5_core_fns); |
c906108c | 285 | } |