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