1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright (C) 1988-2022 Free Software Foundation, Inc.
5 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
6 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "arch-utils.h"
38 #include "mips-tdep.h"
40 #include "reggroups.h"
41 #include "opcode/mips.h"
45 #include "sim-regno.h"
48 #include "frame-unwind.h"
49 #include "frame-base.h"
50 #include "trad-frame.h"
53 #include "target-descriptions.h"
54 #include "dwarf2/frame.h"
55 #include "user-regs.h"
58 #include "target-float.h"
61 static struct type
*mips_register_type (struct gdbarch
*gdbarch
, int regnum
);
63 static int mips32_instruction_has_delay_slot (struct gdbarch
*gdbarch
,
65 static int micromips_instruction_has_delay_slot (ULONGEST insn
, int mustbe32
);
66 static int mips16_instruction_has_delay_slot (unsigned short inst
,
69 static int mips32_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
,
71 static int micromips_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
,
72 CORE_ADDR addr
, int mustbe32
);
73 static int mips16_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
,
74 CORE_ADDR addr
, int mustbe32
);
76 static void mips_print_float_info (struct gdbarch
*, struct ui_file
*,
77 frame_info_ptr
, const char *);
79 /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
80 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
81 #define ST0_FR (1 << 26)
83 /* The sizes of floating point registers. */
87 MIPS_FPU_SINGLE_REGSIZE
= 4,
88 MIPS_FPU_DOUBLE_REGSIZE
= 8
97 static const char *mips_abi_string
;
99 static const char *const mips_abi_strings
[] = {
110 /* Enum describing the different kinds of breakpoints. */
112 enum mips_breakpoint_kind
114 /* 16-bit MIPS16 mode breakpoint. */
115 MIPS_BP_KIND_MIPS16
= 2,
117 /* 16-bit microMIPS mode breakpoint. */
118 MIPS_BP_KIND_MICROMIPS16
= 3,
120 /* 32-bit standard MIPS mode breakpoint. */
121 MIPS_BP_KIND_MIPS32
= 4,
123 /* 32-bit microMIPS mode breakpoint. */
124 MIPS_BP_KIND_MICROMIPS32
= 5,
127 /* For backwards compatibility we default to MIPS16. This flag is
128 overridden as soon as unambiguous ELF file flags tell us the
129 compressed ISA encoding used. */
130 static const char mips_compression_mips16
[] = "mips16";
131 static const char mips_compression_micromips
[] = "micromips";
132 static const char *const mips_compression_strings
[] =
134 mips_compression_mips16
,
135 mips_compression_micromips
,
139 static const char *mips_compression_string
= mips_compression_mips16
;
141 /* The standard register names, and all the valid aliases for them. */
142 struct register_alias
148 /* Aliases for o32 and most other ABIs. */
149 const struct register_alias mips_o32_aliases
[] = {
156 /* Aliases for n32 and n64. */
157 const struct register_alias mips_n32_n64_aliases
[] = {
164 /* Aliases for ABI-independent registers. */
165 const struct register_alias mips_register_aliases
[] = {
166 /* The architecture manuals specify these ABI-independent names for
168 #define R(n) { "r" #n, n }
169 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
170 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
171 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
172 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
175 /* k0 and k1 are sometimes called these instead (for "kernel
180 /* This is the traditional GDB name for the CP0 status register. */
181 { "sr", MIPS_PS_REGNUM
},
183 /* This is the traditional GDB name for the CP0 BadVAddr register. */
184 { "bad", MIPS_EMBED_BADVADDR_REGNUM
},
186 /* This is the traditional GDB name for the FCSR. */
187 { "fsr", MIPS_EMBED_FP0_REGNUM
+ 32 }
190 const struct register_alias mips_numeric_register_aliases
[] = {
191 #define R(n) { #n, n }
192 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
193 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
194 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
195 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
199 #ifndef MIPS_DEFAULT_FPU_TYPE
200 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
202 static int mips_fpu_type_auto
= 1;
203 static enum mips_fpu_type mips_fpu_type
= MIPS_DEFAULT_FPU_TYPE
;
205 static unsigned int mips_debug
= 0;
207 /* Properties (for struct target_desc) describing the g/G packet
209 #define PROPERTY_GP32 "internal: transfers-32bit-registers"
210 #define PROPERTY_GP64 "internal: transfers-64bit-registers"
212 struct target_desc
*mips_tdesc_gp32
;
213 struct target_desc
*mips_tdesc_gp64
;
215 /* The current set of options to be passed to the disassembler. */
216 static char *mips_disassembler_options
;
218 /* Implicit disassembler options for individual ABIs. These tell
219 libopcodes to use general-purpose register names corresponding
220 to the ABI we have selected, perhaps via a `set mips abi ...'
221 override, rather than ones inferred from the ABI set in the ELF
222 headers of the binary file selected for debugging. */
223 static const char mips_disassembler_options_o32
[] = "gpr-names=32";
224 static const char mips_disassembler_options_n32
[] = "gpr-names=n32";
225 static const char mips_disassembler_options_n64
[] = "gpr-names=64";
227 const struct mips_regnum
*
228 mips_regnum (struct gdbarch
*gdbarch
)
230 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
235 mips_fpa0_regnum (struct gdbarch
*gdbarch
)
237 return mips_regnum (gdbarch
)->fp0
+ 12;
240 /* Return 1 if REGNUM refers to a floating-point general register, raw
241 or cooked. Otherwise return 0. */
244 mips_float_register_p (struct gdbarch
*gdbarch
, int regnum
)
246 int rawnum
= regnum
% gdbarch_num_regs (gdbarch
);
248 return (rawnum
>= mips_regnum (gdbarch
)->fp0
249 && rawnum
< mips_regnum (gdbarch
)->fp0
+ 32);
253 mips_eabi (gdbarch
*arch
)
255 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (arch
);
256 return (tdep
->mips_abi
== MIPS_ABI_EABI32 \
257 || tdep
->mips_abi
== MIPS_ABI_EABI64
);
261 mips_last_fp_arg_regnum (gdbarch
*arch
)
263 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (arch
);
264 return tdep
->mips_last_fp_arg_regnum
;
268 mips_last_arg_regnum (gdbarch
*arch
)
270 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (arch
);
271 return tdep
->mips_last_arg_regnum
;
274 static enum mips_fpu_type
275 mips_get_fpu_type (gdbarch
*arch
)
277 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (arch
);
278 return tdep
->mips_fpu_type
;
281 /* Return the MIPS ABI associated with GDBARCH. */
283 mips_abi (struct gdbarch
*gdbarch
)
285 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
286 return tdep
->mips_abi
;
290 mips_isa_regsize (struct gdbarch
*gdbarch
)
292 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
294 /* If we know how big the registers are, use that size. */
295 if (tdep
->register_size_valid_p
)
296 return tdep
->register_size
;
298 /* Fall back to the previous behavior. */
299 return (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
300 / gdbarch_bfd_arch_info (gdbarch
)->bits_per_byte
);
303 /* Max saved register size. */
304 #define MAX_MIPS_ABI_REGSIZE 8
306 /* Return the currently configured (or set) saved register size. */
309 mips_abi_regsize (struct gdbarch
*gdbarch
)
311 switch (mips_abi (gdbarch
))
313 case MIPS_ABI_EABI32
:
319 case MIPS_ABI_EABI64
:
321 case MIPS_ABI_UNKNOWN
:
324 internal_error (_("bad switch"));
328 /* MIPS16/microMIPS function addresses are odd (bit 0 is set). Here
329 are some functions to handle addresses associated with compressed
330 code including but not limited to testing, setting, or clearing
331 bit 0 of such addresses. */
333 /* Return one iff compressed code is the MIPS16 instruction set. */
336 is_mips16_isa (struct gdbarch
*gdbarch
)
338 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
339 return tdep
->mips_isa
== ISA_MIPS16
;
342 /* Return one iff compressed code is the microMIPS instruction set. */
345 is_micromips_isa (struct gdbarch
*gdbarch
)
347 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
348 return tdep
->mips_isa
== ISA_MICROMIPS
;
351 /* Return one iff ADDR denotes compressed code. */
354 is_compact_addr (CORE_ADDR addr
)
359 /* Return one iff ADDR denotes standard ISA code. */
362 is_mips_addr (CORE_ADDR addr
)
364 return !is_compact_addr (addr
);
367 /* Return one iff ADDR denotes MIPS16 code. */
370 is_mips16_addr (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
372 return is_compact_addr (addr
) && is_mips16_isa (gdbarch
);
375 /* Return one iff ADDR denotes microMIPS code. */
378 is_micromips_addr (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
380 return is_compact_addr (addr
) && is_micromips_isa (gdbarch
);
383 /* Strip the ISA (compression) bit off from ADDR. */
386 unmake_compact_addr (CORE_ADDR addr
)
388 return ((addr
) & ~(CORE_ADDR
) 1);
391 /* Add the ISA (compression) bit to ADDR. */
394 make_compact_addr (CORE_ADDR addr
)
396 return ((addr
) | (CORE_ADDR
) 1);
399 /* Extern version of unmake_compact_addr; we use a separate function
400 so that unmake_compact_addr can be inlined throughout this file. */
403 mips_unmake_compact_addr (CORE_ADDR addr
)
405 return unmake_compact_addr (addr
);
408 /* Functions for setting and testing a bit in a minimal symbol that
409 marks it as MIPS16 or microMIPS function. The MSB of the minimal
410 symbol's "info" field is used for this purpose.
412 gdbarch_elf_make_msymbol_special tests whether an ELF symbol is
413 "special", i.e. refers to a MIPS16 or microMIPS function, and sets
414 one of the "special" bits in a minimal symbol to mark it accordingly.
415 The test checks an ELF-private flag that is valid for true function
416 symbols only; for synthetic symbols such as for PLT stubs that have
417 no ELF-private part at all the MIPS BFD backend arranges for this
418 information to be carried in the asymbol's udata field instead.
420 msymbol_is_mips16 and msymbol_is_micromips test the "special" bit
421 in a minimal symbol. */
424 mips_elf_make_msymbol_special (asymbol
* sym
, struct minimal_symbol
*msym
)
426 elf_symbol_type
*elfsym
= (elf_symbol_type
*) sym
;
427 unsigned char st_other
;
429 if ((sym
->flags
& BSF_SYNTHETIC
) == 0)
430 st_other
= elfsym
->internal_elf_sym
.st_other
;
431 else if ((sym
->flags
& BSF_FUNCTION
) != 0)
432 st_other
= sym
->udata
.i
;
436 if (ELF_ST_IS_MICROMIPS (st_other
))
438 SET_MSYMBOL_TARGET_FLAG_MICROMIPS (msym
);
439 msym
->set_value_address (msym
->value_raw_address () | 1);
441 else if (ELF_ST_IS_MIPS16 (st_other
))
443 SET_MSYMBOL_TARGET_FLAG_MIPS16 (msym
);
444 msym
->set_value_address (msym
->value_raw_address () | 1);
448 /* Return one iff MSYM refers to standard ISA code. */
451 msymbol_is_mips (struct minimal_symbol
*msym
)
453 return !(MSYMBOL_TARGET_FLAG_MIPS16 (msym
)
454 || MSYMBOL_TARGET_FLAG_MICROMIPS (msym
));
457 /* Return one iff MSYM refers to MIPS16 code. */
460 msymbol_is_mips16 (struct minimal_symbol
*msym
)
462 return MSYMBOL_TARGET_FLAG_MIPS16 (msym
);
465 /* Return one iff MSYM refers to microMIPS code. */
468 msymbol_is_micromips (struct minimal_symbol
*msym
)
470 return MSYMBOL_TARGET_FLAG_MICROMIPS (msym
);
473 /* Set the ISA bit in the main symbol too, complementing the corresponding
474 minimal symbol setting and reflecting the run-time value of the symbol.
475 The need for comes from the ISA bit having been cleared as code in
476 `_bfd_mips_elf_symbol_processing' separated it into the ELF symbol's
477 `st_other' STO_MIPS16 or STO_MICROMIPS annotation, making the values
478 of symbols referring to compressed code different in GDB to the values
479 used by actual code. That in turn makes them evaluate incorrectly in
480 expressions, producing results different to what the same expressions
481 yield when compiled into the program being debugged. */
484 mips_make_symbol_special (struct symbol
*sym
, struct objfile
*objfile
)
486 if (sym
->aclass () == LOC_BLOCK
)
488 /* We are in symbol reading so it is OK to cast away constness. */
489 struct block
*block
= (struct block
*) sym
->value_block ();
490 CORE_ADDR compact_block_start
;
491 struct bound_minimal_symbol msym
;
493 compact_block_start
= block
->start () | 1;
494 msym
= lookup_minimal_symbol_by_pc (compact_block_start
);
495 if (msym
.minsym
&& !msymbol_is_mips (msym
.minsym
))
497 block
->set_start (compact_block_start
);
502 /* XFER a value from the big/little/left end of the register.
503 Depending on the size of the value it might occupy the entire
504 register or just part of it. Make an allowance for this, aligning
505 things accordingly. */
508 mips_xfer_register (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
509 int reg_num
, int length
,
510 enum bfd_endian endian
, gdb_byte
*in
,
511 const gdb_byte
*out
, int buf_offset
)
515 gdb_assert (reg_num
>= gdbarch_num_regs (gdbarch
));
516 /* Need to transfer the left or right part of the register, based on
517 the targets byte order. */
521 reg_offset
= register_size (gdbarch
, reg_num
) - length
;
523 case BFD_ENDIAN_LITTLE
:
526 case BFD_ENDIAN_UNKNOWN
: /* Indicates no alignment. */
530 internal_error (_("bad switch"));
533 gdb_printf (gdb_stderr
,
534 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
535 reg_num
, reg_offset
, buf_offset
, length
);
536 if (mips_debug
&& out
!= NULL
)
539 gdb_printf (gdb_stdlog
, "out ");
540 for (i
= 0; i
< length
; i
++)
541 gdb_printf (gdb_stdlog
, "%02x", out
[buf_offset
+ i
]);
544 regcache
->cooked_read_part (reg_num
, reg_offset
, length
, in
+ buf_offset
);
546 regcache
->cooked_write_part (reg_num
, reg_offset
, length
, out
+ buf_offset
);
547 if (mips_debug
&& in
!= NULL
)
550 gdb_printf (gdb_stdlog
, "in ");
551 for (i
= 0; i
< length
; i
++)
552 gdb_printf (gdb_stdlog
, "%02x", in
[buf_offset
+ i
]);
555 gdb_printf (gdb_stdlog
, "\n");
558 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
559 compatiblity mode. A return value of 1 means that we have
560 physical 64-bit registers, but should treat them as 32-bit registers. */
563 mips2_fp_compat (frame_info_ptr frame
)
565 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
566 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
568 if (register_size (gdbarch
, mips_regnum (gdbarch
)->fp0
) == 4)
572 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
573 in all the places we deal with FP registers. PR gdb/413. */
574 /* Otherwise check the FR bit in the status register - it controls
575 the FP compatiblity mode. If it is clear we are in compatibility
577 if ((get_frame_register_unsigned (frame
, MIPS_PS_REGNUM
) & ST0_FR
) == 0)
584 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
586 static CORE_ADDR
heuristic_proc_start (struct gdbarch
*, CORE_ADDR
);
588 /* The list of available "set mips " and "show mips " commands. */
590 static struct cmd_list_element
*setmipscmdlist
= NULL
;
591 static struct cmd_list_element
*showmipscmdlist
= NULL
;
593 /* Integer registers 0 thru 31 are handled explicitly by
594 mips_register_name(). Processor specific registers 32 and above
595 are listed in the following tables. */
598 { NUM_MIPS_PROCESSOR_REGS
= (90 - 32) };
602 static const char * const mips_generic_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
603 "sr", "lo", "hi", "bad", "cause", "pc",
604 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
605 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
606 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
607 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
611 /* Names of tx39 registers. */
613 static const char * const mips_tx39_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
614 "sr", "lo", "hi", "bad", "cause", "pc",
615 "", "", "", "", "", "", "", "",
616 "", "", "", "", "", "", "", "",
617 "", "", "", "", "", "", "", "",
618 "", "", "", "", "", "", "", "",
620 "", "", "", "", "", "", "", "",
621 "", "", "config", "cache", "debug", "depc", "epc",
624 /* Names of registers with Linux kernels. */
625 static const char * const mips_linux_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
626 "sr", "lo", "hi", "bad", "cause", "pc",
627 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
628 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
629 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
630 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
635 /* Return the name of the register corresponding to REGNO. */
637 mips_register_name (struct gdbarch
*gdbarch
, int regno
)
639 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
640 /* GPR names for all ABIs other than n32/n64. */
641 static const char *mips_gpr_names
[] = {
642 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
643 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
644 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
645 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
648 /* GPR names for n32 and n64 ABIs. */
649 static const char *mips_n32_n64_gpr_names
[] = {
650 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
651 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
652 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
653 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
656 enum mips_abi abi
= mips_abi (gdbarch
);
658 /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
659 but then don't make the raw register names visible. This (upper)
660 range of user visible register numbers are the pseudo-registers.
662 This approach was adopted accommodate the following scenario:
663 It is possible to debug a 64-bit device using a 32-bit
664 programming model. In such instances, the raw registers are
665 configured to be 64-bits wide, while the pseudo registers are
666 configured to be 32-bits wide. The registers that the user
667 sees - the pseudo registers - match the users expectations
668 given the programming model being used. */
669 int rawnum
= regno
% gdbarch_num_regs (gdbarch
);
670 if (regno
< gdbarch_num_regs (gdbarch
))
673 /* The MIPS integer registers are always mapped from 0 to 31. The
674 names of the registers (which reflects the conventions regarding
675 register use) vary depending on the ABI. */
676 if (0 <= rawnum
&& rawnum
< 32)
678 if (abi
== MIPS_ABI_N32
|| abi
== MIPS_ABI_N64
)
679 return mips_n32_n64_gpr_names
[rawnum
];
681 return mips_gpr_names
[rawnum
];
683 else if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
684 return tdesc_register_name (gdbarch
, rawnum
);
685 else if (32 <= rawnum
&& rawnum
< gdbarch_num_regs (gdbarch
))
687 gdb_assert (rawnum
- 32 < NUM_MIPS_PROCESSOR_REGS
);
688 if (tdep
->mips_processor_reg_names
[rawnum
- 32])
689 return tdep
->mips_processor_reg_names
[rawnum
- 32];
693 internal_error (_("mips_register_name: bad register number %d"), rawnum
);
696 /* Return the groups that a MIPS register can be categorised into. */
699 mips_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
700 const struct reggroup
*reggroup
)
705 int rawnum
= regnum
% gdbarch_num_regs (gdbarch
);
706 int pseudo
= regnum
/ gdbarch_num_regs (gdbarch
);
707 if (reggroup
== all_reggroup
)
709 vector_p
= register_type (gdbarch
, regnum
)->is_vector ();
710 float_p
= register_type (gdbarch
, regnum
)->code () == TYPE_CODE_FLT
;
711 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
712 (gdbarch), as not all architectures are multi-arch. */
713 raw_p
= rawnum
< gdbarch_num_regs (gdbarch
);
714 if (gdbarch_register_name (gdbarch
, regnum
)[0] == '\0')
716 if (reggroup
== float_reggroup
)
717 return float_p
&& pseudo
;
718 if (reggroup
== vector_reggroup
)
719 return vector_p
&& pseudo
;
720 if (reggroup
== general_reggroup
)
721 return (!vector_p
&& !float_p
) && pseudo
;
722 /* Save the pseudo registers. Need to make certain that any code
723 extracting register values from a saved register cache also uses
725 if (reggroup
== save_reggroup
)
726 return raw_p
&& pseudo
;
727 /* Restore the same pseudo register. */
728 if (reggroup
== restore_reggroup
)
729 return raw_p
&& pseudo
;
733 /* Return the groups that a MIPS register can be categorised into.
734 This version is only used if we have a target description which
735 describes real registers (and their groups). */
738 mips_tdesc_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
739 const struct reggroup
*reggroup
)
741 int rawnum
= regnum
% gdbarch_num_regs (gdbarch
);
742 int pseudo
= regnum
/ gdbarch_num_regs (gdbarch
);
745 /* Only save, restore, and display the pseudo registers. Need to
746 make certain that any code extracting register values from a
747 saved register cache also uses pseudo registers.
749 Note: saving and restoring the pseudo registers is slightly
750 strange; if we have 64 bits, we should save and restore all
751 64 bits. But this is hard and has little benefit. */
755 ret
= tdesc_register_in_reggroup_p (gdbarch
, rawnum
, reggroup
);
759 return mips_register_reggroup_p (gdbarch
, regnum
, reggroup
);
762 /* Map the symbol table registers which live in the range [1 *
763 gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
764 registers. Take care of alignment and size problems. */
766 static enum register_status
767 mips_pseudo_register_read (struct gdbarch
*gdbarch
, readable_regcache
*regcache
,
768 int cookednum
, gdb_byte
*buf
)
770 int rawnum
= cookednum
% gdbarch_num_regs (gdbarch
);
771 gdb_assert (cookednum
>= gdbarch_num_regs (gdbarch
)
772 && cookednum
< 2 * gdbarch_num_regs (gdbarch
));
773 if (register_size (gdbarch
, rawnum
) == register_size (gdbarch
, cookednum
))
774 return regcache
->raw_read (rawnum
, buf
);
775 else if (register_size (gdbarch
, rawnum
) >
776 register_size (gdbarch
, cookednum
))
778 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
780 if (tdep
->mips64_transfers_32bit_regs_p
)
781 return regcache
->raw_read_part (rawnum
, 0, 4, buf
);
784 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
786 enum register_status status
;
788 status
= regcache
->raw_read (rawnum
, ®val
);
789 if (status
== REG_VALID
)
790 store_signed_integer (buf
, 4, byte_order
, regval
);
795 internal_error (_("bad register size"));
799 mips_pseudo_register_write (struct gdbarch
*gdbarch
,
800 struct regcache
*regcache
, int cookednum
,
803 int rawnum
= cookednum
% gdbarch_num_regs (gdbarch
);
804 gdb_assert (cookednum
>= gdbarch_num_regs (gdbarch
)
805 && cookednum
< 2 * gdbarch_num_regs (gdbarch
));
806 if (register_size (gdbarch
, rawnum
) == register_size (gdbarch
, cookednum
))
807 regcache
->raw_write (rawnum
, buf
);
808 else if (register_size (gdbarch
, rawnum
) >
809 register_size (gdbarch
, cookednum
))
811 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
813 if (tdep
->mips64_transfers_32bit_regs_p
)
814 regcache
->raw_write_part (rawnum
, 0, 4, buf
);
817 /* Sign extend the shortened version of the register prior
818 to placing it in the raw register. This is required for
819 some mips64 parts in order to avoid unpredictable behavior. */
820 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
821 LONGEST regval
= extract_signed_integer (buf
, 4, byte_order
);
822 regcache_raw_write_signed (regcache
, rawnum
, regval
);
826 internal_error (_("bad register size"));
830 mips_ax_pseudo_register_collect (struct gdbarch
*gdbarch
,
831 struct agent_expr
*ax
, int reg
)
833 int rawnum
= reg
% gdbarch_num_regs (gdbarch
);
834 gdb_assert (reg
>= gdbarch_num_regs (gdbarch
)
835 && reg
< 2 * gdbarch_num_regs (gdbarch
));
837 ax_reg_mask (ax
, rawnum
);
843 mips_ax_pseudo_register_push_stack (struct gdbarch
*gdbarch
,
844 struct agent_expr
*ax
, int reg
)
846 int rawnum
= reg
% gdbarch_num_regs (gdbarch
);
847 gdb_assert (reg
>= gdbarch_num_regs (gdbarch
)
848 && reg
< 2 * gdbarch_num_regs (gdbarch
));
849 if (register_size (gdbarch
, rawnum
) >= register_size (gdbarch
, reg
))
853 if (register_size (gdbarch
, rawnum
) > register_size (gdbarch
, reg
))
855 mips_gdbarch_tdep
*tdep
856 = gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
858 if (!tdep
->mips64_transfers_32bit_regs_p
859 || gdbarch_byte_order (gdbarch
) != BFD_ENDIAN_BIG
)
862 ax_simple (ax
, aop_lsh
);
865 ax_simple (ax
, aop_rsh_signed
);
869 internal_error (_("bad register size"));
874 /* Table to translate 3-bit register field to actual register number. */
875 static const signed char mips_reg3_to_reg
[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
877 /* Heuristic_proc_start may hunt through the text section for a long
878 time across a 2400 baud serial line. Allows the user to limit this
881 static int heuristic_fence_post
= 0;
883 /* Number of bytes of storage in the actual machine representation for
884 register N. NOTE: This defines the pseudo register type so need to
885 rebuild the architecture vector. */
887 static bool mips64_transfers_32bit_regs_p
= false;
890 set_mips64_transfers_32bit_regs (const char *args
, int from_tty
,
891 struct cmd_list_element
*c
)
893 struct gdbarch_info info
;
894 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
895 instead of relying on globals. Doing that would let generic code
896 handle the search for this specific architecture. */
897 if (!gdbarch_update_p (info
))
899 mips64_transfers_32bit_regs_p
= 0;
900 error (_("32-bit compatibility mode not supported"));
904 /* Convert to/from a register and the corresponding memory value. */
906 /* This predicate tests for the case of an 8 byte floating point
907 value that is being transferred to or from a pair of floating point
908 registers each of which are (or are considered to be) only 4 bytes
911 mips_convert_register_float_case_p (struct gdbarch
*gdbarch
, int regnum
,
914 return (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
915 && register_size (gdbarch
, regnum
) == 4
916 && mips_float_register_p (gdbarch
, regnum
)
917 && type
->code () == TYPE_CODE_FLT
&& type
->length () == 8);
920 /* This predicate tests for the case of a value of less than 8
921 bytes in width that is being transfered to or from an 8 byte
922 general purpose register. */
924 mips_convert_register_gpreg_case_p (struct gdbarch
*gdbarch
, int regnum
,
927 int num_regs
= gdbarch_num_regs (gdbarch
);
929 return (register_size (gdbarch
, regnum
) == 8
930 && regnum
% num_regs
> 0 && regnum
% num_regs
< 32
931 && type
->length () < 8);
935 mips_convert_register_p (struct gdbarch
*gdbarch
,
936 int regnum
, struct type
*type
)
938 return (mips_convert_register_float_case_p (gdbarch
, regnum
, type
)
939 || mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
));
943 mips_register_to_value (frame_info_ptr frame
, int regnum
,
944 struct type
*type
, gdb_byte
*to
,
945 int *optimizedp
, int *unavailablep
)
947 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
949 if (mips_convert_register_float_case_p (gdbarch
, regnum
, type
))
951 get_frame_register (frame
, regnum
+ 0, to
+ 4);
952 get_frame_register (frame
, regnum
+ 1, to
+ 0);
954 if (!get_frame_register_bytes (frame
, regnum
+ 0, 0, {to
+ 4, 4},
955 optimizedp
, unavailablep
))
958 if (!get_frame_register_bytes (frame
, regnum
+ 1, 0, {to
+ 0, 4},
959 optimizedp
, unavailablep
))
961 *optimizedp
= *unavailablep
= 0;
964 else if (mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
))
966 size_t len
= type
->length ();
969 offset
= gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
? 8 - len
: 0;
970 if (!get_frame_register_bytes (frame
, regnum
, offset
, {to
, len
},
971 optimizedp
, unavailablep
))
974 *optimizedp
= *unavailablep
= 0;
979 internal_error (_("mips_register_to_value: unrecognized case"));
984 mips_value_to_register (frame_info_ptr frame
, int regnum
,
985 struct type
*type
, const gdb_byte
*from
)
987 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
989 if (mips_convert_register_float_case_p (gdbarch
, regnum
, type
))
991 put_frame_register (frame
, regnum
+ 0, from
+ 4);
992 put_frame_register (frame
, regnum
+ 1, from
+ 0);
994 else if (mips_convert_register_gpreg_case_p (gdbarch
, regnum
, type
))
997 size_t len
= type
->length ();
999 /* Sign extend values, irrespective of type, that are stored to
1000 a 64-bit general purpose register. (32-bit unsigned values
1001 are stored as signed quantities within a 64-bit register.
1002 When performing an operation, in compiled code, that combines
1003 a 32-bit unsigned value with a signed 64-bit value, a type
1004 conversion is first performed that zeroes out the high 32 bits.) */
1005 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1008 store_signed_integer (fill
, 8, BFD_ENDIAN_BIG
, -1);
1010 store_signed_integer (fill
, 8, BFD_ENDIAN_BIG
, 0);
1011 put_frame_register_bytes (frame
, regnum
, 0, {fill
, 8 - len
});
1012 put_frame_register_bytes (frame
, regnum
, 8 - len
, {from
, len
});
1016 if (from
[len
-1] & 0x80)
1017 store_signed_integer (fill
, 8, BFD_ENDIAN_LITTLE
, -1);
1019 store_signed_integer (fill
, 8, BFD_ENDIAN_LITTLE
, 0);
1020 put_frame_register_bytes (frame
, regnum
, 0, {from
, len
});
1021 put_frame_register_bytes (frame
, regnum
, len
, {fill
, 8 - len
});
1026 internal_error (_("mips_value_to_register: unrecognized case"));
1030 /* Return the GDB type object for the "standard" data type of data in
1033 static struct type
*
1034 mips_register_type (struct gdbarch
*gdbarch
, int regnum
)
1036 gdb_assert (regnum
>= 0 && regnum
< 2 * gdbarch_num_regs (gdbarch
));
1037 if (mips_float_register_p (gdbarch
, regnum
))
1039 /* The floating-point registers raw, or cooked, always match
1040 mips_isa_regsize(), and also map 1:1, byte for byte. */
1041 if (mips_isa_regsize (gdbarch
) == 4)
1042 return builtin_type (gdbarch
)->builtin_float
;
1044 return builtin_type (gdbarch
)->builtin_double
;
1046 else if (regnum
< gdbarch_num_regs (gdbarch
))
1048 /* The raw or ISA registers. These are all sized according to
1050 if (mips_isa_regsize (gdbarch
) == 4)
1051 return builtin_type (gdbarch
)->builtin_int32
;
1053 return builtin_type (gdbarch
)->builtin_int64
;
1057 int rawnum
= regnum
- gdbarch_num_regs (gdbarch
);
1058 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
1060 /* The cooked or ABI registers. These are sized according to
1061 the ABI (with a few complications). */
1062 if (rawnum
== mips_regnum (gdbarch
)->fp_control_status
1063 || rawnum
== mips_regnum (gdbarch
)->fp_implementation_revision
)
1064 return builtin_type (gdbarch
)->builtin_int32
;
1065 else if (gdbarch_osabi (gdbarch
) != GDB_OSABI_LINUX
1066 && rawnum
>= MIPS_FIRST_EMBED_REGNUM
1067 && rawnum
<= MIPS_LAST_EMBED_REGNUM
)
1068 /* The pseudo/cooked view of the embedded registers is always
1069 32-bit. The raw view is handled below. */
1070 return builtin_type (gdbarch
)->builtin_int32
;
1071 else if (tdep
->mips64_transfers_32bit_regs_p
)
1072 /* The target, while possibly using a 64-bit register buffer,
1073 is only transfering 32-bits of each integer register.
1074 Reflect this in the cooked/pseudo (ABI) register value. */
1075 return builtin_type (gdbarch
)->builtin_int32
;
1076 else if (mips_abi_regsize (gdbarch
) == 4)
1077 /* The ABI is restricted to 32-bit registers (the ISA could be
1079 return builtin_type (gdbarch
)->builtin_int32
;
1082 return builtin_type (gdbarch
)->builtin_int64
;
1086 /* Return the GDB type for the pseudo register REGNUM, which is the
1087 ABI-level view. This function is only called if there is a target
1088 description which includes registers, so we know precisely the
1089 types of hardware registers. */
1091 static struct type
*
1092 mips_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
1094 const int num_regs
= gdbarch_num_regs (gdbarch
);
1095 int rawnum
= regnum
% num_regs
;
1096 struct type
*rawtype
;
1098 gdb_assert (regnum
>= num_regs
&& regnum
< 2 * num_regs
);
1100 /* Absent registers are still absent. */
1101 rawtype
= gdbarch_register_type (gdbarch
, rawnum
);
1102 if (rawtype
->length () == 0)
1105 /* Present the floating point registers however the hardware did;
1106 do not try to convert between FPU layouts. */
1107 if (mips_float_register_p (gdbarch
, rawnum
))
1110 /* Floating-point control registers are always 32-bit even though for
1111 backwards compatibility reasons 64-bit targets will transfer them
1112 as 64-bit quantities even if using XML descriptions. */
1113 if (rawnum
== mips_regnum (gdbarch
)->fp_control_status
1114 || rawnum
== mips_regnum (gdbarch
)->fp_implementation_revision
)
1115 return builtin_type (gdbarch
)->builtin_int32
;
1117 /* Use pointer types for registers if we can. For n32 we can not,
1118 since we do not have a 64-bit pointer type. */
1119 if (mips_abi_regsize (gdbarch
)
1120 == builtin_type (gdbarch
)->builtin_data_ptr
->length())
1122 if (rawnum
== MIPS_SP_REGNUM
1123 || rawnum
== mips_regnum (gdbarch
)->badvaddr
)
1124 return builtin_type (gdbarch
)->builtin_data_ptr
;
1125 else if (rawnum
== mips_regnum (gdbarch
)->pc
)
1126 return builtin_type (gdbarch
)->builtin_func_ptr
;
1129 if (mips_abi_regsize (gdbarch
) == 4 && rawtype
->length () == 8
1130 && ((rawnum
>= MIPS_ZERO_REGNUM
&& rawnum
<= MIPS_PS_REGNUM
)
1131 || rawnum
== mips_regnum (gdbarch
)->lo
1132 || rawnum
== mips_regnum (gdbarch
)->hi
1133 || rawnum
== mips_regnum (gdbarch
)->badvaddr
1134 || rawnum
== mips_regnum (gdbarch
)->cause
1135 || rawnum
== mips_regnum (gdbarch
)->pc
1136 || (mips_regnum (gdbarch
)->dspacc
!= -1
1137 && rawnum
>= mips_regnum (gdbarch
)->dspacc
1138 && rawnum
< mips_regnum (gdbarch
)->dspacc
+ 6)))
1139 return builtin_type (gdbarch
)->builtin_int32
;
1141 /* The pseudo/cooked view of embedded registers is always
1142 32-bit, even if the target transfers 64-bit values for them.
1143 New targets relying on XML descriptions should only transfer
1144 the necessary 32 bits, but older versions of GDB expected 64,
1145 so allow the target to provide 64 bits without interfering
1146 with the displayed type. */
1147 if (gdbarch_osabi (gdbarch
) != GDB_OSABI_LINUX
1148 && rawnum
>= MIPS_FIRST_EMBED_REGNUM
1149 && rawnum
<= MIPS_LAST_EMBED_REGNUM
)
1150 return builtin_type (gdbarch
)->builtin_int32
;
1152 /* For all other registers, pass through the hardware type. */
1156 /* Should the upper word of 64-bit addresses be zeroed? */
1157 static enum auto_boolean mask_address_var
= AUTO_BOOLEAN_AUTO
;
1160 mips_mask_address_p (mips_gdbarch_tdep
*tdep
)
1162 switch (mask_address_var
)
1164 case AUTO_BOOLEAN_TRUE
:
1166 case AUTO_BOOLEAN_FALSE
:
1169 case AUTO_BOOLEAN_AUTO
:
1170 return tdep
->default_mask_address_p
;
1172 internal_error (_("mips_mask_address_p: bad switch"));
1178 show_mask_address (struct ui_file
*file
, int from_tty
,
1179 struct cmd_list_element
*c
, const char *value
)
1181 const char *additional_text
= "";
1182 if (mask_address_var
== AUTO_BOOLEAN_AUTO
)
1184 if (gdbarch_bfd_arch_info (target_gdbarch ())->arch
!= bfd_arch_mips
)
1185 additional_text
= _(" (current architecture is not MIPS)");
1188 mips_gdbarch_tdep
*tdep
1189 = gdbarch_tdep
<mips_gdbarch_tdep
> (target_gdbarch ());
1191 if (mips_mask_address_p (tdep
))
1192 additional_text
= _(" (currently \"on\")");
1194 additional_text
= _(" (currently \"off\")");
1198 gdb_printf (file
, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
1199 value
, additional_text
);
1202 /* Tell if the program counter value in MEMADDR is in a standard ISA
1206 mips_pc_is_mips (CORE_ADDR memaddr
)
1208 struct bound_minimal_symbol sym
;
1210 /* Flags indicating that this is a MIPS16 or microMIPS function is
1211 stored by elfread.c in the high bit of the info field. Use this
1212 to decide if the function is standard MIPS. Otherwise if bit 0
1213 of the address is clear, then this is a standard MIPS function. */
1214 sym
= lookup_minimal_symbol_by_pc (make_compact_addr (memaddr
));
1216 return msymbol_is_mips (sym
.minsym
);
1218 return is_mips_addr (memaddr
);
1221 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
1224 mips_pc_is_mips16 (struct gdbarch
*gdbarch
, CORE_ADDR memaddr
)
1226 struct bound_minimal_symbol sym
;
1228 /* A flag indicating that this is a MIPS16 function is stored by
1229 elfread.c in the high bit of the info field. Use this to decide
1230 if the function is MIPS16. Otherwise if bit 0 of the address is
1231 set, then ELF file flags will tell if this is a MIPS16 function. */
1232 sym
= lookup_minimal_symbol_by_pc (make_compact_addr (memaddr
));
1234 return msymbol_is_mips16 (sym
.minsym
);
1236 return is_mips16_addr (gdbarch
, memaddr
);
1239 /* Tell if the program counter value in MEMADDR is in a microMIPS function. */
1242 mips_pc_is_micromips (struct gdbarch
*gdbarch
, CORE_ADDR memaddr
)
1244 struct bound_minimal_symbol sym
;
1246 /* A flag indicating that this is a microMIPS function is stored by
1247 elfread.c in the high bit of the info field. Use this to decide
1248 if the function is microMIPS. Otherwise if bit 0 of the address
1249 is set, then ELF file flags will tell if this is a microMIPS
1251 sym
= lookup_minimal_symbol_by_pc (make_compact_addr (memaddr
));
1253 return msymbol_is_micromips (sym
.minsym
);
1255 return is_micromips_addr (gdbarch
, memaddr
);
1258 /* Tell the ISA type of the function the program counter value in MEMADDR
1261 static enum mips_isa
1262 mips_pc_isa (struct gdbarch
*gdbarch
, CORE_ADDR memaddr
)
1264 struct bound_minimal_symbol sym
;
1266 /* A flag indicating that this is a MIPS16 or a microMIPS function
1267 is stored by elfread.c in the high bit of the info field. Use
1268 this to decide if the function is MIPS16 or microMIPS or normal
1269 MIPS. Otherwise if bit 0 of the address is set, then ELF file
1270 flags will tell if this is a MIPS16 or a microMIPS function. */
1271 sym
= lookup_minimal_symbol_by_pc (make_compact_addr (memaddr
));
1274 if (msymbol_is_micromips (sym
.minsym
))
1275 return ISA_MICROMIPS
;
1276 else if (msymbol_is_mips16 (sym
.minsym
))
1283 if (is_mips_addr (memaddr
))
1285 else if (is_micromips_addr (gdbarch
, memaddr
))
1286 return ISA_MICROMIPS
;
1292 /* Set the ISA bit correctly in the PC, used by DWARF-2 machinery.
1293 The need for comes from the ISA bit having been cleared, making
1294 addresses in FDE, range records, etc. referring to compressed code
1295 different to those in line information, the symbol table and finally
1296 the PC register. That in turn confuses many operations. */
1299 mips_adjust_dwarf2_addr (CORE_ADDR pc
)
1301 pc
= unmake_compact_addr (pc
);
1302 return mips_pc_is_mips (pc
) ? pc
: make_compact_addr (pc
);
1305 /* Recalculate the line record requested so that the resulting PC has
1306 the ISA bit set correctly, used by DWARF-2 machinery. The need for
1307 this adjustment comes from some records associated with compressed
1308 code having the ISA bit cleared, most notably at function prologue
1309 ends. The ISA bit is in this context retrieved from the minimal
1310 symbol covering the address requested, which in turn has been
1311 constructed from the binary's symbol table rather than DWARF-2
1312 information. The correct setting of the ISA bit is required for
1313 breakpoint addresses to correctly match against the stop PC.
1315 As line entries can specify relative address adjustments we need to
1316 keep track of the absolute value of the last line address recorded
1317 in line information, so that we can calculate the actual address to
1318 apply the ISA bit adjustment to. We use PC for this tracking and
1319 keep the original address there.
1321 As such relative address adjustments can be odd within compressed
1322 code we need to keep track of the last line address with the ISA
1323 bit adjustment applied too, as the original address may or may not
1324 have had the ISA bit set. We use ADJ_PC for this tracking and keep
1325 the adjusted address there.
1327 For relative address adjustments we then use these variables to
1328 calculate the address intended by line information, which will be
1329 PC-relative, and return an updated adjustment carrying ISA bit
1330 information, which will be ADJ_PC-relative. For absolute address
1331 adjustments we just return the same address that we store in ADJ_PC
1334 As the first line entry can be relative to an implied address value
1335 of 0 we need to have the initial address set up that we store in PC
1336 and ADJ_PC. This is arranged with a call from `dwarf_decode_lines_1'
1337 that sets PC to 0 and ADJ_PC accordingly, usually 0 as well. */
1340 mips_adjust_dwarf2_line (CORE_ADDR addr
, int rel
)
1342 static CORE_ADDR adj_pc
;
1343 static CORE_ADDR pc
;
1346 pc
= rel
? pc
+ addr
: addr
;
1347 isa_pc
= mips_adjust_dwarf2_addr (pc
);
1348 addr
= rel
? isa_pc
- adj_pc
: isa_pc
;
1353 /* Various MIPS16 thunk (aka stub or trampoline) names. */
1355 static const char mips_str_mips16_call_stub
[] = "__mips16_call_stub_";
1356 static const char mips_str_mips16_ret_stub
[] = "__mips16_ret_";
1357 static const char mips_str_call_fp_stub
[] = "__call_stub_fp_";
1358 static const char mips_str_call_stub
[] = "__call_stub_";
1359 static const char mips_str_fn_stub
[] = "__fn_stub_";
1361 /* This is used as a PIC thunk prefix. */
1363 static const char mips_str_pic
[] = ".pic.";
1365 /* Return non-zero if the PC is inside a call thunk (aka stub or
1366 trampoline) that should be treated as a temporary frame. */
1369 mips_in_frame_stub (CORE_ADDR pc
)
1371 CORE_ADDR start_addr
;
1374 /* Find the starting address of the function containing the PC. */
1375 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
1378 /* If the PC is in __mips16_call_stub_*, this is a call/return stub. */
1379 if (startswith (name
, mips_str_mips16_call_stub
))
1381 /* If the PC is in __call_stub_*, this is a call/return or a call stub. */
1382 if (startswith (name
, mips_str_call_stub
))
1384 /* If the PC is in __fn_stub_*, this is a call stub. */
1385 if (startswith (name
, mips_str_fn_stub
))
1388 return 0; /* Not a stub. */
1391 /* MIPS believes that the PC has a sign extended value. Perhaps the
1392 all registers should be sign extended for simplicity? */
1395 mips_read_pc (readable_regcache
*regcache
)
1397 int regnum
= gdbarch_pc_regnum (regcache
->arch ());
1400 regcache
->cooked_read (regnum
, &pc
);
1405 mips_unwind_pc (struct gdbarch
*gdbarch
, frame_info_ptr next_frame
)
1409 pc
= frame_unwind_register_signed (next_frame
, gdbarch_pc_regnum (gdbarch
));
1410 /* macro/2012-04-20: This hack skips over MIPS16 call thunks as
1411 intermediate frames. In this case we can get the caller's address
1412 from $ra, or if $ra contains an address within a thunk as well, then
1413 it must be in the return path of __mips16_call_stub_{s,d}{f,c}_{0..10}
1414 and thus the caller's address is in $s2. */
1415 if (frame_relative_level (next_frame
) >= 0 && mips_in_frame_stub (pc
))
1417 pc
= frame_unwind_register_signed
1418 (next_frame
, gdbarch_num_regs (gdbarch
) + MIPS_RA_REGNUM
);
1419 if (mips_in_frame_stub (pc
))
1420 pc
= frame_unwind_register_signed
1421 (next_frame
, gdbarch_num_regs (gdbarch
) + MIPS_S2_REGNUM
);
1427 mips_unwind_sp (struct gdbarch
*gdbarch
, frame_info_ptr next_frame
)
1429 return frame_unwind_register_signed
1430 (next_frame
, gdbarch_num_regs (gdbarch
) + MIPS_SP_REGNUM
);
1433 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
1434 dummy frame. The frame ID's base needs to match the TOS value
1435 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
1438 static struct frame_id
1439 mips_dummy_id (struct gdbarch
*gdbarch
, frame_info_ptr this_frame
)
1441 return frame_id_build
1442 (get_frame_register_signed (this_frame
,
1443 gdbarch_num_regs (gdbarch
)
1445 get_frame_pc (this_frame
));
1448 /* Implement the "write_pc" gdbarch method. */
1451 mips_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1453 int regnum
= gdbarch_pc_regnum (regcache
->arch ());
1455 regcache_cooked_write_unsigned (regcache
, regnum
, pc
);
1458 /* Fetch and return instruction from the specified location. Handle
1459 MIPS16/microMIPS as appropriate. */
1462 mips_fetch_instruction (struct gdbarch
*gdbarch
,
1463 enum mips_isa isa
, CORE_ADDR addr
, int *errp
)
1465 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1466 gdb_byte buf
[MIPS_INSN32_SIZE
];
1474 instlen
= MIPS_INSN16_SIZE
;
1475 addr
= unmake_compact_addr (addr
);
1478 instlen
= MIPS_INSN32_SIZE
;
1481 internal_error (_("invalid ISA"));
1484 err
= target_read_memory (addr
, buf
, instlen
);
1490 memory_error (TARGET_XFER_E_IO
, addr
);
1493 return extract_unsigned_integer (buf
, instlen
, byte_order
);
1496 /* These are the fields of 32 bit mips instructions. */
1497 #define mips32_op(x) (x >> 26)
1498 #define itype_op(x) (x >> 26)
1499 #define itype_rs(x) ((x >> 21) & 0x1f)
1500 #define itype_rt(x) ((x >> 16) & 0x1f)
1501 #define itype_immediate(x) (x & 0xffff)
1503 #define jtype_op(x) (x >> 26)
1504 #define jtype_target(x) (x & 0x03ffffff)
1506 #define rtype_op(x) (x >> 26)
1507 #define rtype_rs(x) ((x >> 21) & 0x1f)
1508 #define rtype_rt(x) ((x >> 16) & 0x1f)
1509 #define rtype_rd(x) ((x >> 11) & 0x1f)
1510 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1511 #define rtype_funct(x) (x & 0x3f)
1513 /* MicroMIPS instruction fields. */
1514 #define micromips_op(x) ((x) >> 10)
1516 /* 16-bit/32-bit-high-part instruction formats, B and S refer to the lowest
1517 bit and the size respectively of the field extracted. */
1518 #define b0s4_imm(x) ((x) & 0xf)
1519 #define b0s5_imm(x) ((x) & 0x1f)
1520 #define b0s5_reg(x) ((x) & 0x1f)
1521 #define b0s7_imm(x) ((x) & 0x7f)
1522 #define b0s10_imm(x) ((x) & 0x3ff)
1523 #define b1s4_imm(x) (((x) >> 1) & 0xf)
1524 #define b1s9_imm(x) (((x) >> 1) & 0x1ff)
1525 #define b2s3_cc(x) (((x) >> 2) & 0x7)
1526 #define b4s2_regl(x) (((x) >> 4) & 0x3)
1527 #define b5s5_op(x) (((x) >> 5) & 0x1f)
1528 #define b5s5_reg(x) (((x) >> 5) & 0x1f)
1529 #define b6s4_op(x) (((x) >> 6) & 0xf)
1530 #define b7s3_reg(x) (((x) >> 7) & 0x7)
1532 /* 32-bit instruction formats, B and S refer to the lowest bit and the size
1533 respectively of the field extracted. */
1534 #define b0s6_op(x) ((x) & 0x3f)
1535 #define b0s11_op(x) ((x) & 0x7ff)
1536 #define b0s12_imm(x) ((x) & 0xfff)
1537 #define b0s16_imm(x) ((x) & 0xffff)
1538 #define b0s26_imm(x) ((x) & 0x3ffffff)
1539 #define b6s10_ext(x) (((x) >> 6) & 0x3ff)
1540 #define b11s5_reg(x) (((x) >> 11) & 0x1f)
1541 #define b12s4_op(x) (((x) >> 12) & 0xf)
1543 /* Return the size in bytes of the instruction INSN encoded in the ISA
1547 mips_insn_size (enum mips_isa isa
, ULONGEST insn
)
1552 if ((micromips_op (insn
) & 0x4) == 0x4
1553 || (micromips_op (insn
) & 0x7) == 0x0)
1554 return 2 * MIPS_INSN16_SIZE
;
1556 return MIPS_INSN16_SIZE
;
1558 if ((insn
& 0xf800) == 0xf000)
1559 return 2 * MIPS_INSN16_SIZE
;
1561 return MIPS_INSN16_SIZE
;
1563 return MIPS_INSN32_SIZE
;
1565 internal_error (_("invalid ISA"));
1569 mips32_relative_offset (ULONGEST inst
)
1571 return ((itype_immediate (inst
) ^ 0x8000) - 0x8000) << 2;
1574 /* Determine the address of the next instruction executed after the INST
1575 floating condition branch instruction at PC. COUNT specifies the
1576 number of the floating condition bits tested by the branch. */
1579 mips32_bc1_pc (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1580 ULONGEST inst
, CORE_ADDR pc
, int count
)
1582 int fcsr
= mips_regnum (gdbarch
)->fp_control_status
;
1583 int cnum
= (itype_rt (inst
) >> 2) & (count
- 1);
1584 int tf
= itype_rt (inst
) & 1;
1585 int mask
= (1 << count
) - 1;
1590 /* No way to handle; it'll most likely trap anyway. */
1593 fcs
= regcache_raw_get_unsigned (regcache
, fcsr
);
1594 cond
= ((fcs
>> 24) & 0xfe) | ((fcs
>> 23) & 0x01);
1596 if (((cond
>> cnum
) & mask
) != mask
* !tf
)
1597 pc
+= mips32_relative_offset (inst
);
1604 /* Return nonzero if the gdbarch is an Octeon series. */
1607 is_octeon (struct gdbarch
*gdbarch
)
1609 const struct bfd_arch_info
*info
= gdbarch_bfd_arch_info (gdbarch
);
1611 return (info
->mach
== bfd_mach_mips_octeon
1612 || info
->mach
== bfd_mach_mips_octeonp
1613 || info
->mach
== bfd_mach_mips_octeon2
);
1616 /* Return true if the OP represents the Octeon's BBIT instruction. */
1619 is_octeon_bbit_op (int op
, struct gdbarch
*gdbarch
)
1621 if (!is_octeon (gdbarch
))
1623 /* BBIT0 is encoded as LWC2: 110 010. */
1624 /* BBIT032 is encoded as LDC2: 110 110. */
1625 /* BBIT1 is encoded as SWC2: 111 010. */
1626 /* BBIT132 is encoded as SDC2: 111 110. */
1627 if (op
== 50 || op
== 54 || op
== 58 || op
== 62)
1633 /* Determine where to set a single step breakpoint while considering
1634 branch prediction. */
1637 mips32_next_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1639 struct gdbarch
*gdbarch
= regcache
->arch ();
1642 inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, pc
, NULL
);
1643 op
= itype_op (inst
);
1644 if ((inst
& 0xe0000000) != 0) /* Not a special, jump or branch
1648 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1659 goto greater_branch
;
1664 else if (op
== 17 && itype_rs (inst
) == 8)
1665 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1666 pc
= mips32_bc1_pc (gdbarch
, regcache
, inst
, pc
+ 4, 1);
1667 else if (op
== 17 && itype_rs (inst
) == 9
1668 && (itype_rt (inst
) & 2) == 0)
1669 /* BC1ANY2F, BC1ANY2T: 010001 01001 xxx0x */
1670 pc
= mips32_bc1_pc (gdbarch
, regcache
, inst
, pc
+ 4, 2);
1671 else if (op
== 17 && itype_rs (inst
) == 10
1672 && (itype_rt (inst
) & 2) == 0)
1673 /* BC1ANY4F, BC1ANY4T: 010001 01010 xxx0x */
1674 pc
= mips32_bc1_pc (gdbarch
, regcache
, inst
, pc
+ 4, 4);
1677 /* The new PC will be alternate mode. */
1681 reg
= jtype_target (inst
) << 2;
1682 /* Add 1 to indicate 16-bit mode -- invert ISA mode. */
1683 pc
= ((pc
+ 4) & ~(CORE_ADDR
) 0x0fffffff) + reg
+ 1;
1685 else if (is_octeon_bbit_op (op
, gdbarch
))
1689 branch_if
= op
== 58 || op
== 62;
1690 bit
= itype_rt (inst
);
1692 /* Take into account the *32 instructions. */
1693 if (op
== 54 || op
== 62)
1696 if (((regcache_raw_get_signed (regcache
,
1697 itype_rs (inst
)) >> bit
) & 1)
1699 pc
+= mips32_relative_offset (inst
) + 4;
1701 pc
+= 8; /* After the delay slot. */
1705 pc
+= 4; /* Not a branch, next instruction is easy. */
1708 { /* This gets way messy. */
1710 /* Further subdivide into SPECIAL, REGIMM and other. */
1711 switch (op
& 0x07) /* Extract bits 28,27,26. */
1713 case 0: /* SPECIAL */
1714 op
= rtype_funct (inst
);
1719 /* Set PC to that address. */
1720 pc
= regcache_raw_get_signed (regcache
, rtype_rs (inst
));
1722 case 12: /* SYSCALL */
1724 mips_gdbarch_tdep
*tdep
1725 = gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
1727 if (tdep
->syscall_next_pc
!= NULL
)
1728 pc
= tdep
->syscall_next_pc (get_current_frame ());
1737 break; /* end SPECIAL */
1738 case 1: /* REGIMM */
1740 op
= itype_rt (inst
); /* branch condition */
1745 case 16: /* BLTZAL */
1746 case 18: /* BLTZALL */
1748 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) < 0)
1749 pc
+= mips32_relative_offset (inst
) + 4;
1751 pc
+= 8; /* after the delay slot */
1755 case 17: /* BGEZAL */
1756 case 19: /* BGEZALL */
1757 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) >= 0)
1758 pc
+= mips32_relative_offset (inst
) + 4;
1760 pc
+= 8; /* after the delay slot */
1762 case 0x1c: /* BPOSGE32 */
1763 case 0x1e: /* BPOSGE64 */
1765 if (itype_rs (inst
) == 0)
1767 unsigned int pos
= (op
& 2) ? 64 : 32;
1768 int dspctl
= mips_regnum (gdbarch
)->dspctl
;
1771 /* No way to handle; it'll most likely trap anyway. */
1774 if ((regcache_raw_get_unsigned (regcache
,
1775 dspctl
) & 0x7f) >= pos
)
1776 pc
+= mips32_relative_offset (inst
);
1781 /* All of the other instructions in the REGIMM category */
1786 break; /* end REGIMM */
1791 reg
= jtype_target (inst
) << 2;
1792 /* Upper four bits get never changed... */
1793 pc
= reg
+ ((pc
+ 4) & ~(CORE_ADDR
) 0x0fffffff);
1796 case 4: /* BEQ, BEQL */
1798 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) ==
1799 regcache_raw_get_signed (regcache
, itype_rt (inst
)))
1800 pc
+= mips32_relative_offset (inst
) + 4;
1804 case 5: /* BNE, BNEL */
1806 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) !=
1807 regcache_raw_get_signed (regcache
, itype_rt (inst
)))
1808 pc
+= mips32_relative_offset (inst
) + 4;
1812 case 6: /* BLEZ, BLEZL */
1813 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) <= 0)
1814 pc
+= mips32_relative_offset (inst
) + 4;
1820 greater_branch
: /* BGTZ, BGTZL */
1821 if (regcache_raw_get_signed (regcache
, itype_rs (inst
)) > 0)
1822 pc
+= mips32_relative_offset (inst
) + 4;
1829 } /* mips32_next_pc */
1831 /* Extract the 7-bit signed immediate offset from the microMIPS instruction
1835 micromips_relative_offset7 (ULONGEST insn
)
1837 return ((b0s7_imm (insn
) ^ 0x40) - 0x40) << 1;
1840 /* Extract the 10-bit signed immediate offset from the microMIPS instruction
1844 micromips_relative_offset10 (ULONGEST insn
)
1846 return ((b0s10_imm (insn
) ^ 0x200) - 0x200) << 1;
1849 /* Extract the 16-bit signed immediate offset from the microMIPS instruction
1853 micromips_relative_offset16 (ULONGEST insn
)
1855 return ((b0s16_imm (insn
) ^ 0x8000) - 0x8000) << 1;
1858 /* Return the size in bytes of the microMIPS instruction at the address PC. */
1861 micromips_pc_insn_size (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1865 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, NULL
);
1866 return mips_insn_size (ISA_MICROMIPS
, insn
);
1869 /* Calculate the address of the next microMIPS instruction to execute
1870 after the INSN coprocessor 1 conditional branch instruction at the
1871 address PC. COUNT denotes the number of coprocessor condition bits
1872 examined by the branch. */
1875 micromips_bc1_pc (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1876 ULONGEST insn
, CORE_ADDR pc
, int count
)
1878 int fcsr
= mips_regnum (gdbarch
)->fp_control_status
;
1879 int cnum
= b2s3_cc (insn
>> 16) & (count
- 1);
1880 int tf
= b5s5_op (insn
>> 16) & 1;
1881 int mask
= (1 << count
) - 1;
1886 /* No way to handle; it'll most likely trap anyway. */
1889 fcs
= regcache_raw_get_unsigned (regcache
, fcsr
);
1890 cond
= ((fcs
>> 24) & 0xfe) | ((fcs
>> 23) & 0x01);
1892 if (((cond
>> cnum
) & mask
) != mask
* !tf
)
1893 pc
+= micromips_relative_offset16 (insn
);
1895 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
1900 /* Calculate the address of the next microMIPS instruction to execute
1901 after the instruction at the address PC. */
1904 micromips_next_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1906 struct gdbarch
*gdbarch
= regcache
->arch ();
1909 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, NULL
);
1910 pc
+= MIPS_INSN16_SIZE
;
1911 switch (mips_insn_size (ISA_MICROMIPS
, insn
))
1913 /* 32-bit instructions. */
1914 case 2 * MIPS_INSN16_SIZE
:
1916 insn
|= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, NULL
);
1917 pc
+= MIPS_INSN16_SIZE
;
1918 switch (micromips_op (insn
>> 16))
1920 case 0x00: /* POOL32A: bits 000000 */
1921 switch (b0s6_op (insn
))
1923 case 0x3c: /* POOL32Axf: bits 000000 ... 111100 */
1924 switch (b6s10_ext (insn
))
1926 case 0x3c: /* JALR: 000000 0000111100 111100 */
1927 case 0x7c: /* JALR.HB: 000000 0001111100 111100 */
1928 case 0x13c: /* JALRS: 000000 0100111100 111100 */
1929 case 0x17c: /* JALRS.HB: 000000 0101111100 111100 */
1930 pc
= regcache_raw_get_signed (regcache
,
1931 b0s5_reg (insn
>> 16));
1933 case 0x22d: /* SYSCALL: 000000 1000101101 111100 */
1935 mips_gdbarch_tdep
*tdep
1936 = gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
1938 if (tdep
->syscall_next_pc
!= NULL
)
1939 pc
= tdep
->syscall_next_pc (get_current_frame ());
1947 case 0x10: /* POOL32I: bits 010000 */
1948 switch (b5s5_op (insn
>> 16))
1950 case 0x00: /* BLTZ: bits 010000 00000 */
1951 case 0x01: /* BLTZAL: bits 010000 00001 */
1952 case 0x11: /* BLTZALS: bits 010000 10001 */
1953 if (regcache_raw_get_signed (regcache
,
1954 b0s5_reg (insn
>> 16)) < 0)
1955 pc
+= micromips_relative_offset16 (insn
);
1957 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
1960 case 0x02: /* BGEZ: bits 010000 00010 */
1961 case 0x03: /* BGEZAL: bits 010000 00011 */
1962 case 0x13: /* BGEZALS: bits 010000 10011 */
1963 if (regcache_raw_get_signed (regcache
,
1964 b0s5_reg (insn
>> 16)) >= 0)
1965 pc
+= micromips_relative_offset16 (insn
);
1967 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
1970 case 0x04: /* BLEZ: bits 010000 00100 */
1971 if (regcache_raw_get_signed (regcache
,
1972 b0s5_reg (insn
>> 16)) <= 0)
1973 pc
+= micromips_relative_offset16 (insn
);
1975 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
1978 case 0x05: /* BNEZC: bits 010000 00101 */
1979 if (regcache_raw_get_signed (regcache
,
1980 b0s5_reg (insn
>> 16)) != 0)
1981 pc
+= micromips_relative_offset16 (insn
);
1984 case 0x06: /* BGTZ: bits 010000 00110 */
1985 if (regcache_raw_get_signed (regcache
,
1986 b0s5_reg (insn
>> 16)) > 0)
1987 pc
+= micromips_relative_offset16 (insn
);
1989 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
1992 case 0x07: /* BEQZC: bits 010000 00111 */
1993 if (regcache_raw_get_signed (regcache
,
1994 b0s5_reg (insn
>> 16)) == 0)
1995 pc
+= micromips_relative_offset16 (insn
);
1998 case 0x14: /* BC2F: bits 010000 10100 xxx00 */
1999 case 0x15: /* BC2T: bits 010000 10101 xxx00 */
2000 if (((insn
>> 16) & 0x3) == 0x0)
2001 /* BC2F, BC2T: don't know how to handle these. */
2005 case 0x1a: /* BPOSGE64: bits 010000 11010 */
2006 case 0x1b: /* BPOSGE32: bits 010000 11011 */
2008 unsigned int pos
= (b5s5_op (insn
>> 16) & 1) ? 32 : 64;
2009 int dspctl
= mips_regnum (gdbarch
)->dspctl
;
2012 /* No way to handle; it'll most likely trap anyway. */
2015 if ((regcache_raw_get_unsigned (regcache
,
2016 dspctl
) & 0x7f) >= pos
)
2017 pc
+= micromips_relative_offset16 (insn
);
2019 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
2023 case 0x1c: /* BC1F: bits 010000 11100 xxx00 */
2024 /* BC1ANY2F: bits 010000 11100 xxx01 */
2025 case 0x1d: /* BC1T: bits 010000 11101 xxx00 */
2026 /* BC1ANY2T: bits 010000 11101 xxx01 */
2027 if (((insn
>> 16) & 0x2) == 0x0)
2028 pc
= micromips_bc1_pc (gdbarch
, regcache
, insn
, pc
,
2029 ((insn
>> 16) & 0x1) + 1);
2032 case 0x1e: /* BC1ANY4F: bits 010000 11110 xxx01 */
2033 case 0x1f: /* BC1ANY4T: bits 010000 11111 xxx01 */
2034 if (((insn
>> 16) & 0x3) == 0x1)
2035 pc
= micromips_bc1_pc (gdbarch
, regcache
, insn
, pc
, 4);
2040 case 0x1d: /* JALS: bits 011101 */
2041 case 0x35: /* J: bits 110101 */
2042 case 0x3d: /* JAL: bits 111101 */
2043 pc
= ((pc
| 0x7fffffe) ^ 0x7fffffe) | (b0s26_imm (insn
) << 1);
2046 case 0x25: /* BEQ: bits 100101 */
2047 if (regcache_raw_get_signed (regcache
, b0s5_reg (insn
>> 16))
2048 == regcache_raw_get_signed (regcache
, b5s5_reg (insn
>> 16)))
2049 pc
+= micromips_relative_offset16 (insn
);
2051 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
2054 case 0x2d: /* BNE: bits 101101 */
2055 if (regcache_raw_get_signed (regcache
, b0s5_reg (insn
>> 16))
2056 != regcache_raw_get_signed (regcache
, b5s5_reg (insn
>> 16)))
2057 pc
+= micromips_relative_offset16 (insn
);
2059 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
2062 case 0x3c: /* JALX: bits 111100 */
2063 pc
= ((pc
| 0xfffffff) ^ 0xfffffff) | (b0s26_imm (insn
) << 2);
2068 /* 16-bit instructions. */
2069 case MIPS_INSN16_SIZE
:
2070 switch (micromips_op (insn
))
2072 case 0x11: /* POOL16C: bits 010001 */
2073 if ((b5s5_op (insn
) & 0x1c) == 0xc)
2074 /* JR16, JRC, JALR16, JALRS16: 010001 011xx */
2075 pc
= regcache_raw_get_signed (regcache
, b0s5_reg (insn
));
2076 else if (b5s5_op (insn
) == 0x18)
2077 /* JRADDIUSP: bits 010001 11000 */
2078 pc
= regcache_raw_get_signed (regcache
, MIPS_RA_REGNUM
);
2081 case 0x23: /* BEQZ16: bits 100011 */
2083 int rs
= mips_reg3_to_reg
[b7s3_reg (insn
)];
2085 if (regcache_raw_get_signed (regcache
, rs
) == 0)
2086 pc
+= micromips_relative_offset7 (insn
);
2088 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
2092 case 0x2b: /* BNEZ16: bits 101011 */
2094 int rs
= mips_reg3_to_reg
[b7s3_reg (insn
)];
2096 if (regcache_raw_get_signed (regcache
, rs
) != 0)
2097 pc
+= micromips_relative_offset7 (insn
);
2099 pc
+= micromips_pc_insn_size (gdbarch
, pc
);
2103 case 0x33: /* B16: bits 110011 */
2104 pc
+= micromips_relative_offset10 (insn
);
2113 /* Decoding the next place to set a breakpoint is irregular for the
2114 mips 16 variant, but fortunately, there fewer instructions. We have
2115 to cope ith extensions for 16 bit instructions and a pair of actual
2116 32 bit instructions. We dont want to set a single step instruction
2117 on the extend instruction either. */
2119 /* Lots of mips16 instruction formats */
2120 /* Predicting jumps requires itype,ritype,i8type
2121 and their extensions extItype,extritype,extI8type. */
2122 enum mips16_inst_fmts
2124 itype
, /* 0 immediate 5,10 */
2125 ritype
, /* 1 5,3,8 */
2126 rrtype
, /* 2 5,3,3,5 */
2127 rritype
, /* 3 5,3,3,5 */
2128 rrrtype
, /* 4 5,3,3,3,2 */
2129 rriatype
, /* 5 5,3,3,1,4 */
2130 shifttype
, /* 6 5,3,3,3,2 */
2131 i8type
, /* 7 5,3,8 */
2132 i8movtype
, /* 8 5,3,3,5 */
2133 i8mov32rtype
, /* 9 5,3,5,3 */
2134 i64type
, /* 10 5,3,8 */
2135 ri64type
, /* 11 5,3,3,5 */
2136 jalxtype
, /* 12 5,1,5,5,16 - a 32 bit instruction */
2137 exiItype
, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
2138 extRitype
, /* 14 5,6,5,5,3,1,1,1,5 */
2139 extRRItype
, /* 15 5,5,5,5,3,3,5 */
2140 extRRIAtype
, /* 16 5,7,4,5,3,3,1,4 */
2141 EXTshifttype
, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
2142 extI8type
, /* 18 5,6,5,5,3,1,1,1,5 */
2143 extI64type
, /* 19 5,6,5,5,3,1,1,1,5 */
2144 extRi64type
, /* 20 5,6,5,5,3,3,5 */
2145 extshift64type
/* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
2147 /* I am heaping all the fields of the formats into one structure and
2148 then, only the fields which are involved in instruction extension. */
2152 unsigned int regx
; /* Function in i8 type. */
2157 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
2158 for the bits which make up the immediate extension. */
2161 extended_offset (unsigned int extension
)
2165 value
= (extension
>> 16) & 0x1f; /* Extract 15:11. */
2167 value
|= (extension
>> 21) & 0x3f; /* Extract 10:5. */
2169 value
|= extension
& 0x1f; /* Extract 4:0. */
2174 /* Only call this function if you know that this is an extendable
2175 instruction. It won't malfunction, but why make excess remote memory
2176 references? If the immediate operands get sign extended or something,
2177 do it after the extension is performed. */
2178 /* FIXME: Every one of these cases needs to worry about sign extension
2179 when the offset is to be used in relative addressing. */
2182 fetch_mips_16 (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2184 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2187 pc
= unmake_compact_addr (pc
); /* Clear the low order bit. */
2188 target_read_memory (pc
, buf
, 2);
2189 return extract_unsigned_integer (buf
, 2, byte_order
);
2193 unpack_mips16 (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
2194 unsigned int extension
,
2196 enum mips16_inst_fmts insn_format
, struct upk_mips16
*upk
)
2201 switch (insn_format
)
2208 value
= extended_offset ((extension
<< 16) | inst
);
2209 value
= (value
^ 0x8000) - 0x8000; /* Sign-extend. */
2213 value
= inst
& 0x7ff;
2214 value
= (value
^ 0x400) - 0x400; /* Sign-extend. */
2223 { /* A register identifier and an offset. */
2224 /* Most of the fields are the same as I type but the
2225 immediate value is of a different length. */
2229 value
= extended_offset ((extension
<< 16) | inst
);
2230 value
= (value
^ 0x8000) - 0x8000; /* Sign-extend. */
2234 value
= inst
& 0xff; /* 8 bits */
2235 value
= (value
^ 0x80) - 0x80; /* Sign-extend. */
2238 regx
= (inst
>> 8) & 0x07; /* i8 funct */
2244 unsigned long value
;
2245 unsigned int nexthalf
;
2246 value
= ((inst
& 0x1f) << 5) | ((inst
>> 5) & 0x1f);
2247 value
= value
<< 16;
2248 nexthalf
= mips_fetch_instruction (gdbarch
, ISA_MIPS16
, pc
+ 2, NULL
);
2249 /* Low bit still set. */
2257 internal_error (_("bad switch"));
2259 upk
->offset
= offset
;
2265 /* Calculate the destination of a branch whose 16-bit opcode word is at PC,
2266 and having a signed 16-bit OFFSET. */
2269 add_offset_16 (CORE_ADDR pc
, int offset
)
2271 return pc
+ (offset
<< 1) + 2;
2275 extended_mips16_next_pc (regcache
*regcache
, CORE_ADDR pc
,
2276 unsigned int extension
, unsigned int insn
)
2278 struct gdbarch
*gdbarch
= regcache
->arch ();
2279 int op
= (insn
>> 11);
2282 case 2: /* Branch */
2284 struct upk_mips16 upk
;
2285 unpack_mips16 (gdbarch
, pc
, extension
, insn
, itype
, &upk
);
2286 pc
= add_offset_16 (pc
, upk
.offset
);
2289 case 3: /* JAL , JALX - Watch out, these are 32 bit
2292 struct upk_mips16 upk
;
2293 unpack_mips16 (gdbarch
, pc
, extension
, insn
, jalxtype
, &upk
);
2294 pc
= ((pc
+ 2) & (~(CORE_ADDR
) 0x0fffffff)) | (upk
.offset
<< 2);
2295 if ((insn
>> 10) & 0x01) /* Exchange mode */
2296 pc
= pc
& ~0x01; /* Clear low bit, indicate 32 bit mode. */
2303 struct upk_mips16 upk
;
2305 unpack_mips16 (gdbarch
, pc
, extension
, insn
, ritype
, &upk
);
2306 reg
= regcache_raw_get_signed (regcache
, mips_reg3_to_reg
[upk
.regx
]);
2308 pc
= add_offset_16 (pc
, upk
.offset
);
2315 struct upk_mips16 upk
;
2317 unpack_mips16 (gdbarch
, pc
, extension
, insn
, ritype
, &upk
);
2318 reg
= regcache_raw_get_signed (regcache
, mips_reg3_to_reg
[upk
.regx
]);
2320 pc
= add_offset_16 (pc
, upk
.offset
);
2325 case 12: /* I8 Formats btez btnez */
2327 struct upk_mips16 upk
;
2329 unpack_mips16 (gdbarch
, pc
, extension
, insn
, i8type
, &upk
);
2330 /* upk.regx contains the opcode */
2331 /* Test register is 24 */
2332 reg
= regcache_raw_get_signed (regcache
, 24);
2333 if (((upk
.regx
== 0) && (reg
== 0)) /* BTEZ */
2334 || ((upk
.regx
== 1) && (reg
!= 0))) /* BTNEZ */
2335 pc
= add_offset_16 (pc
, upk
.offset
);
2340 case 29: /* RR Formats JR, JALR, JALR-RA */
2342 struct upk_mips16 upk
;
2343 /* upk.fmt = rrtype; */
2348 upk
.regx
= (insn
>> 8) & 0x07;
2349 upk
.regy
= (insn
>> 5) & 0x07;
2350 if ((upk
.regy
& 1) == 0)
2351 reg
= mips_reg3_to_reg
[upk
.regx
];
2353 reg
= 31; /* Function return instruction. */
2354 pc
= regcache_raw_get_signed (regcache
, reg
);
2361 /* This is an instruction extension. Fetch the real instruction
2362 (which follows the extension) and decode things based on
2366 pc
= extended_mips16_next_pc (regcache
, pc
, insn
,
2367 fetch_mips_16 (gdbarch
, pc
));
2380 mips16_next_pc (struct regcache
*regcache
, CORE_ADDR pc
)
2382 struct gdbarch
*gdbarch
= regcache
->arch ();
2383 unsigned int insn
= fetch_mips_16 (gdbarch
, pc
);
2384 return extended_mips16_next_pc (regcache
, pc
, 0, insn
);
2387 /* The mips_next_pc function supports single_step when the remote
2388 target monitor or stub is not developed enough to do a single_step.
2389 It works by decoding the current instruction and predicting where a
2390 branch will go. This isn't hard because all the data is available.
2391 The MIPS32, MIPS16 and microMIPS variants are quite different. */
2393 mips_next_pc (struct regcache
*regcache
, CORE_ADDR pc
)
2395 struct gdbarch
*gdbarch
= regcache
->arch ();
2397 if (mips_pc_is_mips16 (gdbarch
, pc
))
2398 return mips16_next_pc (regcache
, pc
);
2399 else if (mips_pc_is_micromips (gdbarch
, pc
))
2400 return micromips_next_pc (regcache
, pc
);
2402 return mips32_next_pc (regcache
, pc
);
2405 /* Return non-zero if the MIPS16 instruction INSN is a compact branch
2409 mips16_instruction_is_compact_branch (unsigned short insn
)
2411 switch (insn
& 0xf800)
2414 return (insn
& 0x009f) == 0x80; /* JALRC/JRC */
2416 return (insn
& 0x0600) == 0; /* BTNEZ/BTEQZ */
2417 case 0x2800: /* BNEZ */
2418 case 0x2000: /* BEQZ */
2419 case 0x1000: /* B */
2426 /* Return non-zero if the microMIPS instruction INSN is a compact branch
2430 micromips_instruction_is_compact_branch (unsigned short insn
)
2432 switch (micromips_op (insn
))
2434 case 0x11: /* POOL16C: bits 010001 */
2435 return (b5s5_op (insn
) == 0x18
2436 /* JRADDIUSP: bits 010001 11000 */
2437 || b5s5_op (insn
) == 0xd);
2438 /* JRC: bits 010011 01101 */
2439 case 0x10: /* POOL32I: bits 010000 */
2440 return (b5s5_op (insn
) & 0x1d) == 0x5;
2441 /* BEQZC/BNEZC: bits 010000 001x1 */
2447 struct mips_frame_cache
2450 trad_frame_saved_reg
*saved_regs
;
2453 /* Set a register's saved stack address in temp_saved_regs. If an
2454 address has already been set for this register, do nothing; this
2455 way we will only recognize the first save of a given register in a
2458 For simplicity, save the address in both [0 .. gdbarch_num_regs) and
2459 [gdbarch_num_regs .. 2*gdbarch_num_regs).
2460 Strictly speaking, only the second range is used as it is only second
2461 range (the ABI instead of ISA registers) that comes into play when finding
2462 saved registers in a frame. */
2465 set_reg_offset (struct gdbarch
*gdbarch
, struct mips_frame_cache
*this_cache
,
2466 int regnum
, CORE_ADDR offset
)
2468 if (this_cache
!= NULL
2469 && this_cache
->saved_regs
[regnum
].is_realreg ()
2470 && this_cache
->saved_regs
[regnum
].realreg () == regnum
)
2472 this_cache
->saved_regs
[regnum
+ 0
2473 * gdbarch_num_regs (gdbarch
)].set_addr (offset
);
2474 this_cache
->saved_regs
[regnum
+ 1
2475 * gdbarch_num_regs (gdbarch
)].set_addr (offset
);
2480 /* Fetch the immediate value from a MIPS16 instruction.
2481 If the previous instruction was an EXTEND, use it to extend
2482 the upper bits of the immediate value. This is a helper function
2483 for mips16_scan_prologue. */
2486 mips16_get_imm (unsigned short prev_inst
, /* previous instruction */
2487 unsigned short inst
, /* current instruction */
2488 int nbits
, /* number of bits in imm field */
2489 int scale
, /* scale factor to be applied to imm */
2490 int is_signed
) /* is the imm field signed? */
2494 if ((prev_inst
& 0xf800) == 0xf000) /* prev instruction was EXTEND? */
2496 offset
= ((prev_inst
& 0x1f) << 11) | (prev_inst
& 0x7e0);
2497 if (offset
& 0x8000) /* check for negative extend */
2498 offset
= 0 - (0x10000 - (offset
& 0xffff));
2499 return offset
| (inst
& 0x1f);
2503 int max_imm
= 1 << nbits
;
2504 int mask
= max_imm
- 1;
2505 int sign_bit
= max_imm
>> 1;
2507 offset
= inst
& mask
;
2508 if (is_signed
&& (offset
& sign_bit
))
2509 offset
= 0 - (max_imm
- offset
);
2510 return offset
* scale
;
2515 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
2516 the associated FRAME_CACHE if not null.
2517 Return the address of the first instruction past the prologue. */
2520 mips16_scan_prologue (struct gdbarch
*gdbarch
,
2521 CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2522 frame_info_ptr this_frame
,
2523 struct mips_frame_cache
*this_cache
)
2525 int prev_non_prologue_insn
= 0;
2526 int this_non_prologue_insn
;
2527 int non_prologue_insns
= 0;
2530 CORE_ADDR frame_addr
= 0; /* Value of $r17, used as frame pointer. */
2532 long frame_offset
= 0; /* Size of stack frame. */
2533 long frame_adjust
= 0; /* Offset of FP from SP. */
2534 int frame_reg
= MIPS_SP_REGNUM
;
2535 unsigned short prev_inst
= 0; /* saved copy of previous instruction. */
2536 unsigned inst
= 0; /* current instruction */
2537 unsigned entry_inst
= 0; /* the entry instruction */
2538 unsigned save_inst
= 0; /* the save instruction */
2539 int prev_delay_slot
= 0;
2543 int extend_bytes
= 0;
2544 int prev_extend_bytes
= 0;
2545 CORE_ADDR end_prologue_addr
;
2547 /* Can be called when there's no process, and hence when there's no
2549 if (this_frame
!= NULL
)
2550 sp
= get_frame_register_signed (this_frame
,
2551 gdbarch_num_regs (gdbarch
)
2556 if (limit_pc
> start_pc
+ 200)
2557 limit_pc
= start_pc
+ 200;
2560 /* Permit at most one non-prologue non-control-transfer instruction
2561 in the middle which may have been reordered by the compiler for
2563 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS_INSN16_SIZE
)
2565 this_non_prologue_insn
= 0;
2568 /* Save the previous instruction. If it's an EXTEND, we'll extract
2569 the immediate offset extension from it in mips16_get_imm. */
2572 /* Fetch and decode the instruction. */
2573 inst
= (unsigned short) mips_fetch_instruction (gdbarch
, ISA_MIPS16
,
2576 /* Normally we ignore extend instructions. However, if it is
2577 not followed by a valid prologue instruction, then this
2578 instruction is not part of the prologue either. We must
2579 remember in this case to adjust the end_prologue_addr back
2581 if ((inst
& 0xf800) == 0xf000) /* extend */
2583 extend_bytes
= MIPS_INSN16_SIZE
;
2587 prev_extend_bytes
= extend_bytes
;
2590 if ((inst
& 0xff00) == 0x6300 /* addiu sp */
2591 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
2593 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 1);
2594 if (offset
< 0) /* Negative stack adjustment? */
2595 frame_offset
-= offset
;
2597 /* Exit loop if a positive stack adjustment is found, which
2598 usually means that the stack cleanup code in the function
2599 epilogue is reached. */
2602 else if ((inst
& 0xf800) == 0xd000) /* sw reg,n($sp) */
2604 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2605 reg
= mips_reg3_to_reg
[(inst
& 0x700) >> 8];
2606 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2608 else if ((inst
& 0xff00) == 0xf900) /* sd reg,n($sp) */
2610 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
2611 reg
= mips_reg3_to_reg
[(inst
& 0xe0) >> 5];
2612 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2614 else if ((inst
& 0xff00) == 0x6200) /* sw $ra,n($sp) */
2616 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2617 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
2619 else if ((inst
& 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2621 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 0);
2622 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
2624 else if (inst
== 0x673d) /* move $s1, $sp */
2629 else if ((inst
& 0xff00) == 0x0100) /* addiu $s1,sp,n */
2631 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2632 frame_addr
= sp
+ offset
;
2634 frame_adjust
= offset
;
2636 else if ((inst
& 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2638 offset
= mips16_get_imm (prev_inst
, inst
, 5, 4, 0);
2639 reg
= mips_reg3_to_reg
[(inst
& 0xe0) >> 5];
2640 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ offset
);
2642 else if ((inst
& 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2644 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
2645 reg
= mips_reg3_to_reg
[(inst
& 0xe0) >> 5];
2646 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ offset
);
2648 else if ((inst
& 0xf81f) == 0xe809
2649 && (inst
& 0x700) != 0x700) /* entry */
2650 entry_inst
= inst
; /* Save for later processing. */
2651 else if ((inst
& 0xff80) == 0x6480) /* save */
2653 save_inst
= inst
; /* Save for later processing. */
2654 if (prev_extend_bytes
) /* extend */
2655 save_inst
|= prev_inst
<< 16;
2657 else if ((inst
& 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
2659 /* This instruction is part of the prologue, but we don't
2660 need to do anything special to handle it. */
2662 else if (mips16_instruction_has_delay_slot (inst
, 0))
2663 /* JAL/JALR/JALX/JR */
2665 /* The instruction in the delay slot can be a part
2666 of the prologue, so move forward once more. */
2668 if (mips16_instruction_has_delay_slot (inst
, 1))
2671 prev_extend_bytes
= MIPS_INSN16_SIZE
;
2672 cur_pc
+= MIPS_INSN16_SIZE
; /* 32-bit instruction */
2677 this_non_prologue_insn
= 1;
2680 non_prologue_insns
+= this_non_prologue_insn
;
2682 /* A jump or branch, or enough non-prologue insns seen? If so,
2683 then we must have reached the end of the prologue by now. */
2684 if (prev_delay_slot
|| non_prologue_insns
> 1
2685 || mips16_instruction_is_compact_branch (inst
))
2688 prev_non_prologue_insn
= this_non_prologue_insn
;
2689 prev_delay_slot
= in_delay_slot
;
2690 prev_pc
= cur_pc
- prev_extend_bytes
;
2693 /* The entry instruction is typically the first instruction in a function,
2694 and it stores registers at offsets relative to the value of the old SP
2695 (before the prologue). But the value of the sp parameter to this
2696 function is the new SP (after the prologue has been executed). So we
2697 can't calculate those offsets until we've seen the entire prologue,
2698 and can calculate what the old SP must have been. */
2699 if (entry_inst
!= 0)
2701 int areg_count
= (entry_inst
>> 8) & 7;
2702 int sreg_count
= (entry_inst
>> 6) & 3;
2704 /* The entry instruction always subtracts 32 from the SP. */
2707 /* Now we can calculate what the SP must have been at the
2708 start of the function prologue. */
2711 /* Check if a0-a3 were saved in the caller's argument save area. */
2712 for (reg
= 4, offset
= 0; reg
< areg_count
+ 4; reg
++)
2714 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2715 offset
+= mips_abi_regsize (gdbarch
);
2718 /* Check if the ra register was pushed on the stack. */
2720 if (entry_inst
& 0x20)
2722 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
2723 offset
-= mips_abi_regsize (gdbarch
);
2726 /* Check if the s0 and s1 registers were pushed on the stack. */
2727 for (reg
= 16; reg
< sreg_count
+ 16; reg
++)
2729 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2730 offset
-= mips_abi_regsize (gdbarch
);
2734 /* The SAVE instruction is similar to ENTRY, except that defined by the
2735 MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
2736 size of the frame is specified as an immediate field of instruction
2737 and an extended variation exists which lets additional registers and
2738 frame space to be specified. The instruction always treats registers
2739 as 32-bit so its usefulness for 64-bit ABIs is questionable. */
2740 if (save_inst
!= 0 && mips_abi_regsize (gdbarch
) == 4)
2742 static int args_table
[16] = {
2743 0, 0, 0, 0, 1, 1, 1, 1,
2744 2, 2, 2, 0, 3, 3, 4, -1,
2746 static int astatic_table
[16] = {
2747 0, 1, 2, 3, 0, 1, 2, 3,
2748 0, 1, 2, 4, 0, 1, 0, -1,
2750 int aregs
= (save_inst
>> 16) & 0xf;
2751 int xsregs
= (save_inst
>> 24) & 0x7;
2752 int args
= args_table
[aregs
];
2753 int astatic
= astatic_table
[aregs
];
2758 warning (_("Invalid number of argument registers encoded in SAVE."));
2763 warning (_("Invalid number of static registers encoded in SAVE."));
2767 /* For standard SAVE the frame size of 0 means 128. */
2768 frame_size
= ((save_inst
>> 16) & 0xf0) | (save_inst
& 0xf);
2769 if (frame_size
== 0 && (save_inst
>> 16) == 0)
2772 frame_offset
+= frame_size
;
2774 /* Now we can calculate what the SP must have been at the
2775 start of the function prologue. */
2778 /* Check if A0-A3 were saved in the caller's argument save area. */
2779 for (reg
= MIPS_A0_REGNUM
, offset
= 0; reg
< args
+ 4; reg
++)
2781 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2782 offset
+= mips_abi_regsize (gdbarch
);
2787 /* Check if the RA register was pushed on the stack. */
2788 if (save_inst
& 0x40)
2790 set_reg_offset (gdbarch
, this_cache
, MIPS_RA_REGNUM
, sp
+ offset
);
2791 offset
-= mips_abi_regsize (gdbarch
);
2794 /* Check if the S8 register was pushed on the stack. */
2797 set_reg_offset (gdbarch
, this_cache
, 30, sp
+ offset
);
2798 offset
-= mips_abi_regsize (gdbarch
);
2801 /* Check if S2-S7 were pushed on the stack. */
2802 for (reg
= 18 + xsregs
- 1; reg
> 18 - 1; reg
--)
2804 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2805 offset
-= mips_abi_regsize (gdbarch
);
2808 /* Check if the S1 register was pushed on the stack. */
2809 if (save_inst
& 0x10)
2811 set_reg_offset (gdbarch
, this_cache
, 17, sp
+ offset
);
2812 offset
-= mips_abi_regsize (gdbarch
);
2814 /* Check if the S0 register was pushed on the stack. */
2815 if (save_inst
& 0x20)
2817 set_reg_offset (gdbarch
, this_cache
, 16, sp
+ offset
);
2818 offset
-= mips_abi_regsize (gdbarch
);
2821 /* Check if A0-A3 were pushed on the stack. */
2822 for (reg
= MIPS_A0_REGNUM
+ 3; reg
> MIPS_A0_REGNUM
+ 3 - astatic
; reg
--)
2824 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
2825 offset
-= mips_abi_regsize (gdbarch
);
2829 if (this_cache
!= NULL
)
2832 (get_frame_register_signed (this_frame
,
2833 gdbarch_num_regs (gdbarch
) + frame_reg
)
2834 + frame_offset
- frame_adjust
);
2835 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
2836 be able to get rid of the assignment below, evetually. But it's
2837 still needed for now. */
2838 this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
2839 + mips_regnum (gdbarch
)->pc
]
2840 = this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
) + MIPS_RA_REGNUM
];
2843 /* Set end_prologue_addr to the address of the instruction immediately
2844 after the last one we scanned. Unless the last one looked like a
2845 non-prologue instruction (and we looked ahead), in which case use
2846 its address instead. */
2847 end_prologue_addr
= (prev_non_prologue_insn
|| prev_delay_slot
2848 ? prev_pc
: cur_pc
- prev_extend_bytes
);
2850 return end_prologue_addr
;
2853 /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
2854 Procedures that use the 32-bit instruction set are handled by the
2855 mips_insn32 unwinder. */
2857 static struct mips_frame_cache
*
2858 mips_insn16_frame_cache (frame_info_ptr this_frame
, void **this_cache
)
2860 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2861 struct mips_frame_cache
*cache
;
2863 if ((*this_cache
) != NULL
)
2864 return (struct mips_frame_cache
*) (*this_cache
);
2865 cache
= FRAME_OBSTACK_ZALLOC (struct mips_frame_cache
);
2866 (*this_cache
) = cache
;
2867 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2869 /* Analyze the function prologue. */
2871 const CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
2872 CORE_ADDR start_addr
;
2874 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
2875 if (start_addr
== 0)
2876 start_addr
= heuristic_proc_start (gdbarch
, pc
);
2877 /* We can't analyze the prologue if we couldn't find the begining
2879 if (start_addr
== 0)
2882 mips16_scan_prologue (gdbarch
, start_addr
, pc
, this_frame
,
2883 (struct mips_frame_cache
*) *this_cache
);
2886 /* gdbarch_sp_regnum contains the value and not the address. */
2887 cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
2888 + MIPS_SP_REGNUM
].set_value (cache
->base
);
2890 return (struct mips_frame_cache
*) (*this_cache
);
2894 mips_insn16_frame_this_id (frame_info_ptr this_frame
, void **this_cache
,
2895 struct frame_id
*this_id
)
2897 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
2899 /* This marks the outermost frame. */
2900 if (info
->base
== 0)
2902 (*this_id
) = frame_id_build (info
->base
, get_frame_func (this_frame
));
2905 static struct value
*
2906 mips_insn16_frame_prev_register (frame_info_ptr this_frame
,
2907 void **this_cache
, int regnum
)
2909 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
2911 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
2915 mips_insn16_frame_sniffer (const struct frame_unwind
*self
,
2916 frame_info_ptr this_frame
, void **this_cache
)
2918 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2919 CORE_ADDR pc
= get_frame_pc (this_frame
);
2920 if (mips_pc_is_mips16 (gdbarch
, pc
))
2925 static const struct frame_unwind mips_insn16_frame_unwind
=
2927 "mips insn16 prologue",
2929 default_frame_unwind_stop_reason
,
2930 mips_insn16_frame_this_id
,
2931 mips_insn16_frame_prev_register
,
2933 mips_insn16_frame_sniffer
2937 mips_insn16_frame_base_address (frame_info_ptr this_frame
,
2940 struct mips_frame_cache
*info
= mips_insn16_frame_cache (this_frame
,
2945 static const struct frame_base mips_insn16_frame_base
=
2947 &mips_insn16_frame_unwind
,
2948 mips_insn16_frame_base_address
,
2949 mips_insn16_frame_base_address
,
2950 mips_insn16_frame_base_address
2953 static const struct frame_base
*
2954 mips_insn16_frame_base_sniffer (frame_info_ptr this_frame
)
2956 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2957 CORE_ADDR pc
= get_frame_pc (this_frame
);
2958 if (mips_pc_is_mips16 (gdbarch
, pc
))
2959 return &mips_insn16_frame_base
;
2964 /* Decode a 9-bit signed immediate argument of ADDIUSP -- -2 is mapped
2965 to -258, -1 -- to -257, 0 -- to 256, 1 -- to 257 and other values are
2966 interpreted directly, and then multiplied by 4. */
2969 micromips_decode_imm9 (int imm
)
2971 imm
= (imm
^ 0x100) - 0x100;
2972 if (imm
> -3 && imm
< 2)
2977 /* Analyze the function prologue from START_PC to LIMIT_PC. Return
2978 the address of the first instruction past the prologue. */
2981 micromips_scan_prologue (struct gdbarch
*gdbarch
,
2982 CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2983 frame_info_ptr this_frame
,
2984 struct mips_frame_cache
*this_cache
)
2986 CORE_ADDR end_prologue_addr
;
2987 int prev_non_prologue_insn
= 0;
2988 int frame_reg
= MIPS_SP_REGNUM
;
2989 int this_non_prologue_insn
;
2990 int non_prologue_insns
= 0;
2991 long frame_offset
= 0; /* Size of stack frame. */
2992 long frame_adjust
= 0; /* Offset of FP from SP. */
2993 int prev_delay_slot
= 0;
2997 ULONGEST insn
; /* current instruction */
3001 long v1_off
= 0; /* The assumption is LUI will replace it. */
3012 /* Can be called when there's no process, and hence when there's no
3014 if (this_frame
!= NULL
)
3015 sp
= get_frame_register_signed (this_frame
,
3016 gdbarch_num_regs (gdbarch
)
3021 if (limit_pc
> start_pc
+ 200)
3022 limit_pc
= start_pc
+ 200;
3025 /* Permit at most one non-prologue non-control-transfer instruction
3026 in the middle which may have been reordered by the compiler for
3028 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= loc
)
3030 this_non_prologue_insn
= 0;
3034 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, cur_pc
, NULL
);
3035 loc
+= MIPS_INSN16_SIZE
;
3036 switch (mips_insn_size (ISA_MICROMIPS
, insn
))
3038 /* 32-bit instructions. */
3039 case 2 * MIPS_INSN16_SIZE
:
3041 insn
|= mips_fetch_instruction (gdbarch
,
3042 ISA_MICROMIPS
, cur_pc
+ loc
, NULL
);
3043 loc
+= MIPS_INSN16_SIZE
;
3044 switch (micromips_op (insn
>> 16))
3046 /* Record $sp/$fp adjustment. */
3047 /* Discard (D)ADDU $gp,$jp used for PIC code. */
3048 case 0x0: /* POOL32A: bits 000000 */
3049 case 0x16: /* POOL32S: bits 010110 */
3050 op
= b0s11_op (insn
);
3051 sreg
= b0s5_reg (insn
>> 16);
3052 treg
= b5s5_reg (insn
>> 16);
3053 dreg
= b11s5_reg (insn
);
3055 /* SUBU: bits 000000 00111010000 */
3056 /* DSUBU: bits 010110 00111010000 */
3057 && dreg
== MIPS_SP_REGNUM
&& sreg
== MIPS_SP_REGNUM
3059 /* (D)SUBU $sp, $v1 */
3061 else if (op
!= 0x150
3062 /* ADDU: bits 000000 00101010000 */
3063 /* DADDU: bits 010110 00101010000 */
3064 || dreg
!= 28 || sreg
!= 28 || treg
!= MIPS_T9_REGNUM
)
3065 this_non_prologue_insn
= 1;
3068 case 0x8: /* POOL32B: bits 001000 */
3069 op
= b12s4_op (insn
);
3070 breg
= b0s5_reg (insn
>> 16);
3071 reglist
= sreg
= b5s5_reg (insn
>> 16);
3072 offset
= (b0s12_imm (insn
) ^ 0x800) - 0x800;
3073 if ((op
== 0x9 || op
== 0xc)
3074 /* SWP: bits 001000 1001 */
3075 /* SDP: bits 001000 1100 */
3076 && breg
== MIPS_SP_REGNUM
&& sreg
< MIPS_RA_REGNUM
)
3077 /* S[DW]P reg,offset($sp) */
3079 s
= 4 << ((b12s4_op (insn
) & 0x4) == 0x4);
3080 set_reg_offset (gdbarch
, this_cache
,
3082 set_reg_offset (gdbarch
, this_cache
,
3083 sreg
+ 1, sp
+ offset
+ s
);
3085 else if ((op
== 0xd || op
== 0xf)
3086 /* SWM: bits 001000 1101 */
3087 /* SDM: bits 001000 1111 */
3088 && breg
== MIPS_SP_REGNUM
3089 /* SWM reglist,offset($sp) */
3090 && ((reglist
>= 1 && reglist
<= 9)
3091 || (reglist
>= 16 && reglist
<= 25)))
3093 int sreglist
= std::min(reglist
& 0xf, 8);
3095 s
= 4 << ((b12s4_op (insn
) & 0x2) == 0x2);
3096 for (i
= 0; i
< sreglist
; i
++)
3097 set_reg_offset (gdbarch
, this_cache
, 16 + i
, sp
+ s
* i
);
3098 if ((reglist
& 0xf) > 8)
3099 set_reg_offset (gdbarch
, this_cache
, 30, sp
+ s
* i
++);
3100 if ((reglist
& 0x10) == 0x10)
3101 set_reg_offset (gdbarch
, this_cache
,
3102 MIPS_RA_REGNUM
, sp
+ s
* i
++);
3105 this_non_prologue_insn
= 1;
3108 /* Record $sp/$fp adjustment. */
3109 /* Discard (D)ADDIU $gp used for PIC code. */
3110 case 0xc: /* ADDIU: bits 001100 */
3111 case 0x17: /* DADDIU: bits 010111 */
3112 sreg
= b0s5_reg (insn
>> 16);
3113 dreg
= b5s5_reg (insn
>> 16);
3114 offset
= (b0s16_imm (insn
) ^ 0x8000) - 0x8000;
3115 if (sreg
== MIPS_SP_REGNUM
&& dreg
== MIPS_SP_REGNUM
)
3116 /* (D)ADDIU $sp, imm */
3118 else if (sreg
== MIPS_SP_REGNUM
&& dreg
== 30)
3119 /* (D)ADDIU $fp, $sp, imm */
3121 frame_adjust
= offset
;
3124 else if (sreg
!= 28 || dreg
!= 28)
3125 /* (D)ADDIU $gp, imm */
3126 this_non_prologue_insn
= 1;
3129 /* LUI $v1 is used for larger $sp adjustments. */
3130 /* Discard LUI $gp used for PIC code. */
3131 case 0x10: /* POOL32I: bits 010000 */
3132 if (b5s5_op (insn
>> 16) == 0xd
3133 /* LUI: bits 010000 001101 */
3134 && b0s5_reg (insn
>> 16) == 3)
3136 v1_off
= ((b0s16_imm (insn
) << 16) ^ 0x80000000) - 0x80000000;
3137 else if (b5s5_op (insn
>> 16) != 0xd
3138 /* LUI: bits 010000 001101 */
3139 || b0s5_reg (insn
>> 16) != 28)
3141 this_non_prologue_insn
= 1;
3144 /* ORI $v1 is used for larger $sp adjustments. */
3145 case 0x14: /* ORI: bits 010100 */
3146 sreg
= b0s5_reg (insn
>> 16);
3147 dreg
= b5s5_reg (insn
>> 16);
3148 if (sreg
== 3 && dreg
== 3)
3150 v1_off
|= b0s16_imm (insn
);
3152 this_non_prologue_insn
= 1;
3155 case 0x26: /* SWC1: bits 100110 */
3156 case 0x2e: /* SDC1: bits 101110 */
3157 breg
= b0s5_reg (insn
>> 16);
3158 if (breg
!= MIPS_SP_REGNUM
)
3159 /* S[DW]C1 reg,offset($sp) */
3160 this_non_prologue_insn
= 1;
3163 case 0x36: /* SD: bits 110110 */
3164 case 0x3e: /* SW: bits 111110 */
3165 breg
= b0s5_reg (insn
>> 16);
3166 sreg
= b5s5_reg (insn
>> 16);
3167 offset
= (b0s16_imm (insn
) ^ 0x8000) - 0x8000;
3168 if (breg
== MIPS_SP_REGNUM
)
3169 /* S[DW] reg,offset($sp) */
3170 set_reg_offset (gdbarch
, this_cache
, sreg
, sp
+ offset
);
3172 this_non_prologue_insn
= 1;
3176 /* The instruction in the delay slot can be a part
3177 of the prologue, so move forward once more. */
3178 if (micromips_instruction_has_delay_slot (insn
, 0))
3181 this_non_prologue_insn
= 1;
3187 /* 16-bit instructions. */
3188 case MIPS_INSN16_SIZE
:
3189 switch (micromips_op (insn
))
3191 case 0x3: /* MOVE: bits 000011 */
3192 sreg
= b0s5_reg (insn
);
3193 dreg
= b5s5_reg (insn
);
3194 if (sreg
== MIPS_SP_REGNUM
&& dreg
== 30)
3197 else if ((sreg
& 0x1c) != 0x4)
3198 /* MOVE reg, $a0-$a3 */
3199 this_non_prologue_insn
= 1;
3202 case 0x11: /* POOL16C: bits 010001 */
3203 if (b6s4_op (insn
) == 0x5)
3204 /* SWM: bits 010001 0101 */
3206 offset
= ((b0s4_imm (insn
) << 2) ^ 0x20) - 0x20;
3207 reglist
= b4s2_regl (insn
);
3208 for (i
= 0; i
<= reglist
; i
++)
3209 set_reg_offset (gdbarch
, this_cache
, 16 + i
, sp
+ 4 * i
);
3210 set_reg_offset (gdbarch
, this_cache
,
3211 MIPS_RA_REGNUM
, sp
+ 4 * i
++);
3214 this_non_prologue_insn
= 1;
3217 case 0x13: /* POOL16D: bits 010011 */
3218 if ((insn
& 0x1) == 0x1)
3219 /* ADDIUSP: bits 010011 1 */
3220 sp_adj
= micromips_decode_imm9 (b1s9_imm (insn
));
3221 else if (b5s5_reg (insn
) == MIPS_SP_REGNUM
)
3222 /* ADDIUS5: bits 010011 0 */
3223 /* ADDIUS5 $sp, imm */
3224 sp_adj
= (b1s4_imm (insn
) ^ 8) - 8;
3226 this_non_prologue_insn
= 1;
3229 case 0x32: /* SWSP: bits 110010 */
3230 offset
= b0s5_imm (insn
) << 2;
3231 sreg
= b5s5_reg (insn
);
3232 set_reg_offset (gdbarch
, this_cache
, sreg
, sp
+ offset
);
3236 /* The instruction in the delay slot can be a part
3237 of the prologue, so move forward once more. */
3238 if (micromips_instruction_has_delay_slot (insn
<< 16, 0))
3241 this_non_prologue_insn
= 1;
3247 frame_offset
-= sp_adj
;
3249 non_prologue_insns
+= this_non_prologue_insn
;
3251 /* A jump or branch, enough non-prologue insns seen or positive
3252 stack adjustment? If so, then we must have reached the end
3253 of the prologue by now. */
3254 if (prev_delay_slot
|| non_prologue_insns
> 1 || sp_adj
> 0
3255 || micromips_instruction_is_compact_branch (insn
))
3258 prev_non_prologue_insn
= this_non_prologue_insn
;
3259 prev_delay_slot
= in_delay_slot
;
3263 if (this_cache
!= NULL
)
3266 (get_frame_register_signed (this_frame
,
3267 gdbarch_num_regs (gdbarch
) + frame_reg
)
3268 + frame_offset
- frame_adjust
);
3269 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
3270 be able to get rid of the assignment below, evetually. But it's
3271 still needed for now. */
3272 this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
3273 + mips_regnum (gdbarch
)->pc
]
3274 = this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
) + MIPS_RA_REGNUM
];
3277 /* Set end_prologue_addr to the address of the instruction immediately
3278 after the last one we scanned. Unless the last one looked like a
3279 non-prologue instruction (and we looked ahead), in which case use
3280 its address instead. */
3282 = prev_non_prologue_insn
|| prev_delay_slot
? prev_pc
: cur_pc
;
3284 return end_prologue_addr
;
3287 /* Heuristic unwinder for procedures using microMIPS instructions.
3288 Procedures that use the 32-bit instruction set are handled by the
3289 mips_insn32 unwinder. Likewise MIPS16 and the mips_insn16 unwinder. */
3291 static struct mips_frame_cache
*
3292 mips_micro_frame_cache (frame_info_ptr this_frame
, void **this_cache
)
3294 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3295 struct mips_frame_cache
*cache
;
3297 if ((*this_cache
) != NULL
)
3298 return (struct mips_frame_cache
*) (*this_cache
);
3300 cache
= FRAME_OBSTACK_ZALLOC (struct mips_frame_cache
);
3301 (*this_cache
) = cache
;
3302 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
3304 /* Analyze the function prologue. */
3306 const CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
3307 CORE_ADDR start_addr
;
3309 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
3310 if (start_addr
== 0)
3311 start_addr
= heuristic_proc_start (get_frame_arch (this_frame
), pc
);
3312 /* We can't analyze the prologue if we couldn't find the begining
3314 if (start_addr
== 0)
3317 micromips_scan_prologue (gdbarch
, start_addr
, pc
, this_frame
,
3318 (struct mips_frame_cache
*) *this_cache
);
3321 /* gdbarch_sp_regnum contains the value and not the address. */
3322 cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
3323 + MIPS_SP_REGNUM
].set_value (cache
->base
);
3325 return (struct mips_frame_cache
*) (*this_cache
);
3329 mips_micro_frame_this_id (frame_info_ptr this_frame
, void **this_cache
,
3330 struct frame_id
*this_id
)
3332 struct mips_frame_cache
*info
= mips_micro_frame_cache (this_frame
,
3334 /* This marks the outermost frame. */
3335 if (info
->base
== 0)
3337 (*this_id
) = frame_id_build (info
->base
, get_frame_func (this_frame
));
3340 static struct value
*
3341 mips_micro_frame_prev_register (frame_info_ptr this_frame
,
3342 void **this_cache
, int regnum
)
3344 struct mips_frame_cache
*info
= mips_micro_frame_cache (this_frame
,
3346 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
3350 mips_micro_frame_sniffer (const struct frame_unwind
*self
,
3351 frame_info_ptr this_frame
, void **this_cache
)
3353 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3354 CORE_ADDR pc
= get_frame_pc (this_frame
);
3356 if (mips_pc_is_micromips (gdbarch
, pc
))
3361 static const struct frame_unwind mips_micro_frame_unwind
=
3363 "mips micro prologue",
3365 default_frame_unwind_stop_reason
,
3366 mips_micro_frame_this_id
,
3367 mips_micro_frame_prev_register
,
3369 mips_micro_frame_sniffer
3373 mips_micro_frame_base_address (frame_info_ptr this_frame
,
3376 struct mips_frame_cache
*info
= mips_micro_frame_cache (this_frame
,
3381 static const struct frame_base mips_micro_frame_base
=
3383 &mips_micro_frame_unwind
,
3384 mips_micro_frame_base_address
,
3385 mips_micro_frame_base_address
,
3386 mips_micro_frame_base_address
3389 static const struct frame_base
*
3390 mips_micro_frame_base_sniffer (frame_info_ptr this_frame
)
3392 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3393 CORE_ADDR pc
= get_frame_pc (this_frame
);
3395 if (mips_pc_is_micromips (gdbarch
, pc
))
3396 return &mips_micro_frame_base
;
3401 /* Mark all the registers as unset in the saved_regs array
3402 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
3405 reset_saved_regs (struct gdbarch
*gdbarch
, struct mips_frame_cache
*this_cache
)
3407 if (this_cache
== NULL
|| this_cache
->saved_regs
== NULL
)
3411 const int num_regs
= gdbarch_num_regs (gdbarch
);
3414 /* Reset the register values to their default state. Register i's value
3415 is in register i. */
3416 for (i
= 0; i
< num_regs
; i
++)
3417 this_cache
->saved_regs
[i
].set_realreg (i
);
3421 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
3422 the associated FRAME_CACHE if not null.
3423 Return the address of the first instruction past the prologue. */
3426 mips32_scan_prologue (struct gdbarch
*gdbarch
,
3427 CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
3428 frame_info_ptr this_frame
,
3429 struct mips_frame_cache
*this_cache
)
3431 int prev_non_prologue_insn
;
3432 int this_non_prologue_insn
;
3433 int non_prologue_insns
;
3434 CORE_ADDR frame_addr
= 0; /* Value of $r30. Used by gcc for
3436 int prev_delay_slot
;
3441 int frame_reg
= MIPS_SP_REGNUM
;
3443 CORE_ADDR end_prologue_addr
;
3444 int seen_sp_adjust
= 0;
3445 int load_immediate_bytes
= 0;
3447 int regsize_is_64_bits
= (mips_abi_regsize (gdbarch
) == 8);
3449 /* Can be called when there's no process, and hence when there's no
3451 if (this_frame
!= NULL
)
3452 sp
= get_frame_register_signed (this_frame
,
3453 gdbarch_num_regs (gdbarch
)
3458 if (limit_pc
> start_pc
+ 200)
3459 limit_pc
= start_pc
+ 200;
3462 prev_non_prologue_insn
= 0;
3463 non_prologue_insns
= 0;
3464 prev_delay_slot
= 0;
3467 /* Permit at most one non-prologue non-control-transfer instruction
3468 in the middle which may have been reordered by the compiler for
3471 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS_INSN32_SIZE
)
3473 unsigned long inst
, high_word
;
3477 this_non_prologue_insn
= 0;
3480 /* Fetch the instruction. */
3481 inst
= (unsigned long) mips_fetch_instruction (gdbarch
, ISA_MIPS
,
3484 /* Save some code by pre-extracting some useful fields. */
3485 high_word
= (inst
>> 16) & 0xffff;
3486 offset
= ((inst
& 0xffff) ^ 0x8000) - 0x8000;
3487 reg
= high_word
& 0x1f;
3489 if (high_word
== 0x27bd /* addiu $sp,$sp,-i */
3490 || high_word
== 0x23bd /* addi $sp,$sp,-i */
3491 || high_word
== 0x67bd) /* daddiu $sp,$sp,-i */
3493 if (offset
< 0) /* Negative stack adjustment? */
3494 frame_offset
-= offset
;
3496 /* Exit loop if a positive stack adjustment is found, which
3497 usually means that the stack cleanup code in the function
3498 epilogue is reached. */
3502 else if (((high_word
& 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
3503 && !regsize_is_64_bits
)
3505 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
3507 else if (((high_word
& 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
3508 && regsize_is_64_bits
)
3510 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
3511 set_reg_offset (gdbarch
, this_cache
, reg
, sp
+ offset
);
3513 else if (high_word
== 0x27be) /* addiu $30,$sp,size */
3515 /* Old gcc frame, r30 is virtual frame pointer. */
3516 if (offset
!= frame_offset
)
3517 frame_addr
= sp
+ offset
;
3518 else if (this_frame
&& frame_reg
== MIPS_SP_REGNUM
)
3520 unsigned alloca_adjust
;
3523 frame_addr
= get_frame_register_signed
3524 (this_frame
, gdbarch_num_regs (gdbarch
) + 30);
3527 alloca_adjust
= (unsigned) (frame_addr
- (sp
+ offset
));
3528 if (alloca_adjust
> 0)
3530 /* FP > SP + frame_size. This may be because of
3531 an alloca or somethings similar. Fix sp to
3532 "pre-alloca" value, and try again. */
3533 sp
+= alloca_adjust
;
3534 /* Need to reset the status of all registers. Otherwise,
3535 we will hit a guard that prevents the new address
3536 for each register to be recomputed during the second
3538 reset_saved_regs (gdbarch
, this_cache
);
3543 /* move $30,$sp. With different versions of gas this will be either
3544 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
3545 Accept any one of these. */
3546 else if (inst
== 0x03A0F021 || inst
== 0x03a0f025 || inst
== 0x03a0f02d)
3548 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
3549 if (this_frame
&& frame_reg
== MIPS_SP_REGNUM
)
3551 unsigned alloca_adjust
;
3554 frame_addr
= get_frame_register_signed
3555 (this_frame
, gdbarch_num_regs (gdbarch
) + 30);
3557 alloca_adjust
= (unsigned) (frame_addr
- sp
);
3558 if (alloca_adjust
> 0)
3560 /* FP > SP + frame_size. This may be because of
3561 an alloca or somethings similar. Fix sp to
3562 "pre-alloca" value, and try again. */
3564 /* Need to reset the status of all registers. Otherwise,
3565 we will hit a guard that prevents the new address
3566 for each register to be recomputed during the second
3568 reset_saved_regs (gdbarch
, this_cache
);
3573 else if ((high_word
& 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
3574 && !regsize_is_64_bits
)
3576 set_reg_offset (gdbarch
, this_cache
, reg
, frame_addr
+ offset
);
3578 else if ((high_word
& 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
3579 || (high_word
& 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
3580 || (inst
& 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
3581 || high_word
== 0x3c1c /* lui $gp,n */
3582 || high_word
== 0x279c /* addiu $gp,$gp,n */
3583 || high_word
== 0x679c /* daddiu $gp,$gp,n */
3584 || inst
== 0x0399e021 /* addu $gp,$gp,$t9 */
3585 || inst
== 0x033ce021 /* addu $gp,$t9,$gp */
3586 || inst
== 0x0399e02d /* daddu $gp,$gp,$t9 */
3587 || inst
== 0x033ce02d /* daddu $gp,$t9,$gp */
3590 /* These instructions are part of the prologue, but we don't
3591 need to do anything special to handle them. */
3593 /* The instructions below load $at or $t0 with an immediate
3594 value in preparation for a stack adjustment via
3595 subu $sp,$sp,[$at,$t0]. These instructions could also
3596 initialize a local variable, so we accept them only before
3597 a stack adjustment instruction was seen. */
3598 else if (!seen_sp_adjust
3600 && (high_word
== 0x3c01 /* lui $at,n */
3601 || high_word
== 0x3c08 /* lui $t0,n */
3602 || high_word
== 0x3421 /* ori $at,$at,n */
3603 || high_word
== 0x3508 /* ori $t0,$t0,n */
3604 || high_word
== 0x3401 /* ori $at,$zero,n */
3605 || high_word
== 0x3408 /* ori $t0,$zero,n */
3608 load_immediate_bytes
+= MIPS_INSN32_SIZE
; /* FIXME! */
3610 /* Check for branches and jumps. The instruction in the delay
3611 slot can be a part of the prologue, so move forward once more. */
3612 else if (mips32_instruction_has_delay_slot (gdbarch
, inst
))
3616 /* This instruction is not an instruction typically found
3617 in a prologue, so we must have reached the end of the
3621 this_non_prologue_insn
= 1;
3624 non_prologue_insns
+= this_non_prologue_insn
;
3626 /* A jump or branch, or enough non-prologue insns seen? If so,
3627 then we must have reached the end of the prologue by now. */
3628 if (prev_delay_slot
|| non_prologue_insns
> 1)
3631 prev_non_prologue_insn
= this_non_prologue_insn
;
3632 prev_delay_slot
= in_delay_slot
;
3636 if (this_cache
!= NULL
)
3639 (get_frame_register_signed (this_frame
,
3640 gdbarch_num_regs (gdbarch
) + frame_reg
)
3642 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
3643 this assignment below, eventually. But it's still needed
3645 this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
3646 + mips_regnum (gdbarch
)->pc
]
3647 = this_cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
3651 /* Set end_prologue_addr to the address of the instruction immediately
3652 after the last one we scanned. Unless the last one looked like a
3653 non-prologue instruction (and we looked ahead), in which case use
3654 its address instead. */
3656 = prev_non_prologue_insn
|| prev_delay_slot
? prev_pc
: cur_pc
;
3658 /* In a frameless function, we might have incorrectly
3659 skipped some load immediate instructions. Undo the skipping
3660 if the load immediate was not followed by a stack adjustment. */
3661 if (load_immediate_bytes
&& !seen_sp_adjust
)
3662 end_prologue_addr
-= load_immediate_bytes
;
3664 return end_prologue_addr
;
3667 /* Heuristic unwinder for procedures using 32-bit instructions (covers
3668 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
3669 instructions (a.k.a. MIPS16) are handled by the mips_insn16
3670 unwinder. Likewise microMIPS and the mips_micro unwinder. */
3672 static struct mips_frame_cache
*
3673 mips_insn32_frame_cache (frame_info_ptr this_frame
, void **this_cache
)
3675 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3676 struct mips_frame_cache
*cache
;
3678 if ((*this_cache
) != NULL
)
3679 return (struct mips_frame_cache
*) (*this_cache
);
3681 cache
= FRAME_OBSTACK_ZALLOC (struct mips_frame_cache
);
3682 (*this_cache
) = cache
;
3683 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
3685 /* Analyze the function prologue. */
3687 const CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
3688 CORE_ADDR start_addr
;
3690 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
3691 if (start_addr
== 0)
3692 start_addr
= heuristic_proc_start (gdbarch
, pc
);
3693 /* We can't analyze the prologue if we couldn't find the begining
3695 if (start_addr
== 0)
3698 mips32_scan_prologue (gdbarch
, start_addr
, pc
, this_frame
,
3699 (struct mips_frame_cache
*) *this_cache
);
3702 /* gdbarch_sp_regnum contains the value and not the address. */
3703 cache
->saved_regs
[gdbarch_num_regs (gdbarch
)
3704 + MIPS_SP_REGNUM
].set_value (cache
->base
);
3706 return (struct mips_frame_cache
*) (*this_cache
);
3710 mips_insn32_frame_this_id (frame_info_ptr this_frame
, void **this_cache
,
3711 struct frame_id
*this_id
)
3713 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
3715 /* This marks the outermost frame. */
3716 if (info
->base
== 0)
3718 (*this_id
) = frame_id_build (info
->base
, get_frame_func (this_frame
));
3721 static struct value
*
3722 mips_insn32_frame_prev_register (frame_info_ptr this_frame
,
3723 void **this_cache
, int regnum
)
3725 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
3727 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
3731 mips_insn32_frame_sniffer (const struct frame_unwind
*self
,
3732 frame_info_ptr this_frame
, void **this_cache
)
3734 CORE_ADDR pc
= get_frame_pc (this_frame
);
3735 if (mips_pc_is_mips (pc
))
3740 static const struct frame_unwind mips_insn32_frame_unwind
=
3742 "mips insn32 prologue",
3744 default_frame_unwind_stop_reason
,
3745 mips_insn32_frame_this_id
,
3746 mips_insn32_frame_prev_register
,
3748 mips_insn32_frame_sniffer
3752 mips_insn32_frame_base_address (frame_info_ptr this_frame
,
3755 struct mips_frame_cache
*info
= mips_insn32_frame_cache (this_frame
,
3760 static const struct frame_base mips_insn32_frame_base
=
3762 &mips_insn32_frame_unwind
,
3763 mips_insn32_frame_base_address
,
3764 mips_insn32_frame_base_address
,
3765 mips_insn32_frame_base_address
3768 static const struct frame_base
*
3769 mips_insn32_frame_base_sniffer (frame_info_ptr this_frame
)
3771 CORE_ADDR pc
= get_frame_pc (this_frame
);
3772 if (mips_pc_is_mips (pc
))
3773 return &mips_insn32_frame_base
;
3778 static struct trad_frame_cache
*
3779 mips_stub_frame_cache (frame_info_ptr this_frame
, void **this_cache
)
3782 CORE_ADDR start_addr
;
3783 CORE_ADDR stack_addr
;
3784 struct trad_frame_cache
*this_trad_cache
;
3785 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3786 int num_regs
= gdbarch_num_regs (gdbarch
);
3788 if ((*this_cache
) != NULL
)
3789 return (struct trad_frame_cache
*) (*this_cache
);
3790 this_trad_cache
= trad_frame_cache_zalloc (this_frame
);
3791 (*this_cache
) = this_trad_cache
;
3793 /* The return address is in the link register. */
3794 trad_frame_set_reg_realreg (this_trad_cache
,
3795 gdbarch_pc_regnum (gdbarch
),
3796 num_regs
+ MIPS_RA_REGNUM
);
3798 /* Frame ID, since it's a frameless / stackless function, no stack
3799 space is allocated and SP on entry is the current SP. */
3800 pc
= get_frame_pc (this_frame
);
3801 find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
);
3802 stack_addr
= get_frame_register_signed (this_frame
,
3803 num_regs
+ MIPS_SP_REGNUM
);
3804 trad_frame_set_id (this_trad_cache
, frame_id_build (stack_addr
, start_addr
));
3806 /* Assume that the frame's base is the same as the
3808 trad_frame_set_this_base (this_trad_cache
, stack_addr
);
3810 return this_trad_cache
;
3814 mips_stub_frame_this_id (frame_info_ptr this_frame
, void **this_cache
,
3815 struct frame_id
*this_id
)
3817 struct trad_frame_cache
*this_trad_cache
3818 = mips_stub_frame_cache (this_frame
, this_cache
);
3819 trad_frame_get_id (this_trad_cache
, this_id
);
3822 static struct value
*
3823 mips_stub_frame_prev_register (frame_info_ptr this_frame
,
3824 void **this_cache
, int regnum
)
3826 struct trad_frame_cache
*this_trad_cache
3827 = mips_stub_frame_cache (this_frame
, this_cache
);
3828 return trad_frame_get_register (this_trad_cache
, this_frame
, regnum
);
3832 mips_stub_frame_sniffer (const struct frame_unwind
*self
,
3833 frame_info_ptr this_frame
, void **this_cache
)
3836 CORE_ADDR pc
= get_frame_address_in_block (this_frame
);
3837 struct bound_minimal_symbol msym
;
3839 /* Use the stub unwinder for unreadable code. */
3840 if (target_read_memory (get_frame_pc (this_frame
), dummy
, 4) != 0)
3843 if (in_plt_section (pc
) || in_mips_stubs_section (pc
))
3846 /* Calling a PIC function from a non-PIC function passes through a
3847 stub. The stub for foo is named ".pic.foo". */
3848 msym
= lookup_minimal_symbol_by_pc (pc
);
3849 if (msym
.minsym
!= NULL
3850 && msym
.minsym
->linkage_name () != NULL
3851 && startswith (msym
.minsym
->linkage_name (), ".pic."))
3857 static const struct frame_unwind mips_stub_frame_unwind
=
3861 default_frame_unwind_stop_reason
,
3862 mips_stub_frame_this_id
,
3863 mips_stub_frame_prev_register
,
3865 mips_stub_frame_sniffer
3869 mips_stub_frame_base_address (frame_info_ptr this_frame
,
3872 struct trad_frame_cache
*this_trad_cache
3873 = mips_stub_frame_cache (this_frame
, this_cache
);
3874 return trad_frame_get_this_base (this_trad_cache
);
3877 static const struct frame_base mips_stub_frame_base
=
3879 &mips_stub_frame_unwind
,
3880 mips_stub_frame_base_address
,
3881 mips_stub_frame_base_address
,
3882 mips_stub_frame_base_address
3885 static const struct frame_base
*
3886 mips_stub_frame_base_sniffer (frame_info_ptr this_frame
)
3888 if (mips_stub_frame_sniffer (&mips_stub_frame_unwind
, this_frame
, NULL
))
3889 return &mips_stub_frame_base
;
3894 /* mips_addr_bits_remove - remove useless address bits */
3897 mips_addr_bits_remove (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
3899 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
3901 if (mips_mask_address_p (tdep
) && (((ULONGEST
) addr
) >> 32 == 0xffffffffUL
))
3902 /* This hack is a work-around for existing boards using PMON, the
3903 simulator, and any other 64-bit targets that doesn't have true
3904 64-bit addressing. On these targets, the upper 32 bits of
3905 addresses are ignored by the hardware. Thus, the PC or SP are
3906 likely to have been sign extended to all 1s by instruction
3907 sequences that load 32-bit addresses. For example, a typical
3908 piece of code that loads an address is this:
3910 lui $r2, <upper 16 bits>
3911 ori $r2, <lower 16 bits>
3913 But the lui sign-extends the value such that the upper 32 bits
3914 may be all 1s. The workaround is simply to mask off these
3915 bits. In the future, gcc may be changed to support true 64-bit
3916 addressing, and this masking will have to be disabled. */
3917 return addr
&= 0xffffffffUL
;
3923 /* Checks for an atomic sequence of instructions beginning with a LL/LLD
3924 instruction and ending with a SC/SCD instruction. If such a sequence
3925 is found, attempt to step through it. A breakpoint is placed at the end of
3928 /* Instructions used during single-stepping of atomic sequences, standard
3930 #define LL_OPCODE 0x30
3931 #define LLD_OPCODE 0x34
3932 #define SC_OPCODE 0x38
3933 #define SCD_OPCODE 0x3c
3935 static std::vector
<CORE_ADDR
>
3936 mips_deal_with_atomic_sequence (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
3938 CORE_ADDR breaks
[2] = {CORE_ADDR_MAX
, CORE_ADDR_MAX
};
3940 CORE_ADDR branch_bp
; /* Breakpoint at branch instruction's destination. */
3944 int last_breakpoint
= 0; /* Defaults to 0 (no breakpoints placed). */
3945 const int atomic_sequence_length
= 16; /* Instruction sequence length. */
3947 insn
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, loc
, NULL
);
3948 /* Assume all atomic sequences start with a ll/lld instruction. */
3949 if (itype_op (insn
) != LL_OPCODE
&& itype_op (insn
) != LLD_OPCODE
)
3952 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
3954 for (insn_count
= 0; insn_count
< atomic_sequence_length
; ++insn_count
)
3957 loc
+= MIPS_INSN32_SIZE
;
3958 insn
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, loc
, NULL
);
3960 /* Assume that there is at most one branch in the atomic
3961 sequence. If a branch is found, put a breakpoint in its
3962 destination address. */
3963 switch (itype_op (insn
))
3965 case 0: /* SPECIAL */
3966 if (rtype_funct (insn
) >> 1 == 4) /* JR, JALR */
3967 return {}; /* fallback to the standard single-step code. */
3969 case 1: /* REGIMM */
3970 is_branch
= ((itype_rt (insn
) & 0xc) == 0 /* B{LT,GE}Z* */
3971 || ((itype_rt (insn
) & 0x1e) == 0
3972 && itype_rs (insn
) == 0)); /* BPOSGE* */
3976 return {}; /* fallback to the standard single-step code. */
3983 case 22: /* BLEZL */
3984 case 23: /* BGTTL */
3988 is_branch
= ((itype_rs (insn
) == 9 || itype_rs (insn
) == 10)
3989 && (itype_rt (insn
) & 0x2) == 0);
3990 if (is_branch
) /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */
3995 is_branch
= (itype_rs (insn
) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
4000 branch_bp
= loc
+ mips32_relative_offset (insn
) + 4;
4001 if (last_breakpoint
>= 1)
4002 return {}; /* More than one branch found, fallback to the
4003 standard single-step code. */
4004 breaks
[1] = branch_bp
;
4008 if (itype_op (insn
) == SC_OPCODE
|| itype_op (insn
) == SCD_OPCODE
)
4012 /* Assume that the atomic sequence ends with a sc/scd instruction. */
4013 if (itype_op (insn
) != SC_OPCODE
&& itype_op (insn
) != SCD_OPCODE
)
4016 loc
+= MIPS_INSN32_SIZE
;
4018 /* Insert a breakpoint right after the end of the atomic sequence. */
4021 /* Check for duplicated breakpoints. Check also for a breakpoint
4022 placed (branch instruction's destination) in the atomic sequence. */
4023 if (last_breakpoint
&& pc
<= breaks
[1] && breaks
[1] <= breaks
[0])
4024 last_breakpoint
= 0;
4026 std::vector
<CORE_ADDR
> next_pcs
;
4028 /* Effectively inserts the breakpoints. */
4029 for (index
= 0; index
<= last_breakpoint
; index
++)
4030 next_pcs
.push_back (breaks
[index
]);
4035 static std::vector
<CORE_ADDR
>
4036 micromips_deal_with_atomic_sequence (struct gdbarch
*gdbarch
,
4039 const int atomic_sequence_length
= 16; /* Instruction sequence length. */
4040 int last_breakpoint
= 0; /* Defaults to 0 (no breakpoints placed). */
4041 CORE_ADDR breaks
[2] = {CORE_ADDR_MAX
, CORE_ADDR_MAX
};
4042 CORE_ADDR branch_bp
= 0; /* Breakpoint at branch instruction's
4050 /* Assume all atomic sequences start with a ll/lld instruction. */
4051 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, loc
, NULL
);
4052 if (micromips_op (insn
) != 0x18) /* POOL32C: bits 011000 */
4054 loc
+= MIPS_INSN16_SIZE
;
4056 insn
|= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, loc
, NULL
);
4057 if ((b12s4_op (insn
) & 0xb) != 0x3) /* LL, LLD: bits 011000 0x11 */
4059 loc
+= MIPS_INSN16_SIZE
;
4061 /* Assume all atomic sequences end with an sc/scd instruction. Assume
4062 that no atomic sequence is longer than "atomic_sequence_length"
4064 for (insn_count
= 0;
4065 !sc_found
&& insn_count
< atomic_sequence_length
;
4070 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, loc
, NULL
);
4071 loc
+= MIPS_INSN16_SIZE
;
4073 /* Assume that there is at most one conditional branch in the
4074 atomic sequence. If a branch is found, put a breakpoint in
4075 its destination address. */
4076 switch (mips_insn_size (ISA_MICROMIPS
, insn
))
4078 /* 32-bit instructions. */
4079 case 2 * MIPS_INSN16_SIZE
:
4080 switch (micromips_op (insn
))
4082 case 0x10: /* POOL32I: bits 010000 */
4083 if ((b5s5_op (insn
) & 0x18) != 0x0
4084 /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */
4085 /* BLEZ, BNEZC, BGTZ, BEQZC: 010000 001xx */
4086 && (b5s5_op (insn
) & 0x1d) != 0x11
4087 /* BLTZALS, BGEZALS: bits 010000 100x1 */
4088 && ((b5s5_op (insn
) & 0x1e) != 0x14
4089 || (insn
& 0x3) != 0x0)
4090 /* BC2F, BC2T: bits 010000 1010x xxx00 */
4091 && (b5s5_op (insn
) & 0x1e) != 0x1a
4092 /* BPOSGE64, BPOSGE32: bits 010000 1101x */
4093 && ((b5s5_op (insn
) & 0x1e) != 0x1c
4094 || (insn
& 0x3) != 0x0)
4095 /* BC1F, BC1T: bits 010000 1110x xxx00 */
4096 && ((b5s5_op (insn
) & 0x1c) != 0x1c
4097 || (insn
& 0x3) != 0x1))
4098 /* BC1ANY*: bits 010000 111xx xxx01 */
4102 case 0x25: /* BEQ: bits 100101 */
4103 case 0x2d: /* BNE: bits 101101 */
4105 insn
|= mips_fetch_instruction (gdbarch
,
4106 ISA_MICROMIPS
, loc
, NULL
);
4107 branch_bp
= (loc
+ MIPS_INSN16_SIZE
4108 + micromips_relative_offset16 (insn
));
4112 case 0x00: /* POOL32A: bits 000000 */
4114 insn
|= mips_fetch_instruction (gdbarch
,
4115 ISA_MICROMIPS
, loc
, NULL
);
4116 if (b0s6_op (insn
) != 0x3c
4117 /* POOL32Axf: bits 000000 ... 111100 */
4118 || (b6s10_ext (insn
) & 0x2bf) != 0x3c)
4119 /* JALR, JALR.HB: 000000 000x111100 111100 */
4120 /* JALRS, JALRS.HB: 000000 010x111100 111100 */
4124 case 0x1d: /* JALS: bits 011101 */
4125 case 0x35: /* J: bits 110101 */
4126 case 0x3d: /* JAL: bits 111101 */
4127 case 0x3c: /* JALX: bits 111100 */
4128 return {}; /* Fall back to the standard single-step code. */
4130 case 0x18: /* POOL32C: bits 011000 */
4131 if ((b12s4_op (insn
) & 0xb) == 0xb)
4132 /* SC, SCD: bits 011000 1x11 */
4136 loc
+= MIPS_INSN16_SIZE
;
4139 /* 16-bit instructions. */
4140 case MIPS_INSN16_SIZE
:
4141 switch (micromips_op (insn
))
4143 case 0x23: /* BEQZ16: bits 100011 */
4144 case 0x2b: /* BNEZ16: bits 101011 */
4145 branch_bp
= loc
+ micromips_relative_offset7 (insn
);
4149 case 0x11: /* POOL16C: bits 010001 */
4150 if ((b5s5_op (insn
) & 0x1c) != 0xc
4151 /* JR16, JRC, JALR16, JALRS16: 010001 011xx */
4152 && b5s5_op (insn
) != 0x18)
4153 /* JRADDIUSP: bits 010001 11000 */
4155 return {}; /* Fall back to the standard single-step code. */
4157 case 0x33: /* B16: bits 110011 */
4158 return {}; /* Fall back to the standard single-step code. */
4164 if (last_breakpoint
>= 1)
4165 return {}; /* More than one branch found, fallback to the
4166 standard single-step code. */
4167 breaks
[1] = branch_bp
;
4174 /* Insert a breakpoint right after the end of the atomic sequence. */
4177 /* Check for duplicated breakpoints. Check also for a breakpoint
4178 placed (branch instruction's destination) in the atomic sequence */
4179 if (last_breakpoint
&& pc
<= breaks
[1] && breaks
[1] <= breaks
[0])
4180 last_breakpoint
= 0;
4182 std::vector
<CORE_ADDR
> next_pcs
;
4184 /* Effectively inserts the breakpoints. */
4185 for (index
= 0; index
<= last_breakpoint
; index
++)
4186 next_pcs
.push_back (breaks
[index
]);
4191 static std::vector
<CORE_ADDR
>
4192 deal_with_atomic_sequence (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4194 if (mips_pc_is_mips (pc
))
4195 return mips_deal_with_atomic_sequence (gdbarch
, pc
);
4196 else if (mips_pc_is_micromips (gdbarch
, pc
))
4197 return micromips_deal_with_atomic_sequence (gdbarch
, pc
);
4202 /* mips_software_single_step() is called just before we want to resume
4203 the inferior, if we want to single-step it but there is no hardware
4204 or kernel single-step support (MIPS on GNU/Linux for example). We find
4205 the target of the coming instruction and breakpoint it. */
4207 std::vector
<CORE_ADDR
>
4208 mips_software_single_step (struct regcache
*regcache
)
4210 struct gdbarch
*gdbarch
= regcache
->arch ();
4211 CORE_ADDR pc
, next_pc
;
4213 pc
= regcache_read_pc (regcache
);
4214 std::vector
<CORE_ADDR
> next_pcs
= deal_with_atomic_sequence (gdbarch
, pc
);
4216 if (!next_pcs
.empty ())
4219 next_pc
= mips_next_pc (regcache
, pc
);
4224 /* Test whether the PC points to the return instruction at the
4225 end of a function. */
4228 mips_about_to_return (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4233 /* This used to check for MIPS16, but this piece of code is never
4234 called for MIPS16 functions. And likewise microMIPS ones. */
4235 gdb_assert (mips_pc_is_mips (pc
));
4237 insn
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, pc
, NULL
);
4239 return (insn
& ~hint
) == 0x3e00008; /* jr(.hb) $ra */
4243 /* This fencepost looks highly suspicious to me. Removing it also
4244 seems suspicious as it could affect remote debugging across serial
4248 heuristic_proc_start (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4254 struct inferior
*inf
;
4256 pc
= gdbarch_addr_bits_remove (gdbarch
, pc
);
4258 fence
= start_pc
- heuristic_fence_post
;
4262 if (heuristic_fence_post
== -1 || fence
< VM_MIN_ADDRESS
)
4263 fence
= VM_MIN_ADDRESS
;
4265 instlen
= mips_pc_is_mips (pc
) ? MIPS_INSN32_SIZE
: MIPS_INSN16_SIZE
;
4267 inf
= current_inferior ();
4269 /* Search back for previous return. */
4270 for (start_pc
-= instlen
;; start_pc
-= instlen
)
4271 if (start_pc
< fence
)
4273 /* It's not clear to me why we reach this point when
4274 stop_soon, but with this test, at least we
4275 don't print out warnings for every child forked (eg, on
4276 decstation). 22apr93 rich@cygnus.com. */
4277 if (inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
4279 static int blurb_printed
= 0;
4281 warning (_("GDB can't find the start of the function at %s."),
4282 paddress (gdbarch
, pc
));
4286 /* This actually happens frequently in embedded
4287 development, when you first connect to a board
4288 and your stack pointer and pc are nowhere in
4289 particular. This message needs to give people
4290 in that situation enough information to
4291 determine that it's no big deal. */
4293 GDB is unable to find the start of the function at %s\n\
4294 and thus can't determine the size of that function's stack frame.\n\
4295 This means that GDB may be unable to access that stack frame, or\n\
4296 the frames below it.\n\
4297 This problem is most likely caused by an invalid program counter or\n\
4299 However, if you think GDB should simply search farther back\n\
4300 from %s for code which looks like the beginning of a\n\
4301 function, you can increase the range of the search using the `set\n\
4302 heuristic-fence-post' command.\n",
4303 paddress (gdbarch
, pc
), paddress (gdbarch
, pc
));
4310 else if (mips_pc_is_mips16 (gdbarch
, start_pc
))
4312 unsigned short inst
;
4314 /* On MIPS16, any one of the following is likely to be the
4315 start of a function:
4321 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */
4322 inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS16
, start_pc
, NULL
);
4323 if ((inst
& 0xff80) == 0x6480) /* save */
4325 if (start_pc
- instlen
>= fence
)
4327 inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS16
,
4328 start_pc
- instlen
, NULL
);
4329 if ((inst
& 0xf800) == 0xf000) /* extend */
4330 start_pc
-= instlen
;
4334 else if (((inst
& 0xf81f) == 0xe809
4335 && (inst
& 0x700) != 0x700) /* entry */
4336 || (inst
& 0xff80) == 0x6380 /* addiu sp,-n */
4337 || (inst
& 0xff80) == 0xfb80 /* daddiu sp,-n */
4338 || ((inst
& 0xf810) == 0xf010 && seen_adjsp
)) /* extend -n */
4340 else if ((inst
& 0xff00) == 0x6300 /* addiu sp */
4341 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
4346 else if (mips_pc_is_micromips (gdbarch
, start_pc
))
4354 /* On microMIPS, any one of the following is likely to be the
4355 start of a function:
4359 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, NULL
);
4360 switch (micromips_op (insn
))
4362 case 0xc: /* ADDIU: bits 001100 */
4363 case 0x17: /* DADDIU: bits 010111 */
4364 sreg
= b0s5_reg (insn
);
4365 dreg
= b5s5_reg (insn
);
4367 insn
|= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
,
4368 pc
+ MIPS_INSN16_SIZE
, NULL
);
4369 offset
= (b0s16_imm (insn
) ^ 0x8000) - 0x8000;
4370 if (sreg
== MIPS_SP_REGNUM
&& dreg
== MIPS_SP_REGNUM
4371 /* (D)ADDIU $sp, imm */
4376 case 0x10: /* POOL32I: bits 010000 */
4377 if (b5s5_op (insn
) == 0xd
4378 /* LUI: bits 010000 001101 */
4379 && b0s5_reg (insn
>> 16) == 28)
4384 case 0x13: /* POOL16D: bits 010011 */
4385 if ((insn
& 0x1) == 0x1)
4386 /* ADDIUSP: bits 010011 1 */
4388 offset
= micromips_decode_imm9 (b1s9_imm (insn
));
4394 /* ADDIUS5: bits 010011 0 */
4396 dreg
= b5s5_reg (insn
);
4397 offset
= (b1s4_imm (insn
) ^ 8) - 8;
4398 if (dreg
== MIPS_SP_REGNUM
&& offset
< 0)
4399 /* ADDIUS5 $sp, -imm */
4407 else if (mips_about_to_return (gdbarch
, start_pc
))
4409 /* Skip return and its delay slot. */
4410 start_pc
+= 2 * MIPS_INSN32_SIZE
;
4417 struct mips_objfile_private
4423 /* According to the current ABI, should the type be passed in a
4424 floating-point register (assuming that there is space)? When there
4425 is no FPU, FP are not even considered as possible candidates for
4426 FP registers and, consequently this returns false - forces FP
4427 arguments into integer registers. */
4430 fp_register_arg_p (struct gdbarch
*gdbarch
, enum type_code typecode
,
4431 struct type
*arg_type
)
4433 return ((typecode
== TYPE_CODE_FLT
4434 || (mips_eabi (gdbarch
)
4435 && (typecode
== TYPE_CODE_STRUCT
4436 || typecode
== TYPE_CODE_UNION
)
4437 && arg_type
->num_fields () == 1
4438 && check_typedef (arg_type
->field (0).type ())->code ()
4440 && mips_get_fpu_type (gdbarch
) != MIPS_FPU_NONE
);
4443 /* On o32, argument passing in GPRs depends on the alignment of the type being
4444 passed. Return 1 if this type must be aligned to a doubleword boundary. */
4447 mips_type_needs_double_align (struct type
*type
)
4449 enum type_code typecode
= type
->code ();
4451 if (typecode
== TYPE_CODE_FLT
&& type
->length () == 8)
4453 else if (typecode
== TYPE_CODE_STRUCT
)
4455 if (type
->num_fields () < 1)
4457 return mips_type_needs_double_align (type
->field (0).type ());
4459 else if (typecode
== TYPE_CODE_UNION
)
4463 n
= type
->num_fields ();
4464 for (i
= 0; i
< n
; i
++)
4465 if (mips_type_needs_double_align (type
->field (i
).type ()))
4472 /* Adjust the address downward (direction of stack growth) so that it
4473 is correctly aligned for a new stack frame. */
4475 mips_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
4477 return align_down (addr
, 16);
4480 /* Implement the "push_dummy_code" gdbarch method. */
4483 mips_push_dummy_code (struct gdbarch
*gdbarch
, CORE_ADDR sp
,
4484 CORE_ADDR funaddr
, struct value
**args
,
4485 int nargs
, struct type
*value_type
,
4486 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
,
4487 struct regcache
*regcache
)
4489 static gdb_byte nop_insn
[] = { 0, 0, 0, 0 };
4493 /* Reserve enough room on the stack for our breakpoint instruction. */
4494 bp_slot
= sp
- sizeof (nop_insn
);
4496 /* Return to microMIPS mode if calling microMIPS code to avoid
4497 triggering an address error exception on processors that only
4498 support microMIPS execution. */
4499 *bp_addr
= (mips_pc_is_micromips (gdbarch
, funaddr
)
4500 ? make_compact_addr (bp_slot
) : bp_slot
);
4502 /* The breakpoint layer automatically adjusts the address of
4503 breakpoints inserted in a branch delay slot. With enough
4504 bad luck, the 4 bytes located just before our breakpoint
4505 instruction could look like a branch instruction, and thus
4506 trigger the adjustement, and break the function call entirely.
4507 So, we reserve those 4 bytes and write a nop instruction
4508 to prevent that from happening. */
4509 nop_addr
= bp_slot
- sizeof (nop_insn
);
4510 write_memory (nop_addr
, nop_insn
, sizeof (nop_insn
));
4511 sp
= mips_frame_align (gdbarch
, nop_addr
);
4513 /* Inferior resumes at the function entry point. */
4520 mips_eabi_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
4521 struct regcache
*regcache
, CORE_ADDR bp_addr
,
4522 int nargs
, struct value
**args
, CORE_ADDR sp
,
4523 function_call_return_method return_method
,
4524 CORE_ADDR struct_addr
)
4530 int stack_offset
= 0;
4531 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4532 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
4533 int abi_regsize
= mips_abi_regsize (gdbarch
);
4535 /* For shared libraries, "t9" needs to point at the function
4537 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
4539 /* Set the return address register to point to the entry point of
4540 the program, where a breakpoint lies in wait. */
4541 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
4543 /* First ensure that the stack and structure return address (if any)
4544 are properly aligned. The stack has to be at least 64-bit
4545 aligned even on 32-bit machines, because doubles must be 64-bit
4546 aligned. For n32 and n64, stack frames need to be 128-bit
4547 aligned, so we round to this widest known alignment. */
4549 sp
= align_down (sp
, 16);
4550 struct_addr
= align_down (struct_addr
, 16);
4552 /* Now make space on the stack for the args. We allocate more
4553 than necessary for EABI, because the first few arguments are
4554 passed in registers, but that's OK. */
4555 for (argnum
= 0; argnum
< nargs
; argnum
++)
4556 arg_space
+= align_up (value_type (args
[argnum
])->length (),
4558 sp
-= align_up (arg_space
, 16);
4561 gdb_printf (gdb_stdlog
,
4562 "mips_eabi_push_dummy_call: sp=%s allocated %ld\n",
4563 paddress (gdbarch
, sp
),
4564 (long) align_up (arg_space
, 16));
4566 /* Initialize the integer and float register pointers. */
4567 argreg
= MIPS_A0_REGNUM
;
4568 float_argreg
= mips_fpa0_regnum (gdbarch
);
4570 /* The struct_return pointer occupies the first parameter-passing reg. */
4571 if (return_method
== return_method_struct
)
4574 gdb_printf (gdb_stdlog
,
4575 "mips_eabi_push_dummy_call: "
4576 "struct_return reg=%d %s\n",
4577 argreg
, paddress (gdbarch
, struct_addr
));
4578 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
4581 /* Now load as many as possible of the first arguments into
4582 registers, and push the rest onto the stack. Loop thru args
4583 from first to last. */
4584 for (argnum
= 0; argnum
< nargs
; argnum
++)
4586 const gdb_byte
*val
;
4587 /* This holds the address of structures that are passed by
4589 gdb_byte ref_valbuf
[MAX_MIPS_ABI_REGSIZE
];
4590 struct value
*arg
= args
[argnum
];
4591 struct type
*arg_type
= check_typedef (value_type (arg
));
4592 int len
= arg_type
->length ();
4593 enum type_code typecode
= arg_type
->code ();
4596 gdb_printf (gdb_stdlog
,
4597 "mips_eabi_push_dummy_call: %d len=%d type=%d",
4598 argnum
+ 1, len
, (int) typecode
);
4600 /* The EABI passes structures that do not fit in a register by
4602 if (len
> abi_regsize
4603 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
))
4605 gdb_assert (abi_regsize
<= ARRAY_SIZE (ref_valbuf
));
4606 store_unsigned_integer (ref_valbuf
, abi_regsize
, byte_order
,
4607 value_address (arg
));
4608 typecode
= TYPE_CODE_PTR
;
4612 gdb_printf (gdb_stdlog
, " push");
4615 val
= value_contents (arg
).data ();
4617 /* 32-bit ABIs always start floating point arguments in an
4618 even-numbered floating point register. Round the FP register
4619 up before the check to see if there are any FP registers
4620 left. Non MIPS_EABI targets also pass the FP in the integer
4621 registers so also round up normal registers. */
4622 if (abi_regsize
< 8 && fp_register_arg_p (gdbarch
, typecode
, arg_type
))
4624 if ((float_argreg
& 1))
4628 /* Floating point arguments passed in registers have to be
4629 treated specially. On 32-bit architectures, doubles
4630 are passed in register pairs; the even register gets
4631 the low word, and the odd register gets the high word.
4632 On non-EABI processors, the first two floating point arguments are
4633 also copied to general registers, because MIPS16 functions
4634 don't use float registers for arguments. This duplication of
4635 arguments in general registers can't hurt non-MIPS16 functions
4636 because those registers are normally skipped. */
4637 /* MIPS_EABI squeezes a struct that contains a single floating
4638 point value into an FP register instead of pushing it onto the
4640 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
4641 && float_argreg
<= mips_last_fp_arg_regnum (gdbarch
))
4643 /* EABI32 will pass doubles in consecutive registers, even on
4644 64-bit cores. At one time, we used to check the size of
4645 `float_argreg' to determine whether or not to pass doubles
4646 in consecutive registers, but this is not sufficient for
4647 making the ABI determination. */
4648 if (len
== 8 && mips_abi (gdbarch
) == MIPS_ABI_EABI32
)
4650 int low_offset
= gdbarch_byte_order (gdbarch
)
4651 == BFD_ENDIAN_BIG
? 4 : 0;
4654 /* Write the low word of the double to the even register(s). */
4655 regval
= extract_signed_integer (val
+ low_offset
,
4658 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
4659 float_argreg
, phex (regval
, 4));
4660 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
4662 /* Write the high word of the double to the odd register(s). */
4663 regval
= extract_signed_integer (val
+ 4 - low_offset
,
4666 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
4667 float_argreg
, phex (regval
, 4));
4668 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
4672 /* This is a floating point value that fits entirely
4673 in a single register. */
4674 /* On 32 bit ABI's the float_argreg is further adjusted
4675 above to ensure that it is even register aligned. */
4676 LONGEST regval
= extract_signed_integer (val
, len
, byte_order
);
4678 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
4679 float_argreg
, phex (regval
, len
));
4680 regcache_cooked_write_signed (regcache
, float_argreg
++, regval
);
4685 /* Copy the argument to general registers or the stack in
4686 register-sized pieces. Large arguments are split between
4687 registers and stack. */
4688 /* Note: structs whose size is not a multiple of abi_regsize
4689 are treated specially: Irix cc passes
4690 them in registers where gcc sometimes puts them on the
4691 stack. For maximum compatibility, we will put them in
4693 int odd_sized_struct
= (len
> abi_regsize
&& len
% abi_regsize
!= 0);
4695 /* Note: Floating-point values that didn't fit into an FP
4696 register are only written to memory. */
4699 /* Remember if the argument was written to the stack. */
4700 int stack_used_p
= 0;
4701 int partial_len
= (len
< abi_regsize
? len
: abi_regsize
);
4704 gdb_printf (gdb_stdlog
, " -- partial=%d",
4707 /* Write this portion of the argument to the stack. */
4708 if (argreg
> mips_last_arg_regnum (gdbarch
)
4710 || fp_register_arg_p (gdbarch
, typecode
, arg_type
))
4712 /* Should shorter than int integer values be
4713 promoted to int before being stored? */
4714 int longword_offset
= 0;
4717 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
4719 if (abi_regsize
== 8
4720 && (typecode
== TYPE_CODE_INT
4721 || typecode
== TYPE_CODE_PTR
4722 || typecode
== TYPE_CODE_FLT
) && len
<= 4)
4723 longword_offset
= abi_regsize
- len
;
4724 else if ((typecode
== TYPE_CODE_STRUCT
4725 || typecode
== TYPE_CODE_UNION
)
4726 && arg_type
->length () < abi_regsize
)
4727 longword_offset
= abi_regsize
- len
;
4732 gdb_printf (gdb_stdlog
, " - stack_offset=%s",
4733 paddress (gdbarch
, stack_offset
));
4734 gdb_printf (gdb_stdlog
, " longword_offset=%s",
4735 paddress (gdbarch
, longword_offset
));
4738 addr
= sp
+ stack_offset
+ longword_offset
;
4743 gdb_printf (gdb_stdlog
, " @%s ",
4744 paddress (gdbarch
, addr
));
4745 for (i
= 0; i
< partial_len
; i
++)
4747 gdb_printf (gdb_stdlog
, "%02x",
4751 write_memory (addr
, val
, partial_len
);
4754 /* Note!!! This is NOT an else clause. Odd sized
4755 structs may go thru BOTH paths. Floating point
4756 arguments will not. */
4757 /* Write this portion of the argument to a general
4758 purpose register. */
4759 if (argreg
<= mips_last_arg_regnum (gdbarch
)
4760 && !fp_register_arg_p (gdbarch
, typecode
, arg_type
))
4763 extract_signed_integer (val
, partial_len
, byte_order
);
4766 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
4768 phex (regval
, abi_regsize
));
4769 regcache_cooked_write_signed (regcache
, argreg
, regval
);
4776 /* Compute the offset into the stack at which we will
4777 copy the next parameter.
4779 In the new EABI (and the NABI32), the stack_offset
4780 only needs to be adjusted when it has been used. */
4783 stack_offset
+= align_up (partial_len
, abi_regsize
);
4787 gdb_printf (gdb_stdlog
, "\n");
4790 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
4792 /* Return adjusted stack pointer. */
4796 /* Determine the return value convention being used. */
4798 static enum return_value_convention
4799 mips_eabi_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
4800 struct type
*type
, struct regcache
*regcache
,
4801 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
4803 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
4804 int fp_return_type
= 0;
4805 int offset
, regnum
, xfer
;
4807 if (type
->length () > 2 * mips_abi_regsize (gdbarch
))
4808 return RETURN_VALUE_STRUCT_CONVENTION
;
4810 /* Floating point type? */
4811 if (tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4813 if (type
->code () == TYPE_CODE_FLT
)
4815 /* Structs with a single field of float type
4816 are returned in a floating point register. */
4817 if ((type
->code () == TYPE_CODE_STRUCT
4818 || type
->code () == TYPE_CODE_UNION
)
4819 && type
->num_fields () == 1)
4821 struct type
*fieldtype
= type
->field (0).type ();
4823 if (check_typedef (fieldtype
)->code () == TYPE_CODE_FLT
)
4830 /* A floating-point value belongs in the least significant part
4833 gdb_printf (gdb_stderr
, "Return float in $fp0\n");
4834 regnum
= mips_regnum (gdbarch
)->fp0
;
4838 /* An integer value goes in V0/V1. */
4840 gdb_printf (gdb_stderr
, "Return scalar in $v0\n");
4841 regnum
= MIPS_V0_REGNUM
;
4844 offset
< type
->length ();
4845 offset
+= mips_abi_regsize (gdbarch
), regnum
++)
4847 xfer
= mips_abi_regsize (gdbarch
);
4848 if (offset
+ xfer
> type
->length ())
4849 xfer
= type
->length () - offset
;
4850 mips_xfer_register (gdbarch
, regcache
,
4851 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
4852 gdbarch_byte_order (gdbarch
), readbuf
, writebuf
,
4856 return RETURN_VALUE_REGISTER_CONVENTION
;
4860 /* N32/N64 ABI stuff. */
4862 /* Search for a naturally aligned double at OFFSET inside a struct
4863 ARG_TYPE. The N32 / N64 ABIs pass these in floating point
4867 mips_n32n64_fp_arg_chunk_p (struct gdbarch
*gdbarch
, struct type
*arg_type
,
4872 if (arg_type
->code () != TYPE_CODE_STRUCT
)
4875 if (mips_get_fpu_type (gdbarch
) != MIPS_FPU_DOUBLE
)
4878 if (arg_type
->length () < offset
+ MIPS64_REGSIZE
)
4881 for (i
= 0; i
< arg_type
->num_fields (); i
++)
4884 struct type
*field_type
;
4886 /* We're only looking at normal fields. */
4887 if (field_is_static (&arg_type
->field (i
))
4888 || (arg_type
->field (i
).loc_bitpos () % 8) != 0)
4891 /* If we have gone past the offset, there is no double to pass. */
4892 pos
= arg_type
->field (i
).loc_bitpos () / 8;
4896 field_type
= check_typedef (arg_type
->field (i
).type ());
4898 /* If this field is entirely before the requested offset, go
4899 on to the next one. */
4900 if (pos
+ field_type
->length () <= offset
)
4903 /* If this is our special aligned double, we can stop. */
4904 if (field_type
->code () == TYPE_CODE_FLT
4905 && field_type
->length () == MIPS64_REGSIZE
)
4908 /* This field starts at or before the requested offset, and
4909 overlaps it. If it is a structure, recurse inwards. */
4910 return mips_n32n64_fp_arg_chunk_p (gdbarch
, field_type
, offset
- pos
);
4917 mips_n32n64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
4918 struct regcache
*regcache
, CORE_ADDR bp_addr
,
4919 int nargs
, struct value
**args
, CORE_ADDR sp
,
4920 function_call_return_method return_method
,
4921 CORE_ADDR struct_addr
)
4927 int stack_offset
= 0;
4928 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4929 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
4931 /* For shared libraries, "t9" needs to point at the function
4933 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
4935 /* Set the return address register to point to the entry point of
4936 the program, where a breakpoint lies in wait. */
4937 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
4939 /* First ensure that the stack and structure return address (if any)
4940 are properly aligned. The stack has to be at least 64-bit
4941 aligned even on 32-bit machines, because doubles must be 64-bit
4942 aligned. For n32 and n64, stack frames need to be 128-bit
4943 aligned, so we round to this widest known alignment. */
4945 sp
= align_down (sp
, 16);
4946 struct_addr
= align_down (struct_addr
, 16);
4948 /* Now make space on the stack for the args. */
4949 for (argnum
= 0; argnum
< nargs
; argnum
++)
4950 arg_space
+= align_up (value_type (args
[argnum
])->length (),
4952 sp
-= align_up (arg_space
, 16);
4955 gdb_printf (gdb_stdlog
,
4956 "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n",
4957 paddress (gdbarch
, sp
),
4958 (long) align_up (arg_space
, 16));
4960 /* Initialize the integer and float register pointers. */
4961 argreg
= MIPS_A0_REGNUM
;
4962 float_argreg
= mips_fpa0_regnum (gdbarch
);
4964 /* The struct_return pointer occupies the first parameter-passing reg. */
4965 if (return_method
== return_method_struct
)
4968 gdb_printf (gdb_stdlog
,
4969 "mips_n32n64_push_dummy_call: "
4970 "struct_return reg=%d %s\n",
4971 argreg
, paddress (gdbarch
, struct_addr
));
4972 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
4975 /* Now load as many as possible of the first arguments into
4976 registers, and push the rest onto the stack. Loop thru args
4977 from first to last. */
4978 for (argnum
= 0; argnum
< nargs
; argnum
++)
4980 const gdb_byte
*val
;
4981 struct value
*arg
= args
[argnum
];
4982 struct type
*arg_type
= check_typedef (value_type (arg
));
4983 int len
= arg_type
->length ();
4984 enum type_code typecode
= arg_type
->code ();
4987 gdb_printf (gdb_stdlog
,
4988 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
4989 argnum
+ 1, len
, (int) typecode
);
4991 val
= value_contents (arg
).data ();
4993 /* A 128-bit long double value requires an even-odd pair of
4994 floating-point registers. */
4996 && fp_register_arg_p (gdbarch
, typecode
, arg_type
)
4997 && (float_argreg
& 1))
5003 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
5004 && argreg
<= mips_last_arg_regnum (gdbarch
))
5006 /* This is a floating point value that fits entirely
5007 in a single register or a pair of registers. */
5008 int reglen
= (len
<= MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
5009 LONGEST regval
= extract_unsigned_integer (val
, reglen
, byte_order
);
5011 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5012 float_argreg
, phex (regval
, reglen
));
5013 regcache_cooked_write_unsigned (regcache
, float_argreg
, regval
);
5016 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5017 argreg
, phex (regval
, reglen
));
5018 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
5023 regval
= extract_unsigned_integer (val
+ reglen
,
5024 reglen
, byte_order
);
5026 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5027 float_argreg
, phex (regval
, reglen
));
5028 regcache_cooked_write_unsigned (regcache
, float_argreg
, regval
);
5031 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5032 argreg
, phex (regval
, reglen
));
5033 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
5040 /* Copy the argument to general registers or the stack in
5041 register-sized pieces. Large arguments are split between
5042 registers and stack. */
5043 /* For N32/N64, structs, unions, or other composite types are
5044 treated as a sequence of doublewords, and are passed in integer
5045 or floating point registers as though they were simple scalar
5046 parameters to the extent that they fit, with any excess on the
5047 stack packed according to the normal memory layout of the
5049 The caller does not reserve space for the register arguments;
5050 the callee is responsible for reserving it if required. */
5051 /* Note: Floating-point values that didn't fit into an FP
5052 register are only written to memory. */
5055 /* Remember if the argument was written to the stack. */
5056 int stack_used_p
= 0;
5057 int partial_len
= (len
< MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
5060 gdb_printf (gdb_stdlog
, " -- partial=%d",
5063 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
))
5064 gdb_assert (argreg
> mips_last_arg_regnum (gdbarch
));
5066 /* Write this portion of the argument to the stack. */
5067 if (argreg
> mips_last_arg_regnum (gdbarch
))
5069 /* Should shorter than int integer values be
5070 promoted to int before being stored? */
5071 int longword_offset
= 0;
5074 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
5076 if ((typecode
== TYPE_CODE_INT
5077 || typecode
== TYPE_CODE_PTR
)
5079 longword_offset
= MIPS64_REGSIZE
- len
;
5084 gdb_printf (gdb_stdlog
, " - stack_offset=%s",
5085 paddress (gdbarch
, stack_offset
));
5086 gdb_printf (gdb_stdlog
, " longword_offset=%s",
5087 paddress (gdbarch
, longword_offset
));
5090 addr
= sp
+ stack_offset
+ longword_offset
;
5095 gdb_printf (gdb_stdlog
, " @%s ",
5096 paddress (gdbarch
, addr
));
5097 for (i
= 0; i
< partial_len
; i
++)
5099 gdb_printf (gdb_stdlog
, "%02x",
5103 write_memory (addr
, val
, partial_len
);
5106 /* Note!!! This is NOT an else clause. Odd sized
5107 structs may go thru BOTH paths. */
5108 /* Write this portion of the argument to a general
5109 purpose register. */
5110 if (argreg
<= mips_last_arg_regnum (gdbarch
))
5114 /* Sign extend pointers, 32-bit integers and signed
5115 16-bit and 8-bit integers; everything else is taken
5118 if ((partial_len
== 4
5119 && (typecode
== TYPE_CODE_PTR
5120 || typecode
== TYPE_CODE_INT
))
5122 && typecode
== TYPE_CODE_INT
5123 && !arg_type
->is_unsigned ()))
5124 regval
= extract_signed_integer (val
, partial_len
,
5127 regval
= extract_unsigned_integer (val
, partial_len
,
5130 /* A non-floating-point argument being passed in a
5131 general register. If a struct or union, and if
5132 the remaining length is smaller than the register
5133 size, we have to adjust the register value on
5136 It does not seem to be necessary to do the
5137 same for integral types. */
5139 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
5140 && partial_len
< MIPS64_REGSIZE
5141 && (typecode
== TYPE_CODE_STRUCT
5142 || typecode
== TYPE_CODE_UNION
))
5143 regval
<<= ((MIPS64_REGSIZE
- partial_len
)
5147 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5149 phex (regval
, MIPS64_REGSIZE
));
5150 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
5152 if (mips_n32n64_fp_arg_chunk_p (gdbarch
, arg_type
,
5153 arg_type
->length () - len
))
5156 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5158 phex (regval
, MIPS64_REGSIZE
));
5159 regcache_cooked_write_unsigned (regcache
, float_argreg
,
5170 /* Compute the offset into the stack at which we will
5171 copy the next parameter.
5173 In N32 (N64?), the stack_offset only needs to be
5174 adjusted when it has been used. */
5177 stack_offset
+= align_up (partial_len
, MIPS64_REGSIZE
);
5181 gdb_printf (gdb_stdlog
, "\n");
5184 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
5186 /* Return adjusted stack pointer. */
5190 static enum return_value_convention
5191 mips_n32n64_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
5192 struct type
*type
, struct regcache
*regcache
,
5193 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
5195 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
5197 /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
5199 Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
5200 if needed), as appropriate for the type. Composite results (struct,
5201 union, or array) are returned in $2/$f0 and $3/$f2 according to the
5204 * A struct with only one or two floating point fields is returned in $f0
5205 (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
5208 * Any other composite results of at most 128 bits are returned in
5209 $2 (first 64 bits) and $3 (remainder, if necessary).
5211 * Larger composite results are handled by converting the function to a
5212 procedure with an implicit first parameter, which is a pointer to an area
5213 reserved by the caller to receive the result. [The o32-bit ABI requires
5214 that all composite results be handled by conversion to implicit first
5215 parameters. The MIPS/SGI Fortran implementation has always made a
5216 specific exception to return COMPLEX results in the floating point
5219 From MIPSpro Assembly Language Programmer's Guide, Document Number:
5224 Name fgregdef.h) Use and Linkage
5225 -----------------------------------------------------------------
5226 $f0, $f2 fv0, fv1 Hold results of floating-point type function
5227 ($f0) and complex type function ($f0 has the
5228 real part, $f2 has the imaginary part.) */
5230 if (type
->length () > 2 * MIPS64_REGSIZE
)
5231 return RETURN_VALUE_STRUCT_CONVENTION
;
5232 else if ((type
->code () == TYPE_CODE_COMPLEX
5233 || (type
->code () == TYPE_CODE_FLT
&& type
->length () == 16))
5234 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
5236 /* A complex value of up to 128 bits in width as well as a 128-bit
5237 floating-point value goes in both $f0 and $f2. A single complex
5238 value is held in the lower halves only of the respective registers.
5239 The two registers are used in the same as memory order, so the
5240 bytes with the lower memory address are in $f0. */
5242 gdb_printf (gdb_stderr
, "Return float in $f0 and $f2\n");
5243 mips_xfer_register (gdbarch
, regcache
,
5244 (gdbarch_num_regs (gdbarch
)
5245 + mips_regnum (gdbarch
)->fp0
),
5246 type
->length () / 2, gdbarch_byte_order (gdbarch
),
5247 readbuf
, writebuf
, 0);
5248 mips_xfer_register (gdbarch
, regcache
,
5249 (gdbarch_num_regs (gdbarch
)
5250 + mips_regnum (gdbarch
)->fp0
+ 2),
5251 type
->length () / 2, gdbarch_byte_order (gdbarch
),
5252 readbuf
? readbuf
+ type
->length () / 2 : readbuf
,
5254 ? writebuf
+ type
->length () / 2 : writebuf
), 0);
5255 return RETURN_VALUE_REGISTER_CONVENTION
;
5257 else if (type
->code () == TYPE_CODE_FLT
5258 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
5260 /* A single or double floating-point value that fits in FP0. */
5262 gdb_printf (gdb_stderr
, "Return float in $fp0\n");
5263 mips_xfer_register (gdbarch
, regcache
,
5264 (gdbarch_num_regs (gdbarch
)
5265 + mips_regnum (gdbarch
)->fp0
),
5267 gdbarch_byte_order (gdbarch
),
5268 readbuf
, writebuf
, 0);
5269 return RETURN_VALUE_REGISTER_CONVENTION
;
5271 else if (type
->code () == TYPE_CODE_STRUCT
5272 && type
->num_fields () <= 2
5273 && type
->num_fields () >= 1
5274 && ((type
->num_fields () == 1
5275 && (check_typedef (type
->field (0).type ())->code ()
5277 || (type
->num_fields () == 2
5278 && (check_typedef (type
->field (0).type ())->code ()
5280 && (check_typedef (type
->field (1).type ())->code ()
5281 == TYPE_CODE_FLT
))))
5283 /* A struct that contains one or two floats. Each value is part
5284 in the least significant part of their floating point
5285 register (or GPR, for soft float). */
5288 for (field
= 0, regnum
= (tdep
->mips_fpu_type
!= MIPS_FPU_NONE
5289 ? mips_regnum (gdbarch
)->fp0
5291 field
< type
->num_fields (); field
++, regnum
+= 2)
5293 int offset
= type
->field (field
).loc_bitpos () / TARGET_CHAR_BIT
;
5295 gdb_printf (gdb_stderr
, "Return float struct+%d\n",
5297 if (type
->field (field
).type ()->length () == 16)
5299 /* A 16-byte long double field goes in two consecutive
5301 mips_xfer_register (gdbarch
, regcache
,
5302 gdbarch_num_regs (gdbarch
) + regnum
,
5304 gdbarch_byte_order (gdbarch
),
5305 readbuf
, writebuf
, offset
);
5306 mips_xfer_register (gdbarch
, regcache
,
5307 gdbarch_num_regs (gdbarch
) + regnum
+ 1,
5309 gdbarch_byte_order (gdbarch
),
5310 readbuf
, writebuf
, offset
+ 8);
5313 mips_xfer_register (gdbarch
, regcache
,
5314 gdbarch_num_regs (gdbarch
) + regnum
,
5315 type
->field (field
).type ()->length (),
5316 gdbarch_byte_order (gdbarch
),
5317 readbuf
, writebuf
, offset
);
5319 return RETURN_VALUE_REGISTER_CONVENTION
;
5321 else if (type
->code () == TYPE_CODE_STRUCT
5322 || type
->code () == TYPE_CODE_UNION
5323 || type
->code () == TYPE_CODE_ARRAY
)
5325 /* A composite type. Extract the left justified value,
5326 regardless of the byte order. I.e. DO NOT USE
5330 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
5331 offset
< type
->length ();
5332 offset
+= register_size (gdbarch
, regnum
), regnum
++)
5334 int xfer
= register_size (gdbarch
, regnum
);
5335 if (offset
+ xfer
> type
->length ())
5336 xfer
= type
->length () - offset
;
5338 gdb_printf (gdb_stderr
, "Return struct+%d:%d in $%d\n",
5339 offset
, xfer
, regnum
);
5340 mips_xfer_register (gdbarch
, regcache
,
5341 gdbarch_num_regs (gdbarch
) + regnum
,
5342 xfer
, BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
,
5345 return RETURN_VALUE_REGISTER_CONVENTION
;
5349 /* A scalar extract each part but least-significant-byte
5353 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
5354 offset
< type
->length ();
5355 offset
+= register_size (gdbarch
, regnum
), regnum
++)
5357 int xfer
= register_size (gdbarch
, regnum
);
5358 if (offset
+ xfer
> type
->length ())
5359 xfer
= type
->length () - offset
;
5361 gdb_printf (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
5362 offset
, xfer
, regnum
);
5363 mips_xfer_register (gdbarch
, regcache
,
5364 gdbarch_num_regs (gdbarch
) + regnum
,
5365 xfer
, gdbarch_byte_order (gdbarch
),
5366 readbuf
, writebuf
, offset
);
5368 return RETURN_VALUE_REGISTER_CONVENTION
;
5372 /* Which registers to use for passing floating-point values between
5373 function calls, one of floating-point, general and both kinds of
5374 registers. O32 and O64 use different register kinds for standard
5375 MIPS and MIPS16 code; to make the handling of cases where we may
5376 not know what kind of code is being used (e.g. no debug information)
5377 easier we sometimes use both kinds. */
5386 /* O32 ABI stuff. */
5389 mips_o32_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
5390 struct regcache
*regcache
, CORE_ADDR bp_addr
,
5391 int nargs
, struct value
**args
, CORE_ADDR sp
,
5392 function_call_return_method return_method
,
5393 CORE_ADDR struct_addr
)
5399 int stack_offset
= 0;
5400 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5401 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
5403 /* For shared libraries, "t9" needs to point at the function
5405 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
5407 /* Set the return address register to point to the entry point of
5408 the program, where a breakpoint lies in wait. */
5409 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
5411 /* First ensure that the stack and structure return address (if any)
5412 are properly aligned. The stack has to be at least 64-bit
5413 aligned even on 32-bit machines, because doubles must be 64-bit
5414 aligned. For n32 and n64, stack frames need to be 128-bit
5415 aligned, so we round to this widest known alignment. */
5417 sp
= align_down (sp
, 16);
5418 struct_addr
= align_down (struct_addr
, 16);
5420 /* Now make space on the stack for the args. */
5421 for (argnum
= 0; argnum
< nargs
; argnum
++)
5423 struct type
*arg_type
= check_typedef (value_type (args
[argnum
]));
5425 /* Align to double-word if necessary. */
5426 if (mips_type_needs_double_align (arg_type
))
5427 arg_space
= align_up (arg_space
, MIPS32_REGSIZE
* 2);
5428 /* Allocate space on the stack. */
5429 arg_space
+= align_up (arg_type
->length (), MIPS32_REGSIZE
);
5431 sp
-= align_up (arg_space
, 16);
5434 gdb_printf (gdb_stdlog
,
5435 "mips_o32_push_dummy_call: sp=%s allocated %ld\n",
5436 paddress (gdbarch
, sp
),
5437 (long) align_up (arg_space
, 16));
5439 /* Initialize the integer and float register pointers. */
5440 argreg
= MIPS_A0_REGNUM
;
5441 float_argreg
= mips_fpa0_regnum (gdbarch
);
5443 /* The struct_return pointer occupies the first parameter-passing reg. */
5444 if (return_method
== return_method_struct
)
5447 gdb_printf (gdb_stdlog
,
5448 "mips_o32_push_dummy_call: "
5449 "struct_return reg=%d %s\n",
5450 argreg
, paddress (gdbarch
, struct_addr
));
5451 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
5452 stack_offset
+= MIPS32_REGSIZE
;
5455 /* Now load as many as possible of the first arguments into
5456 registers, and push the rest onto the stack. Loop thru args
5457 from first to last. */
5458 for (argnum
= 0; argnum
< nargs
; argnum
++)
5460 const gdb_byte
*val
;
5461 struct value
*arg
= args
[argnum
];
5462 struct type
*arg_type
= check_typedef (value_type (arg
));
5463 int len
= arg_type
->length ();
5464 enum type_code typecode
= arg_type
->code ();
5467 gdb_printf (gdb_stdlog
,
5468 "mips_o32_push_dummy_call: %d len=%d type=%d",
5469 argnum
+ 1, len
, (int) typecode
);
5471 val
= value_contents (arg
).data ();
5473 /* 32-bit ABIs always start floating point arguments in an
5474 even-numbered floating point register. Round the FP register
5475 up before the check to see if there are any FP registers
5476 left. O32 targets also pass the FP in the integer registers
5477 so also round up normal registers. */
5478 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
))
5480 if ((float_argreg
& 1))
5484 /* Floating point arguments passed in registers have to be
5485 treated specially. On 32-bit architectures, doubles are
5486 passed in register pairs; the even FP register gets the
5487 low word, and the odd FP register gets the high word.
5488 On O32, the first two floating point arguments are also
5489 copied to general registers, following their memory order,
5490 because MIPS16 functions don't use float registers for
5491 arguments. This duplication of arguments in general
5492 registers can't hurt non-MIPS16 functions, because those
5493 registers are normally skipped. */
5495 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
5496 && float_argreg
<= mips_last_fp_arg_regnum (gdbarch
))
5498 if (register_size (gdbarch
, float_argreg
) < 8 && len
== 8)
5500 int freg_offset
= gdbarch_byte_order (gdbarch
)
5501 == BFD_ENDIAN_BIG
? 1 : 0;
5502 unsigned long regval
;
5505 regval
= extract_unsigned_integer (val
, 4, byte_order
);
5507 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5508 float_argreg
+ freg_offset
,
5510 regcache_cooked_write_unsigned (regcache
,
5511 float_argreg
++ + freg_offset
,
5514 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5515 argreg
, phex (regval
, 4));
5516 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
5519 regval
= extract_unsigned_integer (val
+ 4, 4, byte_order
);
5521 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5522 float_argreg
- freg_offset
,
5524 regcache_cooked_write_unsigned (regcache
,
5525 float_argreg
++ - freg_offset
,
5528 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5529 argreg
, phex (regval
, 4));
5530 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
5534 /* This is a floating point value that fits entirely
5535 in a single register. */
5536 /* On 32 bit ABI's the float_argreg is further adjusted
5537 above to ensure that it is even register aligned. */
5538 LONGEST regval
= extract_unsigned_integer (val
, len
, byte_order
);
5540 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
5541 float_argreg
, phex (regval
, len
));
5542 regcache_cooked_write_unsigned (regcache
,
5543 float_argreg
++, regval
);
5544 /* Although two FP registers are reserved for each
5545 argument, only one corresponding integer register is
5548 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5549 argreg
, phex (regval
, len
));
5550 regcache_cooked_write_unsigned (regcache
, argreg
++, regval
);
5552 /* Reserve space for the FP register. */
5553 stack_offset
+= align_up (len
, MIPS32_REGSIZE
);
5557 /* Copy the argument to general registers or the stack in
5558 register-sized pieces. Large arguments are split between
5559 registers and stack. */
5560 /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
5561 are treated specially: Irix cc passes
5562 them in registers where gcc sometimes puts them on the
5563 stack. For maximum compatibility, we will put them in
5565 int odd_sized_struct
= (len
> MIPS32_REGSIZE
5566 && len
% MIPS32_REGSIZE
!= 0);
5567 /* Structures should be aligned to eight bytes (even arg registers)
5568 on MIPS_ABI_O32, if their first member has double precision. */
5569 if (mips_type_needs_double_align (arg_type
))
5574 stack_offset
+= MIPS32_REGSIZE
;
5579 int partial_len
= (len
< MIPS32_REGSIZE
? len
: MIPS32_REGSIZE
);
5582 gdb_printf (gdb_stdlog
, " -- partial=%d",
5585 /* Write this portion of the argument to the stack. */
5586 if (argreg
> mips_last_arg_regnum (gdbarch
)
5587 || odd_sized_struct
)
5589 /* Should shorter than int integer values be
5590 promoted to int before being stored? */
5591 int longword_offset
= 0;
5596 gdb_printf (gdb_stdlog
, " - stack_offset=%s",
5597 paddress (gdbarch
, stack_offset
));
5598 gdb_printf (gdb_stdlog
, " longword_offset=%s",
5599 paddress (gdbarch
, longword_offset
));
5602 addr
= sp
+ stack_offset
+ longword_offset
;
5607 gdb_printf (gdb_stdlog
, " @%s ",
5608 paddress (gdbarch
, addr
));
5609 for (i
= 0; i
< partial_len
; i
++)
5611 gdb_printf (gdb_stdlog
, "%02x",
5615 write_memory (addr
, val
, partial_len
);
5618 /* Note!!! This is NOT an else clause. Odd sized
5619 structs may go thru BOTH paths. */
5620 /* Write this portion of the argument to a general
5621 purpose register. */
5622 if (argreg
<= mips_last_arg_regnum (gdbarch
))
5624 LONGEST regval
= extract_signed_integer (val
, partial_len
,
5626 /* Value may need to be sign extended, because
5627 mips_isa_regsize() != mips_abi_regsize(). */
5629 /* A non-floating-point argument being passed in a
5630 general register. If a struct or union, and if
5631 the remaining length is smaller than the register
5632 size, we have to adjust the register value on
5635 It does not seem to be necessary to do the
5636 same for integral types.
5638 Also don't do this adjustment on O64 binaries.
5640 cagney/2001-07-23: gdb/179: Also, GCC, when
5641 outputting LE O32 with sizeof (struct) <
5642 mips_abi_regsize(), generates a left shift
5643 as part of storing the argument in a register
5644 (the left shift isn't generated when
5645 sizeof (struct) >= mips_abi_regsize()). Since
5646 it is quite possible that this is GCC
5647 contradicting the LE/O32 ABI, GDB has not been
5648 adjusted to accommodate this. Either someone
5649 needs to demonstrate that the LE/O32 ABI
5650 specifies such a left shift OR this new ABI gets
5651 identified as such and GDB gets tweaked
5654 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
5655 && partial_len
< MIPS32_REGSIZE
5656 && (typecode
== TYPE_CODE_STRUCT
5657 || typecode
== TYPE_CODE_UNION
))
5658 regval
<<= ((MIPS32_REGSIZE
- partial_len
)
5662 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
5664 phex (regval
, MIPS32_REGSIZE
));
5665 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
5668 /* Prevent subsequent floating point arguments from
5669 being passed in floating point registers. */
5670 float_argreg
= mips_last_fp_arg_regnum (gdbarch
) + 1;
5676 /* Compute the offset into the stack at which we will
5677 copy the next parameter.
5679 In older ABIs, the caller reserved space for
5680 registers that contained arguments. This was loosely
5681 refered to as their "home". Consequently, space is
5682 always allocated. */
5684 stack_offset
+= align_up (partial_len
, MIPS32_REGSIZE
);
5688 gdb_printf (gdb_stdlog
, "\n");
5691 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
5693 /* Return adjusted stack pointer. */
5697 static enum return_value_convention
5698 mips_o32_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
5699 struct type
*type
, struct regcache
*regcache
,
5700 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
5702 CORE_ADDR func_addr
= function
? find_function_addr (function
, NULL
) : 0;
5703 int mips16
= mips_pc_is_mips16 (gdbarch
, func_addr
);
5704 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
5705 enum mips_fval_reg fval_reg
;
5707 fval_reg
= readbuf
? mips16
? mips_fval_gpr
: mips_fval_fpr
: mips_fval_both
;
5708 if (type
->code () == TYPE_CODE_STRUCT
5709 || type
->code () == TYPE_CODE_UNION
5710 || type
->code () == TYPE_CODE_ARRAY
)
5711 return RETURN_VALUE_STRUCT_CONVENTION
;
5712 else if (type
->code () == TYPE_CODE_FLT
5713 && type
->length () == 4 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
5715 /* A single-precision floating-point value. If reading in or copying,
5716 then we get it from/put it to FP0 for standard MIPS code or GPR2
5717 for MIPS16 code. If writing out only, then we put it to both FP0
5718 and GPR2. We do not support reading in with no function known, if
5719 this safety check ever triggers, then we'll have to try harder. */
5720 gdb_assert (function
|| !readbuf
);
5725 gdb_printf (gdb_stderr
, "Return float in $fp0\n");
5728 gdb_printf (gdb_stderr
, "Return float in $2\n");
5730 case mips_fval_both
:
5731 gdb_printf (gdb_stderr
, "Return float in $fp0 and $2\n");
5734 if (fval_reg
!= mips_fval_gpr
)
5735 mips_xfer_register (gdbarch
, regcache
,
5736 (gdbarch_num_regs (gdbarch
)
5737 + mips_regnum (gdbarch
)->fp0
),
5739 gdbarch_byte_order (gdbarch
),
5740 readbuf
, writebuf
, 0);
5741 if (fval_reg
!= mips_fval_fpr
)
5742 mips_xfer_register (gdbarch
, regcache
,
5743 gdbarch_num_regs (gdbarch
) + 2,
5745 gdbarch_byte_order (gdbarch
),
5746 readbuf
, writebuf
, 0);
5747 return RETURN_VALUE_REGISTER_CONVENTION
;
5749 else if (type
->code () == TYPE_CODE_FLT
5750 && type
->length () == 8 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
5752 /* A double-precision floating-point value. If reading in or copying,
5753 then we get it from/put it to FP1 and FP0 for standard MIPS code or
5754 GPR2 and GPR3 for MIPS16 code. If writing out only, then we put it
5755 to both FP1/FP0 and GPR2/GPR3. We do not support reading in with
5756 no function known, if this safety check ever triggers, then we'll
5757 have to try harder. */
5758 gdb_assert (function
|| !readbuf
);
5763 gdb_printf (gdb_stderr
, "Return float in $fp1/$fp0\n");
5766 gdb_printf (gdb_stderr
, "Return float in $2/$3\n");
5768 case mips_fval_both
:
5769 gdb_printf (gdb_stderr
,
5770 "Return float in $fp1/$fp0 and $2/$3\n");
5773 if (fval_reg
!= mips_fval_gpr
)
5775 /* The most significant part goes in FP1, and the least significant
5777 switch (gdbarch_byte_order (gdbarch
))
5779 case BFD_ENDIAN_LITTLE
:
5780 mips_xfer_register (gdbarch
, regcache
,
5781 (gdbarch_num_regs (gdbarch
)
5782 + mips_regnum (gdbarch
)->fp0
+ 0),
5783 4, gdbarch_byte_order (gdbarch
),
5784 readbuf
, writebuf
, 0);
5785 mips_xfer_register (gdbarch
, regcache
,
5786 (gdbarch_num_regs (gdbarch
)
5787 + mips_regnum (gdbarch
)->fp0
+ 1),
5788 4, gdbarch_byte_order (gdbarch
),
5789 readbuf
, writebuf
, 4);
5791 case BFD_ENDIAN_BIG
:
5792 mips_xfer_register (gdbarch
, regcache
,
5793 (gdbarch_num_regs (gdbarch
)
5794 + mips_regnum (gdbarch
)->fp0
+ 1),
5795 4, gdbarch_byte_order (gdbarch
),
5796 readbuf
, writebuf
, 0);
5797 mips_xfer_register (gdbarch
, regcache
,
5798 (gdbarch_num_regs (gdbarch
)
5799 + mips_regnum (gdbarch
)->fp0
+ 0),
5800 4, gdbarch_byte_order (gdbarch
),
5801 readbuf
, writebuf
, 4);
5804 internal_error (_("bad switch"));
5807 if (fval_reg
!= mips_fval_fpr
)
5809 /* The two 32-bit parts are always placed in GPR2 and GPR3
5810 following these registers' memory order. */
5811 mips_xfer_register (gdbarch
, regcache
,
5812 gdbarch_num_regs (gdbarch
) + 2,
5813 4, gdbarch_byte_order (gdbarch
),
5814 readbuf
, writebuf
, 0);
5815 mips_xfer_register (gdbarch
, regcache
,
5816 gdbarch_num_regs (gdbarch
) + 3,
5817 4, gdbarch_byte_order (gdbarch
),
5818 readbuf
, writebuf
, 4);
5820 return RETURN_VALUE_REGISTER_CONVENTION
;
5823 else if (type
->code () == TYPE_CODE_STRUCT
5824 && type
->num_fields () <= 2
5825 && type
->num_fields () >= 1
5826 && ((type
->num_fields () == 1
5827 && (TYPE_CODE (type
->field (0).type ())
5829 || (type
->num_fields () == 2
5830 && (TYPE_CODE (type
->field (0).type ())
5832 && (TYPE_CODE (type
->field (1).type ())
5834 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
5836 /* A struct that contains one or two floats. Each value is part
5837 in the least significant part of their floating point
5841 for (field
= 0, regnum
= mips_regnum (gdbarch
)->fp0
;
5842 field
< type
->num_fields (); field
++, regnum
+= 2)
5844 int offset
= (type
->fields ()[field
].loc_bitpos () / TARGET_CHAR_BIT
);
5846 gdb_printf (gdb_stderr
, "Return float struct+%d\n",
5848 mips_xfer_register (gdbarch
, regcache
,
5849 gdbarch_num_regs (gdbarch
) + regnum
,
5850 TYPE_LENGTH (type
->field (field
).type ()),
5851 gdbarch_byte_order (gdbarch
),
5852 readbuf
, writebuf
, offset
);
5854 return RETURN_VALUE_REGISTER_CONVENTION
;
5858 else if (type
->code () == TYPE_CODE_STRUCT
5859 || type
->code () == TYPE_CODE_UNION
)
5861 /* A structure or union. Extract the left justified value,
5862 regardless of the byte order. I.e. DO NOT USE
5866 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
5867 offset
< type
->length ();
5868 offset
+= register_size (gdbarch
, regnum
), regnum
++)
5870 int xfer
= register_size (gdbarch
, regnum
);
5871 if (offset
+ xfer
> type
->length ())
5872 xfer
= type
->length () - offset
;
5874 gdb_printf (gdb_stderr
, "Return struct+%d:%d in $%d\n",
5875 offset
, xfer
, regnum
);
5876 mips_xfer_register (gdbarch
, regcache
,
5877 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
5878 BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
, offset
);
5880 return RETURN_VALUE_REGISTER_CONVENTION
;
5885 /* A scalar extract each part but least-significant-byte
5886 justified. o32 thinks registers are 4 byte, regardless of
5890 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
5891 offset
< type
->length ();
5892 offset
+= MIPS32_REGSIZE
, regnum
++)
5894 int xfer
= MIPS32_REGSIZE
;
5895 if (offset
+ xfer
> type
->length ())
5896 xfer
= type
->length () - offset
;
5898 gdb_printf (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
5899 offset
, xfer
, regnum
);
5900 mips_xfer_register (gdbarch
, regcache
,
5901 gdbarch_num_regs (gdbarch
) + regnum
, xfer
,
5902 gdbarch_byte_order (gdbarch
),
5903 readbuf
, writebuf
, offset
);
5905 return RETURN_VALUE_REGISTER_CONVENTION
;
5909 /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
5913 mips_o64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
5914 struct regcache
*regcache
, CORE_ADDR bp_addr
,
5916 struct value
**args
, CORE_ADDR sp
,
5917 function_call_return_method return_method
, CORE_ADDR struct_addr
)
5923 int stack_offset
= 0;
5924 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5925 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
5927 /* For shared libraries, "t9" needs to point at the function
5929 regcache_cooked_write_signed (regcache
, MIPS_T9_REGNUM
, func_addr
);
5931 /* Set the return address register to point to the entry point of
5932 the program, where a breakpoint lies in wait. */
5933 regcache_cooked_write_signed (regcache
, MIPS_RA_REGNUM
, bp_addr
);
5935 /* First ensure that the stack and structure return address (if any)
5936 are properly aligned. The stack has to be at least 64-bit
5937 aligned even on 32-bit machines, because doubles must be 64-bit
5938 aligned. For n32 and n64, stack frames need to be 128-bit
5939 aligned, so we round to this widest known alignment. */
5941 sp
= align_down (sp
, 16);
5942 struct_addr
= align_down (struct_addr
, 16);
5944 /* Now make space on the stack for the args. */
5945 for (argnum
= 0; argnum
< nargs
; argnum
++)
5947 struct type
*arg_type
= check_typedef (value_type (args
[argnum
]));
5949 /* Allocate space on the stack. */
5950 arg_space
+= align_up (arg_type
->length (), MIPS64_REGSIZE
);
5952 sp
-= align_up (arg_space
, 16);
5955 gdb_printf (gdb_stdlog
,
5956 "mips_o64_push_dummy_call: sp=%s allocated %ld\n",
5957 paddress (gdbarch
, sp
),
5958 (long) align_up (arg_space
, 16));
5960 /* Initialize the integer and float register pointers. */
5961 argreg
= MIPS_A0_REGNUM
;
5962 float_argreg
= mips_fpa0_regnum (gdbarch
);
5964 /* The struct_return pointer occupies the first parameter-passing reg. */
5965 if (return_method
== return_method_struct
)
5968 gdb_printf (gdb_stdlog
,
5969 "mips_o64_push_dummy_call: "
5970 "struct_return reg=%d %s\n",
5971 argreg
, paddress (gdbarch
, struct_addr
));
5972 regcache_cooked_write_unsigned (regcache
, argreg
++, struct_addr
);
5973 stack_offset
+= MIPS64_REGSIZE
;
5976 /* Now load as many as possible of the first arguments into
5977 registers, and push the rest onto the stack. Loop thru args
5978 from first to last. */
5979 for (argnum
= 0; argnum
< nargs
; argnum
++)
5981 const gdb_byte
*val
;
5982 struct value
*arg
= args
[argnum
];
5983 struct type
*arg_type
= check_typedef (value_type (arg
));
5984 int len
= arg_type
->length ();
5985 enum type_code typecode
= arg_type
->code ();
5988 gdb_printf (gdb_stdlog
,
5989 "mips_o64_push_dummy_call: %d len=%d type=%d",
5990 argnum
+ 1, len
, (int) typecode
);
5992 val
= value_contents (arg
).data ();
5994 /* Floating point arguments passed in registers have to be
5995 treated specially. On 32-bit architectures, doubles are
5996 passed in register pairs; the even FP register gets the
5997 low word, and the odd FP register gets the high word.
5998 On O64, the first two floating point arguments are also
5999 copied to general registers, because MIPS16 functions
6000 don't use float registers for arguments. This duplication
6001 of arguments in general registers can't hurt non-MIPS16
6002 functions because those registers are normally skipped. */
6004 if (fp_register_arg_p (gdbarch
, typecode
, arg_type
)
6005 && float_argreg
<= mips_last_fp_arg_regnum (gdbarch
))
6007 LONGEST regval
= extract_unsigned_integer (val
, len
, byte_order
);
6009 gdb_printf (gdb_stdlog
, " - fpreg=%d val=%s",
6010 float_argreg
, phex (regval
, len
));
6011 regcache_cooked_write_unsigned (regcache
, float_argreg
++, regval
);
6013 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
6014 argreg
, phex (regval
, len
));
6015 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
6017 /* Reserve space for the FP register. */
6018 stack_offset
+= align_up (len
, MIPS64_REGSIZE
);
6022 /* Copy the argument to general registers or the stack in
6023 register-sized pieces. Large arguments are split between
6024 registers and stack. */
6025 /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
6026 are treated specially: Irix cc passes them in registers
6027 where gcc sometimes puts them on the stack. For maximum
6028 compatibility, we will put them in both places. */
6029 int odd_sized_struct
= (len
> MIPS64_REGSIZE
6030 && len
% MIPS64_REGSIZE
!= 0);
6033 int partial_len
= (len
< MIPS64_REGSIZE
? len
: MIPS64_REGSIZE
);
6036 gdb_printf (gdb_stdlog
, " -- partial=%d",
6039 /* Write this portion of the argument to the stack. */
6040 if (argreg
> mips_last_arg_regnum (gdbarch
)
6041 || odd_sized_struct
)
6043 /* Should shorter than int integer values be
6044 promoted to int before being stored? */
6045 int longword_offset
= 0;
6047 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
6049 if ((typecode
== TYPE_CODE_INT
6050 || typecode
== TYPE_CODE_PTR
6051 || typecode
== TYPE_CODE_FLT
)
6053 longword_offset
= MIPS64_REGSIZE
- len
;
6058 gdb_printf (gdb_stdlog
, " - stack_offset=%s",
6059 paddress (gdbarch
, stack_offset
));
6060 gdb_printf (gdb_stdlog
, " longword_offset=%s",
6061 paddress (gdbarch
, longword_offset
));
6064 addr
= sp
+ stack_offset
+ longword_offset
;
6069 gdb_printf (gdb_stdlog
, " @%s ",
6070 paddress (gdbarch
, addr
));
6071 for (i
= 0; i
< partial_len
; i
++)
6073 gdb_printf (gdb_stdlog
, "%02x",
6077 write_memory (addr
, val
, partial_len
);
6080 /* Note!!! This is NOT an else clause. Odd sized
6081 structs may go thru BOTH paths. */
6082 /* Write this portion of the argument to a general
6083 purpose register. */
6084 if (argreg
<= mips_last_arg_regnum (gdbarch
))
6086 LONGEST regval
= extract_signed_integer (val
, partial_len
,
6088 /* Value may need to be sign extended, because
6089 mips_isa_regsize() != mips_abi_regsize(). */
6091 /* A non-floating-point argument being passed in a
6092 general register. If a struct or union, and if
6093 the remaining length is smaller than the register
6094 size, we have to adjust the register value on
6097 It does not seem to be necessary to do the
6098 same for integral types. */
6100 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
6101 && partial_len
< MIPS64_REGSIZE
6102 && (typecode
== TYPE_CODE_STRUCT
6103 || typecode
== TYPE_CODE_UNION
))
6104 regval
<<= ((MIPS64_REGSIZE
- partial_len
)
6108 gdb_printf (gdb_stdlog
, " - reg=%d val=%s",
6110 phex (regval
, MIPS64_REGSIZE
));
6111 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
6114 /* Prevent subsequent floating point arguments from
6115 being passed in floating point registers. */
6116 float_argreg
= mips_last_fp_arg_regnum (gdbarch
) + 1;
6122 /* Compute the offset into the stack at which we will
6123 copy the next parameter.
6125 In older ABIs, the caller reserved space for
6126 registers that contained arguments. This was loosely
6127 refered to as their "home". Consequently, space is
6128 always allocated. */
6130 stack_offset
+= align_up (partial_len
, MIPS64_REGSIZE
);
6134 gdb_printf (gdb_stdlog
, "\n");
6137 regcache_cooked_write_signed (regcache
, MIPS_SP_REGNUM
, sp
);
6139 /* Return adjusted stack pointer. */
6143 static enum return_value_convention
6144 mips_o64_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
6145 struct type
*type
, struct regcache
*regcache
,
6146 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
6148 CORE_ADDR func_addr
= function
? find_function_addr (function
, NULL
) : 0;
6149 int mips16
= mips_pc_is_mips16 (gdbarch
, func_addr
);
6150 enum mips_fval_reg fval_reg
;
6152 fval_reg
= readbuf
? mips16
? mips_fval_gpr
: mips_fval_fpr
: mips_fval_both
;
6153 if (type
->code () == TYPE_CODE_STRUCT
6154 || type
->code () == TYPE_CODE_UNION
6155 || type
->code () == TYPE_CODE_ARRAY
)
6156 return RETURN_VALUE_STRUCT_CONVENTION
;
6157 else if (fp_register_arg_p (gdbarch
, type
->code (), type
))
6159 /* A floating-point value. If reading in or copying, then we get it
6160 from/put it to FP0 for standard MIPS code or GPR2 for MIPS16 code.
6161 If writing out only, then we put it to both FP0 and GPR2. We do
6162 not support reading in with no function known, if this safety
6163 check ever triggers, then we'll have to try harder. */
6164 gdb_assert (function
|| !readbuf
);
6169 gdb_printf (gdb_stderr
, "Return float in $fp0\n");
6172 gdb_printf (gdb_stderr
, "Return float in $2\n");
6174 case mips_fval_both
:
6175 gdb_printf (gdb_stderr
, "Return float in $fp0 and $2\n");
6178 if (fval_reg
!= mips_fval_gpr
)
6179 mips_xfer_register (gdbarch
, regcache
,
6180 (gdbarch_num_regs (gdbarch
)
6181 + mips_regnum (gdbarch
)->fp0
),
6183 gdbarch_byte_order (gdbarch
),
6184 readbuf
, writebuf
, 0);
6185 if (fval_reg
!= mips_fval_fpr
)
6186 mips_xfer_register (gdbarch
, regcache
,
6187 gdbarch_num_regs (gdbarch
) + 2,
6189 gdbarch_byte_order (gdbarch
),
6190 readbuf
, writebuf
, 0);
6191 return RETURN_VALUE_REGISTER_CONVENTION
;
6195 /* A scalar extract each part but least-significant-byte
6199 for (offset
= 0, regnum
= MIPS_V0_REGNUM
;
6200 offset
< type
->length ();
6201 offset
+= MIPS64_REGSIZE
, regnum
++)
6203 int xfer
= MIPS64_REGSIZE
;
6204 if (offset
+ xfer
> type
->length ())
6205 xfer
= type
->length () - offset
;
6207 gdb_printf (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
6208 offset
, xfer
, regnum
);
6209 mips_xfer_register (gdbarch
, regcache
,
6210 gdbarch_num_regs (gdbarch
) + regnum
,
6211 xfer
, gdbarch_byte_order (gdbarch
),
6212 readbuf
, writebuf
, offset
);
6214 return RETURN_VALUE_REGISTER_CONVENTION
;
6218 /* Floating point register management.
6220 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
6221 64bit operations, these early MIPS cpus treat fp register pairs
6222 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
6223 registers and offer a compatibility mode that emulates the MIPS2 fp
6224 model. When operating in MIPS2 fp compat mode, later cpu's split
6225 double precision floats into two 32-bit chunks and store them in
6226 consecutive fp regs. To display 64-bit floats stored in this
6227 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
6228 Throw in user-configurable endianness and you have a real mess.
6230 The way this works is:
6231 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
6232 double-precision value will be split across two logical registers.
6233 The lower-numbered logical register will hold the low-order bits,
6234 regardless of the processor's endianness.
6235 - If we are on a 64-bit processor, and we are looking for a
6236 single-precision value, it will be in the low ordered bits
6237 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
6238 save slot in memory.
6239 - If we are in 64-bit mode, everything is straightforward.
6241 Note that this code only deals with "live" registers at the top of the
6242 stack. We will attempt to deal with saved registers later, when
6243 the raw/cooked register interface is in place. (We need a general
6244 interface that can deal with dynamic saved register sizes -- fp
6245 regs could be 32 bits wide in one frame and 64 on the frame above
6248 /* Copy a 32-bit single-precision value from the current frame
6249 into rare_buffer. */
6252 mips_read_fp_register_single (frame_info_ptr frame
, int regno
,
6253 gdb_byte
*rare_buffer
)
6255 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
6256 int raw_size
= register_size (gdbarch
, regno
);
6257 gdb_byte
*raw_buffer
= (gdb_byte
*) alloca (raw_size
);
6259 if (!deprecated_frame_register_read (frame
, regno
, raw_buffer
))
6260 error (_("can't read register %d (%s)"),
6261 regno
, gdbarch_register_name (gdbarch
, regno
));
6264 /* We have a 64-bit value for this register. Find the low-order
6268 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
6273 memcpy (rare_buffer
, raw_buffer
+ offset
, 4);
6277 memcpy (rare_buffer
, raw_buffer
, 4);
6281 /* Copy a 64-bit double-precision value from the current frame into
6282 rare_buffer. This may include getting half of it from the next
6286 mips_read_fp_register_double (frame_info_ptr frame
, int regno
,
6287 gdb_byte
*rare_buffer
)
6289 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
6290 int raw_size
= register_size (gdbarch
, regno
);
6292 if (raw_size
== 8 && !mips2_fp_compat (frame
))
6294 /* We have a 64-bit value for this register, and we should use
6296 if (!deprecated_frame_register_read (frame
, regno
, rare_buffer
))
6297 error (_("can't read register %d (%s)"),
6298 regno
, gdbarch_register_name (gdbarch
, regno
));
6302 int rawnum
= regno
% gdbarch_num_regs (gdbarch
);
6304 if ((rawnum
- mips_regnum (gdbarch
)->fp0
) & 1)
6305 internal_error (_("mips_read_fp_register_double: bad access to "
6306 "odd-numbered FP register"));
6308 /* mips_read_fp_register_single will find the correct 32 bits from
6310 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
6312 mips_read_fp_register_single (frame
, regno
, rare_buffer
+ 4);
6313 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
);
6317 mips_read_fp_register_single (frame
, regno
, rare_buffer
);
6318 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
+ 4);
6324 mips_print_fp_register (struct ui_file
*file
, frame_info_ptr frame
,
6326 { /* Do values for FP (float) regs. */
6327 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
6328 gdb_byte
*raw_buffer
;
6329 std::string flt_str
, dbl_str
;
6331 const struct type
*flt_type
= builtin_type (gdbarch
)->builtin_float
;
6332 const struct type
*dbl_type
= builtin_type (gdbarch
)->builtin_double
;
6336 alloca (2 * register_size (gdbarch
, mips_regnum (gdbarch
)->fp0
)));
6338 gdb_printf (file
, "%s:", gdbarch_register_name (gdbarch
, regnum
));
6339 gdb_printf (file
, "%*s",
6340 4 - (int) strlen (gdbarch_register_name (gdbarch
, regnum
)),
6343 if (register_size (gdbarch
, regnum
) == 4 || mips2_fp_compat (frame
))
6345 struct value_print_options opts
;
6347 /* 4-byte registers: Print hex and floating. Also print even
6348 numbered registers as doubles. */
6349 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
6350 flt_str
= target_float_to_string (raw_buffer
, flt_type
, "%-17.9g");
6352 get_formatted_print_options (&opts
, 'x');
6353 print_scalar_formatted (raw_buffer
,
6354 builtin_type (gdbarch
)->builtin_uint32
,
6357 gdb_printf (file
, " flt: %s", flt_str
.c_str ());
6359 if ((regnum
- gdbarch_num_regs (gdbarch
)) % 2 == 0)
6361 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
6362 dbl_str
= target_float_to_string (raw_buffer
, dbl_type
, "%-24.17g");
6364 gdb_printf (file
, " dbl: %s", dbl_str
.c_str ());
6369 struct value_print_options opts
;
6371 /* Eight byte registers: print each one as hex, float and double. */
6372 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
6373 flt_str
= target_float_to_string (raw_buffer
, flt_type
, "%-17.9g");
6375 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
6376 dbl_str
= target_float_to_string (raw_buffer
, dbl_type
, "%-24.17g");
6378 get_formatted_print_options (&opts
, 'x');
6379 print_scalar_formatted (raw_buffer
,
6380 builtin_type (gdbarch
)->builtin_uint64
,
6383 gdb_printf (file
, " flt: %s", flt_str
.c_str ());
6384 gdb_printf (file
, " dbl: %s", dbl_str
.c_str ());
6389 mips_print_register (struct ui_file
*file
, frame_info_ptr frame
,
6392 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
6393 struct value_print_options opts
;
6396 if (mips_float_register_p (gdbarch
, regnum
))
6398 mips_print_fp_register (file
, frame
, regnum
);
6402 val
= get_frame_register_value (frame
, regnum
);
6404 gdb_puts (gdbarch_register_name (gdbarch
, regnum
), file
);
6406 /* The problem with printing numeric register names (r26, etc.) is that
6407 the user can't use them on input. Probably the best solution is to
6408 fix it so that either the numeric or the funky (a2, etc.) names
6409 are accepted on input. */
6410 if (regnum
< MIPS_NUMREGS
)
6411 gdb_printf (file
, "(r%d): ", regnum
);
6413 gdb_printf (file
, ": ");
6415 get_formatted_print_options (&opts
, 'x');
6416 value_print_scalar_formatted (val
, &opts
, 0, file
);
6419 /* Print IEEE exception condition bits in FLAGS. */
6422 print_fpu_flags (struct ui_file
*file
, int flags
)
6424 if (flags
& (1 << 0))
6425 gdb_puts (" inexact", file
);
6426 if (flags
& (1 << 1))
6427 gdb_puts (" uflow", file
);
6428 if (flags
& (1 << 2))
6429 gdb_puts (" oflow", file
);
6430 if (flags
& (1 << 3))
6431 gdb_puts (" div0", file
);
6432 if (flags
& (1 << 4))
6433 gdb_puts (" inval", file
);
6434 if (flags
& (1 << 5))
6435 gdb_puts (" unimp", file
);
6436 gdb_putc ('\n', file
);
6439 /* Print interesting information about the floating point processor
6440 (if present) or emulator. */
6443 mips_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
6444 frame_info_ptr frame
, const char *args
)
6446 int fcsr
= mips_regnum (gdbarch
)->fp_control_status
;
6447 enum mips_fpu_type type
= mips_get_fpu_type (gdbarch
);
6451 if (fcsr
== -1 || !read_frame_register_unsigned (frame
, fcsr
, &fcs
))
6452 type
= MIPS_FPU_NONE
;
6454 gdb_printf (file
, "fpu type: %s\n",
6455 type
== MIPS_FPU_DOUBLE
? "double-precision"
6456 : type
== MIPS_FPU_SINGLE
? "single-precision"
6459 if (type
== MIPS_FPU_NONE
)
6462 gdb_printf (file
, "reg size: %d bits\n",
6463 register_size (gdbarch
, mips_regnum (gdbarch
)->fp0
) * 8);
6465 gdb_puts ("cond :", file
);
6466 if (fcs
& (1 << 23))
6467 gdb_puts (" 0", file
);
6468 for (i
= 1; i
<= 7; i
++)
6469 if (fcs
& (1 << (24 + i
)))
6470 gdb_printf (file
, " %d", i
);
6471 gdb_putc ('\n', file
);
6473 gdb_puts ("cause :", file
);
6474 print_fpu_flags (file
, (fcs
>> 12) & 0x3f);
6475 fputs ("mask :", stdout
);
6476 print_fpu_flags (file
, (fcs
>> 7) & 0x1f);
6477 fputs ("flags :", stdout
);
6478 print_fpu_flags (file
, (fcs
>> 2) & 0x1f);
6480 gdb_puts ("rounding: ", file
);
6483 case 0: gdb_puts ("nearest\n", file
); break;
6484 case 1: gdb_puts ("zero\n", file
); break;
6485 case 2: gdb_puts ("+inf\n", file
); break;
6486 case 3: gdb_puts ("-inf\n", file
); break;
6489 gdb_puts ("flush :", file
);
6490 if (fcs
& (1 << 21))
6491 gdb_puts (" nearest", file
);
6492 if (fcs
& (1 << 22))
6493 gdb_puts (" override", file
);
6494 if (fcs
& (1 << 24))
6495 gdb_puts (" zero", file
);
6496 if ((fcs
& (0xb << 21)) == 0)
6497 gdb_puts (" no", file
);
6498 gdb_putc ('\n', file
);
6500 gdb_printf (file
, "nan2008 : %s\n", fcs
& (1 << 18) ? "yes" : "no");
6501 gdb_printf (file
, "abs2008 : %s\n", fcs
& (1 << 19) ? "yes" : "no");
6502 gdb_putc ('\n', file
);
6504 default_print_float_info (gdbarch
, file
, frame
, args
);
6507 /* Replacement for generic do_registers_info.
6508 Print regs in pretty columns. */
6511 print_fp_register_row (struct ui_file
*file
, frame_info_ptr frame
,
6514 gdb_printf (file
, " ");
6515 mips_print_fp_register (file
, frame
, regnum
);
6516 gdb_printf (file
, "\n");
6521 /* Print a row's worth of GP (int) registers, with name labels above. */
6524 print_gp_register_row (struct ui_file
*file
, frame_info_ptr frame
,
6527 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
6528 /* Do values for GP (int) regs. */
6529 const gdb_byte
*raw_buffer
;
6530 struct value
*value
;
6531 int ncols
= (mips_abi_regsize (gdbarch
) == 8 ? 4 : 8); /* display cols
6536 /* For GP registers, we print a separate row of names above the vals. */
6537 for (col
= 0, regnum
= start_regnum
;
6538 col
< ncols
&& regnum
< gdbarch_num_cooked_regs (gdbarch
);
6541 if (*gdbarch_register_name (gdbarch
, regnum
) == '\0')
6542 continue; /* unused register */
6543 if (mips_float_register_p (gdbarch
, regnum
))
6544 break; /* End the row: reached FP register. */
6545 /* Large registers are handled separately. */
6546 if (register_size (gdbarch
, regnum
) > mips_abi_regsize (gdbarch
))
6549 break; /* End the row before this register. */
6551 /* Print this register on a row by itself. */
6552 mips_print_register (file
, frame
, regnum
);
6553 gdb_printf (file
, "\n");
6557 gdb_printf (file
, " ");
6559 mips_abi_regsize (gdbarch
) == 8 ? "%17s" : "%9s",
6560 gdbarch_register_name (gdbarch
, regnum
));
6567 /* Print the R0 to R31 names. */
6568 if ((start_regnum
% gdbarch_num_regs (gdbarch
)) < MIPS_NUMREGS
)
6569 gdb_printf (file
, "\n R%-4d",
6570 start_regnum
% gdbarch_num_regs (gdbarch
));
6572 gdb_printf (file
, "\n ");
6574 /* Now print the values in hex, 4 or 8 to the row. */
6575 for (col
= 0, regnum
= start_regnum
;
6576 col
< ncols
&& regnum
< gdbarch_num_cooked_regs (gdbarch
);
6579 if (*gdbarch_register_name (gdbarch
, regnum
) == '\0')
6580 continue; /* unused register */
6581 if (mips_float_register_p (gdbarch
, regnum
))
6582 break; /* End row: reached FP register. */
6583 if (register_size (gdbarch
, regnum
) > mips_abi_regsize (gdbarch
))
6584 break; /* End row: large register. */
6586 /* OK: get the data in raw format. */
6587 value
= get_frame_register_value (frame
, regnum
);
6588 if (value_optimized_out (value
)
6589 || !value_entirely_available (value
))
6591 gdb_printf (file
, "%*s ",
6592 (int) mips_abi_regsize (gdbarch
) * 2,
6593 (mips_abi_regsize (gdbarch
) == 4 ? "<unavl>"
6594 : "<unavailable>"));
6598 raw_buffer
= value_contents_all (value
).data ();
6599 /* pad small registers */
6601 byte
< (mips_abi_regsize (gdbarch
)
6602 - register_size (gdbarch
, regnum
)); byte
++)
6603 gdb_printf (file
, " ");
6604 /* Now print the register value in hex, endian order. */
6605 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
6607 register_size (gdbarch
, regnum
) - register_size (gdbarch
, regnum
);
6608 byte
< register_size (gdbarch
, regnum
); byte
++)
6609 gdb_printf (file
, "%02x", raw_buffer
[byte
]);
6611 for (byte
= register_size (gdbarch
, regnum
) - 1;
6613 gdb_printf (file
, "%02x", raw_buffer
[byte
]);
6614 gdb_printf (file
, " ");
6617 if (col
> 0) /* ie. if we actually printed anything... */
6618 gdb_printf (file
, "\n");
6623 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */
6626 mips_print_registers_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
6627 frame_info_ptr frame
, int regnum
, int all
)
6629 if (regnum
!= -1) /* Do one specified register. */
6631 gdb_assert (regnum
>= gdbarch_num_regs (gdbarch
));
6632 if (*(gdbarch_register_name (gdbarch
, regnum
)) == '\0')
6633 error (_("Not a valid register for the current processor type"));
6635 mips_print_register (file
, frame
, regnum
);
6636 gdb_printf (file
, "\n");
6639 /* Do all (or most) registers. */
6641 regnum
= gdbarch_num_regs (gdbarch
);
6642 while (regnum
< gdbarch_num_cooked_regs (gdbarch
))
6644 if (mips_float_register_p (gdbarch
, regnum
))
6646 if (all
) /* True for "INFO ALL-REGISTERS" command. */
6647 regnum
= print_fp_register_row (file
, frame
, regnum
);
6649 regnum
+= MIPS_NUMREGS
; /* Skip floating point regs. */
6652 regnum
= print_gp_register_row (file
, frame
, regnum
);
6658 mips_single_step_through_delay (struct gdbarch
*gdbarch
,
6659 frame_info_ptr frame
)
6661 CORE_ADDR pc
= get_frame_pc (frame
);
6666 if ((mips_pc_is_mips (pc
)
6667 && !mips32_insn_at_pc_has_delay_slot (gdbarch
, pc
))
6668 || (mips_pc_is_micromips (gdbarch
, pc
)
6669 && !micromips_insn_at_pc_has_delay_slot (gdbarch
, pc
, 0))
6670 || (mips_pc_is_mips16 (gdbarch
, pc
)
6671 && !mips16_insn_at_pc_has_delay_slot (gdbarch
, pc
, 0)))
6674 isa
= mips_pc_isa (gdbarch
, pc
);
6675 /* _has_delay_slot above will have validated the read. */
6676 insn
= mips_fetch_instruction (gdbarch
, isa
, pc
, NULL
);
6677 size
= mips_insn_size (isa
, insn
);
6679 const address_space
*aspace
= get_frame_address_space (frame
);
6681 return breakpoint_here_p (aspace
, pc
+ size
) != no_breakpoint_here
;
6684 /* To skip prologues, I use this predicate. Returns either PC itself
6685 if the code at PC does not look like a function prologue; otherwise
6686 returns an address that (if we're lucky) follows the prologue. If
6687 LENIENT, then we must skip everything which is involved in setting
6688 up the frame (it's OK to skip more, just so long as we don't skip
6689 anything which might clobber the registers which are being saved.
6690 We must skip more in the case where part of the prologue is in the
6691 delay slot of a non-prologue instruction). */
6694 mips_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6697 CORE_ADDR func_addr
;
6699 /* See if we can determine the end of the prologue via the symbol table.
6700 If so, then return either PC, or the PC after the prologue, whichever
6702 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
))
6704 CORE_ADDR post_prologue_pc
6705 = skip_prologue_using_sal (gdbarch
, func_addr
);
6706 if (post_prologue_pc
!= 0)
6707 return std::max (pc
, post_prologue_pc
);
6710 /* Can't determine prologue from the symbol table, need to examine
6713 /* Find an upper limit on the function prologue using the debug
6714 information. If the debug information could not be used to provide
6715 that bound, then use an arbitrary large number as the upper bound. */
6716 limit_pc
= skip_prologue_using_sal (gdbarch
, pc
);
6718 limit_pc
= pc
+ 100; /* Magic. */
6720 if (mips_pc_is_mips16 (gdbarch
, pc
))
6721 return mips16_scan_prologue (gdbarch
, pc
, limit_pc
, NULL
, NULL
);
6722 else if (mips_pc_is_micromips (gdbarch
, pc
))
6723 return micromips_scan_prologue (gdbarch
, pc
, limit_pc
, NULL
, NULL
);
6725 return mips32_scan_prologue (gdbarch
, pc
, limit_pc
, NULL
, NULL
);
6728 /* Implement the stack_frame_destroyed_p gdbarch method (32-bit version).
6729 This is a helper function for mips_stack_frame_destroyed_p. */
6732 mips32_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6734 CORE_ADDR func_addr
= 0, func_end
= 0;
6736 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
6738 /* The MIPS epilogue is max. 12 bytes long. */
6739 CORE_ADDR addr
= func_end
- 12;
6741 if (addr
< func_addr
+ 4)
6742 addr
= func_addr
+ 4;
6746 for (; pc
< func_end
; pc
+= MIPS_INSN32_SIZE
)
6748 unsigned long high_word
;
6751 inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, pc
, NULL
);
6752 high_word
= (inst
>> 16) & 0xffff;
6754 if (high_word
!= 0x27bd /* addiu $sp,$sp,offset */
6755 && high_word
!= 0x67bd /* daddiu $sp,$sp,offset */
6756 && inst
!= 0x03e00008 /* jr $ra */
6757 && inst
!= 0x00000000) /* nop */
6767 /* Implement the stack_frame_destroyed_p gdbarch method (microMIPS version).
6768 This is a helper function for mips_stack_frame_destroyed_p. */
6771 micromips_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6773 CORE_ADDR func_addr
= 0;
6774 CORE_ADDR func_end
= 0;
6782 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
6785 /* The microMIPS epilogue is max. 12 bytes long. */
6786 addr
= func_end
- 12;
6788 if (addr
< func_addr
+ 2)
6789 addr
= func_addr
+ 2;
6793 for (; pc
< func_end
; pc
+= loc
)
6796 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, NULL
);
6797 loc
+= MIPS_INSN16_SIZE
;
6798 switch (mips_insn_size (ISA_MICROMIPS
, insn
))
6800 /* 32-bit instructions. */
6801 case 2 * MIPS_INSN16_SIZE
:
6803 insn
|= mips_fetch_instruction (gdbarch
,
6804 ISA_MICROMIPS
, pc
+ loc
, NULL
);
6805 loc
+= MIPS_INSN16_SIZE
;
6806 switch (micromips_op (insn
>> 16))
6808 case 0xc: /* ADDIU: bits 001100 */
6809 case 0x17: /* DADDIU: bits 010111 */
6810 sreg
= b0s5_reg (insn
>> 16);
6811 dreg
= b5s5_reg (insn
>> 16);
6812 offset
= (b0s16_imm (insn
) ^ 0x8000) - 0x8000;
6813 if (sreg
== MIPS_SP_REGNUM
&& dreg
== MIPS_SP_REGNUM
6814 /* (D)ADDIU $sp, imm */
6824 /* 16-bit instructions. */
6825 case MIPS_INSN16_SIZE
:
6826 switch (micromips_op (insn
))
6828 case 0x3: /* MOVE: bits 000011 */
6829 sreg
= b0s5_reg (insn
);
6830 dreg
= b5s5_reg (insn
);
6831 if (sreg
== 0 && dreg
== 0)
6832 /* MOVE $zero, $zero aka NOP */
6836 case 0x11: /* POOL16C: bits 010001 */
6837 if (b5s5_op (insn
) == 0x18
6838 /* JRADDIUSP: bits 010011 11000 */
6839 || (b5s5_op (insn
) == 0xd
6840 /* JRC: bits 010011 01101 */
6841 && b0s5_reg (insn
) == MIPS_RA_REGNUM
))
6846 case 0x13: /* POOL16D: bits 010011 */
6847 offset
= micromips_decode_imm9 (b1s9_imm (insn
));
6848 if ((insn
& 0x1) == 0x1
6849 /* ADDIUSP: bits 010011 1 */
6863 /* Implement the stack_frame_destroyed_p gdbarch method (16-bit version).
6864 This is a helper function for mips_stack_frame_destroyed_p. */
6867 mips16_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6869 CORE_ADDR func_addr
= 0, func_end
= 0;
6871 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
6873 /* The MIPS epilogue is max. 12 bytes long. */
6874 CORE_ADDR addr
= func_end
- 12;
6876 if (addr
< func_addr
+ 4)
6877 addr
= func_addr
+ 4;
6881 for (; pc
< func_end
; pc
+= MIPS_INSN16_SIZE
)
6883 unsigned short inst
;
6885 inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS16
, pc
, NULL
);
6887 if ((inst
& 0xf800) == 0xf000) /* extend */
6890 if (inst
!= 0x6300 /* addiu $sp,offset */
6891 && inst
!= 0xfb00 /* daddiu $sp,$sp,offset */
6892 && inst
!= 0xe820 /* jr $ra */
6893 && inst
!= 0xe8a0 /* jrc $ra */
6894 && inst
!= 0x6500) /* nop */
6904 /* Implement the stack_frame_destroyed_p gdbarch method.
6906 The epilogue is defined here as the area at the end of a function,
6907 after an instruction which destroys the function's stack frame. */
6910 mips_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6912 if (mips_pc_is_mips16 (gdbarch
, pc
))
6913 return mips16_stack_frame_destroyed_p (gdbarch
, pc
);
6914 else if (mips_pc_is_micromips (gdbarch
, pc
))
6915 return micromips_stack_frame_destroyed_p (gdbarch
, pc
);
6917 return mips32_stack_frame_destroyed_p (gdbarch
, pc
);
6920 /* Commands to show/set the MIPS FPU type. */
6923 show_mipsfpu_command (const char *args
, int from_tty
)
6927 if (gdbarch_bfd_arch_info (target_gdbarch ())->arch
!= bfd_arch_mips
)
6930 ("The MIPS floating-point coprocessor is unknown "
6931 "because the current architecture is not MIPS.\n");
6935 switch (mips_get_fpu_type (target_gdbarch ()))
6937 case MIPS_FPU_SINGLE
:
6938 fpu
= "single-precision";
6940 case MIPS_FPU_DOUBLE
:
6941 fpu
= "double-precision";
6944 fpu
= "absent (none)";
6947 internal_error (_("bad switch"));
6949 if (mips_fpu_type_auto
)
6950 gdb_printf ("The MIPS floating-point coprocessor "
6951 "is set automatically (currently %s)\n",
6955 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu
);
6960 set_mipsfpu_single_command (const char *args
, int from_tty
)
6962 struct gdbarch_info info
;
6963 mips_fpu_type
= MIPS_FPU_SINGLE
;
6964 mips_fpu_type_auto
= 0;
6965 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
6966 instead of relying on globals. Doing that would let generic code
6967 handle the search for this specific architecture. */
6968 if (!gdbarch_update_p (info
))
6969 internal_error (_("set mipsfpu failed"));
6973 set_mipsfpu_double_command (const char *args
, int from_tty
)
6975 struct gdbarch_info info
;
6976 mips_fpu_type
= MIPS_FPU_DOUBLE
;
6977 mips_fpu_type_auto
= 0;
6978 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
6979 instead of relying on globals. Doing that would let generic code
6980 handle the search for this specific architecture. */
6981 if (!gdbarch_update_p (info
))
6982 internal_error (_("set mipsfpu failed"));
6986 set_mipsfpu_none_command (const char *args
, int from_tty
)
6988 struct gdbarch_info info
;
6989 mips_fpu_type
= MIPS_FPU_NONE
;
6990 mips_fpu_type_auto
= 0;
6991 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
6992 instead of relying on globals. Doing that would let generic code
6993 handle the search for this specific architecture. */
6994 if (!gdbarch_update_p (info
))
6995 internal_error (_("set mipsfpu failed"));
6999 set_mipsfpu_auto_command (const char *args
, int from_tty
)
7001 mips_fpu_type_auto
= 1;
7004 /* Just like reinit_frame_cache, but with the right arguments to be
7005 callable as an sfunc. */
7008 reinit_frame_cache_sfunc (const char *args
, int from_tty
,
7009 struct cmd_list_element
*c
)
7011 reinit_frame_cache ();
7015 gdb_print_insn_mips (bfd_vma memaddr
, struct disassemble_info
*info
)
7017 gdb_disassemble_info
*di
7018 = static_cast<gdb_disassemble_info
*> (info
->application_data
);
7019 struct gdbarch
*gdbarch
= di
->arch ();
7021 /* FIXME: cagney/2003-06-26: Is this even necessary? The
7022 disassembler needs to be able to locally determine the ISA, and
7023 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
7025 if (mips_pc_is_mips16 (gdbarch
, memaddr
))
7026 info
->mach
= bfd_mach_mips16
;
7027 else if (mips_pc_is_micromips (gdbarch
, memaddr
))
7028 info
->mach
= bfd_mach_mips_micromips
;
7030 /* Round down the instruction address to the appropriate boundary. */
7031 memaddr
&= (info
->mach
== bfd_mach_mips16
7032 || info
->mach
== bfd_mach_mips_micromips
) ? ~1 : ~3;
7034 return default_print_insn (memaddr
, info
);
7037 /* Implement the breakpoint_kind_from_pc gdbarch method. */
7040 mips_breakpoint_kind_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
)
7042 CORE_ADDR pc
= *pcptr
;
7044 if (mips_pc_is_mips16 (gdbarch
, pc
))
7046 *pcptr
= unmake_compact_addr (pc
);
7047 return MIPS_BP_KIND_MIPS16
;
7049 else if (mips_pc_is_micromips (gdbarch
, pc
))
7054 *pcptr
= unmake_compact_addr (pc
);
7055 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, pc
, &status
);
7056 if (status
|| (mips_insn_size (ISA_MICROMIPS
, insn
) == 2))
7057 return MIPS_BP_KIND_MICROMIPS16
;
7059 return MIPS_BP_KIND_MICROMIPS32
;
7062 return MIPS_BP_KIND_MIPS32
;
7065 /* Implement the sw_breakpoint_from_kind gdbarch method. */
7067 static const gdb_byte
*
7068 mips_sw_breakpoint_from_kind (struct gdbarch
*gdbarch
, int kind
, int *size
)
7070 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
7074 case MIPS_BP_KIND_MIPS16
:
7076 static gdb_byte mips16_big_breakpoint
[] = { 0xe8, 0xa5 };
7077 static gdb_byte mips16_little_breakpoint
[] = { 0xa5, 0xe8 };
7080 if (byte_order_for_code
== BFD_ENDIAN_BIG
)
7081 return mips16_big_breakpoint
;
7083 return mips16_little_breakpoint
;
7085 case MIPS_BP_KIND_MICROMIPS16
:
7087 static gdb_byte micromips16_big_breakpoint
[] = { 0x46, 0x85 };
7088 static gdb_byte micromips16_little_breakpoint
[] = { 0x85, 0x46 };
7092 if (byte_order_for_code
== BFD_ENDIAN_BIG
)
7093 return micromips16_big_breakpoint
;
7095 return micromips16_little_breakpoint
;
7097 case MIPS_BP_KIND_MICROMIPS32
:
7099 static gdb_byte micromips32_big_breakpoint
[] = { 0, 0x5, 0, 0x7 };
7100 static gdb_byte micromips32_little_breakpoint
[] = { 0x5, 0, 0x7, 0 };
7103 if (byte_order_for_code
== BFD_ENDIAN_BIG
)
7104 return micromips32_big_breakpoint
;
7106 return micromips32_little_breakpoint
;
7108 case MIPS_BP_KIND_MIPS32
:
7110 static gdb_byte big_breakpoint
[] = { 0, 0x5, 0, 0xd };
7111 static gdb_byte little_breakpoint
[] = { 0xd, 0, 0x5, 0 };
7114 if (byte_order_for_code
== BFD_ENDIAN_BIG
)
7115 return big_breakpoint
;
7117 return little_breakpoint
;
7120 gdb_assert_not_reached ("unexpected mips breakpoint kind");
7124 /* Return non-zero if the standard MIPS instruction INST has a branch
7125 delay slot (i.e. it is a jump or branch instruction). This function
7126 is based on mips32_next_pc. */
7129 mips32_instruction_has_delay_slot (struct gdbarch
*gdbarch
, ULONGEST inst
)
7135 op
= itype_op (inst
);
7136 if ((inst
& 0xe0000000) != 0)
7138 rs
= itype_rs (inst
);
7139 rt
= itype_rt (inst
);
7140 return (is_octeon_bbit_op (op
, gdbarch
)
7141 || op
>> 2 == 5 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
7142 || op
== 29 /* JALX: bits 011101 */
7145 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
7146 || (rs
== 9 && (rt
& 0x2) == 0)
7147 /* BC1ANY2F, BC1ANY2T: bits 010001 01001 */
7148 || (rs
== 10 && (rt
& 0x2) == 0))));
7149 /* BC1ANY4F, BC1ANY4T: bits 010001 01010 */
7152 switch (op
& 0x07) /* extract bits 28,27,26 */
7154 case 0: /* SPECIAL */
7155 op
= rtype_funct (inst
);
7156 return (op
== 8 /* JR */
7157 || op
== 9); /* JALR */
7158 break; /* end SPECIAL */
7159 case 1: /* REGIMM */
7160 rs
= itype_rs (inst
);
7161 rt
= itype_rt (inst
); /* branch condition */
7162 return ((rt
& 0xc) == 0
7163 /* BLTZ, BLTZL, BGEZ, BGEZL: bits 000xx */
7164 /* BLTZAL, BLTZALL, BGEZAL, BGEZALL: 100xx */
7165 || ((rt
& 0x1e) == 0x1c && rs
== 0));
7166 /* BPOSGE32, BPOSGE64: bits 1110x */
7167 break; /* end REGIMM */
7168 default: /* J, JAL, BEQ, BNE, BLEZ, BGTZ */
7174 /* Return non-zero if a standard MIPS instruction at ADDR has a branch
7175 delay slot (i.e. it is a jump or branch instruction). */
7178 mips32_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
7183 insn
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, addr
, &status
);
7187 return mips32_instruction_has_delay_slot (gdbarch
, insn
);
7190 /* Return non-zero if the microMIPS instruction INSN, comprising the
7191 16-bit major opcode word in the high 16 bits and any second word
7192 in the low 16 bits, has a branch delay slot (i.e. it is a non-compact
7193 jump or branch instruction). The instruction must be 32-bit if
7194 MUSTBE32 is set or can be any instruction otherwise. */
7197 micromips_instruction_has_delay_slot (ULONGEST insn
, int mustbe32
)
7199 ULONGEST major
= insn
>> 16;
7201 switch (micromips_op (major
))
7203 /* 16-bit instructions. */
7204 case 0x33: /* B16: bits 110011 */
7205 case 0x2b: /* BNEZ16: bits 101011 */
7206 case 0x23: /* BEQZ16: bits 100011 */
7208 case 0x11: /* POOL16C: bits 010001 */
7210 && ((b5s5_op (major
) == 0xc
7211 /* JR16: bits 010001 01100 */
7212 || (b5s5_op (major
) & 0x1e) == 0xe)));
7213 /* JALR16, JALRS16: bits 010001 0111x */
7214 /* 32-bit instructions. */
7215 case 0x3d: /* JAL: bits 111101 */
7216 case 0x3c: /* JALX: bits 111100 */
7217 case 0x35: /* J: bits 110101 */
7218 case 0x2d: /* BNE: bits 101101 */
7219 case 0x25: /* BEQ: bits 100101 */
7220 case 0x1d: /* JALS: bits 011101 */
7222 case 0x10: /* POOL32I: bits 010000 */
7223 return ((b5s5_op (major
) & 0x1c) == 0x0
7224 /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */
7225 || (b5s5_op (major
) & 0x1d) == 0x4
7226 /* BLEZ, BGTZ: bits 010000 001x0 */
7227 || (b5s5_op (major
) & 0x1d) == 0x11
7228 /* BLTZALS, BGEZALS: bits 010000 100x1 */
7229 || ((b5s5_op (major
) & 0x1e) == 0x14
7230 && (major
& 0x3) == 0x0)
7231 /* BC2F, BC2T: bits 010000 1010x xxx00 */
7232 || (b5s5_op (major
) & 0x1e) == 0x1a
7233 /* BPOSGE64, BPOSGE32: bits 010000 1101x */
7234 || ((b5s5_op (major
) & 0x1e) == 0x1c
7235 && (major
& 0x3) == 0x0)
7236 /* BC1F, BC1T: bits 010000 1110x xxx00 */
7237 || ((b5s5_op (major
) & 0x1c) == 0x1c
7238 && (major
& 0x3) == 0x1));
7239 /* BC1ANY*: bits 010000 111xx xxx01 */
7240 case 0x0: /* POOL32A: bits 000000 */
7241 return (b0s6_op (insn
) == 0x3c
7242 /* POOL32Axf: bits 000000 ... 111100 */
7243 && (b6s10_ext (insn
) & 0x2bf) == 0x3c);
7244 /* JALR, JALR.HB: 000000 000x111100 111100 */
7245 /* JALRS, JALRS.HB: 000000 010x111100 111100 */
7251 /* Return non-zero if a microMIPS instruction at ADDR has a branch delay
7252 slot (i.e. it is a non-compact jump instruction). The instruction
7253 must be 32-bit if MUSTBE32 is set or can be any instruction otherwise. */
7256 micromips_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
,
7257 CORE_ADDR addr
, int mustbe32
)
7263 insn
= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, addr
, &status
);
7266 size
= mips_insn_size (ISA_MICROMIPS
, insn
);
7268 if (size
== 2 * MIPS_INSN16_SIZE
)
7270 insn
|= mips_fetch_instruction (gdbarch
, ISA_MICROMIPS
, addr
, &status
);
7275 return micromips_instruction_has_delay_slot (insn
, mustbe32
);
7278 /* Return non-zero if the MIPS16 instruction INST, which must be
7279 a 32-bit instruction if MUSTBE32 is set or can be any instruction
7280 otherwise, has a branch delay slot (i.e. it is a non-compact jump
7281 instruction). This function is based on mips16_next_pc. */
7284 mips16_instruction_has_delay_slot (unsigned short inst
, int mustbe32
)
7286 if ((inst
& 0xf89f) == 0xe800) /* JR/JALR (16-bit instruction) */
7288 return (inst
& 0xf800) == 0x1800; /* JAL/JALX (32-bit instruction) */
7291 /* Return non-zero if a MIPS16 instruction at ADDR has a branch delay
7292 slot (i.e. it is a non-compact jump instruction). The instruction
7293 must be 32-bit if MUSTBE32 is set or can be any instruction otherwise. */
7296 mips16_insn_at_pc_has_delay_slot (struct gdbarch
*gdbarch
,
7297 CORE_ADDR addr
, int mustbe32
)
7299 unsigned short insn
;
7302 insn
= mips_fetch_instruction (gdbarch
, ISA_MIPS16
, addr
, &status
);
7306 return mips16_instruction_has_delay_slot (insn
, mustbe32
);
7309 /* Calculate the starting address of the MIPS memory segment BPADDR is in.
7310 This assumes KSSEG exists. */
7313 mips_segment_boundary (CORE_ADDR bpaddr
)
7315 CORE_ADDR mask
= CORE_ADDR_MAX
;
7318 if (sizeof (CORE_ADDR
) == 8)
7319 /* Get the topmost two bits of bpaddr in a 32-bit safe manner (avoid
7320 a compiler warning produced where CORE_ADDR is a 32-bit type even
7321 though in that case this is dead code). */
7322 switch (bpaddr
>> ((sizeof (CORE_ADDR
) << 3) - 2) & 3)
7325 if (bpaddr
== (bfd_signed_vma
) (int32_t) bpaddr
)
7326 segsize
= 29; /* 32-bit compatibility segment */
7328 segsize
= 62; /* xkseg */
7330 case 2: /* xkphys */
7333 default: /* xksseg (1), xkuseg/kuseg (0) */
7337 else if (bpaddr
& 0x80000000) /* kernel segment */
7340 segsize
= 31; /* user segment */
7342 return bpaddr
& mask
;
7345 /* Move the breakpoint at BPADDR out of any branch delay slot by shifting
7346 it backwards if necessary. Return the address of the new location. */
7349 mips_adjust_breakpoint_address (struct gdbarch
*gdbarch
, CORE_ADDR bpaddr
)
7351 CORE_ADDR prev_addr
;
7353 CORE_ADDR func_addr
;
7355 /* If a breakpoint is set on the instruction in a branch delay slot,
7356 GDB gets confused. When the breakpoint is hit, the PC isn't on
7357 the instruction in the branch delay slot, the PC will point to
7358 the branch instruction. Since the PC doesn't match any known
7359 breakpoints, GDB reports a trap exception.
7361 There are two possible fixes for this problem.
7363 1) When the breakpoint gets hit, see if the BD bit is set in the
7364 Cause register (which indicates the last exception occurred in a
7365 branch delay slot). If the BD bit is set, fix the PC to point to
7366 the instruction in the branch delay slot.
7368 2) When the user sets the breakpoint, don't allow him to set the
7369 breakpoint on the instruction in the branch delay slot. Instead
7370 move the breakpoint to the branch instruction (which will have
7373 The problem with the first solution is that if the user then
7374 single-steps the processor, the branch instruction will get
7375 skipped (since GDB thinks the PC is on the instruction in the
7378 So, we'll use the second solution. To do this we need to know if
7379 the instruction we're trying to set the breakpoint on is in the
7380 branch delay slot. */
7382 boundary
= mips_segment_boundary (bpaddr
);
7384 /* Make sure we don't scan back before the beginning of the current
7385 function, since we may fetch constant data or insns that look like
7386 a jump. Of course we might do that anyway if the compiler has
7387 moved constants inline. :-( */
7388 if (find_pc_partial_function (bpaddr
, NULL
, &func_addr
, NULL
)
7389 && func_addr
> boundary
&& func_addr
<= bpaddr
)
7390 boundary
= func_addr
;
7392 if (mips_pc_is_mips (bpaddr
))
7394 if (bpaddr
== boundary
)
7397 /* If the previous instruction has a branch delay slot, we have
7398 to move the breakpoint to the branch instruction. */
7399 prev_addr
= bpaddr
- 4;
7400 if (mips32_insn_at_pc_has_delay_slot (gdbarch
, prev_addr
))
7405 int (*insn_at_pc_has_delay_slot
) (struct gdbarch
*, CORE_ADDR
, int);
7406 CORE_ADDR addr
, jmpaddr
;
7409 boundary
= unmake_compact_addr (boundary
);
7411 /* The only MIPS16 instructions with delay slots are JAL, JALX,
7412 JALR and JR. An absolute JAL/JALX is always 4 bytes long,
7413 so try for that first, then try the 2 byte JALR/JR.
7414 The microMIPS ASE has a whole range of jumps and branches
7415 with delay slots, some of which take 4 bytes and some take
7416 2 bytes, so the idea is the same.
7417 FIXME: We have to assume that bpaddr is not the second half
7418 of an extended instruction. */
7419 insn_at_pc_has_delay_slot
= (mips_pc_is_micromips (gdbarch
, bpaddr
)
7420 ? micromips_insn_at_pc_has_delay_slot
7421 : mips16_insn_at_pc_has_delay_slot
);
7425 for (i
= 1; i
< 4; i
++)
7427 if (unmake_compact_addr (addr
) == boundary
)
7429 addr
-= MIPS_INSN16_SIZE
;
7430 if (i
== 1 && insn_at_pc_has_delay_slot (gdbarch
, addr
, 0))
7431 /* Looks like a JR/JALR at [target-1], but it could be
7432 the second word of a previous JAL/JALX, so record it
7433 and check back one more. */
7435 else if (i
> 1 && insn_at_pc_has_delay_slot (gdbarch
, addr
, 1))
7438 /* Looks like a JAL/JALX at [target-2], but it could also
7439 be the second word of a previous JAL/JALX, record it,
7440 and check back one more. */
7443 /* Looks like a JAL/JALX at [target-3], so any previously
7444 recorded JAL/JALX or JR/JALR must be wrong, because:
7447 -2: JAL-ext (can't be JAL/JALX)
7448 -1: bdslot (can't be JR/JALR)
7451 Of course it could be another JAL-ext which looks
7452 like a JAL, but in that case we'd have broken out
7453 of this loop at [target-2]:
7457 -2: bdslot (can't be jmp)
7464 /* Not a jump instruction: if we're at [target-1] this
7465 could be the second word of a JAL/JALX, so continue;
7466 otherwise we're done. */
7479 /* Return non-zero if SUFFIX is one of the numeric suffixes used for MIPS16
7480 call stubs, one of 1, 2, 5, 6, 9, 10, or, if ZERO is non-zero, also 0. */
7483 mips_is_stub_suffix (const char *suffix
, int zero
)
7488 return zero
&& suffix
[1] == '\0';
7490 return suffix
[1] == '\0' || (suffix
[1] == '0' && suffix
[2] == '\0');
7495 return suffix
[1] == '\0';
7501 /* Return non-zero if MODE is one of the mode infixes used for MIPS16
7502 call stubs, one of sf, df, sc, or dc. */
7505 mips_is_stub_mode (const char *mode
)
7507 return ((mode
[0] == 's' || mode
[0] == 'd')
7508 && (mode
[1] == 'f' || mode
[1] == 'c'));
7511 /* Code at PC is a compiler-generated stub. Such a stub for a function
7512 bar might have a name like __fn_stub_bar, and might look like this:
7519 followed by (or interspersed with):
7526 addiu $25, $25, %lo(bar)
7529 ($1 may be used in old code; for robustness we accept any register)
7532 lui $28, %hi(_gp_disp)
7533 addiu $28, $28, %lo(_gp_disp)
7536 addiu $25, $25, %lo(bar)
7539 In the case of a __call_stub_bar stub, the sequence to set up
7540 arguments might look like this:
7547 followed by (or interspersed with) one of the jump sequences above.
7549 In the case of a __call_stub_fp_bar stub, JAL or JALR is used instead
7550 of J or JR, respectively, followed by:
7556 We are at the beginning of the stub here, and scan down and extract
7557 the target address from the jump immediate instruction or, if a jump
7558 register instruction is used, from the register referred. Return
7559 the value of PC calculated or 0 if inconclusive.
7561 The limit on the search is arbitrarily set to 20 instructions. FIXME. */
7564 mips_get_mips16_fn_stub_pc (frame_info_ptr frame
, CORE_ADDR pc
)
7566 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
7567 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
7568 int addrreg
= MIPS_ZERO_REGNUM
;
7569 CORE_ADDR start_pc
= pc
;
7570 CORE_ADDR target_pc
= 0;
7577 status
== 0 && target_pc
== 0 && i
< 20;
7578 i
++, pc
+= MIPS_INSN32_SIZE
)
7580 ULONGEST inst
= mips_fetch_instruction (gdbarch
, ISA_MIPS
, pc
, NULL
);
7586 switch (itype_op (inst
))
7588 case 0: /* SPECIAL */
7589 switch (rtype_funct (inst
))
7593 rs
= rtype_rs (inst
);
7594 if (rs
== MIPS_GP_REGNUM
)
7595 target_pc
= gp
; /* Hmm... */
7596 else if (rs
== addrreg
)
7600 case 0x21: /* ADDU */
7601 rt
= rtype_rt (inst
);
7602 rs
= rtype_rs (inst
);
7603 rd
= rtype_rd (inst
);
7604 if (rd
== MIPS_GP_REGNUM
7605 && ((rs
== MIPS_GP_REGNUM
&& rt
== MIPS_T9_REGNUM
)
7606 || (rs
== MIPS_T9_REGNUM
&& rt
== MIPS_GP_REGNUM
)))
7614 target_pc
= jtype_target (inst
) << 2;
7615 target_pc
+= ((pc
+ 4) & ~(CORE_ADDR
) 0x0fffffff);
7619 rt
= itype_rt (inst
);
7620 rs
= itype_rs (inst
);
7623 imm
= (itype_immediate (inst
) ^ 0x8000) - 0x8000;
7624 if (rt
== MIPS_GP_REGNUM
)
7626 else if (rt
== addrreg
)
7632 rt
= itype_rt (inst
);
7633 imm
= ((itype_immediate (inst
) ^ 0x8000) - 0x8000) << 16;
7634 if (rt
== MIPS_GP_REGNUM
)
7636 else if (rt
!= MIPS_ZERO_REGNUM
)
7644 rt
= itype_rt (inst
);
7645 rs
= itype_rs (inst
);
7646 imm
= (itype_immediate (inst
) ^ 0x8000) - 0x8000;
7647 if (gp
!= 0 && rs
== MIPS_GP_REGNUM
)
7651 memset (buf
, 0, sizeof (buf
));
7652 status
= target_read_memory (gp
+ imm
, buf
, sizeof (buf
));
7654 addr
= extract_signed_integer (buf
, sizeof (buf
), byte_order
);
7663 /* If PC is in a MIPS16 call or return stub, return the address of the
7664 target PC, which is either the callee or the caller. There are several
7665 cases which must be handled:
7667 * If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub
7668 and the target PC is in $31 ($ra).
7669 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
7670 and the target PC is in $2.
7671 * If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10},
7672 i.e. before the JALR instruction, this is effectively a call stub
7673 and the target PC is in $2. Otherwise this is effectively
7674 a return stub and the target PC is in $18.
7675 * If the PC is at the start of __call_stub_fp_*, i.e. before the
7676 JAL or JALR instruction, this is effectively a call stub and the
7677 target PC is buried in the instruction stream. Otherwise this
7678 is effectively a return stub and the target PC is in $18.
7679 * If the PC is in __call_stub_* or in __fn_stub_*, this is a call
7680 stub and the target PC is buried in the instruction stream.
7682 See the source code for the stubs in gcc/config/mips/mips16.S, or the
7683 stub builder in gcc/config/mips/mips.c (mips16_build_call_stub) for the
7687 mips_skip_mips16_trampoline_code (frame_info_ptr frame
, CORE_ADDR pc
)
7689 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
7690 CORE_ADDR start_addr
;
7694 /* Find the starting address and name of the function containing the PC. */
7695 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
7698 /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub
7699 and the target PC is in $31 ($ra). */
7700 prefixlen
= strlen (mips_str_mips16_ret_stub
);
7701 if (strncmp (name
, mips_str_mips16_ret_stub
, prefixlen
) == 0
7702 && mips_is_stub_mode (name
+ prefixlen
)
7703 && name
[prefixlen
+ 2] == '\0')
7704 return get_frame_register_signed
7705 (frame
, gdbarch_num_regs (gdbarch
) + MIPS_RA_REGNUM
);
7707 /* If the PC is in __mips16_call_stub_*, this is one of the call
7708 call/return stubs. */
7709 prefixlen
= strlen (mips_str_mips16_call_stub
);
7710 if (strncmp (name
, mips_str_mips16_call_stub
, prefixlen
) == 0)
7712 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
7713 and the target PC is in $2. */
7714 if (mips_is_stub_suffix (name
+ prefixlen
, 0))
7715 return get_frame_register_signed
7716 (frame
, gdbarch_num_regs (gdbarch
) + MIPS_V0_REGNUM
);
7718 /* If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10},
7719 i.e. before the JALR instruction, this is effectively a call stub
7720 and the target PC is in $2. Otherwise this is effectively
7721 a return stub and the target PC is in $18. */
7722 else if (mips_is_stub_mode (name
+ prefixlen
)
7723 && name
[prefixlen
+ 2] == '_'
7724 && mips_is_stub_suffix (name
+ prefixlen
+ 3, 0))
7726 if (pc
== start_addr
)
7727 /* This is the 'call' part of a call stub. The return
7728 address is in $2. */
7729 return get_frame_register_signed
7730 (frame
, gdbarch_num_regs (gdbarch
) + MIPS_V0_REGNUM
);
7732 /* This is the 'return' part of a call stub. The return
7733 address is in $18. */
7734 return get_frame_register_signed
7735 (frame
, gdbarch_num_regs (gdbarch
) + MIPS_S2_REGNUM
);
7738 return 0; /* Not a stub. */
7741 /* If the PC is in __call_stub_* or __fn_stub*, this is one of the
7742 compiler-generated call or call/return stubs. */
7743 if (startswith (name
, mips_str_fn_stub
)
7744 || startswith (name
, mips_str_call_stub
))
7746 if (pc
== start_addr
)
7747 /* This is the 'call' part of a call stub. Call this helper
7748 to scan through this code for interesting instructions
7749 and determine the final PC. */
7750 return mips_get_mips16_fn_stub_pc (frame
, pc
);
7752 /* This is the 'return' part of a call stub. The return address
7754 return get_frame_register_signed
7755 (frame
, gdbarch_num_regs (gdbarch
) + MIPS_S2_REGNUM
);
7758 return 0; /* Not a stub. */
7761 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
7762 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
7765 mips_in_return_stub (struct gdbarch
*gdbarch
, CORE_ADDR pc
, const char *name
)
7767 CORE_ADDR start_addr
;
7770 /* Find the starting address of the function containing the PC. */
7771 if (find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
) == 0)
7774 /* If the PC is in __mips16_call_stub_{s,d}{f,c}_{0..10} but not at
7775 the start, i.e. after the JALR instruction, this is effectively
7777 prefixlen
= strlen (mips_str_mips16_call_stub
);
7778 if (pc
!= start_addr
7779 && strncmp (name
, mips_str_mips16_call_stub
, prefixlen
) == 0
7780 && mips_is_stub_mode (name
+ prefixlen
)
7781 && name
[prefixlen
+ 2] == '_'
7782 && mips_is_stub_suffix (name
+ prefixlen
+ 3, 1))
7785 /* If the PC is in __call_stub_fp_* but not at the start, i.e. after
7786 the JAL or JALR instruction, this is effectively a return stub. */
7787 prefixlen
= strlen (mips_str_call_fp_stub
);
7788 if (pc
!= start_addr
7789 && strncmp (name
, mips_str_call_fp_stub
, prefixlen
) == 0)
7792 /* Consume the .pic. prefix of any PIC stub, this function must return
7793 true when the PC is in a PIC stub of a __mips16_ret_{d,s}{f,c} stub
7794 or the call stub path will trigger in handle_inferior_event causing
7796 prefixlen
= strlen (mips_str_pic
);
7797 if (strncmp (name
, mips_str_pic
, prefixlen
) == 0)
7800 /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub. */
7801 prefixlen
= strlen (mips_str_mips16_ret_stub
);
7802 if (strncmp (name
, mips_str_mips16_ret_stub
, prefixlen
) == 0
7803 && mips_is_stub_mode (name
+ prefixlen
)
7804 && name
[prefixlen
+ 2] == '\0')
7807 return 0; /* Not a stub. */
7810 /* If the current PC is the start of a non-PIC-to-PIC stub, return the
7811 PC of the stub target. The stub just loads $t9 and jumps to it,
7812 so that $t9 has the correct value at function entry. */
7815 mips_skip_pic_trampoline_code (frame_info_ptr frame
, CORE_ADDR pc
)
7817 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
7818 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
7819 struct bound_minimal_symbol msym
;
7821 gdb_byte stub_code
[16];
7822 int32_t stub_words
[4];
7824 /* The stub for foo is named ".pic.foo", and is either two
7825 instructions inserted before foo or a three instruction sequence
7826 which jumps to foo. */
7827 msym
= lookup_minimal_symbol_by_pc (pc
);
7828 if (msym
.minsym
== NULL
7829 || msym
.value_address () != pc
7830 || msym
.minsym
->linkage_name () == NULL
7831 || !startswith (msym
.minsym
->linkage_name (), ".pic."))
7834 /* A two-instruction header. */
7835 if (msym
.minsym
->size () == 8)
7838 /* A three-instruction (plus delay slot) trampoline. */
7839 if (msym
.minsym
->size () == 16)
7841 if (target_read_memory (pc
, stub_code
, 16) != 0)
7843 for (i
= 0; i
< 4; i
++)
7844 stub_words
[i
] = extract_unsigned_integer (stub_code
+ i
* 4,
7847 /* A stub contains these instructions:
7850 addiu t9, t9, %lo(target)
7853 This works even for N64, since stubs are only generated with
7855 if ((stub_words
[0] & 0xffff0000U
) == 0x3c190000
7856 && (stub_words
[1] & 0xfc000000U
) == 0x08000000
7857 && (stub_words
[2] & 0xffff0000U
) == 0x27390000
7858 && stub_words
[3] == 0x00000000)
7859 return ((((stub_words
[0] & 0x0000ffff) << 16)
7860 + (stub_words
[2] & 0x0000ffff)) ^ 0x8000) - 0x8000;
7863 /* Not a recognized stub. */
7868 mips_skip_trampoline_code (frame_info_ptr frame
, CORE_ADDR pc
)
7870 CORE_ADDR requested_pc
= pc
;
7871 CORE_ADDR target_pc
;
7878 new_pc
= mips_skip_mips16_trampoline_code (frame
, pc
);
7882 new_pc
= find_solib_trampoline_target (frame
, pc
);
7886 new_pc
= mips_skip_pic_trampoline_code (frame
, pc
);
7890 while (pc
!= target_pc
);
7892 return pc
!= requested_pc
? pc
: 0;
7895 /* Convert a dbx stab register number (from `r' declaration) to a GDB
7896 [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
7899 mips_stab_reg_to_regnum (struct gdbarch
*gdbarch
, int num
)
7902 if (num
>= 0 && num
< 32)
7904 else if (num
>= 38 && num
< 70)
7905 regnum
= num
+ mips_regnum (gdbarch
)->fp0
- 38;
7907 regnum
= mips_regnum (gdbarch
)->hi
;
7909 regnum
= mips_regnum (gdbarch
)->lo
;
7910 else if (mips_regnum (gdbarch
)->dspacc
!= -1 && num
>= 72 && num
< 78)
7911 regnum
= num
+ mips_regnum (gdbarch
)->dspacc
- 72;
7914 return gdbarch_num_regs (gdbarch
) + regnum
;
7918 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
7919 gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
7922 mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch
*gdbarch
, int num
)
7925 if (num
>= 0 && num
< 32)
7927 else if (num
>= 32 && num
< 64)
7928 regnum
= num
+ mips_regnum (gdbarch
)->fp0
- 32;
7930 regnum
= mips_regnum (gdbarch
)->hi
;
7932 regnum
= mips_regnum (gdbarch
)->lo
;
7933 else if (mips_regnum (gdbarch
)->dspacc
!= -1 && num
>= 66 && num
< 72)
7934 regnum
= num
+ mips_regnum (gdbarch
)->dspacc
- 66;
7937 return gdbarch_num_regs (gdbarch
) + regnum
;
7941 mips_register_sim_regno (struct gdbarch
*gdbarch
, int regnum
)
7943 /* Only makes sense to supply raw registers. */
7944 gdb_assert (regnum
>= 0 && regnum
< gdbarch_num_regs (gdbarch
));
7945 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
7946 decide if it is valid. Should instead define a standard sim/gdb
7947 register numbering scheme. */
7948 if (gdbarch_register_name (gdbarch
,
7949 gdbarch_num_regs (gdbarch
) + regnum
)[0] != '\0')
7952 return LEGACY_SIM_REGNO_IGNORE
;
7956 /* Convert an integer into an address. Extracting the value signed
7957 guarantees a correctly sign extended address. */
7960 mips_integer_to_address (struct gdbarch
*gdbarch
,
7961 struct type
*type
, const gdb_byte
*buf
)
7963 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
7964 return extract_signed_integer (buf
, type
->length (), byte_order
);
7967 /* Dummy virtual frame pointer method. This is no more or less accurate
7968 than most other architectures; we just need to be explicit about it,
7969 because the pseudo-register gdbarch_sp_regnum will otherwise lead to
7970 an assertion failure. */
7973 mips_virtual_frame_pointer (struct gdbarch
*gdbarch
,
7974 CORE_ADDR pc
, int *reg
, LONGEST
*offset
)
7976 *reg
= MIPS_SP_REGNUM
;
7981 mips_find_abi_section (bfd
*abfd
, asection
*sect
, void *obj
)
7983 enum mips_abi
*abip
= (enum mips_abi
*) obj
;
7984 const char *name
= bfd_section_name (sect
);
7986 if (*abip
!= MIPS_ABI_UNKNOWN
)
7989 if (!startswith (name
, ".mdebug."))
7992 if (strcmp (name
, ".mdebug.abi32") == 0)
7993 *abip
= MIPS_ABI_O32
;
7994 else if (strcmp (name
, ".mdebug.abiN32") == 0)
7995 *abip
= MIPS_ABI_N32
;
7996 else if (strcmp (name
, ".mdebug.abi64") == 0)
7997 *abip
= MIPS_ABI_N64
;
7998 else if (strcmp (name
, ".mdebug.abiO64") == 0)
7999 *abip
= MIPS_ABI_O64
;
8000 else if (strcmp (name
, ".mdebug.eabi32") == 0)
8001 *abip
= MIPS_ABI_EABI32
;
8002 else if (strcmp (name
, ".mdebug.eabi64") == 0)
8003 *abip
= MIPS_ABI_EABI64
;
8005 warning (_("unsupported ABI %s."), name
+ 8);
8009 mips_find_long_section (bfd
*abfd
, asection
*sect
, void *obj
)
8011 int *lbp
= (int *) obj
;
8012 const char *name
= bfd_section_name (sect
);
8014 if (startswith (name
, ".gcc_compiled_long32"))
8016 else if (startswith (name
, ".gcc_compiled_long64"))
8018 else if (startswith (name
, ".gcc_compiled_long"))
8019 warning (_("unrecognized .gcc_compiled_longXX"));
8022 static enum mips_abi
8023 global_mips_abi (void)
8027 for (i
= 0; mips_abi_strings
[i
] != NULL
; i
++)
8028 if (mips_abi_strings
[i
] == mips_abi_string
)
8029 return (enum mips_abi
) i
;
8031 internal_error (_("unknown ABI string"));
8034 /* Return the default compressed instruction set, either of MIPS16
8035 or microMIPS, selected when none could have been determined from
8036 the ELF header of the binary being executed (or no binary has been
8039 static enum mips_isa
8040 global_mips_compression (void)
8044 for (i
= 0; mips_compression_strings
[i
] != NULL
; i
++)
8045 if (mips_compression_strings
[i
] == mips_compression_string
)
8046 return (enum mips_isa
) i
;
8048 internal_error (_("unknown compressed ISA string"));
8052 mips_register_g_packet_guesses (struct gdbarch
*gdbarch
)
8054 /* If the size matches the set of 32-bit or 64-bit integer registers,
8055 assume that's what we've got. */
8056 register_remote_g_packet_guess (gdbarch
, 38 * 4, mips_tdesc_gp32
);
8057 register_remote_g_packet_guess (gdbarch
, 38 * 8, mips_tdesc_gp64
);
8059 /* If the size matches the full set of registers GDB traditionally
8060 knows about, including floating point, for either 32-bit or
8061 64-bit, assume that's what we've got. */
8062 register_remote_g_packet_guess (gdbarch
, 90 * 4, mips_tdesc_gp32
);
8063 register_remote_g_packet_guess (gdbarch
, 90 * 8, mips_tdesc_gp64
);
8065 /* Otherwise we don't have a useful guess. */
8068 static struct value
*
8069 value_of_mips_user_reg (frame_info_ptr frame
, const void *baton
)
8071 const int *reg_p
= (const int *) baton
;
8072 return value_of_register (*reg_p
, frame
);
8075 static struct gdbarch
*
8076 mips_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
8078 struct gdbarch
*gdbarch
;
8080 enum mips_abi mips_abi
, found_abi
, wanted_abi
;
8082 enum mips_fpu_type fpu_type
;
8083 tdesc_arch_data_up tdesc_data
;
8084 int elf_fpu_type
= Val_GNU_MIPS_ABI_FP_ANY
;
8085 const char * const *reg_names
;
8086 struct mips_regnum mips_regnum
, *regnum
;
8087 enum mips_isa mips_isa
;
8091 /* First of all, extract the elf_flags, if available. */
8092 if (info
.abfd
&& bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
8093 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
8094 else if (arches
!= NULL
)
8096 mips_gdbarch_tdep
*tdep
8097 = gdbarch_tdep
<mips_gdbarch_tdep
> (arches
->gdbarch
);
8098 elf_flags
= tdep
->elf_flags
;
8103 gdb_printf (gdb_stdlog
,
8104 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags
);
8106 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
8107 switch ((elf_flags
& EF_MIPS_ABI
))
8109 case E_MIPS_ABI_O32
:
8110 found_abi
= MIPS_ABI_O32
;
8112 case E_MIPS_ABI_O64
:
8113 found_abi
= MIPS_ABI_O64
;
8115 case E_MIPS_ABI_EABI32
:
8116 found_abi
= MIPS_ABI_EABI32
;
8118 case E_MIPS_ABI_EABI64
:
8119 found_abi
= MIPS_ABI_EABI64
;
8122 if ((elf_flags
& EF_MIPS_ABI2
))
8123 found_abi
= MIPS_ABI_N32
;
8125 found_abi
= MIPS_ABI_UNKNOWN
;
8129 /* GCC creates a pseudo-section whose name describes the ABI. */
8130 if (found_abi
== MIPS_ABI_UNKNOWN
&& info
.abfd
!= NULL
)
8131 bfd_map_over_sections (info
.abfd
, mips_find_abi_section
, &found_abi
);
8133 /* If we have no useful BFD information, use the ABI from the last
8134 MIPS architecture (if there is one). */
8135 if (found_abi
== MIPS_ABI_UNKNOWN
&& info
.abfd
== NULL
&& arches
!= NULL
)
8137 mips_gdbarch_tdep
*tdep
8138 = gdbarch_tdep
<mips_gdbarch_tdep
> (arches
->gdbarch
);
8139 found_abi
= tdep
->found_abi
;
8142 /* Try the architecture for any hint of the correct ABI. */
8143 if (found_abi
== MIPS_ABI_UNKNOWN
8144 && info
.bfd_arch_info
!= NULL
8145 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
8147 switch (info
.bfd_arch_info
->mach
)
8149 case bfd_mach_mips3900
:
8150 found_abi
= MIPS_ABI_EABI32
;
8152 case bfd_mach_mips4100
:
8153 case bfd_mach_mips5000
:
8154 found_abi
= MIPS_ABI_EABI64
;
8156 case bfd_mach_mips8000
:
8157 case bfd_mach_mips10000
:
8158 /* On Irix, ELF64 executables use the N64 ABI. The
8159 pseudo-sections which describe the ABI aren't present
8160 on IRIX. (Even for executables created by gcc.) */
8161 if (info
.abfd
!= NULL
8162 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
8163 && elf_elfheader (info
.abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
8164 found_abi
= MIPS_ABI_N64
;
8166 found_abi
= MIPS_ABI_N32
;
8171 /* Default 64-bit objects to N64 instead of O32. */
8172 if (found_abi
== MIPS_ABI_UNKNOWN
8173 && info
.abfd
!= NULL
8174 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
8175 && elf_elfheader (info
.abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
8176 found_abi
= MIPS_ABI_N64
;
8179 gdb_printf (gdb_stdlog
, "mips_gdbarch_init: found_abi = %d\n",
8182 /* What has the user specified from the command line? */
8183 wanted_abi
= global_mips_abi ();
8185 gdb_printf (gdb_stdlog
, "mips_gdbarch_init: wanted_abi = %d\n",
8188 /* Now that we have found what the ABI for this binary would be,
8189 check whether the user is overriding it. */
8190 if (wanted_abi
!= MIPS_ABI_UNKNOWN
)
8191 mips_abi
= wanted_abi
;
8192 else if (found_abi
!= MIPS_ABI_UNKNOWN
)
8193 mips_abi
= found_abi
;
8195 mips_abi
= MIPS_ABI_O32
;
8197 gdb_printf (gdb_stdlog
, "mips_gdbarch_init: mips_abi = %d\n",
8200 /* Make sure we don't use a 32-bit architecture with a 64-bit ABI. */
8201 if (mips_abi
!= MIPS_ABI_EABI32
8202 && mips_abi
!= MIPS_ABI_O32
8203 && info
.bfd_arch_info
!= NULL
8204 && info
.bfd_arch_info
->arch
== bfd_arch_mips
8205 && info
.bfd_arch_info
->bits_per_word
< 64)
8206 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_mips
, bfd_mach_mips4000
);
8208 /* Determine the default compressed ISA. */
8209 if ((elf_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
) != 0
8210 && (elf_flags
& EF_MIPS_ARCH_ASE_M16
) == 0)
8211 mips_isa
= ISA_MICROMIPS
;
8212 else if ((elf_flags
& EF_MIPS_ARCH_ASE_M16
) != 0
8213 && (elf_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
) == 0)
8214 mips_isa
= ISA_MIPS16
;
8216 mips_isa
= global_mips_compression ();
8217 mips_compression_string
= mips_compression_strings
[mips_isa
];
8219 /* Also used when doing an architecture lookup. */
8221 gdb_printf (gdb_stdlog
,
8222 "mips_gdbarch_init: "
8223 "mips64_transfers_32bit_regs_p = %d\n",
8224 mips64_transfers_32bit_regs_p
);
8226 /* Determine the MIPS FPU type. */
8229 && bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
8230 elf_fpu_type
= bfd_elf_get_obj_attr_int (info
.abfd
, OBJ_ATTR_GNU
,
8231 Tag_GNU_MIPS_ABI_FP
);
8232 #endif /* HAVE_ELF */
8234 if (!mips_fpu_type_auto
)
8235 fpu_type
= mips_fpu_type
;
8236 else if (elf_fpu_type
!= Val_GNU_MIPS_ABI_FP_ANY
)
8238 switch (elf_fpu_type
)
8240 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
8241 fpu_type
= MIPS_FPU_DOUBLE
;
8243 case Val_GNU_MIPS_ABI_FP_SINGLE
:
8244 fpu_type
= MIPS_FPU_SINGLE
;
8246 case Val_GNU_MIPS_ABI_FP_SOFT
:
8248 /* Soft float or unknown. */
8249 fpu_type
= MIPS_FPU_NONE
;
8253 else if (info
.bfd_arch_info
!= NULL
8254 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
8255 switch (info
.bfd_arch_info
->mach
)
8257 case bfd_mach_mips3900
:
8258 case bfd_mach_mips4100
:
8259 case bfd_mach_mips4111
:
8260 case bfd_mach_mips4120
:
8261 fpu_type
= MIPS_FPU_NONE
;
8263 case bfd_mach_mips4650
:
8264 fpu_type
= MIPS_FPU_SINGLE
;
8267 fpu_type
= MIPS_FPU_DOUBLE
;
8270 else if (arches
!= NULL
)
8271 fpu_type
= mips_get_fpu_type (arches
->gdbarch
);
8273 fpu_type
= MIPS_FPU_DOUBLE
;
8275 gdb_printf (gdb_stdlog
,
8276 "mips_gdbarch_init: fpu_type = %d\n", fpu_type
);
8278 /* Check for blatant incompatibilities. */
8280 /* If we have only 32-bit registers, then we can't debug a 64-bit
8282 if (info
.target_desc
8283 && tdesc_property (info
.target_desc
, PROPERTY_GP32
) != NULL
8284 && mips_abi
!= MIPS_ABI_EABI32
8285 && mips_abi
!= MIPS_ABI_O32
)
8288 /* Fill in the OS dependent register numbers and names. */
8289 if (info
.osabi
== GDB_OSABI_LINUX
)
8291 mips_regnum
.fp0
= 38;
8292 mips_regnum
.pc
= 37;
8293 mips_regnum
.cause
= 36;
8294 mips_regnum
.badvaddr
= 35;
8295 mips_regnum
.hi
= 34;
8296 mips_regnum
.lo
= 33;
8297 mips_regnum
.fp_control_status
= 70;
8298 mips_regnum
.fp_implementation_revision
= 71;
8299 mips_regnum
.dspacc
= -1;
8300 mips_regnum
.dspctl
= -1;
8304 reg_names
= mips_linux_reg_names
;
8308 mips_regnum
.lo
= MIPS_EMBED_LO_REGNUM
;
8309 mips_regnum
.hi
= MIPS_EMBED_HI_REGNUM
;
8310 mips_regnum
.badvaddr
= MIPS_EMBED_BADVADDR_REGNUM
;
8311 mips_regnum
.cause
= MIPS_EMBED_CAUSE_REGNUM
;
8312 mips_regnum
.pc
= MIPS_EMBED_PC_REGNUM
;
8313 mips_regnum
.fp0
= MIPS_EMBED_FP0_REGNUM
;
8314 mips_regnum
.fp_control_status
= 70;
8315 mips_regnum
.fp_implementation_revision
= 71;
8316 mips_regnum
.dspacc
= dspacc
= -1;
8317 mips_regnum
.dspctl
= dspctl
= -1;
8318 num_regs
= MIPS_LAST_EMBED_REGNUM
+ 1;
8319 if (info
.bfd_arch_info
!= NULL
8320 && info
.bfd_arch_info
->mach
== bfd_mach_mips3900
)
8321 reg_names
= mips_tx39_reg_names
;
8323 reg_names
= mips_generic_reg_names
;
8326 /* Check any target description for validity. */
8327 if (tdesc_has_registers (info
.target_desc
))
8329 static const char *const mips_gprs
[] = {
8330 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
8331 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
8332 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
8333 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
8335 static const char *const mips_fprs
[] = {
8336 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
8337 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
8338 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
8339 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
8342 const struct tdesc_feature
*feature
;
8345 feature
= tdesc_find_feature (info
.target_desc
,
8346 "org.gnu.gdb.mips.cpu");
8347 if (feature
== NULL
)
8350 tdesc_data
= tdesc_data_alloc ();
8353 for (i
= MIPS_ZERO_REGNUM
; i
<= MIPS_RA_REGNUM
; i
++)
8354 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (), i
,
8358 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8359 mips_regnum
.lo
, "lo");
8360 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8361 mips_regnum
.hi
, "hi");
8362 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8363 mips_regnum
.pc
, "pc");
8368 feature
= tdesc_find_feature (info
.target_desc
,
8369 "org.gnu.gdb.mips.cp0");
8370 if (feature
== NULL
)
8374 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8375 mips_regnum
.badvaddr
, "badvaddr");
8376 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8377 MIPS_PS_REGNUM
, "status");
8378 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8379 mips_regnum
.cause
, "cause");
8384 /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
8385 backend is not prepared for that, though. */
8386 feature
= tdesc_find_feature (info
.target_desc
,
8387 "org.gnu.gdb.mips.fpu");
8388 if (feature
== NULL
)
8392 for (i
= 0; i
< 32; i
++)
8393 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8394 i
+ mips_regnum
.fp0
, mips_fprs
[i
]);
8396 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8397 mips_regnum
.fp_control_status
,
8400 &= tdesc_numbered_register (feature
, tdesc_data
.get (),
8401 mips_regnum
.fp_implementation_revision
,
8407 num_regs
= mips_regnum
.fp_implementation_revision
+ 1;
8411 feature
= tdesc_find_feature (info
.target_desc
,
8412 "org.gnu.gdb.mips.dsp");
8413 /* The DSP registers are optional; it's OK if they are absent. */
8414 if (feature
!= NULL
)
8418 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8419 dspacc
+ i
++, "hi1");
8420 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8421 dspacc
+ i
++, "lo1");
8422 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8423 dspacc
+ i
++, "hi2");
8424 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8425 dspacc
+ i
++, "lo2");
8426 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8427 dspacc
+ i
++, "hi3");
8428 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8429 dspacc
+ i
++, "lo3");
8431 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
.get (),
8437 mips_regnum
.dspacc
= dspacc
;
8438 mips_regnum
.dspctl
= dspctl
;
8440 num_regs
= mips_regnum
.dspctl
+ 1;
8444 /* It would be nice to detect an attempt to use a 64-bit ABI
8445 when only 32-bit registers are provided. */
8449 /* Try to find a pre-existing architecture. */
8450 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
8452 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
8454 mips_gdbarch_tdep
*tdep
8455 = gdbarch_tdep
<mips_gdbarch_tdep
> (arches
->gdbarch
);
8457 /* MIPS needs to be pedantic about which ABI and the compressed
8458 ISA variation the object is using. */
8459 if (tdep
->elf_flags
!= elf_flags
)
8461 if (tdep
->mips_abi
!= mips_abi
)
8463 if (tdep
->mips_isa
!= mips_isa
)
8465 /* Need to be pedantic about which register virtual size is
8467 if (tdep
->mips64_transfers_32bit_regs_p
8468 != mips64_transfers_32bit_regs_p
)
8470 /* Be pedantic about which FPU is selected. */
8471 if (mips_get_fpu_type (arches
->gdbarch
) != fpu_type
)
8474 return arches
->gdbarch
;
8477 /* Need a new architecture. Fill in a target specific vector. */
8478 mips_gdbarch_tdep
*tdep
= new mips_gdbarch_tdep
;
8479 gdbarch
= gdbarch_alloc (&info
, tdep
);
8480 tdep
->elf_flags
= elf_flags
;
8481 tdep
->mips64_transfers_32bit_regs_p
= mips64_transfers_32bit_regs_p
;
8482 tdep
->found_abi
= found_abi
;
8483 tdep
->mips_abi
= mips_abi
;
8484 tdep
->mips_isa
= mips_isa
;
8485 tdep
->mips_fpu_type
= fpu_type
;
8486 tdep
->register_size_valid_p
= 0;
8487 tdep
->register_size
= 0;
8489 if (info
.target_desc
)
8491 /* Some useful properties can be inferred from the target. */
8492 if (tdesc_property (info
.target_desc
, PROPERTY_GP32
) != NULL
)
8494 tdep
->register_size_valid_p
= 1;
8495 tdep
->register_size
= 4;
8497 else if (tdesc_property (info
.target_desc
, PROPERTY_GP64
) != NULL
)
8499 tdep
->register_size_valid_p
= 1;
8500 tdep
->register_size
= 8;
8504 /* Initially set everything according to the default ABI/ISA. */
8505 set_gdbarch_short_bit (gdbarch
, 16);
8506 set_gdbarch_int_bit (gdbarch
, 32);
8507 set_gdbarch_float_bit (gdbarch
, 32);
8508 set_gdbarch_double_bit (gdbarch
, 64);
8509 set_gdbarch_long_double_bit (gdbarch
, 64);
8510 set_gdbarch_register_reggroup_p (gdbarch
, mips_register_reggroup_p
);
8511 set_gdbarch_pseudo_register_read (gdbarch
, mips_pseudo_register_read
);
8512 set_gdbarch_pseudo_register_write (gdbarch
, mips_pseudo_register_write
);
8514 set_gdbarch_ax_pseudo_register_collect (gdbarch
,
8515 mips_ax_pseudo_register_collect
);
8516 set_gdbarch_ax_pseudo_register_push_stack
8517 (gdbarch
, mips_ax_pseudo_register_push_stack
);
8519 set_gdbarch_elf_make_msymbol_special (gdbarch
,
8520 mips_elf_make_msymbol_special
);
8521 set_gdbarch_make_symbol_special (gdbarch
, mips_make_symbol_special
);
8522 set_gdbarch_adjust_dwarf2_addr (gdbarch
, mips_adjust_dwarf2_addr
);
8523 set_gdbarch_adjust_dwarf2_line (gdbarch
, mips_adjust_dwarf2_line
);
8525 regnum
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct mips_regnum
);
8526 *regnum
= mips_regnum
;
8527 set_gdbarch_fp0_regnum (gdbarch
, regnum
->fp0
);
8528 set_gdbarch_num_regs (gdbarch
, num_regs
);
8529 set_gdbarch_num_pseudo_regs (gdbarch
, num_regs
);
8530 set_gdbarch_register_name (gdbarch
, mips_register_name
);
8531 set_gdbarch_virtual_frame_pointer (gdbarch
, mips_virtual_frame_pointer
);
8532 tdep
->mips_processor_reg_names
= reg_names
;
8533 tdep
->regnum
= regnum
;
8538 set_gdbarch_push_dummy_call (gdbarch
, mips_o32_push_dummy_call
);
8539 set_gdbarch_return_value (gdbarch
, mips_o32_return_value
);
8540 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 4 - 1;
8541 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
8542 tdep
->default_mask_address_p
= 0;
8543 set_gdbarch_long_bit (gdbarch
, 32);
8544 set_gdbarch_ptr_bit (gdbarch
, 32);
8545 set_gdbarch_long_long_bit (gdbarch
, 64);
8548 set_gdbarch_push_dummy_call (gdbarch
, mips_o64_push_dummy_call
);
8549 set_gdbarch_return_value (gdbarch
, mips_o64_return_value
);
8550 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 4 - 1;
8551 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
8552 tdep
->default_mask_address_p
= 0;
8553 set_gdbarch_long_bit (gdbarch
, 32);
8554 set_gdbarch_ptr_bit (gdbarch
, 32);
8555 set_gdbarch_long_long_bit (gdbarch
, 64);
8557 case MIPS_ABI_EABI32
:
8558 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
8559 set_gdbarch_return_value (gdbarch
, mips_eabi_return_value
);
8560 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
8561 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
8562 tdep
->default_mask_address_p
= 0;
8563 set_gdbarch_long_bit (gdbarch
, 32);
8564 set_gdbarch_ptr_bit (gdbarch
, 32);
8565 set_gdbarch_long_long_bit (gdbarch
, 64);
8567 case MIPS_ABI_EABI64
:
8568 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
8569 set_gdbarch_return_value (gdbarch
, mips_eabi_return_value
);
8570 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
8571 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
8572 tdep
->default_mask_address_p
= 0;
8573 set_gdbarch_long_bit (gdbarch
, 64);
8574 set_gdbarch_ptr_bit (gdbarch
, 64);
8575 set_gdbarch_long_long_bit (gdbarch
, 64);
8578 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
8579 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
8580 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
8581 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
8582 tdep
->default_mask_address_p
= 0;
8583 set_gdbarch_long_bit (gdbarch
, 32);
8584 set_gdbarch_ptr_bit (gdbarch
, 32);
8585 set_gdbarch_long_long_bit (gdbarch
, 64);
8586 set_gdbarch_long_double_bit (gdbarch
, 128);
8587 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
8590 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
8591 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
8592 tdep
->mips_last_arg_regnum
= MIPS_A0_REGNUM
+ 8 - 1;
8593 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
8594 tdep
->default_mask_address_p
= 0;
8595 set_gdbarch_long_bit (gdbarch
, 64);
8596 set_gdbarch_ptr_bit (gdbarch
, 64);
8597 set_gdbarch_long_long_bit (gdbarch
, 64);
8598 set_gdbarch_long_double_bit (gdbarch
, 128);
8599 set_gdbarch_long_double_format (gdbarch
, floatformats_ibm_long_double
);
8602 internal_error (_("unknown ABI in switch"));
8605 /* GCC creates a pseudo-section whose name specifies the size of
8606 longs, since -mlong32 or -mlong64 may be used independent of
8607 other options. How those options affect pointer sizes is ABI and
8608 architecture dependent, so use them to override the default sizes
8609 set by the ABI. This table shows the relationship between ABI,
8610 -mlongXX, and size of pointers:
8612 ABI -mlongXX ptr bits
8613 --- -------- --------
8627 Note that for o32 and eabi32, pointers are always 32 bits
8628 regardless of any -mlongXX option. For all others, pointers and
8629 longs are the same, as set by -mlongXX or set by defaults. */
8631 if (info
.abfd
!= NULL
)
8635 bfd_map_over_sections (info
.abfd
, mips_find_long_section
, &long_bit
);
8638 set_gdbarch_long_bit (gdbarch
, long_bit
);
8642 case MIPS_ABI_EABI32
:
8647 case MIPS_ABI_EABI64
:
8648 set_gdbarch_ptr_bit (gdbarch
, long_bit
);
8651 internal_error (_("unknown ABI in switch"));
8656 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
8657 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
8660 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
8661 flag in object files because to do so would make it impossible to
8662 link with libraries compiled without "-gp32". This is
8663 unnecessarily restrictive.
8665 We could solve this problem by adding "-gp32" multilibs to gcc,
8666 but to set this flag before gcc is built with such multilibs will
8667 break too many systems.''
8669 But even more unhelpfully, the default linker output target for
8670 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
8671 for 64-bit programs - you need to change the ABI to change this,
8672 and not all gcc targets support that currently. Therefore using
8673 this flag to detect 32-bit mode would do the wrong thing given
8674 the current gcc - it would make GDB treat these 64-bit programs
8675 as 32-bit programs by default. */
8677 set_gdbarch_read_pc (gdbarch
, mips_read_pc
);
8678 set_gdbarch_write_pc (gdbarch
, mips_write_pc
);
8680 /* Add/remove bits from an address. The MIPS needs be careful to
8681 ensure that all 32 bit addresses are sign extended to 64 bits. */
8682 set_gdbarch_addr_bits_remove (gdbarch
, mips_addr_bits_remove
);
8684 /* Unwind the frame. */
8685 set_gdbarch_unwind_pc (gdbarch
, mips_unwind_pc
);
8686 set_gdbarch_unwind_sp (gdbarch
, mips_unwind_sp
);
8687 set_gdbarch_dummy_id (gdbarch
, mips_dummy_id
);
8689 /* Map debug register numbers onto internal register numbers. */
8690 set_gdbarch_stab_reg_to_regnum (gdbarch
, mips_stab_reg_to_regnum
);
8691 set_gdbarch_ecoff_reg_to_regnum (gdbarch
,
8692 mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
8693 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
,
8694 mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
8695 set_gdbarch_register_sim_regno (gdbarch
, mips_register_sim_regno
);
8697 /* MIPS version of CALL_DUMMY. */
8699 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
8700 set_gdbarch_push_dummy_code (gdbarch
, mips_push_dummy_code
);
8701 set_gdbarch_frame_align (gdbarch
, mips_frame_align
);
8703 set_gdbarch_print_float_info (gdbarch
, mips_print_float_info
);
8705 set_gdbarch_convert_register_p (gdbarch
, mips_convert_register_p
);
8706 set_gdbarch_register_to_value (gdbarch
, mips_register_to_value
);
8707 set_gdbarch_value_to_register (gdbarch
, mips_value_to_register
);
8709 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
8710 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, mips_breakpoint_kind_from_pc
);
8711 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, mips_sw_breakpoint_from_kind
);
8712 set_gdbarch_adjust_breakpoint_address (gdbarch
,
8713 mips_adjust_breakpoint_address
);
8715 set_gdbarch_skip_prologue (gdbarch
, mips_skip_prologue
);
8717 set_gdbarch_stack_frame_destroyed_p (gdbarch
, mips_stack_frame_destroyed_p
);
8719 set_gdbarch_pointer_to_address (gdbarch
, signed_pointer_to_address
);
8720 set_gdbarch_address_to_pointer (gdbarch
, address_to_signed_pointer
);
8721 set_gdbarch_integer_to_address (gdbarch
, mips_integer_to_address
);
8723 set_gdbarch_register_type (gdbarch
, mips_register_type
);
8725 set_gdbarch_print_registers_info (gdbarch
, mips_print_registers_info
);
8727 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_mips
);
8728 if (mips_abi
== MIPS_ABI_N64
)
8729 set_gdbarch_disassembler_options_implicit
8730 (gdbarch
, (const char *) mips_disassembler_options_n64
);
8731 else if (mips_abi
== MIPS_ABI_N32
)
8732 set_gdbarch_disassembler_options_implicit
8733 (gdbarch
, (const char *) mips_disassembler_options_n32
);
8735 set_gdbarch_disassembler_options_implicit
8736 (gdbarch
, (const char *) mips_disassembler_options_o32
);
8737 set_gdbarch_disassembler_options (gdbarch
, &mips_disassembler_options
);
8738 set_gdbarch_valid_disassembler_options (gdbarch
,
8739 disassembler_options_mips ());
8741 /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint,
8742 HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint
8743 need to all be folded into the target vector. Since they are
8744 being used as guards for target_stopped_by_watchpoint, why not have
8745 target_stopped_by_watchpoint return the type of watchpoint that the code
8747 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
8749 set_gdbarch_skip_trampoline_code (gdbarch
, mips_skip_trampoline_code
);
8751 /* NOTE drow/2012-04-25: We overload the core solib trampoline code
8752 to support MIPS16. This is a bad thing. Make sure not to do it
8753 if we have an OS ABI that actually supports shared libraries, since
8754 shared library support is more important. If we have an OS someday
8755 that supports both shared libraries and MIPS16, we'll have to find
8756 a better place for these.
8757 macro/2012-04-25: But that applies to return trampolines only and
8758 currently no MIPS OS ABI uses shared libraries that have them. */
8759 set_gdbarch_in_solib_return_trampoline (gdbarch
, mips_in_return_stub
);
8761 set_gdbarch_single_step_through_delay (gdbarch
,
8762 mips_single_step_through_delay
);
8764 /* Virtual tables. */
8765 set_gdbarch_vbit_in_delta (gdbarch
, 1);
8767 mips_register_g_packet_guesses (gdbarch
);
8769 /* Hook in OS ABI-specific overrides, if they have been registered. */
8770 info
.tdesc_data
= tdesc_data
.get ();
8771 gdbarch_init_osabi (info
, gdbarch
);
8773 /* The hook may have adjusted num_regs, fetch the final value and
8774 set pc_regnum and sp_regnum now that it has been fixed. */
8775 num_regs
= gdbarch_num_regs (gdbarch
);
8776 set_gdbarch_pc_regnum (gdbarch
, regnum
->pc
+ num_regs
);
8777 set_gdbarch_sp_regnum (gdbarch
, MIPS_SP_REGNUM
+ num_regs
);
8779 /* Unwind the frame. */
8780 dwarf2_append_unwinders (gdbarch
);
8781 frame_unwind_append_unwinder (gdbarch
, &mips_stub_frame_unwind
);
8782 frame_unwind_append_unwinder (gdbarch
, &mips_insn16_frame_unwind
);
8783 frame_unwind_append_unwinder (gdbarch
, &mips_micro_frame_unwind
);
8784 frame_unwind_append_unwinder (gdbarch
, &mips_insn32_frame_unwind
);
8785 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
8786 frame_base_append_sniffer (gdbarch
, mips_stub_frame_base_sniffer
);
8787 frame_base_append_sniffer (gdbarch
, mips_insn16_frame_base_sniffer
);
8788 frame_base_append_sniffer (gdbarch
, mips_micro_frame_base_sniffer
);
8789 frame_base_append_sniffer (gdbarch
, mips_insn32_frame_base_sniffer
);
8791 if (tdesc_data
!= nullptr)
8793 set_tdesc_pseudo_register_type (gdbarch
, mips_pseudo_register_type
);
8794 tdesc_use_registers (gdbarch
, info
.target_desc
, std::move (tdesc_data
));
8796 /* Override the normal target description methods to handle our
8797 dual real and pseudo registers. */
8798 set_gdbarch_register_name (gdbarch
, mips_register_name
);
8799 set_gdbarch_register_reggroup_p (gdbarch
,
8800 mips_tdesc_register_reggroup_p
);
8802 num_regs
= gdbarch_num_regs (gdbarch
);
8803 set_gdbarch_num_pseudo_regs (gdbarch
, num_regs
);
8804 set_gdbarch_pc_regnum (gdbarch
, tdep
->regnum
->pc
+ num_regs
);
8805 set_gdbarch_sp_regnum (gdbarch
, MIPS_SP_REGNUM
+ num_regs
);
8808 /* Add ABI-specific aliases for the registers. */
8809 if (mips_abi
== MIPS_ABI_N32
|| mips_abi
== MIPS_ABI_N64
)
8810 for (i
= 0; i
< ARRAY_SIZE (mips_n32_n64_aliases
); i
++)
8811 user_reg_add (gdbarch
, mips_n32_n64_aliases
[i
].name
,
8812 value_of_mips_user_reg
, &mips_n32_n64_aliases
[i
].regnum
);
8814 for (i
= 0; i
< ARRAY_SIZE (mips_o32_aliases
); i
++)
8815 user_reg_add (gdbarch
, mips_o32_aliases
[i
].name
,
8816 value_of_mips_user_reg
, &mips_o32_aliases
[i
].regnum
);
8818 /* Add some other standard aliases. */
8819 for (i
= 0; i
< ARRAY_SIZE (mips_register_aliases
); i
++)
8820 user_reg_add (gdbarch
, mips_register_aliases
[i
].name
,
8821 value_of_mips_user_reg
, &mips_register_aliases
[i
].regnum
);
8823 for (i
= 0; i
< ARRAY_SIZE (mips_numeric_register_aliases
); i
++)
8824 user_reg_add (gdbarch
, mips_numeric_register_aliases
[i
].name
,
8825 value_of_mips_user_reg
,
8826 &mips_numeric_register_aliases
[i
].regnum
);
8832 mips_abi_update (const char *ignore_args
,
8833 int from_tty
, struct cmd_list_element
*c
)
8835 struct gdbarch_info info
;
8837 /* Force the architecture to update, and (if it's a MIPS architecture)
8838 mips_gdbarch_init will take care of the rest. */
8839 gdbarch_update_p (info
);
8842 /* Print out which MIPS ABI is in use. */
8845 show_mips_abi (struct ui_file
*file
,
8847 struct cmd_list_element
*ignored_cmd
,
8848 const char *ignored_value
)
8850 if (gdbarch_bfd_arch_info (target_gdbarch ())->arch
!= bfd_arch_mips
)
8853 "The MIPS ABI is unknown because the current architecture "
8857 enum mips_abi global_abi
= global_mips_abi ();
8858 enum mips_abi actual_abi
= mips_abi (target_gdbarch ());
8859 const char *actual_abi_str
= mips_abi_strings
[actual_abi
];
8861 if (global_abi
== MIPS_ABI_UNKNOWN
)
8864 "The MIPS ABI is set automatically (currently \"%s\").\n",
8866 else if (global_abi
== actual_abi
)
8869 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
8873 /* Probably shouldn't happen... */
8875 "The (auto detected) MIPS ABI \"%s\" is in use "
8876 "even though the user setting was \"%s\".\n",
8877 actual_abi_str
, mips_abi_strings
[global_abi
]);
8882 /* Print out which MIPS compressed ISA encoding is used. */
8885 show_mips_compression (struct ui_file
*file
, int from_tty
,
8886 struct cmd_list_element
*c
, const char *value
)
8888 gdb_printf (file
, _("The compressed ISA encoding used is %s.\n"),
8892 /* Return a textual name for MIPS FPU type FPU_TYPE. */
8895 mips_fpu_type_str (enum mips_fpu_type fpu_type
)
8901 case MIPS_FPU_SINGLE
:
8903 case MIPS_FPU_DOUBLE
:
8911 mips_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
8913 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
8917 int ef_mips_32bitmode
;
8918 /* Determine the ISA. */
8919 switch (tdep
->elf_flags
& EF_MIPS_ARCH
)
8937 /* Determine the size of a pointer. */
8938 ef_mips_32bitmode
= (tdep
->elf_flags
& EF_MIPS_32BITMODE
);
8940 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
8943 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
8946 "mips_dump_tdep: ef_mips_arch = %d\n",
8949 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
8950 tdep
->mips_abi
, mips_abi_strings
[tdep
->mips_abi
]);
8953 "mips_mask_address_p() %d (default %d)\n",
8954 mips_mask_address_p (tdep
),
8955 tdep
->default_mask_address_p
);
8958 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
8959 MIPS_DEFAULT_FPU_TYPE
,
8960 mips_fpu_type_str (MIPS_DEFAULT_FPU_TYPE
));
8961 gdb_printf (file
, "mips_dump_tdep: MIPS_EABI = %d\n",
8962 mips_eabi (gdbarch
));
8964 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
8965 mips_get_fpu_type (gdbarch
),
8966 mips_fpu_type_str (mips_get_fpu_type (gdbarch
)));
8969 void _initialize_mips_tdep ();
8971 _initialize_mips_tdep ()
8973 static struct cmd_list_element
*mipsfpulist
= NULL
;
8975 mips_abi_string
= mips_abi_strings
[MIPS_ABI_UNKNOWN
];
8976 if (MIPS_ABI_LAST
+ 1
8977 != sizeof (mips_abi_strings
) / sizeof (mips_abi_strings
[0]))
8978 internal_error (_("mips_abi_strings out of sync"));
8980 gdbarch_register (bfd_arch_mips
, mips_gdbarch_init
, mips_dump_tdep
);
8982 /* Create feature sets with the appropriate properties. The values
8983 are not important. */
8984 mips_tdesc_gp32
= allocate_target_description ().release ();
8985 set_tdesc_property (mips_tdesc_gp32
, PROPERTY_GP32
, "");
8987 mips_tdesc_gp64
= allocate_target_description ().release ();
8988 set_tdesc_property (mips_tdesc_gp64
, PROPERTY_GP64
, "");
8990 /* Add root prefix command for all "set mips"/"show mips" commands. */
8991 add_setshow_prefix_cmd ("mips", no_class
,
8992 _("Various MIPS specific commands."),
8993 _("Various MIPS specific commands."),
8994 &setmipscmdlist
, &showmipscmdlist
,
8995 &setlist
, &showlist
);
8997 /* Allow the user to override the ABI. */
8998 add_setshow_enum_cmd ("abi", class_obscure
, mips_abi_strings
,
8999 &mips_abi_string
, _("\
9000 Set the MIPS ABI used by this program."), _("\
9001 Show the MIPS ABI used by this program."), _("\
9002 This option can be set to one of:\n\
9003 auto - the default ABI associated with the current binary\n\
9012 &setmipscmdlist
, &showmipscmdlist
);
9014 /* Allow the user to set the ISA to assume for compressed code if ELF
9015 file flags don't tell or there is no program file selected. This
9016 setting is updated whenever unambiguous ELF file flags are interpreted,
9017 and carried over to subsequent sessions. */
9018 add_setshow_enum_cmd ("compression", class_obscure
, mips_compression_strings
,
9019 &mips_compression_string
, _("\
9020 Set the compressed ISA encoding used by MIPS code."), _("\
9021 Show the compressed ISA encoding used by MIPS code."), _("\
9022 Select the compressed ISA encoding used in functions that have no symbol\n\
9023 information available. The encoding can be set to either of:\n\
9026 and is updated automatically from ELF file flags if available."),
9028 show_mips_compression
,
9029 &setmipscmdlist
, &showmipscmdlist
);
9031 /* Let the user turn off floating point and set the fence post for
9032 heuristic_proc_start. */
9034 add_basic_prefix_cmd ("mipsfpu", class_support
,
9035 _("Set use of MIPS floating-point coprocessor."),
9036 &mipsfpulist
, 0, &setlist
);
9037 add_cmd ("single", class_support
, set_mipsfpu_single_command
,
9038 _("Select single-precision MIPS floating-point coprocessor."),
9040 cmd_list_element
*set_mipsfpu_double_cmd
9041 = add_cmd ("double", class_support
, set_mipsfpu_double_command
,
9042 _("Select double-precision MIPS floating-point coprocessor."),
9044 add_alias_cmd ("on", set_mipsfpu_double_cmd
, class_support
, 1, &mipsfpulist
);
9045 add_alias_cmd ("yes", set_mipsfpu_double_cmd
, class_support
, 1, &mipsfpulist
);
9046 add_alias_cmd ("1", set_mipsfpu_double_cmd
, class_support
, 1, &mipsfpulist
);
9048 cmd_list_element
*set_mipsfpu_none_cmd
9049 = add_cmd ("none", class_support
, set_mipsfpu_none_command
,
9050 _("Select no MIPS floating-point coprocessor."), &mipsfpulist
);
9051 add_alias_cmd ("off", set_mipsfpu_none_cmd
, class_support
, 1, &mipsfpulist
);
9052 add_alias_cmd ("no", set_mipsfpu_none_cmd
, class_support
, 1, &mipsfpulist
);
9053 add_alias_cmd ("0", set_mipsfpu_none_cmd
, class_support
, 1, &mipsfpulist
);
9054 add_cmd ("auto", class_support
, set_mipsfpu_auto_command
,
9055 _("Select MIPS floating-point coprocessor automatically."),
9057 add_cmd ("mipsfpu", class_support
, show_mipsfpu_command
,
9058 _("Show current use of MIPS floating-point coprocessor target."),
9061 /* We really would like to have both "0" and "unlimited" work, but
9062 command.c doesn't deal with that. So make it a var_zinteger
9063 because the user can always use "999999" or some such for unlimited. */
9064 add_setshow_zinteger_cmd ("heuristic-fence-post", class_support
,
9065 &heuristic_fence_post
, _("\
9066 Set the distance searched for the start of a function."), _("\
9067 Show the distance searched for the start of a function."), _("\
9068 If you are debugging a stripped executable, GDB needs to search through the\n\
9069 program for the start of a function. This command sets the distance of the\n\
9070 search. The only need to set it is when debugging a stripped executable."),
9071 reinit_frame_cache_sfunc
,
9072 NULL
, /* FIXME: i18n: The distance searched for
9073 the start of a function is %s. */
9074 &setlist
, &showlist
);
9076 /* Allow the user to control whether the upper bits of 64-bit
9077 addresses should be zeroed. */
9078 add_setshow_auto_boolean_cmd ("mask-address", no_class
,
9079 &mask_address_var
, _("\
9080 Set zeroing of upper 32 bits of 64-bit addresses."), _("\
9081 Show zeroing of upper 32 bits of 64-bit addresses."), _("\
9082 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\
9083 allow GDB to determine the correct value."),
9084 NULL
, show_mask_address
,
9085 &setmipscmdlist
, &showmipscmdlist
);
9087 /* Allow the user to control the size of 32 bit registers within the
9088 raw remote packet. */
9089 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure
,
9090 &mips64_transfers_32bit_regs_p
, _("\
9091 Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
9093 Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
9095 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
9096 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
9097 64 bits for others. Use \"off\" to disable compatibility mode"),
9098 set_mips64_transfers_32bit_regs
,
9099 NULL
, /* FIXME: i18n: Compatibility with 64-bit
9100 MIPS target that transfers 32-bit
9101 quantities is %s. */
9102 &setlist
, &showlist
);
9104 /* Debug this files internals. */
9105 add_setshow_zuinteger_cmd ("mips", class_maintenance
,
9107 Set mips debugging."), _("\
9108 Show mips debugging."), _("\
9109 When non-zero, mips specific debugging is enabled."),
9111 NULL
, /* FIXME: i18n: Mips debugging is
9113 &setdebuglist
, &showdebuglist
);