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 MIPS ABI associated with GDBARCH. */
155 mips_abi (struct gdbarch *gdbarch)
157 return gdbarch_tdep (gdbarch)->mips_abi;
161 mips_saved_regsize (void)
163 if (mips_saved_regsize_string == size_auto)
164 return MIPS_DEFAULT_SAVED_REGSIZE;
165 else if (mips_saved_regsize_string == size_64)
167 else /* if (mips_saved_regsize_string == size_32) */
171 /* Functions for setting and testing a bit in a minimal symbol that
172 marks it as 16-bit function. The MSB of the minimal symbol's
173 "info" field is used for this purpose. This field is already
174 being used to store the symbol size, so the assumption is
175 that the symbol size cannot exceed 2^31.
177 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
178 i.e. refers to a 16-bit function, and sets a "special" bit in a
179 minimal symbol to mark it as a 16-bit function
181 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
182 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
183 the "info" field with the "special" bit masked out */
186 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
188 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
190 MSYMBOL_INFO (msym) = (char *)
191 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
192 SYMBOL_VALUE_ADDRESS (msym) |= 1;
197 msymbol_is_special (struct minimal_symbol *msym)
199 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
203 msymbol_size (struct minimal_symbol *msym)
205 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
208 /* XFER a value from the big/little/left end of the register.
209 Depending on the size of the value it might occupy the entire
210 register or just part of it. Make an allowance for this, aligning
211 things accordingly. */
214 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
215 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
218 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
220 /* Need to transfer the left or right part of the register, based on
221 the targets byte order. */
225 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
227 case BFD_ENDIAN_LITTLE:
230 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
234 internal_error (__FILE__, __LINE__, "bad switch");
237 fprintf_unfiltered (gdb_stderr,
238 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
239 reg_num, reg_offset, buf_offset, length);
240 if (mips_debug && out != NULL)
243 fprintf_unfiltered (gdb_stdlog, "out ");
244 for (i = 0; i < length; i++)
245 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
248 regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
250 regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
251 if (mips_debug && in != NULL)
254 fprintf_unfiltered (gdb_stdlog, "in ");
255 for (i = 0; i < length; i++)
256 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
259 fprintf_unfiltered (gdb_stdlog, "\n");
262 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
263 compatiblity mode. A return value of 1 means that we have
264 physical 64-bit registers, but should treat them as 32-bit registers. */
267 mips2_fp_compat (void)
269 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
271 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
275 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
276 in all the places we deal with FP registers. PR gdb/413. */
277 /* Otherwise check the FR bit in the status register - it controls
278 the FP compatiblity mode. If it is clear we are in compatibility
280 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
287 /* Indicate that the ABI makes use of double-precision registers
288 provided by the FPU (rather than combining pairs of registers to
289 form double-precision values). Do not use "TARGET_IS_MIPS64" to
290 determine if the ABI is using double-precision registers. See also
292 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
294 /* The amount of space reserved on the stack for registers. This is
295 different to MIPS_SAVED_REGSIZE as it determines the alignment of
296 data allocated after the registers have run out. */
298 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
300 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
302 static const char *mips_stack_argsize_string = size_auto;
305 mips_stack_argsize (void)
307 if (mips_stack_argsize_string == size_auto)
308 return MIPS_DEFAULT_STACK_ARGSIZE;
309 else if (mips_stack_argsize_string == size_64)
311 else /* if (mips_stack_argsize_string == size_32) */
315 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
317 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
319 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
321 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
323 static void mips_print_register (int, int);
325 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
326 struct frame_info *, int);
328 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
330 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
332 static int mips_set_processor_type (char *);
334 static void mips_show_processor_type_command (char *, int);
336 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
338 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
339 struct frame_info *next_frame,
342 static CORE_ADDR after_prologue (CORE_ADDR pc,
343 mips_extra_func_info_t proc_desc);
345 static void mips_read_fp_register_single (int regno, char *rare_buffer);
346 static void mips_read_fp_register_double (int regno, char *rare_buffer);
348 static struct type *mips_float_register_type (void);
349 static struct type *mips_double_register_type (void);
351 /* This value is the model of MIPS in use. It is derived from the value
352 of the PrID register. */
354 char *mips_processor_type;
356 char *tmp_mips_processor_type;
358 /* The list of available "set mips " and "show mips " commands */
360 static struct cmd_list_element *setmipscmdlist = NULL;
361 static struct cmd_list_element *showmipscmdlist = NULL;
363 /* A set of original names, to be used when restoring back to generic
364 registers from a specific set. */
365 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
367 /* Integer registers 0 thru 31 are handled explicitly by
368 mips_register_name(). Processor specific registers 32 and above
369 are listed in the sets of register names assigned to
370 mips_processor_reg_names. */
371 static char **mips_processor_reg_names = mips_generic_reg_names;
373 /* Return the name of the register corresponding to REGNO. */
375 mips_register_name (int regno)
377 /* GPR names for all ABIs other than n32/n64. */
378 static char *mips_gpr_names[] = {
379 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
380 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
381 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
382 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
385 /* GPR names for n32 and n64 ABIs. */
386 static char *mips_n32_n64_gpr_names[] = {
387 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
388 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
389 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
390 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
393 enum mips_abi abi = mips_abi (current_gdbarch);
395 /* The MIPS integer registers are always mapped from 0 to 31. The
396 names of the registers (which reflects the conventions regarding
397 register use) vary depending on the ABI. */
398 if (0 <= regno && regno < 32)
400 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
401 return mips_n32_n64_gpr_names[regno];
403 return mips_gpr_names[regno];
405 else if (32 <= regno && regno < NUM_REGS)
406 return mips_processor_reg_names[regno - 32];
408 internal_error (__FILE__, __LINE__,
409 "mips_register_name: bad register number %d", regno);
413 /* Names of IDT R3041 registers. */
415 char *mips_r3041_reg_names[] = {
416 "sr", "lo", "hi", "bad", "cause","pc",
417 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
418 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
419 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
420 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
421 "fsr", "fir", "",/*"fp"*/ "",
422 "", "", "bus", "ccfg", "", "", "", "",
423 "", "", "port", "cmp", "", "", "epc", "prid",
426 /* Names of IDT R3051 registers. */
428 char *mips_r3051_reg_names[] = {
429 "sr", "lo", "hi", "bad", "cause","pc",
430 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
431 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
432 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
433 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
434 "fsr", "fir", ""/*"fp"*/, "",
435 "inx", "rand", "elo", "", "ctxt", "", "", "",
436 "", "", "ehi", "", "", "", "epc", "prid",
439 /* Names of IDT R3081 registers. */
441 char *mips_r3081_reg_names[] = {
442 "sr", "lo", "hi", "bad", "cause","pc",
443 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
444 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
445 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
446 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
447 "fsr", "fir", ""/*"fp"*/, "",
448 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
449 "", "", "ehi", "", "", "", "epc", "prid",
452 /* Names of LSI 33k registers. */
454 char *mips_lsi33k_reg_names[] = {
455 "epc", "hi", "lo", "sr", "cause","badvaddr",
456 "dcic", "bpc", "bda", "", "", "", "", "",
457 "", "", "", "", "", "", "", "",
458 "", "", "", "", "", "", "", "",
459 "", "", "", "", "", "", "", "",
461 "", "", "", "", "", "", "", "",
462 "", "", "", "", "", "", "", "",
468 } mips_processor_type_table[] = {
469 { "generic", mips_generic_reg_names },
470 { "r3041", mips_r3041_reg_names },
471 { "r3051", mips_r3051_reg_names },
472 { "r3071", mips_r3081_reg_names },
473 { "r3081", mips_r3081_reg_names },
474 { "lsi33k", mips_lsi33k_reg_names },
482 /* Table to translate MIPS16 register field to actual register number. */
483 static int mips16_to_32_reg[8] =
484 {16, 17, 2, 3, 4, 5, 6, 7};
486 /* Heuristic_proc_start may hunt through the text section for a long
487 time across a 2400 baud serial line. Allows the user to limit this
490 static unsigned int heuristic_fence_post = 0;
492 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
493 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
494 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
495 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
496 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
497 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
498 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
499 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
500 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
501 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
502 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
503 this will corrupt pdr.iline. Fortunately we don't use it. */
504 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
505 #define _PROC_MAGIC_ 0x0F0F0F0F
506 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
507 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
509 struct linked_proc_info
511 struct mips_extra_func_info info;
512 struct linked_proc_info *next;
514 *linked_proc_desc_table = NULL;
517 mips_print_extra_frame_info (struct frame_info *fi)
520 && get_frame_extra_info (fi)
521 && get_frame_extra_info (fi)->proc_desc
522 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
523 printf_filtered (" frame pointer is at %s+%s\n",
524 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
525 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
528 /* Number of bytes of storage in the actual machine representation for
529 register N. NOTE: This indirectly defines the register size
530 transfered by the GDB protocol. */
532 static int mips64_transfers_32bit_regs_p = 0;
535 mips_register_raw_size (int reg_nr)
537 if (mips64_transfers_32bit_regs_p)
538 return REGISTER_VIRTUAL_SIZE (reg_nr);
539 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
540 && FP_REGISTER_DOUBLE)
541 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
548 /* Convert between RAW and VIRTUAL registers. The RAW register size
549 defines the remote-gdb packet. */
552 mips_register_convertible (int reg_nr)
554 if (mips64_transfers_32bit_regs_p)
557 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
561 mips_register_convert_to_virtual (int n, struct type *virtual_type,
562 char *raw_buf, char *virt_buf)
564 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
566 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
567 TYPE_LENGTH (virtual_type));
571 TYPE_LENGTH (virtual_type));
575 mips_register_convert_to_raw (struct type *virtual_type, int n,
576 char *virt_buf, char *raw_buf)
578 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
579 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
580 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
582 TYPE_LENGTH (virtual_type));
586 TYPE_LENGTH (virtual_type));
590 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
592 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
593 && REGISTER_RAW_SIZE (regnum) == 4
594 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
595 && TYPE_CODE(type) == TYPE_CODE_FLT
596 && TYPE_LENGTH(type) == 8)
599 memcpy (temp, ((char *)(buffer))+4, 4);
600 memcpy (((char *)(buffer))+4, (buffer), 4);
601 memcpy (((char *)(buffer)), temp, 4);
606 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
608 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
609 && REGISTER_RAW_SIZE (regnum) == 4
610 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
611 && TYPE_CODE(type) == TYPE_CODE_FLT
612 && TYPE_LENGTH(type) == 8)
615 memcpy (temp, ((char *)(buffer))+4, 4);
616 memcpy (((char *)(buffer))+4, (buffer), 4);
617 memcpy (((char *)(buffer)), temp, 4);
621 /* Return the GDB type object for the "standard" data type
622 of data in register REG.
624 Note: kevinb/2002-08-01: The definition below should faithfully
625 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
626 definitions found in config/mips/tm-*.h. I'm concerned about the
627 ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause though.
628 In some cases DEPRECATED_FP_REGNUM is in this range, and I doubt
629 that this code is correct for the 64-bit case. */
632 mips_register_virtual_type (int reg)
634 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
636 /* Floating point registers... */
637 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
638 return builtin_type_ieee_double_big;
640 return builtin_type_ieee_double_little;
642 else if (reg == PS_REGNUM /* CR */)
643 return builtin_type_uint32;
644 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
645 return builtin_type_uint32;
648 /* Everything else...
649 Return type appropriate for width of register. */
650 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
651 return builtin_type_uint64;
653 return builtin_type_uint32;
657 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
662 return read_signed_register (SP_REGNUM);
665 /* Should the upper word of 64-bit addresses be zeroed? */
666 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
669 mips_mask_address_p (void)
671 switch (mask_address_var)
673 case AUTO_BOOLEAN_TRUE:
675 case AUTO_BOOLEAN_FALSE:
678 case AUTO_BOOLEAN_AUTO:
679 return MIPS_DEFAULT_MASK_ADDRESS_P;
681 internal_error (__FILE__, __LINE__,
682 "mips_mask_address_p: bad switch");
688 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
690 switch (mask_address_var)
692 case AUTO_BOOLEAN_TRUE:
693 printf_filtered ("The 32 bit mips address mask is enabled\n");
695 case AUTO_BOOLEAN_FALSE:
696 printf_filtered ("The 32 bit mips address mask is disabled\n");
698 case AUTO_BOOLEAN_AUTO:
699 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
700 mips_mask_address_p () ? "enabled" : "disabled");
703 internal_error (__FILE__, __LINE__,
704 "show_mask_address: bad switch");
709 /* Should call_function allocate stack space for a struct return? */
712 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
714 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
718 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
720 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
724 mips_o32_use_struct_convention (int gcc_p, struct type *type)
726 return 1; /* Structures are returned by ref in extra arg0. */
729 /* Should call_function pass struct by reference?
730 For each architecture, structs are passed either by
731 value or by reference, depending on their size. */
734 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
736 enum type_code typecode = TYPE_CODE (check_typedef (type));
737 int len = TYPE_LENGTH (check_typedef (type));
739 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
740 return (len > MIPS_SAVED_REGSIZE);
746 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
748 return 0; /* Assumption: N32/N64 never passes struct by ref. */
752 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
754 return 0; /* Assumption: O32/O64 never passes struct by ref. */
757 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
760 pc_is_mips16 (bfd_vma memaddr)
762 struct minimal_symbol *sym;
764 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
765 if (IS_MIPS16_ADDR (memaddr))
768 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
769 the high bit of the info field. Use this to decide if the function is
770 MIPS16 or normal MIPS. */
771 sym = lookup_minimal_symbol_by_pc (memaddr);
773 return msymbol_is_special (sym);
778 /* MIPS believes that the PC has a sign extended value. Perhaphs the
779 all registers should be sign extended for simplicity? */
782 mips_read_pc (ptid_t ptid)
784 return read_signed_register_pid (PC_REGNUM, ptid);
787 /* This returns the PC of the first inst after the prologue. If we can't
788 find the prologue, then return 0. */
791 after_prologue (CORE_ADDR pc,
792 mips_extra_func_info_t proc_desc)
794 struct symtab_and_line sal;
795 CORE_ADDR func_addr, func_end;
797 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
798 to read the stack pointer from the current machine state, because
799 the current machine state has nothing to do with the information
800 we need from the proc_desc; and the process may or may not exist
803 proc_desc = find_proc_desc (pc, NULL, 0);
807 /* If function is frameless, then we need to do it the hard way. I
808 strongly suspect that frameless always means prologueless... */
809 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
810 && PROC_FRAME_OFFSET (proc_desc) == 0)
814 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
815 return 0; /* Unknown */
817 sal = find_pc_line (func_addr, 0);
819 if (sal.end < func_end)
822 /* The line after the prologue is after the end of the function. In this
823 case, tell the caller to find the prologue the hard way. */
828 /* Decode a MIPS32 instruction that saves a register in the stack, and
829 set the appropriate bit in the general register mask or float register mask
830 to indicate which register is saved. This is a helper function
831 for mips_find_saved_regs. */
834 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
835 unsigned long *float_mask)
839 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
840 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
841 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
843 /* It might be possible to use the instruction to
844 find the offset, rather than the code below which
845 is based on things being in a certain order in the
846 frame, but figuring out what the instruction's offset
847 is relative to might be a little tricky. */
848 reg = (inst & 0x001f0000) >> 16;
849 *gen_mask |= (1 << reg);
851 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
852 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
853 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
856 reg = ((inst & 0x001f0000) >> 16);
857 *float_mask |= (1 << reg);
861 /* Decode a MIPS16 instruction that saves a register in the stack, and
862 set the appropriate bit in the general register or float register mask
863 to indicate which register is saved. This is a helper function
864 for mips_find_saved_regs. */
867 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
869 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
871 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
872 *gen_mask |= (1 << reg);
874 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
876 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
877 *gen_mask |= (1 << reg);
879 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
880 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
881 *gen_mask |= (1 << RA_REGNUM);
885 /* Fetch and return instruction from the specified location. If the PC
886 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
889 mips_fetch_instruction (CORE_ADDR addr)
891 char buf[MIPS_INSTLEN];
895 if (pc_is_mips16 (addr))
897 instlen = MIPS16_INSTLEN;
898 addr = UNMAKE_MIPS16_ADDR (addr);
901 instlen = MIPS_INSTLEN;
902 status = read_memory_nobpt (addr, buf, instlen);
904 memory_error (status, addr);
905 return extract_unsigned_integer (buf, instlen);
909 /* These the fields of 32 bit mips instructions */
910 #define mips32_op(x) (x >> 26)
911 #define itype_op(x) (x >> 26)
912 #define itype_rs(x) ((x >> 21) & 0x1f)
913 #define itype_rt(x) ((x >> 16) & 0x1f)
914 #define itype_immediate(x) (x & 0xffff)
916 #define jtype_op(x) (x >> 26)
917 #define jtype_target(x) (x & 0x03ffffff)
919 #define rtype_op(x) (x >> 26)
920 #define rtype_rs(x) ((x >> 21) & 0x1f)
921 #define rtype_rt(x) ((x >> 16) & 0x1f)
922 #define rtype_rd(x) ((x >> 11) & 0x1f)
923 #define rtype_shamt(x) ((x >> 6) & 0x1f)
924 #define rtype_funct(x) (x & 0x3f)
927 mips32_relative_offset (unsigned long inst)
930 x = itype_immediate (inst);
931 if (x & 0x8000) /* sign bit set */
933 x |= 0xffff0000; /* sign extension */
939 /* Determine whate to set a single step breakpoint while considering
942 mips32_next_pc (CORE_ADDR pc)
946 inst = mips_fetch_instruction (pc);
947 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
949 if (itype_op (inst) >> 2 == 5)
950 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
952 op = (itype_op (inst) & 0x03);
967 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
968 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
970 int tf = itype_rt (inst) & 0x01;
971 int cnum = itype_rt (inst) >> 2;
972 int fcrcs = read_signed_register (FCRCS_REGNUM);
973 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
975 if (((cond >> cnum) & 0x01) == tf)
976 pc += mips32_relative_offset (inst) + 4;
981 pc += 4; /* Not a branch, next instruction is easy */
984 { /* This gets way messy */
986 /* Further subdivide into SPECIAL, REGIMM and other */
987 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
989 case 0: /* SPECIAL */
990 op = rtype_funct (inst);
995 /* Set PC to that address */
996 pc = read_signed_register (rtype_rs (inst));
1002 break; /* end SPECIAL */
1003 case 1: /* REGIMM */
1005 op = itype_rt (inst); /* branch condition */
1010 case 16: /* BLTZAL */
1011 case 18: /* BLTZALL */
1013 if (read_signed_register (itype_rs (inst)) < 0)
1014 pc += mips32_relative_offset (inst) + 4;
1016 pc += 8; /* after the delay slot */
1020 case 17: /* BGEZAL */
1021 case 19: /* BGEZALL */
1022 greater_equal_branch:
1023 if (read_signed_register (itype_rs (inst)) >= 0)
1024 pc += mips32_relative_offset (inst) + 4;
1026 pc += 8; /* after the delay slot */
1028 /* All of the other instructions in the REGIMM category */
1033 break; /* end REGIMM */
1038 reg = jtype_target (inst) << 2;
1039 /* Upper four bits get never changed... */
1040 pc = reg + ((pc + 4) & 0xf0000000);
1043 /* FIXME case JALX : */
1046 reg = jtype_target (inst) << 2;
1047 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1048 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1050 break; /* The new PC will be alternate mode */
1051 case 4: /* BEQ, BEQL */
1053 if (read_signed_register (itype_rs (inst)) ==
1054 read_signed_register (itype_rt (inst)))
1055 pc += mips32_relative_offset (inst) + 4;
1059 case 5: /* BNE, BNEL */
1061 if (read_signed_register (itype_rs (inst)) !=
1062 read_signed_register (itype_rt (inst)))
1063 pc += mips32_relative_offset (inst) + 4;
1067 case 6: /* BLEZ, BLEZL */
1069 if (read_signed_register (itype_rs (inst) <= 0))
1070 pc += mips32_relative_offset (inst) + 4;
1076 greater_branch: /* BGTZ, BGTZL */
1077 if (read_signed_register (itype_rs (inst) > 0))
1078 pc += mips32_relative_offset (inst) + 4;
1085 } /* mips32_next_pc */
1087 /* Decoding the next place to set a breakpoint is irregular for the
1088 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1089 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1090 We dont want to set a single step instruction on the extend instruction
1094 /* Lots of mips16 instruction formats */
1095 /* Predicting jumps requires itype,ritype,i8type
1096 and their extensions extItype,extritype,extI8type
1098 enum mips16_inst_fmts
1100 itype, /* 0 immediate 5,10 */
1101 ritype, /* 1 5,3,8 */
1102 rrtype, /* 2 5,3,3,5 */
1103 rritype, /* 3 5,3,3,5 */
1104 rrrtype, /* 4 5,3,3,3,2 */
1105 rriatype, /* 5 5,3,3,1,4 */
1106 shifttype, /* 6 5,3,3,3,2 */
1107 i8type, /* 7 5,3,8 */
1108 i8movtype, /* 8 5,3,3,5 */
1109 i8mov32rtype, /* 9 5,3,5,3 */
1110 i64type, /* 10 5,3,8 */
1111 ri64type, /* 11 5,3,3,5 */
1112 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1113 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1114 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1115 extRRItype, /* 15 5,5,5,5,3,3,5 */
1116 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1117 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1118 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1119 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1120 extRi64type, /* 20 5,6,5,5,3,3,5 */
1121 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1123 /* I am heaping all the fields of the formats into one structure and
1124 then, only the fields which are involved in instruction extension */
1128 unsigned int regx; /* Function in i8 type */
1133 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1134 for the bits which make up the immediatate extension. */
1137 extended_offset (unsigned int extension)
1140 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1142 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1144 value |= extension & 0x01f; /* extract 4:0 */
1148 /* Only call this function if you know that this is an extendable
1149 instruction, It wont malfunction, but why make excess remote memory references?
1150 If the immediate operands get sign extended or somthing, do it after
1151 the extension is performed.
1153 /* FIXME: Every one of these cases needs to worry about sign extension
1154 when the offset is to be used in relative addressing */
1158 fetch_mips_16 (CORE_ADDR pc)
1161 pc &= 0xfffffffe; /* clear the low order bit */
1162 target_read_memory (pc, buf, 2);
1163 return extract_unsigned_integer (buf, 2);
1167 unpack_mips16 (CORE_ADDR pc,
1168 unsigned int extension,
1170 enum mips16_inst_fmts insn_format,
1171 struct upk_mips16 *upk)
1176 switch (insn_format)
1183 value = extended_offset (extension);
1184 value = value << 11; /* rom for the original value */
1185 value |= inst & 0x7ff; /* eleven bits from instruction */
1189 value = inst & 0x7ff;
1190 /* FIXME : Consider sign extension */
1199 { /* A register identifier and an offset */
1200 /* Most of the fields are the same as I type but the
1201 immediate value is of a different length */
1205 value = extended_offset (extension);
1206 value = value << 8; /* from the original instruction */
1207 value |= inst & 0xff; /* eleven bits from instruction */
1208 regx = (extension >> 8) & 0x07; /* or i8 funct */
1209 if (value & 0x4000) /* test the sign bit , bit 26 */
1211 value &= ~0x3fff; /* remove the sign bit */
1217 value = inst & 0xff; /* 8 bits */
1218 regx = (inst >> 8) & 0x07; /* or i8 funct */
1219 /* FIXME: Do sign extension , this format needs it */
1220 if (value & 0x80) /* THIS CONFUSES ME */
1222 value &= 0xef; /* remove the sign bit */
1232 unsigned long value;
1233 unsigned int nexthalf;
1234 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1235 value = value << 16;
1236 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1244 internal_error (__FILE__, __LINE__,
1247 upk->offset = offset;
1254 add_offset_16 (CORE_ADDR pc, int offset)
1256 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1260 extended_mips16_next_pc (CORE_ADDR pc,
1261 unsigned int extension,
1264 int op = (insn >> 11);
1267 case 2: /* Branch */
1270 struct upk_mips16 upk;
1271 unpack_mips16 (pc, extension, insn, itype, &upk);
1272 offset = upk.offset;
1278 pc += (offset << 1) + 2;
1281 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1283 struct upk_mips16 upk;
1284 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1285 pc = add_offset_16 (pc, upk.offset);
1286 if ((insn >> 10) & 0x01) /* Exchange mode */
1287 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1294 struct upk_mips16 upk;
1296 unpack_mips16 (pc, extension, insn, ritype, &upk);
1297 reg = read_signed_register (upk.regx);
1299 pc += (upk.offset << 1) + 2;
1306 struct upk_mips16 upk;
1308 unpack_mips16 (pc, extension, insn, ritype, &upk);
1309 reg = read_signed_register (upk.regx);
1311 pc += (upk.offset << 1) + 2;
1316 case 12: /* I8 Formats btez btnez */
1318 struct upk_mips16 upk;
1320 unpack_mips16 (pc, extension, insn, i8type, &upk);
1321 /* upk.regx contains the opcode */
1322 reg = read_signed_register (24); /* Test register is 24 */
1323 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1324 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1325 /* pc = add_offset_16(pc,upk.offset) ; */
1326 pc += (upk.offset << 1) + 2;
1331 case 29: /* RR Formats JR, JALR, JALR-RA */
1333 struct upk_mips16 upk;
1334 /* upk.fmt = rrtype; */
1339 upk.regx = (insn >> 8) & 0x07;
1340 upk.regy = (insn >> 5) & 0x07;
1348 break; /* Function return instruction */
1354 break; /* BOGUS Guess */
1356 pc = read_signed_register (reg);
1363 /* This is an instruction extension. Fetch the real instruction
1364 (which follows the extension) and decode things based on
1368 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1381 mips16_next_pc (CORE_ADDR pc)
1383 unsigned int insn = fetch_mips_16 (pc);
1384 return extended_mips16_next_pc (pc, 0, insn);
1387 /* The mips_next_pc function supports single_step when the remote
1388 target monitor or stub is not developed enough to do a single_step.
1389 It works by decoding the current instruction and predicting where a
1390 branch will go. This isnt hard because all the data is available.
1391 The MIPS32 and MIPS16 variants are quite different */
1393 mips_next_pc (CORE_ADDR pc)
1396 return mips16_next_pc (pc);
1398 return mips32_next_pc (pc);
1401 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1404 Note: kevinb/2002-08-09: The only caller of this function is (and
1405 should remain) mips_frame_init_saved_regs(). In fact,
1406 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1407 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1408 functions should really be combined and now that there is only one
1409 caller, it should be straightforward. (Watch out for multiple returns
1413 mips_find_saved_regs (struct frame_info *fci)
1416 CORE_ADDR reg_position;
1417 /* r0 bit means kernel trap */
1419 /* What registers have been saved? Bitmasks. */
1420 unsigned long gen_mask, float_mask;
1421 mips_extra_func_info_t proc_desc;
1424 frame_saved_regs_zalloc (fci);
1426 /* If it is the frame for sigtramp, the saved registers are located
1427 in a sigcontext structure somewhere on the stack.
1428 If the stack layout for sigtramp changes we might have to change these
1429 constants and the companion fixup_sigtramp in mdebugread.c */
1430 #ifndef SIGFRAME_BASE
1431 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1432 above the sigtramp frame. */
1433 #define SIGFRAME_BASE MIPS_REGSIZE
1434 /* FIXME! Are these correct?? */
1435 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1436 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1437 #define SIGFRAME_FPREGSAVE_OFF \
1438 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1440 #ifndef SIGFRAME_REG_SIZE
1441 /* FIXME! Is this correct?? */
1442 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1444 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1446 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1448 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1449 + ireg * SIGFRAME_REG_SIZE;
1450 get_frame_saved_regs (fci)[ireg] = reg_position;
1452 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1454 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1455 + ireg * SIGFRAME_REG_SIZE;
1456 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1458 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1462 proc_desc = get_frame_extra_info (fci)->proc_desc;
1463 if (proc_desc == NULL)
1464 /* I'm not sure how/whether this can happen. Normally when we can't
1465 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1466 and set the saved_regs right away. */
1469 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1470 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1471 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1473 if ( /* In any frame other than the innermost or a frame interrupted by
1474 a signal, we assume that all registers have been saved.
1475 This assumes that all register saves in a function happen before
1476 the first function call. */
1477 (get_next_frame (fci) == NULL
1478 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1480 /* In a dummy frame we know exactly where things are saved. */
1481 && !PROC_DESC_IS_DUMMY (proc_desc)
1483 /* Don't bother unless we are inside a function prologue. Outside the
1484 prologue, we know where everything is. */
1486 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1488 /* Not sure exactly what kernel_trap means, but if it means
1489 the kernel saves the registers without a prologue doing it,
1490 we better not examine the prologue to see whether registers
1491 have been saved yet. */
1494 /* We need to figure out whether the registers that the proc_desc
1495 claims are saved have been saved yet. */
1499 /* Bitmasks; set if we have found a save for the register. */
1500 unsigned long gen_save_found = 0;
1501 unsigned long float_save_found = 0;
1504 /* If the address is odd, assume this is MIPS16 code. */
1505 addr = PROC_LOW_ADDR (proc_desc);
1506 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1508 /* Scan through this function's instructions preceding the current
1509 PC, and look for those that save registers. */
1510 while (addr < get_frame_pc (fci))
1512 inst = mips_fetch_instruction (addr);
1513 if (pc_is_mips16 (addr))
1514 mips16_decode_reg_save (inst, &gen_save_found);
1516 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1519 gen_mask = gen_save_found;
1520 float_mask = float_save_found;
1523 /* Fill in the offsets for the registers which gen_mask says
1525 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1526 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1527 if (gen_mask & 0x80000000)
1529 get_frame_saved_regs (fci)[ireg] = reg_position;
1530 reg_position -= MIPS_SAVED_REGSIZE;
1533 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1534 of that normally used by gcc. Therefore, we have to fetch the first
1535 instruction of the function, and if it's an entry instruction that
1536 saves $s0 or $s1, correct their saved addresses. */
1537 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1539 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1540 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1543 int sreg_count = (inst >> 6) & 3;
1545 /* Check if the ra register was pushed on the stack. */
1546 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1548 reg_position -= MIPS_SAVED_REGSIZE;
1550 /* Check if the s0 and s1 registers were pushed on the stack. */
1551 for (reg = 16; reg < sreg_count + 16; reg++)
1553 get_frame_saved_regs (fci)[reg] = reg_position;
1554 reg_position -= MIPS_SAVED_REGSIZE;
1559 /* Fill in the offsets for the registers which float_mask says
1561 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1563 /* Apparently, the freg_offset gives the offset to the first 64 bit
1566 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1567 designates the first saved 64 bit register.
1569 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1570 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1571 FREG_OFFSET, designates the address of the lower register of the
1572 register pair. Adjust the offset so that it designates the upper
1573 register of the pair -- i.e., the address of the first saved 32
1576 if (MIPS_SAVED_REGSIZE == 4)
1577 reg_position += MIPS_SAVED_REGSIZE;
1579 /* Fill in the offsets for the float registers which float_mask says
1581 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1582 if (float_mask & 0x80000000)
1584 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1585 reg_position -= MIPS_SAVED_REGSIZE;
1588 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1591 /* Set up the 'saved_regs' array. This is a data structure containing
1592 the addresses on the stack where each register has been saved, for
1593 each stack frame. Registers that have not been saved will have
1594 zero here. The stack pointer register is special: rather than the
1595 address where the stack register has been saved, saved_regs[SP_REGNUM]
1596 will have the actual value of the previous frame's stack register. */
1599 mips_frame_init_saved_regs (struct frame_info *frame)
1601 if (get_frame_saved_regs (frame) == NULL)
1603 mips_find_saved_regs (frame);
1605 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1609 read_next_frame_reg (struct frame_info *fi, int regno)
1614 enum lval_type lval;
1615 void *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
1619 regcache_cooked_read (current_regcache, regno, raw_buffer);
1623 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1625 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1626 should have a pseudo register range that correspons to the ABI's,
1627 rather than the ISA's, view of registers. These registers would
1628 then implicitly describe their size and hence could be used
1629 without the below munging. */
1630 if (lval == lval_memory)
1634 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1636 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1641 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1644 /* mips_addr_bits_remove - remove useless address bits */
1647 mips_addr_bits_remove (CORE_ADDR addr)
1649 if (GDB_TARGET_IS_MIPS64)
1651 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1653 /* This hack is a work-around for existing boards using
1654 PMON, the simulator, and any other 64-bit targets that
1655 doesn't have true 64-bit addressing. On these targets,
1656 the upper 32 bits of addresses are ignored by the
1657 hardware. Thus, the PC or SP are likely to have been
1658 sign extended to all 1s by instruction sequences that
1659 load 32-bit addresses. For example, a typical piece of
1660 code that loads an address is this:
1661 lui $r2, <upper 16 bits>
1662 ori $r2, <lower 16 bits>
1663 But the lui sign-extends the value such that the upper 32
1664 bits may be all 1s. The workaround is simply to mask off
1665 these bits. In the future, gcc may be changed to support
1666 true 64-bit addressing, and this masking will have to be
1668 addr &= (CORE_ADDR) 0xffffffff;
1671 else if (mips_mask_address_p ())
1673 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1674 masking off bits, instead, the actual target should be asking
1675 for the address to be converted to a valid pointer. */
1676 /* Even when GDB is configured for some 32-bit targets
1677 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1678 so CORE_ADDR is 64 bits. So we still have to mask off
1679 useless bits from addresses. */
1680 addr &= (CORE_ADDR) 0xffffffff;
1685 /* mips_software_single_step() is called just before we want to resume
1686 the inferior, if we want to single-step it but there is no hardware
1687 or kernel single-step support (MIPS on GNU/Linux for example). We find
1688 the target of the coming instruction and breakpoint it.
1690 single_step is also called just after the inferior stops. If we had
1691 set up a simulated single-step, we undo our damage. */
1694 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1696 static CORE_ADDR next_pc;
1697 typedef char binsn_quantum[BREAKPOINT_MAX];
1698 static binsn_quantum break_mem;
1701 if (insert_breakpoints_p)
1703 pc = read_register (PC_REGNUM);
1704 next_pc = mips_next_pc (pc);
1706 target_insert_breakpoint (next_pc, break_mem);
1709 target_remove_breakpoint (next_pc, break_mem);
1713 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1718 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1719 : get_next_frame (prev)
1720 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1722 tmp = SKIP_TRAMPOLINE_CODE (pc);
1723 return tmp ? tmp : pc;
1728 mips_frame_saved_pc (struct frame_info *frame)
1731 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1732 /* We have to get the saved pc from the sigcontext
1733 if it is a signal handler frame. */
1734 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1735 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1737 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1740 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1743 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1744 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1746 saved_pc = read_next_frame_reg (frame, pcreg);
1748 return ADDR_BITS_REMOVE (saved_pc);
1751 static struct mips_extra_func_info temp_proc_desc;
1753 /* This hack will go away once the get_prev_frame() code has been
1754 modified to set the frame's type first. That is BEFORE init extra
1755 frame info et.al. is called. This is because it will become
1756 possible to skip the init extra info call for sigtramp and dummy
1758 static CORE_ADDR *temp_saved_regs;
1760 /* Set a register's saved stack address in temp_saved_regs. If an address
1761 has already been set for this register, do nothing; this way we will
1762 only recognize the first save of a given register in a function prologue.
1763 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1766 set_reg_offset (int regno, CORE_ADDR offset)
1768 if (temp_saved_regs[regno] == 0)
1769 temp_saved_regs[regno] = offset;
1773 /* Test whether the PC points to the return instruction at the
1774 end of a function. */
1777 mips_about_to_return (CORE_ADDR pc)
1779 if (pc_is_mips16 (pc))
1780 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1781 generates a "jr $ra"; other times it generates code to load
1782 the return address from the stack to an accessible register (such
1783 as $a3), then a "jr" using that register. This second case
1784 is almost impossible to distinguish from an indirect jump
1785 used for switch statements, so we don't even try. */
1786 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1788 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1792 /* This fencepost looks highly suspicious to me. Removing it also
1793 seems suspicious as it could affect remote debugging across serial
1797 heuristic_proc_start (CORE_ADDR pc)
1804 pc = ADDR_BITS_REMOVE (pc);
1806 fence = start_pc - heuristic_fence_post;
1810 if (heuristic_fence_post == UINT_MAX
1811 || fence < VM_MIN_ADDRESS)
1812 fence = VM_MIN_ADDRESS;
1814 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1816 /* search back for previous return */
1817 for (start_pc -= instlen;; start_pc -= instlen)
1818 if (start_pc < fence)
1820 /* It's not clear to me why we reach this point when
1821 stop_soon, but with this test, at least we
1822 don't print out warnings for every child forked (eg, on
1824 if (stop_soon == NO_STOP_QUIETLY)
1826 static int blurb_printed = 0;
1828 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1833 /* This actually happens frequently in embedded
1834 development, when you first connect to a board
1835 and your stack pointer and pc are nowhere in
1836 particular. This message needs to give people
1837 in that situation enough information to
1838 determine that it's no big deal. */
1839 printf_filtered ("\n\
1840 GDB is unable to find the start of the function at 0x%s\n\
1841 and thus can't determine the size of that function's stack frame.\n\
1842 This means that GDB may be unable to access that stack frame, or\n\
1843 the frames below it.\n\
1844 This problem is most likely caused by an invalid program counter or\n\
1846 However, if you think GDB should simply search farther back\n\
1847 from 0x%s for code which looks like the beginning of a\n\
1848 function, you can increase the range of the search using the `set\n\
1849 heuristic-fence-post' command.\n",
1850 paddr_nz (pc), paddr_nz (pc));
1857 else if (pc_is_mips16 (start_pc))
1859 unsigned short inst;
1861 /* On MIPS16, any one of the following is likely to be the
1862 start of a function:
1866 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1867 inst = mips_fetch_instruction (start_pc);
1868 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1869 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1870 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1871 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1873 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1874 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1879 else if (mips_about_to_return (start_pc))
1881 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1888 /* Fetch the immediate value from a MIPS16 instruction.
1889 If the previous instruction was an EXTEND, use it to extend
1890 the upper bits of the immediate value. This is a helper function
1891 for mips16_heuristic_proc_desc. */
1894 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1895 unsigned short inst, /* current instruction */
1896 int nbits, /* number of bits in imm field */
1897 int scale, /* scale factor to be applied to imm */
1898 int is_signed) /* is the imm field signed? */
1902 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1904 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1905 if (offset & 0x8000) /* check for negative extend */
1906 offset = 0 - (0x10000 - (offset & 0xffff));
1907 return offset | (inst & 0x1f);
1911 int max_imm = 1 << nbits;
1912 int mask = max_imm - 1;
1913 int sign_bit = max_imm >> 1;
1915 offset = inst & mask;
1916 if (is_signed && (offset & sign_bit))
1917 offset = 0 - (max_imm - offset);
1918 return offset * scale;
1923 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1924 stream from start_pc to limit_pc. */
1927 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1928 struct frame_info *next_frame, CORE_ADDR sp)
1931 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1932 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1933 unsigned inst = 0; /* current instruction */
1934 unsigned entry_inst = 0; /* the entry instruction */
1937 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1938 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1940 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1942 /* Save the previous instruction. If it's an EXTEND, we'll extract
1943 the immediate offset extension from it in mips16_get_imm. */
1946 /* Fetch and decode the instruction. */
1947 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1948 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1949 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1951 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1952 if (offset < 0) /* negative stack adjustment? */
1953 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1955 /* Exit loop if a positive stack adjustment is found, which
1956 usually means that the stack cleanup code in the function
1957 epilogue is reached. */
1960 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1962 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1963 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1964 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1965 set_reg_offset (reg, sp + offset);
1967 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1969 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1970 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1971 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1972 set_reg_offset (reg, sp + offset);
1974 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1976 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1977 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1978 set_reg_offset (RA_REGNUM, sp + offset);
1980 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1982 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1983 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1984 set_reg_offset (RA_REGNUM, sp + offset);
1986 else if (inst == 0x673d) /* move $s1, $sp */
1989 PROC_FRAME_REG (&temp_proc_desc) = 17;
1991 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1993 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1994 frame_addr = sp + offset;
1995 PROC_FRAME_REG (&temp_proc_desc) = 17;
1996 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
1998 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2000 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2001 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2002 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2003 set_reg_offset (reg, frame_addr + offset);
2005 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2007 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2008 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2009 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2010 set_reg_offset (reg, frame_addr + offset);
2012 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2013 entry_inst = inst; /* save for later processing */
2014 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2015 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2018 /* The entry instruction is typically the first instruction in a function,
2019 and it stores registers at offsets relative to the value of the old SP
2020 (before the prologue). But the value of the sp parameter to this
2021 function is the new SP (after the prologue has been executed). So we
2022 can't calculate those offsets until we've seen the entire prologue,
2023 and can calculate what the old SP must have been. */
2024 if (entry_inst != 0)
2026 int areg_count = (entry_inst >> 8) & 7;
2027 int sreg_count = (entry_inst >> 6) & 3;
2029 /* The entry instruction always subtracts 32 from the SP. */
2030 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2032 /* Now we can calculate what the SP must have been at the
2033 start of the function prologue. */
2034 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2036 /* Check if a0-a3 were saved in the caller's argument save area. */
2037 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2039 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2040 set_reg_offset (reg, sp + offset);
2041 offset += MIPS_SAVED_REGSIZE;
2044 /* Check if the ra register was pushed on the stack. */
2046 if (entry_inst & 0x20)
2048 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2049 set_reg_offset (RA_REGNUM, sp + offset);
2050 offset -= MIPS_SAVED_REGSIZE;
2053 /* Check if the s0 and s1 registers were pushed on the stack. */
2054 for (reg = 16; reg < sreg_count + 16; reg++)
2056 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2057 set_reg_offset (reg, sp + offset);
2058 offset -= MIPS_SAVED_REGSIZE;
2064 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2065 struct frame_info *next_frame, CORE_ADDR sp)
2068 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2070 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2071 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2072 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2073 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2074 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2076 unsigned long inst, high_word, low_word;
2079 /* Fetch the instruction. */
2080 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2082 /* Save some code by pre-extracting some useful fields. */
2083 high_word = (inst >> 16) & 0xffff;
2084 low_word = inst & 0xffff;
2085 reg = high_word & 0x1f;
2087 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2088 || high_word == 0x23bd /* addi $sp,$sp,-i */
2089 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2091 if (low_word & 0x8000) /* negative stack adjustment? */
2092 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2094 /* Exit loop if a positive stack adjustment is found, which
2095 usually means that the stack cleanup code in the function
2096 epilogue is reached. */
2099 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2101 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2102 set_reg_offset (reg, sp + low_word);
2104 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2106 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2107 but the register size used is only 32 bits. Make the address
2108 for the saved register point to the lower 32 bits. */
2109 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2110 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2112 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2114 /* Old gcc frame, r30 is virtual frame pointer. */
2115 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2116 frame_addr = sp + low_word;
2117 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2119 unsigned alloca_adjust;
2120 PROC_FRAME_REG (&temp_proc_desc) = 30;
2121 frame_addr = read_next_frame_reg (next_frame, 30);
2122 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2123 if (alloca_adjust > 0)
2125 /* FP > SP + frame_size. This may be because
2126 * of an alloca or somethings similar.
2127 * Fix sp to "pre-alloca" value, and try again.
2129 sp += alloca_adjust;
2134 /* move $30,$sp. With different versions of gas this will be either
2135 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2136 Accept any one of these. */
2137 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2139 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2140 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2142 unsigned alloca_adjust;
2143 PROC_FRAME_REG (&temp_proc_desc) = 30;
2144 frame_addr = read_next_frame_reg (next_frame, 30);
2145 alloca_adjust = (unsigned) (frame_addr - sp);
2146 if (alloca_adjust > 0)
2148 /* FP > SP + frame_size. This may be because
2149 * of an alloca or somethings similar.
2150 * Fix sp to "pre-alloca" value, and try again.
2152 sp += alloca_adjust;
2157 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2159 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2160 set_reg_offset (reg, frame_addr + low_word);
2165 static mips_extra_func_info_t
2166 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2167 struct frame_info *next_frame, int cur_frame)
2172 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2178 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2179 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2180 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2181 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2182 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2183 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2185 if (start_pc + 200 < limit_pc)
2186 limit_pc = start_pc + 200;
2187 if (pc_is_mips16 (start_pc))
2188 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2190 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2191 return &temp_proc_desc;
2194 struct mips_objfile_private
2200 /* Global used to communicate between non_heuristic_proc_desc and
2201 compare_pdr_entries within qsort (). */
2202 static bfd *the_bfd;
2205 compare_pdr_entries (const void *a, const void *b)
2207 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2208 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2212 else if (lhs == rhs)
2218 static mips_extra_func_info_t
2219 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2221 CORE_ADDR startaddr;
2222 mips_extra_func_info_t proc_desc;
2223 struct block *b = block_for_pc (pc);
2225 struct obj_section *sec;
2226 struct mips_objfile_private *priv;
2228 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2231 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2233 *addrptr = startaddr;
2237 sec = find_pc_section (pc);
2240 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2242 /* Search the ".pdr" section generated by GAS. This includes most of
2243 the information normally found in ECOFF PDRs. */
2245 the_bfd = sec->objfile->obfd;
2247 && (the_bfd->format == bfd_object
2248 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2249 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2251 /* Right now GAS only outputs the address as a four-byte sequence.
2252 This means that we should not bother with this method on 64-bit
2253 targets (until that is fixed). */
2255 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2256 sizeof (struct mips_objfile_private));
2258 sec->objfile->obj_private = priv;
2260 else if (priv == NULL)
2264 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2265 sizeof (struct mips_objfile_private));
2267 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2270 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2271 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2273 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2274 priv->contents, 0, priv->size);
2276 /* In general, the .pdr section is sorted. However, in the
2277 presence of multiple code sections (and other corner cases)
2278 it can become unsorted. Sort it so that we can use a faster
2280 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2285 sec->objfile->obj_private = priv;
2289 if (priv->size != 0)
2295 high = priv->size / 32;
2301 mid = (low + high) / 2;
2303 ptr = priv->contents + mid * 32;
2304 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2305 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2306 SECT_OFF_TEXT (sec->objfile));
2307 if (pdr_pc == startaddr)
2309 if (pdr_pc > startaddr)
2314 while (low != high);
2318 struct symbol *sym = find_pc_function (pc);
2320 /* Fill in what we need of the proc_desc. */
2321 proc_desc = (mips_extra_func_info_t)
2322 obstack_alloc (&sec->objfile->psymbol_obstack,
2323 sizeof (struct mips_extra_func_info));
2324 PROC_LOW_ADDR (proc_desc) = startaddr;
2326 /* Only used for dummy frames. */
2327 PROC_HIGH_ADDR (proc_desc) = 0;
2329 PROC_FRAME_OFFSET (proc_desc)
2330 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2331 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2333 PROC_FRAME_ADJUST (proc_desc) = 0;
2334 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2336 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2338 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2340 PROC_FREG_OFFSET (proc_desc)
2341 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2342 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2344 proc_desc->pdr.isym = (long) sym;
2354 if (startaddr > BLOCK_START (b))
2356 /* This is the "pathological" case referred to in a comment in
2357 print_frame_info. It might be better to move this check into
2362 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
2364 /* If we never found a PDR for this function in symbol reading, then
2365 examine prologues to find the information. */
2368 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2369 if (PROC_FRAME_REG (proc_desc) == -1)
2379 static mips_extra_func_info_t
2380 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2382 mips_extra_func_info_t proc_desc;
2383 CORE_ADDR startaddr = 0;
2385 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2389 /* IF this is the topmost frame AND
2390 * (this proc does not have debugging information OR
2391 * the PC is in the procedure prologue)
2392 * THEN create a "heuristic" proc_desc (by analyzing
2393 * the actual code) to replace the "official" proc_desc.
2395 if (next_frame == NULL)
2397 struct symtab_and_line val;
2398 struct symbol *proc_symbol =
2399 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2403 val = find_pc_line (BLOCK_START
2404 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2406 val.pc = val.end ? val.end : pc;
2408 if (!proc_symbol || pc < val.pc)
2410 mips_extra_func_info_t found_heuristic =
2411 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2412 pc, next_frame, cur_frame);
2413 if (found_heuristic)
2414 proc_desc = found_heuristic;
2420 /* Is linked_proc_desc_table really necessary? It only seems to be used
2421 by procedure call dummys. However, the procedures being called ought
2422 to have their own proc_descs, and even if they don't,
2423 heuristic_proc_desc knows how to create them! */
2425 register struct linked_proc_info *link;
2427 for (link = linked_proc_desc_table; link; link = link->next)
2428 if (PROC_LOW_ADDR (&link->info) <= pc
2429 && PROC_HIGH_ADDR (&link->info) > pc)
2433 startaddr = heuristic_proc_start (pc);
2436 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2442 get_frame_pointer (struct frame_info *frame,
2443 mips_extra_func_info_t proc_desc)
2445 return (read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
2446 + PROC_FRAME_OFFSET (proc_desc)
2447 - PROC_FRAME_ADJUST (proc_desc));
2450 static mips_extra_func_info_t cached_proc_desc;
2453 mips_frame_chain (struct frame_info *frame)
2455 mips_extra_func_info_t proc_desc;
2457 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2459 if (saved_pc == 0 || inside_entry_file (saved_pc))
2462 /* Check if the PC is inside a call stub. If it is, fetch the
2463 PC of the caller of that stub. */
2464 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2467 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2469 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2470 is well, frame->frame the bottom of the current frame will
2471 contain that value. */
2472 return get_frame_base (frame);
2475 /* Look up the procedure descriptor for this PC. */
2476 proc_desc = find_proc_desc (saved_pc, frame, 1);
2480 cached_proc_desc = proc_desc;
2482 /* If no frame pointer and frame size is zero, we must be at end
2483 of stack (or otherwise hosed). If we don't check frame size,
2484 we loop forever if we see a zero size frame. */
2485 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2486 && PROC_FRAME_OFFSET (proc_desc) == 0
2487 /* The previous frame from a sigtramp frame might be frameless
2488 and have frame size zero. */
2489 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2490 /* For a generic dummy frame, let get_frame_pointer() unwind a
2491 register value saved as part of the dummy frame call. */
2492 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2495 return get_frame_pointer (frame, proc_desc);
2499 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2502 mips_extra_func_info_t proc_desc;
2504 if (get_frame_type (fci) == DUMMY_FRAME)
2507 /* Use proc_desc calculated in frame_chain. When there is no
2508 next frame, i.e, get_next_frame (fci) == NULL, we call
2509 find_proc_desc () to calculate it, passing an explicit
2510 NULL as the frame parameter. */
2512 get_next_frame (fci)
2514 : find_proc_desc (get_frame_pc (fci),
2515 NULL /* i.e, get_next_frame (fci) */,
2518 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2520 deprecated_set_frame_saved_regs_hack (fci, NULL);
2521 get_frame_extra_info (fci)->proc_desc =
2522 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2525 /* Fixup frame-pointer - only needed for top frame */
2526 /* This may not be quite right, if proc has a real frame register.
2527 Get the value of the frame relative sp, procedure might have been
2528 interrupted by a signal at it's very start. */
2529 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2530 && !PROC_DESC_IS_DUMMY (proc_desc))
2531 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2532 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2533 /* Do not ``fix'' fci->frame. It will have the value of the
2534 generic dummy frame's top-of-stack (since the draft
2535 fci->frame is obtained by returning the unwound stack
2536 pointer) and that is what we want. That way the fci->frame
2537 value will match the top-of-stack value that was saved as
2538 part of the dummy frames data. */
2541 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2543 if (proc_desc == &temp_proc_desc)
2547 /* Do not set the saved registers for a sigtramp frame,
2548 mips_find_saved_registers will do that for us. We can't
2549 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2551 /* FIXME: cagney/2002-11-18: This problem will go away once
2552 frame.c:get_prev_frame() is modified to set the frame's
2553 type before calling functions like this. */
2554 find_pc_partial_function (get_frame_pc (fci), &name,
2555 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2556 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2558 frame_saved_regs_zalloc (fci);
2559 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2560 get_frame_saved_regs (fci)[PC_REGNUM]
2561 = get_frame_saved_regs (fci)[RA_REGNUM];
2562 /* Set value of previous frame's stack pointer. Remember that
2563 saved_regs[SP_REGNUM] is special in that it contains the
2564 value of the stack pointer register. The other saved_regs
2565 values are addresses (in the inferior) at which a given
2566 register's value may be found. */
2567 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2571 /* hack: if argument regs are saved, guess these contain args */
2572 /* assume we can't tell how many args for now */
2573 get_frame_extra_info (fci)->num_args = -1;
2574 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2576 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2578 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2585 /* MIPS stack frames are almost impenetrable. When execution stops,
2586 we basically have to look at symbol information for the function
2587 that we stopped in, which tells us *which* register (if any) is
2588 the base of the frame pointer, and what offset from that register
2589 the frame itself is at.
2591 This presents a problem when trying to examine a stack in memory
2592 (that isn't executing at the moment), using the "frame" command. We
2593 don't have a PC, nor do we have any registers except SP.
2595 This routine takes two arguments, SP and PC, and tries to make the
2596 cached frames look as if these two arguments defined a frame on the
2597 cache. This allows the rest of info frame to extract the important
2598 arguments without difficulty. */
2601 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2604 error ("MIPS frame specifications require two arguments: sp and pc");
2606 return create_new_frame (argv[0], argv[1]);
2609 /* According to the current ABI, should the type be passed in a
2610 floating-point register (assuming that there is space)? When there
2611 is no FPU, FP are not even considered as possibile candidates for
2612 FP registers and, consequently this returns false - forces FP
2613 arguments into integer registers. */
2616 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2618 return ((typecode == TYPE_CODE_FLT
2620 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2621 && TYPE_NFIELDS (arg_type) == 1
2622 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2623 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2626 /* On o32, argument passing in GPRs depends on the alignment of the type being
2627 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2630 mips_type_needs_double_align (struct type *type)
2632 enum type_code typecode = TYPE_CODE (type);
2634 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2636 else if (typecode == TYPE_CODE_STRUCT)
2638 if (TYPE_NFIELDS (type) < 1)
2640 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2642 else if (typecode == TYPE_CODE_UNION)
2646 n = TYPE_NFIELDS (type);
2647 for (i = 0; i < n; i++)
2648 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2655 /* Macros to round N up or down to the next A boundary;
2656 A must be a power of two. */
2658 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2659 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2661 /* Adjust the address downward (direction of stack growth) so that it
2662 is correctly aligned for a new stack frame. */
2664 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2666 return ROUND_DOWN (addr, 16);
2670 mips_eabi_push_arguments (int nargs,
2671 struct value **args,
2674 CORE_ADDR struct_addr)
2680 int stack_offset = 0;
2682 /* First ensure that the stack and structure return address (if any)
2683 are properly aligned. The stack has to be at least 64-bit
2684 aligned even on 32-bit machines, because doubles must be 64-bit
2685 aligned. For n32 and n64, stack frames need to be 128-bit
2686 aligned, so we round to this widest known alignment. */
2688 sp = ROUND_DOWN (sp, 16);
2689 struct_addr = ROUND_DOWN (struct_addr, 16);
2691 /* Now make space on the stack for the args. We allocate more
2692 than necessary for EABI, because the first few arguments are
2693 passed in registers, but that's OK. */
2694 for (argnum = 0; argnum < nargs; argnum++)
2695 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2696 MIPS_STACK_ARGSIZE);
2697 sp -= ROUND_UP (len, 16);
2700 fprintf_unfiltered (gdb_stdlog,
2701 "mips_eabi_push_arguments: sp=0x%s allocated %d\n",
2702 paddr_nz (sp), ROUND_UP (len, 16));
2704 /* Initialize the integer and float register pointers. */
2706 float_argreg = FPA0_REGNUM;
2708 /* The struct_return pointer occupies the first parameter-passing reg. */
2712 fprintf_unfiltered (gdb_stdlog,
2713 "mips_eabi_push_arguments: struct_return reg=%d 0x%s\n",
2714 argreg, paddr_nz (struct_addr));
2715 write_register (argreg++, struct_addr);
2718 /* Now load as many as possible of the first arguments into
2719 registers, and push the rest onto the stack. Loop thru args
2720 from first to last. */
2721 for (argnum = 0; argnum < nargs; argnum++)
2724 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2725 struct value *arg = args[argnum];
2726 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2727 int len = TYPE_LENGTH (arg_type);
2728 enum type_code typecode = TYPE_CODE (arg_type);
2731 fprintf_unfiltered (gdb_stdlog,
2732 "mips_eabi_push_arguments: %d len=%d type=%d",
2733 argnum + 1, len, (int) typecode);
2735 /* The EABI passes structures that do not fit in a register by
2737 if (len > MIPS_SAVED_REGSIZE
2738 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2740 store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2741 typecode = TYPE_CODE_PTR;
2742 len = MIPS_SAVED_REGSIZE;
2745 fprintf_unfiltered (gdb_stdlog, " push");
2748 val = (char *) VALUE_CONTENTS (arg);
2750 /* 32-bit ABIs always start floating point arguments in an
2751 even-numbered floating point register. Round the FP register
2752 up before the check to see if there are any FP registers
2753 left. Non MIPS_EABI targets also pass the FP in the integer
2754 registers so also round up normal registers. */
2755 if (!FP_REGISTER_DOUBLE
2756 && fp_register_arg_p (typecode, arg_type))
2758 if ((float_argreg & 1))
2762 /* Floating point arguments passed in registers have to be
2763 treated specially. On 32-bit architectures, doubles
2764 are passed in register pairs; the even register gets
2765 the low word, and the odd register gets the high word.
2766 On non-EABI processors, the first two floating point arguments are
2767 also copied to general registers, because MIPS16 functions
2768 don't use float registers for arguments. This duplication of
2769 arguments in general registers can't hurt non-MIPS16 functions
2770 because those registers are normally skipped. */
2771 /* MIPS_EABI squeezes a struct that contains a single floating
2772 point value into an FP register instead of pushing it onto the
2774 if (fp_register_arg_p (typecode, arg_type)
2775 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2777 if (!FP_REGISTER_DOUBLE && len == 8)
2779 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2780 unsigned long regval;
2782 /* Write the low word of the double to the even register(s). */
2783 regval = extract_unsigned_integer (val + low_offset, 4);
2785 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2786 float_argreg, phex (regval, 4));
2787 write_register (float_argreg++, regval);
2789 /* Write the high word of the double to the odd register(s). */
2790 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2792 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2793 float_argreg, phex (regval, 4));
2794 write_register (float_argreg++, regval);
2798 /* This is a floating point value that fits entirely
2799 in a single register. */
2800 /* On 32 bit ABI's the float_argreg is further adjusted
2801 above to ensure that it is even register aligned. */
2802 LONGEST regval = extract_unsigned_integer (val, len);
2804 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2805 float_argreg, phex (regval, len));
2806 write_register (float_argreg++, regval);
2811 /* Copy the argument to general registers or the stack in
2812 register-sized pieces. Large arguments are split between
2813 registers and stack. */
2814 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2815 are treated specially: Irix cc passes them in registers
2816 where gcc sometimes puts them on the stack. For maximum
2817 compatibility, we will put them in both places. */
2818 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2819 (len % MIPS_SAVED_REGSIZE != 0));
2821 /* Note: Floating-point values that didn't fit into an FP
2822 register are only written to memory. */
2825 /* Remember if the argument was written to the stack. */
2826 int stack_used_p = 0;
2828 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2831 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2834 /* Write this portion of the argument to the stack. */
2835 if (argreg > MIPS_LAST_ARG_REGNUM
2837 || fp_register_arg_p (typecode, arg_type))
2839 /* Should shorter than int integer values be
2840 promoted to int before being stored? */
2841 int longword_offset = 0;
2844 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2846 if (MIPS_STACK_ARGSIZE == 8 &&
2847 (typecode == TYPE_CODE_INT ||
2848 typecode == TYPE_CODE_PTR ||
2849 typecode == TYPE_CODE_FLT) && len <= 4)
2850 longword_offset = MIPS_STACK_ARGSIZE - len;
2851 else if ((typecode == TYPE_CODE_STRUCT ||
2852 typecode == TYPE_CODE_UNION) &&
2853 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2854 longword_offset = MIPS_STACK_ARGSIZE - len;
2859 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2860 paddr_nz (stack_offset));
2861 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2862 paddr_nz (longword_offset));
2865 addr = sp + stack_offset + longword_offset;
2870 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2872 for (i = 0; i < partial_len; i++)
2874 fprintf_unfiltered (gdb_stdlog, "%02x",
2878 write_memory (addr, val, partial_len);
2881 /* Note!!! This is NOT an else clause. Odd sized
2882 structs may go thru BOTH paths. Floating point
2883 arguments will not. */
2884 /* Write this portion of the argument to a general
2885 purpose register. */
2886 if (argreg <= MIPS_LAST_ARG_REGNUM
2887 && !fp_register_arg_p (typecode, arg_type))
2889 LONGEST regval = extract_unsigned_integer (val, partial_len);
2892 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2894 phex (regval, MIPS_SAVED_REGSIZE));
2895 write_register (argreg, regval);
2902 /* Compute the the offset into the stack at which we
2903 will copy the next parameter.
2905 In the new EABI (and the NABI32), the stack_offset
2906 only needs to be adjusted when it has been used. */
2909 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2913 fprintf_unfiltered (gdb_stdlog, "\n");
2916 /* Return adjusted stack pointer. */
2920 /* N32/N64 version of push_arguments. */
2923 mips_n32n64_push_arguments (int nargs,
2924 struct value **args,
2927 CORE_ADDR struct_addr)
2933 int stack_offset = 0;
2935 /* First ensure that the stack and structure return address (if any)
2936 are properly aligned. The stack has to be at least 64-bit
2937 aligned even on 32-bit machines, because doubles must be 64-bit
2938 aligned. For n32 and n64, stack frames need to be 128-bit
2939 aligned, so we round to this widest known alignment. */
2941 sp = ROUND_DOWN (sp, 16);
2942 struct_addr = ROUND_DOWN (struct_addr, 16);
2944 /* Now make space on the stack for the args. */
2945 for (argnum = 0; argnum < nargs; argnum++)
2946 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2947 MIPS_STACK_ARGSIZE);
2948 sp -= ROUND_UP (len, 16);
2951 fprintf_unfiltered (gdb_stdlog,
2952 "mips_n32n64_push_arguments: sp=0x%s allocated %d\n",
2953 paddr_nz (sp), ROUND_UP (len, 16));
2955 /* Initialize the integer and float register pointers. */
2957 float_argreg = FPA0_REGNUM;
2959 /* The struct_return pointer occupies the first parameter-passing reg. */
2963 fprintf_unfiltered (gdb_stdlog,
2964 "mips_n32n64_push_arguments: struct_return reg=%d 0x%s\n",
2965 argreg, paddr_nz (struct_addr));
2966 write_register (argreg++, struct_addr);
2969 /* Now load as many as possible of the first arguments into
2970 registers, and push the rest onto the stack. Loop thru args
2971 from first to last. */
2972 for (argnum = 0; argnum < nargs; argnum++)
2975 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2976 struct value *arg = args[argnum];
2977 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2978 int len = TYPE_LENGTH (arg_type);
2979 enum type_code typecode = TYPE_CODE (arg_type);
2982 fprintf_unfiltered (gdb_stdlog,
2983 "mips_n32n64_push_arguments: %d len=%d type=%d",
2984 argnum + 1, len, (int) typecode);
2986 val = (char *) VALUE_CONTENTS (arg);
2988 if (fp_register_arg_p (typecode, arg_type)
2989 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2991 /* This is a floating point value that fits entirely
2992 in a single register. */
2993 /* On 32 bit ABI's the float_argreg is further adjusted
2994 above to ensure that it is even register aligned. */
2995 LONGEST regval = extract_unsigned_integer (val, len);
2997 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2998 float_argreg, phex (regval, len));
2999 write_register (float_argreg++, regval);
3002 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3003 argreg, phex (regval, len));
3004 write_register (argreg, regval);
3009 /* Copy the argument to general registers or the stack in
3010 register-sized pieces. Large arguments are split between
3011 registers and stack. */
3012 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3013 are treated specially: Irix cc passes them in registers
3014 where gcc sometimes puts them on the stack. For maximum
3015 compatibility, we will put them in both places. */
3016 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3017 (len % MIPS_SAVED_REGSIZE != 0));
3018 /* Note: Floating-point values that didn't fit into an FP
3019 register are only written to memory. */
3022 /* Rememer if the argument was written to the stack. */
3023 int stack_used_p = 0;
3024 int partial_len = len < MIPS_SAVED_REGSIZE ?
3025 len : MIPS_SAVED_REGSIZE;
3028 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3031 /* Write this portion of the argument to the stack. */
3032 if (argreg > MIPS_LAST_ARG_REGNUM
3034 || fp_register_arg_p (typecode, arg_type))
3036 /* Should shorter than int integer values be
3037 promoted to int before being stored? */
3038 int longword_offset = 0;
3041 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3043 if (MIPS_STACK_ARGSIZE == 8 &&
3044 (typecode == TYPE_CODE_INT ||
3045 typecode == TYPE_CODE_PTR ||
3046 typecode == TYPE_CODE_FLT) && len <= 4)
3047 longword_offset = MIPS_STACK_ARGSIZE - len;
3052 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3053 paddr_nz (stack_offset));
3054 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3055 paddr_nz (longword_offset));
3058 addr = sp + stack_offset + longword_offset;
3063 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3065 for (i = 0; i < partial_len; i++)
3067 fprintf_unfiltered (gdb_stdlog, "%02x",
3071 write_memory (addr, val, partial_len);
3074 /* Note!!! This is NOT an else clause. Odd sized
3075 structs may go thru BOTH paths. Floating point
3076 arguments will not. */
3077 /* Write this portion of the argument to a general
3078 purpose register. */
3079 if (argreg <= MIPS_LAST_ARG_REGNUM
3080 && !fp_register_arg_p (typecode, arg_type))
3082 LONGEST regval = extract_unsigned_integer (val, partial_len);
3084 /* A non-floating-point argument being passed in a
3085 general register. If a struct or union, and if
3086 the remaining length is smaller than the register
3087 size, we have to adjust the register value on
3090 It does not seem to be necessary to do the
3091 same for integral types.
3093 cagney/2001-07-23: gdb/179: Also, GCC, when
3094 outputting LE O32 with sizeof (struct) <
3095 MIPS_SAVED_REGSIZE, generates a left shift as
3096 part of storing the argument in a register a
3097 register (the left shift isn't generated when
3098 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3099 is quite possible that this is GCC contradicting
3100 the LE/O32 ABI, GDB has not been adjusted to
3101 accommodate this. Either someone needs to
3102 demonstrate that the LE/O32 ABI specifies such a
3103 left shift OR this new ABI gets identified as
3104 such and GDB gets tweaked accordingly. */
3106 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3107 && partial_len < MIPS_SAVED_REGSIZE
3108 && (typecode == TYPE_CODE_STRUCT ||
3109 typecode == TYPE_CODE_UNION))
3110 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3114 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3116 phex (regval, MIPS_SAVED_REGSIZE));
3117 write_register (argreg, regval);
3124 /* Compute the the offset into the stack at which we
3125 will copy the next parameter.
3127 In N32 (N64?), the stack_offset only needs to be
3128 adjusted when it has been used. */
3131 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3135 fprintf_unfiltered (gdb_stdlog, "\n");
3138 /* Return adjusted stack pointer. */
3142 /* O32 version of push_arguments. */
3145 mips_o32_push_arguments (int nargs,
3146 struct value **args,
3149 CORE_ADDR struct_addr)
3155 int stack_offset = 0;
3157 /* First ensure that the stack and structure return address (if any)
3158 are properly aligned. The stack has to be at least 64-bit
3159 aligned even on 32-bit machines, because doubles must be 64-bit
3160 aligned. For n32 and n64, stack frames need to be 128-bit
3161 aligned, so we round to this widest known alignment. */
3163 sp = ROUND_DOWN (sp, 16);
3164 struct_addr = ROUND_DOWN (struct_addr, 16);
3166 /* Now make space on the stack for the args. */
3167 for (argnum = 0; argnum < nargs; argnum++)
3168 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3169 MIPS_STACK_ARGSIZE);
3170 sp -= ROUND_UP (len, 16);
3173 fprintf_unfiltered (gdb_stdlog,
3174 "mips_o32_push_arguments: sp=0x%s allocated %d\n",
3175 paddr_nz (sp), ROUND_UP (len, 16));
3177 /* Initialize the integer and float register pointers. */
3179 float_argreg = FPA0_REGNUM;
3181 /* The struct_return pointer occupies the first parameter-passing reg. */
3185 fprintf_unfiltered (gdb_stdlog,
3186 "mips_o32_push_arguments: struct_return reg=%d 0x%s\n",
3187 argreg, paddr_nz (struct_addr));
3188 write_register (argreg++, struct_addr);
3189 stack_offset += MIPS_STACK_ARGSIZE;
3192 /* Now load as many as possible of the first arguments into
3193 registers, and push the rest onto the stack. Loop thru args
3194 from first to last. */
3195 for (argnum = 0; argnum < nargs; argnum++)
3198 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3199 struct value *arg = args[argnum];
3200 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3201 int len = TYPE_LENGTH (arg_type);
3202 enum type_code typecode = TYPE_CODE (arg_type);
3205 fprintf_unfiltered (gdb_stdlog,
3206 "mips_o32_push_arguments: %d len=%d type=%d",
3207 argnum + 1, len, (int) typecode);
3209 val = (char *) VALUE_CONTENTS (arg);
3211 /* 32-bit ABIs always start floating point arguments in an
3212 even-numbered floating point register. Round the FP register
3213 up before the check to see if there are any FP registers
3214 left. O32/O64 targets also pass the FP in the integer
3215 registers so also round up normal registers. */
3216 if (!FP_REGISTER_DOUBLE
3217 && fp_register_arg_p (typecode, arg_type))
3219 if ((float_argreg & 1))
3223 /* Floating point arguments passed in registers have to be
3224 treated specially. On 32-bit architectures, doubles
3225 are passed in register pairs; the even register gets
3226 the low word, and the odd register gets the high word.
3227 On O32/O64, the first two floating point arguments are
3228 also copied to general registers, because MIPS16 functions
3229 don't use float registers for arguments. This duplication of
3230 arguments in general registers can't hurt non-MIPS16 functions
3231 because those registers are normally skipped. */
3233 if (fp_register_arg_p (typecode, arg_type)
3234 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3236 if (!FP_REGISTER_DOUBLE && len == 8)
3238 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3239 unsigned long regval;
3241 /* Write the low word of the double to the even register(s). */
3242 regval = extract_unsigned_integer (val + low_offset, 4);
3244 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3245 float_argreg, phex (regval, 4));
3246 write_register (float_argreg++, regval);
3248 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3249 argreg, phex (regval, 4));
3250 write_register (argreg++, regval);
3252 /* Write the high word of the double to the odd register(s). */
3253 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3255 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3256 float_argreg, phex (regval, 4));
3257 write_register (float_argreg++, regval);
3260 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3261 argreg, phex (regval, 4));
3262 write_register (argreg++, regval);
3266 /* This is a floating point value that fits entirely
3267 in a single register. */
3268 /* On 32 bit ABI's the float_argreg is further adjusted
3269 above to ensure that it is even register aligned. */
3270 LONGEST regval = extract_unsigned_integer (val, len);
3272 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3273 float_argreg, phex (regval, len));
3274 write_register (float_argreg++, regval);
3275 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3276 registers for each argument. The below is (my
3277 guess) to ensure that the corresponding integer
3278 register has reserved the same space. */
3280 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3281 argreg, phex (regval, len));
3282 write_register (argreg, regval);
3283 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3285 /* Reserve space for the FP register. */
3286 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3290 /* Copy the argument to general registers or the stack in
3291 register-sized pieces. Large arguments are split between
3292 registers and stack. */
3293 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3294 are treated specially: Irix cc passes them in registers
3295 where gcc sometimes puts them on the stack. For maximum
3296 compatibility, we will put them in both places. */
3297 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3298 (len % MIPS_SAVED_REGSIZE != 0));
3299 /* Structures should be aligned to eight bytes (even arg registers)
3300 on MIPS_ABI_O32, if their first member has double precision. */
3301 if (MIPS_SAVED_REGSIZE < 8
3302 && mips_type_needs_double_align (arg_type))
3307 /* Note: Floating-point values that didn't fit into an FP
3308 register are only written to memory. */
3311 /* Remember if the argument was written to the stack. */
3312 int stack_used_p = 0;
3314 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3317 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3320 /* Write this portion of the argument to the stack. */
3321 if (argreg > MIPS_LAST_ARG_REGNUM
3323 || fp_register_arg_p (typecode, arg_type))
3325 /* Should shorter than int integer values be
3326 promoted to int before being stored? */
3327 int longword_offset = 0;
3330 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3332 if (MIPS_STACK_ARGSIZE == 8 &&
3333 (typecode == TYPE_CODE_INT ||
3334 typecode == TYPE_CODE_PTR ||
3335 typecode == TYPE_CODE_FLT) && len <= 4)
3336 longword_offset = MIPS_STACK_ARGSIZE - len;
3341 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3342 paddr_nz (stack_offset));
3343 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3344 paddr_nz (longword_offset));
3347 addr = sp + stack_offset + longword_offset;
3352 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3354 for (i = 0; i < partial_len; i++)
3356 fprintf_unfiltered (gdb_stdlog, "%02x",
3360 write_memory (addr, val, partial_len);
3363 /* Note!!! This is NOT an else clause. Odd sized
3364 structs may go thru BOTH paths. Floating point
3365 arguments will not. */
3366 /* Write this portion of the argument to a general
3367 purpose register. */
3368 if (argreg <= MIPS_LAST_ARG_REGNUM
3369 && !fp_register_arg_p (typecode, arg_type))
3371 LONGEST regval = extract_signed_integer (val, partial_len);
3372 /* Value may need to be sign extended, because
3373 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3375 /* A non-floating-point argument being passed in a
3376 general register. If a struct or union, and if
3377 the remaining length is smaller than the register
3378 size, we have to adjust the register value on
3381 It does not seem to be necessary to do the
3382 same for integral types.
3384 Also don't do this adjustment on O64 binaries.
3386 cagney/2001-07-23: gdb/179: Also, GCC, when
3387 outputting LE O32 with sizeof (struct) <
3388 MIPS_SAVED_REGSIZE, generates a left shift as
3389 part of storing the argument in a register a
3390 register (the left shift isn't generated when
3391 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3392 is quite possible that this is GCC contradicting
3393 the LE/O32 ABI, GDB has not been adjusted to
3394 accommodate this. Either someone needs to
3395 demonstrate that the LE/O32 ABI specifies such a
3396 left shift OR this new ABI gets identified as
3397 such and GDB gets tweaked accordingly. */
3399 if (MIPS_SAVED_REGSIZE < 8
3400 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3401 && partial_len < MIPS_SAVED_REGSIZE
3402 && (typecode == TYPE_CODE_STRUCT ||
3403 typecode == TYPE_CODE_UNION))
3404 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3408 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3410 phex (regval, MIPS_SAVED_REGSIZE));
3411 write_register (argreg, regval);
3414 /* Prevent subsequent floating point arguments from
3415 being passed in floating point registers. */
3416 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3422 /* Compute the the offset into the stack at which we
3423 will copy the next parameter.
3425 In older ABIs, the caller reserved space for
3426 registers that contained arguments. This was loosely
3427 refered to as their "home". Consequently, space is
3428 always allocated. */
3430 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3434 fprintf_unfiltered (gdb_stdlog, "\n");
3437 /* Return adjusted stack pointer. */
3441 /* O64 version of push_arguments. */
3444 mips_o64_push_arguments (int nargs,
3445 struct value **args,
3448 CORE_ADDR struct_addr)
3454 int stack_offset = 0;
3456 /* First ensure that the stack and structure return address (if any)
3457 are properly aligned. The stack has to be at least 64-bit
3458 aligned even on 32-bit machines, because doubles must be 64-bit
3459 aligned. For n32 and n64, stack frames need to be 128-bit
3460 aligned, so we round to this widest known alignment. */
3462 sp = ROUND_DOWN (sp, 16);
3463 struct_addr = ROUND_DOWN (struct_addr, 16);
3465 /* Now make space on the stack for the args. */
3466 for (argnum = 0; argnum < nargs; argnum++)
3467 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3468 MIPS_STACK_ARGSIZE);
3469 sp -= ROUND_UP (len, 16);
3472 fprintf_unfiltered (gdb_stdlog,
3473 "mips_o64_push_arguments: sp=0x%s allocated %d\n",
3474 paddr_nz (sp), ROUND_UP (len, 16));
3476 /* Initialize the integer and float register pointers. */
3478 float_argreg = FPA0_REGNUM;
3480 /* The struct_return pointer occupies the first parameter-passing reg. */
3484 fprintf_unfiltered (gdb_stdlog,
3485 "mips_o64_push_arguments: struct_return reg=%d 0x%s\n",
3486 argreg, paddr_nz (struct_addr));
3487 write_register (argreg++, struct_addr);
3488 stack_offset += MIPS_STACK_ARGSIZE;
3491 /* Now load as many as possible of the first arguments into
3492 registers, and push the rest onto the stack. Loop thru args
3493 from first to last. */
3494 for (argnum = 0; argnum < nargs; argnum++)
3497 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3498 struct value *arg = args[argnum];
3499 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3500 int len = TYPE_LENGTH (arg_type);
3501 enum type_code typecode = TYPE_CODE (arg_type);
3504 fprintf_unfiltered (gdb_stdlog,
3505 "mips_o64_push_arguments: %d len=%d type=%d",
3506 argnum + 1, len, (int) typecode);
3508 val = (char *) VALUE_CONTENTS (arg);
3510 /* 32-bit ABIs always start floating point arguments in an
3511 even-numbered floating point register. Round the FP register
3512 up before the check to see if there are any FP registers
3513 left. O32/O64 targets also pass the FP in the integer
3514 registers so also round up normal registers. */
3515 if (!FP_REGISTER_DOUBLE
3516 && fp_register_arg_p (typecode, arg_type))
3518 if ((float_argreg & 1))
3522 /* Floating point arguments passed in registers have to be
3523 treated specially. On 32-bit architectures, doubles
3524 are passed in register pairs; the even register gets
3525 the low word, and the odd register gets the high word.
3526 On O32/O64, the first two floating point arguments are
3527 also copied to general registers, because MIPS16 functions
3528 don't use float registers for arguments. This duplication of
3529 arguments in general registers can't hurt non-MIPS16 functions
3530 because those registers are normally skipped. */
3532 if (fp_register_arg_p (typecode, arg_type)
3533 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3535 if (!FP_REGISTER_DOUBLE && len == 8)
3537 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3538 unsigned long regval;
3540 /* Write the low word of the double to the even register(s). */
3541 regval = extract_unsigned_integer (val + low_offset, 4);
3543 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3544 float_argreg, phex (regval, 4));
3545 write_register (float_argreg++, regval);
3547 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3548 argreg, phex (regval, 4));
3549 write_register (argreg++, regval);
3551 /* Write the high word of the double to the odd register(s). */
3552 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3554 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3555 float_argreg, phex (regval, 4));
3556 write_register (float_argreg++, regval);
3559 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3560 argreg, phex (regval, 4));
3561 write_register (argreg++, regval);
3565 /* This is a floating point value that fits entirely
3566 in a single register. */
3567 /* On 32 bit ABI's the float_argreg is further adjusted
3568 above to ensure that it is even register aligned. */
3569 LONGEST regval = extract_unsigned_integer (val, len);
3571 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3572 float_argreg, phex (regval, len));
3573 write_register (float_argreg++, regval);
3574 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3575 registers for each argument. The below is (my
3576 guess) to ensure that the corresponding integer
3577 register has reserved the same space. */
3579 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3580 argreg, phex (regval, len));
3581 write_register (argreg, regval);
3582 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3584 /* Reserve space for the FP register. */
3585 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3589 /* Copy the argument to general registers or the stack in
3590 register-sized pieces. Large arguments are split between
3591 registers and stack. */
3592 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3593 are treated specially: Irix cc passes them in registers
3594 where gcc sometimes puts them on the stack. For maximum
3595 compatibility, we will put them in both places. */
3596 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3597 (len % MIPS_SAVED_REGSIZE != 0));
3598 /* Structures should be aligned to eight bytes (even arg registers)
3599 on MIPS_ABI_O32, if their first member has double precision. */
3600 if (MIPS_SAVED_REGSIZE < 8
3601 && mips_type_needs_double_align (arg_type))
3606 /* Note: Floating-point values that didn't fit into an FP
3607 register are only written to memory. */
3610 /* Remember if the argument was written to the stack. */
3611 int stack_used_p = 0;
3613 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3616 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3619 /* Write this portion of the argument to the stack. */
3620 if (argreg > MIPS_LAST_ARG_REGNUM
3622 || fp_register_arg_p (typecode, arg_type))
3624 /* Should shorter than int integer values be
3625 promoted to int before being stored? */
3626 int longword_offset = 0;
3629 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3631 if (MIPS_STACK_ARGSIZE == 8 &&
3632 (typecode == TYPE_CODE_INT ||
3633 typecode == TYPE_CODE_PTR ||
3634 typecode == TYPE_CODE_FLT) && len <= 4)
3635 longword_offset = MIPS_STACK_ARGSIZE - len;
3640 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3641 paddr_nz (stack_offset));
3642 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3643 paddr_nz (longword_offset));
3646 addr = sp + stack_offset + longword_offset;
3651 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3653 for (i = 0; i < partial_len; i++)
3655 fprintf_unfiltered (gdb_stdlog, "%02x",
3659 write_memory (addr, val, partial_len);
3662 /* Note!!! This is NOT an else clause. Odd sized
3663 structs may go thru BOTH paths. Floating point
3664 arguments will not. */
3665 /* Write this portion of the argument to a general
3666 purpose register. */
3667 if (argreg <= MIPS_LAST_ARG_REGNUM
3668 && !fp_register_arg_p (typecode, arg_type))
3670 LONGEST regval = extract_signed_integer (val, partial_len);
3671 /* Value may need to be sign extended, because
3672 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3674 /* A non-floating-point argument being passed in a
3675 general register. If a struct or union, and if
3676 the remaining length is smaller than the register
3677 size, we have to adjust the register value on
3680 It does not seem to be necessary to do the
3681 same for integral types.
3683 Also don't do this adjustment on O64 binaries.
3685 cagney/2001-07-23: gdb/179: Also, GCC, when
3686 outputting LE O32 with sizeof (struct) <
3687 MIPS_SAVED_REGSIZE, generates a left shift as
3688 part of storing the argument in a register a
3689 register (the left shift isn't generated when
3690 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3691 is quite possible that this is GCC contradicting
3692 the LE/O32 ABI, GDB has not been adjusted to
3693 accommodate this. Either someone needs to
3694 demonstrate that the LE/O32 ABI specifies such a
3695 left shift OR this new ABI gets identified as
3696 such and GDB gets tweaked accordingly. */
3698 if (MIPS_SAVED_REGSIZE < 8
3699 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3700 && partial_len < MIPS_SAVED_REGSIZE
3701 && (typecode == TYPE_CODE_STRUCT ||
3702 typecode == TYPE_CODE_UNION))
3703 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3707 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3709 phex (regval, MIPS_SAVED_REGSIZE));
3710 write_register (argreg, regval);
3713 /* Prevent subsequent floating point arguments from
3714 being passed in floating point registers. */
3715 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3721 /* Compute the the offset into the stack at which we
3722 will copy the next parameter.
3724 In older ABIs, the caller reserved space for
3725 registers that contained arguments. This was loosely
3726 refered to as their "home". Consequently, space is
3727 always allocated. */
3729 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3733 fprintf_unfiltered (gdb_stdlog, "\n");
3736 /* Return adjusted stack pointer. */
3741 mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
3743 /* Set the return address register to point to the entry
3744 point of the program, where a breakpoint lies in wait. */
3745 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
3750 mips_pop_frame (void)
3752 register int regnum;
3753 struct frame_info *frame = get_current_frame ();
3754 CORE_ADDR new_sp = get_frame_base (frame);
3755 mips_extra_func_info_t proc_desc;
3757 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3759 generic_pop_dummy_frame ();
3760 flush_cached_frames ();
3764 proc_desc = get_frame_extra_info (frame)->proc_desc;
3765 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3766 if (get_frame_saved_regs (frame) == NULL)
3767 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3768 for (regnum = 0; regnum < NUM_REGS; regnum++)
3769 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3770 && get_frame_saved_regs (frame)[regnum])
3772 /* Floating point registers must not be sign extended,
3773 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3775 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3776 write_register (regnum,
3777 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3778 MIPS_SAVED_REGSIZE));
3780 write_register (regnum,
3781 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3782 MIPS_SAVED_REGSIZE));
3785 write_register (SP_REGNUM, new_sp);
3786 flush_cached_frames ();
3788 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3790 struct linked_proc_info *pi_ptr, *prev_ptr;
3792 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3794 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3796 if (&pi_ptr->info == proc_desc)
3801 error ("Can't locate dummy extra frame info\n");
3803 if (prev_ptr != NULL)
3804 prev_ptr->next = pi_ptr->next;
3806 linked_proc_desc_table = pi_ptr->next;
3810 write_register (HI_REGNUM,
3811 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3812 MIPS_SAVED_REGSIZE));
3813 write_register (LO_REGNUM,
3814 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3815 MIPS_SAVED_REGSIZE));
3816 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3817 write_register (FCRCS_REGNUM,
3818 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3819 MIPS_SAVED_REGSIZE));
3824 mips_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
3825 struct value **args, struct type *type, int gcc_p)
3827 write_register(T9_REGNUM, fun);
3830 /* Floating point register management.
3832 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3833 64bit operations, these early MIPS cpus treat fp register pairs
3834 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3835 registers and offer a compatibility mode that emulates the MIPS2 fp
3836 model. When operating in MIPS2 fp compat mode, later cpu's split
3837 double precision floats into two 32-bit chunks and store them in
3838 consecutive fp regs. To display 64-bit floats stored in this
3839 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3840 Throw in user-configurable endianness and you have a real mess.
3842 The way this works is:
3843 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3844 double-precision value will be split across two logical registers.
3845 The lower-numbered logical register will hold the low-order bits,
3846 regardless of the processor's endianness.
3847 - If we are on a 64-bit processor, and we are looking for a
3848 single-precision value, it will be in the low ordered bits
3849 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3850 save slot in memory.
3851 - If we are in 64-bit mode, everything is straightforward.
3853 Note that this code only deals with "live" registers at the top of the
3854 stack. We will attempt to deal with saved registers later, when
3855 the raw/cooked register interface is in place. (We need a general
3856 interface that can deal with dynamic saved register sizes -- fp
3857 regs could be 32 bits wide in one frame and 64 on the frame above
3860 static struct type *
3861 mips_float_register_type (void)
3863 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3864 return builtin_type_ieee_single_big;
3866 return builtin_type_ieee_single_little;
3869 static struct type *
3870 mips_double_register_type (void)
3872 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3873 return builtin_type_ieee_double_big;
3875 return builtin_type_ieee_double_little;
3878 /* Copy a 32-bit single-precision value from the current frame
3879 into rare_buffer. */
3882 mips_read_fp_register_single (int regno, char *rare_buffer)
3884 int raw_size = REGISTER_RAW_SIZE (regno);
3885 char *raw_buffer = alloca (raw_size);
3887 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3888 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3891 /* We have a 64-bit value for this register. Find the low-order
3895 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3900 memcpy (rare_buffer, raw_buffer + offset, 4);
3904 memcpy (rare_buffer, raw_buffer, 4);
3908 /* Copy a 64-bit double-precision value from the current frame into
3909 rare_buffer. This may include getting half of it from the next
3913 mips_read_fp_register_double (int regno, char *rare_buffer)
3915 int raw_size = REGISTER_RAW_SIZE (regno);
3917 if (raw_size == 8 && !mips2_fp_compat ())
3919 /* We have a 64-bit value for this register, and we should use
3921 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
3922 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3926 if ((regno - FP0_REGNUM) & 1)
3927 internal_error (__FILE__, __LINE__,
3928 "mips_read_fp_register_double: bad access to "
3929 "odd-numbered FP register");
3931 /* mips_read_fp_register_single will find the correct 32 bits from
3933 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3935 mips_read_fp_register_single (regno, rare_buffer + 4);
3936 mips_read_fp_register_single (regno + 1, rare_buffer);
3940 mips_read_fp_register_single (regno, rare_buffer);
3941 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
3947 mips_print_fp_register (int regnum)
3948 { /* do values for FP (float) regs */
3950 double doub, flt1, flt2; /* doubles extracted from raw hex data */
3951 int inv1, inv2, namelen;
3953 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
3955 printf_filtered ("%s:", REGISTER_NAME (regnum));
3956 printf_filtered ("%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), "");
3958 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
3960 /* 4-byte registers: Print hex and floating. Also print even
3961 numbered registers as doubles. */
3962 mips_read_fp_register_single (regnum, raw_buffer);
3963 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
3965 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
3968 printf_filtered (" flt: ");
3970 printf_filtered (" <invalid float> ");
3972 printf_filtered ("%-17.9g", flt1);
3974 if (regnum % 2 == 0)
3976 mips_read_fp_register_double (regnum, raw_buffer);
3977 doub = unpack_double (mips_double_register_type (), raw_buffer,
3980 printf_filtered (" dbl: ");
3982 printf_filtered ("<invalid double>");
3984 printf_filtered ("%-24.17g", doub);
3989 /* Eight byte registers: print each one as hex, float and double. */
3990 mips_read_fp_register_single (regnum, raw_buffer);
3991 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
3993 mips_read_fp_register_double (regnum, raw_buffer);
3994 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
3997 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4000 printf_filtered (" flt: ");
4002 printf_filtered ("<invalid float>");
4004 printf_filtered ("%-17.9g", flt1);
4006 printf_filtered (" dbl: ");
4008 printf_filtered ("<invalid double>");
4010 printf_filtered ("%-24.17g", doub);
4015 mips_print_register (int regnum, int all)
4017 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4020 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4022 mips_print_fp_register (regnum);
4026 /* Get the data in raw format. */
4027 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4029 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4033 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4035 /* The problem with printing numeric register names (r26, etc.) is that
4036 the user can't use them on input. Probably the best solution is to
4037 fix it so that either the numeric or the funky (a2, etc.) names
4038 are accepted on input. */
4039 if (regnum < MIPS_NUMREGS)
4040 printf_filtered ("(r%d): ", regnum);
4042 printf_filtered (": ");
4044 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4045 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4049 print_scalar_formatted (raw_buffer + offset,
4050 REGISTER_VIRTUAL_TYPE (regnum),
4051 'x', 0, gdb_stdout);
4054 /* Replacement for generic do_registers_info.
4055 Print regs in pretty columns. */
4058 do_fp_register_row (int regnum)
4060 printf_filtered (" ");
4061 mips_print_fp_register (regnum);
4062 printf_filtered ("\n");
4067 /* Print a row's worth of GP (int) registers, with name labels above */
4070 do_gp_register_row (int regnum)
4072 /* do values for GP (int) regs */
4073 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4074 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4076 int start_regnum = regnum;
4077 int numregs = NUM_REGS;
4080 /* For GP registers, we print a separate row of names above the vals */
4081 printf_filtered (" ");
4082 for (col = 0; col < ncols && regnum < numregs; regnum++)
4084 if (*REGISTER_NAME (regnum) == '\0')
4085 continue; /* unused register */
4086 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4087 break; /* end the row: reached FP register */
4088 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4089 REGISTER_NAME (regnum));
4092 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4093 start_regnum); /* print the R0 to R31 names */
4095 regnum = start_regnum; /* go back to start of row */
4096 /* now print the values in hex, 4 or 8 to the row */
4097 for (col = 0; col < ncols && regnum < numregs; regnum++)
4099 if (*REGISTER_NAME (regnum) == '\0')
4100 continue; /* unused register */
4101 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4102 break; /* end row: reached FP register */
4103 /* OK: get the data in raw format. */
4104 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4105 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4106 /* pad small registers */
4107 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4108 printf_filtered (" ");
4109 /* Now print the register value in hex, endian order. */
4110 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4111 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4112 byte < REGISTER_RAW_SIZE (regnum);
4114 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4116 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4119 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4120 printf_filtered (" ");
4123 if (col > 0) /* ie. if we actually printed anything... */
4124 printf_filtered ("\n");
4129 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4132 mips_do_registers_info (int regnum, int fpregs)
4134 if (regnum != -1) /* do one specified register */
4136 if (*(REGISTER_NAME (regnum)) == '\0')
4137 error ("Not a valid register for the current processor type");
4139 mips_print_register (regnum, 0);
4140 printf_filtered ("\n");
4143 /* do all (or most) registers */
4146 while (regnum < NUM_REGS)
4148 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4149 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4150 regnum = do_fp_register_row (regnum); /* FP regs */
4152 regnum += MIPS_NUMREGS; /* skip floating point regs */
4154 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4159 /* Is this a branch with a delay slot? */
4161 static int is_delayed (unsigned long);
4164 is_delayed (unsigned long insn)
4167 for (i = 0; i < NUMOPCODES; ++i)
4168 if (mips_opcodes[i].pinfo != INSN_MACRO
4169 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4171 return (i < NUMOPCODES
4172 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4173 | INSN_COND_BRANCH_DELAY
4174 | INSN_COND_BRANCH_LIKELY)));
4178 mips_step_skips_delay (CORE_ADDR pc)
4180 char buf[MIPS_INSTLEN];
4182 /* There is no branch delay slot on MIPS16. */
4183 if (pc_is_mips16 (pc))
4186 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4187 /* If error reading memory, guess that it is not a delayed branch. */
4189 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4193 /* Skip the PC past function prologue instructions (32-bit version).
4194 This is a helper function for mips_skip_prologue. */
4197 mips32_skip_prologue (CORE_ADDR pc)
4201 int seen_sp_adjust = 0;
4202 int load_immediate_bytes = 0;
4204 /* Skip the typical prologue instructions. These are the stack adjustment
4205 instruction and the instructions that save registers on the stack
4206 or in the gcc frame. */
4207 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4209 unsigned long high_word;
4211 inst = mips_fetch_instruction (pc);
4212 high_word = (inst >> 16) & 0xffff;
4214 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4215 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4217 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4218 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4220 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4221 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4222 && (inst & 0x001F0000)) /* reg != $zero */
4225 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4227 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4229 continue; /* reg != $zero */
4231 /* move $s8,$sp. With different versions of gas this will be either
4232 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4233 Accept any one of these. */
4234 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4237 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4239 else if (high_word == 0x3c1c) /* lui $gp,n */
4241 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4243 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4244 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4246 /* The following instructions load $at or $t0 with an immediate
4247 value in preparation for a stack adjustment via
4248 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4249 a local variable, so we accept them only before a stack adjustment
4250 instruction was seen. */
4251 else if (!seen_sp_adjust)
4253 if (high_word == 0x3c01 || /* lui $at,n */
4254 high_word == 0x3c08) /* lui $t0,n */
4256 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4259 else if (high_word == 0x3421 || /* ori $at,$at,n */
4260 high_word == 0x3508 || /* ori $t0,$t0,n */
4261 high_word == 0x3401 || /* ori $at,$zero,n */
4262 high_word == 0x3408) /* ori $t0,$zero,n */
4264 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4274 /* In a frameless function, we might have incorrectly
4275 skipped some load immediate instructions. Undo the skipping
4276 if the load immediate was not followed by a stack adjustment. */
4277 if (load_immediate_bytes && !seen_sp_adjust)
4278 pc -= load_immediate_bytes;
4282 /* Skip the PC past function prologue instructions (16-bit version).
4283 This is a helper function for mips_skip_prologue. */
4286 mips16_skip_prologue (CORE_ADDR pc)
4289 int extend_bytes = 0;
4290 int prev_extend_bytes;
4292 /* Table of instructions likely to be found in a function prologue. */
4295 unsigned short inst;
4296 unsigned short mask;
4303 , /* addiu $sp,offset */
4307 , /* daddiu $sp,offset */
4311 , /* sw reg,n($sp) */
4315 , /* sd reg,n($sp) */
4319 , /* sw $ra,n($sp) */
4323 , /* sd $ra,n($sp) */
4331 , /* sw $a0-$a3,n($s1) */
4335 , /* move reg,$a0-$a3 */
4339 , /* entry pseudo-op */
4343 , /* addiu $s1,$sp,n */
4346 } /* end of table marker */
4349 /* Skip the typical prologue instructions. These are the stack adjustment
4350 instruction and the instructions that save registers on the stack
4351 or in the gcc frame. */
4352 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4354 unsigned short inst;
4357 inst = mips_fetch_instruction (pc);
4359 /* Normally we ignore an extend instruction. However, if it is
4360 not followed by a valid prologue instruction, we must adjust
4361 the pc back over the extend so that it won't be considered
4362 part of the prologue. */
4363 if ((inst & 0xf800) == 0xf000) /* extend */
4365 extend_bytes = MIPS16_INSTLEN;
4368 prev_extend_bytes = extend_bytes;
4371 /* Check for other valid prologue instructions besides extend. */
4372 for (i = 0; table[i].mask != 0; i++)
4373 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4375 if (table[i].mask != 0) /* it was in table? */
4376 continue; /* ignore it */
4380 /* Return the current pc, adjusted backwards by 2 if
4381 the previous instruction was an extend. */
4382 return pc - prev_extend_bytes;
4388 /* To skip prologues, I use this predicate. Returns either PC itself
4389 if the code at PC does not look like a function prologue; otherwise
4390 returns an address that (if we're lucky) follows the prologue. If
4391 LENIENT, then we must skip everything which is involved in setting
4392 up the frame (it's OK to skip more, just so long as we don't skip
4393 anything which might clobber the registers which are being saved.
4394 We must skip more in the case where part of the prologue is in the
4395 delay slot of a non-prologue instruction). */
4398 mips_skip_prologue (CORE_ADDR pc)
4400 /* See if we can determine the end of the prologue via the symbol table.
4401 If so, then return either PC, or the PC after the prologue, whichever
4404 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4406 if (post_prologue_pc != 0)
4407 return max (pc, post_prologue_pc);
4409 /* Can't determine prologue from the symbol table, need to examine
4412 if (pc_is_mips16 (pc))
4413 return mips16_skip_prologue (pc);
4415 return mips32_skip_prologue (pc);
4418 /* Determine how a return value is stored within the MIPS register
4419 file, given the return type `valtype'. */
4421 struct return_value_word
4430 return_value_location (struct type *valtype,
4431 struct return_value_word *hi,
4432 struct return_value_word *lo)
4434 int len = TYPE_LENGTH (valtype);
4436 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4437 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4438 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4440 if (!FP_REGISTER_DOUBLE && len == 8)
4442 /* We need to break a 64bit float in two 32 bit halves and
4443 spread them across a floating-point register pair. */
4444 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4445 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4446 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4447 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4449 hi->reg_offset = lo->reg_offset;
4450 lo->reg = FP0_REGNUM + 0;
4451 hi->reg = FP0_REGNUM + 1;
4457 /* The floating point value fits in a single floating-point
4459 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4460 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4463 lo->reg = FP0_REGNUM;
4474 /* Locate a result possibly spread across two registers. */
4476 lo->reg = regnum + 0;
4477 hi->reg = regnum + 1;
4478 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4479 && len < MIPS_SAVED_REGSIZE)
4481 /* "un-left-justify" the value in the low register */
4482 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4487 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4488 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4489 && len < MIPS_SAVED_REGSIZE * 2
4490 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4491 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4493 /* "un-left-justify" the value spread across two registers. */
4494 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4495 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4497 hi->len = len - lo->len;
4501 /* Only perform a partial copy of the second register. */
4504 if (len > MIPS_SAVED_REGSIZE)
4506 lo->len = MIPS_SAVED_REGSIZE;
4507 hi->len = len - MIPS_SAVED_REGSIZE;
4515 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4516 && REGISTER_RAW_SIZE (regnum) == 8
4517 && MIPS_SAVED_REGSIZE == 4)
4519 /* Account for the fact that only the least-signficant part
4520 of the register is being used */
4521 lo->reg_offset += 4;
4522 hi->reg_offset += 4;
4525 hi->buf_offset = lo->len;
4529 /* Given a return value in `regbuf' with a type `valtype', extract and
4530 copy its value into `valbuf'. */
4533 mips_eabi_extract_return_value (struct type *valtype,
4534 char regbuf[REGISTER_BYTES],
4537 struct return_value_word lo;
4538 struct return_value_word hi;
4539 return_value_location (valtype, &hi, &lo);
4541 memcpy (valbuf + lo.buf_offset,
4542 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4546 memcpy (valbuf + hi.buf_offset,
4547 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4552 mips_o64_extract_return_value (struct type *valtype,
4553 char regbuf[REGISTER_BYTES],
4556 struct return_value_word lo;
4557 struct return_value_word hi;
4558 return_value_location (valtype, &hi, &lo);
4560 memcpy (valbuf + lo.buf_offset,
4561 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4565 memcpy (valbuf + hi.buf_offset,
4566 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4570 /* Given a return value in `valbuf' with a type `valtype', write it's
4571 value into the appropriate register. */
4574 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4576 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4577 struct return_value_word lo;
4578 struct return_value_word hi;
4579 return_value_location (valtype, &hi, &lo);
4581 memset (raw_buffer, 0, sizeof (raw_buffer));
4582 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4583 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4584 REGISTER_RAW_SIZE (lo.reg));
4588 memset (raw_buffer, 0, sizeof (raw_buffer));
4589 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4590 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4591 REGISTER_RAW_SIZE (hi.reg));
4596 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4598 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4599 struct return_value_word lo;
4600 struct return_value_word hi;
4601 return_value_location (valtype, &hi, &lo);
4603 memset (raw_buffer, 0, sizeof (raw_buffer));
4604 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4605 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4606 REGISTER_RAW_SIZE (lo.reg));
4610 memset (raw_buffer, 0, sizeof (raw_buffer));
4611 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4612 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4613 REGISTER_RAW_SIZE (hi.reg));
4617 /* O32 ABI stuff. */
4620 mips_o32_xfer_return_value (struct type *type,
4621 struct regcache *regcache,
4622 bfd_byte *in, const bfd_byte *out)
4624 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4625 if (TYPE_CODE (type) == TYPE_CODE_FLT
4626 && TYPE_LENGTH (type) == 4
4627 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4629 /* A single-precision floating-point value. It fits in the
4630 least significant part of FP0. */
4632 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4633 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4634 TARGET_BYTE_ORDER, in, out, 0);
4636 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4637 && TYPE_LENGTH (type) == 8
4638 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4640 /* A double-precision floating-point value. It fits in the
4641 least significant part of FP0/FP1 but with byte ordering
4642 based on the target (???). */
4644 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4645 switch (TARGET_BYTE_ORDER)
4647 case BFD_ENDIAN_LITTLE:
4648 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4649 TARGET_BYTE_ORDER, in, out, 0);
4650 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4651 TARGET_BYTE_ORDER, in, out, 4);
4653 case BFD_ENDIAN_BIG:
4654 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4655 TARGET_BYTE_ORDER, in, out, 0);
4656 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4657 TARGET_BYTE_ORDER, in, out, 4);
4660 internal_error (__FILE__, __LINE__, "bad switch");
4664 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4665 && TYPE_NFIELDS (type) <= 2
4666 && TYPE_NFIELDS (type) >= 1
4667 && ((TYPE_NFIELDS (type) == 1
4668 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4670 || (TYPE_NFIELDS (type) == 2
4671 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4673 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4675 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4677 /* A struct that contains one or two floats. Each value is part
4678 in the least significant part of their floating point
4680 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4683 for (field = 0, regnum = FP0_REGNUM;
4684 field < TYPE_NFIELDS (type);
4685 field++, regnum += 2)
4687 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4690 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4691 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4692 TARGET_BYTE_ORDER, in, out, offset);
4697 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4698 || TYPE_CODE (type) == TYPE_CODE_UNION)
4700 /* A structure or union. Extract the left justified value,
4701 regardless of the byte order. I.e. DO NOT USE
4705 for (offset = 0, regnum = V0_REGNUM;
4706 offset < TYPE_LENGTH (type);
4707 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4709 int xfer = REGISTER_RAW_SIZE (regnum);
4710 if (offset + xfer > TYPE_LENGTH (type))
4711 xfer = TYPE_LENGTH (type) - offset;
4713 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4714 offset, xfer, regnum);
4715 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4722 /* A scalar extract each part but least-significant-byte
4723 justified. o32 thinks registers are 4 byte, regardless of
4724 the ISA. mips_stack_argsize controls this. */
4727 for (offset = 0, regnum = V0_REGNUM;
4728 offset < TYPE_LENGTH (type);
4729 offset += mips_stack_argsize (), regnum++)
4731 int xfer = mips_stack_argsize ();
4733 if (offset + xfer > TYPE_LENGTH (type))
4734 xfer = TYPE_LENGTH (type) - offset;
4736 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4737 offset, xfer, regnum);
4738 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4745 mips_o32_extract_return_value (struct type *type,
4746 struct regcache *regcache,
4749 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4753 mips_o32_store_return_value (struct type *type, char *valbuf)
4755 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4758 /* N32/N44 ABI stuff. */
4761 mips_n32n64_xfer_return_value (struct type *type,
4762 struct regcache *regcache,
4763 bfd_byte *in, const bfd_byte *out)
4765 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4766 if (TYPE_CODE (type) == TYPE_CODE_FLT
4767 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4769 /* A floating-point value belongs in the least significant part
4772 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4773 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4774 TARGET_BYTE_ORDER, in, out, 0);
4776 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4777 && TYPE_NFIELDS (type) <= 2
4778 && TYPE_NFIELDS (type) >= 1
4779 && ((TYPE_NFIELDS (type) == 1
4780 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4782 || (TYPE_NFIELDS (type) == 2
4783 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4785 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4787 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4789 /* A struct that contains one or two floats. Each value is part
4790 in the least significant part of their floating point
4792 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4795 for (field = 0, regnum = FP0_REGNUM;
4796 field < TYPE_NFIELDS (type);
4797 field++, regnum += 2)
4799 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4802 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4803 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4804 TARGET_BYTE_ORDER, in, out, offset);
4807 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4808 || TYPE_CODE (type) == TYPE_CODE_UNION)
4810 /* A structure or union. Extract the left justified value,
4811 regardless of the byte order. I.e. DO NOT USE
4815 for (offset = 0, regnum = V0_REGNUM;
4816 offset < TYPE_LENGTH (type);
4817 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4819 int xfer = REGISTER_RAW_SIZE (regnum);
4820 if (offset + xfer > TYPE_LENGTH (type))
4821 xfer = TYPE_LENGTH (type) - offset;
4823 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4824 offset, xfer, regnum);
4825 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4831 /* A scalar extract each part but least-significant-byte
4835 for (offset = 0, regnum = V0_REGNUM;
4836 offset < TYPE_LENGTH (type);
4837 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4839 int xfer = REGISTER_RAW_SIZE (regnum);
4841 if (offset + xfer > TYPE_LENGTH (type))
4842 xfer = TYPE_LENGTH (type) - offset;
4844 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4845 offset, xfer, regnum);
4846 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4853 mips_n32n64_extract_return_value (struct type *type,
4854 struct regcache *regcache,
4857 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4861 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4863 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4867 mips_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
4869 /* Nothing to do -- push_arguments does all the work. */
4873 mips_extract_struct_value_address (struct regcache *regcache)
4875 /* FIXME: This will only work at random. The caller passes the
4876 struct_return address in V0, but it is not preserved. It may
4877 still be there, or this may be a random value. */
4880 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4884 /* Exported procedure: Is PC in the signal trampoline code */
4887 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4889 if (sigtramp_address == 0)
4891 return (pc >= sigtramp_address && pc < sigtramp_end);
4894 /* Root of all "set mips "/"show mips " commands. This will eventually be
4895 used for all MIPS-specific commands. */
4898 show_mips_command (char *args, int from_tty)
4900 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4904 set_mips_command (char *args, int from_tty)
4906 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4907 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4910 /* Commands to show/set the MIPS FPU type. */
4913 show_mipsfpu_command (char *args, int from_tty)
4916 switch (MIPS_FPU_TYPE)
4918 case MIPS_FPU_SINGLE:
4919 fpu = "single-precision";
4921 case MIPS_FPU_DOUBLE:
4922 fpu = "double-precision";
4925 fpu = "absent (none)";
4928 internal_error (__FILE__, __LINE__, "bad switch");
4930 if (mips_fpu_type_auto)
4931 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4934 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
4940 set_mipsfpu_command (char *args, int from_tty)
4942 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
4943 show_mipsfpu_command (args, from_tty);
4947 set_mipsfpu_single_command (char *args, int from_tty)
4949 mips_fpu_type = MIPS_FPU_SINGLE;
4950 mips_fpu_type_auto = 0;
4951 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
4955 set_mipsfpu_double_command (char *args, int from_tty)
4957 mips_fpu_type = MIPS_FPU_DOUBLE;
4958 mips_fpu_type_auto = 0;
4959 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
4963 set_mipsfpu_none_command (char *args, int from_tty)
4965 mips_fpu_type = MIPS_FPU_NONE;
4966 mips_fpu_type_auto = 0;
4967 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
4971 set_mipsfpu_auto_command (char *args, int from_tty)
4973 mips_fpu_type_auto = 1;
4976 /* Command to set the processor type. */
4979 mips_set_processor_type_command (char *args, int from_tty)
4983 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
4985 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
4986 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
4987 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
4989 /* Restore the value. */
4990 tmp_mips_processor_type = xstrdup (mips_processor_type);
4995 if (!mips_set_processor_type (tmp_mips_processor_type))
4997 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
4998 /* Restore its value. */
4999 tmp_mips_processor_type = xstrdup (mips_processor_type);
5004 mips_show_processor_type_command (char *args, int from_tty)
5008 /* Modify the actual processor type. */
5011 mips_set_processor_type (char *str)
5018 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5020 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5022 mips_processor_type = str;
5023 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5025 /* FIXME tweak fpu flag too */
5032 /* Attempt to identify the particular processor model by reading the
5036 mips_read_processor_type (void)
5040 prid = read_register (PRID_REGNUM);
5042 if ((prid & ~0xf) == 0x700)
5043 return savestring ("r3041", strlen ("r3041"));
5048 /* Just like reinit_frame_cache, but with the right arguments to be
5049 callable as an sfunc. */
5052 reinit_frame_cache_sfunc (char *args, int from_tty,
5053 struct cmd_list_element *c)
5055 reinit_frame_cache ();
5059 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5061 mips_extra_func_info_t proc_desc;
5063 /* Search for the function containing this address. Set the low bit
5064 of the address when searching, in case we were given an even address
5065 that is the start of a 16-bit function. If we didn't do this,
5066 the search would fail because the symbol table says the function
5067 starts at an odd address, i.e. 1 byte past the given address. */
5068 memaddr = ADDR_BITS_REMOVE (memaddr);
5069 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5071 /* Make an attempt to determine if this is a 16-bit function. If
5072 the procedure descriptor exists and the address therein is odd,
5073 it's definitely a 16-bit function. Otherwise, we have to just
5074 guess that if the address passed in is odd, it's 16-bits. */
5076 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5077 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5079 info->mach = pc_is_mips16 (memaddr) ?
5080 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5082 /* Round down the instruction address to the appropriate boundary. */
5083 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5085 /* Call the appropriate disassembler based on the target endian-ness. */
5086 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5087 return print_insn_big_mips (memaddr, info);
5089 return print_insn_little_mips (memaddr, info);
5092 /* Old-style breakpoint macros.
5093 The IDT board uses an unusual breakpoint value, and sometimes gets
5094 confused when it sees the usual MIPS breakpoint instruction. */
5096 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
5097 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
5098 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
5099 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
5100 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
5101 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
5102 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
5103 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
5105 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5106 counter value to determine whether a 16- or 32-bit breakpoint should be
5107 used. It returns a pointer to a string of bytes that encode a breakpoint
5108 instruction, stores the length of the string to *lenptr, and adjusts pc
5109 (if necessary) to point to the actual memory location where the
5110 breakpoint should be inserted. */
5112 static const unsigned char *
5113 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5115 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5117 if (pc_is_mips16 (*pcptr))
5119 static unsigned char mips16_big_breakpoint[] =
5120 MIPS16_BIG_BREAKPOINT;
5121 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5122 *lenptr = sizeof (mips16_big_breakpoint);
5123 return mips16_big_breakpoint;
5127 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
5128 static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
5129 static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
5131 *lenptr = sizeof (big_breakpoint);
5133 if (strcmp (target_shortname, "mips") == 0)
5134 return idt_big_breakpoint;
5135 else if (strcmp (target_shortname, "ddb") == 0
5136 || strcmp (target_shortname, "pmon") == 0
5137 || strcmp (target_shortname, "lsi") == 0)
5138 return pmon_big_breakpoint;
5140 return big_breakpoint;
5145 if (pc_is_mips16 (*pcptr))
5147 static unsigned char mips16_little_breakpoint[] =
5148 MIPS16_LITTLE_BREAKPOINT;
5149 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5150 *lenptr = sizeof (mips16_little_breakpoint);
5151 return mips16_little_breakpoint;
5155 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
5156 static unsigned char pmon_little_breakpoint[] =
5157 PMON_LITTLE_BREAKPOINT;
5158 static unsigned char idt_little_breakpoint[] =
5159 IDT_LITTLE_BREAKPOINT;
5161 *lenptr = sizeof (little_breakpoint);
5163 if (strcmp (target_shortname, "mips") == 0)
5164 return idt_little_breakpoint;
5165 else if (strcmp (target_shortname, "ddb") == 0
5166 || strcmp (target_shortname, "pmon") == 0
5167 || strcmp (target_shortname, "lsi") == 0)
5168 return pmon_little_breakpoint;
5170 return little_breakpoint;
5175 /* If PC is in a mips16 call or return stub, return the address of the target
5176 PC, which is either the callee or the caller. There are several
5177 cases which must be handled:
5179 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5180 target PC is in $31 ($ra).
5181 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5182 and the target PC is in $2.
5183 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5184 before the jal instruction, this is effectively a call stub
5185 and the the target PC is in $2. Otherwise this is effectively
5186 a return stub and the target PC is in $18.
5188 See the source code for the stubs in gcc/config/mips/mips16.S for
5191 This function implements the SKIP_TRAMPOLINE_CODE macro.
5195 mips_skip_stub (CORE_ADDR pc)
5198 CORE_ADDR start_addr;
5200 /* Find the starting address and name of the function containing the PC. */
5201 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5204 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5205 target PC is in $31 ($ra). */
5206 if (strcmp (name, "__mips16_ret_sf") == 0
5207 || strcmp (name, "__mips16_ret_df") == 0)
5208 return read_signed_register (RA_REGNUM);
5210 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5212 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5213 and the target PC is in $2. */
5214 if (name[19] >= '0' && name[19] <= '9')
5215 return read_signed_register (2);
5217 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5218 before the jal instruction, this is effectively a call stub
5219 and the the target PC is in $2. Otherwise this is effectively
5220 a return stub and the target PC is in $18. */
5221 else if (name[19] == 's' || name[19] == 'd')
5223 if (pc == start_addr)
5225 /* Check if the target of the stub is a compiler-generated
5226 stub. Such a stub for a function bar might have a name
5227 like __fn_stub_bar, and might look like this:
5232 la $1,bar (becomes a lui/addiu pair)
5234 So scan down to the lui/addi and extract the target
5235 address from those two instructions. */
5237 CORE_ADDR target_pc = read_signed_register (2);
5241 /* See if the name of the target function is __fn_stub_*. */
5242 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5244 if (strncmp (name, "__fn_stub_", 10) != 0
5245 && strcmp (name, "etext") != 0
5246 && strcmp (name, "_etext") != 0)
5249 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5250 The limit on the search is arbitrarily set to 20
5251 instructions. FIXME. */
5252 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5254 inst = mips_fetch_instruction (target_pc);
5255 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5256 pc = (inst << 16) & 0xffff0000; /* high word */
5257 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5258 return pc | (inst & 0xffff); /* low word */
5261 /* Couldn't find the lui/addui pair, so return stub address. */
5265 /* This is the 'return' part of a call stub. The return
5266 address is in $r18. */
5267 return read_signed_register (18);
5270 return 0; /* not a stub */
5274 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5275 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5278 mips_in_call_stub (CORE_ADDR pc, char *name)
5280 CORE_ADDR start_addr;
5282 /* Find the starting address of the function containing the PC. If the
5283 caller didn't give us a name, look it up at the same time. */
5284 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5287 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5289 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5290 if (name[19] >= '0' && name[19] <= '9')
5292 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5293 before the jal instruction, this is effectively a call stub. */
5294 else if (name[19] == 's' || name[19] == 'd')
5295 return pc == start_addr;
5298 return 0; /* not a stub */
5302 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5303 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5306 mips_in_return_stub (CORE_ADDR pc, char *name)
5308 CORE_ADDR start_addr;
5310 /* Find the starting address of the function containing the PC. */
5311 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5314 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5315 if (strcmp (name, "__mips16_ret_sf") == 0
5316 || strcmp (name, "__mips16_ret_df") == 0)
5319 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5320 i.e. after the jal instruction, this is effectively a return stub. */
5321 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5322 && (name[19] == 's' || name[19] == 'd')
5323 && pc != start_addr)
5326 return 0; /* not a stub */
5330 /* Return non-zero if the PC is in a library helper function that should
5331 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5334 mips_ignore_helper (CORE_ADDR pc)
5338 /* Find the starting address and name of the function containing the PC. */
5339 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5342 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5343 that we want to ignore. */
5344 return (strcmp (name, "__mips16_ret_sf") == 0
5345 || strcmp (name, "__mips16_ret_df") == 0);
5349 /* Return a location where we can set a breakpoint that will be hit
5350 when an inferior function call returns. This is normally the
5351 program's entry point. Executables that don't have an entry
5352 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5353 whose address is the location where the breakpoint should be placed. */
5356 mips_call_dummy_address (void)
5358 struct minimal_symbol *sym;
5360 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5362 return SYMBOL_VALUE_ADDRESS (sym);
5364 return entry_point_address ();
5368 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5369 the register stored on the stack (32) is different to its real raw
5370 size (64). The below ensures that registers are fetched from the
5371 stack using their ABI size and then stored into the RAW_BUFFER
5372 using their raw size.
5374 The alternative to adding this function would be to add an ABI
5375 macro - REGISTER_STACK_SIZE(). */
5378 mips_get_saved_register (char *raw_buffer,
5381 struct frame_info *frame,
5383 enum lval_type *lvalp)
5386 enum lval_type lvalx;
5389 if (!target_has_registers)
5390 error ("No registers.");
5392 /* Make certain that all needed parameters are present. */
5397 if (optimizedp == NULL)
5398 optimizedp = &optimizedx;
5399 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5401 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5402 have a pseudo register range that correspons to the ABI's, rather
5403 than the ISA's, view of registers. These registers would then
5404 implicitly describe their size and hence could be used without
5405 the below munging. */
5406 if ((*lvalp) == lval_memory)
5408 if (raw_buffer != NULL)
5412 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5414 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5415 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5421 /* Immediately after a function call, return the saved pc.
5422 Can't always go through the frames for this because on some machines
5423 the new frame is not set up until the new function executes
5424 some instructions. */
5427 mips_saved_pc_after_call (struct frame_info *frame)
5429 return read_signed_register (RA_REGNUM);
5433 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5437 mips_stab_reg_to_regnum (int num)
5439 if (num >= 0 && num < 32)
5441 else if (num >= 38 && num < 70)
5442 return num + FP0_REGNUM - 38;
5449 /* This will hopefully (eventually) provoke a warning. Should
5450 we be calling complaint() here? */
5451 return NUM_REGS + NUM_PSEUDO_REGS;
5456 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5459 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5461 if (num >= 0 && num < 32)
5463 else if (num >= 32 && num < 64)
5464 return num + FP0_REGNUM - 32;
5471 /* This will hopefully (eventually) provoke a warning. Should
5472 we be calling complaint() here? */
5473 return NUM_REGS + NUM_PSEUDO_REGS;
5478 /* Convert an integer into an address. By first converting the value
5479 into a pointer and then extracting it signed, the address is
5480 guarenteed to be correctly sign extended. */
5483 mips_integer_to_address (struct type *type, void *buf)
5485 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5486 LONGEST val = unpack_long (type, buf);
5487 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5488 return extract_signed_integer (tmp,
5489 TYPE_LENGTH (builtin_type_void_data_ptr));
5493 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5495 enum mips_abi *abip = (enum mips_abi *) obj;
5496 const char *name = bfd_get_section_name (abfd, sect);
5498 if (*abip != MIPS_ABI_UNKNOWN)
5501 if (strncmp (name, ".mdebug.", 8) != 0)
5504 if (strcmp (name, ".mdebug.abi32") == 0)
5505 *abip = MIPS_ABI_O32;
5506 else if (strcmp (name, ".mdebug.abiN32") == 0)
5507 *abip = MIPS_ABI_N32;
5508 else if (strcmp (name, ".mdebug.abi64") == 0)
5509 *abip = MIPS_ABI_N64;
5510 else if (strcmp (name, ".mdebug.abiO64") == 0)
5511 *abip = MIPS_ABI_O64;
5512 else if (strcmp (name, ".mdebug.eabi32") == 0)
5513 *abip = MIPS_ABI_EABI32;
5514 else if (strcmp (name, ".mdebug.eabi64") == 0)
5515 *abip = MIPS_ABI_EABI64;
5517 warning ("unsupported ABI %s.", name + 8);
5520 static enum mips_abi
5521 global_mips_abi (void)
5525 for (i = 0; mips_abi_strings[i] != NULL; i++)
5526 if (mips_abi_strings[i] == mips_abi_string)
5527 return (enum mips_abi) i;
5529 internal_error (__FILE__, __LINE__,
5530 "unknown ABI string");
5533 static struct gdbarch *
5534 mips_gdbarch_init (struct gdbarch_info info,
5535 struct gdbarch_list *arches)
5537 static LONGEST mips_call_dummy_words[] =
5539 struct gdbarch *gdbarch;
5540 struct gdbarch_tdep *tdep;
5542 enum mips_abi mips_abi, found_abi, wanted_abi;
5544 /* Reset the disassembly info, in case it was set to something
5546 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5547 tm_print_insn_info.arch = bfd_arch_unknown;
5548 tm_print_insn_info.mach = 0;
5554 /* First of all, extract the elf_flags, if available. */
5555 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5556 elf_flags = elf_elfheader (info.abfd)->e_flags;
5559 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5560 switch ((elf_flags & EF_MIPS_ABI))
5562 case E_MIPS_ABI_O32:
5563 mips_abi = MIPS_ABI_O32;
5565 case E_MIPS_ABI_O64:
5566 mips_abi = MIPS_ABI_O64;
5568 case E_MIPS_ABI_EABI32:
5569 mips_abi = MIPS_ABI_EABI32;
5571 case E_MIPS_ABI_EABI64:
5572 mips_abi = MIPS_ABI_EABI64;
5575 if ((elf_flags & EF_MIPS_ABI2))
5576 mips_abi = MIPS_ABI_N32;
5578 mips_abi = MIPS_ABI_UNKNOWN;
5582 /* GCC creates a pseudo-section whose name describes the ABI. */
5583 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5584 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5586 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5587 Use the ABI from the last architecture if there is one. */
5588 if (info.abfd == NULL && arches != NULL)
5589 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5591 /* Try the architecture for any hint of the correct ABI. */
5592 if (mips_abi == MIPS_ABI_UNKNOWN
5593 && info.bfd_arch_info != NULL
5594 && info.bfd_arch_info->arch == bfd_arch_mips)
5596 switch (info.bfd_arch_info->mach)
5598 case bfd_mach_mips3900:
5599 mips_abi = MIPS_ABI_EABI32;
5601 case bfd_mach_mips4100:
5602 case bfd_mach_mips5000:
5603 mips_abi = MIPS_ABI_EABI64;
5605 case bfd_mach_mips8000:
5606 case bfd_mach_mips10000:
5607 /* On Irix, ELF64 executables use the N64 ABI. The
5608 pseudo-sections which describe the ABI aren't present
5609 on IRIX. (Even for executables created by gcc.) */
5610 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5611 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5612 mips_abi = MIPS_ABI_N64;
5614 mips_abi = MIPS_ABI_N32;
5619 if (mips_abi == MIPS_ABI_UNKNOWN)
5620 mips_abi = MIPS_ABI_O32;
5622 /* Now that we have found what the ABI for this binary would be,
5623 check whether the user is overriding it. */
5624 found_abi = mips_abi;
5625 wanted_abi = global_mips_abi ();
5626 if (wanted_abi != MIPS_ABI_UNKNOWN)
5627 mips_abi = wanted_abi;
5629 /* We have to set tm_print_insn_info before looking for a
5630 pre-existing architecture, otherwise we may return before we get
5631 a chance to set it up. */
5632 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5634 /* Set up the disassembler info, so that we get the right
5635 register names from libopcodes. */
5636 if (mips_abi == MIPS_ABI_N32)
5637 tm_print_insn_info.disassembler_options = "gpr-names=n32";
5639 tm_print_insn_info.disassembler_options = "gpr-names=64";
5640 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5641 tm_print_insn_info.arch = bfd_arch_mips;
5642 if (info.bfd_arch_info != NULL
5643 && info.bfd_arch_info->arch == bfd_arch_mips
5644 && info.bfd_arch_info->mach)
5645 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5647 tm_print_insn_info.mach = bfd_mach_mips8000;
5650 /* This string is not recognized explicitly by the disassembler,
5651 but it tells the disassembler to not try to guess the ABI from
5652 the bfd elf headers, such that, if the user overrides the ABI
5653 of a program linked as NewABI, the disassembly will follow the
5654 register naming conventions specified by the user. */
5655 tm_print_insn_info.disassembler_options = "gpr-names=32";
5659 fprintf_unfiltered (gdb_stdlog,
5660 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5662 fprintf_unfiltered (gdb_stdlog,
5663 "mips_gdbarch_init: mips_abi = %d\n",
5665 fprintf_unfiltered (gdb_stdlog,
5666 "mips_gdbarch_init: found_mips_abi = %d\n",
5670 /* try to find a pre-existing architecture */
5671 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5673 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5675 /* MIPS needs to be pedantic about which ABI the object is
5677 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5679 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5681 return arches->gdbarch;
5684 /* Need a new architecture. Fill in a target specific vector. */
5685 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5686 gdbarch = gdbarch_alloc (&info, tdep);
5687 tdep->elf_flags = elf_flags;
5689 /* Initially set everything according to the default ABI/ISA. */
5690 set_gdbarch_short_bit (gdbarch, 16);
5691 set_gdbarch_int_bit (gdbarch, 32);
5692 set_gdbarch_float_bit (gdbarch, 32);
5693 set_gdbarch_double_bit (gdbarch, 64);
5694 set_gdbarch_long_double_bit (gdbarch, 64);
5695 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5696 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8);
5697 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5698 tdep->found_abi = found_abi;
5699 tdep->mips_abi = mips_abi;
5701 set_gdbarch_elf_make_msymbol_special (gdbarch,
5702 mips_elf_make_msymbol_special);
5704 if (info.osabi == GDB_OSABI_IRIX)
5705 set_gdbarch_num_regs (gdbarch, 71);
5707 set_gdbarch_num_regs (gdbarch, 90);
5712 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o32_push_arguments);
5713 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5714 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5715 tdep->mips_default_saved_regsize = 4;
5716 tdep->mips_default_stack_argsize = 4;
5717 tdep->mips_fp_register_double = 0;
5718 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5719 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5720 tdep->gdb_target_is_mips64 = 0;
5721 tdep->default_mask_address_p = 0;
5722 set_gdbarch_long_bit (gdbarch, 32);
5723 set_gdbarch_ptr_bit (gdbarch, 32);
5724 set_gdbarch_long_long_bit (gdbarch, 64);
5725 set_gdbarch_reg_struct_has_addr (gdbarch,
5726 mips_o32_reg_struct_has_addr);
5727 set_gdbarch_use_struct_convention (gdbarch,
5728 mips_o32_use_struct_convention);
5731 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o64_push_arguments);
5732 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5733 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5734 tdep->mips_default_saved_regsize = 8;
5735 tdep->mips_default_stack_argsize = 8;
5736 tdep->mips_fp_register_double = 1;
5737 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5738 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5739 tdep->gdb_target_is_mips64 = 1;
5740 tdep->default_mask_address_p = 0;
5741 set_gdbarch_long_bit (gdbarch, 32);
5742 set_gdbarch_ptr_bit (gdbarch, 32);
5743 set_gdbarch_long_long_bit (gdbarch, 64);
5744 set_gdbarch_reg_struct_has_addr (gdbarch,
5745 mips_o32_reg_struct_has_addr);
5746 set_gdbarch_use_struct_convention (gdbarch,
5747 mips_o32_use_struct_convention);
5749 case MIPS_ABI_EABI32:
5750 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5751 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5752 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5753 tdep->mips_default_saved_regsize = 4;
5754 tdep->mips_default_stack_argsize = 4;
5755 tdep->mips_fp_register_double = 0;
5756 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5757 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5758 tdep->gdb_target_is_mips64 = 0;
5759 tdep->default_mask_address_p = 0;
5760 set_gdbarch_long_bit (gdbarch, 32);
5761 set_gdbarch_ptr_bit (gdbarch, 32);
5762 set_gdbarch_long_long_bit (gdbarch, 64);
5763 set_gdbarch_reg_struct_has_addr (gdbarch,
5764 mips_eabi_reg_struct_has_addr);
5765 set_gdbarch_use_struct_convention (gdbarch,
5766 mips_eabi_use_struct_convention);
5768 case MIPS_ABI_EABI64:
5769 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5770 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5771 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5772 tdep->mips_default_saved_regsize = 8;
5773 tdep->mips_default_stack_argsize = 8;
5774 tdep->mips_fp_register_double = 1;
5775 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5776 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5777 tdep->gdb_target_is_mips64 = 1;
5778 tdep->default_mask_address_p = 0;
5779 set_gdbarch_long_bit (gdbarch, 64);
5780 set_gdbarch_ptr_bit (gdbarch, 64);
5781 set_gdbarch_long_long_bit (gdbarch, 64);
5782 set_gdbarch_reg_struct_has_addr (gdbarch,
5783 mips_eabi_reg_struct_has_addr);
5784 set_gdbarch_use_struct_convention (gdbarch,
5785 mips_eabi_use_struct_convention);
5788 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5789 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5790 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5791 tdep->mips_default_saved_regsize = 8;
5792 tdep->mips_default_stack_argsize = 8;
5793 tdep->mips_fp_register_double = 1;
5794 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5795 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5796 tdep->gdb_target_is_mips64 = 1;
5797 tdep->default_mask_address_p = 0;
5798 set_gdbarch_long_bit (gdbarch, 32);
5799 set_gdbarch_ptr_bit (gdbarch, 32);
5800 set_gdbarch_long_long_bit (gdbarch, 64);
5801 set_gdbarch_use_struct_convention (gdbarch,
5802 mips_n32n64_use_struct_convention);
5803 set_gdbarch_reg_struct_has_addr (gdbarch,
5804 mips_n32n64_reg_struct_has_addr);
5807 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5808 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5809 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5810 tdep->mips_default_saved_regsize = 8;
5811 tdep->mips_default_stack_argsize = 8;
5812 tdep->mips_fp_register_double = 1;
5813 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5814 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5815 tdep->gdb_target_is_mips64 = 1;
5816 tdep->default_mask_address_p = 0;
5817 set_gdbarch_long_bit (gdbarch, 64);
5818 set_gdbarch_ptr_bit (gdbarch, 64);
5819 set_gdbarch_long_long_bit (gdbarch, 64);
5820 set_gdbarch_use_struct_convention (gdbarch,
5821 mips_n32n64_use_struct_convention);
5822 set_gdbarch_reg_struct_has_addr (gdbarch,
5823 mips_n32n64_reg_struct_has_addr);
5826 internal_error (__FILE__, __LINE__,
5827 "unknown ABI in switch");
5830 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5831 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5834 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5835 flag in object files because to do so would make it impossible to
5836 link with libraries compiled without "-gp32". This is
5837 unnecessarily restrictive.
5839 We could solve this problem by adding "-gp32" multilibs to gcc,
5840 but to set this flag before gcc is built with such multilibs will
5841 break too many systems.''
5843 But even more unhelpfully, the default linker output target for
5844 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5845 for 64-bit programs - you need to change the ABI to change this,
5846 and not all gcc targets support that currently. Therefore using
5847 this flag to detect 32-bit mode would do the wrong thing given
5848 the current gcc - it would make GDB treat these 64-bit programs
5849 as 32-bit programs by default. */
5851 /* enable/disable the MIPS FPU */
5852 if (!mips_fpu_type_auto)
5853 tdep->mips_fpu_type = mips_fpu_type;
5854 else if (info.bfd_arch_info != NULL
5855 && info.bfd_arch_info->arch == bfd_arch_mips)
5856 switch (info.bfd_arch_info->mach)
5858 case bfd_mach_mips3900:
5859 case bfd_mach_mips4100:
5860 case bfd_mach_mips4111:
5861 tdep->mips_fpu_type = MIPS_FPU_NONE;
5863 case bfd_mach_mips4650:
5864 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5867 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5871 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5873 /* MIPS version of register names. NOTE: At present the MIPS
5874 register name management is part way between the old -
5875 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5876 Further work on it is required. */
5877 /* NOTE: many targets (esp. embedded) do not go thru the
5878 gdbarch_register_name vector at all, instead bypassing it
5879 by defining REGISTER_NAMES. */
5880 set_gdbarch_register_name (gdbarch, mips_register_name);
5881 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5882 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5883 set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5884 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5885 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
5887 /* Add/remove bits from an address. The MIPS needs be careful to
5888 ensure that all 32 bit addresses are sign extended to 64 bits. */
5889 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5891 /* There's a mess in stack frame creation. See comments in
5892 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5893 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5894 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5896 /* Map debug register numbers onto internal register numbers. */
5897 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5898 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5899 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5900 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5902 /* Initialize a frame */
5903 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5904 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5906 /* MIPS version of CALL_DUMMY */
5908 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5909 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
5910 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
5911 set_gdbarch_fix_call_dummy (gdbarch, mips_fix_call_dummy);
5912 set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words);
5913 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
5914 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
5915 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5916 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5917 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
5918 set_gdbarch_register_convert_to_virtual (gdbarch,
5919 mips_register_convert_to_virtual);
5920 set_gdbarch_register_convert_to_raw (gdbarch,
5921 mips_register_convert_to_raw);
5923 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
5924 set_gdbarch_frameless_function_invocation (gdbarch,
5925 generic_frameless_function_invocation_not);
5926 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5927 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
5928 set_gdbarch_frame_args_skip (gdbarch, 0);
5930 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
5932 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5933 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5934 set_gdbarch_decr_pc_after_break (gdbarch, 0);
5936 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5937 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
5939 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5940 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5941 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5943 set_gdbarch_function_start_offset (gdbarch, 0);
5945 /* There are MIPS targets which do not yet use this since they still
5946 define REGISTER_VIRTUAL_TYPE. */
5947 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
5948 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
5950 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
5951 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
5953 /* Hook in OS ABI-specific overrides, if they have been registered. */
5954 gdbarch_init_osabi (info, gdbarch);
5956 set_gdbarch_deprecated_store_struct_return (gdbarch, mips_store_struct_return);
5957 set_gdbarch_extract_struct_value_address (gdbarch,
5958 mips_extract_struct_value_address);
5960 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
5962 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
5963 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
5969 mips_abi_update (char *ignore_args, int from_tty,
5970 struct cmd_list_element *c)
5972 struct gdbarch_info info;
5974 /* Force the architecture to update, and (if it's a MIPS architecture)
5975 mips_gdbarch_init will take care of the rest. */
5976 gdbarch_info_init (&info);
5977 gdbarch_update_p (info);
5980 /* Print out which MIPS ABI is in use. */
5983 show_mips_abi (char *ignore_args, int from_tty)
5985 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
5987 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
5990 enum mips_abi global_abi = global_mips_abi ();
5991 enum mips_abi actual_abi = mips_abi (current_gdbarch);
5992 const char *actual_abi_str = mips_abi_strings[actual_abi];
5994 if (global_abi == MIPS_ABI_UNKNOWN)
5995 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
5997 else if (global_abi == actual_abi)
5999 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6003 /* Probably shouldn't happen... */
6005 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6007 mips_abi_strings[global_abi]);
6013 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6015 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6019 int ef_mips_32bitmode;
6020 /* determine the ISA */
6021 switch (tdep->elf_flags & EF_MIPS_ARCH)
6039 /* determine the size of a pointer */
6040 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6041 fprintf_unfiltered (file,
6042 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6044 fprintf_unfiltered (file,
6045 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6047 fprintf_unfiltered (file,
6048 "mips_dump_tdep: ef_mips_arch = %d\n",
6050 fprintf_unfiltered (file,
6051 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6053 mips_abi_strings[tdep->mips_abi]);
6054 fprintf_unfiltered (file,
6055 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6056 mips_mask_address_p (),
6057 tdep->default_mask_address_p);
6059 fprintf_unfiltered (file,
6060 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6061 FP_REGISTER_DOUBLE);
6062 fprintf_unfiltered (file,
6063 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6064 MIPS_DEFAULT_FPU_TYPE,
6065 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6066 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6067 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6069 fprintf_unfiltered (file,
6070 "mips_dump_tdep: MIPS_EABI = %d\n",
6072 fprintf_unfiltered (file,
6073 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6074 MIPS_LAST_FP_ARG_REGNUM,
6075 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6076 fprintf_unfiltered (file,
6077 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6079 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6080 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6081 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6083 fprintf_unfiltered (file,
6084 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6085 MIPS_DEFAULT_SAVED_REGSIZE);
6086 fprintf_unfiltered (file,
6087 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6088 FP_REGISTER_DOUBLE);
6089 fprintf_unfiltered (file,
6090 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6091 MIPS_DEFAULT_STACK_ARGSIZE);
6092 fprintf_unfiltered (file,
6093 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6094 MIPS_STACK_ARGSIZE);
6095 fprintf_unfiltered (file,
6096 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6098 fprintf_unfiltered (file,
6099 "mips_dump_tdep: A0_REGNUM = %d\n",
6101 fprintf_unfiltered (file,
6102 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6103 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6104 fprintf_unfiltered (file,
6105 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6106 XSTRING (ATTACH_DETACH));
6107 fprintf_unfiltered (file,
6108 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6110 fprintf_unfiltered (file,
6111 "mips_dump_tdep: BIG_BREAKPOINT = delete?\n");
6112 fprintf_unfiltered (file,
6113 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6115 fprintf_unfiltered (file,
6116 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6117 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6118 fprintf_unfiltered (file,
6119 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6120 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6121 fprintf_unfiltered (file,
6122 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6124 fprintf_unfiltered (file,
6125 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6127 fprintf_unfiltered (file,
6128 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6129 FIRST_EMBED_REGNUM);
6130 fprintf_unfiltered (file,
6131 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6133 fprintf_unfiltered (file,
6134 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6135 GDB_TARGET_IS_MIPS64);
6136 fprintf_unfiltered (file,
6137 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6138 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6139 fprintf_unfiltered (file,
6140 "mips_dump_tdep: HI_REGNUM = %d\n",
6142 fprintf_unfiltered (file,
6143 "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n");
6144 fprintf_unfiltered (file,
6145 "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n");
6146 fprintf_unfiltered (file,
6147 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6148 XSTRING (IGNORE_HELPER_CALL (PC)));
6149 fprintf_unfiltered (file,
6150 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6151 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6152 fprintf_unfiltered (file,
6153 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6154 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6155 fprintf_unfiltered (file,
6156 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6157 fprintf_unfiltered (file,
6158 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6160 fprintf_unfiltered (file,
6161 "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n");
6162 fprintf_unfiltered (file,
6163 "mips_dump_tdep: LO_REGNUM = %d\n",
6165 #ifdef MACHINE_CPROC_FP_OFFSET
6166 fprintf_unfiltered (file,
6167 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6168 MACHINE_CPROC_FP_OFFSET);
6170 #ifdef MACHINE_CPROC_PC_OFFSET
6171 fprintf_unfiltered (file,
6172 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6173 MACHINE_CPROC_PC_OFFSET);
6175 #ifdef MACHINE_CPROC_SP_OFFSET
6176 fprintf_unfiltered (file,
6177 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6178 MACHINE_CPROC_SP_OFFSET);
6180 fprintf_unfiltered (file,
6181 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6182 fprintf_unfiltered (file,
6183 "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n");
6184 fprintf_unfiltered (file,
6185 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6187 fprintf_unfiltered (file,
6188 "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n");
6189 fprintf_unfiltered (file,
6190 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6191 fprintf_unfiltered (file,
6192 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6193 fprintf_unfiltered (file,
6194 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6196 fprintf_unfiltered (file,
6197 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6198 MIPS_LAST_ARG_REGNUM,
6199 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6200 fprintf_unfiltered (file,
6201 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6203 fprintf_unfiltered (file,
6204 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6205 fprintf_unfiltered (file,
6206 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6207 MIPS_SAVED_REGSIZE);
6208 fprintf_unfiltered (file,
6209 "mips_dump_tdep: OP_LDFPR = used?\n");
6210 fprintf_unfiltered (file,
6211 "mips_dump_tdep: OP_LDGPR = used?\n");
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n");
6214 fprintf_unfiltered (file,
6215 "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n");
6216 fprintf_unfiltered (file,
6217 "mips_dump_tdep: PRID_REGNUM = %d\n",
6219 fprintf_unfiltered (file,
6220 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6221 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6222 fprintf_unfiltered (file,
6223 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6224 fprintf_unfiltered (file,
6225 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6228 fprintf_unfiltered (file,
6229 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6230 fprintf_unfiltered (file,
6231 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6232 fprintf_unfiltered (file,
6233 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6234 fprintf_unfiltered (file,
6235 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6236 fprintf_unfiltered (file,
6237 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: PROC_PC_REG = function?\n");
6240 fprintf_unfiltered (file,
6241 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6242 fprintf_unfiltered (file,
6243 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6244 fprintf_unfiltered (file,
6245 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6246 fprintf_unfiltered (file,
6247 "mips_dump_tdep: PS_REGNUM = %d\n",
6249 fprintf_unfiltered (file,
6250 "mips_dump_tdep: RA_REGNUM = %d\n",
6252 fprintf_unfiltered (file,
6253 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6254 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6255 fprintf_unfiltered (file,
6256 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6257 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6258 fprintf_unfiltered (file,
6259 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6260 fprintf_unfiltered (file,
6261 "mips_dump_tdep: ROUND_DOWN = function?\n");
6262 fprintf_unfiltered (file,
6263 "mips_dump_tdep: ROUND_UP = function?\n");
6265 fprintf_unfiltered (file,
6266 "mips_dump_tdep: SAVED_BYTES = %d\n",
6270 fprintf_unfiltered (file,
6271 "mips_dump_tdep: SAVED_FP = %d\n",
6275 fprintf_unfiltered (file,
6276 "mips_dump_tdep: SAVED_PC = %d\n",
6279 fprintf_unfiltered (file,
6280 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6281 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6282 fprintf_unfiltered (file,
6283 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6284 fprintf_unfiltered (file,
6285 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6287 fprintf_unfiltered (file,
6288 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6289 SIGFRAME_FPREGSAVE_OFF);
6290 fprintf_unfiltered (file,
6291 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6293 fprintf_unfiltered (file,
6294 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6295 SIGFRAME_REGSAVE_OFF);
6296 fprintf_unfiltered (file,
6297 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6299 fprintf_unfiltered (file,
6300 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6301 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6302 fprintf_unfiltered (file,
6303 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6304 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6305 fprintf_unfiltered (file,
6306 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6307 SOFTWARE_SINGLE_STEP_P ());
6308 fprintf_unfiltered (file,
6309 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6310 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6311 #ifdef STACK_END_ADDR
6312 fprintf_unfiltered (file,
6313 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6316 fprintf_unfiltered (file,
6317 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6318 XSTRING (STEP_SKIPS_DELAY (PC)));
6319 fprintf_unfiltered (file,
6320 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6321 STEP_SKIPS_DELAY_P);
6322 fprintf_unfiltered (file,
6323 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6324 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6325 fprintf_unfiltered (file,
6326 "mips_dump_tdep: T9_REGNUM = %d\n",
6328 fprintf_unfiltered (file,
6329 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6330 fprintf_unfiltered (file,
6331 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6332 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6333 fprintf_unfiltered (file,
6334 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6335 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6336 fprintf_unfiltered (file,
6337 "mips_dump_tdep: TARGET_MIPS = used?\n");
6338 fprintf_unfiltered (file,
6339 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6340 XSTRING (TM_PRINT_INSN_MACH));
6342 fprintf_unfiltered (file,
6343 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6344 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6347 fprintf_unfiltered (file,
6348 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6351 #ifdef TRACE_FLAVOR_SIZE
6352 fprintf_unfiltered (file,
6353 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6357 fprintf_unfiltered (file,
6358 "mips_dump_tdep: TRACE_SET # %s\n",
6359 XSTRING (TRACE_SET (X,STATE)));
6361 fprintf_unfiltered (file,
6362 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6363 #ifdef UNUSED_REGNUM
6364 fprintf_unfiltered (file,
6365 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6368 fprintf_unfiltered (file,
6369 "mips_dump_tdep: V0_REGNUM = %d\n",
6371 fprintf_unfiltered (file,
6372 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6373 (long) VM_MIN_ADDRESS);
6375 fprintf_unfiltered (file,
6376 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6379 fprintf_unfiltered (file,
6380 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6382 fprintf_unfiltered (file,
6383 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6388 _initialize_mips_tdep (void)
6390 static struct cmd_list_element *mipsfpulist = NULL;
6391 struct cmd_list_element *c;
6393 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6394 if (MIPS_ABI_LAST + 1
6395 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6396 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6398 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6399 if (!deprecated_tm_print_insn) /* Someone may have already set it */
6400 deprecated_tm_print_insn = gdb_print_insn_mips;
6402 /* Add root prefix command for all "set mips"/"show mips" commands */
6403 add_prefix_cmd ("mips", no_class, set_mips_command,
6404 "Various MIPS specific commands.",
6405 &setmipscmdlist, "set mips ", 0, &setlist);
6407 add_prefix_cmd ("mips", no_class, show_mips_command,
6408 "Various MIPS specific commands.",
6409 &showmipscmdlist, "show mips ", 0, &showlist);
6411 /* Allow the user to override the saved register size. */
6412 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6415 &mips_saved_regsize_string, "\
6416 Set size of general purpose registers saved on the stack.\n\
6417 This option can be set to one of:\n\
6418 32 - Force GDB to treat saved GP registers as 32-bit\n\
6419 64 - Force GDB to treat saved GP registers as 64-bit\n\
6420 auto - Allow GDB to use the target's default setting or autodetect the\n\
6421 saved GP register size from information contained in the executable.\n\
6426 /* Allow the user to override the argument stack size. */
6427 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6430 &mips_stack_argsize_string, "\
6431 Set the amount of stack space reserved for each argument.\n\
6432 This option can be set to one of:\n\
6433 32 - Force GDB to allocate 32-bit chunks per argument\n\
6434 64 - Force GDB to allocate 64-bit chunks per argument\n\
6435 auto - Allow GDB to determine the correct setting from the current\n\
6436 target and executable (default)",
6440 /* Allow the user to override the ABI. */
6441 c = add_set_enum_cmd
6442 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6443 "Set the ABI used by this program.\n"
6444 "This option can be set to one of:\n"
6445 " auto - the default ABI associated with the current binary\n"
6453 set_cmd_sfunc (c, mips_abi_update);
6454 add_cmd ("abi", class_obscure, show_mips_abi,
6455 "Show ABI in use by MIPS target", &showmipscmdlist);
6457 /* Let the user turn off floating point and set the fence post for
6458 heuristic_proc_start. */
6460 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6461 "Set use of MIPS floating-point coprocessor.",
6462 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6463 add_cmd ("single", class_support, set_mipsfpu_single_command,
6464 "Select single-precision MIPS floating-point coprocessor.",
6466 add_cmd ("double", class_support, set_mipsfpu_double_command,
6467 "Select double-precision MIPS floating-point coprocessor.",
6469 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6470 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6471 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6472 add_cmd ("none", class_support, set_mipsfpu_none_command,
6473 "Select no MIPS floating-point coprocessor.",
6475 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6476 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6477 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6478 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6479 "Select MIPS floating-point coprocessor automatically.",
6481 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6482 "Show current use of MIPS floating-point coprocessor target.",
6485 /* We really would like to have both "0" and "unlimited" work, but
6486 command.c doesn't deal with that. So make it a var_zinteger
6487 because the user can always use "999999" or some such for unlimited. */
6488 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6489 (char *) &heuristic_fence_post,
6491 Set the distance searched for the start of a function.\n\
6492 If you are debugging a stripped executable, GDB needs to search through the\n\
6493 program for the start of a function. This command sets the distance of the\n\
6494 search. The only need to set it is when debugging a stripped executable.",
6496 /* We need to throw away the frame cache when we set this, since it
6497 might change our ability to get backtraces. */
6498 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6499 add_show_from_set (c, &showlist);
6501 /* Allow the user to control whether the upper bits of 64-bit
6502 addresses should be zeroed. */
6503 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6504 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6505 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6506 allow GDB to determine the correct value.\n", "\
6507 Show zeroing of upper 32 bits of 64-bit addresses.",
6508 NULL, show_mask_address,
6509 &setmipscmdlist, &showmipscmdlist);
6511 /* Allow the user to control the size of 32 bit registers within the
6512 raw remote packet. */
6513 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6516 (char *)&mips64_transfers_32bit_regs_p, "\
6517 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6518 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6519 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6520 64 bits for others. Use \"off\" to disable compatibility mode",
6524 /* Debug this files internals. */
6525 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6526 &mips_debug, "Set mips debugging.\n\
6527 When non-zero, mips specific debugging is enabled.", &setdebuglist),