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