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, 2009,
5 2010, 2011 Free Software Foundation, Inc.
7 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
8 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
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"
63 static const struct objfile_data
*mips_pdr_data
;
65 static struct type
*mips_register_type (struct gdbarch
*gdbarch
, int regnum
);
67 /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
68 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
69 #define ST0_FR (1 << 26)
71 /* The sizes of floating point registers. */
75 MIPS_FPU_SINGLE_REGSIZE
= 4,
76 MIPS_FPU_DOUBLE_REGSIZE
= 8
85 static const char *mips_abi_string
;
87 static const char *mips_abi_strings
[] = {
98 /* The standard register names, and all the valid aliases for them. */
105 /* Aliases for o32 and most other ABIs. */
106 const struct register_alias mips_o32_aliases
[] = {
113 /* Aliases for n32 and n64. */
114 const struct register_alias mips_n32_n64_aliases
[] = {
121 /* Aliases for ABI-independent registers. */
122 const struct register_alias mips_register_aliases
[] = {
123 /* The architecture manuals specify these ABI-independent names for
125 #define R(n) { "r" #n, n }
126 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
127 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
128 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
129 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
132 /* k0 and k1 are sometimes called these instead (for "kernel
137 /* This is the traditional GDB name for the CP0 status register. */
138 { "sr", MIPS_PS_REGNUM
},
140 /* This is the traditional GDB name for the CP0 BadVAddr register. */
141 { "bad", MIPS_EMBED_BADVADDR_REGNUM
},
143 /* This is the traditional GDB name for the FCSR. */
144 { "fsr", MIPS_EMBED_FP0_REGNUM
+ 32 }
147 const struct register_alias mips_numeric_register_aliases
[] = {
148 #define R(n) { #n, n }
149 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
150 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
151 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
152 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
156 #ifndef MIPS_DEFAULT_FPU_TYPE
157 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
159 static int mips_fpu_type_auto
= 1;
160 static enum mips_fpu_type mips_fpu_type
= MIPS_DEFAULT_FPU_TYPE
;
162 static int mips_debug
= 0;
164 /* Properties (for struct target_desc) describing the g/G packet
166 #define PROPERTY_GP32 "internal: transfers-32bit-registers"
167 #define PROPERTY_GP64 "internal: transfers-64bit-registers"
169 struct target_desc
*mips_tdesc_gp32
;
170 struct target_desc
*mips_tdesc_gp64
;
172 const struct mips_regnum
*
173 mips_regnum (struct gdbarch
*gdbarch
)
175 return gdbarch_tdep (gdbarch
)->regnum
;
179 mips_fpa0_regnum (struct gdbarch
*gdbarch
)
181 return mips_regnum (gdbarch
)->fp0
+ 12;
184 #define MIPS_EABI(gdbarch) (gdbarch_tdep (gdbarch)->mips_abi \
186 || gdbarch_tdep (gdbarch)->mips_abi == MIPS_ABI_EABI64)
188 #define MIPS_LAST_FP_ARG_REGNUM(gdbarch) \
189 (gdbarch_tdep (gdbarch)->mips_last_fp_arg_regnum)
191 #define MIPS_LAST_ARG_REGNUM(gdbarch) \
192 (gdbarch_tdep (gdbarch)->mips_last_arg_regnum)
194 #define MIPS_FPU_TYPE(gdbarch) (gdbarch_tdep (gdbarch)->mips_fpu_type)
196 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
197 functions to test, set, or clear bit 0 of addresses. */
200 is_mips16_addr (CORE_ADDR addr
)
206 unmake_mips16_addr (CORE_ADDR addr
)
208 return ((addr
) & ~(CORE_ADDR
) 1);
212 make_mips16_addr (CORE_ADDR addr
)
214 return ((addr
) | (CORE_ADDR
) 1);
217 /* Return the MIPS ABI associated with GDBARCH. */
219 mips_abi (struct gdbarch
*gdbarch
)
221 return gdbarch_tdep (gdbarch
)->mips_abi
;
225 mips_isa_regsize (struct gdbarch
*gdbarch
)
227 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
229 /* If we know how big the registers are, use that size. */
230 if (tdep
->register_size_valid_p
)
231 return tdep
->register_size
;
233 /* Fall back to the previous behavior. */
234 return (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
235 / gdbarch_bfd_arch_info (gdbarch
)->bits_per_byte
);
238 /* Return the currently configured (or set) saved register size. */
241 mips_abi_regsize (struct gdbarch
*gdbarch
)
243 switch (mips_abi (gdbarch
))
245 case MIPS_ABI_EABI32
:
251 case MIPS_ABI_EABI64
:
253 case MIPS_ABI_UNKNOWN
:
256 internal_error (__FILE__
, __LINE__
, _("bad switch"));
260 /* Functions for setting and testing a bit in a minimal symbol that
261 marks it as 16-bit function. The MSB of the minimal symbol's
262 "info" field is used for this purpose.
264 gdbarch_elf_make_msymbol_special tests whether an ELF symbol is "special",
265 i.e. refers to a 16-bit function, and sets a "special" bit in a
266 minimal symbol to mark it as a 16-bit function
268 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
271 mips_elf_make_msymbol_special (asymbol
* sym
, struct minimal_symbol
*msym
)
273 if (((elf_symbol_type
*) (sym
))->internal_elf_sym
.st_other
== STO_MIPS16
)
275 MSYMBOL_TARGET_FLAG_1 (msym
) = 1;
280 msymbol_is_special (struct minimal_symbol
*msym
)
282 return MSYMBOL_TARGET_FLAG_1 (msym
);
285 /* XFER a value from the big/little/left end of the register.
286 Depending on the size of the value it might occupy the entire
287 register or just part of it. Make an allowance for this, aligning
288 things accordingly. */
291 mips_xfer_register (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
292 int reg_num
, int length
,
293 enum bfd_endian endian
, gdb_byte
*in
,
294 const gdb_byte
*out
, int buf_offset
)
298 gdb_assert (reg_num
>= gdbarch_num_regs (gdbarch
));
299 /* Need to transfer the left or right part of the register, based on
300 the targets byte order. */
304 reg_offset
= register_size (gdbarch
, reg_num
) - length
;
306 case BFD_ENDIAN_LITTLE
:
309 case BFD_ENDIAN_UNKNOWN
: /* Indicates no alignment. */
313 internal_error (__FILE__
, __LINE__
, _("bad switch"));
316 fprintf_unfiltered (gdb_stderr
,
317 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
318 reg_num
, reg_offset
, buf_offset
, length
);
319 if (mips_debug
&& out
!= NULL
)
322 fprintf_unfiltered (gdb_stdlog
, "out ");
323 for (i
= 0; i
< length
; i
++)
324 fprintf_unfiltered (gdb_stdlog
, "%02x", out
[buf_offset
+ i
]);
327 regcache_cooked_read_part (regcache
, reg_num
, reg_offset
, length
,
330 regcache_cooked_write_part (regcache
, reg_num
, reg_offset
, length
,
332 if (mips_debug
&& in
!= NULL
)
335 fprintf_unfiltered (gdb_stdlog
, "in ");
336 for (i
= 0; i
< length
; i
++)
337 fprintf_unfiltered (gdb_stdlog
, "%02x", in
[buf_offset
+ i
]);
340 fprintf_unfiltered (gdb_stdlog
, "\n");
343 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
344 compatiblity mode. A return value of 1 means that we have
345 physical 64-bit registers, but should treat them as 32-bit registers. */
348 mips2_fp_compat (struct frame_info
*frame
)
350 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
351 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
353 if (register_size (gdbarch
, mips_regnum (gdbarch
)->fp0
) == 4)
357 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
358 in all the places we deal with FP registers. PR gdb/413. */
359 /* Otherwise check the FR bit in the status register - it controls
360 the FP compatiblity mode. If it is clear we are in compatibility
362 if ((get_frame_register_unsigned (frame
, MIPS_PS_REGNUM
) & ST0_FR
) == 0)
369 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
371 static CORE_ADDR
heuristic_proc_start (struct gdbarch
*, CORE_ADDR
);
373 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element
*);
375 /* The list of available "set mips " and "show mips " commands. */
377 static struct cmd_list_element
*setmipscmdlist
= NULL
;
378 static struct cmd_list_element
*showmipscmdlist
= NULL
;
380 /* Integer registers 0 thru 31 are handled explicitly by
381 mips_register_name(). Processor specific registers 32 and above
382 are listed in the following tables. */
385 { NUM_MIPS_PROCESSOR_REGS
= (90 - 32) };
389 static const char *mips_generic_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
390 "sr", "lo", "hi", "bad", "cause", "pc",
391 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
392 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
393 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
394 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
395 "fsr", "fir", "" /*"fp" */ , "",
396 "", "", "", "", "", "", "", "",
397 "", "", "", "", "", "", "", "",
400 /* Names of IDT R3041 registers. */
402 static const char *mips_r3041_reg_names
[] = {
403 "sr", "lo", "hi", "bad", "cause", "pc",
404 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
405 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
406 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
407 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
408 "fsr", "fir", "", /*"fp" */ "",
409 "", "", "bus", "ccfg", "", "", "", "",
410 "", "", "port", "cmp", "", "", "epc", "prid",
413 /* Names of tx39 registers. */
415 static const char *mips_tx39_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
416 "sr", "lo", "hi", "bad", "cause", "pc",
417 "", "", "", "", "", "", "", "",
418 "", "", "", "", "", "", "", "",
419 "", "", "", "", "", "", "", "",
420 "", "", "", "", "", "", "", "",
422 "", "", "", "", "", "", "", "",
423 "", "", "config", "cache", "debug", "depc", "epc", ""
426 /* Names of IRIX registers. */
427 static const char *mips_irix_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
428 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
429 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
430 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
431 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
432 "pc", "cause", "bad", "hi", "lo", "fsr", "fir"
436 /* Return the name of the register corresponding to REGNO. */
438 mips_register_name (struct gdbarch
*gdbarch
, int regno
)
440 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
441 /* GPR names for all ABIs other than n32/n64. */
442 static char *mips_gpr_names
[] = {
443 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
444 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
445 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
446 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
449 /* GPR names for n32 and n64 ABIs. */
450 static char *mips_n32_n64_gpr_names
[] = {
451 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
452 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
453 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
454 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
457 enum mips_abi abi
= mips_abi (gdbarch
);
459 /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
460 but then don't make the raw register names visible. This (upper)
461 range of user visible register numbers are the pseudo-registers.
463 This approach was adopted accommodate the following scenario:
464 It is possible to debug a 64-bit device using a 32-bit
465 programming model. In such instances, the raw registers are
466 configured to be 64-bits wide, while the pseudo registers are
467 configured to be 32-bits wide. The registers that the user
468 sees - the pseudo registers - match the users expectations
469 given the programming model being used. */
470 int rawnum
= regno
% gdbarch_num_regs (gdbarch
);
471 if (regno
< gdbarch_num_regs (gdbarch
))
474 /* The MIPS integer registers are always mapped from 0 to 31. The
475 names of the registers (which reflects the conventions regarding
476 register use) vary depending on the ABI. */
477 if (0 <= rawnum
&& rawnum
< 32)
479 if (abi
== MIPS_ABI_N32
|| abi
== MIPS_ABI_N64
)
480 return mips_n32_n64_gpr_names
[rawnum
];
482 return mips_gpr_names
[rawnum
];
484 else if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
485 return tdesc_register_name (gdbarch
, rawnum
);
486 else if (32 <= rawnum
&& rawnum
< gdbarch_num_regs (gdbarch
))
488 gdb_assert (rawnum
- 32 < NUM_MIPS_PROCESSOR_REGS
);
489 return tdep
->mips_processor_reg_names
[rawnum
- 32];
492 internal_error (__FILE__
, __LINE__
,
493 _("mips_register_name: bad register number %d"), rawnum
);
496 /* Return the groups that a MIPS register can be categorised into. */
499 mips_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
500 struct reggroup
*reggroup
)
505 int rawnum
= regnum
% gdbarch_num_regs (gdbarch
);
506 int pseudo
= regnum
/ gdbarch_num_regs (gdbarch
);
507 if (reggroup
== all_reggroup
)
509 vector_p
= TYPE_VECTOR (register_type (gdbarch
, regnum
));
510 float_p
= TYPE_CODE (register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
;
511 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
512 (gdbarch), as not all architectures are multi-arch. */
513 raw_p
= rawnum
< gdbarch_num_regs (gdbarch
);
514 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
515 || gdbarch_register_name (gdbarch
, regnum
)[0] == '\0')
517 if (reggroup
== float_reggroup
)
518 return float_p
&& pseudo
;
519 if (reggroup
== vector_reggroup
)
520 return vector_p
&& pseudo
;
521 if (reggroup
== general_reggroup
)
522 return (!vector_p
&& !float_p
) && pseudo
;
523 /* Save the pseudo registers. Need to make certain that any code
524 extracting register values from a saved register cache also uses
526 if (reggroup
== save_reggroup
)
527 return raw_p
&& pseudo
;
528 /* Restore the same pseudo register. */
529 if (reggroup
== restore_reggroup
)
530 return raw_p
&& pseudo
;
534 /* Return the groups that a MIPS register can be categorised into.
535 This version is only used if we have a target description which
536 describes real registers (and their groups). */
539 mips_tdesc_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
540 struct reggroup
*reggroup
)
542 int rawnum
= regnum
% gdbarch_num_regs (gdbarch
);
543 int pseudo
= regnum
/ gdbarch_num_regs (gdbarch
);
546 /* Only save, restore, and display the pseudo registers. Need to
547 make certain that any code extracting register values from a
548 saved register cache also uses pseudo registers.
550 Note: saving and restoring the pseudo registers is slightly
551 strange; if we have 64 bits, we should save and restore all
552 64 bits. But this is hard and has little benefit. */
556 ret
= tdesc_register_in_reggroup_p (gdbarch
, rawnum
, reggroup
);
560 return mips_register_reggroup_p (gdbarch
, regnum
, reggroup
);
563 /* Map the symbol table registers which live in the range [1 *
564 gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
565 registers. Take care of alignment and size problems. */
568 mips_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
569 int cookednum
, gdb_byte
*buf
)
571 int rawnum
= cookednum
% gdbarch_num_regs (gdbarch
);
572 gdb_assert (cookednum
>= gdbarch_num_regs (gdbarch
)
573 && cookednum
< 2 * gdbarch_num_regs (gdbarch
));
574 if (register_size (gdbarch
, rawnum
) == register_size (gdbarch
, cookednum
))
575 regcache_raw_read (regcache
, rawnum
, buf
);
576 else if (register_size (gdbarch
, rawnum
) >
577 register_size (gdbarch
, cookednum
))
579 if (gdbarch_tdep (gdbarch
)->mips64_transfers_32bit_regs_p
)
580 regcache_raw_read_part (regcache
, rawnum
, 0, 4, buf
);
583 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
585 regcache_raw_read_signed (regcache
, rawnum
, ®val
);
586 store_signed_integer (buf
, 4, byte_order
, regval
);
590 internal_error (__FILE__
, __LINE__
, _("bad register size"));
594 mips_pseudo_register_write (struct gdbarch
*gdbarch
,
595 struct regcache
*regcache
, int cookednum
,
598 int rawnum
= cookednum
% gdbarch_num_regs (gdbarch
);
599 gdb_assert (cookednum
>= gdbarch_num_regs (gdbarch
)
600 && cookednum
< 2 * gdbarch_num_regs (gdbarch
));
601 if (register_size (gdbarch
, rawnum
) == register_size (gdbarch
, cookednum
))
602 regcache_raw_write (regcache
, rawnum
, buf
);
603 else if (register_size (gdbarch
, rawnum
) >
604 register_size (gdbarch
, cookednum
))
606 if (gdbarch_tdep (gdbarch
)->mips64_transfers_32bit_regs_p
)
607 regcache_raw_write_part (regcache
, rawnum
, 0, 4, buf
);
610 /* Sign extend the shortened version of the register prior
611 to placing it in the raw register. This is required for
612 some mips64 parts in order to avoid unpredictable behavior. */
613 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
614 LONGEST regval
= extract_signed_integer (buf
, 4, byte_order
);
615 regcache_raw_write_signed (regcache
, rawnum
, regval
);
619 internal_error (__FILE__
, __LINE__
, _("bad register size"));
623 mips_ax_pseudo_register_collect (struct gdbarch
*gdbarch
,
624 struct agent_expr
*ax
, int reg
)
626 int rawnum
= reg
% gdbarch_num_regs (gdbarch
);
627 gdb_assert (reg
>= gdbarch_num_regs (gdbarch
)
628 && reg
< 2 * gdbarch_num_regs (gdbarch
));
630 ax_reg_mask (ax
, rawnum
);
636 mips_ax_pseudo_register_push_stack (struct gdbarch
*gdbarch
,
637 struct agent_expr
*ax
, int reg
)
639 int rawnum
= reg
% gdbarch_num_regs (gdbarch
);
640 gdb_assert (reg
>= gdbarch_num_regs (gdbarch
)
641 && reg
< 2 * gdbarch_num_regs (gdbarch
));
642 if (register_size (gdbarch
, rawnum
) >= register_size (gdbarch
, reg
))
646 if (register_size (gdbarch
, rawnum
) > register_size (gdbarch
, reg
))
648 if (!gdbarch_tdep (gdbarch
)->mips64_transfers_32bit_regs_p
649 || gdbarch_byte_order (gdbarch
) != BFD_ENDIAN_BIG
)
652 ax_simple (ax
, aop_lsh
);
655 ax_simple (ax
, aop_rsh_signed
);
659 internal_error (__FILE__
, __LINE__
, _("bad register size"));
664 /* Table to translate MIPS16 register field to actual register number. */
665 static int mips16_to_32_reg
[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
667 /* Heuristic_proc_start may hunt through the text section for a long
668 time across a 2400 baud serial line. Allows the user to limit this
671 static unsigned int heuristic_fence_post
= 0;
673 /* Number of bytes of storage in the actual machine representation for
674 register N. NOTE: This defines the pseudo register type so need to
675 rebuild the architecture vector. */
677 static int mips64_transfers_32bit_regs_p
= 0;
680 set_mips64_transfers_32bit_regs (char *args
, int from_tty
,
681 struct cmd_list_element
*c
)
683 struct gdbarch_info info
;
684 gdbarch_info_init (&info
);
685 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
686 instead of relying on globals. Doing that would let generic code
687 handle the search for this specific architecture. */
688 if (!gdbarch_update_p (info
))
690 mips64_transfers_32bit_regs_p
= 0;
691 error (_("32-bit compatibility mode not supported"));
695 /* Convert to/from a register and the corresponding memory value. */
697 /* This predicate tests for the case of an 8 byte floating point
698 value that is being transferred to or from a pair of floating point
699 registers each of which are (or are considered to be) only 4 bytes
702 mips_convert_register_float_case_p (struct gdbarch
*gdbarch
, int regnum
,
705 return (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
706 && register_size (gdbarch
, regnum
) == 4
707 && (regnum
% gdbarch_num_regs (gdbarch
))
708 >= mips_regnum (gdbarch
)->fp0
709 && (regnum
% gdbarch_num_regs (gdbarch
))
710 < mips_regnum (gdbarch
)->fp0
+ 32
711 && TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8);
714 /* This predicate tests for the case of a value of less than 8
715 bytes in width that is being transfered to or from an 8 byte
716 general purpose register. */
718 mips_convert_register_gpreg_case_p (struct gdbarch
*gdbarch
, int regnum
,
721 int num_regs
= gdbarch_num_regs (gdbarch
);
723 return (register_size (gdbarch
, regnum
) == 8
724 && regnum
% num_regs
> 0 && regnum
% num_regs
< 32
725 && TYPE_LENGTH (type
) < 8);
729 mips_convert_register_p (struct gdbarch
*gdbarch
,
730 int regnum
, struct type
*type
)
732 return mips_convert_register_float_case_p (gdbarch
, regnum
, type
)
733 || mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
);
737 mips_register_to_value (struct frame_info
*frame
, int regnum
,
738 struct type
*type
, gdb_byte
*to
)
740 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
742 if (mips_convert_register_float_case_p (gdbarch
, regnum
, type
))
744 get_frame_register (frame
, regnum
+ 0, to
+ 4);
745 get_frame_register (frame
, regnum
+ 1, to
+ 0);
747 else if (mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
))
749 int len
= TYPE_LENGTH (type
);
750 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
751 get_frame_register_bytes (frame
, regnum
, 8 - len
, len
, to
);
753 get_frame_register_bytes (frame
, regnum
, 0, len
, to
);
757 internal_error (__FILE__
, __LINE__
,
758 _("mips_register_to_value: unrecognized case"));
763 mips_value_to_register (struct frame_info
*frame
, int regnum
,
764 struct type
*type
, const gdb_byte
*from
)
766 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
768 if (mips_convert_register_float_case_p (gdbarch
, regnum
, type
))
770 put_frame_register (frame
, regnum
+ 0, from
+ 4);
771 put_frame_register (frame
, regnum
+ 1, from
+ 0);
773 else if (mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
))
776 int len
= TYPE_LENGTH (type
);
778 /* Sign extend values, irrespective of type, that are stored to
779 a 64-bit general purpose register. (32-bit unsigned values
780 are stored as signed quantities within a 64-bit register.
781 When performing an operation, in compiled code, that combines
782 a 32-bit unsigned value with a signed 64-bit value, a type
783 conversion is first performed that zeroes out the high 32 bits.) */
784 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
787 store_signed_integer (fill
, 8, BFD_ENDIAN_BIG
, -1);
789 store_signed_integer (fill
, 8, BFD_ENDIAN_BIG
, 0);
790 put_frame_register_bytes (frame
, regnum
, 0, 8 - len
, fill
);
791 put_frame_register_bytes (frame
, regnum
, 8 - len
, len
, from
);
795 if (from
[len
-1] & 0x80)
796 store_signed_integer (fill
, 8, BFD_ENDIAN_LITTLE
, -1);
798 store_signed_integer (fill
, 8, BFD_ENDIAN_LITTLE
, 0);
799 put_frame_register_bytes (frame
, regnum
, 0, len
, from
);
800 put_frame_register_bytes (frame
, regnum
, len
, 8 - len
, fill
);
805 internal_error (__FILE__
, __LINE__
,
806 _("mips_value_to_register: unrecognized case"));
810 /* Return the GDB type object for the "standard" data type of data in
814 mips_register_type (struct gdbarch
*gdbarch
, int regnum
)
816 gdb_assert (regnum
>= 0 && regnum
< 2 * gdbarch_num_regs (gdbarch
));
817 if ((regnum
% gdbarch_num_regs (gdbarch
)) >= mips_regnum (gdbarch
)->fp0
818 && (regnum
% gdbarch_num_regs (gdbarch
))
819 < mips_regnum (gdbarch
)->fp0
+ 32)
821 /* The floating-point registers raw, or cooked, always match
822 mips_isa_regsize(), and also map 1:1, byte for byte. */
823 if (mips_isa_regsize (gdbarch
) == 4)
824 return builtin_type (gdbarch
)->builtin_float
;
826 return builtin_type (gdbarch
)->builtin_double
;
828 else if (regnum
< gdbarch_num_regs (gdbarch
))
830 /* The raw or ISA registers. These are all sized according to
832 if (mips_isa_regsize (gdbarch
) == 4)
833 return builtin_type (gdbarch
)->builtin_int32
;
835 return builtin_type (gdbarch
)->builtin_int64
;
839 /* The cooked or ABI registers. These are sized according to
840 the ABI (with a few complications). */
841 if (regnum
>= (gdbarch_num_regs (gdbarch
)
842 + mips_regnum (gdbarch
)->fp_control_status
)
843 && regnum
<= gdbarch_num_regs (gdbarch
) + MIPS_LAST_EMBED_REGNUM
)
844 /* The pseudo/cooked view of the embedded registers is always
845 32-bit. The raw view is handled below. */
846 return builtin_type (gdbarch
)->builtin_int32
;
847 else if (gdbarch_tdep (gdbarch
)->mips64_transfers_32bit_regs_p
)
848 /* The target, while possibly using a 64-bit register buffer,
849 is only transfering 32-bits of each integer register.
850 Reflect this in the cooked/pseudo (ABI) register value. */
851 return builtin_type (gdbarch
)->builtin_int32
;
852 else if (mips_abi_regsize (gdbarch
) == 4)
853 /* The ABI is restricted to 32-bit registers (the ISA could be
855 return builtin_type (gdbarch
)->builtin_int32
;
858 return builtin_type (gdbarch
)->builtin_int64
;
862 /* Return the GDB type for the pseudo register REGNUM, which is the
863 ABI-level view. This function is only called if there is a target
864 description which includes registers, so we know precisely the
865 types of hardware registers. */
868 mips_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
870 const int num_regs
= gdbarch_num_regs (gdbarch
);
871 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
872 int rawnum
= regnum
% num_regs
;
873 struct type
*rawtype
;
875 gdb_assert (regnum
>= num_regs
&& regnum
< 2 * num_regs
);
877 /* Absent registers are still absent. */
878 rawtype
= gdbarch_register_type (gdbarch
, rawnum
);
879 if (TYPE_LENGTH (rawtype
) == 0)
882 if (rawnum
>= MIPS_EMBED_FP0_REGNUM
&& rawnum
< MIPS_EMBED_FP0_REGNUM
+ 32)
883 /* Present the floating point registers however the hardware did;
884 do not try to convert between FPU layouts. */
887 if (rawnum
>= MIPS_EMBED_FP0_REGNUM
+ 32 && rawnum
<= MIPS_LAST_EMBED_REGNUM
)
889 /* The pseudo/cooked view of embedded registers is always
890 32-bit, even if the target transfers 64-bit values for them.
891 New targets relying on XML descriptions should only transfer
892 the necessary 32 bits, but older versions of GDB expected 64,
893 so allow the target to provide 64 bits without interfering
894 with the displayed type. */
895 return builtin_type (gdbarch
)->builtin_int32
;
898 /* Use pointer types for registers if we can. For n32 we can not,
899 since we do not have a 64-bit pointer type. */
900 if (mips_abi_regsize (gdbarch
)
901 == TYPE_LENGTH (builtin_type (gdbarch
)->builtin_data_ptr
))
903 if (rawnum
== MIPS_SP_REGNUM
|| rawnum
== MIPS_EMBED_BADVADDR_REGNUM
)
904 return builtin_type (gdbarch
)->builtin_data_ptr
;
905 else if (rawnum
== MIPS_EMBED_PC_REGNUM
)
906 return builtin_type (gdbarch
)->builtin_func_ptr
;
909 if (mips_abi_regsize (gdbarch
) == 4 && TYPE_LENGTH (rawtype
) == 8
910 && rawnum
>= MIPS_ZERO_REGNUM
&& rawnum
<= MIPS_EMBED_PC_REGNUM
)
911 return builtin_type (gdbarch
)->builtin_int32
;
913 /* For all other registers, pass through the hardware type. */
917 /* Should the upper word of 64-bit addresses be zeroed? */
918 enum auto_boolean mask_address_var
= AUTO_BOOLEAN_AUTO
;
921 mips_mask_address_p (struct gdbarch_tdep
*tdep
)
923 switch (mask_address_var
)
925 case AUTO_BOOLEAN_TRUE
:
927 case AUTO_BOOLEAN_FALSE
:
930 case AUTO_BOOLEAN_AUTO
:
931 return tdep
->default_mask_address_p
;
933 internal_error (__FILE__
, __LINE__
,
934 _("mips_mask_address_p: bad switch"));
940 show_mask_address (struct ui_file
*file
, int from_tty
,
941 struct cmd_list_element
*c
, const char *value
)
943 struct gdbarch_tdep
*tdep
= gdbarch_tdep (target_gdbarch
);
945 deprecated_show_value_hack (file
, from_tty
, c
, value
);
946 switch (mask_address_var
)
948 case AUTO_BOOLEAN_TRUE
:
949 printf_filtered ("The 32 bit mips address mask is enabled\n");
951 case AUTO_BOOLEAN_FALSE
:
952 printf_filtered ("The 32 bit mips address mask is disabled\n");
954 case AUTO_BOOLEAN_AUTO
:
956 ("The 32 bit address mask is set automatically. Currently %s\n",
957 mips_mask_address_p (tdep
) ? "enabled" : "disabled");
960 internal_error (__FILE__
, __LINE__
, _("show_mask_address: bad switch"));
965 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
968 mips_pc_is_mips16 (CORE_ADDR memaddr
)
970 struct minimal_symbol
*sym
;
972 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
973 if (is_mips16_addr (memaddr
))
976 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
977 the high bit of the info field. Use this to decide if the function is
978 MIPS16 or normal MIPS. */
979 sym
= lookup_minimal_symbol_by_pc (memaddr
);
981 return msymbol_is_special (sym
);
986 /* MIPS believes that the PC has a sign extended value. Perhaps the
987 all registers should be sign extended for simplicity? */
990 mips_read_pc (struct regcache
*regcache
)
993 int regnum
= mips_regnum (get_regcache_arch (regcache
))->pc
;
994 regcache_cooked_read_signed (regcache
, regnum
, &pc
);
995 if (is_mips16_addr (pc
))
996 pc
= unmake_mips16_addr (pc
);
1001 mips_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1005 pc
= frame_unwind_register_signed
1006 (next_frame
, gdbarch_num_regs (gdbarch
) + mips_regnum (gdbarch
)->pc
);
1007 if (is_mips16_addr (pc
))
1008 pc
= unmake_mips16_addr (pc
);
1013 mips_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1015 return frame_unwind_register_signed
1016 (next_frame
, gdbarch_num_regs (gdbarch
) + MIPS_SP_REGNUM
);
1019 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
1020 dummy frame. The frame ID's base needs to match the TOS value
1021 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
1024 static struct frame_id
1025 mips_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
1027 return frame_id_build
1028 (get_frame_register_signed (this_frame
,
1029 gdbarch_num_regs (gdbarch
)
1031 get_frame_pc (this_frame
));
1035 mips_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1037 int regnum
= mips_regnum (get_regcache_arch (regcache
))->pc
;
1038 if (mips_pc_is_mips16 (pc
))
1039 regcache_cooked_write_unsigned (regcache
, regnum
, make_mips16_addr (pc
));
1041 regcache_cooked_write_unsigned (regcache
, regnum
, pc
);
1044 /* Fetch and return instruction from the specified location. If the PC
1045 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
1048 mips_fetch_instruction (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1050 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1051 gdb_byte buf
[MIPS_INSN32_SIZE
];
1055 if (mips_pc_is_mips16 (addr
))
1057 instlen
= MIPS_INSN16_SIZE
;
1058 addr
= unmake_mips16_addr (addr
);
1061 instlen
= MIPS_INSN32_SIZE
;
1062 status
= target_read_memory (addr
, buf
, instlen
);
1064 memory_error (status
, addr
);
1065 return extract_unsigned_integer (buf
, instlen
, byte_order
);
1068 /* These are the fields of 32 bit mips instructions. */
1069 #define mips32_op(x) (x >> 26)
1070 #define itype_op(x) (x >> 26)
1071 #define itype_rs(x) ((x >> 21) & 0x1f)
1072 #define itype_rt(x) ((x >> 16) & 0x1f)
1073 #define itype_immediate(x) (x & 0xffff)
1075 #define jtype_op(x) (x >> 26)
1076 #define jtype_target(x) (x & 0x03ffffff)
1078 #define rtype_op(x) (x >> 26)
1079 #define rtype_rs(x) ((x >> 21) & 0x1f)
1080 #define rtype_rt(x) ((x >> 16) & 0x1f)
1081 #define rtype_rd(x) ((x >> 11) & 0x1f)
1082 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1083 #define rtype_funct(x) (x & 0x3f)
1086 mips32_relative_offset (ULONGEST inst
)
1088 return ((itype_immediate (inst
) ^ 0x8000) - 0x8000) << 2;
1091 /* Determine where to set a single step breakpoint while considering
1092 branch prediction. */
1094 mips32_next_pc (struct frame_info
*frame
, CORE_ADDR pc
)
1096 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1099 inst
= mips_fetch_instruction (gdbarch
, pc
);
1100 if ((inst
& 0xe0000000) != 0) /* Not a special, jump or branch
1103 if (itype_op (inst
) >> 2 == 5)
1104 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1106 op
= (itype_op (inst
) & 0x03);
1116 goto greater_branch
;
1121 else if (itype_op (inst
) == 17 && itype_rs (inst
) == 8)
1122 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1124 int tf
= itype_rt (inst
) & 0x01;
1125 int cnum
= itype_rt (inst
) >> 2;
1127 get_frame_register_signed (frame
,
1128 mips_regnum (get_frame_arch (frame
))->
1130 int cond
= ((fcrcs
>> 24) & 0x0e) | ((fcrcs
>> 23) & 0x01);
1132 if (((cond
>> cnum
) & 0x01) == tf
)
1133 pc
+= mips32_relative_offset (inst
) + 4;
1138 pc
+= 4; /* Not a branch, next instruction is easy. */
1141 { /* This gets way messy. */
1143 /* Further subdivide into SPECIAL, REGIMM and other. */
1144 switch (op
= itype_op (inst
) & 0x07) /* Extract bits 28,27,26. */
1146 case 0: /* SPECIAL */
1147 op
= rtype_funct (inst
);
1152 /* Set PC to that address. */
1153 pc
= get_frame_register_signed (frame
, rtype_rs (inst
));
1155 case 12: /* SYSCALL */
1157 struct gdbarch_tdep
*tdep
;
1159 tdep
= gdbarch_tdep (get_frame_arch (frame
));
1160 if (tdep
->syscall_next_pc
!= NULL
)
1161 pc
= tdep
->syscall_next_pc (frame
);
1170 break; /* end SPECIAL */
1171 case 1: /* REGIMM */
1173 op
= itype_rt (inst
); /* branch condition */
1178 case 16: /* BLTZAL */
1179 case 18: /* BLTZALL */
1181 if (get_frame_register_signed (frame
, itype_rs (inst
)) < 0)
1182 pc
+= mips32_relative_offset (inst
) + 4;
1184 pc
+= 8; /* after the delay slot */
1188 case 17: /* BGEZAL */
1189 case 19: /* BGEZALL */
1190 if (get_frame_register_signed (frame
, itype_rs (inst
)) >= 0)
1191 pc
+= mips32_relative_offset (inst
) + 4;
1193 pc
+= 8; /* after the delay slot */
1195 /* All of the other instructions in the REGIMM category */
1200 break; /* end REGIMM */
1205 reg
= jtype_target (inst
) << 2;
1206 /* Upper four bits get never changed... */
1207 pc
= reg
+ ((pc
+ 4) & ~(CORE_ADDR
) 0x0fffffff);
1210 /* FIXME case JALX : */
1213 reg
= jtype_target (inst
) << 2;
1214 pc
= reg
+ ((pc
+ 4) & ~(CORE_ADDR
) 0x0fffffff) + 1; /* yes, +1 */
1215 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1217 break; /* The new PC will be alternate mode */
1218 case 4: /* BEQ, BEQL */
1220 if (get_frame_register_signed (frame
, itype_rs (inst
)) ==
1221 get_frame_register_signed (frame
, itype_rt (inst
)))
1222 pc
+= mips32_relative_offset (inst
) + 4;
1226 case 5: /* BNE, BNEL */
1228 if (get_frame_register_signed (frame
, itype_rs (inst
)) !=
1229 get_frame_register_signed (frame
, itype_rt (inst
)))
1230 pc
+= mips32_relative_offset (inst
) + 4;
1234 case 6: /* BLEZ, BLEZL */
1235 if (get_frame_register_signed (frame
, itype_rs (inst
)) <= 0)
1236 pc
+= mips32_relative_offset (inst
) + 4;
1242 greater_branch
: /* BGTZ, BGTZL */
1243 if (get_frame_register_signed (frame
, itype_rs (inst
)) > 0)
1244 pc
+= mips32_relative_offset (inst
) + 4;
1251 } /* mips32_next_pc */
1253 /* Decoding the next place to set a breakpoint is irregular for the
1254 mips 16 variant, but fortunately, there fewer instructions. We have
1255 to cope ith extensions for 16 bit instructions and a pair of actual
1256 32 bit instructions. We dont want to set a single step instruction
1257 on the extend instruction either. */
1259 /* Lots of mips16 instruction formats */
1260 /* Predicting jumps requires itype,ritype,i8type
1261 and their extensions extItype,extritype,extI8type. */
1262 enum mips16_inst_fmts
1264 itype
, /* 0 immediate 5,10 */
1265 ritype
, /* 1 5,3,8 */
1266 rrtype
, /* 2 5,3,3,5 */
1267 rritype
, /* 3 5,3,3,5 */
1268 rrrtype
, /* 4 5,3,3,3,2 */
1269 rriatype
, /* 5 5,3,3,1,4 */
1270 shifttype
, /* 6 5,3,3,3,2 */
1271 i8type
, /* 7 5,3,8 */
1272 i8movtype
, /* 8 5,3,3,5 */
1273 i8mov32rtype
, /* 9 5,3,5,3 */
1274 i64type
, /* 10 5,3,8 */
1275 ri64type
, /* 11 5,3,3,5 */
1276 jalxtype
, /* 12 5,1,5,5,16 - a 32 bit instruction */
1277 exiItype
, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1278 extRitype
, /* 14 5,6,5,5,3,1,1,1,5 */
1279 extRRItype
, /* 15 5,5,5,5,3,3,5 */
1280 extRRIAtype
, /* 16 5,7,4,5,3,3,1,4 */
1281 EXTshifttype
, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1282 extI8type
, /* 18 5,6,5,5,3,1,1,1,5 */
1283 extI64type
, /* 19 5,6,5,5,3,1,1,1,5 */
1284 extRi64type
, /* 20 5,6,5,5,3,3,5 */
1285 extshift64type
/* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1287 /* I am heaping all the fields of the formats into one structure and
1288 then, only the fields which are involved in instruction extension. */
1292 unsigned int regx
; /* Function in i8 type. */
1297 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1298 for the bits which make up the immediate extension. */
1301 extended_offset (unsigned int extension
)
1304 value
= (extension
>> 21) & 0x3f; /* * extract 15:11 */
1306 value
|= (extension
>> 16) & 0x1f; /* extract 10:5 */
1308 value
|= extension
& 0x01f; /* extract 4:0 */
1312 /* Only call this function if you know that this is an extendable
1313 instruction. It won't malfunction, but why make excess remote memory
1314 references? If the immediate operands get sign extended or something,
1315 do it after the extension is performed. */
1316 /* FIXME: Every one of these cases needs to worry about sign extension
1317 when the offset is to be used in relative addressing. */
1320 fetch_mips_16 (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1322 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1324 pc
&= 0xfffffffe; /* Clear the low order bit. */
1325 target_read_memory (pc
, buf
, 2);
1326 return extract_unsigned_integer (buf
, 2, byte_order
);
1330 unpack_mips16 (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1331 unsigned int extension
,
1333 enum mips16_inst_fmts insn_format
, struct upk_mips16
*upk
)
1338 switch (insn_format
)
1345 value
= extended_offset (extension
);
1346 value
= value
<< 11; /* rom for the original value */
1347 value
|= inst
& 0x7ff; /* eleven bits from instruction */
1351 value
= inst
& 0x7ff;
1352 /* FIXME : Consider sign extension. */
1361 { /* A register identifier and an offset. */
1362 /* Most of the fields are the same as I type but the
1363 immediate value is of a different length. */
1367 value
= extended_offset (extension
);
1368 value
= value
<< 8; /* from the original instruction */
1369 value
|= inst
& 0xff; /* eleven bits from instruction */
1370 regx
= (extension
>> 8) & 0x07; /* or i8 funct */
1371 if (value
& 0x4000) /* Test the sign bit, bit 26. */
1373 value
&= ~0x3fff; /* Remove the sign bit. */
1379 value
= inst
& 0xff; /* 8 bits */
1380 regx
= (inst
>> 8) & 0x07; /* or i8 funct */
1381 /* FIXME: Do sign extension, this format needs it. */
1382 if (value
& 0x80) /* THIS CONFUSES ME. */
1384 value
&= 0xef; /* Remove the sign bit. */
1394 unsigned long value
;
1395 unsigned int nexthalf
;
1396 value
= ((inst
& 0x1f) << 5) | ((inst
>> 5) & 0x1f);
1397 value
= value
<< 16;
1398 nexthalf
= mips_fetch_instruction (gdbarch
, pc
+ 2); /* low bit
1407 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1409 upk
->offset
= offset
;
1416 add_offset_16 (CORE_ADDR pc
, int offset
)
1418 return ((offset
<< 2) | ((pc
+ 2) & (~(CORE_ADDR
) 0x0fffffff)));
1422 extended_mips16_next_pc (struct frame_info
*frame
, CORE_ADDR pc
,
1423 unsigned int extension
, unsigned int insn
)
1425 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1426 int op
= (insn
>> 11);
1429 case 2: /* Branch */
1432 struct upk_mips16 upk
;
1433 unpack_mips16 (gdbarch
, pc
, extension
, insn
, itype
, &upk
);
1434 offset
= upk
.offset
;
1440 pc
+= (offset
<< 1) + 2;
1443 case 3: /* JAL , JALX - Watch out, these are 32 bit
1446 struct upk_mips16 upk
;
1447 unpack_mips16 (gdbarch
, pc
, extension
, insn
, jalxtype
, &upk
);
1448 pc
= add_offset_16 (pc
, upk
.offset
);
1449 if ((insn
>> 10) & 0x01) /* Exchange mode */
1450 pc
= pc
& ~0x01; /* Clear low bit, indicate 32 bit mode. */
1457 struct upk_mips16 upk
;
1459 unpack_mips16 (gdbarch
, pc
, extension
, insn
, ritype
, &upk
);
1460 reg
= get_frame_register_signed (frame
, upk
.regx
);
1462 pc
+= (upk
.offset
<< 1) + 2;
1469 struct upk_mips16 upk
;
1471 unpack_mips16 (gdbarch
, pc
, extension
, insn
, ritype
, &upk
);
1472 reg
= get_frame_register_signed (frame
, upk
.regx
);
1474 pc
+= (upk
.offset
<< 1) + 2;
1479 case 12: /* I8 Formats btez btnez */
1481 struct upk_mips16 upk
;
1483 unpack_mips16 (gdbarch
, pc
, extension
, insn
, i8type
, &upk
);
1484 /* upk.regx contains the opcode */
1485 reg
= get_frame_register_signed (frame
, 24); /* Test register is 24 */
1486 if (((upk
.regx
== 0) && (reg
== 0)) /* BTEZ */
1487 || ((upk
.regx
== 1) && (reg
!= 0))) /* BTNEZ */
1488 /* pc = add_offset_16(pc,upk.offset) ; */
1489 pc
+= (upk
.offset
<< 1) + 2;
1494 case 29: /* RR Formats JR, JALR, JALR-RA */
1496 struct upk_mips16 upk
;
1497 /* upk.fmt = rrtype; */
1502 upk
.regx
= (insn
>> 8) & 0x07;
1503 upk
.regy
= (insn
>> 5) & 0x07;
1511 break; /* Function return instruction. */
1517 break; /* BOGUS Guess */
1519 pc
= get_frame_register_signed (frame
, reg
);
1526 /* This is an instruction extension. Fetch the real instruction
1527 (which follows the extension) and decode things based on
1531 pc
= extended_mips16_next_pc (frame
, pc
, insn
,
1532 fetch_mips_16 (gdbarch
, pc
));
1545 mips16_next_pc (struct frame_info
*frame
, CORE_ADDR pc
)
1547 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1548 unsigned int insn
= fetch_mips_16 (gdbarch
, pc
);
1549 return extended_mips16_next_pc (frame
, pc
, 0, insn
);
1552 /* The mips_next_pc function supports single_step when the remote
1553 target monitor or stub is not developed enough to do a single_step.
1554 It works by decoding the current instruction and predicting where a
1555 branch will go. This isnt hard because all the data is available.
1556 The MIPS32 and MIPS16 variants are quite different. */
1558 mips_next_pc (struct frame_info
*frame
, CORE_ADDR pc
)
1560 if (is_mips16_addr (pc
))
1561 return mips16_next_pc (frame
, pc
);
1563 return mips32_next_pc (frame
, pc
);
1566 struct mips_frame_cache
1569 struct trad_frame_saved_reg
*saved_regs
;
1572 /* Set a register's saved stack address in temp_saved_regs. If an
1573 address has already been set for this register, do nothing; this
1574 way we will only recognize the first save of a given register in a
1577 For simplicity, save the address in both [0 .. gdbarch_num_regs) and
1578 [gdbarch_num_regs .. 2*gdbarch_num_regs).
1579 Strictly speaking, only the second range is used as it is only second
1580 range (the ABI instead of ISA registers) that comes into play when finding
1581 saved registers in a frame. */
1584 set_reg_offset (struct gdbarch
*gdbarch
, struct mips_frame_cache
*this_cache
,
1585 int regnum
, CORE_ADDR offset
)
1587 if (this_cache
!= NULL
1588 && this_cache
->saved_regs
[regnum
].addr
== -1)
1590 this_cache
->saved_regs
[regnum
+ 0 * gdbarch_num_regs (gdbarch
)].addr
1592 this_cache
->saved_regs
[regnum
+ 1 * gdbarch_num_regs (gdbarch
)].addr
1598 /* Fetch the immediate value from a MIPS16 instruction.
1599 If the previous instruction was an EXTEND, use it to extend
1600 the upper bits of the immediate value. This is a helper function
1601 for mips16_scan_prologue. */
1604 mips16_get_imm (unsigned short prev_inst
, /* previous instruction */
1605 unsigned short inst
, /* current instruction */
1606 int nbits
, /* number of bits in imm field */
1607 int scale
, /* scale factor to be applied to imm */
1608 int is_signed
) /* is the imm field signed? */
1612 if ((prev_inst
& 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1614 offset
= ((prev_inst
& 0x1f) << 11) | (prev_inst
& 0x7e0);
1615 if (offset
& 0x8000) /* check for negative extend */
1616 offset
= 0 - (0x10000 - (offset
& 0xffff));
1617 return offset
| (inst
& 0x1f);
1621 int max_imm
= 1 << nbits
;
1622 int mask
= max_imm
- 1;
1623 int sign_bit
= max_imm
>> 1;
1625 offset
= inst
& mask
;
1626 if (is_signed
&& (offset
& sign_bit
))
1627 offset
= 0 - (max_imm
- offset
);
1628 return offset
* scale
;
1633 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1634 the associated FRAME_CACHE if not null.
1635 Return the address of the first instruction past the prologue. */
1638 mips16_scan_prologue (struct gdbarch
*gdbarch
,
1639 CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
1640 struct frame_info
*this_frame
,
1641 struct mips_frame_cache
*this_cache
)
1644 CORE_ADDR frame_addr
= 0; /* Value of $r17, used as frame pointer. */
1646 long frame_offset
= 0; /* Size of stack frame. */
1647 long frame_adjust
= 0; /* Offset of FP from SP. */
1648 int frame_reg
= MIPS_SP_REGNUM
;
1649 unsigned short prev_inst
= 0; /* saved copy of previous instruction. */
1650 unsigned inst
= 0; /* current instruction */
1651 unsigned entry_inst
= 0; /* the entry instruction */
1652 unsigned save_inst
= 0; /* the save instruction */
1655 int extend_bytes
= 0;
1656 int prev_extend_bytes
;
1657 CORE_ADDR end_prologue_addr
= 0;
1659 /* Can be called when there's no process, and hence when there's no
1661 if (this_frame
!= NULL
)
1662 sp
= get_frame_register_signed (this_frame
,
1663 gdbarch_num_regs (gdbarch
)
1668 if (limit_pc
> start_pc
+ 200)
1669 limit_pc
= start_pc
+ 200;
1671 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS_INSN16_SIZE
)
1673 /* Save the previous instruction. If it's an EXTEND, we'll extract
1674 the immediate offset extension from it in mips16_get_imm. */
1677 /* Fetch and decode the instruction. */
1678 inst
= (unsigned short) mips_fetch_instruction (gdbarch
, cur_pc
);
1680 /* Normally we ignore extend instructions. However, if it is
1681 not followed by a valid prologue instruction, then this
1682 instruction is not part of the prologue either. We must
1683 remember in this case to adjust the end_prologue_addr back
1685 if ((inst
& 0xf800) == 0xf000) /* extend */
1687 extend_bytes
= MIPS_INSN16_SIZE
;
1691 prev_extend_bytes
= extend_bytes
;
1694 if ((inst
& 0xff00) == 0x6300 /* addiu sp */
1695 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
1697 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 1);
1698 if (offset
< 0) /* Negative stack adjustment? */
1699 frame_offset
-= offset
;
1701 /* Exit loop if a positive stack adjustment is found, which
1702 usually means that the stack cleanup code in the function
1703 epilogue is reached. */
1706 else if ((inst
& 0xf800) == 0xd000) /* sw reg,n($sp) */
1708 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
1709 reg
= mips16_to_32_reg
[(inst
& 0x700) >> 8];
1710 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1712 else if ((inst
& 0xff00) == 0xf900) /* sd reg,n($sp) */
1714 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
1715 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
1716 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1718 else if ((inst
& 0xff00) == 0x6200) /* sw $ra,n($sp) */
1720 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
1721 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
1723 else if ((inst
& 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1725 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 0);
1726 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
1728 else if (inst
== 0x673d) /* move $s1, $sp */
1733 else if ((inst
& 0xff00) == 0x0100) /* addiu $s1,sp,n */
1735 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
1736 frame_addr
= sp
+ offset
;
1738 frame_adjust
= offset
;
1740 else if ((inst
& 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1742 offset
= mips16_get_imm (prev_inst
, inst
, 5, 4, 0);
1743 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
1744 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ offset
);
1746 else if ((inst
& 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1748 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
1749 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
1750 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ offset
);
1752 else if ((inst
& 0xf81f) == 0xe809
1753 && (inst
& 0x700) != 0x700) /* entry */
1754 entry_inst
= inst
; /* Save for later processing. */
1755 else if ((inst
& 0xff80) == 0x6480) /* save */
1757 save_inst
= inst
; /* Save for later processing. */
1758 if (prev_extend_bytes
) /* extend */
1759 save_inst
|= prev_inst
<< 16;
1761 else if ((inst
& 0xf800) == 0x1800) /* jal(x) */
1762 cur_pc
+= MIPS_INSN16_SIZE
; /* 32-bit instruction */
1763 else if ((inst
& 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
1765 /* This instruction is part of the prologue, but we don't
1766 need to do anything special to handle it. */
1770 /* This instruction is not an instruction typically found
1771 in a prologue, so we must have reached the end of the
1773 if (end_prologue_addr
== 0)
1774 end_prologue_addr
= cur_pc
- prev_extend_bytes
;
1778 /* The entry instruction is typically the first instruction in a function,
1779 and it stores registers at offsets relative to the value of the old SP
1780 (before the prologue). But the value of the sp parameter to this
1781 function is the new SP (after the prologue has been executed). So we
1782 can't calculate those offsets until we've seen the entire prologue,
1783 and can calculate what the old SP must have been. */
1784 if (entry_inst
!= 0)
1786 int areg_count
= (entry_inst
>> 8) & 7;
1787 int sreg_count
= (entry_inst
>> 6) & 3;
1789 /* The entry instruction always subtracts 32 from the SP. */
1792 /* Now we can calculate what the SP must have been at the
1793 start of the function prologue. */
1796 /* Check if a0-a3 were saved in the caller's argument save area. */
1797 for (reg
= 4, offset
= 0; reg
< areg_count
+ 4; reg
++)
1799 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1800 offset
+= mips_abi_regsize (gdbarch
);
1803 /* Check if the ra register was pushed on the stack. */
1805 if (entry_inst
& 0x20)
1807 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
1808 offset
-= mips_abi_regsize (gdbarch
);
1811 /* Check if the s0 and s1 registers were pushed on the stack. */
1812 for (reg
= 16; reg
< sreg_count
+ 16; reg
++)
1814 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1815 offset
-= mips_abi_regsize (gdbarch
);
1819 /* The SAVE instruction is similar to ENTRY, except that defined by the
1820 MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
1821 size of the frame is specified as an immediate field of instruction
1822 and an extended variation exists which lets additional registers and
1823 frame space to be specified. The instruction always treats registers
1824 as 32-bit so its usefulness for 64-bit ABIs is questionable. */
1825 if (save_inst
!= 0 && mips_abi_regsize (gdbarch
) == 4)
1827 static int args_table
[16] = {
1828 0, 0, 0, 0, 1, 1, 1, 1,
1829 2, 2, 2, 0, 3, 3, 4, -1,
1831 static int astatic_table
[16] = {
1832 0, 1, 2, 3, 0, 1, 2, 3,
1833 0, 1, 2, 4, 0, 1, 0, -1,
1835 int aregs
= (save_inst
>> 16) & 0xf;
1836 int xsregs
= (save_inst
>> 24) & 0x7;
1837 int args
= args_table
[aregs
];
1838 int astatic
= astatic_table
[aregs
];
1843 warning (_("Invalid number of argument registers encoded in SAVE."));
1848 warning (_("Invalid number of static registers encoded in SAVE."));
1852 /* For standard SAVE the frame size of 0 means 128. */
1853 frame_size
= ((save_inst
>> 16) & 0xf0) | (save_inst
& 0xf);
1854 if (frame_size
== 0 && (save_inst
>> 16) == 0)
1857 frame_offset
+= frame_size
;
1859 /* Now we can calculate what the SP must have been at the
1860 start of the function prologue. */
1863 /* Check if A0-A3 were saved in the caller's argument save area. */
1864 for (reg
= MIPS_A0_REGNUM
, offset
= 0; reg
< args
+ 4; reg
++)
1866 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1867 offset
+= mips_abi_regsize (gdbarch
);
1872 /* Check if the RA register was pushed on the stack. */
1873 if (save_inst
& 0x40)
1875 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
1876 offset
-= mips_abi_regsize (gdbarch
);
1879 /* Check if the S8 register was pushed on the stack. */
1882 set_reg_offset (gdbarch
, this_cache
, 30, sp
+ offset
);
1883 offset
-= mips_abi_regsize (gdbarch
);
1886 /* Check if S2-S7 were pushed on the stack. */
1887 for (reg
= 18 + xsregs
- 1; reg
> 18 - 1; reg
--)
1889 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1890 offset
-= mips_abi_regsize (gdbarch
);
1893 /* Check if the S1 register was pushed on the stack. */
1894 if (save_inst
& 0x10)
1896 set_reg_offset (gdbarch
, this_cache
, 17, sp
+ offset
);
1897 offset
-= mips_abi_regsize (gdbarch
);
1899 /* Check if the S0 register was pushed on the stack. */
1900 if (save_inst
& 0x20)
1902 set_reg_offset (gdbarch
, this_cache
, 16, sp
+ offset
);
1903 offset
-= mips_abi_regsize (gdbarch
);
1906 /* Check if A0-A3 were pushed on the stack. */
1907 for (reg
= MIPS_A0_REGNUM
+ 3; reg
> MIPS_A0_REGNUM
+ 3 - astatic
; reg
--)
1909 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
1910 offset
-= mips_abi_regsize (gdbarch
);
1914 if (this_cache
!= NULL
)
1917 (get_frame_register_signed (this_frame
,
1918 gdbarch_num_regs (gdbarch
) + frame_reg
)
1919 + frame_offset
- frame_adjust
);
1920 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
1921 be able to get rid of the assignment below, evetually. But it's
1922 still needed for now. */
1923 this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
1924 + mips_regnum (gdbarch
)->pc
]
1925 = this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
) + MIPS_RA_REGNUM
];
1928 /* If we didn't reach the end of the prologue when scanning the function
1929 instructions, then set end_prologue_addr to the address of the
1930 instruction immediately after the last one we scanned. */
1931 if (end_prologue_addr
== 0)
1932 end_prologue_addr
= cur_pc
;
1934 return end_prologue_addr
;
1937 /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
1938 Procedures that use the 32-bit instruction set are handled by the
1939 mips_insn32 unwinder. */
1941 static struct mips_frame_cache
*
1942 mips_insn16_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
1944 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1945 struct mips_frame_cache
*cache
;
1947 if ((*this_cache
) != NULL
)
1948 return (*this_cache
);
1949 cache
= FRAME_OBSTACK_ZALLOC (struct mips_frame_cache
);
1950 (*this_cache
) = cache
;
1951 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1953 /* Analyze the function prologue. */
1955 const CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
1956 CORE_ADDR start_addr
;
1958 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
1959 if (start_addr
== 0)
1960 start_addr
= heuristic_proc_start (gdbarch
, pc
);
1961 /* We can't analyze the prologue if we couldn't find the begining
1963 if (start_addr
== 0)
1966 mips16_scan_prologue (gdbarch
, start_addr
, pc
, this_frame
, *this_cache
);
1969 /* gdbarch_sp_regnum contains the value and not the address. */
1970 trad_frame_set_value (cache
->saved_regs
,
1971 gdbarch_num_regs (gdbarch
) + MIPS_SP_REGNUM
,
1974 return (*this_cache
);
1978 mips_insn16_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
1979 struct frame_id
*this_id
)
1981 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
1983 /* This marks the outermost frame. */
1984 if (info
->base
== 0)
1986 (*this_id
) = frame_id_build (info
->base
, get_frame_func (this_frame
));
1989 static struct value
*
1990 mips_insn16_frame_prev_register (struct frame_info
*this_frame
,
1991 void **this_cache
, int regnum
)
1993 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
1995 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
1999 mips_insn16_frame_sniffer (const struct frame_unwind
*self
,
2000 struct frame_info
*this_frame
, void **this_cache
)
2002 CORE_ADDR pc
= get_frame_pc (this_frame
);
2003 if (mips_pc_is_mips16 (pc
))
2008 static const struct frame_unwind mips_insn16_frame_unwind
=
2011 mips_insn16_frame_this_id
,
2012 mips_insn16_frame_prev_register
,
2014 mips_insn16_frame_sniffer
2018 mips_insn16_frame_base_address (struct frame_info
*this_frame
,
2021 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
2026 static const struct frame_base mips_insn16_frame_base
=
2028 &mips_insn16_frame_unwind
,
2029 mips_insn16_frame_base_address
,
2030 mips_insn16_frame_base_address
,
2031 mips_insn16_frame_base_address
2034 static const struct frame_base
*
2035 mips_insn16_frame_base_sniffer (struct frame_info
*this_frame
)
2037 CORE_ADDR pc
= get_frame_pc (this_frame
);
2038 if (mips_pc_is_mips16 (pc
))
2039 return &mips_insn16_frame_base
;
2044 /* Mark all the registers as unset in the saved_regs array
2045 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
2048 reset_saved_regs (struct gdbarch
*gdbarch
, struct mips_frame_cache
*this_cache
)
2050 if (this_cache
== NULL
|| this_cache
->saved_regs
== NULL
)
2054 const int num_regs
= gdbarch_num_regs (gdbarch
);
2057 for (i
= 0; i
< num_regs
; i
++)
2059 this_cache
->saved_regs
[i
].addr
= -1;
2064 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
2065 the associated FRAME_CACHE if not null.
2066 Return the address of the first instruction past the prologue. */
2069 mips32_scan_prologue (struct gdbarch
*gdbarch
,
2070 CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2071 struct frame_info
*this_frame
,
2072 struct mips_frame_cache
*this_cache
)
2075 CORE_ADDR frame_addr
= 0; /* Value of $r30. Used by gcc for
2079 int frame_reg
= MIPS_SP_REGNUM
;
2081 CORE_ADDR end_prologue_addr
= 0;
2082 int seen_sp_adjust
= 0;
2083 int load_immediate_bytes
= 0;
2084 int in_delay_slot
= 0;
2085 int regsize_is_64_bits
= (mips_abi_regsize (gdbarch
) == 8);
2087 /* Can be called when there's no process, and hence when there's no
2089 if (this_frame
!= NULL
)
2090 sp
= get_frame_register_signed (this_frame
,
2091 gdbarch_num_regs (gdbarch
)
2096 if (limit_pc
> start_pc
+ 200)
2097 limit_pc
= start_pc
+ 200;
2102 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS_INSN32_SIZE
)
2104 unsigned long inst
, high_word
, low_word
;
2107 /* Fetch the instruction. */
2108 inst
= (unsigned long) mips_fetch_instruction (gdbarch
, cur_pc
);
2110 /* Save some code by pre-extracting some useful fields. */
2111 high_word
= (inst
>> 16) & 0xffff;
2112 low_word
= inst
& 0xffff;
2113 reg
= high_word
& 0x1f;
2115 if (high_word
== 0x27bd /* addiu $sp,$sp,-i */
2116 || high_word
== 0x23bd /* addi $sp,$sp,-i */
2117 || high_word
== 0x67bd) /* daddiu $sp,$sp,-i */
2119 if (low_word
& 0x8000) /* Negative stack adjustment? */
2120 frame_offset
+= 0x10000 - low_word
;
2122 /* Exit loop if a positive stack adjustment is found, which
2123 usually means that the stack cleanup code in the function
2124 epilogue is reached. */
2128 else if (((high_word
& 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2129 && !regsize_is_64_bits
)
2131 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ low_word
);
2133 else if (((high_word
& 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2134 && regsize_is_64_bits
)
2136 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
2137 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ low_word
);
2139 else if (high_word
== 0x27be) /* addiu $30,$sp,size */
2141 /* Old gcc frame, r30 is virtual frame pointer. */
2142 if ((long) low_word
!= frame_offset
)
2143 frame_addr
= sp
+ low_word
;
2144 else if (this_frame
&& frame_reg
== MIPS_SP_REGNUM
)
2146 unsigned alloca_adjust
;
2149 frame_addr
= get_frame_register_signed
2150 (this_frame
, gdbarch_num_regs (gdbarch
) + 30);
2152 alloca_adjust
= (unsigned) (frame_addr
- (sp
+ low_word
));
2153 if (alloca_adjust
> 0)
2155 /* FP > SP + frame_size. This may be because of
2156 an alloca or somethings similar. Fix sp to
2157 "pre-alloca" value, and try again. */
2158 sp
+= alloca_adjust
;
2159 /* Need to reset the status of all registers. Otherwise,
2160 we will hit a guard that prevents the new address
2161 for each register to be recomputed during the second
2163 reset_saved_regs (gdbarch
, this_cache
);
2168 /* move $30,$sp. With different versions of gas this will be either
2169 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2170 Accept any one of these. */
2171 else if (inst
== 0x03A0F021 || inst
== 0x03a0f025 || inst
== 0x03a0f02d)
2173 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2174 if (this_frame
&& frame_reg
== MIPS_SP_REGNUM
)
2176 unsigned alloca_adjust
;
2179 frame_addr
= get_frame_register_signed
2180 (this_frame
, gdbarch_num_regs (gdbarch
) + 30);
2182 alloca_adjust
= (unsigned) (frame_addr
- sp
);
2183 if (alloca_adjust
> 0)
2185 /* FP > SP + frame_size. This may be because of
2186 an alloca or somethings similar. Fix sp to
2187 "pre-alloca" value, and try again. */
2189 /* Need to reset the status of all registers. Otherwise,
2190 we will hit a guard that prevents the new address
2191 for each register to be recomputed during the second
2193 reset_saved_regs (gdbarch
, this_cache
);
2198 else if ((high_word
& 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
2199 && !regsize_is_64_bits
)
2201 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ low_word
);
2203 else if ((high_word
& 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
2204 || (high_word
& 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
2205 || (inst
& 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
2206 || high_word
== 0x3c1c /* lui $gp,n */
2207 || high_word
== 0x279c /* addiu $gp,$gp,n */
2208 || inst
== 0x0399e021 /* addu $gp,$gp,$t9 */
2209 || inst
== 0x033ce021 /* addu $gp,$t9,$gp */
2212 /* These instructions are part of the prologue, but we don't
2213 need to do anything special to handle them. */
2215 /* The instructions below load $at or $t0 with an immediate
2216 value in preparation for a stack adjustment via
2217 subu $sp,$sp,[$at,$t0]. These instructions could also
2218 initialize a local variable, so we accept them only before
2219 a stack adjustment instruction was seen. */
2220 else if (!seen_sp_adjust
2221 && (high_word
== 0x3c01 /* lui $at,n */
2222 || high_word
== 0x3c08 /* lui $t0,n */
2223 || high_word
== 0x3421 /* ori $at,$at,n */
2224 || high_word
== 0x3508 /* ori $t0,$t0,n */
2225 || high_word
== 0x3401 /* ori $at,$zero,n */
2226 || high_word
== 0x3408 /* ori $t0,$zero,n */
2229 load_immediate_bytes
+= MIPS_INSN32_SIZE
; /* FIXME! */
2233 /* This instruction is not an instruction typically found
2234 in a prologue, so we must have reached the end of the
2236 /* FIXME: brobecker/2004-10-10: Can't we just break out of this
2237 loop now? Why would we need to continue scanning the function
2239 if (end_prologue_addr
== 0)
2240 end_prologue_addr
= cur_pc
;
2242 /* Check for branches and jumps. For now, only jump to
2243 register are caught (i.e. returns). */
2244 if ((itype_op (inst
) & 0x07) == 0 && rtype_funct (inst
) == 8)
2248 /* If the previous instruction was a jump, we must have reached
2249 the end of the prologue by now. Stop scanning so that we do
2250 not go past the function return. */
2255 if (this_cache
!= NULL
)
2258 (get_frame_register_signed (this_frame
,
2259 gdbarch_num_regs (gdbarch
) + frame_reg
)
2261 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
2262 this assignment below, eventually. But it's still needed
2264 this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
2265 + mips_regnum (gdbarch
)->pc
]
2266 = this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
2270 /* If we didn't reach the end of the prologue when scanning the function
2271 instructions, then set end_prologue_addr to the address of the
2272 instruction immediately after the last one we scanned. */
2273 /* brobecker/2004-10-10: I don't think this would ever happen, but
2274 we may as well be careful and do our best if we have a null
2275 end_prologue_addr. */
2276 if (end_prologue_addr
== 0)
2277 end_prologue_addr
= cur_pc
;
2279 /* In a frameless function, we might have incorrectly
2280 skipped some load immediate instructions. Undo the skipping
2281 if the load immediate was not followed by a stack adjustment. */
2282 if (load_immediate_bytes
&& !seen_sp_adjust
)
2283 end_prologue_addr
-= load_immediate_bytes
;
2285 return end_prologue_addr
;
2288 /* Heuristic unwinder for procedures using 32-bit instructions (covers
2289 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
2290 instructions (a.k.a. MIPS16) are handled by the mips_insn16
2293 static struct mips_frame_cache
*
2294 mips_insn32_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
2296 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2297 struct mips_frame_cache
*cache
;
2299 if ((*this_cache
) != NULL
)
2300 return (*this_cache
);
2302 cache
= FRAME_OBSTACK_ZALLOC (struct mips_frame_cache
);
2303 (*this_cache
) = cache
;
2304 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2306 /* Analyze the function prologue. */
2308 const CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
2309 CORE_ADDR start_addr
;
2311 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
2312 if (start_addr
== 0)
2313 start_addr
= heuristic_proc_start (gdbarch
, pc
);
2314 /* We can't analyze the prologue if we couldn't find the begining
2316 if (start_addr
== 0)
2319 mips32_scan_prologue (gdbarch
, start_addr
, pc
, this_frame
, *this_cache
);
2322 /* gdbarch_sp_regnum contains the value and not the address. */
2323 trad_frame_set_value (cache
->saved_regs
,
2324 gdbarch_num_regs (gdbarch
) + MIPS_SP_REGNUM
,
2327 return (*this_cache
);
2331 mips_insn32_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
2332 struct frame_id
*this_id
)
2334 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
2336 /* This marks the outermost frame. */
2337 if (info
->base
== 0)
2339 (*this_id
) = frame_id_build (info
->base
, get_frame_func (this_frame
));
2342 static struct value
*
2343 mips_insn32_frame_prev_register (struct frame_info
*this_frame
,
2344 void **this_cache
, int regnum
)
2346 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
2348 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
2352 mips_insn32_frame_sniffer (const struct frame_unwind
*self
,
2353 struct frame_info
*this_frame
, void **this_cache
)
2355 CORE_ADDR pc
= get_frame_pc (this_frame
);
2356 if (! mips_pc_is_mips16 (pc
))
2361 static const struct frame_unwind mips_insn32_frame_unwind
=
2364 mips_insn32_frame_this_id
,
2365 mips_insn32_frame_prev_register
,
2367 mips_insn32_frame_sniffer
2371 mips_insn32_frame_base_address (struct frame_info
*this_frame
,
2374 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
2379 static const struct frame_base mips_insn32_frame_base
=
2381 &mips_insn32_frame_unwind
,
2382 mips_insn32_frame_base_address
,
2383 mips_insn32_frame_base_address
,
2384 mips_insn32_frame_base_address
2387 static const struct frame_base
*
2388 mips_insn32_frame_base_sniffer (struct frame_info
*this_frame
)
2390 CORE_ADDR pc
= get_frame_pc (this_frame
);
2391 if (! mips_pc_is_mips16 (pc
))
2392 return &mips_insn32_frame_base
;
2397 static struct trad_frame_cache
*
2398 mips_stub_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
2401 CORE_ADDR start_addr
;
2402 CORE_ADDR stack_addr
;
2403 struct trad_frame_cache
*this_trad_cache
;
2404 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2405 int num_regs
= gdbarch_num_regs (gdbarch
);
2407 if ((*this_cache
) != NULL
)
2408 return (*this_cache
);
2409 this_trad_cache
= trad_frame_cache_zalloc (this_frame
);
2410 (*this_cache
) = this_trad_cache
;
2412 /* The return address is in the link register. */
2413 trad_frame_set_reg_realreg (this_trad_cache
,
2414 gdbarch_pc_regnum (gdbarch
),
2415 num_regs
+ MIPS_RA_REGNUM
);
2417 /* Frame ID, since it's a frameless / stackless function, no stack
2418 space is allocated and SP on entry is the current SP. */
2419 pc
= get_frame_pc (this_frame
);
2420 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
2421 stack_addr
= get_frame_register_signed (this_frame
,
2422 num_regs
+ MIPS_SP_REGNUM
);
2423 trad_frame_set_id (this_trad_cache
, frame_id_build (stack_addr
, start_addr
));
2425 /* Assume that the frame's base is the same as the
2427 trad_frame_set_this_base (this_trad_cache
, stack_addr
);
2429 return this_trad_cache
;
2433 mips_stub_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
2434 struct frame_id
*this_id
)
2436 struct trad_frame_cache
*this_trad_cache
2437 = mips_stub_frame_cache (this_frame
, this_cache
);
2438 trad_frame_get_id (this_trad_cache
, this_id
);
2441 static struct value
*
2442 mips_stub_frame_prev_register (struct frame_info
*this_frame
,
2443 void **this_cache
, int regnum
)
2445 struct trad_frame_cache
*this_trad_cache
2446 = mips_stub_frame_cache (this_frame
, this_cache
);
2447 return trad_frame_get_register (this_trad_cache
, this_frame
, regnum
);
2451 mips_stub_frame_sniffer (const struct frame_unwind
*self
,
2452 struct frame_info
*this_frame
, void **this_cache
)
2455 struct obj_section
*s
;
2456 CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
2457 struct minimal_symbol
*msym
;
2459 /* Use the stub unwinder for unreadable code. */
2460 if (target_read_memory (get_frame_pc (this_frame
), dummy
, 4) != 0)
2463 if (in_plt_section (pc
, NULL
))
2466 /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */
2467 s
= find_pc_section (pc
);
2470 && strcmp (bfd_get_section_name (s
->objfile
->obfd
, s
->the_bfd_section
),
2471 ".MIPS.stubs") == 0)
2474 /* Calling a PIC function from a non-PIC function passes through a
2475 stub. The stub for foo is named ".pic.foo". */
2476 msym
= lookup_minimal_symbol_by_pc (pc
);
2478 && SYMBOL_LINKAGE_NAME (msym
) != NULL
2479 && strncmp (SYMBOL_LINKAGE_NAME (msym
), ".pic.", 5) == 0)
2485 static const struct frame_unwind mips_stub_frame_unwind
=
2488 mips_stub_frame_this_id
,
2489 mips_stub_frame_prev_register
,
2491 mips_stub_frame_sniffer
2495 mips_stub_frame_base_address (struct frame_info
*this_frame
,
2498 struct trad_frame_cache
*this_trad_cache
2499 = mips_stub_frame_cache (this_frame
, this_cache
);
2500 return trad_frame_get_this_base (this_trad_cache
);
2503 static const struct frame_base mips_stub_frame_base
=
2505 &mips_stub_frame_unwind
,
2506 mips_stub_frame_base_address
,
2507 mips_stub_frame_base_address
,
2508 mips_stub_frame_base_address
2511 static const struct frame_base
*
2512 mips_stub_frame_base_sniffer (struct frame_info
*this_frame
)
2514 if (mips_stub_frame_sniffer (&mips_stub_frame_unwind
, this_frame
, NULL
))
2515 return &mips_stub_frame_base
;
2520 /* mips_addr_bits_remove - remove useless address bits */
2523 mips_addr_bits_remove (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2525 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2527 if (is_mips16_addr (addr
))
2528 addr
= unmake_mips16_addr (addr
);
2530 if (mips_mask_address_p (tdep
) && (((ULONGEST
) addr
) >> 32 == 0xffffffffUL
))
2531 /* This hack is a work-around for existing boards using PMON, the
2532 simulator, and any other 64-bit targets that doesn't have true
2533 64-bit addressing. On these targets, the upper 32 bits of
2534 addresses are ignored by the hardware. Thus, the PC or SP are
2535 likely to have been sign extended to all 1s by instruction
2536 sequences that load 32-bit addresses. For example, a typical
2537 piece of code that loads an address is this:
2539 lui $r2, <upper 16 bits>
2540 ori $r2, <lower 16 bits>
2542 But the lui sign-extends the value such that the upper 32 bits
2543 may be all 1s. The workaround is simply to mask off these
2544 bits. In the future, gcc may be changed to support true 64-bit
2545 addressing, and this masking will have to be disabled. */
2546 return addr
&= 0xffffffffUL
;
2551 /* Instructions used during single-stepping of atomic sequences. */
2552 #define LL_OPCODE 0x30
2553 #define LLD_OPCODE 0x34
2554 #define SC_OPCODE 0x38
2555 #define SCD_OPCODE 0x3c
2557 /* Checks for an atomic sequence of instructions beginning with a LL/LLD
2558 instruction and ending with a SC/SCD instruction. If such a sequence
2559 is found, attempt to step through it. A breakpoint is placed at the end of
2563 deal_with_atomic_sequence (struct gdbarch
*gdbarch
,
2564 struct address_space
*aspace
, CORE_ADDR pc
)
2566 CORE_ADDR breaks
[2] = {-1, -1};
2568 CORE_ADDR branch_bp
; /* Breakpoint at branch instruction's destination. */
2572 int last_breakpoint
= 0; /* Defaults to 0 (no breakpoints placed). */
2573 const int atomic_sequence_length
= 16; /* Instruction sequence length. */
2578 insn
= mips_fetch_instruction (gdbarch
, loc
);
2579 /* Assume all atomic sequences start with a ll/lld instruction. */
2580 if (itype_op (insn
) != LL_OPCODE
&& itype_op (insn
) != LLD_OPCODE
)
2583 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
2585 for (insn_count
= 0; insn_count
< atomic_sequence_length
; ++insn_count
)
2588 loc
+= MIPS_INSN32_SIZE
;
2589 insn
= mips_fetch_instruction (gdbarch
, loc
);
2591 /* Assume that there is at most one branch in the atomic
2592 sequence. If a branch is found, put a breakpoint in its
2593 destination address. */
2594 switch (itype_op (insn
))
2596 case 0: /* SPECIAL */
2597 if (rtype_funct (insn
) >> 1 == 4) /* JR, JALR */
2598 return 0; /* fallback to the standard single-step code. */
2600 case 1: /* REGIMM */
2601 is_branch
= ((itype_rt (insn
) & 0xc0) == 0); /* B{LT,GE}Z* */
2605 return 0; /* fallback to the standard single-step code. */
2612 case 22: /* BLEZL */
2613 case 23: /* BGTTL */
2619 is_branch
= (itype_rs (insn
) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
2624 branch_bp
= loc
+ mips32_relative_offset (insn
) + 4;
2625 if (last_breakpoint
>= 1)
2626 return 0; /* More than one branch found, fallback to the
2627 standard single-step code. */
2628 breaks
[1] = branch_bp
;
2632 if (itype_op (insn
) == SC_OPCODE
|| itype_op (insn
) == SCD_OPCODE
)
2636 /* Assume that the atomic sequence ends with a sc/scd instruction. */
2637 if (itype_op (insn
) != SC_OPCODE
&& itype_op (insn
) != SCD_OPCODE
)
2640 loc
+= MIPS_INSN32_SIZE
;
2642 /* Insert a breakpoint right after the end of the atomic sequence. */
2645 /* Check for duplicated breakpoints. Check also for a breakpoint
2646 placed (branch instruction's destination) in the atomic sequence. */
2647 if (last_breakpoint
&& pc
<= breaks
[1] && breaks
[1] <= breaks
[0])
2648 last_breakpoint
= 0;
2650 /* Effectively inserts the breakpoints. */
2651 for (index
= 0; index
<= last_breakpoint
; index
++)
2652 insert_single_step_breakpoint (gdbarch
, aspace
, breaks
[index
]);
2657 /* mips_software_single_step() is called just before we want to resume
2658 the inferior, if we want to single-step it but there is no hardware
2659 or kernel single-step support (MIPS on GNU/Linux for example). We find
2660 the target of the coming instruction and breakpoint it. */
2663 mips_software_single_step (struct frame_info
*frame
)
2665 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2666 struct address_space
*aspace
= get_frame_address_space (frame
);
2667 CORE_ADDR pc
, next_pc
;
2669 pc
= get_frame_pc (frame
);
2670 if (deal_with_atomic_sequence (gdbarch
, aspace
, pc
))
2673 next_pc
= mips_next_pc (frame
, pc
);
2675 insert_single_step_breakpoint (gdbarch
, aspace
, next_pc
);
2679 /* Test whether the PC points to the return instruction at the
2680 end of a function. */
2683 mips_about_to_return (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2685 if (mips_pc_is_mips16 (pc
))
2686 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2687 generates a "jr $ra"; other times it generates code to load
2688 the return address from the stack to an accessible register (such
2689 as $a3), then a "jr" using that register. This second case
2690 is almost impossible to distinguish from an indirect jump
2691 used for switch statements, so we don't even try. */
2692 return mips_fetch_instruction (gdbarch
, pc
) == 0xe820; /* jr $ra */
2694 return mips_fetch_instruction (gdbarch
, pc
) == 0x3e00008; /* jr $ra */
2698 /* This fencepost looks highly suspicious to me. Removing it also
2699 seems suspicious as it could affect remote debugging across serial
2703 heuristic_proc_start (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2709 struct inferior
*inf
;
2711 pc
= gdbarch_addr_bits_remove (gdbarch
, pc
);
2713 fence
= start_pc
- heuristic_fence_post
;
2717 if (heuristic_fence_post
== UINT_MAX
|| fence
< VM_MIN_ADDRESS
)
2718 fence
= VM_MIN_ADDRESS
;
2720 instlen
= mips_pc_is_mips16 (pc
) ? MIPS_INSN16_SIZE
: MIPS_INSN32_SIZE
;
2722 inf
= current_inferior ();
2724 /* Search back for previous return. */
2725 for (start_pc
-= instlen
;; start_pc
-= instlen
)
2726 if (start_pc
< fence
)
2728 /* It's not clear to me why we reach this point when
2729 stop_soon, but with this test, at least we
2730 don't print out warnings for every child forked (eg, on
2731 decstation). 22apr93 rich@cygnus.com. */
2732 if (inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2734 static int blurb_printed
= 0;
2736 warning (_("GDB can't find the start of the function at %s."),
2737 paddress (gdbarch
, pc
));
2741 /* This actually happens frequently in embedded
2742 development, when you first connect to a board
2743 and your stack pointer and pc are nowhere in
2744 particular. This message needs to give people
2745 in that situation enough information to
2746 determine that it's no big deal. */
2747 printf_filtered ("\n\
2748 GDB is unable to find the start of the function at %s\n\
2749 and thus can't determine the size of that function's stack frame.\n\
2750 This means that GDB may be unable to access that stack frame, or\n\
2751 the frames below it.\n\
2752 This problem is most likely caused by an invalid program counter or\n\
2754 However, if you think GDB should simply search farther back\n\
2755 from %s for code which looks like the beginning of a\n\
2756 function, you can increase the range of the search using the `set\n\
2757 heuristic-fence-post' command.\n",
2758 paddress (gdbarch
, pc
), paddress (gdbarch
, pc
));
2765 else if (mips_pc_is_mips16 (start_pc
))
2767 unsigned short inst
;
2769 /* On MIPS16, any one of the following is likely to be the
2770 start of a function:
2776 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */
2777 inst
= mips_fetch_instruction (gdbarch
, start_pc
);
2778 if ((inst
& 0xff80) == 0x6480) /* save */
2780 if (start_pc
- instlen
>= fence
)
2782 inst
= mips_fetch_instruction (gdbarch
, start_pc
- instlen
);
2783 if ((inst
& 0xf800) == 0xf000) /* extend */
2784 start_pc
-= instlen
;
2788 else if (((inst
& 0xf81f) == 0xe809
2789 && (inst
& 0x700) != 0x700) /* entry */
2790 || (inst
& 0xff80) == 0x6380 /* addiu sp,-n */
2791 || (inst
& 0xff80) == 0xfb80 /* daddiu sp,-n */
2792 || ((inst
& 0xf810) == 0xf010 && seen_adjsp
)) /* extend -n */
2794 else if ((inst
& 0xff00) == 0x6300 /* addiu sp */
2795 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
2800 else if (mips_about_to_return (gdbarch
, start_pc
))
2802 /* Skip return and its delay slot. */
2803 start_pc
+= 2 * MIPS_INSN32_SIZE
;
2810 struct mips_objfile_private
2816 /* According to the current ABI, should the type be passed in a
2817 floating-point register (assuming that there is space)? When there
2818 is no FPU, FP are not even considered as possible candidates for
2819 FP registers and, consequently this returns false - forces FP
2820 arguments into integer registers. */
2823 fp_register_arg_p (struct gdbarch
*gdbarch
, enum type_code typecode
,
2824 struct type
*arg_type
)
2826 return ((typecode
== TYPE_CODE_FLT
2827 || (MIPS_EABI (gdbarch
)
2828 && (typecode
== TYPE_CODE_STRUCT
2829 || typecode
== TYPE_CODE_UNION
)
2830 && TYPE_NFIELDS (arg_type
) == 1
2831 && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type
, 0)))
2833 && MIPS_FPU_TYPE(gdbarch
) != MIPS_FPU_NONE
);
2836 /* On o32, argument passing in GPRs depends on the alignment of the type being
2837 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2840 mips_type_needs_double_align (struct type
*type
)
2842 enum type_code typecode
= TYPE_CODE (type
);
2844 if (typecode
== TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
2846 else if (typecode
== TYPE_CODE_STRUCT
)
2848 if (TYPE_NFIELDS (type
) < 1)
2850 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type
, 0));
2852 else if (typecode
== TYPE_CODE_UNION
)
2856 n
= TYPE_NFIELDS (type
);
2857 for (i
= 0; i
< n
; i
++)
2858 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type
, i
)))
2865 /* Adjust the address downward (direction of stack growth) so that it
2866 is correctly aligned for a new stack frame. */
2868 mips_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2870 return align_down (addr
, 16);
2874 mips_eabi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2875 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2876 int nargs
, struct value
**args
, CORE_ADDR sp
,
2877 int struct_return
, CORE_ADDR struct_addr
)
2883 int stack_offset
= 0;
2884 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2885 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2886 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
2887 int regsize
= mips_abi_regsize (gdbarch
);
2889 /* For shared libraries, "t9" needs to point at the function
2891 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
2893 /* Set the return address register to point to the entry point of
2894 the program, where a breakpoint lies in wait. */
2895 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
2897 /* First ensure that the stack and structure return address (if any)
2898 are properly aligned. The stack has to be at least 64-bit
2899 aligned even on 32-bit machines, because doubles must be 64-bit
2900 aligned. For n32 and n64, stack frames need to be 128-bit
2901 aligned, so we round to this widest known alignment. */
2903 sp
= align_down (sp
, 16);
2904 struct_addr
= align_down (struct_addr
, 16);
2906 /* Now make space on the stack for the args. We allocate more
2907 than necessary for EABI, because the first few arguments are
2908 passed in registers, but that's OK. */
2909 for (argnum
= 0; argnum
< nargs
; argnum
++)
2910 len
+= align_up (TYPE_LENGTH (value_type (args
[argnum
])), regsize
);
2911 sp
-= align_up (len
, 16);
2914 fprintf_unfiltered (gdb_stdlog
,
2915 "mips_eabi_push_dummy_call: sp=%s allocated %ld\n",
2916 paddress (gdbarch
, sp
), (long) align_up (len
, 16));
2918 /* Initialize the integer and float register pointers. */
2919 argreg
= MIPS_A0_REGNUM
;
2920 float_argreg
= mips_fpa0_regnum (gdbarch
);
2922 /* The struct_return pointer occupies the first parameter-passing reg. */
2926 fprintf_unfiltered (gdb_stdlog
,
2927 "mips_eabi_push_dummy_call: "
2928 "struct_return reg=%d %s\n",
2929 argreg
, paddress (gdbarch
, struct_addr
));
2930 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
2933 /* Now load as many as possible of the first arguments into
2934 registers, and push the rest onto the stack. Loop thru args
2935 from first to last. */
2936 for (argnum
= 0; argnum
< nargs
; argnum
++)
2938 const gdb_byte
*val
;
2939 gdb_byte valbuf
[MAX_REGISTER_SIZE
];
2940 struct value
*arg
= args
[argnum
];
2941 struct type
*arg_type
= check_typedef (value_type (arg
));
2942 int len
= TYPE_LENGTH (arg_type
);
2943 enum type_code typecode
= TYPE_CODE (arg_type
);
2946 fprintf_unfiltered (gdb_stdlog
,
2947 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2948 argnum
+ 1, len
, (int) typecode
);
2950 /* Function pointer arguments to mips16 code need to be made into
2952 if (typecode
== TYPE_CODE_PTR
2953 && TYPE_CODE (TYPE_TARGET_TYPE (arg_type
)) == TYPE_CODE_FUNC
)
2955 CORE_ADDR addr
= extract_signed_integer (value_contents (arg
),
2957 if (mips_pc_is_mips16 (addr
))
2959 store_signed_integer (valbuf
, len
, byte_order
,
2960 make_mips16_addr (addr
));
2964 val
= value_contents (arg
);
2966 /* The EABI passes structures that do not fit in a register by
2968 else if (len
> regsize
2969 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
))
2971 store_unsigned_integer (valbuf
, regsize
, byte_order
,
2972 value_address (arg
));
2973 typecode
= TYPE_CODE_PTR
;
2977 fprintf_unfiltered (gdb_stdlog
, " push");
2980 val
= value_contents (arg
);
2982 /* 32-bit ABIs always start floating point arguments in an
2983 even-numbered floating point register. Round the FP register
2984 up before the check to see if there are any FP registers
2985 left. Non MIPS_EABI targets also pass the FP in the integer
2986 registers so also round up normal registers. */
2987 if (regsize
< 8 && fp_register_arg_p (gdbarch
, typecode
, arg_type
))
2989 if ((float_argreg
& 1))
2993 /* Floating point arguments passed in registers have to be
2994 treated specially. On 32-bit architectures, doubles
2995 are passed in register pairs; the even register gets
2996 the low word, and the odd register gets the high word.
2997 On non-EABI processors, the first two floating point arguments are
2998 also copied to general registers, because MIPS16 functions
2999 don't use float registers for arguments. This duplication of
3000 arguments in general registers can't hurt non-MIPS16 functions
3001 because those registers are normally skipped. */
3002 /* MIPS_EABI squeezes a struct that contains a single floating
3003 point value into an FP register instead of pushing it onto the
3005 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
3006 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM (gdbarch
))
3008 /* EABI32 will pass doubles in consecutive registers, even on
3009 64-bit cores. At one time, we used to check the size of
3010 `float_argreg' to determine whether or not to pass doubles
3011 in consecutive registers, but this is not sufficient for
3012 making the ABI determination. */
3013 if (len
== 8 && mips_abi (gdbarch
) == MIPS_ABI_EABI32
)
3015 int low_offset
= gdbarch_byte_order (gdbarch
)
3016 == BFD_ENDIAN_BIG
? 4 : 0;
3019 /* Write the low word of the double to the even register(s). */
3020 regval
= extract_signed_integer (val
+ low_offset
,
3023 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3024 float_argreg
, phex (regval
, 4));
3025 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
3027 /* Write the high word of the double to the odd register(s). */
3028 regval
= extract_signed_integer (val
+ 4 - low_offset
,
3031 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3032 float_argreg
, phex (regval
, 4));
3033 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
3037 /* This is a floating point value that fits entirely
3038 in a single register. */
3039 /* On 32 bit ABI's the float_argreg is further adjusted
3040 above to ensure that it is even register aligned. */
3041 LONGEST regval
= extract_signed_integer (val
, len
, byte_order
);
3043 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3044 float_argreg
, phex (regval
, len
));
3045 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
3050 /* Copy the argument to general registers or the stack in
3051 register-sized pieces. Large arguments are split between
3052 registers and stack. */
3053 /* Note: structs whose size is not a multiple of regsize
3054 are treated specially: Irix cc passes
3055 them in registers where gcc sometimes puts them on the
3056 stack. For maximum compatibility, we will put them in
3058 int odd_sized_struct
= (len
> regsize
&& len
% regsize
!= 0);
3060 /* Note: Floating-point values that didn't fit into an FP
3061 register are only written to memory. */
3064 /* Remember if the argument was written to the stack. */
3065 int stack_used_p
= 0;
3066 int partial_len
= (len
< regsize
? len
: regsize
);
3069 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3072 /* Write this portion of the argument to the stack. */
3073 if (argreg
> MIPS_LAST_ARG_REGNUM (gdbarch
)
3075 || fp_register_arg_p (gdbarch
, typecode
, arg_type
))
3077 /* Should shorter than int integer values be
3078 promoted to int before being stored? */
3079 int longword_offset
= 0;
3082 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
3085 && (typecode
== TYPE_CODE_INT
3086 || typecode
== TYPE_CODE_PTR
3087 || typecode
== TYPE_CODE_FLT
) && len
<= 4)
3088 longword_offset
= regsize
- len
;
3089 else if ((typecode
== TYPE_CODE_STRUCT
3090 || typecode
== TYPE_CODE_UNION
)
3091 && TYPE_LENGTH (arg_type
) < regsize
)
3092 longword_offset
= regsize
- len
;
3097 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=%s",
3098 paddress (gdbarch
, stack_offset
));
3099 fprintf_unfiltered (gdb_stdlog
, " longword_offset=%s",
3100 paddress (gdbarch
, longword_offset
));
3103 addr
= sp
+ stack_offset
+ longword_offset
;
3108 fprintf_unfiltered (gdb_stdlog
, " @%s ",
3109 paddress (gdbarch
, addr
));
3110 for (i
= 0; i
< partial_len
; i
++)
3112 fprintf_unfiltered (gdb_stdlog
, "%02x",
3116 write_memory (addr
, val
, partial_len
);
3119 /* Note!!! This is NOT an else clause. Odd sized
3120 structs may go thru BOTH paths. Floating point
3121 arguments will not. */
3122 /* Write this portion of the argument to a general
3123 purpose register. */
3124 if (argreg
<= MIPS_LAST_ARG_REGNUM (gdbarch
)
3125 && !fp_register_arg_p (gdbarch
, typecode
, arg_type
))
3128 extract_signed_integer (val
, partial_len
, byte_order
);
3131 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
3133 phex (regval
, regsize
));
3134 regcache_cooked_write_signed (regcache
, argreg
, regval
);
3141 /* Compute the the offset into the stack at which we
3142 will copy the next parameter.
3144 In the new EABI (and the NABI32), the stack_offset
3145 only needs to be adjusted when it has been used. */
3148 stack_offset
+= align_up (partial_len
, regsize
);
3152 fprintf_unfiltered (gdb_stdlog
, "\n");
3155 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
3157 /* Return adjusted stack pointer. */
3161 /* Determine the return value convention being used. */
3163 static enum return_value_convention
3164 mips_eabi_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
3165 struct type
*type
, struct regcache
*regcache
,
3166 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
3168 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
3169 int fp_return_type
= 0;
3170 int offset
, regnum
, xfer
;
3172 if (TYPE_LENGTH (type
) > 2 * mips_abi_regsize (gdbarch
))
3173 return RETURN_VALUE_STRUCT_CONVENTION
;
3175 /* Floating point type? */
3176 if (tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
3178 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3180 /* Structs with a single field of float type
3181 are returned in a floating point register. */
3182 if ((TYPE_CODE (type
) == TYPE_CODE_STRUCT
3183 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
3184 && TYPE_NFIELDS (type
) == 1)
3186 struct type
*fieldtype
= TYPE_FIELD_TYPE (type
, 0);
3188 if (TYPE_CODE (check_typedef (fieldtype
)) == TYPE_CODE_FLT
)
3195 /* A floating-point value belongs in the least significant part
3198 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
3199 regnum
= mips_regnum (gdbarch
)->fp0
;
3203 /* An integer value goes in V0/V1. */
3205 fprintf_unfiltered (gdb_stderr
, "Return scalar in $v0\n");
3206 regnum
= MIPS_V0_REGNUM
;
3209 offset
< TYPE_LENGTH (type
);
3210 offset
+= mips_abi_regsize (gdbarch
), regnum
++)
3212 xfer
= mips_abi_regsize (gdbarch
);
3213 if (offset
+ xfer
> TYPE_LENGTH (type
))
3214 xfer
= TYPE_LENGTH (type
) - offset
;
3215 mips_xfer_register (gdbarch
, regcache
,
3216 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
3217 gdbarch_byte_order (gdbarch
), readbuf
, writebuf
,
3221 return RETURN_VALUE_REGISTER_CONVENTION
;
3225 /* N32/N64 ABI stuff. */
3227 /* Search for a naturally aligned double at OFFSET inside a struct
3228 ARG_TYPE. The N32 / N64 ABIs pass these in floating point
3232 mips_n32n64_fp_arg_chunk_p (struct gdbarch
*gdbarch
, struct type
*arg_type
,
3237 if (TYPE_CODE (arg_type
) != TYPE_CODE_STRUCT
)
3240 if (MIPS_FPU_TYPE (gdbarch
) != MIPS_FPU_DOUBLE
)
3243 if (TYPE_LENGTH (arg_type
) < offset
+ MIPS64_REGSIZE
)
3246 for (i
= 0; i
< TYPE_NFIELDS (arg_type
); i
++)
3249 struct type
*field_type
;
3251 /* We're only looking at normal fields. */
3252 if (field_is_static (&TYPE_FIELD (arg_type
, i
))
3253 || (TYPE_FIELD_BITPOS (arg_type
, i
) % 8) != 0)
3256 /* If we have gone past the offset, there is no double to pass. */
3257 pos
= TYPE_FIELD_BITPOS (arg_type
, i
) / 8;
3261 field_type
= check_typedef (TYPE_FIELD_TYPE (arg_type
, i
));
3263 /* If this field is entirely before the requested offset, go
3264 on to the next one. */
3265 if (pos
+ TYPE_LENGTH (field_type
) <= offset
)
3268 /* If this is our special aligned double, we can stop. */
3269 if (TYPE_CODE (field_type
) == TYPE_CODE_FLT
3270 && TYPE_LENGTH (field_type
) == MIPS64_REGSIZE
)
3273 /* This field starts at or before the requested offset, and
3274 overlaps it. If it is a structure, recurse inwards. */
3275 return mips_n32n64_fp_arg_chunk_p (gdbarch
, field_type
, offset
- pos
);
3282 mips_n32n64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
3283 struct regcache
*regcache
, CORE_ADDR bp_addr
,
3284 int nargs
, struct value
**args
, CORE_ADDR sp
,
3285 int struct_return
, CORE_ADDR struct_addr
)
3291 int stack_offset
= 0;
3292 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
3293 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3294 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
3296 /* For shared libraries, "t9" needs to point at the function
3298 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
3300 /* Set the return address register to point to the entry point of
3301 the program, where a breakpoint lies in wait. */
3302 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
3304 /* First ensure that the stack and structure return address (if any)
3305 are properly aligned. The stack has to be at least 64-bit
3306 aligned even on 32-bit machines, because doubles must be 64-bit
3307 aligned. For n32 and n64, stack frames need to be 128-bit
3308 aligned, so we round to this widest known alignment. */
3310 sp
= align_down (sp
, 16);
3311 struct_addr
= align_down (struct_addr
, 16);
3313 /* Now make space on the stack for the args. */
3314 for (argnum
= 0; argnum
< nargs
; argnum
++)
3315 len
+= align_up (TYPE_LENGTH (value_type (args
[argnum
])), MIPS64_REGSIZE
);
3316 sp
-= align_up (len
, 16);
3319 fprintf_unfiltered (gdb_stdlog
,
3320 "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n",
3321 paddress (gdbarch
, sp
), (long) align_up (len
, 16));
3323 /* Initialize the integer and float register pointers. */
3324 argreg
= MIPS_A0_REGNUM
;
3325 float_argreg
= mips_fpa0_regnum (gdbarch
);
3327 /* The struct_return pointer occupies the first parameter-passing reg. */
3331 fprintf_unfiltered (gdb_stdlog
,
3332 "mips_n32n64_push_dummy_call: "
3333 "struct_return reg=%d %s\n",
3334 argreg
, paddress (gdbarch
, struct_addr
));
3335 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
3338 /* Now load as many as possible of the first arguments into
3339 registers, and push the rest onto the stack. Loop thru args
3340 from first to last. */
3341 for (argnum
= 0; argnum
< nargs
; argnum
++)
3343 const gdb_byte
*val
;
3344 struct value
*arg
= args
[argnum
];
3345 struct type
*arg_type
= check_typedef (value_type (arg
));
3346 int len
= TYPE_LENGTH (arg_type
);
3347 enum type_code typecode
= TYPE_CODE (arg_type
);
3350 fprintf_unfiltered (gdb_stdlog
,
3351 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3352 argnum
+ 1, len
, (int) typecode
);
3354 val
= value_contents (arg
);
3356 /* A 128-bit long double value requires an even-odd pair of
3357 floating-point registers. */
3359 && fp_register_arg_p (gdbarch
, typecode
, arg_type
)
3360 && (float_argreg
& 1))
3366 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
3367 && argreg
<= MIPS_LAST_ARG_REGNUM (gdbarch
))
3369 /* This is a floating point value that fits entirely
3370 in a single register or a pair of registers. */
3371 int reglen
= (len
<= MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
3372 LONGEST regval
= extract_unsigned_integer (val
, reglen
, byte_order
);
3374 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3375 float_argreg
, phex (regval
, reglen
));
3376 regcache_cooked_write_unsigned (regcache
, float_argreg
, regval
);
3379 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3380 argreg
, phex (regval
, reglen
));
3381 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
3386 regval
= extract_unsigned_integer (val
+ reglen
,
3387 reglen
, byte_order
);
3389 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3390 float_argreg
, phex (regval
, reglen
));
3391 regcache_cooked_write_unsigned (regcache
, float_argreg
, regval
);
3394 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3395 argreg
, phex (regval
, reglen
));
3396 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
3403 /* Copy the argument to general registers or the stack in
3404 register-sized pieces. Large arguments are split between
3405 registers and stack. */
3406 /* For N32/N64, structs, unions, or other composite types are
3407 treated as a sequence of doublewords, and are passed in integer
3408 or floating point registers as though they were simple scalar
3409 parameters to the extent that they fit, with any excess on the
3410 stack packed according to the normal memory layout of the
3412 The caller does not reserve space for the register arguments;
3413 the callee is responsible for reserving it if required. */
3414 /* Note: Floating-point values that didn't fit into an FP
3415 register are only written to memory. */
3418 /* Remember if the argument was written to the stack. */
3419 int stack_used_p
= 0;
3420 int partial_len
= (len
< MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
3423 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3426 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
))
3427 gdb_assert (argreg
> MIPS_LAST_ARG_REGNUM (gdbarch
));
3429 /* Write this portion of the argument to the stack. */
3430 if (argreg
> MIPS_LAST_ARG_REGNUM (gdbarch
))
3432 /* Should shorter than int integer values be
3433 promoted to int before being stored? */
3434 int longword_offset
= 0;
3437 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
3439 if ((typecode
== TYPE_CODE_INT
3440 || typecode
== TYPE_CODE_PTR
)
3442 longword_offset
= MIPS64_REGSIZE
- len
;
3447 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=%s",
3448 paddress (gdbarch
, stack_offset
));
3449 fprintf_unfiltered (gdb_stdlog
, " longword_offset=%s",
3450 paddress (gdbarch
, longword_offset
));
3453 addr
= sp
+ stack_offset
+ longword_offset
;
3458 fprintf_unfiltered (gdb_stdlog
, " @%s ",
3459 paddress (gdbarch
, addr
));
3460 for (i
= 0; i
< partial_len
; i
++)
3462 fprintf_unfiltered (gdb_stdlog
, "%02x",
3466 write_memory (addr
, val
, partial_len
);
3469 /* Note!!! This is NOT an else clause. Odd sized
3470 structs may go thru BOTH paths. */
3471 /* Write this portion of the argument to a general
3472 purpose register. */
3473 if (argreg
<= MIPS_LAST_ARG_REGNUM (gdbarch
))
3477 /* Sign extend pointers, 32-bit integers and signed
3478 16-bit and 8-bit integers; everything else is taken
3481 if ((partial_len
== 4
3482 && (typecode
== TYPE_CODE_PTR
3483 || typecode
== TYPE_CODE_INT
))
3485 && typecode
== TYPE_CODE_INT
3486 && !TYPE_UNSIGNED (arg_type
)))
3487 regval
= extract_signed_integer (val
, partial_len
,
3490 regval
= extract_unsigned_integer (val
, partial_len
,
3493 /* A non-floating-point argument being passed in a
3494 general register. If a struct or union, and if
3495 the remaining length is smaller than the register
3496 size, we have to adjust the register value on
3499 It does not seem to be necessary to do the
3500 same for integral types. */
3502 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
3503 && partial_len
< MIPS64_REGSIZE
3504 && (typecode
== TYPE_CODE_STRUCT
3505 || typecode
== TYPE_CODE_UNION
))
3506 regval
<<= ((MIPS64_REGSIZE
- partial_len
)
3510 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
3512 phex (regval
, MIPS64_REGSIZE
));
3513 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
3515 if (mips_n32n64_fp_arg_chunk_p (gdbarch
, arg_type
,
3516 TYPE_LENGTH (arg_type
) - len
))
3519 fprintf_filtered (gdb_stdlog
, " - fpreg=%d val=%s",
3521 phex (regval
, MIPS64_REGSIZE
));
3522 regcache_cooked_write_unsigned (regcache
, float_argreg
,
3533 /* Compute the the offset into the stack at which we
3534 will copy the next parameter.
3536 In N32 (N64?), the stack_offset only needs to be
3537 adjusted when it has been used. */
3540 stack_offset
+= align_up (partial_len
, MIPS64_REGSIZE
);
3544 fprintf_unfiltered (gdb_stdlog
, "\n");
3547 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
3549 /* Return adjusted stack pointer. */
3553 static enum return_value_convention
3554 mips_n32n64_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
3555 struct type
*type
, struct regcache
*regcache
,
3556 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
3558 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
3560 /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
3562 Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
3563 if needed), as appropriate for the type. Composite results (struct,
3564 union, or array) are returned in $2/$f0 and $3/$f2 according to the
3567 * A struct with only one or two floating point fields is returned in $f0
3568 (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
3571 * Any other composite results of at most 128 bits are returned in
3572 $2 (first 64 bits) and $3 (remainder, if necessary).
3574 * Larger composite results are handled by converting the function to a
3575 procedure with an implicit first parameter, which is a pointer to an area
3576 reserved by the caller to receive the result. [The o32-bit ABI requires
3577 that all composite results be handled by conversion to implicit first
3578 parameters. The MIPS/SGI Fortran implementation has always made a
3579 specific exception to return COMPLEX results in the floating point
3582 if (TYPE_LENGTH (type
) > 2 * MIPS64_REGSIZE
)
3583 return RETURN_VALUE_STRUCT_CONVENTION
;
3584 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
3585 && TYPE_LENGTH (type
) == 16
3586 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
3588 /* A 128-bit floating-point value fills both $f0 and $f2. The
3589 two registers are used in the same as memory order, so the
3590 eight bytes with the lower memory address are in $f0. */
3592 fprintf_unfiltered (gdb_stderr
, "Return float in $f0 and $f2\n");
3593 mips_xfer_register (gdbarch
, regcache
,
3594 gdbarch_num_regs (gdbarch
)
3595 + mips_regnum (gdbarch
)->fp0
,
3596 8, gdbarch_byte_order (gdbarch
),
3597 readbuf
, writebuf
, 0);
3598 mips_xfer_register (gdbarch
, regcache
,
3599 gdbarch_num_regs (gdbarch
)
3600 + mips_regnum (gdbarch
)->fp0
+ 2,
3601 8, gdbarch_byte_order (gdbarch
),
3602 readbuf
? readbuf
+ 8 : readbuf
,
3603 writebuf
? writebuf
+ 8 : writebuf
, 0);
3604 return RETURN_VALUE_REGISTER_CONVENTION
;
3606 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
3607 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
3609 /* A single or double floating-point value that fits in FP0. */
3611 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
3612 mips_xfer_register (gdbarch
, regcache
,
3613 gdbarch_num_regs (gdbarch
)
3614 + mips_regnum (gdbarch
)->fp0
,
3616 gdbarch_byte_order (gdbarch
),
3617 readbuf
, writebuf
, 0);
3618 return RETURN_VALUE_REGISTER_CONVENTION
;
3620 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3621 && TYPE_NFIELDS (type
) <= 2
3622 && TYPE_NFIELDS (type
) >= 1
3623 && ((TYPE_NFIELDS (type
) == 1
3624 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type
, 0)))
3626 || (TYPE_NFIELDS (type
) == 2
3627 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type
, 0)))
3629 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type
, 1)))
3630 == TYPE_CODE_FLT
))))
3632 /* A struct that contains one or two floats. Each value is part
3633 in the least significant part of their floating point
3634 register (or GPR, for soft float). */
3637 for (field
= 0, regnum
= (tdep
->mips_fpu_type
!= MIPS_FPU_NONE
3638 ? mips_regnum (gdbarch
)->fp0
3640 field
< TYPE_NFIELDS (type
); field
++, regnum
+= 2)
3642 int offset
= (FIELD_BITPOS (TYPE_FIELDS (type
)[field
])
3645 fprintf_unfiltered (gdb_stderr
, "Return float struct+%d\n",
3647 if (TYPE_LENGTH (TYPE_FIELD_TYPE (type
, field
)) == 16)
3649 /* A 16-byte long double field goes in two consecutive
3651 mips_xfer_register (gdbarch
, regcache
,
3652 gdbarch_num_regs (gdbarch
) + regnum
,
3654 gdbarch_byte_order (gdbarch
),
3655 readbuf
, writebuf
, offset
);
3656 mips_xfer_register (gdbarch
, regcache
,
3657 gdbarch_num_regs (gdbarch
) + regnum
+ 1,
3659 gdbarch_byte_order (gdbarch
),
3660 readbuf
, writebuf
, offset
+ 8);
3663 mips_xfer_register (gdbarch
, regcache
,
3664 gdbarch_num_regs (gdbarch
) + regnum
,
3665 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, field
)),
3666 gdbarch_byte_order (gdbarch
),
3667 readbuf
, writebuf
, offset
);
3669 return RETURN_VALUE_REGISTER_CONVENTION
;
3671 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3672 || TYPE_CODE (type
) == TYPE_CODE_UNION
3673 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
3675 /* A composite type. Extract the left justified value,
3676 regardless of the byte order. I.e. DO NOT USE
3680 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
3681 offset
< TYPE_LENGTH (type
);
3682 offset
+= register_size (gdbarch
, regnum
), regnum
++)
3684 int xfer
= register_size (gdbarch
, regnum
);
3685 if (offset
+ xfer
> TYPE_LENGTH (type
))
3686 xfer
= TYPE_LENGTH (type
) - offset
;
3688 fprintf_unfiltered (gdb_stderr
, "Return struct+%d:%d in $%d\n",
3689 offset
, xfer
, regnum
);
3690 mips_xfer_register (gdbarch
, regcache
,
3691 gdbarch_num_regs (gdbarch
) + regnum
,
3692 xfer
, BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
,
3695 return RETURN_VALUE_REGISTER_CONVENTION
;
3699 /* A scalar extract each part but least-significant-byte
3703 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
3704 offset
< TYPE_LENGTH (type
);
3705 offset
+= register_size (gdbarch
, regnum
), regnum
++)
3707 int xfer
= register_size (gdbarch
, regnum
);
3708 if (offset
+ xfer
> TYPE_LENGTH (type
))
3709 xfer
= TYPE_LENGTH (type
) - offset
;
3711 fprintf_unfiltered (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
3712 offset
, xfer
, regnum
);
3713 mips_xfer_register (gdbarch
, regcache
,
3714 gdbarch_num_regs (gdbarch
) + regnum
,
3715 xfer
, gdbarch_byte_order (gdbarch
),
3716 readbuf
, writebuf
, offset
);
3718 return RETURN_VALUE_REGISTER_CONVENTION
;
3722 /* O32 ABI stuff. */
3725 mips_o32_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
3726 struct regcache
*regcache
, CORE_ADDR bp_addr
,
3727 int nargs
, struct value
**args
, CORE_ADDR sp
,
3728 int struct_return
, CORE_ADDR struct_addr
)
3734 int stack_offset
= 0;
3735 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
3736 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3737 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
3739 /* For shared libraries, "t9" needs to point at the function
3741 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
3743 /* Set the return address register to point to the entry point of
3744 the program, where a breakpoint lies in wait. */
3745 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
3747 /* First ensure that the stack and structure return address (if any)
3748 are properly aligned. The stack has to be at least 64-bit
3749 aligned even on 32-bit machines, because doubles must be 64-bit
3750 aligned. For n32 and n64, stack frames need to be 128-bit
3751 aligned, so we round to this widest known alignment. */
3753 sp
= align_down (sp
, 16);
3754 struct_addr
= align_down (struct_addr
, 16);
3756 /* Now make space on the stack for the args. */
3757 for (argnum
= 0; argnum
< nargs
; argnum
++)
3759 struct type
*arg_type
= check_typedef (value_type (args
[argnum
]));
3760 int arglen
= TYPE_LENGTH (arg_type
);
3762 /* Align to double-word if necessary. */
3763 if (mips_type_needs_double_align (arg_type
))
3764 len
= align_up (len
, MIPS32_REGSIZE
* 2);
3765 /* Allocate space on the stack. */
3766 len
+= align_up (arglen
, MIPS32_REGSIZE
);
3768 sp
-= align_up (len
, 16);
3771 fprintf_unfiltered (gdb_stdlog
,
3772 "mips_o32_push_dummy_call: sp=%s allocated %ld\n",
3773 paddress (gdbarch
, sp
), (long) align_up (len
, 16));
3775 /* Initialize the integer and float register pointers. */
3776 argreg
= MIPS_A0_REGNUM
;
3777 float_argreg
= mips_fpa0_regnum (gdbarch
);
3779 /* The struct_return pointer occupies the first parameter-passing reg. */
3783 fprintf_unfiltered (gdb_stdlog
,
3784 "mips_o32_push_dummy_call: "
3785 "struct_return reg=%d %s\n",
3786 argreg
, paddress (gdbarch
, struct_addr
));
3787 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
3788 stack_offset
+= MIPS32_REGSIZE
;
3791 /* Now load as many as possible of the first arguments into
3792 registers, and push the rest onto the stack. Loop thru args
3793 from first to last. */
3794 for (argnum
= 0; argnum
< nargs
; argnum
++)
3796 const gdb_byte
*val
;
3797 struct value
*arg
= args
[argnum
];
3798 struct type
*arg_type
= check_typedef (value_type (arg
));
3799 int len
= TYPE_LENGTH (arg_type
);
3800 enum type_code typecode
= TYPE_CODE (arg_type
);
3803 fprintf_unfiltered (gdb_stdlog
,
3804 "mips_o32_push_dummy_call: %d len=%d type=%d",
3805 argnum
+ 1, len
, (int) typecode
);
3807 val
= value_contents (arg
);
3809 /* 32-bit ABIs always start floating point arguments in an
3810 even-numbered floating point register. Round the FP register
3811 up before the check to see if there are any FP registers
3812 left. O32/O64 targets also pass the FP in the integer
3813 registers so also round up normal registers. */
3814 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
))
3816 if ((float_argreg
& 1))
3820 /* Floating point arguments passed in registers have to be
3821 treated specially. On 32-bit architectures, doubles
3822 are passed in register pairs; the even register gets
3823 the low word, and the odd register gets the high word.
3824 On O32/O64, the first two floating point arguments are
3825 also copied to general registers, because MIPS16 functions
3826 don't use float registers for arguments. This duplication of
3827 arguments in general registers can't hurt non-MIPS16 functions
3828 because those registers are normally skipped. */
3830 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
3831 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM (gdbarch
))
3833 if (register_size (gdbarch
, float_argreg
) < 8 && len
== 8)
3835 int low_offset
= gdbarch_byte_order (gdbarch
)
3836 == BFD_ENDIAN_BIG
? 4 : 0;
3837 unsigned long regval
;
3839 /* Write the low word of the double to the even register(s). */
3840 regval
= extract_unsigned_integer (val
+ low_offset
,
3843 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3844 float_argreg
, phex (regval
, 4));
3845 regcache_cooked_write_unsigned (regcache
,
3846 float_argreg
++, regval
);
3848 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3849 argreg
, phex (regval
, 4));
3850 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
3852 /* Write the high word of the double to the odd register(s). */
3853 regval
= extract_unsigned_integer (val
+ 4 - low_offset
,
3856 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3857 float_argreg
, phex (regval
, 4));
3858 regcache_cooked_write_unsigned (regcache
,
3859 float_argreg
++, regval
);
3862 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3863 argreg
, phex (regval
, 4));
3864 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
3868 /* This is a floating point value that fits entirely
3869 in a single register. */
3870 /* On 32 bit ABI's the float_argreg is further adjusted
3871 above to ensure that it is even register aligned. */
3872 LONGEST regval
= extract_unsigned_integer (val
, len
, byte_order
);
3874 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3875 float_argreg
, phex (regval
, len
));
3876 regcache_cooked_write_unsigned (regcache
,
3877 float_argreg
++, regval
);
3878 /* Although two FP registers are reserved for each
3879 argument, only one corresponding integer register is
3882 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3883 argreg
, phex (regval
, len
));
3884 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
3886 /* Reserve space for the FP register. */
3887 stack_offset
+= align_up (len
, MIPS32_REGSIZE
);
3891 /* Copy the argument to general registers or the stack in
3892 register-sized pieces. Large arguments are split between
3893 registers and stack. */
3894 /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
3895 are treated specially: Irix cc passes
3896 them in registers where gcc sometimes puts them on the
3897 stack. For maximum compatibility, we will put them in
3899 int odd_sized_struct
= (len
> MIPS32_REGSIZE
3900 && len
% MIPS32_REGSIZE
!= 0);
3901 /* Structures should be aligned to eight bytes (even arg registers)
3902 on MIPS_ABI_O32, if their first member has double precision. */
3903 if (mips_type_needs_double_align (arg_type
))
3908 stack_offset
+= MIPS32_REGSIZE
;
3913 /* Remember if the argument was written to the stack. */
3914 int stack_used_p
= 0;
3915 int partial_len
= (len
< MIPS32_REGSIZE
? len
: MIPS32_REGSIZE
);
3918 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3921 /* Write this portion of the argument to the stack. */
3922 if (argreg
> MIPS_LAST_ARG_REGNUM (gdbarch
)
3923 || odd_sized_struct
)
3925 /* Should shorter than int integer values be
3926 promoted to int before being stored? */
3927 int longword_offset
= 0;
3933 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=%s",
3934 paddress (gdbarch
, stack_offset
));
3935 fprintf_unfiltered (gdb_stdlog
, " longword_offset=%s",
3936 paddress (gdbarch
, longword_offset
));
3939 addr
= sp
+ stack_offset
+ longword_offset
;
3944 fprintf_unfiltered (gdb_stdlog
, " @%s ",
3945 paddress (gdbarch
, addr
));
3946 for (i
= 0; i
< partial_len
; i
++)
3948 fprintf_unfiltered (gdb_stdlog
, "%02x",
3952 write_memory (addr
, val
, partial_len
);
3955 /* Note!!! This is NOT an else clause. Odd sized
3956 structs may go thru BOTH paths. */
3957 /* Write this portion of the argument to a general
3958 purpose register. */
3959 if (argreg
<= MIPS_LAST_ARG_REGNUM (gdbarch
))
3961 LONGEST regval
= extract_signed_integer (val
, partial_len
,
3963 /* Value may need to be sign extended, because
3964 mips_isa_regsize() != mips_abi_regsize(). */
3966 /* A non-floating-point argument being passed in a
3967 general register. If a struct or union, and if
3968 the remaining length is smaller than the register
3969 size, we have to adjust the register value on
3972 It does not seem to be necessary to do the
3973 same for integral types.
3975 Also don't do this adjustment on O64 binaries.
3977 cagney/2001-07-23: gdb/179: Also, GCC, when
3978 outputting LE O32 with sizeof (struct) <
3979 mips_abi_regsize(), generates a left shift
3980 as part of storing the argument in a register
3981 (the left shift isn't generated when
3982 sizeof (struct) >= mips_abi_regsize()). Since
3983 it is quite possible that this is GCC
3984 contradicting the LE/O32 ABI, GDB has not been
3985 adjusted to accommodate this. Either someone
3986 needs to demonstrate that the LE/O32 ABI
3987 specifies such a left shift OR this new ABI gets
3988 identified as such and GDB gets tweaked
3991 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
3992 && partial_len
< MIPS32_REGSIZE
3993 && (typecode
== TYPE_CODE_STRUCT
3994 || typecode
== TYPE_CODE_UNION
))
3995 regval
<<= ((MIPS32_REGSIZE
- partial_len
)
3999 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
4001 phex (regval
, MIPS32_REGSIZE
));
4002 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
4005 /* Prevent subsequent floating point arguments from
4006 being passed in floating point registers. */
4007 float_argreg
= MIPS_LAST_FP_ARG_REGNUM (gdbarch
) + 1;
4013 /* Compute the the offset into the stack at which we
4014 will copy the next parameter.
4016 In older ABIs, the caller reserved space for
4017 registers that contained arguments. This was loosely
4018 refered to as their "home". Consequently, space is
4019 always allocated. */
4021 stack_offset
+= align_up (partial_len
, MIPS32_REGSIZE
);
4025 fprintf_unfiltered (gdb_stdlog
, "\n");
4028 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
4030 /* Return adjusted stack pointer. */
4034 static enum return_value_convention
4035 mips_o32_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
4036 struct type
*type
, struct regcache
*regcache
,
4037 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
4039 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4041 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4042 || TYPE_CODE (type
) == TYPE_CODE_UNION
4043 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
4044 return RETURN_VALUE_STRUCT_CONVENTION
;
4045 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
4046 && TYPE_LENGTH (type
) == 4 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4048 /* A single-precision floating-point value. It fits in the
4049 least significant part of FP0. */
4051 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
4052 mips_xfer_register (gdbarch
, regcache
,
4053 gdbarch_num_regs (gdbarch
)
4054 + mips_regnum (gdbarch
)->fp0
,
4056 gdbarch_byte_order (gdbarch
),
4057 readbuf
, writebuf
, 0);
4058 return RETURN_VALUE_REGISTER_CONVENTION
;
4060 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
4061 && TYPE_LENGTH (type
) == 8 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4063 /* A double-precision floating-point value. The most
4064 significant part goes in FP1, and the least significant in
4067 fprintf_unfiltered (gdb_stderr
, "Return float in $fp1/$fp0\n");
4068 switch (gdbarch_byte_order (gdbarch
))
4070 case BFD_ENDIAN_LITTLE
:
4071 mips_xfer_register (gdbarch
, regcache
,
4072 gdbarch_num_regs (gdbarch
)
4073 + mips_regnum (gdbarch
)->fp0
+
4074 0, 4, gdbarch_byte_order (gdbarch
),
4075 readbuf
, writebuf
, 0);
4076 mips_xfer_register (gdbarch
, regcache
,
4077 gdbarch_num_regs (gdbarch
)
4078 + mips_regnum (gdbarch
)->fp0
+ 1,
4079 4, gdbarch_byte_order (gdbarch
),
4080 readbuf
, writebuf
, 4);
4082 case BFD_ENDIAN_BIG
:
4083 mips_xfer_register (gdbarch
, regcache
,
4084 gdbarch_num_regs (gdbarch
)
4085 + mips_regnum (gdbarch
)->fp0
+ 1,
4086 4, gdbarch_byte_order (gdbarch
),
4087 readbuf
, writebuf
, 0);
4088 mips_xfer_register (gdbarch
, regcache
,
4089 gdbarch_num_regs (gdbarch
)
4090 + mips_regnum (gdbarch
)->fp0
+ 0,
4091 4, gdbarch_byte_order (gdbarch
),
4092 readbuf
, writebuf
, 4);
4095 internal_error (__FILE__
, __LINE__
, _("bad switch"));
4097 return RETURN_VALUE_REGISTER_CONVENTION
;
4100 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4101 && TYPE_NFIELDS (type
) <= 2
4102 && TYPE_NFIELDS (type
) >= 1
4103 && ((TYPE_NFIELDS (type
) == 1
4104 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4106 || (TYPE_NFIELDS (type
) == 2
4107 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4109 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 1))
4111 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4113 /* A struct that contains one or two floats. Each value is part
4114 in the least significant part of their floating point
4116 gdb_byte reg
[MAX_REGISTER_SIZE
];
4119 for (field
= 0, regnum
= mips_regnum (gdbarch
)->fp0
;
4120 field
< TYPE_NFIELDS (type
); field
++, regnum
+= 2)
4122 int offset
= (FIELD_BITPOS (TYPE_FIELDS (type
)[field
])
4125 fprintf_unfiltered (gdb_stderr
, "Return float struct+%d\n",
4127 mips_xfer_register (gdbarch
, regcache
,
4128 gdbarch_num_regs (gdbarch
) + regnum
,
4129 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, field
)),
4130 gdbarch_byte_order (gdbarch
),
4131 readbuf
, writebuf
, offset
);
4133 return RETURN_VALUE_REGISTER_CONVENTION
;
4137 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4138 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
4140 /* A structure or union. Extract the left justified value,
4141 regardless of the byte order. I.e. DO NOT USE
4145 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
4146 offset
< TYPE_LENGTH (type
);
4147 offset
+= register_size (gdbarch
, regnum
), regnum
++)
4149 int xfer
= register_size (gdbarch
, regnum
);
4150 if (offset
+ xfer
> TYPE_LENGTH (type
))
4151 xfer
= TYPE_LENGTH (type
) - offset
;
4153 fprintf_unfiltered (gdb_stderr
, "Return struct+%d:%d in $%d\n",
4154 offset
, xfer
, regnum
);
4155 mips_xfer_register (gdbarch
, regcache
,
4156 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
4157 BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
, offset
);
4159 return RETURN_VALUE_REGISTER_CONVENTION
;
4164 /* A scalar extract each part but least-significant-byte
4165 justified. o32 thinks registers are 4 byte, regardless of
4169 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
4170 offset
< TYPE_LENGTH (type
);
4171 offset
+= MIPS32_REGSIZE
, regnum
++)
4173 int xfer
= MIPS32_REGSIZE
;
4174 if (offset
+ xfer
> TYPE_LENGTH (type
))
4175 xfer
= TYPE_LENGTH (type
) - offset
;
4177 fprintf_unfiltered (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
4178 offset
, xfer
, regnum
);
4179 mips_xfer_register (gdbarch
, regcache
,
4180 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
4181 gdbarch_byte_order (gdbarch
),
4182 readbuf
, writebuf
, offset
);
4184 return RETURN_VALUE_REGISTER_CONVENTION
;
4188 /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
4192 mips_o64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
4193 struct regcache
*regcache
, CORE_ADDR bp_addr
,
4195 struct value
**args
, CORE_ADDR sp
,
4196 int struct_return
, CORE_ADDR struct_addr
)
4202 int stack_offset
= 0;
4203 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4204 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4205 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
4207 /* For shared libraries, "t9" needs to point at the function
4209 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
4211 /* Set the return address register to point to the entry point of
4212 the program, where a breakpoint lies in wait. */
4213 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
4215 /* First ensure that the stack and structure return address (if any)
4216 are properly aligned. The stack has to be at least 64-bit
4217 aligned even on 32-bit machines, because doubles must be 64-bit
4218 aligned. For n32 and n64, stack frames need to be 128-bit
4219 aligned, so we round to this widest known alignment. */
4221 sp
= align_down (sp
, 16);
4222 struct_addr
= align_down (struct_addr
, 16);
4224 /* Now make space on the stack for the args. */
4225 for (argnum
= 0; argnum
< nargs
; argnum
++)
4227 struct type
*arg_type
= check_typedef (value_type (args
[argnum
]));
4228 int arglen
= TYPE_LENGTH (arg_type
);
4230 /* Allocate space on the stack. */
4231 len
+= align_up (arglen
, MIPS64_REGSIZE
);
4233 sp
-= align_up (len
, 16);
4236 fprintf_unfiltered (gdb_stdlog
,
4237 "mips_o64_push_dummy_call: sp=%s allocated %ld\n",
4238 paddress (gdbarch
, sp
), (long) align_up (len
, 16));
4240 /* Initialize the integer and float register pointers. */
4241 argreg
= MIPS_A0_REGNUM
;
4242 float_argreg
= mips_fpa0_regnum (gdbarch
);
4244 /* The struct_return pointer occupies the first parameter-passing reg. */
4248 fprintf_unfiltered (gdb_stdlog
,
4249 "mips_o64_push_dummy_call: "
4250 "struct_return reg=%d %s\n",
4251 argreg
, paddress (gdbarch
, struct_addr
));
4252 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
4253 stack_offset
+= MIPS64_REGSIZE
;
4256 /* Now load as many as possible of the first arguments into
4257 registers, and push the rest onto the stack. Loop thru args
4258 from first to last. */
4259 for (argnum
= 0; argnum
< nargs
; argnum
++)
4261 const gdb_byte
*val
;
4262 gdb_byte valbuf
[MAX_REGISTER_SIZE
];
4263 struct value
*arg
= args
[argnum
];
4264 struct type
*arg_type
= check_typedef (value_type (arg
));
4265 int len
= TYPE_LENGTH (arg_type
);
4266 enum type_code typecode
= TYPE_CODE (arg_type
);
4269 fprintf_unfiltered (gdb_stdlog
,
4270 "mips_o64_push_dummy_call: %d len=%d type=%d",
4271 argnum
+ 1, len
, (int) typecode
);
4273 val
= value_contents (arg
);
4275 /* Function pointer arguments to mips16 code need to be made into
4277 if (typecode
== TYPE_CODE_PTR
4278 && TYPE_CODE (TYPE_TARGET_TYPE (arg_type
)) == TYPE_CODE_FUNC
)
4280 CORE_ADDR addr
= extract_signed_integer (value_contents (arg
),
4282 if (mips_pc_is_mips16 (addr
))
4284 store_signed_integer (valbuf
, len
, byte_order
,
4285 make_mips16_addr (addr
));
4290 /* Floating point arguments passed in registers have to be
4291 treated specially. On 32-bit architectures, doubles
4292 are passed in register pairs; the even register gets
4293 the low word, and the odd register gets the high word.
4294 On O32/O64, the first two floating point arguments are
4295 also copied to general registers, because MIPS16 functions
4296 don't use float registers for arguments. This duplication of
4297 arguments in general registers can't hurt non-MIPS16 functions
4298 because those registers are normally skipped. */
4300 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
4301 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM (gdbarch
))
4303 LONGEST regval
= extract_unsigned_integer (val
, len
, byte_order
);
4305 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
4306 float_argreg
, phex (regval
, len
));
4307 regcache_cooked_write_unsigned (regcache
, float_argreg
++, regval
);
4309 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
4310 argreg
, phex (regval
, len
));
4311 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
4313 /* Reserve space for the FP register. */
4314 stack_offset
+= align_up (len
, MIPS64_REGSIZE
);
4318 /* Copy the argument to general registers or the stack in
4319 register-sized pieces. Large arguments are split between
4320 registers and stack. */
4321 /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
4322 are treated specially: Irix cc passes them in registers
4323 where gcc sometimes puts them on the stack. For maximum
4324 compatibility, we will put them in both places. */
4325 int odd_sized_struct
= (len
> MIPS64_REGSIZE
4326 && len
% MIPS64_REGSIZE
!= 0);
4329 /* Remember if the argument was written to the stack. */
4330 int stack_used_p
= 0;
4331 int partial_len
= (len
< MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
4334 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
4337 /* Write this portion of the argument to the stack. */
4338 if (argreg
> MIPS_LAST_ARG_REGNUM (gdbarch
)
4339 || odd_sized_struct
)
4341 /* Should shorter than int integer values be
4342 promoted to int before being stored? */
4343 int longword_offset
= 0;
4346 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4348 if ((typecode
== TYPE_CODE_INT
4349 || typecode
== TYPE_CODE_PTR
4350 || typecode
== TYPE_CODE_FLT
)
4352 longword_offset
= MIPS64_REGSIZE
- len
;
4357 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=%s",
4358 paddress (gdbarch
, stack_offset
));
4359 fprintf_unfiltered (gdb_stdlog
, " longword_offset=%s",
4360 paddress (gdbarch
, longword_offset
));
4363 addr
= sp
+ stack_offset
+ longword_offset
;
4368 fprintf_unfiltered (gdb_stdlog
, " @%s ",
4369 paddress (gdbarch
, addr
));
4370 for (i
= 0; i
< partial_len
; i
++)
4372 fprintf_unfiltered (gdb_stdlog
, "%02x",
4376 write_memory (addr
, val
, partial_len
);
4379 /* Note!!! This is NOT an else clause. Odd sized
4380 structs may go thru BOTH paths. */
4381 /* Write this portion of the argument to a general
4382 purpose register. */
4383 if (argreg
<= MIPS_LAST_ARG_REGNUM (gdbarch
))
4385 LONGEST regval
= extract_signed_integer (val
, partial_len
,
4387 /* Value may need to be sign extended, because
4388 mips_isa_regsize() != mips_abi_regsize(). */
4390 /* A non-floating-point argument being passed in a
4391 general register. If a struct or union, and if
4392 the remaining length is smaller than the register
4393 size, we have to adjust the register value on
4396 It does not seem to be necessary to do the
4397 same for integral types. */
4399 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
4400 && partial_len
< MIPS64_REGSIZE
4401 && (typecode
== TYPE_CODE_STRUCT
4402 || typecode
== TYPE_CODE_UNION
))
4403 regval
<<= ((MIPS64_REGSIZE
- partial_len
)
4407 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
4409 phex (regval
, MIPS64_REGSIZE
));
4410 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
4413 /* Prevent subsequent floating point arguments from
4414 being passed in floating point registers. */
4415 float_argreg
= MIPS_LAST_FP_ARG_REGNUM (gdbarch
) + 1;
4421 /* Compute the the offset into the stack at which we
4422 will copy the next parameter.
4424 In older ABIs, the caller reserved space for
4425 registers that contained arguments. This was loosely
4426 refered to as their "home". Consequently, space is
4427 always allocated. */
4429 stack_offset
+= align_up (partial_len
, MIPS64_REGSIZE
);
4433 fprintf_unfiltered (gdb_stdlog
, "\n");
4436 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
4438 /* Return adjusted stack pointer. */
4442 static enum return_value_convention
4443 mips_o64_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
4444 struct type
*type
, struct regcache
*regcache
,
4445 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
4447 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
4449 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4450 || TYPE_CODE (type
) == TYPE_CODE_UNION
4451 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
4452 return RETURN_VALUE_STRUCT_CONVENTION
;
4453 else if (fp_register_arg_p (gdbarch
, TYPE_CODE (type
), type
))
4455 /* A floating-point value. It fits in the least significant
4458 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
4459 mips_xfer_register (gdbarch
, regcache
,
4460 gdbarch_num_regs (gdbarch
)
4461 + mips_regnum (gdbarch
)->fp0
,
4463 gdbarch_byte_order (gdbarch
),
4464 readbuf
, writebuf
, 0);
4465 return RETURN_VALUE_REGISTER_CONVENTION
;
4469 /* A scalar extract each part but least-significant-byte
4473 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
4474 offset
< TYPE_LENGTH (type
);
4475 offset
+= MIPS64_REGSIZE
, regnum
++)
4477 int xfer
= MIPS64_REGSIZE
;
4478 if (offset
+ xfer
> TYPE_LENGTH (type
))
4479 xfer
= TYPE_LENGTH (type
) - offset
;
4481 fprintf_unfiltered (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
4482 offset
, xfer
, regnum
);
4483 mips_xfer_register (gdbarch
, regcache
,
4484 gdbarch_num_regs (gdbarch
) + regnum
,
4485 xfer
, gdbarch_byte_order (gdbarch
),
4486 readbuf
, writebuf
, offset
);
4488 return RETURN_VALUE_REGISTER_CONVENTION
;
4492 /* Floating point register management.
4494 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4495 64bit operations, these early MIPS cpus treat fp register pairs
4496 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4497 registers and offer a compatibility mode that emulates the MIPS2 fp
4498 model. When operating in MIPS2 fp compat mode, later cpu's split
4499 double precision floats into two 32-bit chunks and store them in
4500 consecutive fp regs. To display 64-bit floats stored in this
4501 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4502 Throw in user-configurable endianness and you have a real mess.
4504 The way this works is:
4505 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4506 double-precision value will be split across two logical registers.
4507 The lower-numbered logical register will hold the low-order bits,
4508 regardless of the processor's endianness.
4509 - If we are on a 64-bit processor, and we are looking for a
4510 single-precision value, it will be in the low ordered bits
4511 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4512 save slot in memory.
4513 - If we are in 64-bit mode, everything is straightforward.
4515 Note that this code only deals with "live" registers at the top of the
4516 stack. We will attempt to deal with saved registers later, when
4517 the raw/cooked register interface is in place. (We need a general
4518 interface that can deal with dynamic saved register sizes -- fp
4519 regs could be 32 bits wide in one frame and 64 on the frame above
4522 /* Copy a 32-bit single-precision value from the current frame
4523 into rare_buffer. */
4526 mips_read_fp_register_single (struct frame_info
*frame
, int regno
,
4527 gdb_byte
*rare_buffer
)
4529 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4530 int raw_size
= register_size (gdbarch
, regno
);
4531 gdb_byte
*raw_buffer
= alloca (raw_size
);
4533 if (!frame_register_read (frame
, regno
, raw_buffer
))
4534 error (_("can't read register %d (%s)"),
4535 regno
, gdbarch_register_name (gdbarch
, regno
));
4538 /* We have a 64-bit value for this register. Find the low-order
4542 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4547 memcpy (rare_buffer
, raw_buffer
+ offset
, 4);
4551 memcpy (rare_buffer
, raw_buffer
, 4);
4555 /* Copy a 64-bit double-precision value from the current frame into
4556 rare_buffer. This may include getting half of it from the next
4560 mips_read_fp_register_double (struct frame_info
*frame
, int regno
,
4561 gdb_byte
*rare_buffer
)
4563 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4564 int raw_size
= register_size (gdbarch
, regno
);
4566 if (raw_size
== 8 && !mips2_fp_compat (frame
))
4568 /* We have a 64-bit value for this register, and we should use
4570 if (!frame_register_read (frame
, regno
, rare_buffer
))
4571 error (_("can't read register %d (%s)"),
4572 regno
, gdbarch_register_name (gdbarch
, regno
));
4576 int rawnum
= regno
% gdbarch_num_regs (gdbarch
);
4578 if ((rawnum
- mips_regnum (gdbarch
)->fp0
) & 1)
4579 internal_error (__FILE__
, __LINE__
,
4580 _("mips_read_fp_register_double: bad access to "
4581 "odd-numbered FP register"));
4583 /* mips_read_fp_register_single will find the correct 32 bits from
4585 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4587 mips_read_fp_register_single (frame
, regno
, rare_buffer
+ 4);
4588 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
);
4592 mips_read_fp_register_single (frame
, regno
, rare_buffer
);
4593 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
+ 4);
4599 mips_print_fp_register (struct ui_file
*file
, struct frame_info
*frame
,
4601 { /* Do values for FP (float) regs. */
4602 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4603 gdb_byte
*raw_buffer
;
4604 double doub
, flt1
; /* Doubles extracted from raw hex data. */
4607 raw_buffer
= alloca (2 * register_size (gdbarch
,
4608 mips_regnum (gdbarch
)->fp0
));
4610 fprintf_filtered (file
, "%s:", gdbarch_register_name (gdbarch
, regnum
));
4611 fprintf_filtered (file
, "%*s",
4612 4 - (int) strlen (gdbarch_register_name (gdbarch
, regnum
)),
4615 if (register_size (gdbarch
, regnum
) == 4 || mips2_fp_compat (frame
))
4617 struct value_print_options opts
;
4619 /* 4-byte registers: Print hex and floating. Also print even
4620 numbered registers as doubles. */
4621 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
4622 flt1
= unpack_double (builtin_type (gdbarch
)->builtin_float
,
4625 get_formatted_print_options (&opts
, 'x');
4626 print_scalar_formatted (raw_buffer
,
4627 builtin_type (gdbarch
)->builtin_uint32
,
4630 fprintf_filtered (file
, " flt: ");
4632 fprintf_filtered (file
, " <invalid float> ");
4634 fprintf_filtered (file
, "%-17.9g", flt1
);
4636 if ((regnum
- gdbarch_num_regs (gdbarch
)) % 2 == 0)
4638 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
4639 doub
= unpack_double (builtin_type (gdbarch
)->builtin_double
,
4642 fprintf_filtered (file
, " dbl: ");
4644 fprintf_filtered (file
, "<invalid double>");
4646 fprintf_filtered (file
, "%-24.17g", doub
);
4651 struct value_print_options opts
;
4653 /* Eight byte registers: print each one as hex, float and double. */
4654 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
4655 flt1
= unpack_double (builtin_type (gdbarch
)->builtin_float
,
4658 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
4659 doub
= unpack_double (builtin_type (gdbarch
)->builtin_double
,
4662 get_formatted_print_options (&opts
, 'x');
4663 print_scalar_formatted (raw_buffer
,
4664 builtin_type (gdbarch
)->builtin_uint64
,
4667 fprintf_filtered (file
, " flt: ");
4669 fprintf_filtered (file
, "<invalid float>");
4671 fprintf_filtered (file
, "%-17.9g", flt1
);
4673 fprintf_filtered (file
, " dbl: ");
4675 fprintf_filtered (file
, "<invalid double>");
4677 fprintf_filtered (file
, "%-24.17g", doub
);
4682 mips_print_register (struct ui_file
*file
, struct frame_info
*frame
,
4685 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4686 gdb_byte raw_buffer
[MAX_REGISTER_SIZE
];
4688 struct value_print_options opts
;
4690 if (TYPE_CODE (register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
)
4692 mips_print_fp_register (file
, frame
, regnum
);
4696 /* Get the data in raw format. */
4697 if (!frame_register_read (frame
, regnum
, raw_buffer
))
4699 fprintf_filtered (file
, "%s: [Invalid]",
4700 gdbarch_register_name (gdbarch
, regnum
));
4704 fputs_filtered (gdbarch_register_name (gdbarch
, regnum
), file
);
4706 /* The problem with printing numeric register names (r26, etc.) is that
4707 the user can't use them on input. Probably the best solution is to
4708 fix it so that either the numeric or the funky (a2, etc.) names
4709 are accepted on input. */
4710 if (regnum
< MIPS_NUMREGS
)
4711 fprintf_filtered (file
, "(r%d): ", regnum
);
4713 fprintf_filtered (file
, ": ");
4715 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4717 register_size (gdbarch
, regnum
) - register_size (gdbarch
, regnum
);
4721 get_formatted_print_options (&opts
, 'x');
4722 print_scalar_formatted (raw_buffer
+ offset
,
4723 register_type (gdbarch
, regnum
), &opts
, 0,
4727 /* Replacement for generic do_registers_info.
4728 Print regs in pretty columns. */
4731 print_fp_register_row (struct ui_file
*file
, struct frame_info
*frame
,
4734 fprintf_filtered (file
, " ");
4735 mips_print_fp_register (file
, frame
, regnum
);
4736 fprintf_filtered (file
, "\n");
4741 /* Print a row's worth of GP (int) registers, with name labels above. */
4744 print_gp_register_row (struct ui_file
*file
, struct frame_info
*frame
,
4747 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4748 /* Do values for GP (int) regs. */
4749 gdb_byte raw_buffer
[MAX_REGISTER_SIZE
];
4750 int ncols
= (mips_abi_regsize (gdbarch
) == 8 ? 4 : 8); /* display cols
4755 /* For GP registers, we print a separate row of names above the vals. */
4756 for (col
= 0, regnum
= start_regnum
;
4757 col
< ncols
&& regnum
< gdbarch_num_regs (gdbarch
)
4758 + gdbarch_num_pseudo_regs (gdbarch
);
4761 if (*gdbarch_register_name (gdbarch
, regnum
) == '\0')
4762 continue; /* unused register */
4763 if (TYPE_CODE (register_type (gdbarch
, regnum
)) ==
4765 break; /* End the row: reached FP register. */
4766 /* Large registers are handled separately. */
4767 if (register_size (gdbarch
, regnum
) > mips_abi_regsize (gdbarch
))
4770 break; /* End the row before this register. */
4772 /* Print this register on a row by itself. */
4773 mips_print_register (file
, frame
, regnum
);
4774 fprintf_filtered (file
, "\n");
4778 fprintf_filtered (file
, " ");
4779 fprintf_filtered (file
,
4780 mips_abi_regsize (gdbarch
) == 8 ? "%17s" : "%9s",
4781 gdbarch_register_name (gdbarch
, regnum
));
4788 /* Print the R0 to R31 names. */
4789 if ((start_regnum
% gdbarch_num_regs (gdbarch
)) < MIPS_NUMREGS
)
4790 fprintf_filtered (file
, "\n R%-4d",
4791 start_regnum
% gdbarch_num_regs (gdbarch
));
4793 fprintf_filtered (file
, "\n ");
4795 /* Now print the values in hex, 4 or 8 to the row. */
4796 for (col
= 0, regnum
= start_regnum
;
4797 col
< ncols
&& regnum
< gdbarch_num_regs (gdbarch
)
4798 + gdbarch_num_pseudo_regs (gdbarch
);
4801 if (*gdbarch_register_name (gdbarch
, regnum
) == '\0')
4802 continue; /* unused register */
4803 if (TYPE_CODE (register_type (gdbarch
, regnum
)) ==
4805 break; /* End row: reached FP register. */
4806 if (register_size (gdbarch
, regnum
) > mips_abi_regsize (gdbarch
))
4807 break; /* End row: large register. */
4809 /* OK: get the data in raw format. */
4810 if (!frame_register_read (frame
, regnum
, raw_buffer
))
4811 error (_("can't read register %d (%s)"),
4812 regnum
, gdbarch_register_name (gdbarch
, regnum
));
4813 /* pad small registers */
4815 byte
< (mips_abi_regsize (gdbarch
)
4816 - register_size (gdbarch
, regnum
)); byte
++)
4817 printf_filtered (" ");
4818 /* Now print the register value in hex, endian order. */
4819 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4821 register_size (gdbarch
, regnum
) - register_size (gdbarch
, regnum
);
4822 byte
< register_size (gdbarch
, regnum
); byte
++)
4823 fprintf_filtered (file
, "%02x", raw_buffer
[byte
]);
4825 for (byte
= register_size (gdbarch
, regnum
) - 1;
4827 fprintf_filtered (file
, "%02x", raw_buffer
[byte
]);
4828 fprintf_filtered (file
, " ");
4831 if (col
> 0) /* ie. if we actually printed anything... */
4832 fprintf_filtered (file
, "\n");
4837 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */
4840 mips_print_registers_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
4841 struct frame_info
*frame
, int regnum
, int all
)
4843 if (regnum
!= -1) /* Do one specified register. */
4845 gdb_assert (regnum
>= gdbarch_num_regs (gdbarch
));
4846 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
4847 error (_("Not a valid register for the current processor type"));
4849 mips_print_register (file
, frame
, regnum
);
4850 fprintf_filtered (file
, "\n");
4853 /* Do all (or most) registers. */
4855 regnum
= gdbarch_num_regs (gdbarch
);
4856 while (regnum
< gdbarch_num_regs (gdbarch
)
4857 + gdbarch_num_pseudo_regs (gdbarch
))
4859 if (TYPE_CODE (register_type (gdbarch
, regnum
)) ==
4862 if (all
) /* True for "INFO ALL-REGISTERS" command. */
4863 regnum
= print_fp_register_row (file
, frame
, regnum
);
4865 regnum
+= MIPS_NUMREGS
; /* Skip floating point regs. */
4868 regnum
= print_gp_register_row (file
, frame
, regnum
);
4873 /* Is this a branch with a delay slot? */
4876 is_delayed (unsigned long insn
)
4879 for (i
= 0; i
< NUMOPCODES
; ++i
)
4880 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
4881 && (insn
& mips_opcodes
[i
].mask
) == mips_opcodes
[i
].match
)
4883 return (i
< NUMOPCODES
4884 && (mips_opcodes
[i
].pinfo
& (INSN_UNCOND_BRANCH_DELAY
4885 | INSN_COND_BRANCH_DELAY
4886 | INSN_COND_BRANCH_LIKELY
)));
4890 mips_single_step_through_delay (struct gdbarch
*gdbarch
,
4891 struct frame_info
*frame
)
4893 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4894 CORE_ADDR pc
= get_frame_pc (frame
);
4895 gdb_byte buf
[MIPS_INSN32_SIZE
];
4897 /* There is no branch delay slot on MIPS16. */
4898 if (mips_pc_is_mips16 (pc
))
4901 if (!breakpoint_here_p (get_frame_address_space (frame
), pc
+ 4))
4904 if (!safe_frame_unwind_memory (frame
, pc
, buf
, sizeof buf
))
4905 /* If error reading memory, guess that it is not a delayed
4908 return is_delayed (extract_unsigned_integer (buf
, sizeof buf
, byte_order
));
4911 /* To skip prologues, I use this predicate. Returns either PC itself
4912 if the code at PC does not look like a function prologue; otherwise
4913 returns an address that (if we're lucky) follows the prologue. If
4914 LENIENT, then we must skip everything which is involved in setting
4915 up the frame (it's OK to skip more, just so long as we don't skip
4916 anything which might clobber the registers which are being saved.
4917 We must skip more in the case where part of the prologue is in the
4918 delay slot of a non-prologue instruction). */
4921 mips_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4924 CORE_ADDR func_addr
;
4926 /* See if we can determine the end of the prologue via the symbol table.
4927 If so, then return either PC, or the PC after the prologue, whichever
4929 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
))
4931 CORE_ADDR post_prologue_pc
4932 = skip_prologue_using_sal (gdbarch
, func_addr
);
4933 if (post_prologue_pc
!= 0)
4934 return max (pc
, post_prologue_pc
);
4937 /* Can't determine prologue from the symbol table, need to examine
4940 /* Find an upper limit on the function prologue using the debug
4941 information. If the debug information could not be used to provide
4942 that bound, then use an arbitrary large number as the upper bound. */
4943 limit_pc
= skip_prologue_using_sal (gdbarch
, pc
);
4945 limit_pc
= pc
+ 100; /* Magic. */
4947 if (mips_pc_is_mips16 (pc
))
4948 return mips16_scan_prologue (gdbarch
, pc
, limit_pc
, NULL
, NULL
);
4950 return mips32_scan_prologue (gdbarch
, pc
, limit_pc
, NULL
, NULL
);
4953 /* Check whether the PC is in a function epilogue (32-bit version).
4954 This is a helper function for mips_in_function_epilogue_p. */
4956 mips32_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4958 CORE_ADDR func_addr
= 0, func_end
= 0;
4960 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
4962 /* The MIPS epilogue is max. 12 bytes long. */
4963 CORE_ADDR addr
= func_end
- 12;
4965 if (addr
< func_addr
+ 4)
4966 addr
= func_addr
+ 4;
4970 for (; pc
< func_end
; pc
+= MIPS_INSN32_SIZE
)
4972 unsigned long high_word
;
4975 inst
= mips_fetch_instruction (gdbarch
, pc
);
4976 high_word
= (inst
>> 16) & 0xffff;
4978 if (high_word
!= 0x27bd /* addiu $sp,$sp,offset */
4979 && high_word
!= 0x67bd /* daddiu $sp,$sp,offset */
4980 && inst
!= 0x03e00008 /* jr $ra */
4981 && inst
!= 0x00000000) /* nop */
4991 /* Check whether the PC is in a function epilogue (16-bit version).
4992 This is a helper function for mips_in_function_epilogue_p. */
4994 mips16_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4996 CORE_ADDR func_addr
= 0, func_end
= 0;
4998 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
5000 /* The MIPS epilogue is max. 12 bytes long. */
5001 CORE_ADDR addr
= func_end
- 12;
5003 if (addr
< func_addr
+ 4)
5004 addr
= func_addr
+ 4;
5008 for (; pc
< func_end
; pc
+= MIPS_INSN16_SIZE
)
5010 unsigned short inst
;
5012 inst
= mips_fetch_instruction (gdbarch
, pc
);
5014 if ((inst
& 0xf800) == 0xf000) /* extend */
5017 if (inst
!= 0x6300 /* addiu $sp,offset */
5018 && inst
!= 0xfb00 /* daddiu $sp,$sp,offset */
5019 && inst
!= 0xe820 /* jr $ra */
5020 && inst
!= 0xe8a0 /* jrc $ra */
5021 && inst
!= 0x6500) /* nop */
5031 /* The epilogue is defined here as the area at the end of a function,
5032 after an instruction which destroys the function's stack frame. */
5034 mips_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5036 if (mips_pc_is_mips16 (pc
))
5037 return mips16_in_function_epilogue_p (gdbarch
, pc
);
5039 return mips32_in_function_epilogue_p (gdbarch
, pc
);
5042 /* Root of all "set mips "/"show mips " commands. This will eventually be
5043 used for all MIPS-specific commands. */
5046 show_mips_command (char *args
, int from_tty
)
5048 help_list (showmipscmdlist
, "show mips ", all_commands
, gdb_stdout
);
5052 set_mips_command (char *args
, int from_tty
)
5055 ("\"set mips\" must be followed by an appropriate subcommand.\n");
5056 help_list (setmipscmdlist
, "set mips ", all_commands
, gdb_stdout
);
5059 /* Commands to show/set the MIPS FPU type. */
5062 show_mipsfpu_command (char *args
, int from_tty
)
5066 if (gdbarch_bfd_arch_info (target_gdbarch
)->arch
!= bfd_arch_mips
)
5069 ("The MIPS floating-point coprocessor is unknown "
5070 "because the current architecture is not MIPS.\n");
5074 switch (MIPS_FPU_TYPE (target_gdbarch
))
5076 case MIPS_FPU_SINGLE
:
5077 fpu
= "single-precision";
5079 case MIPS_FPU_DOUBLE
:
5080 fpu
= "double-precision";
5083 fpu
= "absent (none)";
5086 internal_error (__FILE__
, __LINE__
, _("bad switch"));
5088 if (mips_fpu_type_auto
)
5089 printf_unfiltered ("The MIPS floating-point coprocessor "
5090 "is set automatically (currently %s)\n",
5094 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu
);
5099 set_mipsfpu_command (char *args
, int from_tty
)
5101 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", "
5102 "\"single\",\"none\" or \"auto\".\n");
5103 show_mipsfpu_command (args
, from_tty
);
5107 set_mipsfpu_single_command (char *args
, int from_tty
)
5109 struct gdbarch_info info
;
5110 gdbarch_info_init (&info
);
5111 mips_fpu_type
= MIPS_FPU_SINGLE
;
5112 mips_fpu_type_auto
= 0;
5113 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5114 instead of relying on globals. Doing that would let generic code
5115 handle the search for this specific architecture. */
5116 if (!gdbarch_update_p (info
))
5117 internal_error (__FILE__
, __LINE__
, _("set mipsfpu failed"));
5121 set_mipsfpu_double_command (char *args
, int from_tty
)
5123 struct gdbarch_info info
;
5124 gdbarch_info_init (&info
);
5125 mips_fpu_type
= MIPS_FPU_DOUBLE
;
5126 mips_fpu_type_auto
= 0;
5127 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5128 instead of relying on globals. Doing that would let generic code
5129 handle the search for this specific architecture. */
5130 if (!gdbarch_update_p (info
))
5131 internal_error (__FILE__
, __LINE__
, _("set mipsfpu failed"));
5135 set_mipsfpu_none_command (char *args
, int from_tty
)
5137 struct gdbarch_info info
;
5138 gdbarch_info_init (&info
);
5139 mips_fpu_type
= MIPS_FPU_NONE
;
5140 mips_fpu_type_auto
= 0;
5141 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5142 instead of relying on globals. Doing that would let generic code
5143 handle the search for this specific architecture. */
5144 if (!gdbarch_update_p (info
))
5145 internal_error (__FILE__
, __LINE__
, _("set mipsfpu failed"));
5149 set_mipsfpu_auto_command (char *args
, int from_tty
)
5151 mips_fpu_type_auto
= 1;
5154 /* Attempt to identify the particular processor model by reading the
5155 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
5156 the relevant processor still exists (it dates back to '94) and
5157 secondly this is not the way to do this. The processor type should
5158 be set by forcing an architecture change. */
5161 deprecated_mips_set_processor_regs_hack (void)
5163 struct regcache
*regcache
= get_current_regcache ();
5164 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5165 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
5168 regcache_cooked_read_unsigned (regcache
, MIPS_PRID_REGNUM
, &prid
);
5169 if ((prid
& ~0xf) == 0x700)
5170 tdep
->mips_processor_reg_names
= mips_r3041_reg_names
;
5173 /* Just like reinit_frame_cache, but with the right arguments to be
5174 callable as an sfunc. */
5177 reinit_frame_cache_sfunc (char *args
, int from_tty
,
5178 struct cmd_list_element
*c
)
5180 reinit_frame_cache ();
5184 gdb_print_insn_mips (bfd_vma memaddr
, struct disassemble_info
*info
)
5186 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5187 disassembler needs to be able to locally determine the ISA, and
5188 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5190 if (mips_pc_is_mips16 (memaddr
))
5191 info
->mach
= bfd_mach_mips16
;
5193 /* Round down the instruction address to the appropriate boundary. */
5194 memaddr
&= (info
->mach
== bfd_mach_mips16
? ~1 : ~3);
5196 /* Set the disassembler options. */
5197 if (!info
->disassembler_options
)
5198 /* This string is not recognized explicitly by the disassembler,
5199 but it tells the disassembler to not try to guess the ABI from
5200 the bfd elf headers, such that, if the user overrides the ABI
5201 of a program linked as NewABI, the disassembly will follow the
5202 register naming conventions specified by the user. */
5203 info
->disassembler_options
= "gpr-names=32";
5205 /* Call the appropriate disassembler based on the target endian-ness. */
5206 if (info
->endian
== BFD_ENDIAN_BIG
)
5207 return print_insn_big_mips (memaddr
, info
);
5209 return print_insn_little_mips (memaddr
, info
);
5213 gdb_print_insn_mips_n32 (bfd_vma memaddr
, struct disassemble_info
*info
)
5215 /* Set up the disassembler info, so that we get the right
5216 register names from libopcodes. */
5217 info
->disassembler_options
= "gpr-names=n32";
5218 info
->flavour
= bfd_target_elf_flavour
;
5220 return gdb_print_insn_mips (memaddr
, info
);
5224 gdb_print_insn_mips_n64 (bfd_vma memaddr
, struct disassemble_info
*info
)
5226 /* Set up the disassembler info, so that we get the right
5227 register names from libopcodes. */
5228 info
->disassembler_options
= "gpr-names=64";
5229 info
->flavour
= bfd_target_elf_flavour
;
5231 return gdb_print_insn_mips (memaddr
, info
);
5234 /* This function implements gdbarch_breakpoint_from_pc. It uses the
5235 program counter value to determine whether a 16- or 32-bit breakpoint
5236 should be used. It returns a pointer to a string of bytes that encode a
5237 breakpoint instruction, stores the length of the string to *lenptr, and
5238 adjusts pc (if necessary) to point to the actual memory location where
5239 the breakpoint should be inserted. */
5241 static const gdb_byte
*
5242 mips_breakpoint_from_pc (struct gdbarch
*gdbarch
,
5243 CORE_ADDR
*pcptr
, int *lenptr
)
5245 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
5247 if (mips_pc_is_mips16 (*pcptr
))
5249 static gdb_byte mips16_big_breakpoint
[] = { 0xe8, 0xa5 };
5250 *pcptr
= unmake_mips16_addr (*pcptr
);
5251 *lenptr
= sizeof (mips16_big_breakpoint
);
5252 return mips16_big_breakpoint
;
5256 /* The IDT board uses an unusual breakpoint value, and
5257 sometimes gets confused when it sees the usual MIPS
5258 breakpoint instruction. */
5259 static gdb_byte big_breakpoint
[] = { 0, 0x5, 0, 0xd };
5260 static gdb_byte pmon_big_breakpoint
[] = { 0, 0, 0, 0xd };
5261 static gdb_byte idt_big_breakpoint
[] = { 0, 0, 0x0a, 0xd };
5262 /* Likewise, IRIX appears to expect a different breakpoint,
5263 although this is not apparent until you try to use pthreads. */
5264 static gdb_byte irix_big_breakpoint
[] = { 0, 0, 0, 0xd };
5266 *lenptr
= sizeof (big_breakpoint
);
5268 if (strcmp (target_shortname
, "mips") == 0)
5269 return idt_big_breakpoint
;
5270 else if (strcmp (target_shortname
, "ddb") == 0
5271 || strcmp (target_shortname
, "pmon") == 0
5272 || strcmp (target_shortname
, "lsi") == 0)
5273 return pmon_big_breakpoint
;
5274 else if (gdbarch_osabi (gdbarch
) == GDB_OSABI_IRIX
)
5275 return irix_big_breakpoint
;
5277 return big_breakpoint
;
5282 if (mips_pc_is_mips16 (*pcptr
))
5284 static gdb_byte mips16_little_breakpoint
[] = { 0xa5, 0xe8 };
5285 *pcptr
= unmake_mips16_addr (*pcptr
);
5286 *lenptr
= sizeof (mips16_little_breakpoint
);
5287 return mips16_little_breakpoint
;
5291 static gdb_byte little_breakpoint
[] = { 0xd, 0, 0x5, 0 };
5292 static gdb_byte pmon_little_breakpoint
[] = { 0xd, 0, 0, 0 };
5293 static gdb_byte idt_little_breakpoint
[] = { 0xd, 0x0a, 0, 0 };
5295 *lenptr
= sizeof (little_breakpoint
);
5297 if (strcmp (target_shortname
, "mips") == 0)
5298 return idt_little_breakpoint
;
5299 else if (strcmp (target_shortname
, "ddb") == 0
5300 || strcmp (target_shortname
, "pmon") == 0
5301 || strcmp (target_shortname
, "lsi") == 0)
5302 return pmon_little_breakpoint
;
5304 return little_breakpoint
;
5309 /* If PC is in a mips16 call or return stub, return the address of the target
5310 PC, which is either the callee or the caller. There are several
5311 cases which must be handled:
5313 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5314 target PC is in $31 ($ra).
5315 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5316 and the target PC is in $2.
5317 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5318 before the jal instruction, this is effectively a call stub
5319 and the the target PC is in $2. Otherwise this is effectively
5320 a return stub and the target PC is in $18.
5322 See the source code for the stubs in gcc/config/mips/mips16.S for
5326 mips_skip_mips16_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
5328 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
5330 CORE_ADDR start_addr
;
5332 /* Find the starting address and name of the function containing the PC. */
5333 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
5336 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5337 target PC is in $31 ($ra). */
5338 if (strcmp (name
, "__mips16_ret_sf") == 0
5339 || strcmp (name
, "__mips16_ret_df") == 0)
5340 return get_frame_register_signed (frame
, MIPS_RA_REGNUM
);
5342 if (strncmp (name
, "__mips16_call_stub_", 19) == 0)
5344 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5345 and the target PC is in $2. */
5346 if (name
[19] >= '0' && name
[19] <= '9')
5347 return get_frame_register_signed (frame
, 2);
5349 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5350 before the jal instruction, this is effectively a call stub
5351 and the the target PC is in $2. Otherwise this is effectively
5352 a return stub and the target PC is in $18. */
5353 else if (name
[19] == 's' || name
[19] == 'd')
5355 if (pc
== start_addr
)
5357 /* Check if the target of the stub is a compiler-generated
5358 stub. Such a stub for a function bar might have a name
5359 like __fn_stub_bar, and might look like this:
5364 la $1,bar (becomes a lui/addiu pair)
5366 So scan down to the lui/addi and extract the target
5367 address from those two instructions. */
5369 CORE_ADDR target_pc
= get_frame_register_signed (frame
, 2);
5373 /* See if the name of the target function is __fn_stub_*. */
5374 if (find_pc_partial_function (target_pc
, &name
, NULL
, NULL
) ==
5377 if (strncmp (name
, "__fn_stub_", 10) != 0
5378 && strcmp (name
, "etext") != 0
5379 && strcmp (name
, "_etext") != 0)
5382 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5383 The limit on the search is arbitrarily set to 20
5384 instructions. FIXME. */
5385 for (i
= 0, pc
= 0; i
< 20; i
++, target_pc
+= MIPS_INSN32_SIZE
)
5387 inst
= mips_fetch_instruction (gdbarch
, target_pc
);
5388 if ((inst
& 0xffff0000) == 0x3c010000) /* lui $at */
5389 pc
= (inst
<< 16) & 0xffff0000; /* high word */
5390 else if ((inst
& 0xffff0000) == 0x24210000) /* addiu $at */
5391 return pc
| (inst
& 0xffff); /* low word */
5394 /* Couldn't find the lui/addui pair, so return stub address. */
5398 /* This is the 'return' part of a call stub. The return
5399 address is in $r18. */
5400 return get_frame_register_signed (frame
, 18);
5403 return 0; /* not a stub */
5406 /* If the current PC is the start of a non-PIC-to-PIC stub, return the
5407 PC of the stub target. The stub just loads $t9 and jumps to it,
5408 so that $t9 has the correct value at function entry. */
5411 mips_skip_pic_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
5413 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
5414 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5415 struct minimal_symbol
*msym
;
5417 gdb_byte stub_code
[16];
5418 int32_t stub_words
[4];
5420 /* The stub for foo is named ".pic.foo", and is either two
5421 instructions inserted before foo or a three instruction sequence
5422 which jumps to foo. */
5423 msym
= lookup_minimal_symbol_by_pc (pc
);
5425 || SYMBOL_VALUE_ADDRESS (msym
) != pc
5426 || SYMBOL_LINKAGE_NAME (msym
) == NULL
5427 || strncmp (SYMBOL_LINKAGE_NAME (msym
), ".pic.", 5) != 0)
5430 /* A two-instruction header. */
5431 if (MSYMBOL_SIZE (msym
) == 8)
5434 /* A three-instruction (plus delay slot) trampoline. */
5435 if (MSYMBOL_SIZE (msym
) == 16)
5437 if (target_read_memory (pc
, stub_code
, 16) != 0)
5439 for (i
= 0; i
< 4; i
++)
5440 stub_words
[i
] = extract_unsigned_integer (stub_code
+ i
* 4,
5443 /* A stub contains these instructions:
5446 addiu t9, t9, %lo(target)
5449 This works even for N64, since stubs are only generated with
5451 if ((stub_words
[0] & 0xffff0000U
) == 0x3c190000
5452 && (stub_words
[1] & 0xfc000000U
) == 0x08000000
5453 && (stub_words
[2] & 0xffff0000U
) == 0x27390000
5454 && stub_words
[3] == 0x00000000)
5455 return (((stub_words
[0] & 0x0000ffff) << 16)
5456 + (stub_words
[2] & 0x0000ffff));
5459 /* Not a recognized stub. */
5464 mips_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
5466 CORE_ADDR target_pc
;
5468 target_pc
= mips_skip_mips16_trampoline_code (frame
, pc
);
5472 target_pc
= find_solib_trampoline_target (frame
, pc
);
5476 target_pc
= mips_skip_pic_trampoline_code (frame
, pc
);
5483 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5484 [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5487 mips_stab_reg_to_regnum (struct gdbarch
*gdbarch
, int num
)
5490 if (num
>= 0 && num
< 32)
5492 else if (num
>= 38 && num
< 70)
5493 regnum
= num
+ mips_regnum (gdbarch
)->fp0
- 38;
5495 regnum
= mips_regnum (gdbarch
)->hi
;
5497 regnum
= mips_regnum (gdbarch
)->lo
;
5499 /* This will hopefully (eventually) provoke a warning. Should
5500 we be calling complaint() here? */
5501 return gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
5502 return gdbarch_num_regs (gdbarch
) + regnum
;
5506 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5507 gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5510 mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch
*gdbarch
, int num
)
5513 if (num
>= 0 && num
< 32)
5515 else if (num
>= 32 && num
< 64)
5516 regnum
= num
+ mips_regnum (gdbarch
)->fp0
- 32;
5518 regnum
= mips_regnum (gdbarch
)->hi
;
5520 regnum
= mips_regnum (gdbarch
)->lo
;
5522 /* This will hopefully (eventually) provoke a warning. Should we
5523 be calling complaint() here? */
5524 return gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
5525 return gdbarch_num_regs (gdbarch
) + regnum
;
5529 mips_register_sim_regno (struct gdbarch
*gdbarch
, int regnum
)
5531 /* Only makes sense to supply raw registers. */
5532 gdb_assert (regnum
>= 0 && regnum
< gdbarch_num_regs (gdbarch
));
5533 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5534 decide if it is valid. Should instead define a standard sim/gdb
5535 register numbering scheme. */
5536 if (gdbarch_register_name (gdbarch
,
5537 gdbarch_num_regs (gdbarch
) + regnum
) != NULL
5538 && gdbarch_register_name (gdbarch
,
5539 gdbarch_num_regs (gdbarch
)
5540 + regnum
)[0] != '\0')
5543 return LEGACY_SIM_REGNO_IGNORE
;
5547 /* Convert an integer into an address. Extracting the value signed
5548 guarantees a correctly sign extended address. */
5551 mips_integer_to_address (struct gdbarch
*gdbarch
,
5552 struct type
*type
, const gdb_byte
*buf
)
5554 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5555 return extract_signed_integer (buf
, TYPE_LENGTH (type
), byte_order
);
5558 /* Dummy virtual frame pointer method. This is no more or less accurate
5559 than most other architectures; we just need to be explicit about it,
5560 because the pseudo-register gdbarch_sp_regnum will otherwise lead to
5561 an assertion failure. */
5564 mips_virtual_frame_pointer (struct gdbarch
*gdbarch
,
5565 CORE_ADDR pc
, int *reg
, LONGEST
*offset
)
5567 *reg
= MIPS_SP_REGNUM
;
5572 mips_find_abi_section (bfd
*abfd
, asection
*sect
, void *obj
)
5574 enum mips_abi
*abip
= (enum mips_abi
*) obj
;
5575 const char *name
= bfd_get_section_name (abfd
, sect
);
5577 if (*abip
!= MIPS_ABI_UNKNOWN
)
5580 if (strncmp (name
, ".mdebug.", 8) != 0)
5583 if (strcmp (name
, ".mdebug.abi32") == 0)
5584 *abip
= MIPS_ABI_O32
;
5585 else if (strcmp (name
, ".mdebug.abiN32") == 0)
5586 *abip
= MIPS_ABI_N32
;
5587 else if (strcmp (name
, ".mdebug.abi64") == 0)
5588 *abip
= MIPS_ABI_N64
;
5589 else if (strcmp (name
, ".mdebug.abiO64") == 0)
5590 *abip
= MIPS_ABI_O64
;
5591 else if (strcmp (name
, ".mdebug.eabi32") == 0)
5592 *abip
= MIPS_ABI_EABI32
;
5593 else if (strcmp (name
, ".mdebug.eabi64") == 0)
5594 *abip
= MIPS_ABI_EABI64
;
5596 warning (_("unsupported ABI %s."), name
+ 8);
5600 mips_find_long_section (bfd
*abfd
, asection
*sect
, void *obj
)
5602 int *lbp
= (int *) obj
;
5603 const char *name
= bfd_get_section_name (abfd
, sect
);
5605 if (strncmp (name
, ".gcc_compiled_long32", 20) == 0)
5607 else if (strncmp (name
, ".gcc_compiled_long64", 20) == 0)
5609 else if (strncmp (name
, ".gcc_compiled_long", 18) == 0)
5610 warning (_("unrecognized .gcc_compiled_longXX"));
5613 static enum mips_abi
5614 global_mips_abi (void)
5618 for (i
= 0; mips_abi_strings
[i
] != NULL
; i
++)
5619 if (mips_abi_strings
[i
] == mips_abi_string
)
5620 return (enum mips_abi
) i
;
5622 internal_error (__FILE__
, __LINE__
, _("unknown ABI string"));
5626 mips_register_g_packet_guesses (struct gdbarch
*gdbarch
)
5628 /* If the size matches the set of 32-bit or 64-bit integer registers,
5629 assume that's what we've got. */
5630 register_remote_g_packet_guess (gdbarch
, 38 * 4, mips_tdesc_gp32
);
5631 register_remote_g_packet_guess (gdbarch
, 38 * 8, mips_tdesc_gp64
);
5633 /* If the size matches the full set of registers GDB traditionally
5634 knows about, including floating point, for either 32-bit or
5635 64-bit, assume that's what we've got. */
5636 register_remote_g_packet_guess (gdbarch
, 90 * 4, mips_tdesc_gp32
);
5637 register_remote_g_packet_guess (gdbarch
, 90 * 8, mips_tdesc_gp64
);
5639 /* Otherwise we don't have a useful guess. */
5642 static struct value
*
5643 value_of_mips_user_reg (struct frame_info
*frame
, const void *baton
)
5645 const int *reg_p
= baton
;
5646 return value_of_register (*reg_p
, frame
);
5649 static struct gdbarch
*
5650 mips_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
5652 struct gdbarch
*gdbarch
;
5653 struct gdbarch_tdep
*tdep
;
5655 enum mips_abi mips_abi
, found_abi
, wanted_abi
;
5657 enum mips_fpu_type fpu_type
;
5658 struct tdesc_arch_data
*tdesc_data
= NULL
;
5659 int elf_fpu_type
= 0;
5661 /* Check any target description for validity. */
5662 if (tdesc_has_registers (info
.target_desc
))
5664 static const char *const mips_gprs
[] = {
5665 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5666 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5667 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5668 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5670 static const char *const mips_fprs
[] = {
5671 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5672 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5673 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5674 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
5677 const struct tdesc_feature
*feature
;
5680 feature
= tdesc_find_feature (info
.target_desc
,
5681 "org.gnu.gdb.mips.cpu");
5682 if (feature
== NULL
)
5685 tdesc_data
= tdesc_data_alloc ();
5688 for (i
= MIPS_ZERO_REGNUM
; i
<= MIPS_RA_REGNUM
; i
++)
5689 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
, i
,
5693 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5694 MIPS_EMBED_LO_REGNUM
, "lo");
5695 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5696 MIPS_EMBED_HI_REGNUM
, "hi");
5697 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5698 MIPS_EMBED_PC_REGNUM
, "pc");
5702 tdesc_data_cleanup (tdesc_data
);
5706 feature
= tdesc_find_feature (info
.target_desc
,
5707 "org.gnu.gdb.mips.cp0");
5708 if (feature
== NULL
)
5710 tdesc_data_cleanup (tdesc_data
);
5715 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5716 MIPS_EMBED_BADVADDR_REGNUM
,
5718 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5719 MIPS_PS_REGNUM
, "status");
5720 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5721 MIPS_EMBED_CAUSE_REGNUM
, "cause");
5725 tdesc_data_cleanup (tdesc_data
);
5729 /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
5730 backend is not prepared for that, though. */
5731 feature
= tdesc_find_feature (info
.target_desc
,
5732 "org.gnu.gdb.mips.fpu");
5733 if (feature
== NULL
)
5735 tdesc_data_cleanup (tdesc_data
);
5740 for (i
= 0; i
< 32; i
++)
5741 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5742 i
+ MIPS_EMBED_FP0_REGNUM
,
5745 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5746 MIPS_EMBED_FP0_REGNUM
+ 32, "fcsr");
5747 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
5748 MIPS_EMBED_FP0_REGNUM
+ 33, "fir");
5752 tdesc_data_cleanup (tdesc_data
);
5756 /* It would be nice to detect an attempt to use a 64-bit ABI
5757 when only 32-bit registers are provided. */
5760 /* First of all, extract the elf_flags, if available. */
5761 if (info
.abfd
&& bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
5762 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
5763 else if (arches
!= NULL
)
5764 elf_flags
= gdbarch_tdep (arches
->gdbarch
)->elf_flags
;
5768 fprintf_unfiltered (gdb_stdlog
,
5769 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags
);
5771 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5772 switch ((elf_flags
& EF_MIPS_ABI
))
5774 case E_MIPS_ABI_O32
:
5775 found_abi
= MIPS_ABI_O32
;
5777 case E_MIPS_ABI_O64
:
5778 found_abi
= MIPS_ABI_O64
;
5780 case E_MIPS_ABI_EABI32
:
5781 found_abi
= MIPS_ABI_EABI32
;
5783 case E_MIPS_ABI_EABI64
:
5784 found_abi
= MIPS_ABI_EABI64
;
5787 if ((elf_flags
& EF_MIPS_ABI2
))
5788 found_abi
= MIPS_ABI_N32
;
5790 found_abi
= MIPS_ABI_UNKNOWN
;
5794 /* GCC creates a pseudo-section whose name describes the ABI. */
5795 if (found_abi
== MIPS_ABI_UNKNOWN
&& info
.abfd
!= NULL
)
5796 bfd_map_over_sections (info
.abfd
, mips_find_abi_section
, &found_abi
);
5798 /* If we have no useful BFD information, use the ABI from the last
5799 MIPS architecture (if there is one). */
5800 if (found_abi
== MIPS_ABI_UNKNOWN
&& info
.abfd
== NULL
&& arches
!= NULL
)
5801 found_abi
= gdbarch_tdep (arches
->gdbarch
)->found_abi
;
5803 /* Try the architecture for any hint of the correct ABI. */
5804 if (found_abi
== MIPS_ABI_UNKNOWN
5805 && info
.bfd_arch_info
!= NULL
5806 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
5808 switch (info
.bfd_arch_info
->mach
)
5810 case bfd_mach_mips3900
:
5811 found_abi
= MIPS_ABI_EABI32
;
5813 case bfd_mach_mips4100
:
5814 case bfd_mach_mips5000
:
5815 found_abi
= MIPS_ABI_EABI64
;
5817 case bfd_mach_mips8000
:
5818 case bfd_mach_mips10000
:
5819 /* On Irix, ELF64 executables use the N64 ABI. The
5820 pseudo-sections which describe the ABI aren't present
5821 on IRIX. (Even for executables created by gcc.) */
5822 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
5823 && elf_elfheader (info
.abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5824 found_abi
= MIPS_ABI_N64
;
5826 found_abi
= MIPS_ABI_N32
;
5831 /* Default 64-bit objects to N64 instead of O32. */
5832 if (found_abi
== MIPS_ABI_UNKNOWN
5833 && info
.abfd
!= NULL
5834 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
5835 && elf_elfheader (info
.abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5836 found_abi
= MIPS_ABI_N64
;
5839 fprintf_unfiltered (gdb_stdlog
, "mips_gdbarch_init: found_abi = %d\n",
5842 /* What has the user specified from the command line? */
5843 wanted_abi
= global_mips_abi ();
5845 fprintf_unfiltered (gdb_stdlog
, "mips_gdbarch_init: wanted_abi = %d\n",
5848 /* Now that we have found what the ABI for this binary would be,
5849 check whether the user is overriding it. */
5850 if (wanted_abi
!= MIPS_ABI_UNKNOWN
)
5851 mips_abi
= wanted_abi
;
5852 else if (found_abi
!= MIPS_ABI_UNKNOWN
)
5853 mips_abi
= found_abi
;
5855 mips_abi
= MIPS_ABI_O32
;
5857 fprintf_unfiltered (gdb_stdlog
, "mips_gdbarch_init: mips_abi = %d\n",
5860 /* Also used when doing an architecture lookup. */
5862 fprintf_unfiltered (gdb_stdlog
,
5863 "mips_gdbarch_init: "
5864 "mips64_transfers_32bit_regs_p = %d\n",
5865 mips64_transfers_32bit_regs_p
);
5867 /* Determine the MIPS FPU type. */
5870 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
5871 elf_fpu_type
= bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_GNU
,
5872 Tag_GNU_MIPS_ABI_FP
);
5873 #endif /* HAVE_ELF */
5875 if (!mips_fpu_type_auto
)
5876 fpu_type
= mips_fpu_type
;
5877 else if (elf_fpu_type
!= 0)
5879 switch (elf_fpu_type
)
5882 fpu_type
= MIPS_FPU_DOUBLE
;
5885 fpu_type
= MIPS_FPU_SINGLE
;
5889 /* Soft float or unknown. */
5890 fpu_type
= MIPS_FPU_NONE
;
5894 else if (info
.bfd_arch_info
!= NULL
5895 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
5896 switch (info
.bfd_arch_info
->mach
)
5898 case bfd_mach_mips3900
:
5899 case bfd_mach_mips4100
:
5900 case bfd_mach_mips4111
:
5901 case bfd_mach_mips4120
:
5902 fpu_type
= MIPS_FPU_NONE
;
5904 case bfd_mach_mips4650
:
5905 fpu_type
= MIPS_FPU_SINGLE
;
5908 fpu_type
= MIPS_FPU_DOUBLE
;
5911 else if (arches
!= NULL
)
5912 fpu_type
= gdbarch_tdep (arches
->gdbarch
)->mips_fpu_type
;
5914 fpu_type
= MIPS_FPU_DOUBLE
;
5916 fprintf_unfiltered (gdb_stdlog
,
5917 "mips_gdbarch_init: fpu_type = %d\n", fpu_type
);
5919 /* Check for blatant incompatibilities. */
5921 /* If we have only 32-bit registers, then we can't debug a 64-bit
5923 if (info
.target_desc
5924 && tdesc_property (info
.target_desc
, PROPERTY_GP32
) != NULL
5925 && mips_abi
!= MIPS_ABI_EABI32
5926 && mips_abi
!= MIPS_ABI_O32
)
5928 if (tdesc_data
!= NULL
)
5929 tdesc_data_cleanup (tdesc_data
);
5933 /* Try to find a pre-existing architecture. */
5934 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
5936 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
5938 /* MIPS needs to be pedantic about which ABI the object is
5940 if (gdbarch_tdep (arches
->gdbarch
)->elf_flags
!= elf_flags
)
5942 if (gdbarch_tdep (arches
->gdbarch
)->mips_abi
!= mips_abi
)
5944 /* Need to be pedantic about which register virtual size is
5946 if (gdbarch_tdep (arches
->gdbarch
)->mips64_transfers_32bit_regs_p
5947 != mips64_transfers_32bit_regs_p
)
5949 /* Be pedantic about which FPU is selected. */
5950 if (gdbarch_tdep (arches
->gdbarch
)->mips_fpu_type
!= fpu_type
)
5953 if (tdesc_data
!= NULL
)
5954 tdesc_data_cleanup (tdesc_data
);
5955 return arches
->gdbarch
;
5958 /* Need a new architecture. Fill in a target specific vector. */
5959 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
5960 gdbarch
= gdbarch_alloc (&info
, tdep
);
5961 tdep
->elf_flags
= elf_flags
;
5962 tdep
->mips64_transfers_32bit_regs_p
= mips64_transfers_32bit_regs_p
;
5963 tdep
->found_abi
= found_abi
;
5964 tdep
->mips_abi
= mips_abi
;
5965 tdep
->mips_fpu_type
= fpu_type
;
5966 tdep
->register_size_valid_p
= 0;
5967 tdep
->register_size
= 0;
5968 tdep
->gregset
= NULL
;
5969 tdep
->gregset64
= NULL
;
5970 tdep
->fpregset
= NULL
;
5971 tdep
->fpregset64
= NULL
;
5973 if (info
.target_desc
)
5975 /* Some useful properties can be inferred from the target. */
5976 if (tdesc_property (info
.target_desc
, PROPERTY_GP32
) != NULL
)
5978 tdep
->register_size_valid_p
= 1;
5979 tdep
->register_size
= 4;
5981 else if (tdesc_property (info
.target_desc
, PROPERTY_GP64
) != NULL
)
5983 tdep
->register_size_valid_p
= 1;
5984 tdep
->register_size
= 8;
5988 /* Initially set everything according to the default ABI/ISA. */
5989 set_gdbarch_short_bit (gdbarch
, 16);
5990 set_gdbarch_int_bit (gdbarch
, 32);
5991 set_gdbarch_float_bit (gdbarch
, 32);
5992 set_gdbarch_double_bit (gdbarch
, 64);
5993 set_gdbarch_long_double_bit (gdbarch
, 64);
5994 set_gdbarch_register_reggroup_p (gdbarch
, mips_register_reggroup_p
);
5995 set_gdbarch_pseudo_register_read (gdbarch
, mips_pseudo_register_read
);
5996 set_gdbarch_pseudo_register_write (gdbarch
, mips_pseudo_register_write
);
5998 set_gdbarch_ax_pseudo_register_collect (gdbarch
,
5999 mips_ax_pseudo_register_collect
);
6000 set_gdbarch_ax_pseudo_register_push_stack
6001 (gdbarch
, mips_ax_pseudo_register_push_stack
);
6003 set_gdbarch_elf_make_msymbol_special (gdbarch
,
6004 mips_elf_make_msymbol_special
);
6006 /* Fill in the OS dependant register numbers and names. */
6008 const char **reg_names
;
6009 struct mips_regnum
*regnum
= GDBARCH_OBSTACK_ZALLOC (gdbarch
,
6010 struct mips_regnum
);
6011 if (tdesc_has_registers (info
.target_desc
))
6013 regnum
->lo
= MIPS_EMBED_LO_REGNUM
;
6014 regnum
->hi
= MIPS_EMBED_HI_REGNUM
;
6015 regnum
->badvaddr
= MIPS_EMBED_BADVADDR_REGNUM
;
6016 regnum
->cause
= MIPS_EMBED_CAUSE_REGNUM
;
6017 regnum
->pc
= MIPS_EMBED_PC_REGNUM
;
6018 regnum
->fp0
= MIPS_EMBED_FP0_REGNUM
;
6019 regnum
->fp_control_status
= 70;
6020 regnum
->fp_implementation_revision
= 71;
6021 num_regs
= MIPS_LAST_EMBED_REGNUM
+ 1;
6024 else if (info
.osabi
== GDB_OSABI_IRIX
)
6029 regnum
->badvaddr
= 66;
6032 regnum
->fp_control_status
= 69;
6033 regnum
->fp_implementation_revision
= 70;
6035 reg_names
= mips_irix_reg_names
;
6039 regnum
->lo
= MIPS_EMBED_LO_REGNUM
;
6040 regnum
->hi
= MIPS_EMBED_HI_REGNUM
;
6041 regnum
->badvaddr
= MIPS_EMBED_BADVADDR_REGNUM
;
6042 regnum
->cause
= MIPS_EMBED_CAUSE_REGNUM
;
6043 regnum
->pc
= MIPS_EMBED_PC_REGNUM
;
6044 regnum
->fp0
= MIPS_EMBED_FP0_REGNUM
;
6045 regnum
->fp_control_status
= 70;
6046 regnum
->fp_implementation_revision
= 71;
6048 if (info
.bfd_arch_info
!= NULL
6049 && info
.bfd_arch_info
->mach
== bfd_mach_mips3900
)
6050 reg_names
= mips_tx39_reg_names
;
6052 reg_names
= mips_generic_reg_names
;
6054 /* FIXME: cagney/2003-11-15: For MIPS, hasn't gdbarch_pc_regnum been
6055 replaced by gdbarch_read_pc? */
6056 set_gdbarch_pc_regnum (gdbarch
, regnum
->pc
+ num_regs
);
6057 set_gdbarch_sp_regnum (gdbarch
, MIPS_SP_REGNUM
+ num_regs
);
6058 set_gdbarch_fp0_regnum (gdbarch
, regnum
->fp0
);
6059 set_gdbarch_num_regs (gdbarch
, num_regs
);
6060 set_gdbarch_num_pseudo_regs (gdbarch
, num_regs
);
6061 set_gdbarch_register_name (gdbarch
, mips_register_name
);
6062 set_gdbarch_virtual_frame_pointer (gdbarch
, mips_virtual_frame_pointer
);
6063 tdep
->mips_processor_reg_names
= reg_names
;
6064 tdep
->regnum
= regnum
;
6070 set_gdbarch_push_dummy_call (gdbarch
, mips_o32_push_dummy_call
);
6071 set_gdbarch_return_value (gdbarch
, mips_o32_return_value
);
6072 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 4 - 1;
6073 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
6074 tdep
->default_mask_address_p
= 0;
6075 set_gdbarch_long_bit (gdbarch
, 32);
6076 set_gdbarch_ptr_bit (gdbarch
, 32);
6077 set_gdbarch_long_long_bit (gdbarch
, 64);
6080 set_gdbarch_push_dummy_call (gdbarch
, mips_o64_push_dummy_call
);
6081 set_gdbarch_return_value (gdbarch
, mips_o64_return_value
);
6082 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 4 - 1;
6083 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
6084 tdep
->default_mask_address_p
= 0;
6085 set_gdbarch_long_bit (gdbarch
, 32);
6086 set_gdbarch_ptr_bit (gdbarch
, 32);
6087 set_gdbarch_long_long_bit (gdbarch
, 64);
6089 case MIPS_ABI_EABI32
:
6090 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
6091 set_gdbarch_return_value (gdbarch
, mips_eabi_return_value
);
6092 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
6093 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
6094 tdep
->default_mask_address_p
= 0;
6095 set_gdbarch_long_bit (gdbarch
, 32);
6096 set_gdbarch_ptr_bit (gdbarch
, 32);
6097 set_gdbarch_long_long_bit (gdbarch
, 64);
6099 case MIPS_ABI_EABI64
:
6100 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
6101 set_gdbarch_return_value (gdbarch
, mips_eabi_return_value
);
6102 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
6103 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
6104 tdep
->default_mask_address_p
= 0;
6105 set_gdbarch_long_bit (gdbarch
, 64);
6106 set_gdbarch_ptr_bit (gdbarch
, 64);
6107 set_gdbarch_long_long_bit (gdbarch
, 64);
6110 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
6111 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
6112 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
6113 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
6114 tdep
->default_mask_address_p
= 0;
6115 set_gdbarch_long_bit (gdbarch
, 32);
6116 set_gdbarch_ptr_bit (gdbarch
, 32);
6117 set_gdbarch_long_long_bit (gdbarch
, 64);
6118 set_gdbarch_long_double_bit (gdbarch
, 128);
6119 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
6122 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
6123 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
6124 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
6125 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
6126 tdep
->default_mask_address_p
= 0;
6127 set_gdbarch_long_bit (gdbarch
, 64);
6128 set_gdbarch_ptr_bit (gdbarch
, 64);
6129 set_gdbarch_long_long_bit (gdbarch
, 64);
6130 set_gdbarch_long_double_bit (gdbarch
, 128);
6131 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
6134 internal_error (__FILE__
, __LINE__
, _("unknown ABI in switch"));
6137 /* GCC creates a pseudo-section whose name specifies the size of
6138 longs, since -mlong32 or -mlong64 may be used independent of
6139 other options. How those options affect pointer sizes is ABI and
6140 architecture dependent, so use them to override the default sizes
6141 set by the ABI. This table shows the relationship between ABI,
6142 -mlongXX, and size of pointers:
6144 ABI -mlongXX ptr bits
6145 --- -------- --------
6159 Note that for o32 and eabi32, pointers are always 32 bits
6160 regardless of any -mlongXX option. For all others, pointers and
6161 longs are the same, as set by -mlongXX or set by defaults. */
6163 if (info
.abfd
!= NULL
)
6167 bfd_map_over_sections (info
.abfd
, mips_find_long_section
, &long_bit
);
6170 set_gdbarch_long_bit (gdbarch
, long_bit
);
6174 case MIPS_ABI_EABI32
:
6179 case MIPS_ABI_EABI64
:
6180 set_gdbarch_ptr_bit (gdbarch
, long_bit
);
6183 internal_error (__FILE__
, __LINE__
, _("unknown ABI in switch"));
6188 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
6189 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
6192 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
6193 flag in object files because to do so would make it impossible to
6194 link with libraries compiled without "-gp32". This is
6195 unnecessarily restrictive.
6197 We could solve this problem by adding "-gp32" multilibs to gcc,
6198 but to set this flag before gcc is built with such multilibs will
6199 break too many systems.''
6201 But even more unhelpfully, the default linker output target for
6202 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
6203 for 64-bit programs - you need to change the ABI to change this,
6204 and not all gcc targets support that currently. Therefore using
6205 this flag to detect 32-bit mode would do the wrong thing given
6206 the current gcc - it would make GDB treat these 64-bit programs
6207 as 32-bit programs by default. */
6209 set_gdbarch_read_pc (gdbarch
, mips_read_pc
);
6210 set_gdbarch_write_pc (gdbarch
, mips_write_pc
);
6212 /* Add/remove bits from an address. The MIPS needs be careful to
6213 ensure that all 32 bit addresses are sign extended to 64 bits. */
6214 set_gdbarch_addr_bits_remove (gdbarch
, mips_addr_bits_remove
);
6216 /* Unwind the frame. */
6217 set_gdbarch_unwind_pc (gdbarch
, mips_unwind_pc
);
6218 set_gdbarch_unwind_sp (gdbarch
, mips_unwind_sp
);
6219 set_gdbarch_dummy_id (gdbarch
, mips_dummy_id
);
6221 /* Map debug register numbers onto internal register numbers. */
6222 set_gdbarch_stab_reg_to_regnum (gdbarch
, mips_stab_reg_to_regnum
);
6223 set_gdbarch_ecoff_reg_to_regnum (gdbarch
,
6224 mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
6225 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
,
6226 mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
6227 set_gdbarch_register_sim_regno (gdbarch
, mips_register_sim_regno
);
6229 /* MIPS version of CALL_DUMMY. */
6231 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
6232 replaced by a command, and all targets will default to on stack
6233 (regardless of the stack's execute status). */
6234 set_gdbarch_call_dummy_location (gdbarch
, AT_SYMBOL
);
6235 set_gdbarch_frame_align (gdbarch
, mips_frame_align
);
6237 set_gdbarch_convert_register_p (gdbarch
, mips_convert_register_p
);
6238 set_gdbarch_register_to_value (gdbarch
, mips_register_to_value
);
6239 set_gdbarch_value_to_register (gdbarch
, mips_value_to_register
);
6241 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
6242 set_gdbarch_breakpoint_from_pc (gdbarch
, mips_breakpoint_from_pc
);
6244 set_gdbarch_skip_prologue (gdbarch
, mips_skip_prologue
);
6246 set_gdbarch_in_function_epilogue_p (gdbarch
, mips_in_function_epilogue_p
);
6248 set_gdbarch_pointer_to_address (gdbarch
, signed_pointer_to_address
);
6249 set_gdbarch_address_to_pointer (gdbarch
, address_to_signed_pointer
);
6250 set_gdbarch_integer_to_address (gdbarch
, mips_integer_to_address
);
6252 set_gdbarch_register_type (gdbarch
, mips_register_type
);
6254 set_gdbarch_print_registers_info (gdbarch
, mips_print_registers_info
);
6256 if (mips_abi
== MIPS_ABI_N32
)
6257 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_mips_n32
);
6258 else if (mips_abi
== MIPS_ABI_N64
)
6259 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_mips_n64
);
6261 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_mips
);
6263 /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint,
6264 HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint
6265 need to all be folded into the target vector. Since they are
6266 being used as guards for target_stopped_by_watchpoint, why not have
6267 target_stopped_by_watchpoint return the type of watchpoint that the code
6269 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
6271 set_gdbarch_skip_trampoline_code (gdbarch
, mips_skip_trampoline_code
);
6273 set_gdbarch_single_step_through_delay (gdbarch
,
6274 mips_single_step_through_delay
);
6276 /* Virtual tables. */
6277 set_gdbarch_vbit_in_delta (gdbarch
, 1);
6279 mips_register_g_packet_guesses (gdbarch
);
6281 /* Hook in OS ABI-specific overrides, if they have been registered. */
6282 info
.tdep_info
= (void *) tdesc_data
;
6283 gdbarch_init_osabi (info
, gdbarch
);
6285 /* Unwind the frame. */
6286 dwarf2_append_unwinders (gdbarch
);
6287 frame_unwind_append_unwinder (gdbarch
, &mips_stub_frame_unwind
);
6288 frame_unwind_append_unwinder (gdbarch
, &mips_insn16_frame_unwind
);
6289 frame_unwind_append_unwinder (gdbarch
, &mips_insn32_frame_unwind
);
6290 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
6291 frame_base_append_sniffer (gdbarch
, mips_stub_frame_base_sniffer
);
6292 frame_base_append_sniffer (gdbarch
, mips_insn16_frame_base_sniffer
);
6293 frame_base_append_sniffer (gdbarch
, mips_insn32_frame_base_sniffer
);
6297 set_tdesc_pseudo_register_type (gdbarch
, mips_pseudo_register_type
);
6298 tdesc_use_registers (gdbarch
, info
.target_desc
, tdesc_data
);
6300 /* Override the normal target description methods to handle our
6301 dual real and pseudo registers. */
6302 set_gdbarch_register_name (gdbarch
, mips_register_name
);
6303 set_gdbarch_register_reggroup_p (gdbarch
,
6304 mips_tdesc_register_reggroup_p
);
6306 num_regs
= gdbarch_num_regs (gdbarch
);
6307 set_gdbarch_num_pseudo_regs (gdbarch
, num_regs
);
6308 set_gdbarch_pc_regnum (gdbarch
, tdep
->regnum
->pc
+ num_regs
);
6309 set_gdbarch_sp_regnum (gdbarch
, MIPS_SP_REGNUM
+ num_regs
);
6312 /* Add ABI-specific aliases for the registers. */
6313 if (mips_abi
== MIPS_ABI_N32
|| mips_abi
== MIPS_ABI_N64
)
6314 for (i
= 0; i
< ARRAY_SIZE (mips_n32_n64_aliases
); i
++)
6315 user_reg_add (gdbarch
, mips_n32_n64_aliases
[i
].name
,
6316 value_of_mips_user_reg
, &mips_n32_n64_aliases
[i
].regnum
);
6318 for (i
= 0; i
< ARRAY_SIZE (mips_o32_aliases
); i
++)
6319 user_reg_add (gdbarch
, mips_o32_aliases
[i
].name
,
6320 value_of_mips_user_reg
, &mips_o32_aliases
[i
].regnum
);
6322 /* Add some other standard aliases. */
6323 for (i
= 0; i
< ARRAY_SIZE (mips_register_aliases
); i
++)
6324 user_reg_add (gdbarch
, mips_register_aliases
[i
].name
,
6325 value_of_mips_user_reg
, &mips_register_aliases
[i
].regnum
);
6327 for (i
= 0; i
< ARRAY_SIZE (mips_numeric_register_aliases
); i
++)
6328 user_reg_add (gdbarch
, mips_numeric_register_aliases
[i
].name
,
6329 value_of_mips_user_reg
,
6330 &mips_numeric_register_aliases
[i
].regnum
);
6336 mips_abi_update (char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
6338 struct gdbarch_info info
;
6340 /* Force the architecture to update, and (if it's a MIPS architecture)
6341 mips_gdbarch_init will take care of the rest. */
6342 gdbarch_info_init (&info
);
6343 gdbarch_update_p (info
);
6346 /* Print out which MIPS ABI is in use. */
6349 show_mips_abi (struct ui_file
*file
,
6351 struct cmd_list_element
*ignored_cmd
,
6352 const char *ignored_value
)
6354 if (gdbarch_bfd_arch_info (target_gdbarch
)->arch
!= bfd_arch_mips
)
6357 "The MIPS ABI is unknown because the current architecture "
6361 enum mips_abi global_abi
= global_mips_abi ();
6362 enum mips_abi actual_abi
= mips_abi (target_gdbarch
);
6363 const char *actual_abi_str
= mips_abi_strings
[actual_abi
];
6365 if (global_abi
== MIPS_ABI_UNKNOWN
)
6368 "The MIPS ABI is set automatically (currently \"%s\").\n",
6370 else if (global_abi
== actual_abi
)
6373 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6377 /* Probably shouldn't happen... */
6378 fprintf_filtered (file
,
6379 "The (auto detected) MIPS ABI \"%s\" is in use "
6380 "even though the user setting was \"%s\".\n",
6381 actual_abi_str
, mips_abi_strings
[global_abi
]);
6387 mips_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
6389 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
6393 int ef_mips_32bitmode
;
6394 /* Determine the ISA. */
6395 switch (tdep
->elf_flags
& EF_MIPS_ARCH
)
6413 /* Determine the size of a pointer. */
6414 ef_mips_32bitmode
= (tdep
->elf_flags
& EF_MIPS_32BITMODE
);
6415 fprintf_unfiltered (file
,
6416 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6418 fprintf_unfiltered (file
,
6419 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6421 fprintf_unfiltered (file
,
6422 "mips_dump_tdep: ef_mips_arch = %d\n",
6424 fprintf_unfiltered (file
,
6425 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6426 tdep
->mips_abi
, mips_abi_strings
[tdep
->mips_abi
]);
6427 fprintf_unfiltered (file
,
6429 "mips_mask_address_p() %d (default %d)\n",
6430 mips_mask_address_p (tdep
),
6431 tdep
->default_mask_address_p
);
6433 fprintf_unfiltered (file
,
6434 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6435 MIPS_DEFAULT_FPU_TYPE
,
6436 (MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_NONE
? "none"
6437 : MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_SINGLE
? "single"
6438 : MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_DOUBLE
? "double"
6440 fprintf_unfiltered (file
, "mips_dump_tdep: MIPS_EABI = %d\n",
6441 MIPS_EABI (gdbarch
));
6442 fprintf_unfiltered (file
,
6443 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6444 MIPS_FPU_TYPE (gdbarch
),
6445 (MIPS_FPU_TYPE (gdbarch
) == MIPS_FPU_NONE
? "none"
6446 : MIPS_FPU_TYPE (gdbarch
) == MIPS_FPU_SINGLE
? "single"
6447 : MIPS_FPU_TYPE (gdbarch
) == MIPS_FPU_DOUBLE
? "double"
6451 extern initialize_file_ftype _initialize_mips_tdep
; /* -Wmissing-prototypes */
6454 _initialize_mips_tdep (void)
6456 static struct cmd_list_element
*mipsfpulist
= NULL
;
6457 struct cmd_list_element
*c
;
6459 mips_abi_string
= mips_abi_strings
[MIPS_ABI_UNKNOWN
];
6460 if (MIPS_ABI_LAST
+ 1
6461 != sizeof (mips_abi_strings
) / sizeof (mips_abi_strings
[0]))
6462 internal_error (__FILE__
, __LINE__
, _("mips_abi_strings out of sync"));
6464 gdbarch_register (bfd_arch_mips
, mips_gdbarch_init
, mips_dump_tdep
);
6466 mips_pdr_data
= register_objfile_data ();
6468 /* Create feature sets with the appropriate properties. The values
6469 are not important. */
6470 mips_tdesc_gp32
= allocate_target_description ();
6471 set_tdesc_property (mips_tdesc_gp32
, PROPERTY_GP32
, "");
6473 mips_tdesc_gp64
= allocate_target_description ();
6474 set_tdesc_property (mips_tdesc_gp64
, PROPERTY_GP64
, "");
6476 /* Add root prefix command for all "set mips"/"show mips" commands. */
6477 add_prefix_cmd ("mips", no_class
, set_mips_command
,
6478 _("Various MIPS specific commands."),
6479 &setmipscmdlist
, "set mips ", 0, &setlist
);
6481 add_prefix_cmd ("mips", no_class
, show_mips_command
,
6482 _("Various MIPS specific commands."),
6483 &showmipscmdlist
, "show mips ", 0, &showlist
);
6485 /* Allow the user to override the ABI. */
6486 add_setshow_enum_cmd ("abi", class_obscure
, mips_abi_strings
,
6487 &mips_abi_string
, _("\
6488 Set the MIPS ABI used by this program."), _("\
6489 Show the MIPS ABI used by this program."), _("\
6490 This option can be set to one of:\n\
6491 auto - the default ABI associated with the current binary\n\
6500 &setmipscmdlist
, &showmipscmdlist
);
6502 /* Let the user turn off floating point and set the fence post for
6503 heuristic_proc_start. */
6505 add_prefix_cmd ("mipsfpu", class_support
, set_mipsfpu_command
,
6506 _("Set use of MIPS floating-point coprocessor."),
6507 &mipsfpulist
, "set mipsfpu ", 0, &setlist
);
6508 add_cmd ("single", class_support
, set_mipsfpu_single_command
,
6509 _("Select single-precision MIPS floating-point coprocessor."),
6511 add_cmd ("double", class_support
, set_mipsfpu_double_command
,
6512 _("Select double-precision MIPS floating-point coprocessor."),
6514 add_alias_cmd ("on", "double", class_support
, 1, &mipsfpulist
);
6515 add_alias_cmd ("yes", "double", class_support
, 1, &mipsfpulist
);
6516 add_alias_cmd ("1", "double", class_support
, 1, &mipsfpulist
);
6517 add_cmd ("none", class_support
, set_mipsfpu_none_command
,
6518 _("Select no MIPS floating-point coprocessor."), &mipsfpulist
);
6519 add_alias_cmd ("off", "none", class_support
, 1, &mipsfpulist
);
6520 add_alias_cmd ("no", "none", class_support
, 1, &mipsfpulist
);
6521 add_alias_cmd ("0", "none", class_support
, 1, &mipsfpulist
);
6522 add_cmd ("auto", class_support
, set_mipsfpu_auto_command
,
6523 _("Select MIPS floating-point coprocessor automatically."),
6525 add_cmd ("mipsfpu", class_support
, show_mipsfpu_command
,
6526 _("Show current use of MIPS floating-point coprocessor target."),
6529 /* We really would like to have both "0" and "unlimited" work, but
6530 command.c doesn't deal with that. So make it a var_zinteger
6531 because the user can always use "999999" or some such for unlimited. */
6532 add_setshow_zinteger_cmd ("heuristic-fence-post", class_support
,
6533 &heuristic_fence_post
, _("\
6534 Set the distance searched for the start of a function."), _("\
6535 Show the distance searched for the start of a function."), _("\
6536 If you are debugging a stripped executable, GDB needs to search through the\n\
6537 program for the start of a function. This command sets the distance of the\n\
6538 search. The only need to set it is when debugging a stripped executable."),
6539 reinit_frame_cache_sfunc
,
6540 NULL
, /* FIXME: i18n: The distance searched for
6541 the start of a function is %s. */
6542 &setlist
, &showlist
);
6544 /* Allow the user to control whether the upper bits of 64-bit
6545 addresses should be zeroed. */
6546 add_setshow_auto_boolean_cmd ("mask-address", no_class
,
6547 &mask_address_var
, _("\
6548 Set zeroing of upper 32 bits of 64-bit addresses."), _("\
6549 Show zeroing of upper 32 bits of 64-bit addresses."), _("\
6550 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\
6551 allow GDB to determine the correct value."),
6552 NULL
, show_mask_address
,
6553 &setmipscmdlist
, &showmipscmdlist
);
6555 /* Allow the user to control the size of 32 bit registers within the
6556 raw remote packet. */
6557 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure
,
6558 &mips64_transfers_32bit_regs_p
, _("\
6559 Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6561 Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6563 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6564 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6565 64 bits for others. Use \"off\" to disable compatibility mode"),
6566 set_mips64_transfers_32bit_regs
,
6567 NULL
, /* FIXME: i18n: Compatibility with 64-bit
6568 MIPS target that transfers 32-bit
6569 quantities is %s. */
6570 &setlist
, &showlist
);
6572 /* Debug this files internals. */
6573 add_setshow_zinteger_cmd ("mips", class_maintenance
,
6575 Set mips debugging."), _("\
6576 Show mips debugging."), _("\
6577 When non-zero, mips specific debugging is enabled."),
6579 NULL
, /* FIXME: i18n: Mips debugging is
6581 &setdebuglist
, &showdebuglist
);