1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
7 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
9 This file is part of GDB.
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.
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.
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. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
40 #include "arch-utils.h"
43 #include "mips-tdep.h"
45 #include "reggroups.h"
46 #include "opcode/mips.h"
50 #include "sim-regno.h"
53 static void set_reg_offset (CORE_ADDR *saved_regs, int regnum, CORE_ADDR off);
54 static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum);
56 /* A useful bit in the CP0 status register (PS_REGNUM). */
57 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
58 #define ST0_FR (1 << 26)
60 /* The sizes of floating point registers. */
64 MIPS_FPU_SINGLE_REGSIZE = 4,
65 MIPS_FPU_DOUBLE_REGSIZE = 8
69 static const char *mips_abi_string;
71 static const char *mips_abi_strings[] = {
82 struct frame_extra_info
84 mips_extra_func_info_t proc_desc;
88 /* Various MIPS ISA options (related to stack analysis) can be
89 overridden dynamically. Establish an enum/array for managing
92 static const char size_auto[] = "auto";
93 static const char size_32[] = "32";
94 static const char size_64[] = "64";
96 static const char *size_enums[] = {
103 /* Some MIPS boards don't support floating point while others only
104 support single-precision floating-point operations. See also
105 FP_REGISTER_DOUBLE. */
109 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
110 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
111 MIPS_FPU_NONE /* No floating point. */
114 #ifndef MIPS_DEFAULT_FPU_TYPE
115 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
117 static int mips_fpu_type_auto = 1;
118 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
120 static int mips_debug = 0;
122 /* MIPS specific per-architecture information */
125 /* from the elf header */
129 enum mips_abi mips_abi;
130 enum mips_abi found_abi;
131 enum mips_fpu_type mips_fpu_type;
132 int mips_last_arg_regnum;
133 int mips_last_fp_arg_regnum;
134 int mips_default_saved_regsize;
135 int mips_fp_register_double;
136 int mips_default_stack_argsize;
137 int gdb_target_is_mips64;
138 int default_mask_address_p;
141 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
142 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
144 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
146 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
148 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
150 /* Return the currently configured (or set) saved register size. */
152 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
154 static const char *mips_saved_regsize_string = size_auto;
156 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
158 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
159 functions to test, set, or clear bit 0 of addresses. */
162 is_mips16_addr (CORE_ADDR addr)
168 make_mips16_addr (CORE_ADDR addr)
174 unmake_mips16_addr (CORE_ADDR addr)
176 return ((addr) & ~1);
179 /* Return the contents of register REGNUM as a signed integer. */
182 read_signed_register (int regnum)
184 void *buf = alloca (DEPRECATED_REGISTER_RAW_SIZE (regnum));
185 deprecated_read_register_gen (regnum, buf);
186 return (extract_signed_integer (buf, DEPRECATED_REGISTER_RAW_SIZE (regnum)));
190 read_signed_register_pid (int regnum, ptid_t ptid)
195 if (ptid_equal (ptid, inferior_ptid))
196 return read_signed_register (regnum);
198 save_ptid = inferior_ptid;
200 inferior_ptid = ptid;
202 retval = read_signed_register (regnum);
204 inferior_ptid = save_ptid;
209 /* Return the MIPS ABI associated with GDBARCH. */
211 mips_abi (struct gdbarch *gdbarch)
213 return gdbarch_tdep (gdbarch)->mips_abi;
217 mips_saved_regsize (void)
219 if (mips_saved_regsize_string == size_auto)
220 return MIPS_DEFAULT_SAVED_REGSIZE;
221 else if (mips_saved_regsize_string == size_64)
223 else /* if (mips_saved_regsize_string == size_32) */
227 /* Functions for setting and testing a bit in a minimal symbol that
228 marks it as 16-bit function. The MSB of the minimal symbol's
229 "info" field is used for this purpose.
231 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
232 i.e. refers to a 16-bit function, and sets a "special" bit in a
233 minimal symbol to mark it as a 16-bit function
235 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
238 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
240 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
242 MSYMBOL_INFO (msym) = (char *)
243 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
244 SYMBOL_VALUE_ADDRESS (msym) |= 1;
249 msymbol_is_special (struct minimal_symbol *msym)
251 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
255 msymbol_size (struct minimal_symbol *msym)
257 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
260 /* XFER a value from the big/little/left end of the register.
261 Depending on the size of the value it might occupy the entire
262 register or just part of it. Make an allowance for this, aligning
263 things accordingly. */
266 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
267 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
270 bfd_byte reg[MAX_REGISTER_SIZE];
272 gdb_assert (reg_num >= NUM_REGS);
273 /* Need to transfer the left or right part of the register, based on
274 the targets byte order. */
278 reg_offset = DEPRECATED_REGISTER_RAW_SIZE (reg_num) - length;
280 case BFD_ENDIAN_LITTLE:
283 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
287 internal_error (__FILE__, __LINE__, "bad switch");
290 fprintf_unfiltered (gdb_stderr,
291 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
292 reg_num, reg_offset, buf_offset, length);
293 if (mips_debug && out != NULL)
296 fprintf_unfiltered (gdb_stdlog, "out ");
297 for (i = 0; i < length; i++)
298 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
301 regcache_cooked_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
303 regcache_cooked_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
304 if (mips_debug && in != NULL)
307 fprintf_unfiltered (gdb_stdlog, "in ");
308 for (i = 0; i < length; i++)
309 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
312 fprintf_unfiltered (gdb_stdlog, "\n");
315 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
316 compatiblity mode. A return value of 1 means that we have
317 physical 64-bit registers, but should treat them as 32-bit registers. */
320 mips2_fp_compat (void)
322 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
324 if (DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
328 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
329 in all the places we deal with FP registers. PR gdb/413. */
330 /* Otherwise check the FR bit in the status register - it controls
331 the FP compatiblity mode. If it is clear we are in compatibility
333 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
340 /* Indicate that the ABI makes use of double-precision registers
341 provided by the FPU (rather than combining pairs of registers to
342 form double-precision values). Do not use "TARGET_IS_MIPS64" to
343 determine if the ABI is using double-precision registers. See also
345 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
347 /* The amount of space reserved on the stack for registers. This is
348 different to MIPS_SAVED_REGSIZE as it determines the alignment of
349 data allocated after the registers have run out. */
351 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
353 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
355 static const char *mips_stack_argsize_string = size_auto;
358 mips_stack_argsize (void)
360 if (mips_stack_argsize_string == size_auto)
361 return MIPS_DEFAULT_STACK_ARGSIZE;
362 else if (mips_stack_argsize_string == size_64)
364 else /* if (mips_stack_argsize_string == size_32) */
368 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
370 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
372 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
374 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
375 struct frame_info *, int);
377 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
379 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
381 static int mips_set_processor_type (char *);
383 static void mips_show_processor_type_command (char *, int);
385 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
387 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
388 struct frame_info *next_frame,
391 static CORE_ADDR after_prologue (CORE_ADDR pc,
392 mips_extra_func_info_t proc_desc);
394 static struct type *mips_float_register_type (void);
395 static struct type *mips_double_register_type (void);
397 /* This value is the model of MIPS in use. It is derived from the value
398 of the PrID register. */
400 char *mips_processor_type;
402 char *tmp_mips_processor_type;
404 /* The list of available "set mips " and "show mips " commands */
406 static struct cmd_list_element *setmipscmdlist = NULL;
407 static struct cmd_list_element *showmipscmdlist = NULL;
409 /* A set of original names, to be used when restoring back to generic
410 registers from a specific set. */
411 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
413 /* Integer registers 0 thru 31 are handled explicitly by
414 mips_register_name(). Processor specific registers 32 and above
415 are listed in the sets of register names assigned to
416 mips_processor_reg_names. */
417 static char **mips_processor_reg_names = mips_generic_reg_names;
419 /* Return the name of the register corresponding to REGNO. */
421 mips_register_name (int regno)
423 /* GPR names for all ABIs other than n32/n64. */
424 static char *mips_gpr_names[] = {
425 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
426 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
427 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
428 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
431 /* GPR names for n32 and n64 ABIs. */
432 static char *mips_n32_n64_gpr_names[] = {
433 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
434 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
435 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
436 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
439 enum mips_abi abi = mips_abi (current_gdbarch);
441 /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then
442 don't make the raw register names visible. */
443 int rawnum = regno % NUM_REGS;
444 if (regno < NUM_REGS)
447 /* The MIPS integer registers are always mapped from 0 to 31. The
448 names of the registers (which reflects the conventions regarding
449 register use) vary depending on the ABI. */
450 if (0 <= rawnum && rawnum < 32)
452 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
453 return mips_n32_n64_gpr_names[rawnum];
455 return mips_gpr_names[rawnum];
457 else if (32 <= rawnum && rawnum < NUM_REGS)
458 return mips_processor_reg_names[rawnum - 32];
460 internal_error (__FILE__, __LINE__,
461 "mips_register_name: bad register number %d", rawnum);
465 /* Names of IDT R3041 registers. */
467 char *mips_r3041_reg_names[] = {
468 "sr", "lo", "hi", "bad", "cause","pc",
469 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
470 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
471 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
472 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
473 "fsr", "fir", "",/*"fp"*/ "",
474 "", "", "bus", "ccfg", "", "", "", "",
475 "", "", "port", "cmp", "", "", "epc", "prid",
478 /* Names of IDT R3051 registers. */
480 char *mips_r3051_reg_names[] = {
481 "sr", "lo", "hi", "bad", "cause","pc",
482 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
483 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
484 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
485 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
486 "fsr", "fir", ""/*"fp"*/, "",
487 "inx", "rand", "elo", "", "ctxt", "", "", "",
488 "", "", "ehi", "", "", "", "epc", "prid",
491 /* Names of IDT R3081 registers. */
493 char *mips_r3081_reg_names[] = {
494 "sr", "lo", "hi", "bad", "cause","pc",
495 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
496 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
497 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
498 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
499 "fsr", "fir", ""/*"fp"*/, "",
500 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
501 "", "", "ehi", "", "", "", "epc", "prid",
504 /* Names of LSI 33k registers. */
506 char *mips_lsi33k_reg_names[] = {
507 "epc", "hi", "lo", "sr", "cause","badvaddr",
508 "dcic", "bpc", "bda", "", "", "", "", "",
509 "", "", "", "", "", "", "", "",
510 "", "", "", "", "", "", "", "",
511 "", "", "", "", "", "", "", "",
513 "", "", "", "", "", "", "", "",
514 "", "", "", "", "", "", "", "",
520 } mips_processor_type_table[] = {
521 { "generic", mips_generic_reg_names },
522 { "r3041", mips_r3041_reg_names },
523 { "r3051", mips_r3051_reg_names },
524 { "r3071", mips_r3081_reg_names },
525 { "r3081", mips_r3081_reg_names },
526 { "lsi33k", mips_lsi33k_reg_names },
531 /* Return the groups that a MIPS register can be categorised into. */
534 mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
535 struct reggroup *reggroup)
540 int rawnum = regnum % NUM_REGS;
541 int pseudo = regnum / NUM_REGS;
542 if (reggroup == all_reggroup)
544 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
545 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
546 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
547 (gdbarch), as not all architectures are multi-arch. */
548 raw_p = rawnum < NUM_REGS;
549 if (REGISTER_NAME (regnum) == NULL
550 || REGISTER_NAME (regnum)[0] == '\0')
552 if (reggroup == float_reggroup)
553 return float_p && pseudo;
554 if (reggroup == vector_reggroup)
555 return vector_p && pseudo;
556 if (reggroup == general_reggroup)
557 return (!vector_p && !float_p) && pseudo;
558 /* Save the pseudo registers. Need to make certain that any code
559 extracting register values from a saved register cache also uses
561 if (reggroup == save_reggroup)
562 return raw_p && pseudo;
563 /* Restore the same pseudo register. */
564 if (reggroup == restore_reggroup)
565 return raw_p && pseudo;
569 /* Map the symbol table registers which live in the range [1 *
570 NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw
574 mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
575 int cookednum, void *buf)
577 gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS);
578 return regcache_raw_read (regcache, cookednum % NUM_REGS, buf);
582 mips_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
583 int cookednum, const void *buf)
585 gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS);
586 return regcache_raw_write (regcache, cookednum % NUM_REGS, buf);
589 /* Table to translate MIPS16 register field to actual register number. */
590 static int mips16_to_32_reg[8] =
591 {16, 17, 2, 3, 4, 5, 6, 7};
593 /* Heuristic_proc_start may hunt through the text section for a long
594 time across a 2400 baud serial line. Allows the user to limit this
597 static unsigned int heuristic_fence_post = 0;
599 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
600 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
601 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
602 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
603 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
604 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
605 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
606 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
607 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
608 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
609 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
610 this will corrupt pdr.iline. Fortunately we don't use it. */
611 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
612 #define _PROC_MAGIC_ 0x0F0F0F0F
613 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
614 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
616 struct linked_proc_info
618 struct mips_extra_func_info info;
619 struct linked_proc_info *next;
621 *linked_proc_desc_table = NULL;
623 /* Number of bytes of storage in the actual machine representation for
624 register N. NOTE: This indirectly defines the register size
625 transfered by the GDB protocol. */
627 static int mips64_transfers_32bit_regs_p = 0;
630 mips_register_raw_size (int regnum)
632 gdb_assert (regnum >= 0);
633 if (regnum < NUM_REGS)
635 /* For compatibility with old code, implemnt the broken register raw
636 size map for the raw registers.
638 NOTE: cagney/2003-06-15: This is so bogus. The register's
639 raw size is changing according to the ABI
640 (FP_REGISTER_DOUBLE). Also, GDB's protocol is defined by a
641 combination of DEPRECATED_REGISTER_RAW_SIZE and DEPRECATED_REGISTER_BYTE. */
642 if (mips64_transfers_32bit_regs_p)
643 return DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum);
644 else if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM + 32
645 && FP_REGISTER_DOUBLE)
646 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
652 else if (regnum < 2 * NUM_REGS)
654 /* For the moment map [NUM_REGS .. 2*NUM_REGS) onto the same raw
655 registers, but always return the virtual size. */
656 int rawnum = regnum % NUM_REGS;
657 return TYPE_LENGTH (gdbarch_register_type (current_gdbarch, rawnum));
660 internal_error (__FILE__, __LINE__, "Register %d out of range", regnum);
663 /* Register offset in a buffer for each register.
665 FIXME: cagney/2003-06-15: This is so bogus. Instead REGISTER_TYPE
666 should strictly return the layout of the buffer. Unfortunately
667 remote.c and the MIPS have come to rely on a custom layout that
668 doesn't 1:1 map onto the register type. */
671 mips_register_byte (int regnum)
673 gdb_assert (regnum >= 0);
674 if (regnum < NUM_REGS)
675 /* Pick up the relevant per-tm file register byte method. */
676 return MIPS_REGISTER_BYTE (regnum);
677 else if (regnum < 2 * NUM_REGS)
681 /* Start with the end of the raw register buffer - assum that
682 MIPS_REGISTER_BYTE (NUM_REGS) returns that end. */
683 byte = MIPS_REGISTER_BYTE (NUM_REGS);
684 /* Add space for all the proceeding registers based on their
686 for (reg = NUM_REGS; reg < regnum; reg++)
687 byte += TYPE_LENGTH (gdbarch_register_type (current_gdbarch,
692 internal_error (__FILE__, __LINE__, "Register %d out of range", regnum);
695 /* Convert between RAW and VIRTUAL registers. The RAW register size
696 defines the remote-gdb packet. */
699 mips_register_convertible (int reg_nr)
701 if (mips64_transfers_32bit_regs_p)
704 return (DEPRECATED_REGISTER_RAW_SIZE (reg_nr) > DEPRECATED_REGISTER_VIRTUAL_SIZE (reg_nr));
708 mips_register_convert_to_virtual (int n, struct type *virtual_type,
709 char *raw_buf, char *virt_buf)
711 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
713 raw_buf + (DEPRECATED_REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
714 TYPE_LENGTH (virtual_type));
718 TYPE_LENGTH (virtual_type));
722 mips_register_convert_to_raw (struct type *virtual_type, int n,
723 const char *virt_buf, char *raw_buf)
725 memset (raw_buf, 0, DEPRECATED_REGISTER_RAW_SIZE (n));
726 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
727 memcpy (raw_buf + (DEPRECATED_REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
729 TYPE_LENGTH (virtual_type));
733 TYPE_LENGTH (virtual_type));
737 mips_convert_register_p (int regnum, struct type *type)
739 return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
740 && DEPRECATED_REGISTER_RAW_SIZE (regnum) == 4
741 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
742 && TYPE_CODE(type) == TYPE_CODE_FLT
743 && TYPE_LENGTH(type) == 8);
747 mips_register_to_value (struct frame_info *frame, int regnum,
748 struct type *type, void *to)
750 get_frame_register (frame, regnum + 0, (char *) to + 4);
751 get_frame_register (frame, regnum + 1, (char *) to + 0);
755 mips_value_to_register (struct frame_info *frame, int regnum,
756 struct type *type, const void *from)
758 put_frame_register (frame, regnum + 0, (const char *) from + 4);
759 put_frame_register (frame, regnum + 1, (const char *) from + 0);
762 /* Return the GDB type object for the "standard" data type of data in
766 mips_register_type (struct gdbarch *gdbarch, int regnum)
768 /* For moment, map [NUM_REGS .. 2*NUM_REGS) onto the same raw
769 registers. Even return the same type. */
770 int rawnum = regnum % NUM_REGS;
771 gdb_assert (rawnum >= 0 && rawnum < NUM_REGS);
772 #ifdef MIPS_REGISTER_TYPE
773 return MIPS_REGISTER_TYPE (rawnum);
775 if (FP0_REGNUM <= rawnum && rawnum < FP0_REGNUM + 32)
777 /* Floating point registers... */
778 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
779 return builtin_type_ieee_double_big;
781 return builtin_type_ieee_double_little;
783 else if (rawnum == PS_REGNUM /* CR */)
784 return builtin_type_uint32;
785 else if (FCRCS_REGNUM <= rawnum && rawnum <= LAST_EMBED_REGNUM)
786 return builtin_type_uint32;
789 /* Everything else...
790 Return type appropriate for width of register. */
791 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
792 return builtin_type_uint64;
794 return builtin_type_uint32;
799 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
804 return read_signed_register (SP_REGNUM);
807 /* Should the upper word of 64-bit addresses be zeroed? */
808 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
811 mips_mask_address_p (void)
813 switch (mask_address_var)
815 case AUTO_BOOLEAN_TRUE:
817 case AUTO_BOOLEAN_FALSE:
820 case AUTO_BOOLEAN_AUTO:
821 return MIPS_DEFAULT_MASK_ADDRESS_P;
823 internal_error (__FILE__, __LINE__,
824 "mips_mask_address_p: bad switch");
830 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
832 switch (mask_address_var)
834 case AUTO_BOOLEAN_TRUE:
835 printf_filtered ("The 32 bit mips address mask is enabled\n");
837 case AUTO_BOOLEAN_FALSE:
838 printf_filtered ("The 32 bit mips address mask is disabled\n");
840 case AUTO_BOOLEAN_AUTO:
841 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
842 mips_mask_address_p () ? "enabled" : "disabled");
845 internal_error (__FILE__, __LINE__,
846 "show_mask_address: bad switch");
851 /* Should call_function allocate stack space for a struct return? */
854 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
856 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
860 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
862 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
865 /* Should call_function pass struct by reference?
866 For each architecture, structs are passed either by
867 value or by reference, depending on their size. */
870 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
872 enum type_code typecode = TYPE_CODE (check_typedef (type));
873 int len = TYPE_LENGTH (check_typedef (type));
875 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
876 return (len > MIPS_SAVED_REGSIZE);
882 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
884 return 0; /* Assumption: N32/N64 never passes struct by ref. */
888 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
890 return 0; /* Assumption: O32/O64 never passes struct by ref. */
893 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
896 pc_is_mips16 (bfd_vma memaddr)
898 struct minimal_symbol *sym;
900 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
901 if (is_mips16_addr (memaddr))
904 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
905 the high bit of the info field. Use this to decide if the function is
906 MIPS16 or normal MIPS. */
907 sym = lookup_minimal_symbol_by_pc (memaddr);
909 return msymbol_is_special (sym);
914 /* MIPS believes that the PC has a sign extended value. Perhaphs the
915 all registers should be sign extended for simplicity? */
918 mips_read_pc (ptid_t ptid)
920 return read_signed_register_pid (PC_REGNUM, ptid);
923 /* This returns the PC of the first inst after the prologue. If we can't
924 find the prologue, then return 0. */
927 after_prologue (CORE_ADDR pc,
928 mips_extra_func_info_t proc_desc)
930 struct symtab_and_line sal;
931 CORE_ADDR func_addr, func_end;
933 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
934 to read the stack pointer from the current machine state, because
935 the current machine state has nothing to do with the information
936 we need from the proc_desc; and the process may or may not exist
939 proc_desc = find_proc_desc (pc, NULL, 0);
943 /* If function is frameless, then we need to do it the hard way. I
944 strongly suspect that frameless always means prologueless... */
945 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
946 && PROC_FRAME_OFFSET (proc_desc) == 0)
950 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
951 return 0; /* Unknown */
953 sal = find_pc_line (func_addr, 0);
955 if (sal.end < func_end)
958 /* The line after the prologue is after the end of the function. In this
959 case, tell the caller to find the prologue the hard way. */
964 /* Decode a MIPS32 instruction that saves a register in the stack, and
965 set the appropriate bit in the general register mask or float register mask
966 to indicate which register is saved. This is a helper function
967 for mips_find_saved_regs. */
970 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
971 unsigned long *float_mask)
975 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
976 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
977 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
979 /* It might be possible to use the instruction to
980 find the offset, rather than the code below which
981 is based on things being in a certain order in the
982 frame, but figuring out what the instruction's offset
983 is relative to might be a little tricky. */
984 reg = (inst & 0x001f0000) >> 16;
985 *gen_mask |= (1 << reg);
987 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
988 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
989 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
992 reg = ((inst & 0x001f0000) >> 16);
993 *float_mask |= (1 << reg);
997 /* Decode a MIPS16 instruction that saves a register in the stack, and
998 set the appropriate bit in the general register or float register mask
999 to indicate which register is saved. This is a helper function
1000 for mips_find_saved_regs. */
1003 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
1005 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1007 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1008 *gen_mask |= (1 << reg);
1010 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1012 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1013 *gen_mask |= (1 << reg);
1015 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
1016 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1017 *gen_mask |= (1 << RA_REGNUM);
1021 /* Fetch and return instruction from the specified location. If the PC
1022 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
1025 mips_fetch_instruction (CORE_ADDR addr)
1027 char buf[MIPS_INSTLEN];
1031 if (pc_is_mips16 (addr))
1033 instlen = MIPS16_INSTLEN;
1034 addr = unmake_mips16_addr (addr);
1037 instlen = MIPS_INSTLEN;
1038 status = read_memory_nobpt (addr, buf, instlen);
1040 memory_error (status, addr);
1041 return extract_unsigned_integer (buf, instlen);
1045 /* These the fields of 32 bit mips instructions */
1046 #define mips32_op(x) (x >> 26)
1047 #define itype_op(x) (x >> 26)
1048 #define itype_rs(x) ((x >> 21) & 0x1f)
1049 #define itype_rt(x) ((x >> 16) & 0x1f)
1050 #define itype_immediate(x) (x & 0xffff)
1052 #define jtype_op(x) (x >> 26)
1053 #define jtype_target(x) (x & 0x03ffffff)
1055 #define rtype_op(x) (x >> 26)
1056 #define rtype_rs(x) ((x >> 21) & 0x1f)
1057 #define rtype_rt(x) ((x >> 16) & 0x1f)
1058 #define rtype_rd(x) ((x >> 11) & 0x1f)
1059 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1060 #define rtype_funct(x) (x & 0x3f)
1063 mips32_relative_offset (unsigned long inst)
1066 x = itype_immediate (inst);
1067 if (x & 0x8000) /* sign bit set */
1069 x |= 0xffff0000; /* sign extension */
1075 /* Determine whate to set a single step breakpoint while considering
1076 branch prediction */
1078 mips32_next_pc (CORE_ADDR pc)
1082 inst = mips_fetch_instruction (pc);
1083 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
1085 if (itype_op (inst) >> 2 == 5)
1086 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1088 op = (itype_op (inst) & 0x03);
1098 goto greater_branch;
1103 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
1104 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1106 int tf = itype_rt (inst) & 0x01;
1107 int cnum = itype_rt (inst) >> 2;
1108 int fcrcs = read_signed_register (FCRCS_REGNUM);
1109 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1111 if (((cond >> cnum) & 0x01) == tf)
1112 pc += mips32_relative_offset (inst) + 4;
1117 pc += 4; /* Not a branch, next instruction is easy */
1120 { /* This gets way messy */
1122 /* Further subdivide into SPECIAL, REGIMM and other */
1123 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
1125 case 0: /* SPECIAL */
1126 op = rtype_funct (inst);
1131 /* Set PC to that address */
1132 pc = read_signed_register (rtype_rs (inst));
1138 break; /* end SPECIAL */
1139 case 1: /* REGIMM */
1141 op = itype_rt (inst); /* branch condition */
1146 case 16: /* BLTZAL */
1147 case 18: /* BLTZALL */
1149 if (read_signed_register (itype_rs (inst)) < 0)
1150 pc += mips32_relative_offset (inst) + 4;
1152 pc += 8; /* after the delay slot */
1156 case 17: /* BGEZAL */
1157 case 19: /* BGEZALL */
1158 greater_equal_branch:
1159 if (read_signed_register (itype_rs (inst)) >= 0)
1160 pc += mips32_relative_offset (inst) + 4;
1162 pc += 8; /* after the delay slot */
1164 /* All of the other instructions in the REGIMM category */
1169 break; /* end REGIMM */
1174 reg = jtype_target (inst) << 2;
1175 /* Upper four bits get never changed... */
1176 pc = reg + ((pc + 4) & 0xf0000000);
1179 /* FIXME case JALX : */
1182 reg = jtype_target (inst) << 2;
1183 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1184 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1186 break; /* The new PC will be alternate mode */
1187 case 4: /* BEQ, BEQL */
1189 if (read_signed_register (itype_rs (inst)) ==
1190 read_signed_register (itype_rt (inst)))
1191 pc += mips32_relative_offset (inst) + 4;
1195 case 5: /* BNE, BNEL */
1197 if (read_signed_register (itype_rs (inst)) !=
1198 read_signed_register (itype_rt (inst)))
1199 pc += mips32_relative_offset (inst) + 4;
1203 case 6: /* BLEZ, BLEZL */
1205 if (read_signed_register (itype_rs (inst) <= 0))
1206 pc += mips32_relative_offset (inst) + 4;
1212 greater_branch: /* BGTZ, BGTZL */
1213 if (read_signed_register (itype_rs (inst) > 0))
1214 pc += mips32_relative_offset (inst) + 4;
1221 } /* mips32_next_pc */
1223 /* Decoding the next place to set a breakpoint is irregular for the
1224 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1225 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1226 We dont want to set a single step instruction on the extend instruction
1230 /* Lots of mips16 instruction formats */
1231 /* Predicting jumps requires itype,ritype,i8type
1232 and their extensions extItype,extritype,extI8type
1234 enum mips16_inst_fmts
1236 itype, /* 0 immediate 5,10 */
1237 ritype, /* 1 5,3,8 */
1238 rrtype, /* 2 5,3,3,5 */
1239 rritype, /* 3 5,3,3,5 */
1240 rrrtype, /* 4 5,3,3,3,2 */
1241 rriatype, /* 5 5,3,3,1,4 */
1242 shifttype, /* 6 5,3,3,3,2 */
1243 i8type, /* 7 5,3,8 */
1244 i8movtype, /* 8 5,3,3,5 */
1245 i8mov32rtype, /* 9 5,3,5,3 */
1246 i64type, /* 10 5,3,8 */
1247 ri64type, /* 11 5,3,3,5 */
1248 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1249 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1250 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1251 extRRItype, /* 15 5,5,5,5,3,3,5 */
1252 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1253 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1254 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1255 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1256 extRi64type, /* 20 5,6,5,5,3,3,5 */
1257 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1259 /* I am heaping all the fields of the formats into one structure and
1260 then, only the fields which are involved in instruction extension */
1264 unsigned int regx; /* Function in i8 type */
1269 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1270 for the bits which make up the immediatate extension. */
1273 extended_offset (unsigned int extension)
1276 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1278 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1280 value |= extension & 0x01f; /* extract 4:0 */
1284 /* Only call this function if you know that this is an extendable
1285 instruction, It wont malfunction, but why make excess remote memory references?
1286 If the immediate operands get sign extended or somthing, do it after
1287 the extension is performed.
1289 /* FIXME: Every one of these cases needs to worry about sign extension
1290 when the offset is to be used in relative addressing */
1294 fetch_mips_16 (CORE_ADDR pc)
1297 pc &= 0xfffffffe; /* clear the low order bit */
1298 target_read_memory (pc, buf, 2);
1299 return extract_unsigned_integer (buf, 2);
1303 unpack_mips16 (CORE_ADDR pc,
1304 unsigned int extension,
1306 enum mips16_inst_fmts insn_format,
1307 struct upk_mips16 *upk)
1312 switch (insn_format)
1319 value = extended_offset (extension);
1320 value = value << 11; /* rom for the original value */
1321 value |= inst & 0x7ff; /* eleven bits from instruction */
1325 value = inst & 0x7ff;
1326 /* FIXME : Consider sign extension */
1335 { /* A register identifier and an offset */
1336 /* Most of the fields are the same as I type but the
1337 immediate value is of a different length */
1341 value = extended_offset (extension);
1342 value = value << 8; /* from the original instruction */
1343 value |= inst & 0xff; /* eleven bits from instruction */
1344 regx = (extension >> 8) & 0x07; /* or i8 funct */
1345 if (value & 0x4000) /* test the sign bit , bit 26 */
1347 value &= ~0x3fff; /* remove the sign bit */
1353 value = inst & 0xff; /* 8 bits */
1354 regx = (inst >> 8) & 0x07; /* or i8 funct */
1355 /* FIXME: Do sign extension , this format needs it */
1356 if (value & 0x80) /* THIS CONFUSES ME */
1358 value &= 0xef; /* remove the sign bit */
1368 unsigned long value;
1369 unsigned int nexthalf;
1370 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1371 value = value << 16;
1372 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1380 internal_error (__FILE__, __LINE__,
1383 upk->offset = offset;
1390 add_offset_16 (CORE_ADDR pc, int offset)
1392 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1396 extended_mips16_next_pc (CORE_ADDR pc,
1397 unsigned int extension,
1400 int op = (insn >> 11);
1403 case 2: /* Branch */
1406 struct upk_mips16 upk;
1407 unpack_mips16 (pc, extension, insn, itype, &upk);
1408 offset = upk.offset;
1414 pc += (offset << 1) + 2;
1417 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1419 struct upk_mips16 upk;
1420 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1421 pc = add_offset_16 (pc, upk.offset);
1422 if ((insn >> 10) & 0x01) /* Exchange mode */
1423 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1430 struct upk_mips16 upk;
1432 unpack_mips16 (pc, extension, insn, ritype, &upk);
1433 reg = read_signed_register (upk.regx);
1435 pc += (upk.offset << 1) + 2;
1442 struct upk_mips16 upk;
1444 unpack_mips16 (pc, extension, insn, ritype, &upk);
1445 reg = read_signed_register (upk.regx);
1447 pc += (upk.offset << 1) + 2;
1452 case 12: /* I8 Formats btez btnez */
1454 struct upk_mips16 upk;
1456 unpack_mips16 (pc, extension, insn, i8type, &upk);
1457 /* upk.regx contains the opcode */
1458 reg = read_signed_register (24); /* Test register is 24 */
1459 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1460 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1461 /* pc = add_offset_16(pc,upk.offset) ; */
1462 pc += (upk.offset << 1) + 2;
1467 case 29: /* RR Formats JR, JALR, JALR-RA */
1469 struct upk_mips16 upk;
1470 /* upk.fmt = rrtype; */
1475 upk.regx = (insn >> 8) & 0x07;
1476 upk.regy = (insn >> 5) & 0x07;
1484 break; /* Function return instruction */
1490 break; /* BOGUS Guess */
1492 pc = read_signed_register (reg);
1499 /* This is an instruction extension. Fetch the real instruction
1500 (which follows the extension) and decode things based on
1504 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1517 mips16_next_pc (CORE_ADDR pc)
1519 unsigned int insn = fetch_mips_16 (pc);
1520 return extended_mips16_next_pc (pc, 0, insn);
1523 /* The mips_next_pc function supports single_step when the remote
1524 target monitor or stub is not developed enough to do a single_step.
1525 It works by decoding the current instruction and predicting where a
1526 branch will go. This isnt hard because all the data is available.
1527 The MIPS32 and MIPS16 variants are quite different */
1529 mips_next_pc (CORE_ADDR pc)
1532 return mips16_next_pc (pc);
1534 return mips32_next_pc (pc);
1537 /* Set up the 'saved_regs' array. This is a data structure containing
1538 the addresses on the stack where each register has been saved, for
1539 each stack frame. Registers that have not been saved will have
1540 zero here. The stack pointer register is special: rather than the
1541 address where the stack register has been saved,
1542 saved_regs[SP_REGNUM] will have the actual value of the previous
1543 frame's stack register. */
1546 mips_find_saved_regs (struct frame_info *fci)
1549 /* r0 bit means kernel trap */
1551 /* What registers have been saved? Bitmasks. */
1552 unsigned long gen_mask, float_mask;
1553 mips_extra_func_info_t proc_desc;
1555 CORE_ADDR *saved_regs;
1557 if (deprecated_get_frame_saved_regs (fci) != NULL)
1559 saved_regs = frame_saved_regs_zalloc (fci);
1561 /* If it is the frame for sigtramp, the saved registers are located
1562 in a sigcontext structure somewhere on the stack. If the stack
1563 layout for sigtramp changes we might have to change these
1564 constants and the companion fixup_sigtramp in mdebugread.c */
1565 #ifndef SIGFRAME_BASE
1566 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1567 above the sigtramp frame. */
1568 #define SIGFRAME_BASE MIPS_REGSIZE
1569 /* FIXME! Are these correct?? */
1570 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1571 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1572 #define SIGFRAME_FPREGSAVE_OFF \
1573 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1575 #ifndef SIGFRAME_REG_SIZE
1576 /* FIXME! Is this correct?? */
1577 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1579 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1581 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1583 CORE_ADDR reg_position = (get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1584 + ireg * SIGFRAME_REG_SIZE);
1585 set_reg_offset (saved_regs, ireg, reg_position);
1587 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1589 CORE_ADDR reg_position = (get_frame_base (fci)
1590 + SIGFRAME_FPREGSAVE_OFF
1591 + ireg * SIGFRAME_REG_SIZE);
1592 set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1595 set_reg_offset (saved_regs, PC_REGNUM, get_frame_base (fci) + SIGFRAME_PC_OFF);
1596 /* SP_REGNUM, contains the value and not the address. */
1597 set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1601 proc_desc = get_frame_extra_info (fci)->proc_desc;
1602 if (proc_desc == NULL)
1603 /* I'm not sure how/whether this can happen. Normally when we
1604 can't find a proc_desc, we "synthesize" one using
1605 heuristic_proc_desc and set the saved_regs right away. */
1608 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1609 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1610 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1612 if (/* In any frame other than the innermost or a frame interrupted
1613 by a signal, we assume that all registers have been saved.
1614 This assumes that all register saves in a function happen
1615 before the first function call. */
1616 (get_next_frame (fci) == NULL
1617 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1619 /* In a dummy frame we know exactly where things are saved. */
1620 && !PROC_DESC_IS_DUMMY (proc_desc)
1622 /* Don't bother unless we are inside a function prologue.
1623 Outside the prologue, we know where everything is. */
1625 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1627 /* Not sure exactly what kernel_trap means, but if it means the
1628 kernel saves the registers without a prologue doing it, we
1629 better not examine the prologue to see whether registers
1630 have been saved yet. */
1633 /* We need to figure out whether the registers that the
1634 proc_desc claims are saved have been saved yet. */
1638 /* Bitmasks; set if we have found a save for the register. */
1639 unsigned long gen_save_found = 0;
1640 unsigned long float_save_found = 0;
1643 /* If the address is odd, assume this is MIPS16 code. */
1644 addr = PROC_LOW_ADDR (proc_desc);
1645 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1647 /* Scan through this function's instructions preceding the
1648 current PC, and look for those that save registers. */
1649 while (addr < get_frame_pc (fci))
1651 inst = mips_fetch_instruction (addr);
1652 if (pc_is_mips16 (addr))
1653 mips16_decode_reg_save (inst, &gen_save_found);
1655 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1658 gen_mask = gen_save_found;
1659 float_mask = float_save_found;
1662 /* Fill in the offsets for the registers which gen_mask says were
1665 CORE_ADDR reg_position = (get_frame_base (fci)
1666 + PROC_REG_OFFSET (proc_desc));
1667 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1668 if (gen_mask & 0x80000000)
1670 set_reg_offset (saved_regs, ireg, reg_position);
1671 reg_position -= MIPS_SAVED_REGSIZE;
1675 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse
1676 order of that normally used by gcc. Therefore, we have to fetch
1677 the first instruction of the function, and if it's an entry
1678 instruction that saves $s0 or $s1, correct their saved addresses. */
1679 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1681 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1682 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)
1686 int sreg_count = (inst >> 6) & 3;
1688 /* Check if the ra register was pushed on the stack. */
1689 CORE_ADDR reg_position = (get_frame_base (fci)
1690 + PROC_REG_OFFSET (proc_desc));
1692 reg_position -= MIPS_SAVED_REGSIZE;
1694 /* Check if the s0 and s1 registers were pushed on the
1696 for (reg = 16; reg < sreg_count + 16; reg++)
1698 set_reg_offset (saved_regs, reg, reg_position);
1699 reg_position -= MIPS_SAVED_REGSIZE;
1704 /* Fill in the offsets for the registers which float_mask says were
1707 CORE_ADDR reg_position = (get_frame_base (fci)
1708 + PROC_FREG_OFFSET (proc_desc));
1710 /* Fill in the offsets for the float registers which float_mask
1712 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1713 if (float_mask & 0x80000000)
1715 if (MIPS_SAVED_REGSIZE == 4 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1717 /* On a big endian 32 bit ABI, floating point registers
1718 are paired to form doubles such that the most
1719 significant part is in $f[N+1] and the least
1720 significant in $f[N] vis: $f[N+1] ||| $f[N]. The
1721 registers are also spilled as a pair and stored as a
1724 When little-endian the least significant part is
1725 stored first leading to the memory order $f[N] and
1728 Unfortunately, when big-endian the most significant
1729 part of the double is stored first, and the least
1730 significant is stored second. This leads to the
1731 registers being ordered in memory as firt $f[N+1] and
1734 For the big-endian case make certain that the
1735 addresses point at the correct (swapped) locations
1736 $f[N] and $f[N+1] pair (keep in mind that
1737 reg_position is decremented each time through the
1740 set_reg_offset (saved_regs, FP0_REGNUM + ireg,
1741 reg_position - MIPS_SAVED_REGSIZE);
1743 set_reg_offset (saved_regs, FP0_REGNUM + ireg,
1744 reg_position + MIPS_SAVED_REGSIZE);
1747 set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1748 reg_position -= MIPS_SAVED_REGSIZE;
1751 set_reg_offset (saved_regs, PC_REGNUM, saved_regs[RA_REGNUM]);
1754 /* SP_REGNUM, contains the value and not the address. */
1755 set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1759 read_next_frame_reg (struct frame_info *fi, int regno)
1761 /* Always a pseudo. */
1762 gdb_assert (regno >= NUM_REGS);
1766 regcache_cooked_read_signed (current_regcache, regno, &val);
1769 else if ((regno % NUM_REGS) == SP_REGNUM)
1770 /* The SP_REGNUM is special, its value is stored in saved_regs.
1771 In fact, it is so special that it can even only be fetched
1772 using a raw register number! Once this code as been converted
1773 to frame-unwind the problem goes away. */
1774 return frame_unwind_register_signed (fi, regno % NUM_REGS);
1776 return frame_unwind_register_signed (fi, regno);
1780 /* mips_addr_bits_remove - remove useless address bits */
1783 mips_addr_bits_remove (CORE_ADDR addr)
1785 if (GDB_TARGET_IS_MIPS64)
1787 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1789 /* This hack is a work-around for existing boards using
1790 PMON, the simulator, and any other 64-bit targets that
1791 doesn't have true 64-bit addressing. On these targets,
1792 the upper 32 bits of addresses are ignored by the
1793 hardware. Thus, the PC or SP are likely to have been
1794 sign extended to all 1s by instruction sequences that
1795 load 32-bit addresses. For example, a typical piece of
1796 code that loads an address is this:
1797 lui $r2, <upper 16 bits>
1798 ori $r2, <lower 16 bits>
1799 But the lui sign-extends the value such that the upper 32
1800 bits may be all 1s. The workaround is simply to mask off
1801 these bits. In the future, gcc may be changed to support
1802 true 64-bit addressing, and this masking will have to be
1804 addr &= (CORE_ADDR) 0xffffffff;
1807 else if (mips_mask_address_p ())
1809 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1810 masking off bits, instead, the actual target should be asking
1811 for the address to be converted to a valid pointer. */
1812 /* Even when GDB is configured for some 32-bit targets
1813 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1814 so CORE_ADDR is 64 bits. So we still have to mask off
1815 useless bits from addresses. */
1816 addr &= (CORE_ADDR) 0xffffffff;
1821 /* mips_software_single_step() is called just before we want to resume
1822 the inferior, if we want to single-step it but there is no hardware
1823 or kernel single-step support (MIPS on GNU/Linux for example). We find
1824 the target of the coming instruction and breakpoint it.
1826 single_step is also called just after the inferior stops. If we had
1827 set up a simulated single-step, we undo our damage. */
1830 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1832 static CORE_ADDR next_pc;
1833 typedef char binsn_quantum[BREAKPOINT_MAX];
1834 static binsn_quantum break_mem;
1837 if (insert_breakpoints_p)
1839 pc = read_register (PC_REGNUM);
1840 next_pc = mips_next_pc (pc);
1842 target_insert_breakpoint (next_pc, break_mem);
1845 target_remove_breakpoint (next_pc, break_mem);
1849 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1854 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1855 : get_next_frame (prev)
1856 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1858 tmp = SKIP_TRAMPOLINE_CODE (pc);
1859 return tmp ? tmp : pc;
1864 mips_frame_saved_pc (struct frame_info *frame)
1868 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1871 /* Always unwind the cooked PC register value. */
1872 frame_unwind_signed_register (frame, NUM_REGS + PC_REGNUM, &tmp);
1877 mips_extra_func_info_t proc_desc
1878 = get_frame_extra_info (frame)->proc_desc;
1879 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1880 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1883 /* We have to get the saved pc from the sigcontext if it is
1884 a signal handler frame. */
1885 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME ? PC_REGNUM
1886 : proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1887 saved_pc = read_next_frame_reg (frame, NUM_REGS + pcreg);
1890 return ADDR_BITS_REMOVE (saved_pc);
1893 static struct mips_extra_func_info temp_proc_desc;
1895 /* This hack will go away once the get_prev_frame() code has been
1896 modified to set the frame's type first. That is BEFORE init extra
1897 frame info et.al. is called. This is because it will become
1898 possible to skip the init extra info call for sigtramp and dummy
1900 static CORE_ADDR *temp_saved_regs;
1902 /* Set a register's saved stack address in temp_saved_regs. If an
1903 address has already been set for this register, do nothing; this
1904 way we will only recognize the first save of a given register in a
1907 For simplicity, save the address in both [0 .. NUM_REGS) and
1908 [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range
1909 is used as it is only second range (the ABI instead of ISA
1910 registers) that comes into play when finding saved registers in a
1914 set_reg_offset (CORE_ADDR *saved_regs, int regno, CORE_ADDR offset)
1916 if (saved_regs[regno] == 0)
1918 saved_regs[regno + 0 * NUM_REGS] = offset;
1919 saved_regs[regno + 1 * NUM_REGS] = offset;
1924 /* Test whether the PC points to the return instruction at the
1925 end of a function. */
1928 mips_about_to_return (CORE_ADDR pc)
1930 if (pc_is_mips16 (pc))
1931 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1932 generates a "jr $ra"; other times it generates code to load
1933 the return address from the stack to an accessible register (such
1934 as $a3), then a "jr" using that register. This second case
1935 is almost impossible to distinguish from an indirect jump
1936 used for switch statements, so we don't even try. */
1937 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1939 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1943 /* This fencepost looks highly suspicious to me. Removing it also
1944 seems suspicious as it could affect remote debugging across serial
1948 heuristic_proc_start (CORE_ADDR pc)
1955 pc = ADDR_BITS_REMOVE (pc);
1957 fence = start_pc - heuristic_fence_post;
1961 if (heuristic_fence_post == UINT_MAX
1962 || fence < VM_MIN_ADDRESS)
1963 fence = VM_MIN_ADDRESS;
1965 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1967 /* search back for previous return */
1968 for (start_pc -= instlen;; start_pc -= instlen)
1969 if (start_pc < fence)
1971 /* It's not clear to me why we reach this point when
1972 stop_soon, but with this test, at least we
1973 don't print out warnings for every child forked (eg, on
1974 decstation). 22apr93 rich@cygnus.com. */
1975 if (stop_soon == NO_STOP_QUIETLY)
1977 static int blurb_printed = 0;
1979 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1984 /* This actually happens frequently in embedded
1985 development, when you first connect to a board
1986 and your stack pointer and pc are nowhere in
1987 particular. This message needs to give people
1988 in that situation enough information to
1989 determine that it's no big deal. */
1990 printf_filtered ("\n\
1991 GDB is unable to find the start of the function at 0x%s\n\
1992 and thus can't determine the size of that function's stack frame.\n\
1993 This means that GDB may be unable to access that stack frame, or\n\
1994 the frames below it.\n\
1995 This problem is most likely caused by an invalid program counter or\n\
1997 However, if you think GDB should simply search farther back\n\
1998 from 0x%s for code which looks like the beginning of a\n\
1999 function, you can increase the range of the search using the `set\n\
2000 heuristic-fence-post' command.\n",
2001 paddr_nz (pc), paddr_nz (pc));
2008 else if (pc_is_mips16 (start_pc))
2010 unsigned short inst;
2012 /* On MIPS16, any one of the following is likely to be the
2013 start of a function:
2017 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
2018 inst = mips_fetch_instruction (start_pc);
2019 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2020 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2021 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2022 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
2024 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2025 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2030 else if (mips_about_to_return (start_pc))
2032 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
2039 /* Fetch the immediate value from a MIPS16 instruction.
2040 If the previous instruction was an EXTEND, use it to extend
2041 the upper bits of the immediate value. This is a helper function
2042 for mips16_heuristic_proc_desc. */
2045 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
2046 unsigned short inst, /* current instruction */
2047 int nbits, /* number of bits in imm field */
2048 int scale, /* scale factor to be applied to imm */
2049 int is_signed) /* is the imm field signed? */
2053 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
2055 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
2056 if (offset & 0x8000) /* check for negative extend */
2057 offset = 0 - (0x10000 - (offset & 0xffff));
2058 return offset | (inst & 0x1f);
2062 int max_imm = 1 << nbits;
2063 int mask = max_imm - 1;
2064 int sign_bit = max_imm >> 1;
2066 offset = inst & mask;
2067 if (is_signed && (offset & sign_bit))
2068 offset = 0 - (max_imm - offset);
2069 return offset * scale;
2074 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
2075 stream from start_pc to limit_pc. */
2078 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2079 struct frame_info *next_frame, CORE_ADDR sp)
2082 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
2083 unsigned short prev_inst = 0; /* saved copy of previous instruction */
2084 unsigned inst = 0; /* current instruction */
2085 unsigned entry_inst = 0; /* the entry instruction */
2088 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
2089 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2091 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
2093 /* Save the previous instruction. If it's an EXTEND, we'll extract
2094 the immediate offset extension from it in mips16_get_imm. */
2097 /* Fetch and decode the instruction. */
2098 inst = (unsigned short) mips_fetch_instruction (cur_pc);
2099 if ((inst & 0xff00) == 0x6300 /* addiu sp */
2100 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2102 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
2103 if (offset < 0) /* negative stack adjustment? */
2104 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
2106 /* Exit loop if a positive stack adjustment is found, which
2107 usually means that the stack cleanup code in the function
2108 epilogue is reached. */
2111 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
2113 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2114 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
2115 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2116 set_reg_offset (temp_saved_regs, reg, sp + offset);
2118 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
2120 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2121 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2122 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2123 set_reg_offset (temp_saved_regs, reg, sp + offset);
2125 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2127 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2128 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2129 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2131 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2133 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2134 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2135 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2137 else if (inst == 0x673d) /* move $s1, $sp */
2140 PROC_FRAME_REG (&temp_proc_desc) = 17;
2142 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2144 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2145 frame_addr = sp + offset;
2146 PROC_FRAME_REG (&temp_proc_desc) = 17;
2147 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2149 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2151 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2152 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2153 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2154 set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2156 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2158 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2159 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2160 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2161 set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2163 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2164 entry_inst = inst; /* save for later processing */
2165 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2166 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2169 /* The entry instruction is typically the first instruction in a function,
2170 and it stores registers at offsets relative to the value of the old SP
2171 (before the prologue). But the value of the sp parameter to this
2172 function is the new SP (after the prologue has been executed). So we
2173 can't calculate those offsets until we've seen the entire prologue,
2174 and can calculate what the old SP must have been. */
2175 if (entry_inst != 0)
2177 int areg_count = (entry_inst >> 8) & 7;
2178 int sreg_count = (entry_inst >> 6) & 3;
2180 /* The entry instruction always subtracts 32 from the SP. */
2181 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2183 /* Now we can calculate what the SP must have been at the
2184 start of the function prologue. */
2185 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2187 /* Check if a0-a3 were saved in the caller's argument save area. */
2188 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2190 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2191 set_reg_offset (temp_saved_regs, reg, sp + offset);
2192 offset += MIPS_SAVED_REGSIZE;
2195 /* Check if the ra register was pushed on the stack. */
2197 if (entry_inst & 0x20)
2199 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2200 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2201 offset -= MIPS_SAVED_REGSIZE;
2204 /* Check if the s0 and s1 registers were pushed on the stack. */
2205 for (reg = 16; reg < sreg_count + 16; reg++)
2207 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2208 set_reg_offset (temp_saved_regs, reg, sp + offset);
2209 offset -= MIPS_SAVED_REGSIZE;
2215 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2216 struct frame_info *next_frame, CORE_ADDR sp)
2219 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2221 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2222 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2223 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2224 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2225 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2227 unsigned long inst, high_word, low_word;
2230 /* Fetch the instruction. */
2231 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2233 /* Save some code by pre-extracting some useful fields. */
2234 high_word = (inst >> 16) & 0xffff;
2235 low_word = inst & 0xffff;
2236 reg = high_word & 0x1f;
2238 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2239 || high_word == 0x23bd /* addi $sp,$sp,-i */
2240 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2242 if (low_word & 0x8000) /* negative stack adjustment? */
2243 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2245 /* Exit loop if a positive stack adjustment is found, which
2246 usually means that the stack cleanup code in the function
2247 epilogue is reached. */
2250 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2252 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2253 set_reg_offset (temp_saved_regs, reg, sp + low_word);
2255 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2257 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2258 but the register size used is only 32 bits. Make the address
2259 for the saved register point to the lower 32 bits. */
2260 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2261 set_reg_offset (temp_saved_regs, reg, sp + low_word + 8 - MIPS_REGSIZE);
2263 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2265 /* Old gcc frame, r30 is virtual frame pointer. */
2266 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2267 frame_addr = sp + low_word;
2268 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2270 unsigned alloca_adjust;
2271 PROC_FRAME_REG (&temp_proc_desc) = 30;
2272 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2273 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2274 if (alloca_adjust > 0)
2276 /* FP > SP + frame_size. This may be because
2277 * of an alloca or somethings similar.
2278 * Fix sp to "pre-alloca" value, and try again.
2280 sp += alloca_adjust;
2285 /* move $30,$sp. With different versions of gas this will be either
2286 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2287 Accept any one of these. */
2288 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2290 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2291 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2293 unsigned alloca_adjust;
2294 PROC_FRAME_REG (&temp_proc_desc) = 30;
2295 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2296 alloca_adjust = (unsigned) (frame_addr - sp);
2297 if (alloca_adjust > 0)
2299 /* FP > SP + frame_size. This may be because
2300 * of an alloca or somethings similar.
2301 * Fix sp to "pre-alloca" value, and try again.
2303 sp += alloca_adjust;
2308 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2310 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2311 set_reg_offset (temp_saved_regs, reg, frame_addr + low_word);
2316 static mips_extra_func_info_t
2317 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2318 struct frame_info *next_frame, int cur_frame)
2323 sp = read_next_frame_reg (next_frame, NUM_REGS + SP_REGNUM);
2329 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2330 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2331 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2332 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2333 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2334 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2336 if (start_pc + 200 < limit_pc)
2337 limit_pc = start_pc + 200;
2338 if (pc_is_mips16 (start_pc))
2339 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2341 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2342 return &temp_proc_desc;
2345 struct mips_objfile_private
2351 /* Global used to communicate between non_heuristic_proc_desc and
2352 compare_pdr_entries within qsort (). */
2353 static bfd *the_bfd;
2356 compare_pdr_entries (const void *a, const void *b)
2358 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2359 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2363 else if (lhs == rhs)
2369 static mips_extra_func_info_t
2370 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2372 CORE_ADDR startaddr;
2373 mips_extra_func_info_t proc_desc;
2374 struct block *b = block_for_pc (pc);
2376 struct obj_section *sec;
2377 struct mips_objfile_private *priv;
2379 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2382 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2384 *addrptr = startaddr;
2388 sec = find_pc_section (pc);
2391 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2393 /* Search the ".pdr" section generated by GAS. This includes most of
2394 the information normally found in ECOFF PDRs. */
2396 the_bfd = sec->objfile->obfd;
2398 && (the_bfd->format == bfd_object
2399 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2400 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2402 /* Right now GAS only outputs the address as a four-byte sequence.
2403 This means that we should not bother with this method on 64-bit
2404 targets (until that is fixed). */
2406 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2407 sizeof (struct mips_objfile_private));
2409 sec->objfile->obj_private = priv;
2411 else if (priv == NULL)
2415 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2416 sizeof (struct mips_objfile_private));
2418 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2421 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2422 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2424 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2425 priv->contents, 0, priv->size);
2427 /* In general, the .pdr section is sorted. However, in the
2428 presence of multiple code sections (and other corner cases)
2429 it can become unsorted. Sort it so that we can use a faster
2431 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2436 sec->objfile->obj_private = priv;
2440 if (priv->size != 0)
2446 high = priv->size / 32;
2452 mid = (low + high) / 2;
2454 ptr = priv->contents + mid * 32;
2455 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2456 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2457 SECT_OFF_TEXT (sec->objfile));
2458 if (pdr_pc == startaddr)
2460 if (pdr_pc > startaddr)
2465 while (low != high);
2469 struct symbol *sym = find_pc_function (pc);
2471 /* Fill in what we need of the proc_desc. */
2472 proc_desc = (mips_extra_func_info_t)
2473 obstack_alloc (&sec->objfile->psymbol_obstack,
2474 sizeof (struct mips_extra_func_info));
2475 PROC_LOW_ADDR (proc_desc) = startaddr;
2477 /* Only used for dummy frames. */
2478 PROC_HIGH_ADDR (proc_desc) = 0;
2480 PROC_FRAME_OFFSET (proc_desc)
2481 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2482 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2484 PROC_FRAME_ADJUST (proc_desc) = 0;
2485 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2487 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2489 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2491 PROC_FREG_OFFSET (proc_desc)
2492 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2493 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2495 proc_desc->pdr.isym = (long) sym;
2505 if (startaddr > BLOCK_START (b))
2507 /* This is the "pathological" case referred to in a comment in
2508 print_frame_info. It might be better to move this check into
2513 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
2515 /* If we never found a PDR for this function in symbol reading, then
2516 examine prologues to find the information. */
2519 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2520 if (PROC_FRAME_REG (proc_desc) == -1)
2530 static mips_extra_func_info_t
2531 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2533 mips_extra_func_info_t proc_desc;
2534 CORE_ADDR startaddr = 0;
2536 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2540 /* IF this is the topmost frame AND
2541 * (this proc does not have debugging information OR
2542 * the PC is in the procedure prologue)
2543 * THEN create a "heuristic" proc_desc (by analyzing
2544 * the actual code) to replace the "official" proc_desc.
2546 if (next_frame == NULL)
2548 struct symtab_and_line val;
2549 struct symbol *proc_symbol =
2550 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2554 val = find_pc_line (BLOCK_START
2555 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2557 val.pc = val.end ? val.end : pc;
2559 if (!proc_symbol || pc < val.pc)
2561 mips_extra_func_info_t found_heuristic =
2562 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2563 pc, next_frame, cur_frame);
2564 if (found_heuristic)
2565 proc_desc = found_heuristic;
2571 /* Is linked_proc_desc_table really necessary? It only seems to be used
2572 by procedure call dummys. However, the procedures being called ought
2573 to have their own proc_descs, and even if they don't,
2574 heuristic_proc_desc knows how to create them! */
2576 struct linked_proc_info *link;
2578 for (link = linked_proc_desc_table; link; link = link->next)
2579 if (PROC_LOW_ADDR (&link->info) <= pc
2580 && PROC_HIGH_ADDR (&link->info) > pc)
2584 startaddr = heuristic_proc_start (pc);
2587 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2593 get_frame_pointer (struct frame_info *frame,
2594 mips_extra_func_info_t proc_desc)
2596 return (read_next_frame_reg (frame, NUM_REGS + PROC_FRAME_REG (proc_desc))
2597 + PROC_FRAME_OFFSET (proc_desc)
2598 - PROC_FRAME_ADJUST (proc_desc));
2601 static mips_extra_func_info_t cached_proc_desc;
2604 mips_frame_chain (struct frame_info *frame)
2606 mips_extra_func_info_t proc_desc;
2608 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2610 if (saved_pc == 0 || deprecated_inside_entry_file (saved_pc))
2613 /* Check if the PC is inside a call stub. If it is, fetch the
2614 PC of the caller of that stub. */
2615 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2618 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2620 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2621 is well, frame->frame the bottom of the current frame will
2622 contain that value. */
2623 return get_frame_base (frame);
2626 /* Look up the procedure descriptor for this PC. */
2627 proc_desc = find_proc_desc (saved_pc, frame, 1);
2631 cached_proc_desc = proc_desc;
2633 /* If no frame pointer and frame size is zero, we must be at end
2634 of stack (or otherwise hosed). If we don't check frame size,
2635 we loop forever if we see a zero size frame. */
2636 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2637 && PROC_FRAME_OFFSET (proc_desc) == 0
2638 /* The previous frame from a sigtramp frame might be frameless
2639 and have frame size zero. */
2640 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2641 /* For a generic dummy frame, let get_frame_pointer() unwind a
2642 register value saved as part of the dummy frame call. */
2643 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2646 return get_frame_pointer (frame, proc_desc);
2650 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2653 mips_extra_func_info_t proc_desc;
2655 if (get_frame_type (fci) == DUMMY_FRAME)
2658 /* Use proc_desc calculated in frame_chain. When there is no
2659 next frame, i.e, get_next_frame (fci) == NULL, we call
2660 find_proc_desc () to calculate it, passing an explicit
2661 NULL as the frame parameter. */
2663 get_next_frame (fci)
2665 : find_proc_desc (get_frame_pc (fci),
2666 NULL /* i.e, get_next_frame (fci) */,
2669 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2671 deprecated_set_frame_saved_regs_hack (fci, NULL);
2672 get_frame_extra_info (fci)->proc_desc =
2673 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2676 /* Fixup frame-pointer - only needed for top frame */
2677 /* This may not be quite right, if proc has a real frame register.
2678 Get the value of the frame relative sp, procedure might have been
2679 interrupted by a signal at it's very start. */
2680 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2681 && !PROC_DESC_IS_DUMMY (proc_desc))
2682 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), NUM_REGS + SP_REGNUM));
2683 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2684 /* Do not ``fix'' fci->frame. It will have the value of the
2685 generic dummy frame's top-of-stack (since the draft
2686 fci->frame is obtained by returning the unwound stack
2687 pointer) and that is what we want. That way the fci->frame
2688 value will match the top-of-stack value that was saved as
2689 part of the dummy frames data. */
2692 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2694 if (proc_desc == &temp_proc_desc)
2698 /* Do not set the saved registers for a sigtramp frame,
2699 mips_find_saved_registers will do that for us. We can't
2700 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2702 /* FIXME: cagney/2002-11-18: This problem will go away once
2703 frame.c:get_prev_frame() is modified to set the frame's
2704 type before calling functions like this. */
2705 find_pc_partial_function (get_frame_pc (fci), &name,
2706 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2707 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2709 frame_saved_regs_zalloc (fci);
2710 /* Set value of previous frame's stack pointer.
2711 Remember that saved_regs[SP_REGNUM] is special in
2712 that it contains the value of the stack pointer
2713 register. The other saved_regs values are addresses
2714 (in the inferior) at which a given register's value
2716 set_reg_offset (temp_saved_regs, SP_REGNUM,
2717 get_frame_base (fci));
2718 set_reg_offset (temp_saved_regs, PC_REGNUM,
2719 temp_saved_regs[RA_REGNUM]);
2720 memcpy (deprecated_get_frame_saved_regs (fci), temp_saved_regs,
2721 SIZEOF_FRAME_SAVED_REGS);
2725 /* hack: if argument regs are saved, guess these contain args */
2726 /* assume we can't tell how many args for now */
2727 get_frame_extra_info (fci)->num_args = -1;
2728 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2730 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2732 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2739 /* MIPS stack frames are almost impenetrable. When execution stops,
2740 we basically have to look at symbol information for the function
2741 that we stopped in, which tells us *which* register (if any) is
2742 the base of the frame pointer, and what offset from that register
2743 the frame itself is at.
2745 This presents a problem when trying to examine a stack in memory
2746 (that isn't executing at the moment), using the "frame" command. We
2747 don't have a PC, nor do we have any registers except SP.
2749 This routine takes two arguments, SP and PC, and tries to make the
2750 cached frames look as if these two arguments defined a frame on the
2751 cache. This allows the rest of info frame to extract the important
2752 arguments without difficulty. */
2755 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2758 error ("MIPS frame specifications require two arguments: sp and pc");
2760 return create_new_frame (argv[0], argv[1]);
2763 /* According to the current ABI, should the type be passed in a
2764 floating-point register (assuming that there is space)? When there
2765 is no FPU, FP are not even considered as possibile candidates for
2766 FP registers and, consequently this returns false - forces FP
2767 arguments into integer registers. */
2770 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2772 return ((typecode == TYPE_CODE_FLT
2774 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2775 && TYPE_NFIELDS (arg_type) == 1
2776 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2777 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2780 /* On o32, argument passing in GPRs depends on the alignment of the type being
2781 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2784 mips_type_needs_double_align (struct type *type)
2786 enum type_code typecode = TYPE_CODE (type);
2788 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2790 else if (typecode == TYPE_CODE_STRUCT)
2792 if (TYPE_NFIELDS (type) < 1)
2794 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2796 else if (typecode == TYPE_CODE_UNION)
2800 n = TYPE_NFIELDS (type);
2801 for (i = 0; i < n; i++)
2802 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2809 /* Adjust the address downward (direction of stack growth) so that it
2810 is correctly aligned for a new stack frame. */
2812 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2814 return align_down (addr, 16);
2818 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2819 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2820 struct value **args, CORE_ADDR sp, int struct_return,
2821 CORE_ADDR struct_addr)
2827 int stack_offset = 0;
2829 /* For shared libraries, "t9" needs to point at the function
2831 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2833 /* Set the return address register to point to the entry point of
2834 the program, where a breakpoint lies in wait. */
2835 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2837 /* First ensure that the stack and structure return address (if any)
2838 are properly aligned. The stack has to be at least 64-bit
2839 aligned even on 32-bit machines, because doubles must be 64-bit
2840 aligned. For n32 and n64, stack frames need to be 128-bit
2841 aligned, so we round to this widest known alignment. */
2843 sp = align_down (sp, 16);
2844 struct_addr = align_down (struct_addr, 16);
2846 /* Now make space on the stack for the args. We allocate more
2847 than necessary for EABI, because the first few arguments are
2848 passed in registers, but that's OK. */
2849 for (argnum = 0; argnum < nargs; argnum++)
2850 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2851 MIPS_STACK_ARGSIZE);
2852 sp -= align_up (len, 16);
2855 fprintf_unfiltered (gdb_stdlog,
2856 "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n",
2857 paddr_nz (sp), (long) align_up (len, 16));
2859 /* Initialize the integer and float register pointers. */
2861 float_argreg = FPA0_REGNUM;
2863 /* The struct_return pointer occupies the first parameter-passing reg. */
2867 fprintf_unfiltered (gdb_stdlog,
2868 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2869 argreg, paddr_nz (struct_addr));
2870 write_register (argreg++, struct_addr);
2873 /* Now load as many as possible of the first arguments into
2874 registers, and push the rest onto the stack. Loop thru args
2875 from first to last. */
2876 for (argnum = 0; argnum < nargs; argnum++)
2879 char valbuf[MAX_REGISTER_SIZE];
2880 struct value *arg = args[argnum];
2881 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2882 int len = TYPE_LENGTH (arg_type);
2883 enum type_code typecode = TYPE_CODE (arg_type);
2886 fprintf_unfiltered (gdb_stdlog,
2887 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2888 argnum + 1, len, (int) typecode);
2890 /* The EABI passes structures that do not fit in a register by
2892 if (len > MIPS_SAVED_REGSIZE
2893 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2895 store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2896 typecode = TYPE_CODE_PTR;
2897 len = MIPS_SAVED_REGSIZE;
2900 fprintf_unfiltered (gdb_stdlog, " push");
2903 val = (char *) VALUE_CONTENTS (arg);
2905 /* 32-bit ABIs always start floating point arguments in an
2906 even-numbered floating point register. Round the FP register
2907 up before the check to see if there are any FP registers
2908 left. Non MIPS_EABI targets also pass the FP in the integer
2909 registers so also round up normal registers. */
2910 if (!FP_REGISTER_DOUBLE
2911 && fp_register_arg_p (typecode, arg_type))
2913 if ((float_argreg & 1))
2917 /* Floating point arguments passed in registers have to be
2918 treated specially. On 32-bit architectures, doubles
2919 are passed in register pairs; the even register gets
2920 the low word, and the odd register gets the high word.
2921 On non-EABI processors, the first two floating point arguments are
2922 also copied to general registers, because MIPS16 functions
2923 don't use float registers for arguments. This duplication of
2924 arguments in general registers can't hurt non-MIPS16 functions
2925 because those registers are normally skipped. */
2926 /* MIPS_EABI squeezes a struct that contains a single floating
2927 point value into an FP register instead of pushing it onto the
2929 if (fp_register_arg_p (typecode, arg_type)
2930 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2932 if (!FP_REGISTER_DOUBLE && len == 8)
2934 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2935 unsigned long regval;
2937 /* Write the low word of the double to the even register(s). */
2938 regval = extract_unsigned_integer (val + low_offset, 4);
2940 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2941 float_argreg, phex (regval, 4));
2942 write_register (float_argreg++, regval);
2944 /* Write the high word of the double to the odd register(s). */
2945 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2947 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2948 float_argreg, phex (regval, 4));
2949 write_register (float_argreg++, regval);
2953 /* This is a floating point value that fits entirely
2954 in a single register. */
2955 /* On 32 bit ABI's the float_argreg is further adjusted
2956 above to ensure that it is even register aligned. */
2957 LONGEST regval = extract_unsigned_integer (val, len);
2959 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2960 float_argreg, phex (regval, len));
2961 write_register (float_argreg++, regval);
2966 /* Copy the argument to general registers or the stack in
2967 register-sized pieces. Large arguments are split between
2968 registers and stack. */
2969 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2970 are treated specially: Irix cc passes them in registers
2971 where gcc sometimes puts them on the stack. For maximum
2972 compatibility, we will put them in both places. */
2973 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2974 (len % MIPS_SAVED_REGSIZE != 0));
2976 /* Note: Floating-point values that didn't fit into an FP
2977 register are only written to memory. */
2980 /* Remember if the argument was written to the stack. */
2981 int stack_used_p = 0;
2983 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2986 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2989 /* Write this portion of the argument to the stack. */
2990 if (argreg > MIPS_LAST_ARG_REGNUM
2992 || fp_register_arg_p (typecode, arg_type))
2994 /* Should shorter than int integer values be
2995 promoted to int before being stored? */
2996 int longword_offset = 0;
2999 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3001 if (MIPS_STACK_ARGSIZE == 8 &&
3002 (typecode == TYPE_CODE_INT ||
3003 typecode == TYPE_CODE_PTR ||
3004 typecode == TYPE_CODE_FLT) && len <= 4)
3005 longword_offset = MIPS_STACK_ARGSIZE - len;
3006 else if ((typecode == TYPE_CODE_STRUCT ||
3007 typecode == TYPE_CODE_UNION) &&
3008 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
3009 longword_offset = MIPS_STACK_ARGSIZE - len;
3014 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3015 paddr_nz (stack_offset));
3016 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3017 paddr_nz (longword_offset));
3020 addr = sp + stack_offset + longword_offset;
3025 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3027 for (i = 0; i < partial_len; i++)
3029 fprintf_unfiltered (gdb_stdlog, "%02x",
3033 write_memory (addr, val, partial_len);
3036 /* Note!!! This is NOT an else clause. Odd sized
3037 structs may go thru BOTH paths. Floating point
3038 arguments will not. */
3039 /* Write this portion of the argument to a general
3040 purpose register. */
3041 if (argreg <= MIPS_LAST_ARG_REGNUM
3042 && !fp_register_arg_p (typecode, arg_type))
3044 LONGEST regval = extract_unsigned_integer (val, partial_len);
3047 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3049 phex (regval, MIPS_SAVED_REGSIZE));
3050 write_register (argreg, regval);
3057 /* Compute the the offset into the stack at which we
3058 will copy the next parameter.
3060 In the new EABI (and the NABI32), the stack_offset
3061 only needs to be adjusted when it has been used. */
3064 stack_offset += align_up (partial_len, MIPS_STACK_ARGSIZE);
3068 fprintf_unfiltered (gdb_stdlog, "\n");
3071 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3073 /* Return adjusted stack pointer. */
3077 /* N32/N64 version of push_dummy_call. */
3080 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3081 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3082 struct value **args, CORE_ADDR sp, int struct_return,
3083 CORE_ADDR struct_addr)
3089 int stack_offset = 0;
3091 /* For shared libraries, "t9" needs to point at the function
3093 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3095 /* Set the return address register to point to the entry point of
3096 the program, where a breakpoint lies in wait. */
3097 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3099 /* First ensure that the stack and structure return address (if any)
3100 are properly aligned. The stack has to be at least 64-bit
3101 aligned even on 32-bit machines, because doubles must be 64-bit
3102 aligned. For n32 and n64, stack frames need to be 128-bit
3103 aligned, so we round to this widest known alignment. */
3105 sp = align_down (sp, 16);
3106 struct_addr = align_down (struct_addr, 16);
3108 /* Now make space on the stack for the args. */
3109 for (argnum = 0; argnum < nargs; argnum++)
3110 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3111 MIPS_STACK_ARGSIZE);
3112 sp -= align_up (len, 16);
3115 fprintf_unfiltered (gdb_stdlog,
3116 "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n",
3117 paddr_nz (sp), (long) align_up (len, 16));
3119 /* Initialize the integer and float register pointers. */
3121 float_argreg = FPA0_REGNUM;
3123 /* The struct_return pointer occupies the first parameter-passing reg. */
3127 fprintf_unfiltered (gdb_stdlog,
3128 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3129 argreg, paddr_nz (struct_addr));
3130 write_register (argreg++, struct_addr);
3133 /* Now load as many as possible of the first arguments into
3134 registers, and push the rest onto the stack. Loop thru args
3135 from first to last. */
3136 for (argnum = 0; argnum < nargs; argnum++)
3139 char valbuf[MAX_REGISTER_SIZE];
3140 struct value *arg = args[argnum];
3141 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3142 int len = TYPE_LENGTH (arg_type);
3143 enum type_code typecode = TYPE_CODE (arg_type);
3146 fprintf_unfiltered (gdb_stdlog,
3147 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3148 argnum + 1, len, (int) typecode);
3150 val = (char *) VALUE_CONTENTS (arg);
3152 if (fp_register_arg_p (typecode, arg_type)
3153 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3155 /* This is a floating point value that fits entirely
3156 in a single register. */
3157 /* On 32 bit ABI's the float_argreg is further adjusted
3158 above to ensure that it is even register aligned. */
3159 LONGEST regval = extract_unsigned_integer (val, len);
3161 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3162 float_argreg, phex (regval, len));
3163 write_register (float_argreg++, regval);
3166 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3167 argreg, phex (regval, len));
3168 write_register (argreg, regval);
3173 /* Copy the argument to general registers or the stack in
3174 register-sized pieces. Large arguments are split between
3175 registers and stack. */
3176 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3177 are treated specially: Irix cc passes them in registers
3178 where gcc sometimes puts them on the stack. For maximum
3179 compatibility, we will put them in both places. */
3180 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3181 (len % MIPS_SAVED_REGSIZE != 0));
3182 /* Note: Floating-point values that didn't fit into an FP
3183 register are only written to memory. */
3186 /* Rememer if the argument was written to the stack. */
3187 int stack_used_p = 0;
3188 int partial_len = len < MIPS_SAVED_REGSIZE ?
3189 len : MIPS_SAVED_REGSIZE;
3192 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3195 /* Write this portion of the argument to the stack. */
3196 if (argreg > MIPS_LAST_ARG_REGNUM
3198 || fp_register_arg_p (typecode, arg_type))
3200 /* Should shorter than int integer values be
3201 promoted to int before being stored? */
3202 int longword_offset = 0;
3205 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3207 if (MIPS_STACK_ARGSIZE == 8 &&
3208 (typecode == TYPE_CODE_INT ||
3209 typecode == TYPE_CODE_PTR ||
3210 typecode == TYPE_CODE_FLT) && len <= 4)
3211 longword_offset = MIPS_STACK_ARGSIZE - len;
3216 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3217 paddr_nz (stack_offset));
3218 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3219 paddr_nz (longword_offset));
3222 addr = sp + stack_offset + longword_offset;
3227 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3229 for (i = 0; i < partial_len; i++)
3231 fprintf_unfiltered (gdb_stdlog, "%02x",
3235 write_memory (addr, val, partial_len);
3238 /* Note!!! This is NOT an else clause. Odd sized
3239 structs may go thru BOTH paths. Floating point
3240 arguments will not. */
3241 /* Write this portion of the argument to a general
3242 purpose register. */
3243 if (argreg <= MIPS_LAST_ARG_REGNUM
3244 && !fp_register_arg_p (typecode, arg_type))
3246 LONGEST regval = extract_unsigned_integer (val, partial_len);
3248 /* A non-floating-point argument being passed in a
3249 general register. If a struct or union, and if
3250 the remaining length is smaller than the register
3251 size, we have to adjust the register value on
3254 It does not seem to be necessary to do the
3255 same for integral types.
3257 cagney/2001-07-23: gdb/179: Also, GCC, when
3258 outputting LE O32 with sizeof (struct) <
3259 MIPS_SAVED_REGSIZE, generates a left shift as
3260 part of storing the argument in a register a
3261 register (the left shift isn't generated when
3262 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3263 is quite possible that this is GCC contradicting
3264 the LE/O32 ABI, GDB has not been adjusted to
3265 accommodate this. Either someone needs to
3266 demonstrate that the LE/O32 ABI specifies such a
3267 left shift OR this new ABI gets identified as
3268 such and GDB gets tweaked accordingly. */
3270 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3271 && partial_len < MIPS_SAVED_REGSIZE
3272 && (typecode == TYPE_CODE_STRUCT ||
3273 typecode == TYPE_CODE_UNION))
3274 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3278 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3280 phex (regval, MIPS_SAVED_REGSIZE));
3281 write_register (argreg, regval);
3288 /* Compute the the offset into the stack at which we
3289 will copy the next parameter.
3291 In N32 (N64?), the stack_offset only needs to be
3292 adjusted when it has been used. */
3295 stack_offset += align_up (partial_len, MIPS_STACK_ARGSIZE);
3299 fprintf_unfiltered (gdb_stdlog, "\n");
3302 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3304 /* Return adjusted stack pointer. */
3308 /* O32 version of push_dummy_call. */
3311 mips_o32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3312 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3313 struct value **args, CORE_ADDR sp, int struct_return,
3314 CORE_ADDR struct_addr)
3320 int stack_offset = 0;
3322 /* For shared libraries, "t9" needs to point at the function
3324 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3326 /* Set the return address register to point to the entry point of
3327 the program, where a breakpoint lies in wait. */
3328 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3330 /* First ensure that the stack and structure return address (if any)
3331 are properly aligned. The stack has to be at least 64-bit
3332 aligned even on 32-bit machines, because doubles must be 64-bit
3333 aligned. For n32 and n64, stack frames need to be 128-bit
3334 aligned, so we round to this widest known alignment. */
3336 sp = align_down (sp, 16);
3337 struct_addr = align_down (struct_addr, 16);
3339 /* Now make space on the stack for the args. */
3340 for (argnum = 0; argnum < nargs; argnum++)
3341 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3342 MIPS_STACK_ARGSIZE);
3343 sp -= align_up (len, 16);
3346 fprintf_unfiltered (gdb_stdlog,
3347 "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n",
3348 paddr_nz (sp), (long) align_up (len, 16));
3350 /* Initialize the integer and float register pointers. */
3352 float_argreg = FPA0_REGNUM;
3354 /* The struct_return pointer occupies the first parameter-passing reg. */
3358 fprintf_unfiltered (gdb_stdlog,
3359 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3360 argreg, paddr_nz (struct_addr));
3361 write_register (argreg++, struct_addr);
3362 stack_offset += MIPS_STACK_ARGSIZE;
3365 /* Now load as many as possible of the first arguments into
3366 registers, and push the rest onto the stack. Loop thru args
3367 from first to last. */
3368 for (argnum = 0; argnum < nargs; argnum++)
3371 char valbuf[MAX_REGISTER_SIZE];
3372 struct value *arg = args[argnum];
3373 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3374 int len = TYPE_LENGTH (arg_type);
3375 enum type_code typecode = TYPE_CODE (arg_type);
3378 fprintf_unfiltered (gdb_stdlog,
3379 "mips_o32_push_dummy_call: %d len=%d type=%d",
3380 argnum + 1, len, (int) typecode);
3382 val = (char *) VALUE_CONTENTS (arg);
3384 /* 32-bit ABIs always start floating point arguments in an
3385 even-numbered floating point register. Round the FP register
3386 up before the check to see if there are any FP registers
3387 left. O32/O64 targets also pass the FP in the integer
3388 registers so also round up normal registers. */
3389 if (!FP_REGISTER_DOUBLE
3390 && fp_register_arg_p (typecode, arg_type))
3392 if ((float_argreg & 1))
3396 /* Floating point arguments passed in registers have to be
3397 treated specially. On 32-bit architectures, doubles
3398 are passed in register pairs; the even register gets
3399 the low word, and the odd register gets the high word.
3400 On O32/O64, the first two floating point arguments are
3401 also copied to general registers, because MIPS16 functions
3402 don't use float registers for arguments. This duplication of
3403 arguments in general registers can't hurt non-MIPS16 functions
3404 because those registers are normally skipped. */
3406 if (fp_register_arg_p (typecode, arg_type)
3407 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3409 if (!FP_REGISTER_DOUBLE && len == 8)
3411 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3412 unsigned long regval;
3414 /* Write the low word of the double to the even register(s). */
3415 regval = extract_unsigned_integer (val + low_offset, 4);
3417 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3418 float_argreg, phex (regval, 4));
3419 write_register (float_argreg++, regval);
3421 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3422 argreg, phex (regval, 4));
3423 write_register (argreg++, regval);
3425 /* Write the high word of the double to the odd register(s). */
3426 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3428 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3429 float_argreg, phex (regval, 4));
3430 write_register (float_argreg++, regval);
3433 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3434 argreg, phex (regval, 4));
3435 write_register (argreg++, regval);
3439 /* This is a floating point value that fits entirely
3440 in a single register. */
3441 /* On 32 bit ABI's the float_argreg is further adjusted
3442 above to ensure that it is even register aligned. */
3443 LONGEST regval = extract_unsigned_integer (val, len);
3445 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3446 float_argreg, phex (regval, len));
3447 write_register (float_argreg++, regval);
3448 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3449 registers for each argument. The below is (my
3450 guess) to ensure that the corresponding integer
3451 register has reserved the same space. */
3453 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3454 argreg, phex (regval, len));
3455 write_register (argreg, regval);
3456 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3458 /* Reserve space for the FP register. */
3459 stack_offset += align_up (len, MIPS_STACK_ARGSIZE);
3463 /* Copy the argument to general registers or the stack in
3464 register-sized pieces. Large arguments are split between
3465 registers and stack. */
3466 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3467 are treated specially: Irix cc passes them in registers
3468 where gcc sometimes puts them on the stack. For maximum
3469 compatibility, we will put them in both places. */
3470 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3471 (len % MIPS_SAVED_REGSIZE != 0));
3472 /* Structures should be aligned to eight bytes (even arg registers)
3473 on MIPS_ABI_O32, if their first member has double precision. */
3474 if (MIPS_SAVED_REGSIZE < 8
3475 && mips_type_needs_double_align (arg_type))
3480 /* Note: Floating-point values that didn't fit into an FP
3481 register are only written to memory. */
3484 /* Remember if the argument was written to the stack. */
3485 int stack_used_p = 0;
3487 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3490 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3493 /* Write this portion of the argument to the stack. */
3494 if (argreg > MIPS_LAST_ARG_REGNUM
3496 || fp_register_arg_p (typecode, arg_type))
3498 /* Should shorter than int integer values be
3499 promoted to int before being stored? */
3500 int longword_offset = 0;
3503 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3505 if (MIPS_STACK_ARGSIZE == 8 &&
3506 (typecode == TYPE_CODE_INT ||
3507 typecode == TYPE_CODE_PTR ||
3508 typecode == TYPE_CODE_FLT) && len <= 4)
3509 longword_offset = MIPS_STACK_ARGSIZE - len;
3514 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3515 paddr_nz (stack_offset));
3516 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3517 paddr_nz (longword_offset));
3520 addr = sp + stack_offset + longword_offset;
3525 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3527 for (i = 0; i < partial_len; i++)
3529 fprintf_unfiltered (gdb_stdlog, "%02x",
3533 write_memory (addr, val, partial_len);
3536 /* Note!!! This is NOT an else clause. Odd sized
3537 structs may go thru BOTH paths. Floating point
3538 arguments will not. */
3539 /* Write this portion of the argument to a general
3540 purpose register. */
3541 if (argreg <= MIPS_LAST_ARG_REGNUM
3542 && !fp_register_arg_p (typecode, arg_type))
3544 LONGEST regval = extract_signed_integer (val, partial_len);
3545 /* Value may need to be sign extended, because
3546 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3548 /* A non-floating-point argument being passed in a
3549 general register. If a struct or union, and if
3550 the remaining length is smaller than the register
3551 size, we have to adjust the register value on
3554 It does not seem to be necessary to do the
3555 same for integral types.
3557 Also don't do this adjustment on O64 binaries.
3559 cagney/2001-07-23: gdb/179: Also, GCC, when
3560 outputting LE O32 with sizeof (struct) <
3561 MIPS_SAVED_REGSIZE, generates a left shift as
3562 part of storing the argument in a register a
3563 register (the left shift isn't generated when
3564 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3565 is quite possible that this is GCC contradicting
3566 the LE/O32 ABI, GDB has not been adjusted to
3567 accommodate this. Either someone needs to
3568 demonstrate that the LE/O32 ABI specifies such a
3569 left shift OR this new ABI gets identified as
3570 such and GDB gets tweaked accordingly. */
3572 if (MIPS_SAVED_REGSIZE < 8
3573 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3574 && partial_len < MIPS_SAVED_REGSIZE
3575 && (typecode == TYPE_CODE_STRUCT ||
3576 typecode == TYPE_CODE_UNION))
3577 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3581 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3583 phex (regval, MIPS_SAVED_REGSIZE));
3584 write_register (argreg, regval);
3587 /* Prevent subsequent floating point arguments from
3588 being passed in floating point registers. */
3589 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3595 /* Compute the the offset into the stack at which we
3596 will copy the next parameter.
3598 In older ABIs, the caller reserved space for
3599 registers that contained arguments. This was loosely
3600 refered to as their "home". Consequently, space is
3601 always allocated. */
3603 stack_offset += align_up (partial_len, MIPS_STACK_ARGSIZE);
3607 fprintf_unfiltered (gdb_stdlog, "\n");
3610 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3612 /* Return adjusted stack pointer. */
3616 /* O64 version of push_dummy_call. */
3619 mips_o64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3620 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3621 struct value **args, CORE_ADDR sp, int struct_return,
3622 CORE_ADDR struct_addr)
3628 int stack_offset = 0;
3630 /* For shared libraries, "t9" needs to point at the function
3632 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3634 /* Set the return address register to point to the entry point of
3635 the program, where a breakpoint lies in wait. */
3636 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3638 /* First ensure that the stack and structure return address (if any)
3639 are properly aligned. The stack has to be at least 64-bit
3640 aligned even on 32-bit machines, because doubles must be 64-bit
3641 aligned. For n32 and n64, stack frames need to be 128-bit
3642 aligned, so we round to this widest known alignment. */
3644 sp = align_down (sp, 16);
3645 struct_addr = align_down (struct_addr, 16);
3647 /* Now make space on the stack for the args. */
3648 for (argnum = 0; argnum < nargs; argnum++)
3649 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3650 MIPS_STACK_ARGSIZE);
3651 sp -= align_up (len, 16);
3654 fprintf_unfiltered (gdb_stdlog,
3655 "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n",
3656 paddr_nz (sp), (long) align_up (len, 16));
3658 /* Initialize the integer and float register pointers. */
3660 float_argreg = FPA0_REGNUM;
3662 /* The struct_return pointer occupies the first parameter-passing reg. */
3666 fprintf_unfiltered (gdb_stdlog,
3667 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3668 argreg, paddr_nz (struct_addr));
3669 write_register (argreg++, struct_addr);
3670 stack_offset += MIPS_STACK_ARGSIZE;
3673 /* Now load as many as possible of the first arguments into
3674 registers, and push the rest onto the stack. Loop thru args
3675 from first to last. */
3676 for (argnum = 0; argnum < nargs; argnum++)
3679 char valbuf[MAX_REGISTER_SIZE];
3680 struct value *arg = args[argnum];
3681 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3682 int len = TYPE_LENGTH (arg_type);
3683 enum type_code typecode = TYPE_CODE (arg_type);
3686 fprintf_unfiltered (gdb_stdlog,
3687 "mips_o64_push_dummy_call: %d len=%d type=%d",
3688 argnum + 1, len, (int) typecode);
3690 val = (char *) VALUE_CONTENTS (arg);
3692 /* 32-bit ABIs always start floating point arguments in an
3693 even-numbered floating point register. Round the FP register
3694 up before the check to see if there are any FP registers
3695 left. O32/O64 targets also pass the FP in the integer
3696 registers so also round up normal registers. */
3697 if (!FP_REGISTER_DOUBLE
3698 && fp_register_arg_p (typecode, arg_type))
3700 if ((float_argreg & 1))
3704 /* Floating point arguments passed in registers have to be
3705 treated specially. On 32-bit architectures, doubles
3706 are passed in register pairs; the even register gets
3707 the low word, and the odd register gets the high word.
3708 On O32/O64, the first two floating point arguments are
3709 also copied to general registers, because MIPS16 functions
3710 don't use float registers for arguments. This duplication of
3711 arguments in general registers can't hurt non-MIPS16 functions
3712 because those registers are normally skipped. */
3714 if (fp_register_arg_p (typecode, arg_type)
3715 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3717 if (!FP_REGISTER_DOUBLE && len == 8)
3719 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3720 unsigned long regval;
3722 /* Write the low word of the double to the even register(s). */
3723 regval = extract_unsigned_integer (val + low_offset, 4);
3725 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3726 float_argreg, phex (regval, 4));
3727 write_register (float_argreg++, regval);
3729 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3730 argreg, phex (regval, 4));
3731 write_register (argreg++, regval);
3733 /* Write the high word of the double to the odd register(s). */
3734 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3736 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3737 float_argreg, phex (regval, 4));
3738 write_register (float_argreg++, regval);
3741 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3742 argreg, phex (regval, 4));
3743 write_register (argreg++, regval);
3747 /* This is a floating point value that fits entirely
3748 in a single register. */
3749 /* On 32 bit ABI's the float_argreg is further adjusted
3750 above to ensure that it is even register aligned. */
3751 LONGEST regval = extract_unsigned_integer (val, len);
3753 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3754 float_argreg, phex (regval, len));
3755 write_register (float_argreg++, regval);
3756 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3757 registers for each argument. The below is (my
3758 guess) to ensure that the corresponding integer
3759 register has reserved the same space. */
3761 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3762 argreg, phex (regval, len));
3763 write_register (argreg, regval);
3764 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3766 /* Reserve space for the FP register. */
3767 stack_offset += align_up (len, MIPS_STACK_ARGSIZE);
3771 /* Copy the argument to general registers or the stack in
3772 register-sized pieces. Large arguments are split between
3773 registers and stack. */
3774 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3775 are treated specially: Irix cc passes them in registers
3776 where gcc sometimes puts them on the stack. For maximum
3777 compatibility, we will put them in both places. */
3778 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3779 (len % MIPS_SAVED_REGSIZE != 0));
3780 /* Structures should be aligned to eight bytes (even arg registers)
3781 on MIPS_ABI_O32, if their first member has double precision. */
3782 if (MIPS_SAVED_REGSIZE < 8
3783 && mips_type_needs_double_align (arg_type))
3788 /* Note: Floating-point values that didn't fit into an FP
3789 register are only written to memory. */
3792 /* Remember if the argument was written to the stack. */
3793 int stack_used_p = 0;
3795 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3798 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3801 /* Write this portion of the argument to the stack. */
3802 if (argreg > MIPS_LAST_ARG_REGNUM
3804 || fp_register_arg_p (typecode, arg_type))
3806 /* Should shorter than int integer values be
3807 promoted to int before being stored? */
3808 int longword_offset = 0;
3811 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3813 if (MIPS_STACK_ARGSIZE == 8 &&
3814 (typecode == TYPE_CODE_INT ||
3815 typecode == TYPE_CODE_PTR ||
3816 typecode == TYPE_CODE_FLT) && len <= 4)
3817 longword_offset = MIPS_STACK_ARGSIZE - len;
3822 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3823 paddr_nz (stack_offset));
3824 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3825 paddr_nz (longword_offset));
3828 addr = sp + stack_offset + longword_offset;
3833 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3835 for (i = 0; i < partial_len; i++)
3837 fprintf_unfiltered (gdb_stdlog, "%02x",
3841 write_memory (addr, val, partial_len);
3844 /* Note!!! This is NOT an else clause. Odd sized
3845 structs may go thru BOTH paths. Floating point
3846 arguments will not. */
3847 /* Write this portion of the argument to a general
3848 purpose register. */
3849 if (argreg <= MIPS_LAST_ARG_REGNUM
3850 && !fp_register_arg_p (typecode, arg_type))
3852 LONGEST regval = extract_signed_integer (val, partial_len);
3853 /* Value may need to be sign extended, because
3854 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3856 /* A non-floating-point argument being passed in a
3857 general register. If a struct or union, and if
3858 the remaining length is smaller than the register
3859 size, we have to adjust the register value on
3862 It does not seem to be necessary to do the
3863 same for integral types.
3865 Also don't do this adjustment on O64 binaries.
3867 cagney/2001-07-23: gdb/179: Also, GCC, when
3868 outputting LE O32 with sizeof (struct) <
3869 MIPS_SAVED_REGSIZE, generates a left shift as
3870 part of storing the argument in a register a
3871 register (the left shift isn't generated when
3872 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3873 is quite possible that this is GCC contradicting
3874 the LE/O32 ABI, GDB has not been adjusted to
3875 accommodate this. Either someone needs to
3876 demonstrate that the LE/O32 ABI specifies such a
3877 left shift OR this new ABI gets identified as
3878 such and GDB gets tweaked accordingly. */
3880 if (MIPS_SAVED_REGSIZE < 8
3881 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3882 && partial_len < MIPS_SAVED_REGSIZE
3883 && (typecode == TYPE_CODE_STRUCT ||
3884 typecode == TYPE_CODE_UNION))
3885 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3889 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3891 phex (regval, MIPS_SAVED_REGSIZE));
3892 write_register (argreg, regval);
3895 /* Prevent subsequent floating point arguments from
3896 being passed in floating point registers. */
3897 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3903 /* Compute the the offset into the stack at which we
3904 will copy the next parameter.
3906 In older ABIs, the caller reserved space for
3907 registers that contained arguments. This was loosely
3908 refered to as their "home". Consequently, space is
3909 always allocated. */
3911 stack_offset += align_up (partial_len, MIPS_STACK_ARGSIZE);
3915 fprintf_unfiltered (gdb_stdlog, "\n");
3918 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3920 /* Return adjusted stack pointer. */
3925 mips_pop_frame (void)
3928 struct frame_info *frame = get_current_frame ();
3929 CORE_ADDR new_sp = get_frame_base (frame);
3930 mips_extra_func_info_t proc_desc;
3932 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3934 generic_pop_dummy_frame ();
3935 flush_cached_frames ();
3939 proc_desc = get_frame_extra_info (frame)->proc_desc;
3940 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3941 mips_find_saved_regs (frame);
3942 for (regnum = 0; regnum < NUM_REGS; regnum++)
3943 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3944 && deprecated_get_frame_saved_regs (frame)[regnum])
3946 /* Floating point registers must not be sign extended,
3947 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3949 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3950 write_register (regnum,
3951 read_memory_unsigned_integer (deprecated_get_frame_saved_regs (frame)[regnum],
3952 MIPS_SAVED_REGSIZE));
3954 write_register (regnum,
3955 read_memory_integer (deprecated_get_frame_saved_regs (frame)[regnum],
3956 MIPS_SAVED_REGSIZE));
3959 write_register (SP_REGNUM, new_sp);
3960 flush_cached_frames ();
3962 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3964 struct linked_proc_info *pi_ptr, *prev_ptr;
3966 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3968 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3970 if (&pi_ptr->info == proc_desc)
3975 error ("Can't locate dummy extra frame info\n");
3977 if (prev_ptr != NULL)
3978 prev_ptr->next = pi_ptr->next;
3980 linked_proc_desc_table = pi_ptr->next;
3984 write_register (HI_REGNUM,
3985 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3986 MIPS_SAVED_REGSIZE));
3987 write_register (LO_REGNUM,
3988 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3989 MIPS_SAVED_REGSIZE));
3990 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3991 write_register (FCRCS_REGNUM,
3992 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3993 MIPS_SAVED_REGSIZE));
3997 /* Floating point register management.
3999 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4000 64bit operations, these early MIPS cpus treat fp register pairs
4001 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4002 registers and offer a compatibility mode that emulates the MIPS2 fp
4003 model. When operating in MIPS2 fp compat mode, later cpu's split
4004 double precision floats into two 32-bit chunks and store them in
4005 consecutive fp regs. To display 64-bit floats stored in this
4006 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4007 Throw in user-configurable endianness and you have a real mess.
4009 The way this works is:
4010 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4011 double-precision value will be split across two logical registers.
4012 The lower-numbered logical register will hold the low-order bits,
4013 regardless of the processor's endianness.
4014 - If we are on a 64-bit processor, and we are looking for a
4015 single-precision value, it will be in the low ordered bits
4016 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4017 save slot in memory.
4018 - If we are in 64-bit mode, everything is straightforward.
4020 Note that this code only deals with "live" registers at the top of the
4021 stack. We will attempt to deal with saved registers later, when
4022 the raw/cooked register interface is in place. (We need a general
4023 interface that can deal with dynamic saved register sizes -- fp
4024 regs could be 32 bits wide in one frame and 64 on the frame above
4027 static struct type *
4028 mips_float_register_type (void)
4030 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4031 return builtin_type_ieee_single_big;
4033 return builtin_type_ieee_single_little;
4036 static struct type *
4037 mips_double_register_type (void)
4039 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4040 return builtin_type_ieee_double_big;
4042 return builtin_type_ieee_double_little;
4045 /* Copy a 32-bit single-precision value from the current frame
4046 into rare_buffer. */
4049 mips_read_fp_register_single (struct frame_info *frame, int regno,
4052 int raw_size = DEPRECATED_REGISTER_RAW_SIZE (regno);
4053 char *raw_buffer = alloca (raw_size);
4055 if (!frame_register_read (frame, regno, raw_buffer))
4056 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4059 /* We have a 64-bit value for this register. Find the low-order
4063 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4068 memcpy (rare_buffer, raw_buffer + offset, 4);
4072 memcpy (rare_buffer, raw_buffer, 4);
4076 /* Copy a 64-bit double-precision value from the current frame into
4077 rare_buffer. This may include getting half of it from the next
4081 mips_read_fp_register_double (struct frame_info *frame, int regno,
4084 int raw_size = DEPRECATED_REGISTER_RAW_SIZE (regno);
4086 if (raw_size == 8 && !mips2_fp_compat ())
4088 /* We have a 64-bit value for this register, and we should use
4090 if (!frame_register_read (frame, regno, rare_buffer))
4091 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4095 if ((regno - FP0_REGNUM) & 1)
4096 internal_error (__FILE__, __LINE__,
4097 "mips_read_fp_register_double: bad access to "
4098 "odd-numbered FP register");
4100 /* mips_read_fp_register_single will find the correct 32 bits from
4102 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4104 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4105 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4109 mips_read_fp_register_single (frame, regno, rare_buffer);
4110 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4116 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4118 { /* do values for FP (float) regs */
4120 double doub, flt1, flt2; /* doubles extracted from raw hex data */
4121 int inv1, inv2, namelen;
4123 raw_buffer = (char *) alloca (2 * DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM));
4125 fprintf_filtered (file, "%s:", REGISTER_NAME (regnum));
4126 fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)),
4129 if (DEPRECATED_REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4131 /* 4-byte registers: Print hex and floating. Also print even
4132 numbered registers as doubles. */
4133 mips_read_fp_register_single (frame, regnum, raw_buffer);
4134 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4136 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', file);
4138 fprintf_filtered (file, " flt: ");
4140 fprintf_filtered (file, " <invalid float> ");
4142 fprintf_filtered (file, "%-17.9g", flt1);
4144 if (regnum % 2 == 0)
4146 mips_read_fp_register_double (frame, regnum, raw_buffer);
4147 doub = unpack_double (mips_double_register_type (), raw_buffer,
4150 fprintf_filtered (file, " dbl: ");
4152 fprintf_filtered (file, "<invalid double>");
4154 fprintf_filtered (file, "%-24.17g", doub);
4159 /* Eight byte registers: print each one as hex, float and double. */
4160 mips_read_fp_register_single (frame, regnum, raw_buffer);
4161 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4163 mips_read_fp_register_double (frame, regnum, raw_buffer);
4164 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4167 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', file);
4169 fprintf_filtered (file, " flt: ");
4171 fprintf_filtered (file, "<invalid float>");
4173 fprintf_filtered (file, "%-17.9g", flt1);
4175 fprintf_filtered (file, " dbl: ");
4177 fprintf_filtered (file, "<invalid double>");
4179 fprintf_filtered (file, "%-24.17g", doub);
4184 mips_print_register (struct ui_file *file, struct frame_info *frame,
4185 int regnum, int all)
4187 struct gdbarch *gdbarch = get_frame_arch (frame);
4188 char raw_buffer[MAX_REGISTER_SIZE];
4191 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4193 mips_print_fp_register (file, frame, regnum);
4197 /* Get the data in raw format. */
4198 if (!frame_register_read (frame, regnum, raw_buffer))
4200 fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum));
4204 fputs_filtered (REGISTER_NAME (regnum), file);
4206 /* The problem with printing numeric register names (r26, etc.) is that
4207 the user can't use them on input. Probably the best solution is to
4208 fix it so that either the numeric or the funky (a2, etc.) names
4209 are accepted on input. */
4210 if (regnum < MIPS_NUMREGS)
4211 fprintf_filtered (file, "(r%d): ", regnum);
4213 fprintf_filtered (file, ": ");
4215 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4216 offset = DEPRECATED_REGISTER_RAW_SIZE (regnum) - DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum);
4220 print_scalar_formatted (raw_buffer + offset, gdbarch_register_type (gdbarch, regnum),
4224 /* Replacement for generic do_registers_info.
4225 Print regs in pretty columns. */
4228 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4231 fprintf_filtered (file, " ");
4232 mips_print_fp_register (file, frame, regnum);
4233 fprintf_filtered (file, "\n");
4238 /* Print a row's worth of GP (int) registers, with name labels above */
4241 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4244 struct gdbarch *gdbarch = get_frame_arch (frame);
4245 /* do values for GP (int) regs */
4246 char raw_buffer[MAX_REGISTER_SIZE];
4247 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4251 /* For GP registers, we print a separate row of names above the vals */
4252 fprintf_filtered (file, " ");
4253 for (col = 0, regnum = start_regnum;
4254 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS;
4257 if (*REGISTER_NAME (regnum) == '\0')
4258 continue; /* unused register */
4259 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4260 break; /* end the row: reached FP register */
4261 fprintf_filtered (file, MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4262 REGISTER_NAME (regnum));
4265 /* print the R0 to R31 names */
4266 if ((start_regnum % NUM_REGS) < MIPS_NUMREGS)
4267 fprintf_filtered (file, "\n R%-4d", start_regnum % NUM_REGS);
4269 fprintf_filtered (file, "\n ");
4271 /* now print the values in hex, 4 or 8 to the row */
4272 for (col = 0, regnum = start_regnum;
4273 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS;
4276 if (*REGISTER_NAME (regnum) == '\0')
4277 continue; /* unused register */
4278 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4279 break; /* end row: reached FP register */
4280 /* OK: get the data in raw format. */
4281 if (!frame_register_read (frame, regnum, raw_buffer))
4282 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4283 /* pad small registers */
4284 for (byte = 0; byte < (MIPS_REGSIZE - DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4285 printf_filtered (" ");
4286 /* Now print the register value in hex, endian order. */
4287 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4288 for (byte = DEPRECATED_REGISTER_RAW_SIZE (regnum) - DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum);
4289 byte < DEPRECATED_REGISTER_RAW_SIZE (regnum);
4291 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4293 for (byte = DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum) - 1;
4296 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4297 fprintf_filtered (file, " ");
4300 if (col > 0) /* ie. if we actually printed anything... */
4301 fprintf_filtered (file, "\n");
4306 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4309 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4310 struct frame_info *frame, int regnum, int all)
4312 if (regnum != -1) /* do one specified register */
4314 gdb_assert (regnum >= NUM_REGS);
4315 if (*(REGISTER_NAME (regnum)) == '\0')
4316 error ("Not a valid register for the current processor type");
4318 mips_print_register (file, frame, regnum, 0);
4319 fprintf_filtered (file, "\n");
4322 /* do all (or most) registers */
4325 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
4327 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4329 if (all) /* true for "INFO ALL-REGISTERS" command */
4330 regnum = print_fp_register_row (file, frame, regnum);
4332 regnum += MIPS_NUMREGS; /* skip floating point regs */
4335 regnum = print_gp_register_row (file, frame, regnum);
4340 /* Is this a branch with a delay slot? */
4342 static int is_delayed (unsigned long);
4345 is_delayed (unsigned long insn)
4348 for (i = 0; i < NUMOPCODES; ++i)
4349 if (mips_opcodes[i].pinfo != INSN_MACRO
4350 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4352 return (i < NUMOPCODES
4353 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4354 | INSN_COND_BRANCH_DELAY
4355 | INSN_COND_BRANCH_LIKELY)));
4359 mips_step_skips_delay (CORE_ADDR pc)
4361 char buf[MIPS_INSTLEN];
4363 /* There is no branch delay slot on MIPS16. */
4364 if (pc_is_mips16 (pc))
4367 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4368 /* If error reading memory, guess that it is not a delayed branch. */
4370 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4374 /* Skip the PC past function prologue instructions (32-bit version).
4375 This is a helper function for mips_skip_prologue. */
4378 mips32_skip_prologue (CORE_ADDR pc)
4382 int seen_sp_adjust = 0;
4383 int load_immediate_bytes = 0;
4385 /* Skip the typical prologue instructions. These are the stack adjustment
4386 instruction and the instructions that save registers on the stack
4387 or in the gcc frame. */
4388 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4390 unsigned long high_word;
4392 inst = mips_fetch_instruction (pc);
4393 high_word = (inst >> 16) & 0xffff;
4395 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4396 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4398 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4399 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4401 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4402 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4403 && (inst & 0x001F0000)) /* reg != $zero */
4406 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4408 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4410 continue; /* reg != $zero */
4412 /* move $s8,$sp. With different versions of gas this will be either
4413 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4414 Accept any one of these. */
4415 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4418 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4420 else if (high_word == 0x3c1c) /* lui $gp,n */
4422 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4424 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4425 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4427 /* The following instructions load $at or $t0 with an immediate
4428 value in preparation for a stack adjustment via
4429 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4430 a local variable, so we accept them only before a stack adjustment
4431 instruction was seen. */
4432 else if (!seen_sp_adjust)
4434 if (high_word == 0x3c01 || /* lui $at,n */
4435 high_word == 0x3c08) /* lui $t0,n */
4437 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4440 else if (high_word == 0x3421 || /* ori $at,$at,n */
4441 high_word == 0x3508 || /* ori $t0,$t0,n */
4442 high_word == 0x3401 || /* ori $at,$zero,n */
4443 high_word == 0x3408) /* ori $t0,$zero,n */
4445 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4455 /* In a frameless function, we might have incorrectly
4456 skipped some load immediate instructions. Undo the skipping
4457 if the load immediate was not followed by a stack adjustment. */
4458 if (load_immediate_bytes && !seen_sp_adjust)
4459 pc -= load_immediate_bytes;
4463 /* Skip the PC past function prologue instructions (16-bit version).
4464 This is a helper function for mips_skip_prologue. */
4467 mips16_skip_prologue (CORE_ADDR pc)
4470 int extend_bytes = 0;
4471 int prev_extend_bytes;
4473 /* Table of instructions likely to be found in a function prologue. */
4476 unsigned short inst;
4477 unsigned short mask;
4484 , /* addiu $sp,offset */
4488 , /* daddiu $sp,offset */
4492 , /* sw reg,n($sp) */
4496 , /* sd reg,n($sp) */
4500 , /* sw $ra,n($sp) */
4504 , /* sd $ra,n($sp) */
4512 , /* sw $a0-$a3,n($s1) */
4516 , /* move reg,$a0-$a3 */
4520 , /* entry pseudo-op */
4524 , /* addiu $s1,$sp,n */
4527 } /* end of table marker */
4530 /* Skip the typical prologue instructions. These are the stack adjustment
4531 instruction and the instructions that save registers on the stack
4532 or in the gcc frame. */
4533 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4535 unsigned short inst;
4538 inst = mips_fetch_instruction (pc);
4540 /* Normally we ignore an extend instruction. However, if it is
4541 not followed by a valid prologue instruction, we must adjust
4542 the pc back over the extend so that it won't be considered
4543 part of the prologue. */
4544 if ((inst & 0xf800) == 0xf000) /* extend */
4546 extend_bytes = MIPS16_INSTLEN;
4549 prev_extend_bytes = extend_bytes;
4552 /* Check for other valid prologue instructions besides extend. */
4553 for (i = 0; table[i].mask != 0; i++)
4554 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4556 if (table[i].mask != 0) /* it was in table? */
4557 continue; /* ignore it */
4561 /* Return the current pc, adjusted backwards by 2 if
4562 the previous instruction was an extend. */
4563 return pc - prev_extend_bytes;
4569 /* To skip prologues, I use this predicate. Returns either PC itself
4570 if the code at PC does not look like a function prologue; otherwise
4571 returns an address that (if we're lucky) follows the prologue. If
4572 LENIENT, then we must skip everything which is involved in setting
4573 up the frame (it's OK to skip more, just so long as we don't skip
4574 anything which might clobber the registers which are being saved.
4575 We must skip more in the case where part of the prologue is in the
4576 delay slot of a non-prologue instruction). */
4579 mips_skip_prologue (CORE_ADDR pc)
4581 /* See if we can determine the end of the prologue via the symbol table.
4582 If so, then return either PC, or the PC after the prologue, whichever
4585 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4587 if (post_prologue_pc != 0)
4588 return max (pc, post_prologue_pc);
4590 /* Can't determine prologue from the symbol table, need to examine
4593 if (pc_is_mips16 (pc))
4594 return mips16_skip_prologue (pc);
4596 return mips32_skip_prologue (pc);
4599 /* Determine how a return value is stored within the MIPS register
4600 file, given the return type `valtype'. */
4602 struct return_value_word
4611 return_value_location (struct type *valtype,
4612 struct return_value_word *hi,
4613 struct return_value_word *lo)
4615 int len = TYPE_LENGTH (valtype);
4617 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4618 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4619 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4621 if (!FP_REGISTER_DOUBLE && len == 8)
4623 /* We need to break a 64bit float in two 32 bit halves and
4624 spread them across a floating-point register pair. */
4625 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4626 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4627 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4628 && DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4630 hi->reg_offset = lo->reg_offset;
4631 lo->reg = FP0_REGNUM + 0;
4632 hi->reg = FP0_REGNUM + 1;
4638 /* The floating point value fits in a single floating-point
4640 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4641 && DEPRECATED_REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4644 lo->reg = FP0_REGNUM;
4655 /* Locate a result possibly spread across two registers. */
4657 lo->reg = regnum + 0;
4658 hi->reg = regnum + 1;
4659 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4660 && len < MIPS_SAVED_REGSIZE)
4662 /* "un-left-justify" the value in the low register */
4663 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4668 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4669 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4670 && len < MIPS_SAVED_REGSIZE * 2
4671 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4672 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4674 /* "un-left-justify" the value spread across two registers. */
4675 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4676 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4678 hi->len = len - lo->len;
4682 /* Only perform a partial copy of the second register. */
4685 if (len > MIPS_SAVED_REGSIZE)
4687 lo->len = MIPS_SAVED_REGSIZE;
4688 hi->len = len - MIPS_SAVED_REGSIZE;
4696 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4697 && DEPRECATED_REGISTER_RAW_SIZE (regnum) == 8
4698 && MIPS_SAVED_REGSIZE == 4)
4700 /* Account for the fact that only the least-signficant part
4701 of the register is being used */
4702 lo->reg_offset += 4;
4703 hi->reg_offset += 4;
4706 hi->buf_offset = lo->len;
4710 /* Given a return value in `regbuf' with a type `valtype', extract and
4711 copy its value into `valbuf'. */
4714 mips_eabi_extract_return_value (struct type *valtype,
4718 struct return_value_word lo;
4719 struct return_value_word hi;
4720 return_value_location (valtype, &hi, &lo);
4722 memcpy (valbuf + lo.buf_offset,
4723 regbuf + DEPRECATED_REGISTER_BYTE (lo.reg) + lo.reg_offset,
4727 memcpy (valbuf + hi.buf_offset,
4728 regbuf + DEPRECATED_REGISTER_BYTE (hi.reg) + hi.reg_offset,
4733 mips_o64_extract_return_value (struct type *valtype,
4737 struct return_value_word lo;
4738 struct return_value_word hi;
4739 return_value_location (valtype, &hi, &lo);
4741 memcpy (valbuf + lo.buf_offset,
4742 regbuf + DEPRECATED_REGISTER_BYTE (lo.reg) + lo.reg_offset,
4746 memcpy (valbuf + hi.buf_offset,
4747 regbuf + DEPRECATED_REGISTER_BYTE (hi.reg) + hi.reg_offset,
4751 /* Given a return value in `valbuf' with a type `valtype', write it's
4752 value into the appropriate register. */
4755 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4757 char raw_buffer[MAX_REGISTER_SIZE];
4758 struct return_value_word lo;
4759 struct return_value_word hi;
4760 return_value_location (valtype, &hi, &lo);
4762 memset (raw_buffer, 0, sizeof (raw_buffer));
4763 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4764 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg), raw_buffer,
4765 DEPRECATED_REGISTER_RAW_SIZE (lo.reg));
4769 memset (raw_buffer, 0, sizeof (raw_buffer));
4770 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4771 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg), raw_buffer,
4772 DEPRECATED_REGISTER_RAW_SIZE (hi.reg));
4777 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4779 char raw_buffer[MAX_REGISTER_SIZE];
4780 struct return_value_word lo;
4781 struct return_value_word hi;
4782 return_value_location (valtype, &hi, &lo);
4784 memset (raw_buffer, 0, sizeof (raw_buffer));
4785 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4786 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg), raw_buffer,
4787 DEPRECATED_REGISTER_RAW_SIZE (lo.reg));
4791 memset (raw_buffer, 0, sizeof (raw_buffer));
4792 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4793 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg), raw_buffer,
4794 DEPRECATED_REGISTER_RAW_SIZE (hi.reg));
4798 /* O32 ABI stuff. */
4801 mips_o32_xfer_return_value (struct type *type,
4802 struct regcache *regcache,
4803 bfd_byte *in, const bfd_byte *out)
4805 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4806 if (TYPE_CODE (type) == TYPE_CODE_FLT
4807 && TYPE_LENGTH (type) == 4
4808 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4810 /* A single-precision floating-point value. It fits in the
4811 least significant part of FP0. */
4813 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4814 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM, TYPE_LENGTH (type),
4815 TARGET_BYTE_ORDER, in, out, 0);
4817 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4818 && TYPE_LENGTH (type) == 8
4819 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4821 /* A double-precision floating-point value. The most
4822 significant part goes in FP1, and the least significant in
4825 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
4826 switch (TARGET_BYTE_ORDER)
4828 case BFD_ENDIAN_LITTLE:
4829 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 0, 4,
4830 TARGET_BYTE_ORDER, in, out, 0);
4831 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 1, 4,
4832 TARGET_BYTE_ORDER, in, out, 4);
4834 case BFD_ENDIAN_BIG:
4835 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 1, 4,
4836 TARGET_BYTE_ORDER, in, out, 0);
4837 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 0, 4,
4838 TARGET_BYTE_ORDER, in, out, 4);
4841 internal_error (__FILE__, __LINE__, "bad switch");
4845 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4846 && TYPE_NFIELDS (type) <= 2
4847 && TYPE_NFIELDS (type) >= 1
4848 && ((TYPE_NFIELDS (type) == 1
4849 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4851 || (TYPE_NFIELDS (type) == 2
4852 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4854 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4856 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4858 /* A struct that contains one or two floats. Each value is part
4859 in the least significant part of their floating point
4861 bfd_byte reg[MAX_REGISTER_SIZE];
4864 for (field = 0, regnum = FP0_REGNUM;
4865 field < TYPE_NFIELDS (type);
4866 field++, regnum += 2)
4868 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4871 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4872 mips_xfer_register (regcache, NUM_REGS + regnum,
4873 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4874 TARGET_BYTE_ORDER, in, out, offset);
4879 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4880 || TYPE_CODE (type) == TYPE_CODE_UNION)
4882 /* A structure or union. Extract the left justified value,
4883 regardless of the byte order. I.e. DO NOT USE
4887 for (offset = 0, regnum = V0_REGNUM;
4888 offset < TYPE_LENGTH (type);
4889 offset += DEPRECATED_REGISTER_RAW_SIZE (regnum), regnum++)
4891 int xfer = DEPRECATED_REGISTER_RAW_SIZE (regnum);
4892 if (offset + xfer > TYPE_LENGTH (type))
4893 xfer = TYPE_LENGTH (type) - offset;
4895 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4896 offset, xfer, regnum);
4897 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4898 BFD_ENDIAN_UNKNOWN, in, out, offset);
4904 /* A scalar extract each part but least-significant-byte
4905 justified. o32 thinks registers are 4 byte, regardless of
4906 the ISA. mips_stack_argsize controls this. */
4909 for (offset = 0, regnum = V0_REGNUM;
4910 offset < TYPE_LENGTH (type);
4911 offset += mips_stack_argsize (), regnum++)
4913 int xfer = mips_stack_argsize ();
4915 if (offset + xfer > TYPE_LENGTH (type))
4916 xfer = TYPE_LENGTH (type) - offset;
4918 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4919 offset, xfer, regnum);
4920 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4921 TARGET_BYTE_ORDER, in, out, offset);
4927 mips_o32_extract_return_value (struct type *type,
4928 struct regcache *regcache,
4931 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4935 mips_o32_store_return_value (struct type *type, char *valbuf)
4937 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4940 /* N32/N44 ABI stuff. */
4943 mips_n32n64_xfer_return_value (struct type *type,
4944 struct regcache *regcache,
4945 bfd_byte *in, const bfd_byte *out)
4947 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4948 if (TYPE_CODE (type) == TYPE_CODE_FLT
4949 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4951 /* A floating-point value belongs in the least significant part
4954 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4955 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM, TYPE_LENGTH (type),
4956 TARGET_BYTE_ORDER, in, out, 0);
4958 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4959 && TYPE_NFIELDS (type) <= 2
4960 && TYPE_NFIELDS (type) >= 1
4961 && ((TYPE_NFIELDS (type) == 1
4962 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4964 || (TYPE_NFIELDS (type) == 2
4965 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4967 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4969 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4971 /* A struct that contains one or two floats. Each value is part
4972 in the least significant part of their floating point
4974 bfd_byte reg[MAX_REGISTER_SIZE];
4977 for (field = 0, regnum = FP0_REGNUM;
4978 field < TYPE_NFIELDS (type);
4979 field++, regnum += 2)
4981 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4984 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4985 mips_xfer_register (regcache, NUM_REGS + regnum,
4986 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4987 TARGET_BYTE_ORDER, in, out, offset);
4990 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4991 || TYPE_CODE (type) == TYPE_CODE_UNION)
4993 /* A structure or union. Extract the left justified value,
4994 regardless of the byte order. I.e. DO NOT USE
4998 for (offset = 0, regnum = V0_REGNUM;
4999 offset < TYPE_LENGTH (type);
5000 offset += DEPRECATED_REGISTER_RAW_SIZE (regnum), regnum++)
5002 int xfer = DEPRECATED_REGISTER_RAW_SIZE (regnum);
5003 if (offset + xfer > TYPE_LENGTH (type))
5004 xfer = TYPE_LENGTH (type) - offset;
5006 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
5007 offset, xfer, regnum);
5008 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
5009 BFD_ENDIAN_UNKNOWN, in, out, offset);
5014 /* A scalar extract each part but least-significant-byte
5018 for (offset = 0, regnum = V0_REGNUM;
5019 offset < TYPE_LENGTH (type);
5020 offset += DEPRECATED_REGISTER_RAW_SIZE (regnum), regnum++)
5022 int xfer = DEPRECATED_REGISTER_RAW_SIZE (regnum);
5024 if (offset + xfer > TYPE_LENGTH (type))
5025 xfer = TYPE_LENGTH (type) - offset;
5027 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
5028 offset, xfer, regnum);
5029 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
5030 TARGET_BYTE_ORDER, in, out, offset);
5036 mips_n32n64_extract_return_value (struct type *type,
5037 struct regcache *regcache,
5040 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
5044 mips_n32n64_store_return_value (struct type *type, char *valbuf)
5046 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
5050 mips_extract_struct_value_address (struct regcache *regcache)
5052 /* FIXME: This will only work at random. The caller passes the
5053 struct_return address in V0, but it is not preserved. It may
5054 still be there, or this may be a random value. */
5057 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
5061 /* Exported procedure: Is PC in the signal trampoline code */
5064 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
5066 if (sigtramp_address == 0)
5068 return (pc >= sigtramp_address && pc < sigtramp_end);
5071 /* Root of all "set mips "/"show mips " commands. This will eventually be
5072 used for all MIPS-specific commands. */
5075 show_mips_command (char *args, int from_tty)
5077 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5081 set_mips_command (char *args, int from_tty)
5083 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
5084 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5087 /* Commands to show/set the MIPS FPU type. */
5090 show_mipsfpu_command (char *args, int from_tty)
5093 switch (MIPS_FPU_TYPE)
5095 case MIPS_FPU_SINGLE:
5096 fpu = "single-precision";
5098 case MIPS_FPU_DOUBLE:
5099 fpu = "double-precision";
5102 fpu = "absent (none)";
5105 internal_error (__FILE__, __LINE__, "bad switch");
5107 if (mips_fpu_type_auto)
5108 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5111 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5117 set_mipsfpu_command (char *args, int from_tty)
5119 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5120 show_mipsfpu_command (args, from_tty);
5124 set_mipsfpu_single_command (char *args, int from_tty)
5126 mips_fpu_type = MIPS_FPU_SINGLE;
5127 mips_fpu_type_auto = 0;
5128 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5132 set_mipsfpu_double_command (char *args, int from_tty)
5134 mips_fpu_type = MIPS_FPU_DOUBLE;
5135 mips_fpu_type_auto = 0;
5136 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5140 set_mipsfpu_none_command (char *args, int from_tty)
5142 mips_fpu_type = MIPS_FPU_NONE;
5143 mips_fpu_type_auto = 0;
5144 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5148 set_mipsfpu_auto_command (char *args, int from_tty)
5150 mips_fpu_type_auto = 1;
5153 /* Command to set the processor type. */
5156 mips_set_processor_type_command (char *args, int from_tty)
5160 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5162 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5163 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5164 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5166 /* Restore the value. */
5167 tmp_mips_processor_type = xstrdup (mips_processor_type);
5172 if (!mips_set_processor_type (tmp_mips_processor_type))
5174 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5175 /* Restore its value. */
5176 tmp_mips_processor_type = xstrdup (mips_processor_type);
5181 mips_show_processor_type_command (char *args, int from_tty)
5185 /* Modify the actual processor type. */
5188 mips_set_processor_type (char *str)
5195 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5197 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5199 mips_processor_type = str;
5200 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5202 /* FIXME tweak fpu flag too */
5209 /* Attempt to identify the particular processor model by reading the
5213 mips_read_processor_type (void)
5217 prid = read_register (PRID_REGNUM);
5219 if ((prid & ~0xf) == 0x700)
5220 return savestring ("r3041", strlen ("r3041"));
5225 /* Just like reinit_frame_cache, but with the right arguments to be
5226 callable as an sfunc. */
5229 reinit_frame_cache_sfunc (char *args, int from_tty,
5230 struct cmd_list_element *c)
5232 reinit_frame_cache ();
5236 gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
5238 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
5239 mips_extra_func_info_t proc_desc;
5241 /* Search for the function containing this address. Set the low bit
5242 of the address when searching, in case we were given an even address
5243 that is the start of a 16-bit function. If we didn't do this,
5244 the search would fail because the symbol table says the function
5245 starts at an odd address, i.e. 1 byte past the given address. */
5246 memaddr = ADDR_BITS_REMOVE (memaddr);
5247 proc_desc = non_heuristic_proc_desc (make_mips16_addr (memaddr), NULL);
5249 /* Make an attempt to determine if this is a 16-bit function. If
5250 the procedure descriptor exists and the address therein is odd,
5251 it's definitely a 16-bit function. Otherwise, we have to just
5252 guess that if the address passed in is odd, it's 16-bits. */
5253 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5254 disassembler needs to be able to locally determine the ISA, and
5255 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5259 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
5260 info->mach = bfd_mach_mips16;
5264 if (pc_is_mips16 (memaddr))
5265 info->mach = bfd_mach_mips16;
5268 /* Round down the instruction address to the appropriate boundary. */
5269 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5271 /* Set the disassembler options. */
5272 if (tdep->mips_abi == MIPS_ABI_N32
5273 || tdep->mips_abi == MIPS_ABI_N64)
5275 /* Set up the disassembler info, so that we get the right
5276 register names from libopcodes. */
5277 if (tdep->mips_abi == MIPS_ABI_N32)
5278 info->disassembler_options = "gpr-names=n32";
5280 info->disassembler_options = "gpr-names=64";
5281 info->flavour = bfd_target_elf_flavour;
5284 /* This string is not recognized explicitly by the disassembler,
5285 but it tells the disassembler to not try to guess the ABI from
5286 the bfd elf headers, such that, if the user overrides the ABI
5287 of a program linked as NewABI, the disassembly will follow the
5288 register naming conventions specified by the user. */
5289 info->disassembler_options = "gpr-names=32";
5291 /* Call the appropriate disassembler based on the target endian-ness. */
5292 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5293 return print_insn_big_mips (memaddr, info);
5295 return print_insn_little_mips (memaddr, info);
5298 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5299 counter value to determine whether a 16- or 32-bit breakpoint should be
5300 used. It returns a pointer to a string of bytes that encode a breakpoint
5301 instruction, stores the length of the string to *lenptr, and adjusts pc
5302 (if necessary) to point to the actual memory location where the
5303 breakpoint should be inserted. */
5305 static const unsigned char *
5306 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5308 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5310 if (pc_is_mips16 (*pcptr))
5312 static unsigned char mips16_big_breakpoint[] = {0xe8, 0xa5};
5313 *pcptr = unmake_mips16_addr (*pcptr);
5314 *lenptr = sizeof (mips16_big_breakpoint);
5315 return mips16_big_breakpoint;
5319 /* The IDT board uses an unusual breakpoint value, and
5320 sometimes gets confused when it sees the usual MIPS
5321 breakpoint instruction. */
5322 static unsigned char big_breakpoint[] = {0, 0x5, 0, 0xd};
5323 static unsigned char pmon_big_breakpoint[] = {0, 0, 0, 0xd};
5324 static unsigned char idt_big_breakpoint[] = {0, 0, 0x0a, 0xd};
5326 *lenptr = sizeof (big_breakpoint);
5328 if (strcmp (target_shortname, "mips") == 0)
5329 return idt_big_breakpoint;
5330 else if (strcmp (target_shortname, "ddb") == 0
5331 || strcmp (target_shortname, "pmon") == 0
5332 || strcmp (target_shortname, "lsi") == 0)
5333 return pmon_big_breakpoint;
5335 return big_breakpoint;
5340 if (pc_is_mips16 (*pcptr))
5342 static unsigned char mips16_little_breakpoint[] = {0xa5, 0xe8};
5343 *pcptr = unmake_mips16_addr (*pcptr);
5344 *lenptr = sizeof (mips16_little_breakpoint);
5345 return mips16_little_breakpoint;
5349 static unsigned char little_breakpoint[] = {0xd, 0, 0x5, 0};
5350 static unsigned char pmon_little_breakpoint[] = {0xd, 0, 0, 0};
5351 static unsigned char idt_little_breakpoint[] = {0xd, 0x0a, 0, 0};
5353 *lenptr = sizeof (little_breakpoint);
5355 if (strcmp (target_shortname, "mips") == 0)
5356 return idt_little_breakpoint;
5357 else if (strcmp (target_shortname, "ddb") == 0
5358 || strcmp (target_shortname, "pmon") == 0
5359 || strcmp (target_shortname, "lsi") == 0)
5360 return pmon_little_breakpoint;
5362 return little_breakpoint;
5367 /* If PC is in a mips16 call or return stub, return the address of the target
5368 PC, which is either the callee or the caller. There are several
5369 cases which must be handled:
5371 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5372 target PC is in $31 ($ra).
5373 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5374 and the target PC is in $2.
5375 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5376 before the jal instruction, this is effectively a call stub
5377 and the the target PC is in $2. Otherwise this is effectively
5378 a return stub and the target PC is in $18.
5380 See the source code for the stubs in gcc/config/mips/mips16.S for
5383 This function implements the SKIP_TRAMPOLINE_CODE macro.
5387 mips_skip_stub (CORE_ADDR pc)
5390 CORE_ADDR start_addr;
5392 /* Find the starting address and name of the function containing the PC. */
5393 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5396 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5397 target PC is in $31 ($ra). */
5398 if (strcmp (name, "__mips16_ret_sf") == 0
5399 || strcmp (name, "__mips16_ret_df") == 0)
5400 return read_signed_register (RA_REGNUM);
5402 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5404 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5405 and the target PC is in $2. */
5406 if (name[19] >= '0' && name[19] <= '9')
5407 return read_signed_register (2);
5409 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5410 before the jal instruction, this is effectively a call stub
5411 and the the target PC is in $2. Otherwise this is effectively
5412 a return stub and the target PC is in $18. */
5413 else if (name[19] == 's' || name[19] == 'd')
5415 if (pc == start_addr)
5417 /* Check if the target of the stub is a compiler-generated
5418 stub. Such a stub for a function bar might have a name
5419 like __fn_stub_bar, and might look like this:
5424 la $1,bar (becomes a lui/addiu pair)
5426 So scan down to the lui/addi and extract the target
5427 address from those two instructions. */
5429 CORE_ADDR target_pc = read_signed_register (2);
5433 /* See if the name of the target function is __fn_stub_*. */
5434 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5436 if (strncmp (name, "__fn_stub_", 10) != 0
5437 && strcmp (name, "etext") != 0
5438 && strcmp (name, "_etext") != 0)
5441 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5442 The limit on the search is arbitrarily set to 20
5443 instructions. FIXME. */
5444 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5446 inst = mips_fetch_instruction (target_pc);
5447 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5448 pc = (inst << 16) & 0xffff0000; /* high word */
5449 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5450 return pc | (inst & 0xffff); /* low word */
5453 /* Couldn't find the lui/addui pair, so return stub address. */
5457 /* This is the 'return' part of a call stub. The return
5458 address is in $r18. */
5459 return read_signed_register (18);
5462 return 0; /* not a stub */
5466 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5467 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5470 mips_in_call_stub (CORE_ADDR pc, char *name)
5472 CORE_ADDR start_addr;
5474 /* Find the starting address of the function containing the PC. If the
5475 caller didn't give us a name, look it up at the same time. */
5476 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5479 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5481 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5482 if (name[19] >= '0' && name[19] <= '9')
5484 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5485 before the jal instruction, this is effectively a call stub. */
5486 else if (name[19] == 's' || name[19] == 'd')
5487 return pc == start_addr;
5490 return 0; /* not a stub */
5494 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5495 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5498 mips_in_return_stub (CORE_ADDR pc, char *name)
5500 CORE_ADDR start_addr;
5502 /* Find the starting address of the function containing the PC. */
5503 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5506 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5507 if (strcmp (name, "__mips16_ret_sf") == 0
5508 || strcmp (name, "__mips16_ret_df") == 0)
5511 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5512 i.e. after the jal instruction, this is effectively a return stub. */
5513 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5514 && (name[19] == 's' || name[19] == 'd')
5515 && pc != start_addr)
5518 return 0; /* not a stub */
5522 /* Return non-zero if the PC is in a library helper function that should
5523 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5526 mips_ignore_helper (CORE_ADDR pc)
5530 /* Find the starting address and name of the function containing the PC. */
5531 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5534 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5535 that we want to ignore. */
5536 return (strcmp (name, "__mips16_ret_sf") == 0
5537 || strcmp (name, "__mips16_ret_df") == 0);
5541 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5542 the register stored on the stack (32) is different to its real raw
5543 size (64). The below ensures that registers are fetched from the
5544 stack using their ABI size and then stored into the RAW_BUFFER
5545 using their raw size.
5547 The alternative to adding this function would be to add an ABI
5548 macro - REGISTER_STACK_SIZE(). */
5551 mips_get_saved_register (char *raw_buffer,
5554 struct frame_info *frame,
5556 enum lval_type *lvalp)
5559 enum lval_type lvalx;
5563 /* Always a pseudo. */
5564 gdb_assert (regnum >= NUM_REGS);
5566 /* Make certain that all needed parameters are present. */
5571 if (optimizedp == NULL)
5572 optimizedp = &optimizedx;
5574 if ((regnum % NUM_REGS) == SP_REGNUM)
5575 /* The SP_REGNUM is special, its value is stored in saved_regs.
5576 In fact, it is so special that it can even only be fetched
5577 using a raw register number! Once this code as been converted
5578 to frame-unwind the problem goes away. */
5579 frame_register_unwind (deprecated_get_next_frame_hack (frame),
5580 regnum % NUM_REGS, optimizedp, lvalp, addrp,
5581 &realnumx, raw_buffer);
5583 /* Get it from the next frame. */
5584 frame_register_unwind (deprecated_get_next_frame_hack (frame),
5585 regnum, optimizedp, lvalp, addrp,
5586 &realnumx, raw_buffer);
5589 /* Immediately after a function call, return the saved pc.
5590 Can't always go through the frames for this because on some machines
5591 the new frame is not set up until the new function executes
5592 some instructions. */
5595 mips_saved_pc_after_call (struct frame_info *frame)
5597 return read_signed_register (RA_REGNUM);
5601 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5602 [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5605 mips_stab_reg_to_regnum (int num)
5608 if (num >= 0 && num < 32)
5610 else if (num >= 38 && num < 70)
5611 regnum = num + FP0_REGNUM - 38;
5617 /* This will hopefully (eventually) provoke a warning. Should
5618 we be calling complaint() here? */
5619 return NUM_REGS + NUM_PSEUDO_REGS;
5620 return NUM_REGS + regnum;
5624 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5625 NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5628 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5631 if (num >= 0 && num < 32)
5633 else if (num >= 32 && num < 64)
5634 regnum = num + FP0_REGNUM - 32;
5640 /* This will hopefully (eventually) provoke a warning. Should we
5641 be calling complaint() here? */
5642 return NUM_REGS + NUM_PSEUDO_REGS;
5643 return NUM_REGS + regnum;
5647 mips_register_sim_regno (int regnum)
5649 /* Only makes sense to supply raw registers. */
5650 gdb_assert (regnum >= 0 && regnum < NUM_REGS);
5651 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5652 decide if it is valid. Should instead define a standard sim/gdb
5653 register numbering scheme. */
5654 if (REGISTER_NAME (NUM_REGS + regnum) != NULL
5655 && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0')
5658 return LEGACY_SIM_REGNO_IGNORE;
5662 /* Convert an integer into an address. By first converting the value
5663 into a pointer and then extracting it signed, the address is
5664 guarenteed to be correctly sign extended. */
5667 mips_integer_to_address (struct type *type, void *buf)
5669 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5670 LONGEST val = unpack_long (type, buf);
5671 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5672 return extract_signed_integer (tmp,
5673 TYPE_LENGTH (builtin_type_void_data_ptr));
5677 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5679 enum mips_abi *abip = (enum mips_abi *) obj;
5680 const char *name = bfd_get_section_name (abfd, sect);
5682 if (*abip != MIPS_ABI_UNKNOWN)
5685 if (strncmp (name, ".mdebug.", 8) != 0)
5688 if (strcmp (name, ".mdebug.abi32") == 0)
5689 *abip = MIPS_ABI_O32;
5690 else if (strcmp (name, ".mdebug.abiN32") == 0)
5691 *abip = MIPS_ABI_N32;
5692 else if (strcmp (name, ".mdebug.abi64") == 0)
5693 *abip = MIPS_ABI_N64;
5694 else if (strcmp (name, ".mdebug.abiO64") == 0)
5695 *abip = MIPS_ABI_O64;
5696 else if (strcmp (name, ".mdebug.eabi32") == 0)
5697 *abip = MIPS_ABI_EABI32;
5698 else if (strcmp (name, ".mdebug.eabi64") == 0)
5699 *abip = MIPS_ABI_EABI64;
5701 warning ("unsupported ABI %s.", name + 8);
5704 static enum mips_abi
5705 global_mips_abi (void)
5709 for (i = 0; mips_abi_strings[i] != NULL; i++)
5710 if (mips_abi_strings[i] == mips_abi_string)
5711 return (enum mips_abi) i;
5713 internal_error (__FILE__, __LINE__,
5714 "unknown ABI string");
5717 static struct gdbarch *
5718 mips_gdbarch_init (struct gdbarch_info info,
5719 struct gdbarch_list *arches)
5721 struct gdbarch *gdbarch;
5722 struct gdbarch_tdep *tdep;
5724 enum mips_abi mips_abi, found_abi, wanted_abi;
5731 /* First of all, extract the elf_flags, if available. */
5732 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5733 elf_flags = elf_elfheader (info.abfd)->e_flags;
5736 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5737 switch ((elf_flags & EF_MIPS_ABI))
5739 case E_MIPS_ABI_O32:
5740 mips_abi = MIPS_ABI_O32;
5742 case E_MIPS_ABI_O64:
5743 mips_abi = MIPS_ABI_O64;
5745 case E_MIPS_ABI_EABI32:
5746 mips_abi = MIPS_ABI_EABI32;
5748 case E_MIPS_ABI_EABI64:
5749 mips_abi = MIPS_ABI_EABI64;
5752 if ((elf_flags & EF_MIPS_ABI2))
5753 mips_abi = MIPS_ABI_N32;
5755 mips_abi = MIPS_ABI_UNKNOWN;
5759 /* GCC creates a pseudo-section whose name describes the ABI. */
5760 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5761 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5763 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5764 Use the ABI from the last architecture if there is one. */
5765 if (info.abfd == NULL && arches != NULL)
5766 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5768 /* Try the architecture for any hint of the correct ABI. */
5769 if (mips_abi == MIPS_ABI_UNKNOWN
5770 && info.bfd_arch_info != NULL
5771 && info.bfd_arch_info->arch == bfd_arch_mips)
5773 switch (info.bfd_arch_info->mach)
5775 case bfd_mach_mips3900:
5776 mips_abi = MIPS_ABI_EABI32;
5778 case bfd_mach_mips4100:
5779 case bfd_mach_mips5000:
5780 mips_abi = MIPS_ABI_EABI64;
5782 case bfd_mach_mips8000:
5783 case bfd_mach_mips10000:
5784 /* On Irix, ELF64 executables use the N64 ABI. The
5785 pseudo-sections which describe the ABI aren't present
5786 on IRIX. (Even for executables created by gcc.) */
5787 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5788 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5789 mips_abi = MIPS_ABI_N64;
5791 mips_abi = MIPS_ABI_N32;
5796 if (mips_abi == MIPS_ABI_UNKNOWN)
5797 mips_abi = MIPS_ABI_O32;
5799 /* Now that we have found what the ABI for this binary would be,
5800 check whether the user is overriding it. */
5801 found_abi = mips_abi;
5802 wanted_abi = global_mips_abi ();
5803 if (wanted_abi != MIPS_ABI_UNKNOWN)
5804 mips_abi = wanted_abi;
5808 fprintf_unfiltered (gdb_stdlog,
5809 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5811 fprintf_unfiltered (gdb_stdlog,
5812 "mips_gdbarch_init: mips_abi = %d\n",
5814 fprintf_unfiltered (gdb_stdlog,
5815 "mips_gdbarch_init: found_mips_abi = %d\n",
5819 /* try to find a pre-existing architecture */
5820 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5822 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5824 /* MIPS needs to be pedantic about which ABI the object is
5826 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5828 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5830 return arches->gdbarch;
5833 /* Need a new architecture. Fill in a target specific vector. */
5834 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5835 gdbarch = gdbarch_alloc (&info, tdep);
5836 tdep->elf_flags = elf_flags;
5838 /* Initially set everything according to the default ABI/ISA. */
5839 set_gdbarch_short_bit (gdbarch, 16);
5840 set_gdbarch_int_bit (gdbarch, 32);
5841 set_gdbarch_float_bit (gdbarch, 32);
5842 set_gdbarch_double_bit (gdbarch, 64);
5843 set_gdbarch_long_double_bit (gdbarch, 64);
5844 set_gdbarch_deprecated_register_raw_size (gdbarch, mips_register_raw_size);
5845 set_gdbarch_deprecated_register_byte (gdbarch, mips_register_byte);
5846 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
5847 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
5848 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
5849 tdep->found_abi = found_abi;
5850 tdep->mips_abi = mips_abi;
5852 set_gdbarch_elf_make_msymbol_special (gdbarch,
5853 mips_elf_make_msymbol_special);
5856 if (info.osabi == GDB_OSABI_IRIX)
5860 set_gdbarch_num_regs (gdbarch, num_regs);
5861 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
5866 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5867 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5868 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5869 tdep->mips_default_saved_regsize = 4;
5870 tdep->mips_default_stack_argsize = 4;
5871 tdep->mips_fp_register_double = 0;
5872 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5873 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5874 tdep->gdb_target_is_mips64 = 0;
5875 tdep->default_mask_address_p = 0;
5876 set_gdbarch_long_bit (gdbarch, 32);
5877 set_gdbarch_ptr_bit (gdbarch, 32);
5878 set_gdbarch_long_long_bit (gdbarch, 64);
5879 set_gdbarch_deprecated_reg_struct_has_addr
5880 (gdbarch, mips_o32_reg_struct_has_addr);
5881 set_gdbarch_use_struct_convention (gdbarch,
5882 always_use_struct_convention);
5885 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5886 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5887 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5888 tdep->mips_default_saved_regsize = 8;
5889 tdep->mips_default_stack_argsize = 8;
5890 tdep->mips_fp_register_double = 1;
5891 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5892 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5893 tdep->gdb_target_is_mips64 = 1;
5894 tdep->default_mask_address_p = 0;
5895 set_gdbarch_long_bit (gdbarch, 32);
5896 set_gdbarch_ptr_bit (gdbarch, 32);
5897 set_gdbarch_long_long_bit (gdbarch, 64);
5898 set_gdbarch_deprecated_reg_struct_has_addr
5899 (gdbarch, mips_o32_reg_struct_has_addr);
5900 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
5902 case MIPS_ABI_EABI32:
5903 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5904 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5905 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5906 tdep->mips_default_saved_regsize = 4;
5907 tdep->mips_default_stack_argsize = 4;
5908 tdep->mips_fp_register_double = 0;
5909 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5910 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5911 tdep->gdb_target_is_mips64 = 0;
5912 tdep->default_mask_address_p = 0;
5913 set_gdbarch_long_bit (gdbarch, 32);
5914 set_gdbarch_ptr_bit (gdbarch, 32);
5915 set_gdbarch_long_long_bit (gdbarch, 64);
5916 set_gdbarch_deprecated_reg_struct_has_addr
5917 (gdbarch, mips_eabi_reg_struct_has_addr);
5918 set_gdbarch_use_struct_convention (gdbarch,
5919 mips_eabi_use_struct_convention);
5921 case MIPS_ABI_EABI64:
5922 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5923 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5924 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5925 tdep->mips_default_saved_regsize = 8;
5926 tdep->mips_default_stack_argsize = 8;
5927 tdep->mips_fp_register_double = 1;
5928 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5929 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5930 tdep->gdb_target_is_mips64 = 1;
5931 tdep->default_mask_address_p = 0;
5932 set_gdbarch_long_bit (gdbarch, 64);
5933 set_gdbarch_ptr_bit (gdbarch, 64);
5934 set_gdbarch_long_long_bit (gdbarch, 64);
5935 set_gdbarch_deprecated_reg_struct_has_addr
5936 (gdbarch, mips_eabi_reg_struct_has_addr);
5937 set_gdbarch_use_struct_convention (gdbarch,
5938 mips_eabi_use_struct_convention);
5941 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5942 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5943 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5944 tdep->mips_default_saved_regsize = 8;
5945 tdep->mips_default_stack_argsize = 8;
5946 tdep->mips_fp_register_double = 1;
5947 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5948 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5949 tdep->gdb_target_is_mips64 = 1;
5950 tdep->default_mask_address_p = 0;
5951 set_gdbarch_long_bit (gdbarch, 32);
5952 set_gdbarch_ptr_bit (gdbarch, 32);
5953 set_gdbarch_long_long_bit (gdbarch, 64);
5954 set_gdbarch_use_struct_convention (gdbarch,
5955 mips_n32n64_use_struct_convention);
5956 set_gdbarch_deprecated_reg_struct_has_addr
5957 (gdbarch, mips_n32n64_reg_struct_has_addr);
5960 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5961 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5962 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5963 tdep->mips_default_saved_regsize = 8;
5964 tdep->mips_default_stack_argsize = 8;
5965 tdep->mips_fp_register_double = 1;
5966 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5967 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5968 tdep->gdb_target_is_mips64 = 1;
5969 tdep->default_mask_address_p = 0;
5970 set_gdbarch_long_bit (gdbarch, 64);
5971 set_gdbarch_ptr_bit (gdbarch, 64);
5972 set_gdbarch_long_long_bit (gdbarch, 64);
5973 set_gdbarch_use_struct_convention (gdbarch,
5974 mips_n32n64_use_struct_convention);
5975 set_gdbarch_deprecated_reg_struct_has_addr
5976 (gdbarch, mips_n32n64_reg_struct_has_addr);
5979 internal_error (__FILE__, __LINE__,
5980 "unknown ABI in switch");
5983 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5984 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5987 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5988 flag in object files because to do so would make it impossible to
5989 link with libraries compiled without "-gp32". This is
5990 unnecessarily restrictive.
5992 We could solve this problem by adding "-gp32" multilibs to gcc,
5993 but to set this flag before gcc is built with such multilibs will
5994 break too many systems.''
5996 But even more unhelpfully, the default linker output target for
5997 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5998 for 64-bit programs - you need to change the ABI to change this,
5999 and not all gcc targets support that currently. Therefore using
6000 this flag to detect 32-bit mode would do the wrong thing given
6001 the current gcc - it would make GDB treat these 64-bit programs
6002 as 32-bit programs by default. */
6004 /* enable/disable the MIPS FPU */
6005 if (!mips_fpu_type_auto)
6006 tdep->mips_fpu_type = mips_fpu_type;
6007 else if (info.bfd_arch_info != NULL
6008 && info.bfd_arch_info->arch == bfd_arch_mips)
6009 switch (info.bfd_arch_info->mach)
6011 case bfd_mach_mips3900:
6012 case bfd_mach_mips4100:
6013 case bfd_mach_mips4111:
6014 tdep->mips_fpu_type = MIPS_FPU_NONE;
6016 case bfd_mach_mips4650:
6017 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
6020 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
6024 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
6026 /* MIPS version of register names. NOTE: At present the MIPS
6027 register name management is part way between the old -
6028 #undef/#define MIPS_REGISTER_NAMES and the new REGISTER_NAME(nr).
6029 Further work on it is required. */
6030 set_gdbarch_register_name (gdbarch, mips_register_name);
6031 set_gdbarch_read_pc (gdbarch, mips_read_pc);
6032 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
6033 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
6034 set_gdbarch_read_sp (gdbarch, mips_read_sp);
6036 /* Add/remove bits from an address. The MIPS needs be careful to
6037 ensure that all 32 bit addresses are sign extended to 64 bits. */
6038 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
6040 /* There's a mess in stack frame creation. See comments in
6041 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
6042 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
6044 /* Map debug register numbers onto internal register numbers. */
6045 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6046 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6047 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6048 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6049 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
6051 /* Initialize a frame */
6052 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_find_saved_regs);
6053 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
6055 /* MIPS version of CALL_DUMMY */
6057 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
6058 replaced by a command, and all targets will default to on stack
6059 (regardless of the stack's execute status). */
6060 set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL);
6061 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
6062 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6063 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
6064 set_gdbarch_deprecated_register_convertible (gdbarch, mips_register_convertible);
6065 set_gdbarch_deprecated_register_convert_to_virtual (gdbarch, mips_register_convert_to_virtual);
6066 set_gdbarch_deprecated_register_convert_to_raw (gdbarch, mips_register_convert_to_raw);
6068 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
6069 set_gdbarch_frameless_function_invocation (gdbarch,
6070 generic_frameless_function_invocation_not);
6071 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
6072 set_gdbarch_frame_args_skip (gdbarch, 0);
6074 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
6076 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6077 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6078 set_gdbarch_decr_pc_after_break (gdbarch, 0);
6080 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6081 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
6083 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6084 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6085 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6087 set_gdbarch_function_start_offset (gdbarch, 0);
6089 set_gdbarch_register_type (gdbarch, mips_register_type);
6091 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
6092 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
6094 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
6096 /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT,
6097 HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT
6098 need to all be folded into the target vector. Since they are
6099 being used as guards for STOPPED_BY_WATCHPOINT, why not have
6100 STOPPED_BY_WATCHPOINT return the type of watchpoint that the code
6102 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
6104 /* Hook in OS ABI-specific overrides, if they have been registered. */
6105 gdbarch_init_osabi (info, gdbarch);
6107 set_gdbarch_extract_struct_value_address (gdbarch,
6108 mips_extract_struct_value_address);
6110 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6112 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6113 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6119 mips_abi_update (char *ignore_args, int from_tty,
6120 struct cmd_list_element *c)
6122 struct gdbarch_info info;
6124 /* Force the architecture to update, and (if it's a MIPS architecture)
6125 mips_gdbarch_init will take care of the rest. */
6126 gdbarch_info_init (&info);
6127 gdbarch_update_p (info);
6130 /* Print out which MIPS ABI is in use. */
6133 show_mips_abi (char *ignore_args, int from_tty)
6135 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6137 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6140 enum mips_abi global_abi = global_mips_abi ();
6141 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6142 const char *actual_abi_str = mips_abi_strings[actual_abi];
6144 if (global_abi == MIPS_ABI_UNKNOWN)
6145 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6147 else if (global_abi == actual_abi)
6149 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6153 /* Probably shouldn't happen... */
6155 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6157 mips_abi_strings[global_abi]);
6163 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6165 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6169 int ef_mips_32bitmode;
6170 /* determine the ISA */
6171 switch (tdep->elf_flags & EF_MIPS_ARCH)
6189 /* determine the size of a pointer */
6190 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6191 fprintf_unfiltered (file,
6192 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6194 fprintf_unfiltered (file,
6195 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6197 fprintf_unfiltered (file,
6198 "mips_dump_tdep: ef_mips_arch = %d\n",
6200 fprintf_unfiltered (file,
6201 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6203 mips_abi_strings[tdep->mips_abi]);
6204 fprintf_unfiltered (file,
6205 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6206 mips_mask_address_p (),
6207 tdep->default_mask_address_p);
6209 fprintf_unfiltered (file,
6210 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6211 FP_REGISTER_DOUBLE);
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6214 MIPS_DEFAULT_FPU_TYPE,
6215 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6216 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6217 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6219 fprintf_unfiltered (file,
6220 "mips_dump_tdep: MIPS_EABI = %d\n",
6222 fprintf_unfiltered (file,
6223 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6224 MIPS_LAST_FP_ARG_REGNUM,
6225 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6229 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6230 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6231 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6233 fprintf_unfiltered (file,
6234 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6235 MIPS_DEFAULT_SAVED_REGSIZE);
6236 fprintf_unfiltered (file,
6237 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6238 FP_REGISTER_DOUBLE);
6239 fprintf_unfiltered (file,
6240 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6241 MIPS_DEFAULT_STACK_ARGSIZE);
6242 fprintf_unfiltered (file,
6243 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6244 MIPS_STACK_ARGSIZE);
6245 fprintf_unfiltered (file,
6246 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6248 fprintf_unfiltered (file,
6249 "mips_dump_tdep: A0_REGNUM = %d\n",
6251 fprintf_unfiltered (file,
6252 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6253 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6254 fprintf_unfiltered (file,
6255 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6256 XSTRING (ATTACH_DETACH));
6257 fprintf_unfiltered (file,
6258 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6260 fprintf_unfiltered (file,
6261 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6263 fprintf_unfiltered (file,
6264 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6265 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6266 fprintf_unfiltered (file,
6267 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6268 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6269 fprintf_unfiltered (file,
6270 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6272 fprintf_unfiltered (file,
6273 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6275 fprintf_unfiltered (file,
6276 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6277 FIRST_EMBED_REGNUM);
6278 fprintf_unfiltered (file,
6279 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6281 fprintf_unfiltered (file,
6282 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6283 GDB_TARGET_IS_MIPS64);
6284 fprintf_unfiltered (file,
6285 "mips_dump_tdep: HI_REGNUM = %d\n",
6287 fprintf_unfiltered (file,
6288 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6289 XSTRING (IGNORE_HELPER_CALL (PC)));
6290 fprintf_unfiltered (file,
6291 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6292 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6293 fprintf_unfiltered (file,
6294 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6295 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6296 fprintf_unfiltered (file,
6297 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6299 fprintf_unfiltered (file,
6300 "mips_dump_tdep: LO_REGNUM = %d\n",
6302 #ifdef MACHINE_CPROC_FP_OFFSET
6303 fprintf_unfiltered (file,
6304 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6305 MACHINE_CPROC_FP_OFFSET);
6307 #ifdef MACHINE_CPROC_PC_OFFSET
6308 fprintf_unfiltered (file,
6309 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6310 MACHINE_CPROC_PC_OFFSET);
6312 #ifdef MACHINE_CPROC_SP_OFFSET
6313 fprintf_unfiltered (file,
6314 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6315 MACHINE_CPROC_SP_OFFSET);
6317 fprintf_unfiltered (file,
6318 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6320 fprintf_unfiltered (file,
6321 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6322 fprintf_unfiltered (file,
6323 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6324 fprintf_unfiltered (file,
6325 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6327 fprintf_unfiltered (file,
6328 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6329 MIPS_LAST_ARG_REGNUM,
6330 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6331 fprintf_unfiltered (file,
6332 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6334 fprintf_unfiltered (file,
6335 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6336 fprintf_unfiltered (file,
6337 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6338 MIPS_SAVED_REGSIZE);
6339 fprintf_unfiltered (file,
6340 "mips_dump_tdep: OP_LDFPR = used?\n");
6341 fprintf_unfiltered (file,
6342 "mips_dump_tdep: OP_LDGPR = used?\n");
6343 fprintf_unfiltered (file,
6344 "mips_dump_tdep: PRID_REGNUM = %d\n",
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6348 fprintf_unfiltered (file,
6349 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6350 fprintf_unfiltered (file,
6351 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6352 fprintf_unfiltered (file,
6353 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6354 fprintf_unfiltered (file,
6355 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6356 fprintf_unfiltered (file,
6357 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6358 fprintf_unfiltered (file,
6359 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6362 fprintf_unfiltered (file,
6363 "mips_dump_tdep: PROC_PC_REG = function?\n");
6364 fprintf_unfiltered (file,
6365 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6366 fprintf_unfiltered (file,
6367 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6368 fprintf_unfiltered (file,
6369 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6370 fprintf_unfiltered (file,
6371 "mips_dump_tdep: PS_REGNUM = %d\n",
6373 fprintf_unfiltered (file,
6374 "mips_dump_tdep: RA_REGNUM = %d\n",
6377 fprintf_unfiltered (file,
6378 "mips_dump_tdep: SAVED_BYTES = %d\n",
6382 fprintf_unfiltered (file,
6383 "mips_dump_tdep: SAVED_FP = %d\n",
6387 fprintf_unfiltered (file,
6388 "mips_dump_tdep: SAVED_PC = %d\n",
6391 fprintf_unfiltered (file,
6392 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6393 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6394 fprintf_unfiltered (file,
6395 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6396 fprintf_unfiltered (file,
6397 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6399 fprintf_unfiltered (file,
6400 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6401 SIGFRAME_FPREGSAVE_OFF);
6402 fprintf_unfiltered (file,
6403 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6405 fprintf_unfiltered (file,
6406 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6407 SIGFRAME_REGSAVE_OFF);
6408 fprintf_unfiltered (file,
6409 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6411 fprintf_unfiltered (file,
6412 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6413 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6414 fprintf_unfiltered (file,
6415 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6416 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6417 fprintf_unfiltered (file,
6418 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6419 SOFTWARE_SINGLE_STEP_P ());
6420 fprintf_unfiltered (file,
6421 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6422 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6423 #ifdef STACK_END_ADDR
6424 fprintf_unfiltered (file,
6425 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6428 fprintf_unfiltered (file,
6429 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6430 XSTRING (STEP_SKIPS_DELAY (PC)));
6431 fprintf_unfiltered (file,
6432 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6433 STEP_SKIPS_DELAY_P);
6434 fprintf_unfiltered (file,
6435 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6436 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6437 fprintf_unfiltered (file,
6438 "mips_dump_tdep: T9_REGNUM = %d\n",
6440 fprintf_unfiltered (file,
6441 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6442 fprintf_unfiltered (file,
6443 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6444 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6445 fprintf_unfiltered (file,
6446 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6447 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6449 fprintf_unfiltered (file,
6450 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6451 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6454 fprintf_unfiltered (file,
6455 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6458 #ifdef TRACE_FLAVOR_SIZE
6459 fprintf_unfiltered (file,
6460 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6464 fprintf_unfiltered (file,
6465 "mips_dump_tdep: TRACE_SET # %s\n",
6466 XSTRING (TRACE_SET (X,STATE)));
6468 #ifdef UNUSED_REGNUM
6469 fprintf_unfiltered (file,
6470 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6473 fprintf_unfiltered (file,
6474 "mips_dump_tdep: V0_REGNUM = %d\n",
6476 fprintf_unfiltered (file,
6477 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6478 (long) VM_MIN_ADDRESS);
6479 fprintf_unfiltered (file,
6480 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6482 fprintf_unfiltered (file,
6483 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6487 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6490 _initialize_mips_tdep (void)
6492 static struct cmd_list_element *mipsfpulist = NULL;
6493 struct cmd_list_element *c;
6495 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6496 if (MIPS_ABI_LAST + 1
6497 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6498 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6500 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6502 /* Add root prefix command for all "set mips"/"show mips" commands */
6503 add_prefix_cmd ("mips", no_class, set_mips_command,
6504 "Various MIPS specific commands.",
6505 &setmipscmdlist, "set mips ", 0, &setlist);
6507 add_prefix_cmd ("mips", no_class, show_mips_command,
6508 "Various MIPS specific commands.",
6509 &showmipscmdlist, "show mips ", 0, &showlist);
6511 /* Allow the user to override the saved register size. */
6512 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6515 &mips_saved_regsize_string, "\
6516 Set size of general purpose registers saved on the stack.\n\
6517 This option can be set to one of:\n\
6518 32 - Force GDB to treat saved GP registers as 32-bit\n\
6519 64 - Force GDB to treat saved GP registers as 64-bit\n\
6520 auto - Allow GDB to use the target's default setting or autodetect the\n\
6521 saved GP register size from information contained in the executable.\n\
6526 /* Allow the user to override the argument stack size. */
6527 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6530 &mips_stack_argsize_string, "\
6531 Set the amount of stack space reserved for each argument.\n\
6532 This option can be set to one of:\n\
6533 32 - Force GDB to allocate 32-bit chunks per argument\n\
6534 64 - Force GDB to allocate 64-bit chunks per argument\n\
6535 auto - Allow GDB to determine the correct setting from the current\n\
6536 target and executable (default)",
6540 /* Allow the user to override the ABI. */
6541 c = add_set_enum_cmd
6542 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6543 "Set the ABI used by this program.\n"
6544 "This option can be set to one of:\n"
6545 " auto - the default ABI associated with the current binary\n"
6553 set_cmd_sfunc (c, mips_abi_update);
6554 add_cmd ("abi", class_obscure, show_mips_abi,
6555 "Show ABI in use by MIPS target", &showmipscmdlist);
6557 /* Let the user turn off floating point and set the fence post for
6558 heuristic_proc_start. */
6560 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6561 "Set use of MIPS floating-point coprocessor.",
6562 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6563 add_cmd ("single", class_support, set_mipsfpu_single_command,
6564 "Select single-precision MIPS floating-point coprocessor.",
6566 add_cmd ("double", class_support, set_mipsfpu_double_command,
6567 "Select double-precision MIPS floating-point coprocessor.",
6569 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6570 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6571 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6572 add_cmd ("none", class_support, set_mipsfpu_none_command,
6573 "Select no MIPS floating-point coprocessor.",
6575 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6576 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6577 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6578 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6579 "Select MIPS floating-point coprocessor automatically.",
6581 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6582 "Show current use of MIPS floating-point coprocessor target.",
6585 /* We really would like to have both "0" and "unlimited" work, but
6586 command.c doesn't deal with that. So make it a var_zinteger
6587 because the user can always use "999999" or some such for unlimited. */
6588 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6589 (char *) &heuristic_fence_post,
6591 Set the distance searched for the start of a function.\n\
6592 If you are debugging a stripped executable, GDB needs to search through the\n\
6593 program for the start of a function. This command sets the distance of the\n\
6594 search. The only need to set it is when debugging a stripped executable.",
6596 /* We need to throw away the frame cache when we set this, since it
6597 might change our ability to get backtraces. */
6598 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6599 add_show_from_set (c, &showlist);
6601 /* Allow the user to control whether the upper bits of 64-bit
6602 addresses should be zeroed. */
6603 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6604 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6605 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6606 allow GDB to determine the correct value.\n", "\
6607 Show zeroing of upper 32 bits of 64-bit addresses.",
6608 NULL, show_mask_address,
6609 &setmipscmdlist, &showmipscmdlist);
6611 /* Allow the user to control the size of 32 bit registers within the
6612 raw remote packet. */
6613 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6616 (char *)&mips64_transfers_32bit_regs_p, "\
6617 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6618 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6619 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6620 64 bits for others. Use \"off\" to disable compatibility mode",
6624 /* Debug this files internals. */
6625 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6626 &mips_debug, "Set mips debugging.\n\
6627 When non-zero, mips specific debugging is enabled.", &setdebuglist),