Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native support for the SGI Iris running IRIX version 5, for GDB. |
1b13c4f6 AC |
2 | |
3 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, | |
4 | 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. | |
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 | |
25 | Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | Boston, MA 02111-1307, 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 | |
a14ed312 | 43 | static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR); |
c906108c SS |
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 | ||
c5aa993b | 56 | void |
fba45db2 | 57 | supply_gregset (gregset_t *gregsetp) |
c906108c | 58 | { |
52f0bd74 AC |
59 | int regi; |
60 | greg_t *regp = &(*gregsetp)[0]; | |
1b13c4f6 | 61 | int gregoff = sizeof (greg_t) - mips_isa_regsize (current_gdbarch); |
466d7106 | 62 | static char zerobuf[32] = {0}; |
c906108c | 63 | |
c5aa993b | 64 | for (regi = 0; regi <= CTX_RA; regi++) |
23a6d369 AC |
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); | |
c906108c SS |
76 | |
77 | /* Fill inaccessible registers with zero. */ | |
23a6d369 | 78 | regcache_raw_supply (current_regcache, mips_regnum (current_gdbarch)->badvaddr, zerobuf); |
c906108c SS |
79 | } |
80 | ||
81 | void | |
fba45db2 | 82 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
83 | { |
84 | int regi; | |
52f0bd74 | 85 | greg_t *regp = &(*gregsetp)[0]; |
c906108c SS |
86 | |
87 | /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32 | |
88 | executable, we have to sign extend the registers to 64 bits before | |
89 | filling in the gregset structure. */ | |
90 | ||
91 | for (regi = 0; regi <= CTX_RA; regi++) | |
92 | if ((regno == -1) || (regno == regi)) | |
93 | *(regp + regi) = | |
62700349 | 94 | extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)], |
3acba339 | 95 | register_size (current_gdbarch, regi)); |
c906108c SS |
96 | |
97 | if ((regno == -1) || (regno == PC_REGNUM)) | |
98 | *(regp + CTX_EPC) = | |
56cea623 | 99 | extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->pc)], |
3acba339 | 100 | register_size (current_gdbarch, mips_regnum (current_gdbarch)->pc)); |
c906108c | 101 | |
56cea623 | 102 | if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->cause)) |
c906108c | 103 | *(regp + CTX_CAUSE) = |
56cea623 | 104 | extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->cause)], |
3acba339 | 105 | register_size (current_gdbarch, mips_regnum (current_gdbarch)->cause)); |
c906108c | 106 | |
56cea623 AC |
107 | if ((regno == -1) |
108 | || (regno == mips_regnum (current_gdbarch)->hi)) | |
c906108c | 109 | *(regp + CTX_MDHI) = |
56cea623 | 110 | extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->hi)], |
3acba339 | 111 | register_size (current_gdbarch, mips_regnum (current_gdbarch)->hi)); |
c906108c | 112 | |
56cea623 | 113 | if ((regno == -1) || (regno == mips_regnum (current_gdbarch)->lo)) |
c906108c | 114 | *(regp + CTX_MDLO) = |
56cea623 | 115 | extract_signed_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->lo)], |
3acba339 | 116 | register_size (current_gdbarch, mips_regnum (current_gdbarch)->lo)); |
c906108c SS |
117 | } |
118 | ||
119 | /* | |
120 | * Now we do the same thing for floating-point registers. | |
121 | * We don't bother to condition on FP0_REGNUM since any | |
122 | * reasonable MIPS configuration has an R3010 in it. | |
123 | * | |
124 | * Again, see the comments in m68k-tdep.c. | |
125 | */ | |
126 | ||
127 | void | |
fba45db2 | 128 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c | 129 | { |
52f0bd74 | 130 | int regi; |
466d7106 | 131 | static char zerobuf[32] = {0}; |
c906108c SS |
132 | |
133 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
134 | ||
135 | for (regi = 0; regi < 32; regi++) | |
23a6d369 AC |
136 | regcache_raw_supply (current_regcache, FP0_REGNUM + regi, |
137 | (char *) &fpregsetp->fp_r.fp_regs[regi]); | |
c906108c | 138 | |
23a6d369 AC |
139 | regcache_raw_supply (current_regcache, |
140 | mips_regnum (current_gdbarch)->fp_control_status, | |
141 | (char *) &fpregsetp->fp_csr); | |
c906108c | 142 | |
56cea623 | 143 | /* FIXME: how can we supply FCRIR? SGI doesn't tell us. */ |
23a6d369 AC |
144 | regcache_raw_supply (current_regcache, |
145 | mips_regnum (current_gdbarch)->fp_implementation_revision, | |
146 | zerobuf); | |
c906108c SS |
147 | } |
148 | ||
149 | void | |
fba45db2 | 150 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
151 | { |
152 | int regi; | |
153 | char *from, *to; | |
154 | ||
155 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
156 | ||
157 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) | |
158 | { | |
159 | if ((regno == -1) || (regno == regi)) | |
160 | { | |
62700349 | 161 | from = (char *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regi)]; |
c906108c | 162 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); |
3acba339 | 163 | memcpy (to, from, register_size (current_gdbarch, regi)); |
c906108c SS |
164 | } |
165 | } | |
166 | ||
56cea623 AC |
167 | if ((regno == -1) |
168 | || (regno == mips_regnum (current_gdbarch)->fp_control_status)) | |
169 | fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch)->fp_control_status)]; | |
c906108c SS |
170 | } |
171 | ||
172 | ||
173 | /* Figure out where the longjmp will land. | |
174 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
175 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
176 | This routine returns true on success. */ | |
177 | ||
178 | int | |
fba45db2 | 179 | get_longjmp_target (CORE_ADDR *pc) |
c906108c | 180 | { |
35fc8285 | 181 | char *buf; |
c906108c SS |
182 | CORE_ADDR jb_addr; |
183 | ||
35fc8285 | 184 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
613e114f | 185 | jb_addr = read_register (MIPS_A0_REGNUM); |
c906108c SS |
186 | |
187 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, | |
188 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
189 | return 0; | |
190 | ||
7c0b4a20 | 191 | *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
192 | |
193 | return 1; | |
194 | } | |
195 | ||
16bce26c KB |
196 | /* Provide registers to GDB from a core file. |
197 | ||
198 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
199 | a core file which BFD thinks might contain register contents. | |
200 | CORE_REG_SIZE is its size. | |
201 | ||
202 | Normally, WHICH says which register set corelow suspects this is: | |
203 | 0 --- the general-purpose register set | |
204 | 2 --- the floating-point register set | |
205 | However, for Irix 5, WHICH isn't used. | |
206 | ||
207 | REG_ADDR is also unused. */ | |
208 | ||
c906108c | 209 | static void |
16bce26c KB |
210 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
211 | int which, CORE_ADDR reg_addr) | |
c906108c | 212 | { |
f42accbe | 213 | if (core_reg_size == deprecated_register_bytes ()) |
c906108c | 214 | { |
524d7c18 | 215 | memcpy ((char *) deprecated_registers, core_reg_sect, core_reg_size); |
c906108c | 216 | } |
1b13c4f6 AC |
217 | else if (mips_isa_regsize (current_gdbarch) == 4 && |
218 | core_reg_size == (2 * mips_isa_regsize (current_gdbarch)) * NUM_REGS) | |
c906108c SS |
219 | { |
220 | /* This is a core file from a N32 executable, 64 bits are saved | |
c5aa993b | 221 | for all registers. */ |
c906108c | 222 | char *srcp = core_reg_sect; |
524d7c18 | 223 | char *dstp = deprecated_registers; |
c906108c SS |
224 | int regno; |
225 | ||
226 | for (regno = 0; regno < NUM_REGS; regno++) | |
227 | { | |
228 | if (regno >= FP0_REGNUM && regno < (FP0_REGNUM + 32)) | |
229 | { | |
230 | /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB | |
c5aa993b | 231 | currently assumes that they are 32 bit. */ |
c906108c SS |
232 | *dstp++ = *srcp++; |
233 | *dstp++ = *srcp++; | |
234 | *dstp++ = *srcp++; | |
235 | *dstp++ = *srcp++; | |
3acba339 | 236 | if (register_size (current_gdbarch, regno) == 4) |
c906108c SS |
237 | { |
238 | /* copying 4 bytes from eight bytes? | |
239 | I don't see how this can be right... */ | |
c5aa993b | 240 | srcp += 4; |
c906108c SS |
241 | } |
242 | else | |
243 | { | |
244 | /* copy all 8 bytes (sizeof(double)) */ | |
245 | *dstp++ = *srcp++; | |
246 | *dstp++ = *srcp++; | |
247 | *dstp++ = *srcp++; | |
248 | *dstp++ = *srcp++; | |
249 | } | |
250 | } | |
251 | else | |
252 | { | |
253 | srcp += 4; | |
254 | *dstp++ = *srcp++; | |
255 | *dstp++ = *srcp++; | |
256 | *dstp++ = *srcp++; | |
257 | *dstp++ = *srcp++; | |
258 | } | |
259 | } | |
260 | } | |
261 | else | |
262 | { | |
263 | warning ("wrong size gregset struct in core file"); | |
264 | return; | |
265 | } | |
266 | ||
2b9e5f3f | 267 | deprecated_registers_fetched (); |
c906108c | 268 | } |
c5aa993b | 269 | |
c906108c SS |
270 | /* Register that we are able to handle irix5 core file formats. |
271 | This really is bfd_target_unknown_flavour */ | |
272 | ||
273 | static struct core_fns irix5_core_fns = | |
274 | { | |
2acceee2 JM |
275 | bfd_target_unknown_flavour, /* core_flavour */ |
276 | default_check_format, /* check_format */ | |
277 | default_core_sniffer, /* core_sniffer */ | |
278 | fetch_core_registers, /* core_read_registers */ | |
279 | NULL /* next */ | |
c906108c SS |
280 | }; |
281 | ||
282 | void | |
fba45db2 | 283 | _initialize_core_irix5 (void) |
c906108c | 284 | { |
00e32a35 | 285 | deprecated_add_core_fns (&irix5_core_fns); |
c906108c | 286 | } |