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