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.
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"
52 static void set_reg_offset (CORE_ADDR *saved_regs, int regnum, CORE_ADDR off);
54 /* A useful bit in the CP0 status register (PS_REGNUM). */
55 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
56 #define ST0_FR (1 << 26)
58 /* The sizes of floating point registers. */
62 MIPS_FPU_SINGLE_REGSIZE = 4,
63 MIPS_FPU_DOUBLE_REGSIZE = 8
67 static const char *mips_abi_string;
69 static const char *mips_abi_strings[] = {
80 struct frame_extra_info
82 mips_extra_func_info_t proc_desc;
86 /* Various MIPS ISA options (related to stack analysis) can be
87 overridden dynamically. Establish an enum/array for managing
90 static const char size_auto[] = "auto";
91 static const char size_32[] = "32";
92 static const char size_64[] = "64";
94 static const char *size_enums[] = {
101 /* Some MIPS boards don't support floating point while others only
102 support single-precision floating-point operations. See also
103 FP_REGISTER_DOUBLE. */
107 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
108 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
109 MIPS_FPU_NONE /* No floating point. */
112 #ifndef MIPS_DEFAULT_FPU_TYPE
113 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
115 static int mips_fpu_type_auto = 1;
116 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
118 static int mips_debug = 0;
120 /* MIPS specific per-architecture information */
123 /* from the elf header */
127 enum mips_abi mips_abi;
128 enum mips_abi found_abi;
129 enum mips_fpu_type mips_fpu_type;
130 int mips_last_arg_regnum;
131 int mips_last_fp_arg_regnum;
132 int mips_default_saved_regsize;
133 int mips_fp_register_double;
134 int mips_default_stack_argsize;
135 int gdb_target_is_mips64;
136 int default_mask_address_p;
139 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
140 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
142 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
144 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
146 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
148 /* Return the currently configured (or set) saved register size. */
150 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
152 static const char *mips_saved_regsize_string = size_auto;
154 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
156 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
157 functions to test, set, or clear bit 0 of addresses. */
160 is_mips16_addr (CORE_ADDR addr)
166 make_mips16_addr (CORE_ADDR addr)
172 unmake_mips16_addr (CORE_ADDR addr)
174 return ((addr) & ~1);
177 /* Return the contents of register REGNUM as a signed integer. */
180 read_signed_register (int regnum)
182 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
183 deprecated_read_register_gen (regnum, buf);
184 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
188 read_signed_register_pid (int regnum, ptid_t ptid)
193 if (ptid_equal (ptid, inferior_ptid))
194 return read_signed_register (regnum);
196 save_ptid = inferior_ptid;
198 inferior_ptid = ptid;
200 retval = read_signed_register (regnum);
202 inferior_ptid = save_ptid;
207 /* Return the MIPS ABI associated with GDBARCH. */
209 mips_abi (struct gdbarch *gdbarch)
211 return gdbarch_tdep (gdbarch)->mips_abi;
215 mips_saved_regsize (void)
217 if (mips_saved_regsize_string == size_auto)
218 return MIPS_DEFAULT_SAVED_REGSIZE;
219 else if (mips_saved_regsize_string == size_64)
221 else /* if (mips_saved_regsize_string == size_32) */
225 /* Functions for setting and testing a bit in a minimal symbol that
226 marks it as 16-bit function. The MSB of the minimal symbol's
227 "info" field is used for this purpose. This field is already
228 being used to store the symbol size, so the assumption is
229 that the symbol size cannot exceed 2^31.
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
236 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
237 the "info" field with the "special" bit masked out */
240 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
242 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
244 MSYMBOL_INFO (msym) = (char *)
245 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
246 SYMBOL_VALUE_ADDRESS (msym) |= 1;
251 msymbol_is_special (struct minimal_symbol *msym)
253 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
257 msymbol_size (struct minimal_symbol *msym)
259 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
262 /* XFER a value from the big/little/left end of the register.
263 Depending on the size of the value it might occupy the entire
264 register or just part of it. Make an allowance for this, aligning
265 things accordingly. */
268 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
269 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
272 bfd_byte reg[MAX_REGISTER_SIZE];
274 gdb_assert (reg_num >= NUM_REGS);
275 /* Need to transfer the left or right part of the register, based on
276 the targets byte order. */
280 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
282 case BFD_ENDIAN_LITTLE:
285 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
289 internal_error (__FILE__, __LINE__, "bad switch");
292 fprintf_unfiltered (gdb_stderr,
293 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
294 reg_num, reg_offset, buf_offset, length);
295 if (mips_debug && out != NULL)
298 fprintf_unfiltered (gdb_stdlog, "out ");
299 for (i = 0; i < length; i++)
300 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
303 regcache_cooked_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
305 regcache_cooked_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
306 if (mips_debug && in != NULL)
309 fprintf_unfiltered (gdb_stdlog, "in ");
310 for (i = 0; i < length; i++)
311 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
314 fprintf_unfiltered (gdb_stdlog, "\n");
317 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
318 compatiblity mode. A return value of 1 means that we have
319 physical 64-bit registers, but should treat them as 32-bit registers. */
322 mips2_fp_compat (void)
324 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
326 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
330 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
331 in all the places we deal with FP registers. PR gdb/413. */
332 /* Otherwise check the FR bit in the status register - it controls
333 the FP compatiblity mode. If it is clear we are in compatibility
335 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
342 /* Indicate that the ABI makes use of double-precision registers
343 provided by the FPU (rather than combining pairs of registers to
344 form double-precision values). Do not use "TARGET_IS_MIPS64" to
345 determine if the ABI is using double-precision registers. See also
347 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
349 /* The amount of space reserved on the stack for registers. This is
350 different to MIPS_SAVED_REGSIZE as it determines the alignment of
351 data allocated after the registers have run out. */
353 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
355 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
357 static const char *mips_stack_argsize_string = size_auto;
360 mips_stack_argsize (void)
362 if (mips_stack_argsize_string == size_auto)
363 return MIPS_DEFAULT_STACK_ARGSIZE;
364 else if (mips_stack_argsize_string == size_64)
366 else /* if (mips_stack_argsize_string == size_32) */
370 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
372 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
374 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
376 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
378 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
379 struct frame_info *, int);
381 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
383 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
385 static int mips_set_processor_type (char *);
387 static void mips_show_processor_type_command (char *, int);
389 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
391 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
392 struct frame_info *next_frame,
395 static CORE_ADDR after_prologue (CORE_ADDR pc,
396 mips_extra_func_info_t proc_desc);
398 static struct type *mips_float_register_type (void);
399 static struct type *mips_double_register_type (void);
401 /* This value is the model of MIPS in use. It is derived from the value
402 of the PrID register. */
404 char *mips_processor_type;
406 char *tmp_mips_processor_type;
408 /* The list of available "set mips " and "show mips " commands */
410 static struct cmd_list_element *setmipscmdlist = NULL;
411 static struct cmd_list_element *showmipscmdlist = NULL;
413 /* A set of original names, to be used when restoring back to generic
414 registers from a specific set. */
415 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
417 /* Integer registers 0 thru 31 are handled explicitly by
418 mips_register_name(). Processor specific registers 32 and above
419 are listed in the sets of register names assigned to
420 mips_processor_reg_names. */
421 static char **mips_processor_reg_names = mips_generic_reg_names;
423 /* Return the name of the register corresponding to REGNO. */
425 mips_register_name (int regno)
427 /* GPR names for all ABIs other than n32/n64. */
428 static char *mips_gpr_names[] = {
429 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
430 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
431 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
432 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
435 /* GPR names for n32 and n64 ABIs. */
436 static char *mips_n32_n64_gpr_names[] = {
437 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
438 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
439 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
440 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
443 enum mips_abi abi = mips_abi (current_gdbarch);
445 /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then
446 don't make the raw register names visible. */
447 int rawnum = regno % NUM_REGS;
448 if (regno < NUM_REGS)
451 /* The MIPS integer registers are always mapped from 0 to 31. The
452 names of the registers (which reflects the conventions regarding
453 register use) vary depending on the ABI. */
454 if (0 <= rawnum && rawnum < 32)
456 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
457 return mips_n32_n64_gpr_names[rawnum];
459 return mips_gpr_names[rawnum];
461 else if (32 <= rawnum && rawnum < NUM_REGS)
462 return mips_processor_reg_names[rawnum - 32];
464 internal_error (__FILE__, __LINE__,
465 "mips_register_name: bad register number %d", rawnum);
469 /* Names of IDT R3041 registers. */
471 char *mips_r3041_reg_names[] = {
472 "sr", "lo", "hi", "bad", "cause","pc",
473 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
474 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
475 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
476 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
477 "fsr", "fir", "",/*"fp"*/ "",
478 "", "", "bus", "ccfg", "", "", "", "",
479 "", "", "port", "cmp", "", "", "epc", "prid",
482 /* Names of IDT R3051 registers. */
484 char *mips_r3051_reg_names[] = {
485 "sr", "lo", "hi", "bad", "cause","pc",
486 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
487 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
488 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
489 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
490 "fsr", "fir", ""/*"fp"*/, "",
491 "inx", "rand", "elo", "", "ctxt", "", "", "",
492 "", "", "ehi", "", "", "", "epc", "prid",
495 /* Names of IDT R3081 registers. */
497 char *mips_r3081_reg_names[] = {
498 "sr", "lo", "hi", "bad", "cause","pc",
499 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
500 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
501 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
502 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
503 "fsr", "fir", ""/*"fp"*/, "",
504 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
505 "", "", "ehi", "", "", "", "epc", "prid",
508 /* Names of LSI 33k registers. */
510 char *mips_lsi33k_reg_names[] = {
511 "epc", "hi", "lo", "sr", "cause","badvaddr",
512 "dcic", "bpc", "bda", "", "", "", "", "",
513 "", "", "", "", "", "", "", "",
514 "", "", "", "", "", "", "", "",
515 "", "", "", "", "", "", "", "",
517 "", "", "", "", "", "", "", "",
518 "", "", "", "", "", "", "", "",
524 } mips_processor_type_table[] = {
525 { "generic", mips_generic_reg_names },
526 { "r3041", mips_r3041_reg_names },
527 { "r3051", mips_r3051_reg_names },
528 { "r3071", mips_r3081_reg_names },
529 { "r3081", mips_r3081_reg_names },
530 { "lsi33k", mips_lsi33k_reg_names },
535 /* Return the groups that a MIPS register can be categorised into. */
538 mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
539 struct reggroup *reggroup)
544 int rawnum = regnum % NUM_REGS;
545 int pseudo = regnum / NUM_REGS;
546 if (reggroup == all_reggroup)
548 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
549 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
550 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
551 (gdbarch), as not all architectures are multi-arch. */
552 raw_p = rawnum < NUM_REGS;
553 if (REGISTER_NAME (regnum) == NULL
554 || REGISTER_NAME (regnum)[0] == '\0')
556 if (reggroup == float_reggroup)
557 return float_p && pseudo;
558 if (reggroup == vector_reggroup)
559 return vector_p && pseudo;
560 if (reggroup == general_reggroup)
561 return (!vector_p && !float_p) && pseudo;
562 /* Save the pseudo registers. Need to make certain that any code
563 extracting register values from a saved register cache also uses
565 if (reggroup == save_reggroup)
566 return raw_p && pseudo;
567 /* Restore the same pseudo register. */
568 if (reggroup == restore_reggroup)
569 return raw_p && pseudo;
573 /* Map the symbol table registers which live in the range [1 *
574 NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw
578 mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
579 int cookednum, void *buf)
581 gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS);
582 return regcache_raw_read (regcache, cookednum % NUM_REGS, buf);
586 mips_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
587 int cookednum, const void *buf)
589 gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS);
590 return regcache_raw_write (regcache, cookednum % NUM_REGS, buf);
593 /* Table to translate MIPS16 register field to actual register number. */
594 static int mips16_to_32_reg[8] =
595 {16, 17, 2, 3, 4, 5, 6, 7};
597 /* Heuristic_proc_start may hunt through the text section for a long
598 time across a 2400 baud serial line. Allows the user to limit this
601 static unsigned int heuristic_fence_post = 0;
603 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
604 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
605 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
606 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
607 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
608 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
609 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
610 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
611 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
612 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
613 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
614 this will corrupt pdr.iline. Fortunately we don't use it. */
615 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
616 #define _PROC_MAGIC_ 0x0F0F0F0F
617 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
618 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
620 struct linked_proc_info
622 struct mips_extra_func_info info;
623 struct linked_proc_info *next;
625 *linked_proc_desc_table = NULL;
628 mips_print_extra_frame_info (struct frame_info *fi)
631 && get_frame_extra_info (fi)
632 && get_frame_extra_info (fi)->proc_desc
633 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
634 printf_filtered (" frame pointer is at %s+%s\n",
635 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
636 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
639 /* Number of bytes of storage in the actual machine representation for
640 register N. NOTE: This indirectly defines the register size
641 transfered by the GDB protocol. */
643 static int mips64_transfers_32bit_regs_p = 0;
646 mips_register_raw_size (int regnum)
648 gdb_assert (regnum >= 0);
649 if (regnum < NUM_REGS)
651 /* For compatibility with old code, implemnt the broken register raw
652 size map for the raw registers.
654 NOTE: cagney/2003-06-15: This is so bogus. The register's
655 raw size is changing according to the ABI
656 (FP_REGISTER_DOUBLE). Also, GDB's protocol is defined by a
657 combination of REGISTER_RAW_SIZE and REGISTER_BYTE. */
658 if (mips64_transfers_32bit_regs_p)
659 return REGISTER_VIRTUAL_SIZE (regnum);
660 else if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM + 32
661 && FP_REGISTER_DOUBLE)
662 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
668 else if (regnum < 2 * NUM_REGS)
670 /* For the moment map [NUM_REGS .. 2*NUM_REGS) onto the same raw
671 registers, but always return the virtual size. */
672 int rawnum = regnum % NUM_REGS;
673 return TYPE_LENGTH (MIPS_REGISTER_TYPE (rawnum));
676 internal_error (__FILE__, __LINE__, "Register %d out of range", regnum);
679 /* Register offset in a buffer for each register.
681 FIXME: cagney/2003-06-15: This is so bogus. Instead REGISTER_TYPE
682 should strictly return the layout of the buffer. Unfortunatly
683 remote.c and the MIPS have come to rely on a custom layout that
684 doesn't 1:1 map onto the register type. */
687 mips_register_byte (int regnum)
689 gdb_assert (regnum >= 0);
690 if (regnum < NUM_REGS)
691 /* Pick up the relevant per-tm file register byte method. */
692 return MIPS_REGISTER_BYTE (regnum);
693 else if (regnum < 2 * NUM_REGS)
697 /* Start with the end of the raw register buffer - assum that
698 MIPS_REGISTER_BYTE (NUM_REGS) returns that end. */
699 byte = MIPS_REGISTER_BYTE (NUM_REGS);
700 /* Add space for all the proceeding registers based on their
702 for (reg = NUM_REGS; reg < regnum; reg++)
703 byte += TYPE_LENGTH (MIPS_REGISTER_TYPE ((reg % NUM_REGS)));
707 internal_error (__FILE__, __LINE__, "Register %d out of range", regnum);
710 /* Convert between RAW and VIRTUAL registers. The RAW register size
711 defines the remote-gdb packet. */
714 mips_register_convertible (int reg_nr)
716 if (mips64_transfers_32bit_regs_p)
719 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
723 mips_register_convert_to_virtual (int n, struct type *virtual_type,
724 char *raw_buf, char *virt_buf)
726 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
728 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
729 TYPE_LENGTH (virtual_type));
733 TYPE_LENGTH (virtual_type));
737 mips_register_convert_to_raw (struct type *virtual_type, int n,
738 const char *virt_buf, char *raw_buf)
740 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
741 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
742 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
744 TYPE_LENGTH (virtual_type));
748 TYPE_LENGTH (virtual_type));
752 mips_convert_register_p (int regnum, struct type *type)
754 return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
755 && REGISTER_RAW_SIZE (regnum) == 4
756 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
757 && TYPE_CODE(type) == TYPE_CODE_FLT
758 && TYPE_LENGTH(type) == 8);
762 mips_register_to_value (struct frame_info *frame, int regnum,
763 struct type *type, void *to)
765 frame_read_register (frame, regnum + 0, (char *) to + 4);
766 frame_read_register (frame, regnum + 1, (char *) to + 0);
770 mips_value_to_register (struct frame_info *frame, int regnum,
771 struct type *type, const void *from)
773 put_frame_register (frame, regnum + 0, (const char *) from + 4);
774 put_frame_register (frame, regnum + 1, (const char *) from + 0);
777 /* Return the GDB type object for the "standard" data type of data in
781 mips_register_type (struct gdbarch *gdbarch, int regnum)
783 /* For moment, map [NUM_REGS .. 2*NUM_REGS) onto the same raw
784 registers. Even return the same type. */
785 int rawnum = regnum % NUM_REGS;
786 gdb_assert (rawnum >= 0 && rawnum < NUM_REGS);
787 #ifdef MIPS_REGISTER_TYPE
788 return MIPS_REGISTER_TYPE (rawnum);
790 if (FP0_REGNUM <= rawnum && rawnum < FP0_REGNUM + 32)
792 /* Floating point registers... */
793 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
794 return builtin_type_ieee_double_big;
796 return builtin_type_ieee_double_little;
798 else if (rawnum == PS_REGNUM /* CR */)
799 return builtin_type_uint32;
800 else if (FCRCS_REGNUM <= rawnum && rawnum <= LAST_EMBED_REGNUM)
801 return builtin_type_uint32;
804 /* Everything else...
805 Return type appropriate for width of register. */
806 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
807 return builtin_type_uint64;
809 return builtin_type_uint32;
814 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
819 return read_signed_register (SP_REGNUM);
822 /* Should the upper word of 64-bit addresses be zeroed? */
823 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
826 mips_mask_address_p (void)
828 switch (mask_address_var)
830 case AUTO_BOOLEAN_TRUE:
832 case AUTO_BOOLEAN_FALSE:
835 case AUTO_BOOLEAN_AUTO:
836 return MIPS_DEFAULT_MASK_ADDRESS_P;
838 internal_error (__FILE__, __LINE__,
839 "mips_mask_address_p: bad switch");
845 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
847 switch (mask_address_var)
849 case AUTO_BOOLEAN_TRUE:
850 printf_filtered ("The 32 bit mips address mask is enabled\n");
852 case AUTO_BOOLEAN_FALSE:
853 printf_filtered ("The 32 bit mips address mask is disabled\n");
855 case AUTO_BOOLEAN_AUTO:
856 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
857 mips_mask_address_p () ? "enabled" : "disabled");
860 internal_error (__FILE__, __LINE__,
861 "show_mask_address: bad switch");
866 /* Should call_function allocate stack space for a struct return? */
869 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
871 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
875 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
877 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
880 /* Should call_function pass struct by reference?
881 For each architecture, structs are passed either by
882 value or by reference, depending on their size. */
885 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
887 enum type_code typecode = TYPE_CODE (check_typedef (type));
888 int len = TYPE_LENGTH (check_typedef (type));
890 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
891 return (len > MIPS_SAVED_REGSIZE);
897 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
899 return 0; /* Assumption: N32/N64 never passes struct by ref. */
903 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
905 return 0; /* Assumption: O32/O64 never passes struct by ref. */
908 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
911 pc_is_mips16 (bfd_vma memaddr)
913 struct minimal_symbol *sym;
915 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
916 if (is_mips16_addr (memaddr))
919 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
920 the high bit of the info field. Use this to decide if the function is
921 MIPS16 or normal MIPS. */
922 sym = lookup_minimal_symbol_by_pc (memaddr);
924 return msymbol_is_special (sym);
929 /* MIPS believes that the PC has a sign extended value. Perhaphs the
930 all registers should be sign extended for simplicity? */
933 mips_read_pc (ptid_t ptid)
935 return read_signed_register_pid (PC_REGNUM, ptid);
938 /* This returns the PC of the first inst after the prologue. If we can't
939 find the prologue, then return 0. */
942 after_prologue (CORE_ADDR pc,
943 mips_extra_func_info_t proc_desc)
945 struct symtab_and_line sal;
946 CORE_ADDR func_addr, func_end;
948 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
949 to read the stack pointer from the current machine state, because
950 the current machine state has nothing to do with the information
951 we need from the proc_desc; and the process may or may not exist
954 proc_desc = find_proc_desc (pc, NULL, 0);
958 /* If function is frameless, then we need to do it the hard way. I
959 strongly suspect that frameless always means prologueless... */
960 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
961 && PROC_FRAME_OFFSET (proc_desc) == 0)
965 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
966 return 0; /* Unknown */
968 sal = find_pc_line (func_addr, 0);
970 if (sal.end < func_end)
973 /* The line after the prologue is after the end of the function. In this
974 case, tell the caller to find the prologue the hard way. */
979 /* Decode a MIPS32 instruction that saves a register in the stack, and
980 set the appropriate bit in the general register mask or float register mask
981 to indicate which register is saved. This is a helper function
982 for mips_find_saved_regs. */
985 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
986 unsigned long *float_mask)
990 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
991 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
992 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
994 /* It might be possible to use the instruction to
995 find the offset, rather than the code below which
996 is based on things being in a certain order in the
997 frame, but figuring out what the instruction's offset
998 is relative to might be a little tricky. */
999 reg = (inst & 0x001f0000) >> 16;
1000 *gen_mask |= (1 << reg);
1002 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
1003 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
1004 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
1007 reg = ((inst & 0x001f0000) >> 16);
1008 *float_mask |= (1 << reg);
1012 /* Decode a MIPS16 instruction that saves a register in the stack, and
1013 set the appropriate bit in the general register or float register mask
1014 to indicate which register is saved. This is a helper function
1015 for mips_find_saved_regs. */
1018 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
1020 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1022 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1023 *gen_mask |= (1 << reg);
1025 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1027 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1028 *gen_mask |= (1 << reg);
1030 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
1031 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1032 *gen_mask |= (1 << RA_REGNUM);
1036 /* Fetch and return instruction from the specified location. If the PC
1037 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
1040 mips_fetch_instruction (CORE_ADDR addr)
1042 char buf[MIPS_INSTLEN];
1046 if (pc_is_mips16 (addr))
1048 instlen = MIPS16_INSTLEN;
1049 addr = unmake_mips16_addr (addr);
1052 instlen = MIPS_INSTLEN;
1053 status = read_memory_nobpt (addr, buf, instlen);
1055 memory_error (status, addr);
1056 return extract_unsigned_integer (buf, instlen);
1060 /* These the fields of 32 bit mips instructions */
1061 #define mips32_op(x) (x >> 26)
1062 #define itype_op(x) (x >> 26)
1063 #define itype_rs(x) ((x >> 21) & 0x1f)
1064 #define itype_rt(x) ((x >> 16) & 0x1f)
1065 #define itype_immediate(x) (x & 0xffff)
1067 #define jtype_op(x) (x >> 26)
1068 #define jtype_target(x) (x & 0x03ffffff)
1070 #define rtype_op(x) (x >> 26)
1071 #define rtype_rs(x) ((x >> 21) & 0x1f)
1072 #define rtype_rt(x) ((x >> 16) & 0x1f)
1073 #define rtype_rd(x) ((x >> 11) & 0x1f)
1074 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1075 #define rtype_funct(x) (x & 0x3f)
1078 mips32_relative_offset (unsigned long inst)
1081 x = itype_immediate (inst);
1082 if (x & 0x8000) /* sign bit set */
1084 x |= 0xffff0000; /* sign extension */
1090 /* Determine whate to set a single step breakpoint while considering
1091 branch prediction */
1093 mips32_next_pc (CORE_ADDR pc)
1097 inst = mips_fetch_instruction (pc);
1098 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
1100 if (itype_op (inst) >> 2 == 5)
1101 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1103 op = (itype_op (inst) & 0x03);
1113 goto greater_branch;
1118 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
1119 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1121 int tf = itype_rt (inst) & 0x01;
1122 int cnum = itype_rt (inst) >> 2;
1123 int fcrcs = read_signed_register (FCRCS_REGNUM);
1124 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1126 if (((cond >> cnum) & 0x01) == tf)
1127 pc += mips32_relative_offset (inst) + 4;
1132 pc += 4; /* Not a branch, next instruction is easy */
1135 { /* This gets way messy */
1137 /* Further subdivide into SPECIAL, REGIMM and other */
1138 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
1140 case 0: /* SPECIAL */
1141 op = rtype_funct (inst);
1146 /* Set PC to that address */
1147 pc = read_signed_register (rtype_rs (inst));
1153 break; /* end SPECIAL */
1154 case 1: /* REGIMM */
1156 op = itype_rt (inst); /* branch condition */
1161 case 16: /* BLTZAL */
1162 case 18: /* BLTZALL */
1164 if (read_signed_register (itype_rs (inst)) < 0)
1165 pc += mips32_relative_offset (inst) + 4;
1167 pc += 8; /* after the delay slot */
1171 case 17: /* BGEZAL */
1172 case 19: /* BGEZALL */
1173 greater_equal_branch:
1174 if (read_signed_register (itype_rs (inst)) >= 0)
1175 pc += mips32_relative_offset (inst) + 4;
1177 pc += 8; /* after the delay slot */
1179 /* All of the other instructions in the REGIMM category */
1184 break; /* end REGIMM */
1189 reg = jtype_target (inst) << 2;
1190 /* Upper four bits get never changed... */
1191 pc = reg + ((pc + 4) & 0xf0000000);
1194 /* FIXME case JALX : */
1197 reg = jtype_target (inst) << 2;
1198 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1199 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1201 break; /* The new PC will be alternate mode */
1202 case 4: /* BEQ, BEQL */
1204 if (read_signed_register (itype_rs (inst)) ==
1205 read_signed_register (itype_rt (inst)))
1206 pc += mips32_relative_offset (inst) + 4;
1210 case 5: /* BNE, BNEL */
1212 if (read_signed_register (itype_rs (inst)) !=
1213 read_signed_register (itype_rt (inst)))
1214 pc += mips32_relative_offset (inst) + 4;
1218 case 6: /* BLEZ, BLEZL */
1220 if (read_signed_register (itype_rs (inst) <= 0))
1221 pc += mips32_relative_offset (inst) + 4;
1227 greater_branch: /* BGTZ, BGTZL */
1228 if (read_signed_register (itype_rs (inst) > 0))
1229 pc += mips32_relative_offset (inst) + 4;
1236 } /* mips32_next_pc */
1238 /* Decoding the next place to set a breakpoint is irregular for the
1239 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1240 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1241 We dont want to set a single step instruction on the extend instruction
1245 /* Lots of mips16 instruction formats */
1246 /* Predicting jumps requires itype,ritype,i8type
1247 and their extensions extItype,extritype,extI8type
1249 enum mips16_inst_fmts
1251 itype, /* 0 immediate 5,10 */
1252 ritype, /* 1 5,3,8 */
1253 rrtype, /* 2 5,3,3,5 */
1254 rritype, /* 3 5,3,3,5 */
1255 rrrtype, /* 4 5,3,3,3,2 */
1256 rriatype, /* 5 5,3,3,1,4 */
1257 shifttype, /* 6 5,3,3,3,2 */
1258 i8type, /* 7 5,3,8 */
1259 i8movtype, /* 8 5,3,3,5 */
1260 i8mov32rtype, /* 9 5,3,5,3 */
1261 i64type, /* 10 5,3,8 */
1262 ri64type, /* 11 5,3,3,5 */
1263 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1264 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1265 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1266 extRRItype, /* 15 5,5,5,5,3,3,5 */
1267 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1268 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1269 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1270 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1271 extRi64type, /* 20 5,6,5,5,3,3,5 */
1272 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1274 /* I am heaping all the fields of the formats into one structure and
1275 then, only the fields which are involved in instruction extension */
1279 unsigned int regx; /* Function in i8 type */
1284 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1285 for the bits which make up the immediatate extension. */
1288 extended_offset (unsigned int extension)
1291 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1293 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1295 value |= extension & 0x01f; /* extract 4:0 */
1299 /* Only call this function if you know that this is an extendable
1300 instruction, It wont malfunction, but why make excess remote memory references?
1301 If the immediate operands get sign extended or somthing, do it after
1302 the extension is performed.
1304 /* FIXME: Every one of these cases needs to worry about sign extension
1305 when the offset is to be used in relative addressing */
1309 fetch_mips_16 (CORE_ADDR pc)
1312 pc &= 0xfffffffe; /* clear the low order bit */
1313 target_read_memory (pc, buf, 2);
1314 return extract_unsigned_integer (buf, 2);
1318 unpack_mips16 (CORE_ADDR pc,
1319 unsigned int extension,
1321 enum mips16_inst_fmts insn_format,
1322 struct upk_mips16 *upk)
1327 switch (insn_format)
1334 value = extended_offset (extension);
1335 value = value << 11; /* rom for the original value */
1336 value |= inst & 0x7ff; /* eleven bits from instruction */
1340 value = inst & 0x7ff;
1341 /* FIXME : Consider sign extension */
1350 { /* A register identifier and an offset */
1351 /* Most of the fields are the same as I type but the
1352 immediate value is of a different length */
1356 value = extended_offset (extension);
1357 value = value << 8; /* from the original instruction */
1358 value |= inst & 0xff; /* eleven bits from instruction */
1359 regx = (extension >> 8) & 0x07; /* or i8 funct */
1360 if (value & 0x4000) /* test the sign bit , bit 26 */
1362 value &= ~0x3fff; /* remove the sign bit */
1368 value = inst & 0xff; /* 8 bits */
1369 regx = (inst >> 8) & 0x07; /* or i8 funct */
1370 /* FIXME: Do sign extension , this format needs it */
1371 if (value & 0x80) /* THIS CONFUSES ME */
1373 value &= 0xef; /* remove the sign bit */
1383 unsigned long value;
1384 unsigned int nexthalf;
1385 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1386 value = value << 16;
1387 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1395 internal_error (__FILE__, __LINE__,
1398 upk->offset = offset;
1405 add_offset_16 (CORE_ADDR pc, int offset)
1407 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1411 extended_mips16_next_pc (CORE_ADDR pc,
1412 unsigned int extension,
1415 int op = (insn >> 11);
1418 case 2: /* Branch */
1421 struct upk_mips16 upk;
1422 unpack_mips16 (pc, extension, insn, itype, &upk);
1423 offset = upk.offset;
1429 pc += (offset << 1) + 2;
1432 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1434 struct upk_mips16 upk;
1435 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1436 pc = add_offset_16 (pc, upk.offset);
1437 if ((insn >> 10) & 0x01) /* Exchange mode */
1438 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1445 struct upk_mips16 upk;
1447 unpack_mips16 (pc, extension, insn, ritype, &upk);
1448 reg = read_signed_register (upk.regx);
1450 pc += (upk.offset << 1) + 2;
1457 struct upk_mips16 upk;
1459 unpack_mips16 (pc, extension, insn, ritype, &upk);
1460 reg = read_signed_register (upk.regx);
1462 pc += (upk.offset << 1) + 2;
1467 case 12: /* I8 Formats btez btnez */
1469 struct upk_mips16 upk;
1471 unpack_mips16 (pc, extension, insn, i8type, &upk);
1472 /* upk.regx contains the opcode */
1473 reg = read_signed_register (24); /* Test register is 24 */
1474 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1475 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1476 /* pc = add_offset_16(pc,upk.offset) ; */
1477 pc += (upk.offset << 1) + 2;
1482 case 29: /* RR Formats JR, JALR, JALR-RA */
1484 struct upk_mips16 upk;
1485 /* upk.fmt = rrtype; */
1490 upk.regx = (insn >> 8) & 0x07;
1491 upk.regy = (insn >> 5) & 0x07;
1499 break; /* Function return instruction */
1505 break; /* BOGUS Guess */
1507 pc = read_signed_register (reg);
1514 /* This is an instruction extension. Fetch the real instruction
1515 (which follows the extension) and decode things based on
1519 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1532 mips16_next_pc (CORE_ADDR pc)
1534 unsigned int insn = fetch_mips_16 (pc);
1535 return extended_mips16_next_pc (pc, 0, insn);
1538 /* The mips_next_pc function supports single_step when the remote
1539 target monitor or stub is not developed enough to do a single_step.
1540 It works by decoding the current instruction and predicting where a
1541 branch will go. This isnt hard because all the data is available.
1542 The MIPS32 and MIPS16 variants are quite different */
1544 mips_next_pc (CORE_ADDR pc)
1547 return mips16_next_pc (pc);
1549 return mips32_next_pc (pc);
1552 /* Set up the 'saved_regs' array. This is a data structure containing
1553 the addresses on the stack where each register has been saved, for
1554 each stack frame. Registers that have not been saved will have
1555 zero here. The stack pointer register is special: rather than the
1556 address where the stack register has been saved,
1557 saved_regs[SP_REGNUM] will have the actual value of the previous
1558 frame's stack register. */
1561 mips_find_saved_regs (struct frame_info *fci)
1564 /* r0 bit means kernel trap */
1566 /* What registers have been saved? Bitmasks. */
1567 unsigned long gen_mask, float_mask;
1568 mips_extra_func_info_t proc_desc;
1570 CORE_ADDR *saved_regs;
1572 if (get_frame_saved_regs (fci) != NULL)
1574 saved_regs = frame_saved_regs_zalloc (fci);
1576 /* If it is the frame for sigtramp, the saved registers are located
1577 in a sigcontext structure somewhere on the stack. If the stack
1578 layout for sigtramp changes we might have to change these
1579 constants and the companion fixup_sigtramp in mdebugread.c */
1580 #ifndef SIGFRAME_BASE
1581 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1582 above the sigtramp frame. */
1583 #define SIGFRAME_BASE MIPS_REGSIZE
1584 /* FIXME! Are these correct?? */
1585 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1586 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1587 #define SIGFRAME_FPREGSAVE_OFF \
1588 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1590 #ifndef SIGFRAME_REG_SIZE
1591 /* FIXME! Is this correct?? */
1592 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1594 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1596 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1598 CORE_ADDR reg_position = (get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1599 + ireg * SIGFRAME_REG_SIZE);
1600 set_reg_offset (saved_regs, ireg, reg_position);
1602 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1604 CORE_ADDR reg_position = (get_frame_base (fci)
1605 + SIGFRAME_FPREGSAVE_OFF
1606 + ireg * SIGFRAME_REG_SIZE);
1607 set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1610 set_reg_offset (saved_regs, PC_REGNUM, get_frame_base (fci) + SIGFRAME_PC_OFF);
1611 /* SP_REGNUM, contains the value and not the address. */
1612 set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1616 proc_desc = get_frame_extra_info (fci)->proc_desc;
1617 if (proc_desc == NULL)
1618 /* I'm not sure how/whether this can happen. Normally when we
1619 can't find a proc_desc, we "synthesize" one using
1620 heuristic_proc_desc and set the saved_regs right away. */
1623 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1624 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1625 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1627 if (/* In any frame other than the innermost or a frame interrupted
1628 by a signal, we assume that all registers have been saved.
1629 This assumes that all register saves in a function happen
1630 before the first function call. */
1631 (get_next_frame (fci) == NULL
1632 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1634 /* In a dummy frame we know exactly where things are saved. */
1635 && !PROC_DESC_IS_DUMMY (proc_desc)
1637 /* Don't bother unless we are inside a function prologue.
1638 Outside the prologue, we know where everything is. */
1640 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1642 /* Not sure exactly what kernel_trap means, but if it means the
1643 kernel saves the registers without a prologue doing it, we
1644 better not examine the prologue to see whether registers
1645 have been saved yet. */
1648 /* We need to figure out whether the registers that the
1649 proc_desc claims are saved have been saved yet. */
1653 /* Bitmasks; set if we have found a save for the register. */
1654 unsigned long gen_save_found = 0;
1655 unsigned long float_save_found = 0;
1658 /* If the address is odd, assume this is MIPS16 code. */
1659 addr = PROC_LOW_ADDR (proc_desc);
1660 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1662 /* Scan through this function's instructions preceding the
1663 current PC, and look for those that save registers. */
1664 while (addr < get_frame_pc (fci))
1666 inst = mips_fetch_instruction (addr);
1667 if (pc_is_mips16 (addr))
1668 mips16_decode_reg_save (inst, &gen_save_found);
1670 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1673 gen_mask = gen_save_found;
1674 float_mask = float_save_found;
1677 /* Fill in the offsets for the registers which gen_mask says were
1680 CORE_ADDR reg_position = (get_frame_base (fci)
1681 + PROC_REG_OFFSET (proc_desc));
1682 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1683 if (gen_mask & 0x80000000)
1685 set_reg_offset (saved_regs, ireg, reg_position);
1686 reg_position -= MIPS_SAVED_REGSIZE;
1690 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse
1691 order of that normally used by gcc. Therefore, we have to fetch
1692 the first instruction of the function, and if it's an entry
1693 instruction that saves $s0 or $s1, correct their saved addresses. */
1694 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1696 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1697 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)
1701 int sreg_count = (inst >> 6) & 3;
1703 /* Check if the ra register was pushed on the stack. */
1704 CORE_ADDR reg_position = (get_frame_base (fci)
1705 + PROC_REG_OFFSET (proc_desc));
1707 reg_position -= MIPS_SAVED_REGSIZE;
1709 /* Check if the s0 and s1 registers were pushed on the
1711 for (reg = 16; reg < sreg_count + 16; reg++)
1713 set_reg_offset (saved_regs, reg, reg_position);
1714 reg_position -= MIPS_SAVED_REGSIZE;
1719 /* Fill in the offsets for the registers which float_mask says were
1722 CORE_ADDR reg_position = (get_frame_base (fci)
1723 + PROC_FREG_OFFSET (proc_desc));
1725 /* Fill in the offsets for the float registers which float_mask
1727 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1728 if (float_mask & 0x80000000)
1730 if (MIPS_SAVED_REGSIZE == 4 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1732 /* On a big endian 32 bit ABI, floating point registers
1733 are paired to form doubles such that the most
1734 significant part is in $f[N+1] and the least
1735 significant in $f[N] vis: $f[N+1] ||| $f[N]. The
1736 registers are also spilled as a pair and stored as a
1739 When little-endian the least significant part is
1740 stored first leading to the memory order $f[N] and
1743 Unfortunatly, when big-endian the most significant
1744 part of the double is stored first, and the least
1745 significant is stored second. This leads to the
1746 registers being ordered in memory as firt $f[N+1] and
1749 For the big-endian case make certain that the
1750 addresses point at the correct (swapped) locations
1751 $f[N] and $f[N+1] pair (keep in mind that
1752 reg_position is decremented each time through the
1755 set_reg_offset (saved_regs, FP0_REGNUM + ireg,
1756 reg_position - MIPS_SAVED_REGSIZE);
1758 set_reg_offset (saved_regs, FP0_REGNUM + ireg,
1759 reg_position + MIPS_SAVED_REGSIZE);
1762 set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1763 reg_position -= MIPS_SAVED_REGSIZE;
1766 set_reg_offset (saved_regs, PC_REGNUM, saved_regs[RA_REGNUM]);
1769 /* SP_REGNUM, contains the value and not the address. */
1770 set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1774 read_next_frame_reg (struct frame_info *fi, int regno)
1776 /* Always a pseudo. */
1777 gdb_assert (regno >= NUM_REGS);
1781 regcache_cooked_read_signed (current_regcache, regno, &val);
1784 else if ((regno % NUM_REGS) == SP_REGNUM)
1785 /* The SP_REGNUM is special, its value is stored in saved_regs.
1786 In fact, it is so special that it can even only be fetched
1787 using a raw register number! Once this code as been converted
1788 to frame-unwind the problem goes away. */
1789 return frame_unwind_register_signed (fi, regno % NUM_REGS);
1791 return frame_unwind_register_signed (fi, regno);
1795 /* mips_addr_bits_remove - remove useless address bits */
1798 mips_addr_bits_remove (CORE_ADDR addr)
1800 if (GDB_TARGET_IS_MIPS64)
1802 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1804 /* This hack is a work-around for existing boards using
1805 PMON, the simulator, and any other 64-bit targets that
1806 doesn't have true 64-bit addressing. On these targets,
1807 the upper 32 bits of addresses are ignored by the
1808 hardware. Thus, the PC or SP are likely to have been
1809 sign extended to all 1s by instruction sequences that
1810 load 32-bit addresses. For example, a typical piece of
1811 code that loads an address is this:
1812 lui $r2, <upper 16 bits>
1813 ori $r2, <lower 16 bits>
1814 But the lui sign-extends the value such that the upper 32
1815 bits may be all 1s. The workaround is simply to mask off
1816 these bits. In the future, gcc may be changed to support
1817 true 64-bit addressing, and this masking will have to be
1819 addr &= (CORE_ADDR) 0xffffffff;
1822 else if (mips_mask_address_p ())
1824 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1825 masking off bits, instead, the actual target should be asking
1826 for the address to be converted to a valid pointer. */
1827 /* Even when GDB is configured for some 32-bit targets
1828 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1829 so CORE_ADDR is 64 bits. So we still have to mask off
1830 useless bits from addresses. */
1831 addr &= (CORE_ADDR) 0xffffffff;
1836 /* mips_software_single_step() is called just before we want to resume
1837 the inferior, if we want to single-step it but there is no hardware
1838 or kernel single-step support (MIPS on GNU/Linux for example). We find
1839 the target of the coming instruction and breakpoint it.
1841 single_step is also called just after the inferior stops. If we had
1842 set up a simulated single-step, we undo our damage. */
1845 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1847 static CORE_ADDR next_pc;
1848 typedef char binsn_quantum[BREAKPOINT_MAX];
1849 static binsn_quantum break_mem;
1852 if (insert_breakpoints_p)
1854 pc = read_register (PC_REGNUM);
1855 next_pc = mips_next_pc (pc);
1857 target_insert_breakpoint (next_pc, break_mem);
1860 target_remove_breakpoint (next_pc, break_mem);
1864 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1869 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1870 : get_next_frame (prev)
1871 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1873 tmp = SKIP_TRAMPOLINE_CODE (pc);
1874 return tmp ? tmp : pc;
1879 mips_frame_saved_pc (struct frame_info *frame)
1883 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1886 /* Always unwind the cooked PC register value. */
1887 frame_unwind_signed_register (frame, NUM_REGS + PC_REGNUM, &tmp);
1892 mips_extra_func_info_t proc_desc
1893 = get_frame_extra_info (frame)->proc_desc;
1894 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1895 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1898 /* We have to get the saved pc from the sigcontext if it is
1899 a signal handler frame. */
1900 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME ? PC_REGNUM
1901 : proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1902 saved_pc = read_next_frame_reg (frame, NUM_REGS + pcreg);
1905 return ADDR_BITS_REMOVE (saved_pc);
1908 static struct mips_extra_func_info temp_proc_desc;
1910 /* This hack will go away once the get_prev_frame() code has been
1911 modified to set the frame's type first. That is BEFORE init extra
1912 frame info et.al. is called. This is because it will become
1913 possible to skip the init extra info call for sigtramp and dummy
1915 static CORE_ADDR *temp_saved_regs;
1917 /* Set a register's saved stack address in temp_saved_regs. If an
1918 address has already been set for this register, do nothing; this
1919 way we will only recognize the first save of a given register in a
1922 For simplicity, save the address in both [0 .. NUM_REGS) and
1923 [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range
1924 is used as it is only second range (the ABI instead of ISA
1925 registers) that comes into play when finding saved registers in a
1929 set_reg_offset (CORE_ADDR *saved_regs, int regno, CORE_ADDR offset)
1931 if (saved_regs[regno] == 0)
1933 saved_regs[regno + 0 * NUM_REGS] = offset;
1934 saved_regs[regno + 1 * NUM_REGS] = offset;
1939 /* Test whether the PC points to the return instruction at the
1940 end of a function. */
1943 mips_about_to_return (CORE_ADDR pc)
1945 if (pc_is_mips16 (pc))
1946 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1947 generates a "jr $ra"; other times it generates code to load
1948 the return address from the stack to an accessible register (such
1949 as $a3), then a "jr" using that register. This second case
1950 is almost impossible to distinguish from an indirect jump
1951 used for switch statements, so we don't even try. */
1952 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1954 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1958 /* This fencepost looks highly suspicious to me. Removing it also
1959 seems suspicious as it could affect remote debugging across serial
1963 heuristic_proc_start (CORE_ADDR pc)
1970 pc = ADDR_BITS_REMOVE (pc);
1972 fence = start_pc - heuristic_fence_post;
1976 if (heuristic_fence_post == UINT_MAX
1977 || fence < VM_MIN_ADDRESS)
1978 fence = VM_MIN_ADDRESS;
1980 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1982 /* search back for previous return */
1983 for (start_pc -= instlen;; start_pc -= instlen)
1984 if (start_pc < fence)
1986 /* It's not clear to me why we reach this point when
1987 stop_soon, but with this test, at least we
1988 don't print out warnings for every child forked (eg, on
1990 if (stop_soon == NO_STOP_QUIETLY)
1992 static int blurb_printed = 0;
1994 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1999 /* This actually happens frequently in embedded
2000 development, when you first connect to a board
2001 and your stack pointer and pc are nowhere in
2002 particular. This message needs to give people
2003 in that situation enough information to
2004 determine that it's no big deal. */
2005 printf_filtered ("\n\
2006 GDB is unable to find the start of the function at 0x%s\n\
2007 and thus can't determine the size of that function's stack frame.\n\
2008 This means that GDB may be unable to access that stack frame, or\n\
2009 the frames below it.\n\
2010 This problem is most likely caused by an invalid program counter or\n\
2012 However, if you think GDB should simply search farther back\n\
2013 from 0x%s for code which looks like the beginning of a\n\
2014 function, you can increase the range of the search using the `set\n\
2015 heuristic-fence-post' command.\n",
2016 paddr_nz (pc), paddr_nz (pc));
2023 else if (pc_is_mips16 (start_pc))
2025 unsigned short inst;
2027 /* On MIPS16, any one of the following is likely to be the
2028 start of a function:
2032 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
2033 inst = mips_fetch_instruction (start_pc);
2034 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2035 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2036 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2037 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
2039 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2040 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2045 else if (mips_about_to_return (start_pc))
2047 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
2054 /* Fetch the immediate value from a MIPS16 instruction.
2055 If the previous instruction was an EXTEND, use it to extend
2056 the upper bits of the immediate value. This is a helper function
2057 for mips16_heuristic_proc_desc. */
2060 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
2061 unsigned short inst, /* current instruction */
2062 int nbits, /* number of bits in imm field */
2063 int scale, /* scale factor to be applied to imm */
2064 int is_signed) /* is the imm field signed? */
2068 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
2070 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
2071 if (offset & 0x8000) /* check for negative extend */
2072 offset = 0 - (0x10000 - (offset & 0xffff));
2073 return offset | (inst & 0x1f);
2077 int max_imm = 1 << nbits;
2078 int mask = max_imm - 1;
2079 int sign_bit = max_imm >> 1;
2081 offset = inst & mask;
2082 if (is_signed && (offset & sign_bit))
2083 offset = 0 - (max_imm - offset);
2084 return offset * scale;
2089 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
2090 stream from start_pc to limit_pc. */
2093 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2094 struct frame_info *next_frame, CORE_ADDR sp)
2097 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
2098 unsigned short prev_inst = 0; /* saved copy of previous instruction */
2099 unsigned inst = 0; /* current instruction */
2100 unsigned entry_inst = 0; /* the entry instruction */
2103 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
2104 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2106 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
2108 /* Save the previous instruction. If it's an EXTEND, we'll extract
2109 the immediate offset extension from it in mips16_get_imm. */
2112 /* Fetch and decode the instruction. */
2113 inst = (unsigned short) mips_fetch_instruction (cur_pc);
2114 if ((inst & 0xff00) == 0x6300 /* addiu sp */
2115 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2117 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
2118 if (offset < 0) /* negative stack adjustment? */
2119 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
2121 /* Exit loop if a positive stack adjustment is found, which
2122 usually means that the stack cleanup code in the function
2123 epilogue is reached. */
2126 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
2128 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2129 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
2130 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2131 set_reg_offset (temp_saved_regs, reg, sp + offset);
2133 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
2135 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2136 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2137 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2138 set_reg_offset (temp_saved_regs, reg, sp + offset);
2140 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2142 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2143 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2144 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2146 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2148 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2149 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2150 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2152 else if (inst == 0x673d) /* move $s1, $sp */
2155 PROC_FRAME_REG (&temp_proc_desc) = 17;
2157 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2159 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2160 frame_addr = sp + offset;
2161 PROC_FRAME_REG (&temp_proc_desc) = 17;
2162 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2164 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2166 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2167 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2168 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2169 set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2171 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2173 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2174 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2175 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2176 set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2178 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2179 entry_inst = inst; /* save for later processing */
2180 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2181 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2184 /* The entry instruction is typically the first instruction in a function,
2185 and it stores registers at offsets relative to the value of the old SP
2186 (before the prologue). But the value of the sp parameter to this
2187 function is the new SP (after the prologue has been executed). So we
2188 can't calculate those offsets until we've seen the entire prologue,
2189 and can calculate what the old SP must have been. */
2190 if (entry_inst != 0)
2192 int areg_count = (entry_inst >> 8) & 7;
2193 int sreg_count = (entry_inst >> 6) & 3;
2195 /* The entry instruction always subtracts 32 from the SP. */
2196 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2198 /* Now we can calculate what the SP must have been at the
2199 start of the function prologue. */
2200 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2202 /* Check if a0-a3 were saved in the caller's argument save area. */
2203 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2205 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2206 set_reg_offset (temp_saved_regs, reg, sp + offset);
2207 offset += MIPS_SAVED_REGSIZE;
2210 /* Check if the ra register was pushed on the stack. */
2212 if (entry_inst & 0x20)
2214 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2215 set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2216 offset -= MIPS_SAVED_REGSIZE;
2219 /* Check if the s0 and s1 registers were pushed on the stack. */
2220 for (reg = 16; reg < sreg_count + 16; reg++)
2222 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2223 set_reg_offset (temp_saved_regs, reg, sp + offset);
2224 offset -= MIPS_SAVED_REGSIZE;
2230 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2231 struct frame_info *next_frame, CORE_ADDR sp)
2234 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2236 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2237 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2238 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2239 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2240 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2242 unsigned long inst, high_word, low_word;
2245 /* Fetch the instruction. */
2246 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2248 /* Save some code by pre-extracting some useful fields. */
2249 high_word = (inst >> 16) & 0xffff;
2250 low_word = inst & 0xffff;
2251 reg = high_word & 0x1f;
2253 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2254 || high_word == 0x23bd /* addi $sp,$sp,-i */
2255 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2257 if (low_word & 0x8000) /* negative stack adjustment? */
2258 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2260 /* Exit loop if a positive stack adjustment is found, which
2261 usually means that the stack cleanup code in the function
2262 epilogue is reached. */
2265 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2267 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2268 set_reg_offset (temp_saved_regs, reg, sp + low_word);
2270 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2272 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2273 but the register size used is only 32 bits. Make the address
2274 for the saved register point to the lower 32 bits. */
2275 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2276 set_reg_offset (temp_saved_regs, reg, sp + low_word + 8 - MIPS_REGSIZE);
2278 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2280 /* Old gcc frame, r30 is virtual frame pointer. */
2281 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2282 frame_addr = sp + low_word;
2283 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2285 unsigned alloca_adjust;
2286 PROC_FRAME_REG (&temp_proc_desc) = 30;
2287 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2288 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2289 if (alloca_adjust > 0)
2291 /* FP > SP + frame_size. This may be because
2292 * of an alloca or somethings similar.
2293 * Fix sp to "pre-alloca" value, and try again.
2295 sp += alloca_adjust;
2300 /* move $30,$sp. With different versions of gas this will be either
2301 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2302 Accept any one of these. */
2303 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2305 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2306 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2308 unsigned alloca_adjust;
2309 PROC_FRAME_REG (&temp_proc_desc) = 30;
2310 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2311 alloca_adjust = (unsigned) (frame_addr - sp);
2312 if (alloca_adjust > 0)
2314 /* FP > SP + frame_size. This may be because
2315 * of an alloca or somethings similar.
2316 * Fix sp to "pre-alloca" value, and try again.
2318 sp += alloca_adjust;
2323 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2325 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2326 set_reg_offset (temp_saved_regs, reg, frame_addr + low_word);
2331 static mips_extra_func_info_t
2332 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2333 struct frame_info *next_frame, int cur_frame)
2338 sp = read_next_frame_reg (next_frame, NUM_REGS + SP_REGNUM);
2344 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2345 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2346 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2347 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2348 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2349 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2351 if (start_pc + 200 < limit_pc)
2352 limit_pc = start_pc + 200;
2353 if (pc_is_mips16 (start_pc))
2354 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2356 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2357 return &temp_proc_desc;
2360 struct mips_objfile_private
2366 /* Global used to communicate between non_heuristic_proc_desc and
2367 compare_pdr_entries within qsort (). */
2368 static bfd *the_bfd;
2371 compare_pdr_entries (const void *a, const void *b)
2373 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2374 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2378 else if (lhs == rhs)
2384 static mips_extra_func_info_t
2385 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2387 CORE_ADDR startaddr;
2388 mips_extra_func_info_t proc_desc;
2389 struct block *b = block_for_pc (pc);
2391 struct obj_section *sec;
2392 struct mips_objfile_private *priv;
2394 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2397 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2399 *addrptr = startaddr;
2403 sec = find_pc_section (pc);
2406 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2408 /* Search the ".pdr" section generated by GAS. This includes most of
2409 the information normally found in ECOFF PDRs. */
2411 the_bfd = sec->objfile->obfd;
2413 && (the_bfd->format == bfd_object
2414 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2415 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2417 /* Right now GAS only outputs the address as a four-byte sequence.
2418 This means that we should not bother with this method on 64-bit
2419 targets (until that is fixed). */
2421 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2422 sizeof (struct mips_objfile_private));
2424 sec->objfile->obj_private = priv;
2426 else if (priv == NULL)
2430 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2431 sizeof (struct mips_objfile_private));
2433 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2436 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2437 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2439 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2440 priv->contents, 0, priv->size);
2442 /* In general, the .pdr section is sorted. However, in the
2443 presence of multiple code sections (and other corner cases)
2444 it can become unsorted. Sort it so that we can use a faster
2446 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2451 sec->objfile->obj_private = priv;
2455 if (priv->size != 0)
2461 high = priv->size / 32;
2467 mid = (low + high) / 2;
2469 ptr = priv->contents + mid * 32;
2470 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2471 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2472 SECT_OFF_TEXT (sec->objfile));
2473 if (pdr_pc == startaddr)
2475 if (pdr_pc > startaddr)
2480 while (low != high);
2484 struct symbol *sym = find_pc_function (pc);
2486 /* Fill in what we need of the proc_desc. */
2487 proc_desc = (mips_extra_func_info_t)
2488 obstack_alloc (&sec->objfile->psymbol_obstack,
2489 sizeof (struct mips_extra_func_info));
2490 PROC_LOW_ADDR (proc_desc) = startaddr;
2492 /* Only used for dummy frames. */
2493 PROC_HIGH_ADDR (proc_desc) = 0;
2495 PROC_FRAME_OFFSET (proc_desc)
2496 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2497 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2499 PROC_FRAME_ADJUST (proc_desc) = 0;
2500 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2502 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2504 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2506 PROC_FREG_OFFSET (proc_desc)
2507 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2508 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2510 proc_desc->pdr.isym = (long) sym;
2520 if (startaddr > BLOCK_START (b))
2522 /* This is the "pathological" case referred to in a comment in
2523 print_frame_info. It might be better to move this check into
2528 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
2530 /* If we never found a PDR for this function in symbol reading, then
2531 examine prologues to find the information. */
2534 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2535 if (PROC_FRAME_REG (proc_desc) == -1)
2545 static mips_extra_func_info_t
2546 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2548 mips_extra_func_info_t proc_desc;
2549 CORE_ADDR startaddr = 0;
2551 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2555 /* IF this is the topmost frame AND
2556 * (this proc does not have debugging information OR
2557 * the PC is in the procedure prologue)
2558 * THEN create a "heuristic" proc_desc (by analyzing
2559 * the actual code) to replace the "official" proc_desc.
2561 if (next_frame == NULL)
2563 struct symtab_and_line val;
2564 struct symbol *proc_symbol =
2565 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2569 val = find_pc_line (BLOCK_START
2570 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2572 val.pc = val.end ? val.end : pc;
2574 if (!proc_symbol || pc < val.pc)
2576 mips_extra_func_info_t found_heuristic =
2577 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2578 pc, next_frame, cur_frame);
2579 if (found_heuristic)
2580 proc_desc = found_heuristic;
2586 /* Is linked_proc_desc_table really necessary? It only seems to be used
2587 by procedure call dummys. However, the procedures being called ought
2588 to have their own proc_descs, and even if they don't,
2589 heuristic_proc_desc knows how to create them! */
2591 register struct linked_proc_info *link;
2593 for (link = linked_proc_desc_table; link; link = link->next)
2594 if (PROC_LOW_ADDR (&link->info) <= pc
2595 && PROC_HIGH_ADDR (&link->info) > pc)
2599 startaddr = heuristic_proc_start (pc);
2602 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2608 get_frame_pointer (struct frame_info *frame,
2609 mips_extra_func_info_t proc_desc)
2611 return (read_next_frame_reg (frame, NUM_REGS + PROC_FRAME_REG (proc_desc))
2612 + PROC_FRAME_OFFSET (proc_desc)
2613 - PROC_FRAME_ADJUST (proc_desc));
2616 static mips_extra_func_info_t cached_proc_desc;
2619 mips_frame_chain (struct frame_info *frame)
2621 mips_extra_func_info_t proc_desc;
2623 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2625 if (saved_pc == 0 || inside_entry_file (saved_pc))
2628 /* Check if the PC is inside a call stub. If it is, fetch the
2629 PC of the caller of that stub. */
2630 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2633 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2635 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2636 is well, frame->frame the bottom of the current frame will
2637 contain that value. */
2638 return get_frame_base (frame);
2641 /* Look up the procedure descriptor for this PC. */
2642 proc_desc = find_proc_desc (saved_pc, frame, 1);
2646 cached_proc_desc = proc_desc;
2648 /* If no frame pointer and frame size is zero, we must be at end
2649 of stack (or otherwise hosed). If we don't check frame size,
2650 we loop forever if we see a zero size frame. */
2651 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2652 && PROC_FRAME_OFFSET (proc_desc) == 0
2653 /* The previous frame from a sigtramp frame might be frameless
2654 and have frame size zero. */
2655 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2656 /* For a generic dummy frame, let get_frame_pointer() unwind a
2657 register value saved as part of the dummy frame call. */
2658 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2661 return get_frame_pointer (frame, proc_desc);
2665 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2668 mips_extra_func_info_t proc_desc;
2670 if (get_frame_type (fci) == DUMMY_FRAME)
2673 /* Use proc_desc calculated in frame_chain. When there is no
2674 next frame, i.e, get_next_frame (fci) == NULL, we call
2675 find_proc_desc () to calculate it, passing an explicit
2676 NULL as the frame parameter. */
2678 get_next_frame (fci)
2680 : find_proc_desc (get_frame_pc (fci),
2681 NULL /* i.e, get_next_frame (fci) */,
2684 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2686 deprecated_set_frame_saved_regs_hack (fci, NULL);
2687 get_frame_extra_info (fci)->proc_desc =
2688 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2691 /* Fixup frame-pointer - only needed for top frame */
2692 /* This may not be quite right, if proc has a real frame register.
2693 Get the value of the frame relative sp, procedure might have been
2694 interrupted by a signal at it's very start. */
2695 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2696 && !PROC_DESC_IS_DUMMY (proc_desc))
2697 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), NUM_REGS + SP_REGNUM));
2698 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2699 /* Do not ``fix'' fci->frame. It will have the value of the
2700 generic dummy frame's top-of-stack (since the draft
2701 fci->frame is obtained by returning the unwound stack
2702 pointer) and that is what we want. That way the fci->frame
2703 value will match the top-of-stack value that was saved as
2704 part of the dummy frames data. */
2707 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2709 if (proc_desc == &temp_proc_desc)
2713 /* Do not set the saved registers for a sigtramp frame,
2714 mips_find_saved_registers will do that for us. We can't
2715 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2717 /* FIXME: cagney/2002-11-18: This problem will go away once
2718 frame.c:get_prev_frame() is modified to set the frame's
2719 type before calling functions like this. */
2720 find_pc_partial_function (get_frame_pc (fci), &name,
2721 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2722 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2724 frame_saved_regs_zalloc (fci);
2725 /* Set value of previous frame's stack pointer.
2726 Remember that saved_regs[SP_REGNUM] is special in
2727 that it contains the value of the stack pointer
2728 register. The other saved_regs values are addresses
2729 (in the inferior) at which a given register's value
2731 set_reg_offset (temp_saved_regs, SP_REGNUM,
2732 get_frame_base (fci));
2733 set_reg_offset (temp_saved_regs, PC_REGNUM,
2734 temp_saved_regs[RA_REGNUM]);
2735 memcpy (get_frame_saved_regs (fci), temp_saved_regs,
2736 SIZEOF_FRAME_SAVED_REGS);
2740 /* hack: if argument regs are saved, guess these contain args */
2741 /* assume we can't tell how many args for now */
2742 get_frame_extra_info (fci)->num_args = -1;
2743 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2745 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2747 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2754 /* MIPS stack frames are almost impenetrable. When execution stops,
2755 we basically have to look at symbol information for the function
2756 that we stopped in, which tells us *which* register (if any) is
2757 the base of the frame pointer, and what offset from that register
2758 the frame itself is at.
2760 This presents a problem when trying to examine a stack in memory
2761 (that isn't executing at the moment), using the "frame" command. We
2762 don't have a PC, nor do we have any registers except SP.
2764 This routine takes two arguments, SP and PC, and tries to make the
2765 cached frames look as if these two arguments defined a frame on the
2766 cache. This allows the rest of info frame to extract the important
2767 arguments without difficulty. */
2770 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2773 error ("MIPS frame specifications require two arguments: sp and pc");
2775 return create_new_frame (argv[0], argv[1]);
2778 /* According to the current ABI, should the type be passed in a
2779 floating-point register (assuming that there is space)? When there
2780 is no FPU, FP are not even considered as possibile candidates for
2781 FP registers and, consequently this returns false - forces FP
2782 arguments into integer registers. */
2785 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2787 return ((typecode == TYPE_CODE_FLT
2789 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2790 && TYPE_NFIELDS (arg_type) == 1
2791 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2792 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2795 /* On o32, argument passing in GPRs depends on the alignment of the type being
2796 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2799 mips_type_needs_double_align (struct type *type)
2801 enum type_code typecode = TYPE_CODE (type);
2803 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2805 else if (typecode == TYPE_CODE_STRUCT)
2807 if (TYPE_NFIELDS (type) < 1)
2809 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2811 else if (typecode == TYPE_CODE_UNION)
2815 n = TYPE_NFIELDS (type);
2816 for (i = 0; i < n; i++)
2817 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2824 /* Macros to round N up or down to the next A boundary;
2825 A must be a power of two. */
2827 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2828 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2830 /* Adjust the address downward (direction of stack growth) so that it
2831 is correctly aligned for a new stack frame. */
2833 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2835 return ROUND_DOWN (addr, 16);
2839 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2840 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2841 struct value **args, CORE_ADDR sp, int struct_return,
2842 CORE_ADDR struct_addr)
2848 int stack_offset = 0;
2850 /* For shared libraries, "t9" needs to point at the function
2852 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2854 /* Set the return address register to point to the entry point of
2855 the program, where a breakpoint lies in wait. */
2856 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2858 /* First ensure that the stack and structure return address (if any)
2859 are properly aligned. The stack has to be at least 64-bit
2860 aligned even on 32-bit machines, because doubles must be 64-bit
2861 aligned. For n32 and n64, stack frames need to be 128-bit
2862 aligned, so we round to this widest known alignment. */
2864 sp = ROUND_DOWN (sp, 16);
2865 struct_addr = ROUND_DOWN (struct_addr, 16);
2867 /* Now make space on the stack for the args. We allocate more
2868 than necessary for EABI, because the first few arguments are
2869 passed in registers, but that's OK. */
2870 for (argnum = 0; argnum < nargs; argnum++)
2871 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2872 MIPS_STACK_ARGSIZE);
2873 sp -= ROUND_UP (len, 16);
2876 fprintf_unfiltered (gdb_stdlog,
2877 "mips_eabi_push_dummy_call: sp=0x%s allocated %d\n",
2878 paddr_nz (sp), ROUND_UP (len, 16));
2880 /* Initialize the integer and float register pointers. */
2882 float_argreg = FPA0_REGNUM;
2884 /* The struct_return pointer occupies the first parameter-passing reg. */
2888 fprintf_unfiltered (gdb_stdlog,
2889 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2890 argreg, paddr_nz (struct_addr));
2891 write_register (argreg++, struct_addr);
2894 /* Now load as many as possible of the first arguments into
2895 registers, and push the rest onto the stack. Loop thru args
2896 from first to last. */
2897 for (argnum = 0; argnum < nargs; argnum++)
2900 char valbuf[MAX_REGISTER_SIZE];
2901 struct value *arg = args[argnum];
2902 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2903 int len = TYPE_LENGTH (arg_type);
2904 enum type_code typecode = TYPE_CODE (arg_type);
2907 fprintf_unfiltered (gdb_stdlog,
2908 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2909 argnum + 1, len, (int) typecode);
2911 /* The EABI passes structures that do not fit in a register by
2913 if (len > MIPS_SAVED_REGSIZE
2914 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2916 store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2917 typecode = TYPE_CODE_PTR;
2918 len = MIPS_SAVED_REGSIZE;
2921 fprintf_unfiltered (gdb_stdlog, " push");
2924 val = (char *) VALUE_CONTENTS (arg);
2926 /* 32-bit ABIs always start floating point arguments in an
2927 even-numbered floating point register. Round the FP register
2928 up before the check to see if there are any FP registers
2929 left. Non MIPS_EABI targets also pass the FP in the integer
2930 registers so also round up normal registers. */
2931 if (!FP_REGISTER_DOUBLE
2932 && fp_register_arg_p (typecode, arg_type))
2934 if ((float_argreg & 1))
2938 /* Floating point arguments passed in registers have to be
2939 treated specially. On 32-bit architectures, doubles
2940 are passed in register pairs; the even register gets
2941 the low word, and the odd register gets the high word.
2942 On non-EABI processors, the first two floating point arguments are
2943 also copied to general registers, because MIPS16 functions
2944 don't use float registers for arguments. This duplication of
2945 arguments in general registers can't hurt non-MIPS16 functions
2946 because those registers are normally skipped. */
2947 /* MIPS_EABI squeezes a struct that contains a single floating
2948 point value into an FP register instead of pushing it onto the
2950 if (fp_register_arg_p (typecode, arg_type)
2951 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2953 if (!FP_REGISTER_DOUBLE && len == 8)
2955 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2956 unsigned long regval;
2958 /* Write the low word of the double to the even register(s). */
2959 regval = extract_unsigned_integer (val + low_offset, 4);
2961 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2962 float_argreg, phex (regval, 4));
2963 write_register (float_argreg++, regval);
2965 /* Write the high word of the double to the odd register(s). */
2966 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2968 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2969 float_argreg, phex (regval, 4));
2970 write_register (float_argreg++, regval);
2974 /* This is a floating point value that fits entirely
2975 in a single register. */
2976 /* On 32 bit ABI's the float_argreg is further adjusted
2977 above to ensure that it is even register aligned. */
2978 LONGEST regval = extract_unsigned_integer (val, len);
2980 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2981 float_argreg, phex (regval, len));
2982 write_register (float_argreg++, regval);
2987 /* Copy the argument to general registers or the stack in
2988 register-sized pieces. Large arguments are split between
2989 registers and stack. */
2990 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2991 are treated specially: Irix cc passes them in registers
2992 where gcc sometimes puts them on the stack. For maximum
2993 compatibility, we will put them in both places. */
2994 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2995 (len % MIPS_SAVED_REGSIZE != 0));
2997 /* Note: Floating-point values that didn't fit into an FP
2998 register are only written to memory. */
3001 /* Remember if the argument was written to the stack. */
3002 int stack_used_p = 0;
3004 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3007 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3010 /* Write this portion of the argument to the stack. */
3011 if (argreg > MIPS_LAST_ARG_REGNUM
3013 || fp_register_arg_p (typecode, arg_type))
3015 /* Should shorter than int integer values be
3016 promoted to int before being stored? */
3017 int longword_offset = 0;
3020 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3022 if (MIPS_STACK_ARGSIZE == 8 &&
3023 (typecode == TYPE_CODE_INT ||
3024 typecode == TYPE_CODE_PTR ||
3025 typecode == TYPE_CODE_FLT) && len <= 4)
3026 longword_offset = MIPS_STACK_ARGSIZE - len;
3027 else if ((typecode == TYPE_CODE_STRUCT ||
3028 typecode == TYPE_CODE_UNION) &&
3029 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
3030 longword_offset = MIPS_STACK_ARGSIZE - len;
3035 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3036 paddr_nz (stack_offset));
3037 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3038 paddr_nz (longword_offset));
3041 addr = sp + stack_offset + longword_offset;
3046 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3048 for (i = 0; i < partial_len; i++)
3050 fprintf_unfiltered (gdb_stdlog, "%02x",
3054 write_memory (addr, val, partial_len);
3057 /* Note!!! This is NOT an else clause. Odd sized
3058 structs may go thru BOTH paths. Floating point
3059 arguments will not. */
3060 /* Write this portion of the argument to a general
3061 purpose register. */
3062 if (argreg <= MIPS_LAST_ARG_REGNUM
3063 && !fp_register_arg_p (typecode, arg_type))
3065 LONGEST regval = extract_unsigned_integer (val, partial_len);
3068 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3070 phex (regval, MIPS_SAVED_REGSIZE));
3071 write_register (argreg, regval);
3078 /* Compute the the offset into the stack at which we
3079 will copy the next parameter.
3081 In the new EABI (and the NABI32), the stack_offset
3082 only needs to be adjusted when it has been used. */
3085 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3089 fprintf_unfiltered (gdb_stdlog, "\n");
3092 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3094 /* Return adjusted stack pointer. */
3098 /* N32/N64 version of push_dummy_call. */
3101 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3102 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3103 struct value **args, CORE_ADDR sp, int struct_return,
3104 CORE_ADDR struct_addr)
3110 int stack_offset = 0;
3112 /* For shared libraries, "t9" needs to point at the function
3114 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3116 /* Set the return address register to point to the entry point of
3117 the program, where a breakpoint lies in wait. */
3118 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3120 /* First ensure that the stack and structure return address (if any)
3121 are properly aligned. The stack has to be at least 64-bit
3122 aligned even on 32-bit machines, because doubles must be 64-bit
3123 aligned. For n32 and n64, stack frames need to be 128-bit
3124 aligned, so we round to this widest known alignment. */
3126 sp = ROUND_DOWN (sp, 16);
3127 struct_addr = ROUND_DOWN (struct_addr, 16);
3129 /* Now make space on the stack for the args. */
3130 for (argnum = 0; argnum < nargs; argnum++)
3131 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3132 MIPS_STACK_ARGSIZE);
3133 sp -= ROUND_UP (len, 16);
3136 fprintf_unfiltered (gdb_stdlog,
3137 "mips_n32n64_push_dummy_call: sp=0x%s allocated %d\n",
3138 paddr_nz (sp), ROUND_UP (len, 16));
3140 /* Initialize the integer and float register pointers. */
3142 float_argreg = FPA0_REGNUM;
3144 /* The struct_return pointer occupies the first parameter-passing reg. */
3148 fprintf_unfiltered (gdb_stdlog,
3149 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3150 argreg, paddr_nz (struct_addr));
3151 write_register (argreg++, struct_addr);
3154 /* Now load as many as possible of the first arguments into
3155 registers, and push the rest onto the stack. Loop thru args
3156 from first to last. */
3157 for (argnum = 0; argnum < nargs; argnum++)
3160 char valbuf[MAX_REGISTER_SIZE];
3161 struct value *arg = args[argnum];
3162 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3163 int len = TYPE_LENGTH (arg_type);
3164 enum type_code typecode = TYPE_CODE (arg_type);
3167 fprintf_unfiltered (gdb_stdlog,
3168 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3169 argnum + 1, len, (int) typecode);
3171 val = (char *) VALUE_CONTENTS (arg);
3173 if (fp_register_arg_p (typecode, arg_type)
3174 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3176 /* This is a floating point value that fits entirely
3177 in a single register. */
3178 /* On 32 bit ABI's the float_argreg is further adjusted
3179 above to ensure that it is even register aligned. */
3180 LONGEST regval = extract_unsigned_integer (val, len);
3182 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3183 float_argreg, phex (regval, len));
3184 write_register (float_argreg++, regval);
3187 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3188 argreg, phex (regval, len));
3189 write_register (argreg, regval);
3194 /* Copy the argument to general registers or the stack in
3195 register-sized pieces. Large arguments are split between
3196 registers and stack. */
3197 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3198 are treated specially: Irix cc passes them in registers
3199 where gcc sometimes puts them on the stack. For maximum
3200 compatibility, we will put them in both places. */
3201 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3202 (len % MIPS_SAVED_REGSIZE != 0));
3203 /* Note: Floating-point values that didn't fit into an FP
3204 register are only written to memory. */
3207 /* Rememer if the argument was written to the stack. */
3208 int stack_used_p = 0;
3209 int partial_len = len < MIPS_SAVED_REGSIZE ?
3210 len : MIPS_SAVED_REGSIZE;
3213 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3216 /* Write this portion of the argument to the stack. */
3217 if (argreg > MIPS_LAST_ARG_REGNUM
3219 || fp_register_arg_p (typecode, arg_type))
3221 /* Should shorter than int integer values be
3222 promoted to int before being stored? */
3223 int longword_offset = 0;
3226 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3228 if (MIPS_STACK_ARGSIZE == 8 &&
3229 (typecode == TYPE_CODE_INT ||
3230 typecode == TYPE_CODE_PTR ||
3231 typecode == TYPE_CODE_FLT) && len <= 4)
3232 longword_offset = MIPS_STACK_ARGSIZE - len;
3237 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3238 paddr_nz (stack_offset));
3239 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3240 paddr_nz (longword_offset));
3243 addr = sp + stack_offset + longword_offset;
3248 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3250 for (i = 0; i < partial_len; i++)
3252 fprintf_unfiltered (gdb_stdlog, "%02x",
3256 write_memory (addr, val, partial_len);
3259 /* Note!!! This is NOT an else clause. Odd sized
3260 structs may go thru BOTH paths. Floating point
3261 arguments will not. */
3262 /* Write this portion of the argument to a general
3263 purpose register. */
3264 if (argreg <= MIPS_LAST_ARG_REGNUM
3265 && !fp_register_arg_p (typecode, arg_type))
3267 LONGEST regval = extract_unsigned_integer (val, partial_len);
3269 /* A non-floating-point argument being passed in a
3270 general register. If a struct or union, and if
3271 the remaining length is smaller than the register
3272 size, we have to adjust the register value on
3275 It does not seem to be necessary to do the
3276 same for integral types.
3278 cagney/2001-07-23: gdb/179: Also, GCC, when
3279 outputting LE O32 with sizeof (struct) <
3280 MIPS_SAVED_REGSIZE, generates a left shift as
3281 part of storing the argument in a register a
3282 register (the left shift isn't generated when
3283 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3284 is quite possible that this is GCC contradicting
3285 the LE/O32 ABI, GDB has not been adjusted to
3286 accommodate this. Either someone needs to
3287 demonstrate that the LE/O32 ABI specifies such a
3288 left shift OR this new ABI gets identified as
3289 such and GDB gets tweaked accordingly. */
3291 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3292 && partial_len < MIPS_SAVED_REGSIZE
3293 && (typecode == TYPE_CODE_STRUCT ||
3294 typecode == TYPE_CODE_UNION))
3295 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3299 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3301 phex (regval, MIPS_SAVED_REGSIZE));
3302 write_register (argreg, regval);
3309 /* Compute the the offset into the stack at which we
3310 will copy the next parameter.
3312 In N32 (N64?), the stack_offset only needs to be
3313 adjusted when it has been used. */
3316 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3320 fprintf_unfiltered (gdb_stdlog, "\n");
3323 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3325 /* Return adjusted stack pointer. */
3329 /* O32 version of push_dummy_call. */
3332 mips_o32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3333 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3334 struct value **args, CORE_ADDR sp, int struct_return,
3335 CORE_ADDR struct_addr)
3341 int stack_offset = 0;
3343 /* For shared libraries, "t9" needs to point at the function
3345 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3347 /* Set the return address register to point to the entry point of
3348 the program, where a breakpoint lies in wait. */
3349 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3351 /* First ensure that the stack and structure return address (if any)
3352 are properly aligned. The stack has to be at least 64-bit
3353 aligned even on 32-bit machines, because doubles must be 64-bit
3354 aligned. For n32 and n64, stack frames need to be 128-bit
3355 aligned, so we round to this widest known alignment. */
3357 sp = ROUND_DOWN (sp, 16);
3358 struct_addr = ROUND_DOWN (struct_addr, 16);
3360 /* Now make space on the stack for the args. */
3361 for (argnum = 0; argnum < nargs; argnum++)
3362 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3363 MIPS_STACK_ARGSIZE);
3364 sp -= ROUND_UP (len, 16);
3367 fprintf_unfiltered (gdb_stdlog,
3368 "mips_o32_push_dummy_call: sp=0x%s allocated %d\n",
3369 paddr_nz (sp), ROUND_UP (len, 16));
3371 /* Initialize the integer and float register pointers. */
3373 float_argreg = FPA0_REGNUM;
3375 /* The struct_return pointer occupies the first parameter-passing reg. */
3379 fprintf_unfiltered (gdb_stdlog,
3380 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3381 argreg, paddr_nz (struct_addr));
3382 write_register (argreg++, struct_addr);
3383 stack_offset += MIPS_STACK_ARGSIZE;
3386 /* Now load as many as possible of the first arguments into
3387 registers, and push the rest onto the stack. Loop thru args
3388 from first to last. */
3389 for (argnum = 0; argnum < nargs; argnum++)
3392 char valbuf[MAX_REGISTER_SIZE];
3393 struct value *arg = args[argnum];
3394 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3395 int len = TYPE_LENGTH (arg_type);
3396 enum type_code typecode = TYPE_CODE (arg_type);
3399 fprintf_unfiltered (gdb_stdlog,
3400 "mips_o32_push_dummy_call: %d len=%d type=%d",
3401 argnum + 1, len, (int) typecode);
3403 val = (char *) VALUE_CONTENTS (arg);
3405 /* 32-bit ABIs always start floating point arguments in an
3406 even-numbered floating point register. Round the FP register
3407 up before the check to see if there are any FP registers
3408 left. O32/O64 targets also pass the FP in the integer
3409 registers so also round up normal registers. */
3410 if (!FP_REGISTER_DOUBLE
3411 && fp_register_arg_p (typecode, arg_type))
3413 if ((float_argreg & 1))
3417 /* Floating point arguments passed in registers have to be
3418 treated specially. On 32-bit architectures, doubles
3419 are passed in register pairs; the even register gets
3420 the low word, and the odd register gets the high word.
3421 On O32/O64, the first two floating point arguments are
3422 also copied to general registers, because MIPS16 functions
3423 don't use float registers for arguments. This duplication of
3424 arguments in general registers can't hurt non-MIPS16 functions
3425 because those registers are normally skipped. */
3427 if (fp_register_arg_p (typecode, arg_type)
3428 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3430 if (!FP_REGISTER_DOUBLE && len == 8)
3432 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3433 unsigned long regval;
3435 /* Write the low word of the double to the even register(s). */
3436 regval = extract_unsigned_integer (val + low_offset, 4);
3438 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3439 float_argreg, phex (regval, 4));
3440 write_register (float_argreg++, regval);
3442 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3443 argreg, phex (regval, 4));
3444 write_register (argreg++, regval);
3446 /* Write the high word of the double to the odd register(s). */
3447 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3449 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3450 float_argreg, phex (regval, 4));
3451 write_register (float_argreg++, regval);
3454 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3455 argreg, phex (regval, 4));
3456 write_register (argreg++, regval);
3460 /* This is a floating point value that fits entirely
3461 in a single register. */
3462 /* On 32 bit ABI's the float_argreg is further adjusted
3463 above to ensure that it is even register aligned. */
3464 LONGEST regval = extract_unsigned_integer (val, len);
3466 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3467 float_argreg, phex (regval, len));
3468 write_register (float_argreg++, regval);
3469 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3470 registers for each argument. The below is (my
3471 guess) to ensure that the corresponding integer
3472 register has reserved the same space. */
3474 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3475 argreg, phex (regval, len));
3476 write_register (argreg, regval);
3477 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3479 /* Reserve space for the FP register. */
3480 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3484 /* Copy the argument to general registers or the stack in
3485 register-sized pieces. Large arguments are split between
3486 registers and stack. */
3487 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3488 are treated specially: Irix cc passes them in registers
3489 where gcc sometimes puts them on the stack. For maximum
3490 compatibility, we will put them in both places. */
3491 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3492 (len % MIPS_SAVED_REGSIZE != 0));
3493 /* Structures should be aligned to eight bytes (even arg registers)
3494 on MIPS_ABI_O32, if their first member has double precision. */
3495 if (MIPS_SAVED_REGSIZE < 8
3496 && mips_type_needs_double_align (arg_type))
3501 /* Note: Floating-point values that didn't fit into an FP
3502 register are only written to memory. */
3505 /* Remember if the argument was written to the stack. */
3506 int stack_used_p = 0;
3508 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3511 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3514 /* Write this portion of the argument to the stack. */
3515 if (argreg > MIPS_LAST_ARG_REGNUM
3517 || fp_register_arg_p (typecode, arg_type))
3519 /* Should shorter than int integer values be
3520 promoted to int before being stored? */
3521 int longword_offset = 0;
3524 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3526 if (MIPS_STACK_ARGSIZE == 8 &&
3527 (typecode == TYPE_CODE_INT ||
3528 typecode == TYPE_CODE_PTR ||
3529 typecode == TYPE_CODE_FLT) && len <= 4)
3530 longword_offset = MIPS_STACK_ARGSIZE - len;
3535 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3536 paddr_nz (stack_offset));
3537 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3538 paddr_nz (longword_offset));
3541 addr = sp + stack_offset + longword_offset;
3546 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3548 for (i = 0; i < partial_len; i++)
3550 fprintf_unfiltered (gdb_stdlog, "%02x",
3554 write_memory (addr, val, partial_len);
3557 /* Note!!! This is NOT an else clause. Odd sized
3558 structs may go thru BOTH paths. Floating point
3559 arguments will not. */
3560 /* Write this portion of the argument to a general
3561 purpose register. */
3562 if (argreg <= MIPS_LAST_ARG_REGNUM
3563 && !fp_register_arg_p (typecode, arg_type))
3565 LONGEST regval = extract_signed_integer (val, partial_len);
3566 /* Value may need to be sign extended, because
3567 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3569 /* A non-floating-point argument being passed in a
3570 general register. If a struct or union, and if
3571 the remaining length is smaller than the register
3572 size, we have to adjust the register value on
3575 It does not seem to be necessary to do the
3576 same for integral types.
3578 Also don't do this adjustment on O64 binaries.
3580 cagney/2001-07-23: gdb/179: Also, GCC, when
3581 outputting LE O32 with sizeof (struct) <
3582 MIPS_SAVED_REGSIZE, generates a left shift as
3583 part of storing the argument in a register a
3584 register (the left shift isn't generated when
3585 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3586 is quite possible that this is GCC contradicting
3587 the LE/O32 ABI, GDB has not been adjusted to
3588 accommodate this. Either someone needs to
3589 demonstrate that the LE/O32 ABI specifies such a
3590 left shift OR this new ABI gets identified as
3591 such and GDB gets tweaked accordingly. */
3593 if (MIPS_SAVED_REGSIZE < 8
3594 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3595 && partial_len < MIPS_SAVED_REGSIZE
3596 && (typecode == TYPE_CODE_STRUCT ||
3597 typecode == TYPE_CODE_UNION))
3598 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3602 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3604 phex (regval, MIPS_SAVED_REGSIZE));
3605 write_register (argreg, regval);
3608 /* Prevent subsequent floating point arguments from
3609 being passed in floating point registers. */
3610 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3616 /* Compute the the offset into the stack at which we
3617 will copy the next parameter.
3619 In older ABIs, the caller reserved space for
3620 registers that contained arguments. This was loosely
3621 refered to as their "home". Consequently, space is
3622 always allocated. */
3624 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3628 fprintf_unfiltered (gdb_stdlog, "\n");
3631 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3633 /* Return adjusted stack pointer. */
3637 /* O64 version of push_dummy_call. */
3640 mips_o64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3641 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3642 struct value **args, CORE_ADDR sp, int struct_return,
3643 CORE_ADDR struct_addr)
3649 int stack_offset = 0;
3651 /* For shared libraries, "t9" needs to point at the function
3653 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3655 /* Set the return address register to point to the entry point of
3656 the program, where a breakpoint lies in wait. */
3657 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3659 /* First ensure that the stack and structure return address (if any)
3660 are properly aligned. The stack has to be at least 64-bit
3661 aligned even on 32-bit machines, because doubles must be 64-bit
3662 aligned. For n32 and n64, stack frames need to be 128-bit
3663 aligned, so we round to this widest known alignment. */
3665 sp = ROUND_DOWN (sp, 16);
3666 struct_addr = ROUND_DOWN (struct_addr, 16);
3668 /* Now make space on the stack for the args. */
3669 for (argnum = 0; argnum < nargs; argnum++)
3670 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3671 MIPS_STACK_ARGSIZE);
3672 sp -= ROUND_UP (len, 16);
3675 fprintf_unfiltered (gdb_stdlog,
3676 "mips_o64_push_dummy_call: sp=0x%s allocated %d\n",
3677 paddr_nz (sp), ROUND_UP (len, 16));
3679 /* Initialize the integer and float register pointers. */
3681 float_argreg = FPA0_REGNUM;
3683 /* The struct_return pointer occupies the first parameter-passing reg. */
3687 fprintf_unfiltered (gdb_stdlog,
3688 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3689 argreg, paddr_nz (struct_addr));
3690 write_register (argreg++, struct_addr);
3691 stack_offset += MIPS_STACK_ARGSIZE;
3694 /* Now load as many as possible of the first arguments into
3695 registers, and push the rest onto the stack. Loop thru args
3696 from first to last. */
3697 for (argnum = 0; argnum < nargs; argnum++)
3700 char valbuf[MAX_REGISTER_SIZE];
3701 struct value *arg = args[argnum];
3702 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3703 int len = TYPE_LENGTH (arg_type);
3704 enum type_code typecode = TYPE_CODE (arg_type);
3707 fprintf_unfiltered (gdb_stdlog,
3708 "mips_o64_push_dummy_call: %d len=%d type=%d",
3709 argnum + 1, len, (int) typecode);
3711 val = (char *) VALUE_CONTENTS (arg);
3713 /* 32-bit ABIs always start floating point arguments in an
3714 even-numbered floating point register. Round the FP register
3715 up before the check to see if there are any FP registers
3716 left. O32/O64 targets also pass the FP in the integer
3717 registers so also round up normal registers. */
3718 if (!FP_REGISTER_DOUBLE
3719 && fp_register_arg_p (typecode, arg_type))
3721 if ((float_argreg & 1))
3725 /* Floating point arguments passed in registers have to be
3726 treated specially. On 32-bit architectures, doubles
3727 are passed in register pairs; the even register gets
3728 the low word, and the odd register gets the high word.
3729 On O32/O64, the first two floating point arguments are
3730 also copied to general registers, because MIPS16 functions
3731 don't use float registers for arguments. This duplication of
3732 arguments in general registers can't hurt non-MIPS16 functions
3733 because those registers are normally skipped. */
3735 if (fp_register_arg_p (typecode, arg_type)
3736 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3738 if (!FP_REGISTER_DOUBLE && len == 8)
3740 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3741 unsigned long regval;
3743 /* Write the low word of the double to the even register(s). */
3744 regval = extract_unsigned_integer (val + low_offset, 4);
3746 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3747 float_argreg, phex (regval, 4));
3748 write_register (float_argreg++, regval);
3750 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3751 argreg, phex (regval, 4));
3752 write_register (argreg++, regval);
3754 /* Write the high word of the double to the odd register(s). */
3755 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3757 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3758 float_argreg, phex (regval, 4));
3759 write_register (float_argreg++, regval);
3762 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3763 argreg, phex (regval, 4));
3764 write_register (argreg++, regval);
3768 /* This is a floating point value that fits entirely
3769 in a single register. */
3770 /* On 32 bit ABI's the float_argreg is further adjusted
3771 above to ensure that it is even register aligned. */
3772 LONGEST regval = extract_unsigned_integer (val, len);
3774 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3775 float_argreg, phex (regval, len));
3776 write_register (float_argreg++, regval);
3777 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3778 registers for each argument. The below is (my
3779 guess) to ensure that the corresponding integer
3780 register has reserved the same space. */
3782 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3783 argreg, phex (regval, len));
3784 write_register (argreg, regval);
3785 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3787 /* Reserve space for the FP register. */
3788 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3792 /* Copy the argument to general registers or the stack in
3793 register-sized pieces. Large arguments are split between
3794 registers and stack. */
3795 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3796 are treated specially: Irix cc passes them in registers
3797 where gcc sometimes puts them on the stack. For maximum
3798 compatibility, we will put them in both places. */
3799 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3800 (len % MIPS_SAVED_REGSIZE != 0));
3801 /* Structures should be aligned to eight bytes (even arg registers)
3802 on MIPS_ABI_O32, if their first member has double precision. */
3803 if (MIPS_SAVED_REGSIZE < 8
3804 && mips_type_needs_double_align (arg_type))
3809 /* Note: Floating-point values that didn't fit into an FP
3810 register are only written to memory. */
3813 /* Remember if the argument was written to the stack. */
3814 int stack_used_p = 0;
3816 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3819 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3822 /* Write this portion of the argument to the stack. */
3823 if (argreg > MIPS_LAST_ARG_REGNUM
3825 || fp_register_arg_p (typecode, arg_type))
3827 /* Should shorter than int integer values be
3828 promoted to int before being stored? */
3829 int longword_offset = 0;
3832 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3834 if (MIPS_STACK_ARGSIZE == 8 &&
3835 (typecode == TYPE_CODE_INT ||
3836 typecode == TYPE_CODE_PTR ||
3837 typecode == TYPE_CODE_FLT) && len <= 4)
3838 longword_offset = MIPS_STACK_ARGSIZE - len;
3843 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3844 paddr_nz (stack_offset));
3845 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3846 paddr_nz (longword_offset));
3849 addr = sp + stack_offset + longword_offset;
3854 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3856 for (i = 0; i < partial_len; i++)
3858 fprintf_unfiltered (gdb_stdlog, "%02x",
3862 write_memory (addr, val, partial_len);
3865 /* Note!!! This is NOT an else clause. Odd sized
3866 structs may go thru BOTH paths. Floating point
3867 arguments will not. */
3868 /* Write this portion of the argument to a general
3869 purpose register. */
3870 if (argreg <= MIPS_LAST_ARG_REGNUM
3871 && !fp_register_arg_p (typecode, arg_type))
3873 LONGEST regval = extract_signed_integer (val, partial_len);
3874 /* Value may need to be sign extended, because
3875 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3877 /* A non-floating-point argument being passed in a
3878 general register. If a struct or union, and if
3879 the remaining length is smaller than the register
3880 size, we have to adjust the register value on
3883 It does not seem to be necessary to do the
3884 same for integral types.
3886 Also don't do this adjustment on O64 binaries.
3888 cagney/2001-07-23: gdb/179: Also, GCC, when
3889 outputting LE O32 with sizeof (struct) <
3890 MIPS_SAVED_REGSIZE, generates a left shift as
3891 part of storing the argument in a register a
3892 register (the left shift isn't generated when
3893 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3894 is quite possible that this is GCC contradicting
3895 the LE/O32 ABI, GDB has not been adjusted to
3896 accommodate this. Either someone needs to
3897 demonstrate that the LE/O32 ABI specifies such a
3898 left shift OR this new ABI gets identified as
3899 such and GDB gets tweaked accordingly. */
3901 if (MIPS_SAVED_REGSIZE < 8
3902 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3903 && partial_len < MIPS_SAVED_REGSIZE
3904 && (typecode == TYPE_CODE_STRUCT ||
3905 typecode == TYPE_CODE_UNION))
3906 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3910 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3912 phex (regval, MIPS_SAVED_REGSIZE));
3913 write_register (argreg, regval);
3916 /* Prevent subsequent floating point arguments from
3917 being passed in floating point registers. */
3918 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3924 /* Compute the the offset into the stack at which we
3925 will copy the next parameter.
3927 In older ABIs, the caller reserved space for
3928 registers that contained arguments. This was loosely
3929 refered to as their "home". Consequently, space is
3930 always allocated. */
3932 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3936 fprintf_unfiltered (gdb_stdlog, "\n");
3939 regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3941 /* Return adjusted stack pointer. */
3946 mips_pop_frame (void)
3948 register int regnum;
3949 struct frame_info *frame = get_current_frame ();
3950 CORE_ADDR new_sp = get_frame_base (frame);
3951 mips_extra_func_info_t proc_desc;
3953 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3955 generic_pop_dummy_frame ();
3956 flush_cached_frames ();
3960 proc_desc = get_frame_extra_info (frame)->proc_desc;
3961 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3962 mips_find_saved_regs (frame);
3963 for (regnum = 0; regnum < NUM_REGS; regnum++)
3964 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3965 && get_frame_saved_regs (frame)[regnum])
3967 /* Floating point registers must not be sign extended,
3968 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3970 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3971 write_register (regnum,
3972 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3973 MIPS_SAVED_REGSIZE));
3975 write_register (regnum,
3976 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3977 MIPS_SAVED_REGSIZE));
3980 write_register (SP_REGNUM, new_sp);
3981 flush_cached_frames ();
3983 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3985 struct linked_proc_info *pi_ptr, *prev_ptr;
3987 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3989 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3991 if (&pi_ptr->info == proc_desc)
3996 error ("Can't locate dummy extra frame info\n");
3998 if (prev_ptr != NULL)
3999 prev_ptr->next = pi_ptr->next;
4001 linked_proc_desc_table = pi_ptr->next;
4005 write_register (HI_REGNUM,
4006 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
4007 MIPS_SAVED_REGSIZE));
4008 write_register (LO_REGNUM,
4009 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
4010 MIPS_SAVED_REGSIZE));
4011 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
4012 write_register (FCRCS_REGNUM,
4013 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
4014 MIPS_SAVED_REGSIZE));
4018 /* Floating point register management.
4020 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4021 64bit operations, these early MIPS cpus treat fp register pairs
4022 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4023 registers and offer a compatibility mode that emulates the MIPS2 fp
4024 model. When operating in MIPS2 fp compat mode, later cpu's split
4025 double precision floats into two 32-bit chunks and store them in
4026 consecutive fp regs. To display 64-bit floats stored in this
4027 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4028 Throw in user-configurable endianness and you have a real mess.
4030 The way this works is:
4031 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4032 double-precision value will be split across two logical registers.
4033 The lower-numbered logical register will hold the low-order bits,
4034 regardless of the processor's endianness.
4035 - If we are on a 64-bit processor, and we are looking for a
4036 single-precision value, it will be in the low ordered bits
4037 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4038 save slot in memory.
4039 - If we are in 64-bit mode, everything is straightforward.
4041 Note that this code only deals with "live" registers at the top of the
4042 stack. We will attempt to deal with saved registers later, when
4043 the raw/cooked register interface is in place. (We need a general
4044 interface that can deal with dynamic saved register sizes -- fp
4045 regs could be 32 bits wide in one frame and 64 on the frame above
4048 static struct type *
4049 mips_float_register_type (void)
4051 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4052 return builtin_type_ieee_single_big;
4054 return builtin_type_ieee_single_little;
4057 static struct type *
4058 mips_double_register_type (void)
4060 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4061 return builtin_type_ieee_double_big;
4063 return builtin_type_ieee_double_little;
4066 /* Copy a 32-bit single-precision value from the current frame
4067 into rare_buffer. */
4070 mips_read_fp_register_single (struct frame_info *frame, int regno,
4073 int raw_size = REGISTER_RAW_SIZE (regno);
4074 char *raw_buffer = alloca (raw_size);
4076 if (!frame_register_read (frame, regno, raw_buffer))
4077 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4080 /* We have a 64-bit value for this register. Find the low-order
4084 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4089 memcpy (rare_buffer, raw_buffer + offset, 4);
4093 memcpy (rare_buffer, raw_buffer, 4);
4097 /* Copy a 64-bit double-precision value from the current frame into
4098 rare_buffer. This may include getting half of it from the next
4102 mips_read_fp_register_double (struct frame_info *frame, int regno,
4105 int raw_size = REGISTER_RAW_SIZE (regno);
4107 if (raw_size == 8 && !mips2_fp_compat ())
4109 /* We have a 64-bit value for this register, and we should use
4111 if (!frame_register_read (frame, regno, rare_buffer))
4112 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4116 if ((regno - FP0_REGNUM) & 1)
4117 internal_error (__FILE__, __LINE__,
4118 "mips_read_fp_register_double: bad access to "
4119 "odd-numbered FP register");
4121 /* mips_read_fp_register_single will find the correct 32 bits from
4123 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4125 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4126 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4130 mips_read_fp_register_single (frame, regno, rare_buffer);
4131 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4137 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4139 { /* do values for FP (float) regs */
4141 double doub, flt1, flt2; /* doubles extracted from raw hex data */
4142 int inv1, inv2, namelen;
4144 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
4146 fprintf_filtered (file, "%s:", REGISTER_NAME (regnum));
4147 fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)),
4150 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4152 /* 4-byte registers: Print hex and floating. Also print even
4153 numbered registers as doubles. */
4154 mips_read_fp_register_single (frame, regnum, raw_buffer);
4155 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4157 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', file);
4159 fprintf_filtered (file, " flt: ");
4161 fprintf_filtered (file, " <invalid float> ");
4163 fprintf_filtered (file, "%-17.9g", flt1);
4165 if (regnum % 2 == 0)
4167 mips_read_fp_register_double (frame, regnum, raw_buffer);
4168 doub = unpack_double (mips_double_register_type (), raw_buffer,
4171 fprintf_filtered (file, " dbl: ");
4173 fprintf_filtered (file, "<invalid double>");
4175 fprintf_filtered (file, "%-24.17g", doub);
4180 /* Eight byte registers: print each one as hex, float and double. */
4181 mips_read_fp_register_single (frame, regnum, raw_buffer);
4182 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4184 mips_read_fp_register_double (frame, regnum, raw_buffer);
4185 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4188 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', file);
4190 fprintf_filtered (file, " flt: ");
4192 fprintf_filtered (file, "<invalid float>");
4194 fprintf_filtered (file, "%-17.9g", flt1);
4196 fprintf_filtered (file, " dbl: ");
4198 fprintf_filtered (file, "<invalid double>");
4200 fprintf_filtered (file, "%-24.17g", doub);
4205 mips_print_register (struct ui_file *file, struct frame_info *frame,
4206 int regnum, int all)
4208 struct gdbarch *gdbarch = get_frame_arch (frame);
4209 char raw_buffer[MAX_REGISTER_SIZE];
4212 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4214 mips_print_fp_register (file, frame, regnum);
4218 /* Get the data in raw format. */
4219 if (!frame_register_read (frame, regnum, raw_buffer))
4221 fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum));
4225 fputs_filtered (REGISTER_NAME (regnum), file);
4227 /* The problem with printing numeric register names (r26, etc.) is that
4228 the user can't use them on input. Probably the best solution is to
4229 fix it so that either the numeric or the funky (a2, etc.) names
4230 are accepted on input. */
4231 if (regnum < MIPS_NUMREGS)
4232 fprintf_filtered (file, "(r%d): ", regnum);
4234 fprintf_filtered (file, ": ");
4236 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4237 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4241 print_scalar_formatted (raw_buffer + offset, gdbarch_register_type (gdbarch, regnum),
4245 /* Replacement for generic do_registers_info.
4246 Print regs in pretty columns. */
4249 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4252 fprintf_filtered (file, " ");
4253 mips_print_fp_register (file, frame, regnum);
4254 fprintf_filtered (file, "\n");
4259 /* Print a row's worth of GP (int) registers, with name labels above */
4262 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4265 struct gdbarch *gdbarch = get_frame_arch (frame);
4266 /* do values for GP (int) regs */
4267 char raw_buffer[MAX_REGISTER_SIZE];
4268 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4272 /* For GP registers, we print a separate row of names above the vals */
4273 fprintf_filtered (file, " ");
4274 for (col = 0, regnum = start_regnum;
4275 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS;
4278 if (*REGISTER_NAME (regnum) == '\0')
4279 continue; /* unused register */
4280 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4281 break; /* end the row: reached FP register */
4282 fprintf_filtered (file, MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4283 REGISTER_NAME (regnum));
4286 /* print the R0 to R31 names */
4287 fprintf_filtered (file,
4288 (start_regnum % NUM_REGS) < MIPS_NUMREGS
4289 ? "\n R%-4d" : "\n ",
4292 /* now print the values in hex, 4 or 8 to the row */
4293 for (col = 0, regnum = start_regnum;
4294 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS;
4297 if (*REGISTER_NAME (regnum) == '\0')
4298 continue; /* unused register */
4299 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4300 break; /* end row: reached FP register */
4301 /* OK: get the data in raw format. */
4302 if (!frame_register_read (frame, regnum, raw_buffer))
4303 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4304 /* pad small registers */
4305 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4306 printf_filtered (" ");
4307 /* Now print the register value in hex, endian order. */
4308 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4309 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4310 byte < REGISTER_RAW_SIZE (regnum);
4312 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4314 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4317 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4318 fprintf_filtered (file, " ");
4321 if (col > 0) /* ie. if we actually printed anything... */
4322 fprintf_filtered (file, "\n");
4327 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4330 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4331 struct frame_info *frame, int regnum, int all)
4333 if (regnum != -1) /* do one specified register */
4335 gdb_assert (regnum >= NUM_REGS);
4336 if (*(REGISTER_NAME (regnum)) == '\0')
4337 error ("Not a valid register for the current processor type");
4339 mips_print_register (file, frame, regnum, 0);
4340 fprintf_filtered (file, "\n");
4343 /* do all (or most) registers */
4346 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
4348 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4350 if (all) /* true for "INFO ALL-REGISTERS" command */
4351 regnum = print_fp_register_row (file, frame, regnum);
4353 regnum += MIPS_NUMREGS; /* skip floating point regs */
4356 regnum = print_gp_register_row (file, frame, regnum);
4361 /* Is this a branch with a delay slot? */
4363 static int is_delayed (unsigned long);
4366 is_delayed (unsigned long insn)
4369 for (i = 0; i < NUMOPCODES; ++i)
4370 if (mips_opcodes[i].pinfo != INSN_MACRO
4371 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4373 return (i < NUMOPCODES
4374 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4375 | INSN_COND_BRANCH_DELAY
4376 | INSN_COND_BRANCH_LIKELY)));
4380 mips_step_skips_delay (CORE_ADDR pc)
4382 char buf[MIPS_INSTLEN];
4384 /* There is no branch delay slot on MIPS16. */
4385 if (pc_is_mips16 (pc))
4388 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4389 /* If error reading memory, guess that it is not a delayed branch. */
4391 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4395 /* Skip the PC past function prologue instructions (32-bit version).
4396 This is a helper function for mips_skip_prologue. */
4399 mips32_skip_prologue (CORE_ADDR pc)
4403 int seen_sp_adjust = 0;
4404 int load_immediate_bytes = 0;
4406 /* Skip the typical prologue instructions. These are the stack adjustment
4407 instruction and the instructions that save registers on the stack
4408 or in the gcc frame. */
4409 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4411 unsigned long high_word;
4413 inst = mips_fetch_instruction (pc);
4414 high_word = (inst >> 16) & 0xffff;
4416 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4417 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4419 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4420 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4422 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4423 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4424 && (inst & 0x001F0000)) /* reg != $zero */
4427 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4429 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4431 continue; /* reg != $zero */
4433 /* move $s8,$sp. With different versions of gas this will be either
4434 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4435 Accept any one of these. */
4436 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4439 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4441 else if (high_word == 0x3c1c) /* lui $gp,n */
4443 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4445 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4446 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4448 /* The following instructions load $at or $t0 with an immediate
4449 value in preparation for a stack adjustment via
4450 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4451 a local variable, so we accept them only before a stack adjustment
4452 instruction was seen. */
4453 else if (!seen_sp_adjust)
4455 if (high_word == 0x3c01 || /* lui $at,n */
4456 high_word == 0x3c08) /* lui $t0,n */
4458 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4461 else if (high_word == 0x3421 || /* ori $at,$at,n */
4462 high_word == 0x3508 || /* ori $t0,$t0,n */
4463 high_word == 0x3401 || /* ori $at,$zero,n */
4464 high_word == 0x3408) /* ori $t0,$zero,n */
4466 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4476 /* In a frameless function, we might have incorrectly
4477 skipped some load immediate instructions. Undo the skipping
4478 if the load immediate was not followed by a stack adjustment. */
4479 if (load_immediate_bytes && !seen_sp_adjust)
4480 pc -= load_immediate_bytes;
4484 /* Skip the PC past function prologue instructions (16-bit version).
4485 This is a helper function for mips_skip_prologue. */
4488 mips16_skip_prologue (CORE_ADDR pc)
4491 int extend_bytes = 0;
4492 int prev_extend_bytes;
4494 /* Table of instructions likely to be found in a function prologue. */
4497 unsigned short inst;
4498 unsigned short mask;
4505 , /* addiu $sp,offset */
4509 , /* daddiu $sp,offset */
4513 , /* sw reg,n($sp) */
4517 , /* sd reg,n($sp) */
4521 , /* sw $ra,n($sp) */
4525 , /* sd $ra,n($sp) */
4533 , /* sw $a0-$a3,n($s1) */
4537 , /* move reg,$a0-$a3 */
4541 , /* entry pseudo-op */
4545 , /* addiu $s1,$sp,n */
4548 } /* end of table marker */
4551 /* Skip the typical prologue instructions. These are the stack adjustment
4552 instruction and the instructions that save registers on the stack
4553 or in the gcc frame. */
4554 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4556 unsigned short inst;
4559 inst = mips_fetch_instruction (pc);
4561 /* Normally we ignore an extend instruction. However, if it is
4562 not followed by a valid prologue instruction, we must adjust
4563 the pc back over the extend so that it won't be considered
4564 part of the prologue. */
4565 if ((inst & 0xf800) == 0xf000) /* extend */
4567 extend_bytes = MIPS16_INSTLEN;
4570 prev_extend_bytes = extend_bytes;
4573 /* Check for other valid prologue instructions besides extend. */
4574 for (i = 0; table[i].mask != 0; i++)
4575 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4577 if (table[i].mask != 0) /* it was in table? */
4578 continue; /* ignore it */
4582 /* Return the current pc, adjusted backwards by 2 if
4583 the previous instruction was an extend. */
4584 return pc - prev_extend_bytes;
4590 /* To skip prologues, I use this predicate. Returns either PC itself
4591 if the code at PC does not look like a function prologue; otherwise
4592 returns an address that (if we're lucky) follows the prologue. If
4593 LENIENT, then we must skip everything which is involved in setting
4594 up the frame (it's OK to skip more, just so long as we don't skip
4595 anything which might clobber the registers which are being saved.
4596 We must skip more in the case where part of the prologue is in the
4597 delay slot of a non-prologue instruction). */
4600 mips_skip_prologue (CORE_ADDR pc)
4602 /* See if we can determine the end of the prologue via the symbol table.
4603 If so, then return either PC, or the PC after the prologue, whichever
4606 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4608 if (post_prologue_pc != 0)
4609 return max (pc, post_prologue_pc);
4611 /* Can't determine prologue from the symbol table, need to examine
4614 if (pc_is_mips16 (pc))
4615 return mips16_skip_prologue (pc);
4617 return mips32_skip_prologue (pc);
4620 /* Determine how a return value is stored within the MIPS register
4621 file, given the return type `valtype'. */
4623 struct return_value_word
4632 return_value_location (struct type *valtype,
4633 struct return_value_word *hi,
4634 struct return_value_word *lo)
4636 int len = TYPE_LENGTH (valtype);
4638 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4639 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4640 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4642 if (!FP_REGISTER_DOUBLE && len == 8)
4644 /* We need to break a 64bit float in two 32 bit halves and
4645 spread them across a floating-point register pair. */
4646 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4647 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4648 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4649 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4651 hi->reg_offset = lo->reg_offset;
4652 lo->reg = FP0_REGNUM + 0;
4653 hi->reg = FP0_REGNUM + 1;
4659 /* The floating point value fits in a single floating-point
4661 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4662 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4665 lo->reg = FP0_REGNUM;
4676 /* Locate a result possibly spread across two registers. */
4678 lo->reg = regnum + 0;
4679 hi->reg = regnum + 1;
4680 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4681 && len < MIPS_SAVED_REGSIZE)
4683 /* "un-left-justify" the value in the low register */
4684 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4689 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4690 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4691 && len < MIPS_SAVED_REGSIZE * 2
4692 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4693 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4695 /* "un-left-justify" the value spread across two registers. */
4696 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4697 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4699 hi->len = len - lo->len;
4703 /* Only perform a partial copy of the second register. */
4706 if (len > MIPS_SAVED_REGSIZE)
4708 lo->len = MIPS_SAVED_REGSIZE;
4709 hi->len = len - MIPS_SAVED_REGSIZE;
4717 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4718 && REGISTER_RAW_SIZE (regnum) == 8
4719 && MIPS_SAVED_REGSIZE == 4)
4721 /* Account for the fact that only the least-signficant part
4722 of the register is being used */
4723 lo->reg_offset += 4;
4724 hi->reg_offset += 4;
4727 hi->buf_offset = lo->len;
4731 /* Given a return value in `regbuf' with a type `valtype', extract and
4732 copy its value into `valbuf'. */
4735 mips_eabi_extract_return_value (struct type *valtype,
4739 struct return_value_word lo;
4740 struct return_value_word hi;
4741 return_value_location (valtype, &hi, &lo);
4743 memcpy (valbuf + lo.buf_offset,
4744 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4748 memcpy (valbuf + hi.buf_offset,
4749 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4754 mips_o64_extract_return_value (struct type *valtype,
4758 struct return_value_word lo;
4759 struct return_value_word hi;
4760 return_value_location (valtype, &hi, &lo);
4762 memcpy (valbuf + lo.buf_offset,
4763 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4767 memcpy (valbuf + hi.buf_offset,
4768 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4772 /* Given a return value in `valbuf' with a type `valtype', write it's
4773 value into the appropriate register. */
4776 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4778 char raw_buffer[MAX_REGISTER_SIZE];
4779 struct return_value_word lo;
4780 struct return_value_word hi;
4781 return_value_location (valtype, &hi, &lo);
4783 memset (raw_buffer, 0, sizeof (raw_buffer));
4784 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4785 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4786 REGISTER_RAW_SIZE (lo.reg));
4790 memset (raw_buffer, 0, sizeof (raw_buffer));
4791 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4792 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4793 REGISTER_RAW_SIZE (hi.reg));
4798 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4800 char raw_buffer[MAX_REGISTER_SIZE];
4801 struct return_value_word lo;
4802 struct return_value_word hi;
4803 return_value_location (valtype, &hi, &lo);
4805 memset (raw_buffer, 0, sizeof (raw_buffer));
4806 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4807 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4808 REGISTER_RAW_SIZE (lo.reg));
4812 memset (raw_buffer, 0, sizeof (raw_buffer));
4813 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4814 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4815 REGISTER_RAW_SIZE (hi.reg));
4819 /* O32 ABI stuff. */
4822 mips_o32_xfer_return_value (struct type *type,
4823 struct regcache *regcache,
4824 bfd_byte *in, const bfd_byte *out)
4826 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4827 if (TYPE_CODE (type) == TYPE_CODE_FLT
4828 && TYPE_LENGTH (type) == 4
4829 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4831 /* A single-precision floating-point value. It fits in the
4832 least significant part of FP0. */
4834 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4835 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM, TYPE_LENGTH (type),
4836 TARGET_BYTE_ORDER, in, out, 0);
4838 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4839 && TYPE_LENGTH (type) == 8
4840 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4842 /* A double-precision floating-point value. The most
4843 significant part goes in FP1, and the least significant in
4846 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
4847 switch (TARGET_BYTE_ORDER)
4849 case BFD_ENDIAN_LITTLE:
4850 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 0, 4,
4851 TARGET_BYTE_ORDER, in, out, 0);
4852 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 1, 4,
4853 TARGET_BYTE_ORDER, in, out, 4);
4855 case BFD_ENDIAN_BIG:
4856 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 1, 4,
4857 TARGET_BYTE_ORDER, in, out, 0);
4858 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM + 0, 4,
4859 TARGET_BYTE_ORDER, in, out, 4);
4862 internal_error (__FILE__, __LINE__, "bad switch");
4866 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4867 && TYPE_NFIELDS (type) <= 2
4868 && TYPE_NFIELDS (type) >= 1
4869 && ((TYPE_NFIELDS (type) == 1
4870 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4872 || (TYPE_NFIELDS (type) == 2
4873 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4875 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4877 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4879 /* A struct that contains one or two floats. Each value is part
4880 in the least significant part of their floating point
4882 bfd_byte reg[MAX_REGISTER_SIZE];
4885 for (field = 0, regnum = FP0_REGNUM;
4886 field < TYPE_NFIELDS (type);
4887 field++, regnum += 2)
4889 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4892 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4893 mips_xfer_register (regcache, NUM_REGS + regnum,
4894 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4895 TARGET_BYTE_ORDER, in, out, offset);
4900 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4901 || TYPE_CODE (type) == TYPE_CODE_UNION)
4903 /* A structure or union. Extract the left justified value,
4904 regardless of the byte order. I.e. DO NOT USE
4908 for (offset = 0, regnum = V0_REGNUM;
4909 offset < TYPE_LENGTH (type);
4910 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4912 int xfer = REGISTER_RAW_SIZE (regnum);
4913 if (offset + xfer > TYPE_LENGTH (type))
4914 xfer = TYPE_LENGTH (type) - offset;
4916 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4917 offset, xfer, regnum);
4918 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4919 BFD_ENDIAN_UNKNOWN, in, out, offset);
4925 /* A scalar extract each part but least-significant-byte
4926 justified. o32 thinks registers are 4 byte, regardless of
4927 the ISA. mips_stack_argsize controls this. */
4930 for (offset = 0, regnum = V0_REGNUM;
4931 offset < TYPE_LENGTH (type);
4932 offset += mips_stack_argsize (), regnum++)
4934 int xfer = mips_stack_argsize ();
4936 if (offset + xfer > TYPE_LENGTH (type))
4937 xfer = TYPE_LENGTH (type) - offset;
4939 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4940 offset, xfer, regnum);
4941 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4942 TARGET_BYTE_ORDER, in, out, offset);
4948 mips_o32_extract_return_value (struct type *type,
4949 struct regcache *regcache,
4952 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4956 mips_o32_store_return_value (struct type *type, char *valbuf)
4958 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4961 /* N32/N44 ABI stuff. */
4964 mips_n32n64_xfer_return_value (struct type *type,
4965 struct regcache *regcache,
4966 bfd_byte *in, const bfd_byte *out)
4968 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4969 if (TYPE_CODE (type) == TYPE_CODE_FLT
4970 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4972 /* A floating-point value belongs in the least significant part
4975 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4976 mips_xfer_register (regcache, NUM_REGS + FP0_REGNUM, TYPE_LENGTH (type),
4977 TARGET_BYTE_ORDER, in, out, 0);
4979 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4980 && TYPE_NFIELDS (type) <= 2
4981 && TYPE_NFIELDS (type) >= 1
4982 && ((TYPE_NFIELDS (type) == 1
4983 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4985 || (TYPE_NFIELDS (type) == 2
4986 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4988 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4990 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4992 /* A struct that contains one or two floats. Each value is part
4993 in the least significant part of their floating point
4995 bfd_byte reg[MAX_REGISTER_SIZE];
4998 for (field = 0, regnum = FP0_REGNUM;
4999 field < TYPE_NFIELDS (type);
5000 field++, regnum += 2)
5002 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
5005 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
5006 mips_xfer_register (regcache, NUM_REGS + regnum,
5007 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
5008 TARGET_BYTE_ORDER, in, out, offset);
5011 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
5012 || TYPE_CODE (type) == TYPE_CODE_UNION)
5014 /* A structure or union. Extract the left justified value,
5015 regardless of the byte order. I.e. DO NOT USE
5019 for (offset = 0, regnum = V0_REGNUM;
5020 offset < TYPE_LENGTH (type);
5021 offset += REGISTER_RAW_SIZE (regnum), regnum++)
5023 int xfer = REGISTER_RAW_SIZE (regnum);
5024 if (offset + xfer > TYPE_LENGTH (type))
5025 xfer = TYPE_LENGTH (type) - offset;
5027 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
5028 offset, xfer, regnum);
5029 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
5030 BFD_ENDIAN_UNKNOWN, in, out, offset);
5035 /* A scalar extract each part but least-significant-byte
5039 for (offset = 0, regnum = V0_REGNUM;
5040 offset < TYPE_LENGTH (type);
5041 offset += REGISTER_RAW_SIZE (regnum), regnum++)
5043 int xfer = REGISTER_RAW_SIZE (regnum);
5045 if (offset + xfer > TYPE_LENGTH (type))
5046 xfer = TYPE_LENGTH (type) - offset;
5048 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
5049 offset, xfer, regnum);
5050 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
5051 TARGET_BYTE_ORDER, in, out, offset);
5057 mips_n32n64_extract_return_value (struct type *type,
5058 struct regcache *regcache,
5061 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
5065 mips_n32n64_store_return_value (struct type *type, char *valbuf)
5067 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
5071 mips_extract_struct_value_address (struct regcache *regcache)
5073 /* FIXME: This will only work at random. The caller passes the
5074 struct_return address in V0, but it is not preserved. It may
5075 still be there, or this may be a random value. */
5078 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
5082 /* Exported procedure: Is PC in the signal trampoline code */
5085 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
5087 if (sigtramp_address == 0)
5089 return (pc >= sigtramp_address && pc < sigtramp_end);
5092 /* Root of all "set mips "/"show mips " commands. This will eventually be
5093 used for all MIPS-specific commands. */
5096 show_mips_command (char *args, int from_tty)
5098 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5102 set_mips_command (char *args, int from_tty)
5104 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
5105 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5108 /* Commands to show/set the MIPS FPU type. */
5111 show_mipsfpu_command (char *args, int from_tty)
5114 switch (MIPS_FPU_TYPE)
5116 case MIPS_FPU_SINGLE:
5117 fpu = "single-precision";
5119 case MIPS_FPU_DOUBLE:
5120 fpu = "double-precision";
5123 fpu = "absent (none)";
5126 internal_error (__FILE__, __LINE__, "bad switch");
5128 if (mips_fpu_type_auto)
5129 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5132 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5138 set_mipsfpu_command (char *args, int from_tty)
5140 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5141 show_mipsfpu_command (args, from_tty);
5145 set_mipsfpu_single_command (char *args, int from_tty)
5147 mips_fpu_type = MIPS_FPU_SINGLE;
5148 mips_fpu_type_auto = 0;
5149 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5153 set_mipsfpu_double_command (char *args, int from_tty)
5155 mips_fpu_type = MIPS_FPU_DOUBLE;
5156 mips_fpu_type_auto = 0;
5157 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5161 set_mipsfpu_none_command (char *args, int from_tty)
5163 mips_fpu_type = MIPS_FPU_NONE;
5164 mips_fpu_type_auto = 0;
5165 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5169 set_mipsfpu_auto_command (char *args, int from_tty)
5171 mips_fpu_type_auto = 1;
5174 /* Command to set the processor type. */
5177 mips_set_processor_type_command (char *args, int from_tty)
5181 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5183 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5184 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5185 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5187 /* Restore the value. */
5188 tmp_mips_processor_type = xstrdup (mips_processor_type);
5193 if (!mips_set_processor_type (tmp_mips_processor_type))
5195 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5196 /* Restore its value. */
5197 tmp_mips_processor_type = xstrdup (mips_processor_type);
5202 mips_show_processor_type_command (char *args, int from_tty)
5206 /* Modify the actual processor type. */
5209 mips_set_processor_type (char *str)
5216 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5218 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5220 mips_processor_type = str;
5221 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5223 /* FIXME tweak fpu flag too */
5230 /* Attempt to identify the particular processor model by reading the
5234 mips_read_processor_type (void)
5238 prid = read_register (PRID_REGNUM);
5240 if ((prid & ~0xf) == 0x700)
5241 return savestring ("r3041", strlen ("r3041"));
5246 /* Just like reinit_frame_cache, but with the right arguments to be
5247 callable as an sfunc. */
5250 reinit_frame_cache_sfunc (char *args, int from_tty,
5251 struct cmd_list_element *c)
5253 reinit_frame_cache ();
5257 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5259 mips_extra_func_info_t proc_desc;
5261 /* Search for the function containing this address. Set the low bit
5262 of the address when searching, in case we were given an even address
5263 that is the start of a 16-bit function. If we didn't do this,
5264 the search would fail because the symbol table says the function
5265 starts at an odd address, i.e. 1 byte past the given address. */
5266 memaddr = ADDR_BITS_REMOVE (memaddr);
5267 proc_desc = non_heuristic_proc_desc (make_mips16_addr (memaddr), NULL);
5269 /* Make an attempt to determine if this is a 16-bit function. If
5270 the procedure descriptor exists and the address therein is odd,
5271 it's definitely a 16-bit function. Otherwise, we have to just
5272 guess that if the address passed in is odd, it's 16-bits. */
5273 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5274 disassembler needs to be able to locally determine the ISA, and
5275 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5279 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
5280 info->mach = bfd_mach_mips16;
5284 if (pc_is_mips16 (memaddr))
5285 info->mach = bfd_mach_mips16;
5288 /* Round down the instruction address to the appropriate boundary. */
5289 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
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 /* Return a location where we can set a breakpoint that will be hit
5542 when an inferior function call returns. This is normally the
5543 program's entry point. Executables that don't have an entry
5544 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5545 whose address is the location where the breakpoint should be placed. */
5548 mips_call_dummy_address (void)
5550 struct minimal_symbol *sym;
5552 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5554 return SYMBOL_VALUE_ADDRESS (sym);
5556 return entry_point_address ();
5560 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5561 the register stored on the stack (32) is different to its real raw
5562 size (64). The below ensures that registers are fetched from the
5563 stack using their ABI size and then stored into the RAW_BUFFER
5564 using their raw size.
5566 The alternative to adding this function would be to add an ABI
5567 macro - REGISTER_STACK_SIZE(). */
5570 mips_get_saved_register (char *raw_buffer,
5573 struct frame_info *frame,
5575 enum lval_type *lvalp)
5578 enum lval_type lvalx;
5582 /* Always a pseudo. */
5583 gdb_assert (regnum >= NUM_REGS);
5585 /* Make certain that all needed parameters are present. */
5590 if (optimizedp == NULL)
5591 optimizedp = &optimizedx;
5593 if ((regnum % NUM_REGS) == SP_REGNUM)
5594 /* The SP_REGNUM is special, its value is stored in saved_regs.
5595 In fact, it is so special that it can even only be fetched
5596 using a raw register number! Once this code as been converted
5597 to frame-unwind the problem goes away. */
5598 frame_register_unwind (deprecated_get_next_frame_hack (frame),
5599 regnum % NUM_REGS, optimizedp, lvalp, addrp,
5600 &realnumx, raw_buffer);
5602 /* Get it from the next frame. */
5603 frame_register_unwind (deprecated_get_next_frame_hack (frame),
5604 regnum, optimizedp, lvalp, addrp,
5605 &realnumx, raw_buffer);
5608 /* Immediately after a function call, return the saved pc.
5609 Can't always go through the frames for this because on some machines
5610 the new frame is not set up until the new function executes
5611 some instructions. */
5614 mips_saved_pc_after_call (struct frame_info *frame)
5616 return read_signed_register (RA_REGNUM);
5620 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5621 [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5624 mips_stab_reg_to_regnum (int num)
5627 if (num >= 0 && num < 32)
5629 else if (num >= 38 && num < 70)
5630 regnum = num + FP0_REGNUM - 38;
5636 /* This will hopefully (eventually) provoke a warning. Should
5637 we be calling complaint() here? */
5638 return NUM_REGS + NUM_PSEUDO_REGS;
5639 return NUM_REGS + regnum;
5643 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5644 NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5647 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5650 if (num >= 0 && num < 32)
5652 else if (num >= 32 && num < 64)
5653 regnum = num + FP0_REGNUM - 32;
5659 /* This will hopefully (eventually) provoke a warning. Should we
5660 be calling complaint() here? */
5661 return NUM_REGS + NUM_PSEUDO_REGS;
5662 return NUM_REGS + regnum;
5666 mips_register_sim_regno (int regnum)
5668 /* Only makes sense to supply raw registers. */
5669 gdb_assert (regnum >= 0 && regnum < NUM_REGS);
5670 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5671 decide if it is valid. Should instead define a standard sim/gdb
5672 register numbering scheme. */
5673 if (REGISTER_NAME (NUM_REGS + regnum) != NULL
5674 && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0')
5677 return LEGACY_SIM_REGNO_IGNORE;
5681 /* Convert an integer into an address. By first converting the value
5682 into a pointer and then extracting it signed, the address is
5683 guarenteed to be correctly sign extended. */
5686 mips_integer_to_address (struct type *type, void *buf)
5688 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5689 LONGEST val = unpack_long (type, buf);
5690 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5691 return extract_signed_integer (tmp,
5692 TYPE_LENGTH (builtin_type_void_data_ptr));
5696 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5698 enum mips_abi *abip = (enum mips_abi *) obj;
5699 const char *name = bfd_get_section_name (abfd, sect);
5701 if (*abip != MIPS_ABI_UNKNOWN)
5704 if (strncmp (name, ".mdebug.", 8) != 0)
5707 if (strcmp (name, ".mdebug.abi32") == 0)
5708 *abip = MIPS_ABI_O32;
5709 else if (strcmp (name, ".mdebug.abiN32") == 0)
5710 *abip = MIPS_ABI_N32;
5711 else if (strcmp (name, ".mdebug.abi64") == 0)
5712 *abip = MIPS_ABI_N64;
5713 else if (strcmp (name, ".mdebug.abiO64") == 0)
5714 *abip = MIPS_ABI_O64;
5715 else if (strcmp (name, ".mdebug.eabi32") == 0)
5716 *abip = MIPS_ABI_EABI32;
5717 else if (strcmp (name, ".mdebug.eabi64") == 0)
5718 *abip = MIPS_ABI_EABI64;
5720 warning ("unsupported ABI %s.", name + 8);
5723 static enum mips_abi
5724 global_mips_abi (void)
5728 for (i = 0; mips_abi_strings[i] != NULL; i++)
5729 if (mips_abi_strings[i] == mips_abi_string)
5730 return (enum mips_abi) i;
5732 internal_error (__FILE__, __LINE__,
5733 "unknown ABI string");
5736 static struct gdbarch *
5737 mips_gdbarch_init (struct gdbarch_info info,
5738 struct gdbarch_list *arches)
5740 struct gdbarch *gdbarch;
5741 struct gdbarch_tdep *tdep;
5743 enum mips_abi mips_abi, found_abi, wanted_abi;
5746 /* Reset the disassembly info, in case it was set to something
5748 deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5749 deprecated_tm_print_insn_info.arch = bfd_arch_unknown;
5750 deprecated_tm_print_insn_info.mach = 0;
5756 /* First of all, extract the elf_flags, if available. */
5757 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5758 elf_flags = elf_elfheader (info.abfd)->e_flags;
5761 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5762 switch ((elf_flags & EF_MIPS_ABI))
5764 case E_MIPS_ABI_O32:
5765 mips_abi = MIPS_ABI_O32;
5767 case E_MIPS_ABI_O64:
5768 mips_abi = MIPS_ABI_O64;
5770 case E_MIPS_ABI_EABI32:
5771 mips_abi = MIPS_ABI_EABI32;
5773 case E_MIPS_ABI_EABI64:
5774 mips_abi = MIPS_ABI_EABI64;
5777 if ((elf_flags & EF_MIPS_ABI2))
5778 mips_abi = MIPS_ABI_N32;
5780 mips_abi = MIPS_ABI_UNKNOWN;
5784 /* GCC creates a pseudo-section whose name describes the ABI. */
5785 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5786 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5788 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5789 Use the ABI from the last architecture if there is one. */
5790 if (info.abfd == NULL && arches != NULL)
5791 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5793 /* Try the architecture for any hint of the correct ABI. */
5794 if (mips_abi == MIPS_ABI_UNKNOWN
5795 && info.bfd_arch_info != NULL
5796 && info.bfd_arch_info->arch == bfd_arch_mips)
5798 switch (info.bfd_arch_info->mach)
5800 case bfd_mach_mips3900:
5801 mips_abi = MIPS_ABI_EABI32;
5803 case bfd_mach_mips4100:
5804 case bfd_mach_mips5000:
5805 mips_abi = MIPS_ABI_EABI64;
5807 case bfd_mach_mips8000:
5808 case bfd_mach_mips10000:
5809 /* On Irix, ELF64 executables use the N64 ABI. The
5810 pseudo-sections which describe the ABI aren't present
5811 on IRIX. (Even for executables created by gcc.) */
5812 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5813 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5814 mips_abi = MIPS_ABI_N64;
5816 mips_abi = MIPS_ABI_N32;
5821 if (mips_abi == MIPS_ABI_UNKNOWN)
5822 mips_abi = MIPS_ABI_O32;
5824 /* Now that we have found what the ABI for this binary would be,
5825 check whether the user is overriding it. */
5826 found_abi = mips_abi;
5827 wanted_abi = global_mips_abi ();
5828 if (wanted_abi != MIPS_ABI_UNKNOWN)
5829 mips_abi = wanted_abi;
5831 /* We have to set deprecated_tm_print_insn_info before looking for a
5832 pre-existing architecture, otherwise we may return before we get
5833 a chance to set it up. */
5834 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5836 /* Set up the disassembler info, so that we get the right
5837 register names from libopcodes. */
5838 if (mips_abi == MIPS_ABI_N32)
5839 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=n32";
5841 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=64";
5842 deprecated_tm_print_insn_info.flavour = bfd_target_elf_flavour;
5843 deprecated_tm_print_insn_info.arch = bfd_arch_mips;
5844 if (info.bfd_arch_info != NULL
5845 && info.bfd_arch_info->arch == bfd_arch_mips
5846 && info.bfd_arch_info->mach)
5847 deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
5849 deprecated_tm_print_insn_info.mach = bfd_mach_mips8000;
5852 /* This string is not recognized explicitly by the disassembler,
5853 but it tells the disassembler to not try to guess the ABI from
5854 the bfd elf headers, such that, if the user overrides the ABI
5855 of a program linked as NewABI, the disassembly will follow the
5856 register naming conventions specified by the user. */
5857 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=32";
5861 fprintf_unfiltered (gdb_stdlog,
5862 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5864 fprintf_unfiltered (gdb_stdlog,
5865 "mips_gdbarch_init: mips_abi = %d\n",
5867 fprintf_unfiltered (gdb_stdlog,
5868 "mips_gdbarch_init: found_mips_abi = %d\n",
5872 /* try to find a pre-existing architecture */
5873 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5875 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5877 /* MIPS needs to be pedantic about which ABI the object is
5879 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5881 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5883 return arches->gdbarch;
5886 /* Need a new architecture. Fill in a target specific vector. */
5887 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5888 gdbarch = gdbarch_alloc (&info, tdep);
5889 tdep->elf_flags = elf_flags;
5891 /* Initially set everything according to the default ABI/ISA. */
5892 set_gdbarch_short_bit (gdbarch, 16);
5893 set_gdbarch_int_bit (gdbarch, 32);
5894 set_gdbarch_float_bit (gdbarch, 32);
5895 set_gdbarch_double_bit (gdbarch, 64);
5896 set_gdbarch_long_double_bit (gdbarch, 64);
5897 set_gdbarch_deprecated_register_raw_size (gdbarch, mips_register_raw_size);
5898 set_gdbarch_deprecated_register_byte (gdbarch, mips_register_byte);
5899 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
5900 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
5901 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
5902 tdep->found_abi = found_abi;
5903 tdep->mips_abi = mips_abi;
5905 set_gdbarch_elf_make_msymbol_special (gdbarch,
5906 mips_elf_make_msymbol_special);
5909 if (info.osabi == GDB_OSABI_IRIX)
5913 set_gdbarch_num_regs (gdbarch, num_regs);
5914 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
5919 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5920 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5921 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5922 tdep->mips_default_saved_regsize = 4;
5923 tdep->mips_default_stack_argsize = 4;
5924 tdep->mips_fp_register_double = 0;
5925 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5926 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5927 tdep->gdb_target_is_mips64 = 0;
5928 tdep->default_mask_address_p = 0;
5929 set_gdbarch_long_bit (gdbarch, 32);
5930 set_gdbarch_ptr_bit (gdbarch, 32);
5931 set_gdbarch_long_long_bit (gdbarch, 64);
5932 set_gdbarch_reg_struct_has_addr (gdbarch,
5933 mips_o32_reg_struct_has_addr);
5934 set_gdbarch_use_struct_convention (gdbarch,
5935 always_use_struct_convention);
5938 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5939 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5940 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5941 tdep->mips_default_saved_regsize = 8;
5942 tdep->mips_default_stack_argsize = 8;
5943 tdep->mips_fp_register_double = 1;
5944 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5945 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5946 tdep->gdb_target_is_mips64 = 1;
5947 tdep->default_mask_address_p = 0;
5948 set_gdbarch_long_bit (gdbarch, 32);
5949 set_gdbarch_ptr_bit (gdbarch, 32);
5950 set_gdbarch_long_long_bit (gdbarch, 64);
5951 set_gdbarch_reg_struct_has_addr (gdbarch,
5952 mips_o32_reg_struct_has_addr);
5953 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
5955 case MIPS_ABI_EABI32:
5956 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5957 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5958 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5959 tdep->mips_default_saved_regsize = 4;
5960 tdep->mips_default_stack_argsize = 4;
5961 tdep->mips_fp_register_double = 0;
5962 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5963 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5964 tdep->gdb_target_is_mips64 = 0;
5965 tdep->default_mask_address_p = 0;
5966 set_gdbarch_long_bit (gdbarch, 32);
5967 set_gdbarch_ptr_bit (gdbarch, 32);
5968 set_gdbarch_long_long_bit (gdbarch, 64);
5969 set_gdbarch_reg_struct_has_addr (gdbarch,
5970 mips_eabi_reg_struct_has_addr);
5971 set_gdbarch_use_struct_convention (gdbarch,
5972 mips_eabi_use_struct_convention);
5974 case MIPS_ABI_EABI64:
5975 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5976 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5977 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5978 tdep->mips_default_saved_regsize = 8;
5979 tdep->mips_default_stack_argsize = 8;
5980 tdep->mips_fp_register_double = 1;
5981 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5982 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5983 tdep->gdb_target_is_mips64 = 1;
5984 tdep->default_mask_address_p = 0;
5985 set_gdbarch_long_bit (gdbarch, 64);
5986 set_gdbarch_ptr_bit (gdbarch, 64);
5987 set_gdbarch_long_long_bit (gdbarch, 64);
5988 set_gdbarch_reg_struct_has_addr (gdbarch,
5989 mips_eabi_reg_struct_has_addr);
5990 set_gdbarch_use_struct_convention (gdbarch,
5991 mips_eabi_use_struct_convention);
5994 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5995 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5996 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5997 tdep->mips_default_saved_regsize = 8;
5998 tdep->mips_default_stack_argsize = 8;
5999 tdep->mips_fp_register_double = 1;
6000 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6001 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
6002 tdep->gdb_target_is_mips64 = 1;
6003 tdep->default_mask_address_p = 0;
6004 set_gdbarch_long_bit (gdbarch, 32);
6005 set_gdbarch_ptr_bit (gdbarch, 32);
6006 set_gdbarch_long_long_bit (gdbarch, 64);
6007 set_gdbarch_use_struct_convention (gdbarch,
6008 mips_n32n64_use_struct_convention);
6009 set_gdbarch_reg_struct_has_addr (gdbarch,
6010 mips_n32n64_reg_struct_has_addr);
6013 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
6014 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
6015 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
6016 tdep->mips_default_saved_regsize = 8;
6017 tdep->mips_default_stack_argsize = 8;
6018 tdep->mips_fp_register_double = 1;
6019 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6020 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
6021 tdep->gdb_target_is_mips64 = 1;
6022 tdep->default_mask_address_p = 0;
6023 set_gdbarch_long_bit (gdbarch, 64);
6024 set_gdbarch_ptr_bit (gdbarch, 64);
6025 set_gdbarch_long_long_bit (gdbarch, 64);
6026 set_gdbarch_use_struct_convention (gdbarch,
6027 mips_n32n64_use_struct_convention);
6028 set_gdbarch_reg_struct_has_addr (gdbarch,
6029 mips_n32n64_reg_struct_has_addr);
6032 internal_error (__FILE__, __LINE__,
6033 "unknown ABI in switch");
6036 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
6037 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
6040 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
6041 flag in object files because to do so would make it impossible to
6042 link with libraries compiled without "-gp32". This is
6043 unnecessarily restrictive.
6045 We could solve this problem by adding "-gp32" multilibs to gcc,
6046 but to set this flag before gcc is built with such multilibs will
6047 break too many systems.''
6049 But even more unhelpfully, the default linker output target for
6050 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
6051 for 64-bit programs - you need to change the ABI to change this,
6052 and not all gcc targets support that currently. Therefore using
6053 this flag to detect 32-bit mode would do the wrong thing given
6054 the current gcc - it would make GDB treat these 64-bit programs
6055 as 32-bit programs by default. */
6057 /* enable/disable the MIPS FPU */
6058 if (!mips_fpu_type_auto)
6059 tdep->mips_fpu_type = mips_fpu_type;
6060 else if (info.bfd_arch_info != NULL
6061 && info.bfd_arch_info->arch == bfd_arch_mips)
6062 switch (info.bfd_arch_info->mach)
6064 case bfd_mach_mips3900:
6065 case bfd_mach_mips4100:
6066 case bfd_mach_mips4111:
6067 tdep->mips_fpu_type = MIPS_FPU_NONE;
6069 case bfd_mach_mips4650:
6070 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
6073 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
6077 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
6079 /* MIPS version of register names. NOTE: At present the MIPS
6080 register name management is part way between the old -
6081 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
6082 Further work on it is required. */
6083 /* NOTE: many targets (esp. embedded) do not go thru the
6084 gdbarch_register_name vector at all, instead bypassing it
6085 by defining REGISTER_NAMES. */
6086 set_gdbarch_register_name (gdbarch, mips_register_name);
6087 set_gdbarch_read_pc (gdbarch, mips_read_pc);
6088 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
6089 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
6090 set_gdbarch_read_sp (gdbarch, mips_read_sp);
6092 /* Add/remove bits from an address. The MIPS needs be careful to
6093 ensure that all 32 bit addresses are sign extended to 64 bits. */
6094 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
6096 /* There's a mess in stack frame creation. See comments in
6097 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
6098 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
6099 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
6101 /* Map debug register numbers onto internal register numbers. */
6102 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6103 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6104 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6105 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6106 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
6108 /* Initialize a frame */
6109 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_find_saved_regs);
6110 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
6112 /* MIPS version of CALL_DUMMY */
6114 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
6115 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
6116 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6117 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
6118 set_gdbarch_deprecated_register_convertible (gdbarch, mips_register_convertible);
6119 set_gdbarch_deprecated_register_convert_to_virtual (gdbarch, mips_register_convert_to_virtual);
6120 set_gdbarch_deprecated_register_convert_to_raw (gdbarch, mips_register_convert_to_raw);
6122 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
6123 set_gdbarch_frameless_function_invocation (gdbarch,
6124 generic_frameless_function_invocation_not);
6125 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
6126 set_gdbarch_frame_args_skip (gdbarch, 0);
6128 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
6130 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6131 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6132 set_gdbarch_decr_pc_after_break (gdbarch, 0);
6134 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6135 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
6137 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6138 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6139 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6141 set_gdbarch_function_start_offset (gdbarch, 0);
6143 set_gdbarch_register_type (gdbarch, mips_register_type);
6145 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
6146 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
6148 /* Hook in OS ABI-specific overrides, if they have been registered. */
6149 gdbarch_init_osabi (info, gdbarch);
6151 set_gdbarch_extract_struct_value_address (gdbarch,
6152 mips_extract_struct_value_address);
6154 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6156 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6157 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6163 mips_abi_update (char *ignore_args, int from_tty,
6164 struct cmd_list_element *c)
6166 struct gdbarch_info info;
6168 /* Force the architecture to update, and (if it's a MIPS architecture)
6169 mips_gdbarch_init will take care of the rest. */
6170 gdbarch_info_init (&info);
6171 gdbarch_update_p (info);
6174 /* Print out which MIPS ABI is in use. */
6177 show_mips_abi (char *ignore_args, int from_tty)
6179 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6181 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6184 enum mips_abi global_abi = global_mips_abi ();
6185 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6186 const char *actual_abi_str = mips_abi_strings[actual_abi];
6188 if (global_abi == MIPS_ABI_UNKNOWN)
6189 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6191 else if (global_abi == actual_abi)
6193 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6197 /* Probably shouldn't happen... */
6199 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6201 mips_abi_strings[global_abi]);
6207 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6209 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6213 int ef_mips_32bitmode;
6214 /* determine the ISA */
6215 switch (tdep->elf_flags & EF_MIPS_ARCH)
6233 /* determine the size of a pointer */
6234 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6241 fprintf_unfiltered (file,
6242 "mips_dump_tdep: ef_mips_arch = %d\n",
6244 fprintf_unfiltered (file,
6245 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6247 mips_abi_strings[tdep->mips_abi]);
6248 fprintf_unfiltered (file,
6249 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6250 mips_mask_address_p (),
6251 tdep->default_mask_address_p);
6253 fprintf_unfiltered (file,
6254 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6255 FP_REGISTER_DOUBLE);
6256 fprintf_unfiltered (file,
6257 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6258 MIPS_DEFAULT_FPU_TYPE,
6259 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6260 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6261 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6263 fprintf_unfiltered (file,
6264 "mips_dump_tdep: MIPS_EABI = %d\n",
6266 fprintf_unfiltered (file,
6267 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6268 MIPS_LAST_FP_ARG_REGNUM,
6269 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6270 fprintf_unfiltered (file,
6271 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6273 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6274 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6275 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6277 fprintf_unfiltered (file,
6278 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6279 MIPS_DEFAULT_SAVED_REGSIZE);
6280 fprintf_unfiltered (file,
6281 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6282 FP_REGISTER_DOUBLE);
6283 fprintf_unfiltered (file,
6284 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6285 MIPS_DEFAULT_STACK_ARGSIZE);
6286 fprintf_unfiltered (file,
6287 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6288 MIPS_STACK_ARGSIZE);
6289 fprintf_unfiltered (file,
6290 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6292 fprintf_unfiltered (file,
6293 "mips_dump_tdep: A0_REGNUM = %d\n",
6295 fprintf_unfiltered (file,
6296 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6297 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6298 fprintf_unfiltered (file,
6299 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6300 XSTRING (ATTACH_DETACH));
6301 fprintf_unfiltered (file,
6302 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6304 fprintf_unfiltered (file,
6305 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6307 fprintf_unfiltered (file,
6308 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6309 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6310 fprintf_unfiltered (file,
6311 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6312 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6313 fprintf_unfiltered (file,
6314 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6316 fprintf_unfiltered (file,
6317 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6319 fprintf_unfiltered (file,
6320 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6321 FIRST_EMBED_REGNUM);
6322 fprintf_unfiltered (file,
6323 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6325 fprintf_unfiltered (file,
6326 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6327 GDB_TARGET_IS_MIPS64);
6328 fprintf_unfiltered (file,
6329 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6330 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6331 fprintf_unfiltered (file,
6332 "mips_dump_tdep: HI_REGNUM = %d\n",
6334 fprintf_unfiltered (file,
6335 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6336 XSTRING (IGNORE_HELPER_CALL (PC)));
6337 fprintf_unfiltered (file,
6338 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6339 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6340 fprintf_unfiltered (file,
6341 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6342 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6343 fprintf_unfiltered (file,
6344 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: LO_REGNUM = %d\n",
6349 #ifdef MACHINE_CPROC_FP_OFFSET
6350 fprintf_unfiltered (file,
6351 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6352 MACHINE_CPROC_FP_OFFSET);
6354 #ifdef MACHINE_CPROC_PC_OFFSET
6355 fprintf_unfiltered (file,
6356 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6357 MACHINE_CPROC_PC_OFFSET);
6359 #ifdef MACHINE_CPROC_SP_OFFSET
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6362 MACHINE_CPROC_SP_OFFSET);
6364 fprintf_unfiltered (file,
6365 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6367 fprintf_unfiltered (file,
6368 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6369 fprintf_unfiltered (file,
6370 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6371 fprintf_unfiltered (file,
6372 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6374 fprintf_unfiltered (file,
6375 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6376 MIPS_LAST_ARG_REGNUM,
6377 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6378 fprintf_unfiltered (file,
6379 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6381 fprintf_unfiltered (file,
6382 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6383 fprintf_unfiltered (file,
6384 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6385 MIPS_SAVED_REGSIZE);
6386 fprintf_unfiltered (file,
6387 "mips_dump_tdep: OP_LDFPR = used?\n");
6388 fprintf_unfiltered (file,
6389 "mips_dump_tdep: OP_LDGPR = used?\n");
6390 fprintf_unfiltered (file,
6391 "mips_dump_tdep: PRID_REGNUM = %d\n",
6393 fprintf_unfiltered (file,
6394 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6395 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6396 fprintf_unfiltered (file,
6397 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6398 fprintf_unfiltered (file,
6399 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6400 fprintf_unfiltered (file,
6401 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6402 fprintf_unfiltered (file,
6403 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6404 fprintf_unfiltered (file,
6405 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6406 fprintf_unfiltered (file,
6407 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6408 fprintf_unfiltered (file,
6409 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6410 fprintf_unfiltered (file,
6411 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6412 fprintf_unfiltered (file,
6413 "mips_dump_tdep: PROC_PC_REG = function?\n");
6414 fprintf_unfiltered (file,
6415 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6416 fprintf_unfiltered (file,
6417 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6418 fprintf_unfiltered (file,
6419 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6420 fprintf_unfiltered (file,
6421 "mips_dump_tdep: PS_REGNUM = %d\n",
6423 fprintf_unfiltered (file,
6424 "mips_dump_tdep: RA_REGNUM = %d\n",
6426 fprintf_unfiltered (file,
6427 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6428 fprintf_unfiltered (file,
6429 "mips_dump_tdep: ROUND_DOWN = function?\n");
6430 fprintf_unfiltered (file,
6431 "mips_dump_tdep: ROUND_UP = function?\n");
6433 fprintf_unfiltered (file,
6434 "mips_dump_tdep: SAVED_BYTES = %d\n",
6438 fprintf_unfiltered (file,
6439 "mips_dump_tdep: SAVED_FP = %d\n",
6443 fprintf_unfiltered (file,
6444 "mips_dump_tdep: SAVED_PC = %d\n",
6447 fprintf_unfiltered (file,
6448 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6449 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6450 fprintf_unfiltered (file,
6451 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6452 fprintf_unfiltered (file,
6453 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6455 fprintf_unfiltered (file,
6456 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6457 SIGFRAME_FPREGSAVE_OFF);
6458 fprintf_unfiltered (file,
6459 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6461 fprintf_unfiltered (file,
6462 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6463 SIGFRAME_REGSAVE_OFF);
6464 fprintf_unfiltered (file,
6465 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6467 fprintf_unfiltered (file,
6468 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6469 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6470 fprintf_unfiltered (file,
6471 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6472 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6473 fprintf_unfiltered (file,
6474 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6475 SOFTWARE_SINGLE_STEP_P ());
6476 fprintf_unfiltered (file,
6477 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6478 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6479 #ifdef STACK_END_ADDR
6480 fprintf_unfiltered (file,
6481 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6484 fprintf_unfiltered (file,
6485 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6486 XSTRING (STEP_SKIPS_DELAY (PC)));
6487 fprintf_unfiltered (file,
6488 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6489 STEP_SKIPS_DELAY_P);
6490 fprintf_unfiltered (file,
6491 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6492 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6493 fprintf_unfiltered (file,
6494 "mips_dump_tdep: T9_REGNUM = %d\n",
6496 fprintf_unfiltered (file,
6497 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6498 fprintf_unfiltered (file,
6499 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6500 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6501 fprintf_unfiltered (file,
6502 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6503 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6505 fprintf_unfiltered (file,
6506 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6507 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6510 fprintf_unfiltered (file,
6511 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6514 #ifdef TRACE_FLAVOR_SIZE
6515 fprintf_unfiltered (file,
6516 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6520 fprintf_unfiltered (file,
6521 "mips_dump_tdep: TRACE_SET # %s\n",
6522 XSTRING (TRACE_SET (X,STATE)));
6524 #ifdef UNUSED_REGNUM
6525 fprintf_unfiltered (file,
6526 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6529 fprintf_unfiltered (file,
6530 "mips_dump_tdep: V0_REGNUM = %d\n",
6532 fprintf_unfiltered (file,
6533 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6534 (long) VM_MIN_ADDRESS);
6536 fprintf_unfiltered (file,
6537 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6540 fprintf_unfiltered (file,
6541 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6543 fprintf_unfiltered (file,
6544 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6548 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6551 _initialize_mips_tdep (void)
6553 static struct cmd_list_element *mipsfpulist = NULL;
6554 struct cmd_list_element *c;
6556 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6557 if (MIPS_ABI_LAST + 1
6558 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6559 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6561 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6562 if (!deprecated_tm_print_insn) /* Someone may have already set it */
6563 deprecated_tm_print_insn = gdb_print_insn_mips;
6565 /* Add root prefix command for all "set mips"/"show mips" commands */
6566 add_prefix_cmd ("mips", no_class, set_mips_command,
6567 "Various MIPS specific commands.",
6568 &setmipscmdlist, "set mips ", 0, &setlist);
6570 add_prefix_cmd ("mips", no_class, show_mips_command,
6571 "Various MIPS specific commands.",
6572 &showmipscmdlist, "show mips ", 0, &showlist);
6574 /* Allow the user to override the saved register size. */
6575 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6578 &mips_saved_regsize_string, "\
6579 Set size of general purpose registers saved on the stack.\n\
6580 This option can be set to one of:\n\
6581 32 - Force GDB to treat saved GP registers as 32-bit\n\
6582 64 - Force GDB to treat saved GP registers as 64-bit\n\
6583 auto - Allow GDB to use the target's default setting or autodetect the\n\
6584 saved GP register size from information contained in the executable.\n\
6589 /* Allow the user to override the argument stack size. */
6590 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6593 &mips_stack_argsize_string, "\
6594 Set the amount of stack space reserved for each argument.\n\
6595 This option can be set to one of:\n\
6596 32 - Force GDB to allocate 32-bit chunks per argument\n\
6597 64 - Force GDB to allocate 64-bit chunks per argument\n\
6598 auto - Allow GDB to determine the correct setting from the current\n\
6599 target and executable (default)",
6603 /* Allow the user to override the ABI. */
6604 c = add_set_enum_cmd
6605 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6606 "Set the ABI used by this program.\n"
6607 "This option can be set to one of:\n"
6608 " auto - the default ABI associated with the current binary\n"
6616 set_cmd_sfunc (c, mips_abi_update);
6617 add_cmd ("abi", class_obscure, show_mips_abi,
6618 "Show ABI in use by MIPS target", &showmipscmdlist);
6620 /* Let the user turn off floating point and set the fence post for
6621 heuristic_proc_start. */
6623 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6624 "Set use of MIPS floating-point coprocessor.",
6625 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6626 add_cmd ("single", class_support, set_mipsfpu_single_command,
6627 "Select single-precision MIPS floating-point coprocessor.",
6629 add_cmd ("double", class_support, set_mipsfpu_double_command,
6630 "Select double-precision MIPS floating-point coprocessor.",
6632 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6633 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6634 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6635 add_cmd ("none", class_support, set_mipsfpu_none_command,
6636 "Select no MIPS floating-point coprocessor.",
6638 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6639 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6640 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6641 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6642 "Select MIPS floating-point coprocessor automatically.",
6644 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6645 "Show current use of MIPS floating-point coprocessor target.",
6648 /* We really would like to have both "0" and "unlimited" work, but
6649 command.c doesn't deal with that. So make it a var_zinteger
6650 because the user can always use "999999" or some such for unlimited. */
6651 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6652 (char *) &heuristic_fence_post,
6654 Set the distance searched for the start of a function.\n\
6655 If you are debugging a stripped executable, GDB needs to search through the\n\
6656 program for the start of a function. This command sets the distance of the\n\
6657 search. The only need to set it is when debugging a stripped executable.",
6659 /* We need to throw away the frame cache when we set this, since it
6660 might change our ability to get backtraces. */
6661 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6662 add_show_from_set (c, &showlist);
6664 /* Allow the user to control whether the upper bits of 64-bit
6665 addresses should be zeroed. */
6666 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6667 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6668 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6669 allow GDB to determine the correct value.\n", "\
6670 Show zeroing of upper 32 bits of 64-bit addresses.",
6671 NULL, show_mask_address,
6672 &setmipscmdlist, &showmipscmdlist);
6674 /* Allow the user to control the size of 32 bit registers within the
6675 raw remote packet. */
6676 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6679 (char *)&mips64_transfers_32bit_regs_p, "\
6680 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6681 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6682 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6683 64 bits for others. Use \"off\" to disable compatibility mode",
6687 /* Debug this files internals. */
6688 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6689 &mips_debug, "Set mips debugging.\n\
6690 When non-zero, mips specific debugging is enabled.", &setdebuglist),