| 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
| 2 | |
| 3 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, |
| 4 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
| 5 | Free Software Foundation, Inc. |
| 6 | |
| 7 | Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU |
| 8 | and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin. |
| 9 | |
| 10 | This file is part of GDB. |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 3 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 24 | |
| 25 | #include "defs.h" |
| 26 | #include "gdb_string.h" |
| 27 | #include "gdb_assert.h" |
| 28 | #include "frame.h" |
| 29 | #include "inferior.h" |
| 30 | #include "symtab.h" |
| 31 | #include "value.h" |
| 32 | #include "gdbcmd.h" |
| 33 | #include "language.h" |
| 34 | #include "gdbcore.h" |
| 35 | #include "symfile.h" |
| 36 | #include "objfiles.h" |
| 37 | #include "gdbtypes.h" |
| 38 | #include "target.h" |
| 39 | #include "arch-utils.h" |
| 40 | #include "regcache.h" |
| 41 | #include "osabi.h" |
| 42 | #include "mips-tdep.h" |
| 43 | #include "block.h" |
| 44 | #include "reggroups.h" |
| 45 | #include "opcode/mips.h" |
| 46 | #include "elf/mips.h" |
| 47 | #include "elf-bfd.h" |
| 48 | #include "symcat.h" |
| 49 | #include "sim-regno.h" |
| 50 | #include "dis-asm.h" |
| 51 | #include "frame-unwind.h" |
| 52 | #include "frame-base.h" |
| 53 | #include "trad-frame.h" |
| 54 | #include "infcall.h" |
| 55 | #include "floatformat.h" |
| 56 | #include "remote.h" |
| 57 | #include "target-descriptions.h" |
| 58 | #include "dwarf2-frame.h" |
| 59 | #include "user-regs.h" |
| 60 | |
| 61 | static const struct objfile_data *mips_pdr_data; |
| 62 | |
| 63 | static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum); |
| 64 | |
| 65 | /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */ |
| 66 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ |
| 67 | #define ST0_FR (1 << 26) |
| 68 | |
| 69 | /* The sizes of floating point registers. */ |
| 70 | |
| 71 | enum |
| 72 | { |
| 73 | MIPS_FPU_SINGLE_REGSIZE = 4, |
| 74 | MIPS_FPU_DOUBLE_REGSIZE = 8 |
| 75 | }; |
| 76 | |
| 77 | enum |
| 78 | { |
| 79 | MIPS32_REGSIZE = 4, |
| 80 | MIPS64_REGSIZE = 8 |
| 81 | }; |
| 82 | |
| 83 | static const char *mips_abi_string; |
| 84 | |
| 85 | static const char *mips_abi_strings[] = { |
| 86 | "auto", |
| 87 | "n32", |
| 88 | "o32", |
| 89 | "n64", |
| 90 | "o64", |
| 91 | "eabi32", |
| 92 | "eabi64", |
| 93 | NULL |
| 94 | }; |
| 95 | |
| 96 | /* The standard register names, and all the valid aliases for them. */ |
| 97 | struct register_alias |
| 98 | { |
| 99 | const char *name; |
| 100 | int regnum; |
| 101 | }; |
| 102 | |
| 103 | /* Aliases for o32 and most other ABIs. */ |
| 104 | const struct register_alias mips_o32_aliases[] = { |
| 105 | { "ta0", 12 }, |
| 106 | { "ta1", 13 }, |
| 107 | { "ta2", 14 }, |
| 108 | { "ta3", 15 } |
| 109 | }; |
| 110 | |
| 111 | /* Aliases for n32 and n64. */ |
| 112 | const struct register_alias mips_n32_n64_aliases[] = { |
| 113 | { "ta0", 8 }, |
| 114 | { "ta1", 9 }, |
| 115 | { "ta2", 10 }, |
| 116 | { "ta3", 11 } |
| 117 | }; |
| 118 | |
| 119 | /* Aliases for ABI-independent registers. */ |
| 120 | const struct register_alias mips_register_aliases[] = { |
| 121 | /* The architecture manuals specify these ABI-independent names for |
| 122 | the GPRs. */ |
| 123 | #define R(n) { "r" #n, n } |
| 124 | R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7), |
| 125 | R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15), |
| 126 | R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23), |
| 127 | R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31), |
| 128 | #undef R |
| 129 | |
| 130 | /* k0 and k1 are sometimes called these instead (for "kernel |
| 131 | temp"). */ |
| 132 | { "kt0", 26 }, |
| 133 | { "kt1", 27 }, |
| 134 | |
| 135 | /* This is the traditional GDB name for the CP0 status register. */ |
| 136 | { "sr", MIPS_PS_REGNUM }, |
| 137 | |
| 138 | /* This is the traditional GDB name for the CP0 BadVAddr register. */ |
| 139 | { "bad", MIPS_EMBED_BADVADDR_REGNUM }, |
| 140 | |
| 141 | /* This is the traditional GDB name for the FCSR. */ |
| 142 | { "fsr", MIPS_EMBED_FP0_REGNUM + 32 } |
| 143 | }; |
| 144 | |
| 145 | /* Some MIPS boards don't support floating point while others only |
| 146 | support single-precision floating-point operations. */ |
| 147 | |
| 148 | enum mips_fpu_type |
| 149 | { |
| 150 | MIPS_FPU_DOUBLE, /* Full double precision floating point. */ |
| 151 | MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */ |
| 152 | MIPS_FPU_NONE /* No floating point. */ |
| 153 | }; |
| 154 | |
| 155 | #ifndef MIPS_DEFAULT_FPU_TYPE |
| 156 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE |
| 157 | #endif |
| 158 | static int mips_fpu_type_auto = 1; |
| 159 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; |
| 160 | |
| 161 | static int mips_debug = 0; |
| 162 | |
| 163 | /* Properties (for struct target_desc) describing the g/G packet |
| 164 | layout. */ |
| 165 | #define PROPERTY_GP32 "internal: transfers-32bit-registers" |
| 166 | #define PROPERTY_GP64 "internal: transfers-64bit-registers" |
| 167 | |
| 168 | struct target_desc *mips_tdesc_gp32; |
| 169 | struct target_desc *mips_tdesc_gp64; |
| 170 | |
| 171 | /* MIPS specific per-architecture information */ |
| 172 | struct gdbarch_tdep |
| 173 | { |
| 174 | /* from the elf header */ |
| 175 | int elf_flags; |
| 176 | |
| 177 | /* mips options */ |
| 178 | enum mips_abi mips_abi; |
| 179 | enum mips_abi found_abi; |
| 180 | enum mips_fpu_type mips_fpu_type; |
| 181 | int mips_last_arg_regnum; |
| 182 | int mips_last_fp_arg_regnum; |
| 183 | int default_mask_address_p; |
| 184 | /* Is the target using 64-bit raw integer registers but only |
| 185 | storing a left-aligned 32-bit value in each? */ |
| 186 | int mips64_transfers_32bit_regs_p; |
| 187 | /* Indexes for various registers. IRIX and embedded have |
| 188 | different values. This contains the "public" fields. Don't |
| 189 | add any that do not need to be public. */ |
| 190 | const struct mips_regnum *regnum; |
| 191 | /* Register names table for the current register set. */ |
| 192 | const char **mips_processor_reg_names; |
| 193 | |
| 194 | /* The size of register data available from the target, if known. |
| 195 | This doesn't quite obsolete the manual |
| 196 | mips64_transfers_32bit_regs_p, since that is documented to force |
| 197 | left alignment even for big endian (very strange). */ |
| 198 | int register_size_valid_p; |
| 199 | int register_size; |
| 200 | }; |
| 201 | |
| 202 | const struct mips_regnum * |
| 203 | mips_regnum (struct gdbarch *gdbarch) |
| 204 | { |
| 205 | return gdbarch_tdep (gdbarch)->regnum; |
| 206 | } |
| 207 | |
| 208 | static int |
| 209 | mips_fpa0_regnum (struct gdbarch *gdbarch) |
| 210 | { |
| 211 | return mips_regnum (gdbarch)->fp0 + 12; |
| 212 | } |
| 213 | |
| 214 | #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \ |
| 215 | || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64) |
| 216 | |
| 217 | #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum) |
| 218 | |
| 219 | #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum) |
| 220 | |
| 221 | #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type) |
| 222 | |
| 223 | /* MIPS16 function addresses are odd (bit 0 is set). Here are some |
| 224 | functions to test, set, or clear bit 0 of addresses. */ |
| 225 | |
| 226 | static CORE_ADDR |
| 227 | is_mips16_addr (CORE_ADDR addr) |
| 228 | { |
| 229 | return ((addr) & 1); |
| 230 | } |
| 231 | |
| 232 | static CORE_ADDR |
| 233 | unmake_mips16_addr (CORE_ADDR addr) |
| 234 | { |
| 235 | return ((addr) & ~(CORE_ADDR) 1); |
| 236 | } |
| 237 | |
| 238 | /* Return the MIPS ABI associated with GDBARCH. */ |
| 239 | enum mips_abi |
| 240 | mips_abi (struct gdbarch *gdbarch) |
| 241 | { |
| 242 | return gdbarch_tdep (gdbarch)->mips_abi; |
| 243 | } |
| 244 | |
| 245 | int |
| 246 | mips_isa_regsize (struct gdbarch *gdbarch) |
| 247 | { |
| 248 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 249 | |
| 250 | /* If we know how big the registers are, use that size. */ |
| 251 | if (tdep->register_size_valid_p) |
| 252 | return tdep->register_size; |
| 253 | |
| 254 | /* Fall back to the previous behavior. */ |
| 255 | return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word |
| 256 | / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte); |
| 257 | } |
| 258 | |
| 259 | /* Return the currently configured (or set) saved register size. */ |
| 260 | |
| 261 | unsigned int |
| 262 | mips_abi_regsize (struct gdbarch *gdbarch) |
| 263 | { |
| 264 | switch (mips_abi (gdbarch)) |
| 265 | { |
| 266 | case MIPS_ABI_EABI32: |
| 267 | case MIPS_ABI_O32: |
| 268 | return 4; |
| 269 | case MIPS_ABI_N32: |
| 270 | case MIPS_ABI_N64: |
| 271 | case MIPS_ABI_O64: |
| 272 | case MIPS_ABI_EABI64: |
| 273 | return 8; |
| 274 | case MIPS_ABI_UNKNOWN: |
| 275 | case MIPS_ABI_LAST: |
| 276 | default: |
| 277 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /* Functions for setting and testing a bit in a minimal symbol that |
| 282 | marks it as 16-bit function. The MSB of the minimal symbol's |
| 283 | "info" field is used for this purpose. |
| 284 | |
| 285 | gdbarch_elf_make_msymbol_special tests whether an ELF symbol is "special", |
| 286 | i.e. refers to a 16-bit function, and sets a "special" bit in a |
| 287 | minimal symbol to mark it as a 16-bit function |
| 288 | |
| 289 | MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */ |
| 290 | |
| 291 | static void |
| 292 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
| 293 | { |
| 294 | if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16) |
| 295 | { |
| 296 | MSYMBOL_INFO (msym) = (char *) |
| 297 | (((long) MSYMBOL_INFO (msym)) | 0x80000000); |
| 298 | SYMBOL_VALUE_ADDRESS (msym) |= 1; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | static int |
| 303 | msymbol_is_special (struct minimal_symbol *msym) |
| 304 | { |
| 305 | return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0); |
| 306 | } |
| 307 | |
| 308 | /* XFER a value from the big/little/left end of the register. |
| 309 | Depending on the size of the value it might occupy the entire |
| 310 | register or just part of it. Make an allowance for this, aligning |
| 311 | things accordingly. */ |
| 312 | |
| 313 | static void |
| 314 | mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache, |
| 315 | int reg_num, int length, |
| 316 | enum bfd_endian endian, gdb_byte *in, |
| 317 | const gdb_byte *out, int buf_offset) |
| 318 | { |
| 319 | int reg_offset = 0; |
| 320 | |
| 321 | gdb_assert (reg_num >= gdbarch_num_regs (gdbarch)); |
| 322 | /* Need to transfer the left or right part of the register, based on |
| 323 | the targets byte order. */ |
| 324 | switch (endian) |
| 325 | { |
| 326 | case BFD_ENDIAN_BIG: |
| 327 | reg_offset = register_size (gdbarch, reg_num) - length; |
| 328 | break; |
| 329 | case BFD_ENDIAN_LITTLE: |
| 330 | reg_offset = 0; |
| 331 | break; |
| 332 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
| 333 | reg_offset = 0; |
| 334 | break; |
| 335 | default: |
| 336 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 337 | } |
| 338 | if (mips_debug) |
| 339 | fprintf_unfiltered (gdb_stderr, |
| 340 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", |
| 341 | reg_num, reg_offset, buf_offset, length); |
| 342 | if (mips_debug && out != NULL) |
| 343 | { |
| 344 | int i; |
| 345 | fprintf_unfiltered (gdb_stdlog, "out "); |
| 346 | for (i = 0; i < length; i++) |
| 347 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
| 348 | } |
| 349 | if (in != NULL) |
| 350 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
| 351 | in + buf_offset); |
| 352 | if (out != NULL) |
| 353 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
| 354 | out + buf_offset); |
| 355 | if (mips_debug && in != NULL) |
| 356 | { |
| 357 | int i; |
| 358 | fprintf_unfiltered (gdb_stdlog, "in "); |
| 359 | for (i = 0; i < length; i++) |
| 360 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
| 361 | } |
| 362 | if (mips_debug) |
| 363 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 364 | } |
| 365 | |
| 366 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
| 367 | compatiblity mode. A return value of 1 means that we have |
| 368 | physical 64-bit registers, but should treat them as 32-bit registers. */ |
| 369 | |
| 370 | static int |
| 371 | mips2_fp_compat (struct frame_info *frame) |
| 372 | { |
| 373 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 374 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not |
| 375 | meaningful. */ |
| 376 | if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4) |
| 377 | return 0; |
| 378 | |
| 379 | #if 0 |
| 380 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, |
| 381 | in all the places we deal with FP registers. PR gdb/413. */ |
| 382 | /* Otherwise check the FR bit in the status register - it controls |
| 383 | the FP compatiblity mode. If it is clear we are in compatibility |
| 384 | mode. */ |
| 385 | if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0) |
| 386 | return 1; |
| 387 | #endif |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
| 393 | |
| 394 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
| 395 | |
| 396 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
| 397 | |
| 398 | static struct type *mips_float_register_type (void); |
| 399 | static struct type *mips_double_register_type (void); |
| 400 | |
| 401 | /* The list of available "set mips " and "show mips " commands */ |
| 402 | |
| 403 | static struct cmd_list_element *setmipscmdlist = NULL; |
| 404 | static struct cmd_list_element *showmipscmdlist = NULL; |
| 405 | |
| 406 | /* Integer registers 0 thru 31 are handled explicitly by |
| 407 | mips_register_name(). Processor specific registers 32 and above |
| 408 | are listed in the following tables. */ |
| 409 | |
| 410 | enum |
| 411 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; |
| 412 | |
| 413 | /* Generic MIPS. */ |
| 414 | |
| 415 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { |
| 416 | "sr", "lo", "hi", "bad", "cause", "pc", |
| 417 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 418 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 419 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 420 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 421 | "fsr", "fir", "" /*"fp" */ , "", |
| 422 | "", "", "", "", "", "", "", "", |
| 423 | "", "", "", "", "", "", "", "", |
| 424 | }; |
| 425 | |
| 426 | /* Names of IDT R3041 registers. */ |
| 427 | |
| 428 | static const char *mips_r3041_reg_names[] = { |
| 429 | "sr", "lo", "hi", "bad", "cause", "pc", |
| 430 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 431 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 432 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 433 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 434 | "fsr", "fir", "", /*"fp" */ "", |
| 435 | "", "", "bus", "ccfg", "", "", "", "", |
| 436 | "", "", "port", "cmp", "", "", "epc", "prid", |
| 437 | }; |
| 438 | |
| 439 | /* Names of tx39 registers. */ |
| 440 | |
| 441 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { |
| 442 | "sr", "lo", "hi", "bad", "cause", "pc", |
| 443 | "", "", "", "", "", "", "", "", |
| 444 | "", "", "", "", "", "", "", "", |
| 445 | "", "", "", "", "", "", "", "", |
| 446 | "", "", "", "", "", "", "", "", |
| 447 | "", "", "", "", |
| 448 | "", "", "", "", "", "", "", "", |
| 449 | "", "", "config", "cache", "debug", "depc", "epc", "" |
| 450 | }; |
| 451 | |
| 452 | /* Names of IRIX registers. */ |
| 453 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { |
| 454 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 455 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 456 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 457 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 458 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" |
| 459 | }; |
| 460 | |
| 461 | |
| 462 | /* Return the name of the register corresponding to REGNO. */ |
| 463 | static const char * |
| 464 | mips_register_name (struct gdbarch *gdbarch, int regno) |
| 465 | { |
| 466 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 467 | /* GPR names for all ABIs other than n32/n64. */ |
| 468 | static char *mips_gpr_names[] = { |
| 469 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 470 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", |
| 471 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 472 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", |
| 473 | }; |
| 474 | |
| 475 | /* GPR names for n32 and n64 ABIs. */ |
| 476 | static char *mips_n32_n64_gpr_names[] = { |
| 477 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 478 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", |
| 479 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 480 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" |
| 481 | }; |
| 482 | |
| 483 | enum mips_abi abi = mips_abi (gdbarch); |
| 484 | |
| 485 | /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers, |
| 486 | but then don't make the raw register names visible. */ |
| 487 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
| 488 | if (regno < gdbarch_num_regs (gdbarch)) |
| 489 | return ""; |
| 490 | |
| 491 | /* The MIPS integer registers are always mapped from 0 to 31. The |
| 492 | names of the registers (which reflects the conventions regarding |
| 493 | register use) vary depending on the ABI. */ |
| 494 | if (0 <= rawnum && rawnum < 32) |
| 495 | { |
| 496 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) |
| 497 | return mips_n32_n64_gpr_names[rawnum]; |
| 498 | else |
| 499 | return mips_gpr_names[rawnum]; |
| 500 | } |
| 501 | else if (tdesc_has_registers (gdbarch_target_desc (gdbarch))) |
| 502 | return tdesc_register_name (gdbarch, rawnum); |
| 503 | else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch)) |
| 504 | { |
| 505 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); |
| 506 | return tdep->mips_processor_reg_names[rawnum - 32]; |
| 507 | } |
| 508 | else |
| 509 | internal_error (__FILE__, __LINE__, |
| 510 | _("mips_register_name: bad register number %d"), rawnum); |
| 511 | } |
| 512 | |
| 513 | /* Return the groups that a MIPS register can be categorised into. */ |
| 514 | |
| 515 | static int |
| 516 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, |
| 517 | struct reggroup *reggroup) |
| 518 | { |
| 519 | int vector_p; |
| 520 | int float_p; |
| 521 | int raw_p; |
| 522 | int rawnum = regnum % gdbarch_num_regs (gdbarch); |
| 523 | int pseudo = regnum / gdbarch_num_regs (gdbarch); |
| 524 | if (reggroup == all_reggroup) |
| 525 | return pseudo; |
| 526 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); |
| 527 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; |
| 528 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs |
| 529 | (gdbarch), as not all architectures are multi-arch. */ |
| 530 | raw_p = rawnum < gdbarch_num_regs (gdbarch); |
| 531 | if (gdbarch_register_name (gdbarch, regnum) == NULL |
| 532 | || gdbarch_register_name (gdbarch, regnum)[0] == '\0') |
| 533 | return 0; |
| 534 | if (reggroup == float_reggroup) |
| 535 | return float_p && pseudo; |
| 536 | if (reggroup == vector_reggroup) |
| 537 | return vector_p && pseudo; |
| 538 | if (reggroup == general_reggroup) |
| 539 | return (!vector_p && !float_p) && pseudo; |
| 540 | /* Save the pseudo registers. Need to make certain that any code |
| 541 | extracting register values from a saved register cache also uses |
| 542 | pseudo registers. */ |
| 543 | if (reggroup == save_reggroup) |
| 544 | return raw_p && pseudo; |
| 545 | /* Restore the same pseudo register. */ |
| 546 | if (reggroup == restore_reggroup) |
| 547 | return raw_p && pseudo; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | /* Return the groups that a MIPS register can be categorised into. |
| 552 | This version is only used if we have a target description which |
| 553 | describes real registers (and their groups). */ |
| 554 | |
| 555 | static int |
| 556 | mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum, |
| 557 | struct reggroup *reggroup) |
| 558 | { |
| 559 | int rawnum = regnum % gdbarch_num_regs (gdbarch); |
| 560 | int pseudo = regnum / gdbarch_num_regs (gdbarch); |
| 561 | int ret; |
| 562 | |
| 563 | /* Only save, restore, and display the pseudo registers. Need to |
| 564 | make certain that any code extracting register values from a |
| 565 | saved register cache also uses pseudo registers. |
| 566 | |
| 567 | Note: saving and restoring the pseudo registers is slightly |
| 568 | strange; if we have 64 bits, we should save and restore all |
| 569 | 64 bits. But this is hard and has little benefit. */ |
| 570 | if (!pseudo) |
| 571 | return 0; |
| 572 | |
| 573 | ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup); |
| 574 | if (ret != -1) |
| 575 | return ret; |
| 576 | |
| 577 | return mips_register_reggroup_p (gdbarch, regnum, reggroup); |
| 578 | } |
| 579 | |
| 580 | /* Map the symbol table registers which live in the range [1 * |
| 581 | gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw |
| 582 | registers. Take care of alignment and size problems. */ |
| 583 | |
| 584 | static void |
| 585 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, |
| 586 | int cookednum, gdb_byte *buf) |
| 587 | { |
| 588 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
| 589 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) |
| 590 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); |
| 591 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
| 592 | regcache_raw_read (regcache, rawnum, buf); |
| 593 | else if (register_size (gdbarch, rawnum) > |
| 594 | register_size (gdbarch, cookednum)) |
| 595 | { |
| 596 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p |
| 597 | || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) |
| 598 | regcache_raw_read_part (regcache, rawnum, 0, 4, buf); |
| 599 | else |
| 600 | regcache_raw_read_part (regcache, rawnum, 4, 4, buf); |
| 601 | } |
| 602 | else |
| 603 | internal_error (__FILE__, __LINE__, _("bad register size")); |
| 604 | } |
| 605 | |
| 606 | static void |
| 607 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
| 608 | struct regcache *regcache, int cookednum, |
| 609 | const gdb_byte *buf) |
| 610 | { |
| 611 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
| 612 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) |
| 613 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); |
| 614 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
| 615 | regcache_raw_write (regcache, rawnum, buf); |
| 616 | else if (register_size (gdbarch, rawnum) > |
| 617 | register_size (gdbarch, cookednum)) |
| 618 | { |
| 619 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p |
| 620 | || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) |
| 621 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); |
| 622 | else |
| 623 | regcache_raw_write_part (regcache, rawnum, 4, 4, buf); |
| 624 | } |
| 625 | else |
| 626 | internal_error (__FILE__, __LINE__, _("bad register size")); |
| 627 | } |
| 628 | |
| 629 | /* Table to translate MIPS16 register field to actual register number. */ |
| 630 | static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
| 631 | |
| 632 | /* Heuristic_proc_start may hunt through the text section for a long |
| 633 | time across a 2400 baud serial line. Allows the user to limit this |
| 634 | search. */ |
| 635 | |
| 636 | static unsigned int heuristic_fence_post = 0; |
| 637 | |
| 638 | /* Number of bytes of storage in the actual machine representation for |
| 639 | register N. NOTE: This defines the pseudo register type so need to |
| 640 | rebuild the architecture vector. */ |
| 641 | |
| 642 | static int mips64_transfers_32bit_regs_p = 0; |
| 643 | |
| 644 | static void |
| 645 | set_mips64_transfers_32bit_regs (char *args, int from_tty, |
| 646 | struct cmd_list_element *c) |
| 647 | { |
| 648 | struct gdbarch_info info; |
| 649 | gdbarch_info_init (&info); |
| 650 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
| 651 | instead of relying on globals. Doing that would let generic code |
| 652 | handle the search for this specific architecture. */ |
| 653 | if (!gdbarch_update_p (info)) |
| 654 | { |
| 655 | mips64_transfers_32bit_regs_p = 0; |
| 656 | error (_("32-bit compatibility mode not supported")); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /* Convert to/from a register and the corresponding memory value. */ |
| 661 | |
| 662 | static int |
| 663 | mips_convert_register_p (struct gdbarch *gdbarch, int regnum, struct type *type) |
| 664 | { |
| 665 | return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
| 666 | && register_size (gdbarch, regnum) == 4 |
| 667 | && (regnum % gdbarch_num_regs (gdbarch)) |
| 668 | >= mips_regnum (gdbarch)->fp0 |
| 669 | && (regnum % gdbarch_num_regs (gdbarch)) |
| 670 | < mips_regnum (gdbarch)->fp0 + 32 |
| 671 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
| 672 | } |
| 673 | |
| 674 | static void |
| 675 | mips_register_to_value (struct frame_info *frame, int regnum, |
| 676 | struct type *type, gdb_byte *to) |
| 677 | { |
| 678 | get_frame_register (frame, regnum + 0, to + 4); |
| 679 | get_frame_register (frame, regnum + 1, to + 0); |
| 680 | } |
| 681 | |
| 682 | static void |
| 683 | mips_value_to_register (struct frame_info *frame, int regnum, |
| 684 | struct type *type, const gdb_byte *from) |
| 685 | { |
| 686 | put_frame_register (frame, regnum + 0, from + 4); |
| 687 | put_frame_register (frame, regnum + 1, from + 0); |
| 688 | } |
| 689 | |
| 690 | /* Return the GDB type object for the "standard" data type of data in |
| 691 | register REG. */ |
| 692 | |
| 693 | static struct type * |
| 694 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
| 695 | { |
| 696 | gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch)); |
| 697 | if ((regnum % gdbarch_num_regs (gdbarch)) >= mips_regnum (gdbarch)->fp0 |
| 698 | && (regnum % gdbarch_num_regs (gdbarch)) |
| 699 | < mips_regnum (gdbarch)->fp0 + 32) |
| 700 | { |
| 701 | /* The floating-point registers raw, or cooked, always match |
| 702 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
| 703 | if (mips_isa_regsize (gdbarch) == 4) |
| 704 | return builtin_type_ieee_single; |
| 705 | else |
| 706 | return builtin_type_ieee_double; |
| 707 | } |
| 708 | else if (regnum < gdbarch_num_regs (gdbarch)) |
| 709 | { |
| 710 | /* The raw or ISA registers. These are all sized according to |
| 711 | the ISA regsize. */ |
| 712 | if (mips_isa_regsize (gdbarch) == 4) |
| 713 | return builtin_type_int32; |
| 714 | else |
| 715 | return builtin_type_int64; |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | /* The cooked or ABI registers. These are sized according to |
| 720 | the ABI (with a few complications). */ |
| 721 | if (regnum >= (gdbarch_num_regs (gdbarch) |
| 722 | + mips_regnum (gdbarch)->fp_control_status) |
| 723 | && regnum <= gdbarch_num_regs (gdbarch) + MIPS_LAST_EMBED_REGNUM) |
| 724 | /* The pseudo/cooked view of the embedded registers is always |
| 725 | 32-bit. The raw view is handled below. */ |
| 726 | return builtin_type_int32; |
| 727 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
| 728 | /* The target, while possibly using a 64-bit register buffer, |
| 729 | is only transfering 32-bits of each integer register. |
| 730 | Reflect this in the cooked/pseudo (ABI) register value. */ |
| 731 | return builtin_type_int32; |
| 732 | else if (mips_abi_regsize (gdbarch) == 4) |
| 733 | /* The ABI is restricted to 32-bit registers (the ISA could be |
| 734 | 32- or 64-bit). */ |
| 735 | return builtin_type_int32; |
| 736 | else |
| 737 | /* 64-bit ABI. */ |
| 738 | return builtin_type_int64; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /* Return the GDB type for the pseudo register REGNUM, which is the |
| 743 | ABI-level view. This function is only called if there is a target |
| 744 | description which includes registers, so we know precisely the |
| 745 | types of hardware registers. */ |
| 746 | |
| 747 | static struct type * |
| 748 | mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum) |
| 749 | { |
| 750 | const int num_regs = gdbarch_num_regs (gdbarch); |
| 751 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 752 | int rawnum = regnum % num_regs; |
| 753 | struct type *rawtype; |
| 754 | |
| 755 | gdb_assert (regnum >= num_regs && regnum < 2 * num_regs); |
| 756 | |
| 757 | /* Absent registers are still absent. */ |
| 758 | rawtype = gdbarch_register_type (gdbarch, rawnum); |
| 759 | if (TYPE_LENGTH (rawtype) == 0) |
| 760 | return rawtype; |
| 761 | |
| 762 | if (rawnum >= MIPS_EMBED_FP0_REGNUM && rawnum < MIPS_EMBED_FP0_REGNUM + 32) |
| 763 | /* Present the floating point registers however the hardware did; |
| 764 | do not try to convert between FPU layouts. */ |
| 765 | return rawtype; |
| 766 | |
| 767 | if (rawnum >= MIPS_EMBED_FP0_REGNUM + 32 && rawnum <= MIPS_LAST_EMBED_REGNUM) |
| 768 | { |
| 769 | /* The pseudo/cooked view of embedded registers is always |
| 770 | 32-bit, even if the target transfers 64-bit values for them. |
| 771 | New targets relying on XML descriptions should only transfer |
| 772 | the necessary 32 bits, but older versions of GDB expected 64, |
| 773 | so allow the target to provide 64 bits without interfering |
| 774 | with the displayed type. */ |
| 775 | return builtin_type_int32; |
| 776 | } |
| 777 | |
| 778 | /* Use pointer types for registers if we can. For n32 we can not, |
| 779 | since we do not have a 64-bit pointer type. */ |
| 780 | if (mips_abi_regsize (gdbarch) == TYPE_LENGTH (builtin_type_void_data_ptr)) |
| 781 | { |
| 782 | if (rawnum == MIPS_SP_REGNUM || rawnum == MIPS_EMBED_BADVADDR_REGNUM) |
| 783 | return builtin_type_void_data_ptr; |
| 784 | else if (rawnum == MIPS_EMBED_PC_REGNUM) |
| 785 | return builtin_type_void_func_ptr; |
| 786 | } |
| 787 | |
| 788 | if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8 |
| 789 | && rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_EMBED_PC_REGNUM) |
| 790 | return builtin_type_int32; |
| 791 | |
| 792 | /* For all other registers, pass through the hardware type. */ |
| 793 | return rawtype; |
| 794 | } |
| 795 | |
| 796 | /* Should the upper word of 64-bit addresses be zeroed? */ |
| 797 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
| 798 | |
| 799 | static int |
| 800 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
| 801 | { |
| 802 | switch (mask_address_var) |
| 803 | { |
| 804 | case AUTO_BOOLEAN_TRUE: |
| 805 | return 1; |
| 806 | case AUTO_BOOLEAN_FALSE: |
| 807 | return 0; |
| 808 | break; |
| 809 | case AUTO_BOOLEAN_AUTO: |
| 810 | return tdep->default_mask_address_p; |
| 811 | default: |
| 812 | internal_error (__FILE__, __LINE__, _("mips_mask_address_p: bad switch")); |
| 813 | return -1; |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | static void |
| 818 | show_mask_address (struct ui_file *file, int from_tty, |
| 819 | struct cmd_list_element *c, const char *value) |
| 820 | { |
| 821 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
| 822 | |
| 823 | deprecated_show_value_hack (file, from_tty, c, value); |
| 824 | switch (mask_address_var) |
| 825 | { |
| 826 | case AUTO_BOOLEAN_TRUE: |
| 827 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
| 828 | break; |
| 829 | case AUTO_BOOLEAN_FALSE: |
| 830 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
| 831 | break; |
| 832 | case AUTO_BOOLEAN_AUTO: |
| 833 | printf_filtered |
| 834 | ("The 32 bit address mask is set automatically. Currently %s\n", |
| 835 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); |
| 836 | break; |
| 837 | default: |
| 838 | internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch")); |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
| 844 | |
| 845 | int |
| 846 | mips_pc_is_mips16 (CORE_ADDR memaddr) |
| 847 | { |
| 848 | struct minimal_symbol *sym; |
| 849 | |
| 850 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ |
| 851 | if (is_mips16_addr (memaddr)) |
| 852 | return 1; |
| 853 | |
| 854 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in |
| 855 | the high bit of the info field. Use this to decide if the function is |
| 856 | MIPS16 or normal MIPS. */ |
| 857 | sym = lookup_minimal_symbol_by_pc (memaddr); |
| 858 | if (sym) |
| 859 | return msymbol_is_special (sym); |
| 860 | else |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
| 865 | all registers should be sign extended for simplicity? */ |
| 866 | |
| 867 | static CORE_ADDR |
| 868 | mips_read_pc (struct regcache *regcache) |
| 869 | { |
| 870 | ULONGEST pc; |
| 871 | int regnum = mips_regnum (get_regcache_arch (regcache))->pc; |
| 872 | regcache_cooked_read_signed (regcache, regnum, &pc); |
| 873 | return pc; |
| 874 | } |
| 875 | |
| 876 | static CORE_ADDR |
| 877 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 878 | { |
| 879 | return frame_unwind_register_signed |
| 880 | (next_frame, gdbarch_num_regs (gdbarch) + mips_regnum (gdbarch)->pc); |
| 881 | } |
| 882 | |
| 883 | static CORE_ADDR |
| 884 | mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 885 | { |
| 886 | return frame_unwind_register_signed |
| 887 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM); |
| 888 | } |
| 889 | |
| 890 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that |
| 891 | dummy frame. The frame ID's base needs to match the TOS value |
| 892 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's |
| 893 | breakpoint. */ |
| 894 | |
| 895 | static struct frame_id |
| 896 | mips_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 897 | { |
| 898 | return frame_id_build |
| 899 | (frame_unwind_register_signed (next_frame, |
| 900 | gdbarch_num_regs (gdbarch) |
| 901 | + MIPS_SP_REGNUM), |
| 902 | frame_pc_unwind (next_frame)); |
| 903 | } |
| 904 | |
| 905 | static void |
| 906 | mips_write_pc (struct regcache *regcache, CORE_ADDR pc) |
| 907 | { |
| 908 | int regnum = mips_regnum (get_regcache_arch (regcache))->pc; |
| 909 | regcache_cooked_write_unsigned (regcache, regnum, pc); |
| 910 | } |
| 911 | |
| 912 | /* Fetch and return instruction from the specified location. If the PC |
| 913 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ |
| 914 | |
| 915 | static ULONGEST |
| 916 | mips_fetch_instruction (CORE_ADDR addr) |
| 917 | { |
| 918 | gdb_byte buf[MIPS_INSN32_SIZE]; |
| 919 | int instlen; |
| 920 | int status; |
| 921 | |
| 922 | if (mips_pc_is_mips16 (addr)) |
| 923 | { |
| 924 | instlen = MIPS_INSN16_SIZE; |
| 925 | addr = unmake_mips16_addr (addr); |
| 926 | } |
| 927 | else |
| 928 | instlen = MIPS_INSN32_SIZE; |
| 929 | status = read_memory_nobpt (addr, buf, instlen); |
| 930 | if (status) |
| 931 | memory_error (status, addr); |
| 932 | return extract_unsigned_integer (buf, instlen); |
| 933 | } |
| 934 | |
| 935 | /* These the fields of 32 bit mips instructions */ |
| 936 | #define mips32_op(x) (x >> 26) |
| 937 | #define itype_op(x) (x >> 26) |
| 938 | #define itype_rs(x) ((x >> 21) & 0x1f) |
| 939 | #define itype_rt(x) ((x >> 16) & 0x1f) |
| 940 | #define itype_immediate(x) (x & 0xffff) |
| 941 | |
| 942 | #define jtype_op(x) (x >> 26) |
| 943 | #define jtype_target(x) (x & 0x03ffffff) |
| 944 | |
| 945 | #define rtype_op(x) (x >> 26) |
| 946 | #define rtype_rs(x) ((x >> 21) & 0x1f) |
| 947 | #define rtype_rt(x) ((x >> 16) & 0x1f) |
| 948 | #define rtype_rd(x) ((x >> 11) & 0x1f) |
| 949 | #define rtype_shamt(x) ((x >> 6) & 0x1f) |
| 950 | #define rtype_funct(x) (x & 0x3f) |
| 951 | |
| 952 | static LONGEST |
| 953 | mips32_relative_offset (ULONGEST inst) |
| 954 | { |
| 955 | return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2; |
| 956 | } |
| 957 | |
| 958 | /* Determine where to set a single step breakpoint while considering |
| 959 | branch prediction. */ |
| 960 | static CORE_ADDR |
| 961 | mips32_next_pc (struct frame_info *frame, CORE_ADDR pc) |
| 962 | { |
| 963 | unsigned long inst; |
| 964 | int op; |
| 965 | inst = mips_fetch_instruction (pc); |
| 966 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */ |
| 967 | { |
| 968 | if (itype_op (inst) >> 2 == 5) |
| 969 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
| 970 | { |
| 971 | op = (itype_op (inst) & 0x03); |
| 972 | switch (op) |
| 973 | { |
| 974 | case 0: /* BEQL */ |
| 975 | goto equal_branch; |
| 976 | case 1: /* BNEL */ |
| 977 | goto neq_branch; |
| 978 | case 2: /* BLEZL */ |
| 979 | goto less_branch; |
| 980 | case 3: /* BGTZL */ |
| 981 | goto greater_branch; |
| 982 | default: |
| 983 | pc += 4; |
| 984 | } |
| 985 | } |
| 986 | else if (itype_op (inst) == 17 && itype_rs (inst) == 8) |
| 987 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
| 988 | { |
| 989 | int tf = itype_rt (inst) & 0x01; |
| 990 | int cnum = itype_rt (inst) >> 2; |
| 991 | int fcrcs = |
| 992 | get_frame_register_signed (frame, |
| 993 | mips_regnum (get_frame_arch (frame))-> |
| 994 | fp_control_status); |
| 995 | int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01); |
| 996 | |
| 997 | if (((cond >> cnum) & 0x01) == tf) |
| 998 | pc += mips32_relative_offset (inst) + 4; |
| 999 | else |
| 1000 | pc += 8; |
| 1001 | } |
| 1002 | else |
| 1003 | pc += 4; /* Not a branch, next instruction is easy */ |
| 1004 | } |
| 1005 | else |
| 1006 | { /* This gets way messy */ |
| 1007 | |
| 1008 | /* Further subdivide into SPECIAL, REGIMM and other */ |
| 1009 | switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */ |
| 1010 | { |
| 1011 | case 0: /* SPECIAL */ |
| 1012 | op = rtype_funct (inst); |
| 1013 | switch (op) |
| 1014 | { |
| 1015 | case 8: /* JR */ |
| 1016 | case 9: /* JALR */ |
| 1017 | /* Set PC to that address */ |
| 1018 | pc = get_frame_register_signed (frame, rtype_rs (inst)); |
| 1019 | break; |
| 1020 | default: |
| 1021 | pc += 4; |
| 1022 | } |
| 1023 | |
| 1024 | break; /* end SPECIAL */ |
| 1025 | case 1: /* REGIMM */ |
| 1026 | { |
| 1027 | op = itype_rt (inst); /* branch condition */ |
| 1028 | switch (op) |
| 1029 | { |
| 1030 | case 0: /* BLTZ */ |
| 1031 | case 2: /* BLTZL */ |
| 1032 | case 16: /* BLTZAL */ |
| 1033 | case 18: /* BLTZALL */ |
| 1034 | less_branch: |
| 1035 | if (get_frame_register_signed (frame, itype_rs (inst)) < 0) |
| 1036 | pc += mips32_relative_offset (inst) + 4; |
| 1037 | else |
| 1038 | pc += 8; /* after the delay slot */ |
| 1039 | break; |
| 1040 | case 1: /* BGEZ */ |
| 1041 | case 3: /* BGEZL */ |
| 1042 | case 17: /* BGEZAL */ |
| 1043 | case 19: /* BGEZALL */ |
| 1044 | if (get_frame_register_signed (frame, itype_rs (inst)) >= 0) |
| 1045 | pc += mips32_relative_offset (inst) + 4; |
| 1046 | else |
| 1047 | pc += 8; /* after the delay slot */ |
| 1048 | break; |
| 1049 | /* All of the other instructions in the REGIMM category */ |
| 1050 | default: |
| 1051 | pc += 4; |
| 1052 | } |
| 1053 | } |
| 1054 | break; /* end REGIMM */ |
| 1055 | case 2: /* J */ |
| 1056 | case 3: /* JAL */ |
| 1057 | { |
| 1058 | unsigned long reg; |
| 1059 | reg = jtype_target (inst) << 2; |
| 1060 | /* Upper four bits get never changed... */ |
| 1061 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); |
| 1062 | } |
| 1063 | break; |
| 1064 | /* FIXME case JALX : */ |
| 1065 | { |
| 1066 | unsigned long reg; |
| 1067 | reg = jtype_target (inst) << 2; |
| 1068 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + 1; /* yes, +1 */ |
| 1069 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
| 1070 | } |
| 1071 | break; /* The new PC will be alternate mode */ |
| 1072 | case 4: /* BEQ, BEQL */ |
| 1073 | equal_branch: |
| 1074 | if (get_frame_register_signed (frame, itype_rs (inst)) == |
| 1075 | get_frame_register_signed (frame, itype_rt (inst))) |
| 1076 | pc += mips32_relative_offset (inst) + 4; |
| 1077 | else |
| 1078 | pc += 8; |
| 1079 | break; |
| 1080 | case 5: /* BNE, BNEL */ |
| 1081 | neq_branch: |
| 1082 | if (get_frame_register_signed (frame, itype_rs (inst)) != |
| 1083 | get_frame_register_signed (frame, itype_rt (inst))) |
| 1084 | pc += mips32_relative_offset (inst) + 4; |
| 1085 | else |
| 1086 | pc += 8; |
| 1087 | break; |
| 1088 | case 6: /* BLEZ, BLEZL */ |
| 1089 | if (get_frame_register_signed (frame, itype_rs (inst)) <= 0) |
| 1090 | pc += mips32_relative_offset (inst) + 4; |
| 1091 | else |
| 1092 | pc += 8; |
| 1093 | break; |
| 1094 | case 7: |
| 1095 | default: |
| 1096 | greater_branch: /* BGTZ, BGTZL */ |
| 1097 | if (get_frame_register_signed (frame, itype_rs (inst)) > 0) |
| 1098 | pc += mips32_relative_offset (inst) + 4; |
| 1099 | else |
| 1100 | pc += 8; |
| 1101 | break; |
| 1102 | } /* switch */ |
| 1103 | } /* else */ |
| 1104 | return pc; |
| 1105 | } /* mips32_next_pc */ |
| 1106 | |
| 1107 | /* Decoding the next place to set a breakpoint is irregular for the |
| 1108 | mips 16 variant, but fortunately, there fewer instructions. We have to cope |
| 1109 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
| 1110 | We dont want to set a single step instruction on the extend instruction |
| 1111 | either. |
| 1112 | */ |
| 1113 | |
| 1114 | /* Lots of mips16 instruction formats */ |
| 1115 | /* Predicting jumps requires itype,ritype,i8type |
| 1116 | and their extensions extItype,extritype,extI8type |
| 1117 | */ |
| 1118 | enum mips16_inst_fmts |
| 1119 | { |
| 1120 | itype, /* 0 immediate 5,10 */ |
| 1121 | ritype, /* 1 5,3,8 */ |
| 1122 | rrtype, /* 2 5,3,3,5 */ |
| 1123 | rritype, /* 3 5,3,3,5 */ |
| 1124 | rrrtype, /* 4 5,3,3,3,2 */ |
| 1125 | rriatype, /* 5 5,3,3,1,4 */ |
| 1126 | shifttype, /* 6 5,3,3,3,2 */ |
| 1127 | i8type, /* 7 5,3,8 */ |
| 1128 | i8movtype, /* 8 5,3,3,5 */ |
| 1129 | i8mov32rtype, /* 9 5,3,5,3 */ |
| 1130 | i64type, /* 10 5,3,8 */ |
| 1131 | ri64type, /* 11 5,3,3,5 */ |
| 1132 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ |
| 1133 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ |
| 1134 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ |
| 1135 | extRRItype, /* 15 5,5,5,5,3,3,5 */ |
| 1136 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ |
| 1137 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ |
| 1138 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ |
| 1139 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ |
| 1140 | extRi64type, /* 20 5,6,5,5,3,3,5 */ |
| 1141 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ |
| 1142 | }; |
| 1143 | /* I am heaping all the fields of the formats into one structure and |
| 1144 | then, only the fields which are involved in instruction extension */ |
| 1145 | struct upk_mips16 |
| 1146 | { |
| 1147 | CORE_ADDR offset; |
| 1148 | unsigned int regx; /* Function in i8 type */ |
| 1149 | unsigned int regy; |
| 1150 | }; |
| 1151 | |
| 1152 | |
| 1153 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
| 1154 | for the bits which make up the immediate extension. */ |
| 1155 | |
| 1156 | static CORE_ADDR |
| 1157 | extended_offset (unsigned int extension) |
| 1158 | { |
| 1159 | CORE_ADDR value; |
| 1160 | value = (extension >> 21) & 0x3f; /* * extract 15:11 */ |
| 1161 | value = value << 6; |
| 1162 | value |= (extension >> 16) & 0x1f; /* extrace 10:5 */ |
| 1163 | value = value << 5; |
| 1164 | value |= extension & 0x01f; /* extract 4:0 */ |
| 1165 | return value; |
| 1166 | } |
| 1167 | |
| 1168 | /* Only call this function if you know that this is an extendable |
| 1169 | instruction. It won't malfunction, but why make excess remote memory |
| 1170 | references? If the immediate operands get sign extended or something, |
| 1171 | do it after the extension is performed. */ |
| 1172 | /* FIXME: Every one of these cases needs to worry about sign extension |
| 1173 | when the offset is to be used in relative addressing. */ |
| 1174 | |
| 1175 | static unsigned int |
| 1176 | fetch_mips_16 (CORE_ADDR pc) |
| 1177 | { |
| 1178 | gdb_byte buf[8]; |
| 1179 | pc &= 0xfffffffe; /* clear the low order bit */ |
| 1180 | target_read_memory (pc, buf, 2); |
| 1181 | return extract_unsigned_integer (buf, 2); |
| 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | unpack_mips16 (CORE_ADDR pc, |
| 1186 | unsigned int extension, |
| 1187 | unsigned int inst, |
| 1188 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
| 1189 | { |
| 1190 | CORE_ADDR offset; |
| 1191 | int regx; |
| 1192 | int regy; |
| 1193 | switch (insn_format) |
| 1194 | { |
| 1195 | case itype: |
| 1196 | { |
| 1197 | CORE_ADDR value; |
| 1198 | if (extension) |
| 1199 | { |
| 1200 | value = extended_offset (extension); |
| 1201 | value = value << 11; /* rom for the original value */ |
| 1202 | value |= inst & 0x7ff; /* eleven bits from instruction */ |
| 1203 | } |
| 1204 | else |
| 1205 | { |
| 1206 | value = inst & 0x7ff; |
| 1207 | /* FIXME : Consider sign extension */ |
| 1208 | } |
| 1209 | offset = value; |
| 1210 | regx = -1; |
| 1211 | regy = -1; |
| 1212 | } |
| 1213 | break; |
| 1214 | case ritype: |
| 1215 | case i8type: |
| 1216 | { /* A register identifier and an offset */ |
| 1217 | /* Most of the fields are the same as I type but the |
| 1218 | immediate value is of a different length */ |
| 1219 | CORE_ADDR value; |
| 1220 | if (extension) |
| 1221 | { |
| 1222 | value = extended_offset (extension); |
| 1223 | value = value << 8; /* from the original instruction */ |
| 1224 | value |= inst & 0xff; /* eleven bits from instruction */ |
| 1225 | regx = (extension >> 8) & 0x07; /* or i8 funct */ |
| 1226 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
| 1227 | { |
| 1228 | value &= ~0x3fff; /* remove the sign bit */ |
| 1229 | value = -value; |
| 1230 | } |
| 1231 | } |
| 1232 | else |
| 1233 | { |
| 1234 | value = inst & 0xff; /* 8 bits */ |
| 1235 | regx = (inst >> 8) & 0x07; /* or i8 funct */ |
| 1236 | /* FIXME: Do sign extension , this format needs it */ |
| 1237 | if (value & 0x80) /* THIS CONFUSES ME */ |
| 1238 | { |
| 1239 | value &= 0xef; /* remove the sign bit */ |
| 1240 | value = -value; |
| 1241 | } |
| 1242 | } |
| 1243 | offset = value; |
| 1244 | regy = -1; |
| 1245 | break; |
| 1246 | } |
| 1247 | case jalxtype: |
| 1248 | { |
| 1249 | unsigned long value; |
| 1250 | unsigned int nexthalf; |
| 1251 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); |
| 1252 | value = value << 16; |
| 1253 | nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */ |
| 1254 | value |= nexthalf; |
| 1255 | offset = value; |
| 1256 | regx = -1; |
| 1257 | regy = -1; |
| 1258 | break; |
| 1259 | } |
| 1260 | default: |
| 1261 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 1262 | } |
| 1263 | upk->offset = offset; |
| 1264 | upk->regx = regx; |
| 1265 | upk->regy = regy; |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | static CORE_ADDR |
| 1270 | add_offset_16 (CORE_ADDR pc, int offset) |
| 1271 | { |
| 1272 | return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff))); |
| 1273 | } |
| 1274 | |
| 1275 | static CORE_ADDR |
| 1276 | extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc, |
| 1277 | unsigned int extension, unsigned int insn) |
| 1278 | { |
| 1279 | int op = (insn >> 11); |
| 1280 | switch (op) |
| 1281 | { |
| 1282 | case 2: /* Branch */ |
| 1283 | { |
| 1284 | CORE_ADDR offset; |
| 1285 | struct upk_mips16 upk; |
| 1286 | unpack_mips16 (pc, extension, insn, itype, &upk); |
| 1287 | offset = upk.offset; |
| 1288 | if (offset & 0x800) |
| 1289 | { |
| 1290 | offset &= 0xeff; |
| 1291 | offset = -offset; |
| 1292 | } |
| 1293 | pc += (offset << 1) + 2; |
| 1294 | break; |
| 1295 | } |
| 1296 | case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */ |
| 1297 | { |
| 1298 | struct upk_mips16 upk; |
| 1299 | unpack_mips16 (pc, extension, insn, jalxtype, &upk); |
| 1300 | pc = add_offset_16 (pc, upk.offset); |
| 1301 | if ((insn >> 10) & 0x01) /* Exchange mode */ |
| 1302 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */ |
| 1303 | else |
| 1304 | pc |= 0x01; |
| 1305 | break; |
| 1306 | } |
| 1307 | case 4: /* beqz */ |
| 1308 | { |
| 1309 | struct upk_mips16 upk; |
| 1310 | int reg; |
| 1311 | unpack_mips16 (pc, extension, insn, ritype, &upk); |
| 1312 | reg = get_frame_register_signed (frame, upk.regx); |
| 1313 | if (reg == 0) |
| 1314 | pc += (upk.offset << 1) + 2; |
| 1315 | else |
| 1316 | pc += 2; |
| 1317 | break; |
| 1318 | } |
| 1319 | case 5: /* bnez */ |
| 1320 | { |
| 1321 | struct upk_mips16 upk; |
| 1322 | int reg; |
| 1323 | unpack_mips16 (pc, extension, insn, ritype, &upk); |
| 1324 | reg = get_frame_register_signed (frame, upk.regx); |
| 1325 | if (reg != 0) |
| 1326 | pc += (upk.offset << 1) + 2; |
| 1327 | else |
| 1328 | pc += 2; |
| 1329 | break; |
| 1330 | } |
| 1331 | case 12: /* I8 Formats btez btnez */ |
| 1332 | { |
| 1333 | struct upk_mips16 upk; |
| 1334 | int reg; |
| 1335 | unpack_mips16 (pc, extension, insn, i8type, &upk); |
| 1336 | /* upk.regx contains the opcode */ |
| 1337 | reg = get_frame_register_signed (frame, 24); /* Test register is 24 */ |
| 1338 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ |
| 1339 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ |
| 1340 | /* pc = add_offset_16(pc,upk.offset) ; */ |
| 1341 | pc += (upk.offset << 1) + 2; |
| 1342 | else |
| 1343 | pc += 2; |
| 1344 | break; |
| 1345 | } |
| 1346 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
| 1347 | { |
| 1348 | struct upk_mips16 upk; |
| 1349 | /* upk.fmt = rrtype; */ |
| 1350 | op = insn & 0x1f; |
| 1351 | if (op == 0) |
| 1352 | { |
| 1353 | int reg; |
| 1354 | upk.regx = (insn >> 8) & 0x07; |
| 1355 | upk.regy = (insn >> 5) & 0x07; |
| 1356 | switch (upk.regy) |
| 1357 | { |
| 1358 | case 0: |
| 1359 | reg = upk.regx; |
| 1360 | break; |
| 1361 | case 1: |
| 1362 | reg = 31; |
| 1363 | break; /* Function return instruction */ |
| 1364 | case 2: |
| 1365 | reg = upk.regx; |
| 1366 | break; |
| 1367 | default: |
| 1368 | reg = 31; |
| 1369 | break; /* BOGUS Guess */ |
| 1370 | } |
| 1371 | pc = get_frame_register_signed (frame, reg); |
| 1372 | } |
| 1373 | else |
| 1374 | pc += 2; |
| 1375 | break; |
| 1376 | } |
| 1377 | case 30: |
| 1378 | /* This is an instruction extension. Fetch the real instruction |
| 1379 | (which follows the extension) and decode things based on |
| 1380 | that. */ |
| 1381 | { |
| 1382 | pc += 2; |
| 1383 | pc = extended_mips16_next_pc (frame, pc, insn, fetch_mips_16 (pc)); |
| 1384 | break; |
| 1385 | } |
| 1386 | default: |
| 1387 | { |
| 1388 | pc += 2; |
| 1389 | break; |
| 1390 | } |
| 1391 | } |
| 1392 | return pc; |
| 1393 | } |
| 1394 | |
| 1395 | static CORE_ADDR |
| 1396 | mips16_next_pc (struct frame_info *frame, CORE_ADDR pc) |
| 1397 | { |
| 1398 | unsigned int insn = fetch_mips_16 (pc); |
| 1399 | return extended_mips16_next_pc (frame, pc, 0, insn); |
| 1400 | } |
| 1401 | |
| 1402 | /* The mips_next_pc function supports single_step when the remote |
| 1403 | target monitor or stub is not developed enough to do a single_step. |
| 1404 | It works by decoding the current instruction and predicting where a |
| 1405 | branch will go. This isnt hard because all the data is available. |
| 1406 | The MIPS32 and MIPS16 variants are quite different. */ |
| 1407 | static CORE_ADDR |
| 1408 | mips_next_pc (struct frame_info *frame, CORE_ADDR pc) |
| 1409 | { |
| 1410 | if (is_mips16_addr (pc)) |
| 1411 | return mips16_next_pc (frame, pc); |
| 1412 | else |
| 1413 | return mips32_next_pc (frame, pc); |
| 1414 | } |
| 1415 | |
| 1416 | struct mips_frame_cache |
| 1417 | { |
| 1418 | CORE_ADDR base; |
| 1419 | struct trad_frame_saved_reg *saved_regs; |
| 1420 | }; |
| 1421 | |
| 1422 | /* Set a register's saved stack address in temp_saved_regs. If an |
| 1423 | address has already been set for this register, do nothing; this |
| 1424 | way we will only recognize the first save of a given register in a |
| 1425 | function prologue. |
| 1426 | |
| 1427 | For simplicity, save the address in both [0 .. gdbarch_num_regs) and |
| 1428 | [gdbarch_num_regs .. 2*gdbarch_num_regs). |
| 1429 | Strictly speaking, only the second range is used as it is only second |
| 1430 | range (the ABI instead of ISA registers) that comes into play when finding |
| 1431 | saved registers in a frame. */ |
| 1432 | |
| 1433 | static void |
| 1434 | set_reg_offset (struct mips_frame_cache *this_cache, int regnum, |
| 1435 | CORE_ADDR offset) |
| 1436 | { |
| 1437 | if (this_cache != NULL |
| 1438 | && this_cache->saved_regs[regnum].addr == -1) |
| 1439 | { |
| 1440 | this_cache->saved_regs[regnum |
| 1441 | + 0 * gdbarch_num_regs (current_gdbarch)].addr |
| 1442 | = offset; |
| 1443 | this_cache->saved_regs[regnum |
| 1444 | + 1 * gdbarch_num_regs (current_gdbarch)].addr |
| 1445 | = offset; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | /* Fetch the immediate value from a MIPS16 instruction. |
| 1451 | If the previous instruction was an EXTEND, use it to extend |
| 1452 | the upper bits of the immediate value. This is a helper function |
| 1453 | for mips16_scan_prologue. */ |
| 1454 | |
| 1455 | static int |
| 1456 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ |
| 1457 | unsigned short inst, /* current instruction */ |
| 1458 | int nbits, /* number of bits in imm field */ |
| 1459 | int scale, /* scale factor to be applied to imm */ |
| 1460 | int is_signed) /* is the imm field signed? */ |
| 1461 | { |
| 1462 | int offset; |
| 1463 | |
| 1464 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
| 1465 | { |
| 1466 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); |
| 1467 | if (offset & 0x8000) /* check for negative extend */ |
| 1468 | offset = 0 - (0x10000 - (offset & 0xffff)); |
| 1469 | return offset | (inst & 0x1f); |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1473 | int max_imm = 1 << nbits; |
| 1474 | int mask = max_imm - 1; |
| 1475 | int sign_bit = max_imm >> 1; |
| 1476 | |
| 1477 | offset = inst & mask; |
| 1478 | if (is_signed && (offset & sign_bit)) |
| 1479 | offset = 0 - (max_imm - offset); |
| 1480 | return offset * scale; |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | |
| 1485 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
| 1486 | the associated FRAME_CACHE if not null. |
| 1487 | Return the address of the first instruction past the prologue. */ |
| 1488 | |
| 1489 | static CORE_ADDR |
| 1490 | mips16_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
| 1491 | struct frame_info *next_frame, |
| 1492 | struct mips_frame_cache *this_cache) |
| 1493 | { |
| 1494 | CORE_ADDR cur_pc; |
| 1495 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ |
| 1496 | CORE_ADDR sp; |
| 1497 | long frame_offset = 0; /* Size of stack frame. */ |
| 1498 | long frame_adjust = 0; /* Offset of FP from SP. */ |
| 1499 | int frame_reg = MIPS_SP_REGNUM; |
| 1500 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ |
| 1501 | unsigned inst = 0; /* current instruction */ |
| 1502 | unsigned entry_inst = 0; /* the entry instruction */ |
| 1503 | unsigned save_inst = 0; /* the save instruction */ |
| 1504 | int reg, offset; |
| 1505 | |
| 1506 | int extend_bytes = 0; |
| 1507 | int prev_extend_bytes; |
| 1508 | CORE_ADDR end_prologue_addr = 0; |
| 1509 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
| 1510 | |
| 1511 | /* Can be called when there's no process, and hence when there's no |
| 1512 | NEXT_FRAME. */ |
| 1513 | if (next_frame != NULL) |
| 1514 | sp = frame_unwind_register_signed (next_frame, |
| 1515 | gdbarch_num_regs (gdbarch) |
| 1516 | + MIPS_SP_REGNUM); |
| 1517 | else |
| 1518 | sp = 0; |
| 1519 | |
| 1520 | if (limit_pc > start_pc + 200) |
| 1521 | limit_pc = start_pc + 200; |
| 1522 | |
| 1523 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE) |
| 1524 | { |
| 1525 | /* Save the previous instruction. If it's an EXTEND, we'll extract |
| 1526 | the immediate offset extension from it in mips16_get_imm. */ |
| 1527 | prev_inst = inst; |
| 1528 | |
| 1529 | /* Fetch and decode the instruction. */ |
| 1530 | inst = (unsigned short) mips_fetch_instruction (cur_pc); |
| 1531 | |
| 1532 | /* Normally we ignore extend instructions. However, if it is |
| 1533 | not followed by a valid prologue instruction, then this |
| 1534 | instruction is not part of the prologue either. We must |
| 1535 | remember in this case to adjust the end_prologue_addr back |
| 1536 | over the extend. */ |
| 1537 | if ((inst & 0xf800) == 0xf000) /* extend */ |
| 1538 | { |
| 1539 | extend_bytes = MIPS_INSN16_SIZE; |
| 1540 | continue; |
| 1541 | } |
| 1542 | |
| 1543 | prev_extend_bytes = extend_bytes; |
| 1544 | extend_bytes = 0; |
| 1545 | |
| 1546 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
| 1547 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
| 1548 | { |
| 1549 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); |
| 1550 | if (offset < 0) /* negative stack adjustment? */ |
| 1551 | frame_offset -= offset; |
| 1552 | else |
| 1553 | /* Exit loop if a positive stack adjustment is found, which |
| 1554 | usually means that the stack cleanup code in the function |
| 1555 | epilogue is reached. */ |
| 1556 | break; |
| 1557 | } |
| 1558 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ |
| 1559 | { |
| 1560 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1561 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; |
| 1562 | set_reg_offset (this_cache, reg, sp + offset); |
| 1563 | } |
| 1564 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ |
| 1565 | { |
| 1566 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); |
| 1567 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1568 | set_reg_offset (this_cache, reg, sp + offset); |
| 1569 | } |
| 1570 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ |
| 1571 | { |
| 1572 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1573 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
| 1574 | } |
| 1575 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ |
| 1576 | { |
| 1577 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); |
| 1578 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
| 1579 | } |
| 1580 | else if (inst == 0x673d) /* move $s1, $sp */ |
| 1581 | { |
| 1582 | frame_addr = sp; |
| 1583 | frame_reg = 17; |
| 1584 | } |
| 1585 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ |
| 1586 | { |
| 1587 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1588 | frame_addr = sp + offset; |
| 1589 | frame_reg = 17; |
| 1590 | frame_adjust = offset; |
| 1591 | } |
| 1592 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ |
| 1593 | { |
| 1594 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); |
| 1595 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1596 | set_reg_offset (this_cache, reg, frame_addr + offset); |
| 1597 | } |
| 1598 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ |
| 1599 | { |
| 1600 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); |
| 1601 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1602 | set_reg_offset (this_cache, reg, frame_addr + offset); |
| 1603 | } |
| 1604 | else if ((inst & 0xf81f) == 0xe809 |
| 1605 | && (inst & 0x700) != 0x700) /* entry */ |
| 1606 | entry_inst = inst; /* save for later processing */ |
| 1607 | else if ((inst & 0xff80) == 0x6480) /* save */ |
| 1608 | { |
| 1609 | save_inst = inst; /* save for later processing */ |
| 1610 | if (prev_extend_bytes) /* extend */ |
| 1611 | save_inst |= prev_inst << 16; |
| 1612 | } |
| 1613 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
| 1614 | cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */ |
| 1615 | else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */ |
| 1616 | { |
| 1617 | /* This instruction is part of the prologue, but we don't |
| 1618 | need to do anything special to handle it. */ |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | /* This instruction is not an instruction typically found |
| 1623 | in a prologue, so we must have reached the end of the |
| 1624 | prologue. */ |
| 1625 | if (end_prologue_addr == 0) |
| 1626 | end_prologue_addr = cur_pc - prev_extend_bytes; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | /* The entry instruction is typically the first instruction in a function, |
| 1631 | and it stores registers at offsets relative to the value of the old SP |
| 1632 | (before the prologue). But the value of the sp parameter to this |
| 1633 | function is the new SP (after the prologue has been executed). So we |
| 1634 | can't calculate those offsets until we've seen the entire prologue, |
| 1635 | and can calculate what the old SP must have been. */ |
| 1636 | if (entry_inst != 0) |
| 1637 | { |
| 1638 | int areg_count = (entry_inst >> 8) & 7; |
| 1639 | int sreg_count = (entry_inst >> 6) & 3; |
| 1640 | |
| 1641 | /* The entry instruction always subtracts 32 from the SP. */ |
| 1642 | frame_offset += 32; |
| 1643 | |
| 1644 | /* Now we can calculate what the SP must have been at the |
| 1645 | start of the function prologue. */ |
| 1646 | sp += frame_offset; |
| 1647 | |
| 1648 | /* Check if a0-a3 were saved in the caller's argument save area. */ |
| 1649 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) |
| 1650 | { |
| 1651 | set_reg_offset (this_cache, reg, sp + offset); |
| 1652 | offset += mips_abi_regsize (gdbarch); |
| 1653 | } |
| 1654 | |
| 1655 | /* Check if the ra register was pushed on the stack. */ |
| 1656 | offset = -4; |
| 1657 | if (entry_inst & 0x20) |
| 1658 | { |
| 1659 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
| 1660 | offset -= mips_abi_regsize (gdbarch); |
| 1661 | } |
| 1662 | |
| 1663 | /* Check if the s0 and s1 registers were pushed on the stack. */ |
| 1664 | for (reg = 16; reg < sreg_count + 16; reg++) |
| 1665 | { |
| 1666 | set_reg_offset (this_cache, reg, sp + offset); |
| 1667 | offset -= mips_abi_regsize (gdbarch); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /* The SAVE instruction is similar to ENTRY, except that defined by the |
| 1672 | MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the |
| 1673 | size of the frame is specified as an immediate field of instruction |
| 1674 | and an extended variation exists which lets additional registers and |
| 1675 | frame space to be specified. The instruction always treats registers |
| 1676 | as 32-bit so its usefulness for 64-bit ABIs is questionable. */ |
| 1677 | if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4) |
| 1678 | { |
| 1679 | static int args_table[16] = { |
| 1680 | 0, 0, 0, 0, 1, 1, 1, 1, |
| 1681 | 2, 2, 2, 0, 3, 3, 4, -1, |
| 1682 | }; |
| 1683 | static int astatic_table[16] = { |
| 1684 | 0, 1, 2, 3, 0, 1, 2, 3, |
| 1685 | 0, 1, 2, 4, 0, 1, 0, -1, |
| 1686 | }; |
| 1687 | int aregs = (save_inst >> 16) & 0xf; |
| 1688 | int xsregs = (save_inst >> 24) & 0x7; |
| 1689 | int args = args_table[aregs]; |
| 1690 | int astatic = astatic_table[aregs]; |
| 1691 | long frame_size; |
| 1692 | |
| 1693 | if (args < 0) |
| 1694 | { |
| 1695 | warning (_("Invalid number of argument registers encoded in SAVE.")); |
| 1696 | args = 0; |
| 1697 | } |
| 1698 | if (astatic < 0) |
| 1699 | { |
| 1700 | warning (_("Invalid number of static registers encoded in SAVE.")); |
| 1701 | astatic = 0; |
| 1702 | } |
| 1703 | |
| 1704 | /* For standard SAVE the frame size of 0 means 128. */ |
| 1705 | frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf); |
| 1706 | if (frame_size == 0 && (save_inst >> 16) == 0) |
| 1707 | frame_size = 16; |
| 1708 | frame_size *= 8; |
| 1709 | frame_offset += frame_size; |
| 1710 | |
| 1711 | /* Now we can calculate what the SP must have been at the |
| 1712 | start of the function prologue. */ |
| 1713 | sp += frame_offset; |
| 1714 | |
| 1715 | /* Check if A0-A3 were saved in the caller's argument save area. */ |
| 1716 | for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++) |
| 1717 | { |
| 1718 | set_reg_offset (this_cache, reg, sp + offset); |
| 1719 | offset += mips_abi_regsize (gdbarch); |
| 1720 | } |
| 1721 | |
| 1722 | offset = -4; |
| 1723 | |
| 1724 | /* Check if the RA register was pushed on the stack. */ |
| 1725 | if (save_inst & 0x40) |
| 1726 | { |
| 1727 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
| 1728 | offset -= mips_abi_regsize (gdbarch); |
| 1729 | } |
| 1730 | |
| 1731 | /* Check if the S8 register was pushed on the stack. */ |
| 1732 | if (xsregs > 6) |
| 1733 | { |
| 1734 | set_reg_offset (this_cache, 30, sp + offset); |
| 1735 | offset -= mips_abi_regsize (gdbarch); |
| 1736 | xsregs--; |
| 1737 | } |
| 1738 | /* Check if S2-S7 were pushed on the stack. */ |
| 1739 | for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--) |
| 1740 | { |
| 1741 | set_reg_offset (this_cache, reg, sp + offset); |
| 1742 | offset -= mips_abi_regsize (gdbarch); |
| 1743 | } |
| 1744 | |
| 1745 | /* Check if the S1 register was pushed on the stack. */ |
| 1746 | if (save_inst & 0x10) |
| 1747 | { |
| 1748 | set_reg_offset (this_cache, 17, sp + offset); |
| 1749 | offset -= mips_abi_regsize (gdbarch); |
| 1750 | } |
| 1751 | /* Check if the S0 register was pushed on the stack. */ |
| 1752 | if (save_inst & 0x20) |
| 1753 | { |
| 1754 | set_reg_offset (this_cache, 16, sp + offset); |
| 1755 | offset -= mips_abi_regsize (gdbarch); |
| 1756 | } |
| 1757 | |
| 1758 | /* Check if A0-A3 were pushed on the stack. */ |
| 1759 | for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--) |
| 1760 | { |
| 1761 | set_reg_offset (this_cache, reg, sp + offset); |
| 1762 | offset -= mips_abi_regsize (gdbarch); |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | if (this_cache != NULL) |
| 1767 | { |
| 1768 | this_cache->base = |
| 1769 | (frame_unwind_register_signed (next_frame, |
| 1770 | gdbarch_num_regs (gdbarch) + frame_reg) |
| 1771 | + frame_offset - frame_adjust); |
| 1772 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should |
| 1773 | be able to get rid of the assignment below, evetually. But it's |
| 1774 | still needed for now. */ |
| 1775 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
| 1776 | + mips_regnum (gdbarch)->pc] |
| 1777 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM]; |
| 1778 | } |
| 1779 | |
| 1780 | /* If we didn't reach the end of the prologue when scanning the function |
| 1781 | instructions, then set end_prologue_addr to the address of the |
| 1782 | instruction immediately after the last one we scanned. */ |
| 1783 | if (end_prologue_addr == 0) |
| 1784 | end_prologue_addr = cur_pc; |
| 1785 | |
| 1786 | return end_prologue_addr; |
| 1787 | } |
| 1788 | |
| 1789 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). |
| 1790 | Procedures that use the 32-bit instruction set are handled by the |
| 1791 | mips_insn32 unwinder. */ |
| 1792 | |
| 1793 | static struct mips_frame_cache * |
| 1794 | mips_insn16_frame_cache (struct frame_info *next_frame, void **this_cache) |
| 1795 | { |
| 1796 | struct mips_frame_cache *cache; |
| 1797 | |
| 1798 | if ((*this_cache) != NULL) |
| 1799 | return (*this_cache); |
| 1800 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
| 1801 | (*this_cache) = cache; |
| 1802 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); |
| 1803 | |
| 1804 | /* Analyze the function prologue. */ |
| 1805 | { |
| 1806 | const CORE_ADDR pc = |
| 1807 | frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
| 1808 | CORE_ADDR start_addr; |
| 1809 | |
| 1810 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
| 1811 | if (start_addr == 0) |
| 1812 | start_addr = heuristic_proc_start (pc); |
| 1813 | /* We can't analyze the prologue if we couldn't find the begining |
| 1814 | of the function. */ |
| 1815 | if (start_addr == 0) |
| 1816 | return cache; |
| 1817 | |
| 1818 | mips16_scan_prologue (start_addr, pc, next_frame, *this_cache); |
| 1819 | } |
| 1820 | |
| 1821 | /* gdbarch_sp_regnum contains the value and not the address. */ |
| 1822 | trad_frame_set_value (cache->saved_regs, |
| 1823 | gdbarch_num_regs (get_frame_arch (next_frame)) |
| 1824 | + MIPS_SP_REGNUM, |
| 1825 | cache->base); |
| 1826 | |
| 1827 | return (*this_cache); |
| 1828 | } |
| 1829 | |
| 1830 | static void |
| 1831 | mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache, |
| 1832 | struct frame_id *this_id) |
| 1833 | { |
| 1834 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
| 1835 | this_cache); |
| 1836 | (*this_id) = frame_id_build (info->base, |
| 1837 | frame_func_unwind (next_frame, NORMAL_FRAME)); |
| 1838 | } |
| 1839 | |
| 1840 | static void |
| 1841 | mips_insn16_frame_prev_register (struct frame_info *next_frame, |
| 1842 | void **this_cache, |
| 1843 | int regnum, int *optimizedp, |
| 1844 | enum lval_type *lvalp, CORE_ADDR *addrp, |
| 1845 | int *realnump, gdb_byte *valuep) |
| 1846 | { |
| 1847 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
| 1848 | this_cache); |
| 1849 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, |
| 1850 | optimizedp, lvalp, addrp, realnump, valuep); |
| 1851 | } |
| 1852 | |
| 1853 | static const struct frame_unwind mips_insn16_frame_unwind = |
| 1854 | { |
| 1855 | NORMAL_FRAME, |
| 1856 | mips_insn16_frame_this_id, |
| 1857 | mips_insn16_frame_prev_register |
| 1858 | }; |
| 1859 | |
| 1860 | static const struct frame_unwind * |
| 1861 | mips_insn16_frame_sniffer (struct frame_info *next_frame) |
| 1862 | { |
| 1863 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
| 1864 | if (mips_pc_is_mips16 (pc)) |
| 1865 | return &mips_insn16_frame_unwind; |
| 1866 | return NULL; |
| 1867 | } |
| 1868 | |
| 1869 | static CORE_ADDR |
| 1870 | mips_insn16_frame_base_address (struct frame_info *next_frame, |
| 1871 | void **this_cache) |
| 1872 | { |
| 1873 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
| 1874 | this_cache); |
| 1875 | return info->base; |
| 1876 | } |
| 1877 | |
| 1878 | static const struct frame_base mips_insn16_frame_base = |
| 1879 | { |
| 1880 | &mips_insn16_frame_unwind, |
| 1881 | mips_insn16_frame_base_address, |
| 1882 | mips_insn16_frame_base_address, |
| 1883 | mips_insn16_frame_base_address |
| 1884 | }; |
| 1885 | |
| 1886 | static const struct frame_base * |
| 1887 | mips_insn16_frame_base_sniffer (struct frame_info *next_frame) |
| 1888 | { |
| 1889 | if (mips_insn16_frame_sniffer (next_frame) != NULL) |
| 1890 | return &mips_insn16_frame_base; |
| 1891 | else |
| 1892 | return NULL; |
| 1893 | } |
| 1894 | |
| 1895 | /* Mark all the registers as unset in the saved_regs array |
| 1896 | of THIS_CACHE. Do nothing if THIS_CACHE is null. */ |
| 1897 | |
| 1898 | void |
| 1899 | reset_saved_regs (struct mips_frame_cache *this_cache) |
| 1900 | { |
| 1901 | if (this_cache == NULL || this_cache->saved_regs == NULL) |
| 1902 | return; |
| 1903 | |
| 1904 | { |
| 1905 | const int num_regs = gdbarch_num_regs (current_gdbarch); |
| 1906 | int i; |
| 1907 | |
| 1908 | for (i = 0; i < num_regs; i++) |
| 1909 | { |
| 1910 | this_cache->saved_regs[i].addr = -1; |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
| 1916 | the associated FRAME_CACHE if not null. |
| 1917 | Return the address of the first instruction past the prologue. */ |
| 1918 | |
| 1919 | static CORE_ADDR |
| 1920 | mips32_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
| 1921 | struct frame_info *next_frame, |
| 1922 | struct mips_frame_cache *this_cache) |
| 1923 | { |
| 1924 | CORE_ADDR cur_pc; |
| 1925 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ |
| 1926 | CORE_ADDR sp; |
| 1927 | long frame_offset; |
| 1928 | int frame_reg = MIPS_SP_REGNUM; |
| 1929 | |
| 1930 | CORE_ADDR end_prologue_addr = 0; |
| 1931 | int seen_sp_adjust = 0; |
| 1932 | int load_immediate_bytes = 0; |
| 1933 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
| 1934 | |
| 1935 | /* Can be called when there's no process, and hence when there's no |
| 1936 | NEXT_FRAME. */ |
| 1937 | if (next_frame != NULL) |
| 1938 | sp = frame_unwind_register_signed (next_frame, |
| 1939 | gdbarch_num_regs (gdbarch) |
| 1940 | + MIPS_SP_REGNUM); |
| 1941 | else |
| 1942 | sp = 0; |
| 1943 | |
| 1944 | if (limit_pc > start_pc + 200) |
| 1945 | limit_pc = start_pc + 200; |
| 1946 | |
| 1947 | restart: |
| 1948 | |
| 1949 | frame_offset = 0; |
| 1950 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) |
| 1951 | { |
| 1952 | unsigned long inst, high_word, low_word; |
| 1953 | int reg; |
| 1954 | |
| 1955 | /* Fetch the instruction. */ |
| 1956 | inst = (unsigned long) mips_fetch_instruction (cur_pc); |
| 1957 | |
| 1958 | /* Save some code by pre-extracting some useful fields. */ |
| 1959 | high_word = (inst >> 16) & 0xffff; |
| 1960 | low_word = inst & 0xffff; |
| 1961 | reg = high_word & 0x1f; |
| 1962 | |
| 1963 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
| 1964 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
| 1965 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ |
| 1966 | { |
| 1967 | if (low_word & 0x8000) /* negative stack adjustment? */ |
| 1968 | frame_offset += 0x10000 - low_word; |
| 1969 | else |
| 1970 | /* Exit loop if a positive stack adjustment is found, which |
| 1971 | usually means that the stack cleanup code in the function |
| 1972 | epilogue is reached. */ |
| 1973 | break; |
| 1974 | seen_sp_adjust = 1; |
| 1975 | } |
| 1976 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ |
| 1977 | { |
| 1978 | set_reg_offset (this_cache, reg, sp + low_word); |
| 1979 | } |
| 1980 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ |
| 1981 | { |
| 1982 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ |
| 1983 | set_reg_offset (this_cache, reg, sp + low_word); |
| 1984 | } |
| 1985 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ |
| 1986 | { |
| 1987 | /* Old gcc frame, r30 is virtual frame pointer. */ |
| 1988 | if ((long) low_word != frame_offset) |
| 1989 | frame_addr = sp + low_word; |
| 1990 | else if (next_frame && frame_reg == MIPS_SP_REGNUM) |
| 1991 | { |
| 1992 | unsigned alloca_adjust; |
| 1993 | |
| 1994 | frame_reg = 30; |
| 1995 | frame_addr = frame_unwind_register_signed |
| 1996 | (next_frame, gdbarch_num_regs (gdbarch) + 30); |
| 1997 | |
| 1998 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); |
| 1999 | if (alloca_adjust > 0) |
| 2000 | { |
| 2001 | /* FP > SP + frame_size. This may be because of |
| 2002 | an alloca or somethings similar. Fix sp to |
| 2003 | "pre-alloca" value, and try again. */ |
| 2004 | sp += alloca_adjust; |
| 2005 | /* Need to reset the status of all registers. Otherwise, |
| 2006 | we will hit a guard that prevents the new address |
| 2007 | for each register to be recomputed during the second |
| 2008 | pass. */ |
| 2009 | reset_saved_regs (this_cache); |
| 2010 | goto restart; |
| 2011 | } |
| 2012 | } |
| 2013 | } |
| 2014 | /* move $30,$sp. With different versions of gas this will be either |
| 2015 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. |
| 2016 | Accept any one of these. */ |
| 2017 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) |
| 2018 | { |
| 2019 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ |
| 2020 | if (next_frame && frame_reg == MIPS_SP_REGNUM) |
| 2021 | { |
| 2022 | unsigned alloca_adjust; |
| 2023 | |
| 2024 | frame_reg = 30; |
| 2025 | frame_addr = frame_unwind_register_signed |
| 2026 | (next_frame, gdbarch_num_regs (gdbarch) + 30); |
| 2027 | |
| 2028 | alloca_adjust = (unsigned) (frame_addr - sp); |
| 2029 | if (alloca_adjust > 0) |
| 2030 | { |
| 2031 | /* FP > SP + frame_size. This may be because of |
| 2032 | an alloca or somethings similar. Fix sp to |
| 2033 | "pre-alloca" value, and try again. */ |
| 2034 | sp = frame_addr; |
| 2035 | /* Need to reset the status of all registers. Otherwise, |
| 2036 | we will hit a guard that prevents the new address |
| 2037 | for each register to be recomputed during the second |
| 2038 | pass. */ |
| 2039 | reset_saved_regs (this_cache); |
| 2040 | goto restart; |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ |
| 2045 | { |
| 2046 | set_reg_offset (this_cache, reg, frame_addr + low_word); |
| 2047 | } |
| 2048 | else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ |
| 2049 | || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */ |
| 2050 | || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */ |
| 2051 | || high_word == 0x3c1c /* lui $gp,n */ |
| 2052 | || high_word == 0x279c /* addiu $gp,$gp,n */ |
| 2053 | || inst == 0x0399e021 /* addu $gp,$gp,$t9 */ |
| 2054 | || inst == 0x033ce021 /* addu $gp,$t9,$gp */ |
| 2055 | ) |
| 2056 | { |
| 2057 | /* These instructions are part of the prologue, but we don't |
| 2058 | need to do anything special to handle them. */ |
| 2059 | } |
| 2060 | /* The instructions below load $at or $t0 with an immediate |
| 2061 | value in preparation for a stack adjustment via |
| 2062 | subu $sp,$sp,[$at,$t0]. These instructions could also |
| 2063 | initialize a local variable, so we accept them only before |
| 2064 | a stack adjustment instruction was seen. */ |
| 2065 | else if (!seen_sp_adjust |
| 2066 | && (high_word == 0x3c01 /* lui $at,n */ |
| 2067 | || high_word == 0x3c08 /* lui $t0,n */ |
| 2068 | || high_word == 0x3421 /* ori $at,$at,n */ |
| 2069 | || high_word == 0x3508 /* ori $t0,$t0,n */ |
| 2070 | || high_word == 0x3401 /* ori $at,$zero,n */ |
| 2071 | || high_word == 0x3408 /* ori $t0,$zero,n */ |
| 2072 | )) |
| 2073 | { |
| 2074 | load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */ |
| 2075 | } |
| 2076 | else |
| 2077 | { |
| 2078 | /* This instruction is not an instruction typically found |
| 2079 | in a prologue, so we must have reached the end of the |
| 2080 | prologue. */ |
| 2081 | /* FIXME: brobecker/2004-10-10: Can't we just break out of this |
| 2082 | loop now? Why would we need to continue scanning the function |
| 2083 | instructions? */ |
| 2084 | if (end_prologue_addr == 0) |
| 2085 | end_prologue_addr = cur_pc; |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | if (this_cache != NULL) |
| 2090 | { |
| 2091 | this_cache->base = |
| 2092 | (frame_unwind_register_signed (next_frame, |
| 2093 | gdbarch_num_regs (gdbarch) + frame_reg) |
| 2094 | + frame_offset); |
| 2095 | /* FIXME: brobecker/2004-09-15: We should be able to get rid of |
| 2096 | this assignment below, eventually. But it's still needed |
| 2097 | for now. */ |
| 2098 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
| 2099 | + mips_regnum (gdbarch)->pc] |
| 2100 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
| 2101 | + MIPS_RA_REGNUM]; |
| 2102 | } |
| 2103 | |
| 2104 | /* If we didn't reach the end of the prologue when scanning the function |
| 2105 | instructions, then set end_prologue_addr to the address of the |
| 2106 | instruction immediately after the last one we scanned. */ |
| 2107 | /* brobecker/2004-10-10: I don't think this would ever happen, but |
| 2108 | we may as well be careful and do our best if we have a null |
| 2109 | end_prologue_addr. */ |
| 2110 | if (end_prologue_addr == 0) |
| 2111 | end_prologue_addr = cur_pc; |
| 2112 | |
| 2113 | /* In a frameless function, we might have incorrectly |
| 2114 | skipped some load immediate instructions. Undo the skipping |
| 2115 | if the load immediate was not followed by a stack adjustment. */ |
| 2116 | if (load_immediate_bytes && !seen_sp_adjust) |
| 2117 | end_prologue_addr -= load_immediate_bytes; |
| 2118 | |
| 2119 | return end_prologue_addr; |
| 2120 | } |
| 2121 | |
| 2122 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
| 2123 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit |
| 2124 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 |
| 2125 | unwinder. */ |
| 2126 | |
| 2127 | static struct mips_frame_cache * |
| 2128 | mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache) |
| 2129 | { |
| 2130 | struct mips_frame_cache *cache; |
| 2131 | |
| 2132 | if ((*this_cache) != NULL) |
| 2133 | return (*this_cache); |
| 2134 | |
| 2135 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
| 2136 | (*this_cache) = cache; |
| 2137 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); |
| 2138 | |
| 2139 | /* Analyze the function prologue. */ |
| 2140 | { |
| 2141 | const CORE_ADDR pc = |
| 2142 | frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
| 2143 | CORE_ADDR start_addr; |
| 2144 | |
| 2145 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
| 2146 | if (start_addr == 0) |
| 2147 | start_addr = heuristic_proc_start (pc); |
| 2148 | /* We can't analyze the prologue if we couldn't find the begining |
| 2149 | of the function. */ |
| 2150 | if (start_addr == 0) |
| 2151 | return cache; |
| 2152 | |
| 2153 | mips32_scan_prologue (start_addr, pc, next_frame, *this_cache); |
| 2154 | } |
| 2155 | |
| 2156 | /* gdbarch_sp_regnum contains the value and not the address. */ |
| 2157 | trad_frame_set_value (cache->saved_regs, |
| 2158 | gdbarch_num_regs (get_frame_arch (next_frame)) |
| 2159 | + MIPS_SP_REGNUM, |
| 2160 | cache->base); |
| 2161 | |
| 2162 | return (*this_cache); |
| 2163 | } |
| 2164 | |
| 2165 | static void |
| 2166 | mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache, |
| 2167 | struct frame_id *this_id) |
| 2168 | { |
| 2169 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
| 2170 | this_cache); |
| 2171 | (*this_id) = frame_id_build (info->base, |
| 2172 | frame_func_unwind (next_frame, NORMAL_FRAME)); |
| 2173 | } |
| 2174 | |
| 2175 | static void |
| 2176 | mips_insn32_frame_prev_register (struct frame_info *next_frame, |
| 2177 | void **this_cache, |
| 2178 | int regnum, int *optimizedp, |
| 2179 | enum lval_type *lvalp, CORE_ADDR *addrp, |
| 2180 | int *realnump, gdb_byte *valuep) |
| 2181 | { |
| 2182 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
| 2183 | this_cache); |
| 2184 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, |
| 2185 | optimizedp, lvalp, addrp, realnump, valuep); |
| 2186 | } |
| 2187 | |
| 2188 | static const struct frame_unwind mips_insn32_frame_unwind = |
| 2189 | { |
| 2190 | NORMAL_FRAME, |
| 2191 | mips_insn32_frame_this_id, |
| 2192 | mips_insn32_frame_prev_register |
| 2193 | }; |
| 2194 | |
| 2195 | static const struct frame_unwind * |
| 2196 | mips_insn32_frame_sniffer (struct frame_info *next_frame) |
| 2197 | { |
| 2198 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
| 2199 | if (! mips_pc_is_mips16 (pc)) |
| 2200 | return &mips_insn32_frame_unwind; |
| 2201 | return NULL; |
| 2202 | } |
| 2203 | |
| 2204 | static CORE_ADDR |
| 2205 | mips_insn32_frame_base_address (struct frame_info *next_frame, |
| 2206 | void **this_cache) |
| 2207 | { |
| 2208 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
| 2209 | this_cache); |
| 2210 | return info->base; |
| 2211 | } |
| 2212 | |
| 2213 | static const struct frame_base mips_insn32_frame_base = |
| 2214 | { |
| 2215 | &mips_insn32_frame_unwind, |
| 2216 | mips_insn32_frame_base_address, |
| 2217 | mips_insn32_frame_base_address, |
| 2218 | mips_insn32_frame_base_address |
| 2219 | }; |
| 2220 | |
| 2221 | static const struct frame_base * |
| 2222 | mips_insn32_frame_base_sniffer (struct frame_info *next_frame) |
| 2223 | { |
| 2224 | if (mips_insn32_frame_sniffer (next_frame) != NULL) |
| 2225 | return &mips_insn32_frame_base; |
| 2226 | else |
| 2227 | return NULL; |
| 2228 | } |
| 2229 | |
| 2230 | static struct trad_frame_cache * |
| 2231 | mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache) |
| 2232 | { |
| 2233 | CORE_ADDR pc; |
| 2234 | CORE_ADDR start_addr; |
| 2235 | CORE_ADDR stack_addr; |
| 2236 | struct trad_frame_cache *this_trad_cache; |
| 2237 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
| 2238 | |
| 2239 | if ((*this_cache) != NULL) |
| 2240 | return (*this_cache); |
| 2241 | this_trad_cache = trad_frame_cache_zalloc (next_frame); |
| 2242 | (*this_cache) = this_trad_cache; |
| 2243 | |
| 2244 | /* The return address is in the link register. */ |
| 2245 | trad_frame_set_reg_realreg (this_trad_cache, |
| 2246 | gdbarch_pc_regnum (gdbarch), |
| 2247 | (gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM)); |
| 2248 | |
| 2249 | /* Frame ID, since it's a frameless / stackless function, no stack |
| 2250 | space is allocated and SP on entry is the current SP. */ |
| 2251 | pc = frame_pc_unwind (next_frame); |
| 2252 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
| 2253 | stack_addr = frame_unwind_register_signed (next_frame, MIPS_SP_REGNUM); |
| 2254 | trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr)); |
| 2255 | |
| 2256 | /* Assume that the frame's base is the same as the |
| 2257 | stack-pointer. */ |
| 2258 | trad_frame_set_this_base (this_trad_cache, stack_addr); |
| 2259 | |
| 2260 | return this_trad_cache; |
| 2261 | } |
| 2262 | |
| 2263 | static void |
| 2264 | mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache, |
| 2265 | struct frame_id *this_id) |
| 2266 | { |
| 2267 | struct trad_frame_cache *this_trad_cache |
| 2268 | = mips_stub_frame_cache (next_frame, this_cache); |
| 2269 | trad_frame_get_id (this_trad_cache, this_id); |
| 2270 | } |
| 2271 | |
| 2272 | static void |
| 2273 | mips_stub_frame_prev_register (struct frame_info *next_frame, |
| 2274 | void **this_cache, |
| 2275 | int regnum, int *optimizedp, |
| 2276 | enum lval_type *lvalp, CORE_ADDR *addrp, |
| 2277 | int *realnump, gdb_byte *valuep) |
| 2278 | { |
| 2279 | struct trad_frame_cache *this_trad_cache |
| 2280 | = mips_stub_frame_cache (next_frame, this_cache); |
| 2281 | trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp, |
| 2282 | lvalp, addrp, realnump, valuep); |
| 2283 | } |
| 2284 | |
| 2285 | static const struct frame_unwind mips_stub_frame_unwind = |
| 2286 | { |
| 2287 | NORMAL_FRAME, |
| 2288 | mips_stub_frame_this_id, |
| 2289 | mips_stub_frame_prev_register |
| 2290 | }; |
| 2291 | |
| 2292 | static const struct frame_unwind * |
| 2293 | mips_stub_frame_sniffer (struct frame_info *next_frame) |
| 2294 | { |
| 2295 | gdb_byte dummy[4]; |
| 2296 | struct obj_section *s; |
| 2297 | CORE_ADDR pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
| 2298 | |
| 2299 | /* Use the stub unwinder for unreadable code. */ |
| 2300 | if (target_read_memory (frame_pc_unwind (next_frame), dummy, 4) != 0) |
| 2301 | return &mips_stub_frame_unwind; |
| 2302 | |
| 2303 | if (in_plt_section (pc, NULL)) |
| 2304 | return &mips_stub_frame_unwind; |
| 2305 | |
| 2306 | /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */ |
| 2307 | s = find_pc_section (pc); |
| 2308 | |
| 2309 | if (s != NULL |
| 2310 | && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section), |
| 2311 | ".MIPS.stubs") == 0) |
| 2312 | return &mips_stub_frame_unwind; |
| 2313 | |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | |
| 2317 | static CORE_ADDR |
| 2318 | mips_stub_frame_base_address (struct frame_info *next_frame, |
| 2319 | void **this_cache) |
| 2320 | { |
| 2321 | struct trad_frame_cache *this_trad_cache |
| 2322 | = mips_stub_frame_cache (next_frame, this_cache); |
| 2323 | return trad_frame_get_this_base (this_trad_cache); |
| 2324 | } |
| 2325 | |
| 2326 | static const struct frame_base mips_stub_frame_base = |
| 2327 | { |
| 2328 | &mips_stub_frame_unwind, |
| 2329 | mips_stub_frame_base_address, |
| 2330 | mips_stub_frame_base_address, |
| 2331 | mips_stub_frame_base_address |
| 2332 | }; |
| 2333 | |
| 2334 | static const struct frame_base * |
| 2335 | mips_stub_frame_base_sniffer (struct frame_info *next_frame) |
| 2336 | { |
| 2337 | if (mips_stub_frame_sniffer (next_frame) != NULL) |
| 2338 | return &mips_stub_frame_base; |
| 2339 | else |
| 2340 | return NULL; |
| 2341 | } |
| 2342 | |
| 2343 | /* mips_addr_bits_remove - remove useless address bits */ |
| 2344 | |
| 2345 | static CORE_ADDR |
| 2346 | mips_addr_bits_remove (CORE_ADDR addr) |
| 2347 | { |
| 2348 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
| 2349 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) |
| 2350 | /* This hack is a work-around for existing boards using PMON, the |
| 2351 | simulator, and any other 64-bit targets that doesn't have true |
| 2352 | 64-bit addressing. On these targets, the upper 32 bits of |
| 2353 | addresses are ignored by the hardware. Thus, the PC or SP are |
| 2354 | likely to have been sign extended to all 1s by instruction |
| 2355 | sequences that load 32-bit addresses. For example, a typical |
| 2356 | piece of code that loads an address is this: |
| 2357 | |
| 2358 | lui $r2, <upper 16 bits> |
| 2359 | ori $r2, <lower 16 bits> |
| 2360 | |
| 2361 | But the lui sign-extends the value such that the upper 32 bits |
| 2362 | may be all 1s. The workaround is simply to mask off these |
| 2363 | bits. In the future, gcc may be changed to support true 64-bit |
| 2364 | addressing, and this masking will have to be disabled. */ |
| 2365 | return addr &= 0xffffffffUL; |
| 2366 | else |
| 2367 | return addr; |
| 2368 | } |
| 2369 | |
| 2370 | /* Instructions used during single-stepping of atomic sequences. */ |
| 2371 | #define LL_OPCODE 0x30 |
| 2372 | #define LLD_OPCODE 0x34 |
| 2373 | #define SC_OPCODE 0x38 |
| 2374 | #define SCD_OPCODE 0x3c |
| 2375 | |
| 2376 | /* Checks for an atomic sequence of instructions beginning with a LL/LLD |
| 2377 | instruction and ending with a SC/SCD instruction. If such a sequence |
| 2378 | is found, attempt to step through it. A breakpoint is placed at the end of |
| 2379 | the sequence. */ |
| 2380 | |
| 2381 | static int |
| 2382 | deal_with_atomic_sequence (CORE_ADDR pc) |
| 2383 | { |
| 2384 | CORE_ADDR breaks[2] = {-1, -1}; |
| 2385 | CORE_ADDR loc = pc; |
| 2386 | CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */ |
| 2387 | unsigned long insn; |
| 2388 | int insn_count; |
| 2389 | int index; |
| 2390 | int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ |
| 2391 | const int atomic_sequence_length = 16; /* Instruction sequence length. */ |
| 2392 | |
| 2393 | if (pc & 0x01) |
| 2394 | return 0; |
| 2395 | |
| 2396 | insn = mips_fetch_instruction (loc); |
| 2397 | /* Assume all atomic sequences start with a ll/lld instruction. */ |
| 2398 | if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE) |
| 2399 | return 0; |
| 2400 | |
| 2401 | /* Assume that no atomic sequence is longer than "atomic_sequence_length" |
| 2402 | instructions. */ |
| 2403 | for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count) |
| 2404 | { |
| 2405 | int is_branch = 0; |
| 2406 | loc += MIPS_INSN32_SIZE; |
| 2407 | insn = mips_fetch_instruction (loc); |
| 2408 | |
| 2409 | /* Assume that there is at most one branch in the atomic |
| 2410 | sequence. If a branch is found, put a breakpoint in its |
| 2411 | destination address. */ |
| 2412 | switch (itype_op (insn)) |
| 2413 | { |
| 2414 | case 0: /* SPECIAL */ |
| 2415 | if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */ |
| 2416 | return 0; /* fallback to the standard single-step code. */ |
| 2417 | break; |
| 2418 | case 1: /* REGIMM */ |
| 2419 | is_branch = ((itype_rt (insn) & 0xc0) == 0); /* B{LT,GE}Z* */ |
| 2420 | break; |
| 2421 | case 2: /* J */ |
| 2422 | case 3: /* JAL */ |
| 2423 | return 0; /* fallback to the standard single-step code. */ |
| 2424 | case 4: /* BEQ */ |
| 2425 | case 5: /* BNE */ |
| 2426 | case 6: /* BLEZ */ |
| 2427 | case 7: /* BGTZ */ |
| 2428 | case 20: /* BEQL */ |
| 2429 | case 21: /* BNEL */ |
| 2430 | case 22: /* BLEZL */ |
| 2431 | case 23: /* BGTTL */ |
| 2432 | is_branch = 1; |
| 2433 | break; |
| 2434 | case 17: /* COP1 */ |
| 2435 | case 18: /* COP2 */ |
| 2436 | case 19: /* COP3 */ |
| 2437 | is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */ |
| 2438 | break; |
| 2439 | } |
| 2440 | if (is_branch) |
| 2441 | { |
| 2442 | branch_bp = loc + mips32_relative_offset (insn) + 4; |
| 2443 | if (last_breakpoint >= 1) |
| 2444 | return 0; /* More than one branch found, fallback to the |
| 2445 | standard single-step code. */ |
| 2446 | breaks[1] = branch_bp; |
| 2447 | last_breakpoint++; |
| 2448 | } |
| 2449 | |
| 2450 | if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE) |
| 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | /* Assume that the atomic sequence ends with a sc/scd instruction. */ |
| 2455 | if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE) |
| 2456 | return 0; |
| 2457 | |
| 2458 | loc += MIPS_INSN32_SIZE; |
| 2459 | |
| 2460 | /* Insert a breakpoint right after the end of the atomic sequence. */ |
| 2461 | breaks[0] = loc; |
| 2462 | |
| 2463 | /* Check for duplicated breakpoints. Check also for a breakpoint |
| 2464 | placed (branch instruction's destination) in the atomic sequence */ |
| 2465 | if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0]) |
| 2466 | last_breakpoint = 0; |
| 2467 | |
| 2468 | /* Effectively inserts the breakpoints. */ |
| 2469 | for (index = 0; index <= last_breakpoint; index++) |
| 2470 | insert_single_step_breakpoint (breaks[index]); |
| 2471 | |
| 2472 | return 1; |
| 2473 | } |
| 2474 | |
| 2475 | /* mips_software_single_step() is called just before we want to resume |
| 2476 | the inferior, if we want to single-step it but there is no hardware |
| 2477 | or kernel single-step support (MIPS on GNU/Linux for example). We find |
| 2478 | the target of the coming instruction and breakpoint it. */ |
| 2479 | |
| 2480 | int |
| 2481 | mips_software_single_step (struct frame_info *frame) |
| 2482 | { |
| 2483 | CORE_ADDR pc, next_pc; |
| 2484 | |
| 2485 | pc = get_frame_pc (frame); |
| 2486 | if (deal_with_atomic_sequence (pc)) |
| 2487 | return 1; |
| 2488 | |
| 2489 | next_pc = mips_next_pc (frame, pc); |
| 2490 | |
| 2491 | insert_single_step_breakpoint (next_pc); |
| 2492 | return 1; |
| 2493 | } |
| 2494 | |
| 2495 | /* Test whether the PC points to the return instruction at the |
| 2496 | end of a function. */ |
| 2497 | |
| 2498 | static int |
| 2499 | mips_about_to_return (CORE_ADDR pc) |
| 2500 | { |
| 2501 | if (mips_pc_is_mips16 (pc)) |
| 2502 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler |
| 2503 | generates a "jr $ra"; other times it generates code to load |
| 2504 | the return address from the stack to an accessible register (such |
| 2505 | as $a3), then a "jr" using that register. This second case |
| 2506 | is almost impossible to distinguish from an indirect jump |
| 2507 | used for switch statements, so we don't even try. */ |
| 2508 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ |
| 2509 | else |
| 2510 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | /* This fencepost looks highly suspicious to me. Removing it also |
| 2515 | seems suspicious as it could affect remote debugging across serial |
| 2516 | lines. */ |
| 2517 | |
| 2518 | static CORE_ADDR |
| 2519 | heuristic_proc_start (CORE_ADDR pc) |
| 2520 | { |
| 2521 | CORE_ADDR start_pc; |
| 2522 | CORE_ADDR fence; |
| 2523 | int instlen; |
| 2524 | int seen_adjsp = 0; |
| 2525 | |
| 2526 | pc = gdbarch_addr_bits_remove (current_gdbarch, pc); |
| 2527 | start_pc = pc; |
| 2528 | fence = start_pc - heuristic_fence_post; |
| 2529 | if (start_pc == 0) |
| 2530 | return 0; |
| 2531 | |
| 2532 | if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS) |
| 2533 | fence = VM_MIN_ADDRESS; |
| 2534 | |
| 2535 | instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE; |
| 2536 | |
| 2537 | /* search back for previous return */ |
| 2538 | for (start_pc -= instlen;; start_pc -= instlen) |
| 2539 | if (start_pc < fence) |
| 2540 | { |
| 2541 | /* It's not clear to me why we reach this point when |
| 2542 | stop_soon, but with this test, at least we |
| 2543 | don't print out warnings for every child forked (eg, on |
| 2544 | decstation). 22apr93 rich@cygnus.com. */ |
| 2545 | if (stop_soon == NO_STOP_QUIETLY) |
| 2546 | { |
| 2547 | static int blurb_printed = 0; |
| 2548 | |
| 2549 | warning (_("GDB can't find the start of the function at 0x%s."), |
| 2550 | paddr_nz (pc)); |
| 2551 | |
| 2552 | if (!blurb_printed) |
| 2553 | { |
| 2554 | /* This actually happens frequently in embedded |
| 2555 | development, when you first connect to a board |
| 2556 | and your stack pointer and pc are nowhere in |
| 2557 | particular. This message needs to give people |
| 2558 | in that situation enough information to |
| 2559 | determine that it's no big deal. */ |
| 2560 | printf_filtered ("\n\ |
| 2561 | GDB is unable to find the start of the function at 0x%s\n\ |
| 2562 | and thus can't determine the size of that function's stack frame.\n\ |
| 2563 | This means that GDB may be unable to access that stack frame, or\n\ |
| 2564 | the frames below it.\n\ |
| 2565 | This problem is most likely caused by an invalid program counter or\n\ |
| 2566 | stack pointer.\n\ |
| 2567 | However, if you think GDB should simply search farther back\n\ |
| 2568 | from 0x%s for code which looks like the beginning of a\n\ |
| 2569 | function, you can increase the range of the search using the `set\n\ |
| 2570 | heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc)); |
| 2571 | blurb_printed = 1; |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | return 0; |
| 2576 | } |
| 2577 | else if (mips_pc_is_mips16 (start_pc)) |
| 2578 | { |
| 2579 | unsigned short inst; |
| 2580 | |
| 2581 | /* On MIPS16, any one of the following is likely to be the |
| 2582 | start of a function: |
| 2583 | extend save |
| 2584 | save |
| 2585 | entry |
| 2586 | addiu sp,-n |
| 2587 | daddiu sp,-n |
| 2588 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ |
| 2589 | inst = mips_fetch_instruction (start_pc); |
| 2590 | if ((inst & 0xff80) == 0x6480) /* save */ |
| 2591 | { |
| 2592 | if (start_pc - instlen >= fence) |
| 2593 | { |
| 2594 | inst = mips_fetch_instruction (start_pc - instlen); |
| 2595 | if ((inst & 0xf800) == 0xf000) /* extend */ |
| 2596 | start_pc -= instlen; |
| 2597 | } |
| 2598 | break; |
| 2599 | } |
| 2600 | else if (((inst & 0xf81f) == 0xe809 |
| 2601 | && (inst & 0x700) != 0x700) /* entry */ |
| 2602 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ |
| 2603 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ |
| 2604 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ |
| 2605 | break; |
| 2606 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
| 2607 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
| 2608 | seen_adjsp = 1; |
| 2609 | else |
| 2610 | seen_adjsp = 0; |
| 2611 | } |
| 2612 | else if (mips_about_to_return (start_pc)) |
| 2613 | { |
| 2614 | /* Skip return and its delay slot. */ |
| 2615 | start_pc += 2 * MIPS_INSN32_SIZE; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | return start_pc; |
| 2620 | } |
| 2621 | |
| 2622 | struct mips_objfile_private |
| 2623 | { |
| 2624 | bfd_size_type size; |
| 2625 | char *contents; |
| 2626 | }; |
| 2627 | |
| 2628 | /* According to the current ABI, should the type be passed in a |
| 2629 | floating-point register (assuming that there is space)? When there |
| 2630 | is no FPU, FP are not even considered as possible candidates for |
| 2631 | FP registers and, consequently this returns false - forces FP |
| 2632 | arguments into integer registers. */ |
| 2633 | |
| 2634 | static int |
| 2635 | fp_register_arg_p (enum type_code typecode, struct type *arg_type) |
| 2636 | { |
| 2637 | return ((typecode == TYPE_CODE_FLT |
| 2638 | || (MIPS_EABI |
| 2639 | && (typecode == TYPE_CODE_STRUCT |
| 2640 | || typecode == TYPE_CODE_UNION) |
| 2641 | && TYPE_NFIELDS (arg_type) == 1 |
| 2642 | && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0))) |
| 2643 | == TYPE_CODE_FLT)) |
| 2644 | && MIPS_FPU_TYPE != MIPS_FPU_NONE); |
| 2645 | } |
| 2646 | |
| 2647 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
| 2648 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ |
| 2649 | |
| 2650 | static int |
| 2651 | mips_type_needs_double_align (struct type *type) |
| 2652 | { |
| 2653 | enum type_code typecode = TYPE_CODE (type); |
| 2654 | |
| 2655 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
| 2656 | return 1; |
| 2657 | else if (typecode == TYPE_CODE_STRUCT) |
| 2658 | { |
| 2659 | if (TYPE_NFIELDS (type) < 1) |
| 2660 | return 0; |
| 2661 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); |
| 2662 | } |
| 2663 | else if (typecode == TYPE_CODE_UNION) |
| 2664 | { |
| 2665 | int i, n; |
| 2666 | |
| 2667 | n = TYPE_NFIELDS (type); |
| 2668 | for (i = 0; i < n; i++) |
| 2669 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) |
| 2670 | return 1; |
| 2671 | return 0; |
| 2672 | } |
| 2673 | return 0; |
| 2674 | } |
| 2675 | |
| 2676 | /* Adjust the address downward (direction of stack growth) so that it |
| 2677 | is correctly aligned for a new stack frame. */ |
| 2678 | static CORE_ADDR |
| 2679 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) |
| 2680 | { |
| 2681 | return align_down (addr, 16); |
| 2682 | } |
| 2683 | |
| 2684 | static CORE_ADDR |
| 2685 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 2686 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 2687 | int nargs, struct value **args, CORE_ADDR sp, |
| 2688 | int struct_return, CORE_ADDR struct_addr) |
| 2689 | { |
| 2690 | int argreg; |
| 2691 | int float_argreg; |
| 2692 | int argnum; |
| 2693 | int len = 0; |
| 2694 | int stack_offset = 0; |
| 2695 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2696 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
| 2697 | int regsize = mips_abi_regsize (gdbarch); |
| 2698 | |
| 2699 | /* For shared libraries, "t9" needs to point at the function |
| 2700 | address. */ |
| 2701 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
| 2702 | |
| 2703 | /* Set the return address register to point to the entry point of |
| 2704 | the program, where a breakpoint lies in wait. */ |
| 2705 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
| 2706 | |
| 2707 | /* First ensure that the stack and structure return address (if any) |
| 2708 | are properly aligned. The stack has to be at least 64-bit |
| 2709 | aligned even on 32-bit machines, because doubles must be 64-bit |
| 2710 | aligned. For n32 and n64, stack frames need to be 128-bit |
| 2711 | aligned, so we round to this widest known alignment. */ |
| 2712 | |
| 2713 | sp = align_down (sp, 16); |
| 2714 | struct_addr = align_down (struct_addr, 16); |
| 2715 | |
| 2716 | /* Now make space on the stack for the args. We allocate more |
| 2717 | than necessary for EABI, because the first few arguments are |
| 2718 | passed in registers, but that's OK. */ |
| 2719 | for (argnum = 0; argnum < nargs; argnum++) |
| 2720 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize); |
| 2721 | sp -= align_up (len, 16); |
| 2722 | |
| 2723 | if (mips_debug) |
| 2724 | fprintf_unfiltered (gdb_stdlog, |
| 2725 | "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n", |
| 2726 | paddr_nz (sp), (long) align_up (len, 16)); |
| 2727 | |
| 2728 | /* Initialize the integer and float register pointers. */ |
| 2729 | argreg = MIPS_A0_REGNUM; |
| 2730 | float_argreg = mips_fpa0_regnum (gdbarch); |
| 2731 | |
| 2732 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
| 2733 | if (struct_return) |
| 2734 | { |
| 2735 | if (mips_debug) |
| 2736 | fprintf_unfiltered (gdb_stdlog, |
| 2737 | "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n", |
| 2738 | argreg, paddr_nz (struct_addr)); |
| 2739 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
| 2740 | } |
| 2741 | |
| 2742 | /* Now load as many as possible of the first arguments into |
| 2743 | registers, and push the rest onto the stack. Loop thru args |
| 2744 | from first to last. */ |
| 2745 | for (argnum = 0; argnum < nargs; argnum++) |
| 2746 | { |
| 2747 | const gdb_byte *val; |
| 2748 | gdb_byte valbuf[MAX_REGISTER_SIZE]; |
| 2749 | struct value *arg = args[argnum]; |
| 2750 | struct type *arg_type = check_typedef (value_type (arg)); |
| 2751 | int len = TYPE_LENGTH (arg_type); |
| 2752 | enum type_code typecode = TYPE_CODE (arg_type); |
| 2753 | |
| 2754 | if (mips_debug) |
| 2755 | fprintf_unfiltered (gdb_stdlog, |
| 2756 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
| 2757 | argnum + 1, len, (int) typecode); |
| 2758 | |
| 2759 | /* The EABI passes structures that do not fit in a register by |
| 2760 | reference. */ |
| 2761 | if (len > regsize |
| 2762 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
| 2763 | { |
| 2764 | store_unsigned_integer (valbuf, regsize, VALUE_ADDRESS (arg)); |
| 2765 | typecode = TYPE_CODE_PTR; |
| 2766 | len = regsize; |
| 2767 | val = valbuf; |
| 2768 | if (mips_debug) |
| 2769 | fprintf_unfiltered (gdb_stdlog, " push"); |
| 2770 | } |
| 2771 | else |
| 2772 | val = value_contents (arg); |
| 2773 | |
| 2774 | /* 32-bit ABIs always start floating point arguments in an |
| 2775 | even-numbered floating point register. Round the FP register |
| 2776 | up before the check to see if there are any FP registers |
| 2777 | left. Non MIPS_EABI targets also pass the FP in the integer |
| 2778 | registers so also round up normal registers. */ |
| 2779 | if (regsize < 8 && fp_register_arg_p (typecode, arg_type)) |
| 2780 | { |
| 2781 | if ((float_argreg & 1)) |
| 2782 | float_argreg++; |
| 2783 | } |
| 2784 | |
| 2785 | /* Floating point arguments passed in registers have to be |
| 2786 | treated specially. On 32-bit architectures, doubles |
| 2787 | are passed in register pairs; the even register gets |
| 2788 | the low word, and the odd register gets the high word. |
| 2789 | On non-EABI processors, the first two floating point arguments are |
| 2790 | also copied to general registers, because MIPS16 functions |
| 2791 | don't use float registers for arguments. This duplication of |
| 2792 | arguments in general registers can't hurt non-MIPS16 functions |
| 2793 | because those registers are normally skipped. */ |
| 2794 | /* MIPS_EABI squeezes a struct that contains a single floating |
| 2795 | point value into an FP register instead of pushing it onto the |
| 2796 | stack. */ |
| 2797 | if (fp_register_arg_p (typecode, arg_type) |
| 2798 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) |
| 2799 | { |
| 2800 | /* EABI32 will pass doubles in consecutive registers, even on |
| 2801 | 64-bit cores. At one time, we used to check the size of |
| 2802 | `float_argreg' to determine whether or not to pass doubles |
| 2803 | in consecutive registers, but this is not sufficient for |
| 2804 | making the ABI determination. */ |
| 2805 | if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32) |
| 2806 | { |
| 2807 | int low_offset = gdbarch_byte_order (gdbarch) |
| 2808 | == BFD_ENDIAN_BIG ? 4 : 0; |
| 2809 | unsigned long regval; |
| 2810 | |
| 2811 | /* Write the low word of the double to the even register(s). */ |
| 2812 | regval = extract_unsigned_integer (val + low_offset, 4); |
| 2813 | if (mips_debug) |
| 2814 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 2815 | float_argreg, phex (regval, 4)); |
| 2816 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 2817 | |
| 2818 | /* Write the high word of the double to the odd register(s). */ |
| 2819 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
| 2820 | if (mips_debug) |
| 2821 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 2822 | float_argreg, phex (regval, 4)); |
| 2823 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 2824 | } |
| 2825 | else |
| 2826 | { |
| 2827 | /* This is a floating point value that fits entirely |
| 2828 | in a single register. */ |
| 2829 | /* On 32 bit ABI's the float_argreg is further adjusted |
| 2830 | above to ensure that it is even register aligned. */ |
| 2831 | LONGEST regval = extract_unsigned_integer (val, len); |
| 2832 | if (mips_debug) |
| 2833 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 2834 | float_argreg, phex (regval, len)); |
| 2835 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 2836 | } |
| 2837 | } |
| 2838 | else |
| 2839 | { |
| 2840 | /* Copy the argument to general registers or the stack in |
| 2841 | register-sized pieces. Large arguments are split between |
| 2842 | registers and stack. */ |
| 2843 | /* Note: structs whose size is not a multiple of regsize |
| 2844 | are treated specially: Irix cc passes |
| 2845 | them in registers where gcc sometimes puts them on the |
| 2846 | stack. For maximum compatibility, we will put them in |
| 2847 | both places. */ |
| 2848 | int odd_sized_struct = (len > regsize && len % regsize != 0); |
| 2849 | |
| 2850 | /* Note: Floating-point values that didn't fit into an FP |
| 2851 | register are only written to memory. */ |
| 2852 | while (len > 0) |
| 2853 | { |
| 2854 | /* Remember if the argument was written to the stack. */ |
| 2855 | int stack_used_p = 0; |
| 2856 | int partial_len = (len < regsize ? len : regsize); |
| 2857 | |
| 2858 | if (mips_debug) |
| 2859 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", |
| 2860 | partial_len); |
| 2861 | |
| 2862 | /* Write this portion of the argument to the stack. */ |
| 2863 | if (argreg > MIPS_LAST_ARG_REGNUM |
| 2864 | || odd_sized_struct |
| 2865 | || fp_register_arg_p (typecode, arg_type)) |
| 2866 | { |
| 2867 | /* Should shorter than int integer values be |
| 2868 | promoted to int before being stored? */ |
| 2869 | int longword_offset = 0; |
| 2870 | CORE_ADDR addr; |
| 2871 | stack_used_p = 1; |
| 2872 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 2873 | { |
| 2874 | if (regsize == 8 |
| 2875 | && (typecode == TYPE_CODE_INT |
| 2876 | || typecode == TYPE_CODE_PTR |
| 2877 | || typecode == TYPE_CODE_FLT) && len <= 4) |
| 2878 | longword_offset = regsize - len; |
| 2879 | else if ((typecode == TYPE_CODE_STRUCT |
| 2880 | || typecode == TYPE_CODE_UNION) |
| 2881 | && TYPE_LENGTH (arg_type) < regsize) |
| 2882 | longword_offset = regsize - len; |
| 2883 | } |
| 2884 | |
| 2885 | if (mips_debug) |
| 2886 | { |
| 2887 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
| 2888 | paddr_nz (stack_offset)); |
| 2889 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", |
| 2890 | paddr_nz (longword_offset)); |
| 2891 | } |
| 2892 | |
| 2893 | addr = sp + stack_offset + longword_offset; |
| 2894 | |
| 2895 | if (mips_debug) |
| 2896 | { |
| 2897 | int i; |
| 2898 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
| 2899 | paddr_nz (addr)); |
| 2900 | for (i = 0; i < partial_len; i++) |
| 2901 | { |
| 2902 | fprintf_unfiltered (gdb_stdlog, "%02x", |
| 2903 | val[i] & 0xff); |
| 2904 | } |
| 2905 | } |
| 2906 | write_memory (addr, val, partial_len); |
| 2907 | } |
| 2908 | |
| 2909 | /* Note!!! This is NOT an else clause. Odd sized |
| 2910 | structs may go thru BOTH paths. Floating point |
| 2911 | arguments will not. */ |
| 2912 | /* Write this portion of the argument to a general |
| 2913 | purpose register. */ |
| 2914 | if (argreg <= MIPS_LAST_ARG_REGNUM |
| 2915 | && !fp_register_arg_p (typecode, arg_type)) |
| 2916 | { |
| 2917 | LONGEST regval = |
| 2918 | extract_unsigned_integer (val, partial_len); |
| 2919 | |
| 2920 | if (mips_debug) |
| 2921 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
| 2922 | argreg, |
| 2923 | phex (regval, regsize)); |
| 2924 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 2925 | argreg++; |
| 2926 | } |
| 2927 | |
| 2928 | len -= partial_len; |
| 2929 | val += partial_len; |
| 2930 | |
| 2931 | /* Compute the the offset into the stack at which we |
| 2932 | will copy the next parameter. |
| 2933 | |
| 2934 | In the new EABI (and the NABI32), the stack_offset |
| 2935 | only needs to be adjusted when it has been used. */ |
| 2936 | |
| 2937 | if (stack_used_p) |
| 2938 | stack_offset += align_up (partial_len, regsize); |
| 2939 | } |
| 2940 | } |
| 2941 | if (mips_debug) |
| 2942 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 2943 | } |
| 2944 | |
| 2945 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
| 2946 | |
| 2947 | /* Return adjusted stack pointer. */ |
| 2948 | return sp; |
| 2949 | } |
| 2950 | |
| 2951 | /* Determine the return value convention being used. */ |
| 2952 | |
| 2953 | static enum return_value_convention |
| 2954 | mips_eabi_return_value (struct gdbarch *gdbarch, |
| 2955 | struct type *type, struct regcache *regcache, |
| 2956 | gdb_byte *readbuf, const gdb_byte *writebuf) |
| 2957 | { |
| 2958 | if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
| 2959 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 2960 | if (readbuf) |
| 2961 | memset (readbuf, 0, TYPE_LENGTH (type)); |
| 2962 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 2963 | } |
| 2964 | |
| 2965 | |
| 2966 | /* N32/N64 ABI stuff. */ |
| 2967 | |
| 2968 | /* Search for a naturally aligned double at OFFSET inside a struct |
| 2969 | ARG_TYPE. The N32 / N64 ABIs pass these in floating point |
| 2970 | registers. */ |
| 2971 | |
| 2972 | static int |
| 2973 | mips_n32n64_fp_arg_chunk_p (struct type *arg_type, int offset) |
| 2974 | { |
| 2975 | int i; |
| 2976 | |
| 2977 | if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT) |
| 2978 | return 0; |
| 2979 | |
| 2980 | if (MIPS_FPU_TYPE != MIPS_FPU_DOUBLE) |
| 2981 | return 0; |
| 2982 | |
| 2983 | if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE) |
| 2984 | return 0; |
| 2985 | |
| 2986 | for (i = 0; i < TYPE_NFIELDS (arg_type); i++) |
| 2987 | { |
| 2988 | int pos; |
| 2989 | struct type *field_type; |
| 2990 | |
| 2991 | /* We're only looking at normal fields. */ |
| 2992 | if (TYPE_FIELD_STATIC (arg_type, i) |
| 2993 | || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0) |
| 2994 | continue; |
| 2995 | |
| 2996 | /* If we have gone past the offset, there is no double to pass. */ |
| 2997 | pos = TYPE_FIELD_BITPOS (arg_type, i) / 8; |
| 2998 | if (pos > offset) |
| 2999 | return 0; |
| 3000 | |
| 3001 | field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i)); |
| 3002 | |
| 3003 | /* If this field is entirely before the requested offset, go |
| 3004 | on to the next one. */ |
| 3005 | if (pos + TYPE_LENGTH (field_type) <= offset) |
| 3006 | continue; |
| 3007 | |
| 3008 | /* If this is our special aligned double, we can stop. */ |
| 3009 | if (TYPE_CODE (field_type) == TYPE_CODE_FLT |
| 3010 | && TYPE_LENGTH (field_type) == MIPS64_REGSIZE) |
| 3011 | return 1; |
| 3012 | |
| 3013 | /* This field starts at or before the requested offset, and |
| 3014 | overlaps it. If it is a structure, recurse inwards. */ |
| 3015 | return mips_n32n64_fp_arg_chunk_p (field_type, offset - pos); |
| 3016 | } |
| 3017 | |
| 3018 | return 0; |
| 3019 | } |
| 3020 | |
| 3021 | static CORE_ADDR |
| 3022 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 3023 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 3024 | int nargs, struct value **args, CORE_ADDR sp, |
| 3025 | int struct_return, CORE_ADDR struct_addr) |
| 3026 | { |
| 3027 | int argreg; |
| 3028 | int float_argreg; |
| 3029 | int argnum; |
| 3030 | int len = 0; |
| 3031 | int stack_offset = 0; |
| 3032 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 3033 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
| 3034 | |
| 3035 | /* For shared libraries, "t9" needs to point at the function |
| 3036 | address. */ |
| 3037 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
| 3038 | |
| 3039 | /* Set the return address register to point to the entry point of |
| 3040 | the program, where a breakpoint lies in wait. */ |
| 3041 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
| 3042 | |
| 3043 | /* First ensure that the stack and structure return address (if any) |
| 3044 | are properly aligned. The stack has to be at least 64-bit |
| 3045 | aligned even on 32-bit machines, because doubles must be 64-bit |
| 3046 | aligned. For n32 and n64, stack frames need to be 128-bit |
| 3047 | aligned, so we round to this widest known alignment. */ |
| 3048 | |
| 3049 | sp = align_down (sp, 16); |
| 3050 | struct_addr = align_down (struct_addr, 16); |
| 3051 | |
| 3052 | /* Now make space on the stack for the args. */ |
| 3053 | for (argnum = 0; argnum < nargs; argnum++) |
| 3054 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE); |
| 3055 | sp -= align_up (len, 16); |
| 3056 | |
| 3057 | if (mips_debug) |
| 3058 | fprintf_unfiltered (gdb_stdlog, |
| 3059 | "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n", |
| 3060 | paddr_nz (sp), (long) align_up (len, 16)); |
| 3061 | |
| 3062 | /* Initialize the integer and float register pointers. */ |
| 3063 | argreg = MIPS_A0_REGNUM; |
| 3064 | float_argreg = mips_fpa0_regnum (gdbarch); |
| 3065 | |
| 3066 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
| 3067 | if (struct_return) |
| 3068 | { |
| 3069 | if (mips_debug) |
| 3070 | fprintf_unfiltered (gdb_stdlog, |
| 3071 | "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n", |
| 3072 | argreg, paddr_nz (struct_addr)); |
| 3073 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
| 3074 | } |
| 3075 | |
| 3076 | /* Now load as many as possible of the first arguments into |
| 3077 | registers, and push the rest onto the stack. Loop thru args |
| 3078 | from first to last. */ |
| 3079 | for (argnum = 0; argnum < nargs; argnum++) |
| 3080 | { |
| 3081 | const gdb_byte *val; |
| 3082 | struct value *arg = args[argnum]; |
| 3083 | struct type *arg_type = check_typedef (value_type (arg)); |
| 3084 | int len = TYPE_LENGTH (arg_type); |
| 3085 | enum type_code typecode = TYPE_CODE (arg_type); |
| 3086 | |
| 3087 | if (mips_debug) |
| 3088 | fprintf_unfiltered (gdb_stdlog, |
| 3089 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
| 3090 | argnum + 1, len, (int) typecode); |
| 3091 | |
| 3092 | val = value_contents (arg); |
| 3093 | |
| 3094 | if (fp_register_arg_p (typecode, arg_type) |
| 3095 | && argreg <= MIPS_LAST_ARG_REGNUM) |
| 3096 | { |
| 3097 | /* This is a floating point value that fits entirely |
| 3098 | in a single register. */ |
| 3099 | LONGEST regval = extract_unsigned_integer (val, len); |
| 3100 | if (mips_debug) |
| 3101 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3102 | float_argreg, phex (regval, len)); |
| 3103 | regcache_cooked_write_unsigned (regcache, float_argreg, regval); |
| 3104 | |
| 3105 | if (mips_debug) |
| 3106 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
| 3107 | argreg, phex (regval, len)); |
| 3108 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 3109 | float_argreg++; |
| 3110 | argreg++; |
| 3111 | } |
| 3112 | else |
| 3113 | { |
| 3114 | /* Copy the argument to general registers or the stack in |
| 3115 | register-sized pieces. Large arguments are split between |
| 3116 | registers and stack. */ |
| 3117 | /* For N32/N64, structs, unions, or other composite types are |
| 3118 | treated as a sequence of doublewords, and are passed in integer |
| 3119 | or floating point registers as though they were simple scalar |
| 3120 | parameters to the extent that they fit, with any excess on the |
| 3121 | stack packed according to the normal memory layout of the |
| 3122 | object. |
| 3123 | The caller does not reserve space for the register arguments; |
| 3124 | the callee is responsible for reserving it if required. */ |
| 3125 | /* Note: Floating-point values that didn't fit into an FP |
| 3126 | register are only written to memory. */ |
| 3127 | while (len > 0) |
| 3128 | { |
| 3129 | /* Remember if the argument was written to the stack. */ |
| 3130 | int stack_used_p = 0; |
| 3131 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
| 3132 | |
| 3133 | if (mips_debug) |
| 3134 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", |
| 3135 | partial_len); |
| 3136 | |
| 3137 | if (fp_register_arg_p (typecode, arg_type)) |
| 3138 | gdb_assert (argreg > MIPS_LAST_ARG_REGNUM); |
| 3139 | |
| 3140 | /* Write this portion of the argument to the stack. */ |
| 3141 | if (argreg > MIPS_LAST_ARG_REGNUM) |
| 3142 | { |
| 3143 | /* Should shorter than int integer values be |
| 3144 | promoted to int before being stored? */ |
| 3145 | int longword_offset = 0; |
| 3146 | CORE_ADDR addr; |
| 3147 | stack_used_p = 1; |
| 3148 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 3149 | { |
| 3150 | if ((typecode == TYPE_CODE_INT |
| 3151 | || typecode == TYPE_CODE_PTR |
| 3152 | || typecode == TYPE_CODE_FLT) |
| 3153 | && len <= 4) |
| 3154 | longword_offset = MIPS64_REGSIZE - len; |
| 3155 | } |
| 3156 | |
| 3157 | if (mips_debug) |
| 3158 | { |
| 3159 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
| 3160 | paddr_nz (stack_offset)); |
| 3161 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", |
| 3162 | paddr_nz (longword_offset)); |
| 3163 | } |
| 3164 | |
| 3165 | addr = sp + stack_offset + longword_offset; |
| 3166 | |
| 3167 | if (mips_debug) |
| 3168 | { |
| 3169 | int i; |
| 3170 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
| 3171 | paddr_nz (addr)); |
| 3172 | for (i = 0; i < partial_len; i++) |
| 3173 | { |
| 3174 | fprintf_unfiltered (gdb_stdlog, "%02x", |
| 3175 | val[i] & 0xff); |
| 3176 | } |
| 3177 | } |
| 3178 | write_memory (addr, val, partial_len); |
| 3179 | } |
| 3180 | |
| 3181 | /* Note!!! This is NOT an else clause. Odd sized |
| 3182 | structs may go thru BOTH paths. */ |
| 3183 | /* Write this portion of the argument to a general |
| 3184 | purpose register. */ |
| 3185 | if (argreg <= MIPS_LAST_ARG_REGNUM) |
| 3186 | { |
| 3187 | LONGEST regval = |
| 3188 | extract_unsigned_integer (val, partial_len); |
| 3189 | |
| 3190 | /* A non-floating-point argument being passed in a |
| 3191 | general register. If a struct or union, and if |
| 3192 | the remaining length is smaller than the register |
| 3193 | size, we have to adjust the register value on |
| 3194 | big endian targets. |
| 3195 | |
| 3196 | It does not seem to be necessary to do the |
| 3197 | same for integral types. */ |
| 3198 | |
| 3199 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
| 3200 | && partial_len < MIPS64_REGSIZE |
| 3201 | && (typecode == TYPE_CODE_STRUCT |
| 3202 | || typecode == TYPE_CODE_UNION)) |
| 3203 | regval <<= ((MIPS64_REGSIZE - partial_len) |
| 3204 | * TARGET_CHAR_BIT); |
| 3205 | |
| 3206 | if (mips_debug) |
| 3207 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
| 3208 | argreg, |
| 3209 | phex (regval, MIPS64_REGSIZE)); |
| 3210 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 3211 | |
| 3212 | if (mips_n32n64_fp_arg_chunk_p (arg_type, |
| 3213 | TYPE_LENGTH (arg_type) - len)) |
| 3214 | { |
| 3215 | if (mips_debug) |
| 3216 | fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3217 | float_argreg, |
| 3218 | phex (regval, MIPS64_REGSIZE)); |
| 3219 | regcache_cooked_write_unsigned (regcache, float_argreg, |
| 3220 | regval); |
| 3221 | } |
| 3222 | |
| 3223 | float_argreg++; |
| 3224 | argreg++; |
| 3225 | } |
| 3226 | |
| 3227 | len -= partial_len; |
| 3228 | val += partial_len; |
| 3229 | |
| 3230 | /* Compute the the offset into the stack at which we |
| 3231 | will copy the next parameter. |
| 3232 | |
| 3233 | In N32 (N64?), the stack_offset only needs to be |
| 3234 | adjusted when it has been used. */ |
| 3235 | |
| 3236 | if (stack_used_p) |
| 3237 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
| 3238 | } |
| 3239 | } |
| 3240 | if (mips_debug) |
| 3241 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 3242 | } |
| 3243 | |
| 3244 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
| 3245 | |
| 3246 | /* Return adjusted stack pointer. */ |
| 3247 | return sp; |
| 3248 | } |
| 3249 | |
| 3250 | static enum return_value_convention |
| 3251 | mips_n32n64_return_value (struct gdbarch *gdbarch, |
| 3252 | struct type *type, struct regcache *regcache, |
| 3253 | gdb_byte *readbuf, const gdb_byte *writebuf) |
| 3254 | { |
| 3255 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 3256 | |
| 3257 | /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004 |
| 3258 | |
| 3259 | Function results are returned in $2 (and $3 if needed), or $f0 (and $f2 |
| 3260 | if needed), as appropriate for the type. Composite results (struct, |
| 3261 | union, or array) are returned in $2/$f0 and $3/$f2 according to the |
| 3262 | following rules: |
| 3263 | |
| 3264 | * A struct with only one or two floating point fields is returned in $f0 |
| 3265 | (and $f2 if necessary). This is a generalization of the Fortran COMPLEX |
| 3266 | case. |
| 3267 | |
| 3268 | * Any other struct or union results of at most 128 bits are returned in |
| 3269 | $2 (first 64 bits) and $3 (remainder, if necessary). |
| 3270 | |
| 3271 | * Larger composite results are handled by converting the function to a |
| 3272 | procedure with an implicit first parameter, which is a pointer to an area |
| 3273 | reserved by the caller to receive the result. [The o32-bit ABI requires |
| 3274 | that all composite results be handled by conversion to implicit first |
| 3275 | parameters. The MIPS/SGI Fortran implementation has always made a |
| 3276 | specific exception to return COMPLEX results in the floating point |
| 3277 | registers.] */ |
| 3278 | |
| 3279 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
| 3280 | || TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE) |
| 3281 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 3282 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 3283 | && TYPE_LENGTH (type) == 16 |
| 3284 | && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3285 | { |
| 3286 | /* A 128-bit floating-point value fills both $f0 and $f2. The |
| 3287 | two registers are used in the same as memory order, so the |
| 3288 | eight bytes with the lower memory address are in $f0. */ |
| 3289 | if (mips_debug) |
| 3290 | fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n"); |
| 3291 | mips_xfer_register (gdbarch, regcache, |
| 3292 | gdbarch_num_regs (gdbarch) |
| 3293 | + mips_regnum (gdbarch)->fp0, |
| 3294 | 8, gdbarch_byte_order (gdbarch), |
| 3295 | readbuf, writebuf, 0); |
| 3296 | mips_xfer_register (gdbarch, regcache, |
| 3297 | gdbarch_num_regs (gdbarch) |
| 3298 | + mips_regnum (gdbarch)->fp0 + 2, |
| 3299 | 8, gdbarch_byte_order (gdbarch), |
| 3300 | readbuf ? readbuf + 8 : readbuf, |
| 3301 | writebuf ? writebuf + 8 : writebuf, 0); |
| 3302 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3303 | } |
| 3304 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 3305 | && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3306 | { |
| 3307 | /* A single or double floating-point value that fits in FP0. */ |
| 3308 | if (mips_debug) |
| 3309 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); |
| 3310 | mips_xfer_register (gdbarch, regcache, |
| 3311 | gdbarch_num_regs (gdbarch) |
| 3312 | + mips_regnum (gdbarch)->fp0, |
| 3313 | TYPE_LENGTH (type), |
| 3314 | gdbarch_byte_order (gdbarch), |
| 3315 | readbuf, writebuf, 0); |
| 3316 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3317 | } |
| 3318 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 3319 | && TYPE_NFIELDS (type) <= 2 |
| 3320 | && TYPE_NFIELDS (type) >= 1 |
| 3321 | && ((TYPE_NFIELDS (type) == 1 |
| 3322 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
| 3323 | == TYPE_CODE_FLT)) |
| 3324 | || (TYPE_NFIELDS (type) == 2 |
| 3325 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
| 3326 | == TYPE_CODE_FLT) |
| 3327 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1))) |
| 3328 | == TYPE_CODE_FLT))) |
| 3329 | && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3330 | { |
| 3331 | /* A struct that contains one or two floats. Each value is part |
| 3332 | in the least significant part of their floating point |
| 3333 | register.. */ |
| 3334 | int regnum; |
| 3335 | int field; |
| 3336 | for (field = 0, regnum = mips_regnum (gdbarch)->fp0; |
| 3337 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
| 3338 | { |
| 3339 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) |
| 3340 | / TARGET_CHAR_BIT); |
| 3341 | if (mips_debug) |
| 3342 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", |
| 3343 | offset); |
| 3344 | mips_xfer_register (gdbarch, regcache, |
| 3345 | gdbarch_num_regs (gdbarch) + regnum, |
| 3346 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), |
| 3347 | gdbarch_byte_order (gdbarch), |
| 3348 | readbuf, writebuf, offset); |
| 3349 | } |
| 3350 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3351 | } |
| 3352 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 3353 | || TYPE_CODE (type) == TYPE_CODE_UNION) |
| 3354 | { |
| 3355 | /* A structure or union. Extract the left justified value, |
| 3356 | regardless of the byte order. I.e. DO NOT USE |
| 3357 | mips_xfer_lower. */ |
| 3358 | int offset; |
| 3359 | int regnum; |
| 3360 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
| 3361 | offset < TYPE_LENGTH (type); |
| 3362 | offset += register_size (gdbarch, regnum), regnum++) |
| 3363 | { |
| 3364 | int xfer = register_size (gdbarch, regnum); |
| 3365 | if (offset + xfer > TYPE_LENGTH (type)) |
| 3366 | xfer = TYPE_LENGTH (type) - offset; |
| 3367 | if (mips_debug) |
| 3368 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", |
| 3369 | offset, xfer, regnum); |
| 3370 | mips_xfer_register (gdbarch, regcache, |
| 3371 | gdbarch_num_regs (gdbarch) + regnum, |
| 3372 | xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf, |
| 3373 | offset); |
| 3374 | } |
| 3375 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3376 | } |
| 3377 | else |
| 3378 | { |
| 3379 | /* A scalar extract each part but least-significant-byte |
| 3380 | justified. */ |
| 3381 | int offset; |
| 3382 | int regnum; |
| 3383 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
| 3384 | offset < TYPE_LENGTH (type); |
| 3385 | offset += register_size (gdbarch, regnum), regnum++) |
| 3386 | { |
| 3387 | int xfer = register_size (gdbarch, regnum); |
| 3388 | if (offset + xfer > TYPE_LENGTH (type)) |
| 3389 | xfer = TYPE_LENGTH (type) - offset; |
| 3390 | if (mips_debug) |
| 3391 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", |
| 3392 | offset, xfer, regnum); |
| 3393 | mips_xfer_register (gdbarch, regcache, |
| 3394 | gdbarch_num_regs (gdbarch) + regnum, |
| 3395 | xfer, gdbarch_byte_order (gdbarch), |
| 3396 | readbuf, writebuf, offset); |
| 3397 | } |
| 3398 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | /* O32 ABI stuff. */ |
| 3403 | |
| 3404 | static CORE_ADDR |
| 3405 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 3406 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 3407 | int nargs, struct value **args, CORE_ADDR sp, |
| 3408 | int struct_return, CORE_ADDR struct_addr) |
| 3409 | { |
| 3410 | int argreg; |
| 3411 | int float_argreg; |
| 3412 | int argnum; |
| 3413 | int len = 0; |
| 3414 | int stack_offset = 0; |
| 3415 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 3416 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
| 3417 | |
| 3418 | /* For shared libraries, "t9" needs to point at the function |
| 3419 | address. */ |
| 3420 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
| 3421 | |
| 3422 | /* Set the return address register to point to the entry point of |
| 3423 | the program, where a breakpoint lies in wait. */ |
| 3424 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
| 3425 | |
| 3426 | /* First ensure that the stack and structure return address (if any) |
| 3427 | are properly aligned. The stack has to be at least 64-bit |
| 3428 | aligned even on 32-bit machines, because doubles must be 64-bit |
| 3429 | aligned. For n32 and n64, stack frames need to be 128-bit |
| 3430 | aligned, so we round to this widest known alignment. */ |
| 3431 | |
| 3432 | sp = align_down (sp, 16); |
| 3433 | struct_addr = align_down (struct_addr, 16); |
| 3434 | |
| 3435 | /* Now make space on the stack for the args. */ |
| 3436 | for (argnum = 0; argnum < nargs; argnum++) |
| 3437 | { |
| 3438 | struct type *arg_type = check_typedef (value_type (args[argnum])); |
| 3439 | int arglen = TYPE_LENGTH (arg_type); |
| 3440 | |
| 3441 | /* Align to double-word if necessary. */ |
| 3442 | if (mips_type_needs_double_align (arg_type)) |
| 3443 | len = align_up (len, MIPS32_REGSIZE * 2); |
| 3444 | /* Allocate space on the stack. */ |
| 3445 | len += align_up (arglen, MIPS32_REGSIZE); |
| 3446 | } |
| 3447 | sp -= align_up (len, 16); |
| 3448 | |
| 3449 | if (mips_debug) |
| 3450 | fprintf_unfiltered (gdb_stdlog, |
| 3451 | "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n", |
| 3452 | paddr_nz (sp), (long) align_up (len, 16)); |
| 3453 | |
| 3454 | /* Initialize the integer and float register pointers. */ |
| 3455 | argreg = MIPS_A0_REGNUM; |
| 3456 | float_argreg = mips_fpa0_regnum (gdbarch); |
| 3457 | |
| 3458 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
| 3459 | if (struct_return) |
| 3460 | { |
| 3461 | if (mips_debug) |
| 3462 | fprintf_unfiltered (gdb_stdlog, |
| 3463 | "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n", |
| 3464 | argreg, paddr_nz (struct_addr)); |
| 3465 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
| 3466 | stack_offset += MIPS32_REGSIZE; |
| 3467 | } |
| 3468 | |
| 3469 | /* Now load as many as possible of the first arguments into |
| 3470 | registers, and push the rest onto the stack. Loop thru args |
| 3471 | from first to last. */ |
| 3472 | for (argnum = 0; argnum < nargs; argnum++) |
| 3473 | { |
| 3474 | const gdb_byte *val; |
| 3475 | struct value *arg = args[argnum]; |
| 3476 | struct type *arg_type = check_typedef (value_type (arg)); |
| 3477 | int len = TYPE_LENGTH (arg_type); |
| 3478 | enum type_code typecode = TYPE_CODE (arg_type); |
| 3479 | |
| 3480 | if (mips_debug) |
| 3481 | fprintf_unfiltered (gdb_stdlog, |
| 3482 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
| 3483 | argnum + 1, len, (int) typecode); |
| 3484 | |
| 3485 | val = value_contents (arg); |
| 3486 | |
| 3487 | /* 32-bit ABIs always start floating point arguments in an |
| 3488 | even-numbered floating point register. Round the FP register |
| 3489 | up before the check to see if there are any FP registers |
| 3490 | left. O32/O64 targets also pass the FP in the integer |
| 3491 | registers so also round up normal registers. */ |
| 3492 | if (fp_register_arg_p (typecode, arg_type)) |
| 3493 | { |
| 3494 | if ((float_argreg & 1)) |
| 3495 | float_argreg++; |
| 3496 | } |
| 3497 | |
| 3498 | /* Floating point arguments passed in registers have to be |
| 3499 | treated specially. On 32-bit architectures, doubles |
| 3500 | are passed in register pairs; the even register gets |
| 3501 | the low word, and the odd register gets the high word. |
| 3502 | On O32/O64, the first two floating point arguments are |
| 3503 | also copied to general registers, because MIPS16 functions |
| 3504 | don't use float registers for arguments. This duplication of |
| 3505 | arguments in general registers can't hurt non-MIPS16 functions |
| 3506 | because those registers are normally skipped. */ |
| 3507 | |
| 3508 | if (fp_register_arg_p (typecode, arg_type) |
| 3509 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) |
| 3510 | { |
| 3511 | if (register_size (gdbarch, float_argreg) < 8 && len == 8) |
| 3512 | { |
| 3513 | int low_offset = gdbarch_byte_order (gdbarch) |
| 3514 | == BFD_ENDIAN_BIG ? 4 : 0; |
| 3515 | unsigned long regval; |
| 3516 | |
| 3517 | /* Write the low word of the double to the even register(s). */ |
| 3518 | regval = extract_unsigned_integer (val + low_offset, 4); |
| 3519 | if (mips_debug) |
| 3520 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3521 | float_argreg, phex (regval, 4)); |
| 3522 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 3523 | if (mips_debug) |
| 3524 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
| 3525 | argreg, phex (regval, 4)); |
| 3526 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
| 3527 | |
| 3528 | /* Write the high word of the double to the odd register(s). */ |
| 3529 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
| 3530 | if (mips_debug) |
| 3531 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3532 | float_argreg, phex (regval, 4)); |
| 3533 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 3534 | |
| 3535 | if (mips_debug) |
| 3536 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
| 3537 | argreg, phex (regval, 4)); |
| 3538 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
| 3539 | } |
| 3540 | else |
| 3541 | { |
| 3542 | /* This is a floating point value that fits entirely |
| 3543 | in a single register. */ |
| 3544 | /* On 32 bit ABI's the float_argreg is further adjusted |
| 3545 | above to ensure that it is even register aligned. */ |
| 3546 | LONGEST regval = extract_unsigned_integer (val, len); |
| 3547 | if (mips_debug) |
| 3548 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3549 | float_argreg, phex (regval, len)); |
| 3550 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 3551 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP |
| 3552 | registers for each argument. The below is (my |
| 3553 | guess) to ensure that the corresponding integer |
| 3554 | register has reserved the same space. */ |
| 3555 | if (mips_debug) |
| 3556 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
| 3557 | argreg, phex (regval, len)); |
| 3558 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 3559 | argreg += 2; |
| 3560 | } |
| 3561 | /* Reserve space for the FP register. */ |
| 3562 | stack_offset += align_up (len, MIPS32_REGSIZE); |
| 3563 | } |
| 3564 | else |
| 3565 | { |
| 3566 | /* Copy the argument to general registers or the stack in |
| 3567 | register-sized pieces. Large arguments are split between |
| 3568 | registers and stack. */ |
| 3569 | /* Note: structs whose size is not a multiple of MIPS32_REGSIZE |
| 3570 | are treated specially: Irix cc passes |
| 3571 | them in registers where gcc sometimes puts them on the |
| 3572 | stack. For maximum compatibility, we will put them in |
| 3573 | both places. */ |
| 3574 | int odd_sized_struct = (len > MIPS32_REGSIZE |
| 3575 | && len % MIPS32_REGSIZE != 0); |
| 3576 | /* Structures should be aligned to eight bytes (even arg registers) |
| 3577 | on MIPS_ABI_O32, if their first member has double precision. */ |
| 3578 | if (mips_type_needs_double_align (arg_type)) |
| 3579 | { |
| 3580 | if ((argreg & 1)) |
| 3581 | { |
| 3582 | argreg++; |
| 3583 | stack_offset += MIPS32_REGSIZE; |
| 3584 | } |
| 3585 | } |
| 3586 | while (len > 0) |
| 3587 | { |
| 3588 | /* Remember if the argument was written to the stack. */ |
| 3589 | int stack_used_p = 0; |
| 3590 | int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE); |
| 3591 | |
| 3592 | if (mips_debug) |
| 3593 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", |
| 3594 | partial_len); |
| 3595 | |
| 3596 | /* Write this portion of the argument to the stack. */ |
| 3597 | if (argreg > MIPS_LAST_ARG_REGNUM |
| 3598 | || odd_sized_struct) |
| 3599 | { |
| 3600 | /* Should shorter than int integer values be |
| 3601 | promoted to int before being stored? */ |
| 3602 | int longword_offset = 0; |
| 3603 | CORE_ADDR addr; |
| 3604 | stack_used_p = 1; |
| 3605 | |
| 3606 | if (mips_debug) |
| 3607 | { |
| 3608 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
| 3609 | paddr_nz (stack_offset)); |
| 3610 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", |
| 3611 | paddr_nz (longword_offset)); |
| 3612 | } |
| 3613 | |
| 3614 | addr = sp + stack_offset + longword_offset; |
| 3615 | |
| 3616 | if (mips_debug) |
| 3617 | { |
| 3618 | int i; |
| 3619 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
| 3620 | paddr_nz (addr)); |
| 3621 | for (i = 0; i < partial_len; i++) |
| 3622 | { |
| 3623 | fprintf_unfiltered (gdb_stdlog, "%02x", |
| 3624 | val[i] & 0xff); |
| 3625 | } |
| 3626 | } |
| 3627 | write_memory (addr, val, partial_len); |
| 3628 | } |
| 3629 | |
| 3630 | /* Note!!! This is NOT an else clause. Odd sized |
| 3631 | structs may go thru BOTH paths. */ |
| 3632 | /* Write this portion of the argument to a general |
| 3633 | purpose register. */ |
| 3634 | if (argreg <= MIPS_LAST_ARG_REGNUM) |
| 3635 | { |
| 3636 | LONGEST regval = extract_signed_integer (val, partial_len); |
| 3637 | /* Value may need to be sign extended, because |
| 3638 | mips_isa_regsize() != mips_abi_regsize(). */ |
| 3639 | |
| 3640 | /* A non-floating-point argument being passed in a |
| 3641 | general register. If a struct or union, and if |
| 3642 | the remaining length is smaller than the register |
| 3643 | size, we have to adjust the register value on |
| 3644 | big endian targets. |
| 3645 | |
| 3646 | It does not seem to be necessary to do the |
| 3647 | same for integral types. |
| 3648 | |
| 3649 | Also don't do this adjustment on O64 binaries. |
| 3650 | |
| 3651 | cagney/2001-07-23: gdb/179: Also, GCC, when |
| 3652 | outputting LE O32 with sizeof (struct) < |
| 3653 | mips_abi_regsize(), generates a left shift |
| 3654 | as part of storing the argument in a register |
| 3655 | (the left shift isn't generated when |
| 3656 | sizeof (struct) >= mips_abi_regsize()). Since |
| 3657 | it is quite possible that this is GCC |
| 3658 | contradicting the LE/O32 ABI, GDB has not been |
| 3659 | adjusted to accommodate this. Either someone |
| 3660 | needs to demonstrate that the LE/O32 ABI |
| 3661 | specifies such a left shift OR this new ABI gets |
| 3662 | identified as such and GDB gets tweaked |
| 3663 | accordingly. */ |
| 3664 | |
| 3665 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
| 3666 | && partial_len < MIPS32_REGSIZE |
| 3667 | && (typecode == TYPE_CODE_STRUCT |
| 3668 | || typecode == TYPE_CODE_UNION)) |
| 3669 | regval <<= ((MIPS32_REGSIZE - partial_len) |
| 3670 | * TARGET_CHAR_BIT); |
| 3671 | |
| 3672 | if (mips_debug) |
| 3673 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
| 3674 | argreg, |
| 3675 | phex (regval, MIPS32_REGSIZE)); |
| 3676 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 3677 | argreg++; |
| 3678 | |
| 3679 | /* Prevent subsequent floating point arguments from |
| 3680 | being passed in floating point registers. */ |
| 3681 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; |
| 3682 | } |
| 3683 | |
| 3684 | len -= partial_len; |
| 3685 | val += partial_len; |
| 3686 | |
| 3687 | /* Compute the the offset into the stack at which we |
| 3688 | will copy the next parameter. |
| 3689 | |
| 3690 | In older ABIs, the caller reserved space for |
| 3691 | registers that contained arguments. This was loosely |
| 3692 | refered to as their "home". Consequently, space is |
| 3693 | always allocated. */ |
| 3694 | |
| 3695 | stack_offset += align_up (partial_len, MIPS32_REGSIZE); |
| 3696 | } |
| 3697 | } |
| 3698 | if (mips_debug) |
| 3699 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 3700 | } |
| 3701 | |
| 3702 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
| 3703 | |
| 3704 | /* Return adjusted stack pointer. */ |
| 3705 | return sp; |
| 3706 | } |
| 3707 | |
| 3708 | static enum return_value_convention |
| 3709 | mips_o32_return_value (struct gdbarch *gdbarch, struct type *type, |
| 3710 | struct regcache *regcache, |
| 3711 | gdb_byte *readbuf, const gdb_byte *writebuf) |
| 3712 | { |
| 3713 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 3714 | |
| 3715 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 3716 | || TYPE_CODE (type) == TYPE_CODE_UNION |
| 3717 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) |
| 3718 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 3719 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 3720 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3721 | { |
| 3722 | /* A single-precision floating-point value. It fits in the |
| 3723 | least significant part of FP0. */ |
| 3724 | if (mips_debug) |
| 3725 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); |
| 3726 | mips_xfer_register (gdbarch, regcache, |
| 3727 | gdbarch_num_regs (gdbarch) |
| 3728 | + mips_regnum (gdbarch)->fp0, |
| 3729 | TYPE_LENGTH (type), |
| 3730 | gdbarch_byte_order (gdbarch), |
| 3731 | readbuf, writebuf, 0); |
| 3732 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3733 | } |
| 3734 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 3735 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3736 | { |
| 3737 | /* A double-precision floating-point value. The most |
| 3738 | significant part goes in FP1, and the least significant in |
| 3739 | FP0. */ |
| 3740 | if (mips_debug) |
| 3741 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); |
| 3742 | switch (gdbarch_byte_order (gdbarch)) |
| 3743 | { |
| 3744 | case BFD_ENDIAN_LITTLE: |
| 3745 | mips_xfer_register (gdbarch, regcache, |
| 3746 | gdbarch_num_regs (gdbarch) |
| 3747 | + mips_regnum (gdbarch)->fp0 + |
| 3748 | 0, 4, gdbarch_byte_order (gdbarch), |
| 3749 | readbuf, writebuf, 0); |
| 3750 | mips_xfer_register (gdbarch, regcache, |
| 3751 | gdbarch_num_regs (gdbarch) |
| 3752 | + mips_regnum (gdbarch)->fp0 + 1, |
| 3753 | 4, gdbarch_byte_order (gdbarch), |
| 3754 | readbuf, writebuf, 4); |
| 3755 | break; |
| 3756 | case BFD_ENDIAN_BIG: |
| 3757 | mips_xfer_register (gdbarch, regcache, |
| 3758 | gdbarch_num_regs (gdbarch) |
| 3759 | + mips_regnum (gdbarch)->fp0 + 1, |
| 3760 | 4, gdbarch_byte_order (gdbarch), |
| 3761 | readbuf, writebuf, 0); |
| 3762 | mips_xfer_register (gdbarch, regcache, |
| 3763 | gdbarch_num_regs (gdbarch) |
| 3764 | + mips_regnum (gdbarch)->fp0 + 0, |
| 3765 | 4, gdbarch_byte_order (gdbarch), |
| 3766 | readbuf, writebuf, 4); |
| 3767 | break; |
| 3768 | default: |
| 3769 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 3770 | } |
| 3771 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3772 | } |
| 3773 | #if 0 |
| 3774 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 3775 | && TYPE_NFIELDS (type) <= 2 |
| 3776 | && TYPE_NFIELDS (type) >= 1 |
| 3777 | && ((TYPE_NFIELDS (type) == 1 |
| 3778 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) |
| 3779 | == TYPE_CODE_FLT)) |
| 3780 | || (TYPE_NFIELDS (type) == 2 |
| 3781 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) |
| 3782 | == TYPE_CODE_FLT) |
| 3783 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) |
| 3784 | == TYPE_CODE_FLT))) |
| 3785 | && tdep->mips_fpu_type != MIPS_FPU_NONE) |
| 3786 | { |
| 3787 | /* A struct that contains one or two floats. Each value is part |
| 3788 | in the least significant part of their floating point |
| 3789 | register.. */ |
| 3790 | gdb_byte reg[MAX_REGISTER_SIZE]; |
| 3791 | int regnum; |
| 3792 | int field; |
| 3793 | for (field = 0, regnum = mips_regnum (gdbarch)->fp0; |
| 3794 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
| 3795 | { |
| 3796 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) |
| 3797 | / TARGET_CHAR_BIT); |
| 3798 | if (mips_debug) |
| 3799 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", |
| 3800 | offset); |
| 3801 | mips_xfer_register (gdbarch, regcache, |
| 3802 | gdbarch_num_regs (gdbarch) + regnum, |
| 3803 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), |
| 3804 | gdbarch_byte_order (gdbarch), |
| 3805 | readbuf, writebuf, offset); |
| 3806 | } |
| 3807 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3808 | } |
| 3809 | #endif |
| 3810 | #if 0 |
| 3811 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 3812 | || TYPE_CODE (type) == TYPE_CODE_UNION) |
| 3813 | { |
| 3814 | /* A structure or union. Extract the left justified value, |
| 3815 | regardless of the byte order. I.e. DO NOT USE |
| 3816 | mips_xfer_lower. */ |
| 3817 | int offset; |
| 3818 | int regnum; |
| 3819 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
| 3820 | offset < TYPE_LENGTH (type); |
| 3821 | offset += register_size (gdbarch, regnum), regnum++) |
| 3822 | { |
| 3823 | int xfer = register_size (gdbarch, regnum); |
| 3824 | if (offset + xfer > TYPE_LENGTH (type)) |
| 3825 | xfer = TYPE_LENGTH (type) - offset; |
| 3826 | if (mips_debug) |
| 3827 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", |
| 3828 | offset, xfer, regnum); |
| 3829 | mips_xfer_register (gdbarch, regcache, |
| 3830 | gdbarch_num_regs (gdbarch) + regnum, xfer, |
| 3831 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); |
| 3832 | } |
| 3833 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3834 | } |
| 3835 | #endif |
| 3836 | else |
| 3837 | { |
| 3838 | /* A scalar extract each part but least-significant-byte |
| 3839 | justified. o32 thinks registers are 4 byte, regardless of |
| 3840 | the ISA. */ |
| 3841 | int offset; |
| 3842 | int regnum; |
| 3843 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
| 3844 | offset < TYPE_LENGTH (type); |
| 3845 | offset += MIPS32_REGSIZE, regnum++) |
| 3846 | { |
| 3847 | int xfer = MIPS32_REGSIZE; |
| 3848 | if (offset + xfer > TYPE_LENGTH (type)) |
| 3849 | xfer = TYPE_LENGTH (type) - offset; |
| 3850 | if (mips_debug) |
| 3851 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", |
| 3852 | offset, xfer, regnum); |
| 3853 | mips_xfer_register (gdbarch, regcache, |
| 3854 | gdbarch_num_regs (gdbarch) + regnum, xfer, |
| 3855 | gdbarch_byte_order (gdbarch), |
| 3856 | readbuf, writebuf, offset); |
| 3857 | } |
| 3858 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 |
| 3863 | ABI. */ |
| 3864 | |
| 3865 | static CORE_ADDR |
| 3866 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 3867 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 3868 | int nargs, |
| 3869 | struct value **args, CORE_ADDR sp, |
| 3870 | int struct_return, CORE_ADDR struct_addr) |
| 3871 | { |
| 3872 | int argreg; |
| 3873 | int float_argreg; |
| 3874 | int argnum; |
| 3875 | int len = 0; |
| 3876 | int stack_offset = 0; |
| 3877 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 3878 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
| 3879 | |
| 3880 | /* For shared libraries, "t9" needs to point at the function |
| 3881 | address. */ |
| 3882 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
| 3883 | |
| 3884 | /* Set the return address register to point to the entry point of |
| 3885 | the program, where a breakpoint lies in wait. */ |
| 3886 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
| 3887 | |
| 3888 | /* First ensure that the stack and structure return address (if any) |
| 3889 | are properly aligned. The stack has to be at least 64-bit |
| 3890 | aligned even on 32-bit machines, because doubles must be 64-bit |
| 3891 | aligned. For n32 and n64, stack frames need to be 128-bit |
| 3892 | aligned, so we round to this widest known alignment. */ |
| 3893 | |
| 3894 | sp = align_down (sp, 16); |
| 3895 | struct_addr = align_down (struct_addr, 16); |
| 3896 | |
| 3897 | /* Now make space on the stack for the args. */ |
| 3898 | for (argnum = 0; argnum < nargs; argnum++) |
| 3899 | { |
| 3900 | struct type *arg_type = check_typedef (value_type (args[argnum])); |
| 3901 | int arglen = TYPE_LENGTH (arg_type); |
| 3902 | |
| 3903 | /* Allocate space on the stack. */ |
| 3904 | len += align_up (arglen, MIPS64_REGSIZE); |
| 3905 | } |
| 3906 | sp -= align_up (len, 16); |
| 3907 | |
| 3908 | if (mips_debug) |
| 3909 | fprintf_unfiltered (gdb_stdlog, |
| 3910 | "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n", |
| 3911 | paddr_nz (sp), (long) align_up (len, 16)); |
| 3912 | |
| 3913 | /* Initialize the integer and float register pointers. */ |
| 3914 | argreg = MIPS_A0_REGNUM; |
| 3915 | float_argreg = mips_fpa0_regnum (gdbarch); |
| 3916 | |
| 3917 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
| 3918 | if (struct_return) |
| 3919 | { |
| 3920 | if (mips_debug) |
| 3921 | fprintf_unfiltered (gdb_stdlog, |
| 3922 | "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n", |
| 3923 | argreg, paddr_nz (struct_addr)); |
| 3924 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
| 3925 | stack_offset += MIPS64_REGSIZE; |
| 3926 | } |
| 3927 | |
| 3928 | /* Now load as many as possible of the first arguments into |
| 3929 | registers, and push the rest onto the stack. Loop thru args |
| 3930 | from first to last. */ |
| 3931 | for (argnum = 0; argnum < nargs; argnum++) |
| 3932 | { |
| 3933 | const gdb_byte *val; |
| 3934 | struct value *arg = args[argnum]; |
| 3935 | struct type *arg_type = check_typedef (value_type (arg)); |
| 3936 | int len = TYPE_LENGTH (arg_type); |
| 3937 | enum type_code typecode = TYPE_CODE (arg_type); |
| 3938 | |
| 3939 | if (mips_debug) |
| 3940 | fprintf_unfiltered (gdb_stdlog, |
| 3941 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
| 3942 | argnum + 1, len, (int) typecode); |
| 3943 | |
| 3944 | val = value_contents (arg); |
| 3945 | |
| 3946 | /* Floating point arguments passed in registers have to be |
| 3947 | treated specially. On 32-bit architectures, doubles |
| 3948 | are passed in register pairs; the even register gets |
| 3949 | the low word, and the odd register gets the high word. |
| 3950 | On O32/O64, the first two floating point arguments are |
| 3951 | also copied to general registers, because MIPS16 functions |
| 3952 | don't use float registers for arguments. This duplication of |
| 3953 | arguments in general registers can't hurt non-MIPS16 functions |
| 3954 | because those registers are normally skipped. */ |
| 3955 | |
| 3956 | if (fp_register_arg_p (typecode, arg_type) |
| 3957 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) |
| 3958 | { |
| 3959 | LONGEST regval = extract_unsigned_integer (val, len); |
| 3960 | if (mips_debug) |
| 3961 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
| 3962 | float_argreg, phex (regval, len)); |
| 3963 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
| 3964 | if (mips_debug) |
| 3965 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
| 3966 | argreg, phex (regval, len)); |
| 3967 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 3968 | argreg++; |
| 3969 | /* Reserve space for the FP register. */ |
| 3970 | stack_offset += align_up (len, MIPS64_REGSIZE); |
| 3971 | } |
| 3972 | else |
| 3973 | { |
| 3974 | /* Copy the argument to general registers or the stack in |
| 3975 | register-sized pieces. Large arguments are split between |
| 3976 | registers and stack. */ |
| 3977 | /* Note: structs whose size is not a multiple of MIPS64_REGSIZE |
| 3978 | are treated specially: Irix cc passes them in registers |
| 3979 | where gcc sometimes puts them on the stack. For maximum |
| 3980 | compatibility, we will put them in both places. */ |
| 3981 | int odd_sized_struct = (len > MIPS64_REGSIZE |
| 3982 | && len % MIPS64_REGSIZE != 0); |
| 3983 | while (len > 0) |
| 3984 | { |
| 3985 | /* Remember if the argument was written to the stack. */ |
| 3986 | int stack_used_p = 0; |
| 3987 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
| 3988 | |
| 3989 | if (mips_debug) |
| 3990 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", |
| 3991 | partial_len); |
| 3992 | |
| 3993 | /* Write this portion of the argument to the stack. */ |
| 3994 | if (argreg > MIPS_LAST_ARG_REGNUM |
| 3995 | || odd_sized_struct) |
| 3996 | { |
| 3997 | /* Should shorter than int integer values be |
| 3998 | promoted to int before being stored? */ |
| 3999 | int longword_offset = 0; |
| 4000 | CORE_ADDR addr; |
| 4001 | stack_used_p = 1; |
| 4002 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4003 | { |
| 4004 | if ((typecode == TYPE_CODE_INT |
| 4005 | || typecode == TYPE_CODE_PTR |
| 4006 | || typecode == TYPE_CODE_FLT) |
| 4007 | && len <= 4) |
| 4008 | longword_offset = MIPS64_REGSIZE - len; |
| 4009 | } |
| 4010 | |
| 4011 | if (mips_debug) |
| 4012 | { |
| 4013 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
| 4014 | paddr_nz (stack_offset)); |
| 4015 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", |
| 4016 | paddr_nz (longword_offset)); |
| 4017 | } |
| 4018 | |
| 4019 | addr = sp + stack_offset + longword_offset; |
| 4020 | |
| 4021 | if (mips_debug) |
| 4022 | { |
| 4023 | int i; |
| 4024 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
| 4025 | paddr_nz (addr)); |
| 4026 | for (i = 0; i < partial_len; i++) |
| 4027 | { |
| 4028 | fprintf_unfiltered (gdb_stdlog, "%02x", |
| 4029 | val[i] & 0xff); |
| 4030 | } |
| 4031 | } |
| 4032 | write_memory (addr, val, partial_len); |
| 4033 | } |
| 4034 | |
| 4035 | /* Note!!! This is NOT an else clause. Odd sized |
| 4036 | structs may go thru BOTH paths. */ |
| 4037 | /* Write this portion of the argument to a general |
| 4038 | purpose register. */ |
| 4039 | if (argreg <= MIPS_LAST_ARG_REGNUM) |
| 4040 | { |
| 4041 | LONGEST regval = extract_signed_integer (val, partial_len); |
| 4042 | /* Value may need to be sign extended, because |
| 4043 | mips_isa_regsize() != mips_abi_regsize(). */ |
| 4044 | |
| 4045 | /* A non-floating-point argument being passed in a |
| 4046 | general register. If a struct or union, and if |
| 4047 | the remaining length is smaller than the register |
| 4048 | size, we have to adjust the register value on |
| 4049 | big endian targets. |
| 4050 | |
| 4051 | It does not seem to be necessary to do the |
| 4052 | same for integral types. */ |
| 4053 | |
| 4054 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
| 4055 | && partial_len < MIPS64_REGSIZE |
| 4056 | && (typecode == TYPE_CODE_STRUCT |
| 4057 | || typecode == TYPE_CODE_UNION)) |
| 4058 | regval <<= ((MIPS64_REGSIZE - partial_len) |
| 4059 | * TARGET_CHAR_BIT); |
| 4060 | |
| 4061 | if (mips_debug) |
| 4062 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
| 4063 | argreg, |
| 4064 | phex (regval, MIPS64_REGSIZE)); |
| 4065 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
| 4066 | argreg++; |
| 4067 | |
| 4068 | /* Prevent subsequent floating point arguments from |
| 4069 | being passed in floating point registers. */ |
| 4070 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; |
| 4071 | } |
| 4072 | |
| 4073 | len -= partial_len; |
| 4074 | val += partial_len; |
| 4075 | |
| 4076 | /* Compute the the offset into the stack at which we |
| 4077 | will copy the next parameter. |
| 4078 | |
| 4079 | In older ABIs, the caller reserved space for |
| 4080 | registers that contained arguments. This was loosely |
| 4081 | refered to as their "home". Consequently, space is |
| 4082 | always allocated. */ |
| 4083 | |
| 4084 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
| 4085 | } |
| 4086 | } |
| 4087 | if (mips_debug) |
| 4088 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 4089 | } |
| 4090 | |
| 4091 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
| 4092 | |
| 4093 | /* Return adjusted stack pointer. */ |
| 4094 | return sp; |
| 4095 | } |
| 4096 | |
| 4097 | static enum return_value_convention |
| 4098 | mips_o64_return_value (struct gdbarch *gdbarch, |
| 4099 | struct type *type, struct regcache *regcache, |
| 4100 | gdb_byte *readbuf, const gdb_byte *writebuf) |
| 4101 | { |
| 4102 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 4103 | |
| 4104 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 4105 | || TYPE_CODE (type) == TYPE_CODE_UNION |
| 4106 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) |
| 4107 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 4108 | else if (fp_register_arg_p (TYPE_CODE (type), type)) |
| 4109 | { |
| 4110 | /* A floating-point value. It fits in the least significant |
| 4111 | part of FP0. */ |
| 4112 | if (mips_debug) |
| 4113 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); |
| 4114 | mips_xfer_register (gdbarch, regcache, |
| 4115 | gdbarch_num_regs (gdbarch) |
| 4116 | + mips_regnum (gdbarch)->fp0, |
| 4117 | TYPE_LENGTH (type), |
| 4118 | gdbarch_byte_order (gdbarch), |
| 4119 | readbuf, writebuf, 0); |
| 4120 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 4121 | } |
| 4122 | else |
| 4123 | { |
| 4124 | /* A scalar extract each part but least-significant-byte |
| 4125 | justified. */ |
| 4126 | int offset; |
| 4127 | int regnum; |
| 4128 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
| 4129 | offset < TYPE_LENGTH (type); |
| 4130 | offset += MIPS64_REGSIZE, regnum++) |
| 4131 | { |
| 4132 | int xfer = MIPS64_REGSIZE; |
| 4133 | if (offset + xfer > TYPE_LENGTH (type)) |
| 4134 | xfer = TYPE_LENGTH (type) - offset; |
| 4135 | if (mips_debug) |
| 4136 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", |
| 4137 | offset, xfer, regnum); |
| 4138 | mips_xfer_register (gdbarch, regcache, |
| 4139 | gdbarch_num_regs (gdbarch) + regnum, |
| 4140 | xfer, gdbarch_byte_order (gdbarch), |
| 4141 | readbuf, writebuf, offset); |
| 4142 | } |
| 4143 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | /* Floating point register management. |
| 4148 | |
| 4149 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support |
| 4150 | 64bit operations, these early MIPS cpus treat fp register pairs |
| 4151 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp |
| 4152 | registers and offer a compatibility mode that emulates the MIPS2 fp |
| 4153 | model. When operating in MIPS2 fp compat mode, later cpu's split |
| 4154 | double precision floats into two 32-bit chunks and store them in |
| 4155 | consecutive fp regs. To display 64-bit floats stored in this |
| 4156 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. |
| 4157 | Throw in user-configurable endianness and you have a real mess. |
| 4158 | |
| 4159 | The way this works is: |
| 4160 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit |
| 4161 | double-precision value will be split across two logical registers. |
| 4162 | The lower-numbered logical register will hold the low-order bits, |
| 4163 | regardless of the processor's endianness. |
| 4164 | - If we are on a 64-bit processor, and we are looking for a |
| 4165 | single-precision value, it will be in the low ordered bits |
| 4166 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register |
| 4167 | save slot in memory. |
| 4168 | - If we are in 64-bit mode, everything is straightforward. |
| 4169 | |
| 4170 | Note that this code only deals with "live" registers at the top of the |
| 4171 | stack. We will attempt to deal with saved registers later, when |
| 4172 | the raw/cooked register interface is in place. (We need a general |
| 4173 | interface that can deal with dynamic saved register sizes -- fp |
| 4174 | regs could be 32 bits wide in one frame and 64 on the frame above |
| 4175 | and below). */ |
| 4176 | |
| 4177 | static struct type * |
| 4178 | mips_float_register_type (void) |
| 4179 | { |
| 4180 | return builtin_type_ieee_single; |
| 4181 | } |
| 4182 | |
| 4183 | static struct type * |
| 4184 | mips_double_register_type (void) |
| 4185 | { |
| 4186 | return builtin_type_ieee_double; |
| 4187 | } |
| 4188 | |
| 4189 | /* Copy a 32-bit single-precision value from the current frame |
| 4190 | into rare_buffer. */ |
| 4191 | |
| 4192 | static void |
| 4193 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
| 4194 | gdb_byte *rare_buffer) |
| 4195 | { |
| 4196 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 4197 | int raw_size = register_size (gdbarch, regno); |
| 4198 | gdb_byte *raw_buffer = alloca (raw_size); |
| 4199 | |
| 4200 | if (!frame_register_read (frame, regno, raw_buffer)) |
| 4201 | error (_("can't read register %d (%s)"), |
| 4202 | regno, gdbarch_register_name (gdbarch, regno)); |
| 4203 | if (raw_size == 8) |
| 4204 | { |
| 4205 | /* We have a 64-bit value for this register. Find the low-order |
| 4206 | 32 bits. */ |
| 4207 | int offset; |
| 4208 | |
| 4209 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4210 | offset = 4; |
| 4211 | else |
| 4212 | offset = 0; |
| 4213 | |
| 4214 | memcpy (rare_buffer, raw_buffer + offset, 4); |
| 4215 | } |
| 4216 | else |
| 4217 | { |
| 4218 | memcpy (rare_buffer, raw_buffer, 4); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | /* Copy a 64-bit double-precision value from the current frame into |
| 4223 | rare_buffer. This may include getting half of it from the next |
| 4224 | register. */ |
| 4225 | |
| 4226 | static void |
| 4227 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
| 4228 | gdb_byte *rare_buffer) |
| 4229 | { |
| 4230 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 4231 | int raw_size = register_size (gdbarch, regno); |
| 4232 | |
| 4233 | if (raw_size == 8 && !mips2_fp_compat (frame)) |
| 4234 | { |
| 4235 | /* We have a 64-bit value for this register, and we should use |
| 4236 | all 64 bits. */ |
| 4237 | if (!frame_register_read (frame, regno, rare_buffer)) |
| 4238 | error (_("can't read register %d (%s)"), |
| 4239 | regno, gdbarch_register_name (gdbarch, regno)); |
| 4240 | } |
| 4241 | else |
| 4242 | { |
| 4243 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
| 4244 | |
| 4245 | if ((rawnum - mips_regnum (gdbarch)->fp0) & 1) |
| 4246 | internal_error (__FILE__, __LINE__, |
| 4247 | _("mips_read_fp_register_double: bad access to " |
| 4248 | "odd-numbered FP register")); |
| 4249 | |
| 4250 | /* mips_read_fp_register_single will find the correct 32 bits from |
| 4251 | each register. */ |
| 4252 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4253 | { |
| 4254 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
| 4255 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); |
| 4256 | } |
| 4257 | else |
| 4258 | { |
| 4259 | mips_read_fp_register_single (frame, regno, rare_buffer); |
| 4260 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | static void |
| 4266 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
| 4267 | int regnum) |
| 4268 | { /* do values for FP (float) regs */ |
| 4269 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 4270 | gdb_byte *raw_buffer; |
| 4271 | double doub, flt1; /* doubles extracted from raw hex data */ |
| 4272 | int inv1, inv2; |
| 4273 | |
| 4274 | raw_buffer = alloca (2 * register_size (gdbarch, mips_regnum (gdbarch)->fp0)); |
| 4275 | |
| 4276 | fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum)); |
| 4277 | fprintf_filtered (file, "%*s", |
| 4278 | 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)), |
| 4279 | ""); |
| 4280 | |
| 4281 | if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame)) |
| 4282 | { |
| 4283 | /* 4-byte registers: Print hex and floating. Also print even |
| 4284 | numbered registers as doubles. */ |
| 4285 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
| 4286 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
| 4287 | |
| 4288 | print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', |
| 4289 | file); |
| 4290 | |
| 4291 | fprintf_filtered (file, " flt: "); |
| 4292 | if (inv1) |
| 4293 | fprintf_filtered (file, " <invalid float> "); |
| 4294 | else |
| 4295 | fprintf_filtered (file, "%-17.9g", flt1); |
| 4296 | |
| 4297 | if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0) |
| 4298 | { |
| 4299 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
| 4300 | doub = unpack_double (mips_double_register_type (), raw_buffer, |
| 4301 | &inv2); |
| 4302 | |
| 4303 | fprintf_filtered (file, " dbl: "); |
| 4304 | if (inv2) |
| 4305 | fprintf_filtered (file, "<invalid double>"); |
| 4306 | else |
| 4307 | fprintf_filtered (file, "%-24.17g", doub); |
| 4308 | } |
| 4309 | } |
| 4310 | else |
| 4311 | { |
| 4312 | /* Eight byte registers: print each one as hex, float and double. */ |
| 4313 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
| 4314 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
| 4315 | |
| 4316 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
| 4317 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2); |
| 4318 | |
| 4319 | |
| 4320 | print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', |
| 4321 | file); |
| 4322 | |
| 4323 | fprintf_filtered (file, " flt: "); |
| 4324 | if (inv1) |
| 4325 | fprintf_filtered (file, "<invalid float>"); |
| 4326 | else |
| 4327 | fprintf_filtered (file, "%-17.9g", flt1); |
| 4328 | |
| 4329 | fprintf_filtered (file, " dbl: "); |
| 4330 | if (inv2) |
| 4331 | fprintf_filtered (file, "<invalid double>"); |
| 4332 | else |
| 4333 | fprintf_filtered (file, "%-24.17g", doub); |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | static void |
| 4338 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
| 4339 | int regnum) |
| 4340 | { |
| 4341 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 4342 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
| 4343 | int offset; |
| 4344 | |
| 4345 | if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT) |
| 4346 | { |
| 4347 | mips_print_fp_register (file, frame, regnum); |
| 4348 | return; |
| 4349 | } |
| 4350 | |
| 4351 | /* Get the data in raw format. */ |
| 4352 | if (!frame_register_read (frame, regnum, raw_buffer)) |
| 4353 | { |
| 4354 | fprintf_filtered (file, "%s: [Invalid]", |
| 4355 | gdbarch_register_name (gdbarch, regnum)); |
| 4356 | return; |
| 4357 | } |
| 4358 | |
| 4359 | fputs_filtered (gdbarch_register_name (gdbarch, regnum), file); |
| 4360 | |
| 4361 | /* The problem with printing numeric register names (r26, etc.) is that |
| 4362 | the user can't use them on input. Probably the best solution is to |
| 4363 | fix it so that either the numeric or the funky (a2, etc.) names |
| 4364 | are accepted on input. */ |
| 4365 | if (regnum < MIPS_NUMREGS) |
| 4366 | fprintf_filtered (file, "(r%d): ", regnum); |
| 4367 | else |
| 4368 | fprintf_filtered (file, ": "); |
| 4369 | |
| 4370 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4371 | offset = |
| 4372 | register_size (gdbarch, regnum) - register_size (gdbarch, regnum); |
| 4373 | else |
| 4374 | offset = 0; |
| 4375 | |
| 4376 | print_scalar_formatted (raw_buffer + offset, |
| 4377 | register_type (gdbarch, regnum), 'x', 0, |
| 4378 | file); |
| 4379 | } |
| 4380 | |
| 4381 | /* Replacement for generic do_registers_info. |
| 4382 | Print regs in pretty columns. */ |
| 4383 | |
| 4384 | static int |
| 4385 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
| 4386 | int regnum) |
| 4387 | { |
| 4388 | fprintf_filtered (file, " "); |
| 4389 | mips_print_fp_register (file, frame, regnum); |
| 4390 | fprintf_filtered (file, "\n"); |
| 4391 | return regnum + 1; |
| 4392 | } |
| 4393 | |
| 4394 | |
| 4395 | /* Print a row's worth of GP (int) registers, with name labels above */ |
| 4396 | |
| 4397 | static int |
| 4398 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
| 4399 | int start_regnum) |
| 4400 | { |
| 4401 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 4402 | /* do values for GP (int) regs */ |
| 4403 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
| 4404 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */ |
| 4405 | int col, byte; |
| 4406 | int regnum; |
| 4407 | |
| 4408 | /* For GP registers, we print a separate row of names above the vals */ |
| 4409 | for (col = 0, regnum = start_regnum; |
| 4410 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
| 4411 | + gdbarch_num_pseudo_regs (gdbarch); |
| 4412 | regnum++) |
| 4413 | { |
| 4414 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
| 4415 | continue; /* unused register */ |
| 4416 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
| 4417 | TYPE_CODE_FLT) |
| 4418 | break; /* end the row: reached FP register */ |
| 4419 | /* Large registers are handled separately. */ |
| 4420 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
| 4421 | { |
| 4422 | if (col > 0) |
| 4423 | break; /* End the row before this register. */ |
| 4424 | |
| 4425 | /* Print this register on a row by itself. */ |
| 4426 | mips_print_register (file, frame, regnum); |
| 4427 | fprintf_filtered (file, "\n"); |
| 4428 | return regnum + 1; |
| 4429 | } |
| 4430 | if (col == 0) |
| 4431 | fprintf_filtered (file, " "); |
| 4432 | fprintf_filtered (file, |
| 4433 | mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s", |
| 4434 | gdbarch_register_name (gdbarch, regnum)); |
| 4435 | col++; |
| 4436 | } |
| 4437 | |
| 4438 | if (col == 0) |
| 4439 | return regnum; |
| 4440 | |
| 4441 | /* print the R0 to R31 names */ |
| 4442 | if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS) |
| 4443 | fprintf_filtered (file, "\n R%-4d", |
| 4444 | start_regnum % gdbarch_num_regs (gdbarch)); |
| 4445 | else |
| 4446 | fprintf_filtered (file, "\n "); |
| 4447 | |
| 4448 | /* now print the values in hex, 4 or 8 to the row */ |
| 4449 | for (col = 0, regnum = start_regnum; |
| 4450 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
| 4451 | + gdbarch_num_pseudo_regs (gdbarch); |
| 4452 | regnum++) |
| 4453 | { |
| 4454 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
| 4455 | continue; /* unused register */ |
| 4456 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
| 4457 | TYPE_CODE_FLT) |
| 4458 | break; /* end row: reached FP register */ |
| 4459 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
| 4460 | break; /* End row: large register. */ |
| 4461 | |
| 4462 | /* OK: get the data in raw format. */ |
| 4463 | if (!frame_register_read (frame, regnum, raw_buffer)) |
| 4464 | error (_("can't read register %d (%s)"), |
| 4465 | regnum, gdbarch_register_name (gdbarch, regnum)); |
| 4466 | /* pad small registers */ |
| 4467 | for (byte = 0; |
| 4468 | byte < (mips_abi_regsize (gdbarch) |
| 4469 | - register_size (gdbarch, regnum)); byte++) |
| 4470 | printf_filtered (" "); |
| 4471 | /* Now print the register value in hex, endian order. */ |
| 4472 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4473 | for (byte = |
| 4474 | register_size (gdbarch, regnum) - register_size (gdbarch, regnum); |
| 4475 | byte < register_size (gdbarch, regnum); byte++) |
| 4476 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
| 4477 | else |
| 4478 | for (byte = register_size (gdbarch, regnum) - 1; |
| 4479 | byte >= 0; byte--) |
| 4480 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
| 4481 | fprintf_filtered (file, " "); |
| 4482 | col++; |
| 4483 | } |
| 4484 | if (col > 0) /* ie. if we actually printed anything... */ |
| 4485 | fprintf_filtered (file, "\n"); |
| 4486 | |
| 4487 | return regnum; |
| 4488 | } |
| 4489 | |
| 4490 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ |
| 4491 | |
| 4492 | static void |
| 4493 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
| 4494 | struct frame_info *frame, int regnum, int all) |
| 4495 | { |
| 4496 | if (regnum != -1) /* do one specified register */ |
| 4497 | { |
| 4498 | gdb_assert (regnum >= gdbarch_num_regs (gdbarch)); |
| 4499 | if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') |
| 4500 | error (_("Not a valid register for the current processor type")); |
| 4501 | |
| 4502 | mips_print_register (file, frame, regnum); |
| 4503 | fprintf_filtered (file, "\n"); |
| 4504 | } |
| 4505 | else |
| 4506 | /* do all (or most) registers */ |
| 4507 | { |
| 4508 | regnum = gdbarch_num_regs (gdbarch); |
| 4509 | while (regnum < gdbarch_num_regs (gdbarch) |
| 4510 | + gdbarch_num_pseudo_regs (gdbarch)) |
| 4511 | { |
| 4512 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
| 4513 | TYPE_CODE_FLT) |
| 4514 | { |
| 4515 | if (all) /* true for "INFO ALL-REGISTERS" command */ |
| 4516 | regnum = print_fp_register_row (file, frame, regnum); |
| 4517 | else |
| 4518 | regnum += MIPS_NUMREGS; /* skip floating point regs */ |
| 4519 | } |
| 4520 | else |
| 4521 | regnum = print_gp_register_row (file, frame, regnum); |
| 4522 | } |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | /* Is this a branch with a delay slot? */ |
| 4527 | |
| 4528 | static int |
| 4529 | is_delayed (unsigned long insn) |
| 4530 | { |
| 4531 | int i; |
| 4532 | for (i = 0; i < NUMOPCODES; ++i) |
| 4533 | if (mips_opcodes[i].pinfo != INSN_MACRO |
| 4534 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) |
| 4535 | break; |
| 4536 | return (i < NUMOPCODES |
| 4537 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY |
| 4538 | | INSN_COND_BRANCH_DELAY |
| 4539 | | INSN_COND_BRANCH_LIKELY))); |
| 4540 | } |
| 4541 | |
| 4542 | int |
| 4543 | mips_single_step_through_delay (struct gdbarch *gdbarch, |
| 4544 | struct frame_info *frame) |
| 4545 | { |
| 4546 | CORE_ADDR pc = get_frame_pc (frame); |
| 4547 | gdb_byte buf[MIPS_INSN32_SIZE]; |
| 4548 | |
| 4549 | /* There is no branch delay slot on MIPS16. */ |
| 4550 | if (mips_pc_is_mips16 (pc)) |
| 4551 | return 0; |
| 4552 | |
| 4553 | if (!breakpoint_here_p (pc + 4)) |
| 4554 | return 0; |
| 4555 | |
| 4556 | if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf)) |
| 4557 | /* If error reading memory, guess that it is not a delayed |
| 4558 | branch. */ |
| 4559 | return 0; |
| 4560 | return is_delayed (extract_unsigned_integer (buf, sizeof buf)); |
| 4561 | } |
| 4562 | |
| 4563 | /* To skip prologues, I use this predicate. Returns either PC itself |
| 4564 | if the code at PC does not look like a function prologue; otherwise |
| 4565 | returns an address that (if we're lucky) follows the prologue. If |
| 4566 | LENIENT, then we must skip everything which is involved in setting |
| 4567 | up the frame (it's OK to skip more, just so long as we don't skip |
| 4568 | anything which might clobber the registers which are being saved. |
| 4569 | We must skip more in the case where part of the prologue is in the |
| 4570 | delay slot of a non-prologue instruction). */ |
| 4571 | |
| 4572 | static CORE_ADDR |
| 4573 | mips_skip_prologue (CORE_ADDR pc) |
| 4574 | { |
| 4575 | CORE_ADDR limit_pc; |
| 4576 | CORE_ADDR func_addr; |
| 4577 | |
| 4578 | /* See if we can determine the end of the prologue via the symbol table. |
| 4579 | If so, then return either PC, or the PC after the prologue, whichever |
| 4580 | is greater. */ |
| 4581 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) |
| 4582 | { |
| 4583 | CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr); |
| 4584 | if (post_prologue_pc != 0) |
| 4585 | return max (pc, post_prologue_pc); |
| 4586 | } |
| 4587 | |
| 4588 | /* Can't determine prologue from the symbol table, need to examine |
| 4589 | instructions. */ |
| 4590 | |
| 4591 | /* Find an upper limit on the function prologue using the debug |
| 4592 | information. If the debug information could not be used to provide |
| 4593 | that bound, then use an arbitrary large number as the upper bound. */ |
| 4594 | limit_pc = skip_prologue_using_sal (pc); |
| 4595 | if (limit_pc == 0) |
| 4596 | limit_pc = pc + 100; /* Magic. */ |
| 4597 | |
| 4598 | if (mips_pc_is_mips16 (pc)) |
| 4599 | return mips16_scan_prologue (pc, limit_pc, NULL, NULL); |
| 4600 | else |
| 4601 | return mips32_scan_prologue (pc, limit_pc, NULL, NULL); |
| 4602 | } |
| 4603 | |
| 4604 | /* Check whether the PC is in a function epilogue (32-bit version). |
| 4605 | This is a helper function for mips_in_function_epilogue_p. */ |
| 4606 | static int |
| 4607 | mips32_in_function_epilogue_p (CORE_ADDR pc) |
| 4608 | { |
| 4609 | CORE_ADDR func_addr = 0, func_end = 0; |
| 4610 | |
| 4611 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
| 4612 | { |
| 4613 | /* The MIPS epilogue is max. 12 bytes long. */ |
| 4614 | CORE_ADDR addr = func_end - 12; |
| 4615 | |
| 4616 | if (addr < func_addr + 4) |
| 4617 | addr = func_addr + 4; |
| 4618 | if (pc < addr) |
| 4619 | return 0; |
| 4620 | |
| 4621 | for (; pc < func_end; pc += MIPS_INSN32_SIZE) |
| 4622 | { |
| 4623 | unsigned long high_word; |
| 4624 | unsigned long inst; |
| 4625 | |
| 4626 | inst = mips_fetch_instruction (pc); |
| 4627 | high_word = (inst >> 16) & 0xffff; |
| 4628 | |
| 4629 | if (high_word != 0x27bd /* addiu $sp,$sp,offset */ |
| 4630 | && high_word != 0x67bd /* daddiu $sp,$sp,offset */ |
| 4631 | && inst != 0x03e00008 /* jr $ra */ |
| 4632 | && inst != 0x00000000) /* nop */ |
| 4633 | return 0; |
| 4634 | } |
| 4635 | |
| 4636 | return 1; |
| 4637 | } |
| 4638 | |
| 4639 | return 0; |
| 4640 | } |
| 4641 | |
| 4642 | /* Check whether the PC is in a function epilogue (16-bit version). |
| 4643 | This is a helper function for mips_in_function_epilogue_p. */ |
| 4644 | static int |
| 4645 | mips16_in_function_epilogue_p (CORE_ADDR pc) |
| 4646 | { |
| 4647 | CORE_ADDR func_addr = 0, func_end = 0; |
| 4648 | |
| 4649 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
| 4650 | { |
| 4651 | /* The MIPS epilogue is max. 12 bytes long. */ |
| 4652 | CORE_ADDR addr = func_end - 12; |
| 4653 | |
| 4654 | if (addr < func_addr + 4) |
| 4655 | addr = func_addr + 4; |
| 4656 | if (pc < addr) |
| 4657 | return 0; |
| 4658 | |
| 4659 | for (; pc < func_end; pc += MIPS_INSN16_SIZE) |
| 4660 | { |
| 4661 | unsigned short inst; |
| 4662 | |
| 4663 | inst = mips_fetch_instruction (pc); |
| 4664 | |
| 4665 | if ((inst & 0xf800) == 0xf000) /* extend */ |
| 4666 | continue; |
| 4667 | |
| 4668 | if (inst != 0x6300 /* addiu $sp,offset */ |
| 4669 | && inst != 0xfb00 /* daddiu $sp,$sp,offset */ |
| 4670 | && inst != 0xe820 /* jr $ra */ |
| 4671 | && inst != 0xe8a0 /* jrc $ra */ |
| 4672 | && inst != 0x6500) /* nop */ |
| 4673 | return 0; |
| 4674 | } |
| 4675 | |
| 4676 | return 1; |
| 4677 | } |
| 4678 | |
| 4679 | return 0; |
| 4680 | } |
| 4681 | |
| 4682 | /* The epilogue is defined here as the area at the end of a function, |
| 4683 | after an instruction which destroys the function's stack frame. */ |
| 4684 | static int |
| 4685 | mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 4686 | { |
| 4687 | if (mips_pc_is_mips16 (pc)) |
| 4688 | return mips16_in_function_epilogue_p (pc); |
| 4689 | else |
| 4690 | return mips32_in_function_epilogue_p (pc); |
| 4691 | } |
| 4692 | |
| 4693 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
| 4694 | used for all MIPS-specific commands. */ |
| 4695 | |
| 4696 | static void |
| 4697 | show_mips_command (char *args, int from_tty) |
| 4698 | { |
| 4699 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); |
| 4700 | } |
| 4701 | |
| 4702 | static void |
| 4703 | set_mips_command (char *args, int from_tty) |
| 4704 | { |
| 4705 | printf_unfiltered |
| 4706 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); |
| 4707 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
| 4708 | } |
| 4709 | |
| 4710 | /* Commands to show/set the MIPS FPU type. */ |
| 4711 | |
| 4712 | static void |
| 4713 | show_mipsfpu_command (char *args, int from_tty) |
| 4714 | { |
| 4715 | char *fpu; |
| 4716 | |
| 4717 | if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips) |
| 4718 | { |
| 4719 | printf_unfiltered |
| 4720 | ("The MIPS floating-point coprocessor is unknown " |
| 4721 | "because the current architecture is not MIPS.\n"); |
| 4722 | return; |
| 4723 | } |
| 4724 | |
| 4725 | switch (MIPS_FPU_TYPE) |
| 4726 | { |
| 4727 | case MIPS_FPU_SINGLE: |
| 4728 | fpu = "single-precision"; |
| 4729 | break; |
| 4730 | case MIPS_FPU_DOUBLE: |
| 4731 | fpu = "double-precision"; |
| 4732 | break; |
| 4733 | case MIPS_FPU_NONE: |
| 4734 | fpu = "absent (none)"; |
| 4735 | break; |
| 4736 | default: |
| 4737 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 4738 | } |
| 4739 | if (mips_fpu_type_auto) |
| 4740 | printf_unfiltered |
| 4741 | ("The MIPS floating-point coprocessor is set automatically (currently %s)\n", |
| 4742 | fpu); |
| 4743 | else |
| 4744 | printf_unfiltered |
| 4745 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); |
| 4746 | } |
| 4747 | |
| 4748 | |
| 4749 | static void |
| 4750 | set_mipsfpu_command (char *args, int from_tty) |
| 4751 | { |
| 4752 | printf_unfiltered |
| 4753 | ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n"); |
| 4754 | show_mipsfpu_command (args, from_tty); |
| 4755 | } |
| 4756 | |
| 4757 | static void |
| 4758 | set_mipsfpu_single_command (char *args, int from_tty) |
| 4759 | { |
| 4760 | struct gdbarch_info info; |
| 4761 | gdbarch_info_init (&info); |
| 4762 | mips_fpu_type = MIPS_FPU_SINGLE; |
| 4763 | mips_fpu_type_auto = 0; |
| 4764 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
| 4765 | instead of relying on globals. Doing that would let generic code |
| 4766 | handle the search for this specific architecture. */ |
| 4767 | if (!gdbarch_update_p (info)) |
| 4768 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
| 4769 | } |
| 4770 | |
| 4771 | static void |
| 4772 | set_mipsfpu_double_command (char *args, int from_tty) |
| 4773 | { |
| 4774 | struct gdbarch_info info; |
| 4775 | gdbarch_info_init (&info); |
| 4776 | mips_fpu_type = MIPS_FPU_DOUBLE; |
| 4777 | mips_fpu_type_auto = 0; |
| 4778 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
| 4779 | instead of relying on globals. Doing that would let generic code |
| 4780 | handle the search for this specific architecture. */ |
| 4781 | if (!gdbarch_update_p (info)) |
| 4782 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
| 4783 | } |
| 4784 | |
| 4785 | static void |
| 4786 | set_mipsfpu_none_command (char *args, int from_tty) |
| 4787 | { |
| 4788 | struct gdbarch_info info; |
| 4789 | gdbarch_info_init (&info); |
| 4790 | mips_fpu_type = MIPS_FPU_NONE; |
| 4791 | mips_fpu_type_auto = 0; |
| 4792 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
| 4793 | instead of relying on globals. Doing that would let generic code |
| 4794 | handle the search for this specific architecture. */ |
| 4795 | if (!gdbarch_update_p (info)) |
| 4796 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
| 4797 | } |
| 4798 | |
| 4799 | static void |
| 4800 | set_mipsfpu_auto_command (char *args, int from_tty) |
| 4801 | { |
| 4802 | mips_fpu_type_auto = 1; |
| 4803 | } |
| 4804 | |
| 4805 | /* Attempt to identify the particular processor model by reading the |
| 4806 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
| 4807 | the relevant processor still exists (it dates back to '94) and |
| 4808 | secondly this is not the way to do this. The processor type should |
| 4809 | be set by forcing an architecture change. */ |
| 4810 | |
| 4811 | void |
| 4812 | deprecated_mips_set_processor_regs_hack (void) |
| 4813 | { |
| 4814 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
| 4815 | ULONGEST prid; |
| 4816 | |
| 4817 | regcache_cooked_read_unsigned (get_current_regcache (), |
| 4818 | MIPS_PRID_REGNUM, &prid); |
| 4819 | if ((prid & ~0xf) == 0x700) |
| 4820 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
| 4821 | } |
| 4822 | |
| 4823 | /* Just like reinit_frame_cache, but with the right arguments to be |
| 4824 | callable as an sfunc. */ |
| 4825 | |
| 4826 | static void |
| 4827 | reinit_frame_cache_sfunc (char *args, int from_tty, |
| 4828 | struct cmd_list_element *c) |
| 4829 | { |
| 4830 | reinit_frame_cache (); |
| 4831 | } |
| 4832 | |
| 4833 | static int |
| 4834 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) |
| 4835 | { |
| 4836 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
| 4837 | |
| 4838 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
| 4839 | disassembler needs to be able to locally determine the ISA, and |
| 4840 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not |
| 4841 | work. */ |
| 4842 | if (mips_pc_is_mips16 (memaddr)) |
| 4843 | info->mach = bfd_mach_mips16; |
| 4844 | |
| 4845 | /* Round down the instruction address to the appropriate boundary. */ |
| 4846 | memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3); |
| 4847 | |
| 4848 | /* Set the disassembler options. */ |
| 4849 | if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64) |
| 4850 | { |
| 4851 | /* Set up the disassembler info, so that we get the right |
| 4852 | register names from libopcodes. */ |
| 4853 | if (tdep->mips_abi == MIPS_ABI_N32) |
| 4854 | info->disassembler_options = "gpr-names=n32"; |
| 4855 | else |
| 4856 | info->disassembler_options = "gpr-names=64"; |
| 4857 | info->flavour = bfd_target_elf_flavour; |
| 4858 | } |
| 4859 | else |
| 4860 | /* This string is not recognized explicitly by the disassembler, |
| 4861 | but it tells the disassembler to not try to guess the ABI from |
| 4862 | the bfd elf headers, such that, if the user overrides the ABI |
| 4863 | of a program linked as NewABI, the disassembly will follow the |
| 4864 | register naming conventions specified by the user. */ |
| 4865 | info->disassembler_options = "gpr-names=32"; |
| 4866 | |
| 4867 | /* Call the appropriate disassembler based on the target endian-ness. */ |
| 4868 | if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG) |
| 4869 | return print_insn_big_mips (memaddr, info); |
| 4870 | else |
| 4871 | return print_insn_little_mips (memaddr, info); |
| 4872 | } |
| 4873 | |
| 4874 | /* This function implements gdbarch_breakpoint_from_pc. It uses the program |
| 4875 | counter value to determine whether a 16- or 32-bit breakpoint should be used. |
| 4876 | It returns a pointer to a string of bytes that encode a breakpoint |
| 4877 | instruction, stores the length of the string to *lenptr, and adjusts pc (if |
| 4878 | necessary) to point to the actual memory location where the breakpoint |
| 4879 | should be inserted. */ |
| 4880 | |
| 4881 | static const gdb_byte * |
| 4882 | mips_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr) |
| 4883 | { |
| 4884 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
| 4885 | { |
| 4886 | if (mips_pc_is_mips16 (*pcptr)) |
| 4887 | { |
| 4888 | static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
| 4889 | *pcptr = unmake_mips16_addr (*pcptr); |
| 4890 | *lenptr = sizeof (mips16_big_breakpoint); |
| 4891 | return mips16_big_breakpoint; |
| 4892 | } |
| 4893 | else |
| 4894 | { |
| 4895 | /* The IDT board uses an unusual breakpoint value, and |
| 4896 | sometimes gets confused when it sees the usual MIPS |
| 4897 | breakpoint instruction. */ |
| 4898 | static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
| 4899 | static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; |
| 4900 | static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; |
| 4901 | |
| 4902 | *lenptr = sizeof (big_breakpoint); |
| 4903 | |
| 4904 | if (strcmp (target_shortname, "mips") == 0) |
| 4905 | return idt_big_breakpoint; |
| 4906 | else if (strcmp (target_shortname, "ddb") == 0 |
| 4907 | || strcmp (target_shortname, "pmon") == 0 |
| 4908 | || strcmp (target_shortname, "lsi") == 0) |
| 4909 | return pmon_big_breakpoint; |
| 4910 | else |
| 4911 | return big_breakpoint; |
| 4912 | } |
| 4913 | } |
| 4914 | else |
| 4915 | { |
| 4916 | if (mips_pc_is_mips16 (*pcptr)) |
| 4917 | { |
| 4918 | static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
| 4919 | *pcptr = unmake_mips16_addr (*pcptr); |
| 4920 | *lenptr = sizeof (mips16_little_breakpoint); |
| 4921 | return mips16_little_breakpoint; |
| 4922 | } |
| 4923 | else |
| 4924 | { |
| 4925 | static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
| 4926 | static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; |
| 4927 | static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; |
| 4928 | |
| 4929 | *lenptr = sizeof (little_breakpoint); |
| 4930 | |
| 4931 | if (strcmp (target_shortname, "mips") == 0) |
| 4932 | return idt_little_breakpoint; |
| 4933 | else if (strcmp (target_shortname, "ddb") == 0 |
| 4934 | || strcmp (target_shortname, "pmon") == 0 |
| 4935 | || strcmp (target_shortname, "lsi") == 0) |
| 4936 | return pmon_little_breakpoint; |
| 4937 | else |
| 4938 | return little_breakpoint; |
| 4939 | } |
| 4940 | } |
| 4941 | } |
| 4942 | |
| 4943 | /* If PC is in a mips16 call or return stub, return the address of the target |
| 4944 | PC, which is either the callee or the caller. There are several |
| 4945 | cases which must be handled: |
| 4946 | |
| 4947 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the |
| 4948 | target PC is in $31 ($ra). |
| 4949 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
| 4950 | and the target PC is in $2. |
| 4951 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
| 4952 | before the jal instruction, this is effectively a call stub |
| 4953 | and the the target PC is in $2. Otherwise this is effectively |
| 4954 | a return stub and the target PC is in $18. |
| 4955 | |
| 4956 | See the source code for the stubs in gcc/config/mips/mips16.S for |
| 4957 | gory details. */ |
| 4958 | |
| 4959 | static CORE_ADDR |
| 4960 | mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) |
| 4961 | { |
| 4962 | char *name; |
| 4963 | CORE_ADDR start_addr; |
| 4964 | |
| 4965 | /* Find the starting address and name of the function containing the PC. */ |
| 4966 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) |
| 4967 | return 0; |
| 4968 | |
| 4969 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the |
| 4970 | target PC is in $31 ($ra). */ |
| 4971 | if (strcmp (name, "__mips16_ret_sf") == 0 |
| 4972 | || strcmp (name, "__mips16_ret_df") == 0) |
| 4973 | return get_frame_register_signed (frame, MIPS_RA_REGNUM); |
| 4974 | |
| 4975 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) |
| 4976 | { |
| 4977 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
| 4978 | and the target PC is in $2. */ |
| 4979 | if (name[19] >= '0' && name[19] <= '9') |
| 4980 | return get_frame_register_signed (frame, 2); |
| 4981 | |
| 4982 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
| 4983 | before the jal instruction, this is effectively a call stub |
| 4984 | and the the target PC is in $2. Otherwise this is effectively |
| 4985 | a return stub and the target PC is in $18. */ |
| 4986 | else if (name[19] == 's' || name[19] == 'd') |
| 4987 | { |
| 4988 | if (pc == start_addr) |
| 4989 | { |
| 4990 | /* Check if the target of the stub is a compiler-generated |
| 4991 | stub. Such a stub for a function bar might have a name |
| 4992 | like __fn_stub_bar, and might look like this: |
| 4993 | mfc1 $4,$f13 |
| 4994 | mfc1 $5,$f12 |
| 4995 | mfc1 $6,$f15 |
| 4996 | mfc1 $7,$f14 |
| 4997 | la $1,bar (becomes a lui/addiu pair) |
| 4998 | jr $1 |
| 4999 | So scan down to the lui/addi and extract the target |
| 5000 | address from those two instructions. */ |
| 5001 | |
| 5002 | CORE_ADDR target_pc = get_frame_register_signed (frame, 2); |
| 5003 | ULONGEST inst; |
| 5004 | int i; |
| 5005 | |
| 5006 | /* See if the name of the target function is __fn_stub_*. */ |
| 5007 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == |
| 5008 | 0) |
| 5009 | return target_pc; |
| 5010 | if (strncmp (name, "__fn_stub_", 10) != 0 |
| 5011 | && strcmp (name, "etext") != 0 |
| 5012 | && strcmp (name, "_etext") != 0) |
| 5013 | return target_pc; |
| 5014 | |
| 5015 | /* Scan through this _fn_stub_ code for the lui/addiu pair. |
| 5016 | The limit on the search is arbitrarily set to 20 |
| 5017 | instructions. FIXME. */ |
| 5018 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE) |
| 5019 | { |
| 5020 | inst = mips_fetch_instruction (target_pc); |
| 5021 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ |
| 5022 | pc = (inst << 16) & 0xffff0000; /* high word */ |
| 5023 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ |
| 5024 | return pc | (inst & 0xffff); /* low word */ |
| 5025 | } |
| 5026 | |
| 5027 | /* Couldn't find the lui/addui pair, so return stub address. */ |
| 5028 | return target_pc; |
| 5029 | } |
| 5030 | else |
| 5031 | /* This is the 'return' part of a call stub. The return |
| 5032 | address is in $r18. */ |
| 5033 | return get_frame_register_signed (frame, 18); |
| 5034 | } |
| 5035 | } |
| 5036 | return 0; /* not a stub */ |
| 5037 | } |
| 5038 | |
| 5039 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
| 5040 | [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
| 5041 | |
| 5042 | static int |
| 5043 | mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num) |
| 5044 | { |
| 5045 | int regnum; |
| 5046 | if (num >= 0 && num < 32) |
| 5047 | regnum = num; |
| 5048 | else if (num >= 38 && num < 70) |
| 5049 | regnum = num + mips_regnum (gdbarch)->fp0 - 38; |
| 5050 | else if (num == 70) |
| 5051 | regnum = mips_regnum (gdbarch)->hi; |
| 5052 | else if (num == 71) |
| 5053 | regnum = mips_regnum (gdbarch)->lo; |
| 5054 | else |
| 5055 | /* This will hopefully (eventually) provoke a warning. Should |
| 5056 | we be calling complaint() here? */ |
| 5057 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
| 5058 | return gdbarch_num_regs (gdbarch) + regnum; |
| 5059 | } |
| 5060 | |
| 5061 | |
| 5062 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
| 5063 | gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
| 5064 | |
| 5065 | static int |
| 5066 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num) |
| 5067 | { |
| 5068 | int regnum; |
| 5069 | if (num >= 0 && num < 32) |
| 5070 | regnum = num; |
| 5071 | else if (num >= 32 && num < 64) |
| 5072 | regnum = num + mips_regnum (gdbarch)->fp0 - 32; |
| 5073 | else if (num == 64) |
| 5074 | regnum = mips_regnum (gdbarch)->hi; |
| 5075 | else if (num == 65) |
| 5076 | regnum = mips_regnum (gdbarch)->lo; |
| 5077 | else |
| 5078 | /* This will hopefully (eventually) provoke a warning. Should we |
| 5079 | be calling complaint() here? */ |
| 5080 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
| 5081 | return gdbarch_num_regs (gdbarch) + regnum; |
| 5082 | } |
| 5083 | |
| 5084 | static int |
| 5085 | mips_register_sim_regno (struct gdbarch *gdbarch, int regnum) |
| 5086 | { |
| 5087 | /* Only makes sense to supply raw registers. */ |
| 5088 | gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); |
| 5089 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to |
| 5090 | decide if it is valid. Should instead define a standard sim/gdb |
| 5091 | register numbering scheme. */ |
| 5092 | if (gdbarch_register_name (gdbarch, |
| 5093 | gdbarch_num_regs (gdbarch) + regnum) != NULL |
| 5094 | && gdbarch_register_name (gdbarch, |
| 5095 | gdbarch_num_regs (gdbarch) + regnum)[0] != '\0') |
| 5096 | return regnum; |
| 5097 | else |
| 5098 | return LEGACY_SIM_REGNO_IGNORE; |
| 5099 | } |
| 5100 | |
| 5101 | |
| 5102 | /* Convert an integer into an address. Extracting the value signed |
| 5103 | guarantees a correctly sign extended address. */ |
| 5104 | |
| 5105 | static CORE_ADDR |
| 5106 | mips_integer_to_address (struct gdbarch *gdbarch, |
| 5107 | struct type *type, const gdb_byte *buf) |
| 5108 | { |
| 5109 | return (CORE_ADDR) extract_signed_integer (buf, TYPE_LENGTH (type)); |
| 5110 | } |
| 5111 | |
| 5112 | /* Dummy virtual frame pointer method. This is no more or less accurate |
| 5113 | than most other architectures; we just need to be explicit about it, |
| 5114 | because the pseudo-register gdbarch_sp_regnum will otherwise lead to |
| 5115 | an assertion failure. */ |
| 5116 | |
| 5117 | static void |
| 5118 | mips_virtual_frame_pointer (struct gdbarch *gdbarch, |
| 5119 | CORE_ADDR pc, int *reg, LONGEST *offset) |
| 5120 | { |
| 5121 | *reg = MIPS_SP_REGNUM; |
| 5122 | *offset = 0; |
| 5123 | } |
| 5124 | |
| 5125 | static void |
| 5126 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) |
| 5127 | { |
| 5128 | enum mips_abi *abip = (enum mips_abi *) obj; |
| 5129 | const char *name = bfd_get_section_name (abfd, sect); |
| 5130 | |
| 5131 | if (*abip != MIPS_ABI_UNKNOWN) |
| 5132 | return; |
| 5133 | |
| 5134 | if (strncmp (name, ".mdebug.", 8) != 0) |
| 5135 | return; |
| 5136 | |
| 5137 | if (strcmp (name, ".mdebug.abi32") == 0) |
| 5138 | *abip = MIPS_ABI_O32; |
| 5139 | else if (strcmp (name, ".mdebug.abiN32") == 0) |
| 5140 | *abip = MIPS_ABI_N32; |
| 5141 | else if (strcmp (name, ".mdebug.abi64") == 0) |
| 5142 | *abip = MIPS_ABI_N64; |
| 5143 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
| 5144 | *abip = MIPS_ABI_O64; |
| 5145 | else if (strcmp (name, ".mdebug.eabi32") == 0) |
| 5146 | *abip = MIPS_ABI_EABI32; |
| 5147 | else if (strcmp (name, ".mdebug.eabi64") == 0) |
| 5148 | *abip = MIPS_ABI_EABI64; |
| 5149 | else |
| 5150 | warning (_("unsupported ABI %s."), name + 8); |
| 5151 | } |
| 5152 | |
| 5153 | static void |
| 5154 | mips_find_long_section (bfd *abfd, asection *sect, void *obj) |
| 5155 | { |
| 5156 | int *lbp = (int *) obj; |
| 5157 | const char *name = bfd_get_section_name (abfd, sect); |
| 5158 | |
| 5159 | if (strncmp (name, ".gcc_compiled_long32", 20) == 0) |
| 5160 | *lbp = 32; |
| 5161 | else if (strncmp (name, ".gcc_compiled_long64", 20) == 0) |
| 5162 | *lbp = 64; |
| 5163 | else if (strncmp (name, ".gcc_compiled_long", 18) == 0) |
| 5164 | warning (_("unrecognized .gcc_compiled_longXX")); |
| 5165 | } |
| 5166 | |
| 5167 | static enum mips_abi |
| 5168 | global_mips_abi (void) |
| 5169 | { |
| 5170 | int i; |
| 5171 | |
| 5172 | for (i = 0; mips_abi_strings[i] != NULL; i++) |
| 5173 | if (mips_abi_strings[i] == mips_abi_string) |
| 5174 | return (enum mips_abi) i; |
| 5175 | |
| 5176 | internal_error (__FILE__, __LINE__, _("unknown ABI string")); |
| 5177 | } |
| 5178 | |
| 5179 | static void |
| 5180 | mips_register_g_packet_guesses (struct gdbarch *gdbarch) |
| 5181 | { |
| 5182 | /* If the size matches the set of 32-bit or 64-bit integer registers, |
| 5183 | assume that's what we've got. */ |
| 5184 | register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32); |
| 5185 | register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64); |
| 5186 | |
| 5187 | /* If the size matches the full set of registers GDB traditionally |
| 5188 | knows about, including floating point, for either 32-bit or |
| 5189 | 64-bit, assume that's what we've got. */ |
| 5190 | register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32); |
| 5191 | register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64); |
| 5192 | |
| 5193 | /* Otherwise we don't have a useful guess. */ |
| 5194 | } |
| 5195 | |
| 5196 | static struct value * |
| 5197 | value_of_mips_user_reg (struct frame_info *frame, const void *baton) |
| 5198 | { |
| 5199 | const int *reg_p = baton; |
| 5200 | return value_of_register (*reg_p, frame); |
| 5201 | } |
| 5202 | |
| 5203 | static struct gdbarch * |
| 5204 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
| 5205 | { |
| 5206 | struct gdbarch *gdbarch; |
| 5207 | struct gdbarch_tdep *tdep; |
| 5208 | int elf_flags; |
| 5209 | enum mips_abi mips_abi, found_abi, wanted_abi; |
| 5210 | int i, num_regs; |
| 5211 | enum mips_fpu_type fpu_type; |
| 5212 | struct tdesc_arch_data *tdesc_data = NULL; |
| 5213 | int elf_fpu_type = 0; |
| 5214 | |
| 5215 | /* Check any target description for validity. */ |
| 5216 | if (tdesc_has_registers (info.target_desc)) |
| 5217 | { |
| 5218 | static const char *const mips_gprs[] = { |
| 5219 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 5220 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 5221 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 5222 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" |
| 5223 | }; |
| 5224 | static const char *const mips_fprs[] = { |
| 5225 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 5226 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 5227 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 5228 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 5229 | }; |
| 5230 | |
| 5231 | const struct tdesc_feature *feature; |
| 5232 | int valid_p; |
| 5233 | |
| 5234 | feature = tdesc_find_feature (info.target_desc, |
| 5235 | "org.gnu.gdb.mips.cpu"); |
| 5236 | if (feature == NULL) |
| 5237 | return NULL; |
| 5238 | |
| 5239 | tdesc_data = tdesc_data_alloc (); |
| 5240 | |
| 5241 | valid_p = 1; |
| 5242 | for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++) |
| 5243 | valid_p &= tdesc_numbered_register (feature, tdesc_data, i, |
| 5244 | mips_gprs[i]); |
| 5245 | |
| 5246 | |
| 5247 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5248 | MIPS_EMBED_LO_REGNUM, "lo"); |
| 5249 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5250 | MIPS_EMBED_HI_REGNUM, "hi"); |
| 5251 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5252 | MIPS_EMBED_PC_REGNUM, "pc"); |
| 5253 | |
| 5254 | if (!valid_p) |
| 5255 | { |
| 5256 | tdesc_data_cleanup (tdesc_data); |
| 5257 | return NULL; |
| 5258 | } |
| 5259 | |
| 5260 | feature = tdesc_find_feature (info.target_desc, |
| 5261 | "org.gnu.gdb.mips.cp0"); |
| 5262 | if (feature == NULL) |
| 5263 | { |
| 5264 | tdesc_data_cleanup (tdesc_data); |
| 5265 | return NULL; |
| 5266 | } |
| 5267 | |
| 5268 | valid_p = 1; |
| 5269 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5270 | MIPS_EMBED_BADVADDR_REGNUM, |
| 5271 | "badvaddr"); |
| 5272 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5273 | MIPS_PS_REGNUM, "status"); |
| 5274 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5275 | MIPS_EMBED_CAUSE_REGNUM, "cause"); |
| 5276 | |
| 5277 | if (!valid_p) |
| 5278 | { |
| 5279 | tdesc_data_cleanup (tdesc_data); |
| 5280 | return NULL; |
| 5281 | } |
| 5282 | |
| 5283 | /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS |
| 5284 | backend is not prepared for that, though. */ |
| 5285 | feature = tdesc_find_feature (info.target_desc, |
| 5286 | "org.gnu.gdb.mips.fpu"); |
| 5287 | if (feature == NULL) |
| 5288 | { |
| 5289 | tdesc_data_cleanup (tdesc_data); |
| 5290 | return NULL; |
| 5291 | } |
| 5292 | |
| 5293 | valid_p = 1; |
| 5294 | for (i = 0; i < 32; i++) |
| 5295 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5296 | i + MIPS_EMBED_FP0_REGNUM, |
| 5297 | mips_fprs[i]); |
| 5298 | |
| 5299 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5300 | MIPS_EMBED_FP0_REGNUM + 32, "fcsr"); |
| 5301 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 5302 | MIPS_EMBED_FP0_REGNUM + 33, "fir"); |
| 5303 | |
| 5304 | if (!valid_p) |
| 5305 | { |
| 5306 | tdesc_data_cleanup (tdesc_data); |
| 5307 | return NULL; |
| 5308 | } |
| 5309 | |
| 5310 | /* It would be nice to detect an attempt to use a 64-bit ABI |
| 5311 | when only 32-bit registers are provided. */ |
| 5312 | } |
| 5313 | |
| 5314 | /* First of all, extract the elf_flags, if available. */ |
| 5315 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) |
| 5316 | elf_flags = elf_elfheader (info.abfd)->e_flags; |
| 5317 | else if (arches != NULL) |
| 5318 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; |
| 5319 | else |
| 5320 | elf_flags = 0; |
| 5321 | if (gdbarch_debug) |
| 5322 | fprintf_unfiltered (gdb_stdlog, |
| 5323 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
| 5324 | |
| 5325 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
| 5326 | switch ((elf_flags & EF_MIPS_ABI)) |
| 5327 | { |
| 5328 | case E_MIPS_ABI_O32: |
| 5329 | found_abi = MIPS_ABI_O32; |
| 5330 | break; |
| 5331 | case E_MIPS_ABI_O64: |
| 5332 | found_abi = MIPS_ABI_O64; |
| 5333 | break; |
| 5334 | case E_MIPS_ABI_EABI32: |
| 5335 | found_abi = MIPS_ABI_EABI32; |
| 5336 | break; |
| 5337 | case E_MIPS_ABI_EABI64: |
| 5338 | found_abi = MIPS_ABI_EABI64; |
| 5339 | break; |
| 5340 | default: |
| 5341 | if ((elf_flags & EF_MIPS_ABI2)) |
| 5342 | found_abi = MIPS_ABI_N32; |
| 5343 | else |
| 5344 | found_abi = MIPS_ABI_UNKNOWN; |
| 5345 | break; |
| 5346 | } |
| 5347 | |
| 5348 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
| 5349 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
| 5350 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); |
| 5351 | |
| 5352 | /* If we have no useful BFD information, use the ABI from the last |
| 5353 | MIPS architecture (if there is one). */ |
| 5354 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) |
| 5355 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; |
| 5356 | |
| 5357 | /* Try the architecture for any hint of the correct ABI. */ |
| 5358 | if (found_abi == MIPS_ABI_UNKNOWN |
| 5359 | && info.bfd_arch_info != NULL |
| 5360 | && info.bfd_arch_info->arch == bfd_arch_mips) |
| 5361 | { |
| 5362 | switch (info.bfd_arch_info->mach) |
| 5363 | { |
| 5364 | case bfd_mach_mips3900: |
| 5365 | found_abi = MIPS_ABI_EABI32; |
| 5366 | break; |
| 5367 | case bfd_mach_mips4100: |
| 5368 | case bfd_mach_mips5000: |
| 5369 | found_abi = MIPS_ABI_EABI64; |
| 5370 | break; |
| 5371 | case bfd_mach_mips8000: |
| 5372 | case bfd_mach_mips10000: |
| 5373 | /* On Irix, ELF64 executables use the N64 ABI. The |
| 5374 | pseudo-sections which describe the ABI aren't present |
| 5375 | on IRIX. (Even for executables created by gcc.) */ |
| 5376 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
| 5377 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) |
| 5378 | found_abi = MIPS_ABI_N64; |
| 5379 | else |
| 5380 | found_abi = MIPS_ABI_N32; |
| 5381 | break; |
| 5382 | } |
| 5383 | } |
| 5384 | |
| 5385 | /* Default 64-bit objects to N64 instead of O32. */ |
| 5386 | if (found_abi == MIPS_ABI_UNKNOWN |
| 5387 | && info.abfd != NULL |
| 5388 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
| 5389 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) |
| 5390 | found_abi = MIPS_ABI_N64; |
| 5391 | |
| 5392 | if (gdbarch_debug) |
| 5393 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", |
| 5394 | found_abi); |
| 5395 | |
| 5396 | /* What has the user specified from the command line? */ |
| 5397 | wanted_abi = global_mips_abi (); |
| 5398 | if (gdbarch_debug) |
| 5399 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", |
| 5400 | wanted_abi); |
| 5401 | |
| 5402 | /* Now that we have found what the ABI for this binary would be, |
| 5403 | check whether the user is overriding it. */ |
| 5404 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
| 5405 | mips_abi = wanted_abi; |
| 5406 | else if (found_abi != MIPS_ABI_UNKNOWN) |
| 5407 | mips_abi = found_abi; |
| 5408 | else |
| 5409 | mips_abi = MIPS_ABI_O32; |
| 5410 | if (gdbarch_debug) |
| 5411 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", |
| 5412 | mips_abi); |
| 5413 | |
| 5414 | /* Also used when doing an architecture lookup. */ |
| 5415 | if (gdbarch_debug) |
| 5416 | fprintf_unfiltered (gdb_stdlog, |
| 5417 | "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n", |
| 5418 | mips64_transfers_32bit_regs_p); |
| 5419 | |
| 5420 | /* Determine the MIPS FPU type. */ |
| 5421 | #ifdef HAVE_ELF |
| 5422 | if (info.abfd |
| 5423 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) |
| 5424 | elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, |
| 5425 | Tag_GNU_MIPS_ABI_FP); |
| 5426 | #endif /* HAVE_ELF */ |
| 5427 | |
| 5428 | if (!mips_fpu_type_auto) |
| 5429 | fpu_type = mips_fpu_type; |
| 5430 | else if (elf_fpu_type != 0) |
| 5431 | { |
| 5432 | switch (elf_fpu_type) |
| 5433 | { |
| 5434 | case 1: |
| 5435 | fpu_type = MIPS_FPU_DOUBLE; |
| 5436 | break; |
| 5437 | case 2: |
| 5438 | fpu_type = MIPS_FPU_SINGLE; |
| 5439 | break; |
| 5440 | case 3: |
| 5441 | default: |
| 5442 | /* Soft float or unknown. */ |
| 5443 | fpu_type = MIPS_FPU_NONE; |
| 5444 | break; |
| 5445 | } |
| 5446 | } |
| 5447 | else if (info.bfd_arch_info != NULL |
| 5448 | && info.bfd_arch_info->arch == bfd_arch_mips) |
| 5449 | switch (info.bfd_arch_info->mach) |
| 5450 | { |
| 5451 | case bfd_mach_mips3900: |
| 5452 | case bfd_mach_mips4100: |
| 5453 | case bfd_mach_mips4111: |
| 5454 | case bfd_mach_mips4120: |
| 5455 | fpu_type = MIPS_FPU_NONE; |
| 5456 | break; |
| 5457 | case bfd_mach_mips4650: |
| 5458 | fpu_type = MIPS_FPU_SINGLE; |
| 5459 | break; |
| 5460 | default: |
| 5461 | fpu_type = MIPS_FPU_DOUBLE; |
| 5462 | break; |
| 5463 | } |
| 5464 | else if (arches != NULL) |
| 5465 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; |
| 5466 | else |
| 5467 | fpu_type = MIPS_FPU_DOUBLE; |
| 5468 | if (gdbarch_debug) |
| 5469 | fprintf_unfiltered (gdb_stdlog, |
| 5470 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
| 5471 | |
| 5472 | /* Check for blatant incompatibilities. */ |
| 5473 | |
| 5474 | /* If we have only 32-bit registers, then we can't debug a 64-bit |
| 5475 | ABI. */ |
| 5476 | if (info.target_desc |
| 5477 | && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL |
| 5478 | && mips_abi != MIPS_ABI_EABI32 |
| 5479 | && mips_abi != MIPS_ABI_O32) |
| 5480 | { |
| 5481 | if (tdesc_data != NULL) |
| 5482 | tdesc_data_cleanup (tdesc_data); |
| 5483 | return NULL; |
| 5484 | } |
| 5485 | |
| 5486 | /* try to find a pre-existing architecture */ |
| 5487 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
| 5488 | arches != NULL; |
| 5489 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) |
| 5490 | { |
| 5491 | /* MIPS needs to be pedantic about which ABI the object is |
| 5492 | using. */ |
| 5493 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
| 5494 | continue; |
| 5495 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
| 5496 | continue; |
| 5497 | /* Need to be pedantic about which register virtual size is |
| 5498 | used. */ |
| 5499 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p |
| 5500 | != mips64_transfers_32bit_regs_p) |
| 5501 | continue; |
| 5502 | /* Be pedantic about which FPU is selected. */ |
| 5503 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) |
| 5504 | continue; |
| 5505 | |
| 5506 | if (tdesc_data != NULL) |
| 5507 | tdesc_data_cleanup (tdesc_data); |
| 5508 | return arches->gdbarch; |
| 5509 | } |
| 5510 | |
| 5511 | /* Need a new architecture. Fill in a target specific vector. */ |
| 5512 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
| 5513 | gdbarch = gdbarch_alloc (&info, tdep); |
| 5514 | tdep->elf_flags = elf_flags; |
| 5515 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
| 5516 | tdep->found_abi = found_abi; |
| 5517 | tdep->mips_abi = mips_abi; |
| 5518 | tdep->mips_fpu_type = fpu_type; |
| 5519 | tdep->register_size_valid_p = 0; |
| 5520 | tdep->register_size = 0; |
| 5521 | |
| 5522 | if (info.target_desc) |
| 5523 | { |
| 5524 | /* Some useful properties can be inferred from the target. */ |
| 5525 | if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL) |
| 5526 | { |
| 5527 | tdep->register_size_valid_p = 1; |
| 5528 | tdep->register_size = 4; |
| 5529 | } |
| 5530 | else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL) |
| 5531 | { |
| 5532 | tdep->register_size_valid_p = 1; |
| 5533 | tdep->register_size = 8; |
| 5534 | } |
| 5535 | } |
| 5536 | |
| 5537 | /* Initially set everything according to the default ABI/ISA. */ |
| 5538 | set_gdbarch_short_bit (gdbarch, 16); |
| 5539 | set_gdbarch_int_bit (gdbarch, 32); |
| 5540 | set_gdbarch_float_bit (gdbarch, 32); |
| 5541 | set_gdbarch_double_bit (gdbarch, 64); |
| 5542 | set_gdbarch_long_double_bit (gdbarch, 64); |
| 5543 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
| 5544 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); |
| 5545 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); |
| 5546 | |
| 5547 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
| 5548 | mips_elf_make_msymbol_special); |
| 5549 | |
| 5550 | /* Fill in the OS dependant register numbers and names. */ |
| 5551 | { |
| 5552 | const char **reg_names; |
| 5553 | struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, |
| 5554 | struct mips_regnum); |
| 5555 | if (tdesc_has_registers (info.target_desc)) |
| 5556 | { |
| 5557 | regnum->lo = MIPS_EMBED_LO_REGNUM; |
| 5558 | regnum->hi = MIPS_EMBED_HI_REGNUM; |
| 5559 | regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM; |
| 5560 | regnum->cause = MIPS_EMBED_CAUSE_REGNUM; |
| 5561 | regnum->pc = MIPS_EMBED_PC_REGNUM; |
| 5562 | regnum->fp0 = MIPS_EMBED_FP0_REGNUM; |
| 5563 | regnum->fp_control_status = 70; |
| 5564 | regnum->fp_implementation_revision = 71; |
| 5565 | num_regs = MIPS_LAST_EMBED_REGNUM + 1; |
| 5566 | reg_names = NULL; |
| 5567 | } |
| 5568 | else if (info.osabi == GDB_OSABI_IRIX) |
| 5569 | { |
| 5570 | regnum->fp0 = 32; |
| 5571 | regnum->pc = 64; |
| 5572 | regnum->cause = 65; |
| 5573 | regnum->badvaddr = 66; |
| 5574 | regnum->hi = 67; |
| 5575 | regnum->lo = 68; |
| 5576 | regnum->fp_control_status = 69; |
| 5577 | regnum->fp_implementation_revision = 70; |
| 5578 | num_regs = 71; |
| 5579 | reg_names = mips_irix_reg_names; |
| 5580 | } |
| 5581 | else |
| 5582 | { |
| 5583 | regnum->lo = MIPS_EMBED_LO_REGNUM; |
| 5584 | regnum->hi = MIPS_EMBED_HI_REGNUM; |
| 5585 | regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM; |
| 5586 | regnum->cause = MIPS_EMBED_CAUSE_REGNUM; |
| 5587 | regnum->pc = MIPS_EMBED_PC_REGNUM; |
| 5588 | regnum->fp0 = MIPS_EMBED_FP0_REGNUM; |
| 5589 | regnum->fp_control_status = 70; |
| 5590 | regnum->fp_implementation_revision = 71; |
| 5591 | num_regs = 90; |
| 5592 | if (info.bfd_arch_info != NULL |
| 5593 | && info.bfd_arch_info->mach == bfd_mach_mips3900) |
| 5594 | reg_names = mips_tx39_reg_names; |
| 5595 | else |
| 5596 | reg_names = mips_generic_reg_names; |
| 5597 | } |
| 5598 | /* FIXME: cagney/2003-11-15: For MIPS, hasn't gdbarch_pc_regnum been |
| 5599 | replaced by read_pc? */ |
| 5600 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); |
| 5601 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); |
| 5602 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
| 5603 | set_gdbarch_num_regs (gdbarch, num_regs); |
| 5604 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); |
| 5605 | set_gdbarch_register_name (gdbarch, mips_register_name); |
| 5606 | set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer); |
| 5607 | tdep->mips_processor_reg_names = reg_names; |
| 5608 | tdep->regnum = regnum; |
| 5609 | } |
| 5610 | |
| 5611 | switch (mips_abi) |
| 5612 | { |
| 5613 | case MIPS_ABI_O32: |
| 5614 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
| 5615 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
| 5616 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
| 5617 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
| 5618 | tdep->default_mask_address_p = 0; |
| 5619 | set_gdbarch_long_bit (gdbarch, 32); |
| 5620 | set_gdbarch_ptr_bit (gdbarch, 32); |
| 5621 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5622 | break; |
| 5623 | case MIPS_ABI_O64: |
| 5624 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
| 5625 | set_gdbarch_return_value (gdbarch, mips_o64_return_value); |
| 5626 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
| 5627 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
| 5628 | tdep->default_mask_address_p = 0; |
| 5629 | set_gdbarch_long_bit (gdbarch, 32); |
| 5630 | set_gdbarch_ptr_bit (gdbarch, 32); |
| 5631 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5632 | break; |
| 5633 | case MIPS_ABI_EABI32: |
| 5634 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
| 5635 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
| 5636 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
| 5637 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
| 5638 | tdep->default_mask_address_p = 0; |
| 5639 | set_gdbarch_long_bit (gdbarch, 32); |
| 5640 | set_gdbarch_ptr_bit (gdbarch, 32); |
| 5641 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5642 | break; |
| 5643 | case MIPS_ABI_EABI64: |
| 5644 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
| 5645 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
| 5646 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
| 5647 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
| 5648 | tdep->default_mask_address_p = 0; |
| 5649 | set_gdbarch_long_bit (gdbarch, 64); |
| 5650 | set_gdbarch_ptr_bit (gdbarch, 64); |
| 5651 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5652 | break; |
| 5653 | case MIPS_ABI_N32: |
| 5654 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
| 5655 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
| 5656 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
| 5657 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
| 5658 | tdep->default_mask_address_p = 0; |
| 5659 | set_gdbarch_long_bit (gdbarch, 32); |
| 5660 | set_gdbarch_ptr_bit (gdbarch, 32); |
| 5661 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5662 | set_gdbarch_long_double_bit (gdbarch, 128); |
| 5663 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
| 5664 | break; |
| 5665 | case MIPS_ABI_N64: |
| 5666 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
| 5667 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
| 5668 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
| 5669 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
| 5670 | tdep->default_mask_address_p = 0; |
| 5671 | set_gdbarch_long_bit (gdbarch, 64); |
| 5672 | set_gdbarch_ptr_bit (gdbarch, 64); |
| 5673 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 5674 | set_gdbarch_long_double_bit (gdbarch, 128); |
| 5675 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
| 5676 | break; |
| 5677 | default: |
| 5678 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); |
| 5679 | } |
| 5680 | |
| 5681 | /* GCC creates a pseudo-section whose name specifies the size of |
| 5682 | longs, since -mlong32 or -mlong64 may be used independent of |
| 5683 | other options. How those options affect pointer sizes is ABI and |
| 5684 | architecture dependent, so use them to override the default sizes |
| 5685 | set by the ABI. This table shows the relationship between ABI, |
| 5686 | -mlongXX, and size of pointers: |
| 5687 | |
| 5688 | ABI -mlongXX ptr bits |
| 5689 | --- -------- -------- |
| 5690 | o32 32 32 |
| 5691 | o32 64 32 |
| 5692 | n32 32 32 |
| 5693 | n32 64 64 |
| 5694 | o64 32 32 |
| 5695 | o64 64 64 |
| 5696 | n64 32 32 |
| 5697 | n64 64 64 |
| 5698 | eabi32 32 32 |
| 5699 | eabi32 64 32 |
| 5700 | eabi64 32 32 |
| 5701 | eabi64 64 64 |
| 5702 | |
| 5703 | Note that for o32 and eabi32, pointers are always 32 bits |
| 5704 | regardless of any -mlongXX option. For all others, pointers and |
| 5705 | longs are the same, as set by -mlongXX or set by defaults. |
| 5706 | */ |
| 5707 | |
| 5708 | if (info.abfd != NULL) |
| 5709 | { |
| 5710 | int long_bit = 0; |
| 5711 | |
| 5712 | bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit); |
| 5713 | if (long_bit) |
| 5714 | { |
| 5715 | set_gdbarch_long_bit (gdbarch, long_bit); |
| 5716 | switch (mips_abi) |
| 5717 | { |
| 5718 | case MIPS_ABI_O32: |
| 5719 | case MIPS_ABI_EABI32: |
| 5720 | break; |
| 5721 | case MIPS_ABI_N32: |
| 5722 | case MIPS_ABI_O64: |
| 5723 | case MIPS_ABI_N64: |
| 5724 | case MIPS_ABI_EABI64: |
| 5725 | set_gdbarch_ptr_bit (gdbarch, long_bit); |
| 5726 | break; |
| 5727 | default: |
| 5728 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); |
| 5729 | } |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
| 5734 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the |
| 5735 | comment: |
| 5736 | |
| 5737 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE |
| 5738 | flag in object files because to do so would make it impossible to |
| 5739 | link with libraries compiled without "-gp32". This is |
| 5740 | unnecessarily restrictive. |
| 5741 | |
| 5742 | We could solve this problem by adding "-gp32" multilibs to gcc, |
| 5743 | but to set this flag before gcc is built with such multilibs will |
| 5744 | break too many systems.'' |
| 5745 | |
| 5746 | But even more unhelpfully, the default linker output target for |
| 5747 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even |
| 5748 | for 64-bit programs - you need to change the ABI to change this, |
| 5749 | and not all gcc targets support that currently. Therefore using |
| 5750 | this flag to detect 32-bit mode would do the wrong thing given |
| 5751 | the current gcc - it would make GDB treat these 64-bit programs |
| 5752 | as 32-bit programs by default. */ |
| 5753 | |
| 5754 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
| 5755 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
| 5756 | |
| 5757 | /* Add/remove bits from an address. The MIPS needs be careful to |
| 5758 | ensure that all 32 bit addresses are sign extended to 64 bits. */ |
| 5759 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
| 5760 | |
| 5761 | /* Unwind the frame. */ |
| 5762 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); |
| 5763 | set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp); |
| 5764 | set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id); |
| 5765 | |
| 5766 | /* Map debug register numbers onto internal register numbers. */ |
| 5767 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
| 5768 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
| 5769 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); |
| 5770 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, |
| 5771 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); |
| 5772 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, |
| 5773 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); |
| 5774 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
| 5775 | |
| 5776 | /* MIPS version of CALL_DUMMY */ |
| 5777 | |
| 5778 | /* NOTE: cagney/2003-08-05: Eventually call dummy location will be |
| 5779 | replaced by a command, and all targets will default to on stack |
| 5780 | (regardless of the stack's execute status). */ |
| 5781 | set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL); |
| 5782 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
| 5783 | |
| 5784 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
| 5785 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); |
| 5786 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); |
| 5787 | |
| 5788 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
| 5789 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); |
| 5790 | |
| 5791 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); |
| 5792 | |
| 5793 | set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p); |
| 5794 | |
| 5795 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
| 5796 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); |
| 5797 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); |
| 5798 | |
| 5799 | set_gdbarch_register_type (gdbarch, mips_register_type); |
| 5800 | |
| 5801 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
| 5802 | |
| 5803 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); |
| 5804 | |
| 5805 | /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT, |
| 5806 | HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT |
| 5807 | need to all be folded into the target vector. Since they are |
| 5808 | being used as guards for STOPPED_BY_WATCHPOINT, why not have |
| 5809 | STOPPED_BY_WATCHPOINT return the type of watchpoint that the code |
| 5810 | is sitting on? */ |
| 5811 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); |
| 5812 | |
| 5813 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code); |
| 5814 | |
| 5815 | set_gdbarch_single_step_through_delay (gdbarch, mips_single_step_through_delay); |
| 5816 | |
| 5817 | /* Virtual tables. */ |
| 5818 | set_gdbarch_vbit_in_delta (gdbarch, 1); |
| 5819 | |
| 5820 | mips_register_g_packet_guesses (gdbarch); |
| 5821 | |
| 5822 | /* Hook in OS ABI-specific overrides, if they have been registered. */ |
| 5823 | info.tdep_info = (void *) tdesc_data; |
| 5824 | gdbarch_init_osabi (info, gdbarch); |
| 5825 | |
| 5826 | /* Unwind the frame. */ |
| 5827 | frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer); |
| 5828 | frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer); |
| 5829 | frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer); |
| 5830 | frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer); |
| 5831 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
| 5832 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
| 5833 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
| 5834 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); |
| 5835 | |
| 5836 | if (tdesc_data) |
| 5837 | { |
| 5838 | set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type); |
| 5839 | tdesc_use_registers (gdbarch, info.target_desc, tdesc_data); |
| 5840 | |
| 5841 | /* Override the normal target description methods to handle our |
| 5842 | dual real and pseudo registers. */ |
| 5843 | set_gdbarch_register_name (gdbarch, mips_register_name); |
| 5844 | set_gdbarch_register_reggroup_p (gdbarch, mips_tdesc_register_reggroup_p); |
| 5845 | |
| 5846 | num_regs = gdbarch_num_regs (gdbarch); |
| 5847 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); |
| 5848 | set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs); |
| 5849 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); |
| 5850 | } |
| 5851 | |
| 5852 | /* Add ABI-specific aliases for the registers. */ |
| 5853 | if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64) |
| 5854 | for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++) |
| 5855 | user_reg_add (gdbarch, mips_n32_n64_aliases[i].name, |
| 5856 | value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum); |
| 5857 | else |
| 5858 | for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++) |
| 5859 | user_reg_add (gdbarch, mips_o32_aliases[i].name, |
| 5860 | value_of_mips_user_reg, &mips_o32_aliases[i].regnum); |
| 5861 | |
| 5862 | /* Add some other standard aliases. */ |
| 5863 | for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++) |
| 5864 | user_reg_add (gdbarch, mips_register_aliases[i].name, |
| 5865 | value_of_mips_user_reg, &mips_register_aliases[i].regnum); |
| 5866 | |
| 5867 | return gdbarch; |
| 5868 | } |
| 5869 | |
| 5870 | static void |
| 5871 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
| 5872 | { |
| 5873 | struct gdbarch_info info; |
| 5874 | |
| 5875 | /* Force the architecture to update, and (if it's a MIPS architecture) |
| 5876 | mips_gdbarch_init will take care of the rest. */ |
| 5877 | gdbarch_info_init (&info); |
| 5878 | gdbarch_update_p (info); |
| 5879 | } |
| 5880 | |
| 5881 | /* Print out which MIPS ABI is in use. */ |
| 5882 | |
| 5883 | static void |
| 5884 | show_mips_abi (struct ui_file *file, |
| 5885 | int from_tty, |
| 5886 | struct cmd_list_element *ignored_cmd, |
| 5887 | const char *ignored_value) |
| 5888 | { |
| 5889 | if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips) |
| 5890 | fprintf_filtered |
| 5891 | (file, |
| 5892 | "The MIPS ABI is unknown because the current architecture " |
| 5893 | "is not MIPS.\n"); |
| 5894 | else |
| 5895 | { |
| 5896 | enum mips_abi global_abi = global_mips_abi (); |
| 5897 | enum mips_abi actual_abi = mips_abi (current_gdbarch); |
| 5898 | const char *actual_abi_str = mips_abi_strings[actual_abi]; |
| 5899 | |
| 5900 | if (global_abi == MIPS_ABI_UNKNOWN) |
| 5901 | fprintf_filtered |
| 5902 | (file, |
| 5903 | "The MIPS ABI is set automatically (currently \"%s\").\n", |
| 5904 | actual_abi_str); |
| 5905 | else if (global_abi == actual_abi) |
| 5906 | fprintf_filtered |
| 5907 | (file, |
| 5908 | "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", |
| 5909 | actual_abi_str); |
| 5910 | else |
| 5911 | { |
| 5912 | /* Probably shouldn't happen... */ |
| 5913 | fprintf_filtered |
| 5914 | (file, |
| 5915 | "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n", |
| 5916 | actual_abi_str, mips_abi_strings[global_abi]); |
| 5917 | } |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | static void |
| 5922 | mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) |
| 5923 | { |
| 5924 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 5925 | if (tdep != NULL) |
| 5926 | { |
| 5927 | int ef_mips_arch; |
| 5928 | int ef_mips_32bitmode; |
| 5929 | /* Determine the ISA. */ |
| 5930 | switch (tdep->elf_flags & EF_MIPS_ARCH) |
| 5931 | { |
| 5932 | case E_MIPS_ARCH_1: |
| 5933 | ef_mips_arch = 1; |
| 5934 | break; |
| 5935 | case E_MIPS_ARCH_2: |
| 5936 | ef_mips_arch = 2; |
| 5937 | break; |
| 5938 | case E_MIPS_ARCH_3: |
| 5939 | ef_mips_arch = 3; |
| 5940 | break; |
| 5941 | case E_MIPS_ARCH_4: |
| 5942 | ef_mips_arch = 4; |
| 5943 | break; |
| 5944 | default: |
| 5945 | ef_mips_arch = 0; |
| 5946 | break; |
| 5947 | } |
| 5948 | /* Determine the size of a pointer. */ |
| 5949 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); |
| 5950 | fprintf_unfiltered (file, |
| 5951 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", |
| 5952 | tdep->elf_flags); |
| 5953 | fprintf_unfiltered (file, |
| 5954 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
| 5955 | ef_mips_32bitmode); |
| 5956 | fprintf_unfiltered (file, |
| 5957 | "mips_dump_tdep: ef_mips_arch = %d\n", |
| 5958 | ef_mips_arch); |
| 5959 | fprintf_unfiltered (file, |
| 5960 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", |
| 5961 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
| 5962 | fprintf_unfiltered (file, |
| 5963 | "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n", |
| 5964 | mips_mask_address_p (tdep), |
| 5965 | tdep->default_mask_address_p); |
| 5966 | } |
| 5967 | fprintf_unfiltered (file, |
| 5968 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", |
| 5969 | MIPS_DEFAULT_FPU_TYPE, |
| 5970 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" |
| 5971 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" |
| 5972 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" |
| 5973 | : "???")); |
| 5974 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI); |
| 5975 | fprintf_unfiltered (file, |
| 5976 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", |
| 5977 | MIPS_FPU_TYPE, |
| 5978 | (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none" |
| 5979 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single" |
| 5980 | : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" |
| 5981 | : "???")); |
| 5982 | } |
| 5983 | |
| 5984 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
| 5985 | |
| 5986 | void |
| 5987 | _initialize_mips_tdep (void) |
| 5988 | { |
| 5989 | static struct cmd_list_element *mipsfpulist = NULL; |
| 5990 | struct cmd_list_element *c; |
| 5991 | |
| 5992 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
| 5993 | if (MIPS_ABI_LAST + 1 |
| 5994 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) |
| 5995 | internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync")); |
| 5996 | |
| 5997 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
| 5998 | |
| 5999 | mips_pdr_data = register_objfile_data (); |
| 6000 | |
| 6001 | /* Create feature sets with the appropriate properties. The values |
| 6002 | are not important. */ |
| 6003 | mips_tdesc_gp32 = allocate_target_description (); |
| 6004 | set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, ""); |
| 6005 | |
| 6006 | mips_tdesc_gp64 = allocate_target_description (); |
| 6007 | set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, ""); |
| 6008 | |
| 6009 | /* Add root prefix command for all "set mips"/"show mips" commands */ |
| 6010 | add_prefix_cmd ("mips", no_class, set_mips_command, |
| 6011 | _("Various MIPS specific commands."), |
| 6012 | &setmipscmdlist, "set mips ", 0, &setlist); |
| 6013 | |
| 6014 | add_prefix_cmd ("mips", no_class, show_mips_command, |
| 6015 | _("Various MIPS specific commands."), |
| 6016 | &showmipscmdlist, "show mips ", 0, &showlist); |
| 6017 | |
| 6018 | /* Allow the user to override the ABI. */ |
| 6019 | add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings, |
| 6020 | &mips_abi_string, _("\ |
| 6021 | Set the MIPS ABI used by this program."), _("\ |
| 6022 | Show the MIPS ABI used by this program."), _("\ |
| 6023 | This option can be set to one of:\n\ |
| 6024 | auto - the default ABI associated with the current binary\n\ |
| 6025 | o32\n\ |
| 6026 | o64\n\ |
| 6027 | n32\n\ |
| 6028 | n64\n\ |
| 6029 | eabi32\n\ |
| 6030 | eabi64"), |
| 6031 | mips_abi_update, |
| 6032 | show_mips_abi, |
| 6033 | &setmipscmdlist, &showmipscmdlist); |
| 6034 | |
| 6035 | /* Let the user turn off floating point and set the fence post for |
| 6036 | heuristic_proc_start. */ |
| 6037 | |
| 6038 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, |
| 6039 | _("Set use of MIPS floating-point coprocessor."), |
| 6040 | &mipsfpulist, "set mipsfpu ", 0, &setlist); |
| 6041 | add_cmd ("single", class_support, set_mipsfpu_single_command, |
| 6042 | _("Select single-precision MIPS floating-point coprocessor."), |
| 6043 | &mipsfpulist); |
| 6044 | add_cmd ("double", class_support, set_mipsfpu_double_command, |
| 6045 | _("Select double-precision MIPS floating-point coprocessor."), |
| 6046 | &mipsfpulist); |
| 6047 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); |
| 6048 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); |
| 6049 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); |
| 6050 | add_cmd ("none", class_support, set_mipsfpu_none_command, |
| 6051 | _("Select no MIPS floating-point coprocessor."), &mipsfpulist); |
| 6052 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
| 6053 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); |
| 6054 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); |
| 6055 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, |
| 6056 | _("Select MIPS floating-point coprocessor automatically."), |
| 6057 | &mipsfpulist); |
| 6058 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, |
| 6059 | _("Show current use of MIPS floating-point coprocessor target."), |
| 6060 | &showlist); |
| 6061 | |
| 6062 | /* We really would like to have both "0" and "unlimited" work, but |
| 6063 | command.c doesn't deal with that. So make it a var_zinteger |
| 6064 | because the user can always use "999999" or some such for unlimited. */ |
| 6065 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, |
| 6066 | &heuristic_fence_post, _("\ |
| 6067 | Set the distance searched for the start of a function."), _("\ |
| 6068 | Show the distance searched for the start of a function."), _("\ |
| 6069 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
| 6070 | program for the start of a function. This command sets the distance of the\n\ |
| 6071 | search. The only need to set it is when debugging a stripped executable."), |
| 6072 | reinit_frame_cache_sfunc, |
| 6073 | NULL, /* FIXME: i18n: The distance searched for the start of a function is %s. */ |
| 6074 | &setlist, &showlist); |
| 6075 | |
| 6076 | /* Allow the user to control whether the upper bits of 64-bit |
| 6077 | addresses should be zeroed. */ |
| 6078 | add_setshow_auto_boolean_cmd ("mask-address", no_class, |
| 6079 | &mask_address_var, _("\ |
| 6080 | Set zeroing of upper 32 bits of 64-bit addresses."), _("\ |
| 6081 | Show zeroing of upper 32 bits of 64-bit addresses."), _("\ |
| 6082 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\ |
| 6083 | allow GDB to determine the correct value."), |
| 6084 | NULL, show_mask_address, |
| 6085 | &setmipscmdlist, &showmipscmdlist); |
| 6086 | |
| 6087 | /* Allow the user to control the size of 32 bit registers within the |
| 6088 | raw remote packet. */ |
| 6089 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
| 6090 | &mips64_transfers_32bit_regs_p, _("\ |
| 6091 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."), |
| 6092 | _("\ |
| 6093 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."), |
| 6094 | _("\ |
| 6095 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
| 6096 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ |
| 6097 | 64 bits for others. Use \"off\" to disable compatibility mode"), |
| 6098 | set_mips64_transfers_32bit_regs, |
| 6099 | NULL, /* FIXME: i18n: Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s. */ |
| 6100 | &setlist, &showlist); |
| 6101 | |
| 6102 | /* Debug this files internals. */ |
| 6103 | add_setshow_zinteger_cmd ("mips", class_maintenance, |
| 6104 | &mips_debug, _("\ |
| 6105 | Set mips debugging."), _("\ |
| 6106 | Show mips debugging."), _("\ |
| 6107 | When non-zero, mips specific debugging is enabled."), |
| 6108 | NULL, |
| 6109 | NULL, /* FIXME: i18n: Mips debugging is currently %s. */ |
| 6110 | &setdebuglist, &showdebuglist); |
| 6111 | } |