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"
39 #include "arch-utils.h"
42 #include "mips-tdep.h"
45 #include "opcode/mips.h"
50 /* A useful bit in the CP0 status register (PS_REGNUM). */
51 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
52 #define ST0_FR (1 << 26)
54 /* The sizes of floating point registers. */
58 MIPS_FPU_SINGLE_REGSIZE = 4,
59 MIPS_FPU_DOUBLE_REGSIZE = 8
63 static const char *mips_abi_string;
65 static const char *mips_abi_strings[] = {
76 struct frame_extra_info
78 mips_extra_func_info_t proc_desc;
82 /* Various MIPS ISA options (related to stack analysis) can be
83 overridden dynamically. Establish an enum/array for managing
86 static const char size_auto[] = "auto";
87 static const char size_32[] = "32";
88 static const char size_64[] = "64";
90 static const char *size_enums[] = {
97 /* Some MIPS boards don't support floating point while others only
98 support single-precision floating-point operations. See also
99 FP_REGISTER_DOUBLE. */
103 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
104 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
105 MIPS_FPU_NONE /* No floating point. */
108 #ifndef MIPS_DEFAULT_FPU_TYPE
109 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
111 static int mips_fpu_type_auto = 1;
112 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
114 static int mips_debug = 0;
116 /* MIPS specific per-architecture information */
119 /* from the elf header */
123 enum mips_abi mips_abi;
124 enum mips_abi found_abi;
125 enum mips_fpu_type mips_fpu_type;
126 int mips_last_arg_regnum;
127 int mips_last_fp_arg_regnum;
128 int mips_default_saved_regsize;
129 int mips_fp_register_double;
130 int mips_default_stack_argsize;
131 int gdb_target_is_mips64;
132 int default_mask_address_p;
135 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
136 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
138 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
140 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
142 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
144 /* Return the currently configured (or set) saved register size. */
146 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
148 static const char *mips_saved_regsize_string = size_auto;
150 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
152 /* Return the MIPS ABI associated with GDBARCH. */
154 mips_abi (struct gdbarch *gdbarch)
156 return gdbarch_tdep (gdbarch)->mips_abi;
160 mips_saved_regsize (void)
162 if (mips_saved_regsize_string == size_auto)
163 return MIPS_DEFAULT_SAVED_REGSIZE;
164 else if (mips_saved_regsize_string == size_64)
166 else /* if (mips_saved_regsize_string == size_32) */
170 /* Functions for setting and testing a bit in a minimal symbol that
171 marks it as 16-bit function. The MSB of the minimal symbol's
172 "info" field is used for this purpose. This field is already
173 being used to store the symbol size, so the assumption is
174 that the symbol size cannot exceed 2^31.
176 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
177 i.e. refers to a 16-bit function, and sets a "special" bit in a
178 minimal symbol to mark it as a 16-bit function
180 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
181 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
182 the "info" field with the "special" bit masked out */
185 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
187 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
189 MSYMBOL_INFO (msym) = (char *)
190 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
191 SYMBOL_VALUE_ADDRESS (msym) |= 1;
196 msymbol_is_special (struct minimal_symbol *msym)
198 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
202 msymbol_size (struct minimal_symbol *msym)
204 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
207 /* XFER a value from the big/little/left end of the register.
208 Depending on the size of the value it might occupy the entire
209 register or just part of it. Make an allowance for this, aligning
210 things accordingly. */
213 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
214 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
217 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
219 /* Need to transfer the left or right part of the register, based on
220 the targets byte order. */
224 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
226 case BFD_ENDIAN_LITTLE:
229 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
233 internal_error (__FILE__, __LINE__, "bad switch");
236 fprintf_unfiltered (gdb_stderr,
237 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
238 reg_num, reg_offset, buf_offset, length);
239 if (mips_debug && out != NULL)
242 fprintf_unfiltered (gdb_stdlog, "out ");
243 for (i = 0; i < length; i++)
244 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
247 regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
249 regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
250 if (mips_debug && in != NULL)
253 fprintf_unfiltered (gdb_stdlog, "in ");
254 for (i = 0; i < length; i++)
255 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
258 fprintf_unfiltered (gdb_stdlog, "\n");
261 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
262 compatiblity mode. A return value of 1 means that we have
263 physical 64-bit registers, but should treat them as 32-bit registers. */
266 mips2_fp_compat (void)
268 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
270 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
274 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
275 in all the places we deal with FP registers. PR gdb/413. */
276 /* Otherwise check the FR bit in the status register - it controls
277 the FP compatiblity mode. If it is clear we are in compatibility
279 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
286 /* Indicate that the ABI makes use of double-precision registers
287 provided by the FPU (rather than combining pairs of registers to
288 form double-precision values). Do not use "TARGET_IS_MIPS64" to
289 determine if the ABI is using double-precision registers. See also
291 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
293 /* The amount of space reserved on the stack for registers. This is
294 different to MIPS_SAVED_REGSIZE as it determines the alignment of
295 data allocated after the registers have run out. */
297 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
299 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
301 static const char *mips_stack_argsize_string = size_auto;
304 mips_stack_argsize (void)
306 if (mips_stack_argsize_string == size_auto)
307 return MIPS_DEFAULT_STACK_ARGSIZE;
308 else if (mips_stack_argsize_string == size_64)
310 else /* if (mips_stack_argsize_string == size_32) */
314 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
316 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
318 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
320 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
322 static void mips_print_register (int, int);
324 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
325 struct frame_info *, int);
327 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
329 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
331 static int mips_set_processor_type (char *);
333 static void mips_show_processor_type_command (char *, int);
335 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
337 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
338 struct frame_info *next_frame,
341 static CORE_ADDR after_prologue (CORE_ADDR pc,
342 mips_extra_func_info_t proc_desc);
344 static void mips_read_fp_register_single (int regno, char *rare_buffer);
345 static void mips_read_fp_register_double (int regno, char *rare_buffer);
347 static struct type *mips_float_register_type (void);
348 static struct type *mips_double_register_type (void);
350 /* This value is the model of MIPS in use. It is derived from the value
351 of the PrID register. */
353 char *mips_processor_type;
355 char *tmp_mips_processor_type;
357 /* The list of available "set mips " and "show mips " commands */
359 static struct cmd_list_element *setmipscmdlist = NULL;
360 static struct cmd_list_element *showmipscmdlist = NULL;
362 /* A set of original names, to be used when restoring back to generic
363 registers from a specific set. */
365 char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
366 char **mips_processor_reg_names = mips_generic_reg_names;
369 mips_register_name (int i)
371 return mips_processor_reg_names[i];
374 /* Names of IDT R3041 registers. */
376 char *mips_r3041_reg_names[] = {
377 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
378 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
379 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
380 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
381 "sr", "lo", "hi", "bad", "cause","pc",
382 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
383 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
384 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
385 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
386 "fsr", "fir", "",/*"fp"*/ "",
387 "", "", "bus", "ccfg", "", "", "", "",
388 "", "", "port", "cmp", "", "", "epc", "prid",
391 /* Names of IDT R3051 registers. */
393 char *mips_r3051_reg_names[] = {
394 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
395 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
396 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
397 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
398 "sr", "lo", "hi", "bad", "cause","pc",
399 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
400 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
401 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
402 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
403 "fsr", "fir", ""/*"fp"*/, "",
404 "inx", "rand", "elo", "", "ctxt", "", "", "",
405 "", "", "ehi", "", "", "", "epc", "prid",
408 /* Names of IDT R3081 registers. */
410 char *mips_r3081_reg_names[] = {
411 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
412 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
413 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
414 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
415 "sr", "lo", "hi", "bad", "cause","pc",
416 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
417 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
418 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
419 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
420 "fsr", "fir", ""/*"fp"*/, "",
421 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
422 "", "", "ehi", "", "", "", "epc", "prid",
425 /* Names of LSI 33k registers. */
427 char *mips_lsi33k_reg_names[] = {
428 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
429 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
430 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
431 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
432 "epc", "hi", "lo", "sr", "cause","badvaddr",
433 "dcic", "bpc", "bda", "", "", "", "", "",
434 "", "", "", "", "", "", "", "",
435 "", "", "", "", "", "", "", "",
436 "", "", "", "", "", "", "", "",
438 "", "", "", "", "", "", "", "",
439 "", "", "", "", "", "", "", "",
445 } mips_processor_type_table[] = {
446 { "generic", mips_generic_reg_names },
447 { "r3041", mips_r3041_reg_names },
448 { "r3051", mips_r3051_reg_names },
449 { "r3071", mips_r3081_reg_names },
450 { "r3081", mips_r3081_reg_names },
451 { "lsi33k", mips_lsi33k_reg_names },
459 /* Table to translate MIPS16 register field to actual register number. */
460 static int mips16_to_32_reg[8] =
461 {16, 17, 2, 3, 4, 5, 6, 7};
463 /* Heuristic_proc_start may hunt through the text section for a long
464 time across a 2400 baud serial line. Allows the user to limit this
467 static unsigned int heuristic_fence_post = 0;
469 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
470 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
471 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
472 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
473 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
474 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
475 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
476 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
477 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
478 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
479 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
480 this will corrupt pdr.iline. Fortunately we don't use it. */
481 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
482 #define _PROC_MAGIC_ 0x0F0F0F0F
483 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
484 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
486 struct linked_proc_info
488 struct mips_extra_func_info info;
489 struct linked_proc_info *next;
491 *linked_proc_desc_table = NULL;
494 mips_print_extra_frame_info (struct frame_info *fi)
497 && get_frame_extra_info (fi)
498 && get_frame_extra_info (fi)->proc_desc
499 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
500 printf_filtered (" frame pointer is at %s+%s\n",
501 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
502 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
505 /* Number of bytes of storage in the actual machine representation for
506 register N. NOTE: This indirectly defines the register size
507 transfered by the GDB protocol. */
509 static int mips64_transfers_32bit_regs_p = 0;
512 mips_register_raw_size (int reg_nr)
514 if (mips64_transfers_32bit_regs_p)
515 return REGISTER_VIRTUAL_SIZE (reg_nr);
516 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
517 && FP_REGISTER_DOUBLE)
518 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
525 /* Convert between RAW and VIRTUAL registers. The RAW register size
526 defines the remote-gdb packet. */
529 mips_register_convertible (int reg_nr)
531 if (mips64_transfers_32bit_regs_p)
534 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
538 mips_register_convert_to_virtual (int n, struct type *virtual_type,
539 char *raw_buf, char *virt_buf)
541 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
543 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
544 TYPE_LENGTH (virtual_type));
548 TYPE_LENGTH (virtual_type));
552 mips_register_convert_to_raw (struct type *virtual_type, int n,
553 char *virt_buf, char *raw_buf)
555 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
556 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
557 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
559 TYPE_LENGTH (virtual_type));
563 TYPE_LENGTH (virtual_type));
567 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
569 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
570 && REGISTER_RAW_SIZE (regnum) == 4
571 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
572 && TYPE_CODE(type) == TYPE_CODE_FLT
573 && TYPE_LENGTH(type) == 8)
576 memcpy (temp, ((char *)(buffer))+4, 4);
577 memcpy (((char *)(buffer))+4, (buffer), 4);
578 memcpy (((char *)(buffer)), temp, 4);
583 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
585 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
586 && REGISTER_RAW_SIZE (regnum) == 4
587 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
588 && TYPE_CODE(type) == TYPE_CODE_FLT
589 && TYPE_LENGTH(type) == 8)
592 memcpy (temp, ((char *)(buffer))+4, 4);
593 memcpy (((char *)(buffer))+4, (buffer), 4);
594 memcpy (((char *)(buffer)), temp, 4);
598 /* Return the GDB type object for the "standard" data type
599 of data in register REG.
601 Note: kevinb/2002-08-01: The definition below should faithfully
602 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
603 definitions found in config/mips/tm-*.h. I'm concerned about
604 the ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause
605 though. In some cases FP_REGNUM is in this range, and I doubt
606 that this code is correct for the 64-bit case. */
609 mips_register_virtual_type (int reg)
611 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
613 /* Floating point registers... */
614 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
615 return builtin_type_ieee_double_big;
617 return builtin_type_ieee_double_little;
619 else if (reg == PS_REGNUM /* CR */)
620 return builtin_type_uint32;
621 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
622 return builtin_type_uint32;
625 /* Everything else...
626 Return type appropriate for width of register. */
627 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
628 return builtin_type_uint64;
630 return builtin_type_uint32;
634 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
639 return ADDR_BITS_REMOVE (read_register (SP_REGNUM));
642 /* Should the upper word of 64-bit addresses be zeroed? */
643 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
646 mips_mask_address_p (void)
648 switch (mask_address_var)
650 case AUTO_BOOLEAN_TRUE:
652 case AUTO_BOOLEAN_FALSE:
655 case AUTO_BOOLEAN_AUTO:
656 return MIPS_DEFAULT_MASK_ADDRESS_P;
658 internal_error (__FILE__, __LINE__,
659 "mips_mask_address_p: bad switch");
665 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
667 switch (mask_address_var)
669 case AUTO_BOOLEAN_TRUE:
670 printf_filtered ("The 32 bit mips address mask is enabled\n");
672 case AUTO_BOOLEAN_FALSE:
673 printf_filtered ("The 32 bit mips address mask is disabled\n");
675 case AUTO_BOOLEAN_AUTO:
676 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
677 mips_mask_address_p () ? "enabled" : "disabled");
680 internal_error (__FILE__, __LINE__,
681 "show_mask_address: bad switch");
686 /* Should call_function allocate stack space for a struct return? */
689 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
691 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
695 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
697 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
701 mips_o32_use_struct_convention (int gcc_p, struct type *type)
703 return 1; /* Structures are returned by ref in extra arg0. */
706 /* Should call_function pass struct by reference?
707 For each architecture, structs are passed either by
708 value or by reference, depending on their size. */
711 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
713 enum type_code typecode = TYPE_CODE (check_typedef (type));
714 int len = TYPE_LENGTH (check_typedef (type));
716 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
717 return (len > MIPS_SAVED_REGSIZE);
723 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
725 return 0; /* Assumption: N32/N64 never passes struct by ref. */
729 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
731 return 0; /* Assumption: O32/O64 never passes struct by ref. */
734 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
737 pc_is_mips16 (bfd_vma memaddr)
739 struct minimal_symbol *sym;
741 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
742 if (IS_MIPS16_ADDR (memaddr))
745 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
746 the high bit of the info field. Use this to decide if the function is
747 MIPS16 or normal MIPS. */
748 sym = lookup_minimal_symbol_by_pc (memaddr);
750 return msymbol_is_special (sym);
755 /* MIPS believes that the PC has a sign extended value. Perhaphs the
756 all registers should be sign extended for simplicity? */
759 mips_read_pc (ptid_t ptid)
761 return read_signed_register_pid (PC_REGNUM, ptid);
764 /* This returns the PC of the first inst after the prologue. If we can't
765 find the prologue, then return 0. */
768 after_prologue (CORE_ADDR pc,
769 mips_extra_func_info_t proc_desc)
771 struct symtab_and_line sal;
772 CORE_ADDR func_addr, func_end;
774 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
775 to read the stack pointer from the current machine state, because
776 the current machine state has nothing to do with the information
777 we need from the proc_desc; and the process may or may not exist
780 proc_desc = find_proc_desc (pc, NULL, 0);
784 /* If function is frameless, then we need to do it the hard way. I
785 strongly suspect that frameless always means prologueless... */
786 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
787 && PROC_FRAME_OFFSET (proc_desc) == 0)
791 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
792 return 0; /* Unknown */
794 sal = find_pc_line (func_addr, 0);
796 if (sal.end < func_end)
799 /* The line after the prologue is after the end of the function. In this
800 case, tell the caller to find the prologue the hard way. */
805 /* Decode a MIPS32 instruction that saves a register in the stack, and
806 set the appropriate bit in the general register mask or float register mask
807 to indicate which register is saved. This is a helper function
808 for mips_find_saved_regs. */
811 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
812 unsigned long *float_mask)
816 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
817 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
818 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
820 /* It might be possible to use the instruction to
821 find the offset, rather than the code below which
822 is based on things being in a certain order in the
823 frame, but figuring out what the instruction's offset
824 is relative to might be a little tricky. */
825 reg = (inst & 0x001f0000) >> 16;
826 *gen_mask |= (1 << reg);
828 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
829 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
830 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
833 reg = ((inst & 0x001f0000) >> 16);
834 *float_mask |= (1 << reg);
838 /* Decode a MIPS16 instruction that saves a register in the stack, and
839 set the appropriate bit in the general register or float register mask
840 to indicate which register is saved. This is a helper function
841 for mips_find_saved_regs. */
844 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
846 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
848 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
849 *gen_mask |= (1 << reg);
851 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
853 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
854 *gen_mask |= (1 << reg);
856 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
857 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
858 *gen_mask |= (1 << RA_REGNUM);
862 /* Fetch and return instruction from the specified location. If the PC
863 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
866 mips_fetch_instruction (CORE_ADDR addr)
868 char buf[MIPS_INSTLEN];
872 if (pc_is_mips16 (addr))
874 instlen = MIPS16_INSTLEN;
875 addr = UNMAKE_MIPS16_ADDR (addr);
878 instlen = MIPS_INSTLEN;
879 status = read_memory_nobpt (addr, buf, instlen);
881 memory_error (status, addr);
882 return extract_unsigned_integer (buf, instlen);
886 /* These the fields of 32 bit mips instructions */
887 #define mips32_op(x) (x >> 26)
888 #define itype_op(x) (x >> 26)
889 #define itype_rs(x) ((x >> 21) & 0x1f)
890 #define itype_rt(x) ((x >> 16) & 0x1f)
891 #define itype_immediate(x) (x & 0xffff)
893 #define jtype_op(x) (x >> 26)
894 #define jtype_target(x) (x & 0x03ffffff)
896 #define rtype_op(x) (x >> 26)
897 #define rtype_rs(x) ((x >> 21) & 0x1f)
898 #define rtype_rt(x) ((x >> 16) & 0x1f)
899 #define rtype_rd(x) ((x >> 11) & 0x1f)
900 #define rtype_shamt(x) ((x >> 6) & 0x1f)
901 #define rtype_funct(x) (x & 0x3f)
904 mips32_relative_offset (unsigned long inst)
907 x = itype_immediate (inst);
908 if (x & 0x8000) /* sign bit set */
910 x |= 0xffff0000; /* sign extension */
916 /* Determine whate to set a single step breakpoint while considering
919 mips32_next_pc (CORE_ADDR pc)
923 inst = mips_fetch_instruction (pc);
924 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
926 if (itype_op (inst) >> 2 == 5)
927 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
929 op = (itype_op (inst) & 0x03);
944 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
945 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
947 int tf = itype_rt (inst) & 0x01;
948 int cnum = itype_rt (inst) >> 2;
949 int fcrcs = read_signed_register (FCRCS_REGNUM);
950 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
952 if (((cond >> cnum) & 0x01) == tf)
953 pc += mips32_relative_offset (inst) + 4;
958 pc += 4; /* Not a branch, next instruction is easy */
961 { /* This gets way messy */
963 /* Further subdivide into SPECIAL, REGIMM and other */
964 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
966 case 0: /* SPECIAL */
967 op = rtype_funct (inst);
972 /* Set PC to that address */
973 pc = read_signed_register (rtype_rs (inst));
979 break; /* end SPECIAL */
982 op = itype_rt (inst); /* branch condition */
987 case 16: /* BLTZAL */
988 case 18: /* BLTZALL */
990 if (read_signed_register (itype_rs (inst)) < 0)
991 pc += mips32_relative_offset (inst) + 4;
993 pc += 8; /* after the delay slot */
997 case 17: /* BGEZAL */
998 case 19: /* BGEZALL */
999 greater_equal_branch:
1000 if (read_signed_register (itype_rs (inst)) >= 0)
1001 pc += mips32_relative_offset (inst) + 4;
1003 pc += 8; /* after the delay slot */
1005 /* All of the other instructions in the REGIMM category */
1010 break; /* end REGIMM */
1015 reg = jtype_target (inst) << 2;
1016 /* Upper four bits get never changed... */
1017 pc = reg + ((pc + 4) & 0xf0000000);
1020 /* FIXME case JALX : */
1023 reg = jtype_target (inst) << 2;
1024 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1025 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1027 break; /* The new PC will be alternate mode */
1028 case 4: /* BEQ, BEQL */
1030 if (read_signed_register (itype_rs (inst)) ==
1031 read_signed_register (itype_rt (inst)))
1032 pc += mips32_relative_offset (inst) + 4;
1036 case 5: /* BNE, BNEL */
1038 if (read_signed_register (itype_rs (inst)) !=
1039 read_signed_register (itype_rt (inst)))
1040 pc += mips32_relative_offset (inst) + 4;
1044 case 6: /* BLEZ, BLEZL */
1046 if (read_signed_register (itype_rs (inst) <= 0))
1047 pc += mips32_relative_offset (inst) + 4;
1053 greater_branch: /* BGTZ, BGTZL */
1054 if (read_signed_register (itype_rs (inst) > 0))
1055 pc += mips32_relative_offset (inst) + 4;
1062 } /* mips32_next_pc */
1064 /* Decoding the next place to set a breakpoint is irregular for the
1065 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1066 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1067 We dont want to set a single step instruction on the extend instruction
1071 /* Lots of mips16 instruction formats */
1072 /* Predicting jumps requires itype,ritype,i8type
1073 and their extensions extItype,extritype,extI8type
1075 enum mips16_inst_fmts
1077 itype, /* 0 immediate 5,10 */
1078 ritype, /* 1 5,3,8 */
1079 rrtype, /* 2 5,3,3,5 */
1080 rritype, /* 3 5,3,3,5 */
1081 rrrtype, /* 4 5,3,3,3,2 */
1082 rriatype, /* 5 5,3,3,1,4 */
1083 shifttype, /* 6 5,3,3,3,2 */
1084 i8type, /* 7 5,3,8 */
1085 i8movtype, /* 8 5,3,3,5 */
1086 i8mov32rtype, /* 9 5,3,5,3 */
1087 i64type, /* 10 5,3,8 */
1088 ri64type, /* 11 5,3,3,5 */
1089 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1090 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1091 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1092 extRRItype, /* 15 5,5,5,5,3,3,5 */
1093 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1094 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1095 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1096 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1097 extRi64type, /* 20 5,6,5,5,3,3,5 */
1098 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1100 /* I am heaping all the fields of the formats into one structure and
1101 then, only the fields which are involved in instruction extension */
1105 unsigned int regx; /* Function in i8 type */
1110 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1111 for the bits which make up the immediatate extension. */
1114 extended_offset (unsigned int extension)
1117 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1119 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1121 value |= extension & 0x01f; /* extract 4:0 */
1125 /* Only call this function if you know that this is an extendable
1126 instruction, It wont malfunction, but why make excess remote memory references?
1127 If the immediate operands get sign extended or somthing, do it after
1128 the extension is performed.
1130 /* FIXME: Every one of these cases needs to worry about sign extension
1131 when the offset is to be used in relative addressing */
1135 fetch_mips_16 (CORE_ADDR pc)
1138 pc &= 0xfffffffe; /* clear the low order bit */
1139 target_read_memory (pc, buf, 2);
1140 return extract_unsigned_integer (buf, 2);
1144 unpack_mips16 (CORE_ADDR pc,
1145 unsigned int extension,
1147 enum mips16_inst_fmts insn_format,
1148 struct upk_mips16 *upk)
1153 switch (insn_format)
1160 value = extended_offset (extension);
1161 value = value << 11; /* rom for the original value */
1162 value |= inst & 0x7ff; /* eleven bits from instruction */
1166 value = inst & 0x7ff;
1167 /* FIXME : Consider sign extension */
1176 { /* A register identifier and an offset */
1177 /* Most of the fields are the same as I type but the
1178 immediate value is of a different length */
1182 value = extended_offset (extension);
1183 value = value << 8; /* from the original instruction */
1184 value |= inst & 0xff; /* eleven bits from instruction */
1185 regx = (extension >> 8) & 0x07; /* or i8 funct */
1186 if (value & 0x4000) /* test the sign bit , bit 26 */
1188 value &= ~0x3fff; /* remove the sign bit */
1194 value = inst & 0xff; /* 8 bits */
1195 regx = (inst >> 8) & 0x07; /* or i8 funct */
1196 /* FIXME: Do sign extension , this format needs it */
1197 if (value & 0x80) /* THIS CONFUSES ME */
1199 value &= 0xef; /* remove the sign bit */
1209 unsigned long value;
1210 unsigned int nexthalf;
1211 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1212 value = value << 16;
1213 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1221 internal_error (__FILE__, __LINE__,
1224 upk->offset = offset;
1231 add_offset_16 (CORE_ADDR pc, int offset)
1233 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1237 extended_mips16_next_pc (CORE_ADDR pc,
1238 unsigned int extension,
1241 int op = (insn >> 11);
1244 case 2: /* Branch */
1247 struct upk_mips16 upk;
1248 unpack_mips16 (pc, extension, insn, itype, &upk);
1249 offset = upk.offset;
1255 pc += (offset << 1) + 2;
1258 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1260 struct upk_mips16 upk;
1261 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1262 pc = add_offset_16 (pc, upk.offset);
1263 if ((insn >> 10) & 0x01) /* Exchange mode */
1264 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1271 struct upk_mips16 upk;
1273 unpack_mips16 (pc, extension, insn, ritype, &upk);
1274 reg = read_signed_register (upk.regx);
1276 pc += (upk.offset << 1) + 2;
1283 struct upk_mips16 upk;
1285 unpack_mips16 (pc, extension, insn, ritype, &upk);
1286 reg = read_signed_register (upk.regx);
1288 pc += (upk.offset << 1) + 2;
1293 case 12: /* I8 Formats btez btnez */
1295 struct upk_mips16 upk;
1297 unpack_mips16 (pc, extension, insn, i8type, &upk);
1298 /* upk.regx contains the opcode */
1299 reg = read_signed_register (24); /* Test register is 24 */
1300 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1301 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1302 /* pc = add_offset_16(pc,upk.offset) ; */
1303 pc += (upk.offset << 1) + 2;
1308 case 29: /* RR Formats JR, JALR, JALR-RA */
1310 struct upk_mips16 upk;
1311 /* upk.fmt = rrtype; */
1316 upk.regx = (insn >> 8) & 0x07;
1317 upk.regy = (insn >> 5) & 0x07;
1325 break; /* Function return instruction */
1331 break; /* BOGUS Guess */
1333 pc = read_signed_register (reg);
1340 /* This is an instruction extension. Fetch the real instruction
1341 (which follows the extension) and decode things based on
1345 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1358 mips16_next_pc (CORE_ADDR pc)
1360 unsigned int insn = fetch_mips_16 (pc);
1361 return extended_mips16_next_pc (pc, 0, insn);
1364 /* The mips_next_pc function supports single_step when the remote
1365 target monitor or stub is not developed enough to do a single_step.
1366 It works by decoding the current instruction and predicting where a
1367 branch will go. This isnt hard because all the data is available.
1368 The MIPS32 and MIPS16 variants are quite different */
1370 mips_next_pc (CORE_ADDR pc)
1373 return mips16_next_pc (pc);
1375 return mips32_next_pc (pc);
1378 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1381 Note: kevinb/2002-08-09: The only caller of this function is (and
1382 should remain) mips_frame_init_saved_regs(). In fact,
1383 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1384 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1385 functions should really be combined and now that there is only one
1386 caller, it should be straightforward. (Watch out for multiple returns
1390 mips_find_saved_regs (struct frame_info *fci)
1393 CORE_ADDR reg_position;
1394 /* r0 bit means kernel trap */
1396 /* What registers have been saved? Bitmasks. */
1397 unsigned long gen_mask, float_mask;
1398 mips_extra_func_info_t proc_desc;
1401 frame_saved_regs_zalloc (fci);
1403 /* If it is the frame for sigtramp, the saved registers are located
1404 in a sigcontext structure somewhere on the stack.
1405 If the stack layout for sigtramp changes we might have to change these
1406 constants and the companion fixup_sigtramp in mdebugread.c */
1407 #ifndef SIGFRAME_BASE
1408 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1409 above the sigtramp frame. */
1410 #define SIGFRAME_BASE MIPS_REGSIZE
1411 /* FIXME! Are these correct?? */
1412 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1413 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1414 #define SIGFRAME_FPREGSAVE_OFF \
1415 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1417 #ifndef SIGFRAME_REG_SIZE
1418 /* FIXME! Is this correct?? */
1419 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1421 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1423 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1425 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1426 + ireg * SIGFRAME_REG_SIZE;
1427 get_frame_saved_regs (fci)[ireg] = reg_position;
1429 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1431 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1432 + ireg * SIGFRAME_REG_SIZE;
1433 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1435 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1439 proc_desc = get_frame_extra_info (fci)->proc_desc;
1440 if (proc_desc == NULL)
1441 /* I'm not sure how/whether this can happen. Normally when we can't
1442 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1443 and set the saved_regs right away. */
1446 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1447 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1448 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1450 if ( /* In any frame other than the innermost or a frame interrupted by
1451 a signal, we assume that all registers have been saved.
1452 This assumes that all register saves in a function happen before
1453 the first function call. */
1454 (get_next_frame (fci) == NULL
1455 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1457 /* In a dummy frame we know exactly where things are saved. */
1458 && !PROC_DESC_IS_DUMMY (proc_desc)
1460 /* Don't bother unless we are inside a function prologue. Outside the
1461 prologue, we know where everything is. */
1463 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1465 /* Not sure exactly what kernel_trap means, but if it means
1466 the kernel saves the registers without a prologue doing it,
1467 we better not examine the prologue to see whether registers
1468 have been saved yet. */
1471 /* We need to figure out whether the registers that the proc_desc
1472 claims are saved have been saved yet. */
1476 /* Bitmasks; set if we have found a save for the register. */
1477 unsigned long gen_save_found = 0;
1478 unsigned long float_save_found = 0;
1481 /* If the address is odd, assume this is MIPS16 code. */
1482 addr = PROC_LOW_ADDR (proc_desc);
1483 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1485 /* Scan through this function's instructions preceding the current
1486 PC, and look for those that save registers. */
1487 while (addr < get_frame_pc (fci))
1489 inst = mips_fetch_instruction (addr);
1490 if (pc_is_mips16 (addr))
1491 mips16_decode_reg_save (inst, &gen_save_found);
1493 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1496 gen_mask = gen_save_found;
1497 float_mask = float_save_found;
1500 /* Fill in the offsets for the registers which gen_mask says
1502 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1503 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1504 if (gen_mask & 0x80000000)
1506 get_frame_saved_regs (fci)[ireg] = reg_position;
1507 reg_position -= MIPS_SAVED_REGSIZE;
1510 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1511 of that normally used by gcc. Therefore, we have to fetch the first
1512 instruction of the function, and if it's an entry instruction that
1513 saves $s0 or $s1, correct their saved addresses. */
1514 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1516 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1517 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1520 int sreg_count = (inst >> 6) & 3;
1522 /* Check if the ra register was pushed on the stack. */
1523 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1525 reg_position -= MIPS_SAVED_REGSIZE;
1527 /* Check if the s0 and s1 registers were pushed on the stack. */
1528 for (reg = 16; reg < sreg_count + 16; reg++)
1530 get_frame_saved_regs (fci)[reg] = reg_position;
1531 reg_position -= MIPS_SAVED_REGSIZE;
1536 /* Fill in the offsets for the registers which float_mask says
1538 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1540 /* Apparently, the freg_offset gives the offset to the first 64 bit
1543 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1544 designates the first saved 64 bit register.
1546 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1547 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1548 FREG_OFFSET, designates the address of the lower register of the
1549 register pair. Adjust the offset so that it designates the upper
1550 register of the pair -- i.e., the address of the first saved 32
1553 if (MIPS_SAVED_REGSIZE == 4)
1554 reg_position += MIPS_SAVED_REGSIZE;
1556 /* Fill in the offsets for the float registers which float_mask says
1558 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1559 if (float_mask & 0x80000000)
1561 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1562 reg_position -= MIPS_SAVED_REGSIZE;
1565 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1568 /* Set up the 'saved_regs' array. This is a data structure containing
1569 the addresses on the stack where each register has been saved, for
1570 each stack frame. Registers that have not been saved will have
1571 zero here. The stack pointer register is special: rather than the
1572 address where the stack register has been saved, saved_regs[SP_REGNUM]
1573 will have the actual value of the previous frame's stack register. */
1576 mips_frame_init_saved_regs (struct frame_info *frame)
1578 if (get_frame_saved_regs (frame) == NULL)
1580 mips_find_saved_regs (frame);
1582 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1586 read_next_frame_reg (struct frame_info *fi, int regno)
1591 enum lval_type lval;
1592 void *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
1596 regcache_cooked_read (current_regcache, regno, raw_buffer);
1600 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1602 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1603 should have a pseudo register range that correspons to the ABI's,
1604 rather than the ISA's, view of registers. These registers would
1605 then implicitly describe their size and hence could be used
1606 without the below munging. */
1607 if (lval == lval_memory)
1611 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1613 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1618 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1621 /* mips_addr_bits_remove - remove useless address bits */
1624 mips_addr_bits_remove (CORE_ADDR addr)
1626 if (GDB_TARGET_IS_MIPS64)
1628 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1630 /* This hack is a work-around for existing boards using
1631 PMON, the simulator, and any other 64-bit targets that
1632 doesn't have true 64-bit addressing. On these targets,
1633 the upper 32 bits of addresses are ignored by the
1634 hardware. Thus, the PC or SP are likely to have been
1635 sign extended to all 1s by instruction sequences that
1636 load 32-bit addresses. For example, a typical piece of
1637 code that loads an address is this:
1638 lui $r2, <upper 16 bits>
1639 ori $r2, <lower 16 bits>
1640 But the lui sign-extends the value such that the upper 32
1641 bits may be all 1s. The workaround is simply to mask off
1642 these bits. In the future, gcc may be changed to support
1643 true 64-bit addressing, and this masking will have to be
1645 addr &= (CORE_ADDR) 0xffffffff;
1648 else if (mips_mask_address_p ())
1650 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1651 masking off bits, instead, the actual target should be asking
1652 for the address to be converted to a valid pointer. */
1653 /* Even when GDB is configured for some 32-bit targets
1654 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1655 so CORE_ADDR is 64 bits. So we still have to mask off
1656 useless bits from addresses. */
1657 addr &= (CORE_ADDR) 0xffffffff;
1662 /* mips_software_single_step() is called just before we want to resume
1663 the inferior, if we want to single-step it but there is no hardware
1664 or kernel single-step support (MIPS on GNU/Linux for example). We find
1665 the target of the coming instruction and breakpoint it.
1667 single_step is also called just after the inferior stops. If we had
1668 set up a simulated single-step, we undo our damage. */
1671 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1673 static CORE_ADDR next_pc;
1674 typedef char binsn_quantum[BREAKPOINT_MAX];
1675 static binsn_quantum break_mem;
1678 if (insert_breakpoints_p)
1680 pc = read_register (PC_REGNUM);
1681 next_pc = mips_next_pc (pc);
1683 target_insert_breakpoint (next_pc, break_mem);
1686 target_remove_breakpoint (next_pc, break_mem);
1690 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1695 ? SAVED_PC_AFTER_CALL (get_next_frame (prev))
1696 : get_next_frame (prev)
1697 ? FRAME_SAVED_PC (get_next_frame (prev))
1699 tmp = SKIP_TRAMPOLINE_CODE (pc);
1700 return tmp ? tmp : pc;
1705 mips_frame_saved_pc (struct frame_info *frame)
1708 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1709 /* We have to get the saved pc from the sigcontext
1710 if it is a signal handler frame. */
1711 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1712 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1714 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1717 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1720 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1721 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1723 saved_pc = read_next_frame_reg (frame, pcreg);
1725 return ADDR_BITS_REMOVE (saved_pc);
1728 static struct mips_extra_func_info temp_proc_desc;
1730 /* This hack will go away once the get_prev_frame() code has been
1731 modified to set the frame's type first. That is BEFORE init extra
1732 frame info et.al. is called. This is because it will become
1733 possible to skip the init extra info call for sigtramp and dummy
1735 static CORE_ADDR *temp_saved_regs;
1737 /* Set a register's saved stack address in temp_saved_regs. If an address
1738 has already been set for this register, do nothing; this way we will
1739 only recognize the first save of a given register in a function prologue.
1740 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1743 set_reg_offset (int regno, CORE_ADDR offset)
1745 if (temp_saved_regs[regno] == 0)
1746 temp_saved_regs[regno] = offset;
1750 /* Test whether the PC points to the return instruction at the
1751 end of a function. */
1754 mips_about_to_return (CORE_ADDR pc)
1756 if (pc_is_mips16 (pc))
1757 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1758 generates a "jr $ra"; other times it generates code to load
1759 the return address from the stack to an accessible register (such
1760 as $a3), then a "jr" using that register. This second case
1761 is almost impossible to distinguish from an indirect jump
1762 used for switch statements, so we don't even try. */
1763 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1765 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1769 /* This fencepost looks highly suspicious to me. Removing it also
1770 seems suspicious as it could affect remote debugging across serial
1774 heuristic_proc_start (CORE_ADDR pc)
1781 pc = ADDR_BITS_REMOVE (pc);
1783 fence = start_pc - heuristic_fence_post;
1787 if (heuristic_fence_post == UINT_MAX
1788 || fence < VM_MIN_ADDRESS)
1789 fence = VM_MIN_ADDRESS;
1791 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1793 /* search back for previous return */
1794 for (start_pc -= instlen;; start_pc -= instlen)
1795 if (start_pc < fence)
1797 /* It's not clear to me why we reach this point when
1798 stop_soon_quietly, but with this test, at least we
1799 don't print out warnings for every child forked (eg, on
1801 if (!stop_soon_quietly)
1803 static int blurb_printed = 0;
1805 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1810 /* This actually happens frequently in embedded
1811 development, when you first connect to a board
1812 and your stack pointer and pc are nowhere in
1813 particular. This message needs to give people
1814 in that situation enough information to
1815 determine that it's no big deal. */
1816 printf_filtered ("\n\
1817 GDB is unable to find the start of the function at 0x%s\n\
1818 and thus can't determine the size of that function's stack frame.\n\
1819 This means that GDB may be unable to access that stack frame, or\n\
1820 the frames below it.\n\
1821 This problem is most likely caused by an invalid program counter or\n\
1823 However, if you think GDB should simply search farther back\n\
1824 from 0x%s for code which looks like the beginning of a\n\
1825 function, you can increase the range of the search using the `set\n\
1826 heuristic-fence-post' command.\n",
1827 paddr_nz (pc), paddr_nz (pc));
1834 else if (pc_is_mips16 (start_pc))
1836 unsigned short inst;
1838 /* On MIPS16, any one of the following is likely to be the
1839 start of a function:
1843 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1844 inst = mips_fetch_instruction (start_pc);
1845 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1846 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1847 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1848 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1850 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1851 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1856 else if (mips_about_to_return (start_pc))
1858 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1865 /* Fetch the immediate value from a MIPS16 instruction.
1866 If the previous instruction was an EXTEND, use it to extend
1867 the upper bits of the immediate value. This is a helper function
1868 for mips16_heuristic_proc_desc. */
1871 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1872 unsigned short inst, /* current instruction */
1873 int nbits, /* number of bits in imm field */
1874 int scale, /* scale factor to be applied to imm */
1875 int is_signed) /* is the imm field signed? */
1879 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1881 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1882 if (offset & 0x8000) /* check for negative extend */
1883 offset = 0 - (0x10000 - (offset & 0xffff));
1884 return offset | (inst & 0x1f);
1888 int max_imm = 1 << nbits;
1889 int mask = max_imm - 1;
1890 int sign_bit = max_imm >> 1;
1892 offset = inst & mask;
1893 if (is_signed && (offset & sign_bit))
1894 offset = 0 - (max_imm - offset);
1895 return offset * scale;
1900 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1901 stream from start_pc to limit_pc. */
1904 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1905 struct frame_info *next_frame, CORE_ADDR sp)
1908 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1909 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1910 unsigned inst = 0; /* current instruction */
1911 unsigned entry_inst = 0; /* the entry instruction */
1914 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1915 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1917 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1919 /* Save the previous instruction. If it's an EXTEND, we'll extract
1920 the immediate offset extension from it in mips16_get_imm. */
1923 /* Fetch and decode the instruction. */
1924 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1925 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1926 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1928 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1929 if (offset < 0) /* negative stack adjustment? */
1930 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1932 /* Exit loop if a positive stack adjustment is found, which
1933 usually means that the stack cleanup code in the function
1934 epilogue is reached. */
1937 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1939 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1940 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1941 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1942 set_reg_offset (reg, sp + offset);
1944 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1946 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1947 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1948 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1949 set_reg_offset (reg, sp + offset);
1951 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1953 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1954 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1955 set_reg_offset (RA_REGNUM, sp + offset);
1957 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1959 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1960 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1961 set_reg_offset (RA_REGNUM, sp + offset);
1963 else if (inst == 0x673d) /* move $s1, $sp */
1966 PROC_FRAME_REG (&temp_proc_desc) = 17;
1968 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1970 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1971 frame_addr = sp + offset;
1972 PROC_FRAME_REG (&temp_proc_desc) = 17;
1973 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
1975 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1977 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1978 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1979 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
1980 set_reg_offset (reg, frame_addr + offset);
1982 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1984 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1985 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1986 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
1987 set_reg_offset (reg, frame_addr + offset);
1989 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1990 entry_inst = inst; /* save for later processing */
1991 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
1992 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
1995 /* The entry instruction is typically the first instruction in a function,
1996 and it stores registers at offsets relative to the value of the old SP
1997 (before the prologue). But the value of the sp parameter to this
1998 function is the new SP (after the prologue has been executed). So we
1999 can't calculate those offsets until we've seen the entire prologue,
2000 and can calculate what the old SP must have been. */
2001 if (entry_inst != 0)
2003 int areg_count = (entry_inst >> 8) & 7;
2004 int sreg_count = (entry_inst >> 6) & 3;
2006 /* The entry instruction always subtracts 32 from the SP. */
2007 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2009 /* Now we can calculate what the SP must have been at the
2010 start of the function prologue. */
2011 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2013 /* Check if a0-a3 were saved in the caller's argument save area. */
2014 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2016 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2017 set_reg_offset (reg, sp + offset);
2018 offset += MIPS_SAVED_REGSIZE;
2021 /* Check if the ra register was pushed on the stack. */
2023 if (entry_inst & 0x20)
2025 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2026 set_reg_offset (RA_REGNUM, sp + offset);
2027 offset -= MIPS_SAVED_REGSIZE;
2030 /* Check if the s0 and s1 registers were pushed on the stack. */
2031 for (reg = 16; reg < sreg_count + 16; reg++)
2033 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2034 set_reg_offset (reg, sp + offset);
2035 offset -= MIPS_SAVED_REGSIZE;
2041 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2042 struct frame_info *next_frame, CORE_ADDR sp)
2045 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2047 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2048 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2049 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2050 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2051 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2053 unsigned long inst, high_word, low_word;
2056 /* Fetch the instruction. */
2057 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2059 /* Save some code by pre-extracting some useful fields. */
2060 high_word = (inst >> 16) & 0xffff;
2061 low_word = inst & 0xffff;
2062 reg = high_word & 0x1f;
2064 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2065 || high_word == 0x23bd /* addi $sp,$sp,-i */
2066 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2068 if (low_word & 0x8000) /* negative stack adjustment? */
2069 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2071 /* Exit loop if a positive stack adjustment is found, which
2072 usually means that the stack cleanup code in the function
2073 epilogue is reached. */
2076 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2078 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2079 set_reg_offset (reg, sp + low_word);
2081 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2083 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2084 but the register size used is only 32 bits. Make the address
2085 for the saved register point to the lower 32 bits. */
2086 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2087 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2089 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2091 /* Old gcc frame, r30 is virtual frame pointer. */
2092 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2093 frame_addr = sp + low_word;
2094 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2096 unsigned alloca_adjust;
2097 PROC_FRAME_REG (&temp_proc_desc) = 30;
2098 frame_addr = read_next_frame_reg (next_frame, 30);
2099 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2100 if (alloca_adjust > 0)
2102 /* FP > SP + frame_size. This may be because
2103 * of an alloca or somethings similar.
2104 * Fix sp to "pre-alloca" value, and try again.
2106 sp += alloca_adjust;
2111 /* move $30,$sp. With different versions of gas this will be either
2112 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2113 Accept any one of these. */
2114 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2116 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2117 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);
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 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2136 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2137 set_reg_offset (reg, frame_addr + low_word);
2142 static mips_extra_func_info_t
2143 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2144 struct frame_info *next_frame, int cur_frame)
2149 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2155 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2156 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2157 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2158 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2159 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2160 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2162 if (start_pc + 200 < limit_pc)
2163 limit_pc = start_pc + 200;
2164 if (pc_is_mips16 (start_pc))
2165 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2167 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2168 return &temp_proc_desc;
2171 struct mips_objfile_private
2177 /* Global used to communicate between non_heuristic_proc_desc and
2178 compare_pdr_entries within qsort (). */
2179 static bfd *the_bfd;
2182 compare_pdr_entries (const void *a, const void *b)
2184 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2185 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2189 else if (lhs == rhs)
2195 static mips_extra_func_info_t
2196 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2198 CORE_ADDR startaddr;
2199 mips_extra_func_info_t proc_desc;
2200 struct block *b = block_for_pc (pc);
2202 struct obj_section *sec;
2203 struct mips_objfile_private *priv;
2205 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2208 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2210 *addrptr = startaddr;
2214 sec = find_pc_section (pc);
2217 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2219 /* Search the ".pdr" section generated by GAS. This includes most of
2220 the information normally found in ECOFF PDRs. */
2222 the_bfd = sec->objfile->obfd;
2224 && (the_bfd->format == bfd_object
2225 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2226 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2228 /* Right now GAS only outputs the address as a four-byte sequence.
2229 This means that we should not bother with this method on 64-bit
2230 targets (until that is fixed). */
2232 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2233 sizeof (struct mips_objfile_private));
2235 sec->objfile->obj_private = priv;
2237 else if (priv == NULL)
2241 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2242 sizeof (struct mips_objfile_private));
2244 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2247 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2248 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2250 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2251 priv->contents, 0, priv->size);
2253 /* In general, the .pdr section is sorted. However, in the
2254 presence of multiple code sections (and other corner cases)
2255 it can become unsorted. Sort it so that we can use a faster
2257 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2262 sec->objfile->obj_private = priv;
2266 if (priv->size != 0)
2272 high = priv->size / 32;
2278 mid = (low + high) / 2;
2280 ptr = priv->contents + mid * 32;
2281 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2282 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2283 SECT_OFF_TEXT (sec->objfile));
2284 if (pdr_pc == startaddr)
2286 if (pdr_pc > startaddr)
2291 while (low != high);
2295 struct symbol *sym = find_pc_function (pc);
2297 /* Fill in what we need of the proc_desc. */
2298 proc_desc = (mips_extra_func_info_t)
2299 obstack_alloc (&sec->objfile->psymbol_obstack,
2300 sizeof (struct mips_extra_func_info));
2301 PROC_LOW_ADDR (proc_desc) = startaddr;
2303 /* Only used for dummy frames. */
2304 PROC_HIGH_ADDR (proc_desc) = 0;
2306 PROC_FRAME_OFFSET (proc_desc)
2307 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2308 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2310 PROC_FRAME_ADJUST (proc_desc) = 0;
2311 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2313 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2315 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2317 PROC_FREG_OFFSET (proc_desc)
2318 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2319 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2321 proc_desc->pdr.isym = (long) sym;
2331 if (startaddr > BLOCK_START (b))
2333 /* This is the "pathological" case referred to in a comment in
2334 print_frame_info. It might be better to move this check into
2339 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
2341 /* If we never found a PDR for this function in symbol reading, then
2342 examine prologues to find the information. */
2345 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2346 if (PROC_FRAME_REG (proc_desc) == -1)
2356 static mips_extra_func_info_t
2357 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2359 mips_extra_func_info_t proc_desc;
2360 CORE_ADDR startaddr = 0;
2362 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2366 /* IF this is the topmost frame AND
2367 * (this proc does not have debugging information OR
2368 * the PC is in the procedure prologue)
2369 * THEN create a "heuristic" proc_desc (by analyzing
2370 * the actual code) to replace the "official" proc_desc.
2372 if (next_frame == NULL)
2374 struct symtab_and_line val;
2375 struct symbol *proc_symbol =
2376 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2380 val = find_pc_line (BLOCK_START
2381 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2383 val.pc = val.end ? val.end : pc;
2385 if (!proc_symbol || pc < val.pc)
2387 mips_extra_func_info_t found_heuristic =
2388 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2389 pc, next_frame, cur_frame);
2390 if (found_heuristic)
2391 proc_desc = found_heuristic;
2397 /* Is linked_proc_desc_table really necessary? It only seems to be used
2398 by procedure call dummys. However, the procedures being called ought
2399 to have their own proc_descs, and even if they don't,
2400 heuristic_proc_desc knows how to create them! */
2402 register struct linked_proc_info *link;
2404 for (link = linked_proc_desc_table; link; link = link->next)
2405 if (PROC_LOW_ADDR (&link->info) <= pc
2406 && PROC_HIGH_ADDR (&link->info) > pc)
2410 startaddr = heuristic_proc_start (pc);
2413 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2419 get_frame_pointer (struct frame_info *frame,
2420 mips_extra_func_info_t proc_desc)
2422 return ADDR_BITS_REMOVE (read_next_frame_reg (frame,
2423 PROC_FRAME_REG (proc_desc)) +
2424 PROC_FRAME_OFFSET (proc_desc) -
2425 PROC_FRAME_ADJUST (proc_desc));
2428 static mips_extra_func_info_t cached_proc_desc;
2431 mips_frame_chain (struct frame_info *frame)
2433 mips_extra_func_info_t proc_desc;
2435 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
2437 if (saved_pc == 0 || inside_entry_file (saved_pc))
2440 /* Check if the PC is inside a call stub. If it is, fetch the
2441 PC of the caller of that stub. */
2442 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2445 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2447 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2448 is well, frame->frame the bottom of the current frame will
2449 contain that value. */
2450 return get_frame_base (frame);
2453 /* Look up the procedure descriptor for this PC. */
2454 proc_desc = find_proc_desc (saved_pc, frame, 1);
2458 cached_proc_desc = proc_desc;
2460 /* If no frame pointer and frame size is zero, we must be at end
2461 of stack (or otherwise hosed). If we don't check frame size,
2462 we loop forever if we see a zero size frame. */
2463 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2464 && PROC_FRAME_OFFSET (proc_desc) == 0
2465 /* The previous frame from a sigtramp frame might be frameless
2466 and have frame size zero. */
2467 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2468 /* For a generic dummy frame, let get_frame_pointer() unwind a
2469 register value saved as part of the dummy frame call. */
2470 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2473 return get_frame_pointer (frame, proc_desc);
2477 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2480 mips_extra_func_info_t proc_desc;
2482 if (get_frame_type (fci) == DUMMY_FRAME)
2485 /* Use proc_desc calculated in frame_chain. When there is no
2486 next frame, i.e, get_next_frame (fci) == NULL, we call
2487 find_proc_desc () to calculate it, passing an explicit
2488 NULL as the frame parameter. */
2490 get_next_frame (fci)
2492 : find_proc_desc (get_frame_pc (fci),
2493 NULL /* i.e, get_next_frame (fci) */,
2496 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2498 deprecated_set_frame_saved_regs_hack (fci, NULL);
2499 get_frame_extra_info (fci)->proc_desc =
2500 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2503 /* Fixup frame-pointer - only needed for top frame */
2504 /* This may not be quite right, if proc has a real frame register.
2505 Get the value of the frame relative sp, procedure might have been
2506 interrupted by a signal at it's very start. */
2507 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2508 && !PROC_DESC_IS_DUMMY (proc_desc))
2509 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2510 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2511 /* Do not ``fix'' fci->frame. It will have the value of the
2512 generic dummy frame's top-of-stack (since the draft
2513 fci->frame is obtained by returning the unwound stack
2514 pointer) and that is what we want. That way the fci->frame
2515 value will match the top-of-stack value that was saved as
2516 part of the dummy frames data. */
2519 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2521 if (proc_desc == &temp_proc_desc)
2525 /* Do not set the saved registers for a sigtramp frame,
2526 mips_find_saved_registers will do that for us. We can't
2527 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2529 /* FIXME: cagney/2002-11-18: This problem will go away once
2530 frame.c:get_prev_frame() is modified to set the frame's
2531 type before calling functions like this. */
2532 find_pc_partial_function (get_frame_pc (fci), &name,
2533 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2534 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2536 frame_saved_regs_zalloc (fci);
2537 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2538 get_frame_saved_regs (fci)[PC_REGNUM]
2539 = get_frame_saved_regs (fci)[RA_REGNUM];
2540 /* Set value of previous frame's stack pointer. Remember that
2541 saved_regs[SP_REGNUM] is special in that it contains the
2542 value of the stack pointer register. The other saved_regs
2543 values are addresses (in the inferior) at which a given
2544 register's value may be found. */
2545 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2549 /* hack: if argument regs are saved, guess these contain args */
2550 /* assume we can't tell how many args for now */
2551 get_frame_extra_info (fci)->num_args = -1;
2552 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2554 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2556 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2563 /* MIPS stack frames are almost impenetrable. When execution stops,
2564 we basically have to look at symbol information for the function
2565 that we stopped in, which tells us *which* register (if any) is
2566 the base of the frame pointer, and what offset from that register
2567 the frame itself is at.
2569 This presents a problem when trying to examine a stack in memory
2570 (that isn't executing at the moment), using the "frame" command. We
2571 don't have a PC, nor do we have any registers except SP.
2573 This routine takes two arguments, SP and PC, and tries to make the
2574 cached frames look as if these two arguments defined a frame on the
2575 cache. This allows the rest of info frame to extract the important
2576 arguments without difficulty. */
2579 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2582 error ("MIPS frame specifications require two arguments: sp and pc");
2584 return create_new_frame (argv[0], argv[1]);
2587 /* According to the current ABI, should the type be passed in a
2588 floating-point register (assuming that there is space)? When there
2589 is no FPU, FP are not even considered as possibile candidates for
2590 FP registers and, consequently this returns false - forces FP
2591 arguments into integer registers. */
2594 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2596 return ((typecode == TYPE_CODE_FLT
2598 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2599 && TYPE_NFIELDS (arg_type) == 1
2600 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2601 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2604 /* On o32, argument passing in GPRs depends on the alignment of the type being
2605 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2608 mips_type_needs_double_align (struct type *type)
2610 enum type_code typecode = TYPE_CODE (type);
2612 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2614 else if (typecode == TYPE_CODE_STRUCT)
2616 if (TYPE_NFIELDS (type) < 1)
2618 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2620 else if (typecode == TYPE_CODE_UNION)
2624 n = TYPE_NFIELDS (type);
2625 for (i = 0; i < n; i++)
2626 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2633 /* Macros to round N up or down to the next A boundary;
2634 A must be a power of two. */
2636 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2637 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2639 /* Adjust the address downward (direction of stack growth) so that it
2640 is correctly aligned for a new stack frame. */
2642 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2644 return ROUND_DOWN (addr, 16);
2648 mips_eabi_push_arguments (int nargs,
2649 struct value **args,
2652 CORE_ADDR struct_addr)
2658 int stack_offset = 0;
2660 /* First ensure that the stack and structure return address (if any)
2661 are properly aligned. The stack has to be at least 64-bit
2662 aligned even on 32-bit machines, because doubles must be 64-bit
2663 aligned. For n32 and n64, stack frames need to be 128-bit
2664 aligned, so we round to this widest known alignment. */
2666 sp = ROUND_DOWN (sp, 16);
2667 struct_addr = ROUND_DOWN (struct_addr, 16);
2669 /* Now make space on the stack for the args. We allocate more
2670 than necessary for EABI, because the first few arguments are
2671 passed in registers, but that's OK. */
2672 for (argnum = 0; argnum < nargs; argnum++)
2673 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2674 MIPS_STACK_ARGSIZE);
2675 sp -= ROUND_UP (len, 16);
2678 fprintf_unfiltered (gdb_stdlog,
2679 "mips_eabi_push_arguments: sp=0x%s allocated %d\n",
2680 paddr_nz (sp), ROUND_UP (len, 16));
2682 /* Initialize the integer and float register pointers. */
2684 float_argreg = FPA0_REGNUM;
2686 /* The struct_return pointer occupies the first parameter-passing reg. */
2690 fprintf_unfiltered (gdb_stdlog,
2691 "mips_eabi_push_arguments: struct_return reg=%d 0x%s\n",
2692 argreg, paddr_nz (struct_addr));
2693 write_register (argreg++, struct_addr);
2696 /* Now load as many as possible of the first arguments into
2697 registers, and push the rest onto the stack. Loop thru args
2698 from first to last. */
2699 for (argnum = 0; argnum < nargs; argnum++)
2702 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2703 struct value *arg = args[argnum];
2704 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2705 int len = TYPE_LENGTH (arg_type);
2706 enum type_code typecode = TYPE_CODE (arg_type);
2709 fprintf_unfiltered (gdb_stdlog,
2710 "mips_eabi_push_arguments: %d len=%d type=%d",
2711 argnum + 1, len, (int) typecode);
2713 /* The EABI passes structures that do not fit in a register by
2715 if (len > MIPS_SAVED_REGSIZE
2716 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2718 store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2719 typecode = TYPE_CODE_PTR;
2720 len = MIPS_SAVED_REGSIZE;
2723 fprintf_unfiltered (gdb_stdlog, " push");
2726 val = (char *) VALUE_CONTENTS (arg);
2728 /* 32-bit ABIs always start floating point arguments in an
2729 even-numbered floating point register. Round the FP register
2730 up before the check to see if there are any FP registers
2731 left. Non MIPS_EABI targets also pass the FP in the integer
2732 registers so also round up normal registers. */
2733 if (!FP_REGISTER_DOUBLE
2734 && fp_register_arg_p (typecode, arg_type))
2736 if ((float_argreg & 1))
2740 /* Floating point arguments passed in registers have to be
2741 treated specially. On 32-bit architectures, doubles
2742 are passed in register pairs; the even register gets
2743 the low word, and the odd register gets the high word.
2744 On non-EABI processors, the first two floating point arguments are
2745 also copied to general registers, because MIPS16 functions
2746 don't use float registers for arguments. This duplication of
2747 arguments in general registers can't hurt non-MIPS16 functions
2748 because those registers are normally skipped. */
2749 /* MIPS_EABI squeezes a struct that contains a single floating
2750 point value into an FP register instead of pushing it onto the
2752 if (fp_register_arg_p (typecode, arg_type)
2753 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2755 if (!FP_REGISTER_DOUBLE && len == 8)
2757 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2758 unsigned long regval;
2760 /* Write the low word of the double to the even register(s). */
2761 regval = extract_unsigned_integer (val + low_offset, 4);
2763 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2764 float_argreg, phex (regval, 4));
2765 write_register (float_argreg++, regval);
2767 /* Write the high word of the double to the odd register(s). */
2768 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2770 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2771 float_argreg, phex (regval, 4));
2772 write_register (float_argreg++, regval);
2776 /* This is a floating point value that fits entirely
2777 in a single register. */
2778 /* On 32 bit ABI's the float_argreg is further adjusted
2779 above to ensure that it is even register aligned. */
2780 LONGEST regval = extract_unsigned_integer (val, len);
2782 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2783 float_argreg, phex (regval, len));
2784 write_register (float_argreg++, regval);
2789 /* Copy the argument to general registers or the stack in
2790 register-sized pieces. Large arguments are split between
2791 registers and stack. */
2792 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2793 are treated specially: Irix cc passes them in registers
2794 where gcc sometimes puts them on the stack. For maximum
2795 compatibility, we will put them in both places. */
2796 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2797 (len % MIPS_SAVED_REGSIZE != 0));
2799 /* Note: Floating-point values that didn't fit into an FP
2800 register are only written to memory. */
2803 /* Remember if the argument was written to the stack. */
2804 int stack_used_p = 0;
2806 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2809 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2812 /* Write this portion of the argument to the stack. */
2813 if (argreg > MIPS_LAST_ARG_REGNUM
2815 || fp_register_arg_p (typecode, arg_type))
2817 /* Should shorter than int integer values be
2818 promoted to int before being stored? */
2819 int longword_offset = 0;
2822 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2824 if (MIPS_STACK_ARGSIZE == 8 &&
2825 (typecode == TYPE_CODE_INT ||
2826 typecode == TYPE_CODE_PTR ||
2827 typecode == TYPE_CODE_FLT) && len <= 4)
2828 longword_offset = MIPS_STACK_ARGSIZE - len;
2829 else if ((typecode == TYPE_CODE_STRUCT ||
2830 typecode == TYPE_CODE_UNION) &&
2831 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2832 longword_offset = MIPS_STACK_ARGSIZE - len;
2837 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2838 paddr_nz (stack_offset));
2839 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2840 paddr_nz (longword_offset));
2843 addr = sp + stack_offset + longword_offset;
2848 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2850 for (i = 0; i < partial_len; i++)
2852 fprintf_unfiltered (gdb_stdlog, "%02x",
2856 write_memory (addr, val, partial_len);
2859 /* Note!!! This is NOT an else clause. Odd sized
2860 structs may go thru BOTH paths. Floating point
2861 arguments will not. */
2862 /* Write this portion of the argument to a general
2863 purpose register. */
2864 if (argreg <= MIPS_LAST_ARG_REGNUM
2865 && !fp_register_arg_p (typecode, arg_type))
2867 LONGEST regval = extract_unsigned_integer (val, partial_len);
2870 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2872 phex (regval, MIPS_SAVED_REGSIZE));
2873 write_register (argreg, regval);
2880 /* Compute the the offset into the stack at which we
2881 will copy the next parameter.
2883 In the new EABI (and the NABI32), the stack_offset
2884 only needs to be adjusted when it has been used. */
2887 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2891 fprintf_unfiltered (gdb_stdlog, "\n");
2894 /* Return adjusted stack pointer. */
2898 /* N32/N64 version of push_arguments. */
2901 mips_n32n64_push_arguments (int nargs,
2902 struct value **args,
2905 CORE_ADDR struct_addr)
2911 int stack_offset = 0;
2913 /* First ensure that the stack and structure return address (if any)
2914 are properly aligned. The stack has to be at least 64-bit
2915 aligned even on 32-bit machines, because doubles must be 64-bit
2916 aligned. For n32 and n64, stack frames need to be 128-bit
2917 aligned, so we round to this widest known alignment. */
2919 sp = ROUND_DOWN (sp, 16);
2920 struct_addr = ROUND_DOWN (struct_addr, 16);
2922 /* Now make space on the stack for the args. */
2923 for (argnum = 0; argnum < nargs; argnum++)
2924 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2925 MIPS_STACK_ARGSIZE);
2926 sp -= ROUND_UP (len, 16);
2929 fprintf_unfiltered (gdb_stdlog,
2930 "mips_n32n64_push_arguments: sp=0x%s allocated %d\n",
2931 paddr_nz (sp), ROUND_UP (len, 16));
2933 /* Initialize the integer and float register pointers. */
2935 float_argreg = FPA0_REGNUM;
2937 /* The struct_return pointer occupies the first parameter-passing reg. */
2941 fprintf_unfiltered (gdb_stdlog,
2942 "mips_n32n64_push_arguments: struct_return reg=%d 0x%s\n",
2943 argreg, paddr_nz (struct_addr));
2944 write_register (argreg++, struct_addr);
2947 /* Now load as many as possible of the first arguments into
2948 registers, and push the rest onto the stack. Loop thru args
2949 from first to last. */
2950 for (argnum = 0; argnum < nargs; argnum++)
2953 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2954 struct value *arg = args[argnum];
2955 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2956 int len = TYPE_LENGTH (arg_type);
2957 enum type_code typecode = TYPE_CODE (arg_type);
2960 fprintf_unfiltered (gdb_stdlog,
2961 "mips_n32n64_push_arguments: %d len=%d type=%d",
2962 argnum + 1, len, (int) typecode);
2964 val = (char *) VALUE_CONTENTS (arg);
2966 if (fp_register_arg_p (typecode, arg_type)
2967 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2969 /* This is a floating point value that fits entirely
2970 in a single register. */
2971 /* On 32 bit ABI's the float_argreg is further adjusted
2972 above to ensure that it is even register aligned. */
2973 LONGEST regval = extract_unsigned_integer (val, len);
2975 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2976 float_argreg, phex (regval, len));
2977 write_register (float_argreg++, regval);
2980 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
2981 argreg, phex (regval, len));
2982 write_register (argreg, regval);
2987 /* Copy the argument to general registers or the stack in
2988 register-sized pieces. Large arguments are split between
2989 registers and stack. */
2990 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2991 are treated specially: Irix cc passes them in registers
2992 where gcc sometimes puts them on the stack. For maximum
2993 compatibility, we will put them in both places. */
2994 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2995 (len % MIPS_SAVED_REGSIZE != 0));
2996 /* Note: Floating-point values that didn't fit into an FP
2997 register are only written to memory. */
3000 /* Rememer if the argument was written to the stack. */
3001 int stack_used_p = 0;
3002 int partial_len = len < MIPS_SAVED_REGSIZE ?
3003 len : MIPS_SAVED_REGSIZE;
3006 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3009 /* Write this portion of the argument to the stack. */
3010 if (argreg > MIPS_LAST_ARG_REGNUM
3012 || fp_register_arg_p (typecode, arg_type))
3014 /* Should shorter than int integer values be
3015 promoted to int before being stored? */
3016 int longword_offset = 0;
3019 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3021 if (MIPS_STACK_ARGSIZE == 8 &&
3022 (typecode == TYPE_CODE_INT ||
3023 typecode == TYPE_CODE_PTR ||
3024 typecode == TYPE_CODE_FLT) && len <= 4)
3025 longword_offset = MIPS_STACK_ARGSIZE - len;
3030 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3031 paddr_nz (stack_offset));
3032 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3033 paddr_nz (longword_offset));
3036 addr = sp + stack_offset + longword_offset;
3041 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3043 for (i = 0; i < partial_len; i++)
3045 fprintf_unfiltered (gdb_stdlog, "%02x",
3049 write_memory (addr, val, partial_len);
3052 /* Note!!! This is NOT an else clause. Odd sized
3053 structs may go thru BOTH paths. Floating point
3054 arguments will not. */
3055 /* Write this portion of the argument to a general
3056 purpose register. */
3057 if (argreg <= MIPS_LAST_ARG_REGNUM
3058 && !fp_register_arg_p (typecode, arg_type))
3060 LONGEST regval = extract_unsigned_integer (val, partial_len);
3062 /* A non-floating-point argument being passed in a
3063 general register. If a struct or union, and if
3064 the remaining length is smaller than the register
3065 size, we have to adjust the register value on
3068 It does not seem to be necessary to do the
3069 same for integral types.
3071 cagney/2001-07-23: gdb/179: Also, GCC, when
3072 outputting LE O32 with sizeof (struct) <
3073 MIPS_SAVED_REGSIZE, generates a left shift as
3074 part of storing the argument in a register a
3075 register (the left shift isn't generated when
3076 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3077 is quite possible that this is GCC contradicting
3078 the LE/O32 ABI, GDB has not been adjusted to
3079 accommodate this. Either someone needs to
3080 demonstrate that the LE/O32 ABI specifies such a
3081 left shift OR this new ABI gets identified as
3082 such and GDB gets tweaked accordingly. */
3084 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3085 && partial_len < MIPS_SAVED_REGSIZE
3086 && (typecode == TYPE_CODE_STRUCT ||
3087 typecode == TYPE_CODE_UNION))
3088 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3092 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3094 phex (regval, MIPS_SAVED_REGSIZE));
3095 write_register (argreg, regval);
3102 /* Compute the the offset into the stack at which we
3103 will copy the next parameter.
3105 In N32 (N64?), the stack_offset only needs to be
3106 adjusted when it has been used. */
3109 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3113 fprintf_unfiltered (gdb_stdlog, "\n");
3116 /* Return adjusted stack pointer. */
3120 /* O32 version of push_arguments. */
3123 mips_o32_push_arguments (int nargs,
3124 struct value **args,
3127 CORE_ADDR struct_addr)
3133 int stack_offset = 0;
3135 /* First ensure that the stack and structure return address (if any)
3136 are properly aligned. The stack has to be at least 64-bit
3137 aligned even on 32-bit machines, because doubles must be 64-bit
3138 aligned. For n32 and n64, stack frames need to be 128-bit
3139 aligned, so we round to this widest known alignment. */
3141 sp = ROUND_DOWN (sp, 16);
3142 struct_addr = ROUND_DOWN (struct_addr, 16);
3144 /* Now make space on the stack for the args. */
3145 for (argnum = 0; argnum < nargs; argnum++)
3146 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3147 MIPS_STACK_ARGSIZE);
3148 sp -= ROUND_UP (len, 16);
3151 fprintf_unfiltered (gdb_stdlog,
3152 "mips_o32_push_arguments: sp=0x%s allocated %d\n",
3153 paddr_nz (sp), ROUND_UP (len, 16));
3155 /* Initialize the integer and float register pointers. */
3157 float_argreg = FPA0_REGNUM;
3159 /* The struct_return pointer occupies the first parameter-passing reg. */
3163 fprintf_unfiltered (gdb_stdlog,
3164 "mips_o32_push_arguments: struct_return reg=%d 0x%s\n",
3165 argreg, paddr_nz (struct_addr));
3166 write_register (argreg++, struct_addr);
3167 stack_offset += MIPS_STACK_ARGSIZE;
3170 /* Now load as many as possible of the first arguments into
3171 registers, and push the rest onto the stack. Loop thru args
3172 from first to last. */
3173 for (argnum = 0; argnum < nargs; argnum++)
3176 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3177 struct value *arg = args[argnum];
3178 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3179 int len = TYPE_LENGTH (arg_type);
3180 enum type_code typecode = TYPE_CODE (arg_type);
3183 fprintf_unfiltered (gdb_stdlog,
3184 "mips_o32_push_arguments: %d len=%d type=%d",
3185 argnum + 1, len, (int) typecode);
3187 val = (char *) VALUE_CONTENTS (arg);
3189 /* 32-bit ABIs always start floating point arguments in an
3190 even-numbered floating point register. Round the FP register
3191 up before the check to see if there are any FP registers
3192 left. O32/O64 targets also pass the FP in the integer
3193 registers so also round up normal registers. */
3194 if (!FP_REGISTER_DOUBLE
3195 && fp_register_arg_p (typecode, arg_type))
3197 if ((float_argreg & 1))
3201 /* Floating point arguments passed in registers have to be
3202 treated specially. On 32-bit architectures, doubles
3203 are passed in register pairs; the even register gets
3204 the low word, and the odd register gets the high word.
3205 On O32/O64, the first two floating point arguments are
3206 also copied to general registers, because MIPS16 functions
3207 don't use float registers for arguments. This duplication of
3208 arguments in general registers can't hurt non-MIPS16 functions
3209 because those registers are normally skipped. */
3211 if (fp_register_arg_p (typecode, arg_type)
3212 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3214 if (!FP_REGISTER_DOUBLE && len == 8)
3216 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3217 unsigned long regval;
3219 /* Write the low word of the double to the even register(s). */
3220 regval = extract_unsigned_integer (val + low_offset, 4);
3222 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3223 float_argreg, phex (regval, 4));
3224 write_register (float_argreg++, regval);
3226 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3227 argreg, phex (regval, 4));
3228 write_register (argreg++, regval);
3230 /* Write the high word of the double to the odd register(s). */
3231 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3233 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3234 float_argreg, phex (regval, 4));
3235 write_register (float_argreg++, regval);
3238 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3239 argreg, phex (regval, 4));
3240 write_register (argreg++, regval);
3244 /* This is a floating point value that fits entirely
3245 in a single register. */
3246 /* On 32 bit ABI's the float_argreg is further adjusted
3247 above to ensure that it is even register aligned. */
3248 LONGEST regval = extract_unsigned_integer (val, len);
3250 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3251 float_argreg, phex (regval, len));
3252 write_register (float_argreg++, regval);
3253 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3254 registers for each argument. The below is (my
3255 guess) to ensure that the corresponding integer
3256 register has reserved the same space. */
3258 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3259 argreg, phex (regval, len));
3260 write_register (argreg, regval);
3261 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3263 /* Reserve space for the FP register. */
3264 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3268 /* Copy the argument to general registers or the stack in
3269 register-sized pieces. Large arguments are split between
3270 registers and stack. */
3271 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3272 are treated specially: Irix cc passes them in registers
3273 where gcc sometimes puts them on the stack. For maximum
3274 compatibility, we will put them in both places. */
3275 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3276 (len % MIPS_SAVED_REGSIZE != 0));
3277 /* Structures should be aligned to eight bytes (even arg registers)
3278 on MIPS_ABI_O32, if their first member has double precision. */
3279 if (MIPS_SAVED_REGSIZE < 8
3280 && mips_type_needs_double_align (arg_type))
3285 /* Note: Floating-point values that didn't fit into an FP
3286 register are only written to memory. */
3289 /* Remember if the argument was written to the stack. */
3290 int stack_used_p = 0;
3292 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3295 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3298 /* Write this portion of the argument to the stack. */
3299 if (argreg > MIPS_LAST_ARG_REGNUM
3301 || fp_register_arg_p (typecode, arg_type))
3303 /* Should shorter than int integer values be
3304 promoted to int before being stored? */
3305 int longword_offset = 0;
3308 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3310 if (MIPS_STACK_ARGSIZE == 8 &&
3311 (typecode == TYPE_CODE_INT ||
3312 typecode == TYPE_CODE_PTR ||
3313 typecode == TYPE_CODE_FLT) && len <= 4)
3314 longword_offset = MIPS_STACK_ARGSIZE - len;
3319 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3320 paddr_nz (stack_offset));
3321 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3322 paddr_nz (longword_offset));
3325 addr = sp + stack_offset + longword_offset;
3330 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3332 for (i = 0; i < partial_len; i++)
3334 fprintf_unfiltered (gdb_stdlog, "%02x",
3338 write_memory (addr, val, partial_len);
3341 /* Note!!! This is NOT an else clause. Odd sized
3342 structs may go thru BOTH paths. Floating point
3343 arguments will not. */
3344 /* Write this portion of the argument to a general
3345 purpose register. */
3346 if (argreg <= MIPS_LAST_ARG_REGNUM
3347 && !fp_register_arg_p (typecode, arg_type))
3349 LONGEST regval = extract_signed_integer (val, partial_len);
3350 /* Value may need to be sign extended, because
3351 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3353 /* A non-floating-point argument being passed in a
3354 general register. If a struct or union, and if
3355 the remaining length is smaller than the register
3356 size, we have to adjust the register value on
3359 It does not seem to be necessary to do the
3360 same for integral types.
3362 Also don't do this adjustment on O64 binaries.
3364 cagney/2001-07-23: gdb/179: Also, GCC, when
3365 outputting LE O32 with sizeof (struct) <
3366 MIPS_SAVED_REGSIZE, generates a left shift as
3367 part of storing the argument in a register a
3368 register (the left shift isn't generated when
3369 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3370 is quite possible that this is GCC contradicting
3371 the LE/O32 ABI, GDB has not been adjusted to
3372 accommodate this. Either someone needs to
3373 demonstrate that the LE/O32 ABI specifies such a
3374 left shift OR this new ABI gets identified as
3375 such and GDB gets tweaked accordingly. */
3377 if (MIPS_SAVED_REGSIZE < 8
3378 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3379 && partial_len < MIPS_SAVED_REGSIZE
3380 && (typecode == TYPE_CODE_STRUCT ||
3381 typecode == TYPE_CODE_UNION))
3382 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3386 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3388 phex (regval, MIPS_SAVED_REGSIZE));
3389 write_register (argreg, regval);
3392 /* Prevent subsequent floating point arguments from
3393 being passed in floating point registers. */
3394 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3400 /* Compute the the offset into the stack at which we
3401 will copy the next parameter.
3403 In older ABIs, the caller reserved space for
3404 registers that contained arguments. This was loosely
3405 refered to as their "home". Consequently, space is
3406 always allocated. */
3408 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3412 fprintf_unfiltered (gdb_stdlog, "\n");
3415 /* Return adjusted stack pointer. */
3419 /* O64 version of push_arguments. */
3422 mips_o64_push_arguments (int nargs,
3423 struct value **args,
3426 CORE_ADDR struct_addr)
3432 int stack_offset = 0;
3434 /* First ensure that the stack and structure return address (if any)
3435 are properly aligned. The stack has to be at least 64-bit
3436 aligned even on 32-bit machines, because doubles must be 64-bit
3437 aligned. For n32 and n64, stack frames need to be 128-bit
3438 aligned, so we round to this widest known alignment. */
3440 sp = ROUND_DOWN (sp, 16);
3441 struct_addr = ROUND_DOWN (struct_addr, 16);
3443 /* Now make space on the stack for the args. */
3444 for (argnum = 0; argnum < nargs; argnum++)
3445 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3446 MIPS_STACK_ARGSIZE);
3447 sp -= ROUND_UP (len, 16);
3450 fprintf_unfiltered (gdb_stdlog,
3451 "mips_o64_push_arguments: sp=0x%s allocated %d\n",
3452 paddr_nz (sp), ROUND_UP (len, 16));
3454 /* Initialize the integer and float register pointers. */
3456 float_argreg = FPA0_REGNUM;
3458 /* The struct_return pointer occupies the first parameter-passing reg. */
3462 fprintf_unfiltered (gdb_stdlog,
3463 "mips_o64_push_arguments: struct_return reg=%d 0x%s\n",
3464 argreg, paddr_nz (struct_addr));
3465 write_register (argreg++, struct_addr);
3466 stack_offset += MIPS_STACK_ARGSIZE;
3469 /* Now load as many as possible of the first arguments into
3470 registers, and push the rest onto the stack. Loop thru args
3471 from first to last. */
3472 for (argnum = 0; argnum < nargs; argnum++)
3475 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3476 struct value *arg = args[argnum];
3477 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3478 int len = TYPE_LENGTH (arg_type);
3479 enum type_code typecode = TYPE_CODE (arg_type);
3482 fprintf_unfiltered (gdb_stdlog,
3483 "mips_o64_push_arguments: %d len=%d type=%d",
3484 argnum + 1, len, (int) typecode);
3486 val = (char *) VALUE_CONTENTS (arg);
3488 /* 32-bit ABIs always start floating point arguments in an
3489 even-numbered floating point register. Round the FP register
3490 up before the check to see if there are any FP registers
3491 left. O32/O64 targets also pass the FP in the integer
3492 registers so also round up normal registers. */
3493 if (!FP_REGISTER_DOUBLE
3494 && fp_register_arg_p (typecode, arg_type))
3496 if ((float_argreg & 1))
3500 /* Floating point arguments passed in registers have to be
3501 treated specially. On 32-bit architectures, doubles
3502 are passed in register pairs; the even register gets
3503 the low word, and the odd register gets the high word.
3504 On O32/O64, the first two floating point arguments are
3505 also copied to general registers, because MIPS16 functions
3506 don't use float registers for arguments. This duplication of
3507 arguments in general registers can't hurt non-MIPS16 functions
3508 because those registers are normally skipped. */
3510 if (fp_register_arg_p (typecode, arg_type)
3511 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3513 if (!FP_REGISTER_DOUBLE && len == 8)
3515 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3516 unsigned long regval;
3518 /* Write the low word of the double to the even register(s). */
3519 regval = extract_unsigned_integer (val + low_offset, 4);
3521 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3522 float_argreg, phex (regval, 4));
3523 write_register (float_argreg++, regval);
3525 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3526 argreg, phex (regval, 4));
3527 write_register (argreg++, regval);
3529 /* Write the high word of the double to the odd register(s). */
3530 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3532 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3533 float_argreg, phex (regval, 4));
3534 write_register (float_argreg++, regval);
3537 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3538 argreg, phex (regval, 4));
3539 write_register (argreg++, regval);
3543 /* This is a floating point value that fits entirely
3544 in a single register. */
3545 /* On 32 bit ABI's the float_argreg is further adjusted
3546 above to ensure that it is even register aligned. */
3547 LONGEST regval = extract_unsigned_integer (val, len);
3549 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3550 float_argreg, phex (regval, len));
3551 write_register (float_argreg++, regval);
3552 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3553 registers for each argument. The below is (my
3554 guess) to ensure that the corresponding integer
3555 register has reserved the same space. */
3557 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3558 argreg, phex (regval, len));
3559 write_register (argreg, regval);
3560 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3562 /* Reserve space for the FP register. */
3563 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3567 /* Copy the argument to general registers or the stack in
3568 register-sized pieces. Large arguments are split between
3569 registers and stack. */
3570 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3571 are treated specially: Irix cc passes them in registers
3572 where gcc sometimes puts them on the stack. For maximum
3573 compatibility, we will put them in both places. */
3574 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3575 (len % MIPS_SAVED_REGSIZE != 0));
3576 /* Structures should be aligned to eight bytes (even arg registers)
3577 on MIPS_ABI_O32, if their first member has double precision. */
3578 if (MIPS_SAVED_REGSIZE < 8
3579 && mips_type_needs_double_align (arg_type))
3584 /* Note: Floating-point values that didn't fit into an FP
3585 register are only written to memory. */
3588 /* Remember if the argument was written to the stack. */
3589 int stack_used_p = 0;
3591 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3594 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3597 /* Write this portion of the argument to the stack. */
3598 if (argreg > MIPS_LAST_ARG_REGNUM
3600 || fp_register_arg_p (typecode, arg_type))
3602 /* Should shorter than int integer values be
3603 promoted to int before being stored? */
3604 int longword_offset = 0;
3607 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3609 if (MIPS_STACK_ARGSIZE == 8 &&
3610 (typecode == TYPE_CODE_INT ||
3611 typecode == TYPE_CODE_PTR ||
3612 typecode == TYPE_CODE_FLT) && len <= 4)
3613 longword_offset = MIPS_STACK_ARGSIZE - len;
3618 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3619 paddr_nz (stack_offset));
3620 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3621 paddr_nz (longword_offset));
3624 addr = sp + stack_offset + longword_offset;
3629 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3631 for (i = 0; i < partial_len; i++)
3633 fprintf_unfiltered (gdb_stdlog, "%02x",
3637 write_memory (addr, val, partial_len);
3640 /* Note!!! This is NOT an else clause. Odd sized
3641 structs may go thru BOTH paths. Floating point
3642 arguments will not. */
3643 /* Write this portion of the argument to a general
3644 purpose register. */
3645 if (argreg <= MIPS_LAST_ARG_REGNUM
3646 && !fp_register_arg_p (typecode, arg_type))
3648 LONGEST regval = extract_signed_integer (val, partial_len);
3649 /* Value may need to be sign extended, because
3650 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3652 /* A non-floating-point argument being passed in a
3653 general register. If a struct or union, and if
3654 the remaining length is smaller than the register
3655 size, we have to adjust the register value on
3658 It does not seem to be necessary to do the
3659 same for integral types.
3661 Also don't do this adjustment on O64 binaries.
3663 cagney/2001-07-23: gdb/179: Also, GCC, when
3664 outputting LE O32 with sizeof (struct) <
3665 MIPS_SAVED_REGSIZE, generates a left shift as
3666 part of storing the argument in a register a
3667 register (the left shift isn't generated when
3668 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3669 is quite possible that this is GCC contradicting
3670 the LE/O32 ABI, GDB has not been adjusted to
3671 accommodate this. Either someone needs to
3672 demonstrate that the LE/O32 ABI specifies such a
3673 left shift OR this new ABI gets identified as
3674 such and GDB gets tweaked accordingly. */
3676 if (MIPS_SAVED_REGSIZE < 8
3677 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3678 && partial_len < MIPS_SAVED_REGSIZE
3679 && (typecode == TYPE_CODE_STRUCT ||
3680 typecode == TYPE_CODE_UNION))
3681 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3685 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3687 phex (regval, MIPS_SAVED_REGSIZE));
3688 write_register (argreg, regval);
3691 /* Prevent subsequent floating point arguments from
3692 being passed in floating point registers. */
3693 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3699 /* Compute the the offset into the stack at which we
3700 will copy the next parameter.
3702 In older ABIs, the caller reserved space for
3703 registers that contained arguments. This was loosely
3704 refered to as their "home". Consequently, space is
3705 always allocated. */
3707 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3711 fprintf_unfiltered (gdb_stdlog, "\n");
3714 /* Return adjusted stack pointer. */
3719 mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
3721 /* Set the return address register to point to the entry
3722 point of the program, where a breakpoint lies in wait. */
3723 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
3728 mips_push_register (CORE_ADDR * sp, int regno)
3730 char *buffer = alloca (MAX_REGISTER_RAW_SIZE);
3733 if (MIPS_SAVED_REGSIZE < REGISTER_RAW_SIZE (regno))
3735 regsize = MIPS_SAVED_REGSIZE;
3736 offset = (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3737 ? REGISTER_RAW_SIZE (regno) - MIPS_SAVED_REGSIZE
3742 regsize = REGISTER_RAW_SIZE (regno);
3746 deprecated_read_register_gen (regno, buffer);
3747 write_memory (*sp, buffer + offset, regsize);
3750 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
3751 #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
3754 mips_push_dummy_frame (void)
3757 struct linked_proc_info *link = (struct linked_proc_info *)
3758 xmalloc (sizeof (struct linked_proc_info));
3759 mips_extra_func_info_t proc_desc = &link->info;
3760 CORE_ADDR sp = ADDR_BITS_REMOVE (read_signed_register (SP_REGNUM));
3761 CORE_ADDR old_sp = sp;
3762 link->next = linked_proc_desc_table;
3763 linked_proc_desc_table = link;
3765 /* FIXME! are these correct ? */
3766 #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
3767 #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
3768 #define FLOAT_REG_SAVE_MASK MASK(0,19)
3769 #define FLOAT_SINGLE_REG_SAVE_MASK \
3770 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
3772 * The registers we must save are all those not preserved across
3773 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
3774 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
3775 * and FP Control/Status registers.
3778 * Dummy frame layout:
3781 * Saved MMHI, MMLO, FPC_CSR
3786 * Saved D18 (i.e. F19, F18)
3788 * Saved D0 (i.e. F1, F0)
3789 * Argument build area and stack arguments written via mips_push_arguments
3793 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
3794 PROC_FRAME_REG (proc_desc) = PUSH_FP_REGNUM;
3795 PROC_FRAME_OFFSET (proc_desc) = 0;
3796 PROC_FRAME_ADJUST (proc_desc) = 0;
3797 mips_push_register (&sp, PC_REGNUM);
3798 mips_push_register (&sp, HI_REGNUM);
3799 mips_push_register (&sp, LO_REGNUM);
3800 mips_push_register (&sp, MIPS_FPU_TYPE == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
3802 /* Save general CPU registers */
3803 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
3804 /* PROC_REG_OFFSET is the offset of the first saved register from FP. */
3805 PROC_REG_OFFSET (proc_desc) = sp - old_sp - MIPS_SAVED_REGSIZE;
3806 for (ireg = 32; --ireg >= 0;)
3807 if (PROC_REG_MASK (proc_desc) & (1 << ireg))
3808 mips_push_register (&sp, ireg);
3810 /* Save floating point registers starting with high order word */
3811 PROC_FREG_MASK (proc_desc) =
3812 MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
3813 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
3814 /* PROC_FREG_OFFSET is the offset of the first saved *double* register
3816 PROC_FREG_OFFSET (proc_desc) = sp - old_sp - 8;
3817 for (ireg = 32; --ireg >= 0;)
3818 if (PROC_FREG_MASK (proc_desc) & (1 << ireg))
3819 mips_push_register (&sp, ireg + FP0_REGNUM);
3821 /* Update the frame pointer for the call dummy and the stack pointer.
3822 Set the procedure's starting and ending addresses to point to the
3823 call dummy address at the entry point. */
3824 write_register (PUSH_FP_REGNUM, old_sp);
3825 write_register (SP_REGNUM, sp);
3826 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
3827 PROC_HIGH_ADDR (proc_desc) = CALL_DUMMY_ADDRESS () + 4;
3828 SET_PROC_DESC_IS_DUMMY (proc_desc);
3829 PROC_PC_REG (proc_desc) = RA_REGNUM;
3833 mips_pop_frame (void)
3835 register int regnum;
3836 struct frame_info *frame = get_current_frame ();
3837 CORE_ADDR new_sp = get_frame_base (frame);
3838 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
3840 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3842 generic_pop_dummy_frame ();
3843 flush_cached_frames ();
3847 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
3848 if (get_frame_saved_regs (frame) == NULL)
3849 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
3850 for (regnum = 0; regnum < NUM_REGS; regnum++)
3851 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3852 && get_frame_saved_regs (frame)[regnum])
3854 /* Floating point registers must not be sign extended,
3855 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3857 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3858 write_register (regnum,
3859 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3860 MIPS_SAVED_REGSIZE));
3862 write_register (regnum,
3863 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3864 MIPS_SAVED_REGSIZE));
3867 write_register (SP_REGNUM, new_sp);
3868 flush_cached_frames ();
3870 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3872 struct linked_proc_info *pi_ptr, *prev_ptr;
3874 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3876 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3878 if (&pi_ptr->info == proc_desc)
3883 error ("Can't locate dummy extra frame info\n");
3885 if (prev_ptr != NULL)
3886 prev_ptr->next = pi_ptr->next;
3888 linked_proc_desc_table = pi_ptr->next;
3892 write_register (HI_REGNUM,
3893 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3894 MIPS_SAVED_REGSIZE));
3895 write_register (LO_REGNUM,
3896 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3897 MIPS_SAVED_REGSIZE));
3898 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3899 write_register (FCRCS_REGNUM,
3900 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3901 MIPS_SAVED_REGSIZE));
3906 mips_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
3907 struct value **args, struct type *type, int gcc_p)
3909 write_register(T9_REGNUM, fun);
3912 /* Floating point register management.
3914 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3915 64bit operations, these early MIPS cpus treat fp register pairs
3916 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3917 registers and offer a compatibility mode that emulates the MIPS2 fp
3918 model. When operating in MIPS2 fp compat mode, later cpu's split
3919 double precision floats into two 32-bit chunks and store them in
3920 consecutive fp regs. To display 64-bit floats stored in this
3921 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3922 Throw in user-configurable endianness and you have a real mess.
3924 The way this works is:
3925 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3926 double-precision value will be split across two logical registers.
3927 The lower-numbered logical register will hold the low-order bits,
3928 regardless of the processor's endianness.
3929 - If we are on a 64-bit processor, and we are looking for a
3930 single-precision value, it will be in the low ordered bits
3931 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3932 save slot in memory.
3933 - If we are in 64-bit mode, everything is straightforward.
3935 Note that this code only deals with "live" registers at the top of the
3936 stack. We will attempt to deal with saved registers later, when
3937 the raw/cooked register interface is in place. (We need a general
3938 interface that can deal with dynamic saved register sizes -- fp
3939 regs could be 32 bits wide in one frame and 64 on the frame above
3942 static struct type *
3943 mips_float_register_type (void)
3945 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3946 return builtin_type_ieee_single_big;
3948 return builtin_type_ieee_single_little;
3951 static struct type *
3952 mips_double_register_type (void)
3954 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3955 return builtin_type_ieee_double_big;
3957 return builtin_type_ieee_double_little;
3960 /* Copy a 32-bit single-precision value from the current frame
3961 into rare_buffer. */
3964 mips_read_fp_register_single (int regno, char *rare_buffer)
3966 int raw_size = REGISTER_RAW_SIZE (regno);
3967 char *raw_buffer = alloca (raw_size);
3969 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3970 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3973 /* We have a 64-bit value for this register. Find the low-order
3977 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3982 memcpy (rare_buffer, raw_buffer + offset, 4);
3986 memcpy (rare_buffer, raw_buffer, 4);
3990 /* Copy a 64-bit double-precision value from the current frame into
3991 rare_buffer. This may include getting half of it from the next
3995 mips_read_fp_register_double (int regno, char *rare_buffer)
3997 int raw_size = REGISTER_RAW_SIZE (regno);
3999 if (raw_size == 8 && !mips2_fp_compat ())
4001 /* We have a 64-bit value for this register, and we should use
4003 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
4004 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4008 if ((regno - FP0_REGNUM) & 1)
4009 internal_error (__FILE__, __LINE__,
4010 "mips_read_fp_register_double: bad access to "
4011 "odd-numbered FP register");
4013 /* mips_read_fp_register_single will find the correct 32 bits from
4015 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4017 mips_read_fp_register_single (regno, rare_buffer + 4);
4018 mips_read_fp_register_single (regno + 1, rare_buffer);
4022 mips_read_fp_register_single (regno, rare_buffer);
4023 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
4029 mips_print_register (int regnum, int all)
4031 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4033 /* Get the data in raw format. */
4034 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4036 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4040 /* If we have a actual 32-bit floating point register (or we are in
4041 32-bit compatibility mode), and the register is even-numbered,
4042 also print it as a double (spanning two registers). */
4043 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
4044 && (REGISTER_RAW_SIZE (regnum) == 4
4045 || mips2_fp_compat ())
4046 && !((regnum - FP0_REGNUM) & 1))
4048 char *dbuffer = alloca (2 * MAX_REGISTER_RAW_SIZE);
4050 mips_read_fp_register_double (regnum, dbuffer);
4052 printf_filtered ("(d%d: ", regnum - FP0_REGNUM);
4053 val_print (mips_double_register_type (), dbuffer, 0, 0,
4054 gdb_stdout, 0, 1, 0, Val_pretty_default);
4055 printf_filtered ("); ");
4057 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4059 /* The problem with printing numeric register names (r26, etc.) is that
4060 the user can't use them on input. Probably the best solution is to
4061 fix it so that either the numeric or the funky (a2, etc.) names
4062 are accepted on input. */
4063 if (regnum < MIPS_NUMREGS)
4064 printf_filtered ("(r%d): ", regnum);
4066 printf_filtered (": ");
4068 /* If virtual format is floating, print it that way. */
4069 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4070 if (REGISTER_RAW_SIZE (regnum) == 8 && !mips2_fp_compat ())
4072 /* We have a meaningful 64-bit value in this register. Show
4073 it as a 32-bit float and a 64-bit double. */
4074 int offset = 4 * (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG);
4076 printf_filtered (" (float) ");
4077 val_print (mips_float_register_type (), raw_buffer + offset, 0, 0,
4078 gdb_stdout, 0, 1, 0, Val_pretty_default);
4079 printf_filtered (", (double) ");
4080 val_print (mips_double_register_type (), raw_buffer, 0, 0,
4081 gdb_stdout, 0, 1, 0, Val_pretty_default);
4084 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
4085 gdb_stdout, 0, 1, 0, Val_pretty_default);
4086 /* Else print as integer in hex. */
4091 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4092 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4096 print_scalar_formatted (raw_buffer + offset,
4097 REGISTER_VIRTUAL_TYPE (regnum),
4098 'x', 0, gdb_stdout);
4102 /* Replacement for generic do_registers_info.
4103 Print regs in pretty columns. */
4106 do_fp_register_row (int regnum)
4107 { /* do values for FP (float) regs */
4109 double doub, flt1, flt2; /* doubles extracted from raw hex data */
4110 int inv1, inv2, inv3;
4112 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
4114 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4116 /* 4-byte registers: we can fit two registers per row. */
4117 /* Also print every pair of 4-byte regs as an 8-byte double. */
4118 mips_read_fp_register_single (regnum, raw_buffer);
4119 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4121 mips_read_fp_register_single (regnum + 1, raw_buffer);
4122 flt2 = unpack_double (mips_float_register_type (), raw_buffer, &inv2);
4124 mips_read_fp_register_double (regnum, raw_buffer);
4125 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
4127 printf_filtered (" %-5s", REGISTER_NAME (regnum));
4129 printf_filtered (": <invalid float>");
4131 printf_filtered ("%-17.9g", flt1);
4133 printf_filtered (" %-5s", REGISTER_NAME (regnum + 1));
4135 printf_filtered (": <invalid float>");
4137 printf_filtered ("%-17.9g", flt2);
4139 printf_filtered (" dbl: ");
4141 printf_filtered ("<invalid double>");
4143 printf_filtered ("%-24.17g", doub);
4144 printf_filtered ("\n");
4146 /* may want to do hex display here (future enhancement) */
4151 /* Eight byte registers: print each one as float AND as double. */
4152 mips_read_fp_register_single (regnum, raw_buffer);
4153 flt1 = unpack_double (mips_double_register_type (), raw_buffer, &inv1);
4155 mips_read_fp_register_double (regnum, raw_buffer);
4156 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
4158 printf_filtered (" %-5s: ", REGISTER_NAME (regnum));
4160 printf_filtered ("<invalid float>");
4162 printf_filtered ("flt: %-17.9g", flt1);
4164 printf_filtered (" dbl: ");
4166 printf_filtered ("<invalid double>");
4168 printf_filtered ("%-24.17g", doub);
4170 printf_filtered ("\n");
4171 /* may want to do hex display here (future enhancement) */
4177 /* Print a row's worth of GP (int) registers, with name labels above */
4180 do_gp_register_row (int regnum)
4182 /* do values for GP (int) regs */
4183 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4184 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4186 int start_regnum = regnum;
4187 int numregs = NUM_REGS;
4190 /* For GP registers, we print a separate row of names above the vals */
4191 printf_filtered (" ");
4192 for (col = 0; col < ncols && regnum < numregs; regnum++)
4194 if (*REGISTER_NAME (regnum) == '\0')
4195 continue; /* unused register */
4196 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4197 break; /* end the row: reached FP register */
4198 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4199 REGISTER_NAME (regnum));
4202 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4203 start_regnum); /* print the R0 to R31 names */
4205 regnum = start_regnum; /* go back to start of row */
4206 /* now print the values in hex, 4 or 8 to the row */
4207 for (col = 0; col < ncols && regnum < numregs; regnum++)
4209 if (*REGISTER_NAME (regnum) == '\0')
4210 continue; /* unused register */
4211 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4212 break; /* end row: reached FP register */
4213 /* OK: get the data in raw format. */
4214 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4215 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4216 /* pad small registers */
4217 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4218 printf_filtered (" ");
4219 /* Now print the register value in hex, endian order. */
4220 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4221 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4222 byte < REGISTER_RAW_SIZE (regnum);
4224 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4226 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4229 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4230 printf_filtered (" ");
4233 if (col > 0) /* ie. if we actually printed anything... */
4234 printf_filtered ("\n");
4239 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4242 mips_do_registers_info (int regnum, int fpregs)
4244 if (regnum != -1) /* do one specified register */
4246 if (*(REGISTER_NAME (regnum)) == '\0')
4247 error ("Not a valid register for the current processor type");
4249 mips_print_register (regnum, 0);
4250 printf_filtered ("\n");
4253 /* do all (or most) registers */
4256 while (regnum < NUM_REGS)
4258 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4259 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4260 regnum = do_fp_register_row (regnum); /* FP regs */
4262 regnum += MIPS_NUMREGS; /* skip floating point regs */
4264 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4269 /* Is this a branch with a delay slot? */
4271 static int is_delayed (unsigned long);
4274 is_delayed (unsigned long insn)
4277 for (i = 0; i < NUMOPCODES; ++i)
4278 if (mips_opcodes[i].pinfo != INSN_MACRO
4279 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4281 return (i < NUMOPCODES
4282 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4283 | INSN_COND_BRANCH_DELAY
4284 | INSN_COND_BRANCH_LIKELY)));
4288 mips_step_skips_delay (CORE_ADDR pc)
4290 char buf[MIPS_INSTLEN];
4292 /* There is no branch delay slot on MIPS16. */
4293 if (pc_is_mips16 (pc))
4296 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4297 /* If error reading memory, guess that it is not a delayed branch. */
4299 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4303 /* Skip the PC past function prologue instructions (32-bit version).
4304 This is a helper function for mips_skip_prologue. */
4307 mips32_skip_prologue (CORE_ADDR pc)
4311 int seen_sp_adjust = 0;
4312 int load_immediate_bytes = 0;
4314 /* Skip the typical prologue instructions. These are the stack adjustment
4315 instruction and the instructions that save registers on the stack
4316 or in the gcc frame. */
4317 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4319 unsigned long high_word;
4321 inst = mips_fetch_instruction (pc);
4322 high_word = (inst >> 16) & 0xffff;
4324 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4325 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4327 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4328 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4330 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4331 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4332 && (inst & 0x001F0000)) /* reg != $zero */
4335 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4337 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4339 continue; /* reg != $zero */
4341 /* move $s8,$sp. With different versions of gas this will be either
4342 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4343 Accept any one of these. */
4344 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4347 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4349 else if (high_word == 0x3c1c) /* lui $gp,n */
4351 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4353 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4354 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4356 /* The following instructions load $at or $t0 with an immediate
4357 value in preparation for a stack adjustment via
4358 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4359 a local variable, so we accept them only before a stack adjustment
4360 instruction was seen. */
4361 else if (!seen_sp_adjust)
4363 if (high_word == 0x3c01 || /* lui $at,n */
4364 high_word == 0x3c08) /* lui $t0,n */
4366 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4369 else if (high_word == 0x3421 || /* ori $at,$at,n */
4370 high_word == 0x3508 || /* ori $t0,$t0,n */
4371 high_word == 0x3401 || /* ori $at,$zero,n */
4372 high_word == 0x3408) /* ori $t0,$zero,n */
4374 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4384 /* In a frameless function, we might have incorrectly
4385 skipped some load immediate instructions. Undo the skipping
4386 if the load immediate was not followed by a stack adjustment. */
4387 if (load_immediate_bytes && !seen_sp_adjust)
4388 pc -= load_immediate_bytes;
4392 /* Skip the PC past function prologue instructions (16-bit version).
4393 This is a helper function for mips_skip_prologue. */
4396 mips16_skip_prologue (CORE_ADDR pc)
4399 int extend_bytes = 0;
4400 int prev_extend_bytes;
4402 /* Table of instructions likely to be found in a function prologue. */
4405 unsigned short inst;
4406 unsigned short mask;
4413 , /* addiu $sp,offset */
4417 , /* daddiu $sp,offset */
4421 , /* sw reg,n($sp) */
4425 , /* sd reg,n($sp) */
4429 , /* sw $ra,n($sp) */
4433 , /* sd $ra,n($sp) */
4441 , /* sw $a0-$a3,n($s1) */
4445 , /* move reg,$a0-$a3 */
4449 , /* entry pseudo-op */
4453 , /* addiu $s1,$sp,n */
4456 } /* end of table marker */
4459 /* Skip the typical prologue instructions. These are the stack adjustment
4460 instruction and the instructions that save registers on the stack
4461 or in the gcc frame. */
4462 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4464 unsigned short inst;
4467 inst = mips_fetch_instruction (pc);
4469 /* Normally we ignore an extend instruction. However, if it is
4470 not followed by a valid prologue instruction, we must adjust
4471 the pc back over the extend so that it won't be considered
4472 part of the prologue. */
4473 if ((inst & 0xf800) == 0xf000) /* extend */
4475 extend_bytes = MIPS16_INSTLEN;
4478 prev_extend_bytes = extend_bytes;
4481 /* Check for other valid prologue instructions besides extend. */
4482 for (i = 0; table[i].mask != 0; i++)
4483 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4485 if (table[i].mask != 0) /* it was in table? */
4486 continue; /* ignore it */
4490 /* Return the current pc, adjusted backwards by 2 if
4491 the previous instruction was an extend. */
4492 return pc - prev_extend_bytes;
4498 /* To skip prologues, I use this predicate. Returns either PC itself
4499 if the code at PC does not look like a function prologue; otherwise
4500 returns an address that (if we're lucky) follows the prologue. If
4501 LENIENT, then we must skip everything which is involved in setting
4502 up the frame (it's OK to skip more, just so long as we don't skip
4503 anything which might clobber the registers which are being saved.
4504 We must skip more in the case where part of the prologue is in the
4505 delay slot of a non-prologue instruction). */
4508 mips_skip_prologue (CORE_ADDR pc)
4510 /* See if we can determine the end of the prologue via the symbol table.
4511 If so, then return either PC, or the PC after the prologue, whichever
4514 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4516 if (post_prologue_pc != 0)
4517 return max (pc, post_prologue_pc);
4519 /* Can't determine prologue from the symbol table, need to examine
4522 if (pc_is_mips16 (pc))
4523 return mips16_skip_prologue (pc);
4525 return mips32_skip_prologue (pc);
4528 /* Determine how a return value is stored within the MIPS register
4529 file, given the return type `valtype'. */
4531 struct return_value_word
4540 return_value_location (struct type *valtype,
4541 struct return_value_word *hi,
4542 struct return_value_word *lo)
4544 int len = TYPE_LENGTH (valtype);
4546 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4547 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4548 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4550 if (!FP_REGISTER_DOUBLE && len == 8)
4552 /* We need to break a 64bit float in two 32 bit halves and
4553 spread them across a floating-point register pair. */
4554 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4555 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4556 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4557 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4559 hi->reg_offset = lo->reg_offset;
4560 lo->reg = FP0_REGNUM + 0;
4561 hi->reg = FP0_REGNUM + 1;
4567 /* The floating point value fits in a single floating-point
4569 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4570 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4573 lo->reg = FP0_REGNUM;
4584 /* Locate a result possibly spread across two registers. */
4586 lo->reg = regnum + 0;
4587 hi->reg = regnum + 1;
4588 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4589 && len < MIPS_SAVED_REGSIZE)
4591 /* "un-left-justify" the value in the low register */
4592 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4597 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4598 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4599 && len < MIPS_SAVED_REGSIZE * 2
4600 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4601 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4603 /* "un-left-justify" the value spread across two registers. */
4604 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4605 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4607 hi->len = len - lo->len;
4611 /* Only perform a partial copy of the second register. */
4614 if (len > MIPS_SAVED_REGSIZE)
4616 lo->len = MIPS_SAVED_REGSIZE;
4617 hi->len = len - MIPS_SAVED_REGSIZE;
4625 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4626 && REGISTER_RAW_SIZE (regnum) == 8
4627 && MIPS_SAVED_REGSIZE == 4)
4629 /* Account for the fact that only the least-signficant part
4630 of the register is being used */
4631 lo->reg_offset += 4;
4632 hi->reg_offset += 4;
4635 hi->buf_offset = lo->len;
4639 /* Given a return value in `regbuf' with a type `valtype', extract and
4640 copy its value into `valbuf'. */
4643 mips_eabi_extract_return_value (struct type *valtype,
4644 char regbuf[REGISTER_BYTES],
4647 struct return_value_word lo;
4648 struct return_value_word hi;
4649 return_value_location (valtype, &hi, &lo);
4651 memcpy (valbuf + lo.buf_offset,
4652 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4656 memcpy (valbuf + hi.buf_offset,
4657 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4662 mips_o64_extract_return_value (struct type *valtype,
4663 char regbuf[REGISTER_BYTES],
4666 struct return_value_word lo;
4667 struct return_value_word hi;
4668 return_value_location (valtype, &hi, &lo);
4670 memcpy (valbuf + lo.buf_offset,
4671 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4675 memcpy (valbuf + hi.buf_offset,
4676 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4680 /* Given a return value in `valbuf' with a type `valtype', write it's
4681 value into the appropriate register. */
4684 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4686 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4687 struct return_value_word lo;
4688 struct return_value_word hi;
4689 return_value_location (valtype, &hi, &lo);
4691 memset (raw_buffer, 0, sizeof (raw_buffer));
4692 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4693 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4694 REGISTER_RAW_SIZE (lo.reg));
4698 memset (raw_buffer, 0, sizeof (raw_buffer));
4699 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4700 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4701 REGISTER_RAW_SIZE (hi.reg));
4706 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4708 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4709 struct return_value_word lo;
4710 struct return_value_word hi;
4711 return_value_location (valtype, &hi, &lo);
4713 memset (raw_buffer, 0, sizeof (raw_buffer));
4714 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4715 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4716 REGISTER_RAW_SIZE (lo.reg));
4720 memset (raw_buffer, 0, sizeof (raw_buffer));
4721 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4722 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4723 REGISTER_RAW_SIZE (hi.reg));
4727 /* O32 ABI stuff. */
4730 mips_o32_xfer_return_value (struct type *type,
4731 struct regcache *regcache,
4732 bfd_byte *in, const bfd_byte *out)
4734 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4735 if (TYPE_CODE (type) == TYPE_CODE_FLT
4736 && TYPE_LENGTH (type) == 4
4737 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4739 /* A single-precision floating-point value. It fits in the
4740 least significant part of FP0. */
4742 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4743 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4744 TARGET_BYTE_ORDER, in, out, 0);
4746 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4747 && TYPE_LENGTH (type) == 8
4748 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4750 /* A double-precision floating-point value. It fits in the
4751 least significant part of FP0/FP1 but with byte ordering
4752 based on the target (???). */
4754 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4755 switch (TARGET_BYTE_ORDER)
4757 case BFD_ENDIAN_LITTLE:
4758 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4759 TARGET_BYTE_ORDER, in, out, 0);
4760 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4761 TARGET_BYTE_ORDER, in, out, 4);
4763 case BFD_ENDIAN_BIG:
4764 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4765 TARGET_BYTE_ORDER, in, out, 0);
4766 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4767 TARGET_BYTE_ORDER, in, out, 4);
4770 internal_error (__FILE__, __LINE__, "bad switch");
4774 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4775 && TYPE_NFIELDS (type) <= 2
4776 && TYPE_NFIELDS (type) >= 1
4777 && ((TYPE_NFIELDS (type) == 1
4778 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4780 || (TYPE_NFIELDS (type) == 2
4781 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4783 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4785 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4787 /* A struct that contains one or two floats. Each value is part
4788 in the least significant part of their floating point
4790 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4793 for (field = 0, regnum = FP0_REGNUM;
4794 field < TYPE_NFIELDS (type);
4795 field++, regnum += 2)
4797 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4800 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4801 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4802 TARGET_BYTE_ORDER, in, out, offset);
4807 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4808 || TYPE_CODE (type) == TYPE_CODE_UNION)
4810 /* A structure or union. Extract the left justified value,
4811 regardless of the byte order. I.e. DO NOT USE
4815 for (offset = 0, regnum = V0_REGNUM;
4816 offset < TYPE_LENGTH (type);
4817 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4819 int xfer = REGISTER_RAW_SIZE (regnum);
4820 if (offset + xfer > TYPE_LENGTH (type))
4821 xfer = TYPE_LENGTH (type) - offset;
4823 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4824 offset, xfer, regnum);
4825 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4832 /* A scalar extract each part but least-significant-byte
4833 justified. o32 thinks registers are 4 byte, regardless of
4834 the ISA. mips_stack_argsize controls this. */
4837 for (offset = 0, regnum = V0_REGNUM;
4838 offset < TYPE_LENGTH (type);
4839 offset += mips_stack_argsize (), regnum++)
4841 int xfer = mips_stack_argsize ();
4843 if (offset + xfer > TYPE_LENGTH (type))
4844 xfer = TYPE_LENGTH (type) - offset;
4846 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4847 offset, xfer, regnum);
4848 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4855 mips_o32_extract_return_value (struct type *type,
4856 struct regcache *regcache,
4859 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4863 mips_o32_store_return_value (struct type *type, char *valbuf)
4865 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4868 /* N32/N44 ABI stuff. */
4871 mips_n32n64_xfer_return_value (struct type *type,
4872 struct regcache *regcache,
4873 bfd_byte *in, const bfd_byte *out)
4875 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4876 if (TYPE_CODE (type) == TYPE_CODE_FLT
4877 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4879 /* A floating-point value belongs in the least significant part
4882 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4883 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4884 TARGET_BYTE_ORDER, in, out, 0);
4886 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4887 && TYPE_NFIELDS (type) <= 2
4888 && TYPE_NFIELDS (type) >= 1
4889 && ((TYPE_NFIELDS (type) == 1
4890 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4892 || (TYPE_NFIELDS (type) == 2
4893 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4895 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4897 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4899 /* A struct that contains one or two floats. Each value is part
4900 in the least significant part of their floating point
4902 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4905 for (field = 0, regnum = FP0_REGNUM;
4906 field < TYPE_NFIELDS (type);
4907 field++, regnum += 2)
4909 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4912 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4913 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4914 TARGET_BYTE_ORDER, in, out, offset);
4917 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4918 || TYPE_CODE (type) == TYPE_CODE_UNION)
4920 /* A structure or union. Extract the left justified value,
4921 regardless of the byte order. I.e. DO NOT USE
4925 for (offset = 0, regnum = V0_REGNUM;
4926 offset < TYPE_LENGTH (type);
4927 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4929 int xfer = REGISTER_RAW_SIZE (regnum);
4930 if (offset + xfer > TYPE_LENGTH (type))
4931 xfer = TYPE_LENGTH (type) - offset;
4933 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4934 offset, xfer, regnum);
4935 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4941 /* A scalar extract each part but least-significant-byte
4945 for (offset = 0, regnum = V0_REGNUM;
4946 offset < TYPE_LENGTH (type);
4947 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4949 int xfer = REGISTER_RAW_SIZE (regnum);
4951 if (offset + xfer > TYPE_LENGTH (type))
4952 xfer = TYPE_LENGTH (type) - offset;
4954 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4955 offset, xfer, regnum);
4956 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4963 mips_n32n64_extract_return_value (struct type *type,
4964 struct regcache *regcache,
4967 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4971 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4973 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4977 mips_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
4979 /* Nothing to do -- push_arguments does all the work. */
4983 mips_extract_struct_value_address (struct regcache *regcache)
4985 /* FIXME: This will only work at random. The caller passes the
4986 struct_return address in V0, but it is not preserved. It may
4987 still be there, or this may be a random value. */
4990 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4994 /* Exported procedure: Is PC in the signal trampoline code */
4997 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4999 if (sigtramp_address == 0)
5001 return (pc >= sigtramp_address && pc < sigtramp_end);
5004 /* Root of all "set mips "/"show mips " commands. This will eventually be
5005 used for all MIPS-specific commands. */
5008 show_mips_command (char *args, int from_tty)
5010 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5014 set_mips_command (char *args, int from_tty)
5016 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
5017 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5020 /* Commands to show/set the MIPS FPU type. */
5023 show_mipsfpu_command (char *args, int from_tty)
5026 switch (MIPS_FPU_TYPE)
5028 case MIPS_FPU_SINGLE:
5029 fpu = "single-precision";
5031 case MIPS_FPU_DOUBLE:
5032 fpu = "double-precision";
5035 fpu = "absent (none)";
5038 internal_error (__FILE__, __LINE__, "bad switch");
5040 if (mips_fpu_type_auto)
5041 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5044 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5050 set_mipsfpu_command (char *args, int from_tty)
5052 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5053 show_mipsfpu_command (args, from_tty);
5057 set_mipsfpu_single_command (char *args, int from_tty)
5059 mips_fpu_type = MIPS_FPU_SINGLE;
5060 mips_fpu_type_auto = 0;
5061 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5065 set_mipsfpu_double_command (char *args, int from_tty)
5067 mips_fpu_type = MIPS_FPU_DOUBLE;
5068 mips_fpu_type_auto = 0;
5069 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5073 set_mipsfpu_none_command (char *args, int from_tty)
5075 mips_fpu_type = MIPS_FPU_NONE;
5076 mips_fpu_type_auto = 0;
5077 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5081 set_mipsfpu_auto_command (char *args, int from_tty)
5083 mips_fpu_type_auto = 1;
5086 /* Command to set the processor type. */
5089 mips_set_processor_type_command (char *args, int from_tty)
5093 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5095 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5096 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5097 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5099 /* Restore the value. */
5100 tmp_mips_processor_type = xstrdup (mips_processor_type);
5105 if (!mips_set_processor_type (tmp_mips_processor_type))
5107 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5108 /* Restore its value. */
5109 tmp_mips_processor_type = xstrdup (mips_processor_type);
5114 mips_show_processor_type_command (char *args, int from_tty)
5118 /* Modify the actual processor type. */
5121 mips_set_processor_type (char *str)
5128 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5130 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5132 mips_processor_type = str;
5133 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5135 /* FIXME tweak fpu flag too */
5142 /* Attempt to identify the particular processor model by reading the
5146 mips_read_processor_type (void)
5150 prid = read_register (PRID_REGNUM);
5152 if ((prid & ~0xf) == 0x700)
5153 return savestring ("r3041", strlen ("r3041"));
5158 /* Just like reinit_frame_cache, but with the right arguments to be
5159 callable as an sfunc. */
5162 reinit_frame_cache_sfunc (char *args, int from_tty,
5163 struct cmd_list_element *c)
5165 reinit_frame_cache ();
5169 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5171 mips_extra_func_info_t proc_desc;
5173 /* Search for the function containing this address. Set the low bit
5174 of the address when searching, in case we were given an even address
5175 that is the start of a 16-bit function. If we didn't do this,
5176 the search would fail because the symbol table says the function
5177 starts at an odd address, i.e. 1 byte past the given address. */
5178 memaddr = ADDR_BITS_REMOVE (memaddr);
5179 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5181 /* Make an attempt to determine if this is a 16-bit function. If
5182 the procedure descriptor exists and the address therein is odd,
5183 it's definitely a 16-bit function. Otherwise, we have to just
5184 guess that if the address passed in is odd, it's 16-bits. */
5186 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5187 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5189 info->mach = pc_is_mips16 (memaddr) ?
5190 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5192 /* Round down the instruction address to the appropriate boundary. */
5193 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5195 /* Call the appropriate disassembler based on the target endian-ness. */
5196 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5197 return print_insn_big_mips (memaddr, info);
5199 return print_insn_little_mips (memaddr, info);
5202 /* Old-style breakpoint macros.
5203 The IDT board uses an unusual breakpoint value, and sometimes gets
5204 confused when it sees the usual MIPS breakpoint instruction. */
5206 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
5207 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
5208 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
5209 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
5210 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
5211 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
5212 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
5213 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
5215 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5216 counter value to determine whether a 16- or 32-bit breakpoint should be
5217 used. It returns a pointer to a string of bytes that encode a breakpoint
5218 instruction, stores the length of the string to *lenptr, and adjusts pc
5219 (if necessary) to point to the actual memory location where the
5220 breakpoint should be inserted. */
5222 static const unsigned char *
5223 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5225 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5227 if (pc_is_mips16 (*pcptr))
5229 static unsigned char mips16_big_breakpoint[] =
5230 MIPS16_BIG_BREAKPOINT;
5231 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5232 *lenptr = sizeof (mips16_big_breakpoint);
5233 return mips16_big_breakpoint;
5237 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
5238 static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
5239 static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
5241 *lenptr = sizeof (big_breakpoint);
5243 if (strcmp (target_shortname, "mips") == 0)
5244 return idt_big_breakpoint;
5245 else if (strcmp (target_shortname, "ddb") == 0
5246 || strcmp (target_shortname, "pmon") == 0
5247 || strcmp (target_shortname, "lsi") == 0)
5248 return pmon_big_breakpoint;
5250 return big_breakpoint;
5255 if (pc_is_mips16 (*pcptr))
5257 static unsigned char mips16_little_breakpoint[] =
5258 MIPS16_LITTLE_BREAKPOINT;
5259 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5260 *lenptr = sizeof (mips16_little_breakpoint);
5261 return mips16_little_breakpoint;
5265 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
5266 static unsigned char pmon_little_breakpoint[] =
5267 PMON_LITTLE_BREAKPOINT;
5268 static unsigned char idt_little_breakpoint[] =
5269 IDT_LITTLE_BREAKPOINT;
5271 *lenptr = sizeof (little_breakpoint);
5273 if (strcmp (target_shortname, "mips") == 0)
5274 return idt_little_breakpoint;
5275 else if (strcmp (target_shortname, "ddb") == 0
5276 || strcmp (target_shortname, "pmon") == 0
5277 || strcmp (target_shortname, "lsi") == 0)
5278 return pmon_little_breakpoint;
5280 return little_breakpoint;
5285 /* If PC is in a mips16 call or return stub, return the address of the target
5286 PC, which is either the callee or the caller. There are several
5287 cases which must be handled:
5289 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5290 target PC is in $31 ($ra).
5291 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5292 and the target PC is in $2.
5293 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5294 before the jal instruction, this is effectively a call stub
5295 and the the target PC is in $2. Otherwise this is effectively
5296 a return stub and the target PC is in $18.
5298 See the source code for the stubs in gcc/config/mips/mips16.S for
5301 This function implements the SKIP_TRAMPOLINE_CODE macro.
5305 mips_skip_stub (CORE_ADDR pc)
5308 CORE_ADDR start_addr;
5310 /* Find the starting address and name of the function containing the PC. */
5311 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5314 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5315 target PC is in $31 ($ra). */
5316 if (strcmp (name, "__mips16_ret_sf") == 0
5317 || strcmp (name, "__mips16_ret_df") == 0)
5318 return read_signed_register (RA_REGNUM);
5320 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5322 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5323 and the target PC is in $2. */
5324 if (name[19] >= '0' && name[19] <= '9')
5325 return read_signed_register (2);
5327 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5328 before the jal instruction, this is effectively a call stub
5329 and the the target PC is in $2. Otherwise this is effectively
5330 a return stub and the target PC is in $18. */
5331 else if (name[19] == 's' || name[19] == 'd')
5333 if (pc == start_addr)
5335 /* Check if the target of the stub is a compiler-generated
5336 stub. Such a stub for a function bar might have a name
5337 like __fn_stub_bar, and might look like this:
5342 la $1,bar (becomes a lui/addiu pair)
5344 So scan down to the lui/addi and extract the target
5345 address from those two instructions. */
5347 CORE_ADDR target_pc = read_signed_register (2);
5351 /* See if the name of the target function is __fn_stub_*. */
5352 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5354 if (strncmp (name, "__fn_stub_", 10) != 0
5355 && strcmp (name, "etext") != 0
5356 && strcmp (name, "_etext") != 0)
5359 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5360 The limit on the search is arbitrarily set to 20
5361 instructions. FIXME. */
5362 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5364 inst = mips_fetch_instruction (target_pc);
5365 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5366 pc = (inst << 16) & 0xffff0000; /* high word */
5367 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5368 return pc | (inst & 0xffff); /* low word */
5371 /* Couldn't find the lui/addui pair, so return stub address. */
5375 /* This is the 'return' part of a call stub. The return
5376 address is in $r18. */
5377 return read_signed_register (18);
5380 return 0; /* not a stub */
5384 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5385 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5388 mips_in_call_stub (CORE_ADDR pc, char *name)
5390 CORE_ADDR start_addr;
5392 /* Find the starting address of the function containing the PC. If the
5393 caller didn't give us a name, look it up at the same time. */
5394 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5397 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5399 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5400 if (name[19] >= '0' && name[19] <= '9')
5402 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5403 before the jal instruction, this is effectively a call stub. */
5404 else if (name[19] == 's' || name[19] == 'd')
5405 return pc == start_addr;
5408 return 0; /* not a stub */
5412 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5413 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5416 mips_in_return_stub (CORE_ADDR pc, char *name)
5418 CORE_ADDR start_addr;
5420 /* Find the starting address of the function containing the PC. */
5421 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5424 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5425 if (strcmp (name, "__mips16_ret_sf") == 0
5426 || strcmp (name, "__mips16_ret_df") == 0)
5429 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5430 i.e. after the jal instruction, this is effectively a return stub. */
5431 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5432 && (name[19] == 's' || name[19] == 'd')
5433 && pc != start_addr)
5436 return 0; /* not a stub */
5440 /* Return non-zero if the PC is in a library helper function that should
5441 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5444 mips_ignore_helper (CORE_ADDR pc)
5448 /* Find the starting address and name of the function containing the PC. */
5449 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5452 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5453 that we want to ignore. */
5454 return (strcmp (name, "__mips16_ret_sf") == 0
5455 || strcmp (name, "__mips16_ret_df") == 0);
5459 /* Return a location where we can set a breakpoint that will be hit
5460 when an inferior function call returns. This is normally the
5461 program's entry point. Executables that don't have an entry
5462 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5463 whose address is the location where the breakpoint should be placed. */
5466 mips_call_dummy_address (void)
5468 struct minimal_symbol *sym;
5470 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5472 return SYMBOL_VALUE_ADDRESS (sym);
5474 return entry_point_address ();
5478 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5479 the register stored on the stack (32) is different to its real raw
5480 size (64). The below ensures that registers are fetched from the
5481 stack using their ABI size and then stored into the RAW_BUFFER
5482 using their raw size.
5484 The alternative to adding this function would be to add an ABI
5485 macro - REGISTER_STACK_SIZE(). */
5488 mips_get_saved_register (char *raw_buffer,
5491 struct frame_info *frame,
5493 enum lval_type *lvalp)
5496 enum lval_type lvalx;
5499 if (!target_has_registers)
5500 error ("No registers.");
5502 /* Make certain that all needed parameters are present. */
5507 if (optimizedp == NULL)
5508 optimizedp = &optimizedx;
5509 generic_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5511 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5512 have a pseudo register range that correspons to the ABI's, rather
5513 than the ISA's, view of registers. These registers would then
5514 implicitly describe their size and hence could be used without
5515 the below munging. */
5516 if ((*lvalp) == lval_memory)
5518 if (raw_buffer != NULL)
5522 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5524 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5525 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5531 /* Immediately after a function call, return the saved pc.
5532 Can't always go through the frames for this because on some machines
5533 the new frame is not set up until the new function executes
5534 some instructions. */
5537 mips_saved_pc_after_call (struct frame_info *frame)
5539 return read_signed_register (RA_REGNUM);
5543 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5547 mips_stab_reg_to_regnum (int num)
5552 return num + FP0_REGNUM - 38;
5555 /* Convert a ecoff register number to a gdb REGNUM */
5558 mips_ecoff_reg_to_regnum (int num)
5563 return num + FP0_REGNUM - 32;
5566 /* Convert an integer into an address. By first converting the value
5567 into a pointer and then extracting it signed, the address is
5568 guarenteed to be correctly sign extended. */
5571 mips_integer_to_address (struct type *type, void *buf)
5573 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5574 LONGEST val = unpack_long (type, buf);
5575 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5576 return extract_signed_integer (tmp,
5577 TYPE_LENGTH (builtin_type_void_data_ptr));
5581 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5583 enum mips_abi *abip = (enum mips_abi *) obj;
5584 const char *name = bfd_get_section_name (abfd, sect);
5586 if (*abip != MIPS_ABI_UNKNOWN)
5589 if (strncmp (name, ".mdebug.", 8) != 0)
5592 if (strcmp (name, ".mdebug.abi32") == 0)
5593 *abip = MIPS_ABI_O32;
5594 else if (strcmp (name, ".mdebug.abiN32") == 0)
5595 *abip = MIPS_ABI_N32;
5596 else if (strcmp (name, ".mdebug.abi64") == 0)
5597 *abip = MIPS_ABI_N64;
5598 else if (strcmp (name, ".mdebug.abiO64") == 0)
5599 *abip = MIPS_ABI_O64;
5600 else if (strcmp (name, ".mdebug.eabi32") == 0)
5601 *abip = MIPS_ABI_EABI32;
5602 else if (strcmp (name, ".mdebug.eabi64") == 0)
5603 *abip = MIPS_ABI_EABI64;
5605 warning ("unsupported ABI %s.", name + 8);
5608 static enum mips_abi
5609 global_mips_abi (void)
5613 for (i = 0; mips_abi_strings[i] != NULL; i++)
5614 if (mips_abi_strings[i] == mips_abi_string)
5615 return (enum mips_abi) i;
5617 internal_error (__FILE__, __LINE__,
5618 "unknown ABI string");
5621 static struct gdbarch *
5622 mips_gdbarch_init (struct gdbarch_info info,
5623 struct gdbarch_list *arches)
5625 static LONGEST mips_call_dummy_words[] =
5627 struct gdbarch *gdbarch;
5628 struct gdbarch_tdep *tdep;
5630 enum mips_abi mips_abi, found_abi, wanted_abi;
5632 /* Reset the disassembly info, in case it was set to something
5634 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5635 tm_print_insn_info.arch = bfd_arch_unknown;
5636 tm_print_insn_info.mach = 0;
5642 /* First of all, extract the elf_flags, if available. */
5643 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5644 elf_flags = elf_elfheader (info.abfd)->e_flags;
5647 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5648 switch ((elf_flags & EF_MIPS_ABI))
5650 case E_MIPS_ABI_O32:
5651 mips_abi = MIPS_ABI_O32;
5653 case E_MIPS_ABI_O64:
5654 mips_abi = MIPS_ABI_O64;
5656 case E_MIPS_ABI_EABI32:
5657 mips_abi = MIPS_ABI_EABI32;
5659 case E_MIPS_ABI_EABI64:
5660 mips_abi = MIPS_ABI_EABI64;
5663 if ((elf_flags & EF_MIPS_ABI2))
5664 mips_abi = MIPS_ABI_N32;
5666 mips_abi = MIPS_ABI_UNKNOWN;
5670 /* GCC creates a pseudo-section whose name describes the ABI. */
5671 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5672 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5674 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5675 Use the ABI from the last architecture if there is one. */
5676 if (info.abfd == NULL && arches != NULL)
5677 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5679 /* Try the architecture for any hint of the correct ABI. */
5680 if (mips_abi == MIPS_ABI_UNKNOWN
5681 && info.bfd_arch_info != NULL
5682 && info.bfd_arch_info->arch == bfd_arch_mips)
5684 switch (info.bfd_arch_info->mach)
5686 case bfd_mach_mips3900:
5687 mips_abi = MIPS_ABI_EABI32;
5689 case bfd_mach_mips4100:
5690 case bfd_mach_mips5000:
5691 mips_abi = MIPS_ABI_EABI64;
5693 case bfd_mach_mips8000:
5694 case bfd_mach_mips10000:
5695 /* On Irix, ELF64 executables use the N64 ABI. The
5696 pseudo-sections which describe the ABI aren't present
5697 on IRIX. (Even for executables created by gcc.) */
5698 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5699 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5700 mips_abi = MIPS_ABI_N64;
5702 mips_abi = MIPS_ABI_N32;
5707 if (mips_abi == MIPS_ABI_UNKNOWN)
5708 mips_abi = MIPS_ABI_O32;
5710 /* Now that we have found what the ABI for this binary would be,
5711 check whether the user is overriding it. */
5712 found_abi = mips_abi;
5713 wanted_abi = global_mips_abi ();
5714 if (wanted_abi != MIPS_ABI_UNKNOWN)
5715 mips_abi = wanted_abi;
5719 fprintf_unfiltered (gdb_stdlog,
5720 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5722 fprintf_unfiltered (gdb_stdlog,
5723 "mips_gdbarch_init: mips_abi = %d\n",
5725 fprintf_unfiltered (gdb_stdlog,
5726 "mips_gdbarch_init: found_mips_abi = %d\n",
5730 /* try to find a pre-existing architecture */
5731 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5733 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5735 /* MIPS needs to be pedantic about which ABI the object is
5737 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5739 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5741 return arches->gdbarch;
5744 /* Need a new architecture. Fill in a target specific vector. */
5745 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5746 gdbarch = gdbarch_alloc (&info, tdep);
5747 tdep->elf_flags = elf_flags;
5749 /* Initially set everything according to the default ABI/ISA. */
5750 set_gdbarch_short_bit (gdbarch, 16);
5751 set_gdbarch_int_bit (gdbarch, 32);
5752 set_gdbarch_float_bit (gdbarch, 32);
5753 set_gdbarch_double_bit (gdbarch, 64);
5754 set_gdbarch_long_double_bit (gdbarch, 64);
5755 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5756 set_gdbarch_max_register_raw_size (gdbarch, 8);
5757 set_gdbarch_max_register_virtual_size (gdbarch, 8);
5758 tdep->found_abi = found_abi;
5759 tdep->mips_abi = mips_abi;
5761 set_gdbarch_elf_make_msymbol_special (gdbarch,
5762 mips_elf_make_msymbol_special);
5764 if (info.osabi == GDB_OSABI_IRIX)
5765 set_gdbarch_num_regs (gdbarch, 71);
5767 set_gdbarch_num_regs (gdbarch, 90);
5772 set_gdbarch_push_arguments (gdbarch, mips_o32_push_arguments);
5773 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5774 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5775 tdep->mips_default_saved_regsize = 4;
5776 tdep->mips_default_stack_argsize = 4;
5777 tdep->mips_fp_register_double = 0;
5778 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5779 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5780 tdep->gdb_target_is_mips64 = 0;
5781 tdep->default_mask_address_p = 0;
5782 set_gdbarch_long_bit (gdbarch, 32);
5783 set_gdbarch_ptr_bit (gdbarch, 32);
5784 set_gdbarch_long_long_bit (gdbarch, 64);
5785 set_gdbarch_reg_struct_has_addr (gdbarch,
5786 mips_o32_reg_struct_has_addr);
5787 set_gdbarch_use_struct_convention (gdbarch,
5788 mips_o32_use_struct_convention);
5791 set_gdbarch_push_arguments (gdbarch, mips_o64_push_arguments);
5792 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5793 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5794 tdep->mips_default_saved_regsize = 8;
5795 tdep->mips_default_stack_argsize = 8;
5796 tdep->mips_fp_register_double = 1;
5797 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5798 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5799 tdep->gdb_target_is_mips64 = 1;
5800 tdep->default_mask_address_p = 0;
5801 set_gdbarch_long_bit (gdbarch, 32);
5802 set_gdbarch_ptr_bit (gdbarch, 32);
5803 set_gdbarch_long_long_bit (gdbarch, 64);
5804 set_gdbarch_reg_struct_has_addr (gdbarch,
5805 mips_o32_reg_struct_has_addr);
5806 set_gdbarch_use_struct_convention (gdbarch,
5807 mips_o32_use_struct_convention);
5809 case MIPS_ABI_EABI32:
5810 set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
5811 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5812 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5813 tdep->mips_default_saved_regsize = 4;
5814 tdep->mips_default_stack_argsize = 4;
5815 tdep->mips_fp_register_double = 0;
5816 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5817 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5818 tdep->gdb_target_is_mips64 = 0;
5819 tdep->default_mask_address_p = 0;
5820 set_gdbarch_long_bit (gdbarch, 32);
5821 set_gdbarch_ptr_bit (gdbarch, 32);
5822 set_gdbarch_long_long_bit (gdbarch, 64);
5823 set_gdbarch_reg_struct_has_addr (gdbarch,
5824 mips_eabi_reg_struct_has_addr);
5825 set_gdbarch_use_struct_convention (gdbarch,
5826 mips_eabi_use_struct_convention);
5828 case MIPS_ABI_EABI64:
5829 set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
5830 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5831 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5832 tdep->mips_default_saved_regsize = 8;
5833 tdep->mips_default_stack_argsize = 8;
5834 tdep->mips_fp_register_double = 1;
5835 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5836 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5837 tdep->gdb_target_is_mips64 = 1;
5838 tdep->default_mask_address_p = 0;
5839 set_gdbarch_long_bit (gdbarch, 64);
5840 set_gdbarch_ptr_bit (gdbarch, 64);
5841 set_gdbarch_long_long_bit (gdbarch, 64);
5842 set_gdbarch_reg_struct_has_addr (gdbarch,
5843 mips_eabi_reg_struct_has_addr);
5844 set_gdbarch_use_struct_convention (gdbarch,
5845 mips_eabi_use_struct_convention);
5848 set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
5849 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5850 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5851 tdep->mips_default_saved_regsize = 8;
5852 tdep->mips_default_stack_argsize = 8;
5853 tdep->mips_fp_register_double = 1;
5854 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5855 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5856 tdep->gdb_target_is_mips64 = 1;
5857 tdep->default_mask_address_p = 0;
5858 set_gdbarch_long_bit (gdbarch, 32);
5859 set_gdbarch_ptr_bit (gdbarch, 32);
5860 set_gdbarch_long_long_bit (gdbarch, 64);
5862 /* Set up the disassembler info, so that we get the right
5863 register names from libopcodes. */
5864 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5865 tm_print_insn_info.arch = bfd_arch_mips;
5866 if (info.bfd_arch_info != NULL
5867 && info.bfd_arch_info->arch == bfd_arch_mips
5868 && info.bfd_arch_info->mach)
5869 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5871 tm_print_insn_info.mach = bfd_mach_mips8000;
5873 set_gdbarch_use_struct_convention (gdbarch,
5874 mips_n32n64_use_struct_convention);
5875 set_gdbarch_reg_struct_has_addr (gdbarch,
5876 mips_n32n64_reg_struct_has_addr);
5879 set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
5880 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5881 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5882 tdep->mips_default_saved_regsize = 8;
5883 tdep->mips_default_stack_argsize = 8;
5884 tdep->mips_fp_register_double = 1;
5885 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5886 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5887 tdep->gdb_target_is_mips64 = 1;
5888 tdep->default_mask_address_p = 0;
5889 set_gdbarch_long_bit (gdbarch, 64);
5890 set_gdbarch_ptr_bit (gdbarch, 64);
5891 set_gdbarch_long_long_bit (gdbarch, 64);
5893 /* Set up the disassembler info, so that we get the right
5894 register names from libopcodes. */
5895 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5896 tm_print_insn_info.arch = bfd_arch_mips;
5897 if (info.bfd_arch_info != NULL
5898 && info.bfd_arch_info->arch == bfd_arch_mips
5899 && info.bfd_arch_info->mach)
5900 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5902 tm_print_insn_info.mach = bfd_mach_mips8000;
5904 set_gdbarch_use_struct_convention (gdbarch,
5905 mips_n32n64_use_struct_convention);
5906 set_gdbarch_reg_struct_has_addr (gdbarch,
5907 mips_n32n64_reg_struct_has_addr);
5910 internal_error (__FILE__, __LINE__,
5911 "unknown ABI in switch");
5914 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5915 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5918 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5919 flag in object files because to do so would make it impossible to
5920 link with libraries compiled without "-gp32". This is
5921 unnecessarily restrictive.
5923 We could solve this problem by adding "-gp32" multilibs to gcc,
5924 but to set this flag before gcc is built with such multilibs will
5925 break too many systems.''
5927 But even more unhelpfully, the default linker output target for
5928 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5929 for 64-bit programs - you need to change the ABI to change this,
5930 and not all gcc targets support that currently. Therefore using
5931 this flag to detect 32-bit mode would do the wrong thing given
5932 the current gcc - it would make GDB treat these 64-bit programs
5933 as 32-bit programs by default. */
5935 /* enable/disable the MIPS FPU */
5936 if (!mips_fpu_type_auto)
5937 tdep->mips_fpu_type = mips_fpu_type;
5938 else if (info.bfd_arch_info != NULL
5939 && info.bfd_arch_info->arch == bfd_arch_mips)
5940 switch (info.bfd_arch_info->mach)
5942 case bfd_mach_mips3900:
5943 case bfd_mach_mips4100:
5944 case bfd_mach_mips4111:
5945 tdep->mips_fpu_type = MIPS_FPU_NONE;
5947 case bfd_mach_mips4650:
5948 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5951 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5955 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5957 /* MIPS version of register names. NOTE: At present the MIPS
5958 register name management is part way between the old -
5959 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5960 Further work on it is required. */
5961 /* NOTE: many targets (esp. embedded) do not go thru the
5962 gdbarch_register_name vector at all, instead bypassing it
5963 by defining REGISTER_NAMES. */
5964 set_gdbarch_register_name (gdbarch, mips_register_name);
5965 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5966 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5967 set_gdbarch_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5968 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5969 set_gdbarch_write_sp (gdbarch, generic_target_write_sp);
5971 /* Add/remove bits from an address. The MIPS needs be careful to
5972 ensure that all 32 bit addresses are sign extended to 64 bits. */
5973 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5975 /* There's a mess in stack frame creation. See comments in
5976 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5977 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5978 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5980 /* Map debug register numbers onto internal register numbers. */
5981 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5982 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_ecoff_reg_to_regnum);
5984 /* Initialize a frame */
5985 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5986 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5988 /* MIPS version of CALL_DUMMY */
5990 set_gdbarch_call_dummy_p (gdbarch, 1);
5991 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
5992 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5993 set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
5994 set_gdbarch_pop_frame (gdbarch, mips_pop_frame);
5995 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
5996 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
5997 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
5998 set_gdbarch_call_dummy_length (gdbarch, 0);
5999 set_gdbarch_fix_call_dummy (gdbarch, mips_fix_call_dummy);
6000 set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words);
6001 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
6002 set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
6003 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6004 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
6005 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
6006 set_gdbarch_register_convert_to_virtual (gdbarch,
6007 mips_register_convert_to_virtual);
6008 set_gdbarch_register_convert_to_raw (gdbarch,
6009 mips_register_convert_to_raw);
6011 set_gdbarch_frame_chain (gdbarch, mips_frame_chain);
6012 set_gdbarch_frameless_function_invocation (gdbarch,
6013 generic_frameless_function_invocation_not);
6014 set_gdbarch_frame_saved_pc (gdbarch, mips_frame_saved_pc);
6015 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
6016 set_gdbarch_frame_args_skip (gdbarch, 0);
6018 set_gdbarch_get_saved_register (gdbarch, mips_get_saved_register);
6020 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6021 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6022 set_gdbarch_decr_pc_after_break (gdbarch, 0);
6024 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6025 set_gdbarch_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
6027 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6028 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6029 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6031 set_gdbarch_function_start_offset (gdbarch, 0);
6033 /* There are MIPS targets which do not yet use this since they still
6034 define REGISTER_VIRTUAL_TYPE. */
6035 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
6036 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
6038 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
6039 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
6041 /* Hook in OS ABI-specific overrides, if they have been registered. */
6042 gdbarch_init_osabi (info, gdbarch);
6044 set_gdbarch_store_struct_return (gdbarch, mips_store_struct_return);
6045 set_gdbarch_extract_struct_value_address (gdbarch,
6046 mips_extract_struct_value_address);
6048 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6050 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6051 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6057 mips_abi_update (char *ignore_args, int from_tty,
6058 struct cmd_list_element *c)
6060 struct gdbarch_info info;
6062 /* Force the architecture to update, and (if it's a MIPS architecture)
6063 mips_gdbarch_init will take care of the rest. */
6064 gdbarch_info_init (&info);
6065 gdbarch_update_p (info);
6068 /* Print out which MIPS ABI is in use. */
6071 show_mips_abi (char *ignore_args, int from_tty)
6073 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6075 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6078 enum mips_abi global_abi = global_mips_abi ();
6079 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6080 const char *actual_abi_str = mips_abi_strings[actual_abi];
6082 if (global_abi == MIPS_ABI_UNKNOWN)
6083 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6085 else if (global_abi == actual_abi)
6087 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6091 /* Probably shouldn't happen... */
6093 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6095 mips_abi_strings[global_abi]);
6101 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6103 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6107 int ef_mips_32bitmode;
6108 /* determine the ISA */
6109 switch (tdep->elf_flags & EF_MIPS_ARCH)
6127 /* determine the size of a pointer */
6128 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6129 fprintf_unfiltered (file,
6130 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6132 fprintf_unfiltered (file,
6133 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6135 fprintf_unfiltered (file,
6136 "mips_dump_tdep: ef_mips_arch = %d\n",
6138 fprintf_unfiltered (file,
6139 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6141 mips_abi_strings[tdep->mips_abi]);
6142 fprintf_unfiltered (file,
6143 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6144 mips_mask_address_p (),
6145 tdep->default_mask_address_p);
6147 fprintf_unfiltered (file,
6148 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6149 FP_REGISTER_DOUBLE);
6150 fprintf_unfiltered (file,
6151 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6152 MIPS_DEFAULT_FPU_TYPE,
6153 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6154 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6155 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6157 fprintf_unfiltered (file,
6158 "mips_dump_tdep: MIPS_EABI = %d\n",
6160 fprintf_unfiltered (file,
6161 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6162 MIPS_LAST_FP_ARG_REGNUM,
6163 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6164 fprintf_unfiltered (file,
6165 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6167 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6168 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6169 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6171 fprintf_unfiltered (file,
6172 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6173 MIPS_DEFAULT_SAVED_REGSIZE);
6174 fprintf_unfiltered (file,
6175 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6176 FP_REGISTER_DOUBLE);
6177 fprintf_unfiltered (file,
6178 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6179 MIPS_DEFAULT_STACK_ARGSIZE);
6180 fprintf_unfiltered (file,
6181 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6182 MIPS_STACK_ARGSIZE);
6183 fprintf_unfiltered (file,
6184 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6186 fprintf_unfiltered (file,
6187 "mips_dump_tdep: A0_REGNUM = %d\n",
6189 fprintf_unfiltered (file,
6190 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6191 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6192 fprintf_unfiltered (file,
6193 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6194 XSTRING (ATTACH_DETACH));
6195 fprintf_unfiltered (file,
6196 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6198 fprintf_unfiltered (file,
6199 "mips_dump_tdep: BIG_BREAKPOINT = delete?\n");
6200 fprintf_unfiltered (file,
6201 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6203 fprintf_unfiltered (file,
6204 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6205 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6206 fprintf_unfiltered (file,
6207 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6208 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6209 fprintf_unfiltered (file,
6210 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6212 fprintf_unfiltered (file,
6213 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6215 fprintf_unfiltered (file,
6216 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6217 FIRST_EMBED_REGNUM);
6218 fprintf_unfiltered (file,
6219 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6221 fprintf_unfiltered (file,
6222 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6223 GDB_TARGET_IS_MIPS64);
6224 fprintf_unfiltered (file,
6225 "mips_dump_tdep: GEN_REG_SAVE_MASK = %d\n",
6227 fprintf_unfiltered (file,
6228 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6229 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6230 fprintf_unfiltered (file,
6231 "mips_dump_tdep: HI_REGNUM = %d\n",
6233 fprintf_unfiltered (file,
6234 "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n");
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n");
6237 fprintf_unfiltered (file,
6238 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6239 XSTRING (IGNORE_HELPER_CALL (PC)));
6240 fprintf_unfiltered (file,
6241 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6242 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6243 fprintf_unfiltered (file,
6244 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6245 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6246 fprintf_unfiltered (file,
6247 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6248 fprintf_unfiltered (file,
6249 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6251 fprintf_unfiltered (file,
6252 "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n");
6253 fprintf_unfiltered (file,
6254 "mips_dump_tdep: LO_REGNUM = %d\n",
6256 #ifdef MACHINE_CPROC_FP_OFFSET
6257 fprintf_unfiltered (file,
6258 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6259 MACHINE_CPROC_FP_OFFSET);
6261 #ifdef MACHINE_CPROC_PC_OFFSET
6262 fprintf_unfiltered (file,
6263 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6264 MACHINE_CPROC_PC_OFFSET);
6266 #ifdef MACHINE_CPROC_SP_OFFSET
6267 fprintf_unfiltered (file,
6268 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6269 MACHINE_CPROC_SP_OFFSET);
6271 fprintf_unfiltered (file,
6272 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6273 fprintf_unfiltered (file,
6274 "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n");
6275 fprintf_unfiltered (file,
6276 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6278 fprintf_unfiltered (file,
6279 "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n");
6280 fprintf_unfiltered (file,
6281 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6282 fprintf_unfiltered (file,
6283 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6284 fprintf_unfiltered (file,
6285 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6287 fprintf_unfiltered (file,
6288 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6289 MIPS_LAST_ARG_REGNUM,
6290 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6291 fprintf_unfiltered (file,
6292 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6294 fprintf_unfiltered (file,
6295 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6296 fprintf_unfiltered (file,
6297 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6298 MIPS_SAVED_REGSIZE);
6299 fprintf_unfiltered (file,
6300 "mips_dump_tdep: OP_LDFPR = used?\n");
6301 fprintf_unfiltered (file,
6302 "mips_dump_tdep: OP_LDGPR = used?\n");
6303 fprintf_unfiltered (file,
6304 "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n");
6305 fprintf_unfiltered (file,
6306 "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n");
6307 fprintf_unfiltered (file,
6308 "mips_dump_tdep: PRID_REGNUM = %d\n",
6310 fprintf_unfiltered (file,
6311 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6312 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6313 fprintf_unfiltered (file,
6314 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6315 fprintf_unfiltered (file,
6316 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6317 fprintf_unfiltered (file,
6318 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6319 fprintf_unfiltered (file,
6320 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6321 fprintf_unfiltered (file,
6322 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6323 fprintf_unfiltered (file,
6324 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6325 fprintf_unfiltered (file,
6326 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6327 fprintf_unfiltered (file,
6328 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6329 fprintf_unfiltered (file,
6330 "mips_dump_tdep: PROC_PC_REG = function?\n");
6331 fprintf_unfiltered (file,
6332 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6333 fprintf_unfiltered (file,
6334 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6335 fprintf_unfiltered (file,
6336 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6337 fprintf_unfiltered (file,
6338 "mips_dump_tdep: PS_REGNUM = %d\n",
6340 fprintf_unfiltered (file,
6341 "mips_dump_tdep: PUSH_FP_REGNUM = %d\n",
6343 fprintf_unfiltered (file,
6344 "mips_dump_tdep: RA_REGNUM = %d\n",
6346 fprintf_unfiltered (file,
6347 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6348 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6349 fprintf_unfiltered (file,
6350 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6351 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6352 fprintf_unfiltered (file,
6353 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6354 fprintf_unfiltered (file,
6355 "mips_dump_tdep: ROUND_DOWN = function?\n");
6356 fprintf_unfiltered (file,
6357 "mips_dump_tdep: ROUND_UP = function?\n");
6359 fprintf_unfiltered (file,
6360 "mips_dump_tdep: SAVED_BYTES = %d\n",
6364 fprintf_unfiltered (file,
6365 "mips_dump_tdep: SAVED_FP = %d\n",
6369 fprintf_unfiltered (file,
6370 "mips_dump_tdep: SAVED_PC = %d\n",
6373 fprintf_unfiltered (file,
6374 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6375 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6376 fprintf_unfiltered (file,
6377 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6378 fprintf_unfiltered (file,
6379 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6381 fprintf_unfiltered (file,
6382 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6383 SIGFRAME_FPREGSAVE_OFF);
6384 fprintf_unfiltered (file,
6385 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6387 fprintf_unfiltered (file,
6388 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6389 SIGFRAME_REGSAVE_OFF);
6390 fprintf_unfiltered (file,
6391 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6393 fprintf_unfiltered (file,
6394 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6395 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6396 fprintf_unfiltered (file,
6397 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6398 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6399 fprintf_unfiltered (file,
6400 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6401 SOFTWARE_SINGLE_STEP_P ());
6402 fprintf_unfiltered (file,
6403 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6404 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6405 #ifdef STACK_END_ADDR
6406 fprintf_unfiltered (file,
6407 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6410 fprintf_unfiltered (file,
6411 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6412 XSTRING (STEP_SKIPS_DELAY (PC)));
6413 fprintf_unfiltered (file,
6414 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6415 STEP_SKIPS_DELAY_P);
6416 fprintf_unfiltered (file,
6417 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6418 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6419 fprintf_unfiltered (file,
6420 "mips_dump_tdep: T9_REGNUM = %d\n",
6422 fprintf_unfiltered (file,
6423 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6424 fprintf_unfiltered (file,
6425 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6426 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6427 fprintf_unfiltered (file,
6428 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6429 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6430 fprintf_unfiltered (file,
6431 "mips_dump_tdep: TARGET_MIPS = used?\n");
6432 fprintf_unfiltered (file,
6433 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6434 XSTRING (TM_PRINT_INSN_MACH));
6436 fprintf_unfiltered (file,
6437 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6438 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6441 fprintf_unfiltered (file,
6442 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6445 #ifdef TRACE_FLAVOR_SIZE
6446 fprintf_unfiltered (file,
6447 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6451 fprintf_unfiltered (file,
6452 "mips_dump_tdep: TRACE_SET # %s\n",
6453 XSTRING (TRACE_SET (X,STATE)));
6455 fprintf_unfiltered (file,
6456 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6457 #ifdef UNUSED_REGNUM
6458 fprintf_unfiltered (file,
6459 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6462 fprintf_unfiltered (file,
6463 "mips_dump_tdep: V0_REGNUM = %d\n",
6465 fprintf_unfiltered (file,
6466 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6467 (long) VM_MIN_ADDRESS);
6469 fprintf_unfiltered (file,
6470 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6473 fprintf_unfiltered (file,
6474 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6476 fprintf_unfiltered (file,
6477 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6482 _initialize_mips_tdep (void)
6484 static struct cmd_list_element *mipsfpulist = NULL;
6485 struct cmd_list_element *c;
6487 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6488 if (MIPS_ABI_LAST + 1
6489 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6490 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6492 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6493 if (!tm_print_insn) /* Someone may have already set it */
6494 tm_print_insn = gdb_print_insn_mips;
6496 /* Add root prefix command for all "set mips"/"show mips" commands */
6497 add_prefix_cmd ("mips", no_class, set_mips_command,
6498 "Various MIPS specific commands.",
6499 &setmipscmdlist, "set mips ", 0, &setlist);
6501 add_prefix_cmd ("mips", no_class, show_mips_command,
6502 "Various MIPS specific commands.",
6503 &showmipscmdlist, "show mips ", 0, &showlist);
6505 /* Allow the user to override the saved register size. */
6506 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6509 &mips_saved_regsize_string, "\
6510 Set size of general purpose registers saved on the stack.\n\
6511 This option can be set to one of:\n\
6512 32 - Force GDB to treat saved GP registers as 32-bit\n\
6513 64 - Force GDB to treat saved GP registers as 64-bit\n\
6514 auto - Allow GDB to use the target's default setting or autodetect the\n\
6515 saved GP register size from information contained in the executable.\n\
6520 /* Allow the user to override the argument stack size. */
6521 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6524 &mips_stack_argsize_string, "\
6525 Set the amount of stack space reserved for each argument.\n\
6526 This option can be set to one of:\n\
6527 32 - Force GDB to allocate 32-bit chunks per argument\n\
6528 64 - Force GDB to allocate 64-bit chunks per argument\n\
6529 auto - Allow GDB to determine the correct setting from the current\n\
6530 target and executable (default)",
6534 /* Allow the user to override the ABI. */
6535 c = add_set_enum_cmd
6536 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6537 "Set the ABI used by this program.\n"
6538 "This option can be set to one of:\n"
6539 " auto - the default ABI associated with the current binary\n"
6547 set_cmd_sfunc (c, mips_abi_update);
6548 add_cmd ("abi", class_obscure, show_mips_abi,
6549 "Show ABI in use by MIPS target", &showmipscmdlist);
6551 /* Let the user turn off floating point and set the fence post for
6552 heuristic_proc_start. */
6554 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6555 "Set use of MIPS floating-point coprocessor.",
6556 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6557 add_cmd ("single", class_support, set_mipsfpu_single_command,
6558 "Select single-precision MIPS floating-point coprocessor.",
6560 add_cmd ("double", class_support, set_mipsfpu_double_command,
6561 "Select double-precision MIPS floating-point coprocessor.",
6563 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6564 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6565 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6566 add_cmd ("none", class_support, set_mipsfpu_none_command,
6567 "Select no MIPS floating-point coprocessor.",
6569 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6570 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6571 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6572 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6573 "Select MIPS floating-point coprocessor automatically.",
6575 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6576 "Show current use of MIPS floating-point coprocessor target.",
6579 /* We really would like to have both "0" and "unlimited" work, but
6580 command.c doesn't deal with that. So make it a var_zinteger
6581 because the user can always use "999999" or some such for unlimited. */
6582 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6583 (char *) &heuristic_fence_post,
6585 Set the distance searched for the start of a function.\n\
6586 If you are debugging a stripped executable, GDB needs to search through the\n\
6587 program for the start of a function. This command sets the distance of the\n\
6588 search. The only need to set it is when debugging a stripped executable.",
6590 /* We need to throw away the frame cache when we set this, since it
6591 might change our ability to get backtraces. */
6592 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6593 add_show_from_set (c, &showlist);
6595 /* Allow the user to control whether the upper bits of 64-bit
6596 addresses should be zeroed. */
6597 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6598 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6599 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6600 allow GDB to determine the correct value.\n", "\
6601 Show zeroing of upper 32 bits of 64-bit addresses.",
6602 NULL, show_mask_address,
6603 &setmipscmdlist, &showmipscmdlist);
6605 /* Allow the user to control the size of 32 bit registers within the
6606 raw remote packet. */
6607 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6610 (char *)&mips64_transfers_32bit_regs_p, "\
6611 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6612 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6613 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6614 64 bits for others. Use \"off\" to disable compatibility mode",
6618 /* Debug this files internals. */
6619 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6620 &mips_debug, "Set mips debugging.\n\
6621 When non-zero, mips specific debugging is enabled.", &setdebuglist),