1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 Free Software Foundation, Inc.
10 This file is part of GDB.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_string.h"
27 #include "gdb_assert.h"
39 #include "arch-utils.h"
42 #include "mips-tdep.h"
44 #include "reggroups.h"
45 #include "opcode/mips.h"
49 #include "sim-regno.h"
51 #include "frame-unwind.h"
52 #include "frame-base.h"
53 #include "trad-frame.h"
55 #include "floatformat.h"
57 #include "target-descriptions.h"
58 #include "dwarf2-frame.h"
59 #include "user-regs.h"
61 static const struct objfile_data *mips_pdr_data;
63 static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum);
65 /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
66 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
67 #define ST0_FR (1 << 26)
69 /* The sizes of floating point registers. */
73 MIPS_FPU_SINGLE_REGSIZE = 4,
74 MIPS_FPU_DOUBLE_REGSIZE = 8
83 static const char *mips_abi_string;
85 static const char *mips_abi_strings[] = {
96 /* The standard register names, and all the valid aliases for them. */
103 /* Aliases for o32 and most other ABIs. */
104 const struct register_alias mips_o32_aliases[] = {
111 /* Aliases for n32 and n64. */
112 const struct register_alias mips_n32_n64_aliases[] = {
119 /* Aliases for ABI-independent registers. */
120 const struct register_alias mips_register_aliases[] = {
121 /* The architecture manuals specify these ABI-independent names for
123 #define R(n) { "r" #n, n }
124 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
125 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
126 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
127 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
130 /* k0 and k1 are sometimes called these instead (for "kernel
135 /* This is the traditional GDB name for the CP0 status register. */
136 { "sr", MIPS_PS_REGNUM },
138 /* This is the traditional GDB name for the CP0 BadVAddr register. */
139 { "bad", MIPS_EMBED_BADVADDR_REGNUM },
141 /* This is the traditional GDB name for the FCSR. */
142 { "fsr", MIPS_EMBED_FP0_REGNUM + 32 }
145 #ifndef MIPS_DEFAULT_FPU_TYPE
146 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
148 static int mips_fpu_type_auto = 1;
149 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
151 static int mips_debug = 0;
153 /* Properties (for struct target_desc) describing the g/G packet
155 #define PROPERTY_GP32 "internal: transfers-32bit-registers"
156 #define PROPERTY_GP64 "internal: transfers-64bit-registers"
158 struct target_desc *mips_tdesc_gp32;
159 struct target_desc *mips_tdesc_gp64;
161 const struct mips_regnum *
162 mips_regnum (struct gdbarch *gdbarch)
164 return gdbarch_tdep (gdbarch)->regnum;
168 mips_fpa0_regnum (struct gdbarch *gdbarch)
170 return mips_regnum (gdbarch)->fp0 + 12;
173 #define MIPS_EABI(gdbarch) (gdbarch_tdep (gdbarch)->mips_abi \
175 || gdbarch_tdep (gdbarch)->mips_abi == MIPS_ABI_EABI64)
177 #define MIPS_LAST_FP_ARG_REGNUM(gdbarch) (gdbarch_tdep (gdbarch)->mips_last_fp_arg_regnum)
179 #define MIPS_LAST_ARG_REGNUM(gdbarch) (gdbarch_tdep (gdbarch)->mips_last_arg_regnum)
181 #define MIPS_FPU_TYPE(gdbarch) (gdbarch_tdep (gdbarch)->mips_fpu_type)
183 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
184 functions to test, set, or clear bit 0 of addresses. */
187 is_mips16_addr (CORE_ADDR addr)
193 unmake_mips16_addr (CORE_ADDR addr)
195 return ((addr) & ~(CORE_ADDR) 1);
198 /* Return the MIPS ABI associated with GDBARCH. */
200 mips_abi (struct gdbarch *gdbarch)
202 return gdbarch_tdep (gdbarch)->mips_abi;
206 mips_isa_regsize (struct gdbarch *gdbarch)
208 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
210 /* If we know how big the registers are, use that size. */
211 if (tdep->register_size_valid_p)
212 return tdep->register_size;
214 /* Fall back to the previous behavior. */
215 return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word
216 / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte);
219 /* Return the currently configured (or set) saved register size. */
222 mips_abi_regsize (struct gdbarch *gdbarch)
224 switch (mips_abi (gdbarch))
226 case MIPS_ABI_EABI32:
232 case MIPS_ABI_EABI64:
234 case MIPS_ABI_UNKNOWN:
237 internal_error (__FILE__, __LINE__, _("bad switch"));
241 /* Functions for setting and testing a bit in a minimal symbol that
242 marks it as 16-bit function. The MSB of the minimal symbol's
243 "info" field is used for this purpose.
245 gdbarch_elf_make_msymbol_special tests whether an ELF symbol is "special",
246 i.e. refers to a 16-bit function, and sets a "special" bit in a
247 minimal symbol to mark it as a 16-bit function
249 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
252 mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
254 if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16)
256 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
257 SYMBOL_VALUE_ADDRESS (msym) |= 1;
262 msymbol_is_special (struct minimal_symbol *msym)
264 return MSYMBOL_TARGET_FLAG_1 (msym);
267 /* XFER a value from the big/little/left end of the register.
268 Depending on the size of the value it might occupy the entire
269 register or just part of it. Make an allowance for this, aligning
270 things accordingly. */
273 mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache,
274 int reg_num, int length,
275 enum bfd_endian endian, gdb_byte *in,
276 const gdb_byte *out, int buf_offset)
280 gdb_assert (reg_num >= gdbarch_num_regs (gdbarch));
281 /* Need to transfer the left or right part of the register, based on
282 the targets byte order. */
286 reg_offset = register_size (gdbarch, reg_num) - length;
288 case BFD_ENDIAN_LITTLE:
291 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
295 internal_error (__FILE__, __LINE__, _("bad switch"));
298 fprintf_unfiltered (gdb_stderr,
299 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
300 reg_num, reg_offset, buf_offset, length);
301 if (mips_debug && out != NULL)
304 fprintf_unfiltered (gdb_stdlog, "out ");
305 for (i = 0; i < length; i++)
306 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
309 regcache_cooked_read_part (regcache, reg_num, reg_offset, length,
312 regcache_cooked_write_part (regcache, reg_num, reg_offset, length,
314 if (mips_debug && in != NULL)
317 fprintf_unfiltered (gdb_stdlog, "in ");
318 for (i = 0; i < length; i++)
319 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
322 fprintf_unfiltered (gdb_stdlog, "\n");
325 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
326 compatiblity mode. A return value of 1 means that we have
327 physical 64-bit registers, but should treat them as 32-bit registers. */
330 mips2_fp_compat (struct frame_info *frame)
332 struct gdbarch *gdbarch = get_frame_arch (frame);
333 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
335 if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4)
339 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
340 in all the places we deal with FP registers. PR gdb/413. */
341 /* Otherwise check the FR bit in the status register - it controls
342 the FP compatiblity mode. If it is clear we are in compatibility
344 if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0)
351 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
353 static CORE_ADDR heuristic_proc_start (struct gdbarch *, CORE_ADDR);
355 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
357 static struct type *mips_float_register_type (void);
358 static struct type *mips_double_register_type (void);
360 /* The list of available "set mips " and "show mips " commands */
362 static struct cmd_list_element *setmipscmdlist = NULL;
363 static struct cmd_list_element *showmipscmdlist = NULL;
365 /* Integer registers 0 thru 31 are handled explicitly by
366 mips_register_name(). Processor specific registers 32 and above
367 are listed in the following tables. */
370 { NUM_MIPS_PROCESSOR_REGS = (90 - 32) };
374 static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
375 "sr", "lo", "hi", "bad", "cause", "pc",
376 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
377 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
378 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
379 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
380 "fsr", "fir", "" /*"fp" */ , "",
381 "", "", "", "", "", "", "", "",
382 "", "", "", "", "", "", "", "",
385 /* Names of IDT R3041 registers. */
387 static const char *mips_r3041_reg_names[] = {
388 "sr", "lo", "hi", "bad", "cause", "pc",
389 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
390 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
391 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
392 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
393 "fsr", "fir", "", /*"fp" */ "",
394 "", "", "bus", "ccfg", "", "", "", "",
395 "", "", "port", "cmp", "", "", "epc", "prid",
398 /* Names of tx39 registers. */
400 static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
401 "sr", "lo", "hi", "bad", "cause", "pc",
402 "", "", "", "", "", "", "", "",
403 "", "", "", "", "", "", "", "",
404 "", "", "", "", "", "", "", "",
405 "", "", "", "", "", "", "", "",
407 "", "", "", "", "", "", "", "",
408 "", "", "config", "cache", "debug", "depc", "epc", ""
411 /* Names of IRIX registers. */
412 static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
413 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
414 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
415 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
416 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
417 "pc", "cause", "bad", "hi", "lo", "fsr", "fir"
421 /* Return the name of the register corresponding to REGNO. */
423 mips_register_name (struct gdbarch *gdbarch, int regno)
425 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
426 /* GPR names for all ABIs other than n32/n64. */
427 static char *mips_gpr_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",
434 /* GPR names for n32 and n64 ABIs. */
435 static char *mips_n32_n64_gpr_names[] = {
436 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
437 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
438 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
439 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
442 enum mips_abi abi = mips_abi (gdbarch);
444 /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
445 but then don't make the raw register names visible. */
446 int rawnum = regno % gdbarch_num_regs (gdbarch);
447 if (regno < gdbarch_num_regs (gdbarch))
450 /* The MIPS integer registers are always mapped from 0 to 31. The
451 names of the registers (which reflects the conventions regarding
452 register use) vary depending on the ABI. */
453 if (0 <= rawnum && rawnum < 32)
455 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
456 return mips_n32_n64_gpr_names[rawnum];
458 return mips_gpr_names[rawnum];
460 else if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
461 return tdesc_register_name (gdbarch, rawnum);
462 else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch))
464 gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS);
465 return tdep->mips_processor_reg_names[rawnum - 32];
468 internal_error (__FILE__, __LINE__,
469 _("mips_register_name: bad register number %d"), rawnum);
472 /* Return the groups that a MIPS register can be categorised into. */
475 mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
476 struct reggroup *reggroup)
481 int rawnum = regnum % gdbarch_num_regs (gdbarch);
482 int pseudo = regnum / gdbarch_num_regs (gdbarch);
483 if (reggroup == all_reggroup)
485 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
486 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
487 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
488 (gdbarch), as not all architectures are multi-arch. */
489 raw_p = rawnum < gdbarch_num_regs (gdbarch);
490 if (gdbarch_register_name (gdbarch, regnum) == NULL
491 || gdbarch_register_name (gdbarch, regnum)[0] == '\0')
493 if (reggroup == float_reggroup)
494 return float_p && pseudo;
495 if (reggroup == vector_reggroup)
496 return vector_p && pseudo;
497 if (reggroup == general_reggroup)
498 return (!vector_p && !float_p) && pseudo;
499 /* Save the pseudo registers. Need to make certain that any code
500 extracting register values from a saved register cache also uses
502 if (reggroup == save_reggroup)
503 return raw_p && pseudo;
504 /* Restore the same pseudo register. */
505 if (reggroup == restore_reggroup)
506 return raw_p && pseudo;
510 /* Return the groups that a MIPS register can be categorised into.
511 This version is only used if we have a target description which
512 describes real registers (and their groups). */
515 mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
516 struct reggroup *reggroup)
518 int rawnum = regnum % gdbarch_num_regs (gdbarch);
519 int pseudo = regnum / gdbarch_num_regs (gdbarch);
522 /* Only save, restore, and display the pseudo registers. Need to
523 make certain that any code extracting register values from a
524 saved register cache also uses pseudo registers.
526 Note: saving and restoring the pseudo registers is slightly
527 strange; if we have 64 bits, we should save and restore all
528 64 bits. But this is hard and has little benefit. */
532 ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup);
536 return mips_register_reggroup_p (gdbarch, regnum, reggroup);
539 /* Map the symbol table registers which live in the range [1 *
540 gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
541 registers. Take care of alignment and size problems. */
544 mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
545 int cookednum, gdb_byte *buf)
547 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
548 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
549 && cookednum < 2 * gdbarch_num_regs (gdbarch));
550 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
551 regcache_raw_read (regcache, rawnum, buf);
552 else if (register_size (gdbarch, rawnum) >
553 register_size (gdbarch, cookednum))
555 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p
556 || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
557 regcache_raw_read_part (regcache, rawnum, 0, 4, buf);
559 regcache_raw_read_part (regcache, rawnum, 4, 4, buf);
562 internal_error (__FILE__, __LINE__, _("bad register size"));
566 mips_pseudo_register_write (struct gdbarch *gdbarch,
567 struct regcache *regcache, int cookednum,
570 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
571 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
572 && cookednum < 2 * gdbarch_num_regs (gdbarch));
573 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
574 regcache_raw_write (regcache, rawnum, buf);
575 else if (register_size (gdbarch, rawnum) >
576 register_size (gdbarch, cookednum))
578 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p
579 || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
580 regcache_raw_write_part (regcache, rawnum, 0, 4, buf);
582 regcache_raw_write_part (regcache, rawnum, 4, 4, buf);
585 internal_error (__FILE__, __LINE__, _("bad register size"));
588 /* Table to translate MIPS16 register field to actual register number. */
589 static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
591 /* Heuristic_proc_start may hunt through the text section for a long
592 time across a 2400 baud serial line. Allows the user to limit this
595 static unsigned int heuristic_fence_post = 0;
597 /* Number of bytes of storage in the actual machine representation for
598 register N. NOTE: This defines the pseudo register type so need to
599 rebuild the architecture vector. */
601 static int mips64_transfers_32bit_regs_p = 0;
604 set_mips64_transfers_32bit_regs (char *args, int from_tty,
605 struct cmd_list_element *c)
607 struct gdbarch_info info;
608 gdbarch_info_init (&info);
609 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
610 instead of relying on globals. Doing that would let generic code
611 handle the search for this specific architecture. */
612 if (!gdbarch_update_p (info))
614 mips64_transfers_32bit_regs_p = 0;
615 error (_("32-bit compatibility mode not supported"));
619 /* Convert to/from a register and the corresponding memory value. */
622 mips_convert_register_p (struct gdbarch *gdbarch, int regnum, struct type *type)
624 return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
625 && register_size (gdbarch, regnum) == 4
626 && (regnum % gdbarch_num_regs (gdbarch))
627 >= mips_regnum (gdbarch)->fp0
628 && (regnum % gdbarch_num_regs (gdbarch))
629 < mips_regnum (gdbarch)->fp0 + 32
630 && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8);
634 mips_register_to_value (struct frame_info *frame, int regnum,
635 struct type *type, gdb_byte *to)
637 get_frame_register (frame, regnum + 0, to + 4);
638 get_frame_register (frame, regnum + 1, to + 0);
642 mips_value_to_register (struct frame_info *frame, int regnum,
643 struct type *type, const gdb_byte *from)
645 put_frame_register (frame, regnum + 0, from + 4);
646 put_frame_register (frame, regnum + 1, from + 0);
649 /* Return the GDB type object for the "standard" data type of data in
653 mips_register_type (struct gdbarch *gdbarch, int regnum)
655 gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch));
656 if ((regnum % gdbarch_num_regs (gdbarch)) >= mips_regnum (gdbarch)->fp0
657 && (regnum % gdbarch_num_regs (gdbarch))
658 < mips_regnum (gdbarch)->fp0 + 32)
660 /* The floating-point registers raw, or cooked, always match
661 mips_isa_regsize(), and also map 1:1, byte for byte. */
662 if (mips_isa_regsize (gdbarch) == 4)
663 return builtin_type_ieee_single;
665 return builtin_type_ieee_double;
667 else if (regnum < gdbarch_num_regs (gdbarch))
669 /* The raw or ISA registers. These are all sized according to
671 if (mips_isa_regsize (gdbarch) == 4)
672 return builtin_type_int32;
674 return builtin_type_int64;
678 /* The cooked or ABI registers. These are sized according to
679 the ABI (with a few complications). */
680 if (regnum >= (gdbarch_num_regs (gdbarch)
681 + mips_regnum (gdbarch)->fp_control_status)
682 && regnum <= gdbarch_num_regs (gdbarch) + MIPS_LAST_EMBED_REGNUM)
683 /* The pseudo/cooked view of the embedded registers is always
684 32-bit. The raw view is handled below. */
685 return builtin_type_int32;
686 else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p)
687 /* The target, while possibly using a 64-bit register buffer,
688 is only transfering 32-bits of each integer register.
689 Reflect this in the cooked/pseudo (ABI) register value. */
690 return builtin_type_int32;
691 else if (mips_abi_regsize (gdbarch) == 4)
692 /* The ABI is restricted to 32-bit registers (the ISA could be
694 return builtin_type_int32;
697 return builtin_type_int64;
701 /* Return the GDB type for the pseudo register REGNUM, which is the
702 ABI-level view. This function is only called if there is a target
703 description which includes registers, so we know precisely the
704 types of hardware registers. */
707 mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
709 const int num_regs = gdbarch_num_regs (gdbarch);
710 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
711 int rawnum = regnum % num_regs;
712 struct type *rawtype;
714 gdb_assert (regnum >= num_regs && regnum < 2 * num_regs);
716 /* Absent registers are still absent. */
717 rawtype = gdbarch_register_type (gdbarch, rawnum);
718 if (TYPE_LENGTH (rawtype) == 0)
721 if (rawnum >= MIPS_EMBED_FP0_REGNUM && rawnum < MIPS_EMBED_FP0_REGNUM + 32)
722 /* Present the floating point registers however the hardware did;
723 do not try to convert between FPU layouts. */
726 if (rawnum >= MIPS_EMBED_FP0_REGNUM + 32 && rawnum <= MIPS_LAST_EMBED_REGNUM)
728 /* The pseudo/cooked view of embedded registers is always
729 32-bit, even if the target transfers 64-bit values for them.
730 New targets relying on XML descriptions should only transfer
731 the necessary 32 bits, but older versions of GDB expected 64,
732 so allow the target to provide 64 bits without interfering
733 with the displayed type. */
734 return builtin_type_int32;
737 /* Use pointer types for registers if we can. For n32 we can not,
738 since we do not have a 64-bit pointer type. */
739 if (mips_abi_regsize (gdbarch)
740 == TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr))
742 if (rawnum == MIPS_SP_REGNUM || rawnum == MIPS_EMBED_BADVADDR_REGNUM)
743 return builtin_type (gdbarch)->builtin_data_ptr;
744 else if (rawnum == MIPS_EMBED_PC_REGNUM)
745 return builtin_type (gdbarch)->builtin_func_ptr;
748 if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8
749 && rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_EMBED_PC_REGNUM)
750 return builtin_type_int32;
752 /* For all other registers, pass through the hardware type. */
756 /* Should the upper word of 64-bit addresses be zeroed? */
757 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
760 mips_mask_address_p (struct gdbarch_tdep *tdep)
762 switch (mask_address_var)
764 case AUTO_BOOLEAN_TRUE:
766 case AUTO_BOOLEAN_FALSE:
769 case AUTO_BOOLEAN_AUTO:
770 return tdep->default_mask_address_p;
772 internal_error (__FILE__, __LINE__, _("mips_mask_address_p: bad switch"));
778 show_mask_address (struct ui_file *file, int from_tty,
779 struct cmd_list_element *c, const char *value)
781 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
783 deprecated_show_value_hack (file, from_tty, c, value);
784 switch (mask_address_var)
786 case AUTO_BOOLEAN_TRUE:
787 printf_filtered ("The 32 bit mips address mask is enabled\n");
789 case AUTO_BOOLEAN_FALSE:
790 printf_filtered ("The 32 bit mips address mask is disabled\n");
792 case AUTO_BOOLEAN_AUTO:
794 ("The 32 bit address mask is set automatically. Currently %s\n",
795 mips_mask_address_p (tdep) ? "enabled" : "disabled");
798 internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
803 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
806 mips_pc_is_mips16 (CORE_ADDR memaddr)
808 struct minimal_symbol *sym;
810 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
811 if (is_mips16_addr (memaddr))
814 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
815 the high bit of the info field. Use this to decide if the function is
816 MIPS16 or normal MIPS. */
817 sym = lookup_minimal_symbol_by_pc (memaddr);
819 return msymbol_is_special (sym);
824 /* MIPS believes that the PC has a sign extended value. Perhaps the
825 all registers should be sign extended for simplicity? */
828 mips_read_pc (struct regcache *regcache)
831 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
832 regcache_cooked_read_signed (regcache, regnum, &pc);
837 mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
839 return frame_unwind_register_signed
840 (next_frame, gdbarch_num_regs (gdbarch) + mips_regnum (gdbarch)->pc);
844 mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
846 return frame_unwind_register_signed
847 (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM);
850 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
851 dummy frame. The frame ID's base needs to match the TOS value
852 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
855 static struct frame_id
856 mips_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
858 return frame_id_build
859 (get_frame_register_signed (this_frame,
860 gdbarch_num_regs (gdbarch)
862 get_frame_pc (this_frame));
866 mips_write_pc (struct regcache *regcache, CORE_ADDR pc)
868 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
869 regcache_cooked_write_unsigned (regcache, regnum, pc);
872 /* Fetch and return instruction from the specified location. If the PC
873 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
876 mips_fetch_instruction (CORE_ADDR addr)
878 gdb_byte buf[MIPS_INSN32_SIZE];
882 if (mips_pc_is_mips16 (addr))
884 instlen = MIPS_INSN16_SIZE;
885 addr = unmake_mips16_addr (addr);
888 instlen = MIPS_INSN32_SIZE;
889 status = target_read_memory (addr, buf, instlen);
891 memory_error (status, addr);
892 return extract_unsigned_integer (buf, instlen);
895 /* These the fields of 32 bit mips instructions */
896 #define mips32_op(x) (x >> 26)
897 #define itype_op(x) (x >> 26)
898 #define itype_rs(x) ((x >> 21) & 0x1f)
899 #define itype_rt(x) ((x >> 16) & 0x1f)
900 #define itype_immediate(x) (x & 0xffff)
902 #define jtype_op(x) (x >> 26)
903 #define jtype_target(x) (x & 0x03ffffff)
905 #define rtype_op(x) (x >> 26)
906 #define rtype_rs(x) ((x >> 21) & 0x1f)
907 #define rtype_rt(x) ((x >> 16) & 0x1f)
908 #define rtype_rd(x) ((x >> 11) & 0x1f)
909 #define rtype_shamt(x) ((x >> 6) & 0x1f)
910 #define rtype_funct(x) (x & 0x3f)
913 mips32_relative_offset (ULONGEST inst)
915 return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2;
918 /* Determine where to set a single step breakpoint while considering
919 branch prediction. */
921 mips32_next_pc (struct frame_info *frame, CORE_ADDR pc)
925 inst = mips_fetch_instruction (pc);
926 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
928 if (itype_op (inst) >> 2 == 5)
929 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
931 op = (itype_op (inst) & 0x03);
946 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
947 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
949 int tf = itype_rt (inst) & 0x01;
950 int cnum = itype_rt (inst) >> 2;
952 get_frame_register_signed (frame,
953 mips_regnum (get_frame_arch (frame))->
955 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
957 if (((cond >> cnum) & 0x01) == tf)
958 pc += mips32_relative_offset (inst) + 4;
963 pc += 4; /* Not a branch, next instruction is easy */
966 { /* This gets way messy */
968 /* Further subdivide into SPECIAL, REGIMM and other */
969 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
971 case 0: /* SPECIAL */
972 op = rtype_funct (inst);
977 /* Set PC to that address */
978 pc = get_frame_register_signed (frame, rtype_rs (inst));
980 case 12: /* SYSCALL */
982 struct gdbarch_tdep *tdep;
984 tdep = gdbarch_tdep (get_frame_arch (frame));
985 if (tdep->syscall_next_pc != NULL)
986 pc = tdep->syscall_next_pc (frame);
995 break; /* end SPECIAL */
998 op = itype_rt (inst); /* branch condition */
1003 case 16: /* BLTZAL */
1004 case 18: /* BLTZALL */
1006 if (get_frame_register_signed (frame, itype_rs (inst)) < 0)
1007 pc += mips32_relative_offset (inst) + 4;
1009 pc += 8; /* after the delay slot */
1013 case 17: /* BGEZAL */
1014 case 19: /* BGEZALL */
1015 if (get_frame_register_signed (frame, itype_rs (inst)) >= 0)
1016 pc += mips32_relative_offset (inst) + 4;
1018 pc += 8; /* after the delay slot */
1020 /* All of the other instructions in the REGIMM category */
1025 break; /* end REGIMM */
1030 reg = jtype_target (inst) << 2;
1031 /* Upper four bits get never changed... */
1032 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff);
1035 /* FIXME case JALX : */
1038 reg = jtype_target (inst) << 2;
1039 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + 1; /* yes, +1 */
1040 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1042 break; /* The new PC will be alternate mode */
1043 case 4: /* BEQ, BEQL */
1045 if (get_frame_register_signed (frame, itype_rs (inst)) ==
1046 get_frame_register_signed (frame, itype_rt (inst)))
1047 pc += mips32_relative_offset (inst) + 4;
1051 case 5: /* BNE, BNEL */
1053 if (get_frame_register_signed (frame, itype_rs (inst)) !=
1054 get_frame_register_signed (frame, itype_rt (inst)))
1055 pc += mips32_relative_offset (inst) + 4;
1059 case 6: /* BLEZ, BLEZL */
1060 if (get_frame_register_signed (frame, itype_rs (inst)) <= 0)
1061 pc += mips32_relative_offset (inst) + 4;
1067 greater_branch: /* BGTZ, BGTZL */
1068 if (get_frame_register_signed (frame, itype_rs (inst)) > 0)
1069 pc += mips32_relative_offset (inst) + 4;
1076 } /* mips32_next_pc */
1078 /* Decoding the next place to set a breakpoint is irregular for the
1079 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1080 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1081 We dont want to set a single step instruction on the extend instruction
1085 /* Lots of mips16 instruction formats */
1086 /* Predicting jumps requires itype,ritype,i8type
1087 and their extensions extItype,extritype,extI8type
1089 enum mips16_inst_fmts
1091 itype, /* 0 immediate 5,10 */
1092 ritype, /* 1 5,3,8 */
1093 rrtype, /* 2 5,3,3,5 */
1094 rritype, /* 3 5,3,3,5 */
1095 rrrtype, /* 4 5,3,3,3,2 */
1096 rriatype, /* 5 5,3,3,1,4 */
1097 shifttype, /* 6 5,3,3,3,2 */
1098 i8type, /* 7 5,3,8 */
1099 i8movtype, /* 8 5,3,3,5 */
1100 i8mov32rtype, /* 9 5,3,5,3 */
1101 i64type, /* 10 5,3,8 */
1102 ri64type, /* 11 5,3,3,5 */
1103 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1104 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1105 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1106 extRRItype, /* 15 5,5,5,5,3,3,5 */
1107 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1108 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1109 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1110 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1111 extRi64type, /* 20 5,6,5,5,3,3,5 */
1112 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1114 /* I am heaping all the fields of the formats into one structure and
1115 then, only the fields which are involved in instruction extension */
1119 unsigned int regx; /* Function in i8 type */
1124 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1125 for the bits which make up the immediate extension. */
1128 extended_offset (unsigned int extension)
1131 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1133 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1135 value |= extension & 0x01f; /* extract 4:0 */
1139 /* Only call this function if you know that this is an extendable
1140 instruction. It won't malfunction, but why make excess remote memory
1141 references? If the immediate operands get sign extended or something,
1142 do it after the extension is performed. */
1143 /* FIXME: Every one of these cases needs to worry about sign extension
1144 when the offset is to be used in relative addressing. */
1147 fetch_mips_16 (CORE_ADDR pc)
1150 pc &= 0xfffffffe; /* clear the low order bit */
1151 target_read_memory (pc, buf, 2);
1152 return extract_unsigned_integer (buf, 2);
1156 unpack_mips16 (CORE_ADDR pc,
1157 unsigned int extension,
1159 enum mips16_inst_fmts insn_format, struct upk_mips16 *upk)
1164 switch (insn_format)
1171 value = extended_offset (extension);
1172 value = value << 11; /* rom for the original value */
1173 value |= inst & 0x7ff; /* eleven bits from instruction */
1177 value = inst & 0x7ff;
1178 /* FIXME : Consider sign extension */
1187 { /* A register identifier and an offset */
1188 /* Most of the fields are the same as I type but the
1189 immediate value is of a different length */
1193 value = extended_offset (extension);
1194 value = value << 8; /* from the original instruction */
1195 value |= inst & 0xff; /* eleven bits from instruction */
1196 regx = (extension >> 8) & 0x07; /* or i8 funct */
1197 if (value & 0x4000) /* test the sign bit , bit 26 */
1199 value &= ~0x3fff; /* remove the sign bit */
1205 value = inst & 0xff; /* 8 bits */
1206 regx = (inst >> 8) & 0x07; /* or i8 funct */
1207 /* FIXME: Do sign extension , this format needs it */
1208 if (value & 0x80) /* THIS CONFUSES ME */
1210 value &= 0xef; /* remove the sign bit */
1220 unsigned long value;
1221 unsigned int nexthalf;
1222 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1223 value = value << 16;
1224 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1232 internal_error (__FILE__, __LINE__, _("bad switch"));
1234 upk->offset = offset;
1241 add_offset_16 (CORE_ADDR pc, int offset)
1243 return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff)));
1247 extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc,
1248 unsigned int extension, unsigned int insn)
1250 int op = (insn >> 11);
1253 case 2: /* Branch */
1256 struct upk_mips16 upk;
1257 unpack_mips16 (pc, extension, insn, itype, &upk);
1258 offset = upk.offset;
1264 pc += (offset << 1) + 2;
1267 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1269 struct upk_mips16 upk;
1270 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1271 pc = add_offset_16 (pc, upk.offset);
1272 if ((insn >> 10) & 0x01) /* Exchange mode */
1273 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1280 struct upk_mips16 upk;
1282 unpack_mips16 (pc, extension, insn, ritype, &upk);
1283 reg = get_frame_register_signed (frame, upk.regx);
1285 pc += (upk.offset << 1) + 2;
1292 struct upk_mips16 upk;
1294 unpack_mips16 (pc, extension, insn, ritype, &upk);
1295 reg = get_frame_register_signed (frame, upk.regx);
1297 pc += (upk.offset << 1) + 2;
1302 case 12: /* I8 Formats btez btnez */
1304 struct upk_mips16 upk;
1306 unpack_mips16 (pc, extension, insn, i8type, &upk);
1307 /* upk.regx contains the opcode */
1308 reg = get_frame_register_signed (frame, 24); /* Test register is 24 */
1309 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1310 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1311 /* pc = add_offset_16(pc,upk.offset) ; */
1312 pc += (upk.offset << 1) + 2;
1317 case 29: /* RR Formats JR, JALR, JALR-RA */
1319 struct upk_mips16 upk;
1320 /* upk.fmt = rrtype; */
1325 upk.regx = (insn >> 8) & 0x07;
1326 upk.regy = (insn >> 5) & 0x07;
1334 break; /* Function return instruction */
1340 break; /* BOGUS Guess */
1342 pc = get_frame_register_signed (frame, reg);
1349 /* This is an instruction extension. Fetch the real instruction
1350 (which follows the extension) and decode things based on
1354 pc = extended_mips16_next_pc (frame, pc, insn, fetch_mips_16 (pc));
1367 mips16_next_pc (struct frame_info *frame, CORE_ADDR pc)
1369 unsigned int insn = fetch_mips_16 (pc);
1370 return extended_mips16_next_pc (frame, pc, 0, insn);
1373 /* The mips_next_pc function supports single_step when the remote
1374 target monitor or stub is not developed enough to do a single_step.
1375 It works by decoding the current instruction and predicting where a
1376 branch will go. This isnt hard because all the data is available.
1377 The MIPS32 and MIPS16 variants are quite different. */
1379 mips_next_pc (struct frame_info *frame, CORE_ADDR pc)
1381 if (is_mips16_addr (pc))
1382 return mips16_next_pc (frame, pc);
1384 return mips32_next_pc (frame, pc);
1387 struct mips_frame_cache
1390 struct trad_frame_saved_reg *saved_regs;
1393 /* Set a register's saved stack address in temp_saved_regs. If an
1394 address has already been set for this register, do nothing; this
1395 way we will only recognize the first save of a given register in a
1398 For simplicity, save the address in both [0 .. gdbarch_num_regs) and
1399 [gdbarch_num_regs .. 2*gdbarch_num_regs).
1400 Strictly speaking, only the second range is used as it is only second
1401 range (the ABI instead of ISA registers) that comes into play when finding
1402 saved registers in a frame. */
1405 set_reg_offset (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache,
1406 int regnum, CORE_ADDR offset)
1408 if (this_cache != NULL
1409 && this_cache->saved_regs[regnum].addr == -1)
1411 this_cache->saved_regs[regnum + 0 * gdbarch_num_regs (gdbarch)].addr
1413 this_cache->saved_regs[regnum + 1 * gdbarch_num_regs (gdbarch)].addr
1419 /* Fetch the immediate value from a MIPS16 instruction.
1420 If the previous instruction was an EXTEND, use it to extend
1421 the upper bits of the immediate value. This is a helper function
1422 for mips16_scan_prologue. */
1425 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1426 unsigned short inst, /* current instruction */
1427 int nbits, /* number of bits in imm field */
1428 int scale, /* scale factor to be applied to imm */
1429 int is_signed) /* is the imm field signed? */
1433 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1435 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1436 if (offset & 0x8000) /* check for negative extend */
1437 offset = 0 - (0x10000 - (offset & 0xffff));
1438 return offset | (inst & 0x1f);
1442 int max_imm = 1 << nbits;
1443 int mask = max_imm - 1;
1444 int sign_bit = max_imm >> 1;
1446 offset = inst & mask;
1447 if (is_signed && (offset & sign_bit))
1448 offset = 0 - (max_imm - offset);
1449 return offset * scale;
1454 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1455 the associated FRAME_CACHE if not null.
1456 Return the address of the first instruction past the prologue. */
1459 mips16_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1460 struct frame_info *this_frame,
1461 struct mips_frame_cache *this_cache)
1464 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1466 long frame_offset = 0; /* Size of stack frame. */
1467 long frame_adjust = 0; /* Offset of FP from SP. */
1468 int frame_reg = MIPS_SP_REGNUM;
1469 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1470 unsigned inst = 0; /* current instruction */
1471 unsigned entry_inst = 0; /* the entry instruction */
1472 unsigned save_inst = 0; /* the save instruction */
1475 int extend_bytes = 0;
1476 int prev_extend_bytes;
1477 CORE_ADDR end_prologue_addr = 0;
1478 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1480 /* Can be called when there's no process, and hence when there's no
1482 if (this_frame != NULL)
1483 sp = get_frame_register_signed (this_frame,
1484 gdbarch_num_regs (gdbarch)
1489 if (limit_pc > start_pc + 200)
1490 limit_pc = start_pc + 200;
1492 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE)
1494 /* Save the previous instruction. If it's an EXTEND, we'll extract
1495 the immediate offset extension from it in mips16_get_imm. */
1498 /* Fetch and decode the instruction. */
1499 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1501 /* Normally we ignore extend instructions. However, if it is
1502 not followed by a valid prologue instruction, then this
1503 instruction is not part of the prologue either. We must
1504 remember in this case to adjust the end_prologue_addr back
1506 if ((inst & 0xf800) == 0xf000) /* extend */
1508 extend_bytes = MIPS_INSN16_SIZE;
1512 prev_extend_bytes = extend_bytes;
1515 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1516 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1518 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1519 if (offset < 0) /* negative stack adjustment? */
1520 frame_offset -= offset;
1522 /* Exit loop if a positive stack adjustment is found, which
1523 usually means that the stack cleanup code in the function
1524 epilogue is reached. */
1527 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1529 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1530 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1531 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1533 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1535 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1536 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1537 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1539 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1541 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1542 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1544 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1546 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1547 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1549 else if (inst == 0x673d) /* move $s1, $sp */
1554 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1556 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1557 frame_addr = sp + offset;
1559 frame_adjust = offset;
1561 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1563 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1564 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1565 set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
1567 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1569 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1570 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1571 set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
1573 else if ((inst & 0xf81f) == 0xe809
1574 && (inst & 0x700) != 0x700) /* entry */
1575 entry_inst = inst; /* save for later processing */
1576 else if ((inst & 0xff80) == 0x6480) /* save */
1578 save_inst = inst; /* save for later processing */
1579 if (prev_extend_bytes) /* extend */
1580 save_inst |= prev_inst << 16;
1582 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
1583 cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */
1584 else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
1586 /* This instruction is part of the prologue, but we don't
1587 need to do anything special to handle it. */
1591 /* This instruction is not an instruction typically found
1592 in a prologue, so we must have reached the end of the
1594 if (end_prologue_addr == 0)
1595 end_prologue_addr = cur_pc - prev_extend_bytes;
1599 /* The entry instruction is typically the first instruction in a function,
1600 and it stores registers at offsets relative to the value of the old SP
1601 (before the prologue). But the value of the sp parameter to this
1602 function is the new SP (after the prologue has been executed). So we
1603 can't calculate those offsets until we've seen the entire prologue,
1604 and can calculate what the old SP must have been. */
1605 if (entry_inst != 0)
1607 int areg_count = (entry_inst >> 8) & 7;
1608 int sreg_count = (entry_inst >> 6) & 3;
1610 /* The entry instruction always subtracts 32 from the SP. */
1613 /* Now we can calculate what the SP must have been at the
1614 start of the function prologue. */
1617 /* Check if a0-a3 were saved in the caller's argument save area. */
1618 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
1620 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1621 offset += mips_abi_regsize (gdbarch);
1624 /* Check if the ra register was pushed on the stack. */
1626 if (entry_inst & 0x20)
1628 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1629 offset -= mips_abi_regsize (gdbarch);
1632 /* Check if the s0 and s1 registers were pushed on the stack. */
1633 for (reg = 16; reg < sreg_count + 16; reg++)
1635 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1636 offset -= mips_abi_regsize (gdbarch);
1640 /* The SAVE instruction is similar to ENTRY, except that defined by the
1641 MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
1642 size of the frame is specified as an immediate field of instruction
1643 and an extended variation exists which lets additional registers and
1644 frame space to be specified. The instruction always treats registers
1645 as 32-bit so its usefulness for 64-bit ABIs is questionable. */
1646 if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4)
1648 static int args_table[16] = {
1649 0, 0, 0, 0, 1, 1, 1, 1,
1650 2, 2, 2, 0, 3, 3, 4, -1,
1652 static int astatic_table[16] = {
1653 0, 1, 2, 3, 0, 1, 2, 3,
1654 0, 1, 2, 4, 0, 1, 0, -1,
1656 int aregs = (save_inst >> 16) & 0xf;
1657 int xsregs = (save_inst >> 24) & 0x7;
1658 int args = args_table[aregs];
1659 int astatic = astatic_table[aregs];
1664 warning (_("Invalid number of argument registers encoded in SAVE."));
1669 warning (_("Invalid number of static registers encoded in SAVE."));
1673 /* For standard SAVE the frame size of 0 means 128. */
1674 frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf);
1675 if (frame_size == 0 && (save_inst >> 16) == 0)
1678 frame_offset += frame_size;
1680 /* Now we can calculate what the SP must have been at the
1681 start of the function prologue. */
1684 /* Check if A0-A3 were saved in the caller's argument save area. */
1685 for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++)
1687 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1688 offset += mips_abi_regsize (gdbarch);
1693 /* Check if the RA register was pushed on the stack. */
1694 if (save_inst & 0x40)
1696 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1697 offset -= mips_abi_regsize (gdbarch);
1700 /* Check if the S8 register was pushed on the stack. */
1703 set_reg_offset (gdbarch, this_cache, 30, sp + offset);
1704 offset -= mips_abi_regsize (gdbarch);
1707 /* Check if S2-S7 were pushed on the stack. */
1708 for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--)
1710 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1711 offset -= mips_abi_regsize (gdbarch);
1714 /* Check if the S1 register was pushed on the stack. */
1715 if (save_inst & 0x10)
1717 set_reg_offset (gdbarch, this_cache, 17, sp + offset);
1718 offset -= mips_abi_regsize (gdbarch);
1720 /* Check if the S0 register was pushed on the stack. */
1721 if (save_inst & 0x20)
1723 set_reg_offset (gdbarch, this_cache, 16, sp + offset);
1724 offset -= mips_abi_regsize (gdbarch);
1727 /* Check if A0-A3 were pushed on the stack. */
1728 for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--)
1730 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1731 offset -= mips_abi_regsize (gdbarch);
1735 if (this_cache != NULL)
1738 (get_frame_register_signed (this_frame,
1739 gdbarch_num_regs (gdbarch) + frame_reg)
1740 + frame_offset - frame_adjust);
1741 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
1742 be able to get rid of the assignment below, evetually. But it's
1743 still needed for now. */
1744 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
1745 + mips_regnum (gdbarch)->pc]
1746 = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM];
1749 /* If we didn't reach the end of the prologue when scanning the function
1750 instructions, then set end_prologue_addr to the address of the
1751 instruction immediately after the last one we scanned. */
1752 if (end_prologue_addr == 0)
1753 end_prologue_addr = cur_pc;
1755 return end_prologue_addr;
1758 /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
1759 Procedures that use the 32-bit instruction set are handled by the
1760 mips_insn32 unwinder. */
1762 static struct mips_frame_cache *
1763 mips_insn16_frame_cache (struct frame_info *this_frame, void **this_cache)
1765 struct mips_frame_cache *cache;
1767 if ((*this_cache) != NULL)
1768 return (*this_cache);
1769 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
1770 (*this_cache) = cache;
1771 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1773 /* Analyze the function prologue. */
1775 const CORE_ADDR pc = get_frame_address_in_block (this_frame);
1776 CORE_ADDR start_addr;
1778 find_pc_partial_function (pc, NULL, &start_addr, NULL);
1779 if (start_addr == 0)
1780 start_addr = heuristic_proc_start (get_frame_arch (this_frame), pc);
1781 /* We can't analyze the prologue if we couldn't find the begining
1783 if (start_addr == 0)
1786 mips16_scan_prologue (start_addr, pc, this_frame, *this_cache);
1789 /* gdbarch_sp_regnum contains the value and not the address. */
1790 trad_frame_set_value (cache->saved_regs,
1791 gdbarch_num_regs (get_frame_arch (this_frame))
1795 return (*this_cache);
1799 mips_insn16_frame_this_id (struct frame_info *this_frame, void **this_cache,
1800 struct frame_id *this_id)
1802 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
1804 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
1807 static struct value *
1808 mips_insn16_frame_prev_register (struct frame_info *this_frame,
1809 void **this_cache, int regnum)
1811 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
1813 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1817 mips_insn16_frame_sniffer (const struct frame_unwind *self,
1818 struct frame_info *this_frame, void **this_cache)
1820 CORE_ADDR pc = get_frame_pc (this_frame);
1821 if (mips_pc_is_mips16 (pc))
1826 static const struct frame_unwind mips_insn16_frame_unwind =
1829 mips_insn16_frame_this_id,
1830 mips_insn16_frame_prev_register,
1832 mips_insn16_frame_sniffer
1836 mips_insn16_frame_base_address (struct frame_info *this_frame,
1839 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
1844 static const struct frame_base mips_insn16_frame_base =
1846 &mips_insn16_frame_unwind,
1847 mips_insn16_frame_base_address,
1848 mips_insn16_frame_base_address,
1849 mips_insn16_frame_base_address
1852 static const struct frame_base *
1853 mips_insn16_frame_base_sniffer (struct frame_info *this_frame)
1855 CORE_ADDR pc = get_frame_pc (this_frame);
1856 if (mips_pc_is_mips16 (pc))
1857 return &mips_insn16_frame_base;
1862 /* Mark all the registers as unset in the saved_regs array
1863 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
1866 reset_saved_regs (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache)
1868 if (this_cache == NULL || this_cache->saved_regs == NULL)
1872 const int num_regs = gdbarch_num_regs (gdbarch);
1875 for (i = 0; i < num_regs; i++)
1877 this_cache->saved_regs[i].addr = -1;
1882 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1883 the associated FRAME_CACHE if not null.
1884 Return the address of the first instruction past the prologue. */
1887 mips32_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1888 struct frame_info *this_frame,
1889 struct mips_frame_cache *this_cache)
1892 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
1895 int frame_reg = MIPS_SP_REGNUM;
1897 CORE_ADDR end_prologue_addr = 0;
1898 int seen_sp_adjust = 0;
1899 int load_immediate_bytes = 0;
1900 int in_delay_slot = 0;
1901 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1902 int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8);
1904 /* Can be called when there's no process, and hence when there's no
1906 if (this_frame != NULL)
1907 sp = get_frame_register_signed (this_frame,
1908 gdbarch_num_regs (gdbarch)
1913 if (limit_pc > start_pc + 200)
1914 limit_pc = start_pc + 200;
1919 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE)
1921 unsigned long inst, high_word, low_word;
1924 /* Fetch the instruction. */
1925 inst = (unsigned long) mips_fetch_instruction (cur_pc);
1927 /* Save some code by pre-extracting some useful fields. */
1928 high_word = (inst >> 16) & 0xffff;
1929 low_word = inst & 0xffff;
1930 reg = high_word & 0x1f;
1932 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
1933 || high_word == 0x23bd /* addi $sp,$sp,-i */
1934 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
1936 if (low_word & 0x8000) /* negative stack adjustment? */
1937 frame_offset += 0x10000 - low_word;
1939 /* Exit loop if a positive stack adjustment is found, which
1940 usually means that the stack cleanup code in the function
1941 epilogue is reached. */
1945 else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
1946 && !regsize_is_64_bits)
1948 set_reg_offset (gdbarch, this_cache, reg, sp + low_word);
1950 else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
1951 && regsize_is_64_bits)
1953 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
1954 set_reg_offset (gdbarch, this_cache, reg, sp + low_word);
1956 else if (high_word == 0x27be) /* addiu $30,$sp,size */
1958 /* Old gcc frame, r30 is virtual frame pointer. */
1959 if ((long) low_word != frame_offset)
1960 frame_addr = sp + low_word;
1961 else if (this_frame && frame_reg == MIPS_SP_REGNUM)
1963 unsigned alloca_adjust;
1966 frame_addr = get_frame_register_signed
1967 (this_frame, gdbarch_num_regs (gdbarch) + 30);
1969 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
1970 if (alloca_adjust > 0)
1972 /* FP > SP + frame_size. This may be because of
1973 an alloca or somethings similar. Fix sp to
1974 "pre-alloca" value, and try again. */
1975 sp += alloca_adjust;
1976 /* Need to reset the status of all registers. Otherwise,
1977 we will hit a guard that prevents the new address
1978 for each register to be recomputed during the second
1980 reset_saved_regs (gdbarch, this_cache);
1985 /* move $30,$sp. With different versions of gas this will be either
1986 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
1987 Accept any one of these. */
1988 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
1990 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
1991 if (this_frame && frame_reg == MIPS_SP_REGNUM)
1993 unsigned alloca_adjust;
1996 frame_addr = get_frame_register_signed
1997 (this_frame, gdbarch_num_regs (gdbarch) + 30);
1999 alloca_adjust = (unsigned) (frame_addr - sp);
2000 if (alloca_adjust > 0)
2002 /* FP > SP + frame_size. This may be because of
2003 an alloca or somethings similar. Fix sp to
2004 "pre-alloca" value, and try again. */
2006 /* Need to reset the status of all registers. Otherwise,
2007 we will hit a guard that prevents the new address
2008 for each register to be recomputed during the second
2010 reset_saved_regs (gdbarch, this_cache);
2015 else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
2016 && !regsize_is_64_bits)
2018 set_reg_offset (gdbarch, this_cache, reg, frame_addr + low_word);
2020 else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
2021 || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
2022 || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
2023 || high_word == 0x3c1c /* lui $gp,n */
2024 || high_word == 0x279c /* addiu $gp,$gp,n */
2025 || inst == 0x0399e021 /* addu $gp,$gp,$t9 */
2026 || inst == 0x033ce021 /* addu $gp,$t9,$gp */
2029 /* These instructions are part of the prologue, but we don't
2030 need to do anything special to handle them. */
2032 /* The instructions below load $at or $t0 with an immediate
2033 value in preparation for a stack adjustment via
2034 subu $sp,$sp,[$at,$t0]. These instructions could also
2035 initialize a local variable, so we accept them only before
2036 a stack adjustment instruction was seen. */
2037 else if (!seen_sp_adjust
2038 && (high_word == 0x3c01 /* lui $at,n */
2039 || high_word == 0x3c08 /* lui $t0,n */
2040 || high_word == 0x3421 /* ori $at,$at,n */
2041 || high_word == 0x3508 /* ori $t0,$t0,n */
2042 || high_word == 0x3401 /* ori $at,$zero,n */
2043 || high_word == 0x3408 /* ori $t0,$zero,n */
2046 load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */
2050 /* This instruction is not an instruction typically found
2051 in a prologue, so we must have reached the end of the
2053 /* FIXME: brobecker/2004-10-10: Can't we just break out of this
2054 loop now? Why would we need to continue scanning the function
2056 if (end_prologue_addr == 0)
2057 end_prologue_addr = cur_pc;
2059 /* Check for branches and jumps. For now, only jump to
2060 register are caught (i.e. returns). */
2061 if ((itype_op (inst) & 0x07) == 0 && rtype_funct (inst) == 8)
2065 /* If the previous instruction was a jump, we must have reached
2066 the end of the prologue by now. Stop scanning so that we do
2067 not go past the function return. */
2072 if (this_cache != NULL)
2075 (get_frame_register_signed (this_frame,
2076 gdbarch_num_regs (gdbarch) + frame_reg)
2078 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
2079 this assignment below, eventually. But it's still needed
2081 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
2082 + mips_regnum (gdbarch)->pc]
2083 = this_cache->saved_regs[gdbarch_num_regs (gdbarch)
2087 /* If we didn't reach the end of the prologue when scanning the function
2088 instructions, then set end_prologue_addr to the address of the
2089 instruction immediately after the last one we scanned. */
2090 /* brobecker/2004-10-10: I don't think this would ever happen, but
2091 we may as well be careful and do our best if we have a null
2092 end_prologue_addr. */
2093 if (end_prologue_addr == 0)
2094 end_prologue_addr = cur_pc;
2096 /* In a frameless function, we might have incorrectly
2097 skipped some load immediate instructions. Undo the skipping
2098 if the load immediate was not followed by a stack adjustment. */
2099 if (load_immediate_bytes && !seen_sp_adjust)
2100 end_prologue_addr -= load_immediate_bytes;
2102 return end_prologue_addr;
2105 /* Heuristic unwinder for procedures using 32-bit instructions (covers
2106 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
2107 instructions (a.k.a. MIPS16) are handled by the mips_insn16
2110 static struct mips_frame_cache *
2111 mips_insn32_frame_cache (struct frame_info *this_frame, void **this_cache)
2113 struct mips_frame_cache *cache;
2115 if ((*this_cache) != NULL)
2116 return (*this_cache);
2118 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
2119 (*this_cache) = cache;
2120 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2122 /* Analyze the function prologue. */
2124 const CORE_ADDR pc = get_frame_address_in_block (this_frame);
2125 CORE_ADDR start_addr;
2127 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2128 if (start_addr == 0)
2129 start_addr = heuristic_proc_start (get_frame_arch (this_frame), pc);
2130 /* We can't analyze the prologue if we couldn't find the begining
2132 if (start_addr == 0)
2135 mips32_scan_prologue (start_addr, pc, this_frame, *this_cache);
2138 /* gdbarch_sp_regnum contains the value and not the address. */
2139 trad_frame_set_value (cache->saved_regs,
2140 gdbarch_num_regs (get_frame_arch (this_frame))
2144 return (*this_cache);
2148 mips_insn32_frame_this_id (struct frame_info *this_frame, void **this_cache,
2149 struct frame_id *this_id)
2151 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2153 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
2156 static struct value *
2157 mips_insn32_frame_prev_register (struct frame_info *this_frame,
2158 void **this_cache, int regnum)
2160 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2162 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
2166 mips_insn32_frame_sniffer (const struct frame_unwind *self,
2167 struct frame_info *this_frame, void **this_cache)
2169 CORE_ADDR pc = get_frame_pc (this_frame);
2170 if (! mips_pc_is_mips16 (pc))
2175 static const struct frame_unwind mips_insn32_frame_unwind =
2178 mips_insn32_frame_this_id,
2179 mips_insn32_frame_prev_register,
2181 mips_insn32_frame_sniffer
2185 mips_insn32_frame_base_address (struct frame_info *this_frame,
2188 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2193 static const struct frame_base mips_insn32_frame_base =
2195 &mips_insn32_frame_unwind,
2196 mips_insn32_frame_base_address,
2197 mips_insn32_frame_base_address,
2198 mips_insn32_frame_base_address
2201 static const struct frame_base *
2202 mips_insn32_frame_base_sniffer (struct frame_info *this_frame)
2204 CORE_ADDR pc = get_frame_pc (this_frame);
2205 if (! mips_pc_is_mips16 (pc))
2206 return &mips_insn32_frame_base;
2211 static struct trad_frame_cache *
2212 mips_stub_frame_cache (struct frame_info *this_frame, void **this_cache)
2215 CORE_ADDR start_addr;
2216 CORE_ADDR stack_addr;
2217 struct trad_frame_cache *this_trad_cache;
2218 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2219 int num_regs = gdbarch_num_regs (gdbarch);
2221 if ((*this_cache) != NULL)
2222 return (*this_cache);
2223 this_trad_cache = trad_frame_cache_zalloc (this_frame);
2224 (*this_cache) = this_trad_cache;
2226 /* The return address is in the link register. */
2227 trad_frame_set_reg_realreg (this_trad_cache,
2228 gdbarch_pc_regnum (gdbarch),
2229 num_regs + MIPS_RA_REGNUM);
2231 /* Frame ID, since it's a frameless / stackless function, no stack
2232 space is allocated and SP on entry is the current SP. */
2233 pc = get_frame_pc (this_frame);
2234 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2235 stack_addr = get_frame_register_signed (this_frame,
2236 num_regs + MIPS_SP_REGNUM);
2237 trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr));
2239 /* Assume that the frame's base is the same as the
2241 trad_frame_set_this_base (this_trad_cache, stack_addr);
2243 return this_trad_cache;
2247 mips_stub_frame_this_id (struct frame_info *this_frame, void **this_cache,
2248 struct frame_id *this_id)
2250 struct trad_frame_cache *this_trad_cache
2251 = mips_stub_frame_cache (this_frame, this_cache);
2252 trad_frame_get_id (this_trad_cache, this_id);
2255 static struct value *
2256 mips_stub_frame_prev_register (struct frame_info *this_frame,
2257 void **this_cache, int regnum)
2259 struct trad_frame_cache *this_trad_cache
2260 = mips_stub_frame_cache (this_frame, this_cache);
2261 return trad_frame_get_register (this_trad_cache, this_frame, regnum);
2265 mips_stub_frame_sniffer (const struct frame_unwind *self,
2266 struct frame_info *this_frame, void **this_cache)
2269 struct obj_section *s;
2270 CORE_ADDR pc = get_frame_address_in_block (this_frame);
2271 struct minimal_symbol *msym;
2273 /* Use the stub unwinder for unreadable code. */
2274 if (target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0)
2277 if (in_plt_section (pc, NULL))
2280 /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */
2281 s = find_pc_section (pc);
2284 && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section),
2285 ".MIPS.stubs") == 0)
2288 /* Calling a PIC function from a non-PIC function passes through a
2289 stub. The stub for foo is named ".pic.foo". */
2290 msym = lookup_minimal_symbol_by_pc (pc);
2292 && SYMBOL_LINKAGE_NAME (msym) != NULL
2293 && strncmp (SYMBOL_LINKAGE_NAME (msym), ".pic.", 5) == 0)
2299 static const struct frame_unwind mips_stub_frame_unwind =
2302 mips_stub_frame_this_id,
2303 mips_stub_frame_prev_register,
2305 mips_stub_frame_sniffer
2309 mips_stub_frame_base_address (struct frame_info *this_frame,
2312 struct trad_frame_cache *this_trad_cache
2313 = mips_stub_frame_cache (this_frame, this_cache);
2314 return trad_frame_get_this_base (this_trad_cache);
2317 static const struct frame_base mips_stub_frame_base =
2319 &mips_stub_frame_unwind,
2320 mips_stub_frame_base_address,
2321 mips_stub_frame_base_address,
2322 mips_stub_frame_base_address
2325 static const struct frame_base *
2326 mips_stub_frame_base_sniffer (struct frame_info *this_frame)
2328 if (mips_stub_frame_sniffer (&mips_stub_frame_unwind, this_frame, NULL))
2329 return &mips_stub_frame_base;
2334 /* mips_addr_bits_remove - remove useless address bits */
2337 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
2339 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2340 if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
2341 /* This hack is a work-around for existing boards using PMON, the
2342 simulator, and any other 64-bit targets that doesn't have true
2343 64-bit addressing. On these targets, the upper 32 bits of
2344 addresses are ignored by the hardware. Thus, the PC or SP are
2345 likely to have been sign extended to all 1s by instruction
2346 sequences that load 32-bit addresses. For example, a typical
2347 piece of code that loads an address is this:
2349 lui $r2, <upper 16 bits>
2350 ori $r2, <lower 16 bits>
2352 But the lui sign-extends the value such that the upper 32 bits
2353 may be all 1s. The workaround is simply to mask off these
2354 bits. In the future, gcc may be changed to support true 64-bit
2355 addressing, and this masking will have to be disabled. */
2356 return addr &= 0xffffffffUL;
2361 /* Instructions used during single-stepping of atomic sequences. */
2362 #define LL_OPCODE 0x30
2363 #define LLD_OPCODE 0x34
2364 #define SC_OPCODE 0x38
2365 #define SCD_OPCODE 0x3c
2367 /* Checks for an atomic sequence of instructions beginning with a LL/LLD
2368 instruction and ending with a SC/SCD instruction. If such a sequence
2369 is found, attempt to step through it. A breakpoint is placed at the end of
2373 deal_with_atomic_sequence (CORE_ADDR pc)
2375 CORE_ADDR breaks[2] = {-1, -1};
2377 CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */
2381 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
2382 const int atomic_sequence_length = 16; /* Instruction sequence length. */
2387 insn = mips_fetch_instruction (loc);
2388 /* Assume all atomic sequences start with a ll/lld instruction. */
2389 if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE)
2392 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
2394 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
2397 loc += MIPS_INSN32_SIZE;
2398 insn = mips_fetch_instruction (loc);
2400 /* Assume that there is at most one branch in the atomic
2401 sequence. If a branch is found, put a breakpoint in its
2402 destination address. */
2403 switch (itype_op (insn))
2405 case 0: /* SPECIAL */
2406 if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */
2407 return 0; /* fallback to the standard single-step code. */
2409 case 1: /* REGIMM */
2410 is_branch = ((itype_rt (insn) & 0xc0) == 0); /* B{LT,GE}Z* */
2414 return 0; /* fallback to the standard single-step code. */
2421 case 22: /* BLEZL */
2422 case 23: /* BGTTL */
2428 is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
2433 branch_bp = loc + mips32_relative_offset (insn) + 4;
2434 if (last_breakpoint >= 1)
2435 return 0; /* More than one branch found, fallback to the
2436 standard single-step code. */
2437 breaks[1] = branch_bp;
2441 if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE)
2445 /* Assume that the atomic sequence ends with a sc/scd instruction. */
2446 if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE)
2449 loc += MIPS_INSN32_SIZE;
2451 /* Insert a breakpoint right after the end of the atomic sequence. */
2454 /* Check for duplicated breakpoints. Check also for a breakpoint
2455 placed (branch instruction's destination) in the atomic sequence */
2456 if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0])
2457 last_breakpoint = 0;
2459 /* Effectively inserts the breakpoints. */
2460 for (index = 0; index <= last_breakpoint; index++)
2461 insert_single_step_breakpoint (breaks[index]);
2466 /* mips_software_single_step() is called just before we want to resume
2467 the inferior, if we want to single-step it but there is no hardware
2468 or kernel single-step support (MIPS on GNU/Linux for example). We find
2469 the target of the coming instruction and breakpoint it. */
2472 mips_software_single_step (struct frame_info *frame)
2474 CORE_ADDR pc, next_pc;
2476 pc = get_frame_pc (frame);
2477 if (deal_with_atomic_sequence (pc))
2480 next_pc = mips_next_pc (frame, pc);
2482 insert_single_step_breakpoint (next_pc);
2486 /* Test whether the PC points to the return instruction at the
2487 end of a function. */
2490 mips_about_to_return (CORE_ADDR pc)
2492 if (mips_pc_is_mips16 (pc))
2493 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2494 generates a "jr $ra"; other times it generates code to load
2495 the return address from the stack to an accessible register (such
2496 as $a3), then a "jr" using that register. This second case
2497 is almost impossible to distinguish from an indirect jump
2498 used for switch statements, so we don't even try. */
2499 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
2501 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
2505 /* This fencepost looks highly suspicious to me. Removing it also
2506 seems suspicious as it could affect remote debugging across serial
2510 heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
2516 struct inferior *inf;
2518 pc = gdbarch_addr_bits_remove (gdbarch, pc);
2520 fence = start_pc - heuristic_fence_post;
2524 if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS)
2525 fence = VM_MIN_ADDRESS;
2527 instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE;
2529 inf = current_inferior ();
2531 /* search back for previous return */
2532 for (start_pc -= instlen;; start_pc -= instlen)
2533 if (start_pc < fence)
2535 /* It's not clear to me why we reach this point when
2536 stop_soon, but with this test, at least we
2537 don't print out warnings for every child forked (eg, on
2539 if (inf->stop_soon == NO_STOP_QUIETLY)
2541 static int blurb_printed = 0;
2543 warning (_("GDB can't find the start of the function at 0x%s."),
2548 /* This actually happens frequently in embedded
2549 development, when you first connect to a board
2550 and your stack pointer and pc are nowhere in
2551 particular. This message needs to give people
2552 in that situation enough information to
2553 determine that it's no big deal. */
2554 printf_filtered ("\n\
2555 GDB is unable to find the start of the function at 0x%s\n\
2556 and thus can't determine the size of that function's stack frame.\n\
2557 This means that GDB may be unable to access that stack frame, or\n\
2558 the frames below it.\n\
2559 This problem is most likely caused by an invalid program counter or\n\
2561 However, if you think GDB should simply search farther back\n\
2562 from 0x%s for code which looks like the beginning of a\n\
2563 function, you can increase the range of the search using the `set\n\
2564 heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc));
2571 else if (mips_pc_is_mips16 (start_pc))
2573 unsigned short inst;
2575 /* On MIPS16, any one of the following is likely to be the
2576 start of a function:
2582 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
2583 inst = mips_fetch_instruction (start_pc);
2584 if ((inst & 0xff80) == 0x6480) /* save */
2586 if (start_pc - instlen >= fence)
2588 inst = mips_fetch_instruction (start_pc - instlen);
2589 if ((inst & 0xf800) == 0xf000) /* extend */
2590 start_pc -= instlen;
2594 else if (((inst & 0xf81f) == 0xe809
2595 && (inst & 0x700) != 0x700) /* entry */
2596 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2597 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2598 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
2600 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2601 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2606 else if (mips_about_to_return (start_pc))
2608 /* Skip return and its delay slot. */
2609 start_pc += 2 * MIPS_INSN32_SIZE;
2616 struct mips_objfile_private
2622 /* According to the current ABI, should the type be passed in a
2623 floating-point register (assuming that there is space)? When there
2624 is no FPU, FP are not even considered as possible candidates for
2625 FP registers and, consequently this returns false - forces FP
2626 arguments into integer registers. */
2629 fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode,
2630 struct type *arg_type)
2632 return ((typecode == TYPE_CODE_FLT
2633 || (MIPS_EABI (gdbarch)
2634 && (typecode == TYPE_CODE_STRUCT
2635 || typecode == TYPE_CODE_UNION)
2636 && TYPE_NFIELDS (arg_type) == 1
2637 && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0)))
2639 && MIPS_FPU_TYPE(gdbarch) != MIPS_FPU_NONE);
2642 /* On o32, argument passing in GPRs depends on the alignment of the type being
2643 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2646 mips_type_needs_double_align (struct type *type)
2648 enum type_code typecode = TYPE_CODE (type);
2650 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2652 else if (typecode == TYPE_CODE_STRUCT)
2654 if (TYPE_NFIELDS (type) < 1)
2656 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2658 else if (typecode == TYPE_CODE_UNION)
2662 n = TYPE_NFIELDS (type);
2663 for (i = 0; i < n; i++)
2664 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2671 /* Adjust the address downward (direction of stack growth) so that it
2672 is correctly aligned for a new stack frame. */
2674 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2676 return align_down (addr, 16);
2680 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2681 struct regcache *regcache, CORE_ADDR bp_addr,
2682 int nargs, struct value **args, CORE_ADDR sp,
2683 int struct_return, CORE_ADDR struct_addr)
2689 int stack_offset = 0;
2690 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2691 CORE_ADDR func_addr = find_function_addr (function, NULL);
2692 int regsize = mips_abi_regsize (gdbarch);
2694 /* For shared libraries, "t9" needs to point at the function
2696 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
2698 /* Set the return address register to point to the entry point of
2699 the program, where a breakpoint lies in wait. */
2700 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
2702 /* First ensure that the stack and structure return address (if any)
2703 are properly aligned. The stack has to be at least 64-bit
2704 aligned even on 32-bit machines, because doubles must be 64-bit
2705 aligned. For n32 and n64, stack frames need to be 128-bit
2706 aligned, so we round to this widest known alignment. */
2708 sp = align_down (sp, 16);
2709 struct_addr = align_down (struct_addr, 16);
2711 /* Now make space on the stack for the args. We allocate more
2712 than necessary for EABI, because the first few arguments are
2713 passed in registers, but that's OK. */
2714 for (argnum = 0; argnum < nargs; argnum++)
2715 len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize);
2716 sp -= align_up (len, 16);
2719 fprintf_unfiltered (gdb_stdlog,
2720 "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n",
2721 paddr_nz (sp), (long) align_up (len, 16));
2723 /* Initialize the integer and float register pointers. */
2724 argreg = MIPS_A0_REGNUM;
2725 float_argreg = mips_fpa0_regnum (gdbarch);
2727 /* The struct_return pointer occupies the first parameter-passing reg. */
2731 fprintf_unfiltered (gdb_stdlog,
2732 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2733 argreg, paddr_nz (struct_addr));
2734 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
2737 /* Now load as many as possible of the first arguments into
2738 registers, and push the rest onto the stack. Loop thru args
2739 from first to last. */
2740 for (argnum = 0; argnum < nargs; argnum++)
2742 const gdb_byte *val;
2743 gdb_byte valbuf[MAX_REGISTER_SIZE];
2744 struct value *arg = args[argnum];
2745 struct type *arg_type = check_typedef (value_type (arg));
2746 int len = TYPE_LENGTH (arg_type);
2747 enum type_code typecode = TYPE_CODE (arg_type);
2750 fprintf_unfiltered (gdb_stdlog,
2751 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2752 argnum + 1, len, (int) typecode);
2754 /* The EABI passes structures that do not fit in a register by
2757 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2759 store_unsigned_integer (valbuf, regsize, VALUE_ADDRESS (arg));
2760 typecode = TYPE_CODE_PTR;
2764 fprintf_unfiltered (gdb_stdlog, " push");
2767 val = value_contents (arg);
2769 /* 32-bit ABIs always start floating point arguments in an
2770 even-numbered floating point register. Round the FP register
2771 up before the check to see if there are any FP registers
2772 left. Non MIPS_EABI targets also pass the FP in the integer
2773 registers so also round up normal registers. */
2774 if (regsize < 8 && fp_register_arg_p (gdbarch, typecode, arg_type))
2776 if ((float_argreg & 1))
2780 /* Floating point arguments passed in registers have to be
2781 treated specially. On 32-bit architectures, doubles
2782 are passed in register pairs; the even register gets
2783 the low word, and the odd register gets the high word.
2784 On non-EABI processors, the first two floating point arguments are
2785 also copied to general registers, because MIPS16 functions
2786 don't use float registers for arguments. This duplication of
2787 arguments in general registers can't hurt non-MIPS16 functions
2788 because those registers are normally skipped. */
2789 /* MIPS_EABI squeezes a struct that contains a single floating
2790 point value into an FP register instead of pushing it onto the
2792 if (fp_register_arg_p (gdbarch, typecode, arg_type)
2793 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
2795 /* EABI32 will pass doubles in consecutive registers, even on
2796 64-bit cores. At one time, we used to check the size of
2797 `float_argreg' to determine whether or not to pass doubles
2798 in consecutive registers, but this is not sufficient for
2799 making the ABI determination. */
2800 if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32)
2802 int low_offset = gdbarch_byte_order (gdbarch)
2803 == BFD_ENDIAN_BIG ? 4 : 0;
2804 unsigned long regval;
2806 /* Write the low word of the double to the even register(s). */
2807 regval = extract_unsigned_integer (val + low_offset, 4);
2809 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2810 float_argreg, phex (regval, 4));
2811 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
2813 /* Write the high word of the double to the odd register(s). */
2814 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2816 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2817 float_argreg, phex (regval, 4));
2818 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
2822 /* This is a floating point value that fits entirely
2823 in a single register. */
2824 /* On 32 bit ABI's the float_argreg is further adjusted
2825 above to ensure that it is even register aligned. */
2826 LONGEST regval = extract_unsigned_integer (val, len);
2828 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2829 float_argreg, phex (regval, len));
2830 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
2835 /* Copy the argument to general registers or the stack in
2836 register-sized pieces. Large arguments are split between
2837 registers and stack. */
2838 /* Note: structs whose size is not a multiple of regsize
2839 are treated specially: Irix cc passes
2840 them in registers where gcc sometimes puts them on the
2841 stack. For maximum compatibility, we will put them in
2843 int odd_sized_struct = (len > regsize && len % regsize != 0);
2845 /* Note: Floating-point values that didn't fit into an FP
2846 register are only written to memory. */
2849 /* Remember if the argument was written to the stack. */
2850 int stack_used_p = 0;
2851 int partial_len = (len < regsize ? len : regsize);
2854 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2857 /* Write this portion of the argument to the stack. */
2858 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
2860 || fp_register_arg_p (gdbarch, typecode, arg_type))
2862 /* Should shorter than int integer values be
2863 promoted to int before being stored? */
2864 int longword_offset = 0;
2867 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
2870 && (typecode == TYPE_CODE_INT
2871 || typecode == TYPE_CODE_PTR
2872 || typecode == TYPE_CODE_FLT) && len <= 4)
2873 longword_offset = regsize - len;
2874 else if ((typecode == TYPE_CODE_STRUCT
2875 || typecode == TYPE_CODE_UNION)
2876 && TYPE_LENGTH (arg_type) < regsize)
2877 longword_offset = regsize - len;
2882 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2883 paddr_nz (stack_offset));
2884 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2885 paddr_nz (longword_offset));
2888 addr = sp + stack_offset + longword_offset;
2893 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2895 for (i = 0; i < partial_len; i++)
2897 fprintf_unfiltered (gdb_stdlog, "%02x",
2901 write_memory (addr, val, partial_len);
2904 /* Note!!! This is NOT an else clause. Odd sized
2905 structs may go thru BOTH paths. Floating point
2906 arguments will not. */
2907 /* Write this portion of the argument to a general
2908 purpose register. */
2909 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)
2910 && !fp_register_arg_p (gdbarch, typecode, arg_type))
2913 extract_unsigned_integer (val, partial_len);
2916 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2918 phex (regval, regsize));
2919 regcache_cooked_write_unsigned (regcache, argreg, regval);
2926 /* Compute the the offset into the stack at which we
2927 will copy the next parameter.
2929 In the new EABI (and the NABI32), the stack_offset
2930 only needs to be adjusted when it has been used. */
2933 stack_offset += align_up (partial_len, regsize);
2937 fprintf_unfiltered (gdb_stdlog, "\n");
2940 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
2942 /* Return adjusted stack pointer. */
2946 /* Determine the return value convention being used. */
2948 static enum return_value_convention
2949 mips_eabi_return_value (struct gdbarch *gdbarch, struct type *func_type,
2950 struct type *type, struct regcache *regcache,
2951 gdb_byte *readbuf, const gdb_byte *writebuf)
2953 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2954 int fp_return_type = 0;
2955 int offset, regnum, xfer;
2957 if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch))
2958 return RETURN_VALUE_STRUCT_CONVENTION;
2960 /* Floating point type? */
2961 if (tdep->mips_fpu_type != MIPS_FPU_NONE)
2963 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2965 /* Structs with a single field of float type
2966 are returned in a floating point register. */
2967 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
2968 || TYPE_CODE (type) == TYPE_CODE_UNION)
2969 && TYPE_NFIELDS (type) == 1)
2971 struct type *fieldtype = TYPE_FIELD_TYPE (type, 0);
2973 if (TYPE_CODE (check_typedef (fieldtype)) == TYPE_CODE_FLT)
2980 /* A floating-point value belongs in the least significant part
2983 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
2984 regnum = mips_regnum (gdbarch)->fp0;
2988 /* An integer value goes in V0/V1. */
2990 fprintf_unfiltered (gdb_stderr, "Return scalar in $v0\n");
2991 regnum = MIPS_V0_REGNUM;
2994 offset < TYPE_LENGTH (type);
2995 offset += mips_abi_regsize (gdbarch), regnum++)
2997 xfer = mips_abi_regsize (gdbarch);
2998 if (offset + xfer > TYPE_LENGTH (type))
2999 xfer = TYPE_LENGTH (type) - offset;
3000 mips_xfer_register (gdbarch, regcache,
3001 gdbarch_num_regs (gdbarch) + regnum, xfer,
3002 gdbarch_byte_order (gdbarch), readbuf, writebuf,
3006 return RETURN_VALUE_REGISTER_CONVENTION;
3010 /* N32/N64 ABI stuff. */
3012 /* Search for a naturally aligned double at OFFSET inside a struct
3013 ARG_TYPE. The N32 / N64 ABIs pass these in floating point
3017 mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type,
3022 if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT)
3025 if (MIPS_FPU_TYPE (gdbarch) != MIPS_FPU_DOUBLE)
3028 if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE)
3031 for (i = 0; i < TYPE_NFIELDS (arg_type); i++)
3034 struct type *field_type;
3036 /* We're only looking at normal fields. */
3037 if (TYPE_FIELD_STATIC (arg_type, i)
3038 || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0)
3041 /* If we have gone past the offset, there is no double to pass. */
3042 pos = TYPE_FIELD_BITPOS (arg_type, i) / 8;
3046 field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i));
3048 /* If this field is entirely before the requested offset, go
3049 on to the next one. */
3050 if (pos + TYPE_LENGTH (field_type) <= offset)
3053 /* If this is our special aligned double, we can stop. */
3054 if (TYPE_CODE (field_type) == TYPE_CODE_FLT
3055 && TYPE_LENGTH (field_type) == MIPS64_REGSIZE)
3058 /* This field starts at or before the requested offset, and
3059 overlaps it. If it is a structure, recurse inwards. */
3060 return mips_n32n64_fp_arg_chunk_p (gdbarch, field_type, offset - pos);
3067 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3068 struct regcache *regcache, CORE_ADDR bp_addr,
3069 int nargs, struct value **args, CORE_ADDR sp,
3070 int struct_return, CORE_ADDR struct_addr)
3076 int stack_offset = 0;
3077 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3078 CORE_ADDR func_addr = find_function_addr (function, NULL);
3080 /* For shared libraries, "t9" needs to point at the function
3082 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
3084 /* Set the return address register to point to the entry point of
3085 the program, where a breakpoint lies in wait. */
3086 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
3088 /* First ensure that the stack and structure return address (if any)
3089 are properly aligned. The stack has to be at least 64-bit
3090 aligned even on 32-bit machines, because doubles must be 64-bit
3091 aligned. For n32 and n64, stack frames need to be 128-bit
3092 aligned, so we round to this widest known alignment. */
3094 sp = align_down (sp, 16);
3095 struct_addr = align_down (struct_addr, 16);
3097 /* Now make space on the stack for the args. */
3098 for (argnum = 0; argnum < nargs; argnum++)
3099 len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE);
3100 sp -= align_up (len, 16);
3103 fprintf_unfiltered (gdb_stdlog,
3104 "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n",
3105 paddr_nz (sp), (long) align_up (len, 16));
3107 /* Initialize the integer and float register pointers. */
3108 argreg = MIPS_A0_REGNUM;
3109 float_argreg = mips_fpa0_regnum (gdbarch);
3111 /* The struct_return pointer occupies the first parameter-passing reg. */
3115 fprintf_unfiltered (gdb_stdlog,
3116 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3117 argreg, paddr_nz (struct_addr));
3118 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
3121 /* Now load as many as possible of the first arguments into
3122 registers, and push the rest onto the stack. Loop thru args
3123 from first to last. */
3124 for (argnum = 0; argnum < nargs; argnum++)
3126 const gdb_byte *val;
3127 struct value *arg = args[argnum];
3128 struct type *arg_type = check_typedef (value_type (arg));
3129 int len = TYPE_LENGTH (arg_type);
3130 enum type_code typecode = TYPE_CODE (arg_type);
3133 fprintf_unfiltered (gdb_stdlog,
3134 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3135 argnum + 1, len, (int) typecode);
3137 val = value_contents (arg);
3139 /* A 128-bit long double value requires an even-odd pair of
3140 floating-point registers. */
3142 && fp_register_arg_p (gdbarch, typecode, arg_type)
3143 && (float_argreg & 1))
3149 if (fp_register_arg_p (gdbarch, typecode, arg_type)
3150 && argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3152 /* This is a floating point value that fits entirely
3153 in a single register or a pair of registers. */
3154 int reglen = (len <= MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
3155 LONGEST regval = extract_unsigned_integer (val, reglen);
3157 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3158 float_argreg, phex (regval, reglen));
3159 regcache_cooked_write_unsigned (regcache, float_argreg, regval);
3162 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3163 argreg, phex (regval, reglen));
3164 regcache_cooked_write_unsigned (regcache, argreg, regval);
3169 regval = extract_unsigned_integer (val + reglen, reglen);
3171 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3172 float_argreg, phex (regval, reglen));
3173 regcache_cooked_write_unsigned (regcache, float_argreg, regval);
3176 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3177 argreg, phex (regval, reglen));
3178 regcache_cooked_write_unsigned (regcache, argreg, regval);
3185 /* Copy the argument to general registers or the stack in
3186 register-sized pieces. Large arguments are split between
3187 registers and stack. */
3188 /* For N32/N64, structs, unions, or other composite types are
3189 treated as a sequence of doublewords, and are passed in integer
3190 or floating point registers as though they were simple scalar
3191 parameters to the extent that they fit, with any excess on the
3192 stack packed according to the normal memory layout of the
3194 The caller does not reserve space for the register arguments;
3195 the callee is responsible for reserving it if required. */
3196 /* Note: Floating-point values that didn't fit into an FP
3197 register are only written to memory. */
3200 /* Remember if the argument was written to the stack. */
3201 int stack_used_p = 0;
3202 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
3205 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3208 if (fp_register_arg_p (gdbarch, typecode, arg_type))
3209 gdb_assert (argreg > MIPS_LAST_ARG_REGNUM (gdbarch));
3211 /* Write this portion of the argument to the stack. */
3212 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch))
3214 /* Should shorter than int integer values be
3215 promoted to int before being stored? */
3216 int longword_offset = 0;
3219 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3221 if ((typecode == TYPE_CODE_INT
3222 || typecode == TYPE_CODE_PTR)
3224 longword_offset = MIPS64_REGSIZE - len;
3229 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3230 paddr_nz (stack_offset));
3231 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3232 paddr_nz (longword_offset));
3235 addr = sp + stack_offset + longword_offset;
3240 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3242 for (i = 0; i < partial_len; i++)
3244 fprintf_unfiltered (gdb_stdlog, "%02x",
3248 write_memory (addr, val, partial_len);
3251 /* Note!!! This is NOT an else clause. Odd sized
3252 structs may go thru BOTH paths. */
3253 /* Write this portion of the argument to a general
3254 purpose register. */
3255 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3259 /* Sign extend pointers, 32-bit integers and signed
3260 16-bit and 8-bit integers; everything else is taken
3263 if ((partial_len == 4
3264 && (typecode == TYPE_CODE_PTR
3265 || typecode == TYPE_CODE_INT))
3267 && typecode == TYPE_CODE_INT
3268 && !TYPE_UNSIGNED (arg_type)))
3269 regval = extract_signed_integer (val, partial_len);
3271 regval = extract_unsigned_integer (val, partial_len);
3273 /* A non-floating-point argument being passed in a
3274 general register. If a struct or union, and if
3275 the remaining length is smaller than the register
3276 size, we have to adjust the register value on
3279 It does not seem to be necessary to do the
3280 same for integral types. */
3282 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
3283 && partial_len < MIPS64_REGSIZE
3284 && (typecode == TYPE_CODE_STRUCT
3285 || typecode == TYPE_CODE_UNION))
3286 regval <<= ((MIPS64_REGSIZE - partial_len)
3290 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3292 phex (regval, MIPS64_REGSIZE));
3293 regcache_cooked_write_unsigned (regcache, argreg, regval);
3295 if (mips_n32n64_fp_arg_chunk_p (gdbarch, arg_type,
3296 TYPE_LENGTH (arg_type) - len))
3299 fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s",
3301 phex (regval, MIPS64_REGSIZE));
3302 regcache_cooked_write_unsigned (regcache, float_argreg,
3313 /* Compute the the offset into the stack at which we
3314 will copy the next parameter.
3316 In N32 (N64?), the stack_offset only needs to be
3317 adjusted when it has been used. */
3320 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
3324 fprintf_unfiltered (gdb_stdlog, "\n");
3327 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3329 /* Return adjusted stack pointer. */
3333 static enum return_value_convention
3334 mips_n32n64_return_value (struct gdbarch *gdbarch, struct type *func_type,
3335 struct type *type, struct regcache *regcache,
3336 gdb_byte *readbuf, const gdb_byte *writebuf)
3338 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3340 /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
3342 Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
3343 if needed), as appropriate for the type. Composite results (struct,
3344 union, or array) are returned in $2/$f0 and $3/$f2 according to the
3347 * A struct with only one or two floating point fields is returned in $f0
3348 (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
3351 * Any other struct or union results of at most 128 bits are returned in
3352 $2 (first 64 bits) and $3 (remainder, if necessary).
3354 * Larger composite results are handled by converting the function to a
3355 procedure with an implicit first parameter, which is a pointer to an area
3356 reserved by the caller to receive the result. [The o32-bit ABI requires
3357 that all composite results be handled by conversion to implicit first
3358 parameters. The MIPS/SGI Fortran implementation has always made a
3359 specific exception to return COMPLEX results in the floating point
3362 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
3363 || TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE)
3364 return RETURN_VALUE_STRUCT_CONVENTION;
3365 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3366 && TYPE_LENGTH (type) == 16
3367 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3369 /* A 128-bit floating-point value fills both $f0 and $f2. The
3370 two registers are used in the same as memory order, so the
3371 eight bytes with the lower memory address are in $f0. */
3373 fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n");
3374 mips_xfer_register (gdbarch, regcache,
3375 gdbarch_num_regs (gdbarch)
3376 + mips_regnum (gdbarch)->fp0,
3377 8, gdbarch_byte_order (gdbarch),
3378 readbuf, writebuf, 0);
3379 mips_xfer_register (gdbarch, regcache,
3380 gdbarch_num_regs (gdbarch)
3381 + mips_regnum (gdbarch)->fp0 + 2,
3382 8, gdbarch_byte_order (gdbarch),
3383 readbuf ? readbuf + 8 : readbuf,
3384 writebuf ? writebuf + 8 : writebuf, 0);
3385 return RETURN_VALUE_REGISTER_CONVENTION;
3387 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3388 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3390 /* A single or double floating-point value that fits in FP0. */
3392 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
3393 mips_xfer_register (gdbarch, regcache,
3394 gdbarch_num_regs (gdbarch)
3395 + mips_regnum (gdbarch)->fp0,
3397 gdbarch_byte_order (gdbarch),
3398 readbuf, writebuf, 0);
3399 return RETURN_VALUE_REGISTER_CONVENTION;
3401 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3402 && TYPE_NFIELDS (type) <= 2
3403 && TYPE_NFIELDS (type) >= 1
3404 && ((TYPE_NFIELDS (type) == 1
3405 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
3407 || (TYPE_NFIELDS (type) == 2
3408 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
3410 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1)))
3411 == TYPE_CODE_FLT))))
3413 /* A struct that contains one or two floats. Each value is part
3414 in the least significant part of their floating point
3415 register (or GPR, for soft float). */
3418 for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE
3419 ? mips_regnum (gdbarch)->fp0
3421 field < TYPE_NFIELDS (type); field++, regnum += 2)
3423 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3426 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3428 if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)) == 16)
3430 /* A 16-byte long double field goes in two consecutive
3432 mips_xfer_register (gdbarch, regcache,
3433 gdbarch_num_regs (gdbarch) + regnum,
3435 gdbarch_byte_order (gdbarch),
3436 readbuf, writebuf, offset);
3437 mips_xfer_register (gdbarch, regcache,
3438 gdbarch_num_regs (gdbarch) + regnum + 1,
3440 gdbarch_byte_order (gdbarch),
3441 readbuf, writebuf, offset + 8);
3444 mips_xfer_register (gdbarch, regcache,
3445 gdbarch_num_regs (gdbarch) + regnum,
3446 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
3447 gdbarch_byte_order (gdbarch),
3448 readbuf, writebuf, offset);
3450 return RETURN_VALUE_REGISTER_CONVENTION;
3452 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3453 || TYPE_CODE (type) == TYPE_CODE_UNION)
3455 /* A structure or union. Extract the left justified value,
3456 regardless of the byte order. I.e. DO NOT USE
3460 for (offset = 0, regnum = MIPS_V0_REGNUM;
3461 offset < TYPE_LENGTH (type);
3462 offset += register_size (gdbarch, regnum), regnum++)
3464 int xfer = register_size (gdbarch, regnum);
3465 if (offset + xfer > TYPE_LENGTH (type))
3466 xfer = TYPE_LENGTH (type) - offset;
3468 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3469 offset, xfer, regnum);
3470 mips_xfer_register (gdbarch, regcache,
3471 gdbarch_num_regs (gdbarch) + regnum,
3472 xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf,
3475 return RETURN_VALUE_REGISTER_CONVENTION;
3479 /* A scalar extract each part but least-significant-byte
3483 for (offset = 0, regnum = MIPS_V0_REGNUM;
3484 offset < TYPE_LENGTH (type);
3485 offset += register_size (gdbarch, regnum), regnum++)
3487 int xfer = register_size (gdbarch, regnum);
3488 if (offset + xfer > TYPE_LENGTH (type))
3489 xfer = TYPE_LENGTH (type) - offset;
3491 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3492 offset, xfer, regnum);
3493 mips_xfer_register (gdbarch, regcache,
3494 gdbarch_num_regs (gdbarch) + regnum,
3495 xfer, gdbarch_byte_order (gdbarch),
3496 readbuf, writebuf, offset);
3498 return RETURN_VALUE_REGISTER_CONVENTION;
3502 /* O32 ABI stuff. */
3505 mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3506 struct regcache *regcache, CORE_ADDR bp_addr,
3507 int nargs, struct value **args, CORE_ADDR sp,
3508 int struct_return, CORE_ADDR struct_addr)
3514 int stack_offset = 0;
3515 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3516 CORE_ADDR func_addr = find_function_addr (function, NULL);
3518 /* For shared libraries, "t9" needs to point at the function
3520 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
3522 /* Set the return address register to point to the entry point of
3523 the program, where a breakpoint lies in wait. */
3524 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
3526 /* First ensure that the stack and structure return address (if any)
3527 are properly aligned. The stack has to be at least 64-bit
3528 aligned even on 32-bit machines, because doubles must be 64-bit
3529 aligned. For n32 and n64, stack frames need to be 128-bit
3530 aligned, so we round to this widest known alignment. */
3532 sp = align_down (sp, 16);
3533 struct_addr = align_down (struct_addr, 16);
3535 /* Now make space on the stack for the args. */
3536 for (argnum = 0; argnum < nargs; argnum++)
3538 struct type *arg_type = check_typedef (value_type (args[argnum]));
3539 int arglen = TYPE_LENGTH (arg_type);
3541 /* Align to double-word if necessary. */
3542 if (mips_type_needs_double_align (arg_type))
3543 len = align_up (len, MIPS32_REGSIZE * 2);
3544 /* Allocate space on the stack. */
3545 len += align_up (arglen, MIPS32_REGSIZE);
3547 sp -= align_up (len, 16);
3550 fprintf_unfiltered (gdb_stdlog,
3551 "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n",
3552 paddr_nz (sp), (long) align_up (len, 16));
3554 /* Initialize the integer and float register pointers. */
3555 argreg = MIPS_A0_REGNUM;
3556 float_argreg = mips_fpa0_regnum (gdbarch);
3558 /* The struct_return pointer occupies the first parameter-passing reg. */
3562 fprintf_unfiltered (gdb_stdlog,
3563 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3564 argreg, paddr_nz (struct_addr));
3565 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
3566 stack_offset += MIPS32_REGSIZE;
3569 /* Now load as many as possible of the first arguments into
3570 registers, and push the rest onto the stack. Loop thru args
3571 from first to last. */
3572 for (argnum = 0; argnum < nargs; argnum++)
3574 const gdb_byte *val;
3575 struct value *arg = args[argnum];
3576 struct type *arg_type = check_typedef (value_type (arg));
3577 int len = TYPE_LENGTH (arg_type);
3578 enum type_code typecode = TYPE_CODE (arg_type);
3581 fprintf_unfiltered (gdb_stdlog,
3582 "mips_o32_push_dummy_call: %d len=%d type=%d",
3583 argnum + 1, len, (int) typecode);
3585 val = value_contents (arg);
3587 /* 32-bit ABIs always start floating point arguments in an
3588 even-numbered floating point register. Round the FP register
3589 up before the check to see if there are any FP registers
3590 left. O32/O64 targets also pass the FP in the integer
3591 registers so also round up normal registers. */
3592 if (fp_register_arg_p (gdbarch, typecode, arg_type))
3594 if ((float_argreg & 1))
3598 /* Floating point arguments passed in registers have to be
3599 treated specially. On 32-bit architectures, doubles
3600 are passed in register pairs; the even register gets
3601 the low word, and the odd register gets the high word.
3602 On O32/O64, the first two floating point arguments are
3603 also copied to general registers, because MIPS16 functions
3604 don't use float registers for arguments. This duplication of
3605 arguments in general registers can't hurt non-MIPS16 functions
3606 because those registers are normally skipped. */
3608 if (fp_register_arg_p (gdbarch, typecode, arg_type)
3609 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
3611 if (register_size (gdbarch, float_argreg) < 8 && len == 8)
3613 int low_offset = gdbarch_byte_order (gdbarch)
3614 == BFD_ENDIAN_BIG ? 4 : 0;
3615 unsigned long regval;
3617 /* Write the low word of the double to the even register(s). */
3618 regval = extract_unsigned_integer (val + low_offset, 4);
3620 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3621 float_argreg, phex (regval, 4));
3622 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
3624 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3625 argreg, phex (regval, 4));
3626 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3628 /* Write the high word of the double to the odd register(s). */
3629 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3631 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3632 float_argreg, phex (regval, 4));
3633 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
3636 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3637 argreg, phex (regval, 4));
3638 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3642 /* This is a floating point value that fits entirely
3643 in a single register. */
3644 /* On 32 bit ABI's the float_argreg is further adjusted
3645 above to ensure that it is even register aligned. */
3646 LONGEST regval = extract_unsigned_integer (val, len);
3648 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3649 float_argreg, phex (regval, len));
3650 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
3651 /* Although two FP registers are reserved for each
3652 argument, only one corresponding integer register is
3655 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3656 argreg, phex (regval, len));
3657 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3659 /* Reserve space for the FP register. */
3660 stack_offset += align_up (len, MIPS32_REGSIZE);
3664 /* Copy the argument to general registers or the stack in
3665 register-sized pieces. Large arguments are split between
3666 registers and stack. */
3667 /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
3668 are treated specially: Irix cc passes
3669 them in registers where gcc sometimes puts them on the
3670 stack. For maximum compatibility, we will put them in
3672 int odd_sized_struct = (len > MIPS32_REGSIZE
3673 && len % MIPS32_REGSIZE != 0);
3674 /* Structures should be aligned to eight bytes (even arg registers)
3675 on MIPS_ABI_O32, if their first member has double precision. */
3676 if (mips_type_needs_double_align (arg_type))
3681 stack_offset += MIPS32_REGSIZE;
3686 /* Remember if the argument was written to the stack. */
3687 int stack_used_p = 0;
3688 int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE);
3691 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3694 /* Write this portion of the argument to the stack. */
3695 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
3696 || odd_sized_struct)
3698 /* Should shorter than int integer values be
3699 promoted to int before being stored? */
3700 int longword_offset = 0;
3706 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3707 paddr_nz (stack_offset));
3708 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3709 paddr_nz (longword_offset));
3712 addr = sp + stack_offset + longword_offset;
3717 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3719 for (i = 0; i < partial_len; i++)
3721 fprintf_unfiltered (gdb_stdlog, "%02x",
3725 write_memory (addr, val, partial_len);
3728 /* Note!!! This is NOT an else clause. Odd sized
3729 structs may go thru BOTH paths. */
3730 /* Write this portion of the argument to a general
3731 purpose register. */
3732 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3734 LONGEST regval = extract_signed_integer (val, partial_len);
3735 /* Value may need to be sign extended, because
3736 mips_isa_regsize() != mips_abi_regsize(). */
3738 /* A non-floating-point argument being passed in a
3739 general register. If a struct or union, and if
3740 the remaining length is smaller than the register
3741 size, we have to adjust the register value on
3744 It does not seem to be necessary to do the
3745 same for integral types.
3747 Also don't do this adjustment on O64 binaries.
3749 cagney/2001-07-23: gdb/179: Also, GCC, when
3750 outputting LE O32 with sizeof (struct) <
3751 mips_abi_regsize(), generates a left shift
3752 as part of storing the argument in a register
3753 (the left shift isn't generated when
3754 sizeof (struct) >= mips_abi_regsize()). Since
3755 it is quite possible that this is GCC
3756 contradicting the LE/O32 ABI, GDB has not been
3757 adjusted to accommodate this. Either someone
3758 needs to demonstrate that the LE/O32 ABI
3759 specifies such a left shift OR this new ABI gets
3760 identified as such and GDB gets tweaked
3763 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
3764 && partial_len < MIPS32_REGSIZE
3765 && (typecode == TYPE_CODE_STRUCT
3766 || typecode == TYPE_CODE_UNION))
3767 regval <<= ((MIPS32_REGSIZE - partial_len)
3771 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3773 phex (regval, MIPS32_REGSIZE));
3774 regcache_cooked_write_unsigned (regcache, argreg, regval);
3777 /* Prevent subsequent floating point arguments from
3778 being passed in floating point registers. */
3779 float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1;
3785 /* Compute the the offset into the stack at which we
3786 will copy the next parameter.
3788 In older ABIs, the caller reserved space for
3789 registers that contained arguments. This was loosely
3790 refered to as their "home". Consequently, space is
3791 always allocated. */
3793 stack_offset += align_up (partial_len, MIPS32_REGSIZE);
3797 fprintf_unfiltered (gdb_stdlog, "\n");
3800 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3802 /* Return adjusted stack pointer. */
3806 static enum return_value_convention
3807 mips_o32_return_value (struct gdbarch *gdbarch, struct type *func_type,
3808 struct type *type, struct regcache *regcache,
3809 gdb_byte *readbuf, const gdb_byte *writebuf)
3811 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3813 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3814 || TYPE_CODE (type) == TYPE_CODE_UNION
3815 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
3816 return RETURN_VALUE_STRUCT_CONVENTION;
3817 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3818 && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3820 /* A single-precision floating-point value. It fits in the
3821 least significant part of FP0. */
3823 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
3824 mips_xfer_register (gdbarch, regcache,
3825 gdbarch_num_regs (gdbarch)
3826 + mips_regnum (gdbarch)->fp0,
3828 gdbarch_byte_order (gdbarch),
3829 readbuf, writebuf, 0);
3830 return RETURN_VALUE_REGISTER_CONVENTION;
3832 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3833 && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3835 /* A double-precision floating-point value. The most
3836 significant part goes in FP1, and the least significant in
3839 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
3840 switch (gdbarch_byte_order (gdbarch))
3842 case BFD_ENDIAN_LITTLE:
3843 mips_xfer_register (gdbarch, regcache,
3844 gdbarch_num_regs (gdbarch)
3845 + mips_regnum (gdbarch)->fp0 +
3846 0, 4, gdbarch_byte_order (gdbarch),
3847 readbuf, writebuf, 0);
3848 mips_xfer_register (gdbarch, regcache,
3849 gdbarch_num_regs (gdbarch)
3850 + mips_regnum (gdbarch)->fp0 + 1,
3851 4, gdbarch_byte_order (gdbarch),
3852 readbuf, writebuf, 4);
3854 case BFD_ENDIAN_BIG:
3855 mips_xfer_register (gdbarch, regcache,
3856 gdbarch_num_regs (gdbarch)
3857 + mips_regnum (gdbarch)->fp0 + 1,
3858 4, gdbarch_byte_order (gdbarch),
3859 readbuf, writebuf, 0);
3860 mips_xfer_register (gdbarch, regcache,
3861 gdbarch_num_regs (gdbarch)
3862 + mips_regnum (gdbarch)->fp0 + 0,
3863 4, gdbarch_byte_order (gdbarch),
3864 readbuf, writebuf, 4);
3867 internal_error (__FILE__, __LINE__, _("bad switch"));
3869 return RETURN_VALUE_REGISTER_CONVENTION;
3872 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3873 && TYPE_NFIELDS (type) <= 2
3874 && TYPE_NFIELDS (type) >= 1
3875 && ((TYPE_NFIELDS (type) == 1
3876 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3878 || (TYPE_NFIELDS (type) == 2
3879 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3881 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
3883 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3885 /* A struct that contains one or two floats. Each value is part
3886 in the least significant part of their floating point
3888 gdb_byte reg[MAX_REGISTER_SIZE];
3891 for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
3892 field < TYPE_NFIELDS (type); field++, regnum += 2)
3894 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3897 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3899 mips_xfer_register (gdbarch, regcache,
3900 gdbarch_num_regs (gdbarch) + regnum,
3901 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
3902 gdbarch_byte_order (gdbarch),
3903 readbuf, writebuf, offset);
3905 return RETURN_VALUE_REGISTER_CONVENTION;
3909 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3910 || TYPE_CODE (type) == TYPE_CODE_UNION)
3912 /* A structure or union. Extract the left justified value,
3913 regardless of the byte order. I.e. DO NOT USE
3917 for (offset = 0, regnum = MIPS_V0_REGNUM;
3918 offset < TYPE_LENGTH (type);
3919 offset += register_size (gdbarch, regnum), regnum++)
3921 int xfer = register_size (gdbarch, regnum);
3922 if (offset + xfer > TYPE_LENGTH (type))
3923 xfer = TYPE_LENGTH (type) - offset;
3925 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3926 offset, xfer, regnum);
3927 mips_xfer_register (gdbarch, regcache,
3928 gdbarch_num_regs (gdbarch) + regnum, xfer,
3929 BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
3931 return RETURN_VALUE_REGISTER_CONVENTION;
3936 /* A scalar extract each part but least-significant-byte
3937 justified. o32 thinks registers are 4 byte, regardless of
3941 for (offset = 0, regnum = MIPS_V0_REGNUM;
3942 offset < TYPE_LENGTH (type);
3943 offset += MIPS32_REGSIZE, regnum++)
3945 int xfer = MIPS32_REGSIZE;
3946 if (offset + xfer > TYPE_LENGTH (type))
3947 xfer = TYPE_LENGTH (type) - offset;
3949 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3950 offset, xfer, regnum);
3951 mips_xfer_register (gdbarch, regcache,
3952 gdbarch_num_regs (gdbarch) + regnum, xfer,
3953 gdbarch_byte_order (gdbarch),
3954 readbuf, writebuf, offset);
3956 return RETURN_VALUE_REGISTER_CONVENTION;
3960 /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
3964 mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3965 struct regcache *regcache, CORE_ADDR bp_addr,
3967 struct value **args, CORE_ADDR sp,
3968 int struct_return, CORE_ADDR struct_addr)
3974 int stack_offset = 0;
3975 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3976 CORE_ADDR func_addr = find_function_addr (function, NULL);
3978 /* For shared libraries, "t9" needs to point at the function
3980 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
3982 /* Set the return address register to point to the entry point of
3983 the program, where a breakpoint lies in wait. */
3984 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
3986 /* First ensure that the stack and structure return address (if any)
3987 are properly aligned. The stack has to be at least 64-bit
3988 aligned even on 32-bit machines, because doubles must be 64-bit
3989 aligned. For n32 and n64, stack frames need to be 128-bit
3990 aligned, so we round to this widest known alignment. */
3992 sp = align_down (sp, 16);
3993 struct_addr = align_down (struct_addr, 16);
3995 /* Now make space on the stack for the args. */
3996 for (argnum = 0; argnum < nargs; argnum++)
3998 struct type *arg_type = check_typedef (value_type (args[argnum]));
3999 int arglen = TYPE_LENGTH (arg_type);
4001 /* Allocate space on the stack. */
4002 len += align_up (arglen, MIPS64_REGSIZE);
4004 sp -= align_up (len, 16);
4007 fprintf_unfiltered (gdb_stdlog,
4008 "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n",
4009 paddr_nz (sp), (long) align_up (len, 16));
4011 /* Initialize the integer and float register pointers. */
4012 argreg = MIPS_A0_REGNUM;
4013 float_argreg = mips_fpa0_regnum (gdbarch);
4015 /* The struct_return pointer occupies the first parameter-passing reg. */
4019 fprintf_unfiltered (gdb_stdlog,
4020 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
4021 argreg, paddr_nz (struct_addr));
4022 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
4023 stack_offset += MIPS64_REGSIZE;
4026 /* Now load as many as possible of the first arguments into
4027 registers, and push the rest onto the stack. Loop thru args
4028 from first to last. */
4029 for (argnum = 0; argnum < nargs; argnum++)
4031 const gdb_byte *val;
4032 struct value *arg = args[argnum];
4033 struct type *arg_type = check_typedef (value_type (arg));
4034 int len = TYPE_LENGTH (arg_type);
4035 enum type_code typecode = TYPE_CODE (arg_type);
4038 fprintf_unfiltered (gdb_stdlog,
4039 "mips_o64_push_dummy_call: %d len=%d type=%d",
4040 argnum + 1, len, (int) typecode);
4042 val = value_contents (arg);
4044 /* Floating point arguments passed in registers have to be
4045 treated specially. On 32-bit architectures, doubles
4046 are passed in register pairs; the even register gets
4047 the low word, and the odd register gets the high word.
4048 On O32/O64, the first two floating point arguments are
4049 also copied to general registers, because MIPS16 functions
4050 don't use float registers for arguments. This duplication of
4051 arguments in general registers can't hurt non-MIPS16 functions
4052 because those registers are normally skipped. */
4054 if (fp_register_arg_p (gdbarch, typecode, arg_type)
4055 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
4057 LONGEST regval = extract_unsigned_integer (val, len);
4059 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4060 float_argreg, phex (regval, len));
4061 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
4063 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4064 argreg, phex (regval, len));
4065 regcache_cooked_write_unsigned (regcache, argreg, regval);
4067 /* Reserve space for the FP register. */
4068 stack_offset += align_up (len, MIPS64_REGSIZE);
4072 /* Copy the argument to general registers or the stack in
4073 register-sized pieces. Large arguments are split between
4074 registers and stack. */
4075 /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
4076 are treated specially: Irix cc passes them in registers
4077 where gcc sometimes puts them on the stack. For maximum
4078 compatibility, we will put them in both places. */
4079 int odd_sized_struct = (len > MIPS64_REGSIZE
4080 && len % MIPS64_REGSIZE != 0);
4083 /* Remember if the argument was written to the stack. */
4084 int stack_used_p = 0;
4085 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
4088 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
4091 /* Write this portion of the argument to the stack. */
4092 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
4093 || odd_sized_struct)
4095 /* Should shorter than int integer values be
4096 promoted to int before being stored? */
4097 int longword_offset = 0;
4100 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4102 if ((typecode == TYPE_CODE_INT
4103 || typecode == TYPE_CODE_PTR
4104 || typecode == TYPE_CODE_FLT)
4106 longword_offset = MIPS64_REGSIZE - len;
4111 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
4112 paddr_nz (stack_offset));
4113 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
4114 paddr_nz (longword_offset));
4117 addr = sp + stack_offset + longword_offset;
4122 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
4124 for (i = 0; i < partial_len; i++)
4126 fprintf_unfiltered (gdb_stdlog, "%02x",
4130 write_memory (addr, val, partial_len);
4133 /* Note!!! This is NOT an else clause. Odd sized
4134 structs may go thru BOTH paths. */
4135 /* Write this portion of the argument to a general
4136 purpose register. */
4137 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
4139 LONGEST regval = extract_signed_integer (val, partial_len);
4140 /* Value may need to be sign extended, because
4141 mips_isa_regsize() != mips_abi_regsize(). */
4143 /* A non-floating-point argument being passed in a
4144 general register. If a struct or union, and if
4145 the remaining length is smaller than the register
4146 size, we have to adjust the register value on
4149 It does not seem to be necessary to do the
4150 same for integral types. */
4152 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
4153 && partial_len < MIPS64_REGSIZE
4154 && (typecode == TYPE_CODE_STRUCT
4155 || typecode == TYPE_CODE_UNION))
4156 regval <<= ((MIPS64_REGSIZE - partial_len)
4160 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4162 phex (regval, MIPS64_REGSIZE));
4163 regcache_cooked_write_unsigned (regcache, argreg, regval);
4166 /* Prevent subsequent floating point arguments from
4167 being passed in floating point registers. */
4168 float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1;
4174 /* Compute the the offset into the stack at which we
4175 will copy the next parameter.
4177 In older ABIs, the caller reserved space for
4178 registers that contained arguments. This was loosely
4179 refered to as their "home". Consequently, space is
4180 always allocated. */
4182 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
4186 fprintf_unfiltered (gdb_stdlog, "\n");
4189 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
4191 /* Return adjusted stack pointer. */
4195 static enum return_value_convention
4196 mips_o64_return_value (struct gdbarch *gdbarch, struct type *func_type,
4197 struct type *type, struct regcache *regcache,
4198 gdb_byte *readbuf, const gdb_byte *writebuf)
4200 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4202 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4203 || TYPE_CODE (type) == TYPE_CODE_UNION
4204 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
4205 return RETURN_VALUE_STRUCT_CONVENTION;
4206 else if (fp_register_arg_p (gdbarch, TYPE_CODE (type), type))
4208 /* A floating-point value. It fits in the least significant
4211 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4212 mips_xfer_register (gdbarch, regcache,
4213 gdbarch_num_regs (gdbarch)
4214 + mips_regnum (gdbarch)->fp0,
4216 gdbarch_byte_order (gdbarch),
4217 readbuf, writebuf, 0);
4218 return RETURN_VALUE_REGISTER_CONVENTION;
4222 /* A scalar extract each part but least-significant-byte
4226 for (offset = 0, regnum = MIPS_V0_REGNUM;
4227 offset < TYPE_LENGTH (type);
4228 offset += MIPS64_REGSIZE, regnum++)
4230 int xfer = MIPS64_REGSIZE;
4231 if (offset + xfer > TYPE_LENGTH (type))
4232 xfer = TYPE_LENGTH (type) - offset;
4234 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4235 offset, xfer, regnum);
4236 mips_xfer_register (gdbarch, regcache,
4237 gdbarch_num_regs (gdbarch) + regnum,
4238 xfer, gdbarch_byte_order (gdbarch),
4239 readbuf, writebuf, offset);
4241 return RETURN_VALUE_REGISTER_CONVENTION;
4245 /* Floating point register management.
4247 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4248 64bit operations, these early MIPS cpus treat fp register pairs
4249 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4250 registers and offer a compatibility mode that emulates the MIPS2 fp
4251 model. When operating in MIPS2 fp compat mode, later cpu's split
4252 double precision floats into two 32-bit chunks and store them in
4253 consecutive fp regs. To display 64-bit floats stored in this
4254 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4255 Throw in user-configurable endianness and you have a real mess.
4257 The way this works is:
4258 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4259 double-precision value will be split across two logical registers.
4260 The lower-numbered logical register will hold the low-order bits,
4261 regardless of the processor's endianness.
4262 - If we are on a 64-bit processor, and we are looking for a
4263 single-precision value, it will be in the low ordered bits
4264 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4265 save slot in memory.
4266 - If we are in 64-bit mode, everything is straightforward.
4268 Note that this code only deals with "live" registers at the top of the
4269 stack. We will attempt to deal with saved registers later, when
4270 the raw/cooked register interface is in place. (We need a general
4271 interface that can deal with dynamic saved register sizes -- fp
4272 regs could be 32 bits wide in one frame and 64 on the frame above
4275 static struct type *
4276 mips_float_register_type (void)
4278 return builtin_type_ieee_single;
4281 static struct type *
4282 mips_double_register_type (void)
4284 return builtin_type_ieee_double;
4287 /* Copy a 32-bit single-precision value from the current frame
4288 into rare_buffer. */
4291 mips_read_fp_register_single (struct frame_info *frame, int regno,
4292 gdb_byte *rare_buffer)
4294 struct gdbarch *gdbarch = get_frame_arch (frame);
4295 int raw_size = register_size (gdbarch, regno);
4296 gdb_byte *raw_buffer = alloca (raw_size);
4298 if (!frame_register_read (frame, regno, raw_buffer))
4299 error (_("can't read register %d (%s)"),
4300 regno, gdbarch_register_name (gdbarch, regno));
4303 /* We have a 64-bit value for this register. Find the low-order
4307 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4312 memcpy (rare_buffer, raw_buffer + offset, 4);
4316 memcpy (rare_buffer, raw_buffer, 4);
4320 /* Copy a 64-bit double-precision value from the current frame into
4321 rare_buffer. This may include getting half of it from the next
4325 mips_read_fp_register_double (struct frame_info *frame, int regno,
4326 gdb_byte *rare_buffer)
4328 struct gdbarch *gdbarch = get_frame_arch (frame);
4329 int raw_size = register_size (gdbarch, regno);
4331 if (raw_size == 8 && !mips2_fp_compat (frame))
4333 /* We have a 64-bit value for this register, and we should use
4335 if (!frame_register_read (frame, regno, rare_buffer))
4336 error (_("can't read register %d (%s)"),
4337 regno, gdbarch_register_name (gdbarch, regno));
4341 int rawnum = regno % gdbarch_num_regs (gdbarch);
4343 if ((rawnum - mips_regnum (gdbarch)->fp0) & 1)
4344 internal_error (__FILE__, __LINE__,
4345 _("mips_read_fp_register_double: bad access to "
4346 "odd-numbered FP register"));
4348 /* mips_read_fp_register_single will find the correct 32 bits from
4350 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4352 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4353 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4357 mips_read_fp_register_single (frame, regno, rare_buffer);
4358 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4364 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4366 { /* do values for FP (float) regs */
4367 struct gdbarch *gdbarch = get_frame_arch (frame);
4368 gdb_byte *raw_buffer;
4369 double doub, flt1; /* doubles extracted from raw hex data */
4372 raw_buffer = alloca (2 * register_size (gdbarch, mips_regnum (gdbarch)->fp0));
4374 fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum));
4375 fprintf_filtered (file, "%*s",
4376 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)),
4379 if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame))
4381 /* 4-byte registers: Print hex and floating. Also print even
4382 numbered registers as doubles. */
4383 mips_read_fp_register_single (frame, regnum, raw_buffer);
4384 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4386 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
4389 fprintf_filtered (file, " flt: ");
4391 fprintf_filtered (file, " <invalid float> ");
4393 fprintf_filtered (file, "%-17.9g", flt1);
4395 if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0)
4397 mips_read_fp_register_double (frame, regnum, raw_buffer);
4398 doub = unpack_double (mips_double_register_type (), raw_buffer,
4401 fprintf_filtered (file, " dbl: ");
4403 fprintf_filtered (file, "<invalid double>");
4405 fprintf_filtered (file, "%-24.17g", doub);
4410 /* Eight byte registers: print each one as hex, float and double. */
4411 mips_read_fp_register_single (frame, regnum, raw_buffer);
4412 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4414 mips_read_fp_register_double (frame, regnum, raw_buffer);
4415 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4418 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4421 fprintf_filtered (file, " flt: ");
4423 fprintf_filtered (file, "<invalid float>");
4425 fprintf_filtered (file, "%-17.9g", flt1);
4427 fprintf_filtered (file, " dbl: ");
4429 fprintf_filtered (file, "<invalid double>");
4431 fprintf_filtered (file, "%-24.17g", doub);
4436 mips_print_register (struct ui_file *file, struct frame_info *frame,
4439 struct gdbarch *gdbarch = get_frame_arch (frame);
4440 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
4443 if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4445 mips_print_fp_register (file, frame, regnum);
4449 /* Get the data in raw format. */
4450 if (!frame_register_read (frame, regnum, raw_buffer))
4452 fprintf_filtered (file, "%s: [Invalid]",
4453 gdbarch_register_name (gdbarch, regnum));
4457 fputs_filtered (gdbarch_register_name (gdbarch, regnum), file);
4459 /* The problem with printing numeric register names (r26, etc.) is that
4460 the user can't use them on input. Probably the best solution is to
4461 fix it so that either the numeric or the funky (a2, etc.) names
4462 are accepted on input. */
4463 if (regnum < MIPS_NUMREGS)
4464 fprintf_filtered (file, "(r%d): ", regnum);
4466 fprintf_filtered (file, ": ");
4468 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4470 register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
4474 print_scalar_formatted (raw_buffer + offset,
4475 register_type (gdbarch, regnum), 'x', 0,
4479 /* Replacement for generic do_registers_info.
4480 Print regs in pretty columns. */
4483 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4486 fprintf_filtered (file, " ");
4487 mips_print_fp_register (file, frame, regnum);
4488 fprintf_filtered (file, "\n");
4493 /* Print a row's worth of GP (int) registers, with name labels above */
4496 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4499 struct gdbarch *gdbarch = get_frame_arch (frame);
4500 /* do values for GP (int) regs */
4501 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
4502 int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */
4506 /* For GP registers, we print a separate row of names above the vals */
4507 for (col = 0, regnum = start_regnum;
4508 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4509 + gdbarch_num_pseudo_regs (gdbarch);
4512 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
4513 continue; /* unused register */
4514 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4516 break; /* end the row: reached FP register */
4517 /* Large registers are handled separately. */
4518 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
4521 break; /* End the row before this register. */
4523 /* Print this register on a row by itself. */
4524 mips_print_register (file, frame, regnum);
4525 fprintf_filtered (file, "\n");
4529 fprintf_filtered (file, " ");
4530 fprintf_filtered (file,
4531 mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s",
4532 gdbarch_register_name (gdbarch, regnum));
4539 /* print the R0 to R31 names */
4540 if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS)
4541 fprintf_filtered (file, "\n R%-4d",
4542 start_regnum % gdbarch_num_regs (gdbarch));
4544 fprintf_filtered (file, "\n ");
4546 /* now print the values in hex, 4 or 8 to the row */
4547 for (col = 0, regnum = start_regnum;
4548 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4549 + gdbarch_num_pseudo_regs (gdbarch);
4552 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
4553 continue; /* unused register */
4554 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4556 break; /* end row: reached FP register */
4557 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
4558 break; /* End row: large register. */
4560 /* OK: get the data in raw format. */
4561 if (!frame_register_read (frame, regnum, raw_buffer))
4562 error (_("can't read register %d (%s)"),
4563 regnum, gdbarch_register_name (gdbarch, regnum));
4564 /* pad small registers */
4566 byte < (mips_abi_regsize (gdbarch)
4567 - register_size (gdbarch, regnum)); byte++)
4568 printf_filtered (" ");
4569 /* Now print the register value in hex, endian order. */
4570 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4572 register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
4573 byte < register_size (gdbarch, regnum); byte++)
4574 fprintf_filtered (file, "%02x", raw_buffer[byte]);
4576 for (byte = register_size (gdbarch, regnum) - 1;
4578 fprintf_filtered (file, "%02x", raw_buffer[byte]);
4579 fprintf_filtered (file, " ");
4582 if (col > 0) /* ie. if we actually printed anything... */
4583 fprintf_filtered (file, "\n");
4588 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4591 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4592 struct frame_info *frame, int regnum, int all)
4594 if (regnum != -1) /* do one specified register */
4596 gdb_assert (regnum >= gdbarch_num_regs (gdbarch));
4597 if (*(gdbarch_register_name (gdbarch, regnum)) == '\0')
4598 error (_("Not a valid register for the current processor type"));
4600 mips_print_register (file, frame, regnum);
4601 fprintf_filtered (file, "\n");
4604 /* do all (or most) registers */
4606 regnum = gdbarch_num_regs (gdbarch);
4607 while (regnum < gdbarch_num_regs (gdbarch)
4608 + gdbarch_num_pseudo_regs (gdbarch))
4610 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4613 if (all) /* true for "INFO ALL-REGISTERS" command */
4614 regnum = print_fp_register_row (file, frame, regnum);
4616 regnum += MIPS_NUMREGS; /* skip floating point regs */
4619 regnum = print_gp_register_row (file, frame, regnum);
4624 /* Is this a branch with a delay slot? */
4627 is_delayed (unsigned long insn)
4630 for (i = 0; i < NUMOPCODES; ++i)
4631 if (mips_opcodes[i].pinfo != INSN_MACRO
4632 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4634 return (i < NUMOPCODES
4635 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4636 | INSN_COND_BRANCH_DELAY
4637 | INSN_COND_BRANCH_LIKELY)));
4641 mips_single_step_through_delay (struct gdbarch *gdbarch,
4642 struct frame_info *frame)
4644 CORE_ADDR pc = get_frame_pc (frame);
4645 gdb_byte buf[MIPS_INSN32_SIZE];
4647 /* There is no branch delay slot on MIPS16. */
4648 if (mips_pc_is_mips16 (pc))
4651 if (!breakpoint_here_p (pc + 4))
4654 if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf))
4655 /* If error reading memory, guess that it is not a delayed
4658 return is_delayed (extract_unsigned_integer (buf, sizeof buf));
4661 /* To skip prologues, I use this predicate. Returns either PC itself
4662 if the code at PC does not look like a function prologue; otherwise
4663 returns an address that (if we're lucky) follows the prologue. If
4664 LENIENT, then we must skip everything which is involved in setting
4665 up the frame (it's OK to skip more, just so long as we don't skip
4666 anything which might clobber the registers which are being saved.
4667 We must skip more in the case where part of the prologue is in the
4668 delay slot of a non-prologue instruction). */
4671 mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
4674 CORE_ADDR func_addr;
4676 /* See if we can determine the end of the prologue via the symbol table.
4677 If so, then return either PC, or the PC after the prologue, whichever
4679 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
4681 CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr);
4682 if (post_prologue_pc != 0)
4683 return max (pc, post_prologue_pc);
4686 /* Can't determine prologue from the symbol table, need to examine
4689 /* Find an upper limit on the function prologue using the debug
4690 information. If the debug information could not be used to provide
4691 that bound, then use an arbitrary large number as the upper bound. */
4692 limit_pc = skip_prologue_using_sal (pc);
4694 limit_pc = pc + 100; /* Magic. */
4696 if (mips_pc_is_mips16 (pc))
4697 return mips16_scan_prologue (pc, limit_pc, NULL, NULL);
4699 return mips32_scan_prologue (pc, limit_pc, NULL, NULL);
4702 /* Check whether the PC is in a function epilogue (32-bit version).
4703 This is a helper function for mips_in_function_epilogue_p. */
4705 mips32_in_function_epilogue_p (CORE_ADDR pc)
4707 CORE_ADDR func_addr = 0, func_end = 0;
4709 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4711 /* The MIPS epilogue is max. 12 bytes long. */
4712 CORE_ADDR addr = func_end - 12;
4714 if (addr < func_addr + 4)
4715 addr = func_addr + 4;
4719 for (; pc < func_end; pc += MIPS_INSN32_SIZE)
4721 unsigned long high_word;
4724 inst = mips_fetch_instruction (pc);
4725 high_word = (inst >> 16) & 0xffff;
4727 if (high_word != 0x27bd /* addiu $sp,$sp,offset */
4728 && high_word != 0x67bd /* daddiu $sp,$sp,offset */
4729 && inst != 0x03e00008 /* jr $ra */
4730 && inst != 0x00000000) /* nop */
4740 /* Check whether the PC is in a function epilogue (16-bit version).
4741 This is a helper function for mips_in_function_epilogue_p. */
4743 mips16_in_function_epilogue_p (CORE_ADDR pc)
4745 CORE_ADDR func_addr = 0, func_end = 0;
4747 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4749 /* The MIPS epilogue is max. 12 bytes long. */
4750 CORE_ADDR addr = func_end - 12;
4752 if (addr < func_addr + 4)
4753 addr = func_addr + 4;
4757 for (; pc < func_end; pc += MIPS_INSN16_SIZE)
4759 unsigned short inst;
4761 inst = mips_fetch_instruction (pc);
4763 if ((inst & 0xf800) == 0xf000) /* extend */
4766 if (inst != 0x6300 /* addiu $sp,offset */
4767 && inst != 0xfb00 /* daddiu $sp,$sp,offset */
4768 && inst != 0xe820 /* jr $ra */
4769 && inst != 0xe8a0 /* jrc $ra */
4770 && inst != 0x6500) /* nop */
4780 /* The epilogue is defined here as the area at the end of a function,
4781 after an instruction which destroys the function's stack frame. */
4783 mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
4785 if (mips_pc_is_mips16 (pc))
4786 return mips16_in_function_epilogue_p (pc);
4788 return mips32_in_function_epilogue_p (pc);
4791 /* Root of all "set mips "/"show mips " commands. This will eventually be
4792 used for all MIPS-specific commands. */
4795 show_mips_command (char *args, int from_tty)
4797 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4801 set_mips_command (char *args, int from_tty)
4804 ("\"set mips\" must be followed by an appropriate subcommand.\n");
4805 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4808 /* Commands to show/set the MIPS FPU type. */
4811 show_mipsfpu_command (char *args, int from_tty)
4815 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
4818 ("The MIPS floating-point coprocessor is unknown "
4819 "because the current architecture is not MIPS.\n");
4823 switch (MIPS_FPU_TYPE (target_gdbarch))
4825 case MIPS_FPU_SINGLE:
4826 fpu = "single-precision";
4828 case MIPS_FPU_DOUBLE:
4829 fpu = "double-precision";
4832 fpu = "absent (none)";
4835 internal_error (__FILE__, __LINE__, _("bad switch"));
4837 if (mips_fpu_type_auto)
4839 ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4843 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu);
4848 set_mipsfpu_command (char *args, int from_tty)
4851 ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
4852 show_mipsfpu_command (args, from_tty);
4856 set_mipsfpu_single_command (char *args, int from_tty)
4858 struct gdbarch_info info;
4859 gdbarch_info_init (&info);
4860 mips_fpu_type = MIPS_FPU_SINGLE;
4861 mips_fpu_type_auto = 0;
4862 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4863 instead of relying on globals. Doing that would let generic code
4864 handle the search for this specific architecture. */
4865 if (!gdbarch_update_p (info))
4866 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
4870 set_mipsfpu_double_command (char *args, int from_tty)
4872 struct gdbarch_info info;
4873 gdbarch_info_init (&info);
4874 mips_fpu_type = MIPS_FPU_DOUBLE;
4875 mips_fpu_type_auto = 0;
4876 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4877 instead of relying on globals. Doing that would let generic code
4878 handle the search for this specific architecture. */
4879 if (!gdbarch_update_p (info))
4880 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
4884 set_mipsfpu_none_command (char *args, int from_tty)
4886 struct gdbarch_info info;
4887 gdbarch_info_init (&info);
4888 mips_fpu_type = MIPS_FPU_NONE;
4889 mips_fpu_type_auto = 0;
4890 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4891 instead of relying on globals. Doing that would let generic code
4892 handle the search for this specific architecture. */
4893 if (!gdbarch_update_p (info))
4894 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
4898 set_mipsfpu_auto_command (char *args, int from_tty)
4900 mips_fpu_type_auto = 1;
4903 /* Attempt to identify the particular processor model by reading the
4904 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
4905 the relevant processor still exists (it dates back to '94) and
4906 secondly this is not the way to do this. The processor type should
4907 be set by forcing an architecture change. */
4910 deprecated_mips_set_processor_regs_hack (void)
4912 struct regcache *regcache = get_current_regcache ();
4913 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4914 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4917 regcache_cooked_read_unsigned (regcache, MIPS_PRID_REGNUM, &prid);
4918 if ((prid & ~0xf) == 0x700)
4919 tdep->mips_processor_reg_names = mips_r3041_reg_names;
4922 /* Just like reinit_frame_cache, but with the right arguments to be
4923 callable as an sfunc. */
4926 reinit_frame_cache_sfunc (char *args, int from_tty,
4927 struct cmd_list_element *c)
4929 reinit_frame_cache ();
4933 gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
4935 /* FIXME: cagney/2003-06-26: Is this even necessary? The
4936 disassembler needs to be able to locally determine the ISA, and
4937 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
4939 if (mips_pc_is_mips16 (memaddr))
4940 info->mach = bfd_mach_mips16;
4942 /* Round down the instruction address to the appropriate boundary. */
4943 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
4945 /* Set the disassembler options. */
4946 if (!info->disassembler_options)
4947 /* This string is not recognized explicitly by the disassembler,
4948 but it tells the disassembler to not try to guess the ABI from
4949 the bfd elf headers, such that, if the user overrides the ABI
4950 of a program linked as NewABI, the disassembly will follow the
4951 register naming conventions specified by the user. */
4952 info->disassembler_options = "gpr-names=32";
4954 /* Call the appropriate disassembler based on the target endian-ness. */
4955 if (info->endian == BFD_ENDIAN_BIG)
4956 return print_insn_big_mips (memaddr, info);
4958 return print_insn_little_mips (memaddr, info);
4962 gdb_print_insn_mips_n32 (bfd_vma memaddr, struct disassemble_info *info)
4964 /* Set up the disassembler info, so that we get the right
4965 register names from libopcodes. */
4966 info->disassembler_options = "gpr-names=n32";
4967 info->flavour = bfd_target_elf_flavour;
4969 return gdb_print_insn_mips (memaddr, info);
4973 gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
4975 /* Set up the disassembler info, so that we get the right
4976 register names from libopcodes. */
4977 info->disassembler_options = "gpr-names=64";
4978 info->flavour = bfd_target_elf_flavour;
4980 return gdb_print_insn_mips (memaddr, info);
4983 /* This function implements gdbarch_breakpoint_from_pc. It uses the program
4984 counter value to determine whether a 16- or 32-bit breakpoint should be used.
4985 It returns a pointer to a string of bytes that encode a breakpoint
4986 instruction, stores the length of the string to *lenptr, and adjusts pc (if
4987 necessary) to point to the actual memory location where the breakpoint
4988 should be inserted. */
4990 static const gdb_byte *
4991 mips_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
4993 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4995 if (mips_pc_is_mips16 (*pcptr))
4997 static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
4998 *pcptr = unmake_mips16_addr (*pcptr);
4999 *lenptr = sizeof (mips16_big_breakpoint);
5000 return mips16_big_breakpoint;
5004 /* The IDT board uses an unusual breakpoint value, and
5005 sometimes gets confused when it sees the usual MIPS
5006 breakpoint instruction. */
5007 static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
5008 static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
5009 static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
5011 *lenptr = sizeof (big_breakpoint);
5013 if (strcmp (target_shortname, "mips") == 0)
5014 return idt_big_breakpoint;
5015 else if (strcmp (target_shortname, "ddb") == 0
5016 || strcmp (target_shortname, "pmon") == 0
5017 || strcmp (target_shortname, "lsi") == 0)
5018 return pmon_big_breakpoint;
5020 return big_breakpoint;
5025 if (mips_pc_is_mips16 (*pcptr))
5027 static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
5028 *pcptr = unmake_mips16_addr (*pcptr);
5029 *lenptr = sizeof (mips16_little_breakpoint);
5030 return mips16_little_breakpoint;
5034 static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
5035 static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
5036 static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
5038 *lenptr = sizeof (little_breakpoint);
5040 if (strcmp (target_shortname, "mips") == 0)
5041 return idt_little_breakpoint;
5042 else if (strcmp (target_shortname, "ddb") == 0
5043 || strcmp (target_shortname, "pmon") == 0
5044 || strcmp (target_shortname, "lsi") == 0)
5045 return pmon_little_breakpoint;
5047 return little_breakpoint;
5052 /* If PC is in a mips16 call or return stub, return the address of the target
5053 PC, which is either the callee or the caller. There are several
5054 cases which must be handled:
5056 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5057 target PC is in $31 ($ra).
5058 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5059 and the target PC is in $2.
5060 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5061 before the jal instruction, this is effectively a call stub
5062 and the the target PC is in $2. Otherwise this is effectively
5063 a return stub and the target PC is in $18.
5065 See the source code for the stubs in gcc/config/mips/mips16.S for
5069 mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5072 CORE_ADDR start_addr;
5074 /* Find the starting address and name of the function containing the PC. */
5075 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5078 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5079 target PC is in $31 ($ra). */
5080 if (strcmp (name, "__mips16_ret_sf") == 0
5081 || strcmp (name, "__mips16_ret_df") == 0)
5082 return get_frame_register_signed (frame, MIPS_RA_REGNUM);
5084 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5086 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5087 and the target PC is in $2. */
5088 if (name[19] >= '0' && name[19] <= '9')
5089 return get_frame_register_signed (frame, 2);
5091 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5092 before the jal instruction, this is effectively a call stub
5093 and the the target PC is in $2. Otherwise this is effectively
5094 a return stub and the target PC is in $18. */
5095 else if (name[19] == 's' || name[19] == 'd')
5097 if (pc == start_addr)
5099 /* Check if the target of the stub is a compiler-generated
5100 stub. Such a stub for a function bar might have a name
5101 like __fn_stub_bar, and might look like this:
5106 la $1,bar (becomes a lui/addiu pair)
5108 So scan down to the lui/addi and extract the target
5109 address from those two instructions. */
5111 CORE_ADDR target_pc = get_frame_register_signed (frame, 2);
5115 /* See if the name of the target function is __fn_stub_*. */
5116 if (find_pc_partial_function (target_pc, &name, NULL, NULL) ==
5119 if (strncmp (name, "__fn_stub_", 10) != 0
5120 && strcmp (name, "etext") != 0
5121 && strcmp (name, "_etext") != 0)
5124 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5125 The limit on the search is arbitrarily set to 20
5126 instructions. FIXME. */
5127 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE)
5129 inst = mips_fetch_instruction (target_pc);
5130 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5131 pc = (inst << 16) & 0xffff0000; /* high word */
5132 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5133 return pc | (inst & 0xffff); /* low word */
5136 /* Couldn't find the lui/addui pair, so return stub address. */
5140 /* This is the 'return' part of a call stub. The return
5141 address is in $r18. */
5142 return get_frame_register_signed (frame, 18);
5145 return 0; /* not a stub */
5148 /* If the current PC is the start of a non-PIC-to-PIC stub, return the
5149 PC of the stub target. The stub just loads $t9 and jumps to it,
5150 so that $t9 has the correct value at function entry. */
5153 mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5155 struct minimal_symbol *msym;
5157 gdb_byte stub_code[16];
5158 int32_t stub_words[4];
5160 /* The stub for foo is named ".pic.foo", and is either two
5161 instructions inserted before foo or a three instruction sequence
5162 which jumps to foo. */
5163 msym = lookup_minimal_symbol_by_pc (pc);
5165 || SYMBOL_VALUE_ADDRESS (msym) != pc
5166 || SYMBOL_LINKAGE_NAME (msym) == NULL
5167 || strncmp (SYMBOL_LINKAGE_NAME (msym), ".pic.", 5) != 0)
5170 /* A two-instruction header. */
5171 if (MSYMBOL_SIZE (msym) == 8)
5174 /* A three-instruction (plus delay slot) trampoline. */
5175 if (MSYMBOL_SIZE (msym) == 16)
5177 if (target_read_memory (pc, stub_code, 16) != 0)
5179 for (i = 0; i < 4; i++)
5180 stub_words[i] = extract_unsigned_integer (stub_code + i * 4, 4);
5182 /* A stub contains these instructions:
5185 addiu t9, t9, %lo(target)
5188 This works even for N64, since stubs are only generated with
5190 if ((stub_words[0] & 0xffff0000U) == 0x3c190000
5191 && (stub_words[1] & 0xfc000000U) == 0x08000000
5192 && (stub_words[2] & 0xffff0000U) == 0x27390000
5193 && stub_words[3] == 0x00000000)
5194 return (((stub_words[0] & 0x0000ffff) << 16)
5195 + (stub_words[2] & 0x0000ffff));
5198 /* Not a recognized stub. */
5203 mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5205 CORE_ADDR target_pc;
5207 target_pc = mips_skip_mips16_trampoline_code (frame, pc);
5211 target_pc = find_solib_trampoline_target (frame, pc);
5215 target_pc = mips_skip_pic_trampoline_code (frame, pc);
5222 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5223 [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5226 mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
5229 if (num >= 0 && num < 32)
5231 else if (num >= 38 && num < 70)
5232 regnum = num + mips_regnum (gdbarch)->fp0 - 38;
5234 regnum = mips_regnum (gdbarch)->hi;
5236 regnum = mips_regnum (gdbarch)->lo;
5238 /* This will hopefully (eventually) provoke a warning. Should
5239 we be calling complaint() here? */
5240 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5241 return gdbarch_num_regs (gdbarch) + regnum;
5245 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5246 gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5249 mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num)
5252 if (num >= 0 && num < 32)
5254 else if (num >= 32 && num < 64)
5255 regnum = num + mips_regnum (gdbarch)->fp0 - 32;
5257 regnum = mips_regnum (gdbarch)->hi;
5259 regnum = mips_regnum (gdbarch)->lo;
5261 /* This will hopefully (eventually) provoke a warning. Should we
5262 be calling complaint() here? */
5263 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5264 return gdbarch_num_regs (gdbarch) + regnum;
5268 mips_register_sim_regno (struct gdbarch *gdbarch, int regnum)
5270 /* Only makes sense to supply raw registers. */
5271 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
5272 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5273 decide if it is valid. Should instead define a standard sim/gdb
5274 register numbering scheme. */
5275 if (gdbarch_register_name (gdbarch,
5276 gdbarch_num_regs (gdbarch) + regnum) != NULL
5277 && gdbarch_register_name (gdbarch,
5278 gdbarch_num_regs (gdbarch) + regnum)[0] != '\0')
5281 return LEGACY_SIM_REGNO_IGNORE;
5285 /* Convert an integer into an address. Extracting the value signed
5286 guarantees a correctly sign extended address. */
5289 mips_integer_to_address (struct gdbarch *gdbarch,
5290 struct type *type, const gdb_byte *buf)
5292 return (CORE_ADDR) extract_signed_integer (buf, TYPE_LENGTH (type));
5295 /* Dummy virtual frame pointer method. This is no more or less accurate
5296 than most other architectures; we just need to be explicit about it,
5297 because the pseudo-register gdbarch_sp_regnum will otherwise lead to
5298 an assertion failure. */
5301 mips_virtual_frame_pointer (struct gdbarch *gdbarch,
5302 CORE_ADDR pc, int *reg, LONGEST *offset)
5304 *reg = MIPS_SP_REGNUM;
5309 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5311 enum mips_abi *abip = (enum mips_abi *) obj;
5312 const char *name = bfd_get_section_name (abfd, sect);
5314 if (*abip != MIPS_ABI_UNKNOWN)
5317 if (strncmp (name, ".mdebug.", 8) != 0)
5320 if (strcmp (name, ".mdebug.abi32") == 0)
5321 *abip = MIPS_ABI_O32;
5322 else if (strcmp (name, ".mdebug.abiN32") == 0)
5323 *abip = MIPS_ABI_N32;
5324 else if (strcmp (name, ".mdebug.abi64") == 0)
5325 *abip = MIPS_ABI_N64;
5326 else if (strcmp (name, ".mdebug.abiO64") == 0)
5327 *abip = MIPS_ABI_O64;
5328 else if (strcmp (name, ".mdebug.eabi32") == 0)
5329 *abip = MIPS_ABI_EABI32;
5330 else if (strcmp (name, ".mdebug.eabi64") == 0)
5331 *abip = MIPS_ABI_EABI64;
5333 warning (_("unsupported ABI %s."), name + 8);
5337 mips_find_long_section (bfd *abfd, asection *sect, void *obj)
5339 int *lbp = (int *) obj;
5340 const char *name = bfd_get_section_name (abfd, sect);
5342 if (strncmp (name, ".gcc_compiled_long32", 20) == 0)
5344 else if (strncmp (name, ".gcc_compiled_long64", 20) == 0)
5346 else if (strncmp (name, ".gcc_compiled_long", 18) == 0)
5347 warning (_("unrecognized .gcc_compiled_longXX"));
5350 static enum mips_abi
5351 global_mips_abi (void)
5355 for (i = 0; mips_abi_strings[i] != NULL; i++)
5356 if (mips_abi_strings[i] == mips_abi_string)
5357 return (enum mips_abi) i;
5359 internal_error (__FILE__, __LINE__, _("unknown ABI string"));
5363 mips_register_g_packet_guesses (struct gdbarch *gdbarch)
5365 /* If the size matches the set of 32-bit or 64-bit integer registers,
5366 assume that's what we've got. */
5367 register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32);
5368 register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64);
5370 /* If the size matches the full set of registers GDB traditionally
5371 knows about, including floating point, for either 32-bit or
5372 64-bit, assume that's what we've got. */
5373 register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32);
5374 register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64);
5376 /* Otherwise we don't have a useful guess. */
5379 static struct value *
5380 value_of_mips_user_reg (struct frame_info *frame, const void *baton)
5382 const int *reg_p = baton;
5383 return value_of_register (*reg_p, frame);
5386 static struct gdbarch *
5387 mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5389 struct gdbarch *gdbarch;
5390 struct gdbarch_tdep *tdep;
5392 enum mips_abi mips_abi, found_abi, wanted_abi;
5394 enum mips_fpu_type fpu_type;
5395 struct tdesc_arch_data *tdesc_data = NULL;
5396 int elf_fpu_type = 0;
5398 /* Check any target description for validity. */
5399 if (tdesc_has_registers (info.target_desc))
5401 static const char *const mips_gprs[] = {
5402 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5403 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5404 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5405 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5407 static const char *const mips_fprs[] = {
5408 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5409 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5410 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5411 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
5414 const struct tdesc_feature *feature;
5417 feature = tdesc_find_feature (info.target_desc,
5418 "org.gnu.gdb.mips.cpu");
5419 if (feature == NULL)
5422 tdesc_data = tdesc_data_alloc ();
5425 for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++)
5426 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
5430 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5431 MIPS_EMBED_LO_REGNUM, "lo");
5432 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5433 MIPS_EMBED_HI_REGNUM, "hi");
5434 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5435 MIPS_EMBED_PC_REGNUM, "pc");
5439 tdesc_data_cleanup (tdesc_data);
5443 feature = tdesc_find_feature (info.target_desc,
5444 "org.gnu.gdb.mips.cp0");
5445 if (feature == NULL)
5447 tdesc_data_cleanup (tdesc_data);
5452 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5453 MIPS_EMBED_BADVADDR_REGNUM,
5455 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5456 MIPS_PS_REGNUM, "status");
5457 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5458 MIPS_EMBED_CAUSE_REGNUM, "cause");
5462 tdesc_data_cleanup (tdesc_data);
5466 /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
5467 backend is not prepared for that, though. */
5468 feature = tdesc_find_feature (info.target_desc,
5469 "org.gnu.gdb.mips.fpu");
5470 if (feature == NULL)
5472 tdesc_data_cleanup (tdesc_data);
5477 for (i = 0; i < 32; i++)
5478 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5479 i + MIPS_EMBED_FP0_REGNUM,
5482 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5483 MIPS_EMBED_FP0_REGNUM + 32, "fcsr");
5484 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5485 MIPS_EMBED_FP0_REGNUM + 33, "fir");
5489 tdesc_data_cleanup (tdesc_data);
5493 /* It would be nice to detect an attempt to use a 64-bit ABI
5494 when only 32-bit registers are provided. */
5497 /* First of all, extract the elf_flags, if available. */
5498 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5499 elf_flags = elf_elfheader (info.abfd)->e_flags;
5500 else if (arches != NULL)
5501 elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags;
5505 fprintf_unfiltered (gdb_stdlog,
5506 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags);
5508 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5509 switch ((elf_flags & EF_MIPS_ABI))
5511 case E_MIPS_ABI_O32:
5512 found_abi = MIPS_ABI_O32;
5514 case E_MIPS_ABI_O64:
5515 found_abi = MIPS_ABI_O64;
5517 case E_MIPS_ABI_EABI32:
5518 found_abi = MIPS_ABI_EABI32;
5520 case E_MIPS_ABI_EABI64:
5521 found_abi = MIPS_ABI_EABI64;
5524 if ((elf_flags & EF_MIPS_ABI2))
5525 found_abi = MIPS_ABI_N32;
5527 found_abi = MIPS_ABI_UNKNOWN;
5531 /* GCC creates a pseudo-section whose name describes the ABI. */
5532 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5533 bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi);
5535 /* If we have no useful BFD information, use the ABI from the last
5536 MIPS architecture (if there is one). */
5537 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
5538 found_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5540 /* Try the architecture for any hint of the correct ABI. */
5541 if (found_abi == MIPS_ABI_UNKNOWN
5542 && info.bfd_arch_info != NULL
5543 && info.bfd_arch_info->arch == bfd_arch_mips)
5545 switch (info.bfd_arch_info->mach)
5547 case bfd_mach_mips3900:
5548 found_abi = MIPS_ABI_EABI32;
5550 case bfd_mach_mips4100:
5551 case bfd_mach_mips5000:
5552 found_abi = MIPS_ABI_EABI64;
5554 case bfd_mach_mips8000:
5555 case bfd_mach_mips10000:
5556 /* On Irix, ELF64 executables use the N64 ABI. The
5557 pseudo-sections which describe the ABI aren't present
5558 on IRIX. (Even for executables created by gcc.) */
5559 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5560 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5561 found_abi = MIPS_ABI_N64;
5563 found_abi = MIPS_ABI_N32;
5568 /* Default 64-bit objects to N64 instead of O32. */
5569 if (found_abi == MIPS_ABI_UNKNOWN
5570 && info.abfd != NULL
5571 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5572 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5573 found_abi = MIPS_ABI_N64;
5576 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n",
5579 /* What has the user specified from the command line? */
5580 wanted_abi = global_mips_abi ();
5582 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n",
5585 /* Now that we have found what the ABI for this binary would be,
5586 check whether the user is overriding it. */
5587 if (wanted_abi != MIPS_ABI_UNKNOWN)
5588 mips_abi = wanted_abi;
5589 else if (found_abi != MIPS_ABI_UNKNOWN)
5590 mips_abi = found_abi;
5592 mips_abi = MIPS_ABI_O32;
5594 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n",
5597 /* Also used when doing an architecture lookup. */
5599 fprintf_unfiltered (gdb_stdlog,
5600 "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n",
5601 mips64_transfers_32bit_regs_p);
5603 /* Determine the MIPS FPU type. */
5606 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5607 elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5608 Tag_GNU_MIPS_ABI_FP);
5609 #endif /* HAVE_ELF */
5611 if (!mips_fpu_type_auto)
5612 fpu_type = mips_fpu_type;
5613 else if (elf_fpu_type != 0)
5615 switch (elf_fpu_type)
5618 fpu_type = MIPS_FPU_DOUBLE;
5621 fpu_type = MIPS_FPU_SINGLE;
5625 /* Soft float or unknown. */
5626 fpu_type = MIPS_FPU_NONE;
5630 else if (info.bfd_arch_info != NULL
5631 && info.bfd_arch_info->arch == bfd_arch_mips)
5632 switch (info.bfd_arch_info->mach)
5634 case bfd_mach_mips3900:
5635 case bfd_mach_mips4100:
5636 case bfd_mach_mips4111:
5637 case bfd_mach_mips4120:
5638 fpu_type = MIPS_FPU_NONE;
5640 case bfd_mach_mips4650:
5641 fpu_type = MIPS_FPU_SINGLE;
5644 fpu_type = MIPS_FPU_DOUBLE;
5647 else if (arches != NULL)
5648 fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type;
5650 fpu_type = MIPS_FPU_DOUBLE;
5652 fprintf_unfiltered (gdb_stdlog,
5653 "mips_gdbarch_init: fpu_type = %d\n", fpu_type);
5655 /* Check for blatant incompatibilities. */
5657 /* If we have only 32-bit registers, then we can't debug a 64-bit
5659 if (info.target_desc
5660 && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL
5661 && mips_abi != MIPS_ABI_EABI32
5662 && mips_abi != MIPS_ABI_O32)
5664 if (tdesc_data != NULL)
5665 tdesc_data_cleanup (tdesc_data);
5669 /* try to find a pre-existing architecture */
5670 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5672 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5674 /* MIPS needs to be pedantic about which ABI the object is
5676 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5678 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5680 /* Need to be pedantic about which register virtual size is
5682 if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p
5683 != mips64_transfers_32bit_regs_p)
5685 /* Be pedantic about which FPU is selected. */
5686 if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type)
5689 if (tdesc_data != NULL)
5690 tdesc_data_cleanup (tdesc_data);
5691 return arches->gdbarch;
5694 /* Need a new architecture. Fill in a target specific vector. */
5695 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5696 gdbarch = gdbarch_alloc (&info, tdep);
5697 tdep->elf_flags = elf_flags;
5698 tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p;
5699 tdep->found_abi = found_abi;
5700 tdep->mips_abi = mips_abi;
5701 tdep->mips_fpu_type = fpu_type;
5702 tdep->register_size_valid_p = 0;
5703 tdep->register_size = 0;
5705 if (info.target_desc)
5707 /* Some useful properties can be inferred from the target. */
5708 if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL)
5710 tdep->register_size_valid_p = 1;
5711 tdep->register_size = 4;
5713 else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL)
5715 tdep->register_size_valid_p = 1;
5716 tdep->register_size = 8;
5720 /* Initially set everything according to the default ABI/ISA. */
5721 set_gdbarch_short_bit (gdbarch, 16);
5722 set_gdbarch_int_bit (gdbarch, 32);
5723 set_gdbarch_float_bit (gdbarch, 32);
5724 set_gdbarch_double_bit (gdbarch, 64);
5725 set_gdbarch_long_double_bit (gdbarch, 64);
5726 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
5727 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
5728 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
5730 set_gdbarch_elf_make_msymbol_special (gdbarch,
5731 mips_elf_make_msymbol_special);
5733 /* Fill in the OS dependant register numbers and names. */
5735 const char **reg_names;
5736 struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch,
5737 struct mips_regnum);
5738 if (tdesc_has_registers (info.target_desc))
5740 regnum->lo = MIPS_EMBED_LO_REGNUM;
5741 regnum->hi = MIPS_EMBED_HI_REGNUM;
5742 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
5743 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
5744 regnum->pc = MIPS_EMBED_PC_REGNUM;
5745 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
5746 regnum->fp_control_status = 70;
5747 regnum->fp_implementation_revision = 71;
5748 num_regs = MIPS_LAST_EMBED_REGNUM + 1;
5751 else if (info.osabi == GDB_OSABI_IRIX)
5756 regnum->badvaddr = 66;
5759 regnum->fp_control_status = 69;
5760 regnum->fp_implementation_revision = 70;
5762 reg_names = mips_irix_reg_names;
5766 regnum->lo = MIPS_EMBED_LO_REGNUM;
5767 regnum->hi = MIPS_EMBED_HI_REGNUM;
5768 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
5769 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
5770 regnum->pc = MIPS_EMBED_PC_REGNUM;
5771 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
5772 regnum->fp_control_status = 70;
5773 regnum->fp_implementation_revision = 71;
5775 if (info.bfd_arch_info != NULL
5776 && info.bfd_arch_info->mach == bfd_mach_mips3900)
5777 reg_names = mips_tx39_reg_names;
5779 reg_names = mips_generic_reg_names;
5781 /* FIXME: cagney/2003-11-15: For MIPS, hasn't gdbarch_pc_regnum been
5782 replaced by read_pc? */
5783 set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs);
5784 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
5785 set_gdbarch_fp0_regnum (gdbarch, regnum->fp0);
5786 set_gdbarch_num_regs (gdbarch, num_regs);
5787 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
5788 set_gdbarch_register_name (gdbarch, mips_register_name);
5789 set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer);
5790 tdep->mips_processor_reg_names = reg_names;
5791 tdep->regnum = regnum;
5797 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5798 set_gdbarch_return_value (gdbarch, mips_o32_return_value);
5799 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
5800 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
5801 tdep->default_mask_address_p = 0;
5802 set_gdbarch_long_bit (gdbarch, 32);
5803 set_gdbarch_ptr_bit (gdbarch, 32);
5804 set_gdbarch_long_long_bit (gdbarch, 64);
5807 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5808 set_gdbarch_return_value (gdbarch, mips_o64_return_value);
5809 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
5810 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
5811 tdep->default_mask_address_p = 0;
5812 set_gdbarch_long_bit (gdbarch, 32);
5813 set_gdbarch_ptr_bit (gdbarch, 32);
5814 set_gdbarch_long_long_bit (gdbarch, 64);
5816 case MIPS_ABI_EABI32:
5817 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5818 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
5819 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
5820 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
5821 tdep->default_mask_address_p = 0;
5822 set_gdbarch_long_bit (gdbarch, 32);
5823 set_gdbarch_ptr_bit (gdbarch, 32);
5824 set_gdbarch_long_long_bit (gdbarch, 64);
5826 case MIPS_ABI_EABI64:
5827 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5828 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
5829 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
5830 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
5831 tdep->default_mask_address_p = 0;
5832 set_gdbarch_long_bit (gdbarch, 64);
5833 set_gdbarch_ptr_bit (gdbarch, 64);
5834 set_gdbarch_long_long_bit (gdbarch, 64);
5837 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5838 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
5839 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
5840 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
5841 tdep->default_mask_address_p = 0;
5842 set_gdbarch_long_bit (gdbarch, 32);
5843 set_gdbarch_ptr_bit (gdbarch, 32);
5844 set_gdbarch_long_long_bit (gdbarch, 64);
5845 set_gdbarch_long_double_bit (gdbarch, 128);
5846 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
5849 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5850 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
5851 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
5852 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
5853 tdep->default_mask_address_p = 0;
5854 set_gdbarch_long_bit (gdbarch, 64);
5855 set_gdbarch_ptr_bit (gdbarch, 64);
5856 set_gdbarch_long_long_bit (gdbarch, 64);
5857 set_gdbarch_long_double_bit (gdbarch, 128);
5858 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
5861 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
5864 /* GCC creates a pseudo-section whose name specifies the size of
5865 longs, since -mlong32 or -mlong64 may be used independent of
5866 other options. How those options affect pointer sizes is ABI and
5867 architecture dependent, so use them to override the default sizes
5868 set by the ABI. This table shows the relationship between ABI,
5869 -mlongXX, and size of pointers:
5871 ABI -mlongXX ptr bits
5872 --- -------- --------
5886 Note that for o32 and eabi32, pointers are always 32 bits
5887 regardless of any -mlongXX option. For all others, pointers and
5888 longs are the same, as set by -mlongXX or set by defaults.
5891 if (info.abfd != NULL)
5895 bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit);
5898 set_gdbarch_long_bit (gdbarch, long_bit);
5902 case MIPS_ABI_EABI32:
5907 case MIPS_ABI_EABI64:
5908 set_gdbarch_ptr_bit (gdbarch, long_bit);
5911 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
5916 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5917 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5920 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5921 flag in object files because to do so would make it impossible to
5922 link with libraries compiled without "-gp32". This is
5923 unnecessarily restrictive.
5925 We could solve this problem by adding "-gp32" multilibs to gcc,
5926 but to set this flag before gcc is built with such multilibs will
5927 break too many systems.''
5929 But even more unhelpfully, the default linker output target for
5930 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5931 for 64-bit programs - you need to change the ABI to change this,
5932 and not all gcc targets support that currently. Therefore using
5933 this flag to detect 32-bit mode would do the wrong thing given
5934 the current gcc - it would make GDB treat these 64-bit programs
5935 as 32-bit programs by default. */
5937 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5938 set_gdbarch_write_pc (gdbarch, mips_write_pc);
5940 /* Add/remove bits from an address. The MIPS needs be careful to
5941 ensure that all 32 bit addresses are sign extended to 64 bits. */
5942 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5944 /* Unwind the frame. */
5945 set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc);
5946 set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp);
5947 set_gdbarch_dummy_id (gdbarch, mips_dummy_id);
5949 /* Map debug register numbers onto internal register numbers. */
5950 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5951 set_gdbarch_ecoff_reg_to_regnum (gdbarch,
5952 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5953 set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
5954 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5955 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
5957 /* MIPS version of CALL_DUMMY */
5959 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
5960 replaced by a command, and all targets will default to on stack
5961 (regardless of the stack's execute status). */
5962 set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL);
5963 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5965 set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p);
5966 set_gdbarch_register_to_value (gdbarch, mips_register_to_value);
5967 set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
5969 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5970 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5972 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5974 set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p);
5976 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5977 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5978 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5980 set_gdbarch_register_type (gdbarch, mips_register_type);
5982 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
5984 if (mips_abi == MIPS_ABI_N32)
5985 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n32);
5986 else if (mips_abi == MIPS_ABI_N64)
5987 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n64);
5989 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
5991 /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT,
5992 HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT
5993 need to all be folded into the target vector. Since they are
5994 being used as guards for STOPPED_BY_WATCHPOINT, why not have
5995 STOPPED_BY_WATCHPOINT return the type of watchpoint that the code
5997 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
5999 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code);
6001 set_gdbarch_single_step_through_delay (gdbarch, mips_single_step_through_delay);
6003 /* Virtual tables. */
6004 set_gdbarch_vbit_in_delta (gdbarch, 1);
6006 mips_register_g_packet_guesses (gdbarch);
6008 /* Hook in OS ABI-specific overrides, if they have been registered. */
6009 info.tdep_info = (void *) tdesc_data;
6010 gdbarch_init_osabi (info, gdbarch);
6012 /* Unwind the frame. */
6013 dwarf2_append_unwinders (gdbarch);
6014 frame_unwind_append_unwinder (gdbarch, &mips_stub_frame_unwind);
6015 frame_unwind_append_unwinder (gdbarch, &mips_insn16_frame_unwind);
6016 frame_unwind_append_unwinder (gdbarch, &mips_insn32_frame_unwind);
6017 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
6018 frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer);
6019 frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer);
6020 frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer);
6024 set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type);
6025 tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
6027 /* Override the normal target description methods to handle our
6028 dual real and pseudo registers. */
6029 set_gdbarch_register_name (gdbarch, mips_register_name);
6030 set_gdbarch_register_reggroup_p (gdbarch, mips_tdesc_register_reggroup_p);
6032 num_regs = gdbarch_num_regs (gdbarch);
6033 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
6034 set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs);
6035 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
6038 /* Add ABI-specific aliases for the registers. */
6039 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
6040 for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++)
6041 user_reg_add (gdbarch, mips_n32_n64_aliases[i].name,
6042 value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum);
6044 for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++)
6045 user_reg_add (gdbarch, mips_o32_aliases[i].name,
6046 value_of_mips_user_reg, &mips_o32_aliases[i].regnum);
6048 /* Add some other standard aliases. */
6049 for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++)
6050 user_reg_add (gdbarch, mips_register_aliases[i].name,
6051 value_of_mips_user_reg, &mips_register_aliases[i].regnum);
6057 mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c)
6059 struct gdbarch_info info;
6061 /* Force the architecture to update, and (if it's a MIPS architecture)
6062 mips_gdbarch_init will take care of the rest. */
6063 gdbarch_info_init (&info);
6064 gdbarch_update_p (info);
6067 /* Print out which MIPS ABI is in use. */
6070 show_mips_abi (struct ui_file *file,
6072 struct cmd_list_element *ignored_cmd,
6073 const char *ignored_value)
6075 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
6078 "The MIPS ABI is unknown because the current architecture "
6082 enum mips_abi global_abi = global_mips_abi ();
6083 enum mips_abi actual_abi = mips_abi (target_gdbarch);
6084 const char *actual_abi_str = mips_abi_strings[actual_abi];
6086 if (global_abi == MIPS_ABI_UNKNOWN)
6089 "The MIPS ABI is set automatically (currently \"%s\").\n",
6091 else if (global_abi == actual_abi)
6094 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6098 /* Probably shouldn't happen... */
6101 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6102 actual_abi_str, mips_abi_strings[global_abi]);
6108 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
6110 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
6114 int ef_mips_32bitmode;
6115 /* Determine the ISA. */
6116 switch (tdep->elf_flags & EF_MIPS_ARCH)
6134 /* Determine the size of a pointer. */
6135 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6136 fprintf_unfiltered (file,
6137 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6139 fprintf_unfiltered (file,
6140 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6142 fprintf_unfiltered (file,
6143 "mips_dump_tdep: ef_mips_arch = %d\n",
6145 fprintf_unfiltered (file,
6146 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6147 tdep->mips_abi, mips_abi_strings[tdep->mips_abi]);
6148 fprintf_unfiltered (file,
6149 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6150 mips_mask_address_p (tdep),
6151 tdep->default_mask_address_p);
6153 fprintf_unfiltered (file,
6154 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6155 MIPS_DEFAULT_FPU_TYPE,
6156 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6157 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6158 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6160 fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n",
6161 MIPS_EABI (gdbarch));
6162 fprintf_unfiltered (file,
6163 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6164 MIPS_FPU_TYPE (gdbarch),
6165 (MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_NONE ? "none"
6166 : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_SINGLE ? "single"
6167 : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_DOUBLE ? "double"
6171 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6174 _initialize_mips_tdep (void)
6176 static struct cmd_list_element *mipsfpulist = NULL;
6177 struct cmd_list_element *c;
6179 mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN];
6180 if (MIPS_ABI_LAST + 1
6181 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6182 internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync"));
6184 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6186 mips_pdr_data = register_objfile_data ();
6188 /* Create feature sets with the appropriate properties. The values
6189 are not important. */
6190 mips_tdesc_gp32 = allocate_target_description ();
6191 set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, "");
6193 mips_tdesc_gp64 = allocate_target_description ();
6194 set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, "");
6196 /* Add root prefix command for all "set mips"/"show mips" commands */
6197 add_prefix_cmd ("mips", no_class, set_mips_command,
6198 _("Various MIPS specific commands."),
6199 &setmipscmdlist, "set mips ", 0, &setlist);
6201 add_prefix_cmd ("mips", no_class, show_mips_command,
6202 _("Various MIPS specific commands."),
6203 &showmipscmdlist, "show mips ", 0, &showlist);
6205 /* Allow the user to override the ABI. */
6206 add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings,
6207 &mips_abi_string, _("\
6208 Set the MIPS ABI used by this program."), _("\
6209 Show the MIPS ABI used by this program."), _("\
6210 This option can be set to one of:\n\
6211 auto - the default ABI associated with the current binary\n\
6220 &setmipscmdlist, &showmipscmdlist);
6222 /* Let the user turn off floating point and set the fence post for
6223 heuristic_proc_start. */
6225 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6226 _("Set use of MIPS floating-point coprocessor."),
6227 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6228 add_cmd ("single", class_support, set_mipsfpu_single_command,
6229 _("Select single-precision MIPS floating-point coprocessor."),
6231 add_cmd ("double", class_support, set_mipsfpu_double_command,
6232 _("Select double-precision MIPS floating-point coprocessor."),
6234 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6235 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6236 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6237 add_cmd ("none", class_support, set_mipsfpu_none_command,
6238 _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
6239 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6240 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6241 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6242 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6243 _("Select MIPS floating-point coprocessor automatically."),
6245 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6246 _("Show current use of MIPS floating-point coprocessor target."),
6249 /* We really would like to have both "0" and "unlimited" work, but
6250 command.c doesn't deal with that. So make it a var_zinteger
6251 because the user can always use "999999" or some such for unlimited. */
6252 add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
6253 &heuristic_fence_post, _("\
6254 Set the distance searched for the start of a function."), _("\
6255 Show the distance searched for the start of a function."), _("\
6256 If you are debugging a stripped executable, GDB needs to search through the\n\
6257 program for the start of a function. This command sets the distance of the\n\
6258 search. The only need to set it is when debugging a stripped executable."),
6259 reinit_frame_cache_sfunc,
6260 NULL, /* FIXME: i18n: The distance searched for the start of a function is %s. */
6261 &setlist, &showlist);
6263 /* Allow the user to control whether the upper bits of 64-bit
6264 addresses should be zeroed. */
6265 add_setshow_auto_boolean_cmd ("mask-address", no_class,
6266 &mask_address_var, _("\
6267 Set zeroing of upper 32 bits of 64-bit addresses."), _("\
6268 Show zeroing of upper 32 bits of 64-bit addresses."), _("\
6269 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6270 allow GDB to determine the correct value."),
6271 NULL, show_mask_address,
6272 &setmipscmdlist, &showmipscmdlist);
6274 /* Allow the user to control the size of 32 bit registers within the
6275 raw remote packet. */
6276 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure,
6277 &mips64_transfers_32bit_regs_p, _("\
6278 Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6280 Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6282 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6283 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6284 64 bits for others. Use \"off\" to disable compatibility mode"),
6285 set_mips64_transfers_32bit_regs,
6286 NULL, /* FIXME: i18n: Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s. */
6287 &setlist, &showlist);
6289 /* Debug this files internals. */
6290 add_setshow_zinteger_cmd ("mips", class_maintenance,
6292 Set mips debugging."), _("\
6293 Show mips debugging."), _("\
6294 When non-zero, mips specific debugging is enabled."),
6296 NULL, /* FIXME: i18n: Mips debugging is currently %s. */
6297 &setdebuglist, &showdebuglist);