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"
46 #include "opcode/mips.h"
51 /* A useful bit in the CP0 status register (PS_REGNUM). */
52 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
53 #define ST0_FR (1 << 26)
55 /* The sizes of floating point registers. */
59 MIPS_FPU_SINGLE_REGSIZE = 4,
60 MIPS_FPU_DOUBLE_REGSIZE = 8
64 static const char *mips_abi_string;
66 static const char *mips_abi_strings[] = {
77 struct frame_extra_info
79 mips_extra_func_info_t proc_desc;
83 /* Various MIPS ISA options (related to stack analysis) can be
84 overridden dynamically. Establish an enum/array for managing
87 static const char size_auto[] = "auto";
88 static const char size_32[] = "32";
89 static const char size_64[] = "64";
91 static const char *size_enums[] = {
98 /* Some MIPS boards don't support floating point while others only
99 support single-precision floating-point operations. See also
100 FP_REGISTER_DOUBLE. */
104 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
105 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
106 MIPS_FPU_NONE /* No floating point. */
109 #ifndef MIPS_DEFAULT_FPU_TYPE
110 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
112 static int mips_fpu_type_auto = 1;
113 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
115 static int mips_debug = 0;
117 /* MIPS specific per-architecture information */
120 /* from the elf header */
124 enum mips_abi mips_abi;
125 enum mips_abi found_abi;
126 enum mips_fpu_type mips_fpu_type;
127 int mips_last_arg_regnum;
128 int mips_last_fp_arg_regnum;
129 int mips_default_saved_regsize;
130 int mips_fp_register_double;
131 int mips_default_stack_argsize;
132 int gdb_target_is_mips64;
133 int default_mask_address_p;
136 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
137 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
139 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
141 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
143 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
145 /* Return the currently configured (or set) saved register size. */
147 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
149 static const char *mips_saved_regsize_string = size_auto;
151 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
153 /* Return the contents of register REGNUM as a signed integer. */
156 read_signed_register (int regnum)
158 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
159 deprecated_read_register_gen (regnum, buf);
160 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
164 read_signed_register_pid (int regnum, ptid_t ptid)
169 if (ptid_equal (ptid, inferior_ptid))
170 return read_signed_register (regnum);
172 save_ptid = inferior_ptid;
174 inferior_ptid = ptid;
176 retval = read_signed_register (regnum);
178 inferior_ptid = save_ptid;
183 /* Return the MIPS ABI associated with GDBARCH. */
185 mips_abi (struct gdbarch *gdbarch)
187 return gdbarch_tdep (gdbarch)->mips_abi;
191 mips_saved_regsize (void)
193 if (mips_saved_regsize_string == size_auto)
194 return MIPS_DEFAULT_SAVED_REGSIZE;
195 else if (mips_saved_regsize_string == size_64)
197 else /* if (mips_saved_regsize_string == size_32) */
201 /* Functions for setting and testing a bit in a minimal symbol that
202 marks it as 16-bit function. The MSB of the minimal symbol's
203 "info" field is used for this purpose. This field is already
204 being used to store the symbol size, so the assumption is
205 that the symbol size cannot exceed 2^31.
207 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
208 i.e. refers to a 16-bit function, and sets a "special" bit in a
209 minimal symbol to mark it as a 16-bit function
211 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
212 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
213 the "info" field with the "special" bit masked out */
216 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
218 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
220 MSYMBOL_INFO (msym) = (char *)
221 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
222 SYMBOL_VALUE_ADDRESS (msym) |= 1;
227 msymbol_is_special (struct minimal_symbol *msym)
229 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
233 msymbol_size (struct minimal_symbol *msym)
235 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
238 /* XFER a value from the big/little/left end of the register.
239 Depending on the size of the value it might occupy the entire
240 register or just part of it. Make an allowance for this, aligning
241 things accordingly. */
244 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
245 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
248 bfd_byte reg[MAX_REGISTER_SIZE];
250 /* Need to transfer the left or right part of the register, based on
251 the targets byte order. */
255 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
257 case BFD_ENDIAN_LITTLE:
260 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
264 internal_error (__FILE__, __LINE__, "bad switch");
267 fprintf_unfiltered (gdb_stderr,
268 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
269 reg_num, reg_offset, buf_offset, length);
270 if (mips_debug && out != NULL)
273 fprintf_unfiltered (gdb_stdlog, "out ");
274 for (i = 0; i < length; i++)
275 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
278 regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
280 regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
281 if (mips_debug && in != NULL)
284 fprintf_unfiltered (gdb_stdlog, "in ");
285 for (i = 0; i < length; i++)
286 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
289 fprintf_unfiltered (gdb_stdlog, "\n");
292 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
293 compatiblity mode. A return value of 1 means that we have
294 physical 64-bit registers, but should treat them as 32-bit registers. */
297 mips2_fp_compat (void)
299 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
301 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
305 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
306 in all the places we deal with FP registers. PR gdb/413. */
307 /* Otherwise check the FR bit in the status register - it controls
308 the FP compatiblity mode. If it is clear we are in compatibility
310 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
317 /* Indicate that the ABI makes use of double-precision registers
318 provided by the FPU (rather than combining pairs of registers to
319 form double-precision values). Do not use "TARGET_IS_MIPS64" to
320 determine if the ABI is using double-precision registers. See also
322 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
324 /* The amount of space reserved on the stack for registers. This is
325 different to MIPS_SAVED_REGSIZE as it determines the alignment of
326 data allocated after the registers have run out. */
328 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
330 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
332 static const char *mips_stack_argsize_string = size_auto;
335 mips_stack_argsize (void)
337 if (mips_stack_argsize_string == size_auto)
338 return MIPS_DEFAULT_STACK_ARGSIZE;
339 else if (mips_stack_argsize_string == size_64)
341 else /* if (mips_stack_argsize_string == size_32) */
345 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
347 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
349 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
351 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
353 static void mips_print_register (int, int);
355 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
356 struct frame_info *, int);
358 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
360 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
362 static int mips_set_processor_type (char *);
364 static void mips_show_processor_type_command (char *, int);
366 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
368 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
369 struct frame_info *next_frame,
372 static CORE_ADDR after_prologue (CORE_ADDR pc,
373 mips_extra_func_info_t proc_desc);
375 static void mips_read_fp_register_single (int regno, char *rare_buffer);
376 static void mips_read_fp_register_double (int regno, char *rare_buffer);
378 static struct type *mips_float_register_type (void);
379 static struct type *mips_double_register_type (void);
381 /* This value is the model of MIPS in use. It is derived from the value
382 of the PrID register. */
384 char *mips_processor_type;
386 char *tmp_mips_processor_type;
388 /* The list of available "set mips " and "show mips " commands */
390 static struct cmd_list_element *setmipscmdlist = NULL;
391 static struct cmd_list_element *showmipscmdlist = NULL;
393 /* A set of original names, to be used when restoring back to generic
394 registers from a specific set. */
395 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
397 /* Integer registers 0 thru 31 are handled explicitly by
398 mips_register_name(). Processor specific registers 32 and above
399 are listed in the sets of register names assigned to
400 mips_processor_reg_names. */
401 static char **mips_processor_reg_names = mips_generic_reg_names;
403 /* Return the name of the register corresponding to REGNO. */
405 mips_register_name (int regno)
407 /* GPR names for all ABIs other than n32/n64. */
408 static char *mips_gpr_names[] = {
409 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
410 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
411 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
412 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
415 /* GPR names for n32 and n64 ABIs. */
416 static char *mips_n32_n64_gpr_names[] = {
417 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
418 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
419 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
420 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
423 enum mips_abi abi = mips_abi (current_gdbarch);
425 /* The MIPS integer registers are always mapped from 0 to 31. The
426 names of the registers (which reflects the conventions regarding
427 register use) vary depending on the ABI. */
428 if (0 <= regno && regno < 32)
430 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
431 return mips_n32_n64_gpr_names[regno];
433 return mips_gpr_names[regno];
435 else if (32 <= regno && regno < NUM_REGS)
436 return mips_processor_reg_names[regno - 32];
438 internal_error (__FILE__, __LINE__,
439 "mips_register_name: bad register number %d", regno);
443 /* Names of IDT R3041 registers. */
445 char *mips_r3041_reg_names[] = {
446 "sr", "lo", "hi", "bad", "cause","pc",
447 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
448 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
449 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
450 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
451 "fsr", "fir", "",/*"fp"*/ "",
452 "", "", "bus", "ccfg", "", "", "", "",
453 "", "", "port", "cmp", "", "", "epc", "prid",
456 /* Names of IDT R3051 registers. */
458 char *mips_r3051_reg_names[] = {
459 "sr", "lo", "hi", "bad", "cause","pc",
460 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
461 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
462 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
463 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
464 "fsr", "fir", ""/*"fp"*/, "",
465 "inx", "rand", "elo", "", "ctxt", "", "", "",
466 "", "", "ehi", "", "", "", "epc", "prid",
469 /* Names of IDT R3081 registers. */
471 char *mips_r3081_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 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
479 "", "", "ehi", "", "", "", "epc", "prid",
482 /* Names of LSI 33k registers. */
484 char *mips_lsi33k_reg_names[] = {
485 "epc", "hi", "lo", "sr", "cause","badvaddr",
486 "dcic", "bpc", "bda", "", "", "", "", "",
487 "", "", "", "", "", "", "", "",
488 "", "", "", "", "", "", "", "",
489 "", "", "", "", "", "", "", "",
491 "", "", "", "", "", "", "", "",
492 "", "", "", "", "", "", "", "",
498 } mips_processor_type_table[] = {
499 { "generic", mips_generic_reg_names },
500 { "r3041", mips_r3041_reg_names },
501 { "r3051", mips_r3051_reg_names },
502 { "r3071", mips_r3081_reg_names },
503 { "r3081", mips_r3081_reg_names },
504 { "lsi33k", mips_lsi33k_reg_names },
512 /* Table to translate MIPS16 register field to actual register number. */
513 static int mips16_to_32_reg[8] =
514 {16, 17, 2, 3, 4, 5, 6, 7};
516 /* Heuristic_proc_start may hunt through the text section for a long
517 time across a 2400 baud serial line. Allows the user to limit this
520 static unsigned int heuristic_fence_post = 0;
522 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
523 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
524 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
525 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
526 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
527 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
528 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
529 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
530 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
531 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
532 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
533 this will corrupt pdr.iline. Fortunately we don't use it. */
534 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
535 #define _PROC_MAGIC_ 0x0F0F0F0F
536 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
537 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
539 struct linked_proc_info
541 struct mips_extra_func_info info;
542 struct linked_proc_info *next;
544 *linked_proc_desc_table = NULL;
547 mips_print_extra_frame_info (struct frame_info *fi)
550 && get_frame_extra_info (fi)
551 && get_frame_extra_info (fi)->proc_desc
552 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
553 printf_filtered (" frame pointer is at %s+%s\n",
554 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
555 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
558 /* Number of bytes of storage in the actual machine representation for
559 register N. NOTE: This indirectly defines the register size
560 transfered by the GDB protocol. */
562 static int mips64_transfers_32bit_regs_p = 0;
565 mips_register_raw_size (int reg_nr)
567 if (mips64_transfers_32bit_regs_p)
568 return REGISTER_VIRTUAL_SIZE (reg_nr);
569 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
570 && FP_REGISTER_DOUBLE)
571 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
578 /* Convert between RAW and VIRTUAL registers. The RAW register size
579 defines the remote-gdb packet. */
582 mips_register_convertible (int reg_nr)
584 if (mips64_transfers_32bit_regs_p)
587 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
591 mips_register_convert_to_virtual (int n, struct type *virtual_type,
592 char *raw_buf, char *virt_buf)
594 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
596 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
597 TYPE_LENGTH (virtual_type));
601 TYPE_LENGTH (virtual_type));
605 mips_register_convert_to_raw (struct type *virtual_type, int n,
606 char *virt_buf, char *raw_buf)
608 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
609 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
610 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
612 TYPE_LENGTH (virtual_type));
616 TYPE_LENGTH (virtual_type));
620 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
622 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
623 && REGISTER_RAW_SIZE (regnum) == 4
624 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
625 && TYPE_CODE(type) == TYPE_CODE_FLT
626 && TYPE_LENGTH(type) == 8)
629 memcpy (temp, ((char *)(buffer))+4, 4);
630 memcpy (((char *)(buffer))+4, (buffer), 4);
631 memcpy (((char *)(buffer)), temp, 4);
636 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
638 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
639 && REGISTER_RAW_SIZE (regnum) == 4
640 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
641 && TYPE_CODE(type) == TYPE_CODE_FLT
642 && TYPE_LENGTH(type) == 8)
645 memcpy (temp, ((char *)(buffer))+4, 4);
646 memcpy (((char *)(buffer))+4, (buffer), 4);
647 memcpy (((char *)(buffer)), temp, 4);
651 /* Return the GDB type object for the "standard" data type
652 of data in register REG.
654 Note: kevinb/2002-08-01: The definition below should faithfully
655 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
656 definitions found in config/mips/tm-*.h. I'm concerned about the
657 ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause though.
658 In some cases DEPRECATED_FP_REGNUM is in this range, and I doubt
659 that this code is correct for the 64-bit case. */
662 mips_register_virtual_type (int reg)
664 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
666 /* Floating point registers... */
667 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
668 return builtin_type_ieee_double_big;
670 return builtin_type_ieee_double_little;
672 else if (reg == PS_REGNUM /* CR */)
673 return builtin_type_uint32;
674 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
675 return builtin_type_uint32;
678 /* Everything else...
679 Return type appropriate for width of register. */
680 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
681 return builtin_type_uint64;
683 return builtin_type_uint32;
687 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
692 return read_signed_register (SP_REGNUM);
695 /* Should the upper word of 64-bit addresses be zeroed? */
696 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
699 mips_mask_address_p (void)
701 switch (mask_address_var)
703 case AUTO_BOOLEAN_TRUE:
705 case AUTO_BOOLEAN_FALSE:
708 case AUTO_BOOLEAN_AUTO:
709 return MIPS_DEFAULT_MASK_ADDRESS_P;
711 internal_error (__FILE__, __LINE__,
712 "mips_mask_address_p: bad switch");
718 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
720 switch (mask_address_var)
722 case AUTO_BOOLEAN_TRUE:
723 printf_filtered ("The 32 bit mips address mask is enabled\n");
725 case AUTO_BOOLEAN_FALSE:
726 printf_filtered ("The 32 bit mips address mask is disabled\n");
728 case AUTO_BOOLEAN_AUTO:
729 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
730 mips_mask_address_p () ? "enabled" : "disabled");
733 internal_error (__FILE__, __LINE__,
734 "show_mask_address: bad switch");
739 /* Should call_function allocate stack space for a struct return? */
742 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
744 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
748 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
750 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
754 mips_o32_use_struct_convention (int gcc_p, struct type *type)
756 return 1; /* Structures are returned by ref in extra arg0. */
759 /* Should call_function pass struct by reference?
760 For each architecture, structs are passed either by
761 value or by reference, depending on their size. */
764 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
766 enum type_code typecode = TYPE_CODE (check_typedef (type));
767 int len = TYPE_LENGTH (check_typedef (type));
769 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
770 return (len > MIPS_SAVED_REGSIZE);
776 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
778 return 0; /* Assumption: N32/N64 never passes struct by ref. */
782 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
784 return 0; /* Assumption: O32/O64 never passes struct by ref. */
787 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
790 pc_is_mips16 (bfd_vma memaddr)
792 struct minimal_symbol *sym;
794 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
795 if (IS_MIPS16_ADDR (memaddr))
798 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
799 the high bit of the info field. Use this to decide if the function is
800 MIPS16 or normal MIPS. */
801 sym = lookup_minimal_symbol_by_pc (memaddr);
803 return msymbol_is_special (sym);
808 /* MIPS believes that the PC has a sign extended value. Perhaphs the
809 all registers should be sign extended for simplicity? */
812 mips_read_pc (ptid_t ptid)
814 return read_signed_register_pid (PC_REGNUM, ptid);
817 /* This returns the PC of the first inst after the prologue. If we can't
818 find the prologue, then return 0. */
821 after_prologue (CORE_ADDR pc,
822 mips_extra_func_info_t proc_desc)
824 struct symtab_and_line sal;
825 CORE_ADDR func_addr, func_end;
827 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
828 to read the stack pointer from the current machine state, because
829 the current machine state has nothing to do with the information
830 we need from the proc_desc; and the process may or may not exist
833 proc_desc = find_proc_desc (pc, NULL, 0);
837 /* If function is frameless, then we need to do it the hard way. I
838 strongly suspect that frameless always means prologueless... */
839 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
840 && PROC_FRAME_OFFSET (proc_desc) == 0)
844 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
845 return 0; /* Unknown */
847 sal = find_pc_line (func_addr, 0);
849 if (sal.end < func_end)
852 /* The line after the prologue is after the end of the function. In this
853 case, tell the caller to find the prologue the hard way. */
858 /* Decode a MIPS32 instruction that saves a register in the stack, and
859 set the appropriate bit in the general register mask or float register mask
860 to indicate which register is saved. This is a helper function
861 for mips_find_saved_regs. */
864 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
865 unsigned long *float_mask)
869 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
870 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
871 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
873 /* It might be possible to use the instruction to
874 find the offset, rather than the code below which
875 is based on things being in a certain order in the
876 frame, but figuring out what the instruction's offset
877 is relative to might be a little tricky. */
878 reg = (inst & 0x001f0000) >> 16;
879 *gen_mask |= (1 << reg);
881 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
882 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
883 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
886 reg = ((inst & 0x001f0000) >> 16);
887 *float_mask |= (1 << reg);
891 /* Decode a MIPS16 instruction that saves a register in the stack, and
892 set the appropriate bit in the general register or float register mask
893 to indicate which register is saved. This is a helper function
894 for mips_find_saved_regs. */
897 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
899 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
901 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
902 *gen_mask |= (1 << reg);
904 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
906 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
907 *gen_mask |= (1 << reg);
909 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
910 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
911 *gen_mask |= (1 << RA_REGNUM);
915 /* Fetch and return instruction from the specified location. If the PC
916 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
919 mips_fetch_instruction (CORE_ADDR addr)
921 char buf[MIPS_INSTLEN];
925 if (pc_is_mips16 (addr))
927 instlen = MIPS16_INSTLEN;
928 addr = UNMAKE_MIPS16_ADDR (addr);
931 instlen = MIPS_INSTLEN;
932 status = read_memory_nobpt (addr, buf, instlen);
934 memory_error (status, addr);
935 return extract_unsigned_integer (buf, instlen);
939 /* These the fields of 32 bit mips instructions */
940 #define mips32_op(x) (x >> 26)
941 #define itype_op(x) (x >> 26)
942 #define itype_rs(x) ((x >> 21) & 0x1f)
943 #define itype_rt(x) ((x >> 16) & 0x1f)
944 #define itype_immediate(x) (x & 0xffff)
946 #define jtype_op(x) (x >> 26)
947 #define jtype_target(x) (x & 0x03ffffff)
949 #define rtype_op(x) (x >> 26)
950 #define rtype_rs(x) ((x >> 21) & 0x1f)
951 #define rtype_rt(x) ((x >> 16) & 0x1f)
952 #define rtype_rd(x) ((x >> 11) & 0x1f)
953 #define rtype_shamt(x) ((x >> 6) & 0x1f)
954 #define rtype_funct(x) (x & 0x3f)
957 mips32_relative_offset (unsigned long inst)
960 x = itype_immediate (inst);
961 if (x & 0x8000) /* sign bit set */
963 x |= 0xffff0000; /* sign extension */
969 /* Determine whate to set a single step breakpoint while considering
972 mips32_next_pc (CORE_ADDR pc)
976 inst = mips_fetch_instruction (pc);
977 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
979 if (itype_op (inst) >> 2 == 5)
980 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
982 op = (itype_op (inst) & 0x03);
997 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
998 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1000 int tf = itype_rt (inst) & 0x01;
1001 int cnum = itype_rt (inst) >> 2;
1002 int fcrcs = read_signed_register (FCRCS_REGNUM);
1003 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1005 if (((cond >> cnum) & 0x01) == tf)
1006 pc += mips32_relative_offset (inst) + 4;
1011 pc += 4; /* Not a branch, next instruction is easy */
1014 { /* This gets way messy */
1016 /* Further subdivide into SPECIAL, REGIMM and other */
1017 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
1019 case 0: /* SPECIAL */
1020 op = rtype_funct (inst);
1025 /* Set PC to that address */
1026 pc = read_signed_register (rtype_rs (inst));
1032 break; /* end SPECIAL */
1033 case 1: /* REGIMM */
1035 op = itype_rt (inst); /* branch condition */
1040 case 16: /* BLTZAL */
1041 case 18: /* BLTZALL */
1043 if (read_signed_register (itype_rs (inst)) < 0)
1044 pc += mips32_relative_offset (inst) + 4;
1046 pc += 8; /* after the delay slot */
1050 case 17: /* BGEZAL */
1051 case 19: /* BGEZALL */
1052 greater_equal_branch:
1053 if (read_signed_register (itype_rs (inst)) >= 0)
1054 pc += mips32_relative_offset (inst) + 4;
1056 pc += 8; /* after the delay slot */
1058 /* All of the other instructions in the REGIMM category */
1063 break; /* end REGIMM */
1068 reg = jtype_target (inst) << 2;
1069 /* Upper four bits get never changed... */
1070 pc = reg + ((pc + 4) & 0xf0000000);
1073 /* FIXME case JALX : */
1076 reg = jtype_target (inst) << 2;
1077 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1078 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1080 break; /* The new PC will be alternate mode */
1081 case 4: /* BEQ, BEQL */
1083 if (read_signed_register (itype_rs (inst)) ==
1084 read_signed_register (itype_rt (inst)))
1085 pc += mips32_relative_offset (inst) + 4;
1089 case 5: /* BNE, BNEL */
1091 if (read_signed_register (itype_rs (inst)) !=
1092 read_signed_register (itype_rt (inst)))
1093 pc += mips32_relative_offset (inst) + 4;
1097 case 6: /* BLEZ, BLEZL */
1099 if (read_signed_register (itype_rs (inst) <= 0))
1100 pc += mips32_relative_offset (inst) + 4;
1106 greater_branch: /* BGTZ, BGTZL */
1107 if (read_signed_register (itype_rs (inst) > 0))
1108 pc += mips32_relative_offset (inst) + 4;
1115 } /* mips32_next_pc */
1117 /* Decoding the next place to set a breakpoint is irregular for the
1118 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1119 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1120 We dont want to set a single step instruction on the extend instruction
1124 /* Lots of mips16 instruction formats */
1125 /* Predicting jumps requires itype,ritype,i8type
1126 and their extensions extItype,extritype,extI8type
1128 enum mips16_inst_fmts
1130 itype, /* 0 immediate 5,10 */
1131 ritype, /* 1 5,3,8 */
1132 rrtype, /* 2 5,3,3,5 */
1133 rritype, /* 3 5,3,3,5 */
1134 rrrtype, /* 4 5,3,3,3,2 */
1135 rriatype, /* 5 5,3,3,1,4 */
1136 shifttype, /* 6 5,3,3,3,2 */
1137 i8type, /* 7 5,3,8 */
1138 i8movtype, /* 8 5,3,3,5 */
1139 i8mov32rtype, /* 9 5,3,5,3 */
1140 i64type, /* 10 5,3,8 */
1141 ri64type, /* 11 5,3,3,5 */
1142 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1143 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1144 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1145 extRRItype, /* 15 5,5,5,5,3,3,5 */
1146 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1147 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1148 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1149 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1150 extRi64type, /* 20 5,6,5,5,3,3,5 */
1151 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1153 /* I am heaping all the fields of the formats into one structure and
1154 then, only the fields which are involved in instruction extension */
1158 unsigned int regx; /* Function in i8 type */
1163 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1164 for the bits which make up the immediatate extension. */
1167 extended_offset (unsigned int extension)
1170 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1172 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1174 value |= extension & 0x01f; /* extract 4:0 */
1178 /* Only call this function if you know that this is an extendable
1179 instruction, It wont malfunction, but why make excess remote memory references?
1180 If the immediate operands get sign extended or somthing, do it after
1181 the extension is performed.
1183 /* FIXME: Every one of these cases needs to worry about sign extension
1184 when the offset is to be used in relative addressing */
1188 fetch_mips_16 (CORE_ADDR pc)
1191 pc &= 0xfffffffe; /* clear the low order bit */
1192 target_read_memory (pc, buf, 2);
1193 return extract_unsigned_integer (buf, 2);
1197 unpack_mips16 (CORE_ADDR pc,
1198 unsigned int extension,
1200 enum mips16_inst_fmts insn_format,
1201 struct upk_mips16 *upk)
1206 switch (insn_format)
1213 value = extended_offset (extension);
1214 value = value << 11; /* rom for the original value */
1215 value |= inst & 0x7ff; /* eleven bits from instruction */
1219 value = inst & 0x7ff;
1220 /* FIXME : Consider sign extension */
1229 { /* A register identifier and an offset */
1230 /* Most of the fields are the same as I type but the
1231 immediate value is of a different length */
1235 value = extended_offset (extension);
1236 value = value << 8; /* from the original instruction */
1237 value |= inst & 0xff; /* eleven bits from instruction */
1238 regx = (extension >> 8) & 0x07; /* or i8 funct */
1239 if (value & 0x4000) /* test the sign bit , bit 26 */
1241 value &= ~0x3fff; /* remove the sign bit */
1247 value = inst & 0xff; /* 8 bits */
1248 regx = (inst >> 8) & 0x07; /* or i8 funct */
1249 /* FIXME: Do sign extension , this format needs it */
1250 if (value & 0x80) /* THIS CONFUSES ME */
1252 value &= 0xef; /* remove the sign bit */
1262 unsigned long value;
1263 unsigned int nexthalf;
1264 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1265 value = value << 16;
1266 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1274 internal_error (__FILE__, __LINE__,
1277 upk->offset = offset;
1284 add_offset_16 (CORE_ADDR pc, int offset)
1286 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1290 extended_mips16_next_pc (CORE_ADDR pc,
1291 unsigned int extension,
1294 int op = (insn >> 11);
1297 case 2: /* Branch */
1300 struct upk_mips16 upk;
1301 unpack_mips16 (pc, extension, insn, itype, &upk);
1302 offset = upk.offset;
1308 pc += (offset << 1) + 2;
1311 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1313 struct upk_mips16 upk;
1314 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1315 pc = add_offset_16 (pc, upk.offset);
1316 if ((insn >> 10) & 0x01) /* Exchange mode */
1317 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1324 struct upk_mips16 upk;
1326 unpack_mips16 (pc, extension, insn, ritype, &upk);
1327 reg = read_signed_register (upk.regx);
1329 pc += (upk.offset << 1) + 2;
1336 struct upk_mips16 upk;
1338 unpack_mips16 (pc, extension, insn, ritype, &upk);
1339 reg = read_signed_register (upk.regx);
1341 pc += (upk.offset << 1) + 2;
1346 case 12: /* I8 Formats btez btnez */
1348 struct upk_mips16 upk;
1350 unpack_mips16 (pc, extension, insn, i8type, &upk);
1351 /* upk.regx contains the opcode */
1352 reg = read_signed_register (24); /* Test register is 24 */
1353 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1354 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1355 /* pc = add_offset_16(pc,upk.offset) ; */
1356 pc += (upk.offset << 1) + 2;
1361 case 29: /* RR Formats JR, JALR, JALR-RA */
1363 struct upk_mips16 upk;
1364 /* upk.fmt = rrtype; */
1369 upk.regx = (insn >> 8) & 0x07;
1370 upk.regy = (insn >> 5) & 0x07;
1378 break; /* Function return instruction */
1384 break; /* BOGUS Guess */
1386 pc = read_signed_register (reg);
1393 /* This is an instruction extension. Fetch the real instruction
1394 (which follows the extension) and decode things based on
1398 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1411 mips16_next_pc (CORE_ADDR pc)
1413 unsigned int insn = fetch_mips_16 (pc);
1414 return extended_mips16_next_pc (pc, 0, insn);
1417 /* The mips_next_pc function supports single_step when the remote
1418 target monitor or stub is not developed enough to do a single_step.
1419 It works by decoding the current instruction and predicting where a
1420 branch will go. This isnt hard because all the data is available.
1421 The MIPS32 and MIPS16 variants are quite different */
1423 mips_next_pc (CORE_ADDR pc)
1426 return mips16_next_pc (pc);
1428 return mips32_next_pc (pc);
1431 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1434 Note: kevinb/2002-08-09: The only caller of this function is (and
1435 should remain) mips_frame_init_saved_regs(). In fact,
1436 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1437 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1438 functions should really be combined and now that there is only one
1439 caller, it should be straightforward. (Watch out for multiple returns
1443 mips_find_saved_regs (struct frame_info *fci)
1446 CORE_ADDR reg_position;
1447 /* r0 bit means kernel trap */
1449 /* What registers have been saved? Bitmasks. */
1450 unsigned long gen_mask, float_mask;
1451 mips_extra_func_info_t proc_desc;
1454 frame_saved_regs_zalloc (fci);
1456 /* If it is the frame for sigtramp, the saved registers are located
1457 in a sigcontext structure somewhere on the stack.
1458 If the stack layout for sigtramp changes we might have to change these
1459 constants and the companion fixup_sigtramp in mdebugread.c */
1460 #ifndef SIGFRAME_BASE
1461 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1462 above the sigtramp frame. */
1463 #define SIGFRAME_BASE MIPS_REGSIZE
1464 /* FIXME! Are these correct?? */
1465 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1466 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1467 #define SIGFRAME_FPREGSAVE_OFF \
1468 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1470 #ifndef SIGFRAME_REG_SIZE
1471 /* FIXME! Is this correct?? */
1472 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1474 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1476 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1478 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1479 + ireg * SIGFRAME_REG_SIZE;
1480 get_frame_saved_regs (fci)[ireg] = reg_position;
1482 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1484 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1485 + ireg * SIGFRAME_REG_SIZE;
1486 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1488 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1492 proc_desc = get_frame_extra_info (fci)->proc_desc;
1493 if (proc_desc == NULL)
1494 /* I'm not sure how/whether this can happen. Normally when we can't
1495 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1496 and set the saved_regs right away. */
1499 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1500 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1501 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1503 if ( /* In any frame other than the innermost or a frame interrupted by
1504 a signal, we assume that all registers have been saved.
1505 This assumes that all register saves in a function happen before
1506 the first function call. */
1507 (get_next_frame (fci) == NULL
1508 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1510 /* In a dummy frame we know exactly where things are saved. */
1511 && !PROC_DESC_IS_DUMMY (proc_desc)
1513 /* Don't bother unless we are inside a function prologue. Outside the
1514 prologue, we know where everything is. */
1516 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1518 /* Not sure exactly what kernel_trap means, but if it means
1519 the kernel saves the registers without a prologue doing it,
1520 we better not examine the prologue to see whether registers
1521 have been saved yet. */
1524 /* We need to figure out whether the registers that the proc_desc
1525 claims are saved have been saved yet. */
1529 /* Bitmasks; set if we have found a save for the register. */
1530 unsigned long gen_save_found = 0;
1531 unsigned long float_save_found = 0;
1534 /* If the address is odd, assume this is MIPS16 code. */
1535 addr = PROC_LOW_ADDR (proc_desc);
1536 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1538 /* Scan through this function's instructions preceding the current
1539 PC, and look for those that save registers. */
1540 while (addr < get_frame_pc (fci))
1542 inst = mips_fetch_instruction (addr);
1543 if (pc_is_mips16 (addr))
1544 mips16_decode_reg_save (inst, &gen_save_found);
1546 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1549 gen_mask = gen_save_found;
1550 float_mask = float_save_found;
1553 /* Fill in the offsets for the registers which gen_mask says
1555 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1556 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1557 if (gen_mask & 0x80000000)
1559 get_frame_saved_regs (fci)[ireg] = reg_position;
1560 reg_position -= MIPS_SAVED_REGSIZE;
1563 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1564 of that normally used by gcc. Therefore, we have to fetch the first
1565 instruction of the function, and if it's an entry instruction that
1566 saves $s0 or $s1, correct their saved addresses. */
1567 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1569 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1570 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1573 int sreg_count = (inst >> 6) & 3;
1575 /* Check if the ra register was pushed on the stack. */
1576 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1578 reg_position -= MIPS_SAVED_REGSIZE;
1580 /* Check if the s0 and s1 registers were pushed on the stack. */
1581 for (reg = 16; reg < sreg_count + 16; reg++)
1583 get_frame_saved_regs (fci)[reg] = reg_position;
1584 reg_position -= MIPS_SAVED_REGSIZE;
1589 /* Fill in the offsets for the registers which float_mask says
1591 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1593 /* Apparently, the freg_offset gives the offset to the first 64 bit
1596 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1597 designates the first saved 64 bit register.
1599 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1600 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1601 FREG_OFFSET, designates the address of the lower register of the
1602 register pair. Adjust the offset so that it designates the upper
1603 register of the pair -- i.e., the address of the first saved 32
1606 if (MIPS_SAVED_REGSIZE == 4)
1607 reg_position += MIPS_SAVED_REGSIZE;
1609 /* Fill in the offsets for the float registers which float_mask says
1611 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1612 if (float_mask & 0x80000000)
1614 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1615 reg_position -= MIPS_SAVED_REGSIZE;
1618 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1621 /* Set up the 'saved_regs' array. This is a data structure containing
1622 the addresses on the stack where each register has been saved, for
1623 each stack frame. Registers that have not been saved will have
1624 zero here. The stack pointer register is special: rather than the
1625 address where the stack register has been saved, saved_regs[SP_REGNUM]
1626 will have the actual value of the previous frame's stack register. */
1629 mips_frame_init_saved_regs (struct frame_info *frame)
1631 if (get_frame_saved_regs (frame) == NULL)
1633 mips_find_saved_regs (frame);
1635 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1639 read_next_frame_reg (struct frame_info *fi, int regno)
1644 enum lval_type lval;
1645 char raw_buffer[MAX_REGISTER_SIZE];
1649 regcache_cooked_read (current_regcache, regno, raw_buffer);
1653 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1655 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1656 should have a pseudo register range that correspons to the ABI's,
1657 rather than the ISA's, view of registers. These registers would
1658 then implicitly describe their size and hence could be used
1659 without the below munging. */
1660 if (lval == lval_memory)
1664 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1666 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1671 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1674 /* mips_addr_bits_remove - remove useless address bits */
1677 mips_addr_bits_remove (CORE_ADDR addr)
1679 if (GDB_TARGET_IS_MIPS64)
1681 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1683 /* This hack is a work-around for existing boards using
1684 PMON, the simulator, and any other 64-bit targets that
1685 doesn't have true 64-bit addressing. On these targets,
1686 the upper 32 bits of addresses are ignored by the
1687 hardware. Thus, the PC or SP are likely to have been
1688 sign extended to all 1s by instruction sequences that
1689 load 32-bit addresses. For example, a typical piece of
1690 code that loads an address is this:
1691 lui $r2, <upper 16 bits>
1692 ori $r2, <lower 16 bits>
1693 But the lui sign-extends the value such that the upper 32
1694 bits may be all 1s. The workaround is simply to mask off
1695 these bits. In the future, gcc may be changed to support
1696 true 64-bit addressing, and this masking will have to be
1698 addr &= (CORE_ADDR) 0xffffffff;
1701 else if (mips_mask_address_p ())
1703 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1704 masking off bits, instead, the actual target should be asking
1705 for the address to be converted to a valid pointer. */
1706 /* Even when GDB is configured for some 32-bit targets
1707 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1708 so CORE_ADDR is 64 bits. So we still have to mask off
1709 useless bits from addresses. */
1710 addr &= (CORE_ADDR) 0xffffffff;
1715 /* mips_software_single_step() is called just before we want to resume
1716 the inferior, if we want to single-step it but there is no hardware
1717 or kernel single-step support (MIPS on GNU/Linux for example). We find
1718 the target of the coming instruction and breakpoint it.
1720 single_step is also called just after the inferior stops. If we had
1721 set up a simulated single-step, we undo our damage. */
1724 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1726 static CORE_ADDR next_pc;
1727 typedef char binsn_quantum[BREAKPOINT_MAX];
1728 static binsn_quantum break_mem;
1731 if (insert_breakpoints_p)
1733 pc = read_register (PC_REGNUM);
1734 next_pc = mips_next_pc (pc);
1736 target_insert_breakpoint (next_pc, break_mem);
1739 target_remove_breakpoint (next_pc, break_mem);
1743 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1748 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1749 : get_next_frame (prev)
1750 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1752 tmp = SKIP_TRAMPOLINE_CODE (pc);
1753 return tmp ? tmp : pc;
1758 mips_frame_saved_pc (struct frame_info *frame)
1761 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1762 /* We have to get the saved pc from the sigcontext
1763 if it is a signal handler frame. */
1764 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1765 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1767 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1770 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1773 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1774 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1776 saved_pc = read_next_frame_reg (frame, pcreg);
1778 return ADDR_BITS_REMOVE (saved_pc);
1781 static struct mips_extra_func_info temp_proc_desc;
1783 /* This hack will go away once the get_prev_frame() code has been
1784 modified to set the frame's type first. That is BEFORE init extra
1785 frame info et.al. is called. This is because it will become
1786 possible to skip the init extra info call for sigtramp and dummy
1788 static CORE_ADDR *temp_saved_regs;
1790 /* Set a register's saved stack address in temp_saved_regs. If an address
1791 has already been set for this register, do nothing; this way we will
1792 only recognize the first save of a given register in a function prologue.
1793 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1796 set_reg_offset (int regno, CORE_ADDR offset)
1798 if (temp_saved_regs[regno] == 0)
1799 temp_saved_regs[regno] = offset;
1803 /* Test whether the PC points to the return instruction at the
1804 end of a function. */
1807 mips_about_to_return (CORE_ADDR pc)
1809 if (pc_is_mips16 (pc))
1810 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1811 generates a "jr $ra"; other times it generates code to load
1812 the return address from the stack to an accessible register (such
1813 as $a3), then a "jr" using that register. This second case
1814 is almost impossible to distinguish from an indirect jump
1815 used for switch statements, so we don't even try. */
1816 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1818 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1822 /* This fencepost looks highly suspicious to me. Removing it also
1823 seems suspicious as it could affect remote debugging across serial
1827 heuristic_proc_start (CORE_ADDR pc)
1834 pc = ADDR_BITS_REMOVE (pc);
1836 fence = start_pc - heuristic_fence_post;
1840 if (heuristic_fence_post == UINT_MAX
1841 || fence < VM_MIN_ADDRESS)
1842 fence = VM_MIN_ADDRESS;
1844 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1846 /* search back for previous return */
1847 for (start_pc -= instlen;; start_pc -= instlen)
1848 if (start_pc < fence)
1850 /* It's not clear to me why we reach this point when
1851 stop_soon, but with this test, at least we
1852 don't print out warnings for every child forked (eg, on
1854 if (stop_soon == NO_STOP_QUIETLY)
1856 static int blurb_printed = 0;
1858 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1863 /* This actually happens frequently in embedded
1864 development, when you first connect to a board
1865 and your stack pointer and pc are nowhere in
1866 particular. This message needs to give people
1867 in that situation enough information to
1868 determine that it's no big deal. */
1869 printf_filtered ("\n\
1870 GDB is unable to find the start of the function at 0x%s\n\
1871 and thus can't determine the size of that function's stack frame.\n\
1872 This means that GDB may be unable to access that stack frame, or\n\
1873 the frames below it.\n\
1874 This problem is most likely caused by an invalid program counter or\n\
1876 However, if you think GDB should simply search farther back\n\
1877 from 0x%s for code which looks like the beginning of a\n\
1878 function, you can increase the range of the search using the `set\n\
1879 heuristic-fence-post' command.\n",
1880 paddr_nz (pc), paddr_nz (pc));
1887 else if (pc_is_mips16 (start_pc))
1889 unsigned short inst;
1891 /* On MIPS16, any one of the following is likely to be the
1892 start of a function:
1896 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1897 inst = mips_fetch_instruction (start_pc);
1898 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1899 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1900 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1901 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1903 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1904 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1909 else if (mips_about_to_return (start_pc))
1911 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1918 /* Fetch the immediate value from a MIPS16 instruction.
1919 If the previous instruction was an EXTEND, use it to extend
1920 the upper bits of the immediate value. This is a helper function
1921 for mips16_heuristic_proc_desc. */
1924 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1925 unsigned short inst, /* current instruction */
1926 int nbits, /* number of bits in imm field */
1927 int scale, /* scale factor to be applied to imm */
1928 int is_signed) /* is the imm field signed? */
1932 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1934 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1935 if (offset & 0x8000) /* check for negative extend */
1936 offset = 0 - (0x10000 - (offset & 0xffff));
1937 return offset | (inst & 0x1f);
1941 int max_imm = 1 << nbits;
1942 int mask = max_imm - 1;
1943 int sign_bit = max_imm >> 1;
1945 offset = inst & mask;
1946 if (is_signed && (offset & sign_bit))
1947 offset = 0 - (max_imm - offset);
1948 return offset * scale;
1953 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1954 stream from start_pc to limit_pc. */
1957 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1958 struct frame_info *next_frame, CORE_ADDR sp)
1961 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1962 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1963 unsigned inst = 0; /* current instruction */
1964 unsigned entry_inst = 0; /* the entry instruction */
1967 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1968 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1970 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1972 /* Save the previous instruction. If it's an EXTEND, we'll extract
1973 the immediate offset extension from it in mips16_get_imm. */
1976 /* Fetch and decode the instruction. */
1977 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1978 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1979 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1981 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1982 if (offset < 0) /* negative stack adjustment? */
1983 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1985 /* Exit loop if a positive stack adjustment is found, which
1986 usually means that the stack cleanup code in the function
1987 epilogue is reached. */
1990 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1992 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1993 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1994 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1995 set_reg_offset (reg, sp + offset);
1997 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1999 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2000 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2001 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2002 set_reg_offset (reg, sp + offset);
2004 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2006 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2007 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2008 set_reg_offset (RA_REGNUM, sp + offset);
2010 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2012 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2013 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2014 set_reg_offset (RA_REGNUM, sp + offset);
2016 else if (inst == 0x673d) /* move $s1, $sp */
2019 PROC_FRAME_REG (&temp_proc_desc) = 17;
2021 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2023 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2024 frame_addr = sp + offset;
2025 PROC_FRAME_REG (&temp_proc_desc) = 17;
2026 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2028 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2030 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2031 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2032 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2033 set_reg_offset (reg, frame_addr + offset);
2035 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2037 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2038 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2039 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2040 set_reg_offset (reg, frame_addr + offset);
2042 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2043 entry_inst = inst; /* save for later processing */
2044 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2045 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2048 /* The entry instruction is typically the first instruction in a function,
2049 and it stores registers at offsets relative to the value of the old SP
2050 (before the prologue). But the value of the sp parameter to this
2051 function is the new SP (after the prologue has been executed). So we
2052 can't calculate those offsets until we've seen the entire prologue,
2053 and can calculate what the old SP must have been. */
2054 if (entry_inst != 0)
2056 int areg_count = (entry_inst >> 8) & 7;
2057 int sreg_count = (entry_inst >> 6) & 3;
2059 /* The entry instruction always subtracts 32 from the SP. */
2060 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2062 /* Now we can calculate what the SP must have been at the
2063 start of the function prologue. */
2064 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2066 /* Check if a0-a3 were saved in the caller's argument save area. */
2067 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2069 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2070 set_reg_offset (reg, sp + offset);
2071 offset += MIPS_SAVED_REGSIZE;
2074 /* Check if the ra register was pushed on the stack. */
2076 if (entry_inst & 0x20)
2078 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2079 set_reg_offset (RA_REGNUM, sp + offset);
2080 offset -= MIPS_SAVED_REGSIZE;
2083 /* Check if the s0 and s1 registers were pushed on the stack. */
2084 for (reg = 16; reg < sreg_count + 16; reg++)
2086 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2087 set_reg_offset (reg, sp + offset);
2088 offset -= MIPS_SAVED_REGSIZE;
2094 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2095 struct frame_info *next_frame, CORE_ADDR sp)
2098 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2100 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2101 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2102 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2103 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2104 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2106 unsigned long inst, high_word, low_word;
2109 /* Fetch the instruction. */
2110 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2112 /* Save some code by pre-extracting some useful fields. */
2113 high_word = (inst >> 16) & 0xffff;
2114 low_word = inst & 0xffff;
2115 reg = high_word & 0x1f;
2117 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2118 || high_word == 0x23bd /* addi $sp,$sp,-i */
2119 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2121 if (low_word & 0x8000) /* negative stack adjustment? */
2122 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2124 /* Exit loop if a positive stack adjustment is found, which
2125 usually means that the stack cleanup code in the function
2126 epilogue is reached. */
2129 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2131 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2132 set_reg_offset (reg, sp + low_word);
2134 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2136 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2137 but the register size used is only 32 bits. Make the address
2138 for the saved register point to the lower 32 bits. */
2139 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2140 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2142 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2144 /* Old gcc frame, r30 is virtual frame pointer. */
2145 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2146 frame_addr = sp + low_word;
2147 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2149 unsigned alloca_adjust;
2150 PROC_FRAME_REG (&temp_proc_desc) = 30;
2151 frame_addr = read_next_frame_reg (next_frame, 30);
2152 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2153 if (alloca_adjust > 0)
2155 /* FP > SP + frame_size. This may be because
2156 * of an alloca or somethings similar.
2157 * Fix sp to "pre-alloca" value, and try again.
2159 sp += alloca_adjust;
2164 /* move $30,$sp. With different versions of gas this will be either
2165 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2166 Accept any one of these. */
2167 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2169 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2170 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2172 unsigned alloca_adjust;
2173 PROC_FRAME_REG (&temp_proc_desc) = 30;
2174 frame_addr = read_next_frame_reg (next_frame, 30);
2175 alloca_adjust = (unsigned) (frame_addr - sp);
2176 if (alloca_adjust > 0)
2178 /* FP > SP + frame_size. This may be because
2179 * of an alloca or somethings similar.
2180 * Fix sp to "pre-alloca" value, and try again.
2182 sp += alloca_adjust;
2187 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2189 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2190 set_reg_offset (reg, frame_addr + low_word);
2195 static mips_extra_func_info_t
2196 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2197 struct frame_info *next_frame, int cur_frame)
2202 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2208 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2209 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2210 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2211 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2212 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2213 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2215 if (start_pc + 200 < limit_pc)
2216 limit_pc = start_pc + 200;
2217 if (pc_is_mips16 (start_pc))
2218 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2220 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2221 return &temp_proc_desc;
2224 struct mips_objfile_private
2230 /* Global used to communicate between non_heuristic_proc_desc and
2231 compare_pdr_entries within qsort (). */
2232 static bfd *the_bfd;
2235 compare_pdr_entries (const void *a, const void *b)
2237 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2238 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2242 else if (lhs == rhs)
2248 static mips_extra_func_info_t
2249 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2251 CORE_ADDR startaddr;
2252 mips_extra_func_info_t proc_desc;
2253 struct block *b = block_for_pc (pc);
2255 struct obj_section *sec;
2256 struct mips_objfile_private *priv;
2258 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2261 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2263 *addrptr = startaddr;
2267 sec = find_pc_section (pc);
2270 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2272 /* Search the ".pdr" section generated by GAS. This includes most of
2273 the information normally found in ECOFF PDRs. */
2275 the_bfd = sec->objfile->obfd;
2277 && (the_bfd->format == bfd_object
2278 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2279 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2281 /* Right now GAS only outputs the address as a four-byte sequence.
2282 This means that we should not bother with this method on 64-bit
2283 targets (until that is fixed). */
2285 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2286 sizeof (struct mips_objfile_private));
2288 sec->objfile->obj_private = priv;
2290 else if (priv == NULL)
2294 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2295 sizeof (struct mips_objfile_private));
2297 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2300 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2301 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2303 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2304 priv->contents, 0, priv->size);
2306 /* In general, the .pdr section is sorted. However, in the
2307 presence of multiple code sections (and other corner cases)
2308 it can become unsorted. Sort it so that we can use a faster
2310 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2315 sec->objfile->obj_private = priv;
2319 if (priv->size != 0)
2325 high = priv->size / 32;
2331 mid = (low + high) / 2;
2333 ptr = priv->contents + mid * 32;
2334 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2335 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2336 SECT_OFF_TEXT (sec->objfile));
2337 if (pdr_pc == startaddr)
2339 if (pdr_pc > startaddr)
2344 while (low != high);
2348 struct symbol *sym = find_pc_function (pc);
2350 /* Fill in what we need of the proc_desc. */
2351 proc_desc = (mips_extra_func_info_t)
2352 obstack_alloc (&sec->objfile->psymbol_obstack,
2353 sizeof (struct mips_extra_func_info));
2354 PROC_LOW_ADDR (proc_desc) = startaddr;
2356 /* Only used for dummy frames. */
2357 PROC_HIGH_ADDR (proc_desc) = 0;
2359 PROC_FRAME_OFFSET (proc_desc)
2360 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2361 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2363 PROC_FRAME_ADJUST (proc_desc) = 0;
2364 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2366 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2368 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2370 PROC_FREG_OFFSET (proc_desc)
2371 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2372 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2374 proc_desc->pdr.isym = (long) sym;
2384 if (startaddr > BLOCK_START (b))
2386 /* This is the "pathological" case referred to in a comment in
2387 print_frame_info. It might be better to move this check into
2392 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
2394 /* If we never found a PDR for this function in symbol reading, then
2395 examine prologues to find the information. */
2398 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2399 if (PROC_FRAME_REG (proc_desc) == -1)
2409 static mips_extra_func_info_t
2410 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2412 mips_extra_func_info_t proc_desc;
2413 CORE_ADDR startaddr = 0;
2415 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2419 /* IF this is the topmost frame AND
2420 * (this proc does not have debugging information OR
2421 * the PC is in the procedure prologue)
2422 * THEN create a "heuristic" proc_desc (by analyzing
2423 * the actual code) to replace the "official" proc_desc.
2425 if (next_frame == NULL)
2427 struct symtab_and_line val;
2428 struct symbol *proc_symbol =
2429 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2433 val = find_pc_line (BLOCK_START
2434 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2436 val.pc = val.end ? val.end : pc;
2438 if (!proc_symbol || pc < val.pc)
2440 mips_extra_func_info_t found_heuristic =
2441 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2442 pc, next_frame, cur_frame);
2443 if (found_heuristic)
2444 proc_desc = found_heuristic;
2450 /* Is linked_proc_desc_table really necessary? It only seems to be used
2451 by procedure call dummys. However, the procedures being called ought
2452 to have their own proc_descs, and even if they don't,
2453 heuristic_proc_desc knows how to create them! */
2455 register struct linked_proc_info *link;
2457 for (link = linked_proc_desc_table; link; link = link->next)
2458 if (PROC_LOW_ADDR (&link->info) <= pc
2459 && PROC_HIGH_ADDR (&link->info) > pc)
2463 startaddr = heuristic_proc_start (pc);
2466 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2472 get_frame_pointer (struct frame_info *frame,
2473 mips_extra_func_info_t proc_desc)
2475 return (read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
2476 + PROC_FRAME_OFFSET (proc_desc)
2477 - PROC_FRAME_ADJUST (proc_desc));
2480 static mips_extra_func_info_t cached_proc_desc;
2483 mips_frame_chain (struct frame_info *frame)
2485 mips_extra_func_info_t proc_desc;
2487 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2489 if (saved_pc == 0 || inside_entry_file (saved_pc))
2492 /* Check if the PC is inside a call stub. If it is, fetch the
2493 PC of the caller of that stub. */
2494 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2497 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2499 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2500 is well, frame->frame the bottom of the current frame will
2501 contain that value. */
2502 return get_frame_base (frame);
2505 /* Look up the procedure descriptor for this PC. */
2506 proc_desc = find_proc_desc (saved_pc, frame, 1);
2510 cached_proc_desc = proc_desc;
2512 /* If no frame pointer and frame size is zero, we must be at end
2513 of stack (or otherwise hosed). If we don't check frame size,
2514 we loop forever if we see a zero size frame. */
2515 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2516 && PROC_FRAME_OFFSET (proc_desc) == 0
2517 /* The previous frame from a sigtramp frame might be frameless
2518 and have frame size zero. */
2519 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2520 /* For a generic dummy frame, let get_frame_pointer() unwind a
2521 register value saved as part of the dummy frame call. */
2522 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2525 return get_frame_pointer (frame, proc_desc);
2529 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2532 mips_extra_func_info_t proc_desc;
2534 if (get_frame_type (fci) == DUMMY_FRAME)
2537 /* Use proc_desc calculated in frame_chain. When there is no
2538 next frame, i.e, get_next_frame (fci) == NULL, we call
2539 find_proc_desc () to calculate it, passing an explicit
2540 NULL as the frame parameter. */
2542 get_next_frame (fci)
2544 : find_proc_desc (get_frame_pc (fci),
2545 NULL /* i.e, get_next_frame (fci) */,
2548 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2550 deprecated_set_frame_saved_regs_hack (fci, NULL);
2551 get_frame_extra_info (fci)->proc_desc =
2552 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2555 /* Fixup frame-pointer - only needed for top frame */
2556 /* This may not be quite right, if proc has a real frame register.
2557 Get the value of the frame relative sp, procedure might have been
2558 interrupted by a signal at it's very start. */
2559 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2560 && !PROC_DESC_IS_DUMMY (proc_desc))
2561 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2562 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2563 /* Do not ``fix'' fci->frame. It will have the value of the
2564 generic dummy frame's top-of-stack (since the draft
2565 fci->frame is obtained by returning the unwound stack
2566 pointer) and that is what we want. That way the fci->frame
2567 value will match the top-of-stack value that was saved as
2568 part of the dummy frames data. */
2571 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2573 if (proc_desc == &temp_proc_desc)
2577 /* Do not set the saved registers for a sigtramp frame,
2578 mips_find_saved_registers will do that for us. We can't
2579 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2581 /* FIXME: cagney/2002-11-18: This problem will go away once
2582 frame.c:get_prev_frame() is modified to set the frame's
2583 type before calling functions like this. */
2584 find_pc_partial_function (get_frame_pc (fci), &name,
2585 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2586 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2588 frame_saved_regs_zalloc (fci);
2589 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2590 get_frame_saved_regs (fci)[PC_REGNUM]
2591 = get_frame_saved_regs (fci)[RA_REGNUM];
2592 /* Set value of previous frame's stack pointer. Remember that
2593 saved_regs[SP_REGNUM] is special in that it contains the
2594 value of the stack pointer register. The other saved_regs
2595 values are addresses (in the inferior) at which a given
2596 register's value may be found. */
2597 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2601 /* hack: if argument regs are saved, guess these contain args */
2602 /* assume we can't tell how many args for now */
2603 get_frame_extra_info (fci)->num_args = -1;
2604 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2606 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2608 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2615 /* MIPS stack frames are almost impenetrable. When execution stops,
2616 we basically have to look at symbol information for the function
2617 that we stopped in, which tells us *which* register (if any) is
2618 the base of the frame pointer, and what offset from that register
2619 the frame itself is at.
2621 This presents a problem when trying to examine a stack in memory
2622 (that isn't executing at the moment), using the "frame" command. We
2623 don't have a PC, nor do we have any registers except SP.
2625 This routine takes two arguments, SP and PC, and tries to make the
2626 cached frames look as if these two arguments defined a frame on the
2627 cache. This allows the rest of info frame to extract the important
2628 arguments without difficulty. */
2631 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2634 error ("MIPS frame specifications require two arguments: sp and pc");
2636 return create_new_frame (argv[0], argv[1]);
2639 /* According to the current ABI, should the type be passed in a
2640 floating-point register (assuming that there is space)? When there
2641 is no FPU, FP are not even considered as possibile candidates for
2642 FP registers and, consequently this returns false - forces FP
2643 arguments into integer registers. */
2646 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2648 return ((typecode == TYPE_CODE_FLT
2650 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2651 && TYPE_NFIELDS (arg_type) == 1
2652 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2653 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2656 /* On o32, argument passing in GPRs depends on the alignment of the type being
2657 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2660 mips_type_needs_double_align (struct type *type)
2662 enum type_code typecode = TYPE_CODE (type);
2664 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2666 else if (typecode == TYPE_CODE_STRUCT)
2668 if (TYPE_NFIELDS (type) < 1)
2670 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2672 else if (typecode == TYPE_CODE_UNION)
2676 n = TYPE_NFIELDS (type);
2677 for (i = 0; i < n; i++)
2678 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2685 /* Macros to round N up or down to the next A boundary;
2686 A must be a power of two. */
2688 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2689 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2691 /* Adjust the address downward (direction of stack growth) so that it
2692 is correctly aligned for a new stack frame. */
2694 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2696 return ROUND_DOWN (addr, 16);
2700 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2701 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2702 struct value **args, CORE_ADDR sp, int struct_return,
2703 CORE_ADDR struct_addr)
2709 int stack_offset = 0;
2711 /* For shared libraries, "t9" needs to point at the function
2713 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2715 /* Set the return address register to point to the entry point of
2716 the program, where a breakpoint lies in wait. */
2717 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2719 /* First ensure that the stack and structure return address (if any)
2720 are properly aligned. The stack has to be at least 64-bit
2721 aligned even on 32-bit machines, because doubles must be 64-bit
2722 aligned. For n32 and n64, stack frames need to be 128-bit
2723 aligned, so we round to this widest known alignment. */
2725 sp = ROUND_DOWN (sp, 16);
2726 struct_addr = ROUND_DOWN (struct_addr, 16);
2728 /* Now make space on the stack for the args. We allocate more
2729 than necessary for EABI, because the first few arguments are
2730 passed in registers, but that's OK. */
2731 for (argnum = 0; argnum < nargs; argnum++)
2732 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2733 MIPS_STACK_ARGSIZE);
2734 sp -= ROUND_UP (len, 16);
2737 fprintf_unfiltered (gdb_stdlog,
2738 "mips_eabi_push_dummy_call: sp=0x%s allocated %d\n",
2739 paddr_nz (sp), ROUND_UP (len, 16));
2741 /* Initialize the integer and float register pointers. */
2743 float_argreg = FPA0_REGNUM;
2745 /* The struct_return pointer occupies the first parameter-passing reg. */
2749 fprintf_unfiltered (gdb_stdlog,
2750 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2751 argreg, paddr_nz (struct_addr));
2752 write_register (argreg++, struct_addr);
2755 /* Now load as many as possible of the first arguments into
2756 registers, and push the rest onto the stack. Loop thru args
2757 from first to last. */
2758 for (argnum = 0; argnum < nargs; argnum++)
2761 char valbuf[MAX_REGISTER_SIZE];
2762 struct value *arg = args[argnum];
2763 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2764 int len = TYPE_LENGTH (arg_type);
2765 enum type_code typecode = TYPE_CODE (arg_type);
2768 fprintf_unfiltered (gdb_stdlog,
2769 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2770 argnum + 1, len, (int) typecode);
2772 /* The EABI passes structures that do not fit in a register by
2774 if (len > MIPS_SAVED_REGSIZE
2775 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2777 store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2778 typecode = TYPE_CODE_PTR;
2779 len = MIPS_SAVED_REGSIZE;
2782 fprintf_unfiltered (gdb_stdlog, " push");
2785 val = (char *) VALUE_CONTENTS (arg);
2787 /* 32-bit ABIs always start floating point arguments in an
2788 even-numbered floating point register. Round the FP register
2789 up before the check to see if there are any FP registers
2790 left. Non MIPS_EABI targets also pass the FP in the integer
2791 registers so also round up normal registers. */
2792 if (!FP_REGISTER_DOUBLE
2793 && fp_register_arg_p (typecode, arg_type))
2795 if ((float_argreg & 1))
2799 /* Floating point arguments passed in registers have to be
2800 treated specially. On 32-bit architectures, doubles
2801 are passed in register pairs; the even register gets
2802 the low word, and the odd register gets the high word.
2803 On non-EABI processors, the first two floating point arguments are
2804 also copied to general registers, because MIPS16 functions
2805 don't use float registers for arguments. This duplication of
2806 arguments in general registers can't hurt non-MIPS16 functions
2807 because those registers are normally skipped. */
2808 /* MIPS_EABI squeezes a struct that contains a single floating
2809 point value into an FP register instead of pushing it onto the
2811 if (fp_register_arg_p (typecode, arg_type)
2812 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2814 if (!FP_REGISTER_DOUBLE && len == 8)
2816 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2817 unsigned long regval;
2819 /* Write the low word of the double to the even register(s). */
2820 regval = extract_unsigned_integer (val + low_offset, 4);
2822 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2823 float_argreg, phex (regval, 4));
2824 write_register (float_argreg++, regval);
2826 /* Write the high word of the double to the odd register(s). */
2827 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2829 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2830 float_argreg, phex (regval, 4));
2831 write_register (float_argreg++, regval);
2835 /* This is a floating point value that fits entirely
2836 in a single register. */
2837 /* On 32 bit ABI's the float_argreg is further adjusted
2838 above to ensure that it is even register aligned. */
2839 LONGEST regval = extract_unsigned_integer (val, len);
2841 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2842 float_argreg, phex (regval, len));
2843 write_register (float_argreg++, regval);
2848 /* Copy the argument to general registers or the stack in
2849 register-sized pieces. Large arguments are split between
2850 registers and stack. */
2851 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2852 are treated specially: Irix cc passes them in registers
2853 where gcc sometimes puts them on the stack. For maximum
2854 compatibility, we will put them in both places. */
2855 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2856 (len % MIPS_SAVED_REGSIZE != 0));
2858 /* Note: Floating-point values that didn't fit into an FP
2859 register are only written to memory. */
2862 /* Remember if the argument was written to the stack. */
2863 int stack_used_p = 0;
2865 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2868 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2871 /* Write this portion of the argument to the stack. */
2872 if (argreg > MIPS_LAST_ARG_REGNUM
2874 || fp_register_arg_p (typecode, arg_type))
2876 /* Should shorter than int integer values be
2877 promoted to int before being stored? */
2878 int longword_offset = 0;
2881 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2883 if (MIPS_STACK_ARGSIZE == 8 &&
2884 (typecode == TYPE_CODE_INT ||
2885 typecode == TYPE_CODE_PTR ||
2886 typecode == TYPE_CODE_FLT) && len <= 4)
2887 longword_offset = MIPS_STACK_ARGSIZE - len;
2888 else if ((typecode == TYPE_CODE_STRUCT ||
2889 typecode == TYPE_CODE_UNION) &&
2890 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2891 longword_offset = MIPS_STACK_ARGSIZE - len;
2896 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2897 paddr_nz (stack_offset));
2898 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2899 paddr_nz (longword_offset));
2902 addr = sp + stack_offset + longword_offset;
2907 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2909 for (i = 0; i < partial_len; i++)
2911 fprintf_unfiltered (gdb_stdlog, "%02x",
2915 write_memory (addr, val, partial_len);
2918 /* Note!!! This is NOT an else clause. Odd sized
2919 structs may go thru BOTH paths. Floating point
2920 arguments will not. */
2921 /* Write this portion of the argument to a general
2922 purpose register. */
2923 if (argreg <= MIPS_LAST_ARG_REGNUM
2924 && !fp_register_arg_p (typecode, arg_type))
2926 LONGEST regval = extract_unsigned_integer (val, partial_len);
2929 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2931 phex (regval, MIPS_SAVED_REGSIZE));
2932 write_register (argreg, regval);
2939 /* Compute the the offset into the stack at which we
2940 will copy the next parameter.
2942 In the new EABI (and the NABI32), the stack_offset
2943 only needs to be adjusted when it has been used. */
2946 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2950 fprintf_unfiltered (gdb_stdlog, "\n");
2953 /* Return adjusted stack pointer. */
2957 /* N32/N64 version of push_dummy_call. */
2960 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2961 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2962 struct value **args, CORE_ADDR sp, int struct_return,
2963 CORE_ADDR struct_addr)
2969 int stack_offset = 0;
2971 /* For shared libraries, "t9" needs to point at the function
2973 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2975 /* Set the return address register to point to the entry point of
2976 the program, where a breakpoint lies in wait. */
2977 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2979 /* First ensure that the stack and structure return address (if any)
2980 are properly aligned. The stack has to be at least 64-bit
2981 aligned even on 32-bit machines, because doubles must be 64-bit
2982 aligned. For n32 and n64, stack frames need to be 128-bit
2983 aligned, so we round to this widest known alignment. */
2985 sp = ROUND_DOWN (sp, 16);
2986 struct_addr = ROUND_DOWN (struct_addr, 16);
2988 /* Now make space on the stack for the args. */
2989 for (argnum = 0; argnum < nargs; argnum++)
2990 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2991 MIPS_STACK_ARGSIZE);
2992 sp -= ROUND_UP (len, 16);
2995 fprintf_unfiltered (gdb_stdlog,
2996 "mips_n32n64_push_dummy_call: sp=0x%s allocated %d\n",
2997 paddr_nz (sp), ROUND_UP (len, 16));
2999 /* Initialize the integer and float register pointers. */
3001 float_argreg = FPA0_REGNUM;
3003 /* The struct_return pointer occupies the first parameter-passing reg. */
3007 fprintf_unfiltered (gdb_stdlog,
3008 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3009 argreg, paddr_nz (struct_addr));
3010 write_register (argreg++, struct_addr);
3013 /* Now load as many as possible of the first arguments into
3014 registers, and push the rest onto the stack. Loop thru args
3015 from first to last. */
3016 for (argnum = 0; argnum < nargs; argnum++)
3019 char valbuf[MAX_REGISTER_SIZE];
3020 struct value *arg = args[argnum];
3021 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3022 int len = TYPE_LENGTH (arg_type);
3023 enum type_code typecode = TYPE_CODE (arg_type);
3026 fprintf_unfiltered (gdb_stdlog,
3027 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3028 argnum + 1, len, (int) typecode);
3030 val = (char *) VALUE_CONTENTS (arg);
3032 if (fp_register_arg_p (typecode, arg_type)
3033 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3035 /* This is a floating point value that fits entirely
3036 in a single register. */
3037 /* On 32 bit ABI's the float_argreg is further adjusted
3038 above to ensure that it is even register aligned. */
3039 LONGEST regval = extract_unsigned_integer (val, len);
3041 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3042 float_argreg, phex (regval, len));
3043 write_register (float_argreg++, regval);
3046 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3047 argreg, phex (regval, len));
3048 write_register (argreg, regval);
3053 /* Copy the argument to general registers or the stack in
3054 register-sized pieces. Large arguments are split between
3055 registers and stack. */
3056 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3057 are treated specially: Irix cc passes them in registers
3058 where gcc sometimes puts them on the stack. For maximum
3059 compatibility, we will put them in both places. */
3060 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3061 (len % MIPS_SAVED_REGSIZE != 0));
3062 /* Note: Floating-point values that didn't fit into an FP
3063 register are only written to memory. */
3066 /* Rememer if the argument was written to the stack. */
3067 int stack_used_p = 0;
3068 int partial_len = len < MIPS_SAVED_REGSIZE ?
3069 len : MIPS_SAVED_REGSIZE;
3072 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3075 /* Write this portion of the argument to the stack. */
3076 if (argreg > MIPS_LAST_ARG_REGNUM
3078 || fp_register_arg_p (typecode, arg_type))
3080 /* Should shorter than int integer values be
3081 promoted to int before being stored? */
3082 int longword_offset = 0;
3085 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3087 if (MIPS_STACK_ARGSIZE == 8 &&
3088 (typecode == TYPE_CODE_INT ||
3089 typecode == TYPE_CODE_PTR ||
3090 typecode == TYPE_CODE_FLT) && len <= 4)
3091 longword_offset = MIPS_STACK_ARGSIZE - len;
3096 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3097 paddr_nz (stack_offset));
3098 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3099 paddr_nz (longword_offset));
3102 addr = sp + stack_offset + longword_offset;
3107 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3109 for (i = 0; i < partial_len; i++)
3111 fprintf_unfiltered (gdb_stdlog, "%02x",
3115 write_memory (addr, val, partial_len);
3118 /* Note!!! This is NOT an else clause. Odd sized
3119 structs may go thru BOTH paths. Floating point
3120 arguments will not. */
3121 /* Write this portion of the argument to a general
3122 purpose register. */
3123 if (argreg <= MIPS_LAST_ARG_REGNUM
3124 && !fp_register_arg_p (typecode, arg_type))
3126 LONGEST regval = extract_unsigned_integer (val, partial_len);
3128 /* A non-floating-point argument being passed in a
3129 general register. If a struct or union, and if
3130 the remaining length is smaller than the register
3131 size, we have to adjust the register value on
3134 It does not seem to be necessary to do the
3135 same for integral types.
3137 cagney/2001-07-23: gdb/179: Also, GCC, when
3138 outputting LE O32 with sizeof (struct) <
3139 MIPS_SAVED_REGSIZE, generates a left shift as
3140 part of storing the argument in a register a
3141 register (the left shift isn't generated when
3142 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3143 is quite possible that this is GCC contradicting
3144 the LE/O32 ABI, GDB has not been adjusted to
3145 accommodate this. Either someone needs to
3146 demonstrate that the LE/O32 ABI specifies such a
3147 left shift OR this new ABI gets identified as
3148 such and GDB gets tweaked accordingly. */
3150 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3151 && partial_len < MIPS_SAVED_REGSIZE
3152 && (typecode == TYPE_CODE_STRUCT ||
3153 typecode == TYPE_CODE_UNION))
3154 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3158 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3160 phex (regval, MIPS_SAVED_REGSIZE));
3161 write_register (argreg, regval);
3168 /* Compute the the offset into the stack at which we
3169 will copy the next parameter.
3171 In N32 (N64?), the stack_offset only needs to be
3172 adjusted when it has been used. */
3175 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3179 fprintf_unfiltered (gdb_stdlog, "\n");
3182 /* Return adjusted stack pointer. */
3186 /* O32 version of push_dummy_call. */
3189 mips_o32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3190 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3191 struct value **args, CORE_ADDR sp, int struct_return,
3192 CORE_ADDR struct_addr)
3198 int stack_offset = 0;
3200 /* For shared libraries, "t9" needs to point at the function
3202 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3204 /* Set the return address register to point to the entry point of
3205 the program, where a breakpoint lies in wait. */
3206 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3208 /* First ensure that the stack and structure return address (if any)
3209 are properly aligned. The stack has to be at least 64-bit
3210 aligned even on 32-bit machines, because doubles must be 64-bit
3211 aligned. For n32 and n64, stack frames need to be 128-bit
3212 aligned, so we round to this widest known alignment. */
3214 sp = ROUND_DOWN (sp, 16);
3215 struct_addr = ROUND_DOWN (struct_addr, 16);
3217 /* Now make space on the stack for the args. */
3218 for (argnum = 0; argnum < nargs; argnum++)
3219 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3220 MIPS_STACK_ARGSIZE);
3221 sp -= ROUND_UP (len, 16);
3224 fprintf_unfiltered (gdb_stdlog,
3225 "mips_o32_push_dummy_call: sp=0x%s allocated %d\n",
3226 paddr_nz (sp), ROUND_UP (len, 16));
3228 /* Initialize the integer and float register pointers. */
3230 float_argreg = FPA0_REGNUM;
3232 /* The struct_return pointer occupies the first parameter-passing reg. */
3236 fprintf_unfiltered (gdb_stdlog,
3237 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3238 argreg, paddr_nz (struct_addr));
3239 write_register (argreg++, struct_addr);
3240 stack_offset += MIPS_STACK_ARGSIZE;
3243 /* Now load as many as possible of the first arguments into
3244 registers, and push the rest onto the stack. Loop thru args
3245 from first to last. */
3246 for (argnum = 0; argnum < nargs; argnum++)
3249 char valbuf[MAX_REGISTER_SIZE];
3250 struct value *arg = args[argnum];
3251 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3252 int len = TYPE_LENGTH (arg_type);
3253 enum type_code typecode = TYPE_CODE (arg_type);
3256 fprintf_unfiltered (gdb_stdlog,
3257 "mips_o32_push_dummy_call: %d len=%d type=%d",
3258 argnum + 1, len, (int) typecode);
3260 val = (char *) VALUE_CONTENTS (arg);
3262 /* 32-bit ABIs always start floating point arguments in an
3263 even-numbered floating point register. Round the FP register
3264 up before the check to see if there are any FP registers
3265 left. O32/O64 targets also pass the FP in the integer
3266 registers so also round up normal registers. */
3267 if (!FP_REGISTER_DOUBLE
3268 && fp_register_arg_p (typecode, arg_type))
3270 if ((float_argreg & 1))
3274 /* Floating point arguments passed in registers have to be
3275 treated specially. On 32-bit architectures, doubles
3276 are passed in register pairs; the even register gets
3277 the low word, and the odd register gets the high word.
3278 On O32/O64, the first two floating point arguments are
3279 also copied to general registers, because MIPS16 functions
3280 don't use float registers for arguments. This duplication of
3281 arguments in general registers can't hurt non-MIPS16 functions
3282 because those registers are normally skipped. */
3284 if (fp_register_arg_p (typecode, arg_type)
3285 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3287 if (!FP_REGISTER_DOUBLE && len == 8)
3289 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3290 unsigned long regval;
3292 /* Write the low word of the double to the even register(s). */
3293 regval = extract_unsigned_integer (val + low_offset, 4);
3295 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3296 float_argreg, phex (regval, 4));
3297 write_register (float_argreg++, regval);
3299 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3300 argreg, phex (regval, 4));
3301 write_register (argreg++, regval);
3303 /* Write the high word of the double to the odd register(s). */
3304 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3306 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3307 float_argreg, phex (regval, 4));
3308 write_register (float_argreg++, regval);
3311 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3312 argreg, phex (regval, 4));
3313 write_register (argreg++, regval);
3317 /* This is a floating point value that fits entirely
3318 in a single register. */
3319 /* On 32 bit ABI's the float_argreg is further adjusted
3320 above to ensure that it is even register aligned. */
3321 LONGEST regval = extract_unsigned_integer (val, len);
3323 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3324 float_argreg, phex (regval, len));
3325 write_register (float_argreg++, regval);
3326 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3327 registers for each argument. The below is (my
3328 guess) to ensure that the corresponding integer
3329 register has reserved the same space. */
3331 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3332 argreg, phex (regval, len));
3333 write_register (argreg, regval);
3334 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3336 /* Reserve space for the FP register. */
3337 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3341 /* Copy the argument to general registers or the stack in
3342 register-sized pieces. Large arguments are split between
3343 registers and stack. */
3344 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3345 are treated specially: Irix cc passes them in registers
3346 where gcc sometimes puts them on the stack. For maximum
3347 compatibility, we will put them in both places. */
3348 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3349 (len % MIPS_SAVED_REGSIZE != 0));
3350 /* Structures should be aligned to eight bytes (even arg registers)
3351 on MIPS_ABI_O32, if their first member has double precision. */
3352 if (MIPS_SAVED_REGSIZE < 8
3353 && mips_type_needs_double_align (arg_type))
3358 /* Note: Floating-point values that didn't fit into an FP
3359 register are only written to memory. */
3362 /* Remember if the argument was written to the stack. */
3363 int stack_used_p = 0;
3365 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3368 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3371 /* Write this portion of the argument to the stack. */
3372 if (argreg > MIPS_LAST_ARG_REGNUM
3374 || fp_register_arg_p (typecode, arg_type))
3376 /* Should shorter than int integer values be
3377 promoted to int before being stored? */
3378 int longword_offset = 0;
3381 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3383 if (MIPS_STACK_ARGSIZE == 8 &&
3384 (typecode == TYPE_CODE_INT ||
3385 typecode == TYPE_CODE_PTR ||
3386 typecode == TYPE_CODE_FLT) && len <= 4)
3387 longword_offset = MIPS_STACK_ARGSIZE - len;
3392 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3393 paddr_nz (stack_offset));
3394 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3395 paddr_nz (longword_offset));
3398 addr = sp + stack_offset + longword_offset;
3403 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3405 for (i = 0; i < partial_len; i++)
3407 fprintf_unfiltered (gdb_stdlog, "%02x",
3411 write_memory (addr, val, partial_len);
3414 /* Note!!! This is NOT an else clause. Odd sized
3415 structs may go thru BOTH paths. Floating point
3416 arguments will not. */
3417 /* Write this portion of the argument to a general
3418 purpose register. */
3419 if (argreg <= MIPS_LAST_ARG_REGNUM
3420 && !fp_register_arg_p (typecode, arg_type))
3422 LONGEST regval = extract_signed_integer (val, partial_len);
3423 /* Value may need to be sign extended, because
3424 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3426 /* A non-floating-point argument being passed in a
3427 general register. If a struct or union, and if
3428 the remaining length is smaller than the register
3429 size, we have to adjust the register value on
3432 It does not seem to be necessary to do the
3433 same for integral types.
3435 Also don't do this adjustment on O64 binaries.
3437 cagney/2001-07-23: gdb/179: Also, GCC, when
3438 outputting LE O32 with sizeof (struct) <
3439 MIPS_SAVED_REGSIZE, generates a left shift as
3440 part of storing the argument in a register a
3441 register (the left shift isn't generated when
3442 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3443 is quite possible that this is GCC contradicting
3444 the LE/O32 ABI, GDB has not been adjusted to
3445 accommodate this. Either someone needs to
3446 demonstrate that the LE/O32 ABI specifies such a
3447 left shift OR this new ABI gets identified as
3448 such and GDB gets tweaked accordingly. */
3450 if (MIPS_SAVED_REGSIZE < 8
3451 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3452 && partial_len < MIPS_SAVED_REGSIZE
3453 && (typecode == TYPE_CODE_STRUCT ||
3454 typecode == TYPE_CODE_UNION))
3455 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3459 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3461 phex (regval, MIPS_SAVED_REGSIZE));
3462 write_register (argreg, regval);
3465 /* Prevent subsequent floating point arguments from
3466 being passed in floating point registers. */
3467 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3473 /* Compute the the offset into the stack at which we
3474 will copy the next parameter.
3476 In older ABIs, the caller reserved space for
3477 registers that contained arguments. This was loosely
3478 refered to as their "home". Consequently, space is
3479 always allocated. */
3481 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3485 fprintf_unfiltered (gdb_stdlog, "\n");
3488 /* Return adjusted stack pointer. */
3492 /* O64 version of push_dummy_call. */
3495 mips_o64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3496 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3497 struct value **args, CORE_ADDR sp, int struct_return,
3498 CORE_ADDR struct_addr)
3504 int stack_offset = 0;
3506 /* For shared libraries, "t9" needs to point at the function
3508 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3510 /* Set the return address register to point to the entry point of
3511 the program, where a breakpoint lies in wait. */
3512 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3514 /* First ensure that the stack and structure return address (if any)
3515 are properly aligned. The stack has to be at least 64-bit
3516 aligned even on 32-bit machines, because doubles must be 64-bit
3517 aligned. For n32 and n64, stack frames need to be 128-bit
3518 aligned, so we round to this widest known alignment. */
3520 sp = ROUND_DOWN (sp, 16);
3521 struct_addr = ROUND_DOWN (struct_addr, 16);
3523 /* Now make space on the stack for the args. */
3524 for (argnum = 0; argnum < nargs; argnum++)
3525 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3526 MIPS_STACK_ARGSIZE);
3527 sp -= ROUND_UP (len, 16);
3530 fprintf_unfiltered (gdb_stdlog,
3531 "mips_o64_push_dummy_call: sp=0x%s allocated %d\n",
3532 paddr_nz (sp), ROUND_UP (len, 16));
3534 /* Initialize the integer and float register pointers. */
3536 float_argreg = FPA0_REGNUM;
3538 /* The struct_return pointer occupies the first parameter-passing reg. */
3542 fprintf_unfiltered (gdb_stdlog,
3543 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3544 argreg, paddr_nz (struct_addr));
3545 write_register (argreg++, struct_addr);
3546 stack_offset += MIPS_STACK_ARGSIZE;
3549 /* Now load as many as possible of the first arguments into
3550 registers, and push the rest onto the stack. Loop thru args
3551 from first to last. */
3552 for (argnum = 0; argnum < nargs; argnum++)
3555 char valbuf[MAX_REGISTER_SIZE];
3556 struct value *arg = args[argnum];
3557 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3558 int len = TYPE_LENGTH (arg_type);
3559 enum type_code typecode = TYPE_CODE (arg_type);
3562 fprintf_unfiltered (gdb_stdlog,
3563 "mips_o64_push_dummy_call: %d len=%d type=%d",
3564 argnum + 1, len, (int) typecode);
3566 val = (char *) VALUE_CONTENTS (arg);
3568 /* 32-bit ABIs always start floating point arguments in an
3569 even-numbered floating point register. Round the FP register
3570 up before the check to see if there are any FP registers
3571 left. O32/O64 targets also pass the FP in the integer
3572 registers so also round up normal registers. */
3573 if (!FP_REGISTER_DOUBLE
3574 && fp_register_arg_p (typecode, arg_type))
3576 if ((float_argreg & 1))
3580 /* Floating point arguments passed in registers have to be
3581 treated specially. On 32-bit architectures, doubles
3582 are passed in register pairs; the even register gets
3583 the low word, and the odd register gets the high word.
3584 On O32/O64, the first two floating point arguments are
3585 also copied to general registers, because MIPS16 functions
3586 don't use float registers for arguments. This duplication of
3587 arguments in general registers can't hurt non-MIPS16 functions
3588 because those registers are normally skipped. */
3590 if (fp_register_arg_p (typecode, arg_type)
3591 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3593 if (!FP_REGISTER_DOUBLE && len == 8)
3595 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3596 unsigned long regval;
3598 /* Write the low word of the double to the even register(s). */
3599 regval = extract_unsigned_integer (val + low_offset, 4);
3601 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3602 float_argreg, phex (regval, 4));
3603 write_register (float_argreg++, regval);
3605 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3606 argreg, phex (regval, 4));
3607 write_register (argreg++, regval);
3609 /* Write the high word of the double to the odd register(s). */
3610 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3612 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3613 float_argreg, phex (regval, 4));
3614 write_register (float_argreg++, regval);
3617 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3618 argreg, phex (regval, 4));
3619 write_register (argreg++, regval);
3623 /* This is a floating point value that fits entirely
3624 in a single register. */
3625 /* On 32 bit ABI's the float_argreg is further adjusted
3626 above to ensure that it is even register aligned. */
3627 LONGEST regval = extract_unsigned_integer (val, len);
3629 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3630 float_argreg, phex (regval, len));
3631 write_register (float_argreg++, regval);
3632 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3633 registers for each argument. The below is (my
3634 guess) to ensure that the corresponding integer
3635 register has reserved the same space. */
3637 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3638 argreg, phex (regval, len));
3639 write_register (argreg, regval);
3640 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3642 /* Reserve space for the FP register. */
3643 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3647 /* Copy the argument to general registers or the stack in
3648 register-sized pieces. Large arguments are split between
3649 registers and stack. */
3650 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3651 are treated specially: Irix cc passes them in registers
3652 where gcc sometimes puts them on the stack. For maximum
3653 compatibility, we will put them in both places. */
3654 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3655 (len % MIPS_SAVED_REGSIZE != 0));
3656 /* Structures should be aligned to eight bytes (even arg registers)
3657 on MIPS_ABI_O32, if their first member has double precision. */
3658 if (MIPS_SAVED_REGSIZE < 8
3659 && mips_type_needs_double_align (arg_type))
3664 /* Note: Floating-point values that didn't fit into an FP
3665 register are only written to memory. */
3668 /* Remember if the argument was written to the stack. */
3669 int stack_used_p = 0;
3671 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3674 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3677 /* Write this portion of the argument to the stack. */
3678 if (argreg > MIPS_LAST_ARG_REGNUM
3680 || fp_register_arg_p (typecode, arg_type))
3682 /* Should shorter than int integer values be
3683 promoted to int before being stored? */
3684 int longword_offset = 0;
3687 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3689 if (MIPS_STACK_ARGSIZE == 8 &&
3690 (typecode == TYPE_CODE_INT ||
3691 typecode == TYPE_CODE_PTR ||
3692 typecode == TYPE_CODE_FLT) && len <= 4)
3693 longword_offset = MIPS_STACK_ARGSIZE - len;
3698 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3699 paddr_nz (stack_offset));
3700 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3701 paddr_nz (longword_offset));
3704 addr = sp + stack_offset + longword_offset;
3709 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3711 for (i = 0; i < partial_len; i++)
3713 fprintf_unfiltered (gdb_stdlog, "%02x",
3717 write_memory (addr, val, partial_len);
3720 /* Note!!! This is NOT an else clause. Odd sized
3721 structs may go thru BOTH paths. Floating point
3722 arguments will not. */
3723 /* Write this portion of the argument to a general
3724 purpose register. */
3725 if (argreg <= MIPS_LAST_ARG_REGNUM
3726 && !fp_register_arg_p (typecode, arg_type))
3728 LONGEST regval = extract_signed_integer (val, partial_len);
3729 /* Value may need to be sign extended, because
3730 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3732 /* A non-floating-point argument being passed in a
3733 general register. If a struct or union, and if
3734 the remaining length is smaller than the register
3735 size, we have to adjust the register value on
3738 It does not seem to be necessary to do the
3739 same for integral types.
3741 Also don't do this adjustment on O64 binaries.
3743 cagney/2001-07-23: gdb/179: Also, GCC, when
3744 outputting LE O32 with sizeof (struct) <
3745 MIPS_SAVED_REGSIZE, generates a left shift as
3746 part of storing the argument in a register a
3747 register (the left shift isn't generated when
3748 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3749 is quite possible that this is GCC contradicting
3750 the LE/O32 ABI, GDB has not been adjusted to
3751 accommodate this. Either someone needs to
3752 demonstrate that the LE/O32 ABI specifies such a
3753 left shift OR this new ABI gets identified as
3754 such and GDB gets tweaked accordingly. */
3756 if (MIPS_SAVED_REGSIZE < 8
3757 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3758 && partial_len < MIPS_SAVED_REGSIZE
3759 && (typecode == TYPE_CODE_STRUCT ||
3760 typecode == TYPE_CODE_UNION))
3761 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3765 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3767 phex (regval, MIPS_SAVED_REGSIZE));
3768 write_register (argreg, regval);
3771 /* Prevent subsequent floating point arguments from
3772 being passed in floating point registers. */
3773 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3779 /* Compute the the offset into the stack at which we
3780 will copy the next parameter.
3782 In older ABIs, the caller reserved space for
3783 registers that contained arguments. This was loosely
3784 refered to as their "home". Consequently, space is
3785 always allocated. */
3787 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3791 fprintf_unfiltered (gdb_stdlog, "\n");
3794 /* Return adjusted stack pointer. */
3799 mips_pop_frame (void)
3801 register int regnum;
3802 struct frame_info *frame = get_current_frame ();
3803 CORE_ADDR new_sp = get_frame_base (frame);
3804 mips_extra_func_info_t proc_desc;
3806 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3808 generic_pop_dummy_frame ();
3809 flush_cached_frames ();
3813 proc_desc = get_frame_extra_info (frame)->proc_desc;
3814 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3815 if (get_frame_saved_regs (frame) == NULL)
3816 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3817 for (regnum = 0; regnum < NUM_REGS; regnum++)
3818 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3819 && get_frame_saved_regs (frame)[regnum])
3821 /* Floating point registers must not be sign extended,
3822 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3824 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3825 write_register (regnum,
3826 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3827 MIPS_SAVED_REGSIZE));
3829 write_register (regnum,
3830 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3831 MIPS_SAVED_REGSIZE));
3834 write_register (SP_REGNUM, new_sp);
3835 flush_cached_frames ();
3837 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3839 struct linked_proc_info *pi_ptr, *prev_ptr;
3841 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3843 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3845 if (&pi_ptr->info == proc_desc)
3850 error ("Can't locate dummy extra frame info\n");
3852 if (prev_ptr != NULL)
3853 prev_ptr->next = pi_ptr->next;
3855 linked_proc_desc_table = pi_ptr->next;
3859 write_register (HI_REGNUM,
3860 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3861 MIPS_SAVED_REGSIZE));
3862 write_register (LO_REGNUM,
3863 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3864 MIPS_SAVED_REGSIZE));
3865 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3866 write_register (FCRCS_REGNUM,
3867 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3868 MIPS_SAVED_REGSIZE));
3872 /* Floating point register management.
3874 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3875 64bit operations, these early MIPS cpus treat fp register pairs
3876 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3877 registers and offer a compatibility mode that emulates the MIPS2 fp
3878 model. When operating in MIPS2 fp compat mode, later cpu's split
3879 double precision floats into two 32-bit chunks and store them in
3880 consecutive fp regs. To display 64-bit floats stored in this
3881 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3882 Throw in user-configurable endianness and you have a real mess.
3884 The way this works is:
3885 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3886 double-precision value will be split across two logical registers.
3887 The lower-numbered logical register will hold the low-order bits,
3888 regardless of the processor's endianness.
3889 - If we are on a 64-bit processor, and we are looking for a
3890 single-precision value, it will be in the low ordered bits
3891 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3892 save slot in memory.
3893 - If we are in 64-bit mode, everything is straightforward.
3895 Note that this code only deals with "live" registers at the top of the
3896 stack. We will attempt to deal with saved registers later, when
3897 the raw/cooked register interface is in place. (We need a general
3898 interface that can deal with dynamic saved register sizes -- fp
3899 regs could be 32 bits wide in one frame and 64 on the frame above
3902 static struct type *
3903 mips_float_register_type (void)
3905 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3906 return builtin_type_ieee_single_big;
3908 return builtin_type_ieee_single_little;
3911 static struct type *
3912 mips_double_register_type (void)
3914 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3915 return builtin_type_ieee_double_big;
3917 return builtin_type_ieee_double_little;
3920 /* Copy a 32-bit single-precision value from the current frame
3921 into rare_buffer. */
3924 mips_read_fp_register_single (int regno, char *rare_buffer)
3926 int raw_size = REGISTER_RAW_SIZE (regno);
3927 char *raw_buffer = alloca (raw_size);
3929 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3930 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3933 /* We have a 64-bit value for this register. Find the low-order
3937 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3942 memcpy (rare_buffer, raw_buffer + offset, 4);
3946 memcpy (rare_buffer, raw_buffer, 4);
3950 /* Copy a 64-bit double-precision value from the current frame into
3951 rare_buffer. This may include getting half of it from the next
3955 mips_read_fp_register_double (int regno, char *rare_buffer)
3957 int raw_size = REGISTER_RAW_SIZE (regno);
3959 if (raw_size == 8 && !mips2_fp_compat ())
3961 /* We have a 64-bit value for this register, and we should use
3963 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
3964 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3968 if ((regno - FP0_REGNUM) & 1)
3969 internal_error (__FILE__, __LINE__,
3970 "mips_read_fp_register_double: bad access to "
3971 "odd-numbered FP register");
3973 /* mips_read_fp_register_single will find the correct 32 bits from
3975 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3977 mips_read_fp_register_single (regno, rare_buffer + 4);
3978 mips_read_fp_register_single (regno + 1, rare_buffer);
3982 mips_read_fp_register_single (regno, rare_buffer);
3983 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
3989 mips_print_fp_register (int regnum)
3990 { /* do values for FP (float) regs */
3992 double doub, flt1, flt2; /* doubles extracted from raw hex data */
3993 int inv1, inv2, namelen;
3995 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
3997 printf_filtered ("%s:", REGISTER_NAME (regnum));
3998 printf_filtered ("%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), "");
4000 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4002 /* 4-byte registers: Print hex and floating. Also print even
4003 numbered registers as doubles. */
4004 mips_read_fp_register_single (regnum, raw_buffer);
4005 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4007 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
4010 printf_filtered (" flt: ");
4012 printf_filtered (" <invalid float> ");
4014 printf_filtered ("%-17.9g", flt1);
4016 if (regnum % 2 == 0)
4018 mips_read_fp_register_double (regnum, raw_buffer);
4019 doub = unpack_double (mips_double_register_type (), raw_buffer,
4022 printf_filtered (" dbl: ");
4024 printf_filtered ("<invalid double>");
4026 printf_filtered ("%-24.17g", doub);
4031 /* Eight byte registers: print each one as hex, float and double. */
4032 mips_read_fp_register_single (regnum, raw_buffer);
4033 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4035 mips_read_fp_register_double (regnum, raw_buffer);
4036 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4039 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4042 printf_filtered (" flt: ");
4044 printf_filtered ("<invalid float>");
4046 printf_filtered ("%-17.9g", flt1);
4048 printf_filtered (" dbl: ");
4050 printf_filtered ("<invalid double>");
4052 printf_filtered ("%-24.17g", doub);
4057 mips_print_register (int regnum, int all)
4059 char raw_buffer[MAX_REGISTER_SIZE];
4062 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4064 mips_print_fp_register (regnum);
4068 /* Get the data in raw format. */
4069 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4071 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4075 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4077 /* The problem with printing numeric register names (r26, etc.) is that
4078 the user can't use them on input. Probably the best solution is to
4079 fix it so that either the numeric or the funky (a2, etc.) names
4080 are accepted on input. */
4081 if (regnum < MIPS_NUMREGS)
4082 printf_filtered ("(r%d): ", regnum);
4084 printf_filtered (": ");
4086 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4087 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4091 print_scalar_formatted (raw_buffer + offset,
4092 REGISTER_VIRTUAL_TYPE (regnum),
4093 'x', 0, gdb_stdout);
4096 /* Replacement for generic do_registers_info.
4097 Print regs in pretty columns. */
4100 do_fp_register_row (int regnum)
4102 printf_filtered (" ");
4103 mips_print_fp_register (regnum);
4104 printf_filtered ("\n");
4109 /* Print a row's worth of GP (int) registers, with name labels above */
4112 do_gp_register_row (int regnum)
4114 /* do values for GP (int) regs */
4115 char raw_buffer[MAX_REGISTER_SIZE];
4116 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4118 int start_regnum = regnum;
4119 int numregs = NUM_REGS;
4122 /* For GP registers, we print a separate row of names above the vals */
4123 printf_filtered (" ");
4124 for (col = 0; col < ncols && regnum < numregs; regnum++)
4126 if (*REGISTER_NAME (regnum) == '\0')
4127 continue; /* unused register */
4128 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4129 break; /* end the row: reached FP register */
4130 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4131 REGISTER_NAME (regnum));
4134 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4135 start_regnum); /* print the R0 to R31 names */
4137 regnum = start_regnum; /* go back to start of row */
4138 /* now print the values in hex, 4 or 8 to the row */
4139 for (col = 0; col < ncols && regnum < numregs; regnum++)
4141 if (*REGISTER_NAME (regnum) == '\0')
4142 continue; /* unused register */
4143 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4144 break; /* end row: reached FP register */
4145 /* OK: get the data in raw format. */
4146 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4147 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4148 /* pad small registers */
4149 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4150 printf_filtered (" ");
4151 /* Now print the register value in hex, endian order. */
4152 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4153 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4154 byte < REGISTER_RAW_SIZE (regnum);
4156 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4158 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4161 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4162 printf_filtered (" ");
4165 if (col > 0) /* ie. if we actually printed anything... */
4166 printf_filtered ("\n");
4171 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4174 mips_do_registers_info (int regnum, int fpregs)
4176 if (regnum != -1) /* do one specified register */
4178 if (*(REGISTER_NAME (regnum)) == '\0')
4179 error ("Not a valid register for the current processor type");
4181 mips_print_register (regnum, 0);
4182 printf_filtered ("\n");
4185 /* do all (or most) registers */
4188 while (regnum < NUM_REGS)
4190 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4191 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4192 regnum = do_fp_register_row (regnum); /* FP regs */
4194 regnum += MIPS_NUMREGS; /* skip floating point regs */
4196 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4201 /* Is this a branch with a delay slot? */
4203 static int is_delayed (unsigned long);
4206 is_delayed (unsigned long insn)
4209 for (i = 0; i < NUMOPCODES; ++i)
4210 if (mips_opcodes[i].pinfo != INSN_MACRO
4211 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4213 return (i < NUMOPCODES
4214 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4215 | INSN_COND_BRANCH_DELAY
4216 | INSN_COND_BRANCH_LIKELY)));
4220 mips_step_skips_delay (CORE_ADDR pc)
4222 char buf[MIPS_INSTLEN];
4224 /* There is no branch delay slot on MIPS16. */
4225 if (pc_is_mips16 (pc))
4228 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4229 /* If error reading memory, guess that it is not a delayed branch. */
4231 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4235 /* Skip the PC past function prologue instructions (32-bit version).
4236 This is a helper function for mips_skip_prologue. */
4239 mips32_skip_prologue (CORE_ADDR pc)
4243 int seen_sp_adjust = 0;
4244 int load_immediate_bytes = 0;
4246 /* Skip the typical prologue instructions. These are the stack adjustment
4247 instruction and the instructions that save registers on the stack
4248 or in the gcc frame. */
4249 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4251 unsigned long high_word;
4253 inst = mips_fetch_instruction (pc);
4254 high_word = (inst >> 16) & 0xffff;
4256 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4257 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4259 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4260 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4262 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4263 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4264 && (inst & 0x001F0000)) /* reg != $zero */
4267 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4269 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4271 continue; /* reg != $zero */
4273 /* move $s8,$sp. With different versions of gas this will be either
4274 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4275 Accept any one of these. */
4276 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4279 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4281 else if (high_word == 0x3c1c) /* lui $gp,n */
4283 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4285 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4286 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4288 /* The following instructions load $at or $t0 with an immediate
4289 value in preparation for a stack adjustment via
4290 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4291 a local variable, so we accept them only before a stack adjustment
4292 instruction was seen. */
4293 else if (!seen_sp_adjust)
4295 if (high_word == 0x3c01 || /* lui $at,n */
4296 high_word == 0x3c08) /* lui $t0,n */
4298 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4301 else if (high_word == 0x3421 || /* ori $at,$at,n */
4302 high_word == 0x3508 || /* ori $t0,$t0,n */
4303 high_word == 0x3401 || /* ori $at,$zero,n */
4304 high_word == 0x3408) /* ori $t0,$zero,n */
4306 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4316 /* In a frameless function, we might have incorrectly
4317 skipped some load immediate instructions. Undo the skipping
4318 if the load immediate was not followed by a stack adjustment. */
4319 if (load_immediate_bytes && !seen_sp_adjust)
4320 pc -= load_immediate_bytes;
4324 /* Skip the PC past function prologue instructions (16-bit version).
4325 This is a helper function for mips_skip_prologue. */
4328 mips16_skip_prologue (CORE_ADDR pc)
4331 int extend_bytes = 0;
4332 int prev_extend_bytes;
4334 /* Table of instructions likely to be found in a function prologue. */
4337 unsigned short inst;
4338 unsigned short mask;
4345 , /* addiu $sp,offset */
4349 , /* daddiu $sp,offset */
4353 , /* sw reg,n($sp) */
4357 , /* sd reg,n($sp) */
4361 , /* sw $ra,n($sp) */
4365 , /* sd $ra,n($sp) */
4373 , /* sw $a0-$a3,n($s1) */
4377 , /* move reg,$a0-$a3 */
4381 , /* entry pseudo-op */
4385 , /* addiu $s1,$sp,n */
4388 } /* end of table marker */
4391 /* Skip the typical prologue instructions. These are the stack adjustment
4392 instruction and the instructions that save registers on the stack
4393 or in the gcc frame. */
4394 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4396 unsigned short inst;
4399 inst = mips_fetch_instruction (pc);
4401 /* Normally we ignore an extend instruction. However, if it is
4402 not followed by a valid prologue instruction, we must adjust
4403 the pc back over the extend so that it won't be considered
4404 part of the prologue. */
4405 if ((inst & 0xf800) == 0xf000) /* extend */
4407 extend_bytes = MIPS16_INSTLEN;
4410 prev_extend_bytes = extend_bytes;
4413 /* Check for other valid prologue instructions besides extend. */
4414 for (i = 0; table[i].mask != 0; i++)
4415 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4417 if (table[i].mask != 0) /* it was in table? */
4418 continue; /* ignore it */
4422 /* Return the current pc, adjusted backwards by 2 if
4423 the previous instruction was an extend. */
4424 return pc - prev_extend_bytes;
4430 /* To skip prologues, I use this predicate. Returns either PC itself
4431 if the code at PC does not look like a function prologue; otherwise
4432 returns an address that (if we're lucky) follows the prologue. If
4433 LENIENT, then we must skip everything which is involved in setting
4434 up the frame (it's OK to skip more, just so long as we don't skip
4435 anything which might clobber the registers which are being saved.
4436 We must skip more in the case where part of the prologue is in the
4437 delay slot of a non-prologue instruction). */
4440 mips_skip_prologue (CORE_ADDR pc)
4442 /* See if we can determine the end of the prologue via the symbol table.
4443 If so, then return either PC, or the PC after the prologue, whichever
4446 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4448 if (post_prologue_pc != 0)
4449 return max (pc, post_prologue_pc);
4451 /* Can't determine prologue from the symbol table, need to examine
4454 if (pc_is_mips16 (pc))
4455 return mips16_skip_prologue (pc);
4457 return mips32_skip_prologue (pc);
4460 /* Determine how a return value is stored within the MIPS register
4461 file, given the return type `valtype'. */
4463 struct return_value_word
4472 return_value_location (struct type *valtype,
4473 struct return_value_word *hi,
4474 struct return_value_word *lo)
4476 int len = TYPE_LENGTH (valtype);
4478 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4479 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4480 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4482 if (!FP_REGISTER_DOUBLE && len == 8)
4484 /* We need to break a 64bit float in two 32 bit halves and
4485 spread them across a floating-point register pair. */
4486 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4487 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4488 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4489 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4491 hi->reg_offset = lo->reg_offset;
4492 lo->reg = FP0_REGNUM + 0;
4493 hi->reg = FP0_REGNUM + 1;
4499 /* The floating point value fits in a single floating-point
4501 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4502 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4505 lo->reg = FP0_REGNUM;
4516 /* Locate a result possibly spread across two registers. */
4518 lo->reg = regnum + 0;
4519 hi->reg = regnum + 1;
4520 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4521 && len < MIPS_SAVED_REGSIZE)
4523 /* "un-left-justify" the value in the low register */
4524 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4529 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4530 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4531 && len < MIPS_SAVED_REGSIZE * 2
4532 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4533 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4535 /* "un-left-justify" the value spread across two registers. */
4536 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4537 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4539 hi->len = len - lo->len;
4543 /* Only perform a partial copy of the second register. */
4546 if (len > MIPS_SAVED_REGSIZE)
4548 lo->len = MIPS_SAVED_REGSIZE;
4549 hi->len = len - MIPS_SAVED_REGSIZE;
4557 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4558 && REGISTER_RAW_SIZE (regnum) == 8
4559 && MIPS_SAVED_REGSIZE == 4)
4561 /* Account for the fact that only the least-signficant part
4562 of the register is being used */
4563 lo->reg_offset += 4;
4564 hi->reg_offset += 4;
4567 hi->buf_offset = lo->len;
4571 /* Given a return value in `regbuf' with a type `valtype', extract and
4572 copy its value into `valbuf'. */
4575 mips_eabi_extract_return_value (struct type *valtype,
4579 struct return_value_word lo;
4580 struct return_value_word hi;
4581 return_value_location (valtype, &hi, &lo);
4583 memcpy (valbuf + lo.buf_offset,
4584 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4588 memcpy (valbuf + hi.buf_offset,
4589 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4594 mips_o64_extract_return_value (struct type *valtype,
4598 struct return_value_word lo;
4599 struct return_value_word hi;
4600 return_value_location (valtype, &hi, &lo);
4602 memcpy (valbuf + lo.buf_offset,
4603 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4607 memcpy (valbuf + hi.buf_offset,
4608 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4612 /* Given a return value in `valbuf' with a type `valtype', write it's
4613 value into the appropriate register. */
4616 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4618 char raw_buffer[MAX_REGISTER_SIZE];
4619 struct return_value_word lo;
4620 struct return_value_word hi;
4621 return_value_location (valtype, &hi, &lo);
4623 memset (raw_buffer, 0, sizeof (raw_buffer));
4624 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4625 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4626 REGISTER_RAW_SIZE (lo.reg));
4630 memset (raw_buffer, 0, sizeof (raw_buffer));
4631 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4632 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4633 REGISTER_RAW_SIZE (hi.reg));
4638 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4640 char raw_buffer[MAX_REGISTER_SIZE];
4641 struct return_value_word lo;
4642 struct return_value_word hi;
4643 return_value_location (valtype, &hi, &lo);
4645 memset (raw_buffer, 0, sizeof (raw_buffer));
4646 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4647 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4648 REGISTER_RAW_SIZE (lo.reg));
4652 memset (raw_buffer, 0, sizeof (raw_buffer));
4653 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4654 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4655 REGISTER_RAW_SIZE (hi.reg));
4659 /* O32 ABI stuff. */
4662 mips_o32_xfer_return_value (struct type *type,
4663 struct regcache *regcache,
4664 bfd_byte *in, const bfd_byte *out)
4666 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4667 if (TYPE_CODE (type) == TYPE_CODE_FLT
4668 && TYPE_LENGTH (type) == 4
4669 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4671 /* A single-precision floating-point value. It fits in the
4672 least significant part of FP0. */
4674 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4675 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4676 TARGET_BYTE_ORDER, in, out, 0);
4678 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4679 && TYPE_LENGTH (type) == 8
4680 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4682 /* A double-precision floating-point value. It fits in the
4683 least significant part of FP0/FP1 but with byte ordering
4684 based on the target (???). */
4686 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4687 switch (TARGET_BYTE_ORDER)
4689 case BFD_ENDIAN_LITTLE:
4690 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4691 TARGET_BYTE_ORDER, in, out, 0);
4692 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4693 TARGET_BYTE_ORDER, in, out, 4);
4695 case BFD_ENDIAN_BIG:
4696 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4697 TARGET_BYTE_ORDER, in, out, 0);
4698 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4699 TARGET_BYTE_ORDER, in, out, 4);
4702 internal_error (__FILE__, __LINE__, "bad switch");
4706 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4707 && TYPE_NFIELDS (type) <= 2
4708 && TYPE_NFIELDS (type) >= 1
4709 && ((TYPE_NFIELDS (type) == 1
4710 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4712 || (TYPE_NFIELDS (type) == 2
4713 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4715 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4717 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4719 /* A struct that contains one or two floats. Each value is part
4720 in the least significant part of their floating point
4722 bfd_byte reg[MAX_REGISTER_SIZE];
4725 for (field = 0, regnum = FP0_REGNUM;
4726 field < TYPE_NFIELDS (type);
4727 field++, regnum += 2)
4729 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4732 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4733 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4734 TARGET_BYTE_ORDER, in, out, offset);
4739 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4740 || TYPE_CODE (type) == TYPE_CODE_UNION)
4742 /* A structure or union. Extract the left justified value,
4743 regardless of the byte order. I.e. DO NOT USE
4747 for (offset = 0, regnum = V0_REGNUM;
4748 offset < TYPE_LENGTH (type);
4749 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4751 int xfer = REGISTER_RAW_SIZE (regnum);
4752 if (offset + xfer > TYPE_LENGTH (type))
4753 xfer = TYPE_LENGTH (type) - offset;
4755 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4756 offset, xfer, regnum);
4757 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4764 /* A scalar extract each part but least-significant-byte
4765 justified. o32 thinks registers are 4 byte, regardless of
4766 the ISA. mips_stack_argsize controls this. */
4769 for (offset = 0, regnum = V0_REGNUM;
4770 offset < TYPE_LENGTH (type);
4771 offset += mips_stack_argsize (), regnum++)
4773 int xfer = mips_stack_argsize ();
4775 if (offset + xfer > TYPE_LENGTH (type))
4776 xfer = TYPE_LENGTH (type) - offset;
4778 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4779 offset, xfer, regnum);
4780 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4787 mips_o32_extract_return_value (struct type *type,
4788 struct regcache *regcache,
4791 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4795 mips_o32_store_return_value (struct type *type, char *valbuf)
4797 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4800 /* N32/N44 ABI stuff. */
4803 mips_n32n64_xfer_return_value (struct type *type,
4804 struct regcache *regcache,
4805 bfd_byte *in, const bfd_byte *out)
4807 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4808 if (TYPE_CODE (type) == TYPE_CODE_FLT
4809 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4811 /* A floating-point value belongs in the least significant part
4814 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4815 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4816 TARGET_BYTE_ORDER, in, out, 0);
4818 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4819 && TYPE_NFIELDS (type) <= 2
4820 && TYPE_NFIELDS (type) >= 1
4821 && ((TYPE_NFIELDS (type) == 1
4822 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4824 || (TYPE_NFIELDS (type) == 2
4825 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4827 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4829 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4831 /* A struct that contains one or two floats. Each value is part
4832 in the least significant part of their floating point
4834 bfd_byte reg[MAX_REGISTER_SIZE];
4837 for (field = 0, regnum = FP0_REGNUM;
4838 field < TYPE_NFIELDS (type);
4839 field++, regnum += 2)
4841 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4844 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4845 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4846 TARGET_BYTE_ORDER, in, out, offset);
4849 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4850 || TYPE_CODE (type) == TYPE_CODE_UNION)
4852 /* A structure or union. Extract the left justified value,
4853 regardless of the byte order. I.e. DO NOT USE
4857 for (offset = 0, regnum = V0_REGNUM;
4858 offset < TYPE_LENGTH (type);
4859 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4861 int xfer = REGISTER_RAW_SIZE (regnum);
4862 if (offset + xfer > TYPE_LENGTH (type))
4863 xfer = TYPE_LENGTH (type) - offset;
4865 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4866 offset, xfer, regnum);
4867 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4873 /* A scalar extract each part but least-significant-byte
4877 for (offset = 0, regnum = V0_REGNUM;
4878 offset < TYPE_LENGTH (type);
4879 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4881 int xfer = REGISTER_RAW_SIZE (regnum);
4883 if (offset + xfer > TYPE_LENGTH (type))
4884 xfer = TYPE_LENGTH (type) - offset;
4886 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4887 offset, xfer, regnum);
4888 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4895 mips_n32n64_extract_return_value (struct type *type,
4896 struct regcache *regcache,
4899 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4903 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4905 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4909 mips_extract_struct_value_address (struct regcache *regcache)
4911 /* FIXME: This will only work at random. The caller passes the
4912 struct_return address in V0, but it is not preserved. It may
4913 still be there, or this may be a random value. */
4916 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4920 /* Exported procedure: Is PC in the signal trampoline code */
4923 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4925 if (sigtramp_address == 0)
4927 return (pc >= sigtramp_address && pc < sigtramp_end);
4930 /* Root of all "set mips "/"show mips " commands. This will eventually be
4931 used for all MIPS-specific commands. */
4934 show_mips_command (char *args, int from_tty)
4936 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4940 set_mips_command (char *args, int from_tty)
4942 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4943 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4946 /* Commands to show/set the MIPS FPU type. */
4949 show_mipsfpu_command (char *args, int from_tty)
4952 switch (MIPS_FPU_TYPE)
4954 case MIPS_FPU_SINGLE:
4955 fpu = "single-precision";
4957 case MIPS_FPU_DOUBLE:
4958 fpu = "double-precision";
4961 fpu = "absent (none)";
4964 internal_error (__FILE__, __LINE__, "bad switch");
4966 if (mips_fpu_type_auto)
4967 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4970 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
4976 set_mipsfpu_command (char *args, int from_tty)
4978 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
4979 show_mipsfpu_command (args, from_tty);
4983 set_mipsfpu_single_command (char *args, int from_tty)
4985 mips_fpu_type = MIPS_FPU_SINGLE;
4986 mips_fpu_type_auto = 0;
4987 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
4991 set_mipsfpu_double_command (char *args, int from_tty)
4993 mips_fpu_type = MIPS_FPU_DOUBLE;
4994 mips_fpu_type_auto = 0;
4995 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
4999 set_mipsfpu_none_command (char *args, int from_tty)
5001 mips_fpu_type = MIPS_FPU_NONE;
5002 mips_fpu_type_auto = 0;
5003 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5007 set_mipsfpu_auto_command (char *args, int from_tty)
5009 mips_fpu_type_auto = 1;
5012 /* Command to set the processor type. */
5015 mips_set_processor_type_command (char *args, int from_tty)
5019 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5021 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5022 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5023 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5025 /* Restore the value. */
5026 tmp_mips_processor_type = xstrdup (mips_processor_type);
5031 if (!mips_set_processor_type (tmp_mips_processor_type))
5033 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5034 /* Restore its value. */
5035 tmp_mips_processor_type = xstrdup (mips_processor_type);
5040 mips_show_processor_type_command (char *args, int from_tty)
5044 /* Modify the actual processor type. */
5047 mips_set_processor_type (char *str)
5054 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5056 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5058 mips_processor_type = str;
5059 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5061 /* FIXME tweak fpu flag too */
5068 /* Attempt to identify the particular processor model by reading the
5072 mips_read_processor_type (void)
5076 prid = read_register (PRID_REGNUM);
5078 if ((prid & ~0xf) == 0x700)
5079 return savestring ("r3041", strlen ("r3041"));
5084 /* Just like reinit_frame_cache, but with the right arguments to be
5085 callable as an sfunc. */
5088 reinit_frame_cache_sfunc (char *args, int from_tty,
5089 struct cmd_list_element *c)
5091 reinit_frame_cache ();
5095 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5097 mips_extra_func_info_t proc_desc;
5099 /* Search for the function containing this address. Set the low bit
5100 of the address when searching, in case we were given an even address
5101 that is the start of a 16-bit function. If we didn't do this,
5102 the search would fail because the symbol table says the function
5103 starts at an odd address, i.e. 1 byte past the given address. */
5104 memaddr = ADDR_BITS_REMOVE (memaddr);
5105 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5107 /* Make an attempt to determine if this is a 16-bit function. If
5108 the procedure descriptor exists and the address therein is odd,
5109 it's definitely a 16-bit function. Otherwise, we have to just
5110 guess that if the address passed in is odd, it's 16-bits. */
5112 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5113 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5115 info->mach = pc_is_mips16 (memaddr) ?
5116 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5118 /* Round down the instruction address to the appropriate boundary. */
5119 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5121 /* Call the appropriate disassembler based on the target endian-ness. */
5122 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5123 return print_insn_big_mips (memaddr, info);
5125 return print_insn_little_mips (memaddr, info);
5128 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5129 counter value to determine whether a 16- or 32-bit breakpoint should be
5130 used. It returns a pointer to a string of bytes that encode a breakpoint
5131 instruction, stores the length of the string to *lenptr, and adjusts pc
5132 (if necessary) to point to the actual memory location where the
5133 breakpoint should be inserted. */
5135 static const unsigned char *
5136 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5138 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5140 if (pc_is_mips16 (*pcptr))
5142 static unsigned char mips16_big_breakpoint[] = {0xe8, 0xa5};
5143 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5144 *lenptr = sizeof (mips16_big_breakpoint);
5145 return mips16_big_breakpoint;
5149 /* The IDT board uses an unusual breakpoint value, and
5150 sometimes gets confused when it sees the usual MIPS
5151 breakpoint instruction. */
5152 static unsigned char big_breakpoint[] = {0, 0x5, 0, 0xd};
5153 static unsigned char pmon_big_breakpoint[] = {0, 0, 0, 0xd};
5154 static unsigned char idt_big_breakpoint[] = {0, 0, 0x0a, 0xd};
5156 *lenptr = sizeof (big_breakpoint);
5158 if (strcmp (target_shortname, "mips") == 0)
5159 return idt_big_breakpoint;
5160 else if (strcmp (target_shortname, "ddb") == 0
5161 || strcmp (target_shortname, "pmon") == 0
5162 || strcmp (target_shortname, "lsi") == 0)
5163 return pmon_big_breakpoint;
5165 return big_breakpoint;
5170 if (pc_is_mips16 (*pcptr))
5172 static unsigned char mips16_little_breakpoint[] = {0xa5, 0xe8};
5173 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5174 *lenptr = sizeof (mips16_little_breakpoint);
5175 return mips16_little_breakpoint;
5179 static unsigned char little_breakpoint[] = {0xd, 0, 0x5, 0};
5180 static unsigned char pmon_little_breakpoint[] = {0xd, 0, 0, 0};
5181 static unsigned char idt_little_breakpoint[] = {0xd, 0x0a, 0, 0};
5183 *lenptr = sizeof (little_breakpoint);
5185 if (strcmp (target_shortname, "mips") == 0)
5186 return idt_little_breakpoint;
5187 else if (strcmp (target_shortname, "ddb") == 0
5188 || strcmp (target_shortname, "pmon") == 0
5189 || strcmp (target_shortname, "lsi") == 0)
5190 return pmon_little_breakpoint;
5192 return little_breakpoint;
5197 /* If PC is in a mips16 call or return stub, return the address of the target
5198 PC, which is either the callee or the caller. There are several
5199 cases which must be handled:
5201 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5202 target PC is in $31 ($ra).
5203 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5204 and the target PC is in $2.
5205 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5206 before the jal instruction, this is effectively a call stub
5207 and the the target PC is in $2. Otherwise this is effectively
5208 a return stub and the target PC is in $18.
5210 See the source code for the stubs in gcc/config/mips/mips16.S for
5213 This function implements the SKIP_TRAMPOLINE_CODE macro.
5217 mips_skip_stub (CORE_ADDR pc)
5220 CORE_ADDR start_addr;
5222 /* Find the starting address and name of the function containing the PC. */
5223 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5226 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5227 target PC is in $31 ($ra). */
5228 if (strcmp (name, "__mips16_ret_sf") == 0
5229 || strcmp (name, "__mips16_ret_df") == 0)
5230 return read_signed_register (RA_REGNUM);
5232 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5234 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5235 and the target PC is in $2. */
5236 if (name[19] >= '0' && name[19] <= '9')
5237 return read_signed_register (2);
5239 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5240 before the jal instruction, this is effectively a call stub
5241 and the the target PC is in $2. Otherwise this is effectively
5242 a return stub and the target PC is in $18. */
5243 else if (name[19] == 's' || name[19] == 'd')
5245 if (pc == start_addr)
5247 /* Check if the target of the stub is a compiler-generated
5248 stub. Such a stub for a function bar might have a name
5249 like __fn_stub_bar, and might look like this:
5254 la $1,bar (becomes a lui/addiu pair)
5256 So scan down to the lui/addi and extract the target
5257 address from those two instructions. */
5259 CORE_ADDR target_pc = read_signed_register (2);
5263 /* See if the name of the target function is __fn_stub_*. */
5264 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5266 if (strncmp (name, "__fn_stub_", 10) != 0
5267 && strcmp (name, "etext") != 0
5268 && strcmp (name, "_etext") != 0)
5271 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5272 The limit on the search is arbitrarily set to 20
5273 instructions. FIXME. */
5274 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5276 inst = mips_fetch_instruction (target_pc);
5277 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5278 pc = (inst << 16) & 0xffff0000; /* high word */
5279 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5280 return pc | (inst & 0xffff); /* low word */
5283 /* Couldn't find the lui/addui pair, so return stub address. */
5287 /* This is the 'return' part of a call stub. The return
5288 address is in $r18. */
5289 return read_signed_register (18);
5292 return 0; /* not a stub */
5296 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5297 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5300 mips_in_call_stub (CORE_ADDR pc, char *name)
5302 CORE_ADDR start_addr;
5304 /* Find the starting address of the function containing the PC. If the
5305 caller didn't give us a name, look it up at the same time. */
5306 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5309 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5311 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5312 if (name[19] >= '0' && name[19] <= '9')
5314 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5315 before the jal instruction, this is effectively a call stub. */
5316 else if (name[19] == 's' || name[19] == 'd')
5317 return pc == start_addr;
5320 return 0; /* not a stub */
5324 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5325 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5328 mips_in_return_stub (CORE_ADDR pc, char *name)
5330 CORE_ADDR start_addr;
5332 /* Find the starting address of the function containing the PC. */
5333 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5336 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5337 if (strcmp (name, "__mips16_ret_sf") == 0
5338 || strcmp (name, "__mips16_ret_df") == 0)
5341 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5342 i.e. after the jal instruction, this is effectively a return stub. */
5343 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5344 && (name[19] == 's' || name[19] == 'd')
5345 && pc != start_addr)
5348 return 0; /* not a stub */
5352 /* Return non-zero if the PC is in a library helper function that should
5353 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5356 mips_ignore_helper (CORE_ADDR pc)
5360 /* Find the starting address and name of the function containing the PC. */
5361 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5364 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5365 that we want to ignore. */
5366 return (strcmp (name, "__mips16_ret_sf") == 0
5367 || strcmp (name, "__mips16_ret_df") == 0);
5371 /* Return a location where we can set a breakpoint that will be hit
5372 when an inferior function call returns. This is normally the
5373 program's entry point. Executables that don't have an entry
5374 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5375 whose address is the location where the breakpoint should be placed. */
5378 mips_call_dummy_address (void)
5380 struct minimal_symbol *sym;
5382 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5384 return SYMBOL_VALUE_ADDRESS (sym);
5386 return entry_point_address ();
5390 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5391 the register stored on the stack (32) is different to its real raw
5392 size (64). The below ensures that registers are fetched from the
5393 stack using their ABI size and then stored into the RAW_BUFFER
5394 using their raw size.
5396 The alternative to adding this function would be to add an ABI
5397 macro - REGISTER_STACK_SIZE(). */
5400 mips_get_saved_register (char *raw_buffer,
5403 struct frame_info *frame,
5405 enum lval_type *lvalp)
5408 enum lval_type lvalx;
5411 if (!target_has_registers)
5412 error ("No registers.");
5414 /* Make certain that all needed parameters are present. */
5419 if (optimizedp == NULL)
5420 optimizedp = &optimizedx;
5421 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5423 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5424 have a pseudo register range that correspons to the ABI's, rather
5425 than the ISA's, view of registers. These registers would then
5426 implicitly describe their size and hence could be used without
5427 the below munging. */
5428 if ((*lvalp) == lval_memory)
5430 if (raw_buffer != NULL)
5434 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5436 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5437 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5443 /* Immediately after a function call, return the saved pc.
5444 Can't always go through the frames for this because on some machines
5445 the new frame is not set up until the new function executes
5446 some instructions. */
5449 mips_saved_pc_after_call (struct frame_info *frame)
5451 return read_signed_register (RA_REGNUM);
5455 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5459 mips_stab_reg_to_regnum (int num)
5461 if (num >= 0 && num < 32)
5463 else if (num >= 38 && num < 70)
5464 return num + FP0_REGNUM - 38;
5471 /* This will hopefully (eventually) provoke a warning. Should
5472 we be calling complaint() here? */
5473 return NUM_REGS + NUM_PSEUDO_REGS;
5478 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5481 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5483 if (num >= 0 && num < 32)
5485 else if (num >= 32 && num < 64)
5486 return num + FP0_REGNUM - 32;
5493 /* This will hopefully (eventually) provoke a warning. Should
5494 we be calling complaint() here? */
5495 return NUM_REGS + NUM_PSEUDO_REGS;
5500 /* Convert an integer into an address. By first converting the value
5501 into a pointer and then extracting it signed, the address is
5502 guarenteed to be correctly sign extended. */
5505 mips_integer_to_address (struct type *type, void *buf)
5507 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5508 LONGEST val = unpack_long (type, buf);
5509 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5510 return extract_signed_integer (tmp,
5511 TYPE_LENGTH (builtin_type_void_data_ptr));
5515 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5517 enum mips_abi *abip = (enum mips_abi *) obj;
5518 const char *name = bfd_get_section_name (abfd, sect);
5520 if (*abip != MIPS_ABI_UNKNOWN)
5523 if (strncmp (name, ".mdebug.", 8) != 0)
5526 if (strcmp (name, ".mdebug.abi32") == 0)
5527 *abip = MIPS_ABI_O32;
5528 else if (strcmp (name, ".mdebug.abiN32") == 0)
5529 *abip = MIPS_ABI_N32;
5530 else if (strcmp (name, ".mdebug.abi64") == 0)
5531 *abip = MIPS_ABI_N64;
5532 else if (strcmp (name, ".mdebug.abiO64") == 0)
5533 *abip = MIPS_ABI_O64;
5534 else if (strcmp (name, ".mdebug.eabi32") == 0)
5535 *abip = MIPS_ABI_EABI32;
5536 else if (strcmp (name, ".mdebug.eabi64") == 0)
5537 *abip = MIPS_ABI_EABI64;
5539 warning ("unsupported ABI %s.", name + 8);
5542 static enum mips_abi
5543 global_mips_abi (void)
5547 for (i = 0; mips_abi_strings[i] != NULL; i++)
5548 if (mips_abi_strings[i] == mips_abi_string)
5549 return (enum mips_abi) i;
5551 internal_error (__FILE__, __LINE__,
5552 "unknown ABI string");
5555 static struct gdbarch *
5556 mips_gdbarch_init (struct gdbarch_info info,
5557 struct gdbarch_list *arches)
5559 struct gdbarch *gdbarch;
5560 struct gdbarch_tdep *tdep;
5562 enum mips_abi mips_abi, found_abi, wanted_abi;
5564 /* Reset the disassembly info, in case it was set to something
5566 deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5567 deprecated_tm_print_insn_info.arch = bfd_arch_unknown;
5568 deprecated_tm_print_insn_info.mach = 0;
5574 /* First of all, extract the elf_flags, if available. */
5575 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5576 elf_flags = elf_elfheader (info.abfd)->e_flags;
5579 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5580 switch ((elf_flags & EF_MIPS_ABI))
5582 case E_MIPS_ABI_O32:
5583 mips_abi = MIPS_ABI_O32;
5585 case E_MIPS_ABI_O64:
5586 mips_abi = MIPS_ABI_O64;
5588 case E_MIPS_ABI_EABI32:
5589 mips_abi = MIPS_ABI_EABI32;
5591 case E_MIPS_ABI_EABI64:
5592 mips_abi = MIPS_ABI_EABI64;
5595 if ((elf_flags & EF_MIPS_ABI2))
5596 mips_abi = MIPS_ABI_N32;
5598 mips_abi = MIPS_ABI_UNKNOWN;
5602 /* GCC creates a pseudo-section whose name describes the ABI. */
5603 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5604 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5606 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5607 Use the ABI from the last architecture if there is one. */
5608 if (info.abfd == NULL && arches != NULL)
5609 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5611 /* Try the architecture for any hint of the correct ABI. */
5612 if (mips_abi == MIPS_ABI_UNKNOWN
5613 && info.bfd_arch_info != NULL
5614 && info.bfd_arch_info->arch == bfd_arch_mips)
5616 switch (info.bfd_arch_info->mach)
5618 case bfd_mach_mips3900:
5619 mips_abi = MIPS_ABI_EABI32;
5621 case bfd_mach_mips4100:
5622 case bfd_mach_mips5000:
5623 mips_abi = MIPS_ABI_EABI64;
5625 case bfd_mach_mips8000:
5626 case bfd_mach_mips10000:
5627 /* On Irix, ELF64 executables use the N64 ABI. The
5628 pseudo-sections which describe the ABI aren't present
5629 on IRIX. (Even for executables created by gcc.) */
5630 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5631 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5632 mips_abi = MIPS_ABI_N64;
5634 mips_abi = MIPS_ABI_N32;
5639 if (mips_abi == MIPS_ABI_UNKNOWN)
5640 mips_abi = MIPS_ABI_O32;
5642 /* Now that we have found what the ABI for this binary would be,
5643 check whether the user is overriding it. */
5644 found_abi = mips_abi;
5645 wanted_abi = global_mips_abi ();
5646 if (wanted_abi != MIPS_ABI_UNKNOWN)
5647 mips_abi = wanted_abi;
5649 /* We have to set deprecated_tm_print_insn_info before looking for a
5650 pre-existing architecture, otherwise we may return before we get
5651 a chance to set it up. */
5652 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5654 /* Set up the disassembler info, so that we get the right
5655 register names from libopcodes. */
5656 if (mips_abi == MIPS_ABI_N32)
5657 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=n32";
5659 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=64";
5660 deprecated_tm_print_insn_info.flavour = bfd_target_elf_flavour;
5661 deprecated_tm_print_insn_info.arch = bfd_arch_mips;
5662 if (info.bfd_arch_info != NULL
5663 && info.bfd_arch_info->arch == bfd_arch_mips
5664 && info.bfd_arch_info->mach)
5665 deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
5667 deprecated_tm_print_insn_info.mach = bfd_mach_mips8000;
5670 /* This string is not recognized explicitly by the disassembler,
5671 but it tells the disassembler to not try to guess the ABI from
5672 the bfd elf headers, such that, if the user overrides the ABI
5673 of a program linked as NewABI, the disassembly will follow the
5674 register naming conventions specified by the user. */
5675 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=32";
5679 fprintf_unfiltered (gdb_stdlog,
5680 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5682 fprintf_unfiltered (gdb_stdlog,
5683 "mips_gdbarch_init: mips_abi = %d\n",
5685 fprintf_unfiltered (gdb_stdlog,
5686 "mips_gdbarch_init: found_mips_abi = %d\n",
5690 /* try to find a pre-existing architecture */
5691 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5693 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5695 /* MIPS needs to be pedantic about which ABI the object is
5697 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5699 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5701 return arches->gdbarch;
5704 /* Need a new architecture. Fill in a target specific vector. */
5705 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5706 gdbarch = gdbarch_alloc (&info, tdep);
5707 tdep->elf_flags = elf_flags;
5709 /* Initially set everything according to the default ABI/ISA. */
5710 set_gdbarch_short_bit (gdbarch, 16);
5711 set_gdbarch_int_bit (gdbarch, 32);
5712 set_gdbarch_float_bit (gdbarch, 32);
5713 set_gdbarch_double_bit (gdbarch, 64);
5714 set_gdbarch_long_double_bit (gdbarch, 64);
5715 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5716 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8);
5717 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5718 tdep->found_abi = found_abi;
5719 tdep->mips_abi = mips_abi;
5721 set_gdbarch_elf_make_msymbol_special (gdbarch,
5722 mips_elf_make_msymbol_special);
5724 if (info.osabi == GDB_OSABI_IRIX)
5725 set_gdbarch_num_regs (gdbarch, 71);
5727 set_gdbarch_num_regs (gdbarch, 90);
5732 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5733 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5734 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5735 tdep->mips_default_saved_regsize = 4;
5736 tdep->mips_default_stack_argsize = 4;
5737 tdep->mips_fp_register_double = 0;
5738 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5739 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5740 tdep->gdb_target_is_mips64 = 0;
5741 tdep->default_mask_address_p = 0;
5742 set_gdbarch_long_bit (gdbarch, 32);
5743 set_gdbarch_ptr_bit (gdbarch, 32);
5744 set_gdbarch_long_long_bit (gdbarch, 64);
5745 set_gdbarch_reg_struct_has_addr (gdbarch,
5746 mips_o32_reg_struct_has_addr);
5747 set_gdbarch_use_struct_convention (gdbarch,
5748 mips_o32_use_struct_convention);
5751 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5752 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5753 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5754 tdep->mips_default_saved_regsize = 8;
5755 tdep->mips_default_stack_argsize = 8;
5756 tdep->mips_fp_register_double = 1;
5757 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5758 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5759 tdep->gdb_target_is_mips64 = 1;
5760 tdep->default_mask_address_p = 0;
5761 set_gdbarch_long_bit (gdbarch, 32);
5762 set_gdbarch_ptr_bit (gdbarch, 32);
5763 set_gdbarch_long_long_bit (gdbarch, 64);
5764 set_gdbarch_reg_struct_has_addr (gdbarch,
5765 mips_o32_reg_struct_has_addr);
5766 set_gdbarch_use_struct_convention (gdbarch,
5767 mips_o32_use_struct_convention);
5769 case MIPS_ABI_EABI32:
5770 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5771 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5772 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5773 tdep->mips_default_saved_regsize = 4;
5774 tdep->mips_default_stack_argsize = 4;
5775 tdep->mips_fp_register_double = 0;
5776 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5777 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5778 tdep->gdb_target_is_mips64 = 0;
5779 tdep->default_mask_address_p = 0;
5780 set_gdbarch_long_bit (gdbarch, 32);
5781 set_gdbarch_ptr_bit (gdbarch, 32);
5782 set_gdbarch_long_long_bit (gdbarch, 64);
5783 set_gdbarch_reg_struct_has_addr (gdbarch,
5784 mips_eabi_reg_struct_has_addr);
5785 set_gdbarch_use_struct_convention (gdbarch,
5786 mips_eabi_use_struct_convention);
5788 case MIPS_ABI_EABI64:
5789 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5790 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5791 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5792 tdep->mips_default_saved_regsize = 8;
5793 tdep->mips_default_stack_argsize = 8;
5794 tdep->mips_fp_register_double = 1;
5795 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5796 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5797 tdep->gdb_target_is_mips64 = 1;
5798 tdep->default_mask_address_p = 0;
5799 set_gdbarch_long_bit (gdbarch, 64);
5800 set_gdbarch_ptr_bit (gdbarch, 64);
5801 set_gdbarch_long_long_bit (gdbarch, 64);
5802 set_gdbarch_reg_struct_has_addr (gdbarch,
5803 mips_eabi_reg_struct_has_addr);
5804 set_gdbarch_use_struct_convention (gdbarch,
5805 mips_eabi_use_struct_convention);
5808 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5809 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5810 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5811 tdep->mips_default_saved_regsize = 8;
5812 tdep->mips_default_stack_argsize = 8;
5813 tdep->mips_fp_register_double = 1;
5814 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5815 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5816 tdep->gdb_target_is_mips64 = 1;
5817 tdep->default_mask_address_p = 0;
5818 set_gdbarch_long_bit (gdbarch, 32);
5819 set_gdbarch_ptr_bit (gdbarch, 32);
5820 set_gdbarch_long_long_bit (gdbarch, 64);
5821 set_gdbarch_use_struct_convention (gdbarch,
5822 mips_n32n64_use_struct_convention);
5823 set_gdbarch_reg_struct_has_addr (gdbarch,
5824 mips_n32n64_reg_struct_has_addr);
5827 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5828 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5829 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5830 tdep->mips_default_saved_regsize = 8;
5831 tdep->mips_default_stack_argsize = 8;
5832 tdep->mips_fp_register_double = 1;
5833 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5834 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5835 tdep->gdb_target_is_mips64 = 1;
5836 tdep->default_mask_address_p = 0;
5837 set_gdbarch_long_bit (gdbarch, 64);
5838 set_gdbarch_ptr_bit (gdbarch, 64);
5839 set_gdbarch_long_long_bit (gdbarch, 64);
5840 set_gdbarch_use_struct_convention (gdbarch,
5841 mips_n32n64_use_struct_convention);
5842 set_gdbarch_reg_struct_has_addr (gdbarch,
5843 mips_n32n64_reg_struct_has_addr);
5846 internal_error (__FILE__, __LINE__,
5847 "unknown ABI in switch");
5850 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5851 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5854 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5855 flag in object files because to do so would make it impossible to
5856 link with libraries compiled without "-gp32". This is
5857 unnecessarily restrictive.
5859 We could solve this problem by adding "-gp32" multilibs to gcc,
5860 but to set this flag before gcc is built with such multilibs will
5861 break too many systems.''
5863 But even more unhelpfully, the default linker output target for
5864 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5865 for 64-bit programs - you need to change the ABI to change this,
5866 and not all gcc targets support that currently. Therefore using
5867 this flag to detect 32-bit mode would do the wrong thing given
5868 the current gcc - it would make GDB treat these 64-bit programs
5869 as 32-bit programs by default. */
5871 /* enable/disable the MIPS FPU */
5872 if (!mips_fpu_type_auto)
5873 tdep->mips_fpu_type = mips_fpu_type;
5874 else if (info.bfd_arch_info != NULL
5875 && info.bfd_arch_info->arch == bfd_arch_mips)
5876 switch (info.bfd_arch_info->mach)
5878 case bfd_mach_mips3900:
5879 case bfd_mach_mips4100:
5880 case bfd_mach_mips4111:
5881 tdep->mips_fpu_type = MIPS_FPU_NONE;
5883 case bfd_mach_mips4650:
5884 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5887 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5891 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5893 /* MIPS version of register names. NOTE: At present the MIPS
5894 register name management is part way between the old -
5895 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5896 Further work on it is required. */
5897 /* NOTE: many targets (esp. embedded) do not go thru the
5898 gdbarch_register_name vector at all, instead bypassing it
5899 by defining REGISTER_NAMES. */
5900 set_gdbarch_register_name (gdbarch, mips_register_name);
5901 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5902 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5903 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5904 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5905 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
5907 /* Add/remove bits from an address. The MIPS needs be careful to
5908 ensure that all 32 bit addresses are sign extended to 64 bits. */
5909 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5911 /* There's a mess in stack frame creation. See comments in
5912 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5913 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5914 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5916 /* Map debug register numbers onto internal register numbers. */
5917 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5918 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5919 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5920 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5922 /* Initialize a frame */
5923 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5924 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5926 /* MIPS version of CALL_DUMMY */
5928 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5929 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
5930 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5931 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5932 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
5933 set_gdbarch_register_convert_to_virtual (gdbarch,
5934 mips_register_convert_to_virtual);
5935 set_gdbarch_register_convert_to_raw (gdbarch,
5936 mips_register_convert_to_raw);
5938 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
5939 set_gdbarch_frameless_function_invocation (gdbarch,
5940 generic_frameless_function_invocation_not);
5941 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5942 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
5943 set_gdbarch_frame_args_skip (gdbarch, 0);
5945 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
5947 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5948 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5949 set_gdbarch_decr_pc_after_break (gdbarch, 0);
5951 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5952 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
5954 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5955 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5956 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5958 set_gdbarch_function_start_offset (gdbarch, 0);
5960 /* There are MIPS targets which do not yet use this since they still
5961 define REGISTER_VIRTUAL_TYPE. */
5962 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
5963 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
5965 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
5966 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
5968 /* Hook in OS ABI-specific overrides, if they have been registered. */
5969 gdbarch_init_osabi (info, gdbarch);
5971 set_gdbarch_extract_struct_value_address (gdbarch,
5972 mips_extract_struct_value_address);
5974 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
5976 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
5977 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
5983 mips_abi_update (char *ignore_args, int from_tty,
5984 struct cmd_list_element *c)
5986 struct gdbarch_info info;
5988 /* Force the architecture to update, and (if it's a MIPS architecture)
5989 mips_gdbarch_init will take care of the rest. */
5990 gdbarch_info_init (&info);
5991 gdbarch_update_p (info);
5994 /* Print out which MIPS ABI is in use. */
5997 show_mips_abi (char *ignore_args, int from_tty)
5999 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6001 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6004 enum mips_abi global_abi = global_mips_abi ();
6005 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6006 const char *actual_abi_str = mips_abi_strings[actual_abi];
6008 if (global_abi == MIPS_ABI_UNKNOWN)
6009 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6011 else if (global_abi == actual_abi)
6013 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6017 /* Probably shouldn't happen... */
6019 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6021 mips_abi_strings[global_abi]);
6027 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6029 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6033 int ef_mips_32bitmode;
6034 /* determine the ISA */
6035 switch (tdep->elf_flags & EF_MIPS_ARCH)
6053 /* determine the size of a pointer */
6054 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6055 fprintf_unfiltered (file,
6056 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6058 fprintf_unfiltered (file,
6059 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6061 fprintf_unfiltered (file,
6062 "mips_dump_tdep: ef_mips_arch = %d\n",
6064 fprintf_unfiltered (file,
6065 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6067 mips_abi_strings[tdep->mips_abi]);
6068 fprintf_unfiltered (file,
6069 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6070 mips_mask_address_p (),
6071 tdep->default_mask_address_p);
6073 fprintf_unfiltered (file,
6074 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6075 FP_REGISTER_DOUBLE);
6076 fprintf_unfiltered (file,
6077 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6078 MIPS_DEFAULT_FPU_TYPE,
6079 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6080 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6081 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6083 fprintf_unfiltered (file,
6084 "mips_dump_tdep: MIPS_EABI = %d\n",
6086 fprintf_unfiltered (file,
6087 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6088 MIPS_LAST_FP_ARG_REGNUM,
6089 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6090 fprintf_unfiltered (file,
6091 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6093 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6094 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6095 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6097 fprintf_unfiltered (file,
6098 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6099 MIPS_DEFAULT_SAVED_REGSIZE);
6100 fprintf_unfiltered (file,
6101 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6102 FP_REGISTER_DOUBLE);
6103 fprintf_unfiltered (file,
6104 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6105 MIPS_DEFAULT_STACK_ARGSIZE);
6106 fprintf_unfiltered (file,
6107 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6108 MIPS_STACK_ARGSIZE);
6109 fprintf_unfiltered (file,
6110 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6112 fprintf_unfiltered (file,
6113 "mips_dump_tdep: A0_REGNUM = %d\n",
6115 fprintf_unfiltered (file,
6116 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6117 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6118 fprintf_unfiltered (file,
6119 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6120 XSTRING (ATTACH_DETACH));
6121 fprintf_unfiltered (file,
6122 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6124 fprintf_unfiltered (file,
6125 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6127 fprintf_unfiltered (file,
6128 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6129 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6130 fprintf_unfiltered (file,
6131 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6132 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6133 fprintf_unfiltered (file,
6134 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6136 fprintf_unfiltered (file,
6137 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6139 fprintf_unfiltered (file,
6140 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6141 FIRST_EMBED_REGNUM);
6142 fprintf_unfiltered (file,
6143 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6145 fprintf_unfiltered (file,
6146 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6147 GDB_TARGET_IS_MIPS64);
6148 fprintf_unfiltered (file,
6149 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6150 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6151 fprintf_unfiltered (file,
6152 "mips_dump_tdep: HI_REGNUM = %d\n",
6154 fprintf_unfiltered (file,
6155 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6156 XSTRING (IGNORE_HELPER_CALL (PC)));
6157 fprintf_unfiltered (file,
6158 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6159 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6160 fprintf_unfiltered (file,
6161 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6162 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6163 fprintf_unfiltered (file,
6164 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6165 fprintf_unfiltered (file,
6166 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6168 fprintf_unfiltered (file,
6169 "mips_dump_tdep: LO_REGNUM = %d\n",
6171 #ifdef MACHINE_CPROC_FP_OFFSET
6172 fprintf_unfiltered (file,
6173 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6174 MACHINE_CPROC_FP_OFFSET);
6176 #ifdef MACHINE_CPROC_PC_OFFSET
6177 fprintf_unfiltered (file,
6178 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6179 MACHINE_CPROC_PC_OFFSET);
6181 #ifdef MACHINE_CPROC_SP_OFFSET
6182 fprintf_unfiltered (file,
6183 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6184 MACHINE_CPROC_SP_OFFSET);
6186 fprintf_unfiltered (file,
6187 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6188 fprintf_unfiltered (file,
6189 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6191 fprintf_unfiltered (file,
6192 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6193 fprintf_unfiltered (file,
6194 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6195 fprintf_unfiltered (file,
6196 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6198 fprintf_unfiltered (file,
6199 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6200 MIPS_LAST_ARG_REGNUM,
6201 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6202 fprintf_unfiltered (file,
6203 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6205 fprintf_unfiltered (file,
6206 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6207 fprintf_unfiltered (file,
6208 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6209 MIPS_SAVED_REGSIZE);
6210 fprintf_unfiltered (file,
6211 "mips_dump_tdep: OP_LDFPR = used?\n");
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: OP_LDGPR = used?\n");
6214 fprintf_unfiltered (file,
6215 "mips_dump_tdep: PRID_REGNUM = %d\n",
6217 fprintf_unfiltered (file,
6218 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6219 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6220 fprintf_unfiltered (file,
6221 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6222 fprintf_unfiltered (file,
6223 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6224 fprintf_unfiltered (file,
6225 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6228 fprintf_unfiltered (file,
6229 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6230 fprintf_unfiltered (file,
6231 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6232 fprintf_unfiltered (file,
6233 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6234 fprintf_unfiltered (file,
6235 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6236 fprintf_unfiltered (file,
6237 "mips_dump_tdep: PROC_PC_REG = function?\n");
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6240 fprintf_unfiltered (file,
6241 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6242 fprintf_unfiltered (file,
6243 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6244 fprintf_unfiltered (file,
6245 "mips_dump_tdep: PS_REGNUM = %d\n",
6247 fprintf_unfiltered (file,
6248 "mips_dump_tdep: RA_REGNUM = %d\n",
6250 fprintf_unfiltered (file,
6251 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6252 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6253 fprintf_unfiltered (file,
6254 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6255 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6256 fprintf_unfiltered (file,
6257 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6258 fprintf_unfiltered (file,
6259 "mips_dump_tdep: ROUND_DOWN = function?\n");
6260 fprintf_unfiltered (file,
6261 "mips_dump_tdep: ROUND_UP = function?\n");
6263 fprintf_unfiltered (file,
6264 "mips_dump_tdep: SAVED_BYTES = %d\n",
6268 fprintf_unfiltered (file,
6269 "mips_dump_tdep: SAVED_FP = %d\n",
6273 fprintf_unfiltered (file,
6274 "mips_dump_tdep: SAVED_PC = %d\n",
6277 fprintf_unfiltered (file,
6278 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6279 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6280 fprintf_unfiltered (file,
6281 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6282 fprintf_unfiltered (file,
6283 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6285 fprintf_unfiltered (file,
6286 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6287 SIGFRAME_FPREGSAVE_OFF);
6288 fprintf_unfiltered (file,
6289 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6291 fprintf_unfiltered (file,
6292 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6293 SIGFRAME_REGSAVE_OFF);
6294 fprintf_unfiltered (file,
6295 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6297 fprintf_unfiltered (file,
6298 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6299 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6300 fprintf_unfiltered (file,
6301 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6302 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6303 fprintf_unfiltered (file,
6304 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6305 SOFTWARE_SINGLE_STEP_P ());
6306 fprintf_unfiltered (file,
6307 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6308 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6309 #ifdef STACK_END_ADDR
6310 fprintf_unfiltered (file,
6311 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6314 fprintf_unfiltered (file,
6315 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6316 XSTRING (STEP_SKIPS_DELAY (PC)));
6317 fprintf_unfiltered (file,
6318 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6319 STEP_SKIPS_DELAY_P);
6320 fprintf_unfiltered (file,
6321 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6322 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6323 fprintf_unfiltered (file,
6324 "mips_dump_tdep: T9_REGNUM = %d\n",
6326 fprintf_unfiltered (file,
6327 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6328 fprintf_unfiltered (file,
6329 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6330 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6331 fprintf_unfiltered (file,
6332 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6333 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6334 fprintf_unfiltered (file,
6335 "mips_dump_tdep: TARGET_MIPS = used?\n");
6336 fprintf_unfiltered (file,
6337 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6338 XSTRING (TM_PRINT_INSN_MACH));
6340 fprintf_unfiltered (file,
6341 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6342 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6345 fprintf_unfiltered (file,
6346 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6349 #ifdef TRACE_FLAVOR_SIZE
6350 fprintf_unfiltered (file,
6351 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6355 fprintf_unfiltered (file,
6356 "mips_dump_tdep: TRACE_SET # %s\n",
6357 XSTRING (TRACE_SET (X,STATE)));
6359 fprintf_unfiltered (file,
6360 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6361 #ifdef UNUSED_REGNUM
6362 fprintf_unfiltered (file,
6363 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6366 fprintf_unfiltered (file,
6367 "mips_dump_tdep: V0_REGNUM = %d\n",
6369 fprintf_unfiltered (file,
6370 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6371 (long) VM_MIN_ADDRESS);
6373 fprintf_unfiltered (file,
6374 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6377 fprintf_unfiltered (file,
6378 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6380 fprintf_unfiltered (file,
6381 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6386 _initialize_mips_tdep (void)
6388 static struct cmd_list_element *mipsfpulist = NULL;
6389 struct cmd_list_element *c;
6391 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6392 if (MIPS_ABI_LAST + 1
6393 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6394 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6396 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6397 if (!deprecated_tm_print_insn) /* Someone may have already set it */
6398 deprecated_tm_print_insn = gdb_print_insn_mips;
6400 /* Add root prefix command for all "set mips"/"show mips" commands */
6401 add_prefix_cmd ("mips", no_class, set_mips_command,
6402 "Various MIPS specific commands.",
6403 &setmipscmdlist, "set mips ", 0, &setlist);
6405 add_prefix_cmd ("mips", no_class, show_mips_command,
6406 "Various MIPS specific commands.",
6407 &showmipscmdlist, "show mips ", 0, &showlist);
6409 /* Allow the user to override the saved register size. */
6410 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6413 &mips_saved_regsize_string, "\
6414 Set size of general purpose registers saved on the stack.\n\
6415 This option can be set to one of:\n\
6416 32 - Force GDB to treat saved GP registers as 32-bit\n\
6417 64 - Force GDB to treat saved GP registers as 64-bit\n\
6418 auto - Allow GDB to use the target's default setting or autodetect the\n\
6419 saved GP register size from information contained in the executable.\n\
6424 /* Allow the user to override the argument stack size. */
6425 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6428 &mips_stack_argsize_string, "\
6429 Set the amount of stack space reserved for each argument.\n\
6430 This option can be set to one of:\n\
6431 32 - Force GDB to allocate 32-bit chunks per argument\n\
6432 64 - Force GDB to allocate 64-bit chunks per argument\n\
6433 auto - Allow GDB to determine the correct setting from the current\n\
6434 target and executable (default)",
6438 /* Allow the user to override the ABI. */
6439 c = add_set_enum_cmd
6440 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6441 "Set the ABI used by this program.\n"
6442 "This option can be set to one of:\n"
6443 " auto - the default ABI associated with the current binary\n"
6451 set_cmd_sfunc (c, mips_abi_update);
6452 add_cmd ("abi", class_obscure, show_mips_abi,
6453 "Show ABI in use by MIPS target", &showmipscmdlist);
6455 /* Let the user turn off floating point and set the fence post for
6456 heuristic_proc_start. */
6458 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6459 "Set use of MIPS floating-point coprocessor.",
6460 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6461 add_cmd ("single", class_support, set_mipsfpu_single_command,
6462 "Select single-precision MIPS floating-point coprocessor.",
6464 add_cmd ("double", class_support, set_mipsfpu_double_command,
6465 "Select double-precision MIPS floating-point coprocessor.",
6467 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6468 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6469 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6470 add_cmd ("none", class_support, set_mipsfpu_none_command,
6471 "Select no MIPS floating-point coprocessor.",
6473 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6474 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6475 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6476 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6477 "Select MIPS floating-point coprocessor automatically.",
6479 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6480 "Show current use of MIPS floating-point coprocessor target.",
6483 /* We really would like to have both "0" and "unlimited" work, but
6484 command.c doesn't deal with that. So make it a var_zinteger
6485 because the user can always use "999999" or some such for unlimited. */
6486 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6487 (char *) &heuristic_fence_post,
6489 Set the distance searched for the start of a function.\n\
6490 If you are debugging a stripped executable, GDB needs to search through the\n\
6491 program for the start of a function. This command sets the distance of the\n\
6492 search. The only need to set it is when debugging a stripped executable.",
6494 /* We need to throw away the frame cache when we set this, since it
6495 might change our ability to get backtraces. */
6496 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6497 add_show_from_set (c, &showlist);
6499 /* Allow the user to control whether the upper bits of 64-bit
6500 addresses should be zeroed. */
6501 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6502 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6503 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6504 allow GDB to determine the correct value.\n", "\
6505 Show zeroing of upper 32 bits of 64-bit addresses.",
6506 NULL, show_mask_address,
6507 &setmipscmdlist, &showmipscmdlist);
6509 /* Allow the user to control the size of 32 bit registers within the
6510 raw remote packet. */
6511 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6514 (char *)&mips64_transfers_32bit_regs_p, "\
6515 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6516 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6517 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6518 64 bits for others. Use \"off\" to disable compatibility mode",
6522 /* Debug this files internals. */
6523 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6524 &mips_debug, "Set mips debugging.\n\
6525 When non-zero, mips specific debugging is enabled.", &setdebuglist),