1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
40 #include "arch-utils.h"
43 #include "mips-tdep.h"
46 #include "opcode/mips.h"
51 /* A useful bit in the CP0 status register (PS_REGNUM). */
52 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
53 #define ST0_FR (1 << 26)
55 /* The sizes of floating point registers. */
59 MIPS_FPU_SINGLE_REGSIZE = 4,
60 MIPS_FPU_DOUBLE_REGSIZE = 8
64 static const char *mips_abi_string;
66 static const char *mips_abi_strings[] = {
77 struct frame_extra_info
79 mips_extra_func_info_t proc_desc;
83 /* Various MIPS ISA options (related to stack analysis) can be
84 overridden dynamically. Establish an enum/array for managing
87 static const char size_auto[] = "auto";
88 static const char size_32[] = "32";
89 static const char size_64[] = "64";
91 static const char *size_enums[] = {
98 /* Some MIPS boards don't support floating point while others only
99 support single-precision floating-point operations. See also
100 FP_REGISTER_DOUBLE. */
104 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
105 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
106 MIPS_FPU_NONE /* No floating point. */
109 #ifndef MIPS_DEFAULT_FPU_TYPE
110 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
112 static int mips_fpu_type_auto = 1;
113 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
115 static int mips_debug = 0;
117 /* MIPS specific per-architecture information */
120 /* from the elf header */
124 enum mips_abi mips_abi;
125 enum mips_abi found_abi;
126 enum mips_fpu_type mips_fpu_type;
127 int mips_last_arg_regnum;
128 int mips_last_fp_arg_regnum;
129 int mips_default_saved_regsize;
130 int mips_fp_register_double;
131 int mips_default_stack_argsize;
132 int gdb_target_is_mips64;
133 int default_mask_address_p;
136 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
137 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
139 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
141 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
143 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
145 /* Return the currently configured (or set) saved register size. */
147 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
149 static const char *mips_saved_regsize_string = size_auto;
151 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
153 /* Return the contents of register REGNUM as a signed integer. */
156 read_signed_register (int regnum)
158 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
159 deprecated_read_register_gen (regnum, buf);
160 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
164 read_signed_register_pid (int regnum, ptid_t ptid)
169 if (ptid_equal (ptid, inferior_ptid))
170 return read_signed_register (regnum);
172 save_ptid = inferior_ptid;
174 inferior_ptid = ptid;
176 retval = read_signed_register (regnum);
178 inferior_ptid = save_ptid;
183 /* Return the MIPS ABI associated with GDBARCH. */
185 mips_abi (struct gdbarch *gdbarch)
187 return gdbarch_tdep (gdbarch)->mips_abi;
191 mips_saved_regsize (void)
193 if (mips_saved_regsize_string == size_auto)
194 return MIPS_DEFAULT_SAVED_REGSIZE;
195 else if (mips_saved_regsize_string == size_64)
197 else /* if (mips_saved_regsize_string == size_32) */
201 /* Functions for setting and testing a bit in a minimal symbol that
202 marks it as 16-bit function. The MSB of the minimal symbol's
203 "info" field is used for this purpose. This field is already
204 being used to store the symbol size, so the assumption is
205 that the symbol size cannot exceed 2^31.
207 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
208 i.e. refers to a 16-bit function, and sets a "special" bit in a
209 minimal symbol to mark it as a 16-bit function
211 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
212 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
213 the "info" field with the "special" bit masked out */
216 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
218 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
220 MSYMBOL_INFO (msym) = (char *)
221 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
222 SYMBOL_VALUE_ADDRESS (msym) |= 1;
227 msymbol_is_special (struct minimal_symbol *msym)
229 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
233 msymbol_size (struct minimal_symbol *msym)
235 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
238 /* XFER a value from the big/little/left end of the register.
239 Depending on the size of the value it might occupy the entire
240 register or just part of it. Make an allowance for this, aligning
241 things accordingly. */
244 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
245 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
248 bfd_byte reg[MAX_REGISTER_SIZE];
250 /* Need to transfer the left or right part of the register, based on
251 the targets byte order. */
255 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
257 case BFD_ENDIAN_LITTLE:
260 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
264 internal_error (__FILE__, __LINE__, "bad switch");
267 fprintf_unfiltered (gdb_stderr,
268 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
269 reg_num, reg_offset, buf_offset, length);
270 if (mips_debug && out != NULL)
273 fprintf_unfiltered (gdb_stdlog, "out ");
274 for (i = 0; i < length; i++)
275 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
278 regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
280 regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
281 if (mips_debug && in != NULL)
284 fprintf_unfiltered (gdb_stdlog, "in ");
285 for (i = 0; i < length; i++)
286 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
289 fprintf_unfiltered (gdb_stdlog, "\n");
292 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
293 compatiblity mode. A return value of 1 means that we have
294 physical 64-bit registers, but should treat them as 32-bit registers. */
297 mips2_fp_compat (void)
299 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
301 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
305 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
306 in all the places we deal with FP registers. PR gdb/413. */
307 /* Otherwise check the FR bit in the status register - it controls
308 the FP compatiblity mode. If it is clear we are in compatibility
310 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
317 /* Indicate that the ABI makes use of double-precision registers
318 provided by the FPU (rather than combining pairs of registers to
319 form double-precision values). Do not use "TARGET_IS_MIPS64" to
320 determine if the ABI is using double-precision registers. See also
322 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
324 /* The amount of space reserved on the stack for registers. This is
325 different to MIPS_SAVED_REGSIZE as it determines the alignment of
326 data allocated after the registers have run out. */
328 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
330 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
332 static const char *mips_stack_argsize_string = size_auto;
335 mips_stack_argsize (void)
337 if (mips_stack_argsize_string == size_auto)
338 return MIPS_DEFAULT_STACK_ARGSIZE;
339 else if (mips_stack_argsize_string == size_64)
341 else /* if (mips_stack_argsize_string == size_32) */
345 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
347 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
349 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
351 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
353 static void mips_print_register (int, int);
355 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
356 struct frame_info *, int);
358 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
360 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
362 static int mips_set_processor_type (char *);
364 static void mips_show_processor_type_command (char *, int);
366 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
368 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
369 struct frame_info *next_frame,
372 static CORE_ADDR after_prologue (CORE_ADDR pc,
373 mips_extra_func_info_t proc_desc);
375 static void mips_read_fp_register_single (int regno, char *rare_buffer);
376 static void mips_read_fp_register_double (int regno, char *rare_buffer);
378 static struct type *mips_float_register_type (void);
379 static struct type *mips_double_register_type (void);
381 /* This value is the model of MIPS in use. It is derived from the value
382 of the PrID register. */
384 char *mips_processor_type;
386 char *tmp_mips_processor_type;
388 /* The list of available "set mips " and "show mips " commands */
390 static struct cmd_list_element *setmipscmdlist = NULL;
391 static struct cmd_list_element *showmipscmdlist = NULL;
393 /* A set of original names, to be used when restoring back to generic
394 registers from a specific set. */
395 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
397 /* Integer registers 0 thru 31 are handled explicitly by
398 mips_register_name(). Processor specific registers 32 and above
399 are listed in the sets of register names assigned to
400 mips_processor_reg_names. */
401 static char **mips_processor_reg_names = mips_generic_reg_names;
403 /* Return the name of the register corresponding to REGNO. */
405 mips_register_name (int regno)
407 /* GPR names for all ABIs other than n32/n64. */
408 static char *mips_gpr_names[] = {
409 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
410 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
411 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
412 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
415 /* GPR names for n32 and n64 ABIs. */
416 static char *mips_n32_n64_gpr_names[] = {
417 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
418 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
419 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
420 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
423 enum mips_abi abi = mips_abi (current_gdbarch);
425 /* The MIPS integer registers are always mapped from 0 to 31. The
426 names of the registers (which reflects the conventions regarding
427 register use) vary depending on the ABI. */
428 if (0 <= regno && regno < 32)
430 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
431 return mips_n32_n64_gpr_names[regno];
433 return mips_gpr_names[regno];
435 else if (32 <= regno && regno < NUM_REGS)
436 return mips_processor_reg_names[regno - 32];
438 internal_error (__FILE__, __LINE__,
439 "mips_register_name: bad register number %d", regno);
443 /* Names of IDT R3041 registers. */
445 char *mips_r3041_reg_names[] = {
446 "sr", "lo", "hi", "bad", "cause","pc",
447 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
448 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
449 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
450 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
451 "fsr", "fir", "",/*"fp"*/ "",
452 "", "", "bus", "ccfg", "", "", "", "",
453 "", "", "port", "cmp", "", "", "epc", "prid",
456 /* Names of IDT R3051 registers. */
458 char *mips_r3051_reg_names[] = {
459 "sr", "lo", "hi", "bad", "cause","pc",
460 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
461 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
462 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
463 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
464 "fsr", "fir", ""/*"fp"*/, "",
465 "inx", "rand", "elo", "", "ctxt", "", "", "",
466 "", "", "ehi", "", "", "", "epc", "prid",
469 /* Names of IDT R3081 registers. */
471 char *mips_r3081_reg_names[] = {
472 "sr", "lo", "hi", "bad", "cause","pc",
473 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
474 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
475 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
476 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
477 "fsr", "fir", ""/*"fp"*/, "",
478 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
479 "", "", "ehi", "", "", "", "epc", "prid",
482 /* Names of LSI 33k registers. */
484 char *mips_lsi33k_reg_names[] = {
485 "epc", "hi", "lo", "sr", "cause","badvaddr",
486 "dcic", "bpc", "bda", "", "", "", "", "",
487 "", "", "", "", "", "", "", "",
488 "", "", "", "", "", "", "", "",
489 "", "", "", "", "", "", "", "",
491 "", "", "", "", "", "", "", "",
492 "", "", "", "", "", "", "", "",
498 } mips_processor_type_table[] = {
499 { "generic", mips_generic_reg_names },
500 { "r3041", mips_r3041_reg_names },
501 { "r3051", mips_r3051_reg_names },
502 { "r3071", mips_r3081_reg_names },
503 { "r3081", mips_r3081_reg_names },
504 { "lsi33k", mips_lsi33k_reg_names },
512 /* Table to translate MIPS16 register field to actual register number. */
513 static int mips16_to_32_reg[8] =
514 {16, 17, 2, 3, 4, 5, 6, 7};
516 /* Heuristic_proc_start may hunt through the text section for a long
517 time across a 2400 baud serial line. Allows the user to limit this
520 static unsigned int heuristic_fence_post = 0;
522 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
523 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
524 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
525 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
526 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
527 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
528 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
529 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
530 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
531 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
532 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
533 this will corrupt pdr.iline. Fortunately we don't use it. */
534 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
535 #define _PROC_MAGIC_ 0x0F0F0F0F
536 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
537 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
539 struct linked_proc_info
541 struct mips_extra_func_info info;
542 struct linked_proc_info *next;
544 *linked_proc_desc_table = NULL;
547 mips_print_extra_frame_info (struct frame_info *fi)
550 && get_frame_extra_info (fi)
551 && get_frame_extra_info (fi)->proc_desc
552 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
553 printf_filtered (" frame pointer is at %s+%s\n",
554 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
555 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
558 /* Number of bytes of storage in the actual machine representation for
559 register N. NOTE: This indirectly defines the register size
560 transfered by the GDB protocol. */
562 static int mips64_transfers_32bit_regs_p = 0;
565 mips_register_raw_size (int reg_nr)
567 if (mips64_transfers_32bit_regs_p)
568 return REGISTER_VIRTUAL_SIZE (reg_nr);
569 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
570 && FP_REGISTER_DOUBLE)
571 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
578 /* Convert between RAW and VIRTUAL registers. The RAW register size
579 defines the remote-gdb packet. */
582 mips_register_convertible (int reg_nr)
584 if (mips64_transfers_32bit_regs_p)
587 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
591 mips_register_convert_to_virtual (int n, struct type *virtual_type,
592 char *raw_buf, char *virt_buf)
594 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
596 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
597 TYPE_LENGTH (virtual_type));
601 TYPE_LENGTH (virtual_type));
605 mips_register_convert_to_raw (struct type *virtual_type, int n,
606 char *virt_buf, char *raw_buf)
608 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
609 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
610 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
612 TYPE_LENGTH (virtual_type));
616 TYPE_LENGTH (virtual_type));
620 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
622 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
623 && REGISTER_RAW_SIZE (regnum) == 4
624 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
625 && TYPE_CODE(type) == TYPE_CODE_FLT
626 && TYPE_LENGTH(type) == 8)
629 memcpy (temp, ((char *)(buffer))+4, 4);
630 memcpy (((char *)(buffer))+4, (buffer), 4);
631 memcpy (((char *)(buffer)), temp, 4);
636 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
638 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
639 && REGISTER_RAW_SIZE (regnum) == 4
640 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
641 && TYPE_CODE(type) == TYPE_CODE_FLT
642 && TYPE_LENGTH(type) == 8)
645 memcpy (temp, ((char *)(buffer))+4, 4);
646 memcpy (((char *)(buffer))+4, (buffer), 4);
647 memcpy (((char *)(buffer)), temp, 4);
651 /* Return the GDB type object for the "standard" data type
652 of data in register REG.
654 Note: kevinb/2002-08-01: The definition below should faithfully
655 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
656 definitions found in config/mips/tm-*.h. I'm concerned about the
657 ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause though.
658 In some cases DEPRECATED_FP_REGNUM is in this range, and I doubt
659 that this code is correct for the 64-bit case. */
662 mips_register_virtual_type (int reg)
664 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
666 /* Floating point registers... */
667 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
668 return builtin_type_ieee_double_big;
670 return builtin_type_ieee_double_little;
672 else if (reg == PS_REGNUM /* CR */)
673 return builtin_type_uint32;
674 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
675 return builtin_type_uint32;
678 /* Everything else...
679 Return type appropriate for width of register. */
680 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
681 return builtin_type_uint64;
683 return builtin_type_uint32;
687 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
692 return read_signed_register (SP_REGNUM);
695 /* Should the upper word of 64-bit addresses be zeroed? */
696 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
699 mips_mask_address_p (void)
701 switch (mask_address_var)
703 case AUTO_BOOLEAN_TRUE:
705 case AUTO_BOOLEAN_FALSE:
708 case AUTO_BOOLEAN_AUTO:
709 return MIPS_DEFAULT_MASK_ADDRESS_P;
711 internal_error (__FILE__, __LINE__,
712 "mips_mask_address_p: bad switch");
718 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
720 switch (mask_address_var)
722 case AUTO_BOOLEAN_TRUE:
723 printf_filtered ("The 32 bit mips address mask is enabled\n");
725 case AUTO_BOOLEAN_FALSE:
726 printf_filtered ("The 32 bit mips address mask is disabled\n");
728 case AUTO_BOOLEAN_AUTO:
729 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
730 mips_mask_address_p () ? "enabled" : "disabled");
733 internal_error (__FILE__, __LINE__,
734 "show_mask_address: bad switch");
739 /* Should call_function allocate stack space for a struct return? */
742 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
744 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
748 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
750 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
754 mips_o32_use_struct_convention (int gcc_p, struct type *type)
756 return 1; /* Structures are returned by ref in extra arg0. */
759 /* Should call_function pass struct by reference?
760 For each architecture, structs are passed either by
761 value or by reference, depending on their size. */
764 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
766 enum type_code typecode = TYPE_CODE (check_typedef (type));
767 int len = TYPE_LENGTH (check_typedef (type));
769 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
770 return (len > MIPS_SAVED_REGSIZE);
776 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
778 return 0; /* Assumption: N32/N64 never passes struct by ref. */
782 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
784 return 0; /* Assumption: O32/O64 never passes struct by ref. */
787 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
790 pc_is_mips16 (bfd_vma memaddr)
792 struct minimal_symbol *sym;
794 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
795 if (IS_MIPS16_ADDR (memaddr))
798 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
799 the high bit of the info field. Use this to decide if the function is
800 MIPS16 or normal MIPS. */
801 sym = lookup_minimal_symbol_by_pc (memaddr);
803 return msymbol_is_special (sym);
808 /* MIPS believes that the PC has a sign extended value. Perhaphs the
809 all registers should be sign extended for simplicity? */
812 mips_read_pc (ptid_t ptid)
814 return read_signed_register_pid (PC_REGNUM, ptid);
817 /* This returns the PC of the first inst after the prologue. If we can't
818 find the prologue, then return 0. */
821 after_prologue (CORE_ADDR pc,
822 mips_extra_func_info_t proc_desc)
824 struct symtab_and_line sal;
825 CORE_ADDR func_addr, func_end;
827 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
828 to read the stack pointer from the current machine state, because
829 the current machine state has nothing to do with the information
830 we need from the proc_desc; and the process may or may not exist
833 proc_desc = find_proc_desc (pc, NULL, 0);
837 /* If function is frameless, then we need to do it the hard way. I
838 strongly suspect that frameless always means prologueless... */
839 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
840 && PROC_FRAME_OFFSET (proc_desc) == 0)
844 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
845 return 0; /* Unknown */
847 sal = find_pc_line (func_addr, 0);
849 if (sal.end < func_end)
852 /* The line after the prologue is after the end of the function. In this
853 case, tell the caller to find the prologue the hard way. */
858 /* Decode a MIPS32 instruction that saves a register in the stack, and
859 set the appropriate bit in the general register mask or float register mask
860 to indicate which register is saved. This is a helper function
861 for mips_find_saved_regs. */
864 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
865 unsigned long *float_mask)
869 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
870 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
871 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
873 /* It might be possible to use the instruction to
874 find the offset, rather than the code below which
875 is based on things being in a certain order in the
876 frame, but figuring out what the instruction's offset
877 is relative to might be a little tricky. */
878 reg = (inst & 0x001f0000) >> 16;
879 *gen_mask |= (1 << reg);
881 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
882 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
883 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
886 reg = ((inst & 0x001f0000) >> 16);
887 *float_mask |= (1 << reg);
891 /* Decode a MIPS16 instruction that saves a register in the stack, and
892 set the appropriate bit in the general register or float register mask
893 to indicate which register is saved. This is a helper function
894 for mips_find_saved_regs. */
897 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
899 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
901 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
902 *gen_mask |= (1 << reg);
904 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
906 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
907 *gen_mask |= (1 << reg);
909 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
910 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
911 *gen_mask |= (1 << RA_REGNUM);
915 /* Fetch and return instruction from the specified location. If the PC
916 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
919 mips_fetch_instruction (CORE_ADDR addr)
921 char buf[MIPS_INSTLEN];
925 if (pc_is_mips16 (addr))
927 instlen = MIPS16_INSTLEN;
928 addr = UNMAKE_MIPS16_ADDR (addr);
931 instlen = MIPS_INSTLEN;
932 status = read_memory_nobpt (addr, buf, instlen);
934 memory_error (status, addr);
935 return extract_unsigned_integer (buf, instlen);
939 /* These the fields of 32 bit mips instructions */
940 #define mips32_op(x) (x >> 26)
941 #define itype_op(x) (x >> 26)
942 #define itype_rs(x) ((x >> 21) & 0x1f)
943 #define itype_rt(x) ((x >> 16) & 0x1f)
944 #define itype_immediate(x) (x & 0xffff)
946 #define jtype_op(x) (x >> 26)
947 #define jtype_target(x) (x & 0x03ffffff)
949 #define rtype_op(x) (x >> 26)
950 #define rtype_rs(x) ((x >> 21) & 0x1f)
951 #define rtype_rt(x) ((x >> 16) & 0x1f)
952 #define rtype_rd(x) ((x >> 11) & 0x1f)
953 #define rtype_shamt(x) ((x >> 6) & 0x1f)
954 #define rtype_funct(x) (x & 0x3f)
957 mips32_relative_offset (unsigned long inst)
960 x = itype_immediate (inst);
961 if (x & 0x8000) /* sign bit set */
963 x |= 0xffff0000; /* sign extension */
969 /* Determine whate to set a single step breakpoint while considering
972 mips32_next_pc (CORE_ADDR pc)
976 inst = mips_fetch_instruction (pc);
977 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
979 if (itype_op (inst) >> 2 == 5)
980 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
982 op = (itype_op (inst) & 0x03);
997 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
998 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1000 int tf = itype_rt (inst) & 0x01;
1001 int cnum = itype_rt (inst) >> 2;
1002 int fcrcs = read_signed_register (FCRCS_REGNUM);
1003 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1005 if (((cond >> cnum) & 0x01) == tf)
1006 pc += mips32_relative_offset (inst) + 4;
1011 pc += 4; /* Not a branch, next instruction is easy */
1014 { /* This gets way messy */
1016 /* Further subdivide into SPECIAL, REGIMM and other */
1017 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
1019 case 0: /* SPECIAL */
1020 op = rtype_funct (inst);
1025 /* Set PC to that address */
1026 pc = read_signed_register (rtype_rs (inst));
1032 break; /* end SPECIAL */
1033 case 1: /* REGIMM */
1035 op = itype_rt (inst); /* branch condition */
1040 case 16: /* BLTZAL */
1041 case 18: /* BLTZALL */
1043 if (read_signed_register (itype_rs (inst)) < 0)
1044 pc += mips32_relative_offset (inst) + 4;
1046 pc += 8; /* after the delay slot */
1050 case 17: /* BGEZAL */
1051 case 19: /* BGEZALL */
1052 greater_equal_branch:
1053 if (read_signed_register (itype_rs (inst)) >= 0)
1054 pc += mips32_relative_offset (inst) + 4;
1056 pc += 8; /* after the delay slot */
1058 /* All of the other instructions in the REGIMM category */
1063 break; /* end REGIMM */
1068 reg = jtype_target (inst) << 2;
1069 /* Upper four bits get never changed... */
1070 pc = reg + ((pc + 4) & 0xf0000000);
1073 /* FIXME case JALX : */
1076 reg = jtype_target (inst) << 2;
1077 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1078 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1080 break; /* The new PC will be alternate mode */
1081 case 4: /* BEQ, BEQL */
1083 if (read_signed_register (itype_rs (inst)) ==
1084 read_signed_register (itype_rt (inst)))
1085 pc += mips32_relative_offset (inst) + 4;
1089 case 5: /* BNE, BNEL */
1091 if (read_signed_register (itype_rs (inst)) !=
1092 read_signed_register (itype_rt (inst)))
1093 pc += mips32_relative_offset (inst) + 4;
1097 case 6: /* BLEZ, BLEZL */
1099 if (read_signed_register (itype_rs (inst) <= 0))
1100 pc += mips32_relative_offset (inst) + 4;
1106 greater_branch: /* BGTZ, BGTZL */
1107 if (read_signed_register (itype_rs (inst) > 0))
1108 pc += mips32_relative_offset (inst) + 4;
1115 } /* mips32_next_pc */
1117 /* Decoding the next place to set a breakpoint is irregular for the
1118 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1119 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1120 We dont want to set a single step instruction on the extend instruction
1124 /* Lots of mips16 instruction formats */
1125 /* Predicting jumps requires itype,ritype,i8type
1126 and their extensions extItype,extritype,extI8type
1128 enum mips16_inst_fmts
1130 itype, /* 0 immediate 5,10 */
1131 ritype, /* 1 5,3,8 */
1132 rrtype, /* 2 5,3,3,5 */
1133 rritype, /* 3 5,3,3,5 */
1134 rrrtype, /* 4 5,3,3,3,2 */
1135 rriatype, /* 5 5,3,3,1,4 */
1136 shifttype, /* 6 5,3,3,3,2 */
1137 i8type, /* 7 5,3,8 */
1138 i8movtype, /* 8 5,3,3,5 */
1139 i8mov32rtype, /* 9 5,3,5,3 */
1140 i64type, /* 10 5,3,8 */
1141 ri64type, /* 11 5,3,3,5 */
1142 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1143 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1144 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1145 extRRItype, /* 15 5,5,5,5,3,3,5 */
1146 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1147 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1148 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1149 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1150 extRi64type, /* 20 5,6,5,5,3,3,5 */
1151 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1153 /* I am heaping all the fields of the formats into one structure and
1154 then, only the fields which are involved in instruction extension */
1158 unsigned int regx; /* Function in i8 type */
1163 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1164 for the bits which make up the immediatate extension. */
1167 extended_offset (unsigned int extension)
1170 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1172 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1174 value |= extension & 0x01f; /* extract 4:0 */
1178 /* Only call this function if you know that this is an extendable
1179 instruction, It wont malfunction, but why make excess remote memory references?
1180 If the immediate operands get sign extended or somthing, do it after
1181 the extension is performed.
1183 /* FIXME: Every one of these cases needs to worry about sign extension
1184 when the offset is to be used in relative addressing */
1188 fetch_mips_16 (CORE_ADDR pc)
1191 pc &= 0xfffffffe; /* clear the low order bit */
1192 target_read_memory (pc, buf, 2);
1193 return extract_unsigned_integer (buf, 2);
1197 unpack_mips16 (CORE_ADDR pc,
1198 unsigned int extension,
1200 enum mips16_inst_fmts insn_format,
1201 struct upk_mips16 *upk)
1206 switch (insn_format)
1213 value = extended_offset (extension);
1214 value = value << 11; /* rom for the original value */
1215 value |= inst & 0x7ff; /* eleven bits from instruction */
1219 value = inst & 0x7ff;
1220 /* FIXME : Consider sign extension */
1229 { /* A register identifier and an offset */
1230 /* Most of the fields are the same as I type but the
1231 immediate value is of a different length */
1235 value = extended_offset (extension);
1236 value = value << 8; /* from the original instruction */
1237 value |= inst & 0xff; /* eleven bits from instruction */
1238 regx = (extension >> 8) & 0x07; /* or i8 funct */
1239 if (value & 0x4000) /* test the sign bit , bit 26 */
1241 value &= ~0x3fff; /* remove the sign bit */
1247 value = inst & 0xff; /* 8 bits */
1248 regx = (inst >> 8) & 0x07; /* or i8 funct */
1249 /* FIXME: Do sign extension , this format needs it */
1250 if (value & 0x80) /* THIS CONFUSES ME */
1252 value &= 0xef; /* remove the sign bit */
1262 unsigned long value;
1263 unsigned int nexthalf;
1264 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1265 value = value << 16;
1266 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1274 internal_error (__FILE__, __LINE__,
1277 upk->offset = offset;
1284 add_offset_16 (CORE_ADDR pc, int offset)
1286 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1290 extended_mips16_next_pc (CORE_ADDR pc,
1291 unsigned int extension,
1294 int op = (insn >> 11);
1297 case 2: /* Branch */
1300 struct upk_mips16 upk;
1301 unpack_mips16 (pc, extension, insn, itype, &upk);
1302 offset = upk.offset;
1308 pc += (offset << 1) + 2;
1311 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1313 struct upk_mips16 upk;
1314 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1315 pc = add_offset_16 (pc, upk.offset);
1316 if ((insn >> 10) & 0x01) /* Exchange mode */
1317 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1324 struct upk_mips16 upk;
1326 unpack_mips16 (pc, extension, insn, ritype, &upk);
1327 reg = read_signed_register (upk.regx);
1329 pc += (upk.offset << 1) + 2;
1336 struct upk_mips16 upk;
1338 unpack_mips16 (pc, extension, insn, ritype, &upk);
1339 reg = read_signed_register (upk.regx);
1341 pc += (upk.offset << 1) + 2;
1346 case 12: /* I8 Formats btez btnez */
1348 struct upk_mips16 upk;
1350 unpack_mips16 (pc, extension, insn, i8type, &upk);
1351 /* upk.regx contains the opcode */
1352 reg = read_signed_register (24); /* Test register is 24 */
1353 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1354 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1355 /* pc = add_offset_16(pc,upk.offset) ; */
1356 pc += (upk.offset << 1) + 2;
1361 case 29: /* RR Formats JR, JALR, JALR-RA */
1363 struct upk_mips16 upk;
1364 /* upk.fmt = rrtype; */
1369 upk.regx = (insn >> 8) & 0x07;
1370 upk.regy = (insn >> 5) & 0x07;
1378 break; /* Function return instruction */
1384 break; /* BOGUS Guess */
1386 pc = read_signed_register (reg);
1393 /* This is an instruction extension. Fetch the real instruction
1394 (which follows the extension) and decode things based on
1398 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1411 mips16_next_pc (CORE_ADDR pc)
1413 unsigned int insn = fetch_mips_16 (pc);
1414 return extended_mips16_next_pc (pc, 0, insn);
1417 /* The mips_next_pc function supports single_step when the remote
1418 target monitor or stub is not developed enough to do a single_step.
1419 It works by decoding the current instruction and predicting where a
1420 branch will go. This isnt hard because all the data is available.
1421 The MIPS32 and MIPS16 variants are quite different */
1423 mips_next_pc (CORE_ADDR pc)
1426 return mips16_next_pc (pc);
1428 return mips32_next_pc (pc);
1431 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1434 Note: kevinb/2002-08-09: The only caller of this function is (and
1435 should remain) mips_frame_init_saved_regs(). In fact,
1436 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1437 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1438 functions should really be combined and now that there is only one
1439 caller, it should be straightforward. (Watch out for multiple returns
1443 mips_find_saved_regs (struct frame_info *fci)
1446 CORE_ADDR reg_position;
1447 /* r0 bit means kernel trap */
1449 /* What registers have been saved? Bitmasks. */
1450 unsigned long gen_mask, float_mask;
1451 mips_extra_func_info_t proc_desc;
1454 frame_saved_regs_zalloc (fci);
1456 /* If it is the frame for sigtramp, the saved registers are located
1457 in a sigcontext structure somewhere on the stack.
1458 If the stack layout for sigtramp changes we might have to change these
1459 constants and the companion fixup_sigtramp in mdebugread.c */
1460 #ifndef SIGFRAME_BASE
1461 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1462 above the sigtramp frame. */
1463 #define SIGFRAME_BASE MIPS_REGSIZE
1464 /* FIXME! Are these correct?? */
1465 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1466 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1467 #define SIGFRAME_FPREGSAVE_OFF \
1468 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1470 #ifndef SIGFRAME_REG_SIZE
1471 /* FIXME! Is this correct?? */
1472 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1474 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1476 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1478 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1479 + ireg * SIGFRAME_REG_SIZE;
1480 get_frame_saved_regs (fci)[ireg] = reg_position;
1482 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1484 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1485 + ireg * SIGFRAME_REG_SIZE;
1486 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1488 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1492 proc_desc = get_frame_extra_info (fci)->proc_desc;
1493 if (proc_desc == NULL)
1494 /* I'm not sure how/whether this can happen. Normally when we can't
1495 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1496 and set the saved_regs right away. */
1499 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1500 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1501 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1503 if ( /* In any frame other than the innermost or a frame interrupted by
1504 a signal, we assume that all registers have been saved.
1505 This assumes that all register saves in a function happen before
1506 the first function call. */
1507 (get_next_frame (fci) == NULL
1508 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1510 /* In a dummy frame we know exactly where things are saved. */
1511 && !PROC_DESC_IS_DUMMY (proc_desc)
1513 /* Don't bother unless we are inside a function prologue. Outside the
1514 prologue, we know where everything is. */
1516 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1518 /* Not sure exactly what kernel_trap means, but if it means
1519 the kernel saves the registers without a prologue doing it,
1520 we better not examine the prologue to see whether registers
1521 have been saved yet. */
1524 /* We need to figure out whether the registers that the proc_desc
1525 claims are saved have been saved yet. */
1529 /* Bitmasks; set if we have found a save for the register. */
1530 unsigned long gen_save_found = 0;
1531 unsigned long float_save_found = 0;
1534 /* If the address is odd, assume this is MIPS16 code. */
1535 addr = PROC_LOW_ADDR (proc_desc);
1536 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1538 /* Scan through this function's instructions preceding the current
1539 PC, and look for those that save registers. */
1540 while (addr < get_frame_pc (fci))
1542 inst = mips_fetch_instruction (addr);
1543 if (pc_is_mips16 (addr))
1544 mips16_decode_reg_save (inst, &gen_save_found);
1546 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1549 gen_mask = gen_save_found;
1550 float_mask = float_save_found;
1553 /* Fill in the offsets for the registers which gen_mask says
1555 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1556 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1557 if (gen_mask & 0x80000000)
1559 get_frame_saved_regs (fci)[ireg] = reg_position;
1560 reg_position -= MIPS_SAVED_REGSIZE;
1563 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1564 of that normally used by gcc. Therefore, we have to fetch the first
1565 instruction of the function, and if it's an entry instruction that
1566 saves $s0 or $s1, correct their saved addresses. */
1567 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1569 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1570 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1573 int sreg_count = (inst >> 6) & 3;
1575 /* Check if the ra register was pushed on the stack. */
1576 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1578 reg_position -= MIPS_SAVED_REGSIZE;
1580 /* Check if the s0 and s1 registers were pushed on the stack. */
1581 for (reg = 16; reg < sreg_count + 16; reg++)
1583 get_frame_saved_regs (fci)[reg] = reg_position;
1584 reg_position -= MIPS_SAVED_REGSIZE;
1589 /* Fill in the offsets for the registers which float_mask says
1591 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1593 /* Apparently, the freg_offset gives the offset to the first 64 bit
1596 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1597 designates the first saved 64 bit register.
1599 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1600 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1601 FREG_OFFSET, designates the address of the lower register of the
1602 register pair. Adjust the offset so that it designates the upper
1603 register of the pair -- i.e., the address of the first saved 32
1606 if (MIPS_SAVED_REGSIZE == 4)
1607 reg_position += MIPS_SAVED_REGSIZE;
1609 /* Fill in the offsets for the float registers which float_mask says
1611 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1612 if (float_mask & 0x80000000)
1614 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1615 reg_position -= MIPS_SAVED_REGSIZE;
1618 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1621 /* Set up the 'saved_regs' array. This is a data structure containing
1622 the addresses on the stack where each register has been saved, for
1623 each stack frame. Registers that have not been saved will have
1624 zero here. The stack pointer register is special: rather than the
1625 address where the stack register has been saved, saved_regs[SP_REGNUM]
1626 will have the actual value of the previous frame's stack register. */
1629 mips_frame_init_saved_regs (struct frame_info *frame)
1631 if (get_frame_saved_regs (frame) == NULL)
1633 mips_find_saved_regs (frame);
1635 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1639 read_next_frame_reg (struct frame_info *fi, int regno)
1644 enum lval_type lval;
1645 char raw_buffer[MAX_REGISTER_SIZE];
1649 regcache_cooked_read (current_regcache, regno, raw_buffer);
1653 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1655 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1656 should have a pseudo register range that correspons to the ABI's,
1657 rather than the ISA's, view of registers. These registers would
1658 then implicitly describe their size and hence could be used
1659 without the below munging. */
1660 if (lval == lval_memory)
1664 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1666 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1671 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1674 /* mips_addr_bits_remove - remove useless address bits */
1677 mips_addr_bits_remove (CORE_ADDR addr)
1679 if (GDB_TARGET_IS_MIPS64)
1681 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1683 /* This hack is a work-around for existing boards using
1684 PMON, the simulator, and any other 64-bit targets that
1685 doesn't have true 64-bit addressing. On these targets,
1686 the upper 32 bits of addresses are ignored by the
1687 hardware. Thus, the PC or SP are likely to have been
1688 sign extended to all 1s by instruction sequences that
1689 load 32-bit addresses. For example, a typical piece of
1690 code that loads an address is this:
1691 lui $r2, <upper 16 bits>
1692 ori $r2, <lower 16 bits>
1693 But the lui sign-extends the value such that the upper 32
1694 bits may be all 1s. The workaround is simply to mask off
1695 these bits. In the future, gcc may be changed to support
1696 true 64-bit addressing, and this masking will have to be
1698 addr &= (CORE_ADDR) 0xffffffff;
1701 else if (mips_mask_address_p ())
1703 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1704 masking off bits, instead, the actual target should be asking
1705 for the address to be converted to a valid pointer. */
1706 /* Even when GDB is configured for some 32-bit targets
1707 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1708 so CORE_ADDR is 64 bits. So we still have to mask off
1709 useless bits from addresses. */
1710 addr &= (CORE_ADDR) 0xffffffff;
1715 /* mips_software_single_step() is called just before we want to resume
1716 the inferior, if we want to single-step it but there is no hardware
1717 or kernel single-step support (MIPS on GNU/Linux for example). We find
1718 the target of the coming instruction and breakpoint it.
1720 single_step is also called just after the inferior stops. If we had
1721 set up a simulated single-step, we undo our damage. */
1724 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1726 static CORE_ADDR next_pc;
1727 typedef char binsn_quantum[BREAKPOINT_MAX];
1728 static binsn_quantum break_mem;
1731 if (insert_breakpoints_p)
1733 pc = read_register (PC_REGNUM);
1734 next_pc = mips_next_pc (pc);
1736 target_insert_breakpoint (next_pc, break_mem);
1739 target_remove_breakpoint (next_pc, break_mem);
1743 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1748 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1749 : get_next_frame (prev)
1750 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1752 tmp = SKIP_TRAMPOLINE_CODE (pc);
1753 return tmp ? tmp : pc;
1758 mips_frame_saved_pc (struct frame_info *frame)
1761 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1762 /* We have to get the saved pc from the sigcontext
1763 if it is a signal handler frame. */
1764 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1765 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1767 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1770 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1773 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1774 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1776 saved_pc = read_next_frame_reg (frame, pcreg);
1778 return ADDR_BITS_REMOVE (saved_pc);
1781 static struct mips_extra_func_info temp_proc_desc;
1783 /* This hack will go away once the get_prev_frame() code has been
1784 modified to set the frame's type first. That is BEFORE init extra
1785 frame info et.al. is called. This is because it will become
1786 possible to skip the init extra info call for sigtramp and dummy
1788 static CORE_ADDR *temp_saved_regs;
1790 /* Set a register's saved stack address in temp_saved_regs. If an address
1791 has already been set for this register, do nothing; this way we will
1792 only recognize the first save of a given register in a function prologue.
1793 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1796 set_reg_offset (int regno, CORE_ADDR offset)
1798 if (temp_saved_regs[regno] == 0)
1799 temp_saved_regs[regno] = offset;
1803 /* Test whether the PC points to the return instruction at the
1804 end of a function. */
1807 mips_about_to_return (CORE_ADDR pc)
1809 if (pc_is_mips16 (pc))
1810 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1811 generates a "jr $ra"; other times it generates code to load
1812 the return address from the stack to an accessible register (such
1813 as $a3), then a "jr" using that register. This second case
1814 is almost impossible to distinguish from an indirect jump
1815 used for switch statements, so we don't even try. */
1816 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1818 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1822 /* This fencepost looks highly suspicious to me. Removing it also
1823 seems suspicious as it could affect remote debugging across serial
1827 heuristic_proc_start (CORE_ADDR pc)
1834 pc = ADDR_BITS_REMOVE (pc);
1836 fence = start_pc - heuristic_fence_post;
1840 if (heuristic_fence_post == UINT_MAX
1841 || fence < VM_MIN_ADDRESS)
1842 fence = VM_MIN_ADDRESS;
1844 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1846 /* search back for previous return */
1847 for (start_pc -= instlen;; start_pc -= instlen)
1848 if (start_pc < fence)
1850 /* It's not clear to me why we reach this point when
1851 stop_soon, but with this test, at least we
1852 don't print out warnings for every child forked (eg, on
1854 if (stop_soon == NO_STOP_QUIETLY)
1856 static int blurb_printed = 0;
1858 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1863 /* This actually happens frequently in embedded
1864 development, when you first connect to a board
1865 and your stack pointer and pc are nowhere in
1866 particular. This message needs to give people
1867 in that situation enough information to
1868 determine that it's no big deal. */
1869 printf_filtered ("\n\
1870 GDB is unable to find the start of the function at 0x%s\n\
1871 and thus can't determine the size of that function's stack frame.\n\
1872 This means that GDB may be unable to access that stack frame, or\n\
1873 the frames below it.\n\
1874 This problem is most likely caused by an invalid program counter or\n\
1876 However, if you think GDB should simply search farther back\n\
1877 from 0x%s for code which looks like the beginning of a\n\
1878 function, you can increase the range of the search using the `set\n\
1879 heuristic-fence-post' command.\n",
1880 paddr_nz (pc), paddr_nz (pc));
1887 else if (pc_is_mips16 (start_pc))
1889 unsigned short inst;
1891 /* On MIPS16, any one of the following is likely to be the
1892 start of a function:
1896 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1897 inst = mips_fetch_instruction (start_pc);
1898 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1899 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1900 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1901 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1903 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1904 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1909 else if (mips_about_to_return (start_pc))
1911 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1918 /* Fetch the immediate value from a MIPS16 instruction.
1919 If the previous instruction was an EXTEND, use it to extend
1920 the upper bits of the immediate value. This is a helper function
1921 for mips16_heuristic_proc_desc. */
1924 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1925 unsigned short inst, /* current instruction */
1926 int nbits, /* number of bits in imm field */
1927 int scale, /* scale factor to be applied to imm */
1928 int is_signed) /* is the imm field signed? */
1932 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1934 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1935 if (offset & 0x8000) /* check for negative extend */
1936 offset = 0 - (0x10000 - (offset & 0xffff));
1937 return offset | (inst & 0x1f);
1941 int max_imm = 1 << nbits;
1942 int mask = max_imm - 1;
1943 int sign_bit = max_imm >> 1;
1945 offset = inst & mask;
1946 if (is_signed && (offset & sign_bit))
1947 offset = 0 - (max_imm - offset);
1948 return offset * scale;
1953 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1954 stream from start_pc to limit_pc. */
1957 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1958 struct frame_info *next_frame, CORE_ADDR sp)
1961 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1962 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1963 unsigned inst = 0; /* current instruction */
1964 unsigned entry_inst = 0; /* the entry instruction */
1967 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1968 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1970 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1972 /* Save the previous instruction. If it's an EXTEND, we'll extract
1973 the immediate offset extension from it in mips16_get_imm. */
1976 /* Fetch and decode the instruction. */
1977 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1978 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1979 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1981 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1982 if (offset < 0) /* negative stack adjustment? */
1983 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1985 /* Exit loop if a positive stack adjustment is found, which
1986 usually means that the stack cleanup code in the function
1987 epilogue is reached. */
1990 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1992 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1993 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1994 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1995 set_reg_offset (reg, sp + offset);
1997 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1999 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2000 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2001 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2002 set_reg_offset (reg, sp + offset);
2004 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2006 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2007 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2008 set_reg_offset (RA_REGNUM, sp + offset);
2010 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2012 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2013 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2014 set_reg_offset (RA_REGNUM, sp + offset);
2016 else if (inst == 0x673d) /* move $s1, $sp */
2019 PROC_FRAME_REG (&temp_proc_desc) = 17;
2021 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2023 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2024 frame_addr = sp + offset;
2025 PROC_FRAME_REG (&temp_proc_desc) = 17;
2026 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2028 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2030 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2031 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2032 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2033 set_reg_offset (reg, frame_addr + offset);
2035 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2037 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2038 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2039 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2040 set_reg_offset (reg, frame_addr + offset);
2042 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2043 entry_inst = inst; /* save for later processing */
2044 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2045 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2048 /* The entry instruction is typically the first instruction in a function,
2049 and it stores registers at offsets relative to the value of the old SP
2050 (before the prologue). But the value of the sp parameter to this
2051 function is the new SP (after the prologue has been executed). So we
2052 can't calculate those offsets until we've seen the entire prologue,
2053 and can calculate what the old SP must have been. */
2054 if (entry_inst != 0)
2056 int areg_count = (entry_inst >> 8) & 7;
2057 int sreg_count = (entry_inst >> 6) & 3;
2059 /* The entry instruction always subtracts 32 from the SP. */
2060 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2062 /* Now we can calculate what the SP must have been at the
2063 start of the function prologue. */
2064 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2066 /* Check if a0-a3 were saved in the caller's argument save area. */
2067 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2069 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2070 set_reg_offset (reg, sp + offset);
2071 offset += MIPS_SAVED_REGSIZE;
2074 /* Check if the ra register was pushed on the stack. */
2076 if (entry_inst & 0x20)
2078 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2079 set_reg_offset (RA_REGNUM, sp + offset);
2080 offset -= MIPS_SAVED_REGSIZE;
2083 /* Check if the s0 and s1 registers were pushed on the stack. */
2084 for (reg = 16; reg < sreg_count + 16; reg++)
2086 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2087 set_reg_offset (reg, sp + offset);
2088 offset -= MIPS_SAVED_REGSIZE;
2094 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2095 struct frame_info *next_frame, CORE_ADDR sp)
2098 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2100 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2101 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2102 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2103 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2104 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2106 unsigned long inst, high_word, low_word;
2109 /* Fetch the instruction. */
2110 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2112 /* Save some code by pre-extracting some useful fields. */
2113 high_word = (inst >> 16) & 0xffff;
2114 low_word = inst & 0xffff;
2115 reg = high_word & 0x1f;
2117 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2118 || high_word == 0x23bd /* addi $sp,$sp,-i */
2119 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2121 if (low_word & 0x8000) /* negative stack adjustment? */
2122 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2124 /* Exit loop if a positive stack adjustment is found, which
2125 usually means that the stack cleanup code in the function
2126 epilogue is reached. */
2129 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2131 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2132 set_reg_offset (reg, sp + low_word);
2134 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2136 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2137 but the register size used is only 32 bits. Make the address
2138 for the saved register point to the lower 32 bits. */
2139 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2140 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2142 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2144 /* Old gcc frame, r30 is virtual frame pointer. */
2145 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2146 frame_addr = sp + low_word;
2147 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2149 unsigned alloca_adjust;
2150 PROC_FRAME_REG (&temp_proc_desc) = 30;
2151 frame_addr = read_next_frame_reg (next_frame, 30);
2152 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2153 if (alloca_adjust > 0)
2155 /* FP > SP + frame_size. This may be because
2156 * of an alloca or somethings similar.
2157 * Fix sp to "pre-alloca" value, and try again.
2159 sp += alloca_adjust;
2164 /* move $30,$sp. With different versions of gas this will be either
2165 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2166 Accept any one of these. */
2167 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2169 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2170 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2172 unsigned alloca_adjust;
2173 PROC_FRAME_REG (&temp_proc_desc) = 30;
2174 frame_addr = read_next_frame_reg (next_frame, 30);
2175 alloca_adjust = (unsigned) (frame_addr - sp);
2176 if (alloca_adjust > 0)
2178 /* FP > SP + frame_size. This may be because
2179 * of an alloca or somethings similar.
2180 * Fix sp to "pre-alloca" value, and try again.
2182 sp += alloca_adjust;
2187 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2189 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2190 set_reg_offset (reg, frame_addr + low_word);
2195 static mips_extra_func_info_t
2196 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2197 struct frame_info *next_frame, int cur_frame)
2202 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2208 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2209 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2210 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2211 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2212 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2213 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2215 if (start_pc + 200 < limit_pc)
2216 limit_pc = start_pc + 200;
2217 if (pc_is_mips16 (start_pc))
2218 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2220 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2221 return &temp_proc_desc;
2224 struct mips_objfile_private
2230 /* Global used to communicate between non_heuristic_proc_desc and
2231 compare_pdr_entries within qsort (). */
2232 static bfd *the_bfd;
2235 compare_pdr_entries (const void *a, const void *b)
2237 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2238 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2242 else if (lhs == rhs)
2248 static mips_extra_func_info_t
2249 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2251 CORE_ADDR startaddr;
2252 mips_extra_func_info_t proc_desc;
2253 struct block *b = block_for_pc (pc);
2255 struct obj_section *sec;
2256 struct mips_objfile_private *priv;
2258 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2261 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2263 *addrptr = startaddr;
2267 sec = find_pc_section (pc);
2270 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2272 /* Search the ".pdr" section generated by GAS. This includes most of
2273 the information normally found in ECOFF PDRs. */
2275 the_bfd = sec->objfile->obfd;
2277 && (the_bfd->format == bfd_object
2278 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2279 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2281 /* Right now GAS only outputs the address as a four-byte sequence.
2282 This means that we should not bother with this method on 64-bit
2283 targets (until that is fixed). */
2285 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2286 sizeof (struct mips_objfile_private));
2288 sec->objfile->obj_private = priv;
2290 else if (priv == NULL)
2294 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2295 sizeof (struct mips_objfile_private));
2297 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2300 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2301 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2303 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2304 priv->contents, 0, priv->size);
2306 /* In general, the .pdr section is sorted. However, in the
2307 presence of multiple code sections (and other corner cases)
2308 it can become unsorted. Sort it so that we can use a faster
2310 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2315 sec->objfile->obj_private = priv;
2319 if (priv->size != 0)
2325 high = priv->size / 32;
2331 mid = (low + high) / 2;
2333 ptr = priv->contents + mid * 32;
2334 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2335 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2336 SECT_OFF_TEXT (sec->objfile));
2337 if (pdr_pc == startaddr)
2339 if (pdr_pc > startaddr)
2344 while (low != high);
2348 struct symbol *sym = find_pc_function (pc);
2350 /* Fill in what we need of the proc_desc. */
2351 proc_desc = (mips_extra_func_info_t)
2352 obstack_alloc (&sec->objfile->psymbol_obstack,
2353 sizeof (struct mips_extra_func_info));
2354 PROC_LOW_ADDR (proc_desc) = startaddr;
2356 /* Only used for dummy frames. */
2357 PROC_HIGH_ADDR (proc_desc) = 0;
2359 PROC_FRAME_OFFSET (proc_desc)
2360 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2361 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2363 PROC_FRAME_ADJUST (proc_desc) = 0;
2364 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2366 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2368 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2370 PROC_FREG_OFFSET (proc_desc)
2371 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2372 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2374 proc_desc->pdr.isym = (long) sym;
2384 if (startaddr > BLOCK_START (b))
2386 /* This is the "pathological" case referred to in a comment in
2387 print_frame_info. It might be better to move this check into
2392 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
2394 /* If we never found a PDR for this function in symbol reading, then
2395 examine prologues to find the information. */
2398 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2399 if (PROC_FRAME_REG (proc_desc) == -1)
2409 static mips_extra_func_info_t
2410 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2412 mips_extra_func_info_t proc_desc;
2413 CORE_ADDR startaddr = 0;
2415 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2419 /* IF this is the topmost frame AND
2420 * (this proc does not have debugging information OR
2421 * the PC is in the procedure prologue)
2422 * THEN create a "heuristic" proc_desc (by analyzing
2423 * the actual code) to replace the "official" proc_desc.
2425 if (next_frame == NULL)
2427 struct symtab_and_line val;
2428 struct symbol *proc_symbol =
2429 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2433 val = find_pc_line (BLOCK_START
2434 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2436 val.pc = val.end ? val.end : pc;
2438 if (!proc_symbol || pc < val.pc)
2440 mips_extra_func_info_t found_heuristic =
2441 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2442 pc, next_frame, cur_frame);
2443 if (found_heuristic)
2444 proc_desc = found_heuristic;
2450 /* Is linked_proc_desc_table really necessary? It only seems to be used
2451 by procedure call dummys. However, the procedures being called ought
2452 to have their own proc_descs, and even if they don't,
2453 heuristic_proc_desc knows how to create them! */
2455 register struct linked_proc_info *link;
2457 for (link = linked_proc_desc_table; link; link = link->next)
2458 if (PROC_LOW_ADDR (&link->info) <= pc
2459 && PROC_HIGH_ADDR (&link->info) > pc)
2463 startaddr = heuristic_proc_start (pc);
2466 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2472 get_frame_pointer (struct frame_info *frame,
2473 mips_extra_func_info_t proc_desc)
2475 return (read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
2476 + PROC_FRAME_OFFSET (proc_desc)
2477 - PROC_FRAME_ADJUST (proc_desc));
2480 static mips_extra_func_info_t cached_proc_desc;
2483 mips_frame_chain (struct frame_info *frame)
2485 mips_extra_func_info_t proc_desc;
2487 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2489 if (saved_pc == 0 || inside_entry_file (saved_pc))
2492 /* Check if the PC is inside a call stub. If it is, fetch the
2493 PC of the caller of that stub. */
2494 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2497 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2499 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2500 is well, frame->frame the bottom of the current frame will
2501 contain that value. */
2502 return get_frame_base (frame);
2505 /* Look up the procedure descriptor for this PC. */
2506 proc_desc = find_proc_desc (saved_pc, frame, 1);
2510 cached_proc_desc = proc_desc;
2512 /* If no frame pointer and frame size is zero, we must be at end
2513 of stack (or otherwise hosed). If we don't check frame size,
2514 we loop forever if we see a zero size frame. */
2515 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2516 && PROC_FRAME_OFFSET (proc_desc) == 0
2517 /* The previous frame from a sigtramp frame might be frameless
2518 and have frame size zero. */
2519 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2520 /* For a generic dummy frame, let get_frame_pointer() unwind a
2521 register value saved as part of the dummy frame call. */
2522 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2525 return get_frame_pointer (frame, proc_desc);
2529 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2532 mips_extra_func_info_t proc_desc;
2534 if (get_frame_type (fci) == DUMMY_FRAME)
2537 /* Use proc_desc calculated in frame_chain. When there is no
2538 next frame, i.e, get_next_frame (fci) == NULL, we call
2539 find_proc_desc () to calculate it, passing an explicit
2540 NULL as the frame parameter. */
2542 get_next_frame (fci)
2544 : find_proc_desc (get_frame_pc (fci),
2545 NULL /* i.e, get_next_frame (fci) */,
2548 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2550 deprecated_set_frame_saved_regs_hack (fci, NULL);
2551 get_frame_extra_info (fci)->proc_desc =
2552 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2555 /* Fixup frame-pointer - only needed for top frame */
2556 /* This may not be quite right, if proc has a real frame register.
2557 Get the value of the frame relative sp, procedure might have been
2558 interrupted by a signal at it's very start. */
2559 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2560 && !PROC_DESC_IS_DUMMY (proc_desc))
2561 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2562 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2563 /* Do not ``fix'' fci->frame. It will have the value of the
2564 generic dummy frame's top-of-stack (since the draft
2565 fci->frame is obtained by returning the unwound stack
2566 pointer) and that is what we want. That way the fci->frame
2567 value will match the top-of-stack value that was saved as
2568 part of the dummy frames data. */
2571 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2573 if (proc_desc == &temp_proc_desc)
2577 /* Do not set the saved registers for a sigtramp frame,
2578 mips_find_saved_registers will do that for us. We can't
2579 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2581 /* FIXME: cagney/2002-11-18: This problem will go away once
2582 frame.c:get_prev_frame() is modified to set the frame's
2583 type before calling functions like this. */
2584 find_pc_partial_function (get_frame_pc (fci), &name,
2585 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2586 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2588 frame_saved_regs_zalloc (fci);
2589 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2590 get_frame_saved_regs (fci)[PC_REGNUM]
2591 = get_frame_saved_regs (fci)[RA_REGNUM];
2592 /* Set value of previous frame's stack pointer. Remember that
2593 saved_regs[SP_REGNUM] is special in that it contains the
2594 value of the stack pointer register. The other saved_regs
2595 values are addresses (in the inferior) at which a given
2596 register's value may be found. */
2597 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2601 /* hack: if argument regs are saved, guess these contain args */
2602 /* assume we can't tell how many args for now */
2603 get_frame_extra_info (fci)->num_args = -1;
2604 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2606 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2608 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2615 /* MIPS stack frames are almost impenetrable. When execution stops,
2616 we basically have to look at symbol information for the function
2617 that we stopped in, which tells us *which* register (if any) is
2618 the base of the frame pointer, and what offset from that register
2619 the frame itself is at.
2621 This presents a problem when trying to examine a stack in memory
2622 (that isn't executing at the moment), using the "frame" command. We
2623 don't have a PC, nor do we have any registers except SP.
2625 This routine takes two arguments, SP and PC, and tries to make the
2626 cached frames look as if these two arguments defined a frame on the
2627 cache. This allows the rest of info frame to extract the important
2628 arguments without difficulty. */
2631 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2634 error ("MIPS frame specifications require two arguments: sp and pc");
2636 return create_new_frame (argv[0], argv[1]);
2639 /* According to the current ABI, should the type be passed in a
2640 floating-point register (assuming that there is space)? When there
2641 is no FPU, FP are not even considered as possibile candidates for
2642 FP registers and, consequently this returns false - forces FP
2643 arguments into integer registers. */
2646 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2648 return ((typecode == TYPE_CODE_FLT
2650 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2651 && TYPE_NFIELDS (arg_type) == 1
2652 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2653 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2656 /* On o32, argument passing in GPRs depends on the alignment of the type being
2657 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2660 mips_type_needs_double_align (struct type *type)
2662 enum type_code typecode = TYPE_CODE (type);
2664 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2666 else if (typecode == TYPE_CODE_STRUCT)
2668 if (TYPE_NFIELDS (type) < 1)
2670 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2672 else if (typecode == TYPE_CODE_UNION)
2676 n = TYPE_NFIELDS (type);
2677 for (i = 0; i < n; i++)
2678 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2685 /* Macros to round N up or down to the next A boundary;
2686 A must be a power of two. */
2688 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2689 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2691 /* Adjust the address downward (direction of stack growth) so that it
2692 is correctly aligned for a new stack frame. */
2694 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2696 return ROUND_DOWN (addr, 16);
2700 mips_eabi_push_arguments (int nargs,
2701 struct value **args,
2704 CORE_ADDR struct_addr)
2710 int stack_offset = 0;
2712 /* First ensure that the stack and structure return address (if any)
2713 are properly aligned. The stack has to be at least 64-bit
2714 aligned even on 32-bit machines, because doubles must be 64-bit
2715 aligned. For n32 and n64, stack frames need to be 128-bit
2716 aligned, so we round to this widest known alignment. */
2718 sp = ROUND_DOWN (sp, 16);
2719 struct_addr = ROUND_DOWN (struct_addr, 16);
2721 /* Now make space on the stack for the args. We allocate more
2722 than necessary for EABI, because the first few arguments are
2723 passed in registers, but that's OK. */
2724 for (argnum = 0; argnum < nargs; argnum++)
2725 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2726 MIPS_STACK_ARGSIZE);
2727 sp -= ROUND_UP (len, 16);
2730 fprintf_unfiltered (gdb_stdlog,
2731 "mips_eabi_push_arguments: sp=0x%s allocated %d\n",
2732 paddr_nz (sp), ROUND_UP (len, 16));
2734 /* Initialize the integer and float register pointers. */
2736 float_argreg = FPA0_REGNUM;
2738 /* The struct_return pointer occupies the first parameter-passing reg. */
2742 fprintf_unfiltered (gdb_stdlog,
2743 "mips_eabi_push_arguments: struct_return reg=%d 0x%s\n",
2744 argreg, paddr_nz (struct_addr));
2745 write_register (argreg++, struct_addr);
2748 /* Now load as many as possible of the first arguments into
2749 registers, and push the rest onto the stack. Loop thru args
2750 from first to last. */
2751 for (argnum = 0; argnum < nargs; argnum++)
2754 char valbuf[MAX_REGISTER_SIZE];
2755 struct value *arg = args[argnum];
2756 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2757 int len = TYPE_LENGTH (arg_type);
2758 enum type_code typecode = TYPE_CODE (arg_type);
2761 fprintf_unfiltered (gdb_stdlog,
2762 "mips_eabi_push_arguments: %d len=%d type=%d",
2763 argnum + 1, len, (int) typecode);
2765 /* The EABI passes structures that do not fit in a register by
2767 if (len > MIPS_SAVED_REGSIZE
2768 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2770 store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2771 typecode = TYPE_CODE_PTR;
2772 len = MIPS_SAVED_REGSIZE;
2775 fprintf_unfiltered (gdb_stdlog, " push");
2778 val = (char *) VALUE_CONTENTS (arg);
2780 /* 32-bit ABIs always start floating point arguments in an
2781 even-numbered floating point register. Round the FP register
2782 up before the check to see if there are any FP registers
2783 left. Non MIPS_EABI targets also pass the FP in the integer
2784 registers so also round up normal registers. */
2785 if (!FP_REGISTER_DOUBLE
2786 && fp_register_arg_p (typecode, arg_type))
2788 if ((float_argreg & 1))
2792 /* Floating point arguments passed in registers have to be
2793 treated specially. On 32-bit architectures, doubles
2794 are passed in register pairs; the even register gets
2795 the low word, and the odd register gets the high word.
2796 On non-EABI processors, the first two floating point arguments are
2797 also copied to general registers, because MIPS16 functions
2798 don't use float registers for arguments. This duplication of
2799 arguments in general registers can't hurt non-MIPS16 functions
2800 because those registers are normally skipped. */
2801 /* MIPS_EABI squeezes a struct that contains a single floating
2802 point value into an FP register instead of pushing it onto the
2804 if (fp_register_arg_p (typecode, arg_type)
2805 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2807 if (!FP_REGISTER_DOUBLE && len == 8)
2809 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2810 unsigned long regval;
2812 /* Write the low word of the double to the even register(s). */
2813 regval = extract_unsigned_integer (val + low_offset, 4);
2815 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2816 float_argreg, phex (regval, 4));
2817 write_register (float_argreg++, regval);
2819 /* Write the high word of the double to the odd register(s). */
2820 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2822 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2823 float_argreg, phex (regval, 4));
2824 write_register (float_argreg++, regval);
2828 /* This is a floating point value that fits entirely
2829 in a single register. */
2830 /* On 32 bit ABI's the float_argreg is further adjusted
2831 above to ensure that it is even register aligned. */
2832 LONGEST regval = extract_unsigned_integer (val, len);
2834 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2835 float_argreg, phex (regval, len));
2836 write_register (float_argreg++, regval);
2841 /* Copy the argument to general registers or the stack in
2842 register-sized pieces. Large arguments are split between
2843 registers and stack. */
2844 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2845 are treated specially: Irix cc passes them in registers
2846 where gcc sometimes puts them on the stack. For maximum
2847 compatibility, we will put them in both places. */
2848 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2849 (len % MIPS_SAVED_REGSIZE != 0));
2851 /* Note: Floating-point values that didn't fit into an FP
2852 register are only written to memory. */
2855 /* Remember if the argument was written to the stack. */
2856 int stack_used_p = 0;
2858 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2861 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2864 /* Write this portion of the argument to the stack. */
2865 if (argreg > MIPS_LAST_ARG_REGNUM
2867 || fp_register_arg_p (typecode, arg_type))
2869 /* Should shorter than int integer values be
2870 promoted to int before being stored? */
2871 int longword_offset = 0;
2874 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2876 if (MIPS_STACK_ARGSIZE == 8 &&
2877 (typecode == TYPE_CODE_INT ||
2878 typecode == TYPE_CODE_PTR ||
2879 typecode == TYPE_CODE_FLT) && len <= 4)
2880 longword_offset = MIPS_STACK_ARGSIZE - len;
2881 else if ((typecode == TYPE_CODE_STRUCT ||
2882 typecode == TYPE_CODE_UNION) &&
2883 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2884 longword_offset = MIPS_STACK_ARGSIZE - len;
2889 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2890 paddr_nz (stack_offset));
2891 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2892 paddr_nz (longword_offset));
2895 addr = sp + stack_offset + longword_offset;
2900 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2902 for (i = 0; i < partial_len; i++)
2904 fprintf_unfiltered (gdb_stdlog, "%02x",
2908 write_memory (addr, val, partial_len);
2911 /* Note!!! This is NOT an else clause. Odd sized
2912 structs may go thru BOTH paths. Floating point
2913 arguments will not. */
2914 /* Write this portion of the argument to a general
2915 purpose register. */
2916 if (argreg <= MIPS_LAST_ARG_REGNUM
2917 && !fp_register_arg_p (typecode, arg_type))
2919 LONGEST regval = extract_unsigned_integer (val, partial_len);
2922 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2924 phex (regval, MIPS_SAVED_REGSIZE));
2925 write_register (argreg, regval);
2932 /* Compute the the offset into the stack at which we
2933 will copy the next parameter.
2935 In the new EABI (and the NABI32), the stack_offset
2936 only needs to be adjusted when it has been used. */
2939 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2943 fprintf_unfiltered (gdb_stdlog, "\n");
2946 /* Return adjusted stack pointer. */
2950 /* N32/N64 version of push_arguments. */
2953 mips_n32n64_push_arguments (int nargs,
2954 struct value **args,
2957 CORE_ADDR struct_addr)
2963 int stack_offset = 0;
2965 /* First ensure that the stack and structure return address (if any)
2966 are properly aligned. The stack has to be at least 64-bit
2967 aligned even on 32-bit machines, because doubles must be 64-bit
2968 aligned. For n32 and n64, stack frames need to be 128-bit
2969 aligned, so we round to this widest known alignment. */
2971 sp = ROUND_DOWN (sp, 16);
2972 struct_addr = ROUND_DOWN (struct_addr, 16);
2974 /* Now make space on the stack for the args. */
2975 for (argnum = 0; argnum < nargs; argnum++)
2976 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2977 MIPS_STACK_ARGSIZE);
2978 sp -= ROUND_UP (len, 16);
2981 fprintf_unfiltered (gdb_stdlog,
2982 "mips_n32n64_push_arguments: sp=0x%s allocated %d\n",
2983 paddr_nz (sp), ROUND_UP (len, 16));
2985 /* Initialize the integer and float register pointers. */
2987 float_argreg = FPA0_REGNUM;
2989 /* The struct_return pointer occupies the first parameter-passing reg. */
2993 fprintf_unfiltered (gdb_stdlog,
2994 "mips_n32n64_push_arguments: struct_return reg=%d 0x%s\n",
2995 argreg, paddr_nz (struct_addr));
2996 write_register (argreg++, struct_addr);
2999 /* Now load as many as possible of the first arguments into
3000 registers, and push the rest onto the stack. Loop thru args
3001 from first to last. */
3002 for (argnum = 0; argnum < nargs; argnum++)
3005 char valbuf[MAX_REGISTER_SIZE];
3006 struct value *arg = args[argnum];
3007 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3008 int len = TYPE_LENGTH (arg_type);
3009 enum type_code typecode = TYPE_CODE (arg_type);
3012 fprintf_unfiltered (gdb_stdlog,
3013 "mips_n32n64_push_arguments: %d len=%d type=%d",
3014 argnum + 1, len, (int) typecode);
3016 val = (char *) VALUE_CONTENTS (arg);
3018 if (fp_register_arg_p (typecode, arg_type)
3019 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3021 /* This is a floating point value that fits entirely
3022 in a single register. */
3023 /* On 32 bit ABI's the float_argreg is further adjusted
3024 above to ensure that it is even register aligned. */
3025 LONGEST regval = extract_unsigned_integer (val, len);
3027 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3028 float_argreg, phex (regval, len));
3029 write_register (float_argreg++, regval);
3032 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3033 argreg, phex (regval, len));
3034 write_register (argreg, regval);
3039 /* Copy the argument to general registers or the stack in
3040 register-sized pieces. Large arguments are split between
3041 registers and stack. */
3042 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3043 are treated specially: Irix cc passes them in registers
3044 where gcc sometimes puts them on the stack. For maximum
3045 compatibility, we will put them in both places. */
3046 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3047 (len % MIPS_SAVED_REGSIZE != 0));
3048 /* Note: Floating-point values that didn't fit into an FP
3049 register are only written to memory. */
3052 /* Rememer if the argument was written to the stack. */
3053 int stack_used_p = 0;
3054 int partial_len = len < MIPS_SAVED_REGSIZE ?
3055 len : MIPS_SAVED_REGSIZE;
3058 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3061 /* Write this portion of the argument to the stack. */
3062 if (argreg > MIPS_LAST_ARG_REGNUM
3064 || fp_register_arg_p (typecode, arg_type))
3066 /* Should shorter than int integer values be
3067 promoted to int before being stored? */
3068 int longword_offset = 0;
3071 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3073 if (MIPS_STACK_ARGSIZE == 8 &&
3074 (typecode == TYPE_CODE_INT ||
3075 typecode == TYPE_CODE_PTR ||
3076 typecode == TYPE_CODE_FLT) && len <= 4)
3077 longword_offset = MIPS_STACK_ARGSIZE - len;
3082 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3083 paddr_nz (stack_offset));
3084 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3085 paddr_nz (longword_offset));
3088 addr = sp + stack_offset + longword_offset;
3093 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3095 for (i = 0; i < partial_len; i++)
3097 fprintf_unfiltered (gdb_stdlog, "%02x",
3101 write_memory (addr, val, partial_len);
3104 /* Note!!! This is NOT an else clause. Odd sized
3105 structs may go thru BOTH paths. Floating point
3106 arguments will not. */
3107 /* Write this portion of the argument to a general
3108 purpose register. */
3109 if (argreg <= MIPS_LAST_ARG_REGNUM
3110 && !fp_register_arg_p (typecode, arg_type))
3112 LONGEST regval = extract_unsigned_integer (val, partial_len);
3114 /* A non-floating-point argument being passed in a
3115 general register. If a struct or union, and if
3116 the remaining length is smaller than the register
3117 size, we have to adjust the register value on
3120 It does not seem to be necessary to do the
3121 same for integral types.
3123 cagney/2001-07-23: gdb/179: Also, GCC, when
3124 outputting LE O32 with sizeof (struct) <
3125 MIPS_SAVED_REGSIZE, generates a left shift as
3126 part of storing the argument in a register a
3127 register (the left shift isn't generated when
3128 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3129 is quite possible that this is GCC contradicting
3130 the LE/O32 ABI, GDB has not been adjusted to
3131 accommodate this. Either someone needs to
3132 demonstrate that the LE/O32 ABI specifies such a
3133 left shift OR this new ABI gets identified as
3134 such and GDB gets tweaked accordingly. */
3136 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3137 && partial_len < MIPS_SAVED_REGSIZE
3138 && (typecode == TYPE_CODE_STRUCT ||
3139 typecode == TYPE_CODE_UNION))
3140 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3144 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3146 phex (regval, MIPS_SAVED_REGSIZE));
3147 write_register (argreg, regval);
3154 /* Compute the the offset into the stack at which we
3155 will copy the next parameter.
3157 In N32 (N64?), the stack_offset only needs to be
3158 adjusted when it has been used. */
3161 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3165 fprintf_unfiltered (gdb_stdlog, "\n");
3168 /* Return adjusted stack pointer. */
3172 /* O32 version of push_arguments. */
3175 mips_o32_push_arguments (int nargs,
3176 struct value **args,
3179 CORE_ADDR struct_addr)
3185 int stack_offset = 0;
3187 /* First ensure that the stack and structure return address (if any)
3188 are properly aligned. The stack has to be at least 64-bit
3189 aligned even on 32-bit machines, because doubles must be 64-bit
3190 aligned. For n32 and n64, stack frames need to be 128-bit
3191 aligned, so we round to this widest known alignment. */
3193 sp = ROUND_DOWN (sp, 16);
3194 struct_addr = ROUND_DOWN (struct_addr, 16);
3196 /* Now make space on the stack for the args. */
3197 for (argnum = 0; argnum < nargs; argnum++)
3198 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3199 MIPS_STACK_ARGSIZE);
3200 sp -= ROUND_UP (len, 16);
3203 fprintf_unfiltered (gdb_stdlog,
3204 "mips_o32_push_arguments: sp=0x%s allocated %d\n",
3205 paddr_nz (sp), ROUND_UP (len, 16));
3207 /* Initialize the integer and float register pointers. */
3209 float_argreg = FPA0_REGNUM;
3211 /* The struct_return pointer occupies the first parameter-passing reg. */
3215 fprintf_unfiltered (gdb_stdlog,
3216 "mips_o32_push_arguments: struct_return reg=%d 0x%s\n",
3217 argreg, paddr_nz (struct_addr));
3218 write_register (argreg++, struct_addr);
3219 stack_offset += MIPS_STACK_ARGSIZE;
3222 /* Now load as many as possible of the first arguments into
3223 registers, and push the rest onto the stack. Loop thru args
3224 from first to last. */
3225 for (argnum = 0; argnum < nargs; argnum++)
3228 char valbuf[MAX_REGISTER_SIZE];
3229 struct value *arg = args[argnum];
3230 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3231 int len = TYPE_LENGTH (arg_type);
3232 enum type_code typecode = TYPE_CODE (arg_type);
3235 fprintf_unfiltered (gdb_stdlog,
3236 "mips_o32_push_arguments: %d len=%d type=%d",
3237 argnum + 1, len, (int) typecode);
3239 val = (char *) VALUE_CONTENTS (arg);
3241 /* 32-bit ABIs always start floating point arguments in an
3242 even-numbered floating point register. Round the FP register
3243 up before the check to see if there are any FP registers
3244 left. O32/O64 targets also pass the FP in the integer
3245 registers so also round up normal registers. */
3246 if (!FP_REGISTER_DOUBLE
3247 && fp_register_arg_p (typecode, arg_type))
3249 if ((float_argreg & 1))
3253 /* Floating point arguments passed in registers have to be
3254 treated specially. On 32-bit architectures, doubles
3255 are passed in register pairs; the even register gets
3256 the low word, and the odd register gets the high word.
3257 On O32/O64, the first two floating point arguments are
3258 also copied to general registers, because MIPS16 functions
3259 don't use float registers for arguments. This duplication of
3260 arguments in general registers can't hurt non-MIPS16 functions
3261 because those registers are normally skipped. */
3263 if (fp_register_arg_p (typecode, arg_type)
3264 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3266 if (!FP_REGISTER_DOUBLE && len == 8)
3268 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3269 unsigned long regval;
3271 /* Write the low word of the double to the even register(s). */
3272 regval = extract_unsigned_integer (val + low_offset, 4);
3274 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3275 float_argreg, phex (regval, 4));
3276 write_register (float_argreg++, regval);
3278 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3279 argreg, phex (regval, 4));
3280 write_register (argreg++, regval);
3282 /* Write the high word of the double to the odd register(s). */
3283 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3285 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3286 float_argreg, phex (regval, 4));
3287 write_register (float_argreg++, regval);
3290 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3291 argreg, phex (regval, 4));
3292 write_register (argreg++, regval);
3296 /* This is a floating point value that fits entirely
3297 in a single register. */
3298 /* On 32 bit ABI's the float_argreg is further adjusted
3299 above to ensure that it is even register aligned. */
3300 LONGEST regval = extract_unsigned_integer (val, len);
3302 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3303 float_argreg, phex (regval, len));
3304 write_register (float_argreg++, regval);
3305 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3306 registers for each argument. The below is (my
3307 guess) to ensure that the corresponding integer
3308 register has reserved the same space. */
3310 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3311 argreg, phex (regval, len));
3312 write_register (argreg, regval);
3313 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3315 /* Reserve space for the FP register. */
3316 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3320 /* Copy the argument to general registers or the stack in
3321 register-sized pieces. Large arguments are split between
3322 registers and stack. */
3323 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3324 are treated specially: Irix cc passes them in registers
3325 where gcc sometimes puts them on the stack. For maximum
3326 compatibility, we will put them in both places. */
3327 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3328 (len % MIPS_SAVED_REGSIZE != 0));
3329 /* Structures should be aligned to eight bytes (even arg registers)
3330 on MIPS_ABI_O32, if their first member has double precision. */
3331 if (MIPS_SAVED_REGSIZE < 8
3332 && mips_type_needs_double_align (arg_type))
3337 /* Note: Floating-point values that didn't fit into an FP
3338 register are only written to memory. */
3341 /* Remember if the argument was written to the stack. */
3342 int stack_used_p = 0;
3344 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3347 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3350 /* Write this portion of the argument to the stack. */
3351 if (argreg > MIPS_LAST_ARG_REGNUM
3353 || fp_register_arg_p (typecode, arg_type))
3355 /* Should shorter than int integer values be
3356 promoted to int before being stored? */
3357 int longword_offset = 0;
3360 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3362 if (MIPS_STACK_ARGSIZE == 8 &&
3363 (typecode == TYPE_CODE_INT ||
3364 typecode == TYPE_CODE_PTR ||
3365 typecode == TYPE_CODE_FLT) && len <= 4)
3366 longword_offset = MIPS_STACK_ARGSIZE - len;
3371 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3372 paddr_nz (stack_offset));
3373 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3374 paddr_nz (longword_offset));
3377 addr = sp + stack_offset + longword_offset;
3382 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3384 for (i = 0; i < partial_len; i++)
3386 fprintf_unfiltered (gdb_stdlog, "%02x",
3390 write_memory (addr, val, partial_len);
3393 /* Note!!! This is NOT an else clause. Odd sized
3394 structs may go thru BOTH paths. Floating point
3395 arguments will not. */
3396 /* Write this portion of the argument to a general
3397 purpose register. */
3398 if (argreg <= MIPS_LAST_ARG_REGNUM
3399 && !fp_register_arg_p (typecode, arg_type))
3401 LONGEST regval = extract_signed_integer (val, partial_len);
3402 /* Value may need to be sign extended, because
3403 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3405 /* A non-floating-point argument being passed in a
3406 general register. If a struct or union, and if
3407 the remaining length is smaller than the register
3408 size, we have to adjust the register value on
3411 It does not seem to be necessary to do the
3412 same for integral types.
3414 Also don't do this adjustment on O64 binaries.
3416 cagney/2001-07-23: gdb/179: Also, GCC, when
3417 outputting LE O32 with sizeof (struct) <
3418 MIPS_SAVED_REGSIZE, generates a left shift as
3419 part of storing the argument in a register a
3420 register (the left shift isn't generated when
3421 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3422 is quite possible that this is GCC contradicting
3423 the LE/O32 ABI, GDB has not been adjusted to
3424 accommodate this. Either someone needs to
3425 demonstrate that the LE/O32 ABI specifies such a
3426 left shift OR this new ABI gets identified as
3427 such and GDB gets tweaked accordingly. */
3429 if (MIPS_SAVED_REGSIZE < 8
3430 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3431 && partial_len < MIPS_SAVED_REGSIZE
3432 && (typecode == TYPE_CODE_STRUCT ||
3433 typecode == TYPE_CODE_UNION))
3434 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3438 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3440 phex (regval, MIPS_SAVED_REGSIZE));
3441 write_register (argreg, regval);
3444 /* Prevent subsequent floating point arguments from
3445 being passed in floating point registers. */
3446 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3452 /* Compute the the offset into the stack at which we
3453 will copy the next parameter.
3455 In older ABIs, the caller reserved space for
3456 registers that contained arguments. This was loosely
3457 refered to as their "home". Consequently, space is
3458 always allocated. */
3460 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3464 fprintf_unfiltered (gdb_stdlog, "\n");
3467 /* Return adjusted stack pointer. */
3471 /* O64 version of push_arguments. */
3474 mips_o64_push_arguments (int nargs,
3475 struct value **args,
3478 CORE_ADDR struct_addr)
3484 int stack_offset = 0;
3486 /* First ensure that the stack and structure return address (if any)
3487 are properly aligned. The stack has to be at least 64-bit
3488 aligned even on 32-bit machines, because doubles must be 64-bit
3489 aligned. For n32 and n64, stack frames need to be 128-bit
3490 aligned, so we round to this widest known alignment. */
3492 sp = ROUND_DOWN (sp, 16);
3493 struct_addr = ROUND_DOWN (struct_addr, 16);
3495 /* Now make space on the stack for the args. */
3496 for (argnum = 0; argnum < nargs; argnum++)
3497 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3498 MIPS_STACK_ARGSIZE);
3499 sp -= ROUND_UP (len, 16);
3502 fprintf_unfiltered (gdb_stdlog,
3503 "mips_o64_push_arguments: sp=0x%s allocated %d\n",
3504 paddr_nz (sp), ROUND_UP (len, 16));
3506 /* Initialize the integer and float register pointers. */
3508 float_argreg = FPA0_REGNUM;
3510 /* The struct_return pointer occupies the first parameter-passing reg. */
3514 fprintf_unfiltered (gdb_stdlog,
3515 "mips_o64_push_arguments: struct_return reg=%d 0x%s\n",
3516 argreg, paddr_nz (struct_addr));
3517 write_register (argreg++, struct_addr);
3518 stack_offset += MIPS_STACK_ARGSIZE;
3521 /* Now load as many as possible of the first arguments into
3522 registers, and push the rest onto the stack. Loop thru args
3523 from first to last. */
3524 for (argnum = 0; argnum < nargs; argnum++)
3527 char valbuf[MAX_REGISTER_SIZE];
3528 struct value *arg = args[argnum];
3529 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3530 int len = TYPE_LENGTH (arg_type);
3531 enum type_code typecode = TYPE_CODE (arg_type);
3534 fprintf_unfiltered (gdb_stdlog,
3535 "mips_o64_push_arguments: %d len=%d type=%d",
3536 argnum + 1, len, (int) typecode);
3538 val = (char *) VALUE_CONTENTS (arg);
3540 /* 32-bit ABIs always start floating point arguments in an
3541 even-numbered floating point register. Round the FP register
3542 up before the check to see if there are any FP registers
3543 left. O32/O64 targets also pass the FP in the integer
3544 registers so also round up normal registers. */
3545 if (!FP_REGISTER_DOUBLE
3546 && fp_register_arg_p (typecode, arg_type))
3548 if ((float_argreg & 1))
3552 /* Floating point arguments passed in registers have to be
3553 treated specially. On 32-bit architectures, doubles
3554 are passed in register pairs; the even register gets
3555 the low word, and the odd register gets the high word.
3556 On O32/O64, the first two floating point arguments are
3557 also copied to general registers, because MIPS16 functions
3558 don't use float registers for arguments. This duplication of
3559 arguments in general registers can't hurt non-MIPS16 functions
3560 because those registers are normally skipped. */
3562 if (fp_register_arg_p (typecode, arg_type)
3563 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3565 if (!FP_REGISTER_DOUBLE && len == 8)
3567 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3568 unsigned long regval;
3570 /* Write the low word of the double to the even register(s). */
3571 regval = extract_unsigned_integer (val + low_offset, 4);
3573 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3574 float_argreg, phex (regval, 4));
3575 write_register (float_argreg++, regval);
3577 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3578 argreg, phex (regval, 4));
3579 write_register (argreg++, regval);
3581 /* Write the high word of the double to the odd register(s). */
3582 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3584 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3585 float_argreg, phex (regval, 4));
3586 write_register (float_argreg++, regval);
3589 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3590 argreg, phex (regval, 4));
3591 write_register (argreg++, regval);
3595 /* This is a floating point value that fits entirely
3596 in a single register. */
3597 /* On 32 bit ABI's the float_argreg is further adjusted
3598 above to ensure that it is even register aligned. */
3599 LONGEST regval = extract_unsigned_integer (val, len);
3601 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3602 float_argreg, phex (regval, len));
3603 write_register (float_argreg++, regval);
3604 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3605 registers for each argument. The below is (my
3606 guess) to ensure that the corresponding integer
3607 register has reserved the same space. */
3609 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3610 argreg, phex (regval, len));
3611 write_register (argreg, regval);
3612 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3614 /* Reserve space for the FP register. */
3615 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3619 /* Copy the argument to general registers or the stack in
3620 register-sized pieces. Large arguments are split between
3621 registers and stack. */
3622 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3623 are treated specially: Irix cc passes them in registers
3624 where gcc sometimes puts them on the stack. For maximum
3625 compatibility, we will put them in both places. */
3626 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3627 (len % MIPS_SAVED_REGSIZE != 0));
3628 /* Structures should be aligned to eight bytes (even arg registers)
3629 on MIPS_ABI_O32, if their first member has double precision. */
3630 if (MIPS_SAVED_REGSIZE < 8
3631 && mips_type_needs_double_align (arg_type))
3636 /* Note: Floating-point values that didn't fit into an FP
3637 register are only written to memory. */
3640 /* Remember if the argument was written to the stack. */
3641 int stack_used_p = 0;
3643 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3646 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3649 /* Write this portion of the argument to the stack. */
3650 if (argreg > MIPS_LAST_ARG_REGNUM
3652 || fp_register_arg_p (typecode, arg_type))
3654 /* Should shorter than int integer values be
3655 promoted to int before being stored? */
3656 int longword_offset = 0;
3659 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3661 if (MIPS_STACK_ARGSIZE == 8 &&
3662 (typecode == TYPE_CODE_INT ||
3663 typecode == TYPE_CODE_PTR ||
3664 typecode == TYPE_CODE_FLT) && len <= 4)
3665 longword_offset = MIPS_STACK_ARGSIZE - len;
3670 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3671 paddr_nz (stack_offset));
3672 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3673 paddr_nz (longword_offset));
3676 addr = sp + stack_offset + longword_offset;
3681 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3683 for (i = 0; i < partial_len; i++)
3685 fprintf_unfiltered (gdb_stdlog, "%02x",
3689 write_memory (addr, val, partial_len);
3692 /* Note!!! This is NOT an else clause. Odd sized
3693 structs may go thru BOTH paths. Floating point
3694 arguments will not. */
3695 /* Write this portion of the argument to a general
3696 purpose register. */
3697 if (argreg <= MIPS_LAST_ARG_REGNUM
3698 && !fp_register_arg_p (typecode, arg_type))
3700 LONGEST regval = extract_signed_integer (val, partial_len);
3701 /* Value may need to be sign extended, because
3702 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3704 /* A non-floating-point argument being passed in a
3705 general register. If a struct or union, and if
3706 the remaining length is smaller than the register
3707 size, we have to adjust the register value on
3710 It does not seem to be necessary to do the
3711 same for integral types.
3713 Also don't do this adjustment on O64 binaries.
3715 cagney/2001-07-23: gdb/179: Also, GCC, when
3716 outputting LE O32 with sizeof (struct) <
3717 MIPS_SAVED_REGSIZE, generates a left shift as
3718 part of storing the argument in a register a
3719 register (the left shift isn't generated when
3720 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3721 is quite possible that this is GCC contradicting
3722 the LE/O32 ABI, GDB has not been adjusted to
3723 accommodate this. Either someone needs to
3724 demonstrate that the LE/O32 ABI specifies such a
3725 left shift OR this new ABI gets identified as
3726 such and GDB gets tweaked accordingly. */
3728 if (MIPS_SAVED_REGSIZE < 8
3729 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3730 && partial_len < MIPS_SAVED_REGSIZE
3731 && (typecode == TYPE_CODE_STRUCT ||
3732 typecode == TYPE_CODE_UNION))
3733 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3737 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3739 phex (regval, MIPS_SAVED_REGSIZE));
3740 write_register (argreg, regval);
3743 /* Prevent subsequent floating point arguments from
3744 being passed in floating point registers. */
3745 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3751 /* Compute the the offset into the stack at which we
3752 will copy the next parameter.
3754 In older ABIs, the caller reserved space for
3755 registers that contained arguments. This was loosely
3756 refered to as their "home". Consequently, space is
3757 always allocated. */
3759 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3763 fprintf_unfiltered (gdb_stdlog, "\n");
3766 /* Return adjusted stack pointer. */
3771 mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
3773 /* Set the return address register to point to the entry
3774 point of the program, where a breakpoint lies in wait. */
3775 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
3780 mips_pop_frame (void)
3782 register int regnum;
3783 struct frame_info *frame = get_current_frame ();
3784 CORE_ADDR new_sp = get_frame_base (frame);
3785 mips_extra_func_info_t proc_desc;
3787 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3789 generic_pop_dummy_frame ();
3790 flush_cached_frames ();
3794 proc_desc = get_frame_extra_info (frame)->proc_desc;
3795 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3796 if (get_frame_saved_regs (frame) == NULL)
3797 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3798 for (regnum = 0; regnum < NUM_REGS; regnum++)
3799 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3800 && get_frame_saved_regs (frame)[regnum])
3802 /* Floating point registers must not be sign extended,
3803 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3805 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3806 write_register (regnum,
3807 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3808 MIPS_SAVED_REGSIZE));
3810 write_register (regnum,
3811 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3812 MIPS_SAVED_REGSIZE));
3815 write_register (SP_REGNUM, new_sp);
3816 flush_cached_frames ();
3818 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3820 struct linked_proc_info *pi_ptr, *prev_ptr;
3822 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3824 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3826 if (&pi_ptr->info == proc_desc)
3831 error ("Can't locate dummy extra frame info\n");
3833 if (prev_ptr != NULL)
3834 prev_ptr->next = pi_ptr->next;
3836 linked_proc_desc_table = pi_ptr->next;
3840 write_register (HI_REGNUM,
3841 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3842 MIPS_SAVED_REGSIZE));
3843 write_register (LO_REGNUM,
3844 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3845 MIPS_SAVED_REGSIZE));
3846 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3847 write_register (FCRCS_REGNUM,
3848 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3849 MIPS_SAVED_REGSIZE));
3854 mips_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
3855 struct value **args, struct type *type, int gcc_p)
3857 write_register(T9_REGNUM, fun);
3860 /* Floating point register management.
3862 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3863 64bit operations, these early MIPS cpus treat fp register pairs
3864 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3865 registers and offer a compatibility mode that emulates the MIPS2 fp
3866 model. When operating in MIPS2 fp compat mode, later cpu's split
3867 double precision floats into two 32-bit chunks and store them in
3868 consecutive fp regs. To display 64-bit floats stored in this
3869 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3870 Throw in user-configurable endianness and you have a real mess.
3872 The way this works is:
3873 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3874 double-precision value will be split across two logical registers.
3875 The lower-numbered logical register will hold the low-order bits,
3876 regardless of the processor's endianness.
3877 - If we are on a 64-bit processor, and we are looking for a
3878 single-precision value, it will be in the low ordered bits
3879 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3880 save slot in memory.
3881 - If we are in 64-bit mode, everything is straightforward.
3883 Note that this code only deals with "live" registers at the top of the
3884 stack. We will attempt to deal with saved registers later, when
3885 the raw/cooked register interface is in place. (We need a general
3886 interface that can deal with dynamic saved register sizes -- fp
3887 regs could be 32 bits wide in one frame and 64 on the frame above
3890 static struct type *
3891 mips_float_register_type (void)
3893 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3894 return builtin_type_ieee_single_big;
3896 return builtin_type_ieee_single_little;
3899 static struct type *
3900 mips_double_register_type (void)
3902 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3903 return builtin_type_ieee_double_big;
3905 return builtin_type_ieee_double_little;
3908 /* Copy a 32-bit single-precision value from the current frame
3909 into rare_buffer. */
3912 mips_read_fp_register_single (int regno, char *rare_buffer)
3914 int raw_size = REGISTER_RAW_SIZE (regno);
3915 char *raw_buffer = alloca (raw_size);
3917 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3918 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3921 /* We have a 64-bit value for this register. Find the low-order
3925 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3930 memcpy (rare_buffer, raw_buffer + offset, 4);
3934 memcpy (rare_buffer, raw_buffer, 4);
3938 /* Copy a 64-bit double-precision value from the current frame into
3939 rare_buffer. This may include getting half of it from the next
3943 mips_read_fp_register_double (int regno, char *rare_buffer)
3945 int raw_size = REGISTER_RAW_SIZE (regno);
3947 if (raw_size == 8 && !mips2_fp_compat ())
3949 /* We have a 64-bit value for this register, and we should use
3951 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
3952 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3956 if ((regno - FP0_REGNUM) & 1)
3957 internal_error (__FILE__, __LINE__,
3958 "mips_read_fp_register_double: bad access to "
3959 "odd-numbered FP register");
3961 /* mips_read_fp_register_single will find the correct 32 bits from
3963 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3965 mips_read_fp_register_single (regno, rare_buffer + 4);
3966 mips_read_fp_register_single (regno + 1, rare_buffer);
3970 mips_read_fp_register_single (regno, rare_buffer);
3971 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
3977 mips_print_fp_register (int regnum)
3978 { /* do values for FP (float) regs */
3980 double doub, flt1, flt2; /* doubles extracted from raw hex data */
3981 int inv1, inv2, namelen;
3983 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
3985 printf_filtered ("%s:", REGISTER_NAME (regnum));
3986 printf_filtered ("%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), "");
3988 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
3990 /* 4-byte registers: Print hex and floating. Also print even
3991 numbered registers as doubles. */
3992 mips_read_fp_register_single (regnum, raw_buffer);
3993 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
3995 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
3998 printf_filtered (" flt: ");
4000 printf_filtered (" <invalid float> ");
4002 printf_filtered ("%-17.9g", flt1);
4004 if (regnum % 2 == 0)
4006 mips_read_fp_register_double (regnum, raw_buffer);
4007 doub = unpack_double (mips_double_register_type (), raw_buffer,
4010 printf_filtered (" dbl: ");
4012 printf_filtered ("<invalid double>");
4014 printf_filtered ("%-24.17g", doub);
4019 /* Eight byte registers: print each one as hex, float and double. */
4020 mips_read_fp_register_single (regnum, raw_buffer);
4021 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4023 mips_read_fp_register_double (regnum, raw_buffer);
4024 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4027 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4030 printf_filtered (" flt: ");
4032 printf_filtered ("<invalid float>");
4034 printf_filtered ("%-17.9g", flt1);
4036 printf_filtered (" dbl: ");
4038 printf_filtered ("<invalid double>");
4040 printf_filtered ("%-24.17g", doub);
4045 mips_print_register (int regnum, int all)
4047 char raw_buffer[MAX_REGISTER_SIZE];
4050 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4052 mips_print_fp_register (regnum);
4056 /* Get the data in raw format. */
4057 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4059 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4063 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4065 /* The problem with printing numeric register names (r26, etc.) is that
4066 the user can't use them on input. Probably the best solution is to
4067 fix it so that either the numeric or the funky (a2, etc.) names
4068 are accepted on input. */
4069 if (regnum < MIPS_NUMREGS)
4070 printf_filtered ("(r%d): ", regnum);
4072 printf_filtered (": ");
4074 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4075 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4079 print_scalar_formatted (raw_buffer + offset,
4080 REGISTER_VIRTUAL_TYPE (regnum),
4081 'x', 0, gdb_stdout);
4084 /* Replacement for generic do_registers_info.
4085 Print regs in pretty columns. */
4088 do_fp_register_row (int regnum)
4090 printf_filtered (" ");
4091 mips_print_fp_register (regnum);
4092 printf_filtered ("\n");
4097 /* Print a row's worth of GP (int) registers, with name labels above */
4100 do_gp_register_row (int regnum)
4102 /* do values for GP (int) regs */
4103 char raw_buffer[MAX_REGISTER_SIZE];
4104 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4106 int start_regnum = regnum;
4107 int numregs = NUM_REGS;
4110 /* For GP registers, we print a separate row of names above the vals */
4111 printf_filtered (" ");
4112 for (col = 0; col < ncols && regnum < numregs; regnum++)
4114 if (*REGISTER_NAME (regnum) == '\0')
4115 continue; /* unused register */
4116 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4117 break; /* end the row: reached FP register */
4118 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4119 REGISTER_NAME (regnum));
4122 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4123 start_regnum); /* print the R0 to R31 names */
4125 regnum = start_regnum; /* go back to start of row */
4126 /* now print the values in hex, 4 or 8 to the row */
4127 for (col = 0; col < ncols && regnum < numregs; regnum++)
4129 if (*REGISTER_NAME (regnum) == '\0')
4130 continue; /* unused register */
4131 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4132 break; /* end row: reached FP register */
4133 /* OK: get the data in raw format. */
4134 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4135 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4136 /* pad small registers */
4137 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4138 printf_filtered (" ");
4139 /* Now print the register value in hex, endian order. */
4140 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4141 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4142 byte < REGISTER_RAW_SIZE (regnum);
4144 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4146 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4149 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4150 printf_filtered (" ");
4153 if (col > 0) /* ie. if we actually printed anything... */
4154 printf_filtered ("\n");
4159 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4162 mips_do_registers_info (int regnum, int fpregs)
4164 if (regnum != -1) /* do one specified register */
4166 if (*(REGISTER_NAME (regnum)) == '\0')
4167 error ("Not a valid register for the current processor type");
4169 mips_print_register (regnum, 0);
4170 printf_filtered ("\n");
4173 /* do all (or most) registers */
4176 while (regnum < NUM_REGS)
4178 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4179 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4180 regnum = do_fp_register_row (regnum); /* FP regs */
4182 regnum += MIPS_NUMREGS; /* skip floating point regs */
4184 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4189 /* Is this a branch with a delay slot? */
4191 static int is_delayed (unsigned long);
4194 is_delayed (unsigned long insn)
4197 for (i = 0; i < NUMOPCODES; ++i)
4198 if (mips_opcodes[i].pinfo != INSN_MACRO
4199 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4201 return (i < NUMOPCODES
4202 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4203 | INSN_COND_BRANCH_DELAY
4204 | INSN_COND_BRANCH_LIKELY)));
4208 mips_step_skips_delay (CORE_ADDR pc)
4210 char buf[MIPS_INSTLEN];
4212 /* There is no branch delay slot on MIPS16. */
4213 if (pc_is_mips16 (pc))
4216 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4217 /* If error reading memory, guess that it is not a delayed branch. */
4219 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4223 /* Skip the PC past function prologue instructions (32-bit version).
4224 This is a helper function for mips_skip_prologue. */
4227 mips32_skip_prologue (CORE_ADDR pc)
4231 int seen_sp_adjust = 0;
4232 int load_immediate_bytes = 0;
4234 /* Skip the typical prologue instructions. These are the stack adjustment
4235 instruction and the instructions that save registers on the stack
4236 or in the gcc frame. */
4237 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4239 unsigned long high_word;
4241 inst = mips_fetch_instruction (pc);
4242 high_word = (inst >> 16) & 0xffff;
4244 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4245 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4247 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4248 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4250 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4251 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4252 && (inst & 0x001F0000)) /* reg != $zero */
4255 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4257 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4259 continue; /* reg != $zero */
4261 /* move $s8,$sp. With different versions of gas this will be either
4262 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4263 Accept any one of these. */
4264 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4267 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4269 else if (high_word == 0x3c1c) /* lui $gp,n */
4271 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4273 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4274 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4276 /* The following instructions load $at or $t0 with an immediate
4277 value in preparation for a stack adjustment via
4278 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4279 a local variable, so we accept them only before a stack adjustment
4280 instruction was seen. */
4281 else if (!seen_sp_adjust)
4283 if (high_word == 0x3c01 || /* lui $at,n */
4284 high_word == 0x3c08) /* lui $t0,n */
4286 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4289 else if (high_word == 0x3421 || /* ori $at,$at,n */
4290 high_word == 0x3508 || /* ori $t0,$t0,n */
4291 high_word == 0x3401 || /* ori $at,$zero,n */
4292 high_word == 0x3408) /* ori $t0,$zero,n */
4294 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4304 /* In a frameless function, we might have incorrectly
4305 skipped some load immediate instructions. Undo the skipping
4306 if the load immediate was not followed by a stack adjustment. */
4307 if (load_immediate_bytes && !seen_sp_adjust)
4308 pc -= load_immediate_bytes;
4312 /* Skip the PC past function prologue instructions (16-bit version).
4313 This is a helper function for mips_skip_prologue. */
4316 mips16_skip_prologue (CORE_ADDR pc)
4319 int extend_bytes = 0;
4320 int prev_extend_bytes;
4322 /* Table of instructions likely to be found in a function prologue. */
4325 unsigned short inst;
4326 unsigned short mask;
4333 , /* addiu $sp,offset */
4337 , /* daddiu $sp,offset */
4341 , /* sw reg,n($sp) */
4345 , /* sd reg,n($sp) */
4349 , /* sw $ra,n($sp) */
4353 , /* sd $ra,n($sp) */
4361 , /* sw $a0-$a3,n($s1) */
4365 , /* move reg,$a0-$a3 */
4369 , /* entry pseudo-op */
4373 , /* addiu $s1,$sp,n */
4376 } /* end of table marker */
4379 /* Skip the typical prologue instructions. These are the stack adjustment
4380 instruction and the instructions that save registers on the stack
4381 or in the gcc frame. */
4382 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4384 unsigned short inst;
4387 inst = mips_fetch_instruction (pc);
4389 /* Normally we ignore an extend instruction. However, if it is
4390 not followed by a valid prologue instruction, we must adjust
4391 the pc back over the extend so that it won't be considered
4392 part of the prologue. */
4393 if ((inst & 0xf800) == 0xf000) /* extend */
4395 extend_bytes = MIPS16_INSTLEN;
4398 prev_extend_bytes = extend_bytes;
4401 /* Check for other valid prologue instructions besides extend. */
4402 for (i = 0; table[i].mask != 0; i++)
4403 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4405 if (table[i].mask != 0) /* it was in table? */
4406 continue; /* ignore it */
4410 /* Return the current pc, adjusted backwards by 2 if
4411 the previous instruction was an extend. */
4412 return pc - prev_extend_bytes;
4418 /* To skip prologues, I use this predicate. Returns either PC itself
4419 if the code at PC does not look like a function prologue; otherwise
4420 returns an address that (if we're lucky) follows the prologue. If
4421 LENIENT, then we must skip everything which is involved in setting
4422 up the frame (it's OK to skip more, just so long as we don't skip
4423 anything which might clobber the registers which are being saved.
4424 We must skip more in the case where part of the prologue is in the
4425 delay slot of a non-prologue instruction). */
4428 mips_skip_prologue (CORE_ADDR pc)
4430 /* See if we can determine the end of the prologue via the symbol table.
4431 If so, then return either PC, or the PC after the prologue, whichever
4434 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4436 if (post_prologue_pc != 0)
4437 return max (pc, post_prologue_pc);
4439 /* Can't determine prologue from the symbol table, need to examine
4442 if (pc_is_mips16 (pc))
4443 return mips16_skip_prologue (pc);
4445 return mips32_skip_prologue (pc);
4448 /* Determine how a return value is stored within the MIPS register
4449 file, given the return type `valtype'. */
4451 struct return_value_word
4460 return_value_location (struct type *valtype,
4461 struct return_value_word *hi,
4462 struct return_value_word *lo)
4464 int len = TYPE_LENGTH (valtype);
4466 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4467 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4468 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4470 if (!FP_REGISTER_DOUBLE && len == 8)
4472 /* We need to break a 64bit float in two 32 bit halves and
4473 spread them across a floating-point register pair. */
4474 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4475 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4476 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4477 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4479 hi->reg_offset = lo->reg_offset;
4480 lo->reg = FP0_REGNUM + 0;
4481 hi->reg = FP0_REGNUM + 1;
4487 /* The floating point value fits in a single floating-point
4489 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4490 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4493 lo->reg = FP0_REGNUM;
4504 /* Locate a result possibly spread across two registers. */
4506 lo->reg = regnum + 0;
4507 hi->reg = regnum + 1;
4508 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4509 && len < MIPS_SAVED_REGSIZE)
4511 /* "un-left-justify" the value in the low register */
4512 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4517 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4518 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4519 && len < MIPS_SAVED_REGSIZE * 2
4520 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4521 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4523 /* "un-left-justify" the value spread across two registers. */
4524 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4525 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4527 hi->len = len - lo->len;
4531 /* Only perform a partial copy of the second register. */
4534 if (len > MIPS_SAVED_REGSIZE)
4536 lo->len = MIPS_SAVED_REGSIZE;
4537 hi->len = len - MIPS_SAVED_REGSIZE;
4545 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4546 && REGISTER_RAW_SIZE (regnum) == 8
4547 && MIPS_SAVED_REGSIZE == 4)
4549 /* Account for the fact that only the least-signficant part
4550 of the register is being used */
4551 lo->reg_offset += 4;
4552 hi->reg_offset += 4;
4555 hi->buf_offset = lo->len;
4559 /* Given a return value in `regbuf' with a type `valtype', extract and
4560 copy its value into `valbuf'. */
4563 mips_eabi_extract_return_value (struct type *valtype,
4564 char regbuf[REGISTER_BYTES],
4567 struct return_value_word lo;
4568 struct return_value_word hi;
4569 return_value_location (valtype, &hi, &lo);
4571 memcpy (valbuf + lo.buf_offset,
4572 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4576 memcpy (valbuf + hi.buf_offset,
4577 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4582 mips_o64_extract_return_value (struct type *valtype,
4583 char regbuf[REGISTER_BYTES],
4586 struct return_value_word lo;
4587 struct return_value_word hi;
4588 return_value_location (valtype, &hi, &lo);
4590 memcpy (valbuf + lo.buf_offset,
4591 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4595 memcpy (valbuf + hi.buf_offset,
4596 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4600 /* Given a return value in `valbuf' with a type `valtype', write it's
4601 value into the appropriate register. */
4604 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4606 char raw_buffer[MAX_REGISTER_SIZE];
4607 struct return_value_word lo;
4608 struct return_value_word hi;
4609 return_value_location (valtype, &hi, &lo);
4611 memset (raw_buffer, 0, sizeof (raw_buffer));
4612 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4613 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4614 REGISTER_RAW_SIZE (lo.reg));
4618 memset (raw_buffer, 0, sizeof (raw_buffer));
4619 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4620 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4621 REGISTER_RAW_SIZE (hi.reg));
4626 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4628 char raw_buffer[MAX_REGISTER_SIZE];
4629 struct return_value_word lo;
4630 struct return_value_word hi;
4631 return_value_location (valtype, &hi, &lo);
4633 memset (raw_buffer, 0, sizeof (raw_buffer));
4634 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4635 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4636 REGISTER_RAW_SIZE (lo.reg));
4640 memset (raw_buffer, 0, sizeof (raw_buffer));
4641 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4642 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4643 REGISTER_RAW_SIZE (hi.reg));
4647 /* O32 ABI stuff. */
4650 mips_o32_xfer_return_value (struct type *type,
4651 struct regcache *regcache,
4652 bfd_byte *in, const bfd_byte *out)
4654 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4655 if (TYPE_CODE (type) == TYPE_CODE_FLT
4656 && TYPE_LENGTH (type) == 4
4657 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4659 /* A single-precision floating-point value. It fits in the
4660 least significant part of FP0. */
4662 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4663 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4664 TARGET_BYTE_ORDER, in, out, 0);
4666 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4667 && TYPE_LENGTH (type) == 8
4668 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4670 /* A double-precision floating-point value. It fits in the
4671 least significant part of FP0/FP1 but with byte ordering
4672 based on the target (???). */
4674 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4675 switch (TARGET_BYTE_ORDER)
4677 case BFD_ENDIAN_LITTLE:
4678 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4679 TARGET_BYTE_ORDER, in, out, 0);
4680 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4681 TARGET_BYTE_ORDER, in, out, 4);
4683 case BFD_ENDIAN_BIG:
4684 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4685 TARGET_BYTE_ORDER, in, out, 0);
4686 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4687 TARGET_BYTE_ORDER, in, out, 4);
4690 internal_error (__FILE__, __LINE__, "bad switch");
4694 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4695 && TYPE_NFIELDS (type) <= 2
4696 && TYPE_NFIELDS (type) >= 1
4697 && ((TYPE_NFIELDS (type) == 1
4698 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4700 || (TYPE_NFIELDS (type) == 2
4701 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4703 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4705 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4707 /* A struct that contains one or two floats. Each value is part
4708 in the least significant part of their floating point
4710 bfd_byte reg[MAX_REGISTER_SIZE];
4713 for (field = 0, regnum = FP0_REGNUM;
4714 field < TYPE_NFIELDS (type);
4715 field++, regnum += 2)
4717 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4720 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4721 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4722 TARGET_BYTE_ORDER, in, out, offset);
4727 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4728 || TYPE_CODE (type) == TYPE_CODE_UNION)
4730 /* A structure or union. Extract the left justified value,
4731 regardless of the byte order. I.e. DO NOT USE
4735 for (offset = 0, regnum = V0_REGNUM;
4736 offset < TYPE_LENGTH (type);
4737 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4739 int xfer = REGISTER_RAW_SIZE (regnum);
4740 if (offset + xfer > TYPE_LENGTH (type))
4741 xfer = TYPE_LENGTH (type) - offset;
4743 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4744 offset, xfer, regnum);
4745 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4752 /* A scalar extract each part but least-significant-byte
4753 justified. o32 thinks registers are 4 byte, regardless of
4754 the ISA. mips_stack_argsize controls this. */
4757 for (offset = 0, regnum = V0_REGNUM;
4758 offset < TYPE_LENGTH (type);
4759 offset += mips_stack_argsize (), regnum++)
4761 int xfer = mips_stack_argsize ();
4763 if (offset + xfer > TYPE_LENGTH (type))
4764 xfer = TYPE_LENGTH (type) - offset;
4766 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4767 offset, xfer, regnum);
4768 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4775 mips_o32_extract_return_value (struct type *type,
4776 struct regcache *regcache,
4779 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4783 mips_o32_store_return_value (struct type *type, char *valbuf)
4785 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4788 /* N32/N44 ABI stuff. */
4791 mips_n32n64_xfer_return_value (struct type *type,
4792 struct regcache *regcache,
4793 bfd_byte *in, const bfd_byte *out)
4795 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4796 if (TYPE_CODE (type) == TYPE_CODE_FLT
4797 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4799 /* A floating-point value belongs in the least significant part
4802 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4803 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4804 TARGET_BYTE_ORDER, in, out, 0);
4806 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4807 && TYPE_NFIELDS (type) <= 2
4808 && TYPE_NFIELDS (type) >= 1
4809 && ((TYPE_NFIELDS (type) == 1
4810 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4812 || (TYPE_NFIELDS (type) == 2
4813 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4815 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4817 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4819 /* A struct that contains one or two floats. Each value is part
4820 in the least significant part of their floating point
4822 bfd_byte reg[MAX_REGISTER_SIZE];
4825 for (field = 0, regnum = FP0_REGNUM;
4826 field < TYPE_NFIELDS (type);
4827 field++, regnum += 2)
4829 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4832 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4833 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4834 TARGET_BYTE_ORDER, in, out, offset);
4837 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4838 || TYPE_CODE (type) == TYPE_CODE_UNION)
4840 /* A structure or union. Extract the left justified value,
4841 regardless of the byte order. I.e. DO NOT USE
4845 for (offset = 0, regnum = V0_REGNUM;
4846 offset < TYPE_LENGTH (type);
4847 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4849 int xfer = REGISTER_RAW_SIZE (regnum);
4850 if (offset + xfer > TYPE_LENGTH (type))
4851 xfer = TYPE_LENGTH (type) - offset;
4853 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4854 offset, xfer, regnum);
4855 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4861 /* A scalar extract each part but least-significant-byte
4865 for (offset = 0, regnum = V0_REGNUM;
4866 offset < TYPE_LENGTH (type);
4867 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4869 int xfer = REGISTER_RAW_SIZE (regnum);
4871 if (offset + xfer > TYPE_LENGTH (type))
4872 xfer = TYPE_LENGTH (type) - offset;
4874 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4875 offset, xfer, regnum);
4876 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4883 mips_n32n64_extract_return_value (struct type *type,
4884 struct regcache *regcache,
4887 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4891 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4893 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4897 mips_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
4899 /* Nothing to do -- push_arguments does all the work. */
4903 mips_extract_struct_value_address (struct regcache *regcache)
4905 /* FIXME: This will only work at random. The caller passes the
4906 struct_return address in V0, but it is not preserved. It may
4907 still be there, or this may be a random value. */
4910 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4914 /* Exported procedure: Is PC in the signal trampoline code */
4917 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4919 if (sigtramp_address == 0)
4921 return (pc >= sigtramp_address && pc < sigtramp_end);
4924 /* Root of all "set mips "/"show mips " commands. This will eventually be
4925 used for all MIPS-specific commands. */
4928 show_mips_command (char *args, int from_tty)
4930 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4934 set_mips_command (char *args, int from_tty)
4936 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4937 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4940 /* Commands to show/set the MIPS FPU type. */
4943 show_mipsfpu_command (char *args, int from_tty)
4946 switch (MIPS_FPU_TYPE)
4948 case MIPS_FPU_SINGLE:
4949 fpu = "single-precision";
4951 case MIPS_FPU_DOUBLE:
4952 fpu = "double-precision";
4955 fpu = "absent (none)";
4958 internal_error (__FILE__, __LINE__, "bad switch");
4960 if (mips_fpu_type_auto)
4961 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4964 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
4970 set_mipsfpu_command (char *args, int from_tty)
4972 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
4973 show_mipsfpu_command (args, from_tty);
4977 set_mipsfpu_single_command (char *args, int from_tty)
4979 mips_fpu_type = MIPS_FPU_SINGLE;
4980 mips_fpu_type_auto = 0;
4981 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
4985 set_mipsfpu_double_command (char *args, int from_tty)
4987 mips_fpu_type = MIPS_FPU_DOUBLE;
4988 mips_fpu_type_auto = 0;
4989 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
4993 set_mipsfpu_none_command (char *args, int from_tty)
4995 mips_fpu_type = MIPS_FPU_NONE;
4996 mips_fpu_type_auto = 0;
4997 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5001 set_mipsfpu_auto_command (char *args, int from_tty)
5003 mips_fpu_type_auto = 1;
5006 /* Command to set the processor type. */
5009 mips_set_processor_type_command (char *args, int from_tty)
5013 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5015 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5016 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5017 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5019 /* Restore the value. */
5020 tmp_mips_processor_type = xstrdup (mips_processor_type);
5025 if (!mips_set_processor_type (tmp_mips_processor_type))
5027 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5028 /* Restore its value. */
5029 tmp_mips_processor_type = xstrdup (mips_processor_type);
5034 mips_show_processor_type_command (char *args, int from_tty)
5038 /* Modify the actual processor type. */
5041 mips_set_processor_type (char *str)
5048 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5050 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5052 mips_processor_type = str;
5053 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5055 /* FIXME tweak fpu flag too */
5062 /* Attempt to identify the particular processor model by reading the
5066 mips_read_processor_type (void)
5070 prid = read_register (PRID_REGNUM);
5072 if ((prid & ~0xf) == 0x700)
5073 return savestring ("r3041", strlen ("r3041"));
5078 /* Just like reinit_frame_cache, but with the right arguments to be
5079 callable as an sfunc. */
5082 reinit_frame_cache_sfunc (char *args, int from_tty,
5083 struct cmd_list_element *c)
5085 reinit_frame_cache ();
5089 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5091 mips_extra_func_info_t proc_desc;
5093 /* Search for the function containing this address. Set the low bit
5094 of the address when searching, in case we were given an even address
5095 that is the start of a 16-bit function. If we didn't do this,
5096 the search would fail because the symbol table says the function
5097 starts at an odd address, i.e. 1 byte past the given address. */
5098 memaddr = ADDR_BITS_REMOVE (memaddr);
5099 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5101 /* Make an attempt to determine if this is a 16-bit function. If
5102 the procedure descriptor exists and the address therein is odd,
5103 it's definitely a 16-bit function. Otherwise, we have to just
5104 guess that if the address passed in is odd, it's 16-bits. */
5106 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5107 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5109 info->mach = pc_is_mips16 (memaddr) ?
5110 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5112 /* Round down the instruction address to the appropriate boundary. */
5113 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5115 /* Call the appropriate disassembler based on the target endian-ness. */
5116 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5117 return print_insn_big_mips (memaddr, info);
5119 return print_insn_little_mips (memaddr, info);
5122 /* Old-style breakpoint macros.
5123 The IDT board uses an unusual breakpoint value, and sometimes gets
5124 confused when it sees the usual MIPS breakpoint instruction. */
5126 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
5127 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
5128 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
5129 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
5130 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
5131 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
5132 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
5133 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
5135 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5136 counter value to determine whether a 16- or 32-bit breakpoint should be
5137 used. It returns a pointer to a string of bytes that encode a breakpoint
5138 instruction, stores the length of the string to *lenptr, and adjusts pc
5139 (if necessary) to point to the actual memory location where the
5140 breakpoint should be inserted. */
5142 static const unsigned char *
5143 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5145 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5147 if (pc_is_mips16 (*pcptr))
5149 static unsigned char mips16_big_breakpoint[] =
5150 MIPS16_BIG_BREAKPOINT;
5151 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5152 *lenptr = sizeof (mips16_big_breakpoint);
5153 return mips16_big_breakpoint;
5157 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
5158 static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
5159 static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
5161 *lenptr = sizeof (big_breakpoint);
5163 if (strcmp (target_shortname, "mips") == 0)
5164 return idt_big_breakpoint;
5165 else if (strcmp (target_shortname, "ddb") == 0
5166 || strcmp (target_shortname, "pmon") == 0
5167 || strcmp (target_shortname, "lsi") == 0)
5168 return pmon_big_breakpoint;
5170 return big_breakpoint;
5175 if (pc_is_mips16 (*pcptr))
5177 static unsigned char mips16_little_breakpoint[] =
5178 MIPS16_LITTLE_BREAKPOINT;
5179 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5180 *lenptr = sizeof (mips16_little_breakpoint);
5181 return mips16_little_breakpoint;
5185 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
5186 static unsigned char pmon_little_breakpoint[] =
5187 PMON_LITTLE_BREAKPOINT;
5188 static unsigned char idt_little_breakpoint[] =
5189 IDT_LITTLE_BREAKPOINT;
5191 *lenptr = sizeof (little_breakpoint);
5193 if (strcmp (target_shortname, "mips") == 0)
5194 return idt_little_breakpoint;
5195 else if (strcmp (target_shortname, "ddb") == 0
5196 || strcmp (target_shortname, "pmon") == 0
5197 || strcmp (target_shortname, "lsi") == 0)
5198 return pmon_little_breakpoint;
5200 return little_breakpoint;
5205 /* If PC is in a mips16 call or return stub, return the address of the target
5206 PC, which is either the callee or the caller. There are several
5207 cases which must be handled:
5209 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5210 target PC is in $31 ($ra).
5211 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5212 and the target PC is in $2.
5213 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5214 before the jal instruction, this is effectively a call stub
5215 and the the target PC is in $2. Otherwise this is effectively
5216 a return stub and the target PC is in $18.
5218 See the source code for the stubs in gcc/config/mips/mips16.S for
5221 This function implements the SKIP_TRAMPOLINE_CODE macro.
5225 mips_skip_stub (CORE_ADDR pc)
5228 CORE_ADDR start_addr;
5230 /* Find the starting address and name of the function containing the PC. */
5231 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5234 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5235 target PC is in $31 ($ra). */
5236 if (strcmp (name, "__mips16_ret_sf") == 0
5237 || strcmp (name, "__mips16_ret_df") == 0)
5238 return read_signed_register (RA_REGNUM);
5240 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5242 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5243 and the target PC is in $2. */
5244 if (name[19] >= '0' && name[19] <= '9')
5245 return read_signed_register (2);
5247 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5248 before the jal instruction, this is effectively a call stub
5249 and the the target PC is in $2. Otherwise this is effectively
5250 a return stub and the target PC is in $18. */
5251 else if (name[19] == 's' || name[19] == 'd')
5253 if (pc == start_addr)
5255 /* Check if the target of the stub is a compiler-generated
5256 stub. Such a stub for a function bar might have a name
5257 like __fn_stub_bar, and might look like this:
5262 la $1,bar (becomes a lui/addiu pair)
5264 So scan down to the lui/addi and extract the target
5265 address from those two instructions. */
5267 CORE_ADDR target_pc = read_signed_register (2);
5271 /* See if the name of the target function is __fn_stub_*. */
5272 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5274 if (strncmp (name, "__fn_stub_", 10) != 0
5275 && strcmp (name, "etext") != 0
5276 && strcmp (name, "_etext") != 0)
5279 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5280 The limit on the search is arbitrarily set to 20
5281 instructions. FIXME. */
5282 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5284 inst = mips_fetch_instruction (target_pc);
5285 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5286 pc = (inst << 16) & 0xffff0000; /* high word */
5287 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5288 return pc | (inst & 0xffff); /* low word */
5291 /* Couldn't find the lui/addui pair, so return stub address. */
5295 /* This is the 'return' part of a call stub. The return
5296 address is in $r18. */
5297 return read_signed_register (18);
5300 return 0; /* not a stub */
5304 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5305 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5308 mips_in_call_stub (CORE_ADDR pc, char *name)
5310 CORE_ADDR start_addr;
5312 /* Find the starting address of the function containing the PC. If the
5313 caller didn't give us a name, look it up at the same time. */
5314 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5317 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5319 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5320 if (name[19] >= '0' && name[19] <= '9')
5322 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5323 before the jal instruction, this is effectively a call stub. */
5324 else if (name[19] == 's' || name[19] == 'd')
5325 return pc == start_addr;
5328 return 0; /* not a stub */
5332 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5333 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5336 mips_in_return_stub (CORE_ADDR pc, char *name)
5338 CORE_ADDR start_addr;
5340 /* Find the starting address of the function containing the PC. */
5341 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5344 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5345 if (strcmp (name, "__mips16_ret_sf") == 0
5346 || strcmp (name, "__mips16_ret_df") == 0)
5349 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5350 i.e. after the jal instruction, this is effectively a return stub. */
5351 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5352 && (name[19] == 's' || name[19] == 'd')
5353 && pc != start_addr)
5356 return 0; /* not a stub */
5360 /* Return non-zero if the PC is in a library helper function that should
5361 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5364 mips_ignore_helper (CORE_ADDR pc)
5368 /* Find the starting address and name of the function containing the PC. */
5369 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5372 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5373 that we want to ignore. */
5374 return (strcmp (name, "__mips16_ret_sf") == 0
5375 || strcmp (name, "__mips16_ret_df") == 0);
5379 /* Return a location where we can set a breakpoint that will be hit
5380 when an inferior function call returns. This is normally the
5381 program's entry point. Executables that don't have an entry
5382 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5383 whose address is the location where the breakpoint should be placed. */
5386 mips_call_dummy_address (void)
5388 struct minimal_symbol *sym;
5390 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5392 return SYMBOL_VALUE_ADDRESS (sym);
5394 return entry_point_address ();
5398 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5399 the register stored on the stack (32) is different to its real raw
5400 size (64). The below ensures that registers are fetched from the
5401 stack using their ABI size and then stored into the RAW_BUFFER
5402 using their raw size.
5404 The alternative to adding this function would be to add an ABI
5405 macro - REGISTER_STACK_SIZE(). */
5408 mips_get_saved_register (char *raw_buffer,
5411 struct frame_info *frame,
5413 enum lval_type *lvalp)
5416 enum lval_type lvalx;
5419 if (!target_has_registers)
5420 error ("No registers.");
5422 /* Make certain that all needed parameters are present. */
5427 if (optimizedp == NULL)
5428 optimizedp = &optimizedx;
5429 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5431 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5432 have a pseudo register range that correspons to the ABI's, rather
5433 than the ISA's, view of registers. These registers would then
5434 implicitly describe their size and hence could be used without
5435 the below munging. */
5436 if ((*lvalp) == lval_memory)
5438 if (raw_buffer != NULL)
5442 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5444 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5445 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5451 /* Immediately after a function call, return the saved pc.
5452 Can't always go through the frames for this because on some machines
5453 the new frame is not set up until the new function executes
5454 some instructions. */
5457 mips_saved_pc_after_call (struct frame_info *frame)
5459 return read_signed_register (RA_REGNUM);
5463 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5467 mips_stab_reg_to_regnum (int num)
5469 if (num >= 0 && num < 32)
5471 else if (num >= 38 && num < 70)
5472 return num + FP0_REGNUM - 38;
5479 /* This will hopefully (eventually) provoke a warning. Should
5480 we be calling complaint() here? */
5481 return NUM_REGS + NUM_PSEUDO_REGS;
5486 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5489 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5491 if (num >= 0 && num < 32)
5493 else if (num >= 32 && num < 64)
5494 return num + FP0_REGNUM - 32;
5501 /* This will hopefully (eventually) provoke a warning. Should
5502 we be calling complaint() here? */
5503 return NUM_REGS + NUM_PSEUDO_REGS;
5508 /* Convert an integer into an address. By first converting the value
5509 into a pointer and then extracting it signed, the address is
5510 guarenteed to be correctly sign extended. */
5513 mips_integer_to_address (struct type *type, void *buf)
5515 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5516 LONGEST val = unpack_long (type, buf);
5517 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5518 return extract_signed_integer (tmp,
5519 TYPE_LENGTH (builtin_type_void_data_ptr));
5523 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5525 enum mips_abi *abip = (enum mips_abi *) obj;
5526 const char *name = bfd_get_section_name (abfd, sect);
5528 if (*abip != MIPS_ABI_UNKNOWN)
5531 if (strncmp (name, ".mdebug.", 8) != 0)
5534 if (strcmp (name, ".mdebug.abi32") == 0)
5535 *abip = MIPS_ABI_O32;
5536 else if (strcmp (name, ".mdebug.abiN32") == 0)
5537 *abip = MIPS_ABI_N32;
5538 else if (strcmp (name, ".mdebug.abi64") == 0)
5539 *abip = MIPS_ABI_N64;
5540 else if (strcmp (name, ".mdebug.abiO64") == 0)
5541 *abip = MIPS_ABI_O64;
5542 else if (strcmp (name, ".mdebug.eabi32") == 0)
5543 *abip = MIPS_ABI_EABI32;
5544 else if (strcmp (name, ".mdebug.eabi64") == 0)
5545 *abip = MIPS_ABI_EABI64;
5547 warning ("unsupported ABI %s.", name + 8);
5550 static enum mips_abi
5551 global_mips_abi (void)
5555 for (i = 0; mips_abi_strings[i] != NULL; i++)
5556 if (mips_abi_strings[i] == mips_abi_string)
5557 return (enum mips_abi) i;
5559 internal_error (__FILE__, __LINE__,
5560 "unknown ABI string");
5563 static struct gdbarch *
5564 mips_gdbarch_init (struct gdbarch_info info,
5565 struct gdbarch_list *arches)
5567 static LONGEST mips_call_dummy_words[] =
5569 struct gdbarch *gdbarch;
5570 struct gdbarch_tdep *tdep;
5572 enum mips_abi mips_abi, found_abi, wanted_abi;
5574 /* Reset the disassembly info, in case it was set to something
5576 deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5577 deprecated_tm_print_insn_info.arch = bfd_arch_unknown;
5578 deprecated_tm_print_insn_info.mach = 0;
5584 /* First of all, extract the elf_flags, if available. */
5585 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5586 elf_flags = elf_elfheader (info.abfd)->e_flags;
5589 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5590 switch ((elf_flags & EF_MIPS_ABI))
5592 case E_MIPS_ABI_O32:
5593 mips_abi = MIPS_ABI_O32;
5595 case E_MIPS_ABI_O64:
5596 mips_abi = MIPS_ABI_O64;
5598 case E_MIPS_ABI_EABI32:
5599 mips_abi = MIPS_ABI_EABI32;
5601 case E_MIPS_ABI_EABI64:
5602 mips_abi = MIPS_ABI_EABI64;
5605 if ((elf_flags & EF_MIPS_ABI2))
5606 mips_abi = MIPS_ABI_N32;
5608 mips_abi = MIPS_ABI_UNKNOWN;
5612 /* GCC creates a pseudo-section whose name describes the ABI. */
5613 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5614 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5616 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5617 Use the ABI from the last architecture if there is one. */
5618 if (info.abfd == NULL && arches != NULL)
5619 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5621 /* Try the architecture for any hint of the correct ABI. */
5622 if (mips_abi == MIPS_ABI_UNKNOWN
5623 && info.bfd_arch_info != NULL
5624 && info.bfd_arch_info->arch == bfd_arch_mips)
5626 switch (info.bfd_arch_info->mach)
5628 case bfd_mach_mips3900:
5629 mips_abi = MIPS_ABI_EABI32;
5631 case bfd_mach_mips4100:
5632 case bfd_mach_mips5000:
5633 mips_abi = MIPS_ABI_EABI64;
5635 case bfd_mach_mips8000:
5636 case bfd_mach_mips10000:
5637 /* On Irix, ELF64 executables use the N64 ABI. The
5638 pseudo-sections which describe the ABI aren't present
5639 on IRIX. (Even for executables created by gcc.) */
5640 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5641 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5642 mips_abi = MIPS_ABI_N64;
5644 mips_abi = MIPS_ABI_N32;
5649 if (mips_abi == MIPS_ABI_UNKNOWN)
5650 mips_abi = MIPS_ABI_O32;
5652 /* Now that we have found what the ABI for this binary would be,
5653 check whether the user is overriding it. */
5654 found_abi = mips_abi;
5655 wanted_abi = global_mips_abi ();
5656 if (wanted_abi != MIPS_ABI_UNKNOWN)
5657 mips_abi = wanted_abi;
5659 /* We have to set deprecated_tm_print_insn_info before looking for a
5660 pre-existing architecture, otherwise we may return before we get
5661 a chance to set it up. */
5662 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5664 /* Set up the disassembler info, so that we get the right
5665 register names from libopcodes. */
5666 if (mips_abi == MIPS_ABI_N32)
5667 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=n32";
5669 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=64";
5670 deprecated_tm_print_insn_info.flavour = bfd_target_elf_flavour;
5671 deprecated_tm_print_insn_info.arch = bfd_arch_mips;
5672 if (info.bfd_arch_info != NULL
5673 && info.bfd_arch_info->arch == bfd_arch_mips
5674 && info.bfd_arch_info->mach)
5675 deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
5677 deprecated_tm_print_insn_info.mach = bfd_mach_mips8000;
5680 /* This string is not recognized explicitly by the disassembler,
5681 but it tells the disassembler to not try to guess the ABI from
5682 the bfd elf headers, such that, if the user overrides the ABI
5683 of a program linked as NewABI, the disassembly will follow the
5684 register naming conventions specified by the user. */
5685 deprecated_tm_print_insn_info.disassembler_options = "gpr-names=32";
5689 fprintf_unfiltered (gdb_stdlog,
5690 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5692 fprintf_unfiltered (gdb_stdlog,
5693 "mips_gdbarch_init: mips_abi = %d\n",
5695 fprintf_unfiltered (gdb_stdlog,
5696 "mips_gdbarch_init: found_mips_abi = %d\n",
5700 /* try to find a pre-existing architecture */
5701 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5703 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5705 /* MIPS needs to be pedantic about which ABI the object is
5707 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5709 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5711 return arches->gdbarch;
5714 /* Need a new architecture. Fill in a target specific vector. */
5715 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5716 gdbarch = gdbarch_alloc (&info, tdep);
5717 tdep->elf_flags = elf_flags;
5719 /* Initially set everything according to the default ABI/ISA. */
5720 set_gdbarch_short_bit (gdbarch, 16);
5721 set_gdbarch_int_bit (gdbarch, 32);
5722 set_gdbarch_float_bit (gdbarch, 32);
5723 set_gdbarch_double_bit (gdbarch, 64);
5724 set_gdbarch_long_double_bit (gdbarch, 64);
5725 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5726 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8);
5727 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5728 tdep->found_abi = found_abi;
5729 tdep->mips_abi = mips_abi;
5731 set_gdbarch_elf_make_msymbol_special (gdbarch,
5732 mips_elf_make_msymbol_special);
5734 if (info.osabi == GDB_OSABI_IRIX)
5735 set_gdbarch_num_regs (gdbarch, 71);
5737 set_gdbarch_num_regs (gdbarch, 90);
5742 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o32_push_arguments);
5743 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5744 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5745 tdep->mips_default_saved_regsize = 4;
5746 tdep->mips_default_stack_argsize = 4;
5747 tdep->mips_fp_register_double = 0;
5748 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5749 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5750 tdep->gdb_target_is_mips64 = 0;
5751 tdep->default_mask_address_p = 0;
5752 set_gdbarch_long_bit (gdbarch, 32);
5753 set_gdbarch_ptr_bit (gdbarch, 32);
5754 set_gdbarch_long_long_bit (gdbarch, 64);
5755 set_gdbarch_reg_struct_has_addr (gdbarch,
5756 mips_o32_reg_struct_has_addr);
5757 set_gdbarch_use_struct_convention (gdbarch,
5758 mips_o32_use_struct_convention);
5761 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o64_push_arguments);
5762 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5763 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5764 tdep->mips_default_saved_regsize = 8;
5765 tdep->mips_default_stack_argsize = 8;
5766 tdep->mips_fp_register_double = 1;
5767 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5768 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5769 tdep->gdb_target_is_mips64 = 1;
5770 tdep->default_mask_address_p = 0;
5771 set_gdbarch_long_bit (gdbarch, 32);
5772 set_gdbarch_ptr_bit (gdbarch, 32);
5773 set_gdbarch_long_long_bit (gdbarch, 64);
5774 set_gdbarch_reg_struct_has_addr (gdbarch,
5775 mips_o32_reg_struct_has_addr);
5776 set_gdbarch_use_struct_convention (gdbarch,
5777 mips_o32_use_struct_convention);
5779 case MIPS_ABI_EABI32:
5780 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5781 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5782 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5783 tdep->mips_default_saved_regsize = 4;
5784 tdep->mips_default_stack_argsize = 4;
5785 tdep->mips_fp_register_double = 0;
5786 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5787 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5788 tdep->gdb_target_is_mips64 = 0;
5789 tdep->default_mask_address_p = 0;
5790 set_gdbarch_long_bit (gdbarch, 32);
5791 set_gdbarch_ptr_bit (gdbarch, 32);
5792 set_gdbarch_long_long_bit (gdbarch, 64);
5793 set_gdbarch_reg_struct_has_addr (gdbarch,
5794 mips_eabi_reg_struct_has_addr);
5795 set_gdbarch_use_struct_convention (gdbarch,
5796 mips_eabi_use_struct_convention);
5798 case MIPS_ABI_EABI64:
5799 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5800 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5801 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5802 tdep->mips_default_saved_regsize = 8;
5803 tdep->mips_default_stack_argsize = 8;
5804 tdep->mips_fp_register_double = 1;
5805 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5806 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5807 tdep->gdb_target_is_mips64 = 1;
5808 tdep->default_mask_address_p = 0;
5809 set_gdbarch_long_bit (gdbarch, 64);
5810 set_gdbarch_ptr_bit (gdbarch, 64);
5811 set_gdbarch_long_long_bit (gdbarch, 64);
5812 set_gdbarch_reg_struct_has_addr (gdbarch,
5813 mips_eabi_reg_struct_has_addr);
5814 set_gdbarch_use_struct_convention (gdbarch,
5815 mips_eabi_use_struct_convention);
5818 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5819 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5820 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5821 tdep->mips_default_saved_regsize = 8;
5822 tdep->mips_default_stack_argsize = 8;
5823 tdep->mips_fp_register_double = 1;
5824 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5825 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5826 tdep->gdb_target_is_mips64 = 1;
5827 tdep->default_mask_address_p = 0;
5828 set_gdbarch_long_bit (gdbarch, 32);
5829 set_gdbarch_ptr_bit (gdbarch, 32);
5830 set_gdbarch_long_long_bit (gdbarch, 64);
5831 set_gdbarch_use_struct_convention (gdbarch,
5832 mips_n32n64_use_struct_convention);
5833 set_gdbarch_reg_struct_has_addr (gdbarch,
5834 mips_n32n64_reg_struct_has_addr);
5837 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5838 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5839 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5840 tdep->mips_default_saved_regsize = 8;
5841 tdep->mips_default_stack_argsize = 8;
5842 tdep->mips_fp_register_double = 1;
5843 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5844 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5845 tdep->gdb_target_is_mips64 = 1;
5846 tdep->default_mask_address_p = 0;
5847 set_gdbarch_long_bit (gdbarch, 64);
5848 set_gdbarch_ptr_bit (gdbarch, 64);
5849 set_gdbarch_long_long_bit (gdbarch, 64);
5850 set_gdbarch_use_struct_convention (gdbarch,
5851 mips_n32n64_use_struct_convention);
5852 set_gdbarch_reg_struct_has_addr (gdbarch,
5853 mips_n32n64_reg_struct_has_addr);
5856 internal_error (__FILE__, __LINE__,
5857 "unknown ABI in switch");
5860 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5861 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5864 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5865 flag in object files because to do so would make it impossible to
5866 link with libraries compiled without "-gp32". This is
5867 unnecessarily restrictive.
5869 We could solve this problem by adding "-gp32" multilibs to gcc,
5870 but to set this flag before gcc is built with such multilibs will
5871 break too many systems.''
5873 But even more unhelpfully, the default linker output target for
5874 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5875 for 64-bit programs - you need to change the ABI to change this,
5876 and not all gcc targets support that currently. Therefore using
5877 this flag to detect 32-bit mode would do the wrong thing given
5878 the current gcc - it would make GDB treat these 64-bit programs
5879 as 32-bit programs by default. */
5881 /* enable/disable the MIPS FPU */
5882 if (!mips_fpu_type_auto)
5883 tdep->mips_fpu_type = mips_fpu_type;
5884 else if (info.bfd_arch_info != NULL
5885 && info.bfd_arch_info->arch == bfd_arch_mips)
5886 switch (info.bfd_arch_info->mach)
5888 case bfd_mach_mips3900:
5889 case bfd_mach_mips4100:
5890 case bfd_mach_mips4111:
5891 tdep->mips_fpu_type = MIPS_FPU_NONE;
5893 case bfd_mach_mips4650:
5894 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5897 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5901 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5903 /* MIPS version of register names. NOTE: At present the MIPS
5904 register name management is part way between the old -
5905 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5906 Further work on it is required. */
5907 /* NOTE: many targets (esp. embedded) do not go thru the
5908 gdbarch_register_name vector at all, instead bypassing it
5909 by defining REGISTER_NAMES. */
5910 set_gdbarch_register_name (gdbarch, mips_register_name);
5911 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5912 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5913 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5914 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5915 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
5917 /* Add/remove bits from an address. The MIPS needs be careful to
5918 ensure that all 32 bit addresses are sign extended to 64 bits. */
5919 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5921 /* There's a mess in stack frame creation. See comments in
5922 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5923 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5924 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5926 /* Map debug register numbers onto internal register numbers. */
5927 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5928 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5929 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5930 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5932 /* Initialize a frame */
5933 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5934 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5936 /* MIPS version of CALL_DUMMY */
5938 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5939 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
5940 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
5941 set_gdbarch_deprecated_fix_call_dummy (gdbarch, mips_fix_call_dummy);
5942 set_gdbarch_deprecated_call_dummy_words (gdbarch, mips_call_dummy_words);
5943 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
5944 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
5945 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5946 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5947 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
5948 set_gdbarch_register_convert_to_virtual (gdbarch,
5949 mips_register_convert_to_virtual);
5950 set_gdbarch_register_convert_to_raw (gdbarch,
5951 mips_register_convert_to_raw);
5953 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
5954 set_gdbarch_frameless_function_invocation (gdbarch,
5955 generic_frameless_function_invocation_not);
5956 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5957 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
5958 set_gdbarch_frame_args_skip (gdbarch, 0);
5960 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
5962 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5963 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5964 set_gdbarch_decr_pc_after_break (gdbarch, 0);
5966 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5967 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
5969 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5970 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5971 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5973 set_gdbarch_function_start_offset (gdbarch, 0);
5975 /* There are MIPS targets which do not yet use this since they still
5976 define REGISTER_VIRTUAL_TYPE. */
5977 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
5978 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
5980 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
5981 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
5983 /* Hook in OS ABI-specific overrides, if they have been registered. */
5984 gdbarch_init_osabi (info, gdbarch);
5986 set_gdbarch_deprecated_store_struct_return (gdbarch, mips_store_struct_return);
5987 set_gdbarch_extract_struct_value_address (gdbarch,
5988 mips_extract_struct_value_address);
5990 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
5992 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
5993 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
5999 mips_abi_update (char *ignore_args, int from_tty,
6000 struct cmd_list_element *c)
6002 struct gdbarch_info info;
6004 /* Force the architecture to update, and (if it's a MIPS architecture)
6005 mips_gdbarch_init will take care of the rest. */
6006 gdbarch_info_init (&info);
6007 gdbarch_update_p (info);
6010 /* Print out which MIPS ABI is in use. */
6013 show_mips_abi (char *ignore_args, int from_tty)
6015 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6017 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6020 enum mips_abi global_abi = global_mips_abi ();
6021 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6022 const char *actual_abi_str = mips_abi_strings[actual_abi];
6024 if (global_abi == MIPS_ABI_UNKNOWN)
6025 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6027 else if (global_abi == actual_abi)
6029 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6033 /* Probably shouldn't happen... */
6035 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6037 mips_abi_strings[global_abi]);
6043 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6045 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6049 int ef_mips_32bitmode;
6050 /* determine the ISA */
6051 switch (tdep->elf_flags & EF_MIPS_ARCH)
6069 /* determine the size of a pointer */
6070 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6071 fprintf_unfiltered (file,
6072 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6074 fprintf_unfiltered (file,
6075 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6077 fprintf_unfiltered (file,
6078 "mips_dump_tdep: ef_mips_arch = %d\n",
6080 fprintf_unfiltered (file,
6081 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6083 mips_abi_strings[tdep->mips_abi]);
6084 fprintf_unfiltered (file,
6085 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6086 mips_mask_address_p (),
6087 tdep->default_mask_address_p);
6089 fprintf_unfiltered (file,
6090 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6091 FP_REGISTER_DOUBLE);
6092 fprintf_unfiltered (file,
6093 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6094 MIPS_DEFAULT_FPU_TYPE,
6095 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6096 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6097 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6099 fprintf_unfiltered (file,
6100 "mips_dump_tdep: MIPS_EABI = %d\n",
6102 fprintf_unfiltered (file,
6103 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6104 MIPS_LAST_FP_ARG_REGNUM,
6105 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6106 fprintf_unfiltered (file,
6107 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6109 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6110 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6111 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6113 fprintf_unfiltered (file,
6114 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6115 MIPS_DEFAULT_SAVED_REGSIZE);
6116 fprintf_unfiltered (file,
6117 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6118 FP_REGISTER_DOUBLE);
6119 fprintf_unfiltered (file,
6120 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6121 MIPS_DEFAULT_STACK_ARGSIZE);
6122 fprintf_unfiltered (file,
6123 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6124 MIPS_STACK_ARGSIZE);
6125 fprintf_unfiltered (file,
6126 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6128 fprintf_unfiltered (file,
6129 "mips_dump_tdep: A0_REGNUM = %d\n",
6131 fprintf_unfiltered (file,
6132 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6133 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6134 fprintf_unfiltered (file,
6135 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6136 XSTRING (ATTACH_DETACH));
6137 fprintf_unfiltered (file,
6138 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6140 fprintf_unfiltered (file,
6141 "mips_dump_tdep: BIG_BREAKPOINT = delete?\n");
6142 fprintf_unfiltered (file,
6143 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6145 fprintf_unfiltered (file,
6146 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6147 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6148 fprintf_unfiltered (file,
6149 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6150 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6151 fprintf_unfiltered (file,
6152 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6154 fprintf_unfiltered (file,
6155 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6157 fprintf_unfiltered (file,
6158 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6159 FIRST_EMBED_REGNUM);
6160 fprintf_unfiltered (file,
6161 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6163 fprintf_unfiltered (file,
6164 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6165 GDB_TARGET_IS_MIPS64);
6166 fprintf_unfiltered (file,
6167 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6168 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6169 fprintf_unfiltered (file,
6170 "mips_dump_tdep: HI_REGNUM = %d\n",
6172 fprintf_unfiltered (file,
6173 "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n");
6174 fprintf_unfiltered (file,
6175 "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n");
6176 fprintf_unfiltered (file,
6177 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6178 XSTRING (IGNORE_HELPER_CALL (PC)));
6179 fprintf_unfiltered (file,
6180 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6181 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6182 fprintf_unfiltered (file,
6183 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6184 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6185 fprintf_unfiltered (file,
6186 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6187 fprintf_unfiltered (file,
6188 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6190 fprintf_unfiltered (file,
6191 "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n");
6192 fprintf_unfiltered (file,
6193 "mips_dump_tdep: LO_REGNUM = %d\n",
6195 #ifdef MACHINE_CPROC_FP_OFFSET
6196 fprintf_unfiltered (file,
6197 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6198 MACHINE_CPROC_FP_OFFSET);
6200 #ifdef MACHINE_CPROC_PC_OFFSET
6201 fprintf_unfiltered (file,
6202 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6203 MACHINE_CPROC_PC_OFFSET);
6205 #ifdef MACHINE_CPROC_SP_OFFSET
6206 fprintf_unfiltered (file,
6207 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6208 MACHINE_CPROC_SP_OFFSET);
6210 fprintf_unfiltered (file,
6211 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n");
6214 fprintf_unfiltered (file,
6215 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6217 fprintf_unfiltered (file,
6218 "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n");
6219 fprintf_unfiltered (file,
6220 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6221 fprintf_unfiltered (file,
6222 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6223 fprintf_unfiltered (file,
6224 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6228 MIPS_LAST_ARG_REGNUM,
6229 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6230 fprintf_unfiltered (file,
6231 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6233 fprintf_unfiltered (file,
6234 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6237 MIPS_SAVED_REGSIZE);
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: OP_LDFPR = used?\n");
6240 fprintf_unfiltered (file,
6241 "mips_dump_tdep: OP_LDGPR = used?\n");
6242 fprintf_unfiltered (file,
6243 "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n");
6244 fprintf_unfiltered (file,
6245 "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n");
6246 fprintf_unfiltered (file,
6247 "mips_dump_tdep: PRID_REGNUM = %d\n",
6249 fprintf_unfiltered (file,
6250 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6251 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6252 fprintf_unfiltered (file,
6253 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6254 fprintf_unfiltered (file,
6255 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6256 fprintf_unfiltered (file,
6257 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6258 fprintf_unfiltered (file,
6259 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6260 fprintf_unfiltered (file,
6261 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6262 fprintf_unfiltered (file,
6263 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6264 fprintf_unfiltered (file,
6265 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6266 fprintf_unfiltered (file,
6267 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6268 fprintf_unfiltered (file,
6269 "mips_dump_tdep: PROC_PC_REG = function?\n");
6270 fprintf_unfiltered (file,
6271 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6272 fprintf_unfiltered (file,
6273 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6274 fprintf_unfiltered (file,
6275 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6276 fprintf_unfiltered (file,
6277 "mips_dump_tdep: PS_REGNUM = %d\n",
6279 fprintf_unfiltered (file,
6280 "mips_dump_tdep: RA_REGNUM = %d\n",
6282 fprintf_unfiltered (file,
6283 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6284 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6285 fprintf_unfiltered (file,
6286 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6287 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6288 fprintf_unfiltered (file,
6289 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6290 fprintf_unfiltered (file,
6291 "mips_dump_tdep: ROUND_DOWN = function?\n");
6292 fprintf_unfiltered (file,
6293 "mips_dump_tdep: ROUND_UP = function?\n");
6295 fprintf_unfiltered (file,
6296 "mips_dump_tdep: SAVED_BYTES = %d\n",
6300 fprintf_unfiltered (file,
6301 "mips_dump_tdep: SAVED_FP = %d\n",
6305 fprintf_unfiltered (file,
6306 "mips_dump_tdep: SAVED_PC = %d\n",
6309 fprintf_unfiltered (file,
6310 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6311 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6312 fprintf_unfiltered (file,
6313 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6314 fprintf_unfiltered (file,
6315 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6317 fprintf_unfiltered (file,
6318 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6319 SIGFRAME_FPREGSAVE_OFF);
6320 fprintf_unfiltered (file,
6321 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6323 fprintf_unfiltered (file,
6324 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6325 SIGFRAME_REGSAVE_OFF);
6326 fprintf_unfiltered (file,
6327 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6329 fprintf_unfiltered (file,
6330 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6331 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6332 fprintf_unfiltered (file,
6333 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6334 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6335 fprintf_unfiltered (file,
6336 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6337 SOFTWARE_SINGLE_STEP_P ());
6338 fprintf_unfiltered (file,
6339 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6340 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6341 #ifdef STACK_END_ADDR
6342 fprintf_unfiltered (file,
6343 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6348 XSTRING (STEP_SKIPS_DELAY (PC)));
6349 fprintf_unfiltered (file,
6350 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6351 STEP_SKIPS_DELAY_P);
6352 fprintf_unfiltered (file,
6353 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6354 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6355 fprintf_unfiltered (file,
6356 "mips_dump_tdep: T9_REGNUM = %d\n",
6358 fprintf_unfiltered (file,
6359 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6362 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6363 fprintf_unfiltered (file,
6364 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6365 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6366 fprintf_unfiltered (file,
6367 "mips_dump_tdep: TARGET_MIPS = used?\n");
6368 fprintf_unfiltered (file,
6369 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6370 XSTRING (TM_PRINT_INSN_MACH));
6372 fprintf_unfiltered (file,
6373 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6374 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6377 fprintf_unfiltered (file,
6378 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6381 #ifdef TRACE_FLAVOR_SIZE
6382 fprintf_unfiltered (file,
6383 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6387 fprintf_unfiltered (file,
6388 "mips_dump_tdep: TRACE_SET # %s\n",
6389 XSTRING (TRACE_SET (X,STATE)));
6391 fprintf_unfiltered (file,
6392 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6393 #ifdef UNUSED_REGNUM
6394 fprintf_unfiltered (file,
6395 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6398 fprintf_unfiltered (file,
6399 "mips_dump_tdep: V0_REGNUM = %d\n",
6401 fprintf_unfiltered (file,
6402 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6403 (long) VM_MIN_ADDRESS);
6405 fprintf_unfiltered (file,
6406 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6409 fprintf_unfiltered (file,
6410 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6412 fprintf_unfiltered (file,
6413 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6418 _initialize_mips_tdep (void)
6420 static struct cmd_list_element *mipsfpulist = NULL;
6421 struct cmd_list_element *c;
6423 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6424 if (MIPS_ABI_LAST + 1
6425 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6426 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6428 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6429 if (!deprecated_tm_print_insn) /* Someone may have already set it */
6430 deprecated_tm_print_insn = gdb_print_insn_mips;
6432 /* Add root prefix command for all "set mips"/"show mips" commands */
6433 add_prefix_cmd ("mips", no_class, set_mips_command,
6434 "Various MIPS specific commands.",
6435 &setmipscmdlist, "set mips ", 0, &setlist);
6437 add_prefix_cmd ("mips", no_class, show_mips_command,
6438 "Various MIPS specific commands.",
6439 &showmipscmdlist, "show mips ", 0, &showlist);
6441 /* Allow the user to override the saved register size. */
6442 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6445 &mips_saved_regsize_string, "\
6446 Set size of general purpose registers saved on the stack.\n\
6447 This option can be set to one of:\n\
6448 32 - Force GDB to treat saved GP registers as 32-bit\n\
6449 64 - Force GDB to treat saved GP registers as 64-bit\n\
6450 auto - Allow GDB to use the target's default setting or autodetect the\n\
6451 saved GP register size from information contained in the executable.\n\
6456 /* Allow the user to override the argument stack size. */
6457 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6460 &mips_stack_argsize_string, "\
6461 Set the amount of stack space reserved for each argument.\n\
6462 This option can be set to one of:\n\
6463 32 - Force GDB to allocate 32-bit chunks per argument\n\
6464 64 - Force GDB to allocate 64-bit chunks per argument\n\
6465 auto - Allow GDB to determine the correct setting from the current\n\
6466 target and executable (default)",
6470 /* Allow the user to override the ABI. */
6471 c = add_set_enum_cmd
6472 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6473 "Set the ABI used by this program.\n"
6474 "This option can be set to one of:\n"
6475 " auto - the default ABI associated with the current binary\n"
6483 set_cmd_sfunc (c, mips_abi_update);
6484 add_cmd ("abi", class_obscure, show_mips_abi,
6485 "Show ABI in use by MIPS target", &showmipscmdlist);
6487 /* Let the user turn off floating point and set the fence post for
6488 heuristic_proc_start. */
6490 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6491 "Set use of MIPS floating-point coprocessor.",
6492 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6493 add_cmd ("single", class_support, set_mipsfpu_single_command,
6494 "Select single-precision MIPS floating-point coprocessor.",
6496 add_cmd ("double", class_support, set_mipsfpu_double_command,
6497 "Select double-precision MIPS floating-point coprocessor.",
6499 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6500 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6501 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6502 add_cmd ("none", class_support, set_mipsfpu_none_command,
6503 "Select no MIPS floating-point coprocessor.",
6505 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6506 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6507 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6508 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6509 "Select MIPS floating-point coprocessor automatically.",
6511 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6512 "Show current use of MIPS floating-point coprocessor target.",
6515 /* We really would like to have both "0" and "unlimited" work, but
6516 command.c doesn't deal with that. So make it a var_zinteger
6517 because the user can always use "999999" or some such for unlimited. */
6518 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6519 (char *) &heuristic_fence_post,
6521 Set the distance searched for the start of a function.\n\
6522 If you are debugging a stripped executable, GDB needs to search through the\n\
6523 program for the start of a function. This command sets the distance of the\n\
6524 search. The only need to set it is when debugging a stripped executable.",
6526 /* We need to throw away the frame cache when we set this, since it
6527 might change our ability to get backtraces. */
6528 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6529 add_show_from_set (c, &showlist);
6531 /* Allow the user to control whether the upper bits of 64-bit
6532 addresses should be zeroed. */
6533 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6534 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6535 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6536 allow GDB to determine the correct value.\n", "\
6537 Show zeroing of upper 32 bits of 64-bit addresses.",
6538 NULL, show_mask_address,
6539 &setmipscmdlist, &showmipscmdlist);
6541 /* Allow the user to control the size of 32 bit registers within the
6542 raw remote packet. */
6543 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6546 (char *)&mips64_transfers_32bit_regs_p, "\
6547 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6548 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6549 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6550 64 bits for others. Use \"off\" to disable compatibility mode",
6554 /* Debug this files internals. */
6555 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6556 &mips_debug, "Set mips debugging.\n\
6557 When non-zero, mips specific debugging is enabled.", &setdebuglist),