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
627 the ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause
628 though. In some cases 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 ADDR_BITS_REMOVE (read_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 ADDR_BITS_REMOVE (read_next_frame_reg (frame,
2446 PROC_FRAME_REG (proc_desc)) +
2447 PROC_FRAME_OFFSET (proc_desc) -
2448 PROC_FRAME_ADJUST (proc_desc));
2451 static mips_extra_func_info_t cached_proc_desc;
2454 mips_frame_chain (struct frame_info *frame)
2456 mips_extra_func_info_t proc_desc;
2458 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2460 if (saved_pc == 0 || inside_entry_file (saved_pc))
2463 /* Check if the PC is inside a call stub. If it is, fetch the
2464 PC of the caller of that stub. */
2465 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2468 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2470 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2471 is well, frame->frame the bottom of the current frame will
2472 contain that value. */
2473 return get_frame_base (frame);
2476 /* Look up the procedure descriptor for this PC. */
2477 proc_desc = find_proc_desc (saved_pc, frame, 1);
2481 cached_proc_desc = proc_desc;
2483 /* If no frame pointer and frame size is zero, we must be at end
2484 of stack (or otherwise hosed). If we don't check frame size,
2485 we loop forever if we see a zero size frame. */
2486 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2487 && PROC_FRAME_OFFSET (proc_desc) == 0
2488 /* The previous frame from a sigtramp frame might be frameless
2489 and have frame size zero. */
2490 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2491 /* For a generic dummy frame, let get_frame_pointer() unwind a
2492 register value saved as part of the dummy frame call. */
2493 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2496 return get_frame_pointer (frame, proc_desc);
2500 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2503 mips_extra_func_info_t proc_desc;
2505 if (get_frame_type (fci) == DUMMY_FRAME)
2508 /* Use proc_desc calculated in frame_chain. When there is no
2509 next frame, i.e, get_next_frame (fci) == NULL, we call
2510 find_proc_desc () to calculate it, passing an explicit
2511 NULL as the frame parameter. */
2513 get_next_frame (fci)
2515 : find_proc_desc (get_frame_pc (fci),
2516 NULL /* i.e, get_next_frame (fci) */,
2519 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2521 deprecated_set_frame_saved_regs_hack (fci, NULL);
2522 get_frame_extra_info (fci)->proc_desc =
2523 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2526 /* Fixup frame-pointer - only needed for top frame */
2527 /* This may not be quite right, if proc has a real frame register.
2528 Get the value of the frame relative sp, procedure might have been
2529 interrupted by a signal at it's very start. */
2530 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2531 && !PROC_DESC_IS_DUMMY (proc_desc))
2532 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2533 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2534 /* Do not ``fix'' fci->frame. It will have the value of the
2535 generic dummy frame's top-of-stack (since the draft
2536 fci->frame is obtained by returning the unwound stack
2537 pointer) and that is what we want. That way the fci->frame
2538 value will match the top-of-stack value that was saved as
2539 part of the dummy frames data. */
2542 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2544 if (proc_desc == &temp_proc_desc)
2548 /* Do not set the saved registers for a sigtramp frame,
2549 mips_find_saved_registers will do that for us. We can't
2550 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2552 /* FIXME: cagney/2002-11-18: This problem will go away once
2553 frame.c:get_prev_frame() is modified to set the frame's
2554 type before calling functions like this. */
2555 find_pc_partial_function (get_frame_pc (fci), &name,
2556 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2557 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2559 frame_saved_regs_zalloc (fci);
2560 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2561 get_frame_saved_regs (fci)[PC_REGNUM]
2562 = get_frame_saved_regs (fci)[RA_REGNUM];
2563 /* Set value of previous frame's stack pointer. Remember that
2564 saved_regs[SP_REGNUM] is special in that it contains the
2565 value of the stack pointer register. The other saved_regs
2566 values are addresses (in the inferior) at which a given
2567 register's value may be found. */
2568 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2572 /* hack: if argument regs are saved, guess these contain args */
2573 /* assume we can't tell how many args for now */
2574 get_frame_extra_info (fci)->num_args = -1;
2575 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2577 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2579 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2586 /* MIPS stack frames are almost impenetrable. When execution stops,
2587 we basically have to look at symbol information for the function
2588 that we stopped in, which tells us *which* register (if any) is
2589 the base of the frame pointer, and what offset from that register
2590 the frame itself is at.
2592 This presents a problem when trying to examine a stack in memory
2593 (that isn't executing at the moment), using the "frame" command. We
2594 don't have a PC, nor do we have any registers except SP.
2596 This routine takes two arguments, SP and PC, and tries to make the
2597 cached frames look as if these two arguments defined a frame on the
2598 cache. This allows the rest of info frame to extract the important
2599 arguments without difficulty. */
2602 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2605 error ("MIPS frame specifications require two arguments: sp and pc");
2607 return create_new_frame (argv[0], argv[1]);
2610 /* According to the current ABI, should the type be passed in a
2611 floating-point register (assuming that there is space)? When there
2612 is no FPU, FP are not even considered as possibile candidates for
2613 FP registers and, consequently this returns false - forces FP
2614 arguments into integer registers. */
2617 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2619 return ((typecode == TYPE_CODE_FLT
2621 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2622 && TYPE_NFIELDS (arg_type) == 1
2623 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2624 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2627 /* On o32, argument passing in GPRs depends on the alignment of the type being
2628 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2631 mips_type_needs_double_align (struct type *type)
2633 enum type_code typecode = TYPE_CODE (type);
2635 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2637 else if (typecode == TYPE_CODE_STRUCT)
2639 if (TYPE_NFIELDS (type) < 1)
2641 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2643 else if (typecode == TYPE_CODE_UNION)
2647 n = TYPE_NFIELDS (type);
2648 for (i = 0; i < n; i++)
2649 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2656 /* Macros to round N up or down to the next A boundary;
2657 A must be a power of two. */
2659 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2660 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2662 /* Adjust the address downward (direction of stack growth) so that it
2663 is correctly aligned for a new stack frame. */
2665 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2667 return ROUND_DOWN (addr, 16);
2671 mips_eabi_push_arguments (int nargs,
2672 struct value **args,
2675 CORE_ADDR struct_addr)
2681 int stack_offset = 0;
2683 /* First ensure that the stack and structure return address (if any)
2684 are properly aligned. The stack has to be at least 64-bit
2685 aligned even on 32-bit machines, because doubles must be 64-bit
2686 aligned. For n32 and n64, stack frames need to be 128-bit
2687 aligned, so we round to this widest known alignment. */
2689 sp = ROUND_DOWN (sp, 16);
2690 struct_addr = ROUND_DOWN (struct_addr, 16);
2692 /* Now make space on the stack for the args. We allocate more
2693 than necessary for EABI, because the first few arguments are
2694 passed in registers, but that's OK. */
2695 for (argnum = 0; argnum < nargs; argnum++)
2696 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2697 MIPS_STACK_ARGSIZE);
2698 sp -= ROUND_UP (len, 16);
2701 fprintf_unfiltered (gdb_stdlog,
2702 "mips_eabi_push_arguments: sp=0x%s allocated %d\n",
2703 paddr_nz (sp), ROUND_UP (len, 16));
2705 /* Initialize the integer and float register pointers. */
2707 float_argreg = FPA0_REGNUM;
2709 /* The struct_return pointer occupies the first parameter-passing reg. */
2713 fprintf_unfiltered (gdb_stdlog,
2714 "mips_eabi_push_arguments: struct_return reg=%d 0x%s\n",
2715 argreg, paddr_nz (struct_addr));
2716 write_register (argreg++, struct_addr);
2719 /* Now load as many as possible of the first arguments into
2720 registers, and push the rest onto the stack. Loop thru args
2721 from first to last. */
2722 for (argnum = 0; argnum < nargs; argnum++)
2725 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2726 struct value *arg = args[argnum];
2727 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2728 int len = TYPE_LENGTH (arg_type);
2729 enum type_code typecode = TYPE_CODE (arg_type);
2732 fprintf_unfiltered (gdb_stdlog,
2733 "mips_eabi_push_arguments: %d len=%d type=%d",
2734 argnum + 1, len, (int) typecode);
2736 /* The EABI passes structures that do not fit in a register by
2738 if (len > MIPS_SAVED_REGSIZE
2739 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2741 store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2742 typecode = TYPE_CODE_PTR;
2743 len = MIPS_SAVED_REGSIZE;
2746 fprintf_unfiltered (gdb_stdlog, " push");
2749 val = (char *) VALUE_CONTENTS (arg);
2751 /* 32-bit ABIs always start floating point arguments in an
2752 even-numbered floating point register. Round the FP register
2753 up before the check to see if there are any FP registers
2754 left. Non MIPS_EABI targets also pass the FP in the integer
2755 registers so also round up normal registers. */
2756 if (!FP_REGISTER_DOUBLE
2757 && fp_register_arg_p (typecode, arg_type))
2759 if ((float_argreg & 1))
2763 /* Floating point arguments passed in registers have to be
2764 treated specially. On 32-bit architectures, doubles
2765 are passed in register pairs; the even register gets
2766 the low word, and the odd register gets the high word.
2767 On non-EABI processors, the first two floating point arguments are
2768 also copied to general registers, because MIPS16 functions
2769 don't use float registers for arguments. This duplication of
2770 arguments in general registers can't hurt non-MIPS16 functions
2771 because those registers are normally skipped. */
2772 /* MIPS_EABI squeezes a struct that contains a single floating
2773 point value into an FP register instead of pushing it onto the
2775 if (fp_register_arg_p (typecode, arg_type)
2776 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2778 if (!FP_REGISTER_DOUBLE && len == 8)
2780 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2781 unsigned long regval;
2783 /* Write the low word of the double to the even register(s). */
2784 regval = extract_unsigned_integer (val + low_offset, 4);
2786 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2787 float_argreg, phex (regval, 4));
2788 write_register (float_argreg++, regval);
2790 /* Write the high word of the double to the odd register(s). */
2791 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2793 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2794 float_argreg, phex (regval, 4));
2795 write_register (float_argreg++, regval);
2799 /* This is a floating point value that fits entirely
2800 in a single register. */
2801 /* On 32 bit ABI's the float_argreg is further adjusted
2802 above to ensure that it is even register aligned. */
2803 LONGEST regval = extract_unsigned_integer (val, len);
2805 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2806 float_argreg, phex (regval, len));
2807 write_register (float_argreg++, regval);
2812 /* Copy the argument to general registers or the stack in
2813 register-sized pieces. Large arguments are split between
2814 registers and stack. */
2815 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2816 are treated specially: Irix cc passes them in registers
2817 where gcc sometimes puts them on the stack. For maximum
2818 compatibility, we will put them in both places. */
2819 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2820 (len % MIPS_SAVED_REGSIZE != 0));
2822 /* Note: Floating-point values that didn't fit into an FP
2823 register are only written to memory. */
2826 /* Remember if the argument was written to the stack. */
2827 int stack_used_p = 0;
2829 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2832 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2835 /* Write this portion of the argument to the stack. */
2836 if (argreg > MIPS_LAST_ARG_REGNUM
2838 || fp_register_arg_p (typecode, arg_type))
2840 /* Should shorter than int integer values be
2841 promoted to int before being stored? */
2842 int longword_offset = 0;
2845 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2847 if (MIPS_STACK_ARGSIZE == 8 &&
2848 (typecode == TYPE_CODE_INT ||
2849 typecode == TYPE_CODE_PTR ||
2850 typecode == TYPE_CODE_FLT) && len <= 4)
2851 longword_offset = MIPS_STACK_ARGSIZE - len;
2852 else if ((typecode == TYPE_CODE_STRUCT ||
2853 typecode == TYPE_CODE_UNION) &&
2854 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2855 longword_offset = MIPS_STACK_ARGSIZE - len;
2860 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2861 paddr_nz (stack_offset));
2862 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2863 paddr_nz (longword_offset));
2866 addr = sp + stack_offset + longword_offset;
2871 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2873 for (i = 0; i < partial_len; i++)
2875 fprintf_unfiltered (gdb_stdlog, "%02x",
2879 write_memory (addr, val, partial_len);
2882 /* Note!!! This is NOT an else clause. Odd sized
2883 structs may go thru BOTH paths. Floating point
2884 arguments will not. */
2885 /* Write this portion of the argument to a general
2886 purpose register. */
2887 if (argreg <= MIPS_LAST_ARG_REGNUM
2888 && !fp_register_arg_p (typecode, arg_type))
2890 LONGEST regval = extract_unsigned_integer (val, partial_len);
2893 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2895 phex (regval, MIPS_SAVED_REGSIZE));
2896 write_register (argreg, regval);
2903 /* Compute the the offset into the stack at which we
2904 will copy the next parameter.
2906 In the new EABI (and the NABI32), the stack_offset
2907 only needs to be adjusted when it has been used. */
2910 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2914 fprintf_unfiltered (gdb_stdlog, "\n");
2917 /* Return adjusted stack pointer. */
2921 /* N32/N64 version of push_arguments. */
2924 mips_n32n64_push_arguments (int nargs,
2925 struct value **args,
2928 CORE_ADDR struct_addr)
2934 int stack_offset = 0;
2936 /* First ensure that the stack and structure return address (if any)
2937 are properly aligned. The stack has to be at least 64-bit
2938 aligned even on 32-bit machines, because doubles must be 64-bit
2939 aligned. For n32 and n64, stack frames need to be 128-bit
2940 aligned, so we round to this widest known alignment. */
2942 sp = ROUND_DOWN (sp, 16);
2943 struct_addr = ROUND_DOWN (struct_addr, 16);
2945 /* Now make space on the stack for the args. */
2946 for (argnum = 0; argnum < nargs; argnum++)
2947 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2948 MIPS_STACK_ARGSIZE);
2949 sp -= ROUND_UP (len, 16);
2952 fprintf_unfiltered (gdb_stdlog,
2953 "mips_n32n64_push_arguments: sp=0x%s allocated %d\n",
2954 paddr_nz (sp), ROUND_UP (len, 16));
2956 /* Initialize the integer and float register pointers. */
2958 float_argreg = FPA0_REGNUM;
2960 /* The struct_return pointer occupies the first parameter-passing reg. */
2964 fprintf_unfiltered (gdb_stdlog,
2965 "mips_n32n64_push_arguments: struct_return reg=%d 0x%s\n",
2966 argreg, paddr_nz (struct_addr));
2967 write_register (argreg++, struct_addr);
2970 /* Now load as many as possible of the first arguments into
2971 registers, and push the rest onto the stack. Loop thru args
2972 from first to last. */
2973 for (argnum = 0; argnum < nargs; argnum++)
2976 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2977 struct value *arg = args[argnum];
2978 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2979 int len = TYPE_LENGTH (arg_type);
2980 enum type_code typecode = TYPE_CODE (arg_type);
2983 fprintf_unfiltered (gdb_stdlog,
2984 "mips_n32n64_push_arguments: %d len=%d type=%d",
2985 argnum + 1, len, (int) typecode);
2987 val = (char *) VALUE_CONTENTS (arg);
2989 if (fp_register_arg_p (typecode, arg_type)
2990 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2992 /* This is a floating point value that fits entirely
2993 in a single register. */
2994 /* On 32 bit ABI's the float_argreg is further adjusted
2995 above to ensure that it is even register aligned. */
2996 LONGEST regval = extract_unsigned_integer (val, len);
2998 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2999 float_argreg, phex (regval, len));
3000 write_register (float_argreg++, regval);
3003 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3004 argreg, phex (regval, len));
3005 write_register (argreg, regval);
3010 /* Copy the argument to general registers or the stack in
3011 register-sized pieces. Large arguments are split between
3012 registers and stack. */
3013 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3014 are treated specially: Irix cc passes them in registers
3015 where gcc sometimes puts them on the stack. For maximum
3016 compatibility, we will put them in both places. */
3017 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3018 (len % MIPS_SAVED_REGSIZE != 0));
3019 /* Note: Floating-point values that didn't fit into an FP
3020 register are only written to memory. */
3023 /* Rememer if the argument was written to the stack. */
3024 int stack_used_p = 0;
3025 int partial_len = len < MIPS_SAVED_REGSIZE ?
3026 len : MIPS_SAVED_REGSIZE;
3029 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3032 /* Write this portion of the argument to the stack. */
3033 if (argreg > MIPS_LAST_ARG_REGNUM
3035 || fp_register_arg_p (typecode, arg_type))
3037 /* Should shorter than int integer values be
3038 promoted to int before being stored? */
3039 int longword_offset = 0;
3042 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3044 if (MIPS_STACK_ARGSIZE == 8 &&
3045 (typecode == TYPE_CODE_INT ||
3046 typecode == TYPE_CODE_PTR ||
3047 typecode == TYPE_CODE_FLT) && len <= 4)
3048 longword_offset = MIPS_STACK_ARGSIZE - len;
3053 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3054 paddr_nz (stack_offset));
3055 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3056 paddr_nz (longword_offset));
3059 addr = sp + stack_offset + longword_offset;
3064 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3066 for (i = 0; i < partial_len; i++)
3068 fprintf_unfiltered (gdb_stdlog, "%02x",
3072 write_memory (addr, val, partial_len);
3075 /* Note!!! This is NOT an else clause. Odd sized
3076 structs may go thru BOTH paths. Floating point
3077 arguments will not. */
3078 /* Write this portion of the argument to a general
3079 purpose register. */
3080 if (argreg <= MIPS_LAST_ARG_REGNUM
3081 && !fp_register_arg_p (typecode, arg_type))
3083 LONGEST regval = extract_unsigned_integer (val, partial_len);
3085 /* A non-floating-point argument being passed in a
3086 general register. If a struct or union, and if
3087 the remaining length is smaller than the register
3088 size, we have to adjust the register value on
3091 It does not seem to be necessary to do the
3092 same for integral types.
3094 cagney/2001-07-23: gdb/179: Also, GCC, when
3095 outputting LE O32 with sizeof (struct) <
3096 MIPS_SAVED_REGSIZE, generates a left shift as
3097 part of storing the argument in a register a
3098 register (the left shift isn't generated when
3099 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3100 is quite possible that this is GCC contradicting
3101 the LE/O32 ABI, GDB has not been adjusted to
3102 accommodate this. Either someone needs to
3103 demonstrate that the LE/O32 ABI specifies such a
3104 left shift OR this new ABI gets identified as
3105 such and GDB gets tweaked accordingly. */
3107 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3108 && partial_len < MIPS_SAVED_REGSIZE
3109 && (typecode == TYPE_CODE_STRUCT ||
3110 typecode == TYPE_CODE_UNION))
3111 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3115 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3117 phex (regval, MIPS_SAVED_REGSIZE));
3118 write_register (argreg, regval);
3125 /* Compute the the offset into the stack at which we
3126 will copy the next parameter.
3128 In N32 (N64?), the stack_offset only needs to be
3129 adjusted when it has been used. */
3132 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3136 fprintf_unfiltered (gdb_stdlog, "\n");
3139 /* Return adjusted stack pointer. */
3143 /* O32 version of push_arguments. */
3146 mips_o32_push_arguments (int nargs,
3147 struct value **args,
3150 CORE_ADDR struct_addr)
3156 int stack_offset = 0;
3158 /* First ensure that the stack and structure return address (if any)
3159 are properly aligned. The stack has to be at least 64-bit
3160 aligned even on 32-bit machines, because doubles must be 64-bit
3161 aligned. For n32 and n64, stack frames need to be 128-bit
3162 aligned, so we round to this widest known alignment. */
3164 sp = ROUND_DOWN (sp, 16);
3165 struct_addr = ROUND_DOWN (struct_addr, 16);
3167 /* Now make space on the stack for the args. */
3168 for (argnum = 0; argnum < nargs; argnum++)
3169 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3170 MIPS_STACK_ARGSIZE);
3171 sp -= ROUND_UP (len, 16);
3174 fprintf_unfiltered (gdb_stdlog,
3175 "mips_o32_push_arguments: sp=0x%s allocated %d\n",
3176 paddr_nz (sp), ROUND_UP (len, 16));
3178 /* Initialize the integer and float register pointers. */
3180 float_argreg = FPA0_REGNUM;
3182 /* The struct_return pointer occupies the first parameter-passing reg. */
3186 fprintf_unfiltered (gdb_stdlog,
3187 "mips_o32_push_arguments: struct_return reg=%d 0x%s\n",
3188 argreg, paddr_nz (struct_addr));
3189 write_register (argreg++, struct_addr);
3190 stack_offset += MIPS_STACK_ARGSIZE;
3193 /* Now load as many as possible of the first arguments into
3194 registers, and push the rest onto the stack. Loop thru args
3195 from first to last. */
3196 for (argnum = 0; argnum < nargs; argnum++)
3199 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3200 struct value *arg = args[argnum];
3201 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3202 int len = TYPE_LENGTH (arg_type);
3203 enum type_code typecode = TYPE_CODE (arg_type);
3206 fprintf_unfiltered (gdb_stdlog,
3207 "mips_o32_push_arguments: %d len=%d type=%d",
3208 argnum + 1, len, (int) typecode);
3210 val = (char *) VALUE_CONTENTS (arg);
3212 /* 32-bit ABIs always start floating point arguments in an
3213 even-numbered floating point register. Round the FP register
3214 up before the check to see if there are any FP registers
3215 left. O32/O64 targets also pass the FP in the integer
3216 registers so also round up normal registers. */
3217 if (!FP_REGISTER_DOUBLE
3218 && fp_register_arg_p (typecode, arg_type))
3220 if ((float_argreg & 1))
3224 /* Floating point arguments passed in registers have to be
3225 treated specially. On 32-bit architectures, doubles
3226 are passed in register pairs; the even register gets
3227 the low word, and the odd register gets the high word.
3228 On O32/O64, the first two floating point arguments are
3229 also copied to general registers, because MIPS16 functions
3230 don't use float registers for arguments. This duplication of
3231 arguments in general registers can't hurt non-MIPS16 functions
3232 because those registers are normally skipped. */
3234 if (fp_register_arg_p (typecode, arg_type)
3235 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3237 if (!FP_REGISTER_DOUBLE && len == 8)
3239 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3240 unsigned long regval;
3242 /* Write the low word of the double to the even register(s). */
3243 regval = extract_unsigned_integer (val + low_offset, 4);
3245 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3246 float_argreg, phex (regval, 4));
3247 write_register (float_argreg++, regval);
3249 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3250 argreg, phex (regval, 4));
3251 write_register (argreg++, regval);
3253 /* Write the high word of the double to the odd register(s). */
3254 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3256 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3257 float_argreg, phex (regval, 4));
3258 write_register (float_argreg++, regval);
3261 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3262 argreg, phex (regval, 4));
3263 write_register (argreg++, regval);
3267 /* This is a floating point value that fits entirely
3268 in a single register. */
3269 /* On 32 bit ABI's the float_argreg is further adjusted
3270 above to ensure that it is even register aligned. */
3271 LONGEST regval = extract_unsigned_integer (val, len);
3273 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3274 float_argreg, phex (regval, len));
3275 write_register (float_argreg++, regval);
3276 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3277 registers for each argument. The below is (my
3278 guess) to ensure that the corresponding integer
3279 register has reserved the same space. */
3281 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3282 argreg, phex (regval, len));
3283 write_register (argreg, regval);
3284 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3286 /* Reserve space for the FP register. */
3287 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3291 /* Copy the argument to general registers or the stack in
3292 register-sized pieces. Large arguments are split between
3293 registers and stack. */
3294 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3295 are treated specially: Irix cc passes them in registers
3296 where gcc sometimes puts them on the stack. For maximum
3297 compatibility, we will put them in both places. */
3298 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3299 (len % MIPS_SAVED_REGSIZE != 0));
3300 /* Structures should be aligned to eight bytes (even arg registers)
3301 on MIPS_ABI_O32, if their first member has double precision. */
3302 if (MIPS_SAVED_REGSIZE < 8
3303 && mips_type_needs_double_align (arg_type))
3308 /* Note: Floating-point values that didn't fit into an FP
3309 register are only written to memory. */
3312 /* Remember if the argument was written to the stack. */
3313 int stack_used_p = 0;
3315 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3318 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3321 /* Write this portion of the argument to the stack. */
3322 if (argreg > MIPS_LAST_ARG_REGNUM
3324 || fp_register_arg_p (typecode, arg_type))
3326 /* Should shorter than int integer values be
3327 promoted to int before being stored? */
3328 int longword_offset = 0;
3331 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3333 if (MIPS_STACK_ARGSIZE == 8 &&
3334 (typecode == TYPE_CODE_INT ||
3335 typecode == TYPE_CODE_PTR ||
3336 typecode == TYPE_CODE_FLT) && len <= 4)
3337 longword_offset = MIPS_STACK_ARGSIZE - len;
3342 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3343 paddr_nz (stack_offset));
3344 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3345 paddr_nz (longword_offset));
3348 addr = sp + stack_offset + longword_offset;
3353 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3355 for (i = 0; i < partial_len; i++)
3357 fprintf_unfiltered (gdb_stdlog, "%02x",
3361 write_memory (addr, val, partial_len);
3364 /* Note!!! This is NOT an else clause. Odd sized
3365 structs may go thru BOTH paths. Floating point
3366 arguments will not. */
3367 /* Write this portion of the argument to a general
3368 purpose register. */
3369 if (argreg <= MIPS_LAST_ARG_REGNUM
3370 && !fp_register_arg_p (typecode, arg_type))
3372 LONGEST regval = extract_signed_integer (val, partial_len);
3373 /* Value may need to be sign extended, because
3374 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3376 /* A non-floating-point argument being passed in a
3377 general register. If a struct or union, and if
3378 the remaining length is smaller than the register
3379 size, we have to adjust the register value on
3382 It does not seem to be necessary to do the
3383 same for integral types.
3385 Also don't do this adjustment on O64 binaries.
3387 cagney/2001-07-23: gdb/179: Also, GCC, when
3388 outputting LE O32 with sizeof (struct) <
3389 MIPS_SAVED_REGSIZE, generates a left shift as
3390 part of storing the argument in a register a
3391 register (the left shift isn't generated when
3392 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3393 is quite possible that this is GCC contradicting
3394 the LE/O32 ABI, GDB has not been adjusted to
3395 accommodate this. Either someone needs to
3396 demonstrate that the LE/O32 ABI specifies such a
3397 left shift OR this new ABI gets identified as
3398 such and GDB gets tweaked accordingly. */
3400 if (MIPS_SAVED_REGSIZE < 8
3401 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3402 && partial_len < MIPS_SAVED_REGSIZE
3403 && (typecode == TYPE_CODE_STRUCT ||
3404 typecode == TYPE_CODE_UNION))
3405 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3409 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3411 phex (regval, MIPS_SAVED_REGSIZE));
3412 write_register (argreg, regval);
3415 /* Prevent subsequent floating point arguments from
3416 being passed in floating point registers. */
3417 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3423 /* Compute the the offset into the stack at which we
3424 will copy the next parameter.
3426 In older ABIs, the caller reserved space for
3427 registers that contained arguments. This was loosely
3428 refered to as their "home". Consequently, space is
3429 always allocated. */
3431 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3435 fprintf_unfiltered (gdb_stdlog, "\n");
3438 /* Return adjusted stack pointer. */
3442 /* O64 version of push_arguments. */
3445 mips_o64_push_arguments (int nargs,
3446 struct value **args,
3449 CORE_ADDR struct_addr)
3455 int stack_offset = 0;
3457 /* First ensure that the stack and structure return address (if any)
3458 are properly aligned. The stack has to be at least 64-bit
3459 aligned even on 32-bit machines, because doubles must be 64-bit
3460 aligned. For n32 and n64, stack frames need to be 128-bit
3461 aligned, so we round to this widest known alignment. */
3463 sp = ROUND_DOWN (sp, 16);
3464 struct_addr = ROUND_DOWN (struct_addr, 16);
3466 /* Now make space on the stack for the args. */
3467 for (argnum = 0; argnum < nargs; argnum++)
3468 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3469 MIPS_STACK_ARGSIZE);
3470 sp -= ROUND_UP (len, 16);
3473 fprintf_unfiltered (gdb_stdlog,
3474 "mips_o64_push_arguments: sp=0x%s allocated %d\n",
3475 paddr_nz (sp), ROUND_UP (len, 16));
3477 /* Initialize the integer and float register pointers. */
3479 float_argreg = FPA0_REGNUM;
3481 /* The struct_return pointer occupies the first parameter-passing reg. */
3485 fprintf_unfiltered (gdb_stdlog,
3486 "mips_o64_push_arguments: struct_return reg=%d 0x%s\n",
3487 argreg, paddr_nz (struct_addr));
3488 write_register (argreg++, struct_addr);
3489 stack_offset += MIPS_STACK_ARGSIZE;
3492 /* Now load as many as possible of the first arguments into
3493 registers, and push the rest onto the stack. Loop thru args
3494 from first to last. */
3495 for (argnum = 0; argnum < nargs; argnum++)
3498 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3499 struct value *arg = args[argnum];
3500 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3501 int len = TYPE_LENGTH (arg_type);
3502 enum type_code typecode = TYPE_CODE (arg_type);
3505 fprintf_unfiltered (gdb_stdlog,
3506 "mips_o64_push_arguments: %d len=%d type=%d",
3507 argnum + 1, len, (int) typecode);
3509 val = (char *) VALUE_CONTENTS (arg);
3511 /* 32-bit ABIs always start floating point arguments in an
3512 even-numbered floating point register. Round the FP register
3513 up before the check to see if there are any FP registers
3514 left. O32/O64 targets also pass the FP in the integer
3515 registers so also round up normal registers. */
3516 if (!FP_REGISTER_DOUBLE
3517 && fp_register_arg_p (typecode, arg_type))
3519 if ((float_argreg & 1))
3523 /* Floating point arguments passed in registers have to be
3524 treated specially. On 32-bit architectures, doubles
3525 are passed in register pairs; the even register gets
3526 the low word, and the odd register gets the high word.
3527 On O32/O64, the first two floating point arguments are
3528 also copied to general registers, because MIPS16 functions
3529 don't use float registers for arguments. This duplication of
3530 arguments in general registers can't hurt non-MIPS16 functions
3531 because those registers are normally skipped. */
3533 if (fp_register_arg_p (typecode, arg_type)
3534 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3536 if (!FP_REGISTER_DOUBLE && len == 8)
3538 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3539 unsigned long regval;
3541 /* Write the low word of the double to the even register(s). */
3542 regval = extract_unsigned_integer (val + low_offset, 4);
3544 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3545 float_argreg, phex (regval, 4));
3546 write_register (float_argreg++, regval);
3548 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3549 argreg, phex (regval, 4));
3550 write_register (argreg++, regval);
3552 /* Write the high word of the double to the odd register(s). */
3553 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3555 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3556 float_argreg, phex (regval, 4));
3557 write_register (float_argreg++, regval);
3560 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3561 argreg, phex (regval, 4));
3562 write_register (argreg++, regval);
3566 /* This is a floating point value that fits entirely
3567 in a single register. */
3568 /* On 32 bit ABI's the float_argreg is further adjusted
3569 above to ensure that it is even register aligned. */
3570 LONGEST regval = extract_unsigned_integer (val, len);
3572 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3573 float_argreg, phex (regval, len));
3574 write_register (float_argreg++, regval);
3575 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3576 registers for each argument. The below is (my
3577 guess) to ensure that the corresponding integer
3578 register has reserved the same space. */
3580 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3581 argreg, phex (regval, len));
3582 write_register (argreg, regval);
3583 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3585 /* Reserve space for the FP register. */
3586 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3590 /* Copy the argument to general registers or the stack in
3591 register-sized pieces. Large arguments are split between
3592 registers and stack. */
3593 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3594 are treated specially: Irix cc passes them in registers
3595 where gcc sometimes puts them on the stack. For maximum
3596 compatibility, we will put them in both places. */
3597 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3598 (len % MIPS_SAVED_REGSIZE != 0));
3599 /* Structures should be aligned to eight bytes (even arg registers)
3600 on MIPS_ABI_O32, if their first member has double precision. */
3601 if (MIPS_SAVED_REGSIZE < 8
3602 && mips_type_needs_double_align (arg_type))
3607 /* Note: Floating-point values that didn't fit into an FP
3608 register are only written to memory. */
3611 /* Remember if the argument was written to the stack. */
3612 int stack_used_p = 0;
3614 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3617 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3620 /* Write this portion of the argument to the stack. */
3621 if (argreg > MIPS_LAST_ARG_REGNUM
3623 || fp_register_arg_p (typecode, arg_type))
3625 /* Should shorter than int integer values be
3626 promoted to int before being stored? */
3627 int longword_offset = 0;
3630 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3632 if (MIPS_STACK_ARGSIZE == 8 &&
3633 (typecode == TYPE_CODE_INT ||
3634 typecode == TYPE_CODE_PTR ||
3635 typecode == TYPE_CODE_FLT) && len <= 4)
3636 longword_offset = MIPS_STACK_ARGSIZE - len;
3641 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3642 paddr_nz (stack_offset));
3643 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3644 paddr_nz (longword_offset));
3647 addr = sp + stack_offset + longword_offset;
3652 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3654 for (i = 0; i < partial_len; i++)
3656 fprintf_unfiltered (gdb_stdlog, "%02x",
3660 write_memory (addr, val, partial_len);
3663 /* Note!!! This is NOT an else clause. Odd sized
3664 structs may go thru BOTH paths. Floating point
3665 arguments will not. */
3666 /* Write this portion of the argument to a general
3667 purpose register. */
3668 if (argreg <= MIPS_LAST_ARG_REGNUM
3669 && !fp_register_arg_p (typecode, arg_type))
3671 LONGEST regval = extract_signed_integer (val, partial_len);
3672 /* Value may need to be sign extended, because
3673 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3675 /* A non-floating-point argument being passed in a
3676 general register. If a struct or union, and if
3677 the remaining length is smaller than the register
3678 size, we have to adjust the register value on
3681 It does not seem to be necessary to do the
3682 same for integral types.
3684 Also don't do this adjustment on O64 binaries.
3686 cagney/2001-07-23: gdb/179: Also, GCC, when
3687 outputting LE O32 with sizeof (struct) <
3688 MIPS_SAVED_REGSIZE, generates a left shift as
3689 part of storing the argument in a register a
3690 register (the left shift isn't generated when
3691 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3692 is quite possible that this is GCC contradicting
3693 the LE/O32 ABI, GDB has not been adjusted to
3694 accommodate this. Either someone needs to
3695 demonstrate that the LE/O32 ABI specifies such a
3696 left shift OR this new ABI gets identified as
3697 such and GDB gets tweaked accordingly. */
3699 if (MIPS_SAVED_REGSIZE < 8
3700 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3701 && partial_len < MIPS_SAVED_REGSIZE
3702 && (typecode == TYPE_CODE_STRUCT ||
3703 typecode == TYPE_CODE_UNION))
3704 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3708 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3710 phex (regval, MIPS_SAVED_REGSIZE));
3711 write_register (argreg, regval);
3714 /* Prevent subsequent floating point arguments from
3715 being passed in floating point registers. */
3716 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3722 /* Compute the the offset into the stack at which we
3723 will copy the next parameter.
3725 In older ABIs, the caller reserved space for
3726 registers that contained arguments. This was loosely
3727 refered to as their "home". Consequently, space is
3728 always allocated. */
3730 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3734 fprintf_unfiltered (gdb_stdlog, "\n");
3737 /* Return adjusted stack pointer. */
3742 mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
3744 /* Set the return address register to point to the entry
3745 point of the program, where a breakpoint lies in wait. */
3746 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
3751 mips_push_register (CORE_ADDR * sp, int regno)
3753 char *buffer = alloca (MAX_REGISTER_RAW_SIZE);
3756 if (MIPS_SAVED_REGSIZE < REGISTER_RAW_SIZE (regno))
3758 regsize = MIPS_SAVED_REGSIZE;
3759 offset = (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3760 ? REGISTER_RAW_SIZE (regno) - MIPS_SAVED_REGSIZE
3765 regsize = REGISTER_RAW_SIZE (regno);
3769 deprecated_read_register_gen (regno, buffer);
3770 write_memory (*sp, buffer + offset, regsize);
3773 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
3774 #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
3777 mips_push_dummy_frame (void)
3780 struct linked_proc_info *link = (struct linked_proc_info *)
3781 xmalloc (sizeof (struct linked_proc_info));
3782 mips_extra_func_info_t proc_desc = &link->info;
3783 CORE_ADDR sp = ADDR_BITS_REMOVE (read_signed_register (SP_REGNUM));
3784 CORE_ADDR old_sp = sp;
3785 link->next = linked_proc_desc_table;
3786 linked_proc_desc_table = link;
3788 /* FIXME! are these correct ? */
3789 #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
3790 #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
3791 #define FLOAT_REG_SAVE_MASK MASK(0,19)
3792 #define FLOAT_SINGLE_REG_SAVE_MASK \
3793 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
3795 * The registers we must save are all those not preserved across
3796 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
3797 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
3798 * and FP Control/Status registers.
3801 * Dummy frame layout:
3804 * Saved MMHI, MMLO, FPC_CSR
3809 * Saved D18 (i.e. F19, F18)
3811 * Saved D0 (i.e. F1, F0)
3812 * Argument build area and stack arguments written via mips_push_arguments
3816 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
3817 PROC_FRAME_REG (proc_desc) = PUSH_FP_REGNUM;
3818 PROC_FRAME_OFFSET (proc_desc) = 0;
3819 PROC_FRAME_ADJUST (proc_desc) = 0;
3820 mips_push_register (&sp, PC_REGNUM);
3821 mips_push_register (&sp, HI_REGNUM);
3822 mips_push_register (&sp, LO_REGNUM);
3823 mips_push_register (&sp, MIPS_FPU_TYPE == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
3825 /* Save general CPU registers */
3826 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
3827 /* PROC_REG_OFFSET is the offset of the first saved register from FP. */
3828 PROC_REG_OFFSET (proc_desc) = sp - old_sp - MIPS_SAVED_REGSIZE;
3829 for (ireg = 32; --ireg >= 0;)
3830 if (PROC_REG_MASK (proc_desc) & (1 << ireg))
3831 mips_push_register (&sp, ireg);
3833 /* Save floating point registers starting with high order word */
3834 PROC_FREG_MASK (proc_desc) =
3835 MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
3836 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
3837 /* PROC_FREG_OFFSET is the offset of the first saved *double* register
3839 PROC_FREG_OFFSET (proc_desc) = sp - old_sp - 8;
3840 for (ireg = 32; --ireg >= 0;)
3841 if (PROC_FREG_MASK (proc_desc) & (1 << ireg))
3842 mips_push_register (&sp, ireg + FP0_REGNUM);
3844 /* Update the frame pointer for the call dummy and the stack pointer.
3845 Set the procedure's starting and ending addresses to point to the
3846 call dummy address at the entry point. */
3847 write_register (PUSH_FP_REGNUM, old_sp);
3848 write_register (SP_REGNUM, sp);
3849 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
3850 PROC_HIGH_ADDR (proc_desc) = CALL_DUMMY_ADDRESS () + 4;
3851 SET_PROC_DESC_IS_DUMMY (proc_desc);
3852 PROC_PC_REG (proc_desc) = RA_REGNUM;
3856 mips_pop_frame (void)
3858 register int regnum;
3859 struct frame_info *frame = get_current_frame ();
3860 CORE_ADDR new_sp = get_frame_base (frame);
3861 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
3863 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3865 generic_pop_dummy_frame ();
3866 flush_cached_frames ();
3870 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3871 if (get_frame_saved_regs (frame) == NULL)
3872 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3873 for (regnum = 0; regnum < NUM_REGS; regnum++)
3874 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3875 && get_frame_saved_regs (frame)[regnum])
3877 /* Floating point registers must not be sign extended,
3878 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3880 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3881 write_register (regnum,
3882 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3883 MIPS_SAVED_REGSIZE));
3885 write_register (regnum,
3886 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3887 MIPS_SAVED_REGSIZE));
3890 write_register (SP_REGNUM, new_sp);
3891 flush_cached_frames ();
3893 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3895 struct linked_proc_info *pi_ptr, *prev_ptr;
3897 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3899 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3901 if (&pi_ptr->info == proc_desc)
3906 error ("Can't locate dummy extra frame info\n");
3908 if (prev_ptr != NULL)
3909 prev_ptr->next = pi_ptr->next;
3911 linked_proc_desc_table = pi_ptr->next;
3915 write_register (HI_REGNUM,
3916 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3917 MIPS_SAVED_REGSIZE));
3918 write_register (LO_REGNUM,
3919 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3920 MIPS_SAVED_REGSIZE));
3921 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3922 write_register (FCRCS_REGNUM,
3923 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3924 MIPS_SAVED_REGSIZE));
3929 mips_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
3930 struct value **args, struct type *type, int gcc_p)
3932 write_register(T9_REGNUM, fun);
3935 /* Floating point register management.
3937 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3938 64bit operations, these early MIPS cpus treat fp register pairs
3939 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3940 registers and offer a compatibility mode that emulates the MIPS2 fp
3941 model. When operating in MIPS2 fp compat mode, later cpu's split
3942 double precision floats into two 32-bit chunks and store them in
3943 consecutive fp regs. To display 64-bit floats stored in this
3944 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3945 Throw in user-configurable endianness and you have a real mess.
3947 The way this works is:
3948 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3949 double-precision value will be split across two logical registers.
3950 The lower-numbered logical register will hold the low-order bits,
3951 regardless of the processor's endianness.
3952 - If we are on a 64-bit processor, and we are looking for a
3953 single-precision value, it will be in the low ordered bits
3954 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3955 save slot in memory.
3956 - If we are in 64-bit mode, everything is straightforward.
3958 Note that this code only deals with "live" registers at the top of the
3959 stack. We will attempt to deal with saved registers later, when
3960 the raw/cooked register interface is in place. (We need a general
3961 interface that can deal with dynamic saved register sizes -- fp
3962 regs could be 32 bits wide in one frame and 64 on the frame above
3965 static struct type *
3966 mips_float_register_type (void)
3968 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3969 return builtin_type_ieee_single_big;
3971 return builtin_type_ieee_single_little;
3974 static struct type *
3975 mips_double_register_type (void)
3977 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3978 return builtin_type_ieee_double_big;
3980 return builtin_type_ieee_double_little;
3983 /* Copy a 32-bit single-precision value from the current frame
3984 into rare_buffer. */
3987 mips_read_fp_register_single (int regno, char *rare_buffer)
3989 int raw_size = REGISTER_RAW_SIZE (regno);
3990 char *raw_buffer = alloca (raw_size);
3992 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3993 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3996 /* We have a 64-bit value for this register. Find the low-order
4000 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4005 memcpy (rare_buffer, raw_buffer + offset, 4);
4009 memcpy (rare_buffer, raw_buffer, 4);
4013 /* Copy a 64-bit double-precision value from the current frame into
4014 rare_buffer. This may include getting half of it from the next
4018 mips_read_fp_register_double (int regno, char *rare_buffer)
4020 int raw_size = REGISTER_RAW_SIZE (regno);
4022 if (raw_size == 8 && !mips2_fp_compat ())
4024 /* We have a 64-bit value for this register, and we should use
4026 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
4027 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4031 if ((regno - FP0_REGNUM) & 1)
4032 internal_error (__FILE__, __LINE__,
4033 "mips_read_fp_register_double: bad access to "
4034 "odd-numbered FP register");
4036 /* mips_read_fp_register_single will find the correct 32 bits from
4038 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4040 mips_read_fp_register_single (regno, rare_buffer + 4);
4041 mips_read_fp_register_single (regno + 1, rare_buffer);
4045 mips_read_fp_register_single (regno, rare_buffer);
4046 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
4052 mips_print_fp_register (int regnum)
4053 { /* do values for FP (float) regs */
4055 double doub, flt1, flt2; /* doubles extracted from raw hex data */
4056 int inv1, inv2, namelen;
4058 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
4060 printf_filtered ("%s:", REGISTER_NAME (regnum));
4061 printf_filtered ("%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), "");
4063 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4065 /* 4-byte registers: Print hex and floating. Also print even
4066 numbered registers as doubles. */
4067 mips_read_fp_register_single (regnum, raw_buffer);
4068 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4070 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
4073 printf_filtered (" flt: ");
4075 printf_filtered (" <invalid float> ");
4077 printf_filtered ("%-17.9g", flt1);
4079 if (regnum % 2 == 0)
4081 mips_read_fp_register_double (regnum, raw_buffer);
4082 doub = unpack_double (mips_double_register_type (), raw_buffer,
4085 printf_filtered (" dbl: ");
4087 printf_filtered ("<invalid double>");
4089 printf_filtered ("%-24.17g", doub);
4094 /* Eight byte registers: print each one as hex, float and double. */
4095 mips_read_fp_register_single (regnum, raw_buffer);
4096 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4098 mips_read_fp_register_double (regnum, raw_buffer);
4099 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4102 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4105 printf_filtered (" flt: ");
4107 printf_filtered ("<invalid float>");
4109 printf_filtered ("%-17.9g", flt1);
4111 printf_filtered (" dbl: ");
4113 printf_filtered ("<invalid double>");
4115 printf_filtered ("%-24.17g", doub);
4120 mips_print_register (int regnum, int all)
4122 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4125 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4127 mips_print_fp_register (regnum);
4131 /* Get the data in raw format. */
4132 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4134 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4138 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4140 /* The problem with printing numeric register names (r26, etc.) is that
4141 the user can't use them on input. Probably the best solution is to
4142 fix it so that either the numeric or the funky (a2, etc.) names
4143 are accepted on input. */
4144 if (regnum < MIPS_NUMREGS)
4145 printf_filtered ("(r%d): ", regnum);
4147 printf_filtered (": ");
4149 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4150 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4154 print_scalar_formatted (raw_buffer + offset,
4155 REGISTER_VIRTUAL_TYPE (regnum),
4156 'x', 0, gdb_stdout);
4159 /* Replacement for generic do_registers_info.
4160 Print regs in pretty columns. */
4163 do_fp_register_row (int regnum)
4165 printf_filtered (" ");
4166 mips_print_fp_register (regnum);
4167 printf_filtered ("\n");
4172 /* Print a row's worth of GP (int) registers, with name labels above */
4175 do_gp_register_row (int regnum)
4177 /* do values for GP (int) regs */
4178 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4179 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4181 int start_regnum = regnum;
4182 int numregs = NUM_REGS;
4185 /* For GP registers, we print a separate row of names above the vals */
4186 printf_filtered (" ");
4187 for (col = 0; col < ncols && regnum < numregs; regnum++)
4189 if (*REGISTER_NAME (regnum) == '\0')
4190 continue; /* unused register */
4191 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4192 break; /* end the row: reached FP register */
4193 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4194 REGISTER_NAME (regnum));
4197 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4198 start_regnum); /* print the R0 to R31 names */
4200 regnum = start_regnum; /* go back to start of row */
4201 /* now print the values in hex, 4 or 8 to the row */
4202 for (col = 0; col < ncols && regnum < numregs; regnum++)
4204 if (*REGISTER_NAME (regnum) == '\0')
4205 continue; /* unused register */
4206 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4207 break; /* end row: reached FP register */
4208 /* OK: get the data in raw format. */
4209 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4210 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4211 /* pad small registers */
4212 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4213 printf_filtered (" ");
4214 /* Now print the register value in hex, endian order. */
4215 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4216 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4217 byte < REGISTER_RAW_SIZE (regnum);
4219 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4221 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4224 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4225 printf_filtered (" ");
4228 if (col > 0) /* ie. if we actually printed anything... */
4229 printf_filtered ("\n");
4234 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4237 mips_do_registers_info (int regnum, int fpregs)
4239 if (regnum != -1) /* do one specified register */
4241 if (*(REGISTER_NAME (regnum)) == '\0')
4242 error ("Not a valid register for the current processor type");
4244 mips_print_register (regnum, 0);
4245 printf_filtered ("\n");
4248 /* do all (or most) registers */
4251 while (regnum < NUM_REGS)
4253 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4254 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4255 regnum = do_fp_register_row (regnum); /* FP regs */
4257 regnum += MIPS_NUMREGS; /* skip floating point regs */
4259 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4264 /* Is this a branch with a delay slot? */
4266 static int is_delayed (unsigned long);
4269 is_delayed (unsigned long insn)
4272 for (i = 0; i < NUMOPCODES; ++i)
4273 if (mips_opcodes[i].pinfo != INSN_MACRO
4274 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4276 return (i < NUMOPCODES
4277 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4278 | INSN_COND_BRANCH_DELAY
4279 | INSN_COND_BRANCH_LIKELY)));
4283 mips_step_skips_delay (CORE_ADDR pc)
4285 char buf[MIPS_INSTLEN];
4287 /* There is no branch delay slot on MIPS16. */
4288 if (pc_is_mips16 (pc))
4291 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4292 /* If error reading memory, guess that it is not a delayed branch. */
4294 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4298 /* Skip the PC past function prologue instructions (32-bit version).
4299 This is a helper function for mips_skip_prologue. */
4302 mips32_skip_prologue (CORE_ADDR pc)
4306 int seen_sp_adjust = 0;
4307 int load_immediate_bytes = 0;
4309 /* Skip the typical prologue instructions. These are the stack adjustment
4310 instruction and the instructions that save registers on the stack
4311 or in the gcc frame. */
4312 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4314 unsigned long high_word;
4316 inst = mips_fetch_instruction (pc);
4317 high_word = (inst >> 16) & 0xffff;
4319 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4320 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4322 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4323 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4325 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4326 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4327 && (inst & 0x001F0000)) /* reg != $zero */
4330 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4332 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4334 continue; /* reg != $zero */
4336 /* move $s8,$sp. With different versions of gas this will be either
4337 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4338 Accept any one of these. */
4339 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4342 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4344 else if (high_word == 0x3c1c) /* lui $gp,n */
4346 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4348 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4349 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4351 /* The following instructions load $at or $t0 with an immediate
4352 value in preparation for a stack adjustment via
4353 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4354 a local variable, so we accept them only before a stack adjustment
4355 instruction was seen. */
4356 else if (!seen_sp_adjust)
4358 if (high_word == 0x3c01 || /* lui $at,n */
4359 high_word == 0x3c08) /* lui $t0,n */
4361 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4364 else if (high_word == 0x3421 || /* ori $at,$at,n */
4365 high_word == 0x3508 || /* ori $t0,$t0,n */
4366 high_word == 0x3401 || /* ori $at,$zero,n */
4367 high_word == 0x3408) /* ori $t0,$zero,n */
4369 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4379 /* In a frameless function, we might have incorrectly
4380 skipped some load immediate instructions. Undo the skipping
4381 if the load immediate was not followed by a stack adjustment. */
4382 if (load_immediate_bytes && !seen_sp_adjust)
4383 pc -= load_immediate_bytes;
4387 /* Skip the PC past function prologue instructions (16-bit version).
4388 This is a helper function for mips_skip_prologue. */
4391 mips16_skip_prologue (CORE_ADDR pc)
4394 int extend_bytes = 0;
4395 int prev_extend_bytes;
4397 /* Table of instructions likely to be found in a function prologue. */
4400 unsigned short inst;
4401 unsigned short mask;
4408 , /* addiu $sp,offset */
4412 , /* daddiu $sp,offset */
4416 , /* sw reg,n($sp) */
4420 , /* sd reg,n($sp) */
4424 , /* sw $ra,n($sp) */
4428 , /* sd $ra,n($sp) */
4436 , /* sw $a0-$a3,n($s1) */
4440 , /* move reg,$a0-$a3 */
4444 , /* entry pseudo-op */
4448 , /* addiu $s1,$sp,n */
4451 } /* end of table marker */
4454 /* Skip the typical prologue instructions. These are the stack adjustment
4455 instruction and the instructions that save registers on the stack
4456 or in the gcc frame. */
4457 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4459 unsigned short inst;
4462 inst = mips_fetch_instruction (pc);
4464 /* Normally we ignore an extend instruction. However, if it is
4465 not followed by a valid prologue instruction, we must adjust
4466 the pc back over the extend so that it won't be considered
4467 part of the prologue. */
4468 if ((inst & 0xf800) == 0xf000) /* extend */
4470 extend_bytes = MIPS16_INSTLEN;
4473 prev_extend_bytes = extend_bytes;
4476 /* Check for other valid prologue instructions besides extend. */
4477 for (i = 0; table[i].mask != 0; i++)
4478 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4480 if (table[i].mask != 0) /* it was in table? */
4481 continue; /* ignore it */
4485 /* Return the current pc, adjusted backwards by 2 if
4486 the previous instruction was an extend. */
4487 return pc - prev_extend_bytes;
4493 /* To skip prologues, I use this predicate. Returns either PC itself
4494 if the code at PC does not look like a function prologue; otherwise
4495 returns an address that (if we're lucky) follows the prologue. If
4496 LENIENT, then we must skip everything which is involved in setting
4497 up the frame (it's OK to skip more, just so long as we don't skip
4498 anything which might clobber the registers which are being saved.
4499 We must skip more in the case where part of the prologue is in the
4500 delay slot of a non-prologue instruction). */
4503 mips_skip_prologue (CORE_ADDR pc)
4505 /* See if we can determine the end of the prologue via the symbol table.
4506 If so, then return either PC, or the PC after the prologue, whichever
4509 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4511 if (post_prologue_pc != 0)
4512 return max (pc, post_prologue_pc);
4514 /* Can't determine prologue from the symbol table, need to examine
4517 if (pc_is_mips16 (pc))
4518 return mips16_skip_prologue (pc);
4520 return mips32_skip_prologue (pc);
4523 /* Determine how a return value is stored within the MIPS register
4524 file, given the return type `valtype'. */
4526 struct return_value_word
4535 return_value_location (struct type *valtype,
4536 struct return_value_word *hi,
4537 struct return_value_word *lo)
4539 int len = TYPE_LENGTH (valtype);
4541 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4542 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4543 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4545 if (!FP_REGISTER_DOUBLE && len == 8)
4547 /* We need to break a 64bit float in two 32 bit halves and
4548 spread them across a floating-point register pair. */
4549 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4550 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4551 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4552 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4554 hi->reg_offset = lo->reg_offset;
4555 lo->reg = FP0_REGNUM + 0;
4556 hi->reg = FP0_REGNUM + 1;
4562 /* The floating point value fits in a single floating-point
4564 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4565 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4568 lo->reg = FP0_REGNUM;
4579 /* Locate a result possibly spread across two registers. */
4581 lo->reg = regnum + 0;
4582 hi->reg = regnum + 1;
4583 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4584 && len < MIPS_SAVED_REGSIZE)
4586 /* "un-left-justify" the value in the low register */
4587 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4592 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4593 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4594 && len < MIPS_SAVED_REGSIZE * 2
4595 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4596 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4598 /* "un-left-justify" the value spread across two registers. */
4599 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4600 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4602 hi->len = len - lo->len;
4606 /* Only perform a partial copy of the second register. */
4609 if (len > MIPS_SAVED_REGSIZE)
4611 lo->len = MIPS_SAVED_REGSIZE;
4612 hi->len = len - MIPS_SAVED_REGSIZE;
4620 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4621 && REGISTER_RAW_SIZE (regnum) == 8
4622 && MIPS_SAVED_REGSIZE == 4)
4624 /* Account for the fact that only the least-signficant part
4625 of the register is being used */
4626 lo->reg_offset += 4;
4627 hi->reg_offset += 4;
4630 hi->buf_offset = lo->len;
4634 /* Given a return value in `regbuf' with a type `valtype', extract and
4635 copy its value into `valbuf'. */
4638 mips_eabi_extract_return_value (struct type *valtype,
4639 char regbuf[REGISTER_BYTES],
4642 struct return_value_word lo;
4643 struct return_value_word hi;
4644 return_value_location (valtype, &hi, &lo);
4646 memcpy (valbuf + lo.buf_offset,
4647 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4651 memcpy (valbuf + hi.buf_offset,
4652 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4657 mips_o64_extract_return_value (struct type *valtype,
4658 char regbuf[REGISTER_BYTES],
4661 struct return_value_word lo;
4662 struct return_value_word hi;
4663 return_value_location (valtype, &hi, &lo);
4665 memcpy (valbuf + lo.buf_offset,
4666 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4670 memcpy (valbuf + hi.buf_offset,
4671 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4675 /* Given a return value in `valbuf' with a type `valtype', write it's
4676 value into the appropriate register. */
4679 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4681 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4682 struct return_value_word lo;
4683 struct return_value_word hi;
4684 return_value_location (valtype, &hi, &lo);
4686 memset (raw_buffer, 0, sizeof (raw_buffer));
4687 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4688 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4689 REGISTER_RAW_SIZE (lo.reg));
4693 memset (raw_buffer, 0, sizeof (raw_buffer));
4694 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4695 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4696 REGISTER_RAW_SIZE (hi.reg));
4701 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4703 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4704 struct return_value_word lo;
4705 struct return_value_word hi;
4706 return_value_location (valtype, &hi, &lo);
4708 memset (raw_buffer, 0, sizeof (raw_buffer));
4709 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4710 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4711 REGISTER_RAW_SIZE (lo.reg));
4715 memset (raw_buffer, 0, sizeof (raw_buffer));
4716 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4717 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4718 REGISTER_RAW_SIZE (hi.reg));
4722 /* O32 ABI stuff. */
4725 mips_o32_xfer_return_value (struct type *type,
4726 struct regcache *regcache,
4727 bfd_byte *in, const bfd_byte *out)
4729 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4730 if (TYPE_CODE (type) == TYPE_CODE_FLT
4731 && TYPE_LENGTH (type) == 4
4732 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4734 /* A single-precision floating-point value. It fits in the
4735 least significant part of FP0. */
4737 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4738 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4739 TARGET_BYTE_ORDER, in, out, 0);
4741 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4742 && TYPE_LENGTH (type) == 8
4743 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4745 /* A double-precision floating-point value. It fits in the
4746 least significant part of FP0/FP1 but with byte ordering
4747 based on the target (???). */
4749 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4750 switch (TARGET_BYTE_ORDER)
4752 case BFD_ENDIAN_LITTLE:
4753 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4754 TARGET_BYTE_ORDER, in, out, 0);
4755 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4756 TARGET_BYTE_ORDER, in, out, 4);
4758 case BFD_ENDIAN_BIG:
4759 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4760 TARGET_BYTE_ORDER, in, out, 0);
4761 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4762 TARGET_BYTE_ORDER, in, out, 4);
4765 internal_error (__FILE__, __LINE__, "bad switch");
4769 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4770 && TYPE_NFIELDS (type) <= 2
4771 && TYPE_NFIELDS (type) >= 1
4772 && ((TYPE_NFIELDS (type) == 1
4773 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4775 || (TYPE_NFIELDS (type) == 2
4776 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4778 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4780 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4782 /* A struct that contains one or two floats. Each value is part
4783 in the least significant part of their floating point
4785 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4788 for (field = 0, regnum = FP0_REGNUM;
4789 field < TYPE_NFIELDS (type);
4790 field++, regnum += 2)
4792 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4795 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4796 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4797 TARGET_BYTE_ORDER, in, out, offset);
4802 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4803 || TYPE_CODE (type) == TYPE_CODE_UNION)
4805 /* A structure or union. Extract the left justified value,
4806 regardless of the byte order. I.e. DO NOT USE
4810 for (offset = 0, regnum = V0_REGNUM;
4811 offset < TYPE_LENGTH (type);
4812 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4814 int xfer = REGISTER_RAW_SIZE (regnum);
4815 if (offset + xfer > TYPE_LENGTH (type))
4816 xfer = TYPE_LENGTH (type) - offset;
4818 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4819 offset, xfer, regnum);
4820 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4827 /* A scalar extract each part but least-significant-byte
4828 justified. o32 thinks registers are 4 byte, regardless of
4829 the ISA. mips_stack_argsize controls this. */
4832 for (offset = 0, regnum = V0_REGNUM;
4833 offset < TYPE_LENGTH (type);
4834 offset += mips_stack_argsize (), regnum++)
4836 int xfer = mips_stack_argsize ();
4838 if (offset + xfer > TYPE_LENGTH (type))
4839 xfer = TYPE_LENGTH (type) - offset;
4841 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4842 offset, xfer, regnum);
4843 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4850 mips_o32_extract_return_value (struct type *type,
4851 struct regcache *regcache,
4854 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4858 mips_o32_store_return_value (struct type *type, char *valbuf)
4860 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4863 /* N32/N44 ABI stuff. */
4866 mips_n32n64_xfer_return_value (struct type *type,
4867 struct regcache *regcache,
4868 bfd_byte *in, const bfd_byte *out)
4870 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4871 if (TYPE_CODE (type) == TYPE_CODE_FLT
4872 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4874 /* A floating-point value belongs in the least significant part
4877 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4878 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4879 TARGET_BYTE_ORDER, in, out, 0);
4881 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4882 && TYPE_NFIELDS (type) <= 2
4883 && TYPE_NFIELDS (type) >= 1
4884 && ((TYPE_NFIELDS (type) == 1
4885 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4887 || (TYPE_NFIELDS (type) == 2
4888 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4890 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4892 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4894 /* A struct that contains one or two floats. Each value is part
4895 in the least significant part of their floating point
4897 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4900 for (field = 0, regnum = FP0_REGNUM;
4901 field < TYPE_NFIELDS (type);
4902 field++, regnum += 2)
4904 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4907 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4908 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4909 TARGET_BYTE_ORDER, in, out, offset);
4912 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4913 || TYPE_CODE (type) == TYPE_CODE_UNION)
4915 /* A structure or union. Extract the left justified value,
4916 regardless of the byte order. I.e. DO NOT USE
4920 for (offset = 0, regnum = V0_REGNUM;
4921 offset < TYPE_LENGTH (type);
4922 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4924 int xfer = REGISTER_RAW_SIZE (regnum);
4925 if (offset + xfer > TYPE_LENGTH (type))
4926 xfer = TYPE_LENGTH (type) - offset;
4928 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4929 offset, xfer, regnum);
4930 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4936 /* A scalar extract each part but least-significant-byte
4940 for (offset = 0, regnum = V0_REGNUM;
4941 offset < TYPE_LENGTH (type);
4942 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4944 int xfer = REGISTER_RAW_SIZE (regnum);
4946 if (offset + xfer > TYPE_LENGTH (type))
4947 xfer = TYPE_LENGTH (type) - offset;
4949 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4950 offset, xfer, regnum);
4951 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4958 mips_n32n64_extract_return_value (struct type *type,
4959 struct regcache *regcache,
4962 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4966 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4968 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4972 mips_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
4974 /* Nothing to do -- push_arguments does all the work. */
4978 mips_extract_struct_value_address (struct regcache *regcache)
4980 /* FIXME: This will only work at random. The caller passes the
4981 struct_return address in V0, but it is not preserved. It may
4982 still be there, or this may be a random value. */
4985 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4989 /* Exported procedure: Is PC in the signal trampoline code */
4992 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4994 if (sigtramp_address == 0)
4996 return (pc >= sigtramp_address && pc < sigtramp_end);
4999 /* Root of all "set mips "/"show mips " commands. This will eventually be
5000 used for all MIPS-specific commands. */
5003 show_mips_command (char *args, int from_tty)
5005 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5009 set_mips_command (char *args, int from_tty)
5011 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
5012 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5015 /* Commands to show/set the MIPS FPU type. */
5018 show_mipsfpu_command (char *args, int from_tty)
5021 switch (MIPS_FPU_TYPE)
5023 case MIPS_FPU_SINGLE:
5024 fpu = "single-precision";
5026 case MIPS_FPU_DOUBLE:
5027 fpu = "double-precision";
5030 fpu = "absent (none)";
5033 internal_error (__FILE__, __LINE__, "bad switch");
5035 if (mips_fpu_type_auto)
5036 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5039 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5045 set_mipsfpu_command (char *args, int from_tty)
5047 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5048 show_mipsfpu_command (args, from_tty);
5052 set_mipsfpu_single_command (char *args, int from_tty)
5054 mips_fpu_type = MIPS_FPU_SINGLE;
5055 mips_fpu_type_auto = 0;
5056 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5060 set_mipsfpu_double_command (char *args, int from_tty)
5062 mips_fpu_type = MIPS_FPU_DOUBLE;
5063 mips_fpu_type_auto = 0;
5064 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5068 set_mipsfpu_none_command (char *args, int from_tty)
5070 mips_fpu_type = MIPS_FPU_NONE;
5071 mips_fpu_type_auto = 0;
5072 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5076 set_mipsfpu_auto_command (char *args, int from_tty)
5078 mips_fpu_type_auto = 1;
5081 /* Command to set the processor type. */
5084 mips_set_processor_type_command (char *args, int from_tty)
5088 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5090 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5091 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5092 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5094 /* Restore the value. */
5095 tmp_mips_processor_type = xstrdup (mips_processor_type);
5100 if (!mips_set_processor_type (tmp_mips_processor_type))
5102 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5103 /* Restore its value. */
5104 tmp_mips_processor_type = xstrdup (mips_processor_type);
5109 mips_show_processor_type_command (char *args, int from_tty)
5113 /* Modify the actual processor type. */
5116 mips_set_processor_type (char *str)
5123 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5125 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5127 mips_processor_type = str;
5128 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5130 /* FIXME tweak fpu flag too */
5137 /* Attempt to identify the particular processor model by reading the
5141 mips_read_processor_type (void)
5145 prid = read_register (PRID_REGNUM);
5147 if ((prid & ~0xf) == 0x700)
5148 return savestring ("r3041", strlen ("r3041"));
5153 /* Just like reinit_frame_cache, but with the right arguments to be
5154 callable as an sfunc. */
5157 reinit_frame_cache_sfunc (char *args, int from_tty,
5158 struct cmd_list_element *c)
5160 reinit_frame_cache ();
5164 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5166 mips_extra_func_info_t proc_desc;
5168 /* Search for the function containing this address. Set the low bit
5169 of the address when searching, in case we were given an even address
5170 that is the start of a 16-bit function. If we didn't do this,
5171 the search would fail because the symbol table says the function
5172 starts at an odd address, i.e. 1 byte past the given address. */
5173 memaddr = ADDR_BITS_REMOVE (memaddr);
5174 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5176 /* Make an attempt to determine if this is a 16-bit function. If
5177 the procedure descriptor exists and the address therein is odd,
5178 it's definitely a 16-bit function. Otherwise, we have to just
5179 guess that if the address passed in is odd, it's 16-bits. */
5181 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5182 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5184 info->mach = pc_is_mips16 (memaddr) ?
5185 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5187 /* Round down the instruction address to the appropriate boundary. */
5188 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5190 /* Call the appropriate disassembler based on the target endian-ness. */
5191 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5192 return print_insn_big_mips (memaddr, info);
5194 return print_insn_little_mips (memaddr, info);
5197 /* Old-style breakpoint macros.
5198 The IDT board uses an unusual breakpoint value, and sometimes gets
5199 confused when it sees the usual MIPS breakpoint instruction. */
5201 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
5202 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
5203 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
5204 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
5205 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
5206 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
5207 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
5208 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
5210 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5211 counter value to determine whether a 16- or 32-bit breakpoint should be
5212 used. It returns a pointer to a string of bytes that encode a breakpoint
5213 instruction, stores the length of the string to *lenptr, and adjusts pc
5214 (if necessary) to point to the actual memory location where the
5215 breakpoint should be inserted. */
5217 static const unsigned char *
5218 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5220 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5222 if (pc_is_mips16 (*pcptr))
5224 static unsigned char mips16_big_breakpoint[] =
5225 MIPS16_BIG_BREAKPOINT;
5226 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5227 *lenptr = sizeof (mips16_big_breakpoint);
5228 return mips16_big_breakpoint;
5232 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
5233 static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
5234 static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
5236 *lenptr = sizeof (big_breakpoint);
5238 if (strcmp (target_shortname, "mips") == 0)
5239 return idt_big_breakpoint;
5240 else if (strcmp (target_shortname, "ddb") == 0
5241 || strcmp (target_shortname, "pmon") == 0
5242 || strcmp (target_shortname, "lsi") == 0)
5243 return pmon_big_breakpoint;
5245 return big_breakpoint;
5250 if (pc_is_mips16 (*pcptr))
5252 static unsigned char mips16_little_breakpoint[] =
5253 MIPS16_LITTLE_BREAKPOINT;
5254 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5255 *lenptr = sizeof (mips16_little_breakpoint);
5256 return mips16_little_breakpoint;
5260 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
5261 static unsigned char pmon_little_breakpoint[] =
5262 PMON_LITTLE_BREAKPOINT;
5263 static unsigned char idt_little_breakpoint[] =
5264 IDT_LITTLE_BREAKPOINT;
5266 *lenptr = sizeof (little_breakpoint);
5268 if (strcmp (target_shortname, "mips") == 0)
5269 return idt_little_breakpoint;
5270 else if (strcmp (target_shortname, "ddb") == 0
5271 || strcmp (target_shortname, "pmon") == 0
5272 || strcmp (target_shortname, "lsi") == 0)
5273 return pmon_little_breakpoint;
5275 return little_breakpoint;
5280 /* If PC is in a mips16 call or return stub, return the address of the target
5281 PC, which is either the callee or the caller. There are several
5282 cases which must be handled:
5284 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5285 target PC is in $31 ($ra).
5286 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5287 and the target PC is in $2.
5288 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5289 before the jal instruction, this is effectively a call stub
5290 and the the target PC is in $2. Otherwise this is effectively
5291 a return stub and the target PC is in $18.
5293 See the source code for the stubs in gcc/config/mips/mips16.S for
5296 This function implements the SKIP_TRAMPOLINE_CODE macro.
5300 mips_skip_stub (CORE_ADDR pc)
5303 CORE_ADDR start_addr;
5305 /* Find the starting address and name of the function containing the PC. */
5306 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5309 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5310 target PC is in $31 ($ra). */
5311 if (strcmp (name, "__mips16_ret_sf") == 0
5312 || strcmp (name, "__mips16_ret_df") == 0)
5313 return read_signed_register (RA_REGNUM);
5315 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5317 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5318 and the target PC is in $2. */
5319 if (name[19] >= '0' && name[19] <= '9')
5320 return read_signed_register (2);
5322 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5323 before the jal instruction, this is effectively a call stub
5324 and the the target PC is in $2. Otherwise this is effectively
5325 a return stub and the target PC is in $18. */
5326 else if (name[19] == 's' || name[19] == 'd')
5328 if (pc == start_addr)
5330 /* Check if the target of the stub is a compiler-generated
5331 stub. Such a stub for a function bar might have a name
5332 like __fn_stub_bar, and might look like this:
5337 la $1,bar (becomes a lui/addiu pair)
5339 So scan down to the lui/addi and extract the target
5340 address from those two instructions. */
5342 CORE_ADDR target_pc = read_signed_register (2);
5346 /* See if the name of the target function is __fn_stub_*. */
5347 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5349 if (strncmp (name, "__fn_stub_", 10) != 0
5350 && strcmp (name, "etext") != 0
5351 && strcmp (name, "_etext") != 0)
5354 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5355 The limit on the search is arbitrarily set to 20
5356 instructions. FIXME. */
5357 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5359 inst = mips_fetch_instruction (target_pc);
5360 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5361 pc = (inst << 16) & 0xffff0000; /* high word */
5362 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5363 return pc | (inst & 0xffff); /* low word */
5366 /* Couldn't find the lui/addui pair, so return stub address. */
5370 /* This is the 'return' part of a call stub. The return
5371 address is in $r18. */
5372 return read_signed_register (18);
5375 return 0; /* not a stub */
5379 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5380 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5383 mips_in_call_stub (CORE_ADDR pc, char *name)
5385 CORE_ADDR start_addr;
5387 /* Find the starting address of the function containing the PC. If the
5388 caller didn't give us a name, look it up at the same time. */
5389 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5392 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5394 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5395 if (name[19] >= '0' && name[19] <= '9')
5397 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5398 before the jal instruction, this is effectively a call stub. */
5399 else if (name[19] == 's' || name[19] == 'd')
5400 return pc == start_addr;
5403 return 0; /* not a stub */
5407 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5408 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5411 mips_in_return_stub (CORE_ADDR pc, char *name)
5413 CORE_ADDR start_addr;
5415 /* Find the starting address of the function containing the PC. */
5416 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5419 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5420 if (strcmp (name, "__mips16_ret_sf") == 0
5421 || strcmp (name, "__mips16_ret_df") == 0)
5424 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5425 i.e. after the jal instruction, this is effectively a return stub. */
5426 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5427 && (name[19] == 's' || name[19] == 'd')
5428 && pc != start_addr)
5431 return 0; /* not a stub */
5435 /* Return non-zero if the PC is in a library helper function that should
5436 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5439 mips_ignore_helper (CORE_ADDR pc)
5443 /* Find the starting address and name of the function containing the PC. */
5444 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5447 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5448 that we want to ignore. */
5449 return (strcmp (name, "__mips16_ret_sf") == 0
5450 || strcmp (name, "__mips16_ret_df") == 0);
5454 /* Return a location where we can set a breakpoint that will be hit
5455 when an inferior function call returns. This is normally the
5456 program's entry point. Executables that don't have an entry
5457 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5458 whose address is the location where the breakpoint should be placed. */
5461 mips_call_dummy_address (void)
5463 struct minimal_symbol *sym;
5465 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5467 return SYMBOL_VALUE_ADDRESS (sym);
5469 return entry_point_address ();
5473 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5474 the register stored on the stack (32) is different to its real raw
5475 size (64). The below ensures that registers are fetched from the
5476 stack using their ABI size and then stored into the RAW_BUFFER
5477 using their raw size.
5479 The alternative to adding this function would be to add an ABI
5480 macro - REGISTER_STACK_SIZE(). */
5483 mips_get_saved_register (char *raw_buffer,
5486 struct frame_info *frame,
5488 enum lval_type *lvalp)
5491 enum lval_type lvalx;
5494 if (!target_has_registers)
5495 error ("No registers.");
5497 /* Make certain that all needed parameters are present. */
5502 if (optimizedp == NULL)
5503 optimizedp = &optimizedx;
5504 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5506 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5507 have a pseudo register range that correspons to the ABI's, rather
5508 than the ISA's, view of registers. These registers would then
5509 implicitly describe their size and hence could be used without
5510 the below munging. */
5511 if ((*lvalp) == lval_memory)
5513 if (raw_buffer != NULL)
5517 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5519 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5520 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5526 /* Immediately after a function call, return the saved pc.
5527 Can't always go through the frames for this because on some machines
5528 the new frame is not set up until the new function executes
5529 some instructions. */
5532 mips_saved_pc_after_call (struct frame_info *frame)
5534 return read_signed_register (RA_REGNUM);
5538 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5542 mips_stab_reg_to_regnum (int num)
5544 if (num >= 0 && num < 32)
5546 else if (num >= 38 && num < 70)
5547 return num + FP0_REGNUM - 38;
5554 /* This will hopefully (eventually) provoke a warning. Should
5555 we be calling complaint() here? */
5556 return NUM_REGS + NUM_PSEUDO_REGS;
5561 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5564 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5566 if (num >= 0 && num < 32)
5568 else if (num >= 32 && num < 64)
5569 return num + FP0_REGNUM - 32;
5576 /* This will hopefully (eventually) provoke a warning. Should
5577 we be calling complaint() here? */
5578 return NUM_REGS + NUM_PSEUDO_REGS;
5583 /* Convert an integer into an address. By first converting the value
5584 into a pointer and then extracting it signed, the address is
5585 guarenteed to be correctly sign extended. */
5588 mips_integer_to_address (struct type *type, void *buf)
5590 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5591 LONGEST val = unpack_long (type, buf);
5592 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5593 return extract_signed_integer (tmp,
5594 TYPE_LENGTH (builtin_type_void_data_ptr));
5598 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5600 enum mips_abi *abip = (enum mips_abi *) obj;
5601 const char *name = bfd_get_section_name (abfd, sect);
5603 if (*abip != MIPS_ABI_UNKNOWN)
5606 if (strncmp (name, ".mdebug.", 8) != 0)
5609 if (strcmp (name, ".mdebug.abi32") == 0)
5610 *abip = MIPS_ABI_O32;
5611 else if (strcmp (name, ".mdebug.abiN32") == 0)
5612 *abip = MIPS_ABI_N32;
5613 else if (strcmp (name, ".mdebug.abi64") == 0)
5614 *abip = MIPS_ABI_N64;
5615 else if (strcmp (name, ".mdebug.abiO64") == 0)
5616 *abip = MIPS_ABI_O64;
5617 else if (strcmp (name, ".mdebug.eabi32") == 0)
5618 *abip = MIPS_ABI_EABI32;
5619 else if (strcmp (name, ".mdebug.eabi64") == 0)
5620 *abip = MIPS_ABI_EABI64;
5622 warning ("unsupported ABI %s.", name + 8);
5625 static enum mips_abi
5626 global_mips_abi (void)
5630 for (i = 0; mips_abi_strings[i] != NULL; i++)
5631 if (mips_abi_strings[i] == mips_abi_string)
5632 return (enum mips_abi) i;
5634 internal_error (__FILE__, __LINE__,
5635 "unknown ABI string");
5638 static struct gdbarch *
5639 mips_gdbarch_init (struct gdbarch_info info,
5640 struct gdbarch_list *arches)
5642 static LONGEST mips_call_dummy_words[] =
5644 struct gdbarch *gdbarch;
5645 struct gdbarch_tdep *tdep;
5647 enum mips_abi mips_abi, found_abi, wanted_abi;
5649 /* Reset the disassembly info, in case it was set to something
5651 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5652 tm_print_insn_info.arch = bfd_arch_unknown;
5653 tm_print_insn_info.mach = 0;
5659 /* First of all, extract the elf_flags, if available. */
5660 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5661 elf_flags = elf_elfheader (info.abfd)->e_flags;
5664 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5665 switch ((elf_flags & EF_MIPS_ABI))
5667 case E_MIPS_ABI_O32:
5668 mips_abi = MIPS_ABI_O32;
5670 case E_MIPS_ABI_O64:
5671 mips_abi = MIPS_ABI_O64;
5673 case E_MIPS_ABI_EABI32:
5674 mips_abi = MIPS_ABI_EABI32;
5676 case E_MIPS_ABI_EABI64:
5677 mips_abi = MIPS_ABI_EABI64;
5680 if ((elf_flags & EF_MIPS_ABI2))
5681 mips_abi = MIPS_ABI_N32;
5683 mips_abi = MIPS_ABI_UNKNOWN;
5687 /* GCC creates a pseudo-section whose name describes the ABI. */
5688 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5689 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5691 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5692 Use the ABI from the last architecture if there is one. */
5693 if (info.abfd == NULL && arches != NULL)
5694 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5696 /* Try the architecture for any hint of the correct ABI. */
5697 if (mips_abi == MIPS_ABI_UNKNOWN
5698 && info.bfd_arch_info != NULL
5699 && info.bfd_arch_info->arch == bfd_arch_mips)
5701 switch (info.bfd_arch_info->mach)
5703 case bfd_mach_mips3900:
5704 mips_abi = MIPS_ABI_EABI32;
5706 case bfd_mach_mips4100:
5707 case bfd_mach_mips5000:
5708 mips_abi = MIPS_ABI_EABI64;
5710 case bfd_mach_mips8000:
5711 case bfd_mach_mips10000:
5712 /* On Irix, ELF64 executables use the N64 ABI. The
5713 pseudo-sections which describe the ABI aren't present
5714 on IRIX. (Even for executables created by gcc.) */
5715 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5716 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5717 mips_abi = MIPS_ABI_N64;
5719 mips_abi = MIPS_ABI_N32;
5724 if (mips_abi == MIPS_ABI_UNKNOWN)
5725 mips_abi = MIPS_ABI_O32;
5727 /* Now that we have found what the ABI for this binary would be,
5728 check whether the user is overriding it. */
5729 found_abi = mips_abi;
5730 wanted_abi = global_mips_abi ();
5731 if (wanted_abi != MIPS_ABI_UNKNOWN)
5732 mips_abi = wanted_abi;
5734 /* We have to set tm_print_insn_info before looking for a
5735 pre-existing architecture, otherwise we may return before we get
5736 a chance to set it up. */
5737 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5739 /* Set up the disassembler info, so that we get the right
5740 register names from libopcodes. */
5741 if (mips_abi == MIPS_ABI_N32)
5742 tm_print_insn_info.disassembler_options = "gpr-names=n32";
5744 tm_print_insn_info.disassembler_options = "gpr-names=64";
5745 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5746 tm_print_insn_info.arch = bfd_arch_mips;
5747 if (info.bfd_arch_info != NULL
5748 && info.bfd_arch_info->arch == bfd_arch_mips
5749 && info.bfd_arch_info->mach)
5750 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5752 tm_print_insn_info.mach = bfd_mach_mips8000;
5755 /* This string is not recognized explicitly by the disassembler,
5756 but it tells the disassembler to not try to guess the ABI from
5757 the bfd elf headers, such that, if the user overrides the ABI
5758 of a program linked as NewABI, the disassembly will follow the
5759 register naming conventions specified by the user. */
5760 tm_print_insn_info.disassembler_options = "gpr-names=32";
5764 fprintf_unfiltered (gdb_stdlog,
5765 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5767 fprintf_unfiltered (gdb_stdlog,
5768 "mips_gdbarch_init: mips_abi = %d\n",
5770 fprintf_unfiltered (gdb_stdlog,
5771 "mips_gdbarch_init: found_mips_abi = %d\n",
5775 /* try to find a pre-existing architecture */
5776 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5778 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5780 /* MIPS needs to be pedantic about which ABI the object is
5782 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5784 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5786 return arches->gdbarch;
5789 /* Need a new architecture. Fill in a target specific vector. */
5790 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5791 gdbarch = gdbarch_alloc (&info, tdep);
5792 tdep->elf_flags = elf_flags;
5794 /* Initially set everything according to the default ABI/ISA. */
5795 set_gdbarch_short_bit (gdbarch, 16);
5796 set_gdbarch_int_bit (gdbarch, 32);
5797 set_gdbarch_float_bit (gdbarch, 32);
5798 set_gdbarch_double_bit (gdbarch, 64);
5799 set_gdbarch_long_double_bit (gdbarch, 64);
5800 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5801 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8);
5802 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5803 tdep->found_abi = found_abi;
5804 tdep->mips_abi = mips_abi;
5806 set_gdbarch_elf_make_msymbol_special (gdbarch,
5807 mips_elf_make_msymbol_special);
5809 if (info.osabi == GDB_OSABI_IRIX)
5810 set_gdbarch_num_regs (gdbarch, 71);
5812 set_gdbarch_num_regs (gdbarch, 90);
5817 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o32_push_arguments);
5818 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5819 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5820 tdep->mips_default_saved_regsize = 4;
5821 tdep->mips_default_stack_argsize = 4;
5822 tdep->mips_fp_register_double = 0;
5823 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5824 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5825 tdep->gdb_target_is_mips64 = 0;
5826 tdep->default_mask_address_p = 0;
5827 set_gdbarch_long_bit (gdbarch, 32);
5828 set_gdbarch_ptr_bit (gdbarch, 32);
5829 set_gdbarch_long_long_bit (gdbarch, 64);
5830 set_gdbarch_reg_struct_has_addr (gdbarch,
5831 mips_o32_reg_struct_has_addr);
5832 set_gdbarch_use_struct_convention (gdbarch,
5833 mips_o32_use_struct_convention);
5836 set_gdbarch_deprecated_push_arguments (gdbarch, mips_o64_push_arguments);
5837 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5838 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5839 tdep->mips_default_saved_regsize = 8;
5840 tdep->mips_default_stack_argsize = 8;
5841 tdep->mips_fp_register_double = 1;
5842 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5843 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5844 tdep->gdb_target_is_mips64 = 1;
5845 tdep->default_mask_address_p = 0;
5846 set_gdbarch_long_bit (gdbarch, 32);
5847 set_gdbarch_ptr_bit (gdbarch, 32);
5848 set_gdbarch_long_long_bit (gdbarch, 64);
5849 set_gdbarch_reg_struct_has_addr (gdbarch,
5850 mips_o32_reg_struct_has_addr);
5851 set_gdbarch_use_struct_convention (gdbarch,
5852 mips_o32_use_struct_convention);
5854 case MIPS_ABI_EABI32:
5855 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5856 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5857 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5858 tdep->mips_default_saved_regsize = 4;
5859 tdep->mips_default_stack_argsize = 4;
5860 tdep->mips_fp_register_double = 0;
5861 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5862 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5863 tdep->gdb_target_is_mips64 = 0;
5864 tdep->default_mask_address_p = 0;
5865 set_gdbarch_long_bit (gdbarch, 32);
5866 set_gdbarch_ptr_bit (gdbarch, 32);
5867 set_gdbarch_long_long_bit (gdbarch, 64);
5868 set_gdbarch_reg_struct_has_addr (gdbarch,
5869 mips_eabi_reg_struct_has_addr);
5870 set_gdbarch_use_struct_convention (gdbarch,
5871 mips_eabi_use_struct_convention);
5873 case MIPS_ABI_EABI64:
5874 set_gdbarch_deprecated_push_arguments (gdbarch, mips_eabi_push_arguments);
5875 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5876 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5877 tdep->mips_default_saved_regsize = 8;
5878 tdep->mips_default_stack_argsize = 8;
5879 tdep->mips_fp_register_double = 1;
5880 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5881 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5882 tdep->gdb_target_is_mips64 = 1;
5883 tdep->default_mask_address_p = 0;
5884 set_gdbarch_long_bit (gdbarch, 64);
5885 set_gdbarch_ptr_bit (gdbarch, 64);
5886 set_gdbarch_long_long_bit (gdbarch, 64);
5887 set_gdbarch_reg_struct_has_addr (gdbarch,
5888 mips_eabi_reg_struct_has_addr);
5889 set_gdbarch_use_struct_convention (gdbarch,
5890 mips_eabi_use_struct_convention);
5893 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5894 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5895 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5896 tdep->mips_default_saved_regsize = 8;
5897 tdep->mips_default_stack_argsize = 8;
5898 tdep->mips_fp_register_double = 1;
5899 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5900 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5901 tdep->gdb_target_is_mips64 = 1;
5902 tdep->default_mask_address_p = 0;
5903 set_gdbarch_long_bit (gdbarch, 32);
5904 set_gdbarch_ptr_bit (gdbarch, 32);
5905 set_gdbarch_long_long_bit (gdbarch, 64);
5906 set_gdbarch_use_struct_convention (gdbarch,
5907 mips_n32n64_use_struct_convention);
5908 set_gdbarch_reg_struct_has_addr (gdbarch,
5909 mips_n32n64_reg_struct_has_addr);
5912 set_gdbarch_deprecated_push_arguments (gdbarch, mips_n32n64_push_arguments);
5913 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5914 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5915 tdep->mips_default_saved_regsize = 8;
5916 tdep->mips_default_stack_argsize = 8;
5917 tdep->mips_fp_register_double = 1;
5918 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5919 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5920 tdep->gdb_target_is_mips64 = 1;
5921 tdep->default_mask_address_p = 0;
5922 set_gdbarch_long_bit (gdbarch, 64);
5923 set_gdbarch_ptr_bit (gdbarch, 64);
5924 set_gdbarch_long_long_bit (gdbarch, 64);
5925 set_gdbarch_use_struct_convention (gdbarch,
5926 mips_n32n64_use_struct_convention);
5927 set_gdbarch_reg_struct_has_addr (gdbarch,
5928 mips_n32n64_reg_struct_has_addr);
5931 internal_error (__FILE__, __LINE__,
5932 "unknown ABI in switch");
5935 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5936 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5939 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5940 flag in object files because to do so would make it impossible to
5941 link with libraries compiled without "-gp32". This is
5942 unnecessarily restrictive.
5944 We could solve this problem by adding "-gp32" multilibs to gcc,
5945 but to set this flag before gcc is built with such multilibs will
5946 break too many systems.''
5948 But even more unhelpfully, the default linker output target for
5949 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5950 for 64-bit programs - you need to change the ABI to change this,
5951 and not all gcc targets support that currently. Therefore using
5952 this flag to detect 32-bit mode would do the wrong thing given
5953 the current gcc - it would make GDB treat these 64-bit programs
5954 as 32-bit programs by default. */
5956 /* enable/disable the MIPS FPU */
5957 if (!mips_fpu_type_auto)
5958 tdep->mips_fpu_type = mips_fpu_type;
5959 else if (info.bfd_arch_info != NULL
5960 && info.bfd_arch_info->arch == bfd_arch_mips)
5961 switch (info.bfd_arch_info->mach)
5963 case bfd_mach_mips3900:
5964 case bfd_mach_mips4100:
5965 case bfd_mach_mips4111:
5966 tdep->mips_fpu_type = MIPS_FPU_NONE;
5968 case bfd_mach_mips4650:
5969 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5972 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5976 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5978 /* MIPS version of register names. NOTE: At present the MIPS
5979 register name management is part way between the old -
5980 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5981 Further work on it is required. */
5982 /* NOTE: many targets (esp. embedded) do not go thru the
5983 gdbarch_register_name vector at all, instead bypassing it
5984 by defining REGISTER_NAMES. */
5985 set_gdbarch_register_name (gdbarch, mips_register_name);
5986 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5987 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5988 set_gdbarch_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5989 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5990 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
5992 /* Add/remove bits from an address. The MIPS needs be careful to
5993 ensure that all 32 bit addresses are sign extended to 64 bits. */
5994 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5996 /* There's a mess in stack frame creation. See comments in
5997 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5998 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5999 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
6001 /* Map debug register numbers onto internal register numbers. */
6002 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6003 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6004 set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6005 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6007 /* Initialize a frame */
6008 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
6009 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
6011 /* MIPS version of CALL_DUMMY */
6013 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
6014 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
6015 set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
6016 set_gdbarch_fix_call_dummy (gdbarch, mips_fix_call_dummy);
6017 set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words);
6018 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
6019 set_gdbarch_deprecated_push_return_address (gdbarch, mips_push_return_address);
6020 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6021 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
6022 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
6023 set_gdbarch_register_convert_to_virtual (gdbarch,
6024 mips_register_convert_to_virtual);
6025 set_gdbarch_register_convert_to_raw (gdbarch,
6026 mips_register_convert_to_raw);
6028 set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
6029 set_gdbarch_frameless_function_invocation (gdbarch,
6030 generic_frameless_function_invocation_not);
6031 set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
6032 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
6033 set_gdbarch_frame_args_skip (gdbarch, 0);
6035 set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
6037 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6038 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6039 set_gdbarch_decr_pc_after_break (gdbarch, 0);
6041 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6042 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
6044 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6045 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6046 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6048 set_gdbarch_function_start_offset (gdbarch, 0);
6050 /* There are MIPS targets which do not yet use this since they still
6051 define REGISTER_VIRTUAL_TYPE. */
6052 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
6053 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
6055 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
6056 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
6058 /* Hook in OS ABI-specific overrides, if they have been registered. */
6059 gdbarch_init_osabi (info, gdbarch);
6061 set_gdbarch_deprecated_store_struct_return (gdbarch, mips_store_struct_return);
6062 set_gdbarch_extract_struct_value_address (gdbarch,
6063 mips_extract_struct_value_address);
6065 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6067 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6068 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6074 mips_abi_update (char *ignore_args, int from_tty,
6075 struct cmd_list_element *c)
6077 struct gdbarch_info info;
6079 /* Force the architecture to update, and (if it's a MIPS architecture)
6080 mips_gdbarch_init will take care of the rest. */
6081 gdbarch_info_init (&info);
6082 gdbarch_update_p (info);
6085 /* Print out which MIPS ABI is in use. */
6088 show_mips_abi (char *ignore_args, int from_tty)
6090 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6092 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6095 enum mips_abi global_abi = global_mips_abi ();
6096 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6097 const char *actual_abi_str = mips_abi_strings[actual_abi];
6099 if (global_abi == MIPS_ABI_UNKNOWN)
6100 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6102 else if (global_abi == actual_abi)
6104 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6108 /* Probably shouldn't happen... */
6110 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6112 mips_abi_strings[global_abi]);
6118 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6120 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6124 int ef_mips_32bitmode;
6125 /* determine the ISA */
6126 switch (tdep->elf_flags & EF_MIPS_ARCH)
6144 /* determine the size of a pointer */
6145 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6146 fprintf_unfiltered (file,
6147 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6149 fprintf_unfiltered (file,
6150 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6152 fprintf_unfiltered (file,
6153 "mips_dump_tdep: ef_mips_arch = %d\n",
6155 fprintf_unfiltered (file,
6156 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6158 mips_abi_strings[tdep->mips_abi]);
6159 fprintf_unfiltered (file,
6160 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6161 mips_mask_address_p (),
6162 tdep->default_mask_address_p);
6164 fprintf_unfiltered (file,
6165 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6166 FP_REGISTER_DOUBLE);
6167 fprintf_unfiltered (file,
6168 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6169 MIPS_DEFAULT_FPU_TYPE,
6170 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6171 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6172 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6174 fprintf_unfiltered (file,
6175 "mips_dump_tdep: MIPS_EABI = %d\n",
6177 fprintf_unfiltered (file,
6178 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6179 MIPS_LAST_FP_ARG_REGNUM,
6180 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6181 fprintf_unfiltered (file,
6182 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6184 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6185 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6186 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6188 fprintf_unfiltered (file,
6189 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6190 MIPS_DEFAULT_SAVED_REGSIZE);
6191 fprintf_unfiltered (file,
6192 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6193 FP_REGISTER_DOUBLE);
6194 fprintf_unfiltered (file,
6195 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6196 MIPS_DEFAULT_STACK_ARGSIZE);
6197 fprintf_unfiltered (file,
6198 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6199 MIPS_STACK_ARGSIZE);
6200 fprintf_unfiltered (file,
6201 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6203 fprintf_unfiltered (file,
6204 "mips_dump_tdep: A0_REGNUM = %d\n",
6206 fprintf_unfiltered (file,
6207 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6208 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6209 fprintf_unfiltered (file,
6210 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6211 XSTRING (ATTACH_DETACH));
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6215 fprintf_unfiltered (file,
6216 "mips_dump_tdep: BIG_BREAKPOINT = delete?\n");
6217 fprintf_unfiltered (file,
6218 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6220 fprintf_unfiltered (file,
6221 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6222 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6223 fprintf_unfiltered (file,
6224 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6225 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6229 fprintf_unfiltered (file,
6230 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6232 fprintf_unfiltered (file,
6233 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6234 FIRST_EMBED_REGNUM);
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6240 GDB_TARGET_IS_MIPS64);
6241 fprintf_unfiltered (file,
6242 "mips_dump_tdep: GEN_REG_SAVE_MASK = %d\n",
6244 fprintf_unfiltered (file,
6245 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6246 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6247 fprintf_unfiltered (file,
6248 "mips_dump_tdep: HI_REGNUM = %d\n",
6250 fprintf_unfiltered (file,
6251 "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n");
6252 fprintf_unfiltered (file,
6253 "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n");
6254 fprintf_unfiltered (file,
6255 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6256 XSTRING (IGNORE_HELPER_CALL (PC)));
6257 fprintf_unfiltered (file,
6258 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6259 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6260 fprintf_unfiltered (file,
6261 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6262 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6263 fprintf_unfiltered (file,
6264 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6265 fprintf_unfiltered (file,
6266 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6268 fprintf_unfiltered (file,
6269 "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n");
6270 fprintf_unfiltered (file,
6271 "mips_dump_tdep: LO_REGNUM = %d\n",
6273 #ifdef MACHINE_CPROC_FP_OFFSET
6274 fprintf_unfiltered (file,
6275 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6276 MACHINE_CPROC_FP_OFFSET);
6278 #ifdef MACHINE_CPROC_PC_OFFSET
6279 fprintf_unfiltered (file,
6280 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6281 MACHINE_CPROC_PC_OFFSET);
6283 #ifdef MACHINE_CPROC_SP_OFFSET
6284 fprintf_unfiltered (file,
6285 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6286 MACHINE_CPROC_SP_OFFSET);
6288 fprintf_unfiltered (file,
6289 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6290 fprintf_unfiltered (file,
6291 "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n");
6292 fprintf_unfiltered (file,
6293 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6295 fprintf_unfiltered (file,
6296 "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n");
6297 fprintf_unfiltered (file,
6298 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6299 fprintf_unfiltered (file,
6300 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6301 fprintf_unfiltered (file,
6302 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6304 fprintf_unfiltered (file,
6305 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6306 MIPS_LAST_ARG_REGNUM,
6307 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6308 fprintf_unfiltered (file,
6309 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6311 fprintf_unfiltered (file,
6312 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6313 fprintf_unfiltered (file,
6314 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6315 MIPS_SAVED_REGSIZE);
6316 fprintf_unfiltered (file,
6317 "mips_dump_tdep: OP_LDFPR = used?\n");
6318 fprintf_unfiltered (file,
6319 "mips_dump_tdep: OP_LDGPR = used?\n");
6320 fprintf_unfiltered (file,
6321 "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n");
6322 fprintf_unfiltered (file,
6323 "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n");
6324 fprintf_unfiltered (file,
6325 "mips_dump_tdep: PRID_REGNUM = %d\n",
6327 fprintf_unfiltered (file,
6328 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6329 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6330 fprintf_unfiltered (file,
6331 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6332 fprintf_unfiltered (file,
6333 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6334 fprintf_unfiltered (file,
6335 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6336 fprintf_unfiltered (file,
6337 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6338 fprintf_unfiltered (file,
6339 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6340 fprintf_unfiltered (file,
6341 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6342 fprintf_unfiltered (file,
6343 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6344 fprintf_unfiltered (file,
6345 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: PROC_PC_REG = function?\n");
6348 fprintf_unfiltered (file,
6349 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6350 fprintf_unfiltered (file,
6351 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6352 fprintf_unfiltered (file,
6353 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6354 fprintf_unfiltered (file,
6355 "mips_dump_tdep: PS_REGNUM = %d\n",
6357 fprintf_unfiltered (file,
6358 "mips_dump_tdep: PUSH_FP_REGNUM = %d\n",
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: RA_REGNUM = %d\n",
6363 fprintf_unfiltered (file,
6364 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6365 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6366 fprintf_unfiltered (file,
6367 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6368 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6369 fprintf_unfiltered (file,
6370 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6371 fprintf_unfiltered (file,
6372 "mips_dump_tdep: ROUND_DOWN = function?\n");
6373 fprintf_unfiltered (file,
6374 "mips_dump_tdep: ROUND_UP = function?\n");
6376 fprintf_unfiltered (file,
6377 "mips_dump_tdep: SAVED_BYTES = %d\n",
6381 fprintf_unfiltered (file,
6382 "mips_dump_tdep: SAVED_FP = %d\n",
6386 fprintf_unfiltered (file,
6387 "mips_dump_tdep: SAVED_PC = %d\n",
6390 fprintf_unfiltered (file,
6391 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6392 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6393 fprintf_unfiltered (file,
6394 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6395 fprintf_unfiltered (file,
6396 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6398 fprintf_unfiltered (file,
6399 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6400 SIGFRAME_FPREGSAVE_OFF);
6401 fprintf_unfiltered (file,
6402 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6404 fprintf_unfiltered (file,
6405 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6406 SIGFRAME_REGSAVE_OFF);
6407 fprintf_unfiltered (file,
6408 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6410 fprintf_unfiltered (file,
6411 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6412 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6413 fprintf_unfiltered (file,
6414 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6415 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6416 fprintf_unfiltered (file,
6417 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6418 SOFTWARE_SINGLE_STEP_P ());
6419 fprintf_unfiltered (file,
6420 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6421 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6422 #ifdef STACK_END_ADDR
6423 fprintf_unfiltered (file,
6424 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6427 fprintf_unfiltered (file,
6428 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6429 XSTRING (STEP_SKIPS_DELAY (PC)));
6430 fprintf_unfiltered (file,
6431 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6432 STEP_SKIPS_DELAY_P);
6433 fprintf_unfiltered (file,
6434 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6435 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6436 fprintf_unfiltered (file,
6437 "mips_dump_tdep: T9_REGNUM = %d\n",
6439 fprintf_unfiltered (file,
6440 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6441 fprintf_unfiltered (file,
6442 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6443 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6444 fprintf_unfiltered (file,
6445 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6446 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6447 fprintf_unfiltered (file,
6448 "mips_dump_tdep: TARGET_MIPS = used?\n");
6449 fprintf_unfiltered (file,
6450 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6451 XSTRING (TM_PRINT_INSN_MACH));
6453 fprintf_unfiltered (file,
6454 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6455 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6458 fprintf_unfiltered (file,
6459 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6462 #ifdef TRACE_FLAVOR_SIZE
6463 fprintf_unfiltered (file,
6464 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6468 fprintf_unfiltered (file,
6469 "mips_dump_tdep: TRACE_SET # %s\n",
6470 XSTRING (TRACE_SET (X,STATE)));
6472 fprintf_unfiltered (file,
6473 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6474 #ifdef UNUSED_REGNUM
6475 fprintf_unfiltered (file,
6476 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6479 fprintf_unfiltered (file,
6480 "mips_dump_tdep: V0_REGNUM = %d\n",
6482 fprintf_unfiltered (file,
6483 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6484 (long) VM_MIN_ADDRESS);
6486 fprintf_unfiltered (file,
6487 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6490 fprintf_unfiltered (file,
6491 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6493 fprintf_unfiltered (file,
6494 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6499 _initialize_mips_tdep (void)
6501 static struct cmd_list_element *mipsfpulist = NULL;
6502 struct cmd_list_element *c;
6504 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6505 if (MIPS_ABI_LAST + 1
6506 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6507 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6509 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6510 if (!tm_print_insn) /* Someone may have already set it */
6511 tm_print_insn = gdb_print_insn_mips;
6513 /* Add root prefix command for all "set mips"/"show mips" commands */
6514 add_prefix_cmd ("mips", no_class, set_mips_command,
6515 "Various MIPS specific commands.",
6516 &setmipscmdlist, "set mips ", 0, &setlist);
6518 add_prefix_cmd ("mips", no_class, show_mips_command,
6519 "Various MIPS specific commands.",
6520 &showmipscmdlist, "show mips ", 0, &showlist);
6522 /* Allow the user to override the saved register size. */
6523 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6526 &mips_saved_regsize_string, "\
6527 Set size of general purpose registers saved on the stack.\n\
6528 This option can be set to one of:\n\
6529 32 - Force GDB to treat saved GP registers as 32-bit\n\
6530 64 - Force GDB to treat saved GP registers as 64-bit\n\
6531 auto - Allow GDB to use the target's default setting or autodetect the\n\
6532 saved GP register size from information contained in the executable.\n\
6537 /* Allow the user to override the argument stack size. */
6538 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6541 &mips_stack_argsize_string, "\
6542 Set the amount of stack space reserved for each argument.\n\
6543 This option can be set to one of:\n\
6544 32 - Force GDB to allocate 32-bit chunks per argument\n\
6545 64 - Force GDB to allocate 64-bit chunks per argument\n\
6546 auto - Allow GDB to determine the correct setting from the current\n\
6547 target and executable (default)",
6551 /* Allow the user to override the ABI. */
6552 c = add_set_enum_cmd
6553 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6554 "Set the ABI used by this program.\n"
6555 "This option can be set to one of:\n"
6556 " auto - the default ABI associated with the current binary\n"
6564 set_cmd_sfunc (c, mips_abi_update);
6565 add_cmd ("abi", class_obscure, show_mips_abi,
6566 "Show ABI in use by MIPS target", &showmipscmdlist);
6568 /* Let the user turn off floating point and set the fence post for
6569 heuristic_proc_start. */
6571 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6572 "Set use of MIPS floating-point coprocessor.",
6573 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6574 add_cmd ("single", class_support, set_mipsfpu_single_command,
6575 "Select single-precision MIPS floating-point coprocessor.",
6577 add_cmd ("double", class_support, set_mipsfpu_double_command,
6578 "Select double-precision MIPS floating-point coprocessor.",
6580 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6581 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6582 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6583 add_cmd ("none", class_support, set_mipsfpu_none_command,
6584 "Select no MIPS floating-point coprocessor.",
6586 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6587 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6588 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6589 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6590 "Select MIPS floating-point coprocessor automatically.",
6592 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6593 "Show current use of MIPS floating-point coprocessor target.",
6596 /* We really would like to have both "0" and "unlimited" work, but
6597 command.c doesn't deal with that. So make it a var_zinteger
6598 because the user can always use "999999" or some such for unlimited. */
6599 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6600 (char *) &heuristic_fence_post,
6602 Set the distance searched for the start of a function.\n\
6603 If you are debugging a stripped executable, GDB needs to search through the\n\
6604 program for the start of a function. This command sets the distance of the\n\
6605 search. The only need to set it is when debugging a stripped executable.",
6607 /* We need to throw away the frame cache when we set this, since it
6608 might change our ability to get backtraces. */
6609 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6610 add_show_from_set (c, &showlist);
6612 /* Allow the user to control whether the upper bits of 64-bit
6613 addresses should be zeroed. */
6614 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6615 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6616 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6617 allow GDB to determine the correct value.\n", "\
6618 Show zeroing of upper 32 bits of 64-bit addresses.",
6619 NULL, show_mask_address,
6620 &setmipscmdlist, &showmipscmdlist);
6622 /* Allow the user to control the size of 32 bit registers within the
6623 raw remote packet. */
6624 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6627 (char *)&mips64_transfers_32bit_regs_p, "\
6628 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6629 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6630 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6631 64 bits for others. Use \"off\" to disable compatibility mode",
6635 /* Debug this files internals. */
6636 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6637 &mips_debug, "Set mips debugging.\n\
6638 When non-zero, mips specific debugging is enabled.", &setdebuglist),