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 mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
354 struct frame_info *, int);
356 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
358 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
360 static int mips_set_processor_type (char *);
362 static void mips_show_processor_type_command (char *, int);
364 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
366 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
367 struct frame_info *next_frame,
370 static CORE_ADDR after_prologue (CORE_ADDR pc,
371 mips_extra_func_info_t proc_desc);
373 static struct type *mips_float_register_type (void);
374 static struct type *mips_double_register_type (void);
376 /* This value is the model of MIPS in use. It is derived from the value
377 of the PrID register. */
379 char *mips_processor_type;
381 char *tmp_mips_processor_type;
383 /* The list of available "set mips " and "show mips " commands */
385 static struct cmd_list_element *setmipscmdlist = NULL;
386 static struct cmd_list_element *showmipscmdlist = NULL;
388 /* A set of original names, to be used when restoring back to generic
389 registers from a specific set. */
390 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
392 /* Integer registers 0 thru 31 are handled explicitly by
393 mips_register_name(). Processor specific registers 32 and above
394 are listed in the sets of register names assigned to
395 mips_processor_reg_names. */
396 static char **mips_processor_reg_names = mips_generic_reg_names;
398 /* Return the name of the register corresponding to REGNO. */
400 mips_register_name (int regno)
402 /* GPR names for all ABIs other than n32/n64. */
403 static char *mips_gpr_names[] = {
404 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
405 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
406 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
407 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
410 /* GPR names for n32 and n64 ABIs. */
411 static char *mips_n32_n64_gpr_names[] = {
412 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
413 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
414 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
415 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
418 enum mips_abi abi = mips_abi (current_gdbarch);
420 /* The MIPS integer registers are always mapped from 0 to 31. The
421 names of the registers (which reflects the conventions regarding
422 register use) vary depending on the ABI. */
423 if (0 <= regno && regno < 32)
425 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
426 return mips_n32_n64_gpr_names[regno];
428 return mips_gpr_names[regno];
430 else if (32 <= regno && regno < NUM_REGS)
431 return mips_processor_reg_names[regno - 32];
433 internal_error (__FILE__, __LINE__,
434 "mips_register_name: bad register number %d", regno);
438 /* Names of IDT R3041 registers. */
440 char *mips_r3041_reg_names[] = {
441 "sr", "lo", "hi", "bad", "cause","pc",
442 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
443 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
444 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
445 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
446 "fsr", "fir", "",/*"fp"*/ "",
447 "", "", "bus", "ccfg", "", "", "", "",
448 "", "", "port", "cmp", "", "", "epc", "prid",
451 /* Names of IDT R3051 registers. */
453 char *mips_r3051_reg_names[] = {
454 "sr", "lo", "hi", "bad", "cause","pc",
455 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
456 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
457 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
458 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
459 "fsr", "fir", ""/*"fp"*/, "",
460 "inx", "rand", "elo", "", "ctxt", "", "", "",
461 "", "", "ehi", "", "", "", "epc", "prid",
464 /* Names of IDT R3081 registers. */
466 char *mips_r3081_reg_names[] = {
467 "sr", "lo", "hi", "bad", "cause","pc",
468 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
469 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
470 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
471 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
472 "fsr", "fir", ""/*"fp"*/, "",
473 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
474 "", "", "ehi", "", "", "", "epc", "prid",
477 /* Names of LSI 33k registers. */
479 char *mips_lsi33k_reg_names[] = {
480 "epc", "hi", "lo", "sr", "cause","badvaddr",
481 "dcic", "bpc", "bda", "", "", "", "", "",
482 "", "", "", "", "", "", "", "",
483 "", "", "", "", "", "", "", "",
484 "", "", "", "", "", "", "", "",
486 "", "", "", "", "", "", "", "",
487 "", "", "", "", "", "", "", "",
493 } mips_processor_type_table[] = {
494 { "generic", mips_generic_reg_names },
495 { "r3041", mips_r3041_reg_names },
496 { "r3051", mips_r3051_reg_names },
497 { "r3071", mips_r3081_reg_names },
498 { "r3081", mips_r3081_reg_names },
499 { "lsi33k", mips_lsi33k_reg_names },
507 /* Table to translate MIPS16 register field to actual register number. */
508 static int mips16_to_32_reg[8] =
509 {16, 17, 2, 3, 4, 5, 6, 7};
511 /* Heuristic_proc_start may hunt through the text section for a long
512 time across a 2400 baud serial line. Allows the user to limit this
515 static unsigned int heuristic_fence_post = 0;
517 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
518 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
519 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
520 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
521 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
522 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
523 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
524 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
525 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
526 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
527 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
528 this will corrupt pdr.iline. Fortunately we don't use it. */
529 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
530 #define _PROC_MAGIC_ 0x0F0F0F0F
531 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
532 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
534 struct linked_proc_info
536 struct mips_extra_func_info info;
537 struct linked_proc_info *next;
539 *linked_proc_desc_table = NULL;
542 mips_print_extra_frame_info (struct frame_info *fi)
545 && get_frame_extra_info (fi)
546 && get_frame_extra_info (fi)->proc_desc
547 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
548 printf_filtered (" frame pointer is at %s+%s\n",
549 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
550 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
553 /* Number of bytes of storage in the actual machine representation for
554 register N. NOTE: This indirectly defines the register size
555 transfered by the GDB protocol. */
557 static int mips64_transfers_32bit_regs_p = 0;
560 mips_register_raw_size (int reg_nr)
562 if (mips64_transfers_32bit_regs_p)
563 return REGISTER_VIRTUAL_SIZE (reg_nr);
564 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
565 && FP_REGISTER_DOUBLE)
566 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
573 /* Convert between RAW and VIRTUAL registers. The RAW register size
574 defines the remote-gdb packet. */
577 mips_register_convertible (int reg_nr)
579 if (mips64_transfers_32bit_regs_p)
582 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
586 mips_register_convert_to_virtual (int n, struct type *virtual_type,
587 char *raw_buf, char *virt_buf)
589 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
591 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
592 TYPE_LENGTH (virtual_type));
596 TYPE_LENGTH (virtual_type));
600 mips_register_convert_to_raw (struct type *virtual_type, int n,
601 char *virt_buf, char *raw_buf)
603 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
604 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
605 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
607 TYPE_LENGTH (virtual_type));
611 TYPE_LENGTH (virtual_type));
615 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
617 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
618 && REGISTER_RAW_SIZE (regnum) == 4
619 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
620 && TYPE_CODE(type) == TYPE_CODE_FLT
621 && TYPE_LENGTH(type) == 8)
624 memcpy (temp, ((char *)(buffer))+4, 4);
625 memcpy (((char *)(buffer))+4, (buffer), 4);
626 memcpy (((char *)(buffer)), temp, 4);
631 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
633 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
634 && REGISTER_RAW_SIZE (regnum) == 4
635 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
636 && TYPE_CODE(type) == TYPE_CODE_FLT
637 && TYPE_LENGTH(type) == 8)
640 memcpy (temp, ((char *)(buffer))+4, 4);
641 memcpy (((char *)(buffer))+4, (buffer), 4);
642 memcpy (((char *)(buffer)), temp, 4);
646 /* Return the GDB type object for the "standard" data type
647 of data in register REG.
649 Note: kevinb/2002-08-01: The definition below should faithfully
650 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
651 definitions found in config/mips/tm-*.h. I'm concerned about the
652 ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause though.
653 In some cases DEPRECATED_FP_REGNUM is in this range, and I doubt
654 that this code is correct for the 64-bit case. */
657 mips_register_virtual_type (int reg)
659 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
661 /* Floating point registers... */
662 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
663 return builtin_type_ieee_double_big;
665 return builtin_type_ieee_double_little;
667 else if (reg == PS_REGNUM /* CR */)
668 return builtin_type_uint32;
669 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
670 return builtin_type_uint32;
673 /* Everything else...
674 Return type appropriate for width of register. */
675 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
676 return builtin_type_uint64;
678 return builtin_type_uint32;
682 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
687 return read_signed_register (SP_REGNUM);
690 /* Should the upper word of 64-bit addresses be zeroed? */
691 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
694 mips_mask_address_p (void)
696 switch (mask_address_var)
698 case AUTO_BOOLEAN_TRUE:
700 case AUTO_BOOLEAN_FALSE:
703 case AUTO_BOOLEAN_AUTO:
704 return MIPS_DEFAULT_MASK_ADDRESS_P;
706 internal_error (__FILE__, __LINE__,
707 "mips_mask_address_p: bad switch");
713 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
715 switch (mask_address_var)
717 case AUTO_BOOLEAN_TRUE:
718 printf_filtered ("The 32 bit mips address mask is enabled\n");
720 case AUTO_BOOLEAN_FALSE:
721 printf_filtered ("The 32 bit mips address mask is disabled\n");
723 case AUTO_BOOLEAN_AUTO:
724 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
725 mips_mask_address_p () ? "enabled" : "disabled");
728 internal_error (__FILE__, __LINE__,
729 "show_mask_address: bad switch");
734 /* Should call_function allocate stack space for a struct return? */
737 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
739 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
743 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
745 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
749 mips_o32_use_struct_convention (int gcc_p, struct type *type)
751 return 1; /* Structures are returned by ref in extra arg0. */
754 /* Should call_function pass struct by reference?
755 For each architecture, structs are passed either by
756 value or by reference, depending on their size. */
759 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
761 enum type_code typecode = TYPE_CODE (check_typedef (type));
762 int len = TYPE_LENGTH (check_typedef (type));
764 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
765 return (len > MIPS_SAVED_REGSIZE);
771 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
773 return 0; /* Assumption: N32/N64 never passes struct by ref. */
777 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
779 return 0; /* Assumption: O32/O64 never passes struct by ref. */
782 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
785 pc_is_mips16 (bfd_vma memaddr)
787 struct minimal_symbol *sym;
789 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
790 if (IS_MIPS16_ADDR (memaddr))
793 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
794 the high bit of the info field. Use this to decide if the function is
795 MIPS16 or normal MIPS. */
796 sym = lookup_minimal_symbol_by_pc (memaddr);
798 return msymbol_is_special (sym);
803 /* MIPS believes that the PC has a sign extended value. Perhaphs the
804 all registers should be sign extended for simplicity? */
807 mips_read_pc (ptid_t ptid)
809 return read_signed_register_pid (PC_REGNUM, ptid);
812 /* This returns the PC of the first inst after the prologue. If we can't
813 find the prologue, then return 0. */
816 after_prologue (CORE_ADDR pc,
817 mips_extra_func_info_t proc_desc)
819 struct symtab_and_line sal;
820 CORE_ADDR func_addr, func_end;
822 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
823 to read the stack pointer from the current machine state, because
824 the current machine state has nothing to do with the information
825 we need from the proc_desc; and the process may or may not exist
828 proc_desc = find_proc_desc (pc, NULL, 0);
832 /* If function is frameless, then we need to do it the hard way. I
833 strongly suspect that frameless always means prologueless... */
834 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
835 && PROC_FRAME_OFFSET (proc_desc) == 0)
839 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
840 return 0; /* Unknown */
842 sal = find_pc_line (func_addr, 0);
844 if (sal.end < func_end)
847 /* The line after the prologue is after the end of the function. In this
848 case, tell the caller to find the prologue the hard way. */
853 /* Decode a MIPS32 instruction that saves a register in the stack, and
854 set the appropriate bit in the general register mask or float register mask
855 to indicate which register is saved. This is a helper function
856 for mips_find_saved_regs. */
859 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
860 unsigned long *float_mask)
864 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
865 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
866 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
868 /* It might be possible to use the instruction to
869 find the offset, rather than the code below which
870 is based on things being in a certain order in the
871 frame, but figuring out what the instruction's offset
872 is relative to might be a little tricky. */
873 reg = (inst & 0x001f0000) >> 16;
874 *gen_mask |= (1 << reg);
876 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
877 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
878 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
881 reg = ((inst & 0x001f0000) >> 16);
882 *float_mask |= (1 << reg);
886 /* Decode a MIPS16 instruction that saves a register in the stack, and
887 set the appropriate bit in the general register or float register mask
888 to indicate which register is saved. This is a helper function
889 for mips_find_saved_regs. */
892 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
894 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
896 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
897 *gen_mask |= (1 << reg);
899 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
901 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
902 *gen_mask |= (1 << reg);
904 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
905 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
906 *gen_mask |= (1 << RA_REGNUM);
910 /* Fetch and return instruction from the specified location. If the PC
911 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
914 mips_fetch_instruction (CORE_ADDR addr)
916 char buf[MIPS_INSTLEN];
920 if (pc_is_mips16 (addr))
922 instlen = MIPS16_INSTLEN;
923 addr = UNMAKE_MIPS16_ADDR (addr);
926 instlen = MIPS_INSTLEN;
927 status = read_memory_nobpt (addr, buf, instlen);
929 memory_error (status, addr);
930 return extract_unsigned_integer (buf, instlen);
934 /* These the fields of 32 bit mips instructions */
935 #define mips32_op(x) (x >> 26)
936 #define itype_op(x) (x >> 26)
937 #define itype_rs(x) ((x >> 21) & 0x1f)
938 #define itype_rt(x) ((x >> 16) & 0x1f)
939 #define itype_immediate(x) (x & 0xffff)
941 #define jtype_op(x) (x >> 26)
942 #define jtype_target(x) (x & 0x03ffffff)
944 #define rtype_op(x) (x >> 26)
945 #define rtype_rs(x) ((x >> 21) & 0x1f)
946 #define rtype_rt(x) ((x >> 16) & 0x1f)
947 #define rtype_rd(x) ((x >> 11) & 0x1f)
948 #define rtype_shamt(x) ((x >> 6) & 0x1f)
949 #define rtype_funct(x) (x & 0x3f)
952 mips32_relative_offset (unsigned long inst)
955 x = itype_immediate (inst);
956 if (x & 0x8000) /* sign bit set */
958 x |= 0xffff0000; /* sign extension */
964 /* Determine whate to set a single step breakpoint while considering
967 mips32_next_pc (CORE_ADDR pc)
971 inst = mips_fetch_instruction (pc);
972 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
974 if (itype_op (inst) >> 2 == 5)
975 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
977 op = (itype_op (inst) & 0x03);
992 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
993 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
995 int tf = itype_rt (inst) & 0x01;
996 int cnum = itype_rt (inst) >> 2;
997 int fcrcs = read_signed_register (FCRCS_REGNUM);
998 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1000 if (((cond >> cnum) & 0x01) == tf)
1001 pc += mips32_relative_offset (inst) + 4;
1006 pc += 4; /* Not a branch, next instruction is easy */
1009 { /* This gets way messy */
1011 /* Further subdivide into SPECIAL, REGIMM and other */
1012 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
1014 case 0: /* SPECIAL */
1015 op = rtype_funct (inst);
1020 /* Set PC to that address */
1021 pc = read_signed_register (rtype_rs (inst));
1027 break; /* end SPECIAL */
1028 case 1: /* REGIMM */
1030 op = itype_rt (inst); /* branch condition */
1035 case 16: /* BLTZAL */
1036 case 18: /* BLTZALL */
1038 if (read_signed_register (itype_rs (inst)) < 0)
1039 pc += mips32_relative_offset (inst) + 4;
1041 pc += 8; /* after the delay slot */
1045 case 17: /* BGEZAL */
1046 case 19: /* BGEZALL */
1047 greater_equal_branch:
1048 if (read_signed_register (itype_rs (inst)) >= 0)
1049 pc += mips32_relative_offset (inst) + 4;
1051 pc += 8; /* after the delay slot */
1053 /* All of the other instructions in the REGIMM category */
1058 break; /* end REGIMM */
1063 reg = jtype_target (inst) << 2;
1064 /* Upper four bits get never changed... */
1065 pc = reg + ((pc + 4) & 0xf0000000);
1068 /* FIXME case JALX : */
1071 reg = jtype_target (inst) << 2;
1072 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1073 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1075 break; /* The new PC will be alternate mode */
1076 case 4: /* BEQ, BEQL */
1078 if (read_signed_register (itype_rs (inst)) ==
1079 read_signed_register (itype_rt (inst)))
1080 pc += mips32_relative_offset (inst) + 4;
1084 case 5: /* BNE, BNEL */
1086 if (read_signed_register (itype_rs (inst)) !=
1087 read_signed_register (itype_rt (inst)))
1088 pc += mips32_relative_offset (inst) + 4;
1092 case 6: /* BLEZ, BLEZL */
1094 if (read_signed_register (itype_rs (inst) <= 0))
1095 pc += mips32_relative_offset (inst) + 4;
1101 greater_branch: /* BGTZ, BGTZL */
1102 if (read_signed_register (itype_rs (inst) > 0))
1103 pc += mips32_relative_offset (inst) + 4;
1110 } /* mips32_next_pc */
1112 /* Decoding the next place to set a breakpoint is irregular for the
1113 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1114 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1115 We dont want to set a single step instruction on the extend instruction
1119 /* Lots of mips16 instruction formats */
1120 /* Predicting jumps requires itype,ritype,i8type
1121 and their extensions extItype,extritype,extI8type
1123 enum mips16_inst_fmts
1125 itype, /* 0 immediate 5,10 */
1126 ritype, /* 1 5,3,8 */
1127 rrtype, /* 2 5,3,3,5 */
1128 rritype, /* 3 5,3,3,5 */
1129 rrrtype, /* 4 5,3,3,3,2 */
1130 rriatype, /* 5 5,3,3,1,4 */
1131 shifttype, /* 6 5,3,3,3,2 */
1132 i8type, /* 7 5,3,8 */
1133 i8movtype, /* 8 5,3,3,5 */
1134 i8mov32rtype, /* 9 5,3,5,3 */
1135 i64type, /* 10 5,3,8 */
1136 ri64type, /* 11 5,3,3,5 */
1137 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1138 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1139 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1140 extRRItype, /* 15 5,5,5,5,3,3,5 */
1141 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1142 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1143 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1144 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1145 extRi64type, /* 20 5,6,5,5,3,3,5 */
1146 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1148 /* I am heaping all the fields of the formats into one structure and
1149 then, only the fields which are involved in instruction extension */
1153 unsigned int regx; /* Function in i8 type */
1158 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1159 for the bits which make up the immediatate extension. */
1162 extended_offset (unsigned int extension)
1165 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1167 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1169 value |= extension & 0x01f; /* extract 4:0 */
1173 /* Only call this function if you know that this is an extendable
1174 instruction, It wont malfunction, but why make excess remote memory references?
1175 If the immediate operands get sign extended or somthing, do it after
1176 the extension is performed.
1178 /* FIXME: Every one of these cases needs to worry about sign extension
1179 when the offset is to be used in relative addressing */
1183 fetch_mips_16 (CORE_ADDR pc)
1186 pc &= 0xfffffffe; /* clear the low order bit */
1187 target_read_memory (pc, buf, 2);
1188 return extract_unsigned_integer (buf, 2);
1192 unpack_mips16 (CORE_ADDR pc,
1193 unsigned int extension,
1195 enum mips16_inst_fmts insn_format,
1196 struct upk_mips16 *upk)
1201 switch (insn_format)
1208 value = extended_offset (extension);
1209 value = value << 11; /* rom for the original value */
1210 value |= inst & 0x7ff; /* eleven bits from instruction */
1214 value = inst & 0x7ff;
1215 /* FIXME : Consider sign extension */
1224 { /* A register identifier and an offset */
1225 /* Most of the fields are the same as I type but the
1226 immediate value is of a different length */
1230 value = extended_offset (extension);
1231 value = value << 8; /* from the original instruction */
1232 value |= inst & 0xff; /* eleven bits from instruction */
1233 regx = (extension >> 8) & 0x07; /* or i8 funct */
1234 if (value & 0x4000) /* test the sign bit , bit 26 */
1236 value &= ~0x3fff; /* remove the sign bit */
1242 value = inst & 0xff; /* 8 bits */
1243 regx = (inst >> 8) & 0x07; /* or i8 funct */
1244 /* FIXME: Do sign extension , this format needs it */
1245 if (value & 0x80) /* THIS CONFUSES ME */
1247 value &= 0xef; /* remove the sign bit */
1257 unsigned long value;
1258 unsigned int nexthalf;
1259 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1260 value = value << 16;
1261 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1269 internal_error (__FILE__, __LINE__,
1272 upk->offset = offset;
1279 add_offset_16 (CORE_ADDR pc, int offset)
1281 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1285 extended_mips16_next_pc (CORE_ADDR pc,
1286 unsigned int extension,
1289 int op = (insn >> 11);
1292 case 2: /* Branch */
1295 struct upk_mips16 upk;
1296 unpack_mips16 (pc, extension, insn, itype, &upk);
1297 offset = upk.offset;
1303 pc += (offset << 1) + 2;
1306 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1308 struct upk_mips16 upk;
1309 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1310 pc = add_offset_16 (pc, upk.offset);
1311 if ((insn >> 10) & 0x01) /* Exchange mode */
1312 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1319 struct upk_mips16 upk;
1321 unpack_mips16 (pc, extension, insn, ritype, &upk);
1322 reg = read_signed_register (upk.regx);
1324 pc += (upk.offset << 1) + 2;
1331 struct upk_mips16 upk;
1333 unpack_mips16 (pc, extension, insn, ritype, &upk);
1334 reg = read_signed_register (upk.regx);
1336 pc += (upk.offset << 1) + 2;
1341 case 12: /* I8 Formats btez btnez */
1343 struct upk_mips16 upk;
1345 unpack_mips16 (pc, extension, insn, i8type, &upk);
1346 /* upk.regx contains the opcode */
1347 reg = read_signed_register (24); /* Test register is 24 */
1348 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1349 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1350 /* pc = add_offset_16(pc,upk.offset) ; */
1351 pc += (upk.offset << 1) + 2;
1356 case 29: /* RR Formats JR, JALR, JALR-RA */
1358 struct upk_mips16 upk;
1359 /* upk.fmt = rrtype; */
1364 upk.regx = (insn >> 8) & 0x07;
1365 upk.regy = (insn >> 5) & 0x07;
1373 break; /* Function return instruction */
1379 break; /* BOGUS Guess */
1381 pc = read_signed_register (reg);
1388 /* This is an instruction extension. Fetch the real instruction
1389 (which follows the extension) and decode things based on
1393 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1406 mips16_next_pc (CORE_ADDR pc)
1408 unsigned int insn = fetch_mips_16 (pc);
1409 return extended_mips16_next_pc (pc, 0, insn);
1412 /* The mips_next_pc function supports single_step when the remote
1413 target monitor or stub is not developed enough to do a single_step.
1414 It works by decoding the current instruction and predicting where a
1415 branch will go. This isnt hard because all the data is available.
1416 The MIPS32 and MIPS16 variants are quite different */
1418 mips_next_pc (CORE_ADDR pc)
1421 return mips16_next_pc (pc);
1423 return mips32_next_pc (pc);
1426 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1429 Note: kevinb/2002-08-09: The only caller of this function is (and
1430 should remain) mips_frame_init_saved_regs(). In fact,
1431 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1432 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1433 functions should really be combined and now that there is only one
1434 caller, it should be straightforward. (Watch out for multiple returns
1438 mips_find_saved_regs (struct frame_info *fci)
1441 CORE_ADDR reg_position;
1442 /* r0 bit means kernel trap */
1444 /* What registers have been saved? Bitmasks. */
1445 unsigned long gen_mask, float_mask;
1446 mips_extra_func_info_t proc_desc;
1449 frame_saved_regs_zalloc (fci);
1451 /* If it is the frame for sigtramp, the saved registers are located
1452 in a sigcontext structure somewhere on the stack.
1453 If the stack layout for sigtramp changes we might have to change these
1454 constants and the companion fixup_sigtramp in mdebugread.c */
1455 #ifndef SIGFRAME_BASE
1456 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1457 above the sigtramp frame. */
1458 #define SIGFRAME_BASE MIPS_REGSIZE
1459 /* FIXME! Are these correct?? */
1460 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1461 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1462 #define SIGFRAME_FPREGSAVE_OFF \
1463 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1465 #ifndef SIGFRAME_REG_SIZE
1466 /* FIXME! Is this correct?? */
1467 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1469 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1471 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1473 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1474 + ireg * SIGFRAME_REG_SIZE;
1475 get_frame_saved_regs (fci)[ireg] = reg_position;
1477 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1479 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1480 + ireg * SIGFRAME_REG_SIZE;
1481 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1483 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1487 proc_desc = get_frame_extra_info (fci)->proc_desc;
1488 if (proc_desc == NULL)
1489 /* I'm not sure how/whether this can happen. Normally when we can't
1490 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1491 and set the saved_regs right away. */
1494 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1495 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1496 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1498 if ( /* In any frame other than the innermost or a frame interrupted by
1499 a signal, we assume that all registers have been saved.
1500 This assumes that all register saves in a function happen before
1501 the first function call. */
1502 (get_next_frame (fci) == NULL
1503 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1505 /* In a dummy frame we know exactly where things are saved. */
1506 && !PROC_DESC_IS_DUMMY (proc_desc)
1508 /* Don't bother unless we are inside a function prologue. Outside the
1509 prologue, we know where everything is. */
1511 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1513 /* Not sure exactly what kernel_trap means, but if it means
1514 the kernel saves the registers without a prologue doing it,
1515 we better not examine the prologue to see whether registers
1516 have been saved yet. */
1519 /* We need to figure out whether the registers that the proc_desc
1520 claims are saved have been saved yet. */
1524 /* Bitmasks; set if we have found a save for the register. */
1525 unsigned long gen_save_found = 0;
1526 unsigned long float_save_found = 0;
1529 /* If the address is odd, assume this is MIPS16 code. */
1530 addr = PROC_LOW_ADDR (proc_desc);
1531 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1533 /* Scan through this function's instructions preceding the current
1534 PC, and look for those that save registers. */
1535 while (addr < get_frame_pc (fci))
1537 inst = mips_fetch_instruction (addr);
1538 if (pc_is_mips16 (addr))
1539 mips16_decode_reg_save (inst, &gen_save_found);
1541 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1544 gen_mask = gen_save_found;
1545 float_mask = float_save_found;
1548 /* Fill in the offsets for the registers which gen_mask says
1550 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1551 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1552 if (gen_mask & 0x80000000)
1554 get_frame_saved_regs (fci)[ireg] = reg_position;
1555 reg_position -= MIPS_SAVED_REGSIZE;
1558 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1559 of that normally used by gcc. Therefore, we have to fetch the first
1560 instruction of the function, and if it's an entry instruction that
1561 saves $s0 or $s1, correct their saved addresses. */
1562 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1564 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1565 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1568 int sreg_count = (inst >> 6) & 3;
1570 /* Check if the ra register was pushed on the stack. */
1571 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1573 reg_position -= MIPS_SAVED_REGSIZE;
1575 /* Check if the s0 and s1 registers were pushed on the stack. */
1576 for (reg = 16; reg < sreg_count + 16; reg++)
1578 get_frame_saved_regs (fci)[reg] = reg_position;
1579 reg_position -= MIPS_SAVED_REGSIZE;
1584 /* Fill in the offsets for the registers which float_mask says
1586 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1588 /* Apparently, the freg_offset gives the offset to the first 64 bit
1591 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1592 designates the first saved 64 bit register.
1594 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1595 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1596 FREG_OFFSET, designates the address of the lower register of the
1597 register pair. Adjust the offset so that it designates the upper
1598 register of the pair -- i.e., the address of the first saved 32
1601 if (MIPS_SAVED_REGSIZE == 4)
1602 reg_position += MIPS_SAVED_REGSIZE;
1604 /* Fill in the offsets for the float registers which float_mask says
1606 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1607 if (float_mask & 0x80000000)
1609 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1610 reg_position -= MIPS_SAVED_REGSIZE;
1613 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1616 /* Set up the 'saved_regs' array. This is a data structure containing
1617 the addresses on the stack where each register has been saved, for
1618 each stack frame. Registers that have not been saved will have
1619 zero here. The stack pointer register is special: rather than the
1620 address where the stack register has been saved, saved_regs[SP_REGNUM]
1621 will have the actual value of the previous frame's stack register. */
1624 mips_frame_init_saved_regs (struct frame_info *frame)
1626 if (get_frame_saved_regs (frame) == NULL)
1628 mips_find_saved_regs (frame);
1630 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1634 read_next_frame_reg (struct frame_info *fi, int regno)
1639 enum lval_type lval;
1640 char raw_buffer[MAX_REGISTER_SIZE];
1644 regcache_cooked_read (current_regcache, regno, raw_buffer);
1648 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1650 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1651 should have a pseudo register range that correspons to the ABI's,
1652 rather than the ISA's, view of registers. These registers would
1653 then implicitly describe their size and hence could be used
1654 without the below munging. */
1655 if (lval == lval_memory)
1659 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1661 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1666 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1669 /* mips_addr_bits_remove - remove useless address bits */
1672 mips_addr_bits_remove (CORE_ADDR addr)
1674 if (GDB_TARGET_IS_MIPS64)
1676 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1678 /* This hack is a work-around for existing boards using
1679 PMON, the simulator, and any other 64-bit targets that
1680 doesn't have true 64-bit addressing. On these targets,
1681 the upper 32 bits of addresses are ignored by the
1682 hardware. Thus, the PC or SP are likely to have been
1683 sign extended to all 1s by instruction sequences that
1684 load 32-bit addresses. For example, a typical piece of
1685 code that loads an address is this:
1686 lui $r2, <upper 16 bits>
1687 ori $r2, <lower 16 bits>
1688 But the lui sign-extends the value such that the upper 32
1689 bits may be all 1s. The workaround is simply to mask off
1690 these bits. In the future, gcc may be changed to support
1691 true 64-bit addressing, and this masking will have to be
1693 addr &= (CORE_ADDR) 0xffffffff;
1696 else if (mips_mask_address_p ())
1698 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1699 masking off bits, instead, the actual target should be asking
1700 for the address to be converted to a valid pointer. */
1701 /* Even when GDB is configured for some 32-bit targets
1702 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1703 so CORE_ADDR is 64 bits. So we still have to mask off
1704 useless bits from addresses. */
1705 addr &= (CORE_ADDR) 0xffffffff;
1710 /* mips_software_single_step() is called just before we want to resume
1711 the inferior, if we want to single-step it but there is no hardware
1712 or kernel single-step support (MIPS on GNU/Linux for example). We find
1713 the target of the coming instruction and breakpoint it.
1715 single_step is also called just after the inferior stops. If we had
1716 set up a simulated single-step, we undo our damage. */
1719 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1721 static CORE_ADDR next_pc;
1722 typedef char binsn_quantum[BREAKPOINT_MAX];
1723 static binsn_quantum break_mem;
1726 if (insert_breakpoints_p)
1728 pc = read_register (PC_REGNUM);
1729 next_pc = mips_next_pc (pc);
1731 target_insert_breakpoint (next_pc, break_mem);
1734 target_remove_breakpoint (next_pc, break_mem);
1738 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1743 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1744 : get_next_frame (prev)
1745 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1747 tmp = SKIP_TRAMPOLINE_CODE (pc);
1748 return tmp ? tmp : pc;
1753 mips_frame_saved_pc (struct frame_info *frame)
1756 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1757 /* We have to get the saved pc from the sigcontext
1758 if it is a signal handler frame. */
1759 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1760 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1762 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1765 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1768 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1769 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1771 saved_pc = read_next_frame_reg (frame, pcreg);
1773 return ADDR_BITS_REMOVE (saved_pc);
1776 static struct mips_extra_func_info temp_proc_desc;
1778 /* This hack will go away once the get_prev_frame() code has been
1779 modified to set the frame's type first. That is BEFORE init extra
1780 frame info et.al. is called. This is because it will become
1781 possible to skip the init extra info call for sigtramp and dummy
1783 static CORE_ADDR *temp_saved_regs;
1785 /* Set a register's saved stack address in temp_saved_regs. If an address
1786 has already been set for this register, do nothing; this way we will
1787 only recognize the first save of a given register in a function prologue.
1788 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1791 set_reg_offset (int regno, CORE_ADDR offset)
1793 if (temp_saved_regs[regno] == 0)
1794 temp_saved_regs[regno] = offset;
1798 /* Test whether the PC points to the return instruction at the
1799 end of a function. */
1802 mips_about_to_return (CORE_ADDR pc)
1804 if (pc_is_mips16 (pc))
1805 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1806 generates a "jr $ra"; other times it generates code to load
1807 the return address from the stack to an accessible register (such
1808 as $a3), then a "jr" using that register. This second case
1809 is almost impossible to distinguish from an indirect jump
1810 used for switch statements, so we don't even try. */
1811 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1813 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1817 /* This fencepost looks highly suspicious to me. Removing it also
1818 seems suspicious as it could affect remote debugging across serial
1822 heuristic_proc_start (CORE_ADDR pc)
1829 pc = ADDR_BITS_REMOVE (pc);
1831 fence = start_pc - heuristic_fence_post;
1835 if (heuristic_fence_post == UINT_MAX
1836 || fence < VM_MIN_ADDRESS)
1837 fence = VM_MIN_ADDRESS;
1839 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1841 /* search back for previous return */
1842 for (start_pc -= instlen;; start_pc -= instlen)
1843 if (start_pc < fence)
1845 /* It's not clear to me why we reach this point when
1846 stop_soon, but with this test, at least we
1847 don't print out warnings for every child forked (eg, on
1849 if (stop_soon == NO_STOP_QUIETLY)
1851 static int blurb_printed = 0;
1853 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1858 /* This actually happens frequently in embedded
1859 development, when you first connect to a board
1860 and your stack pointer and pc are nowhere in
1861 particular. This message needs to give people
1862 in that situation enough information to
1863 determine that it's no big deal. */
1864 printf_filtered ("\n\
1865 GDB is unable to find the start of the function at 0x%s\n\
1866 and thus can't determine the size of that function's stack frame.\n\
1867 This means that GDB may be unable to access that stack frame, or\n\
1868 the frames below it.\n\
1869 This problem is most likely caused by an invalid program counter or\n\
1871 However, if you think GDB should simply search farther back\n\
1872 from 0x%s for code which looks like the beginning of a\n\
1873 function, you can increase the range of the search using the `set\n\
1874 heuristic-fence-post' command.\n",
1875 paddr_nz (pc), paddr_nz (pc));
1882 else if (pc_is_mips16 (start_pc))
1884 unsigned short inst;
1886 /* On MIPS16, any one of the following is likely to be the
1887 start of a function:
1891 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1892 inst = mips_fetch_instruction (start_pc);
1893 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1894 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1895 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1896 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1898 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1899 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1904 else if (mips_about_to_return (start_pc))
1906 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1913 /* Fetch the immediate value from a MIPS16 instruction.
1914 If the previous instruction was an EXTEND, use it to extend
1915 the upper bits of the immediate value. This is a helper function
1916 for mips16_heuristic_proc_desc. */
1919 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1920 unsigned short inst, /* current instruction */
1921 int nbits, /* number of bits in imm field */
1922 int scale, /* scale factor to be applied to imm */
1923 int is_signed) /* is the imm field signed? */
1927 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1929 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1930 if (offset & 0x8000) /* check for negative extend */
1931 offset = 0 - (0x10000 - (offset & 0xffff));
1932 return offset | (inst & 0x1f);
1936 int max_imm = 1 << nbits;
1937 int mask = max_imm - 1;
1938 int sign_bit = max_imm >> 1;
1940 offset = inst & mask;
1941 if (is_signed && (offset & sign_bit))
1942 offset = 0 - (max_imm - offset);
1943 return offset * scale;
1948 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1949 stream from start_pc to limit_pc. */
1952 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1953 struct frame_info *next_frame, CORE_ADDR sp)
1956 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1957 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1958 unsigned inst = 0; /* current instruction */
1959 unsigned entry_inst = 0; /* the entry instruction */
1962 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1963 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1965 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1967 /* Save the previous instruction. If it's an EXTEND, we'll extract
1968 the immediate offset extension from it in mips16_get_imm. */
1971 /* Fetch and decode the instruction. */
1972 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1973 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1974 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1976 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1977 if (offset < 0) /* negative stack adjustment? */
1978 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1980 /* Exit loop if a positive stack adjustment is found, which
1981 usually means that the stack cleanup code in the function
1982 epilogue is reached. */
1985 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1987 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1988 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1989 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1990 set_reg_offset (reg, sp + offset);
1992 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1994 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1995 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1996 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1997 set_reg_offset (reg, sp + offset);
1999 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2001 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2002 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2003 set_reg_offset (RA_REGNUM, sp + offset);
2005 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2007 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2008 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2009 set_reg_offset (RA_REGNUM, sp + offset);
2011 else if (inst == 0x673d) /* move $s1, $sp */
2014 PROC_FRAME_REG (&temp_proc_desc) = 17;
2016 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2018 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2019 frame_addr = sp + offset;
2020 PROC_FRAME_REG (&temp_proc_desc) = 17;
2021 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2023 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2025 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2026 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2027 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2028 set_reg_offset (reg, frame_addr + offset);
2030 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2032 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2033 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2034 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2035 set_reg_offset (reg, frame_addr + offset);
2037 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2038 entry_inst = inst; /* save for later processing */
2039 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2040 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2043 /* The entry instruction is typically the first instruction in a function,
2044 and it stores registers at offsets relative to the value of the old SP
2045 (before the prologue). But the value of the sp parameter to this
2046 function is the new SP (after the prologue has been executed). So we
2047 can't calculate those offsets until we've seen the entire prologue,
2048 and can calculate what the old SP must have been. */
2049 if (entry_inst != 0)
2051 int areg_count = (entry_inst >> 8) & 7;
2052 int sreg_count = (entry_inst >> 6) & 3;
2054 /* The entry instruction always subtracts 32 from the SP. */
2055 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2057 /* Now we can calculate what the SP must have been at the
2058 start of the function prologue. */
2059 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2061 /* Check if a0-a3 were saved in the caller's argument save area. */
2062 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2064 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2065 set_reg_offset (reg, sp + offset);
2066 offset += MIPS_SAVED_REGSIZE;
2069 /* Check if the ra register was pushed on the stack. */
2071 if (entry_inst & 0x20)
2073 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2074 set_reg_offset (RA_REGNUM, sp + offset);
2075 offset -= MIPS_SAVED_REGSIZE;
2078 /* Check if the s0 and s1 registers were pushed on the stack. */
2079 for (reg = 16; reg < sreg_count + 16; reg++)
2081 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2082 set_reg_offset (reg, sp + offset);
2083 offset -= MIPS_SAVED_REGSIZE;
2089 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2090 struct frame_info *next_frame, CORE_ADDR sp)
2093 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2095 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2096 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2097 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2098 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2099 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2101 unsigned long inst, high_word, low_word;
2104 /* Fetch the instruction. */
2105 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2107 /* Save some code by pre-extracting some useful fields. */
2108 high_word = (inst >> 16) & 0xffff;
2109 low_word = inst & 0xffff;
2110 reg = high_word & 0x1f;
2112 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2113 || high_word == 0x23bd /* addi $sp,$sp,-i */
2114 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2116 if (low_word & 0x8000) /* negative stack adjustment? */
2117 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2119 /* Exit loop if a positive stack adjustment is found, which
2120 usually means that the stack cleanup code in the function
2121 epilogue is reached. */
2124 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2126 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2127 set_reg_offset (reg, sp + low_word);
2129 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2131 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2132 but the register size used is only 32 bits. Make the address
2133 for the saved register point to the lower 32 bits. */
2134 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2135 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2137 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2139 /* Old gcc frame, r30 is virtual frame pointer. */
2140 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2141 frame_addr = sp + low_word;
2142 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2144 unsigned alloca_adjust;
2145 PROC_FRAME_REG (&temp_proc_desc) = 30;
2146 frame_addr = read_next_frame_reg (next_frame, 30);
2147 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2148 if (alloca_adjust > 0)
2150 /* FP > SP + frame_size. This may be because
2151 * of an alloca or somethings similar.
2152 * Fix sp to "pre-alloca" value, and try again.
2154 sp += alloca_adjust;
2159 /* move $30,$sp. With different versions of gas this will be either
2160 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2161 Accept any one of these. */
2162 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2164 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2165 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2167 unsigned alloca_adjust;
2168 PROC_FRAME_REG (&temp_proc_desc) = 30;
2169 frame_addr = read_next_frame_reg (next_frame, 30);
2170 alloca_adjust = (unsigned) (frame_addr - sp);
2171 if (alloca_adjust > 0)
2173 /* FP > SP + frame_size. This may be because
2174 * of an alloca or somethings similar.
2175 * Fix sp to "pre-alloca" value, and try again.
2177 sp += alloca_adjust;
2182 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2184 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2185 set_reg_offset (reg, frame_addr + low_word);
2190 static mips_extra_func_info_t
2191 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2192 struct frame_info *next_frame, int cur_frame)
2197 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2203 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2204 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2205 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2206 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2207 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2208 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2210 if (start_pc + 200 < limit_pc)
2211 limit_pc = start_pc + 200;
2212 if (pc_is_mips16 (start_pc))
2213 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2215 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2216 return &temp_proc_desc;
2219 struct mips_objfile_private
2225 /* Global used to communicate between non_heuristic_proc_desc and
2226 compare_pdr_entries within qsort (). */
2227 static bfd *the_bfd;
2230 compare_pdr_entries (const void *a, const void *b)
2232 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2233 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2237 else if (lhs == rhs)
2243 static mips_extra_func_info_t
2244 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2246 CORE_ADDR startaddr;
2247 mips_extra_func_info_t proc_desc;
2248 struct block *b = block_for_pc (pc);
2250 struct obj_section *sec;
2251 struct mips_objfile_private *priv;
2253 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2256 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2258 *addrptr = startaddr;
2262 sec = find_pc_section (pc);
2265 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2267 /* Search the ".pdr" section generated by GAS. This includes most of
2268 the information normally found in ECOFF PDRs. */
2270 the_bfd = sec->objfile->obfd;
2272 && (the_bfd->format == bfd_object
2273 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2274 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2276 /* Right now GAS only outputs the address as a four-byte sequence.
2277 This means that we should not bother with this method on 64-bit
2278 targets (until that is fixed). */
2280 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2281 sizeof (struct mips_objfile_private));
2283 sec->objfile->obj_private = priv;
2285 else if (priv == NULL)
2289 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2290 sizeof (struct mips_objfile_private));
2292 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2295 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2296 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2298 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2299 priv->contents, 0, priv->size);
2301 /* In general, the .pdr section is sorted. However, in the
2302 presence of multiple code sections (and other corner cases)
2303 it can become unsorted. Sort it so that we can use a faster
2305 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2310 sec->objfile->obj_private = priv;
2314 if (priv->size != 0)
2320 high = priv->size / 32;
2326 mid = (low + high) / 2;
2328 ptr = priv->contents + mid * 32;
2329 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2330 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2331 SECT_OFF_TEXT (sec->objfile));
2332 if (pdr_pc == startaddr)
2334 if (pdr_pc > startaddr)
2339 while (low != high);
2343 struct symbol *sym = find_pc_function (pc);
2345 /* Fill in what we need of the proc_desc. */
2346 proc_desc = (mips_extra_func_info_t)
2347 obstack_alloc (&sec->objfile->psymbol_obstack,
2348 sizeof (struct mips_extra_func_info));
2349 PROC_LOW_ADDR (proc_desc) = startaddr;
2351 /* Only used for dummy frames. */
2352 PROC_HIGH_ADDR (proc_desc) = 0;
2354 PROC_FRAME_OFFSET (proc_desc)
2355 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2356 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2358 PROC_FRAME_ADJUST (proc_desc) = 0;
2359 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2361 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2363 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2365 PROC_FREG_OFFSET (proc_desc)
2366 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2367 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2369 proc_desc->pdr.isym = (long) sym;
2379 if (startaddr > BLOCK_START (b))
2381 /* This is the "pathological" case referred to in a comment in
2382 print_frame_info. It might be better to move this check into
2387 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
2389 /* If we never found a PDR for this function in symbol reading, then
2390 examine prologues to find the information. */
2393 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2394 if (PROC_FRAME_REG (proc_desc) == -1)
2404 static mips_extra_func_info_t
2405 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2407 mips_extra_func_info_t proc_desc;
2408 CORE_ADDR startaddr = 0;
2410 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2414 /* IF this is the topmost frame AND
2415 * (this proc does not have debugging information OR
2416 * the PC is in the procedure prologue)
2417 * THEN create a "heuristic" proc_desc (by analyzing
2418 * the actual code) to replace the "official" proc_desc.
2420 if (next_frame == NULL)
2422 struct symtab_and_line val;
2423 struct symbol *proc_symbol =
2424 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2428 val = find_pc_line (BLOCK_START
2429 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2431 val.pc = val.end ? val.end : pc;
2433 if (!proc_symbol || pc < val.pc)
2435 mips_extra_func_info_t found_heuristic =
2436 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2437 pc, next_frame, cur_frame);
2438 if (found_heuristic)
2439 proc_desc = found_heuristic;
2445 /* Is linked_proc_desc_table really necessary? It only seems to be used
2446 by procedure call dummys. However, the procedures being called ought
2447 to have their own proc_descs, and even if they don't,
2448 heuristic_proc_desc knows how to create them! */
2450 register struct linked_proc_info *link;
2452 for (link = linked_proc_desc_table; link; link = link->next)
2453 if (PROC_LOW_ADDR (&link->info) <= pc
2454 && PROC_HIGH_ADDR (&link->info) > pc)
2458 startaddr = heuristic_proc_start (pc);
2461 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2467 get_frame_pointer (struct frame_info *frame,
2468 mips_extra_func_info_t proc_desc)
2470 return (read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
2471 + PROC_FRAME_OFFSET (proc_desc)
2472 - PROC_FRAME_ADJUST (proc_desc));
2475 static mips_extra_func_info_t cached_proc_desc;
2478 mips_frame_chain (struct frame_info *frame)
2480 mips_extra_func_info_t proc_desc;
2482 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2484 if (saved_pc == 0 || inside_entry_file (saved_pc))
2487 /* Check if the PC is inside a call stub. If it is, fetch the
2488 PC of the caller of that stub. */
2489 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2492 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2494 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2495 is well, frame->frame the bottom of the current frame will
2496 contain that value. */
2497 return get_frame_base (frame);
2500 /* Look up the procedure descriptor for this PC. */
2501 proc_desc = find_proc_desc (saved_pc, frame, 1);
2505 cached_proc_desc = proc_desc;
2507 /* If no frame pointer and frame size is zero, we must be at end
2508 of stack (or otherwise hosed). If we don't check frame size,
2509 we loop forever if we see a zero size frame. */
2510 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2511 && PROC_FRAME_OFFSET (proc_desc) == 0
2512 /* The previous frame from a sigtramp frame might be frameless
2513 and have frame size zero. */
2514 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2515 /* For a generic dummy frame, let get_frame_pointer() unwind a
2516 register value saved as part of the dummy frame call. */
2517 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2520 return get_frame_pointer (frame, proc_desc);
2524 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2527 mips_extra_func_info_t proc_desc;
2529 if (get_frame_type (fci) == DUMMY_FRAME)
2532 /* Use proc_desc calculated in frame_chain. When there is no
2533 next frame, i.e, get_next_frame (fci) == NULL, we call
2534 find_proc_desc () to calculate it, passing an explicit
2535 NULL as the frame parameter. */
2537 get_next_frame (fci)
2539 : find_proc_desc (get_frame_pc (fci),
2540 NULL /* i.e, get_next_frame (fci) */,
2543 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2545 deprecated_set_frame_saved_regs_hack (fci, NULL);
2546 get_frame_extra_info (fci)->proc_desc =
2547 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2550 /* Fixup frame-pointer - only needed for top frame */
2551 /* This may not be quite right, if proc has a real frame register.
2552 Get the value of the frame relative sp, procedure might have been
2553 interrupted by a signal at it's very start. */
2554 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2555 && !PROC_DESC_IS_DUMMY (proc_desc))
2556 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2557 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2558 /* Do not ``fix'' fci->frame. It will have the value of the
2559 generic dummy frame's top-of-stack (since the draft
2560 fci->frame is obtained by returning the unwound stack
2561 pointer) and that is what we want. That way the fci->frame
2562 value will match the top-of-stack value that was saved as
2563 part of the dummy frames data. */
2566 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2568 if (proc_desc == &temp_proc_desc)
2572 /* Do not set the saved registers for a sigtramp frame,
2573 mips_find_saved_registers will do that for us. We can't
2574 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2576 /* FIXME: cagney/2002-11-18: This problem will go away once
2577 frame.c:get_prev_frame() is modified to set the frame's
2578 type before calling functions like this. */
2579 find_pc_partial_function (get_frame_pc (fci), &name,
2580 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2581 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2583 frame_saved_regs_zalloc (fci);
2584 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2585 get_frame_saved_regs (fci)[PC_REGNUM]
2586 = get_frame_saved_regs (fci)[RA_REGNUM];
2587 /* Set value of previous frame's stack pointer. Remember that
2588 saved_regs[SP_REGNUM] is special in that it contains the
2589 value of the stack pointer register. The other saved_regs
2590 values are addresses (in the inferior) at which a given
2591 register's value may be found. */
2592 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2596 /* hack: if argument regs are saved, guess these contain args */
2597 /* assume we can't tell how many args for now */
2598 get_frame_extra_info (fci)->num_args = -1;
2599 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2601 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2603 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2610 /* MIPS stack frames are almost impenetrable. When execution stops,
2611 we basically have to look at symbol information for the function
2612 that we stopped in, which tells us *which* register (if any) is
2613 the base of the frame pointer, and what offset from that register
2614 the frame itself is at.
2616 This presents a problem when trying to examine a stack in memory
2617 (that isn't executing at the moment), using the "frame" command. We
2618 don't have a PC, nor do we have any registers except SP.
2620 This routine takes two arguments, SP and PC, and tries to make the
2621 cached frames look as if these two arguments defined a frame on the
2622 cache. This allows the rest of info frame to extract the important
2623 arguments without difficulty. */
2626 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2629 error ("MIPS frame specifications require two arguments: sp and pc");
2631 return create_new_frame (argv[0], argv[1]);
2634 /* According to the current ABI, should the type be passed in a
2635 floating-point register (assuming that there is space)? When there
2636 is no FPU, FP are not even considered as possibile candidates for
2637 FP registers and, consequently this returns false - forces FP
2638 arguments into integer registers. */
2641 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2643 return ((typecode == TYPE_CODE_FLT
2645 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2646 && TYPE_NFIELDS (arg_type) == 1
2647 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2648 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2651 /* On o32, argument passing in GPRs depends on the alignment of the type being
2652 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2655 mips_type_needs_double_align (struct type *type)
2657 enum type_code typecode = TYPE_CODE (type);
2659 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2661 else if (typecode == TYPE_CODE_STRUCT)
2663 if (TYPE_NFIELDS (type) < 1)
2665 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2667 else if (typecode == TYPE_CODE_UNION)
2671 n = TYPE_NFIELDS (type);
2672 for (i = 0; i < n; i++)
2673 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2680 /* Macros to round N up or down to the next A boundary;
2681 A must be a power of two. */
2683 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2684 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2686 /* Adjust the address downward (direction of stack growth) so that it
2687 is correctly aligned for a new stack frame. */
2689 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2691 return ROUND_DOWN (addr, 16);
2695 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2696 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2697 struct value **args, CORE_ADDR sp, int struct_return,
2698 CORE_ADDR struct_addr)
2704 int stack_offset = 0;
2706 /* For shared libraries, "t9" needs to point at the function
2708 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2710 /* Set the return address register to point to the entry point of
2711 the program, where a breakpoint lies in wait. */
2712 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2714 /* First ensure that the stack and structure return address (if any)
2715 are properly aligned. The stack has to be at least 64-bit
2716 aligned even on 32-bit machines, because doubles must be 64-bit
2717 aligned. For n32 and n64, stack frames need to be 128-bit
2718 aligned, so we round to this widest known alignment. */
2720 sp = ROUND_DOWN (sp, 16);
2721 struct_addr = ROUND_DOWN (struct_addr, 16);
2723 /* Now make space on the stack for the args. We allocate more
2724 than necessary for EABI, because the first few arguments are
2725 passed in registers, but that's OK. */
2726 for (argnum = 0; argnum < nargs; argnum++)
2727 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2728 MIPS_STACK_ARGSIZE);
2729 sp -= ROUND_UP (len, 16);
2732 fprintf_unfiltered (gdb_stdlog,
2733 "mips_eabi_push_dummy_call: sp=0x%s allocated %d\n",
2734 paddr_nz (sp), ROUND_UP (len, 16));
2736 /* Initialize the integer and float register pointers. */
2738 float_argreg = FPA0_REGNUM;
2740 /* The struct_return pointer occupies the first parameter-passing reg. */
2744 fprintf_unfiltered (gdb_stdlog,
2745 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2746 argreg, paddr_nz (struct_addr));
2747 write_register (argreg++, struct_addr);
2750 /* Now load as many as possible of the first arguments into
2751 registers, and push the rest onto the stack. Loop thru args
2752 from first to last. */
2753 for (argnum = 0; argnum < nargs; argnum++)
2756 char valbuf[MAX_REGISTER_SIZE];
2757 struct value *arg = args[argnum];
2758 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2759 int len = TYPE_LENGTH (arg_type);
2760 enum type_code typecode = TYPE_CODE (arg_type);
2763 fprintf_unfiltered (gdb_stdlog,
2764 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2765 argnum + 1, len, (int) typecode);
2767 /* The EABI passes structures that do not fit in a register by
2769 if (len > MIPS_SAVED_REGSIZE
2770 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2772 store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2773 typecode = TYPE_CODE_PTR;
2774 len = MIPS_SAVED_REGSIZE;
2777 fprintf_unfiltered (gdb_stdlog, " push");
2780 val = (char *) VALUE_CONTENTS (arg);
2782 /* 32-bit ABIs always start floating point arguments in an
2783 even-numbered floating point register. Round the FP register
2784 up before the check to see if there are any FP registers
2785 left. Non MIPS_EABI targets also pass the FP in the integer
2786 registers so also round up normal registers. */
2787 if (!FP_REGISTER_DOUBLE
2788 && fp_register_arg_p (typecode, arg_type))
2790 if ((float_argreg & 1))
2794 /* Floating point arguments passed in registers have to be
2795 treated specially. On 32-bit architectures, doubles
2796 are passed in register pairs; the even register gets
2797 the low word, and the odd register gets the high word.
2798 On non-EABI processors, the first two floating point arguments are
2799 also copied to general registers, because MIPS16 functions
2800 don't use float registers for arguments. This duplication of
2801 arguments in general registers can't hurt non-MIPS16 functions
2802 because those registers are normally skipped. */
2803 /* MIPS_EABI squeezes a struct that contains a single floating
2804 point value into an FP register instead of pushing it onto the
2806 if (fp_register_arg_p (typecode, arg_type)
2807 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2809 if (!FP_REGISTER_DOUBLE && len == 8)
2811 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2812 unsigned long regval;
2814 /* Write the low word of the double to the even register(s). */
2815 regval = extract_unsigned_integer (val + low_offset, 4);
2817 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2818 float_argreg, phex (regval, 4));
2819 write_register (float_argreg++, regval);
2821 /* Write the high word of the double to the odd register(s). */
2822 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2824 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2825 float_argreg, phex (regval, 4));
2826 write_register (float_argreg++, regval);
2830 /* This is a floating point value that fits entirely
2831 in a single register. */
2832 /* On 32 bit ABI's the float_argreg is further adjusted
2833 above to ensure that it is even register aligned. */
2834 LONGEST regval = extract_unsigned_integer (val, len);
2836 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2837 float_argreg, phex (regval, len));
2838 write_register (float_argreg++, regval);
2843 /* Copy the argument to general registers or the stack in
2844 register-sized pieces. Large arguments are split between
2845 registers and stack. */
2846 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2847 are treated specially: Irix cc passes them in registers
2848 where gcc sometimes puts them on the stack. For maximum
2849 compatibility, we will put them in both places. */
2850 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2851 (len % MIPS_SAVED_REGSIZE != 0));
2853 /* Note: Floating-point values that didn't fit into an FP
2854 register are only written to memory. */
2857 /* Remember if the argument was written to the stack. */
2858 int stack_used_p = 0;
2860 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2863 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2866 /* Write this portion of the argument to the stack. */
2867 if (argreg > MIPS_LAST_ARG_REGNUM
2869 || fp_register_arg_p (typecode, arg_type))
2871 /* Should shorter than int integer values be
2872 promoted to int before being stored? */
2873 int longword_offset = 0;
2876 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2878 if (MIPS_STACK_ARGSIZE == 8 &&
2879 (typecode == TYPE_CODE_INT ||
2880 typecode == TYPE_CODE_PTR ||
2881 typecode == TYPE_CODE_FLT) && len <= 4)
2882 longword_offset = MIPS_STACK_ARGSIZE - len;
2883 else if ((typecode == TYPE_CODE_STRUCT ||
2884 typecode == TYPE_CODE_UNION) &&
2885 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2886 longword_offset = MIPS_STACK_ARGSIZE - len;
2891 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2892 paddr_nz (stack_offset));
2893 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2894 paddr_nz (longword_offset));
2897 addr = sp + stack_offset + longword_offset;
2902 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2904 for (i = 0; i < partial_len; i++)
2906 fprintf_unfiltered (gdb_stdlog, "%02x",
2910 write_memory (addr, val, partial_len);
2913 /* Note!!! This is NOT an else clause. Odd sized
2914 structs may go thru BOTH paths. Floating point
2915 arguments will not. */
2916 /* Write this portion of the argument to a general
2917 purpose register. */
2918 if (argreg <= MIPS_LAST_ARG_REGNUM
2919 && !fp_register_arg_p (typecode, arg_type))
2921 LONGEST regval = extract_unsigned_integer (val, partial_len);
2924 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2926 phex (regval, MIPS_SAVED_REGSIZE));
2927 write_register (argreg, regval);
2934 /* Compute the the offset into the stack at which we
2935 will copy the next parameter.
2937 In the new EABI (and the NABI32), the stack_offset
2938 only needs to be adjusted when it has been used. */
2941 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2945 fprintf_unfiltered (gdb_stdlog, "\n");
2948 /* Return adjusted stack pointer. */
2952 /* N32/N64 version of push_dummy_call. */
2955 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2956 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2957 struct value **args, CORE_ADDR sp, int struct_return,
2958 CORE_ADDR struct_addr)
2964 int stack_offset = 0;
2966 /* For shared libraries, "t9" needs to point at the function
2968 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2970 /* Set the return address register to point to the entry point of
2971 the program, where a breakpoint lies in wait. */
2972 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2974 /* First ensure that the stack and structure return address (if any)
2975 are properly aligned. The stack has to be at least 64-bit
2976 aligned even on 32-bit machines, because doubles must be 64-bit
2977 aligned. For n32 and n64, stack frames need to be 128-bit
2978 aligned, so we round to this widest known alignment. */
2980 sp = ROUND_DOWN (sp, 16);
2981 struct_addr = ROUND_DOWN (struct_addr, 16);
2983 /* Now make space on the stack for the args. */
2984 for (argnum = 0; argnum < nargs; argnum++)
2985 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2986 MIPS_STACK_ARGSIZE);
2987 sp -= ROUND_UP (len, 16);
2990 fprintf_unfiltered (gdb_stdlog,
2991 "mips_n32n64_push_dummy_call: sp=0x%s allocated %d\n",
2992 paddr_nz (sp), ROUND_UP (len, 16));
2994 /* Initialize the integer and float register pointers. */
2996 float_argreg = FPA0_REGNUM;
2998 /* The struct_return pointer occupies the first parameter-passing reg. */
3002 fprintf_unfiltered (gdb_stdlog,
3003 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3004 argreg, paddr_nz (struct_addr));
3005 write_register (argreg++, struct_addr);
3008 /* Now load as many as possible of the first arguments into
3009 registers, and push the rest onto the stack. Loop thru args
3010 from first to last. */
3011 for (argnum = 0; argnum < nargs; argnum++)
3014 char valbuf[MAX_REGISTER_SIZE];
3015 struct value *arg = args[argnum];
3016 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3017 int len = TYPE_LENGTH (arg_type);
3018 enum type_code typecode = TYPE_CODE (arg_type);
3021 fprintf_unfiltered (gdb_stdlog,
3022 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3023 argnum + 1, len, (int) typecode);
3025 val = (char *) VALUE_CONTENTS (arg);
3027 if (fp_register_arg_p (typecode, arg_type)
3028 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3030 /* This is a floating point value that fits entirely
3031 in a single register. */
3032 /* On 32 bit ABI's the float_argreg is further adjusted
3033 above to ensure that it is even register aligned. */
3034 LONGEST regval = extract_unsigned_integer (val, len);
3036 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3037 float_argreg, phex (regval, len));
3038 write_register (float_argreg++, regval);
3041 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3042 argreg, phex (regval, len));
3043 write_register (argreg, regval);
3048 /* Copy the argument to general registers or the stack in
3049 register-sized pieces. Large arguments are split between
3050 registers and stack. */
3051 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3052 are treated specially: Irix cc passes them in registers
3053 where gcc sometimes puts them on the stack. For maximum
3054 compatibility, we will put them in both places. */
3055 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3056 (len % MIPS_SAVED_REGSIZE != 0));
3057 /* Note: Floating-point values that didn't fit into an FP
3058 register are only written to memory. */
3061 /* Rememer if the argument was written to the stack. */
3062 int stack_used_p = 0;
3063 int partial_len = len < MIPS_SAVED_REGSIZE ?
3064 len : MIPS_SAVED_REGSIZE;
3067 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3070 /* Write this portion of the argument to the stack. */
3071 if (argreg > MIPS_LAST_ARG_REGNUM
3073 || fp_register_arg_p (typecode, arg_type))
3075 /* Should shorter than int integer values be
3076 promoted to int before being stored? */
3077 int longword_offset = 0;
3080 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3082 if (MIPS_STACK_ARGSIZE == 8 &&
3083 (typecode == TYPE_CODE_INT ||
3084 typecode == TYPE_CODE_PTR ||
3085 typecode == TYPE_CODE_FLT) && len <= 4)
3086 longword_offset = MIPS_STACK_ARGSIZE - len;
3091 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3092 paddr_nz (stack_offset));
3093 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3094 paddr_nz (longword_offset));
3097 addr = sp + stack_offset + longword_offset;
3102 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3104 for (i = 0; i < partial_len; i++)
3106 fprintf_unfiltered (gdb_stdlog, "%02x",
3110 write_memory (addr, val, partial_len);
3113 /* Note!!! This is NOT an else clause. Odd sized
3114 structs may go thru BOTH paths. Floating point
3115 arguments will not. */
3116 /* Write this portion of the argument to a general
3117 purpose register. */
3118 if (argreg <= MIPS_LAST_ARG_REGNUM
3119 && !fp_register_arg_p (typecode, arg_type))
3121 LONGEST regval = extract_unsigned_integer (val, partial_len);
3123 /* A non-floating-point argument being passed in a
3124 general register. If a struct or union, and if
3125 the remaining length is smaller than the register
3126 size, we have to adjust the register value on
3129 It does not seem to be necessary to do the
3130 same for integral types.
3132 cagney/2001-07-23: gdb/179: Also, GCC, when
3133 outputting LE O32 with sizeof (struct) <
3134 MIPS_SAVED_REGSIZE, generates a left shift as
3135 part of storing the argument in a register a
3136 register (the left shift isn't generated when
3137 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3138 is quite possible that this is GCC contradicting
3139 the LE/O32 ABI, GDB has not been adjusted to
3140 accommodate this. Either someone needs to
3141 demonstrate that the LE/O32 ABI specifies such a
3142 left shift OR this new ABI gets identified as
3143 such and GDB gets tweaked accordingly. */
3145 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3146 && partial_len < MIPS_SAVED_REGSIZE
3147 && (typecode == TYPE_CODE_STRUCT ||
3148 typecode == TYPE_CODE_UNION))
3149 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3153 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3155 phex (regval, MIPS_SAVED_REGSIZE));
3156 write_register (argreg, regval);
3163 /* Compute the the offset into the stack at which we
3164 will copy the next parameter.
3166 In N32 (N64?), the stack_offset only needs to be
3167 adjusted when it has been used. */
3170 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3174 fprintf_unfiltered (gdb_stdlog, "\n");
3177 /* Return adjusted stack pointer. */
3181 /* O32 version of push_dummy_call. */
3184 mips_o32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3185 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3186 struct value **args, CORE_ADDR sp, int struct_return,
3187 CORE_ADDR struct_addr)
3193 int stack_offset = 0;
3195 /* For shared libraries, "t9" needs to point at the function
3197 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3199 /* Set the return address register to point to the entry point of
3200 the program, where a breakpoint lies in wait. */
3201 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3203 /* First ensure that the stack and structure return address (if any)
3204 are properly aligned. The stack has to be at least 64-bit
3205 aligned even on 32-bit machines, because doubles must be 64-bit
3206 aligned. For n32 and n64, stack frames need to be 128-bit
3207 aligned, so we round to this widest known alignment. */
3209 sp = ROUND_DOWN (sp, 16);
3210 struct_addr = ROUND_DOWN (struct_addr, 16);
3212 /* Now make space on the stack for the args. */
3213 for (argnum = 0; argnum < nargs; argnum++)
3214 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3215 MIPS_STACK_ARGSIZE);
3216 sp -= ROUND_UP (len, 16);
3219 fprintf_unfiltered (gdb_stdlog,
3220 "mips_o32_push_dummy_call: sp=0x%s allocated %d\n",
3221 paddr_nz (sp), ROUND_UP (len, 16));
3223 /* Initialize the integer and float register pointers. */
3225 float_argreg = FPA0_REGNUM;
3227 /* The struct_return pointer occupies the first parameter-passing reg. */
3231 fprintf_unfiltered (gdb_stdlog,
3232 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3233 argreg, paddr_nz (struct_addr));
3234 write_register (argreg++, struct_addr);
3235 stack_offset += MIPS_STACK_ARGSIZE;
3238 /* Now load as many as possible of the first arguments into
3239 registers, and push the rest onto the stack. Loop thru args
3240 from first to last. */
3241 for (argnum = 0; argnum < nargs; argnum++)
3244 char valbuf[MAX_REGISTER_SIZE];
3245 struct value *arg = args[argnum];
3246 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3247 int len = TYPE_LENGTH (arg_type);
3248 enum type_code typecode = TYPE_CODE (arg_type);
3251 fprintf_unfiltered (gdb_stdlog,
3252 "mips_o32_push_dummy_call: %d len=%d type=%d",
3253 argnum + 1, len, (int) typecode);
3255 val = (char *) VALUE_CONTENTS (arg);
3257 /* 32-bit ABIs always start floating point arguments in an
3258 even-numbered floating point register. Round the FP register
3259 up before the check to see if there are any FP registers
3260 left. O32/O64 targets also pass the FP in the integer
3261 registers so also round up normal registers. */
3262 if (!FP_REGISTER_DOUBLE
3263 && fp_register_arg_p (typecode, arg_type))
3265 if ((float_argreg & 1))
3269 /* Floating point arguments passed in registers have to be
3270 treated specially. On 32-bit architectures, doubles
3271 are passed in register pairs; the even register gets
3272 the low word, and the odd register gets the high word.
3273 On O32/O64, the first two floating point arguments are
3274 also copied to general registers, because MIPS16 functions
3275 don't use float registers for arguments. This duplication of
3276 arguments in general registers can't hurt non-MIPS16 functions
3277 because those registers are normally skipped. */
3279 if (fp_register_arg_p (typecode, arg_type)
3280 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3282 if (!FP_REGISTER_DOUBLE && len == 8)
3284 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3285 unsigned long regval;
3287 /* Write the low word of the double to the even register(s). */
3288 regval = extract_unsigned_integer (val + low_offset, 4);
3290 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3291 float_argreg, phex (regval, 4));
3292 write_register (float_argreg++, regval);
3294 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3295 argreg, phex (regval, 4));
3296 write_register (argreg++, regval);
3298 /* Write the high word of the double to the odd register(s). */
3299 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3301 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3302 float_argreg, phex (regval, 4));
3303 write_register (float_argreg++, regval);
3306 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3307 argreg, phex (regval, 4));
3308 write_register (argreg++, regval);
3312 /* This is a floating point value that fits entirely
3313 in a single register. */
3314 /* On 32 bit ABI's the float_argreg is further adjusted
3315 above to ensure that it is even register aligned. */
3316 LONGEST regval = extract_unsigned_integer (val, len);
3318 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3319 float_argreg, phex (regval, len));
3320 write_register (float_argreg++, regval);
3321 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3322 registers for each argument. The below is (my
3323 guess) to ensure that the corresponding integer
3324 register has reserved the same space. */
3326 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3327 argreg, phex (regval, len));
3328 write_register (argreg, regval);
3329 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3331 /* Reserve space for the FP register. */
3332 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3336 /* Copy the argument to general registers or the stack in
3337 register-sized pieces. Large arguments are split between
3338 registers and stack. */
3339 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3340 are treated specially: Irix cc passes them in registers
3341 where gcc sometimes puts them on the stack. For maximum
3342 compatibility, we will put them in both places. */
3343 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3344 (len % MIPS_SAVED_REGSIZE != 0));
3345 /* Structures should be aligned to eight bytes (even arg registers)
3346 on MIPS_ABI_O32, if their first member has double precision. */
3347 if (MIPS_SAVED_REGSIZE < 8
3348 && mips_type_needs_double_align (arg_type))
3353 /* Note: Floating-point values that didn't fit into an FP
3354 register are only written to memory. */
3357 /* Remember if the argument was written to the stack. */
3358 int stack_used_p = 0;
3360 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3363 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3366 /* Write this portion of the argument to the stack. */
3367 if (argreg > MIPS_LAST_ARG_REGNUM
3369 || fp_register_arg_p (typecode, arg_type))
3371 /* Should shorter than int integer values be
3372 promoted to int before being stored? */
3373 int longword_offset = 0;
3376 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3378 if (MIPS_STACK_ARGSIZE == 8 &&
3379 (typecode == TYPE_CODE_INT ||
3380 typecode == TYPE_CODE_PTR ||
3381 typecode == TYPE_CODE_FLT) && len <= 4)
3382 longword_offset = MIPS_STACK_ARGSIZE - len;
3387 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3388 paddr_nz (stack_offset));
3389 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3390 paddr_nz (longword_offset));
3393 addr = sp + stack_offset + longword_offset;
3398 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3400 for (i = 0; i < partial_len; i++)
3402 fprintf_unfiltered (gdb_stdlog, "%02x",
3406 write_memory (addr, val, partial_len);
3409 /* Note!!! This is NOT an else clause. Odd sized
3410 structs may go thru BOTH paths. Floating point
3411 arguments will not. */
3412 /* Write this portion of the argument to a general
3413 purpose register. */
3414 if (argreg <= MIPS_LAST_ARG_REGNUM
3415 && !fp_register_arg_p (typecode, arg_type))
3417 LONGEST regval = extract_signed_integer (val, partial_len);
3418 /* Value may need to be sign extended, because
3419 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3421 /* A non-floating-point argument being passed in a
3422 general register. If a struct or union, and if
3423 the remaining length is smaller than the register
3424 size, we have to adjust the register value on
3427 It does not seem to be necessary to do the
3428 same for integral types.
3430 Also don't do this adjustment on O64 binaries.
3432 cagney/2001-07-23: gdb/179: Also, GCC, when
3433 outputting LE O32 with sizeof (struct) <
3434 MIPS_SAVED_REGSIZE, generates a left shift as
3435 part of storing the argument in a register a
3436 register (the left shift isn't generated when
3437 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3438 is quite possible that this is GCC contradicting
3439 the LE/O32 ABI, GDB has not been adjusted to
3440 accommodate this. Either someone needs to
3441 demonstrate that the LE/O32 ABI specifies such a
3442 left shift OR this new ABI gets identified as
3443 such and GDB gets tweaked accordingly. */
3445 if (MIPS_SAVED_REGSIZE < 8
3446 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3447 && partial_len < MIPS_SAVED_REGSIZE
3448 && (typecode == TYPE_CODE_STRUCT ||
3449 typecode == TYPE_CODE_UNION))
3450 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3454 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3456 phex (regval, MIPS_SAVED_REGSIZE));
3457 write_register (argreg, regval);
3460 /* Prevent subsequent floating point arguments from
3461 being passed in floating point registers. */
3462 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3468 /* Compute the the offset into the stack at which we
3469 will copy the next parameter.
3471 In older ABIs, the caller reserved space for
3472 registers that contained arguments. This was loosely
3473 refered to as their "home". Consequently, space is
3474 always allocated. */
3476 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3480 fprintf_unfiltered (gdb_stdlog, "\n");
3483 /* Return adjusted stack pointer. */
3487 /* O64 version of push_dummy_call. */
3490 mips_o64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3491 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3492 struct value **args, CORE_ADDR sp, int struct_return,
3493 CORE_ADDR struct_addr)
3499 int stack_offset = 0;
3501 /* For shared libraries, "t9" needs to point at the function
3503 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3505 /* Set the return address register to point to the entry point of
3506 the program, where a breakpoint lies in wait. */
3507 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3509 /* First ensure that the stack and structure return address (if any)
3510 are properly aligned. The stack has to be at least 64-bit
3511 aligned even on 32-bit machines, because doubles must be 64-bit
3512 aligned. For n32 and n64, stack frames need to be 128-bit
3513 aligned, so we round to this widest known alignment. */
3515 sp = ROUND_DOWN (sp, 16);
3516 struct_addr = ROUND_DOWN (struct_addr, 16);
3518 /* Now make space on the stack for the args. */
3519 for (argnum = 0; argnum < nargs; argnum++)
3520 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3521 MIPS_STACK_ARGSIZE);
3522 sp -= ROUND_UP (len, 16);
3525 fprintf_unfiltered (gdb_stdlog,
3526 "mips_o64_push_dummy_call: sp=0x%s allocated %d\n",
3527 paddr_nz (sp), ROUND_UP (len, 16));
3529 /* Initialize the integer and float register pointers. */
3531 float_argreg = FPA0_REGNUM;
3533 /* The struct_return pointer occupies the first parameter-passing reg. */
3537 fprintf_unfiltered (gdb_stdlog,
3538 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3539 argreg, paddr_nz (struct_addr));
3540 write_register (argreg++, struct_addr);
3541 stack_offset += MIPS_STACK_ARGSIZE;
3544 /* Now load as many as possible of the first arguments into
3545 registers, and push the rest onto the stack. Loop thru args
3546 from first to last. */
3547 for (argnum = 0; argnum < nargs; argnum++)
3550 char valbuf[MAX_REGISTER_SIZE];
3551 struct value *arg = args[argnum];
3552 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3553 int len = TYPE_LENGTH (arg_type);
3554 enum type_code typecode = TYPE_CODE (arg_type);
3557 fprintf_unfiltered (gdb_stdlog,
3558 "mips_o64_push_dummy_call: %d len=%d type=%d",
3559 argnum + 1, len, (int) typecode);
3561 val = (char *) VALUE_CONTENTS (arg);
3563 /* 32-bit ABIs always start floating point arguments in an
3564 even-numbered floating point register. Round the FP register
3565 up before the check to see if there are any FP registers
3566 left. O32/O64 targets also pass the FP in the integer
3567 registers so also round up normal registers. */
3568 if (!FP_REGISTER_DOUBLE
3569 && fp_register_arg_p (typecode, arg_type))
3571 if ((float_argreg & 1))
3575 /* Floating point arguments passed in registers have to be
3576 treated specially. On 32-bit architectures, doubles
3577 are passed in register pairs; the even register gets
3578 the low word, and the odd register gets the high word.
3579 On O32/O64, the first two floating point arguments are
3580 also copied to general registers, because MIPS16 functions
3581 don't use float registers for arguments. This duplication of
3582 arguments in general registers can't hurt non-MIPS16 functions
3583 because those registers are normally skipped. */
3585 if (fp_register_arg_p (typecode, arg_type)
3586 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3588 if (!FP_REGISTER_DOUBLE && len == 8)
3590 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3591 unsigned long regval;
3593 /* Write the low word of the double to the even register(s). */
3594 regval = extract_unsigned_integer (val + low_offset, 4);
3596 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3597 float_argreg, phex (regval, 4));
3598 write_register (float_argreg++, regval);
3600 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3601 argreg, phex (regval, 4));
3602 write_register (argreg++, regval);
3604 /* Write the high word of the double to the odd register(s). */
3605 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3607 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3608 float_argreg, phex (regval, 4));
3609 write_register (float_argreg++, regval);
3612 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3613 argreg, phex (regval, 4));
3614 write_register (argreg++, regval);
3618 /* This is a floating point value that fits entirely
3619 in a single register. */
3620 /* On 32 bit ABI's the float_argreg is further adjusted
3621 above to ensure that it is even register aligned. */
3622 LONGEST regval = extract_unsigned_integer (val, len);
3624 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3625 float_argreg, phex (regval, len));
3626 write_register (float_argreg++, regval);
3627 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3628 registers for each argument. The below is (my
3629 guess) to ensure that the corresponding integer
3630 register has reserved the same space. */
3632 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3633 argreg, phex (regval, len));
3634 write_register (argreg, regval);
3635 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3637 /* Reserve space for the FP register. */
3638 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3642 /* Copy the argument to general registers or the stack in
3643 register-sized pieces. Large arguments are split between
3644 registers and stack. */
3645 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3646 are treated specially: Irix cc passes them in registers
3647 where gcc sometimes puts them on the stack. For maximum
3648 compatibility, we will put them in both places. */
3649 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3650 (len % MIPS_SAVED_REGSIZE != 0));
3651 /* Structures should be aligned to eight bytes (even arg registers)
3652 on MIPS_ABI_O32, if their first member has double precision. */
3653 if (MIPS_SAVED_REGSIZE < 8
3654 && mips_type_needs_double_align (arg_type))
3659 /* Note: Floating-point values that didn't fit into an FP
3660 register are only written to memory. */
3663 /* Remember if the argument was written to the stack. */
3664 int stack_used_p = 0;
3666 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3669 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3672 /* Write this portion of the argument to the stack. */
3673 if (argreg > MIPS_LAST_ARG_REGNUM
3675 || fp_register_arg_p (typecode, arg_type))
3677 /* Should shorter than int integer values be
3678 promoted to int before being stored? */
3679 int longword_offset = 0;
3682 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3684 if (MIPS_STACK_ARGSIZE == 8 &&
3685 (typecode == TYPE_CODE_INT ||
3686 typecode == TYPE_CODE_PTR ||
3687 typecode == TYPE_CODE_FLT) && len <= 4)
3688 longword_offset = MIPS_STACK_ARGSIZE - len;
3693 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3694 paddr_nz (stack_offset));
3695 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3696 paddr_nz (longword_offset));
3699 addr = sp + stack_offset + longword_offset;
3704 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3706 for (i = 0; i < partial_len; i++)
3708 fprintf_unfiltered (gdb_stdlog, "%02x",
3712 write_memory (addr, val, partial_len);
3715 /* Note!!! This is NOT an else clause. Odd sized
3716 structs may go thru BOTH paths. Floating point
3717 arguments will not. */
3718 /* Write this portion of the argument to a general
3719 purpose register. */
3720 if (argreg <= MIPS_LAST_ARG_REGNUM
3721 && !fp_register_arg_p (typecode, arg_type))
3723 LONGEST regval = extract_signed_integer (val, partial_len);
3724 /* Value may need to be sign extended, because
3725 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3727 /* A non-floating-point argument being passed in a
3728 general register. If a struct or union, and if
3729 the remaining length is smaller than the register
3730 size, we have to adjust the register value on
3733 It does not seem to be necessary to do the
3734 same for integral types.
3736 Also don't do this adjustment on O64 binaries.
3738 cagney/2001-07-23: gdb/179: Also, GCC, when
3739 outputting LE O32 with sizeof (struct) <
3740 MIPS_SAVED_REGSIZE, generates a left shift as
3741 part of storing the argument in a register a
3742 register (the left shift isn't generated when
3743 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3744 is quite possible that this is GCC contradicting
3745 the LE/O32 ABI, GDB has not been adjusted to
3746 accommodate this. Either someone needs to
3747 demonstrate that the LE/O32 ABI specifies such a
3748 left shift OR this new ABI gets identified as
3749 such and GDB gets tweaked accordingly. */
3751 if (MIPS_SAVED_REGSIZE < 8
3752 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3753 && partial_len < MIPS_SAVED_REGSIZE
3754 && (typecode == TYPE_CODE_STRUCT ||
3755 typecode == TYPE_CODE_UNION))
3756 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3760 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3762 phex (regval, MIPS_SAVED_REGSIZE));
3763 write_register (argreg, regval);
3766 /* Prevent subsequent floating point arguments from
3767 being passed in floating point registers. */
3768 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3774 /* Compute the the offset into the stack at which we
3775 will copy the next parameter.
3777 In older ABIs, the caller reserved space for
3778 registers that contained arguments. This was loosely
3779 refered to as their "home". Consequently, space is
3780 always allocated. */
3782 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3786 fprintf_unfiltered (gdb_stdlog, "\n");
3789 /* Return adjusted stack pointer. */
3794 mips_pop_frame (void)
3796 register int regnum;
3797 struct frame_info *frame = get_current_frame ();
3798 CORE_ADDR new_sp = get_frame_base (frame);
3799 mips_extra_func_info_t proc_desc;
3801 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3803 generic_pop_dummy_frame ();
3804 flush_cached_frames ();
3808 proc_desc = get_frame_extra_info (frame)->proc_desc;
3809 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3810 if (get_frame_saved_regs (frame) == NULL)
3811 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3812 for (regnum = 0; regnum < NUM_REGS; regnum++)
3813 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3814 && get_frame_saved_regs (frame)[regnum])
3816 /* Floating point registers must not be sign extended,
3817 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3819 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3820 write_register (regnum,
3821 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3822 MIPS_SAVED_REGSIZE));
3824 write_register (regnum,
3825 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3826 MIPS_SAVED_REGSIZE));
3829 write_register (SP_REGNUM, new_sp);
3830 flush_cached_frames ();
3832 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3834 struct linked_proc_info *pi_ptr, *prev_ptr;
3836 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3838 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3840 if (&pi_ptr->info == proc_desc)
3845 error ("Can't locate dummy extra frame info\n");
3847 if (prev_ptr != NULL)
3848 prev_ptr->next = pi_ptr->next;
3850 linked_proc_desc_table = pi_ptr->next;
3854 write_register (HI_REGNUM,
3855 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3856 MIPS_SAVED_REGSIZE));
3857 write_register (LO_REGNUM,
3858 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3859 MIPS_SAVED_REGSIZE));
3860 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3861 write_register (FCRCS_REGNUM,
3862 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3863 MIPS_SAVED_REGSIZE));
3867 /* Floating point register management.
3869 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3870 64bit operations, these early MIPS cpus treat fp register pairs
3871 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3872 registers and offer a compatibility mode that emulates the MIPS2 fp
3873 model. When operating in MIPS2 fp compat mode, later cpu's split
3874 double precision floats into two 32-bit chunks and store them in
3875 consecutive fp regs. To display 64-bit floats stored in this
3876 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3877 Throw in user-configurable endianness and you have a real mess.
3879 The way this works is:
3880 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3881 double-precision value will be split across two logical registers.
3882 The lower-numbered logical register will hold the low-order bits,
3883 regardless of the processor's endianness.
3884 - If we are on a 64-bit processor, and we are looking for a
3885 single-precision value, it will be in the low ordered bits
3886 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3887 save slot in memory.
3888 - If we are in 64-bit mode, everything is straightforward.
3890 Note that this code only deals with "live" registers at the top of the
3891 stack. We will attempt to deal with saved registers later, when
3892 the raw/cooked register interface is in place. (We need a general
3893 interface that can deal with dynamic saved register sizes -- fp
3894 regs could be 32 bits wide in one frame and 64 on the frame above
3897 static struct type *
3898 mips_float_register_type (void)
3900 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3901 return builtin_type_ieee_single_big;
3903 return builtin_type_ieee_single_little;
3906 static struct type *
3907 mips_double_register_type (void)
3909 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3910 return builtin_type_ieee_double_big;
3912 return builtin_type_ieee_double_little;
3915 /* Copy a 32-bit single-precision value from the current frame
3916 into rare_buffer. */
3919 mips_read_fp_register_single (struct frame_info *frame, int regno,
3922 int raw_size = REGISTER_RAW_SIZE (regno);
3923 char *raw_buffer = alloca (raw_size);
3925 if (!frame_register_read (frame, regno, raw_buffer))
3926 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3929 /* We have a 64-bit value for this register. Find the low-order
3933 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3938 memcpy (rare_buffer, raw_buffer + offset, 4);
3942 memcpy (rare_buffer, raw_buffer, 4);
3946 /* Copy a 64-bit double-precision value from the current frame into
3947 rare_buffer. This may include getting half of it from the next
3951 mips_read_fp_register_double (struct frame_info *frame, int regno,
3954 int raw_size = REGISTER_RAW_SIZE (regno);
3956 if (raw_size == 8 && !mips2_fp_compat ())
3958 /* We have a 64-bit value for this register, and we should use
3960 if (!frame_register_read (frame, regno, rare_buffer))
3961 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3965 if ((regno - FP0_REGNUM) & 1)
3966 internal_error (__FILE__, __LINE__,
3967 "mips_read_fp_register_double: bad access to "
3968 "odd-numbered FP register");
3970 /* mips_read_fp_register_single will find the correct 32 bits from
3972 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3974 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
3975 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
3979 mips_read_fp_register_single (frame, regno, rare_buffer);
3980 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
3986 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
3988 { /* do values for FP (float) regs */
3990 double doub, flt1, flt2; /* doubles extracted from raw hex data */
3991 int inv1, inv2, namelen;
3993 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
3995 fprintf_filtered (file, "%s:", REGISTER_NAME (regnum));
3996 fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)),
3999 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4001 /* 4-byte registers: Print hex and floating. Also print even
4002 numbered registers as doubles. */
4003 mips_read_fp_register_single (frame, regnum, raw_buffer);
4004 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4006 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', file);
4008 fprintf_filtered (file, " flt: ");
4010 fprintf_filtered (file, " <invalid float> ");
4012 fprintf_filtered (file, "%-17.9g", flt1);
4014 if (regnum % 2 == 0)
4016 mips_read_fp_register_double (frame, regnum, raw_buffer);
4017 doub = unpack_double (mips_double_register_type (), raw_buffer,
4020 fprintf_filtered (file, " dbl: ");
4022 fprintf_filtered (file, "<invalid double>");
4024 fprintf_filtered (file, "%-24.17g", doub);
4029 /* Eight byte registers: print each one as hex, float and double. */
4030 mips_read_fp_register_single (frame, regnum, raw_buffer);
4031 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4033 mips_read_fp_register_double (frame, regnum, raw_buffer);
4034 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4037 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', file);
4039 fprintf_filtered (file, " flt: ");
4041 fprintf_filtered (file, "<invalid float>");
4043 fprintf_filtered (file, "%-17.9g", flt1);
4045 fprintf_filtered (file, " dbl: ");
4047 fprintf_filtered (file, "<invalid double>");
4049 fprintf_filtered (file, "%-24.17g", doub);
4054 mips_print_register (struct ui_file *file, struct frame_info *frame,
4055 int regnum, int all)
4057 char raw_buffer[MAX_REGISTER_SIZE];
4060 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4062 mips_print_fp_register (file, frame, regnum);
4066 /* Get the data in raw format. */
4067 if (!frame_register_read (frame, regnum, raw_buffer))
4069 fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum));
4073 fputs_filtered (REGISTER_NAME (regnum), file);
4075 /* The problem with printing numeric register names (r26, etc.) is that
4076 the user can't use them on input. Probably the best solution is to
4077 fix it so that either the numeric or the funky (a2, etc.) names
4078 are accepted on input. */
4079 if (regnum < MIPS_NUMREGS)
4080 fprintf_filtered (file, "(r%d): ", regnum);
4082 fprintf_filtered (file, ": ");
4084 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4085 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4089 print_scalar_formatted (raw_buffer + offset,
4090 REGISTER_VIRTUAL_TYPE (regnum),
4094 /* Replacement for generic do_registers_info.
4095 Print regs in pretty columns. */
4098 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4101 fprintf_filtered (file, " ");
4102 mips_print_fp_register (file, frame, regnum);
4103 fprintf_filtered (file, "\n");
4108 /* Print a row's worth of GP (int) registers, with name labels above */
4111 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
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 fprintf_filtered (file, " ");
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 fprintf_filtered (file, MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4131 REGISTER_NAME (regnum));
4134 fprintf_filtered (file,
4135 start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4136 start_regnum); /* print the R0 to R31 names */
4138 regnum = start_regnum; /* go back to start of row */
4139 /* now print the values in hex, 4 or 8 to the row */
4140 for (col = 0; col < ncols && regnum < numregs; regnum++)
4142 if (*REGISTER_NAME (regnum) == '\0')
4143 continue; /* unused register */
4144 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4145 break; /* end row: reached FP register */
4146 /* OK: get the data in raw format. */
4147 if (!frame_register_read (frame, regnum, raw_buffer))
4148 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4149 /* pad small registers */
4150 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4151 printf_filtered (" ");
4152 /* Now print the register value in hex, endian order. */
4153 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4154 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4155 byte < REGISTER_RAW_SIZE (regnum);
4157 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4159 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4162 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4163 fprintf_filtered (file, " ");
4166 if (col > 0) /* ie. if we actually printed anything... */
4167 fprintf_filtered (file, "\n");
4172 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4175 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4176 struct frame_info *frame, int regnum, int all)
4178 if (regnum != -1) /* do one specified register */
4180 if (*(REGISTER_NAME (regnum)) == '\0')
4181 error ("Not a valid register for the current processor type");
4183 mips_print_register (file, frame, regnum, 0);
4184 fprintf_filtered (file, "\n");
4187 /* do all (or most) registers */
4190 while (regnum < NUM_REGS)
4192 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4194 if (all) /* true for "INFO ALL-REGISTERS" command */
4195 regnum = print_fp_register_row (file, frame, regnum);
4197 regnum += MIPS_NUMREGS; /* skip floating point regs */
4200 regnum = print_gp_register_row (file, frame, regnum);
4205 /* Is this a branch with a delay slot? */
4207 static int is_delayed (unsigned long);
4210 is_delayed (unsigned long insn)
4213 for (i = 0; i < NUMOPCODES; ++i)
4214 if (mips_opcodes[i].pinfo != INSN_MACRO
4215 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4217 return (i < NUMOPCODES
4218 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4219 | INSN_COND_BRANCH_DELAY
4220 | INSN_COND_BRANCH_LIKELY)));
4224 mips_step_skips_delay (CORE_ADDR pc)
4226 char buf[MIPS_INSTLEN];
4228 /* There is no branch delay slot on MIPS16. */
4229 if (pc_is_mips16 (pc))
4232 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4233 /* If error reading memory, guess that it is not a delayed branch. */
4235 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4239 /* Skip the PC past function prologue instructions (32-bit version).
4240 This is a helper function for mips_skip_prologue. */
4243 mips32_skip_prologue (CORE_ADDR pc)
4247 int seen_sp_adjust = 0;
4248 int load_immediate_bytes = 0;
4250 /* Skip the typical prologue instructions. These are the stack adjustment
4251 instruction and the instructions that save registers on the stack
4252 or in the gcc frame. */
4253 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4255 unsigned long high_word;
4257 inst = mips_fetch_instruction (pc);
4258 high_word = (inst >> 16) & 0xffff;
4260 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4261 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4263 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4264 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4266 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4267 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4268 && (inst & 0x001F0000)) /* reg != $zero */
4271 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4273 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4275 continue; /* reg != $zero */
4277 /* move $s8,$sp. With different versions of gas this will be either
4278 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4279 Accept any one of these. */
4280 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4283 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4285 else if (high_word == 0x3c1c) /* lui $gp,n */
4287 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4289 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4290 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4292 /* The following instructions load $at or $t0 with an immediate
4293 value in preparation for a stack adjustment via
4294 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4295 a local variable, so we accept them only before a stack adjustment
4296 instruction was seen. */
4297 else if (!seen_sp_adjust)
4299 if (high_word == 0x3c01 || /* lui $at,n */
4300 high_word == 0x3c08) /* lui $t0,n */
4302 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4305 else if (high_word == 0x3421 || /* ori $at,$at,n */
4306 high_word == 0x3508 || /* ori $t0,$t0,n */
4307 high_word == 0x3401 || /* ori $at,$zero,n */
4308 high_word == 0x3408) /* ori $t0,$zero,n */
4310 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4320 /* In a frameless function, we might have incorrectly
4321 skipped some load immediate instructions. Undo the skipping
4322 if the load immediate was not followed by a stack adjustment. */
4323 if (load_immediate_bytes && !seen_sp_adjust)
4324 pc -= load_immediate_bytes;
4328 /* Skip the PC past function prologue instructions (16-bit version).
4329 This is a helper function for mips_skip_prologue. */
4332 mips16_skip_prologue (CORE_ADDR pc)
4335 int extend_bytes = 0;
4336 int prev_extend_bytes;
4338 /* Table of instructions likely to be found in a function prologue. */
4341 unsigned short inst;
4342 unsigned short mask;
4349 , /* addiu $sp,offset */
4353 , /* daddiu $sp,offset */
4357 , /* sw reg,n($sp) */
4361 , /* sd reg,n($sp) */
4365 , /* sw $ra,n($sp) */
4369 , /* sd $ra,n($sp) */
4377 , /* sw $a0-$a3,n($s1) */
4381 , /* move reg,$a0-$a3 */
4385 , /* entry pseudo-op */
4389 , /* addiu $s1,$sp,n */
4392 } /* end of table marker */
4395 /* Skip the typical prologue instructions. These are the stack adjustment
4396 instruction and the instructions that save registers on the stack
4397 or in the gcc frame. */
4398 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4400 unsigned short inst;
4403 inst = mips_fetch_instruction (pc);
4405 /* Normally we ignore an extend instruction. However, if it is
4406 not followed by a valid prologue instruction, we must adjust
4407 the pc back over the extend so that it won't be considered
4408 part of the prologue. */
4409 if ((inst & 0xf800) == 0xf000) /* extend */
4411 extend_bytes = MIPS16_INSTLEN;
4414 prev_extend_bytes = extend_bytes;
4417 /* Check for other valid prologue instructions besides extend. */
4418 for (i = 0; table[i].mask != 0; i++)
4419 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4421 if (table[i].mask != 0) /* it was in table? */
4422 continue; /* ignore it */
4426 /* Return the current pc, adjusted backwards by 2 if
4427 the previous instruction was an extend. */
4428 return pc - prev_extend_bytes;
4434 /* To skip prologues, I use this predicate. Returns either PC itself
4435 if the code at PC does not look like a function prologue; otherwise
4436 returns an address that (if we're lucky) follows the prologue. If
4437 LENIENT, then we must skip everything which is involved in setting
4438 up the frame (it's OK to skip more, just so long as we don't skip
4439 anything which might clobber the registers which are being saved.
4440 We must skip more in the case where part of the prologue is in the
4441 delay slot of a non-prologue instruction). */
4444 mips_skip_prologue (CORE_ADDR pc)
4446 /* See if we can determine the end of the prologue via the symbol table.
4447 If so, then return either PC, or the PC after the prologue, whichever
4450 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4452 if (post_prologue_pc != 0)
4453 return max (pc, post_prologue_pc);
4455 /* Can't determine prologue from the symbol table, need to examine
4458 if (pc_is_mips16 (pc))
4459 return mips16_skip_prologue (pc);
4461 return mips32_skip_prologue (pc);
4464 /* Determine how a return value is stored within the MIPS register
4465 file, given the return type `valtype'. */
4467 struct return_value_word
4476 return_value_location (struct type *valtype,
4477 struct return_value_word *hi,
4478 struct return_value_word *lo)
4480 int len = TYPE_LENGTH (valtype);
4482 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4483 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4484 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4486 if (!FP_REGISTER_DOUBLE && len == 8)
4488 /* We need to break a 64bit float in two 32 bit halves and
4489 spread them across a floating-point register pair. */
4490 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4491 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4492 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4493 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4495 hi->reg_offset = lo->reg_offset;
4496 lo->reg = FP0_REGNUM + 0;
4497 hi->reg = FP0_REGNUM + 1;
4503 /* The floating point value fits in a single floating-point
4505 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4506 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4509 lo->reg = FP0_REGNUM;
4520 /* Locate a result possibly spread across two registers. */
4522 lo->reg = regnum + 0;
4523 hi->reg = regnum + 1;
4524 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4525 && len < MIPS_SAVED_REGSIZE)
4527 /* "un-left-justify" the value in the low register */
4528 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4533 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4534 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4535 && len < MIPS_SAVED_REGSIZE * 2
4536 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4537 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4539 /* "un-left-justify" the value spread across two registers. */
4540 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4541 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4543 hi->len = len - lo->len;
4547 /* Only perform a partial copy of the second register. */
4550 if (len > MIPS_SAVED_REGSIZE)
4552 lo->len = MIPS_SAVED_REGSIZE;
4553 hi->len = len - MIPS_SAVED_REGSIZE;
4561 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4562 && REGISTER_RAW_SIZE (regnum) == 8
4563 && MIPS_SAVED_REGSIZE == 4)
4565 /* Account for the fact that only the least-signficant part
4566 of the register is being used */
4567 lo->reg_offset += 4;
4568 hi->reg_offset += 4;
4571 hi->buf_offset = lo->len;
4575 /* Given a return value in `regbuf' with a type `valtype', extract and
4576 copy its value into `valbuf'. */
4579 mips_eabi_extract_return_value (struct type *valtype,
4583 struct return_value_word lo;
4584 struct return_value_word hi;
4585 return_value_location (valtype, &hi, &lo);
4587 memcpy (valbuf + lo.buf_offset,
4588 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4592 memcpy (valbuf + hi.buf_offset,
4593 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4598 mips_o64_extract_return_value (struct type *valtype,
4602 struct return_value_word lo;
4603 struct return_value_word hi;
4604 return_value_location (valtype, &hi, &lo);
4606 memcpy (valbuf + lo.buf_offset,
4607 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4611 memcpy (valbuf + hi.buf_offset,
4612 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4616 /* Given a return value in `valbuf' with a type `valtype', write it's
4617 value into the appropriate register. */
4620 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4622 char raw_buffer[MAX_REGISTER_SIZE];
4623 struct return_value_word lo;
4624 struct return_value_word hi;
4625 return_value_location (valtype, &hi, &lo);
4627 memset (raw_buffer, 0, sizeof (raw_buffer));
4628 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4629 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4630 REGISTER_RAW_SIZE (lo.reg));
4634 memset (raw_buffer, 0, sizeof (raw_buffer));
4635 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4636 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4637 REGISTER_RAW_SIZE (hi.reg));
4642 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4644 char raw_buffer[MAX_REGISTER_SIZE];
4645 struct return_value_word lo;
4646 struct return_value_word hi;
4647 return_value_location (valtype, &hi, &lo);
4649 memset (raw_buffer, 0, sizeof (raw_buffer));
4650 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4651 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4652 REGISTER_RAW_SIZE (lo.reg));
4656 memset (raw_buffer, 0, sizeof (raw_buffer));
4657 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4658 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4659 REGISTER_RAW_SIZE (hi.reg));
4663 /* O32 ABI stuff. */
4666 mips_o32_xfer_return_value (struct type *type,
4667 struct regcache *regcache,
4668 bfd_byte *in, const bfd_byte *out)
4670 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4671 if (TYPE_CODE (type) == TYPE_CODE_FLT
4672 && TYPE_LENGTH (type) == 4
4673 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4675 /* A single-precision floating-point value. It fits in the
4676 least significant part of FP0. */
4678 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4679 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4680 TARGET_BYTE_ORDER, in, out, 0);
4682 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4683 && TYPE_LENGTH (type) == 8
4684 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4686 /* A double-precision floating-point value. It fits in the
4687 least significant part of FP0/FP1 but with byte ordering
4688 based on the target (???). */
4690 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4691 switch (TARGET_BYTE_ORDER)
4693 case BFD_ENDIAN_LITTLE:
4694 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4695 TARGET_BYTE_ORDER, in, out, 0);
4696 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4697 TARGET_BYTE_ORDER, in, out, 4);
4699 case BFD_ENDIAN_BIG:
4700 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4701 TARGET_BYTE_ORDER, in, out, 0);
4702 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4703 TARGET_BYTE_ORDER, in, out, 4);
4706 internal_error (__FILE__, __LINE__, "bad switch");
4710 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4711 && TYPE_NFIELDS (type) <= 2
4712 && TYPE_NFIELDS (type) >= 1
4713 && ((TYPE_NFIELDS (type) == 1
4714 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4716 || (TYPE_NFIELDS (type) == 2
4717 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4719 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4721 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4723 /* A struct that contains one or two floats. Each value is part
4724 in the least significant part of their floating point
4726 bfd_byte reg[MAX_REGISTER_SIZE];
4729 for (field = 0, regnum = FP0_REGNUM;
4730 field < TYPE_NFIELDS (type);
4731 field++, regnum += 2)
4733 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4736 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4737 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4738 TARGET_BYTE_ORDER, in, out, offset);
4743 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4744 || TYPE_CODE (type) == TYPE_CODE_UNION)
4746 /* A structure or union. Extract the left justified value,
4747 regardless of the byte order. I.e. DO NOT USE
4751 for (offset = 0, regnum = V0_REGNUM;
4752 offset < TYPE_LENGTH (type);
4753 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4755 int xfer = REGISTER_RAW_SIZE (regnum);
4756 if (offset + xfer > TYPE_LENGTH (type))
4757 xfer = TYPE_LENGTH (type) - offset;
4759 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4760 offset, xfer, regnum);
4761 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4768 /* A scalar extract each part but least-significant-byte
4769 justified. o32 thinks registers are 4 byte, regardless of
4770 the ISA. mips_stack_argsize controls this. */
4773 for (offset = 0, regnum = V0_REGNUM;
4774 offset < TYPE_LENGTH (type);
4775 offset += mips_stack_argsize (), regnum++)
4777 int xfer = mips_stack_argsize ();
4779 if (offset + xfer > TYPE_LENGTH (type))
4780 xfer = TYPE_LENGTH (type) - offset;
4782 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4783 offset, xfer, regnum);
4784 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4791 mips_o32_extract_return_value (struct type *type,
4792 struct regcache *regcache,
4795 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4799 mips_o32_store_return_value (struct type *type, char *valbuf)
4801 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4804 /* N32/N44 ABI stuff. */
4807 mips_n32n64_xfer_return_value (struct type *type,
4808 struct regcache *regcache,
4809 bfd_byte *in, const bfd_byte *out)
4811 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4812 if (TYPE_CODE (type) == TYPE_CODE_FLT
4813 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4815 /* A floating-point value belongs in the least significant part
4818 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4819 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4820 TARGET_BYTE_ORDER, in, out, 0);
4822 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4823 && TYPE_NFIELDS (type) <= 2
4824 && TYPE_NFIELDS (type) >= 1
4825 && ((TYPE_NFIELDS (type) == 1
4826 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4828 || (TYPE_NFIELDS (type) == 2
4829 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4831 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4833 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4835 /* A struct that contains one or two floats. Each value is part
4836 in the least significant part of their floating point
4838 bfd_byte reg[MAX_REGISTER_SIZE];
4841 for (field = 0, regnum = FP0_REGNUM;
4842 field < TYPE_NFIELDS (type);
4843 field++, regnum += 2)
4845 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4848 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4849 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4850 TARGET_BYTE_ORDER, in, out, offset);
4853 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4854 || TYPE_CODE (type) == TYPE_CODE_UNION)
4856 /* A structure or union. Extract the left justified value,
4857 regardless of the byte order. I.e. DO NOT USE
4861 for (offset = 0, regnum = V0_REGNUM;
4862 offset < TYPE_LENGTH (type);
4863 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4865 int xfer = REGISTER_RAW_SIZE (regnum);
4866 if (offset + xfer > TYPE_LENGTH (type))
4867 xfer = TYPE_LENGTH (type) - offset;
4869 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4870 offset, xfer, regnum);
4871 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4877 /* A scalar extract each part but least-significant-byte
4881 for (offset = 0, regnum = V0_REGNUM;
4882 offset < TYPE_LENGTH (type);
4883 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4885 int xfer = REGISTER_RAW_SIZE (regnum);
4887 if (offset + xfer > TYPE_LENGTH (type))
4888 xfer = TYPE_LENGTH (type) - offset;
4890 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4891 offset, xfer, regnum);
4892 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4899 mips_n32n64_extract_return_value (struct type *type,
4900 struct regcache *regcache,
4903 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4907 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4909 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4913 mips_extract_struct_value_address (struct regcache *regcache)
4915 /* FIXME: This will only work at random. The caller passes the
4916 struct_return address in V0, but it is not preserved. It may
4917 still be there, or this may be a random value. */
4920 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4924 /* Exported procedure: Is PC in the signal trampoline code */
4927 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4929 if (sigtramp_address == 0)
4931 return (pc >= sigtramp_address && pc < sigtramp_end);
4934 /* Root of all "set mips "/"show mips " commands. This will eventually be
4935 used for all MIPS-specific commands. */
4938 show_mips_command (char *args, int from_tty)
4940 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4944 set_mips_command (char *args, int from_tty)
4946 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4947 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4950 /* Commands to show/set the MIPS FPU type. */
4953 show_mipsfpu_command (char *args, int from_tty)
4956 switch (MIPS_FPU_TYPE)
4958 case MIPS_FPU_SINGLE:
4959 fpu = "single-precision";
4961 case MIPS_FPU_DOUBLE:
4962 fpu = "double-precision";
4965 fpu = "absent (none)";
4968 internal_error (__FILE__, __LINE__, "bad switch");
4970 if (mips_fpu_type_auto)
4971 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4974 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
4980 set_mipsfpu_command (char *args, int from_tty)
4982 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
4983 show_mipsfpu_command (args, from_tty);
4987 set_mipsfpu_single_command (char *args, int from_tty)
4989 mips_fpu_type = MIPS_FPU_SINGLE;
4990 mips_fpu_type_auto = 0;
4991 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
4995 set_mipsfpu_double_command (char *args, int from_tty)
4997 mips_fpu_type = MIPS_FPU_DOUBLE;
4998 mips_fpu_type_auto = 0;
4999 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5003 set_mipsfpu_none_command (char *args, int from_tty)
5005 mips_fpu_type = MIPS_FPU_NONE;
5006 mips_fpu_type_auto = 0;
5007 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5011 set_mipsfpu_auto_command (char *args, int from_tty)
5013 mips_fpu_type_auto = 1;
5016 /* Command to set the processor type. */
5019 mips_set_processor_type_command (char *args, int from_tty)
5023 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5025 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5026 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5027 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5029 /* Restore the value. */
5030 tmp_mips_processor_type = xstrdup (mips_processor_type);
5035 if (!mips_set_processor_type (tmp_mips_processor_type))
5037 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5038 /* Restore its value. */
5039 tmp_mips_processor_type = xstrdup (mips_processor_type);
5044 mips_show_processor_type_command (char *args, int from_tty)
5048 /* Modify the actual processor type. */
5051 mips_set_processor_type (char *str)
5058 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5060 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5062 mips_processor_type = str;
5063 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5065 /* FIXME tweak fpu flag too */
5072 /* Attempt to identify the particular processor model by reading the
5076 mips_read_processor_type (void)
5080 prid = read_register (PRID_REGNUM);
5082 if ((prid & ~0xf) == 0x700)
5083 return savestring ("r3041", strlen ("r3041"));
5088 /* Just like reinit_frame_cache, but with the right arguments to be
5089 callable as an sfunc. */
5092 reinit_frame_cache_sfunc (char *args, int from_tty,
5093 struct cmd_list_element *c)
5095 reinit_frame_cache ();
5099 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5101 mips_extra_func_info_t proc_desc;
5103 /* Search for the function containing this address. Set the low bit
5104 of the address when searching, in case we were given an even address
5105 that is the start of a 16-bit function. If we didn't do this,
5106 the search would fail because the symbol table says the function
5107 starts at an odd address, i.e. 1 byte past the given address. */
5108 memaddr = ADDR_BITS_REMOVE (memaddr);
5109 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5111 /* Make an attempt to determine if this is a 16-bit function. If
5112 the procedure descriptor exists and the address therein is odd,
5113 it's definitely a 16-bit function. Otherwise, we have to just
5114 guess that if the address passed in is odd, it's 16-bits. */
5116 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5117 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5119 info->mach = pc_is_mips16 (memaddr) ?
5120 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5122 /* Round down the instruction address to the appropriate boundary. */
5123 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5125 /* Call the appropriate disassembler based on the target endian-ness. */
5126 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5127 return print_insn_big_mips (memaddr, info);
5129 return print_insn_little_mips (memaddr, info);
5132 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5133 counter value to determine whether a 16- or 32-bit breakpoint should be
5134 used. It returns a pointer to a string of bytes that encode a breakpoint
5135 instruction, stores the length of the string to *lenptr, and adjusts pc
5136 (if necessary) to point to the actual memory location where the
5137 breakpoint should be inserted. */
5139 static const unsigned char *
5140 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5142 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5144 if (pc_is_mips16 (*pcptr))
5146 static unsigned char mips16_big_breakpoint[] = {0xe8, 0xa5};
5147 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5148 *lenptr = sizeof (mips16_big_breakpoint);
5149 return mips16_big_breakpoint;
5153 /* The IDT board uses an unusual breakpoint value, and
5154 sometimes gets confused when it sees the usual MIPS
5155 breakpoint instruction. */
5156 static unsigned char big_breakpoint[] = {0, 0x5, 0, 0xd};
5157 static unsigned char pmon_big_breakpoint[] = {0, 0, 0, 0xd};
5158 static unsigned char idt_big_breakpoint[] = {0, 0, 0x0a, 0xd};
5160 *lenptr = sizeof (big_breakpoint);
5162 if (strcmp (target_shortname, "mips") == 0)
5163 return idt_big_breakpoint;
5164 else if (strcmp (target_shortname, "ddb") == 0
5165 || strcmp (target_shortname, "pmon") == 0
5166 || strcmp (target_shortname, "lsi") == 0)
5167 return pmon_big_breakpoint;
5169 return big_breakpoint;
5174 if (pc_is_mips16 (*pcptr))
5176 static unsigned char mips16_little_breakpoint[] = {0xa5, 0xe8};
5177 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5178 *lenptr = sizeof (mips16_little_breakpoint);
5179 return mips16_little_breakpoint;
5183 static unsigned char little_breakpoint[] = {0xd, 0, 0x5, 0};
5184 static unsigned char pmon_little_breakpoint[] = {0xd, 0, 0, 0};
5185 static unsigned char idt_little_breakpoint[] = {0xd, 0x0a, 0, 0};
5187 *lenptr = sizeof (little_breakpoint);
5189 if (strcmp (target_shortname, "mips") == 0)
5190 return idt_little_breakpoint;
5191 else if (strcmp (target_shortname, "ddb") == 0
5192 || strcmp (target_shortname, "pmon") == 0
5193 || strcmp (target_shortname, "lsi") == 0)
5194 return pmon_little_breakpoint;
5196 return little_breakpoint;
5201 /* If PC is in a mips16 call or return stub, return the address of the target
5202 PC, which is either the callee or the caller. There are several
5203 cases which must be handled:
5205 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5206 target PC is in $31 ($ra).
5207 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5208 and the target PC is in $2.
5209 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5210 before the jal instruction, this is effectively a call stub
5211 and the the target PC is in $2. Otherwise this is effectively
5212 a return stub and the target PC is in $18.
5214 See the source code for the stubs in gcc/config/mips/mips16.S for
5217 This function implements the SKIP_TRAMPOLINE_CODE macro.
5221 mips_skip_stub (CORE_ADDR pc)
5224 CORE_ADDR start_addr;
5226 /* Find the starting address and name of the function containing the PC. */
5227 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5230 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5231 target PC is in $31 ($ra). */
5232 if (strcmp (name, "__mips16_ret_sf") == 0
5233 || strcmp (name, "__mips16_ret_df") == 0)
5234 return read_signed_register (RA_REGNUM);
5236 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5238 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5239 and the target PC is in $2. */
5240 if (name[19] >= '0' && name[19] <= '9')
5241 return read_signed_register (2);
5243 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5244 before the jal instruction, this is effectively a call stub
5245 and the the target PC is in $2. Otherwise this is effectively
5246 a return stub and the target PC is in $18. */
5247 else if (name[19] == 's' || name[19] == 'd')
5249 if (pc == start_addr)
5251 /* Check if the target of the stub is a compiler-generated
5252 stub. Such a stub for a function bar might have a name
5253 like __fn_stub_bar, and might look like this:
5258 la $1,bar (becomes a lui/addiu pair)
5260 So scan down to the lui/addi and extract the target
5261 address from those two instructions. */
5263 CORE_ADDR target_pc = read_signed_register (2);
5267 /* See if the name of the target function is __fn_stub_*. */
5268 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5270 if (strncmp (name, "__fn_stub_", 10) != 0
5271 && strcmp (name, "etext") != 0
5272 && strcmp (name, "_etext") != 0)
5275 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5276 The limit on the search is arbitrarily set to 20
5277 instructions. FIXME. */
5278 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5280 inst = mips_fetch_instruction (target_pc);
5281 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5282 pc = (inst << 16) & 0xffff0000; /* high word */
5283 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5284 return pc | (inst & 0xffff); /* low word */
5287 /* Couldn't find the lui/addui pair, so return stub address. */
5291 /* This is the 'return' part of a call stub. The return
5292 address is in $r18. */
5293 return read_signed_register (18);
5296 return 0; /* not a stub */
5300 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5301 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5304 mips_in_call_stub (CORE_ADDR pc, char *name)
5306 CORE_ADDR start_addr;
5308 /* Find the starting address of the function containing the PC. If the
5309 caller didn't give us a name, look it up at the same time. */
5310 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5313 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5315 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5316 if (name[19] >= '0' && name[19] <= '9')
5318 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5319 before the jal instruction, this is effectively a call stub. */
5320 else if (name[19] == 's' || name[19] == 'd')
5321 return pc == start_addr;
5324 return 0; /* not a stub */
5328 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5329 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5332 mips_in_return_stub (CORE_ADDR pc, char *name)
5334 CORE_ADDR start_addr;
5336 /* Find the starting address of the function containing the PC. */
5337 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5340 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5341 if (strcmp (name, "__mips16_ret_sf") == 0
5342 || strcmp (name, "__mips16_ret_df") == 0)
5345 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5346 i.e. after the jal instruction, this is effectively a return stub. */
5347 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5348 && (name[19] == 's' || name[19] == 'd')
5349 && pc != start_addr)
5352 return 0; /* not a stub */
5356 /* Return non-zero if the PC is in a library helper function that should
5357 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5360 mips_ignore_helper (CORE_ADDR pc)
5364 /* Find the starting address and name of the function containing the PC. */
5365 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5368 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5369 that we want to ignore. */
5370 return (strcmp (name, "__mips16_ret_sf") == 0
5371 || strcmp (name, "__mips16_ret_df") == 0);
5375 /* Return a location where we can set a breakpoint that will be hit
5376 when an inferior function call returns. This is normally the
5377 program's entry point. Executables that don't have an entry
5378 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5379 whose address is the location where the breakpoint should be placed. */
5382 mips_call_dummy_address (void)
5384 struct minimal_symbol *sym;
5386 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5388 return SYMBOL_VALUE_ADDRESS (sym);
5390 return entry_point_address ();
5394 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5395 the register stored on the stack (32) is different to its real raw
5396 size (64). The below ensures that registers are fetched from the
5397 stack using their ABI size and then stored into the RAW_BUFFER
5398 using their raw size.
5400 The alternative to adding this function would be to add an ABI
5401 macro - REGISTER_STACK_SIZE(). */
5404 mips_get_saved_register (char *raw_buffer,
5407 struct frame_info *frame,
5409 enum lval_type *lvalp)
5412 enum lval_type lvalx;
5415 if (!target_has_registers)
5416 error ("No registers.");
5418 /* Make certain that all needed parameters are present. */
5423 if (optimizedp == NULL)
5424 optimizedp = &optimizedx;
5425 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5427 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5428 have a pseudo register range that correspons to the ABI's, rather
5429 than the ISA's, view of registers. These registers would then
5430 implicitly describe their size and hence could be used without
5431 the below munging. */
5432 if ((*lvalp) == lval_memory)
5434 if (raw_buffer != NULL)
5438 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5440 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5441 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5447 /* Immediately after a function call, return the saved pc.
5448 Can't always go through the frames for this because on some machines
5449 the new frame is not set up until the new function executes
5450 some instructions. */
5453 mips_saved_pc_after_call (struct frame_info *frame)
5455 return read_signed_register (RA_REGNUM);
5459 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5463 mips_stab_reg_to_regnum (int num)
5465 if (num >= 0 && num < 32)
5467 else if (num >= 38 && num < 70)
5468 return num + FP0_REGNUM - 38;
5475 /* This will hopefully (eventually) provoke a warning. Should
5476 we be calling complaint() here? */
5477 return NUM_REGS + NUM_PSEUDO_REGS;
5482 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5485 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5487 if (num >= 0 && num < 32)
5489 else if (num >= 32 && num < 64)
5490 return num + FP0_REGNUM - 32;
5497 /* This will hopefully (eventually) provoke a warning. Should
5498 we be calling complaint() here? */
5499 return NUM_REGS + NUM_PSEUDO_REGS;
5504 /* Convert an integer into an address. By first converting the value
5505 into a pointer and then extracting it signed, the address is
5506 guarenteed to be correctly sign extended. */
5509 mips_integer_to_address (struct type *type, void *buf)
5511 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5512 LONGEST val = unpack_long (type, buf);
5513 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5514 return extract_signed_integer (tmp,
5515 TYPE_LENGTH (builtin_type_void_data_ptr));
5519 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5521 enum mips_abi *abip = (enum mips_abi *) obj;
5522 const char *name = bfd_get_section_name (abfd, sect);
5524 if (*abip != MIPS_ABI_UNKNOWN)
5527 if (strncmp (name, ".mdebug.", 8) != 0)
5530 if (strcmp (name, ".mdebug.abi32") == 0)
5531 *abip = MIPS_ABI_O32;
5532 else if (strcmp (name, ".mdebug.abiN32") == 0)
5533 *abip = MIPS_ABI_N32;
5534 else if (strcmp (name, ".mdebug.abi64") == 0)
5535 *abip = MIPS_ABI_N64;
5536 else if (strcmp (name, ".mdebug.abiO64") == 0)
5537 *abip = MIPS_ABI_O64;
5538 else if (strcmp (name, ".mdebug.eabi32") == 0)
5539 *abip = MIPS_ABI_EABI32;
5540 else if (strcmp (name, ".mdebug.eabi64") == 0)
5541 *abip = MIPS_ABI_EABI64;
5543 warning ("unsupported ABI %s.", name + 8);
5546 static enum mips_abi
5547 global_mips_abi (void)
5551 for (i = 0; mips_abi_strings[i] != NULL; i++)
5552 if (mips_abi_strings[i] == mips_abi_string)
5553 return (enum mips_abi) i;
5555 internal_error (__FILE__, __LINE__,
5556 "unknown ABI string");
5559 static struct gdbarch *
5560 mips_gdbarch_init (struct gdbarch_info info,
5561 struct gdbarch_list *arches)
5563 struct gdbarch *gdbarch;
5564 struct gdbarch_tdep *tdep;
5566 enum mips_abi mips_abi, found_abi, wanted_abi;
5568 /* Reset the disassembly info, in case it was set to something
5570 deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5571 deprecated_tm_print_insn_info.arch = bfd_arch_unknown;
5572 deprecated_tm_print_insn_info.mach = 0;
5578 /* First of all, extract the elf_flags, if available. */
5579 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5580 elf_flags = elf_elfheader (info.abfd)->e_flags;
5583 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5584 switch ((elf_flags & EF_MIPS_ABI))
5586 case E_MIPS_ABI_O32:
5587 mips_abi = MIPS_ABI_O32;
5589 case E_MIPS_ABI_O64:
5590 mips_abi = MIPS_ABI_O64;
5592 case E_MIPS_ABI_EABI32:
5593 mips_abi = MIPS_ABI_EABI32;
5595 case E_MIPS_ABI_EABI64:
5596 mips_abi = MIPS_ABI_EABI64;
5599 if ((elf_flags & EF_MIPS_ABI2))
5600 mips_abi = MIPS_ABI_N32;
5602 mips_abi = MIPS_ABI_UNKNOWN;
5606 /* GCC creates a pseudo-section whose name describes the ABI. */
5607 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5608 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5610 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5611 Use the ABI from the last architecture if there is one. */
5612 if (info.abfd == NULL && arches != NULL)
5613 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5615 /* Try the architecture for any hint of the correct ABI. */
5616 if (mips_abi == MIPS_ABI_UNKNOWN
5617 && info.bfd_arch_info != NULL
5618 && info.bfd_arch_info->arch == bfd_arch_mips)
5620 switch (info.bfd_arch_info->mach)
5622 case bfd_mach_mips3900:
5623 mips_abi = MIPS_ABI_EABI32;
5625 case bfd_mach_mips4100:
5626 case bfd_mach_mips5000:
5627 mips_abi = MIPS_ABI_EABI64;
5629 case bfd_mach_mips8000:
5630 case bfd_mach_mips10000:
5631 /* On Irix, ELF64 executables use the N64 ABI. The
5632 pseudo-sections which describe the ABI aren't present
5633 on IRIX. (Even for executables created by gcc.) */
5634 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5635 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5636 mips_abi = MIPS_ABI_N64;
5638 mips_abi = MIPS_ABI_N32;
5643 if (mips_abi == MIPS_ABI_UNKNOWN)
5644 mips_abi = MIPS_ABI_O32;
5646 /* Now that we have found what the ABI for this binary would be,
5647 check whether the user is overriding it. */
5648 found_abi = mips_abi;
5649 wanted_abi = global_mips_abi ();
5650 if (wanted_abi != MIPS_ABI_UNKNOWN)
5651 mips_abi = wanted_abi;
5653 /* We have to set deprecated_tm_print_insn_info before looking for a
5654 pre-existing architecture, otherwise we may return before we get
5655 a chance to set it up. */
5656 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5658 /* Set up the disassembler info, so that we get the right
5659 register names from libopcodes. */
5660 if (mips_abi == MIPS_ABI_N32)
5661 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=n32";
5663 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=64";
5664 deprecated_tm_print_insn_info.flavour = bfd_target_elf_flavour;
5665 deprecated_tm_print_insn_info.arch = bfd_arch_mips;
5666 if (info.bfd_arch_info != NULL
5667 && info.bfd_arch_info->arch == bfd_arch_mips
5668 && info.bfd_arch_info->mach)
5669 deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
5671 deprecated_tm_print_insn_info.mach = bfd_mach_mips8000;
5674 /* This string is not recognized explicitly by the disassembler,
5675 but it tells the disassembler to not try to guess the ABI from
5676 the bfd elf headers, such that, if the user overrides the ABI
5677 of a program linked as NewABI, the disassembly will follow the
5678 register naming conventions specified by the user. */
5679 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=32";
5683 fprintf_unfiltered (gdb_stdlog,
5684 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5686 fprintf_unfiltered (gdb_stdlog,
5687 "mips_gdbarch_init: mips_abi = %d\n",
5689 fprintf_unfiltered (gdb_stdlog,
5690 "mips_gdbarch_init: found_mips_abi = %d\n",
5694 /* try to find a pre-existing architecture */
5695 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5697 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5699 /* MIPS needs to be pedantic about which ABI the object is
5701 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5703 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5705 return arches->gdbarch;
5708 /* Need a new architecture. Fill in a target specific vector. */
5709 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5710 gdbarch = gdbarch_alloc (&info, tdep);
5711 tdep->elf_flags = elf_flags;
5713 /* Initially set everything according to the default ABI/ISA. */
5714 set_gdbarch_short_bit (gdbarch, 16);
5715 set_gdbarch_int_bit (gdbarch, 32);
5716 set_gdbarch_float_bit (gdbarch, 32);
5717 set_gdbarch_double_bit (gdbarch, 64);
5718 set_gdbarch_long_double_bit (gdbarch, 64);
5719 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5720 tdep->found_abi = found_abi;
5721 tdep->mips_abi = mips_abi;
5723 set_gdbarch_elf_make_msymbol_special (gdbarch,
5724 mips_elf_make_msymbol_special);
5726 if (info.osabi == GDB_OSABI_IRIX)
5727 set_gdbarch_num_regs (gdbarch, 71);
5729 set_gdbarch_num_regs (gdbarch, 90);
5734 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5735 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5736 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5737 tdep->mips_default_saved_regsize = 4;
5738 tdep->mips_default_stack_argsize = 4;
5739 tdep->mips_fp_register_double = 0;
5740 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5741 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5742 tdep->gdb_target_is_mips64 = 0;
5743 tdep->default_mask_address_p = 0;
5744 set_gdbarch_long_bit (gdbarch, 32);
5745 set_gdbarch_ptr_bit (gdbarch, 32);
5746 set_gdbarch_long_long_bit (gdbarch, 64);
5747 set_gdbarch_reg_struct_has_addr (gdbarch,
5748 mips_o32_reg_struct_has_addr);
5749 set_gdbarch_use_struct_convention (gdbarch,
5750 mips_o32_use_struct_convention);
5753 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5754 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5755 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5756 tdep->mips_default_saved_regsize = 8;
5757 tdep->mips_default_stack_argsize = 8;
5758 tdep->mips_fp_register_double = 1;
5759 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5760 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5761 tdep->gdb_target_is_mips64 = 1;
5762 tdep->default_mask_address_p = 0;
5763 set_gdbarch_long_bit (gdbarch, 32);
5764 set_gdbarch_ptr_bit (gdbarch, 32);
5765 set_gdbarch_long_long_bit (gdbarch, 64);
5766 set_gdbarch_reg_struct_has_addr (gdbarch,
5767 mips_o32_reg_struct_has_addr);
5768 set_gdbarch_use_struct_convention (gdbarch,
5769 mips_o32_use_struct_convention);
5771 case MIPS_ABI_EABI32:
5772 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5773 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5774 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5775 tdep->mips_default_saved_regsize = 4;
5776 tdep->mips_default_stack_argsize = 4;
5777 tdep->mips_fp_register_double = 0;
5778 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5779 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5780 tdep->gdb_target_is_mips64 = 0;
5781 tdep->default_mask_address_p = 0;
5782 set_gdbarch_long_bit (gdbarch, 32);
5783 set_gdbarch_ptr_bit (gdbarch, 32);
5784 set_gdbarch_long_long_bit (gdbarch, 64);
5785 set_gdbarch_reg_struct_has_addr (gdbarch,
5786 mips_eabi_reg_struct_has_addr);
5787 set_gdbarch_use_struct_convention (gdbarch,
5788 mips_eabi_use_struct_convention);
5790 case MIPS_ABI_EABI64:
5791 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5792 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5793 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5794 tdep->mips_default_saved_regsize = 8;
5795 tdep->mips_default_stack_argsize = 8;
5796 tdep->mips_fp_register_double = 1;
5797 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5798 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5799 tdep->gdb_target_is_mips64 = 1;
5800 tdep->default_mask_address_p = 0;
5801 set_gdbarch_long_bit (gdbarch, 64);
5802 set_gdbarch_ptr_bit (gdbarch, 64);
5803 set_gdbarch_long_long_bit (gdbarch, 64);
5804 set_gdbarch_reg_struct_has_addr (gdbarch,
5805 mips_eabi_reg_struct_has_addr);
5806 set_gdbarch_use_struct_convention (gdbarch,
5807 mips_eabi_use_struct_convention);
5810 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5811 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5812 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5813 tdep->mips_default_saved_regsize = 8;
5814 tdep->mips_default_stack_argsize = 8;
5815 tdep->mips_fp_register_double = 1;
5816 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5817 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5818 tdep->gdb_target_is_mips64 = 1;
5819 tdep->default_mask_address_p = 0;
5820 set_gdbarch_long_bit (gdbarch, 32);
5821 set_gdbarch_ptr_bit (gdbarch, 32);
5822 set_gdbarch_long_long_bit (gdbarch, 64);
5823 set_gdbarch_use_struct_convention (gdbarch,
5824 mips_n32n64_use_struct_convention);
5825 set_gdbarch_reg_struct_has_addr (gdbarch,
5826 mips_n32n64_reg_struct_has_addr);
5829 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5830 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5831 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5832 tdep->mips_default_saved_regsize = 8;
5833 tdep->mips_default_stack_argsize = 8;
5834 tdep->mips_fp_register_double = 1;
5835 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5836 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5837 tdep->gdb_target_is_mips64 = 1;
5838 tdep->default_mask_address_p = 0;
5839 set_gdbarch_long_bit (gdbarch, 64);
5840 set_gdbarch_ptr_bit (gdbarch, 64);
5841 set_gdbarch_long_long_bit (gdbarch, 64);
5842 set_gdbarch_use_struct_convention (gdbarch,
5843 mips_n32n64_use_struct_convention);
5844 set_gdbarch_reg_struct_has_addr (gdbarch,
5845 mips_n32n64_reg_struct_has_addr);
5848 internal_error (__FILE__, __LINE__,
5849 "unknown ABI in switch");
5852 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5853 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5856 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5857 flag in object files because to do so would make it impossible to
5858 link with libraries compiled without "-gp32". This is
5859 unnecessarily restrictive.
5861 We could solve this problem by adding "-gp32" multilibs to gcc,
5862 but to set this flag before gcc is built with such multilibs will
5863 break too many systems.''
5865 But even more unhelpfully, the default linker output target for
5866 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5867 for 64-bit programs - you need to change the ABI to change this,
5868 and not all gcc targets support that currently. Therefore using
5869 this flag to detect 32-bit mode would do the wrong thing given
5870 the current gcc - it would make GDB treat these 64-bit programs
5871 as 32-bit programs by default. */
5873 /* enable/disable the MIPS FPU */
5874 if (!mips_fpu_type_auto)
5875 tdep->mips_fpu_type = mips_fpu_type;
5876 else if (info.bfd_arch_info != NULL
5877 && info.bfd_arch_info->arch == bfd_arch_mips)
5878 switch (info.bfd_arch_info->mach)
5880 case bfd_mach_mips3900:
5881 case bfd_mach_mips4100:
5882 case bfd_mach_mips4111:
5883 tdep->mips_fpu_type = MIPS_FPU_NONE;
5885 case bfd_mach_mips4650:
5886 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5889 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5893 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5895 /* MIPS version of register names. NOTE: At present the MIPS
5896 register name management is part way between the old -
5897 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5898 Further work on it is required. */
5899 /* NOTE: many targets (esp. embedded) do not go thru the
5900 gdbarch_register_name vector at all, instead bypassing it
5901 by defining REGISTER_NAMES. */
5902 set_gdbarch_register_name (gdbarch, mips_register_name);
5903 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5904 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5905 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5906 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5907 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
5909 /* Add/remove bits from an address. The MIPS needs be careful to
5910 ensure that all 32 bit addresses are sign extended to 64 bits. */
5911 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5913 /* There's a mess in stack frame creation. See comments in
5914 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5915 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5916 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5918 /* Map debug register numbers onto internal register numbers. */
5919 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5920 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5921 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5922 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5924 /* Initialize a frame */
5925 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5926 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5928 /* MIPS version of CALL_DUMMY */
5930 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5931 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
5932 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5933 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5934 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
5935 set_gdbarch_register_convert_to_virtual (gdbarch,
5936 mips_register_convert_to_virtual);
5937 set_gdbarch_register_convert_to_raw (gdbarch,
5938 mips_register_convert_to_raw);
5940 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
5941 set_gdbarch_frameless_function_invocation (gdbarch,
5942 generic_frameless_function_invocation_not);
5943 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5944 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
5945 set_gdbarch_frame_args_skip (gdbarch, 0);
5947 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
5949 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5950 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5951 set_gdbarch_decr_pc_after_break (gdbarch, 0);
5953 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5954 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
5956 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5957 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5958 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5960 set_gdbarch_function_start_offset (gdbarch, 0);
5962 /* There are MIPS targets which do not yet use this since they still
5963 define REGISTER_VIRTUAL_TYPE. */
5964 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
5966 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
5967 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
5969 /* Hook in OS ABI-specific overrides, if they have been registered. */
5970 gdbarch_init_osabi (info, gdbarch);
5972 set_gdbarch_extract_struct_value_address (gdbarch,
5973 mips_extract_struct_value_address);
5975 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
5977 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
5978 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
5984 mips_abi_update (char *ignore_args, int from_tty,
5985 struct cmd_list_element *c)
5987 struct gdbarch_info info;
5989 /* Force the architecture to update, and (if it's a MIPS architecture)
5990 mips_gdbarch_init will take care of the rest. */
5991 gdbarch_info_init (&info);
5992 gdbarch_update_p (info);
5995 /* Print out which MIPS ABI is in use. */
5998 show_mips_abi (char *ignore_args, int from_tty)
6000 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6002 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6005 enum mips_abi global_abi = global_mips_abi ();
6006 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6007 const char *actual_abi_str = mips_abi_strings[actual_abi];
6009 if (global_abi == MIPS_ABI_UNKNOWN)
6010 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6012 else if (global_abi == actual_abi)
6014 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6018 /* Probably shouldn't happen... */
6020 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6022 mips_abi_strings[global_abi]);
6028 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6030 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6034 int ef_mips_32bitmode;
6035 /* determine the ISA */
6036 switch (tdep->elf_flags & EF_MIPS_ARCH)
6054 /* determine the size of a pointer */
6055 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6056 fprintf_unfiltered (file,
6057 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6059 fprintf_unfiltered (file,
6060 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6062 fprintf_unfiltered (file,
6063 "mips_dump_tdep: ef_mips_arch = %d\n",
6065 fprintf_unfiltered (file,
6066 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6068 mips_abi_strings[tdep->mips_abi]);
6069 fprintf_unfiltered (file,
6070 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6071 mips_mask_address_p (),
6072 tdep->default_mask_address_p);
6074 fprintf_unfiltered (file,
6075 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6076 FP_REGISTER_DOUBLE);
6077 fprintf_unfiltered (file,
6078 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6079 MIPS_DEFAULT_FPU_TYPE,
6080 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6081 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6082 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6084 fprintf_unfiltered (file,
6085 "mips_dump_tdep: MIPS_EABI = %d\n",
6087 fprintf_unfiltered (file,
6088 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6089 MIPS_LAST_FP_ARG_REGNUM,
6090 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6091 fprintf_unfiltered (file,
6092 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6094 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6095 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6096 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6098 fprintf_unfiltered (file,
6099 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6100 MIPS_DEFAULT_SAVED_REGSIZE);
6101 fprintf_unfiltered (file,
6102 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6103 FP_REGISTER_DOUBLE);
6104 fprintf_unfiltered (file,
6105 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6106 MIPS_DEFAULT_STACK_ARGSIZE);
6107 fprintf_unfiltered (file,
6108 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6109 MIPS_STACK_ARGSIZE);
6110 fprintf_unfiltered (file,
6111 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6113 fprintf_unfiltered (file,
6114 "mips_dump_tdep: A0_REGNUM = %d\n",
6116 fprintf_unfiltered (file,
6117 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6118 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6119 fprintf_unfiltered (file,
6120 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6121 XSTRING (ATTACH_DETACH));
6122 fprintf_unfiltered (file,
6123 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6125 fprintf_unfiltered (file,
6126 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6128 fprintf_unfiltered (file,
6129 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6130 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6131 fprintf_unfiltered (file,
6132 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6133 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6134 fprintf_unfiltered (file,
6135 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6137 fprintf_unfiltered (file,
6138 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6140 fprintf_unfiltered (file,
6141 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6142 FIRST_EMBED_REGNUM);
6143 fprintf_unfiltered (file,
6144 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6146 fprintf_unfiltered (file,
6147 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6148 GDB_TARGET_IS_MIPS64);
6149 fprintf_unfiltered (file,
6150 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6151 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6152 fprintf_unfiltered (file,
6153 "mips_dump_tdep: HI_REGNUM = %d\n",
6155 fprintf_unfiltered (file,
6156 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6157 XSTRING (IGNORE_HELPER_CALL (PC)));
6158 fprintf_unfiltered (file,
6159 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6160 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6161 fprintf_unfiltered (file,
6162 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6163 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6164 fprintf_unfiltered (file,
6165 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6166 fprintf_unfiltered (file,
6167 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6169 fprintf_unfiltered (file,
6170 "mips_dump_tdep: LO_REGNUM = %d\n",
6172 #ifdef MACHINE_CPROC_FP_OFFSET
6173 fprintf_unfiltered (file,
6174 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6175 MACHINE_CPROC_FP_OFFSET);
6177 #ifdef MACHINE_CPROC_PC_OFFSET
6178 fprintf_unfiltered (file,
6179 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6180 MACHINE_CPROC_PC_OFFSET);
6182 #ifdef MACHINE_CPROC_SP_OFFSET
6183 fprintf_unfiltered (file,
6184 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6185 MACHINE_CPROC_SP_OFFSET);
6187 fprintf_unfiltered (file,
6188 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6189 fprintf_unfiltered (file,
6190 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6192 fprintf_unfiltered (file,
6193 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6194 fprintf_unfiltered (file,
6195 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6196 fprintf_unfiltered (file,
6197 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6199 fprintf_unfiltered (file,
6200 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6201 MIPS_LAST_ARG_REGNUM,
6202 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6203 fprintf_unfiltered (file,
6204 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6206 fprintf_unfiltered (file,
6207 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6208 fprintf_unfiltered (file,
6209 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6210 MIPS_SAVED_REGSIZE);
6211 fprintf_unfiltered (file,
6212 "mips_dump_tdep: OP_LDFPR = used?\n");
6213 fprintf_unfiltered (file,
6214 "mips_dump_tdep: OP_LDGPR = used?\n");
6215 fprintf_unfiltered (file,
6216 "mips_dump_tdep: PRID_REGNUM = %d\n",
6218 fprintf_unfiltered (file,
6219 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6220 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6221 fprintf_unfiltered (file,
6222 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6223 fprintf_unfiltered (file,
6224 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6225 fprintf_unfiltered (file,
6226 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6227 fprintf_unfiltered (file,
6228 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6229 fprintf_unfiltered (file,
6230 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6231 fprintf_unfiltered (file,
6232 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6233 fprintf_unfiltered (file,
6234 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6237 fprintf_unfiltered (file,
6238 "mips_dump_tdep: PROC_PC_REG = function?\n");
6239 fprintf_unfiltered (file,
6240 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6241 fprintf_unfiltered (file,
6242 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6243 fprintf_unfiltered (file,
6244 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6245 fprintf_unfiltered (file,
6246 "mips_dump_tdep: PS_REGNUM = %d\n",
6248 fprintf_unfiltered (file,
6249 "mips_dump_tdep: RA_REGNUM = %d\n",
6251 fprintf_unfiltered (file,
6252 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6253 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6254 fprintf_unfiltered (file,
6255 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6256 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6257 fprintf_unfiltered (file,
6258 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6259 fprintf_unfiltered (file,
6260 "mips_dump_tdep: ROUND_DOWN = function?\n");
6261 fprintf_unfiltered (file,
6262 "mips_dump_tdep: ROUND_UP = function?\n");
6264 fprintf_unfiltered (file,
6265 "mips_dump_tdep: SAVED_BYTES = %d\n",
6269 fprintf_unfiltered (file,
6270 "mips_dump_tdep: SAVED_FP = %d\n",
6274 fprintf_unfiltered (file,
6275 "mips_dump_tdep: SAVED_PC = %d\n",
6278 fprintf_unfiltered (file,
6279 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6280 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6281 fprintf_unfiltered (file,
6282 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6283 fprintf_unfiltered (file,
6284 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6286 fprintf_unfiltered (file,
6287 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6288 SIGFRAME_FPREGSAVE_OFF);
6289 fprintf_unfiltered (file,
6290 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6292 fprintf_unfiltered (file,
6293 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6294 SIGFRAME_REGSAVE_OFF);
6295 fprintf_unfiltered (file,
6296 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6298 fprintf_unfiltered (file,
6299 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6300 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6301 fprintf_unfiltered (file,
6302 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6303 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6304 fprintf_unfiltered (file,
6305 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6306 SOFTWARE_SINGLE_STEP_P ());
6307 fprintf_unfiltered (file,
6308 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6309 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6310 #ifdef STACK_END_ADDR
6311 fprintf_unfiltered (file,
6312 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6315 fprintf_unfiltered (file,
6316 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6317 XSTRING (STEP_SKIPS_DELAY (PC)));
6318 fprintf_unfiltered (file,
6319 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6320 STEP_SKIPS_DELAY_P);
6321 fprintf_unfiltered (file,
6322 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6323 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6324 fprintf_unfiltered (file,
6325 "mips_dump_tdep: T9_REGNUM = %d\n",
6327 fprintf_unfiltered (file,
6328 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6329 fprintf_unfiltered (file,
6330 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6331 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6332 fprintf_unfiltered (file,
6333 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6334 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6335 fprintf_unfiltered (file,
6336 "mips_dump_tdep: TARGET_MIPS = used?\n");
6337 fprintf_unfiltered (file,
6338 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6339 XSTRING (TM_PRINT_INSN_MACH));
6341 fprintf_unfiltered (file,
6342 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6343 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6350 #ifdef TRACE_FLAVOR_SIZE
6351 fprintf_unfiltered (file,
6352 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6356 fprintf_unfiltered (file,
6357 "mips_dump_tdep: TRACE_SET # %s\n",
6358 XSTRING (TRACE_SET (X,STATE)));
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6362 #ifdef UNUSED_REGNUM
6363 fprintf_unfiltered (file,
6364 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6367 fprintf_unfiltered (file,
6368 "mips_dump_tdep: V0_REGNUM = %d\n",
6370 fprintf_unfiltered (file,
6371 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6372 (long) VM_MIN_ADDRESS);
6374 fprintf_unfiltered (file,
6375 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6378 fprintf_unfiltered (file,
6379 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6381 fprintf_unfiltered (file,
6382 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6387 _initialize_mips_tdep (void)
6389 static struct cmd_list_element *mipsfpulist = NULL;
6390 struct cmd_list_element *c;
6392 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6393 if (MIPS_ABI_LAST + 1
6394 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6395 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6397 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6398 if (!deprecated_tm_print_insn) /* Someone may have already set it */
6399 deprecated_tm_print_insn = gdb_print_insn_mips;
6401 /* Add root prefix command for all "set mips"/"show mips" commands */
6402 add_prefix_cmd ("mips", no_class, set_mips_command,
6403 "Various MIPS specific commands.",
6404 &setmipscmdlist, "set mips ", 0, &setlist);
6406 add_prefix_cmd ("mips", no_class, show_mips_command,
6407 "Various MIPS specific commands.",
6408 &showmipscmdlist, "show mips ", 0, &showlist);
6410 /* Allow the user to override the saved register size. */
6411 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6414 &mips_saved_regsize_string, "\
6415 Set size of general purpose registers saved on the stack.\n\
6416 This option can be set to one of:\n\
6417 32 - Force GDB to treat saved GP registers as 32-bit\n\
6418 64 - Force GDB to treat saved GP registers as 64-bit\n\
6419 auto - Allow GDB to use the target's default setting or autodetect the\n\
6420 saved GP register size from information contained in the executable.\n\
6425 /* Allow the user to override the argument stack size. */
6426 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6429 &mips_stack_argsize_string, "\
6430 Set the amount of stack space reserved for each argument.\n\
6431 This option can be set to one of:\n\
6432 32 - Force GDB to allocate 32-bit chunks per argument\n\
6433 64 - Force GDB to allocate 64-bit chunks per argument\n\
6434 auto - Allow GDB to determine the correct setting from the current\n\
6435 target and executable (default)",
6439 /* Allow the user to override the ABI. */
6440 c = add_set_enum_cmd
6441 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6442 "Set the ABI used by this program.\n"
6443 "This option can be set to one of:\n"
6444 " auto - the default ABI associated with the current binary\n"
6452 set_cmd_sfunc (c, mips_abi_update);
6453 add_cmd ("abi", class_obscure, show_mips_abi,
6454 "Show ABI in use by MIPS target", &showmipscmdlist);
6456 /* Let the user turn off floating point and set the fence post for
6457 heuristic_proc_start. */
6459 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6460 "Set use of MIPS floating-point coprocessor.",
6461 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6462 add_cmd ("single", class_support, set_mipsfpu_single_command,
6463 "Select single-precision MIPS floating-point coprocessor.",
6465 add_cmd ("double", class_support, set_mipsfpu_double_command,
6466 "Select double-precision MIPS floating-point coprocessor.",
6468 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6469 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6470 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6471 add_cmd ("none", class_support, set_mipsfpu_none_command,
6472 "Select no MIPS floating-point coprocessor.",
6474 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6475 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6476 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6477 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6478 "Select MIPS floating-point coprocessor automatically.",
6480 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6481 "Show current use of MIPS floating-point coprocessor target.",
6484 /* We really would like to have both "0" and "unlimited" work, but
6485 command.c doesn't deal with that. So make it a var_zinteger
6486 because the user can always use "999999" or some such for unlimited. */
6487 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6488 (char *) &heuristic_fence_post,
6490 Set the distance searched for the start of a function.\n\
6491 If you are debugging a stripped executable, GDB needs to search through the\n\
6492 program for the start of a function. This command sets the distance of the\n\
6493 search. The only need to set it is when debugging a stripped executable.",
6495 /* We need to throw away the frame cache when we set this, since it
6496 might change our ability to get backtraces. */
6497 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6498 add_show_from_set (c, &showlist);
6500 /* Allow the user to control whether the upper bits of 64-bit
6501 addresses should be zeroed. */
6502 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6503 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6504 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6505 allow GDB to determine the correct value.\n", "\
6506 Show zeroing of upper 32 bits of 64-bit addresses.",
6507 NULL, show_mask_address,
6508 &setmipscmdlist, &showmipscmdlist);
6510 /* Allow the user to control the size of 32 bit registers within the
6511 raw remote packet. */
6512 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6515 (char *)&mips64_transfers_32bit_regs_p, "\
6516 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6517 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6518 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6519 64 bits for others. Use \"off\" to disable compatibility mode",
6523 /* Debug this files internals. */
6524 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6525 &mips_debug, "Set mips debugging.\n\
6526 When non-zero, mips specific debugging is enabled.", &setdebuglist),