1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
7 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
40 #include "arch-utils.h"
43 #include "mips-tdep.h"
45 #include "reggroups.h"
46 #include "opcode/mips.h"
50 #include "sim-regno.h"
53 static void set_reg_offset (CORE_ADDR
*saved_regs
, int regnum
, CORE_ADDR off
);
54 static struct type
*mips_register_type (struct gdbarch
*gdbarch
, int regnum
);
56 /* A useful bit in the CP0 status register (PS_REGNUM). */
57 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
58 #define ST0_FR (1 << 26)
60 /* The sizes of floating point registers. */
64 MIPS_FPU_SINGLE_REGSIZE
= 4,
65 MIPS_FPU_DOUBLE_REGSIZE
= 8
69 static const char *mips_abi_string
;
71 static const char *mips_abi_strings
[] = {
82 struct frame_extra_info
84 mips_extra_func_info_t proc_desc
;
88 /* Various MIPS ISA options (related to stack analysis) can be
89 overridden dynamically. Establish an enum/array for managing
92 static const char size_auto
[] = "auto";
93 static const char size_32
[] = "32";
94 static const char size_64
[] = "64";
96 static const char *size_enums
[] = {
103 /* Some MIPS boards don't support floating point while others only
104 support single-precision floating-point operations. See also
105 FP_REGISTER_DOUBLE. */
109 MIPS_FPU_DOUBLE
, /* Full double precision floating point. */
110 MIPS_FPU_SINGLE
, /* Single precision floating point (R4650). */
111 MIPS_FPU_NONE
/* No floating point. */
114 #ifndef MIPS_DEFAULT_FPU_TYPE
115 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
117 static int mips_fpu_type_auto
= 1;
118 static enum mips_fpu_type mips_fpu_type
= MIPS_DEFAULT_FPU_TYPE
;
120 static int mips_debug
= 0;
122 /* MIPS specific per-architecture information */
125 /* from the elf header */
129 enum mips_abi mips_abi
;
130 enum mips_abi found_abi
;
131 enum mips_fpu_type mips_fpu_type
;
132 int mips_last_arg_regnum
;
133 int mips_last_fp_arg_regnum
;
134 int mips_default_saved_regsize
;
135 int mips_fp_register_double
;
136 int mips_default_stack_argsize
;
137 int default_mask_address_p
;
138 /* Is the target using 64-bit raw integer registers but only
139 storing a left-aligned 32-bit value in each? */
140 int mips64_transfers_32bit_regs_p
;
141 /* Indexes for various registers. IRIX and embedded have
142 different values. This contains the "public" fields. Don't
143 add any that do not need to be public. */
144 const struct mips_regnum
*regnum
;
145 /* Register names table for the current register set. */
146 const char **mips_processor_reg_names
;
149 const struct mips_regnum
*
150 mips_regnum (struct gdbarch
*gdbarch
)
152 return gdbarch_tdep (gdbarch
)->regnum
;
156 mips_fpa0_regnum (struct gdbarch
*gdbarch
)
158 return mips_regnum (gdbarch
)->fp0
+ 12;
161 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
162 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
164 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
166 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
168 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
170 /* Return the currently configured (or set) saved register size. */
172 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
174 static const char *mips_saved_regsize_string
= size_auto
;
176 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
178 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
179 functions to test, set, or clear bit 0 of addresses. */
182 is_mips16_addr (CORE_ADDR addr
)
188 make_mips16_addr (CORE_ADDR addr
)
194 unmake_mips16_addr (CORE_ADDR addr
)
196 return ((addr
) & ~1);
199 /* Return the contents of register REGNUM as a signed integer. */
202 read_signed_register (int regnum
)
204 void *buf
= alloca (register_size (current_gdbarch
, regnum
));
205 deprecated_read_register_gen (regnum
, buf
);
206 return (extract_signed_integer (buf
, register_size (current_gdbarch
, regnum
)));
210 read_signed_register_pid (int regnum
, ptid_t ptid
)
215 if (ptid_equal (ptid
, inferior_ptid
))
216 return read_signed_register (regnum
);
218 save_ptid
= inferior_ptid
;
220 inferior_ptid
= ptid
;
222 retval
= read_signed_register (regnum
);
224 inferior_ptid
= save_ptid
;
229 /* Return the MIPS ABI associated with GDBARCH. */
231 mips_abi (struct gdbarch
*gdbarch
)
233 return gdbarch_tdep (gdbarch
)->mips_abi
;
237 mips_regsize (struct gdbarch
*gdbarch
)
239 return (gdbarch_bfd_arch_info (gdbarch
)->bits_per_word
240 / gdbarch_bfd_arch_info (gdbarch
)->bits_per_byte
);
244 mips_saved_regsize (void)
246 if (mips_saved_regsize_string
== size_auto
)
247 return MIPS_DEFAULT_SAVED_REGSIZE
;
248 else if (mips_saved_regsize_string
== size_64
)
250 else /* if (mips_saved_regsize_string == size_32) */
254 /* Functions for setting and testing a bit in a minimal symbol that
255 marks it as 16-bit function. The MSB of the minimal symbol's
256 "info" field is used for this purpose.
258 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
259 i.e. refers to a 16-bit function, and sets a "special" bit in a
260 minimal symbol to mark it as a 16-bit function
262 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
265 mips_elf_make_msymbol_special (asymbol
*sym
, struct minimal_symbol
*msym
)
267 if (((elf_symbol_type
*)(sym
))->internal_elf_sym
.st_other
== STO_MIPS16
)
269 MSYMBOL_INFO (msym
) = (char *)
270 (((long) MSYMBOL_INFO (msym
)) | 0x80000000);
271 SYMBOL_VALUE_ADDRESS (msym
) |= 1;
276 msymbol_is_special (struct minimal_symbol
*msym
)
278 return (((long) MSYMBOL_INFO (msym
) & 0x80000000) != 0);
281 /* XFER a value from the big/little/left end of the register.
282 Depending on the size of the value it might occupy the entire
283 register or just part of it. Make an allowance for this, aligning
284 things accordingly. */
287 mips_xfer_register (struct regcache
*regcache
, int reg_num
, int length
,
288 enum bfd_endian endian
, bfd_byte
*in
, const bfd_byte
*out
,
291 bfd_byte reg
[MAX_REGISTER_SIZE
];
293 gdb_assert (reg_num
>= NUM_REGS
);
294 /* Need to transfer the left or right part of the register, based on
295 the targets byte order. */
299 reg_offset
= register_size (current_gdbarch
, reg_num
) - length
;
301 case BFD_ENDIAN_LITTLE
:
304 case BFD_ENDIAN_UNKNOWN
: /* Indicates no alignment. */
308 internal_error (__FILE__
, __LINE__
, "bad switch");
311 fprintf_unfiltered (gdb_stderr
,
312 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
313 reg_num
, reg_offset
, buf_offset
, length
);
314 if (mips_debug
&& out
!= NULL
)
317 fprintf_unfiltered (gdb_stdlog
, "out ");
318 for (i
= 0; i
< length
; i
++)
319 fprintf_unfiltered (gdb_stdlog
, "%02x", out
[buf_offset
+ i
]);
322 regcache_cooked_read_part (regcache
, reg_num
, reg_offset
, length
, in
+ buf_offset
);
324 regcache_cooked_write_part (regcache
, reg_num
, reg_offset
, length
, out
+ buf_offset
);
325 if (mips_debug
&& in
!= NULL
)
328 fprintf_unfiltered (gdb_stdlog
, "in ");
329 for (i
= 0; i
< length
; i
++)
330 fprintf_unfiltered (gdb_stdlog
, "%02x", in
[buf_offset
+ i
]);
333 fprintf_unfiltered (gdb_stdlog
, "\n");
336 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
337 compatiblity mode. A return value of 1 means that we have
338 physical 64-bit registers, but should treat them as 32-bit registers. */
341 mips2_fp_compat (void)
343 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
345 if (register_size (current_gdbarch
, mips_regnum (current_gdbarch
)->fp0
) == 4)
349 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
350 in all the places we deal with FP registers. PR gdb/413. */
351 /* Otherwise check the FR bit in the status register - it controls
352 the FP compatiblity mode. If it is clear we are in compatibility
354 if ((read_register (PS_REGNUM
) & ST0_FR
) == 0)
361 /* Indicate that the ABI makes use of double-precision registers
362 provided by the FPU (rather than combining pairs of registers to
363 form double-precision values). See also MIPS_FPU_TYPE. */
364 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
366 /* The amount of space reserved on the stack for registers. This is
367 different to MIPS_SAVED_REGSIZE as it determines the alignment of
368 data allocated after the registers have run out. */
370 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
372 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
374 static const char *mips_stack_argsize_string
= size_auto
;
377 mips_stack_argsize (void)
379 if (mips_stack_argsize_string
== size_auto
)
380 return MIPS_DEFAULT_STACK_ARGSIZE
;
381 else if (mips_stack_argsize_string
== size_64
)
383 else /* if (mips_stack_argsize_string == size_32) */
387 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
389 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
391 static mips_extra_func_info_t
heuristic_proc_desc (CORE_ADDR
, CORE_ADDR
,
392 struct frame_info
*, int);
394 static CORE_ADDR
heuristic_proc_start (CORE_ADDR
);
396 static CORE_ADDR
read_next_frame_reg (struct frame_info
*, int);
398 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element
*);
400 static mips_extra_func_info_t
find_proc_desc (CORE_ADDR pc
,
401 struct frame_info
*next_frame
,
404 static CORE_ADDR
after_prologue (CORE_ADDR pc
,
405 mips_extra_func_info_t proc_desc
);
407 static struct type
*mips_float_register_type (void);
408 static struct type
*mips_double_register_type (void);
410 /* The list of available "set mips " and "show mips " commands */
412 static struct cmd_list_element
*setmipscmdlist
= NULL
;
413 static struct cmd_list_element
*showmipscmdlist
= NULL
;
415 /* Integer registers 0 thru 31 are handled explicitly by
416 mips_register_name(). Processor specific registers 32 and above
417 are listed in the followign tables. */
419 enum { NUM_MIPS_PROCESSOR_REGS
= (90 - 32) };
423 static const char *mips_generic_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
424 "sr", "lo", "hi", "bad", "cause","pc",
425 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
426 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
427 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
428 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
429 "fsr", "fir", ""/*"fp"*/, "",
430 "", "", "", "", "", "", "", "",
431 "", "", "", "", "", "", "", "",
434 /* Names of IDT R3041 registers. */
436 static const char *mips_r3041_reg_names
[] = {
437 "sr", "lo", "hi", "bad", "cause","pc",
438 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
439 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
440 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
441 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
442 "fsr", "fir", "",/*"fp"*/ "",
443 "", "", "bus", "ccfg", "", "", "", "",
444 "", "", "port", "cmp", "", "", "epc", "prid",
447 /* Names of tx39 registers. */
449 static const char *mips_tx39_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
450 "sr", "lo", "hi", "bad", "cause","pc",
451 "", "", "", "", "", "", "", "",
452 "", "", "", "", "", "", "", "",
453 "", "", "", "", "", "", "", "",
454 "", "", "", "", "", "", "", "",
456 "", "", "", "", "", "", "", "",
457 "", "", "config", "cache", "debug", "depc", "epc", ""
460 /* Names of IRIX registers. */
461 static const char *mips_irix_reg_names
[NUM_MIPS_PROCESSOR_REGS
] = {
462 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
463 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
464 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
465 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
466 "pc", "cause", "bad", "hi", "lo", "fsr", "fir"
470 /* Return the name of the register corresponding to REGNO. */
472 mips_register_name (int regno
)
474 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
475 /* GPR names for all ABIs other than n32/n64. */
476 static char *mips_gpr_names
[] = {
477 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
478 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
479 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
480 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
483 /* GPR names for n32 and n64 ABIs. */
484 static char *mips_n32_n64_gpr_names
[] = {
485 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
486 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
487 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
488 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
491 enum mips_abi abi
= mips_abi (current_gdbarch
);
493 /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then
494 don't make the raw register names visible. */
495 int rawnum
= regno
% NUM_REGS
;
496 if (regno
< NUM_REGS
)
499 /* The MIPS integer registers are always mapped from 0 to 31. The
500 names of the registers (which reflects the conventions regarding
501 register use) vary depending on the ABI. */
502 if (0 <= rawnum
&& rawnum
< 32)
504 if (abi
== MIPS_ABI_N32
|| abi
== MIPS_ABI_N64
)
505 return mips_n32_n64_gpr_names
[rawnum
];
507 return mips_gpr_names
[rawnum
];
509 else if (32 <= rawnum
&& rawnum
< NUM_REGS
)
511 gdb_assert (rawnum
- 32 < NUM_MIPS_PROCESSOR_REGS
);
512 return tdep
->mips_processor_reg_names
[rawnum
- 32];
515 internal_error (__FILE__
, __LINE__
,
516 "mips_register_name: bad register number %d", rawnum
);
519 /* Return the groups that a MIPS register can be categorised into. */
522 mips_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
523 struct reggroup
*reggroup
)
528 int rawnum
= regnum
% NUM_REGS
;
529 int pseudo
= regnum
/ NUM_REGS
;
530 if (reggroup
== all_reggroup
)
532 vector_p
= TYPE_VECTOR (register_type (gdbarch
, regnum
));
533 float_p
= TYPE_CODE (register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
;
534 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
535 (gdbarch), as not all architectures are multi-arch. */
536 raw_p
= rawnum
< NUM_REGS
;
537 if (REGISTER_NAME (regnum
) == NULL
538 || REGISTER_NAME (regnum
)[0] == '\0')
540 if (reggroup
== float_reggroup
)
541 return float_p
&& pseudo
;
542 if (reggroup
== vector_reggroup
)
543 return vector_p
&& pseudo
;
544 if (reggroup
== general_reggroup
)
545 return (!vector_p
&& !float_p
) && pseudo
;
546 /* Save the pseudo registers. Need to make certain that any code
547 extracting register values from a saved register cache also uses
549 if (reggroup
== save_reggroup
)
550 return raw_p
&& pseudo
;
551 /* Restore the same pseudo register. */
552 if (reggroup
== restore_reggroup
)
553 return raw_p
&& pseudo
;
557 /* Map the symbol table registers which live in the range [1 *
558 NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw
562 mips_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
563 int cookednum
, void *buf
)
565 gdb_assert (cookednum
>= NUM_REGS
&& cookednum
< 2 * NUM_REGS
);
566 return regcache_raw_read (regcache
, cookednum
% NUM_REGS
, buf
);
570 mips_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
571 int cookednum
, const void *buf
)
573 gdb_assert (cookednum
>= NUM_REGS
&& cookednum
< 2 * NUM_REGS
);
574 return regcache_raw_write (regcache
, cookednum
% NUM_REGS
, buf
);
577 /* Table to translate MIPS16 register field to actual register number. */
578 static int mips16_to_32_reg
[8] =
579 {16, 17, 2, 3, 4, 5, 6, 7};
581 /* Heuristic_proc_start may hunt through the text section for a long
582 time across a 2400 baud serial line. Allows the user to limit this
585 static unsigned int heuristic_fence_post
= 0;
587 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
588 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
589 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
590 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
591 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
592 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
593 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
594 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
595 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
596 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
597 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
598 this will corrupt pdr.iline. Fortunately we don't use it. */
599 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
600 #define _PROC_MAGIC_ 0x0F0F0F0F
601 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
602 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
604 struct linked_proc_info
606 struct mips_extra_func_info info
;
607 struct linked_proc_info
*next
;
609 *linked_proc_desc_table
= NULL
;
611 /* Number of bytes of storage in the actual machine representation for
612 register N. NOTE: This defines the pseudo register type so need to
613 rebuild the architecture vector. */
615 static int mips64_transfers_32bit_regs_p
= 0;
618 set_mips64_transfers_32bit_regs (char *args
, int from_tty
,
619 struct cmd_list_element
*c
)
621 struct gdbarch_info info
;
622 gdbarch_info_init (&info
);
623 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
624 instead of relying on globals. Doing that would let generic code
625 handle the search for this specific architecture. */
626 if (!gdbarch_update_p (info
))
628 mips64_transfers_32bit_regs_p
= 0;
629 error ("32-bit compatibility mode not supported");
633 /* Convert between RAW and VIRTUAL registers. The RAW register size
634 defines the remote-gdb packet. */
637 mips_register_convertible (int reg_nr
)
639 if (gdbarch_tdep (current_gdbarch
)->mips64_transfers_32bit_regs_p
)
642 return (register_size (current_gdbarch
, reg_nr
) > register_size (current_gdbarch
, reg_nr
));
646 mips_register_convert_to_virtual (int n
, struct type
*virtual_type
,
647 char *raw_buf
, char *virt_buf
)
649 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
651 raw_buf
+ (register_size (current_gdbarch
, n
) - TYPE_LENGTH (virtual_type
)),
652 TYPE_LENGTH (virtual_type
));
656 TYPE_LENGTH (virtual_type
));
660 mips_register_convert_to_raw (struct type
*virtual_type
, int n
,
661 const char *virt_buf
, char *raw_buf
)
663 memset (raw_buf
, 0, register_size (current_gdbarch
, n
));
664 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
665 memcpy (raw_buf
+ (register_size (current_gdbarch
, n
) - TYPE_LENGTH (virtual_type
)),
667 TYPE_LENGTH (virtual_type
));
671 TYPE_LENGTH (virtual_type
));
675 mips_convert_register_p (int regnum
, struct type
*type
)
677 return (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
678 && register_size (current_gdbarch
, regnum
) == 4
679 && (regnum
) >= mips_regnum (current_gdbarch
)->fp0
&& (regnum
) < mips_regnum (current_gdbarch
)->fp0
+ 32
680 && TYPE_CODE(type
) == TYPE_CODE_FLT
681 && TYPE_LENGTH(type
) == 8);
685 mips_register_to_value (struct frame_info
*frame
, int regnum
,
686 struct type
*type
, void *to
)
688 get_frame_register (frame
, regnum
+ 0, (char *) to
+ 4);
689 get_frame_register (frame
, regnum
+ 1, (char *) to
+ 0);
693 mips_value_to_register (struct frame_info
*frame
, int regnum
,
694 struct type
*type
, const void *from
)
696 put_frame_register (frame
, regnum
+ 0, (const char *) from
+ 4);
697 put_frame_register (frame
, regnum
+ 1, (const char *) from
+ 0);
700 /* Return the GDB type object for the "standard" data type of data in
704 mips_register_type (struct gdbarch
*gdbarch
, int regnum
)
706 gdb_assert (regnum
>= 0 && regnum
< 2 * NUM_REGS
);
707 if ((regnum
% NUM_REGS
) >= mips_regnum (current_gdbarch
)->fp0
708 && (regnum
% NUM_REGS
) < mips_regnum (current_gdbarch
)->fp0
+ 32)
710 /* The floating-point registers raw, or cooked, always match
711 mips_regsize(), and also map 1:1, byte for byte. */
712 switch (gdbarch_byte_order (gdbarch
))
715 if (mips_regsize (gdbarch
) == 4)
716 return builtin_type_ieee_single_big
;
718 return builtin_type_ieee_double_big
;
719 case BFD_ENDIAN_LITTLE
:
720 if (mips_regsize (gdbarch
) == 4)
721 return builtin_type_ieee_single_little
;
723 return builtin_type_ieee_double_little
;
724 case BFD_ENDIAN_UNKNOWN
:
726 internal_error (__FILE__
, __LINE__
, "bad switch");
729 else if (regnum
>= (NUM_REGS
+ mips_regnum (current_gdbarch
)->fp_control_status
)
730 && regnum
<= NUM_REGS
+ LAST_EMBED_REGNUM
)
731 /* The pseudo/cooked view of the embedded registers is always
732 32-bit. The raw view is handled below. */
733 return builtin_type_int32
;
734 else if (regnum
>= NUM_REGS
&& mips_regsize (gdbarch
)
735 && gdbarch_tdep (gdbarch
)->mips64_transfers_32bit_regs_p
)
736 /* The target, while using a 64-bit register buffer, is only
737 transfering 32-bits of each integer register. Reflect this in
738 the cooked/pseudo register value. */
739 return builtin_type_int32
;
740 else if (mips_regsize (gdbarch
) == 8)
742 return builtin_type_int64
;
745 return builtin_type_int32
;
748 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
753 return read_signed_register (SP_REGNUM
);
756 /* Should the upper word of 64-bit addresses be zeroed? */
757 enum auto_boolean mask_address_var
= AUTO_BOOLEAN_AUTO
;
760 mips_mask_address_p (void)
762 switch (mask_address_var
)
764 case AUTO_BOOLEAN_TRUE
:
766 case AUTO_BOOLEAN_FALSE
:
769 case AUTO_BOOLEAN_AUTO
:
770 return MIPS_DEFAULT_MASK_ADDRESS_P
;
772 internal_error (__FILE__
, __LINE__
,
773 "mips_mask_address_p: bad switch");
779 show_mask_address (char *cmd
, int from_tty
, struct cmd_list_element
*c
)
781 switch (mask_address_var
)
783 case AUTO_BOOLEAN_TRUE
:
784 printf_filtered ("The 32 bit mips address mask is enabled\n");
786 case AUTO_BOOLEAN_FALSE
:
787 printf_filtered ("The 32 bit mips address mask is disabled\n");
789 case AUTO_BOOLEAN_AUTO
:
790 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
791 mips_mask_address_p () ? "enabled" : "disabled");
794 internal_error (__FILE__
, __LINE__
,
795 "show_mask_address: bad switch");
800 /* Should call_function allocate stack space for a struct return? */
803 mips_eabi_use_struct_convention (int gcc_p
, struct type
*type
)
805 return (TYPE_LENGTH (type
) > 2 * MIPS_SAVED_REGSIZE
);
808 /* Should call_function pass struct by reference?
809 For each architecture, structs are passed either by
810 value or by reference, depending on their size. */
813 mips_eabi_reg_struct_has_addr (int gcc_p
, struct type
*type
)
815 enum type_code typecode
= TYPE_CODE (check_typedef (type
));
816 int len
= TYPE_LENGTH (check_typedef (type
));
818 if (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
)
819 return (len
> MIPS_SAVED_REGSIZE
);
825 mips_n32n64_reg_struct_has_addr (int gcc_p
, struct type
*type
)
827 return 0; /* Assumption: N32/N64 never passes struct by ref. */
831 mips_o32_reg_struct_has_addr (int gcc_p
, struct type
*type
)
833 return 0; /* Assumption: O32/O64 never passes struct by ref. */
836 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
839 pc_is_mips16 (bfd_vma memaddr
)
841 struct minimal_symbol
*sym
;
843 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
844 if (is_mips16_addr (memaddr
))
847 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
848 the high bit of the info field. Use this to decide if the function is
849 MIPS16 or normal MIPS. */
850 sym
= lookup_minimal_symbol_by_pc (memaddr
);
852 return msymbol_is_special (sym
);
857 /* MIPS believes that the PC has a sign extended value. Perhaphs the
858 all registers should be sign extended for simplicity? */
861 mips_read_pc (ptid_t ptid
)
863 return read_signed_register_pid (PC_REGNUM
, ptid
);
866 /* This returns the PC of the first inst after the prologue. If we can't
867 find the prologue, then return 0. */
870 after_prologue (CORE_ADDR pc
,
871 mips_extra_func_info_t proc_desc
)
873 struct symtab_and_line sal
;
874 CORE_ADDR func_addr
, func_end
;
876 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
877 to read the stack pointer from the current machine state, because
878 the current machine state has nothing to do with the information
879 we need from the proc_desc; and the process may or may not exist
882 proc_desc
= find_proc_desc (pc
, NULL
, 0);
886 /* If function is frameless, then we need to do it the hard way. I
887 strongly suspect that frameless always means prologueless... */
888 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
889 && PROC_FRAME_OFFSET (proc_desc
) == 0)
893 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
894 return 0; /* Unknown */
896 sal
= find_pc_line (func_addr
, 0);
898 if (sal
.end
< func_end
)
901 /* The line after the prologue is after the end of the function. In this
902 case, tell the caller to find the prologue the hard way. */
907 /* Decode a MIPS32 instruction that saves a register in the stack, and
908 set the appropriate bit in the general register mask or float register mask
909 to indicate which register is saved. This is a helper function
910 for mips_find_saved_regs. */
913 mips32_decode_reg_save (t_inst inst
, unsigned long *gen_mask
,
914 unsigned long *float_mask
)
918 if ((inst
& 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
919 || (inst
& 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
920 || (inst
& 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
922 /* It might be possible to use the instruction to
923 find the offset, rather than the code below which
924 is based on things being in a certain order in the
925 frame, but figuring out what the instruction's offset
926 is relative to might be a little tricky. */
927 reg
= (inst
& 0x001f0000) >> 16;
928 *gen_mask
|= (1 << reg
);
930 else if ((inst
& 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
931 || (inst
& 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
932 || (inst
& 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
935 reg
= ((inst
& 0x001f0000) >> 16);
936 *float_mask
|= (1 << reg
);
940 /* Decode a MIPS16 instruction that saves a register in the stack, and
941 set the appropriate bit in the general register or float register mask
942 to indicate which register is saved. This is a helper function
943 for mips_find_saved_regs. */
946 mips16_decode_reg_save (t_inst inst
, unsigned long *gen_mask
)
948 if ((inst
& 0xf800) == 0xd000) /* sw reg,n($sp) */
950 int reg
= mips16_to_32_reg
[(inst
& 0x700) >> 8];
951 *gen_mask
|= (1 << reg
);
953 else if ((inst
& 0xff00) == 0xf900) /* sd reg,n($sp) */
955 int reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
956 *gen_mask
|= (1 << reg
);
958 else if ((inst
& 0xff00) == 0x6200 /* sw $ra,n($sp) */
959 || (inst
& 0xff00) == 0xfa00) /* sd $ra,n($sp) */
960 *gen_mask
|= (1 << RA_REGNUM
);
964 /* Fetch and return instruction from the specified location. If the PC
965 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
968 mips_fetch_instruction (CORE_ADDR addr
)
970 char buf
[MIPS_INSTLEN
];
974 if (pc_is_mips16 (addr
))
976 instlen
= MIPS16_INSTLEN
;
977 addr
= unmake_mips16_addr (addr
);
980 instlen
= MIPS_INSTLEN
;
981 status
= read_memory_nobpt (addr
, buf
, instlen
);
983 memory_error (status
, addr
);
984 return extract_unsigned_integer (buf
, instlen
);
988 /* These the fields of 32 bit mips instructions */
989 #define mips32_op(x) (x >> 26)
990 #define itype_op(x) (x >> 26)
991 #define itype_rs(x) ((x >> 21) & 0x1f)
992 #define itype_rt(x) ((x >> 16) & 0x1f)
993 #define itype_immediate(x) (x & 0xffff)
995 #define jtype_op(x) (x >> 26)
996 #define jtype_target(x) (x & 0x03ffffff)
998 #define rtype_op(x) (x >> 26)
999 #define rtype_rs(x) ((x >> 21) & 0x1f)
1000 #define rtype_rt(x) ((x >> 16) & 0x1f)
1001 #define rtype_rd(x) ((x >> 11) & 0x1f)
1002 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1003 #define rtype_funct(x) (x & 0x3f)
1006 mips32_relative_offset (unsigned long inst
)
1009 x
= itype_immediate (inst
);
1010 if (x
& 0x8000) /* sign bit set */
1012 x
|= 0xffff0000; /* sign extension */
1018 /* Determine whate to set a single step breakpoint while considering
1019 branch prediction */
1021 mips32_next_pc (CORE_ADDR pc
)
1025 inst
= mips_fetch_instruction (pc
);
1026 if ((inst
& 0xe0000000) != 0) /* Not a special, jump or branch instruction */
1028 if (itype_op (inst
) >> 2 == 5)
1029 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1031 op
= (itype_op (inst
) & 0x03);
1041 goto greater_branch
;
1046 else if (itype_op (inst
) == 17 && itype_rs (inst
) == 8)
1047 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1049 int tf
= itype_rt (inst
) & 0x01;
1050 int cnum
= itype_rt (inst
) >> 2;
1051 int fcrcs
= read_signed_register (mips_regnum (current_gdbarch
)->fp_control_status
);
1052 int cond
= ((fcrcs
>> 24) & 0x0e) | ((fcrcs
>> 23) & 0x01);
1054 if (((cond
>> cnum
) & 0x01) == tf
)
1055 pc
+= mips32_relative_offset (inst
) + 4;
1060 pc
+= 4; /* Not a branch, next instruction is easy */
1063 { /* This gets way messy */
1065 /* Further subdivide into SPECIAL, REGIMM and other */
1066 switch (op
= itype_op (inst
) & 0x07) /* extract bits 28,27,26 */
1068 case 0: /* SPECIAL */
1069 op
= rtype_funct (inst
);
1074 /* Set PC to that address */
1075 pc
= read_signed_register (rtype_rs (inst
));
1081 break; /* end SPECIAL */
1082 case 1: /* REGIMM */
1084 op
= itype_rt (inst
); /* branch condition */
1089 case 16: /* BLTZAL */
1090 case 18: /* BLTZALL */
1092 if (read_signed_register (itype_rs (inst
)) < 0)
1093 pc
+= mips32_relative_offset (inst
) + 4;
1095 pc
+= 8; /* after the delay slot */
1099 case 17: /* BGEZAL */
1100 case 19: /* BGEZALL */
1101 greater_equal_branch
:
1102 if (read_signed_register (itype_rs (inst
)) >= 0)
1103 pc
+= mips32_relative_offset (inst
) + 4;
1105 pc
+= 8; /* after the delay slot */
1107 /* All of the other instructions in the REGIMM category */
1112 break; /* end REGIMM */
1117 reg
= jtype_target (inst
) << 2;
1118 /* Upper four bits get never changed... */
1119 pc
= reg
+ ((pc
+ 4) & 0xf0000000);
1122 /* FIXME case JALX : */
1125 reg
= jtype_target (inst
) << 2;
1126 pc
= reg
+ ((pc
+ 4) & 0xf0000000) + 1; /* yes, +1 */
1127 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1129 break; /* The new PC will be alternate mode */
1130 case 4: /* BEQ, BEQL */
1132 if (read_signed_register (itype_rs (inst
)) ==
1133 read_signed_register (itype_rt (inst
)))
1134 pc
+= mips32_relative_offset (inst
) + 4;
1138 case 5: /* BNE, BNEL */
1140 if (read_signed_register (itype_rs (inst
)) !=
1141 read_signed_register (itype_rt (inst
)))
1142 pc
+= mips32_relative_offset (inst
) + 4;
1146 case 6: /* BLEZ, BLEZL */
1148 if (read_signed_register (itype_rs (inst
) <= 0))
1149 pc
+= mips32_relative_offset (inst
) + 4;
1155 greater_branch
: /* BGTZ, BGTZL */
1156 if (read_signed_register (itype_rs (inst
) > 0))
1157 pc
+= mips32_relative_offset (inst
) + 4;
1164 } /* mips32_next_pc */
1166 /* Decoding the next place to set a breakpoint is irregular for the
1167 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1168 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1169 We dont want to set a single step instruction on the extend instruction
1173 /* Lots of mips16 instruction formats */
1174 /* Predicting jumps requires itype,ritype,i8type
1175 and their extensions extItype,extritype,extI8type
1177 enum mips16_inst_fmts
1179 itype
, /* 0 immediate 5,10 */
1180 ritype
, /* 1 5,3,8 */
1181 rrtype
, /* 2 5,3,3,5 */
1182 rritype
, /* 3 5,3,3,5 */
1183 rrrtype
, /* 4 5,3,3,3,2 */
1184 rriatype
, /* 5 5,3,3,1,4 */
1185 shifttype
, /* 6 5,3,3,3,2 */
1186 i8type
, /* 7 5,3,8 */
1187 i8movtype
, /* 8 5,3,3,5 */
1188 i8mov32rtype
, /* 9 5,3,5,3 */
1189 i64type
, /* 10 5,3,8 */
1190 ri64type
, /* 11 5,3,3,5 */
1191 jalxtype
, /* 12 5,1,5,5,16 - a 32 bit instruction */
1192 exiItype
, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1193 extRitype
, /* 14 5,6,5,5,3,1,1,1,5 */
1194 extRRItype
, /* 15 5,5,5,5,3,3,5 */
1195 extRRIAtype
, /* 16 5,7,4,5,3,3,1,4 */
1196 EXTshifttype
, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1197 extI8type
, /* 18 5,6,5,5,3,1,1,1,5 */
1198 extI64type
, /* 19 5,6,5,5,3,1,1,1,5 */
1199 extRi64type
, /* 20 5,6,5,5,3,3,5 */
1200 extshift64type
/* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1202 /* I am heaping all the fields of the formats into one structure and
1203 then, only the fields which are involved in instruction extension */
1207 unsigned int regx
; /* Function in i8 type */
1212 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1213 for the bits which make up the immediatate extension. */
1216 extended_offset (unsigned int extension
)
1219 value
= (extension
>> 21) & 0x3f; /* * extract 15:11 */
1221 value
|= (extension
>> 16) & 0x1f; /* extrace 10:5 */
1223 value
|= extension
& 0x01f; /* extract 4:0 */
1227 /* Only call this function if you know that this is an extendable
1228 instruction, It wont malfunction, but why make excess remote memory references?
1229 If the immediate operands get sign extended or somthing, do it after
1230 the extension is performed.
1232 /* FIXME: Every one of these cases needs to worry about sign extension
1233 when the offset is to be used in relative addressing */
1237 fetch_mips_16 (CORE_ADDR pc
)
1240 pc
&= 0xfffffffe; /* clear the low order bit */
1241 target_read_memory (pc
, buf
, 2);
1242 return extract_unsigned_integer (buf
, 2);
1246 unpack_mips16 (CORE_ADDR pc
,
1247 unsigned int extension
,
1249 enum mips16_inst_fmts insn_format
,
1250 struct upk_mips16
*upk
)
1255 switch (insn_format
)
1262 value
= extended_offset (extension
);
1263 value
= value
<< 11; /* rom for the original value */
1264 value
|= inst
& 0x7ff; /* eleven bits from instruction */
1268 value
= inst
& 0x7ff;
1269 /* FIXME : Consider sign extension */
1278 { /* A register identifier and an offset */
1279 /* Most of the fields are the same as I type but the
1280 immediate value is of a different length */
1284 value
= extended_offset (extension
);
1285 value
= value
<< 8; /* from the original instruction */
1286 value
|= inst
& 0xff; /* eleven bits from instruction */
1287 regx
= (extension
>> 8) & 0x07; /* or i8 funct */
1288 if (value
& 0x4000) /* test the sign bit , bit 26 */
1290 value
&= ~0x3fff; /* remove the sign bit */
1296 value
= inst
& 0xff; /* 8 bits */
1297 regx
= (inst
>> 8) & 0x07; /* or i8 funct */
1298 /* FIXME: Do sign extension , this format needs it */
1299 if (value
& 0x80) /* THIS CONFUSES ME */
1301 value
&= 0xef; /* remove the sign bit */
1311 unsigned long value
;
1312 unsigned int nexthalf
;
1313 value
= ((inst
& 0x1f) << 5) | ((inst
>> 5) & 0x1f);
1314 value
= value
<< 16;
1315 nexthalf
= mips_fetch_instruction (pc
+ 2); /* low bit still set */
1323 internal_error (__FILE__
, __LINE__
,
1326 upk
->offset
= offset
;
1333 add_offset_16 (CORE_ADDR pc
, int offset
)
1335 return ((offset
<< 2) | ((pc
+ 2) & (0xf0000000)));
1339 extended_mips16_next_pc (CORE_ADDR pc
,
1340 unsigned int extension
,
1343 int op
= (insn
>> 11);
1346 case 2: /* Branch */
1349 struct upk_mips16 upk
;
1350 unpack_mips16 (pc
, extension
, insn
, itype
, &upk
);
1351 offset
= upk
.offset
;
1357 pc
+= (offset
<< 1) + 2;
1360 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1362 struct upk_mips16 upk
;
1363 unpack_mips16 (pc
, extension
, insn
, jalxtype
, &upk
);
1364 pc
= add_offset_16 (pc
, upk
.offset
);
1365 if ((insn
>> 10) & 0x01) /* Exchange mode */
1366 pc
= pc
& ~0x01; /* Clear low bit, indicate 32 bit mode */
1373 struct upk_mips16 upk
;
1375 unpack_mips16 (pc
, extension
, insn
, ritype
, &upk
);
1376 reg
= read_signed_register (upk
.regx
);
1378 pc
+= (upk
.offset
<< 1) + 2;
1385 struct upk_mips16 upk
;
1387 unpack_mips16 (pc
, extension
, insn
, ritype
, &upk
);
1388 reg
= read_signed_register (upk
.regx
);
1390 pc
+= (upk
.offset
<< 1) + 2;
1395 case 12: /* I8 Formats btez btnez */
1397 struct upk_mips16 upk
;
1399 unpack_mips16 (pc
, extension
, insn
, i8type
, &upk
);
1400 /* upk.regx contains the opcode */
1401 reg
= read_signed_register (24); /* Test register is 24 */
1402 if (((upk
.regx
== 0) && (reg
== 0)) /* BTEZ */
1403 || ((upk
.regx
== 1) && (reg
!= 0))) /* BTNEZ */
1404 /* pc = add_offset_16(pc,upk.offset) ; */
1405 pc
+= (upk
.offset
<< 1) + 2;
1410 case 29: /* RR Formats JR, JALR, JALR-RA */
1412 struct upk_mips16 upk
;
1413 /* upk.fmt = rrtype; */
1418 upk
.regx
= (insn
>> 8) & 0x07;
1419 upk
.regy
= (insn
>> 5) & 0x07;
1427 break; /* Function return instruction */
1433 break; /* BOGUS Guess */
1435 pc
= read_signed_register (reg
);
1442 /* This is an instruction extension. Fetch the real instruction
1443 (which follows the extension) and decode things based on
1447 pc
= extended_mips16_next_pc (pc
, insn
, fetch_mips_16 (pc
));
1460 mips16_next_pc (CORE_ADDR pc
)
1462 unsigned int insn
= fetch_mips_16 (pc
);
1463 return extended_mips16_next_pc (pc
, 0, insn
);
1466 /* The mips_next_pc function supports single_step when the remote
1467 target monitor or stub is not developed enough to do a single_step.
1468 It works by decoding the current instruction and predicting where a
1469 branch will go. This isnt hard because all the data is available.
1470 The MIPS32 and MIPS16 variants are quite different */
1472 mips_next_pc (CORE_ADDR pc
)
1475 return mips16_next_pc (pc
);
1477 return mips32_next_pc (pc
);
1480 /* Set up the 'saved_regs' array. This is a data structure containing
1481 the addresses on the stack where each register has been saved, for
1482 each stack frame. Registers that have not been saved will have
1483 zero here. The stack pointer register is special: rather than the
1484 address where the stack register has been saved,
1485 saved_regs[SP_REGNUM] will have the actual value of the previous
1486 frame's stack register. */
1489 mips_find_saved_regs (struct frame_info
*fci
)
1492 /* r0 bit means kernel trap */
1494 /* What registers have been saved? Bitmasks. */
1495 unsigned long gen_mask
, float_mask
;
1496 mips_extra_func_info_t proc_desc
;
1498 CORE_ADDR
*saved_regs
;
1500 if (deprecated_get_frame_saved_regs (fci
) != NULL
)
1502 saved_regs
= frame_saved_regs_zalloc (fci
);
1504 /* If it is the frame for sigtramp, the saved registers are located
1505 in a sigcontext structure somewhere on the stack. If the stack
1506 layout for sigtramp changes we might have to change these
1507 constants and the companion fixup_sigtramp in mdebugread.c */
1508 #ifndef SIGFRAME_BASE
1509 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1510 above the sigtramp frame. */
1511 #define SIGFRAME_BASE mips_regsize (current_gdbarch)
1512 /* FIXME! Are these correct?? */
1513 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * mips_regsize (current_gdbarch))
1514 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * mips_regsize (current_gdbarch))
1515 #define SIGFRAME_FPREGSAVE_OFF \
1516 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * mips_regsize (current_gdbarch) + 3 * mips_regsize (current_gdbarch))
1518 #ifndef SIGFRAME_REG_SIZE
1519 /* FIXME! Is this correct?? */
1520 #define SIGFRAME_REG_SIZE mips_regsize (current_gdbarch)
1522 if ((get_frame_type (fci
) == SIGTRAMP_FRAME
))
1524 for (ireg
= 0; ireg
< MIPS_NUMREGS
; ireg
++)
1526 CORE_ADDR reg_position
= (get_frame_base (fci
) + SIGFRAME_REGSAVE_OFF
1527 + ireg
* SIGFRAME_REG_SIZE
);
1528 set_reg_offset (saved_regs
, ireg
, reg_position
);
1530 for (ireg
= 0; ireg
< MIPS_NUMREGS
; ireg
++)
1532 CORE_ADDR reg_position
= (get_frame_base (fci
)
1533 + SIGFRAME_FPREGSAVE_OFF
1534 + ireg
* SIGFRAME_REG_SIZE
);
1535 set_reg_offset (saved_regs
, mips_regnum (current_gdbarch
)->fp0
+ ireg
, reg_position
);
1538 set_reg_offset (saved_regs
, PC_REGNUM
, get_frame_base (fci
) + SIGFRAME_PC_OFF
);
1539 /* SP_REGNUM, contains the value and not the address. */
1540 set_reg_offset (saved_regs
, SP_REGNUM
, get_frame_base (fci
));
1544 proc_desc
= get_frame_extra_info (fci
)->proc_desc
;
1545 if (proc_desc
== NULL
)
1546 /* I'm not sure how/whether this can happen. Normally when we
1547 can't find a proc_desc, we "synthesize" one using
1548 heuristic_proc_desc and set the saved_regs right away. */
1551 kernel_trap
= PROC_REG_MASK (proc_desc
) & 1;
1552 gen_mask
= kernel_trap
? 0xFFFFFFFF : PROC_REG_MASK (proc_desc
);
1553 float_mask
= kernel_trap
? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc
);
1555 if (/* In any frame other than the innermost or a frame interrupted
1556 by a signal, we assume that all registers have been saved.
1557 This assumes that all register saves in a function happen
1558 before the first function call. */
1559 (get_next_frame (fci
) == NULL
1560 || (get_frame_type (get_next_frame (fci
)) == SIGTRAMP_FRAME
))
1562 /* In a dummy frame we know exactly where things are saved. */
1563 && !PROC_DESC_IS_DUMMY (proc_desc
)
1565 /* Don't bother unless we are inside a function prologue.
1566 Outside the prologue, we know where everything is. */
1568 && in_prologue (get_frame_pc (fci
), PROC_LOW_ADDR (proc_desc
))
1570 /* Not sure exactly what kernel_trap means, but if it means the
1571 kernel saves the registers without a prologue doing it, we
1572 better not examine the prologue to see whether registers
1573 have been saved yet. */
1576 /* We need to figure out whether the registers that the
1577 proc_desc claims are saved have been saved yet. */
1581 /* Bitmasks; set if we have found a save for the register. */
1582 unsigned long gen_save_found
= 0;
1583 unsigned long float_save_found
= 0;
1586 /* If the address is odd, assume this is MIPS16 code. */
1587 addr
= PROC_LOW_ADDR (proc_desc
);
1588 instlen
= pc_is_mips16 (addr
) ? MIPS16_INSTLEN
: MIPS_INSTLEN
;
1590 /* Scan through this function's instructions preceding the
1591 current PC, and look for those that save registers. */
1592 while (addr
< get_frame_pc (fci
))
1594 inst
= mips_fetch_instruction (addr
);
1595 if (pc_is_mips16 (addr
))
1596 mips16_decode_reg_save (inst
, &gen_save_found
);
1598 mips32_decode_reg_save (inst
, &gen_save_found
, &float_save_found
);
1601 gen_mask
= gen_save_found
;
1602 float_mask
= float_save_found
;
1605 /* Fill in the offsets for the registers which gen_mask says were
1608 CORE_ADDR reg_position
= (get_frame_base (fci
)
1609 + PROC_REG_OFFSET (proc_desc
));
1610 for (ireg
= MIPS_NUMREGS
- 1; gen_mask
; --ireg
, gen_mask
<<= 1)
1611 if (gen_mask
& 0x80000000)
1613 set_reg_offset (saved_regs
, ireg
, reg_position
);
1614 reg_position
-= MIPS_SAVED_REGSIZE
;
1618 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse
1619 order of that normally used by gcc. Therefore, we have to fetch
1620 the first instruction of the function, and if it's an entry
1621 instruction that saves $s0 or $s1, correct their saved addresses. */
1622 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc
)))
1624 inst
= mips_fetch_instruction (PROC_LOW_ADDR (proc_desc
));
1625 if ((inst
& 0xf81f) == 0xe809 && (inst
& 0x700) != 0x700)
1629 int sreg_count
= (inst
>> 6) & 3;
1631 /* Check if the ra register was pushed on the stack. */
1632 CORE_ADDR reg_position
= (get_frame_base (fci
)
1633 + PROC_REG_OFFSET (proc_desc
));
1635 reg_position
-= MIPS_SAVED_REGSIZE
;
1637 /* Check if the s0 and s1 registers were pushed on the
1639 for (reg
= 16; reg
< sreg_count
+ 16; reg
++)
1641 set_reg_offset (saved_regs
, reg
, reg_position
);
1642 reg_position
-= MIPS_SAVED_REGSIZE
;
1647 /* Fill in the offsets for the registers which float_mask says were
1650 CORE_ADDR reg_position
= (get_frame_base (fci
)
1651 + PROC_FREG_OFFSET (proc_desc
));
1653 /* Fill in the offsets for the float registers which float_mask
1655 for (ireg
= MIPS_NUMREGS
- 1; float_mask
; --ireg
, float_mask
<<= 1)
1656 if (float_mask
& 0x80000000)
1658 if (MIPS_SAVED_REGSIZE
== 4 && TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
1660 /* On a big endian 32 bit ABI, floating point registers
1661 are paired to form doubles such that the most
1662 significant part is in $f[N+1] and the least
1663 significant in $f[N] vis: $f[N+1] ||| $f[N]. The
1664 registers are also spilled as a pair and stored as a
1667 When little-endian the least significant part is
1668 stored first leading to the memory order $f[N] and
1671 Unfortunately, when big-endian the most significant
1672 part of the double is stored first, and the least
1673 significant is stored second. This leads to the
1674 registers being ordered in memory as firt $f[N+1] and
1677 For the big-endian case make certain that the
1678 addresses point at the correct (swapped) locations
1679 $f[N] and $f[N+1] pair (keep in mind that
1680 reg_position is decremented each time through the
1683 set_reg_offset (saved_regs
, mips_regnum (current_gdbarch
)->fp0
+ ireg
,
1684 reg_position
- MIPS_SAVED_REGSIZE
);
1686 set_reg_offset (saved_regs
, mips_regnum (current_gdbarch
)->fp0
+ ireg
,
1687 reg_position
+ MIPS_SAVED_REGSIZE
);
1690 set_reg_offset (saved_regs
, mips_regnum (current_gdbarch
)->fp0
+ ireg
, reg_position
);
1691 reg_position
-= MIPS_SAVED_REGSIZE
;
1694 set_reg_offset (saved_regs
, PC_REGNUM
, saved_regs
[RA_REGNUM
]);
1697 /* SP_REGNUM, contains the value and not the address. */
1698 set_reg_offset (saved_regs
, SP_REGNUM
, get_frame_base (fci
));
1702 read_next_frame_reg (struct frame_info
*fi
, int regno
)
1704 /* Always a pseudo. */
1705 gdb_assert (regno
>= NUM_REGS
);
1709 regcache_cooked_read_signed (current_regcache
, regno
, &val
);
1712 else if ((regno
% NUM_REGS
) == SP_REGNUM
)
1713 /* The SP_REGNUM is special, its value is stored in saved_regs.
1714 In fact, it is so special that it can even only be fetched
1715 using a raw register number! Once this code as been converted
1716 to frame-unwind the problem goes away. */
1717 return frame_unwind_register_signed (fi
, regno
% NUM_REGS
);
1719 return frame_unwind_register_signed (fi
, regno
);
1723 /* mips_addr_bits_remove - remove useless address bits */
1726 mips_addr_bits_remove (CORE_ADDR addr
)
1728 if (mips_mask_address_p ()
1729 && (((ULONGEST
) addr
) >> 32 == 0xffffffffUL
))
1730 /* This hack is a work-around for existing boards using PMON, the
1731 simulator, and any other 64-bit targets that doesn't have true
1732 64-bit addressing. On these targets, the upper 32 bits of
1733 addresses are ignored by the hardware. Thus, the PC or SP are
1734 likely to have been sign extended to all 1s by instruction
1735 sequences that load 32-bit addresses. For example, a typical
1736 piece of code that loads an address is this:
1738 lui $r2, <upper 16 bits>
1739 ori $r2, <lower 16 bits>
1741 But the lui sign-extends the value such that the upper 32 bits
1742 may be all 1s. The workaround is simply to mask off these
1743 bits. In the future, gcc may be changed to support true 64-bit
1744 addressing, and this masking will have to be disabled. */
1745 return addr
&= 0xffffffffUL
;
1750 /* mips_software_single_step() is called just before we want to resume
1751 the inferior, if we want to single-step it but there is no hardware
1752 or kernel single-step support (MIPS on GNU/Linux for example). We find
1753 the target of the coming instruction and breakpoint it.
1755 single_step is also called just after the inferior stops. If we had
1756 set up a simulated single-step, we undo our damage. */
1759 mips_software_single_step (enum target_signal sig
, int insert_breakpoints_p
)
1761 static CORE_ADDR next_pc
;
1762 typedef char binsn_quantum
[BREAKPOINT_MAX
];
1763 static binsn_quantum break_mem
;
1766 if (insert_breakpoints_p
)
1768 pc
= read_register (PC_REGNUM
);
1769 next_pc
= mips_next_pc (pc
);
1771 target_insert_breakpoint (next_pc
, break_mem
);
1774 target_remove_breakpoint (next_pc
, break_mem
);
1778 mips_init_frame_pc_first (int fromleaf
, struct frame_info
*prev
)
1783 ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev
))
1784 : get_next_frame (prev
)
1785 ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev
))
1787 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
1788 return tmp
? tmp
: pc
;
1793 mips_frame_saved_pc (struct frame_info
*frame
)
1797 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
), 0, 0))
1800 /* Always unwind the cooked PC register value. */
1801 frame_unwind_signed_register (frame
, NUM_REGS
+ PC_REGNUM
, &tmp
);
1806 mips_extra_func_info_t proc_desc
1807 = get_frame_extra_info (frame
)->proc_desc
;
1808 if (proc_desc
&& PROC_DESC_IS_DUMMY (proc_desc
))
1809 saved_pc
= read_memory_integer (get_frame_base (frame
) - MIPS_SAVED_REGSIZE
, MIPS_SAVED_REGSIZE
);
1812 /* We have to get the saved pc from the sigcontext if it is
1813 a signal handler frame. */
1814 int pcreg
= (get_frame_type (frame
) == SIGTRAMP_FRAME
? PC_REGNUM
1815 : proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
);
1816 saved_pc
= read_next_frame_reg (frame
, NUM_REGS
+ pcreg
);
1819 return ADDR_BITS_REMOVE (saved_pc
);
1822 static struct mips_extra_func_info temp_proc_desc
;
1824 /* This hack will go away once the get_prev_frame() code has been
1825 modified to set the frame's type first. That is BEFORE init extra
1826 frame info et.al. is called. This is because it will become
1827 possible to skip the init extra info call for sigtramp and dummy
1829 static CORE_ADDR
*temp_saved_regs
;
1831 /* Set a register's saved stack address in temp_saved_regs. If an
1832 address has already been set for this register, do nothing; this
1833 way we will only recognize the first save of a given register in a
1836 For simplicity, save the address in both [0 .. NUM_REGS) and
1837 [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range
1838 is used as it is only second range (the ABI instead of ISA
1839 registers) that comes into play when finding saved registers in a
1843 set_reg_offset (CORE_ADDR
*saved_regs
, int regno
, CORE_ADDR offset
)
1845 if (saved_regs
[regno
] == 0)
1847 saved_regs
[regno
+ 0 * NUM_REGS
] = offset
;
1848 saved_regs
[regno
+ 1 * NUM_REGS
] = offset
;
1853 /* Test whether the PC points to the return instruction at the
1854 end of a function. */
1857 mips_about_to_return (CORE_ADDR pc
)
1859 if (pc_is_mips16 (pc
))
1860 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1861 generates a "jr $ra"; other times it generates code to load
1862 the return address from the stack to an accessible register (such
1863 as $a3), then a "jr" using that register. This second case
1864 is almost impossible to distinguish from an indirect jump
1865 used for switch statements, so we don't even try. */
1866 return mips_fetch_instruction (pc
) == 0xe820; /* jr $ra */
1868 return mips_fetch_instruction (pc
) == 0x3e00008; /* jr $ra */
1872 /* This fencepost looks highly suspicious to me. Removing it also
1873 seems suspicious as it could affect remote debugging across serial
1877 heuristic_proc_start (CORE_ADDR pc
)
1884 pc
= ADDR_BITS_REMOVE (pc
);
1886 fence
= start_pc
- heuristic_fence_post
;
1890 if (heuristic_fence_post
== UINT_MAX
1891 || fence
< VM_MIN_ADDRESS
)
1892 fence
= VM_MIN_ADDRESS
;
1894 instlen
= pc_is_mips16 (pc
) ? MIPS16_INSTLEN
: MIPS_INSTLEN
;
1896 /* search back for previous return */
1897 for (start_pc
-= instlen
;; start_pc
-= instlen
)
1898 if (start_pc
< fence
)
1900 /* It's not clear to me why we reach this point when
1901 stop_soon, but with this test, at least we
1902 don't print out warnings for every child forked (eg, on
1903 decstation). 22apr93 rich@cygnus.com. */
1904 if (stop_soon
== NO_STOP_QUIETLY
)
1906 static int blurb_printed
= 0;
1908 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1913 /* This actually happens frequently in embedded
1914 development, when you first connect to a board
1915 and your stack pointer and pc are nowhere in
1916 particular. This message needs to give people
1917 in that situation enough information to
1918 determine that it's no big deal. */
1919 printf_filtered ("\n\
1920 GDB is unable to find the start of the function at 0x%s\n\
1921 and thus can't determine the size of that function's stack frame.\n\
1922 This means that GDB may be unable to access that stack frame, or\n\
1923 the frames below it.\n\
1924 This problem is most likely caused by an invalid program counter or\n\
1926 However, if you think GDB should simply search farther back\n\
1927 from 0x%s for code which looks like the beginning of a\n\
1928 function, you can increase the range of the search using the `set\n\
1929 heuristic-fence-post' command.\n",
1930 paddr_nz (pc
), paddr_nz (pc
));
1937 else if (pc_is_mips16 (start_pc
))
1939 unsigned short inst
;
1941 /* On MIPS16, any one of the following is likely to be the
1942 start of a function:
1946 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1947 inst
= mips_fetch_instruction (start_pc
);
1948 if (((inst
& 0xf81f) == 0xe809 && (inst
& 0x700) != 0x700) /* entry */
1949 || (inst
& 0xff80) == 0x6380 /* addiu sp,-n */
1950 || (inst
& 0xff80) == 0xfb80 /* daddiu sp,-n */
1951 || ((inst
& 0xf810) == 0xf010 && seen_adjsp
)) /* extend -n */
1953 else if ((inst
& 0xff00) == 0x6300 /* addiu sp */
1954 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
1959 else if (mips_about_to_return (start_pc
))
1961 start_pc
+= 2 * MIPS_INSTLEN
; /* skip return, and its delay slot */
1968 /* Fetch the immediate value from a MIPS16 instruction.
1969 If the previous instruction was an EXTEND, use it to extend
1970 the upper bits of the immediate value. This is a helper function
1971 for mips16_heuristic_proc_desc. */
1974 mips16_get_imm (unsigned short prev_inst
, /* previous instruction */
1975 unsigned short inst
, /* current instruction */
1976 int nbits
, /* number of bits in imm field */
1977 int scale
, /* scale factor to be applied to imm */
1978 int is_signed
) /* is the imm field signed? */
1982 if ((prev_inst
& 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1984 offset
= ((prev_inst
& 0x1f) << 11) | (prev_inst
& 0x7e0);
1985 if (offset
& 0x8000) /* check for negative extend */
1986 offset
= 0 - (0x10000 - (offset
& 0xffff));
1987 return offset
| (inst
& 0x1f);
1991 int max_imm
= 1 << nbits
;
1992 int mask
= max_imm
- 1;
1993 int sign_bit
= max_imm
>> 1;
1995 offset
= inst
& mask
;
1996 if (is_signed
&& (offset
& sign_bit
))
1997 offset
= 0 - (max_imm
- offset
);
1998 return offset
* scale
;
2003 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
2004 stream from start_pc to limit_pc. */
2007 mips16_heuristic_proc_desc (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2008 struct frame_info
*next_frame
, CORE_ADDR sp
)
2011 CORE_ADDR frame_addr
= 0; /* Value of $r17, used as frame pointer */
2012 unsigned short prev_inst
= 0; /* saved copy of previous instruction */
2013 unsigned inst
= 0; /* current instruction */
2014 unsigned entry_inst
= 0; /* the entry instruction */
2017 PROC_FRAME_OFFSET (&temp_proc_desc
) = 0; /* size of stack frame */
2018 PROC_FRAME_ADJUST (&temp_proc_desc
) = 0; /* offset of FP from SP */
2020 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS16_INSTLEN
)
2022 /* Save the previous instruction. If it's an EXTEND, we'll extract
2023 the immediate offset extension from it in mips16_get_imm. */
2026 /* Fetch and decode the instruction. */
2027 inst
= (unsigned short) mips_fetch_instruction (cur_pc
);
2028 if ((inst
& 0xff00) == 0x6300 /* addiu sp */
2029 || (inst
& 0xff00) == 0xfb00) /* daddiu sp */
2031 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 1);
2032 if (offset
< 0) /* negative stack adjustment? */
2033 PROC_FRAME_OFFSET (&temp_proc_desc
) -= offset
;
2035 /* Exit loop if a positive stack adjustment is found, which
2036 usually means that the stack cleanup code in the function
2037 epilogue is reached. */
2040 else if ((inst
& 0xf800) == 0xd000) /* sw reg,n($sp) */
2042 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2043 reg
= mips16_to_32_reg
[(inst
& 0x700) >> 8];
2044 PROC_REG_MASK (&temp_proc_desc
) |= (1 << reg
);
2045 set_reg_offset (temp_saved_regs
, reg
, sp
+ offset
);
2047 else if ((inst
& 0xff00) == 0xf900) /* sd reg,n($sp) */
2049 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
2050 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
2051 PROC_REG_MASK (&temp_proc_desc
) |= (1 << reg
);
2052 set_reg_offset (temp_saved_regs
, reg
, sp
+ offset
);
2054 else if ((inst
& 0xff00) == 0x6200) /* sw $ra,n($sp) */
2056 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2057 PROC_REG_MASK (&temp_proc_desc
) |= (1 << RA_REGNUM
);
2058 set_reg_offset (temp_saved_regs
, RA_REGNUM
, sp
+ offset
);
2060 else if ((inst
& 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2062 offset
= mips16_get_imm (prev_inst
, inst
, 8, 8, 0);
2063 PROC_REG_MASK (&temp_proc_desc
) |= (1 << RA_REGNUM
);
2064 set_reg_offset (temp_saved_regs
, RA_REGNUM
, sp
+ offset
);
2066 else if (inst
== 0x673d) /* move $s1, $sp */
2069 PROC_FRAME_REG (&temp_proc_desc
) = 17;
2071 else if ((inst
& 0xff00) == 0x0100) /* addiu $s1,sp,n */
2073 offset
= mips16_get_imm (prev_inst
, inst
, 8, 4, 0);
2074 frame_addr
= sp
+ offset
;
2075 PROC_FRAME_REG (&temp_proc_desc
) = 17;
2076 PROC_FRAME_ADJUST (&temp_proc_desc
) = offset
;
2078 else if ((inst
& 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2080 offset
= mips16_get_imm (prev_inst
, inst
, 5, 4, 0);
2081 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
2082 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2083 set_reg_offset (temp_saved_regs
, reg
, frame_addr
+ offset
);
2085 else if ((inst
& 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2087 offset
= mips16_get_imm (prev_inst
, inst
, 5, 8, 0);
2088 reg
= mips16_to_32_reg
[(inst
& 0xe0) >> 5];
2089 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2090 set_reg_offset (temp_saved_regs
, reg
, frame_addr
+ offset
);
2092 else if ((inst
& 0xf81f) == 0xe809 && (inst
& 0x700) != 0x700) /* entry */
2093 entry_inst
= inst
; /* save for later processing */
2094 else if ((inst
& 0xf800) == 0x1800) /* jal(x) */
2095 cur_pc
+= MIPS16_INSTLEN
; /* 32-bit instruction */
2098 /* The entry instruction is typically the first instruction in a function,
2099 and it stores registers at offsets relative to the value of the old SP
2100 (before the prologue). But the value of the sp parameter to this
2101 function is the new SP (after the prologue has been executed). So we
2102 can't calculate those offsets until we've seen the entire prologue,
2103 and can calculate what the old SP must have been. */
2104 if (entry_inst
!= 0)
2106 int areg_count
= (entry_inst
>> 8) & 7;
2107 int sreg_count
= (entry_inst
>> 6) & 3;
2109 /* The entry instruction always subtracts 32 from the SP. */
2110 PROC_FRAME_OFFSET (&temp_proc_desc
) += 32;
2112 /* Now we can calculate what the SP must have been at the
2113 start of the function prologue. */
2114 sp
+= PROC_FRAME_OFFSET (&temp_proc_desc
);
2116 /* Check if a0-a3 were saved in the caller's argument save area. */
2117 for (reg
= 4, offset
= 0; reg
< areg_count
+ 4; reg
++)
2119 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2120 set_reg_offset (temp_saved_regs
, reg
, sp
+ offset
);
2121 offset
+= MIPS_SAVED_REGSIZE
;
2124 /* Check if the ra register was pushed on the stack. */
2126 if (entry_inst
& 0x20)
2128 PROC_REG_MASK (&temp_proc_desc
) |= 1 << RA_REGNUM
;
2129 set_reg_offset (temp_saved_regs
, RA_REGNUM
, sp
+ offset
);
2130 offset
-= MIPS_SAVED_REGSIZE
;
2133 /* Check if the s0 and s1 registers were pushed on the stack. */
2134 for (reg
= 16; reg
< sreg_count
+ 16; reg
++)
2136 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2137 set_reg_offset (temp_saved_regs
, reg
, sp
+ offset
);
2138 offset
-= MIPS_SAVED_REGSIZE
;
2144 mips32_heuristic_proc_desc (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2145 struct frame_info
*next_frame
, CORE_ADDR sp
)
2148 CORE_ADDR frame_addr
= 0; /* Value of $r30. Used by gcc for frame-pointer */
2150 temp_saved_regs
= xrealloc (temp_saved_regs
, SIZEOF_FRAME_SAVED_REGS
);
2151 memset (temp_saved_regs
, '\0', SIZEOF_FRAME_SAVED_REGS
);
2152 PROC_FRAME_OFFSET (&temp_proc_desc
) = 0;
2153 PROC_FRAME_ADJUST (&temp_proc_desc
) = 0; /* offset of FP from SP */
2154 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= MIPS_INSTLEN
)
2156 unsigned long inst
, high_word
, low_word
;
2159 /* Fetch the instruction. */
2160 inst
= (unsigned long) mips_fetch_instruction (cur_pc
);
2162 /* Save some code by pre-extracting some useful fields. */
2163 high_word
= (inst
>> 16) & 0xffff;
2164 low_word
= inst
& 0xffff;
2165 reg
= high_word
& 0x1f;
2167 if (high_word
== 0x27bd /* addiu $sp,$sp,-i */
2168 || high_word
== 0x23bd /* addi $sp,$sp,-i */
2169 || high_word
== 0x67bd) /* daddiu $sp,$sp,-i */
2171 if (low_word
& 0x8000) /* negative stack adjustment? */
2172 PROC_FRAME_OFFSET (&temp_proc_desc
) += 0x10000 - low_word
;
2174 /* Exit loop if a positive stack adjustment is found, which
2175 usually means that the stack cleanup code in the function
2176 epilogue is reached. */
2179 else if ((high_word
& 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2181 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2182 set_reg_offset (temp_saved_regs
, reg
, sp
+ low_word
);
2184 else if ((high_word
& 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2186 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2187 but the register size used is only 32 bits. Make the address
2188 for the saved register point to the lower 32 bits. */
2189 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2190 set_reg_offset (temp_saved_regs
, reg
, sp
+ low_word
+ 8 - mips_regsize (current_gdbarch
));
2192 else if (high_word
== 0x27be) /* addiu $30,$sp,size */
2194 /* Old gcc frame, r30 is virtual frame pointer. */
2195 if ((long) low_word
!= PROC_FRAME_OFFSET (&temp_proc_desc
))
2196 frame_addr
= sp
+ low_word
;
2197 else if (PROC_FRAME_REG (&temp_proc_desc
) == SP_REGNUM
)
2199 unsigned alloca_adjust
;
2200 PROC_FRAME_REG (&temp_proc_desc
) = 30;
2201 frame_addr
= read_next_frame_reg (next_frame
, NUM_REGS
+ 30);
2202 alloca_adjust
= (unsigned) (frame_addr
- (sp
+ low_word
));
2203 if (alloca_adjust
> 0)
2205 /* FP > SP + frame_size. This may be because
2206 * of an alloca or somethings similar.
2207 * Fix sp to "pre-alloca" value, and try again.
2209 sp
+= alloca_adjust
;
2214 /* move $30,$sp. With different versions of gas this will be either
2215 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2216 Accept any one of these. */
2217 else if (inst
== 0x03A0F021 || inst
== 0x03a0f025 || inst
== 0x03a0f02d)
2219 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2220 if (PROC_FRAME_REG (&temp_proc_desc
) == SP_REGNUM
)
2222 unsigned alloca_adjust
;
2223 PROC_FRAME_REG (&temp_proc_desc
) = 30;
2224 frame_addr
= read_next_frame_reg (next_frame
, NUM_REGS
+ 30);
2225 alloca_adjust
= (unsigned) (frame_addr
- sp
);
2226 if (alloca_adjust
> 0)
2228 /* FP > SP + frame_size. This may be because
2229 * of an alloca or somethings similar.
2230 * Fix sp to "pre-alloca" value, and try again.
2232 sp
+= alloca_adjust
;
2237 else if ((high_word
& 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2239 PROC_REG_MASK (&temp_proc_desc
) |= 1 << reg
;
2240 set_reg_offset (temp_saved_regs
, reg
, frame_addr
+ low_word
);
2245 static mips_extra_func_info_t
2246 heuristic_proc_desc (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
2247 struct frame_info
*next_frame
, int cur_frame
)
2252 sp
= read_next_frame_reg (next_frame
, NUM_REGS
+ SP_REGNUM
);
2258 memset (&temp_proc_desc
, '\0', sizeof (temp_proc_desc
));
2259 temp_saved_regs
= xrealloc (temp_saved_regs
, SIZEOF_FRAME_SAVED_REGS
);
2260 memset (temp_saved_regs
, '\0', SIZEOF_FRAME_SAVED_REGS
);
2261 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
2262 PROC_FRAME_REG (&temp_proc_desc
) = SP_REGNUM
;
2263 PROC_PC_REG (&temp_proc_desc
) = RA_REGNUM
;
2265 if (start_pc
+ 200 < limit_pc
)
2266 limit_pc
= start_pc
+ 200;
2267 if (pc_is_mips16 (start_pc
))
2268 mips16_heuristic_proc_desc (start_pc
, limit_pc
, next_frame
, sp
);
2270 mips32_heuristic_proc_desc (start_pc
, limit_pc
, next_frame
, sp
);
2271 return &temp_proc_desc
;
2274 struct mips_objfile_private
2280 /* Global used to communicate between non_heuristic_proc_desc and
2281 compare_pdr_entries within qsort (). */
2282 static bfd
*the_bfd
;
2285 compare_pdr_entries (const void *a
, const void *b
)
2287 CORE_ADDR lhs
= bfd_get_32 (the_bfd
, (bfd_byte
*) a
);
2288 CORE_ADDR rhs
= bfd_get_32 (the_bfd
, (bfd_byte
*) b
);
2292 else if (lhs
== rhs
)
2298 static mips_extra_func_info_t
2299 non_heuristic_proc_desc (CORE_ADDR pc
, CORE_ADDR
*addrptr
)
2301 CORE_ADDR startaddr
;
2302 mips_extra_func_info_t proc_desc
;
2303 struct block
*b
= block_for_pc (pc
);
2305 struct obj_section
*sec
;
2306 struct mips_objfile_private
*priv
;
2308 if (DEPRECATED_PC_IN_CALL_DUMMY (pc
, 0, 0))
2311 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
2313 *addrptr
= startaddr
;
2317 sec
= find_pc_section (pc
);
2320 priv
= (struct mips_objfile_private
*) sec
->objfile
->obj_private
;
2322 /* Search the ".pdr" section generated by GAS. This includes most of
2323 the information normally found in ECOFF PDRs. */
2325 the_bfd
= sec
->objfile
->obfd
;
2327 && (the_bfd
->format
== bfd_object
2328 && bfd_get_flavour (the_bfd
) == bfd_target_elf_flavour
2329 && elf_elfheader (the_bfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
))
2331 /* Right now GAS only outputs the address as a four-byte sequence.
2332 This means that we should not bother with this method on 64-bit
2333 targets (until that is fixed). */
2335 priv
= obstack_alloc (& sec
->objfile
->psymbol_obstack
,
2336 sizeof (struct mips_objfile_private
));
2338 sec
->objfile
->obj_private
= priv
;
2340 else if (priv
== NULL
)
2344 priv
= obstack_alloc (& sec
->objfile
->psymbol_obstack
,
2345 sizeof (struct mips_objfile_private
));
2347 bfdsec
= bfd_get_section_by_name (sec
->objfile
->obfd
, ".pdr");
2350 priv
->size
= bfd_section_size (sec
->objfile
->obfd
, bfdsec
);
2351 priv
->contents
= obstack_alloc (& sec
->objfile
->psymbol_obstack
,
2353 bfd_get_section_contents (sec
->objfile
->obfd
, bfdsec
,
2354 priv
->contents
, 0, priv
->size
);
2356 /* In general, the .pdr section is sorted. However, in the
2357 presence of multiple code sections (and other corner cases)
2358 it can become unsorted. Sort it so that we can use a faster
2360 qsort (priv
->contents
, priv
->size
/ 32, 32, compare_pdr_entries
);
2365 sec
->objfile
->obj_private
= priv
;
2369 if (priv
->size
!= 0)
2375 high
= priv
->size
/ 32;
2381 mid
= (low
+ high
) / 2;
2383 ptr
= priv
->contents
+ mid
* 32;
2384 pdr_pc
= bfd_get_signed_32 (sec
->objfile
->obfd
, ptr
);
2385 pdr_pc
+= ANOFFSET (sec
->objfile
->section_offsets
,
2386 SECT_OFF_TEXT (sec
->objfile
));
2387 if (pdr_pc
== startaddr
)
2389 if (pdr_pc
> startaddr
)
2394 while (low
!= high
);
2398 struct symbol
*sym
= find_pc_function (pc
);
2400 /* Fill in what we need of the proc_desc. */
2401 proc_desc
= (mips_extra_func_info_t
)
2402 obstack_alloc (&sec
->objfile
->psymbol_obstack
,
2403 sizeof (struct mips_extra_func_info
));
2404 PROC_LOW_ADDR (proc_desc
) = startaddr
;
2406 /* Only used for dummy frames. */
2407 PROC_HIGH_ADDR (proc_desc
) = 0;
2409 PROC_FRAME_OFFSET (proc_desc
)
2410 = bfd_get_32 (sec
->objfile
->obfd
, ptr
+ 20);
2411 PROC_FRAME_REG (proc_desc
) = bfd_get_32 (sec
->objfile
->obfd
,
2413 PROC_FRAME_ADJUST (proc_desc
) = 0;
2414 PROC_REG_MASK (proc_desc
) = bfd_get_32 (sec
->objfile
->obfd
,
2416 PROC_FREG_MASK (proc_desc
) = bfd_get_32 (sec
->objfile
->obfd
,
2418 PROC_REG_OFFSET (proc_desc
) = bfd_get_32 (sec
->objfile
->obfd
,
2420 PROC_FREG_OFFSET (proc_desc
)
2421 = bfd_get_32 (sec
->objfile
->obfd
, ptr
+ 16);
2422 PROC_PC_REG (proc_desc
) = bfd_get_32 (sec
->objfile
->obfd
,
2424 proc_desc
->pdr
.isym
= (long) sym
;
2434 if (startaddr
> BLOCK_START (b
))
2436 /* This is the "pathological" case referred to in a comment in
2437 print_frame_info. It might be better to move this check into
2442 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_DOMAIN
, 0, NULL
);
2444 /* If we never found a PDR for this function in symbol reading, then
2445 examine prologues to find the information. */
2448 proc_desc
= (mips_extra_func_info_t
) SYMBOL_VALUE (sym
);
2449 if (PROC_FRAME_REG (proc_desc
) == -1)
2459 static mips_extra_func_info_t
2460 find_proc_desc (CORE_ADDR pc
, struct frame_info
*next_frame
, int cur_frame
)
2462 mips_extra_func_info_t proc_desc
;
2463 CORE_ADDR startaddr
= 0;
2465 proc_desc
= non_heuristic_proc_desc (pc
, &startaddr
);
2469 /* IF this is the topmost frame AND
2470 * (this proc does not have debugging information OR
2471 * the PC is in the procedure prologue)
2472 * THEN create a "heuristic" proc_desc (by analyzing
2473 * the actual code) to replace the "official" proc_desc.
2475 if (next_frame
== NULL
)
2477 struct symtab_and_line val
;
2478 struct symbol
*proc_symbol
=
2479 PROC_DESC_IS_DUMMY (proc_desc
) ? 0 : PROC_SYMBOL (proc_desc
);
2483 val
= find_pc_line (BLOCK_START
2484 (SYMBOL_BLOCK_VALUE (proc_symbol
)),
2486 val
.pc
= val
.end
? val
.end
: pc
;
2488 if (!proc_symbol
|| pc
< val
.pc
)
2490 mips_extra_func_info_t found_heuristic
=
2491 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
2492 pc
, next_frame
, cur_frame
);
2493 if (found_heuristic
)
2494 proc_desc
= found_heuristic
;
2500 /* Is linked_proc_desc_table really necessary? It only seems to be used
2501 by procedure call dummys. However, the procedures being called ought
2502 to have their own proc_descs, and even if they don't,
2503 heuristic_proc_desc knows how to create them! */
2505 struct linked_proc_info
*link
;
2507 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
2508 if (PROC_LOW_ADDR (&link
->info
) <= pc
2509 && PROC_HIGH_ADDR (&link
->info
) > pc
)
2513 startaddr
= heuristic_proc_start (pc
);
2516 heuristic_proc_desc (startaddr
, pc
, next_frame
, cur_frame
);
2522 get_frame_pointer (struct frame_info
*frame
,
2523 mips_extra_func_info_t proc_desc
)
2525 return (read_next_frame_reg (frame
, NUM_REGS
+ PROC_FRAME_REG (proc_desc
))
2526 + PROC_FRAME_OFFSET (proc_desc
)
2527 - PROC_FRAME_ADJUST (proc_desc
));
2530 static mips_extra_func_info_t cached_proc_desc
;
2533 mips_frame_chain (struct frame_info
*frame
)
2535 mips_extra_func_info_t proc_desc
;
2537 CORE_ADDR saved_pc
= DEPRECATED_FRAME_SAVED_PC (frame
);
2539 if (saved_pc
== 0 || deprecated_inside_entry_file (saved_pc
))
2542 /* Check if the PC is inside a call stub. If it is, fetch the
2543 PC of the caller of that stub. */
2544 if ((tmp
= SKIP_TRAMPOLINE_CODE (saved_pc
)) != 0)
2547 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc
, 0, 0))
2549 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2550 is well, frame->frame the bottom of the current frame will
2551 contain that value. */
2552 return get_frame_base (frame
);
2555 /* Look up the procedure descriptor for this PC. */
2556 proc_desc
= find_proc_desc (saved_pc
, frame
, 1);
2560 cached_proc_desc
= proc_desc
;
2562 /* If no frame pointer and frame size is zero, we must be at end
2563 of stack (or otherwise hosed). If we don't check frame size,
2564 we loop forever if we see a zero size frame. */
2565 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
2566 && PROC_FRAME_OFFSET (proc_desc
) == 0
2567 /* The previous frame from a sigtramp frame might be frameless
2568 and have frame size zero. */
2569 && !(get_frame_type (frame
) == SIGTRAMP_FRAME
)
2570 /* For a generic dummy frame, let get_frame_pointer() unwind a
2571 register value saved as part of the dummy frame call. */
2572 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
), 0, 0)))
2575 return get_frame_pointer (frame
, proc_desc
);
2579 mips_init_extra_frame_info (int fromleaf
, struct frame_info
*fci
)
2582 mips_extra_func_info_t proc_desc
;
2584 if (get_frame_type (fci
) == DUMMY_FRAME
)
2587 /* Use proc_desc calculated in frame_chain. When there is no
2588 next frame, i.e, get_next_frame (fci) == NULL, we call
2589 find_proc_desc () to calculate it, passing an explicit
2590 NULL as the frame parameter. */
2592 get_next_frame (fci
)
2594 : find_proc_desc (get_frame_pc (fci
),
2595 NULL
/* i.e, get_next_frame (fci) */,
2598 frame_extra_info_zalloc (fci
, sizeof (struct frame_extra_info
));
2600 deprecated_set_frame_saved_regs_hack (fci
, NULL
);
2601 get_frame_extra_info (fci
)->proc_desc
=
2602 proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
2605 /* Fixup frame-pointer - only needed for top frame */
2606 /* This may not be quite right, if proc has a real frame register.
2607 Get the value of the frame relative sp, procedure might have been
2608 interrupted by a signal at it's very start. */
2609 if (get_frame_pc (fci
) == PROC_LOW_ADDR (proc_desc
)
2610 && !PROC_DESC_IS_DUMMY (proc_desc
))
2611 deprecated_update_frame_base_hack (fci
, read_next_frame_reg (get_next_frame (fci
), NUM_REGS
+ SP_REGNUM
));
2612 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci
), 0, 0))
2613 /* Do not ``fix'' fci->frame. It will have the value of the
2614 generic dummy frame's top-of-stack (since the draft
2615 fci->frame is obtained by returning the unwound stack
2616 pointer) and that is what we want. That way the fci->frame
2617 value will match the top-of-stack value that was saved as
2618 part of the dummy frames data. */
2621 deprecated_update_frame_base_hack (fci
, get_frame_pointer (get_next_frame (fci
), proc_desc
));
2623 if (proc_desc
== &temp_proc_desc
)
2627 /* Do not set the saved registers for a sigtramp frame,
2628 mips_find_saved_registers will do that for us. We can't
2629 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2631 /* FIXME: cagney/2002-11-18: This problem will go away once
2632 frame.c:get_prev_frame() is modified to set the frame's
2633 type before calling functions like this. */
2634 find_pc_partial_function (get_frame_pc (fci
), &name
,
2635 (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
2636 if (!PC_IN_SIGTRAMP (get_frame_pc (fci
), name
))
2638 frame_saved_regs_zalloc (fci
);
2639 /* Set value of previous frame's stack pointer.
2640 Remember that saved_regs[SP_REGNUM] is special in
2641 that it contains the value of the stack pointer
2642 register. The other saved_regs values are addresses
2643 (in the inferior) at which a given register's value
2645 set_reg_offset (temp_saved_regs
, SP_REGNUM
,
2646 get_frame_base (fci
));
2647 set_reg_offset (temp_saved_regs
, PC_REGNUM
,
2648 temp_saved_regs
[RA_REGNUM
]);
2649 memcpy (deprecated_get_frame_saved_regs (fci
), temp_saved_regs
,
2650 SIZEOF_FRAME_SAVED_REGS
);
2654 /* hack: if argument regs are saved, guess these contain args */
2655 /* assume we can't tell how many args for now */
2656 get_frame_extra_info (fci
)->num_args
= -1;
2657 for (regnum
= MIPS_LAST_ARG_REGNUM
; regnum
>= A0_REGNUM
; regnum
--)
2659 if (PROC_REG_MASK (proc_desc
) & (1 << regnum
))
2661 get_frame_extra_info (fci
)->num_args
= regnum
- A0_REGNUM
+ 1;
2668 /* MIPS stack frames are almost impenetrable. When execution stops,
2669 we basically have to look at symbol information for the function
2670 that we stopped in, which tells us *which* register (if any) is
2671 the base of the frame pointer, and what offset from that register
2672 the frame itself is at.
2674 This presents a problem when trying to examine a stack in memory
2675 (that isn't executing at the moment), using the "frame" command. We
2676 don't have a PC, nor do we have any registers except SP.
2678 This routine takes two arguments, SP and PC, and tries to make the
2679 cached frames look as if these two arguments defined a frame on the
2680 cache. This allows the rest of info frame to extract the important
2681 arguments without difficulty. */
2684 setup_arbitrary_frame (int argc
, CORE_ADDR
*argv
)
2687 error ("MIPS frame specifications require two arguments: sp and pc");
2689 return create_new_frame (argv
[0], argv
[1]);
2692 /* According to the current ABI, should the type be passed in a
2693 floating-point register (assuming that there is space)? When there
2694 is no FPU, FP are not even considered as possibile candidates for
2695 FP registers and, consequently this returns false - forces FP
2696 arguments into integer registers. */
2699 fp_register_arg_p (enum type_code typecode
, struct type
*arg_type
)
2701 return ((typecode
== TYPE_CODE_FLT
2703 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
)
2704 && TYPE_NFIELDS (arg_type
) == 1
2705 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type
, 0)) == TYPE_CODE_FLT
))
2706 && MIPS_FPU_TYPE
!= MIPS_FPU_NONE
);
2709 /* On o32, argument passing in GPRs depends on the alignment of the type being
2710 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2713 mips_type_needs_double_align (struct type
*type
)
2715 enum type_code typecode
= TYPE_CODE (type
);
2717 if (typecode
== TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 8)
2719 else if (typecode
== TYPE_CODE_STRUCT
)
2721 if (TYPE_NFIELDS (type
) < 1)
2723 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type
, 0));
2725 else if (typecode
== TYPE_CODE_UNION
)
2729 n
= TYPE_NFIELDS (type
);
2730 for (i
= 0; i
< n
; i
++)
2731 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type
, i
)))
2738 /* Adjust the address downward (direction of stack growth) so that it
2739 is correctly aligned for a new stack frame. */
2741 mips_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2743 return align_down (addr
, 16);
2747 mips_eabi_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
2748 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
2749 struct value
**args
, CORE_ADDR sp
, int struct_return
,
2750 CORE_ADDR struct_addr
)
2756 int stack_offset
= 0;
2758 /* For shared libraries, "t9" needs to point at the function
2760 regcache_cooked_write_signed (regcache
, T9_REGNUM
, func_addr
);
2762 /* Set the return address register to point to the entry point of
2763 the program, where a breakpoint lies in wait. */
2764 regcache_cooked_write_signed (regcache
, RA_REGNUM
, bp_addr
);
2766 /* First ensure that the stack and structure return address (if any)
2767 are properly aligned. The stack has to be at least 64-bit
2768 aligned even on 32-bit machines, because doubles must be 64-bit
2769 aligned. For n32 and n64, stack frames need to be 128-bit
2770 aligned, so we round to this widest known alignment. */
2772 sp
= align_down (sp
, 16);
2773 struct_addr
= align_down (struct_addr
, 16);
2775 /* Now make space on the stack for the args. We allocate more
2776 than necessary for EABI, because the first few arguments are
2777 passed in registers, but that's OK. */
2778 for (argnum
= 0; argnum
< nargs
; argnum
++)
2779 len
+= align_up (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])),
2780 MIPS_STACK_ARGSIZE
);
2781 sp
-= align_up (len
, 16);
2784 fprintf_unfiltered (gdb_stdlog
,
2785 "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n",
2786 paddr_nz (sp
), (long) align_up (len
, 16));
2788 /* Initialize the integer and float register pointers. */
2790 float_argreg
= mips_fpa0_regnum (current_gdbarch
);
2792 /* The struct_return pointer occupies the first parameter-passing reg. */
2796 fprintf_unfiltered (gdb_stdlog
,
2797 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2798 argreg
, paddr_nz (struct_addr
));
2799 write_register (argreg
++, struct_addr
);
2802 /* Now load as many as possible of the first arguments into
2803 registers, and push the rest onto the stack. Loop thru args
2804 from first to last. */
2805 for (argnum
= 0; argnum
< nargs
; argnum
++)
2808 char valbuf
[MAX_REGISTER_SIZE
];
2809 struct value
*arg
= args
[argnum
];
2810 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
2811 int len
= TYPE_LENGTH (arg_type
);
2812 enum type_code typecode
= TYPE_CODE (arg_type
);
2815 fprintf_unfiltered (gdb_stdlog
,
2816 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2817 argnum
+ 1, len
, (int) typecode
);
2819 /* The EABI passes structures that do not fit in a register by
2821 if (len
> MIPS_SAVED_REGSIZE
2822 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
))
2824 store_unsigned_integer (valbuf
, MIPS_SAVED_REGSIZE
, VALUE_ADDRESS (arg
));
2825 typecode
= TYPE_CODE_PTR
;
2826 len
= MIPS_SAVED_REGSIZE
;
2829 fprintf_unfiltered (gdb_stdlog
, " push");
2832 val
= (char *) VALUE_CONTENTS (arg
);
2834 /* 32-bit ABIs always start floating point arguments in an
2835 even-numbered floating point register. Round the FP register
2836 up before the check to see if there are any FP registers
2837 left. Non MIPS_EABI targets also pass the FP in the integer
2838 registers so also round up normal registers. */
2839 if (!FP_REGISTER_DOUBLE
2840 && fp_register_arg_p (typecode
, arg_type
))
2842 if ((float_argreg
& 1))
2846 /* Floating point arguments passed in registers have to be
2847 treated specially. On 32-bit architectures, doubles
2848 are passed in register pairs; the even register gets
2849 the low word, and the odd register gets the high word.
2850 On non-EABI processors, the first two floating point arguments are
2851 also copied to general registers, because MIPS16 functions
2852 don't use float registers for arguments. This duplication of
2853 arguments in general registers can't hurt non-MIPS16 functions
2854 because those registers are normally skipped. */
2855 /* MIPS_EABI squeezes a struct that contains a single floating
2856 point value into an FP register instead of pushing it onto the
2858 if (fp_register_arg_p (typecode
, arg_type
)
2859 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM
)
2861 if (!FP_REGISTER_DOUBLE
&& len
== 8)
2863 int low_offset
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? 4 : 0;
2864 unsigned long regval
;
2866 /* Write the low word of the double to the even register(s). */
2867 regval
= extract_unsigned_integer (val
+ low_offset
, 4);
2869 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
2870 float_argreg
, phex (regval
, 4));
2871 write_register (float_argreg
++, regval
);
2873 /* Write the high word of the double to the odd register(s). */
2874 regval
= extract_unsigned_integer (val
+ 4 - low_offset
, 4);
2876 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
2877 float_argreg
, phex (regval
, 4));
2878 write_register (float_argreg
++, regval
);
2882 /* This is a floating point value that fits entirely
2883 in a single register. */
2884 /* On 32 bit ABI's the float_argreg is further adjusted
2885 above to ensure that it is even register aligned. */
2886 LONGEST regval
= extract_unsigned_integer (val
, len
);
2888 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
2889 float_argreg
, phex (regval
, len
));
2890 write_register (float_argreg
++, regval
);
2895 /* Copy the argument to general registers or the stack in
2896 register-sized pieces. Large arguments are split between
2897 registers and stack. */
2898 /* Note: structs whose size is not a multiple of
2899 mips_regsize() are treated specially: Irix cc passes them
2900 in registers where gcc sometimes puts them on the stack.
2901 For maximum compatibility, we will put them in both
2903 int odd_sized_struct
= ((len
> MIPS_SAVED_REGSIZE
) &&
2904 (len
% MIPS_SAVED_REGSIZE
!= 0));
2906 /* Note: Floating-point values that didn't fit into an FP
2907 register are only written to memory. */
2910 /* Remember if the argument was written to the stack. */
2911 int stack_used_p
= 0;
2913 len
< MIPS_SAVED_REGSIZE
? len
: MIPS_SAVED_REGSIZE
;
2916 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
2919 /* Write this portion of the argument to the stack. */
2920 if (argreg
> MIPS_LAST_ARG_REGNUM
2922 || fp_register_arg_p (typecode
, arg_type
))
2924 /* Should shorter than int integer values be
2925 promoted to int before being stored? */
2926 int longword_offset
= 0;
2929 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
2931 if (MIPS_STACK_ARGSIZE
== 8 &&
2932 (typecode
== TYPE_CODE_INT
||
2933 typecode
== TYPE_CODE_PTR
||
2934 typecode
== TYPE_CODE_FLT
) && len
<= 4)
2935 longword_offset
= MIPS_STACK_ARGSIZE
- len
;
2936 else if ((typecode
== TYPE_CODE_STRUCT
||
2937 typecode
== TYPE_CODE_UNION
) &&
2938 TYPE_LENGTH (arg_type
) < MIPS_STACK_ARGSIZE
)
2939 longword_offset
= MIPS_STACK_ARGSIZE
- len
;
2944 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=0x%s",
2945 paddr_nz (stack_offset
));
2946 fprintf_unfiltered (gdb_stdlog
, " longword_offset=0x%s",
2947 paddr_nz (longword_offset
));
2950 addr
= sp
+ stack_offset
+ longword_offset
;
2955 fprintf_unfiltered (gdb_stdlog
, " @0x%s ",
2957 for (i
= 0; i
< partial_len
; i
++)
2959 fprintf_unfiltered (gdb_stdlog
, "%02x",
2963 write_memory (addr
, val
, partial_len
);
2966 /* Note!!! This is NOT an else clause. Odd sized
2967 structs may go thru BOTH paths. Floating point
2968 arguments will not. */
2969 /* Write this portion of the argument to a general
2970 purpose register. */
2971 if (argreg
<= MIPS_LAST_ARG_REGNUM
2972 && !fp_register_arg_p (typecode
, arg_type
))
2974 LONGEST regval
= extract_unsigned_integer (val
, partial_len
);
2977 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
2979 phex (regval
, MIPS_SAVED_REGSIZE
));
2980 write_register (argreg
, regval
);
2987 /* Compute the the offset into the stack at which we
2988 will copy the next parameter.
2990 In the new EABI (and the NABI32), the stack_offset
2991 only needs to be adjusted when it has been used. */
2994 stack_offset
+= align_up (partial_len
, MIPS_STACK_ARGSIZE
);
2998 fprintf_unfiltered (gdb_stdlog
, "\n");
3001 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
3003 /* Return adjusted stack pointer. */
3007 /* N32/N64 version of push_dummy_call. */
3010 mips_n32n64_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
3011 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
3012 struct value
**args
, CORE_ADDR sp
, int struct_return
,
3013 CORE_ADDR struct_addr
)
3019 int stack_offset
= 0;
3021 /* For shared libraries, "t9" needs to point at the function
3023 regcache_cooked_write_signed (regcache
, T9_REGNUM
, func_addr
);
3025 /* Set the return address register to point to the entry point of
3026 the program, where a breakpoint lies in wait. */
3027 regcache_cooked_write_signed (regcache
, RA_REGNUM
, bp_addr
);
3029 /* First ensure that the stack and structure return address (if any)
3030 are properly aligned. The stack has to be at least 64-bit
3031 aligned even on 32-bit machines, because doubles must be 64-bit
3032 aligned. For n32 and n64, stack frames need to be 128-bit
3033 aligned, so we round to this widest known alignment. */
3035 sp
= align_down (sp
, 16);
3036 struct_addr
= align_down (struct_addr
, 16);
3038 /* Now make space on the stack for the args. */
3039 for (argnum
= 0; argnum
< nargs
; argnum
++)
3040 len
+= align_up (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])),
3041 MIPS_STACK_ARGSIZE
);
3042 sp
-= align_up (len
, 16);
3045 fprintf_unfiltered (gdb_stdlog
,
3046 "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n",
3047 paddr_nz (sp
), (long) align_up (len
, 16));
3049 /* Initialize the integer and float register pointers. */
3051 float_argreg
= mips_fpa0_regnum (current_gdbarch
);
3053 /* The struct_return pointer occupies the first parameter-passing reg. */
3057 fprintf_unfiltered (gdb_stdlog
,
3058 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3059 argreg
, paddr_nz (struct_addr
));
3060 write_register (argreg
++, struct_addr
);
3063 /* Now load as many as possible of the first arguments into
3064 registers, and push the rest onto the stack. Loop thru args
3065 from first to last. */
3066 for (argnum
= 0; argnum
< nargs
; argnum
++)
3069 char valbuf
[MAX_REGISTER_SIZE
];
3070 struct value
*arg
= args
[argnum
];
3071 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
3072 int len
= TYPE_LENGTH (arg_type
);
3073 enum type_code typecode
= TYPE_CODE (arg_type
);
3076 fprintf_unfiltered (gdb_stdlog
,
3077 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3078 argnum
+ 1, len
, (int) typecode
);
3080 val
= (char *) VALUE_CONTENTS (arg
);
3082 if (fp_register_arg_p (typecode
, arg_type
)
3083 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM
)
3085 /* This is a floating point value that fits entirely
3086 in a single register. */
3087 /* On 32 bit ABI's the float_argreg is further adjusted
3088 above to ensure that it is even register aligned. */
3089 LONGEST regval
= extract_unsigned_integer (val
, len
);
3091 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3092 float_argreg
, phex (regval
, len
));
3093 write_register (float_argreg
++, regval
);
3096 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3097 argreg
, phex (regval
, len
));
3098 write_register (argreg
, regval
);
3103 /* Copy the argument to general registers or the stack in
3104 register-sized pieces. Large arguments are split between
3105 registers and stack. */
3106 /* Note: structs whose size is not a multiple of
3107 mips_regsize() are treated specially: Irix cc passes them
3108 in registers where gcc sometimes puts them on the stack.
3109 For maximum compatibility, we will put them in both
3111 int odd_sized_struct
= ((len
> MIPS_SAVED_REGSIZE
) &&
3112 (len
% MIPS_SAVED_REGSIZE
!= 0));
3113 /* Note: Floating-point values that didn't fit into an FP
3114 register are only written to memory. */
3117 /* Rememer if the argument was written to the stack. */
3118 int stack_used_p
= 0;
3119 int partial_len
= len
< MIPS_SAVED_REGSIZE
?
3120 len
: MIPS_SAVED_REGSIZE
;
3123 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3126 /* Write this portion of the argument to the stack. */
3127 if (argreg
> MIPS_LAST_ARG_REGNUM
3129 || fp_register_arg_p (typecode
, arg_type
))
3131 /* Should shorter than int integer values be
3132 promoted to int before being stored? */
3133 int longword_offset
= 0;
3136 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
3138 if (MIPS_STACK_ARGSIZE
== 8 &&
3139 (typecode
== TYPE_CODE_INT
||
3140 typecode
== TYPE_CODE_PTR
||
3141 typecode
== TYPE_CODE_FLT
) && len
<= 4)
3142 longword_offset
= MIPS_STACK_ARGSIZE
- len
;
3147 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=0x%s",
3148 paddr_nz (stack_offset
));
3149 fprintf_unfiltered (gdb_stdlog
, " longword_offset=0x%s",
3150 paddr_nz (longword_offset
));
3153 addr
= sp
+ stack_offset
+ longword_offset
;
3158 fprintf_unfiltered (gdb_stdlog
, " @0x%s ",
3160 for (i
= 0; i
< partial_len
; i
++)
3162 fprintf_unfiltered (gdb_stdlog
, "%02x",
3166 write_memory (addr
, val
, partial_len
);
3169 /* Note!!! This is NOT an else clause. Odd sized
3170 structs may go thru BOTH paths. Floating point
3171 arguments will not. */
3172 /* Write this portion of the argument to a general
3173 purpose register. */
3174 if (argreg
<= MIPS_LAST_ARG_REGNUM
3175 && !fp_register_arg_p (typecode
, arg_type
))
3177 LONGEST regval
= extract_unsigned_integer (val
, partial_len
);
3179 /* A non-floating-point argument being passed in a
3180 general register. If a struct or union, and if
3181 the remaining length is smaller than the register
3182 size, we have to adjust the register value on
3185 It does not seem to be necessary to do the
3186 same for integral types.
3188 cagney/2001-07-23: gdb/179: Also, GCC, when
3189 outputting LE O32 with sizeof (struct) <
3190 MIPS_SAVED_REGSIZE, generates a left shift as
3191 part of storing the argument in a register a
3192 register (the left shift isn't generated when
3193 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3194 is quite possible that this is GCC contradicting
3195 the LE/O32 ABI, GDB has not been adjusted to
3196 accommodate this. Either someone needs to
3197 demonstrate that the LE/O32 ABI specifies such a
3198 left shift OR this new ABI gets identified as
3199 such and GDB gets tweaked accordingly. */
3201 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
3202 && partial_len
< MIPS_SAVED_REGSIZE
3203 && (typecode
== TYPE_CODE_STRUCT
||
3204 typecode
== TYPE_CODE_UNION
))
3205 regval
<<= ((MIPS_SAVED_REGSIZE
- partial_len
) *
3209 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
3211 phex (regval
, MIPS_SAVED_REGSIZE
));
3212 write_register (argreg
, regval
);
3219 /* Compute the the offset into the stack at which we
3220 will copy the next parameter.
3222 In N32 (N64?), the stack_offset only needs to be
3223 adjusted when it has been used. */
3226 stack_offset
+= align_up (partial_len
, MIPS_STACK_ARGSIZE
);
3230 fprintf_unfiltered (gdb_stdlog
, "\n");
3233 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
3235 /* Return adjusted stack pointer. */
3239 /* O32 version of push_dummy_call. */
3242 mips_o32_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
3243 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
3244 struct value
**args
, CORE_ADDR sp
, int struct_return
,
3245 CORE_ADDR struct_addr
)
3251 int stack_offset
= 0;
3253 /* For shared libraries, "t9" needs to point at the function
3255 regcache_cooked_write_signed (regcache
, T9_REGNUM
, func_addr
);
3257 /* Set the return address register to point to the entry point of
3258 the program, where a breakpoint lies in wait. */
3259 regcache_cooked_write_signed (regcache
, RA_REGNUM
, bp_addr
);
3261 /* First ensure that the stack and structure return address (if any)
3262 are properly aligned. The stack has to be at least 64-bit
3263 aligned even on 32-bit machines, because doubles must be 64-bit
3264 aligned. For n32 and n64, stack frames need to be 128-bit
3265 aligned, so we round to this widest known alignment. */
3267 sp
= align_down (sp
, 16);
3268 struct_addr
= align_down (struct_addr
, 16);
3270 /* Now make space on the stack for the args. */
3271 for (argnum
= 0; argnum
< nargs
; argnum
++)
3272 len
+= align_up (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])),
3273 MIPS_STACK_ARGSIZE
);
3274 sp
-= align_up (len
, 16);
3277 fprintf_unfiltered (gdb_stdlog
,
3278 "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n",
3279 paddr_nz (sp
), (long) align_up (len
, 16));
3281 /* Initialize the integer and float register pointers. */
3283 float_argreg
= mips_fpa0_regnum (current_gdbarch
);
3285 /* The struct_return pointer occupies the first parameter-passing reg. */
3289 fprintf_unfiltered (gdb_stdlog
,
3290 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3291 argreg
, paddr_nz (struct_addr
));
3292 write_register (argreg
++, struct_addr
);
3293 stack_offset
+= MIPS_STACK_ARGSIZE
;
3296 /* Now load as many as possible of the first arguments into
3297 registers, and push the rest onto the stack. Loop thru args
3298 from first to last. */
3299 for (argnum
= 0; argnum
< nargs
; argnum
++)
3302 char valbuf
[MAX_REGISTER_SIZE
];
3303 struct value
*arg
= args
[argnum
];
3304 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
3305 int len
= TYPE_LENGTH (arg_type
);
3306 enum type_code typecode
= TYPE_CODE (arg_type
);
3309 fprintf_unfiltered (gdb_stdlog
,
3310 "mips_o32_push_dummy_call: %d len=%d type=%d",
3311 argnum
+ 1, len
, (int) typecode
);
3313 val
= (char *) VALUE_CONTENTS (arg
);
3315 /* 32-bit ABIs always start floating point arguments in an
3316 even-numbered floating point register. Round the FP register
3317 up before the check to see if there are any FP registers
3318 left. O32/O64 targets also pass the FP in the integer
3319 registers so also round up normal registers. */
3320 if (!FP_REGISTER_DOUBLE
3321 && fp_register_arg_p (typecode
, arg_type
))
3323 if ((float_argreg
& 1))
3327 /* Floating point arguments passed in registers have to be
3328 treated specially. On 32-bit architectures, doubles
3329 are passed in register pairs; the even register gets
3330 the low word, and the odd register gets the high word.
3331 On O32/O64, the first two floating point arguments are
3332 also copied to general registers, because MIPS16 functions
3333 don't use float registers for arguments. This duplication of
3334 arguments in general registers can't hurt non-MIPS16 functions
3335 because those registers are normally skipped. */
3337 if (fp_register_arg_p (typecode
, arg_type
)
3338 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM
)
3340 if (!FP_REGISTER_DOUBLE
&& len
== 8)
3342 int low_offset
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? 4 : 0;
3343 unsigned long regval
;
3345 /* Write the low word of the double to the even register(s). */
3346 regval
= extract_unsigned_integer (val
+ low_offset
, 4);
3348 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3349 float_argreg
, phex (regval
, 4));
3350 write_register (float_argreg
++, regval
);
3352 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3353 argreg
, phex (regval
, 4));
3354 write_register (argreg
++, regval
);
3356 /* Write the high word of the double to the odd register(s). */
3357 regval
= extract_unsigned_integer (val
+ 4 - low_offset
, 4);
3359 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3360 float_argreg
, phex (regval
, 4));
3361 write_register (float_argreg
++, regval
);
3364 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3365 argreg
, phex (regval
, 4));
3366 write_register (argreg
++, regval
);
3370 /* This is a floating point value that fits entirely
3371 in a single register. */
3372 /* On 32 bit ABI's the float_argreg is further adjusted
3373 above to ensure that it is even register aligned. */
3374 LONGEST regval
= extract_unsigned_integer (val
, len
);
3376 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3377 float_argreg
, phex (regval
, len
));
3378 write_register (float_argreg
++, regval
);
3379 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3380 registers for each argument. The below is (my
3381 guess) to ensure that the corresponding integer
3382 register has reserved the same space. */
3384 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3385 argreg
, phex (regval
, len
));
3386 write_register (argreg
, regval
);
3387 argreg
+= FP_REGISTER_DOUBLE
? 1 : 2;
3389 /* Reserve space for the FP register. */
3390 stack_offset
+= align_up (len
, MIPS_STACK_ARGSIZE
);
3394 /* Copy the argument to general registers or the stack in
3395 register-sized pieces. Large arguments are split between
3396 registers and stack. */
3397 /* Note: structs whose size is not a multiple of
3398 mips_regsize() are treated specially: Irix cc passes them
3399 in registers where gcc sometimes puts them on the stack.
3400 For maximum compatibility, we will put them in both
3402 int odd_sized_struct
= ((len
> MIPS_SAVED_REGSIZE
) &&
3403 (len
% MIPS_SAVED_REGSIZE
!= 0));
3404 /* Structures should be aligned to eight bytes (even arg registers)
3405 on MIPS_ABI_O32, if their first member has double precision. */
3406 if (MIPS_SAVED_REGSIZE
< 8
3407 && mips_type_needs_double_align (arg_type
))
3412 /* Note: Floating-point values that didn't fit into an FP
3413 register are only written to memory. */
3416 /* Remember if the argument was written to the stack. */
3417 int stack_used_p
= 0;
3419 len
< MIPS_SAVED_REGSIZE
? len
: MIPS_SAVED_REGSIZE
;
3422 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3425 /* Write this portion of the argument to the stack. */
3426 if (argreg
> MIPS_LAST_ARG_REGNUM
3428 || fp_register_arg_p (typecode
, arg_type
))
3430 /* Should shorter than int integer values be
3431 promoted to int before being stored? */
3432 int longword_offset
= 0;
3435 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
3437 if (MIPS_STACK_ARGSIZE
== 8 &&
3438 (typecode
== TYPE_CODE_INT
||
3439 typecode
== TYPE_CODE_PTR
||
3440 typecode
== TYPE_CODE_FLT
) && len
<= 4)
3441 longword_offset
= MIPS_STACK_ARGSIZE
- len
;
3446 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=0x%s",
3447 paddr_nz (stack_offset
));
3448 fprintf_unfiltered (gdb_stdlog
, " longword_offset=0x%s",
3449 paddr_nz (longword_offset
));
3452 addr
= sp
+ stack_offset
+ longword_offset
;
3457 fprintf_unfiltered (gdb_stdlog
, " @0x%s ",
3459 for (i
= 0; i
< partial_len
; i
++)
3461 fprintf_unfiltered (gdb_stdlog
, "%02x",
3465 write_memory (addr
, val
, partial_len
);
3468 /* Note!!! This is NOT an else clause. Odd sized
3469 structs may go thru BOTH paths. Floating point
3470 arguments will not. */
3471 /* Write this portion of the argument to a general
3472 purpose register. */
3473 if (argreg
<= MIPS_LAST_ARG_REGNUM
3474 && !fp_register_arg_p (typecode
, arg_type
))
3476 LONGEST regval
= extract_signed_integer (val
, partial_len
);
3477 /* Value may need to be sign extended, because
3478 mips_regsize() != MIPS_SAVED_REGSIZE. */
3480 /* A non-floating-point argument being passed in a
3481 general register. If a struct or union, and if
3482 the remaining length is smaller than the register
3483 size, we have to adjust the register value on
3486 It does not seem to be necessary to do the
3487 same for integral types.
3489 Also don't do this adjustment on O64 binaries.
3491 cagney/2001-07-23: gdb/179: Also, GCC, when
3492 outputting LE O32 with sizeof (struct) <
3493 MIPS_SAVED_REGSIZE, generates a left shift as
3494 part of storing the argument in a register a
3495 register (the left shift isn't generated when
3496 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3497 is quite possible that this is GCC contradicting
3498 the LE/O32 ABI, GDB has not been adjusted to
3499 accommodate this. Either someone needs to
3500 demonstrate that the LE/O32 ABI specifies such a
3501 left shift OR this new ABI gets identified as
3502 such and GDB gets tweaked accordingly. */
3504 if (MIPS_SAVED_REGSIZE
< 8
3505 && TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
3506 && partial_len
< MIPS_SAVED_REGSIZE
3507 && (typecode
== TYPE_CODE_STRUCT
||
3508 typecode
== TYPE_CODE_UNION
))
3509 regval
<<= ((MIPS_SAVED_REGSIZE
- partial_len
) *
3513 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
3515 phex (regval
, MIPS_SAVED_REGSIZE
));
3516 write_register (argreg
, regval
);
3519 /* Prevent subsequent floating point arguments from
3520 being passed in floating point registers. */
3521 float_argreg
= MIPS_LAST_FP_ARG_REGNUM
+ 1;
3527 /* Compute the the offset into the stack at which we
3528 will copy the next parameter.
3530 In older ABIs, the caller reserved space for
3531 registers that contained arguments. This was loosely
3532 refered to as their "home". Consequently, space is
3533 always allocated. */
3535 stack_offset
+= align_up (partial_len
, MIPS_STACK_ARGSIZE
);
3539 fprintf_unfiltered (gdb_stdlog
, "\n");
3542 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
3544 /* Return adjusted stack pointer. */
3548 /* O64 version of push_dummy_call. */
3551 mips_o64_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
3552 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
3553 struct value
**args
, CORE_ADDR sp
, int struct_return
,
3554 CORE_ADDR struct_addr
)
3560 int stack_offset
= 0;
3562 /* For shared libraries, "t9" needs to point at the function
3564 regcache_cooked_write_signed (regcache
, T9_REGNUM
, func_addr
);
3566 /* Set the return address register to point to the entry point of
3567 the program, where a breakpoint lies in wait. */
3568 regcache_cooked_write_signed (regcache
, RA_REGNUM
, bp_addr
);
3570 /* First ensure that the stack and structure return address (if any)
3571 are properly aligned. The stack has to be at least 64-bit
3572 aligned even on 32-bit machines, because doubles must be 64-bit
3573 aligned. For n32 and n64, stack frames need to be 128-bit
3574 aligned, so we round to this widest known alignment. */
3576 sp
= align_down (sp
, 16);
3577 struct_addr
= align_down (struct_addr
, 16);
3579 /* Now make space on the stack for the args. */
3580 for (argnum
= 0; argnum
< nargs
; argnum
++)
3581 len
+= align_up (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])),
3582 MIPS_STACK_ARGSIZE
);
3583 sp
-= align_up (len
, 16);
3586 fprintf_unfiltered (gdb_stdlog
,
3587 "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n",
3588 paddr_nz (sp
), (long) align_up (len
, 16));
3590 /* Initialize the integer and float register pointers. */
3592 float_argreg
= mips_fpa0_regnum (current_gdbarch
);
3594 /* The struct_return pointer occupies the first parameter-passing reg. */
3598 fprintf_unfiltered (gdb_stdlog
,
3599 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3600 argreg
, paddr_nz (struct_addr
));
3601 write_register (argreg
++, struct_addr
);
3602 stack_offset
+= MIPS_STACK_ARGSIZE
;
3605 /* Now load as many as possible of the first arguments into
3606 registers, and push the rest onto the stack. Loop thru args
3607 from first to last. */
3608 for (argnum
= 0; argnum
< nargs
; argnum
++)
3611 char valbuf
[MAX_REGISTER_SIZE
];
3612 struct value
*arg
= args
[argnum
];
3613 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
3614 int len
= TYPE_LENGTH (arg_type
);
3615 enum type_code typecode
= TYPE_CODE (arg_type
);
3618 fprintf_unfiltered (gdb_stdlog
,
3619 "mips_o64_push_dummy_call: %d len=%d type=%d",
3620 argnum
+ 1, len
, (int) typecode
);
3622 val
= (char *) VALUE_CONTENTS (arg
);
3624 /* 32-bit ABIs always start floating point arguments in an
3625 even-numbered floating point register. Round the FP register
3626 up before the check to see if there are any FP registers
3627 left. O32/O64 targets also pass the FP in the integer
3628 registers so also round up normal registers. */
3629 if (!FP_REGISTER_DOUBLE
3630 && fp_register_arg_p (typecode
, arg_type
))
3632 if ((float_argreg
& 1))
3636 /* Floating point arguments passed in registers have to be
3637 treated specially. On 32-bit architectures, doubles
3638 are passed in register pairs; the even register gets
3639 the low word, and the odd register gets the high word.
3640 On O32/O64, the first two floating point arguments are
3641 also copied to general registers, because MIPS16 functions
3642 don't use float registers for arguments. This duplication of
3643 arguments in general registers can't hurt non-MIPS16 functions
3644 because those registers are normally skipped. */
3646 if (fp_register_arg_p (typecode
, arg_type
)
3647 && float_argreg
<= MIPS_LAST_FP_ARG_REGNUM
)
3649 if (!FP_REGISTER_DOUBLE
&& len
== 8)
3651 int low_offset
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? 4 : 0;
3652 unsigned long regval
;
3654 /* Write the low word of the double to the even register(s). */
3655 regval
= extract_unsigned_integer (val
+ low_offset
, 4);
3657 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3658 float_argreg
, phex (regval
, 4));
3659 write_register (float_argreg
++, regval
);
3661 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3662 argreg
, phex (regval
, 4));
3663 write_register (argreg
++, regval
);
3665 /* Write the high word of the double to the odd register(s). */
3666 regval
= extract_unsigned_integer (val
+ 4 - low_offset
, 4);
3668 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3669 float_argreg
, phex (regval
, 4));
3670 write_register (float_argreg
++, regval
);
3673 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3674 argreg
, phex (regval
, 4));
3675 write_register (argreg
++, regval
);
3679 /* This is a floating point value that fits entirely
3680 in a single register. */
3681 /* On 32 bit ABI's the float_argreg is further adjusted
3682 above to ensure that it is even register aligned. */
3683 LONGEST regval
= extract_unsigned_integer (val
, len
);
3685 fprintf_unfiltered (gdb_stdlog
, " - fpreg=%d val=%s",
3686 float_argreg
, phex (regval
, len
));
3687 write_register (float_argreg
++, regval
);
3688 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3689 registers for each argument. The below is (my
3690 guess) to ensure that the corresponding integer
3691 register has reserved the same space. */
3693 fprintf_unfiltered (gdb_stdlog
, " - reg=%d val=%s",
3694 argreg
, phex (regval
, len
));
3695 write_register (argreg
, regval
);
3696 argreg
+= FP_REGISTER_DOUBLE
? 1 : 2;
3698 /* Reserve space for the FP register. */
3699 stack_offset
+= align_up (len
, MIPS_STACK_ARGSIZE
);
3703 /* Copy the argument to general registers or the stack in
3704 register-sized pieces. Large arguments are split between
3705 registers and stack. */
3706 /* Note: structs whose size is not a multiple of
3707 mips_regsize() are treated specially: Irix cc passes them
3708 in registers where gcc sometimes puts them on the stack.
3709 For maximum compatibility, we will put them in both
3711 int odd_sized_struct
= ((len
> MIPS_SAVED_REGSIZE
) &&
3712 (len
% MIPS_SAVED_REGSIZE
!= 0));
3713 /* Structures should be aligned to eight bytes (even arg registers)
3714 on MIPS_ABI_O32, if their first member has double precision. */
3715 if (MIPS_SAVED_REGSIZE
< 8
3716 && mips_type_needs_double_align (arg_type
))
3721 /* Note: Floating-point values that didn't fit into an FP
3722 register are only written to memory. */
3725 /* Remember if the argument was written to the stack. */
3726 int stack_used_p
= 0;
3728 len
< MIPS_SAVED_REGSIZE
? len
: MIPS_SAVED_REGSIZE
;
3731 fprintf_unfiltered (gdb_stdlog
, " -- partial=%d",
3734 /* Write this portion of the argument to the stack. */
3735 if (argreg
> MIPS_LAST_ARG_REGNUM
3737 || fp_register_arg_p (typecode
, arg_type
))
3739 /* Should shorter than int integer values be
3740 promoted to int before being stored? */
3741 int longword_offset
= 0;
3744 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
3746 if (MIPS_STACK_ARGSIZE
== 8 &&
3747 (typecode
== TYPE_CODE_INT
||
3748 typecode
== TYPE_CODE_PTR
||
3749 typecode
== TYPE_CODE_FLT
) && len
<= 4)
3750 longword_offset
= MIPS_STACK_ARGSIZE
- len
;
3755 fprintf_unfiltered (gdb_stdlog
, " - stack_offset=0x%s",
3756 paddr_nz (stack_offset
));
3757 fprintf_unfiltered (gdb_stdlog
, " longword_offset=0x%s",
3758 paddr_nz (longword_offset
));
3761 addr
= sp
+ stack_offset
+ longword_offset
;
3766 fprintf_unfiltered (gdb_stdlog
, " @0x%s ",
3768 for (i
= 0; i
< partial_len
; i
++)
3770 fprintf_unfiltered (gdb_stdlog
, "%02x",
3774 write_memory (addr
, val
, partial_len
);
3777 /* Note!!! This is NOT an else clause. Odd sized
3778 structs may go thru BOTH paths. Floating point
3779 arguments will not. */
3780 /* Write this portion of the argument to a general
3781 purpose register. */
3782 if (argreg
<= MIPS_LAST_ARG_REGNUM
3783 && !fp_register_arg_p (typecode
, arg_type
))
3785 LONGEST regval
= extract_signed_integer (val
, partial_len
);
3786 /* Value may need to be sign extended, because
3787 mips_regsize() != MIPS_SAVED_REGSIZE. */
3789 /* A non-floating-point argument being passed in a
3790 general register. If a struct or union, and if
3791 the remaining length is smaller than the register
3792 size, we have to adjust the register value on
3795 It does not seem to be necessary to do the
3796 same for integral types.
3798 Also don't do this adjustment on O64 binaries.
3800 cagney/2001-07-23: gdb/179: Also, GCC, when
3801 outputting LE O32 with sizeof (struct) <
3802 MIPS_SAVED_REGSIZE, generates a left shift as
3803 part of storing the argument in a register a
3804 register (the left shift isn't generated when
3805 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3806 is quite possible that this is GCC contradicting
3807 the LE/O32 ABI, GDB has not been adjusted to
3808 accommodate this. Either someone needs to
3809 demonstrate that the LE/O32 ABI specifies such a
3810 left shift OR this new ABI gets identified as
3811 such and GDB gets tweaked accordingly. */
3813 if (MIPS_SAVED_REGSIZE
< 8
3814 && TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
3815 && partial_len
< MIPS_SAVED_REGSIZE
3816 && (typecode
== TYPE_CODE_STRUCT
||
3817 typecode
== TYPE_CODE_UNION
))
3818 regval
<<= ((MIPS_SAVED_REGSIZE
- partial_len
) *
3822 fprintf_filtered (gdb_stdlog
, " - reg=%d val=%s",
3824 phex (regval
, MIPS_SAVED_REGSIZE
));
3825 write_register (argreg
, regval
);
3828 /* Prevent subsequent floating point arguments from
3829 being passed in floating point registers. */
3830 float_argreg
= MIPS_LAST_FP_ARG_REGNUM
+ 1;
3836 /* Compute the the offset into the stack at which we
3837 will copy the next parameter.
3839 In older ABIs, the caller reserved space for
3840 registers that contained arguments. This was loosely
3841 refered to as their "home". Consequently, space is
3842 always allocated. */
3844 stack_offset
+= align_up (partial_len
, MIPS_STACK_ARGSIZE
);
3848 fprintf_unfiltered (gdb_stdlog
, "\n");
3851 regcache_cooked_write_signed (regcache
, SP_REGNUM
, sp
);
3853 /* Return adjusted stack pointer. */
3858 mips_pop_frame (void)
3861 struct frame_info
*frame
= get_current_frame ();
3862 CORE_ADDR new_sp
= get_frame_base (frame
);
3863 mips_extra_func_info_t proc_desc
;
3865 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame
), 0, 0))
3867 generic_pop_dummy_frame ();
3868 flush_cached_frames ();
3872 proc_desc
= get_frame_extra_info (frame
)->proc_desc
;
3873 write_register (PC_REGNUM
, DEPRECATED_FRAME_SAVED_PC (frame
));
3874 mips_find_saved_regs (frame
);
3875 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
3876 if (regnum
!= SP_REGNUM
&& regnum
!= PC_REGNUM
3877 && deprecated_get_frame_saved_regs (frame
)[regnum
])
3879 /* Floating point registers must not be sign extended,
3880 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3882 if (mips_regnum (current_gdbarch
)->fp0
<= regnum
&& regnum
< mips_regnum (current_gdbarch
)->fp0
+ 32)
3883 write_register (regnum
,
3884 read_memory_unsigned_integer (deprecated_get_frame_saved_regs (frame
)[regnum
],
3885 MIPS_SAVED_REGSIZE
));
3887 write_register (regnum
,
3888 read_memory_integer (deprecated_get_frame_saved_regs (frame
)[regnum
],
3889 MIPS_SAVED_REGSIZE
));
3892 write_register (SP_REGNUM
, new_sp
);
3893 flush_cached_frames ();
3895 if (proc_desc
&& PROC_DESC_IS_DUMMY (proc_desc
))
3897 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
3899 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
3901 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
3903 if (&pi_ptr
->info
== proc_desc
)
3908 error ("Can't locate dummy extra frame info\n");
3910 if (prev_ptr
!= NULL
)
3911 prev_ptr
->next
= pi_ptr
->next
;
3913 linked_proc_desc_table
= pi_ptr
->next
;
3917 write_register (mips_regnum (current_gdbarch
)->hi
,
3918 read_memory_integer (new_sp
- 2 * MIPS_SAVED_REGSIZE
,
3919 MIPS_SAVED_REGSIZE
));
3920 write_register (mips_regnum (current_gdbarch
)->lo
,
3921 read_memory_integer (new_sp
- 3 * MIPS_SAVED_REGSIZE
,
3922 MIPS_SAVED_REGSIZE
));
3923 if (MIPS_FPU_TYPE
!= MIPS_FPU_NONE
)
3924 write_register (mips_regnum (current_gdbarch
)->fp_control_status
,
3925 read_memory_integer (new_sp
- 4 * MIPS_SAVED_REGSIZE
,
3926 MIPS_SAVED_REGSIZE
));
3930 /* Floating point register management.
3932 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3933 64bit operations, these early MIPS cpus treat fp register pairs
3934 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3935 registers and offer a compatibility mode that emulates the MIPS2 fp
3936 model. When operating in MIPS2 fp compat mode, later cpu's split
3937 double precision floats into two 32-bit chunks and store them in
3938 consecutive fp regs. To display 64-bit floats stored in this
3939 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3940 Throw in user-configurable endianness and you have a real mess.
3942 The way this works is:
3943 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3944 double-precision value will be split across two logical registers.
3945 The lower-numbered logical register will hold the low-order bits,
3946 regardless of the processor's endianness.
3947 - If we are on a 64-bit processor, and we are looking for a
3948 single-precision value, it will be in the low ordered bits
3949 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3950 save slot in memory.
3951 - If we are in 64-bit mode, everything is straightforward.
3953 Note that this code only deals with "live" registers at the top of the
3954 stack. We will attempt to deal with saved registers later, when
3955 the raw/cooked register interface is in place. (We need a general
3956 interface that can deal with dynamic saved register sizes -- fp
3957 regs could be 32 bits wide in one frame and 64 on the frame above
3960 static struct type
*
3961 mips_float_register_type (void)
3963 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
3964 return builtin_type_ieee_single_big
;
3966 return builtin_type_ieee_single_little
;
3969 static struct type
*
3970 mips_double_register_type (void)
3972 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
3973 return builtin_type_ieee_double_big
;
3975 return builtin_type_ieee_double_little
;
3978 /* Copy a 32-bit single-precision value from the current frame
3979 into rare_buffer. */
3982 mips_read_fp_register_single (struct frame_info
*frame
, int regno
,
3985 int raw_size
= register_size (current_gdbarch
, regno
);
3986 char *raw_buffer
= alloca (raw_size
);
3988 if (!frame_register_read (frame
, regno
, raw_buffer
))
3989 error ("can't read register %d (%s)", regno
, REGISTER_NAME (regno
));
3992 /* We have a 64-bit value for this register. Find the low-order
3996 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4001 memcpy (rare_buffer
, raw_buffer
+ offset
, 4);
4005 memcpy (rare_buffer
, raw_buffer
, 4);
4009 /* Copy a 64-bit double-precision value from the current frame into
4010 rare_buffer. This may include getting half of it from the next
4014 mips_read_fp_register_double (struct frame_info
*frame
, int regno
,
4017 int raw_size
= register_size (current_gdbarch
, regno
);
4019 if (raw_size
== 8 && !mips2_fp_compat ())
4021 /* We have a 64-bit value for this register, and we should use
4023 if (!frame_register_read (frame
, regno
, rare_buffer
))
4024 error ("can't read register %d (%s)", regno
, REGISTER_NAME (regno
));
4028 if ((regno
- mips_regnum (current_gdbarch
)->fp0
) & 1)
4029 internal_error (__FILE__
, __LINE__
,
4030 "mips_read_fp_register_double: bad access to "
4031 "odd-numbered FP register");
4033 /* mips_read_fp_register_single will find the correct 32 bits from
4035 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4037 mips_read_fp_register_single (frame
, regno
, rare_buffer
+ 4);
4038 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
);
4042 mips_read_fp_register_single (frame
, regno
, rare_buffer
);
4043 mips_read_fp_register_single (frame
, regno
+ 1, rare_buffer
+ 4);
4049 mips_print_fp_register (struct ui_file
*file
, struct frame_info
*frame
,
4051 { /* do values for FP (float) regs */
4053 double doub
, flt1
, flt2
; /* doubles extracted from raw hex data */
4054 int inv1
, inv2
, namelen
;
4056 raw_buffer
= (char *) alloca (2 * register_size (current_gdbarch
, mips_regnum (current_gdbarch
)->fp0
));
4058 fprintf_filtered (file
, "%s:", REGISTER_NAME (regnum
));
4059 fprintf_filtered (file
, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum
)),
4062 if (register_size (current_gdbarch
, regnum
) == 4 || mips2_fp_compat ())
4064 /* 4-byte registers: Print hex and floating. Also print even
4065 numbered registers as doubles. */
4066 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
4067 flt1
= unpack_double (mips_float_register_type (), raw_buffer
, &inv1
);
4069 print_scalar_formatted (raw_buffer
, builtin_type_uint32
, 'x', 'w', file
);
4071 fprintf_filtered (file
, " flt: ");
4073 fprintf_filtered (file
, " <invalid float> ");
4075 fprintf_filtered (file
, "%-17.9g", flt1
);
4077 if (regnum
% 2 == 0)
4079 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
4080 doub
= unpack_double (mips_double_register_type (), raw_buffer
,
4083 fprintf_filtered (file
, " dbl: ");
4085 fprintf_filtered (file
, "<invalid double>");
4087 fprintf_filtered (file
, "%-24.17g", doub
);
4092 /* Eight byte registers: print each one as hex, float and double. */
4093 mips_read_fp_register_single (frame
, regnum
, raw_buffer
);
4094 flt1
= unpack_double (mips_float_register_type (), raw_buffer
, &inv1
);
4096 mips_read_fp_register_double (frame
, regnum
, raw_buffer
);
4097 doub
= unpack_double (mips_double_register_type (), raw_buffer
, &inv2
);
4100 print_scalar_formatted (raw_buffer
, builtin_type_uint64
, 'x', 'g', file
);
4102 fprintf_filtered (file
, " flt: ");
4104 fprintf_filtered (file
, "<invalid float>");
4106 fprintf_filtered (file
, "%-17.9g", flt1
);
4108 fprintf_filtered (file
, " dbl: ");
4110 fprintf_filtered (file
, "<invalid double>");
4112 fprintf_filtered (file
, "%-24.17g", doub
);
4117 mips_print_register (struct ui_file
*file
, struct frame_info
*frame
,
4118 int regnum
, int all
)
4120 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4121 char raw_buffer
[MAX_REGISTER_SIZE
];
4124 if (TYPE_CODE (gdbarch_register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
)
4126 mips_print_fp_register (file
, frame
, regnum
);
4130 /* Get the data in raw format. */
4131 if (!frame_register_read (frame
, regnum
, raw_buffer
))
4133 fprintf_filtered (file
, "%s: [Invalid]", REGISTER_NAME (regnum
));
4137 fputs_filtered (REGISTER_NAME (regnum
), file
);
4139 /* The problem with printing numeric register names (r26, etc.) is that
4140 the user can't use them on input. Probably the best solution is to
4141 fix it so that either the numeric or the funky (a2, etc.) names
4142 are accepted on input. */
4143 if (regnum
< MIPS_NUMREGS
)
4144 fprintf_filtered (file
, "(r%d): ", regnum
);
4146 fprintf_filtered (file
, ": ");
4148 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4149 offset
= register_size (current_gdbarch
, regnum
) - register_size (current_gdbarch
, regnum
);
4153 print_scalar_formatted (raw_buffer
+ offset
, gdbarch_register_type (gdbarch
, regnum
),
4157 /* Replacement for generic do_registers_info.
4158 Print regs in pretty columns. */
4161 print_fp_register_row (struct ui_file
*file
, struct frame_info
*frame
,
4164 fprintf_filtered (file
, " ");
4165 mips_print_fp_register (file
, frame
, regnum
);
4166 fprintf_filtered (file
, "\n");
4171 /* Print a row's worth of GP (int) registers, with name labels above */
4174 print_gp_register_row (struct ui_file
*file
, struct frame_info
*frame
,
4177 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4178 /* do values for GP (int) regs */
4179 char raw_buffer
[MAX_REGISTER_SIZE
];
4180 int ncols
= (mips_regsize (gdbarch
) == 8 ? 4 : 8); /* display cols per row */
4184 /* For GP registers, we print a separate row of names above the vals */
4185 fprintf_filtered (file
, " ");
4186 for (col
= 0, regnum
= start_regnum
;
4187 col
< ncols
&& regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
;
4190 if (*REGISTER_NAME (regnum
) == '\0')
4191 continue; /* unused register */
4192 if (TYPE_CODE (gdbarch_register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
)
4193 break; /* end the row: reached FP register */
4194 fprintf_filtered (file
, mips_regsize (current_gdbarch
) == 8 ? "%17s" : "%9s",
4195 REGISTER_NAME (regnum
));
4198 /* print the R0 to R31 names */
4199 if ((start_regnum
% NUM_REGS
) < MIPS_NUMREGS
)
4200 fprintf_filtered (file
, "\n R%-4d", start_regnum
% NUM_REGS
);
4202 fprintf_filtered (file
, "\n ");
4204 /* now print the values in hex, 4 or 8 to the row */
4205 for (col
= 0, regnum
= start_regnum
;
4206 col
< ncols
&& regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
;
4209 if (*REGISTER_NAME (regnum
) == '\0')
4210 continue; /* unused register */
4211 if (TYPE_CODE (gdbarch_register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
)
4212 break; /* end row: reached FP register */
4213 /* OK: get the data in raw format. */
4214 if (!frame_register_read (frame
, regnum
, raw_buffer
))
4215 error ("can't read register %d (%s)", regnum
, REGISTER_NAME (regnum
));
4216 /* pad small registers */
4218 byte
< (mips_regsize (current_gdbarch
)
4219 - register_size (current_gdbarch
, regnum
));
4221 printf_filtered (" ");
4222 /* Now print the register value in hex, endian order. */
4223 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4224 for (byte
= register_size (current_gdbarch
, regnum
) - register_size (current_gdbarch
, regnum
);
4225 byte
< register_size (current_gdbarch
, regnum
);
4227 fprintf_filtered (file
, "%02x", (unsigned char) raw_buffer
[byte
]);
4229 for (byte
= register_size (current_gdbarch
, regnum
) - 1;
4232 fprintf_filtered (file
, "%02x", (unsigned char) raw_buffer
[byte
]);
4233 fprintf_filtered (file
, " ");
4236 if (col
> 0) /* ie. if we actually printed anything... */
4237 fprintf_filtered (file
, "\n");
4242 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4245 mips_print_registers_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
4246 struct frame_info
*frame
, int regnum
, int all
)
4248 if (regnum
!= -1) /* do one specified register */
4250 gdb_assert (regnum
>= NUM_REGS
);
4251 if (*(REGISTER_NAME (regnum
)) == '\0')
4252 error ("Not a valid register for the current processor type");
4254 mips_print_register (file
, frame
, regnum
, 0);
4255 fprintf_filtered (file
, "\n");
4258 /* do all (or most) registers */
4261 while (regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
)
4263 if (TYPE_CODE (gdbarch_register_type (gdbarch
, regnum
)) == TYPE_CODE_FLT
)
4265 if (all
) /* true for "INFO ALL-REGISTERS" command */
4266 regnum
= print_fp_register_row (file
, frame
, regnum
);
4268 regnum
+= MIPS_NUMREGS
; /* skip floating point regs */
4271 regnum
= print_gp_register_row (file
, frame
, regnum
);
4276 /* Is this a branch with a delay slot? */
4278 static int is_delayed (unsigned long);
4281 is_delayed (unsigned long insn
)
4284 for (i
= 0; i
< NUMOPCODES
; ++i
)
4285 if (mips_opcodes
[i
].pinfo
!= INSN_MACRO
4286 && (insn
& mips_opcodes
[i
].mask
) == mips_opcodes
[i
].match
)
4288 return (i
< NUMOPCODES
4289 && (mips_opcodes
[i
].pinfo
& (INSN_UNCOND_BRANCH_DELAY
4290 | INSN_COND_BRANCH_DELAY
4291 | INSN_COND_BRANCH_LIKELY
)));
4295 mips_step_skips_delay (CORE_ADDR pc
)
4297 char buf
[MIPS_INSTLEN
];
4299 /* There is no branch delay slot on MIPS16. */
4300 if (pc_is_mips16 (pc
))
4303 if (target_read_memory (pc
, buf
, MIPS_INSTLEN
) != 0)
4304 /* If error reading memory, guess that it is not a delayed branch. */
4306 return is_delayed ((unsigned long) extract_unsigned_integer (buf
, MIPS_INSTLEN
));
4310 /* Skip the PC past function prologue instructions (32-bit version).
4311 This is a helper function for mips_skip_prologue. */
4314 mips32_skip_prologue (CORE_ADDR pc
)
4318 int seen_sp_adjust
= 0;
4319 int load_immediate_bytes
= 0;
4321 /* Skip the typical prologue instructions. These are the stack adjustment
4322 instruction and the instructions that save registers on the stack
4323 or in the gcc frame. */
4324 for (end_pc
= pc
+ 100; pc
< end_pc
; pc
+= MIPS_INSTLEN
)
4326 unsigned long high_word
;
4328 inst
= mips_fetch_instruction (pc
);
4329 high_word
= (inst
>> 16) & 0xffff;
4331 if (high_word
== 0x27bd /* addiu $sp,$sp,offset */
4332 || high_word
== 0x67bd) /* daddiu $sp,$sp,offset */
4334 else if (inst
== 0x03a1e823 || /* subu $sp,$sp,$at */
4335 inst
== 0x03a8e823) /* subu $sp,$sp,$t0 */
4337 else if (((inst
& 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4338 || (inst
& 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4339 && (inst
& 0x001F0000)) /* reg != $zero */
4342 else if ((inst
& 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4344 else if ((inst
& 0xF3E00000) == 0xA3C00000 && (inst
& 0x001F0000))
4346 continue; /* reg != $zero */
4348 /* move $s8,$sp. With different versions of gas this will be either
4349 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4350 Accept any one of these. */
4351 else if (inst
== 0x03A0F021 || inst
== 0x03a0f025 || inst
== 0x03a0f02d)
4354 else if ((inst
& 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4356 else if (high_word
== 0x3c1c) /* lui $gp,n */
4358 else if (high_word
== 0x279c) /* addiu $gp,$gp,n */
4360 else if (inst
== 0x0399e021 /* addu $gp,$gp,$t9 */
4361 || inst
== 0x033ce021) /* addu $gp,$t9,$gp */
4363 /* The following instructions load $at or $t0 with an immediate
4364 value in preparation for a stack adjustment via
4365 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4366 a local variable, so we accept them only before a stack adjustment
4367 instruction was seen. */
4368 else if (!seen_sp_adjust
)
4370 if (high_word
== 0x3c01 || /* lui $at,n */
4371 high_word
== 0x3c08) /* lui $t0,n */
4373 load_immediate_bytes
+= MIPS_INSTLEN
; /* FIXME!! */
4376 else if (high_word
== 0x3421 || /* ori $at,$at,n */
4377 high_word
== 0x3508 || /* ori $t0,$t0,n */
4378 high_word
== 0x3401 || /* ori $at,$zero,n */
4379 high_word
== 0x3408) /* ori $t0,$zero,n */
4381 load_immediate_bytes
+= MIPS_INSTLEN
; /* FIXME!! */
4391 /* In a frameless function, we might have incorrectly
4392 skipped some load immediate instructions. Undo the skipping
4393 if the load immediate was not followed by a stack adjustment. */
4394 if (load_immediate_bytes
&& !seen_sp_adjust
)
4395 pc
-= load_immediate_bytes
;
4399 /* Skip the PC past function prologue instructions (16-bit version).
4400 This is a helper function for mips_skip_prologue. */
4403 mips16_skip_prologue (CORE_ADDR pc
)
4406 int extend_bytes
= 0;
4407 int prev_extend_bytes
;
4409 /* Table of instructions likely to be found in a function prologue. */
4412 unsigned short inst
;
4413 unsigned short mask
;
4420 , /* addiu $sp,offset */
4424 , /* daddiu $sp,offset */
4428 , /* sw reg,n($sp) */
4432 , /* sd reg,n($sp) */
4436 , /* sw $ra,n($sp) */
4440 , /* sd $ra,n($sp) */
4448 , /* sw $a0-$a3,n($s1) */
4452 , /* move reg,$a0-$a3 */
4456 , /* entry pseudo-op */
4460 , /* addiu $s1,$sp,n */
4463 } /* end of table marker */
4466 /* Skip the typical prologue instructions. These are the stack adjustment
4467 instruction and the instructions that save registers on the stack
4468 or in the gcc frame. */
4469 for (end_pc
= pc
+ 100; pc
< end_pc
; pc
+= MIPS16_INSTLEN
)
4471 unsigned short inst
;
4474 inst
= mips_fetch_instruction (pc
);
4476 /* Normally we ignore an extend instruction. However, if it is
4477 not followed by a valid prologue instruction, we must adjust
4478 the pc back over the extend so that it won't be considered
4479 part of the prologue. */
4480 if ((inst
& 0xf800) == 0xf000) /* extend */
4482 extend_bytes
= MIPS16_INSTLEN
;
4485 prev_extend_bytes
= extend_bytes
;
4488 /* Check for other valid prologue instructions besides extend. */
4489 for (i
= 0; table
[i
].mask
!= 0; i
++)
4490 if ((inst
& table
[i
].mask
) == table
[i
].inst
) /* found, get out */
4492 if (table
[i
].mask
!= 0) /* it was in table? */
4493 continue; /* ignore it */
4497 /* Return the current pc, adjusted backwards by 2 if
4498 the previous instruction was an extend. */
4499 return pc
- prev_extend_bytes
;
4505 /* To skip prologues, I use this predicate. Returns either PC itself
4506 if the code at PC does not look like a function prologue; otherwise
4507 returns an address that (if we're lucky) follows the prologue. If
4508 LENIENT, then we must skip everything which is involved in setting
4509 up the frame (it's OK to skip more, just so long as we don't skip
4510 anything which might clobber the registers which are being saved.
4511 We must skip more in the case where part of the prologue is in the
4512 delay slot of a non-prologue instruction). */
4515 mips_skip_prologue (CORE_ADDR pc
)
4517 /* See if we can determine the end of the prologue via the symbol table.
4518 If so, then return either PC, or the PC after the prologue, whichever
4521 CORE_ADDR post_prologue_pc
= after_prologue (pc
, NULL
);
4523 if (post_prologue_pc
!= 0)
4524 return max (pc
, post_prologue_pc
);
4526 /* Can't determine prologue from the symbol table, need to examine
4529 if (pc_is_mips16 (pc
))
4530 return mips16_skip_prologue (pc
);
4532 return mips32_skip_prologue (pc
);
4535 /* Determine how a return value is stored within the MIPS register
4536 file, given the return type `valtype'. */
4538 struct return_value_word
4547 return_value_location (struct type
*valtype
,
4548 struct return_value_word
*hi
,
4549 struct return_value_word
*lo
)
4551 int len
= TYPE_LENGTH (valtype
);
4553 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
4554 && ((MIPS_FPU_TYPE
== MIPS_FPU_DOUBLE
&& (len
== 4 || len
== 8))
4555 || (MIPS_FPU_TYPE
== MIPS_FPU_SINGLE
&& len
== 4)))
4557 if (!FP_REGISTER_DOUBLE
&& len
== 8)
4559 /* We need to break a 64bit float in two 32 bit halves and
4560 spread them across a floating-point register pair. */
4561 lo
->buf_offset
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? 4 : 0;
4562 hi
->buf_offset
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? 0 : 4;
4563 lo
->reg_offset
= ((TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
4564 && register_size (current_gdbarch
, mips_regnum (current_gdbarch
)->fp0
) == 8)
4566 hi
->reg_offset
= lo
->reg_offset
;
4567 lo
->reg
= mips_regnum (current_gdbarch
)->fp0
+ 0;
4568 hi
->reg
= mips_regnum (current_gdbarch
)->fp0
+ 1;
4574 /* The floating point value fits in a single floating-point
4576 lo
->reg_offset
= ((TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
4577 && register_size (current_gdbarch
, mips_regnum (current_gdbarch
)->fp0
) == 8
4580 lo
->reg
= mips_regnum (current_gdbarch
)->fp0
;
4591 /* Locate a result possibly spread across two registers. */
4593 lo
->reg
= regnum
+ 0;
4594 hi
->reg
= regnum
+ 1;
4595 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
4596 && len
< MIPS_SAVED_REGSIZE
)
4598 /* "un-left-justify" the value in the low register */
4599 lo
->reg_offset
= MIPS_SAVED_REGSIZE
- len
;
4604 else if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
4605 && len
> MIPS_SAVED_REGSIZE
/* odd-size structs */
4606 && len
< MIPS_SAVED_REGSIZE
* 2
4607 && (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
||
4608 TYPE_CODE (valtype
) == TYPE_CODE_UNION
))
4610 /* "un-left-justify" the value spread across two registers. */
4611 lo
->reg_offset
= 2 * MIPS_SAVED_REGSIZE
- len
;
4612 lo
->len
= MIPS_SAVED_REGSIZE
- lo
->reg_offset
;
4614 hi
->len
= len
- lo
->len
;
4618 /* Only perform a partial copy of the second register. */
4621 if (len
> MIPS_SAVED_REGSIZE
)
4623 lo
->len
= MIPS_SAVED_REGSIZE
;
4624 hi
->len
= len
- MIPS_SAVED_REGSIZE
;
4632 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
4633 && register_size (current_gdbarch
, regnum
) == 8
4634 && MIPS_SAVED_REGSIZE
== 4)
4636 /* Account for the fact that only the least-signficant part
4637 of the register is being used */
4638 lo
->reg_offset
+= 4;
4639 hi
->reg_offset
+= 4;
4642 hi
->buf_offset
= lo
->len
;
4646 /* Given a return value in `regbuf' with a type `valtype', extract and
4647 copy its value into `valbuf'. */
4650 mips_eabi_extract_return_value (struct type
*valtype
,
4654 struct return_value_word lo
;
4655 struct return_value_word hi
;
4656 return_value_location (valtype
, &hi
, &lo
);
4658 memcpy (valbuf
+ lo
.buf_offset
,
4659 regbuf
+ DEPRECATED_REGISTER_BYTE (lo
.reg
) + lo
.reg_offset
,
4663 memcpy (valbuf
+ hi
.buf_offset
,
4664 regbuf
+ DEPRECATED_REGISTER_BYTE (hi
.reg
) + hi
.reg_offset
,
4669 mips_o64_extract_return_value (struct type
*valtype
,
4673 struct return_value_word lo
;
4674 struct return_value_word hi
;
4675 return_value_location (valtype
, &hi
, &lo
);
4677 memcpy (valbuf
+ lo
.buf_offset
,
4678 regbuf
+ DEPRECATED_REGISTER_BYTE (lo
.reg
) + lo
.reg_offset
,
4682 memcpy (valbuf
+ hi
.buf_offset
,
4683 regbuf
+ DEPRECATED_REGISTER_BYTE (hi
.reg
) + hi
.reg_offset
,
4687 /* Given a return value in `valbuf' with a type `valtype', write it's
4688 value into the appropriate register. */
4691 mips_eabi_store_return_value (struct type
*valtype
, char *valbuf
)
4693 char raw_buffer
[MAX_REGISTER_SIZE
];
4694 struct return_value_word lo
;
4695 struct return_value_word hi
;
4696 return_value_location (valtype
, &hi
, &lo
);
4698 memset (raw_buffer
, 0, sizeof (raw_buffer
));
4699 memcpy (raw_buffer
+ lo
.reg_offset
, valbuf
+ lo
.buf_offset
, lo
.len
);
4700 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo
.reg
), raw_buffer
,
4701 register_size (current_gdbarch
, lo
.reg
));
4705 memset (raw_buffer
, 0, sizeof (raw_buffer
));
4706 memcpy (raw_buffer
+ hi
.reg_offset
, valbuf
+ hi
.buf_offset
, hi
.len
);
4707 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi
.reg
), raw_buffer
,
4708 register_size (current_gdbarch
, hi
.reg
));
4713 mips_o64_store_return_value (struct type
*valtype
, char *valbuf
)
4715 char raw_buffer
[MAX_REGISTER_SIZE
];
4716 struct return_value_word lo
;
4717 struct return_value_word hi
;
4718 return_value_location (valtype
, &hi
, &lo
);
4720 memset (raw_buffer
, 0, sizeof (raw_buffer
));
4721 memcpy (raw_buffer
+ lo
.reg_offset
, valbuf
+ lo
.buf_offset
, lo
.len
);
4722 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo
.reg
), raw_buffer
,
4723 register_size (current_gdbarch
, lo
.reg
));
4727 memset (raw_buffer
, 0, sizeof (raw_buffer
));
4728 memcpy (raw_buffer
+ hi
.reg_offset
, valbuf
+ hi
.buf_offset
, hi
.len
);
4729 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi
.reg
), raw_buffer
,
4730 register_size (current_gdbarch
, hi
.reg
));
4734 /* O32 ABI stuff. */
4736 static enum return_value_convention
4737 mips_o32_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
4738 struct regcache
*regcache
,
4739 void *readbuf
, const void *writebuf
)
4741 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
4743 if (TYPE_CODE (type
)== TYPE_CODE_STRUCT
4744 || TYPE_CODE (type
)== TYPE_CODE_UNION
4745 || TYPE_CODE (type
)== TYPE_CODE_ARRAY
)
4746 return RETURN_VALUE_STRUCT_CONVENTION
;
4747 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
4748 && TYPE_LENGTH (type
) == 4
4749 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4751 /* A single-precision floating-point value. It fits in the
4752 least significant part of FP0. */
4754 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
4755 mips_xfer_register (regcache
,
4756 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
,
4758 TARGET_BYTE_ORDER
, readbuf
, writebuf
, 0);
4759 return RETURN_VALUE_REGISTER_CONVENTION
;
4761 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
4762 && TYPE_LENGTH (type
) == 8
4763 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4765 /* A double-precision floating-point value. The most
4766 significant part goes in FP1, and the least significant in
4769 fprintf_unfiltered (gdb_stderr
, "Return float in $fp1/$fp0\n");
4770 switch (TARGET_BYTE_ORDER
)
4772 case BFD_ENDIAN_LITTLE
:
4773 mips_xfer_register (regcache
,
4774 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
+ 0,
4775 4, TARGET_BYTE_ORDER
, readbuf
, writebuf
, 0);
4776 mips_xfer_register (regcache
,
4777 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
+ 1,
4778 4, TARGET_BYTE_ORDER
, readbuf
, writebuf
, 4);
4780 case BFD_ENDIAN_BIG
:
4781 mips_xfer_register (regcache
,
4782 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
+ 1,
4783 4, TARGET_BYTE_ORDER
, readbuf
, writebuf
, 0);
4784 mips_xfer_register (regcache
,
4785 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
+ 0,
4786 4, TARGET_BYTE_ORDER
, readbuf
, writebuf
, 4);
4789 internal_error (__FILE__
, __LINE__
, "bad switch");
4791 return RETURN_VALUE_REGISTER_CONVENTION
;
4794 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4795 && TYPE_NFIELDS (type
) <= 2
4796 && TYPE_NFIELDS (type
) >= 1
4797 && ((TYPE_NFIELDS (type
) == 1
4798 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4800 || (TYPE_NFIELDS (type
) == 2
4801 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4803 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 1))
4805 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4807 /* A struct that contains one or two floats. Each value is part
4808 in the least significant part of their floating point
4810 bfd_byte reg
[MAX_REGISTER_SIZE
];
4813 for (field
= 0, regnum
= mips_regnum (current_gdbarch
)->fp0
;
4814 field
< TYPE_NFIELDS (type
);
4815 field
++, regnum
+= 2)
4817 int offset
= (FIELD_BITPOS (TYPE_FIELDS (type
)[field
])
4820 fprintf_unfiltered (gdb_stderr
, "Return float struct+%d\n", offset
);
4821 mips_xfer_register (regcache
, NUM_REGS
+ regnum
,
4822 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, field
)),
4823 TARGET_BYTE_ORDER
, readbuf
, writebuf
, offset
);
4825 return RETURN_VALUE_REGISTER_CONVENTION
;
4829 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4830 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
4832 /* A structure or union. Extract the left justified value,
4833 regardless of the byte order. I.e. DO NOT USE
4837 for (offset
= 0, regnum
= V0_REGNUM
;
4838 offset
< TYPE_LENGTH (type
);
4839 offset
+= register_size (current_gdbarch
, regnum
), regnum
++)
4841 int xfer
= register_size (current_gdbarch
, regnum
);
4842 if (offset
+ xfer
> TYPE_LENGTH (type
))
4843 xfer
= TYPE_LENGTH (type
) - offset
;
4845 fprintf_unfiltered (gdb_stderr
, "Return struct+%d:%d in $%d\n",
4846 offset
, xfer
, regnum
);
4847 mips_xfer_register (regcache
, NUM_REGS
+ regnum
, xfer
,
4848 BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
, offset
);
4850 return RETURN_VALUE_REGISTER_CONVENTION
;
4855 /* A scalar extract each part but least-significant-byte
4856 justified. o32 thinks registers are 4 byte, regardless of
4857 the ISA. mips_stack_argsize controls this. */
4860 for (offset
= 0, regnum
= V0_REGNUM
;
4861 offset
< TYPE_LENGTH (type
);
4862 offset
+= mips_stack_argsize (), regnum
++)
4864 int xfer
= mips_stack_argsize ();
4866 if (offset
+ xfer
> TYPE_LENGTH (type
))
4867 xfer
= TYPE_LENGTH (type
) - offset
;
4869 fprintf_unfiltered (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
4870 offset
, xfer
, regnum
);
4871 mips_xfer_register (regcache
, NUM_REGS
+ regnum
, xfer
,
4872 TARGET_BYTE_ORDER
, readbuf
, writebuf
, offset
);
4874 return RETURN_VALUE_REGISTER_CONVENTION
;
4878 /* N32/N44 ABI stuff. */
4880 static enum return_value_convention
4881 mips_n32n64_return_value (struct gdbarch
*gdbarch
,
4882 struct type
*type
, struct regcache
*regcache
,
4883 void *readbuf
, const void *writebuf
)
4885 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
4886 if (TYPE_CODE (type
)== TYPE_CODE_STRUCT
4887 || TYPE_CODE (type
)== TYPE_CODE_UNION
4888 || TYPE_CODE (type
)== TYPE_CODE_ARRAY
4889 || TYPE_LENGTH (type
) > 2 * MIPS_SAVED_REGSIZE
)
4890 return RETURN_VALUE_STRUCT_CONVENTION
;
4891 else if (TYPE_CODE (type
) == TYPE_CODE_FLT
4892 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4894 /* A floating-point value belongs in the least significant part
4897 fprintf_unfiltered (gdb_stderr
, "Return float in $fp0\n");
4898 mips_xfer_register (regcache
,
4899 NUM_REGS
+ mips_regnum (current_gdbarch
)->fp0
,
4901 TARGET_BYTE_ORDER
, readbuf
, writebuf
, 0);
4902 return RETURN_VALUE_REGISTER_CONVENTION
;
4904 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4905 && TYPE_NFIELDS (type
) <= 2
4906 && TYPE_NFIELDS (type
) >= 1
4907 && ((TYPE_NFIELDS (type
) == 1
4908 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4910 || (TYPE_NFIELDS (type
) == 2
4911 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0))
4913 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 1))
4915 && tdep
->mips_fpu_type
!= MIPS_FPU_NONE
)
4917 /* A struct that contains one or two floats. Each value is part
4918 in the least significant part of their floating point
4920 bfd_byte reg
[MAX_REGISTER_SIZE
];
4923 for (field
= 0, regnum
= mips_regnum (current_gdbarch
)->fp0
;
4924 field
< TYPE_NFIELDS (type
);
4925 field
++, regnum
+= 2)
4927 int offset
= (FIELD_BITPOS (TYPE_FIELDS (type
)[field
])
4930 fprintf_unfiltered (gdb_stderr
, "Return float struct+%d\n", offset
);
4931 mips_xfer_register (regcache
, NUM_REGS
+ regnum
,
4932 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, field
)),
4933 TARGET_BYTE_ORDER
, readbuf
, writebuf
, offset
);
4935 return RETURN_VALUE_REGISTER_CONVENTION
;
4937 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
4938 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
4940 /* A structure or union. Extract the left justified value,
4941 regardless of the byte order. I.e. DO NOT USE
4945 for (offset
= 0, regnum
= V0_REGNUM
;
4946 offset
< TYPE_LENGTH (type
);
4947 offset
+= register_size (current_gdbarch
, regnum
), regnum
++)
4949 int xfer
= register_size (current_gdbarch
, regnum
);
4950 if (offset
+ xfer
> TYPE_LENGTH (type
))
4951 xfer
= TYPE_LENGTH (type
) - offset
;
4953 fprintf_unfiltered (gdb_stderr
, "Return struct+%d:%d in $%d\n",
4954 offset
, xfer
, regnum
);
4955 mips_xfer_register (regcache
, NUM_REGS
+ regnum
, xfer
,
4956 BFD_ENDIAN_UNKNOWN
, readbuf
, writebuf
, offset
);
4958 return RETURN_VALUE_REGISTER_CONVENTION
;
4962 /* A scalar extract each part but least-significant-byte
4966 for (offset
= 0, regnum
= V0_REGNUM
;
4967 offset
< TYPE_LENGTH (type
);
4968 offset
+= register_size (current_gdbarch
, regnum
), regnum
++)
4970 int xfer
= register_size (current_gdbarch
, regnum
);
4972 if (offset
+ xfer
> TYPE_LENGTH (type
))
4973 xfer
= TYPE_LENGTH (type
) - offset
;
4975 fprintf_unfiltered (gdb_stderr
, "Return scalar+%d:%d in $%d\n",
4976 offset
, xfer
, regnum
);
4977 mips_xfer_register (regcache
, NUM_REGS
+ regnum
, xfer
,
4978 TARGET_BYTE_ORDER
, readbuf
, writebuf
, offset
);
4980 return RETURN_VALUE_REGISTER_CONVENTION
;
4985 mips_extract_struct_value_address (struct regcache
*regcache
)
4987 /* FIXME: This will only work at random. The caller passes the
4988 struct_return address in V0, but it is not preserved. It may
4989 still be there, or this may be a random value. */
4992 regcache_cooked_read_signed (regcache
, V0_REGNUM
, &val
);
4996 /* Exported procedure: Is PC in the signal trampoline code */
4999 mips_pc_in_sigtramp (CORE_ADDR pc
, char *ignore
)
5001 if (sigtramp_address
== 0)
5003 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
5006 /* Root of all "set mips "/"show mips " commands. This will eventually be
5007 used for all MIPS-specific commands. */
5010 show_mips_command (char *args
, int from_tty
)
5012 help_list (showmipscmdlist
, "show mips ", all_commands
, gdb_stdout
);
5016 set_mips_command (char *args
, int from_tty
)
5018 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
5019 help_list (setmipscmdlist
, "set mips ", all_commands
, gdb_stdout
);
5022 /* Commands to show/set the MIPS FPU type. */
5025 show_mipsfpu_command (char *args
, int from_tty
)
5028 switch (MIPS_FPU_TYPE
)
5030 case MIPS_FPU_SINGLE
:
5031 fpu
= "single-precision";
5033 case MIPS_FPU_DOUBLE
:
5034 fpu
= "double-precision";
5037 fpu
= "absent (none)";
5040 internal_error (__FILE__
, __LINE__
, "bad switch");
5042 if (mips_fpu_type_auto
)
5043 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5046 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5052 set_mipsfpu_command (char *args
, int from_tty
)
5054 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5055 show_mipsfpu_command (args
, from_tty
);
5059 set_mipsfpu_single_command (char *args
, int from_tty
)
5061 mips_fpu_type
= MIPS_FPU_SINGLE
;
5062 mips_fpu_type_auto
= 0;
5063 gdbarch_tdep (current_gdbarch
)->mips_fpu_type
= MIPS_FPU_SINGLE
;
5067 set_mipsfpu_double_command (char *args
, int from_tty
)
5069 mips_fpu_type
= MIPS_FPU_DOUBLE
;
5070 mips_fpu_type_auto
= 0;
5071 gdbarch_tdep (current_gdbarch
)->mips_fpu_type
= MIPS_FPU_DOUBLE
;
5075 set_mipsfpu_none_command (char *args
, int from_tty
)
5077 mips_fpu_type
= MIPS_FPU_NONE
;
5078 mips_fpu_type_auto
= 0;
5079 gdbarch_tdep (current_gdbarch
)->mips_fpu_type
= MIPS_FPU_NONE
;
5083 set_mipsfpu_auto_command (char *args
, int from_tty
)
5085 mips_fpu_type_auto
= 1;
5088 /* Attempt to identify the particular processor model by reading the
5089 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
5090 the relevant processor still exists (it dates back to '94) and
5091 secondly this is not the way to do this. The processor type should
5092 be set by forcing an architecture change. */
5095 deprecated_mips_set_processor_regs_hack (void)
5097 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
5100 prid
= read_register (PRID_REGNUM
);
5102 if ((prid
& ~0xf) == 0x700)
5103 tdep
->mips_processor_reg_names
= mips_r3041_reg_names
;
5106 /* Just like reinit_frame_cache, but with the right arguments to be
5107 callable as an sfunc. */
5110 reinit_frame_cache_sfunc (char *args
, int from_tty
,
5111 struct cmd_list_element
*c
)
5113 reinit_frame_cache ();
5117 gdb_print_insn_mips (bfd_vma memaddr
, struct disassemble_info
*info
)
5119 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
5120 mips_extra_func_info_t proc_desc
;
5122 /* Search for the function containing this address. Set the low bit
5123 of the address when searching, in case we were given an even address
5124 that is the start of a 16-bit function. If we didn't do this,
5125 the search would fail because the symbol table says the function
5126 starts at an odd address, i.e. 1 byte past the given address. */
5127 memaddr
= ADDR_BITS_REMOVE (memaddr
);
5128 proc_desc
= non_heuristic_proc_desc (make_mips16_addr (memaddr
), NULL
);
5130 /* Make an attempt to determine if this is a 16-bit function. If
5131 the procedure descriptor exists and the address therein is odd,
5132 it's definitely a 16-bit function. Otherwise, we have to just
5133 guess that if the address passed in is odd, it's 16-bits. */
5134 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5135 disassembler needs to be able to locally determine the ISA, and
5136 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5140 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc
)))
5141 info
->mach
= bfd_mach_mips16
;
5145 if (pc_is_mips16 (memaddr
))
5146 info
->mach
= bfd_mach_mips16
;
5149 /* Round down the instruction address to the appropriate boundary. */
5150 memaddr
&= (info
->mach
== bfd_mach_mips16
? ~1 : ~3);
5152 /* Set the disassembler options. */
5153 if (tdep
->mips_abi
== MIPS_ABI_N32
5154 || tdep
->mips_abi
== MIPS_ABI_N64
)
5156 /* Set up the disassembler info, so that we get the right
5157 register names from libopcodes. */
5158 if (tdep
->mips_abi
== MIPS_ABI_N32
)
5159 info
->disassembler_options
= "gpr-names=n32";
5161 info
->disassembler_options
= "gpr-names=64";
5162 info
->flavour
= bfd_target_elf_flavour
;
5165 /* This string is not recognized explicitly by the disassembler,
5166 but it tells the disassembler to not try to guess the ABI from
5167 the bfd elf headers, such that, if the user overrides the ABI
5168 of a program linked as NewABI, the disassembly will follow the
5169 register naming conventions specified by the user. */
5170 info
->disassembler_options
= "gpr-names=32";
5172 /* Call the appropriate disassembler based on the target endian-ness. */
5173 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
5174 return print_insn_big_mips (memaddr
, info
);
5176 return print_insn_little_mips (memaddr
, info
);
5179 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5180 counter value to determine whether a 16- or 32-bit breakpoint should be
5181 used. It returns a pointer to a string of bytes that encode a breakpoint
5182 instruction, stores the length of the string to *lenptr, and adjusts pc
5183 (if necessary) to point to the actual memory location where the
5184 breakpoint should be inserted. */
5186 static const unsigned char *
5187 mips_breakpoint_from_pc (CORE_ADDR
* pcptr
, int *lenptr
)
5189 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
5191 if (pc_is_mips16 (*pcptr
))
5193 static unsigned char mips16_big_breakpoint
[] = {0xe8, 0xa5};
5194 *pcptr
= unmake_mips16_addr (*pcptr
);
5195 *lenptr
= sizeof (mips16_big_breakpoint
);
5196 return mips16_big_breakpoint
;
5200 /* The IDT board uses an unusual breakpoint value, and
5201 sometimes gets confused when it sees the usual MIPS
5202 breakpoint instruction. */
5203 static unsigned char big_breakpoint
[] = {0, 0x5, 0, 0xd};
5204 static unsigned char pmon_big_breakpoint
[] = {0, 0, 0, 0xd};
5205 static unsigned char idt_big_breakpoint
[] = {0, 0, 0x0a, 0xd};
5207 *lenptr
= sizeof (big_breakpoint
);
5209 if (strcmp (target_shortname
, "mips") == 0)
5210 return idt_big_breakpoint
;
5211 else if (strcmp (target_shortname
, "ddb") == 0
5212 || strcmp (target_shortname
, "pmon") == 0
5213 || strcmp (target_shortname
, "lsi") == 0)
5214 return pmon_big_breakpoint
;
5216 return big_breakpoint
;
5221 if (pc_is_mips16 (*pcptr
))
5223 static unsigned char mips16_little_breakpoint
[] = {0xa5, 0xe8};
5224 *pcptr
= unmake_mips16_addr (*pcptr
);
5225 *lenptr
= sizeof (mips16_little_breakpoint
);
5226 return mips16_little_breakpoint
;
5230 static unsigned char little_breakpoint
[] = {0xd, 0, 0x5, 0};
5231 static unsigned char pmon_little_breakpoint
[] = {0xd, 0, 0, 0};
5232 static unsigned char idt_little_breakpoint
[] = {0xd, 0x0a, 0, 0};
5234 *lenptr
= sizeof (little_breakpoint
);
5236 if (strcmp (target_shortname
, "mips") == 0)
5237 return idt_little_breakpoint
;
5238 else if (strcmp (target_shortname
, "ddb") == 0
5239 || strcmp (target_shortname
, "pmon") == 0
5240 || strcmp (target_shortname
, "lsi") == 0)
5241 return pmon_little_breakpoint
;
5243 return little_breakpoint
;
5248 /* If PC is in a mips16 call or return stub, return the address of the target
5249 PC, which is either the callee or the caller. There are several
5250 cases which must be handled:
5252 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5253 target PC is in $31 ($ra).
5254 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5255 and the target PC is in $2.
5256 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5257 before the jal instruction, this is effectively a call stub
5258 and the the target PC is in $2. Otherwise this is effectively
5259 a return stub and the target PC is in $18.
5261 See the source code for the stubs in gcc/config/mips/mips16.S for
5264 This function implements the SKIP_TRAMPOLINE_CODE macro.
5268 mips_skip_stub (CORE_ADDR pc
)
5271 CORE_ADDR start_addr
;
5273 /* Find the starting address and name of the function containing the PC. */
5274 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
5277 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5278 target PC is in $31 ($ra). */
5279 if (strcmp (name
, "__mips16_ret_sf") == 0
5280 || strcmp (name
, "__mips16_ret_df") == 0)
5281 return read_signed_register (RA_REGNUM
);
5283 if (strncmp (name
, "__mips16_call_stub_", 19) == 0)
5285 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5286 and the target PC is in $2. */
5287 if (name
[19] >= '0' && name
[19] <= '9')
5288 return read_signed_register (2);
5290 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5291 before the jal instruction, this is effectively a call stub
5292 and the the target PC is in $2. Otherwise this is effectively
5293 a return stub and the target PC is in $18. */
5294 else if (name
[19] == 's' || name
[19] == 'd')
5296 if (pc
== start_addr
)
5298 /* Check if the target of the stub is a compiler-generated
5299 stub. Such a stub for a function bar might have a name
5300 like __fn_stub_bar, and might look like this:
5305 la $1,bar (becomes a lui/addiu pair)
5307 So scan down to the lui/addi and extract the target
5308 address from those two instructions. */
5310 CORE_ADDR target_pc
= read_signed_register (2);
5314 /* See if the name of the target function is __fn_stub_*. */
5315 if (find_pc_partial_function (target_pc
, &name
, NULL
, NULL
) == 0)
5317 if (strncmp (name
, "__fn_stub_", 10) != 0
5318 && strcmp (name
, "etext") != 0
5319 && strcmp (name
, "_etext") != 0)
5322 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5323 The limit on the search is arbitrarily set to 20
5324 instructions. FIXME. */
5325 for (i
= 0, pc
= 0; i
< 20; i
++, target_pc
+= MIPS_INSTLEN
)
5327 inst
= mips_fetch_instruction (target_pc
);
5328 if ((inst
& 0xffff0000) == 0x3c010000) /* lui $at */
5329 pc
= (inst
<< 16) & 0xffff0000; /* high word */
5330 else if ((inst
& 0xffff0000) == 0x24210000) /* addiu $at */
5331 return pc
| (inst
& 0xffff); /* low word */
5334 /* Couldn't find the lui/addui pair, so return stub address. */
5338 /* This is the 'return' part of a call stub. The return
5339 address is in $r18. */
5340 return read_signed_register (18);
5343 return 0; /* not a stub */
5347 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5348 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5351 mips_in_call_stub (CORE_ADDR pc
, char *name
)
5353 CORE_ADDR start_addr
;
5355 /* Find the starting address of the function containing the PC. If the
5356 caller didn't give us a name, look it up at the same time. */
5357 if (find_pc_partial_function (pc
, name
? NULL
: &name
, &start_addr
, NULL
) == 0)
5360 if (strncmp (name
, "__mips16_call_stub_", 19) == 0)
5362 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5363 if (name
[19] >= '0' && name
[19] <= '9')
5365 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5366 before the jal instruction, this is effectively a call stub. */
5367 else if (name
[19] == 's' || name
[19] == 'd')
5368 return pc
== start_addr
;
5371 return 0; /* not a stub */
5375 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5376 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5379 mips_in_return_stub (CORE_ADDR pc
, char *name
)
5381 CORE_ADDR start_addr
;
5383 /* Find the starting address of the function containing the PC. */
5384 if (find_pc_partial_function (pc
, NULL
, &start_addr
, NULL
) == 0)
5387 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5388 if (strcmp (name
, "__mips16_ret_sf") == 0
5389 || strcmp (name
, "__mips16_ret_df") == 0)
5392 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5393 i.e. after the jal instruction, this is effectively a return stub. */
5394 if (strncmp (name
, "__mips16_call_stub_", 19) == 0
5395 && (name
[19] == 's' || name
[19] == 'd')
5396 && pc
!= start_addr
)
5399 return 0; /* not a stub */
5403 /* Return non-zero if the PC is in a library helper function that should
5404 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5407 mips_ignore_helper (CORE_ADDR pc
)
5411 /* Find the starting address and name of the function containing the PC. */
5412 if (find_pc_partial_function (pc
, &name
, NULL
, NULL
) == 0)
5415 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5416 that we want to ignore. */
5417 return (strcmp (name
, "__mips16_ret_sf") == 0
5418 || strcmp (name
, "__mips16_ret_df") == 0);
5422 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5423 the register stored on the stack (32) is different to its real raw
5424 size (64). The below ensures that registers are fetched from the
5425 stack using their ABI size and then stored into the RAW_BUFFER
5426 using their raw size.
5428 The alternative to adding this function would be to add an ABI
5429 macro - REGISTER_STACK_SIZE(). */
5432 mips_get_saved_register (char *raw_buffer
,
5435 struct frame_info
*frame
,
5437 enum lval_type
*lvalp
)
5440 enum lval_type lvalx
;
5444 /* Always a pseudo. */
5445 gdb_assert (regnum
>= NUM_REGS
);
5447 /* Make certain that all needed parameters are present. */
5452 if (optimizedp
== NULL
)
5453 optimizedp
= &optimizedx
;
5455 if ((regnum
% NUM_REGS
) == SP_REGNUM
)
5456 /* The SP_REGNUM is special, its value is stored in saved_regs.
5457 In fact, it is so special that it can even only be fetched
5458 using a raw register number! Once this code as been converted
5459 to frame-unwind the problem goes away. */
5460 frame_register_unwind (deprecated_get_next_frame_hack (frame
),
5461 regnum
% NUM_REGS
, optimizedp
, lvalp
, addrp
,
5462 &realnumx
, raw_buffer
);
5464 /* Get it from the next frame. */
5465 frame_register_unwind (deprecated_get_next_frame_hack (frame
),
5466 regnum
, optimizedp
, lvalp
, addrp
,
5467 &realnumx
, raw_buffer
);
5470 /* Immediately after a function call, return the saved pc.
5471 Can't always go through the frames for this because on some machines
5472 the new frame is not set up until the new function executes
5473 some instructions. */
5476 mips_saved_pc_after_call (struct frame_info
*frame
)
5478 return read_signed_register (RA_REGNUM
);
5482 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5483 [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5486 mips_stab_reg_to_regnum (int num
)
5489 if (num
>= 0 && num
< 32)
5491 else if (num
>= 38 && num
< 70)
5492 regnum
= num
+ mips_regnum (current_gdbarch
)->fp0
- 38;
5494 regnum
= mips_regnum (current_gdbarch
)->hi
;
5496 regnum
= mips_regnum (current_gdbarch
)->lo
;
5498 /* This will hopefully (eventually) provoke a warning. Should
5499 we be calling complaint() here? */
5500 return NUM_REGS
+ NUM_PSEUDO_REGS
;
5501 return NUM_REGS
+ regnum
;
5505 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5506 NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5509 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num
)
5512 if (num
>= 0 && num
< 32)
5514 else if (num
>= 32 && num
< 64)
5515 regnum
= num
+ mips_regnum (current_gdbarch
)->fp0
- 32;
5517 regnum
= mips_regnum (current_gdbarch
)->hi
;
5519 regnum
= mips_regnum (current_gdbarch
)->lo
;
5521 /* This will hopefully (eventually) provoke a warning. Should we
5522 be calling complaint() here? */
5523 return NUM_REGS
+ NUM_PSEUDO_REGS
;
5524 return NUM_REGS
+ regnum
;
5528 mips_register_sim_regno (int regnum
)
5530 /* Only makes sense to supply raw registers. */
5531 gdb_assert (regnum
>= 0 && regnum
< NUM_REGS
);
5532 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5533 decide if it is valid. Should instead define a standard sim/gdb
5534 register numbering scheme. */
5535 if (REGISTER_NAME (NUM_REGS
+ regnum
) != NULL
5536 && REGISTER_NAME (NUM_REGS
+ regnum
)[0] != '\0')
5539 return LEGACY_SIM_REGNO_IGNORE
;
5543 /* Convert an integer into an address. By first converting the value
5544 into a pointer and then extracting it signed, the address is
5545 guarenteed to be correctly sign extended. */
5548 mips_integer_to_address (struct type
*type
, void *buf
)
5550 char *tmp
= alloca (TYPE_LENGTH (builtin_type_void_data_ptr
));
5551 LONGEST val
= unpack_long (type
, buf
);
5552 store_signed_integer (tmp
, TYPE_LENGTH (builtin_type_void_data_ptr
), val
);
5553 return extract_signed_integer (tmp
,
5554 TYPE_LENGTH (builtin_type_void_data_ptr
));
5558 mips_find_abi_section (bfd
*abfd
, asection
*sect
, void *obj
)
5560 enum mips_abi
*abip
= (enum mips_abi
*) obj
;
5561 const char *name
= bfd_get_section_name (abfd
, sect
);
5563 if (*abip
!= MIPS_ABI_UNKNOWN
)
5566 if (strncmp (name
, ".mdebug.", 8) != 0)
5569 if (strcmp (name
, ".mdebug.abi32") == 0)
5570 *abip
= MIPS_ABI_O32
;
5571 else if (strcmp (name
, ".mdebug.abiN32") == 0)
5572 *abip
= MIPS_ABI_N32
;
5573 else if (strcmp (name
, ".mdebug.abi64") == 0)
5574 *abip
= MIPS_ABI_N64
;
5575 else if (strcmp (name
, ".mdebug.abiO64") == 0)
5576 *abip
= MIPS_ABI_O64
;
5577 else if (strcmp (name
, ".mdebug.eabi32") == 0)
5578 *abip
= MIPS_ABI_EABI32
;
5579 else if (strcmp (name
, ".mdebug.eabi64") == 0)
5580 *abip
= MIPS_ABI_EABI64
;
5582 warning ("unsupported ABI %s.", name
+ 8);
5585 static enum mips_abi
5586 global_mips_abi (void)
5590 for (i
= 0; mips_abi_strings
[i
] != NULL
; i
++)
5591 if (mips_abi_strings
[i
] == mips_abi_string
)
5592 return (enum mips_abi
) i
;
5594 internal_error (__FILE__
, __LINE__
,
5595 "unknown ABI string");
5598 static struct gdbarch
*
5599 mips_gdbarch_init (struct gdbarch_info info
,
5600 struct gdbarch_list
*arches
)
5602 struct gdbarch
*gdbarch
;
5603 struct gdbarch_tdep
*tdep
;
5605 enum mips_abi mips_abi
, found_abi
, wanted_abi
;
5612 /* First of all, extract the elf_flags, if available. */
5613 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
5614 elf_flags
= elf_elfheader (info
.abfd
)->e_flags
;
5617 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5618 switch ((elf_flags
& EF_MIPS_ABI
))
5620 case E_MIPS_ABI_O32
:
5621 mips_abi
= MIPS_ABI_O32
;
5623 case E_MIPS_ABI_O64
:
5624 mips_abi
= MIPS_ABI_O64
;
5626 case E_MIPS_ABI_EABI32
:
5627 mips_abi
= MIPS_ABI_EABI32
;
5629 case E_MIPS_ABI_EABI64
:
5630 mips_abi
= MIPS_ABI_EABI64
;
5633 if ((elf_flags
& EF_MIPS_ABI2
))
5634 mips_abi
= MIPS_ABI_N32
;
5636 mips_abi
= MIPS_ABI_UNKNOWN
;
5640 /* GCC creates a pseudo-section whose name describes the ABI. */
5641 if (mips_abi
== MIPS_ABI_UNKNOWN
&& info
.abfd
!= NULL
)
5642 bfd_map_over_sections (info
.abfd
, mips_find_abi_section
, &mips_abi
);
5644 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5645 Use the ABI from the last architecture if there is one. */
5646 if (info
.abfd
== NULL
&& arches
!= NULL
)
5647 mips_abi
= gdbarch_tdep (arches
->gdbarch
)->found_abi
;
5649 /* Try the architecture for any hint of the correct ABI. */
5650 if (mips_abi
== MIPS_ABI_UNKNOWN
5651 && info
.bfd_arch_info
!= NULL
5652 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
5654 switch (info
.bfd_arch_info
->mach
)
5656 case bfd_mach_mips3900
:
5657 mips_abi
= MIPS_ABI_EABI32
;
5659 case bfd_mach_mips4100
:
5660 case bfd_mach_mips5000
:
5661 mips_abi
= MIPS_ABI_EABI64
;
5663 case bfd_mach_mips8000
:
5664 case bfd_mach_mips10000
:
5665 /* On Irix, ELF64 executables use the N64 ABI. The
5666 pseudo-sections which describe the ABI aren't present
5667 on IRIX. (Even for executables created by gcc.) */
5668 if (bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
5669 && elf_elfheader (info
.abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
5670 mips_abi
= MIPS_ABI_N64
;
5672 mips_abi
= MIPS_ABI_N32
;
5677 if (mips_abi
== MIPS_ABI_UNKNOWN
)
5678 mips_abi
= MIPS_ABI_O32
;
5680 /* Now that we have found what the ABI for this binary would be,
5681 check whether the user is overriding it. */
5682 found_abi
= mips_abi
;
5683 wanted_abi
= global_mips_abi ();
5684 if (wanted_abi
!= MIPS_ABI_UNKNOWN
)
5685 mips_abi
= wanted_abi
;
5689 fprintf_unfiltered (gdb_stdlog
,
5690 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5692 fprintf_unfiltered (gdb_stdlog
,
5693 "mips_gdbarch_init: mips_abi = %d\n",
5695 fprintf_unfiltered (gdb_stdlog
,
5696 "mips_gdbarch_init: found_mips_abi = %d\n",
5700 /* try to find a pre-existing architecture */
5701 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
5703 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
5705 /* MIPS needs to be pedantic about which ABI the object is
5707 if (gdbarch_tdep (arches
->gdbarch
)->elf_flags
!= elf_flags
)
5709 if (gdbarch_tdep (arches
->gdbarch
)->mips_abi
!= mips_abi
)
5711 /* Need to be pedantic about which register virtual size is
5713 if (gdbarch_tdep (arches
->gdbarch
)->mips64_transfers_32bit_regs_p
5714 != mips64_transfers_32bit_regs_p
)
5716 return arches
->gdbarch
;
5719 /* Need a new architecture. Fill in a target specific vector. */
5720 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
5721 gdbarch
= gdbarch_alloc (&info
, tdep
);
5722 tdep
->elf_flags
= elf_flags
;
5723 tdep
->mips64_transfers_32bit_regs_p
= mips64_transfers_32bit_regs_p
;
5725 /* Initially set everything according to the default ABI/ISA. */
5726 set_gdbarch_short_bit (gdbarch
, 16);
5727 set_gdbarch_int_bit (gdbarch
, 32);
5728 set_gdbarch_float_bit (gdbarch
, 32);
5729 set_gdbarch_double_bit (gdbarch
, 64);
5730 set_gdbarch_long_double_bit (gdbarch
, 64);
5731 set_gdbarch_register_reggroup_p (gdbarch
, mips_register_reggroup_p
);
5732 set_gdbarch_pseudo_register_read (gdbarch
, mips_pseudo_register_read
);
5733 set_gdbarch_pseudo_register_write (gdbarch
, mips_pseudo_register_write
);
5734 tdep
->found_abi
= found_abi
;
5735 tdep
->mips_abi
= mips_abi
;
5737 set_gdbarch_elf_make_msymbol_special (gdbarch
,
5738 mips_elf_make_msymbol_special
);
5740 /* Fill in the OS dependant register numbers. */
5742 struct mips_regnum
*regnum
= GDBARCH_OBSTACK_ZALLOC (gdbarch
,
5743 struct mips_regnum
);
5744 tdep
->regnum
= regnum
;
5745 if (info
.osabi
== GDB_OSABI_IRIX
)
5750 regnum
->badvaddr
= 66;
5753 regnum
->fp_control_status
= 69;
5754 regnum
->fp_implementation_revision
= 70;
5759 regnum
->lo
= MIPS_EMBED_LO_REGNUM
;
5760 regnum
->hi
= MIPS_EMBED_HI_REGNUM
;
5761 regnum
->badvaddr
= MIPS_EMBED_BADVADDR_REGNUM
;
5762 regnum
->cause
= MIPS_EMBED_CAUSE_REGNUM
;
5763 regnum
->pc
= MIPS_EMBED_PC_REGNUM
;
5764 regnum
->fp0
= MIPS_EMBED_FP0_REGNUM
;
5765 regnum
->fp_control_status
= 70;
5766 regnum
->fp_implementation_revision
= 71;
5769 /* FIXME: cagney/2003-11-15: For MIPS, hasn't PC_REGNUM been
5770 replaced by read_pc? */
5771 set_gdbarch_pc_regnum (gdbarch
, regnum
->pc
);
5772 set_gdbarch_fp0_regnum (gdbarch
, regnum
->fp0
);
5773 set_gdbarch_num_regs (gdbarch
, num_regs
);
5774 set_gdbarch_num_pseudo_regs (gdbarch
, num_regs
);
5780 set_gdbarch_push_dummy_call (gdbarch
, mips_o32_push_dummy_call
);
5781 set_gdbarch_return_value (gdbarch
, mips_o32_return_value
);
5782 tdep
->mips_default_saved_regsize
= 4;
5783 tdep
->mips_default_stack_argsize
= 4;
5784 tdep
->mips_fp_register_double
= 0;
5785 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 4 - 1;
5786 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
5787 tdep
->default_mask_address_p
= 0;
5788 set_gdbarch_long_bit (gdbarch
, 32);
5789 set_gdbarch_ptr_bit (gdbarch
, 32);
5790 set_gdbarch_long_long_bit (gdbarch
, 64);
5791 set_gdbarch_deprecated_reg_struct_has_addr
5792 (gdbarch
, mips_o32_reg_struct_has_addr
);
5795 set_gdbarch_push_dummy_call (gdbarch
, mips_o64_push_dummy_call
);
5796 set_gdbarch_deprecated_store_return_value (gdbarch
, mips_o64_store_return_value
);
5797 set_gdbarch_deprecated_extract_return_value (gdbarch
, mips_o64_extract_return_value
);
5798 tdep
->mips_default_saved_regsize
= 8;
5799 tdep
->mips_default_stack_argsize
= 8;
5800 tdep
->mips_fp_register_double
= 1;
5801 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 4 - 1;
5802 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 4 - 1;
5803 tdep
->default_mask_address_p
= 0;
5804 set_gdbarch_long_bit (gdbarch
, 32);
5805 set_gdbarch_ptr_bit (gdbarch
, 32);
5806 set_gdbarch_long_long_bit (gdbarch
, 64);
5807 set_gdbarch_deprecated_reg_struct_has_addr
5808 (gdbarch
, mips_o32_reg_struct_has_addr
);
5809 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
5811 case MIPS_ABI_EABI32
:
5812 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
5813 set_gdbarch_deprecated_store_return_value (gdbarch
, mips_eabi_store_return_value
);
5814 set_gdbarch_deprecated_extract_return_value (gdbarch
, mips_eabi_extract_return_value
);
5815 tdep
->mips_default_saved_regsize
= 4;
5816 tdep
->mips_default_stack_argsize
= 4;
5817 tdep
->mips_fp_register_double
= 0;
5818 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 8 - 1;
5819 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
5820 tdep
->default_mask_address_p
= 0;
5821 set_gdbarch_long_bit (gdbarch
, 32);
5822 set_gdbarch_ptr_bit (gdbarch
, 32);
5823 set_gdbarch_long_long_bit (gdbarch
, 64);
5824 set_gdbarch_deprecated_reg_struct_has_addr
5825 (gdbarch
, mips_eabi_reg_struct_has_addr
);
5826 set_gdbarch_use_struct_convention (gdbarch
,
5827 mips_eabi_use_struct_convention
);
5829 case MIPS_ABI_EABI64
:
5830 set_gdbarch_push_dummy_call (gdbarch
, mips_eabi_push_dummy_call
);
5831 set_gdbarch_deprecated_store_return_value (gdbarch
, mips_eabi_store_return_value
);
5832 set_gdbarch_deprecated_extract_return_value (gdbarch
, mips_eabi_extract_return_value
);
5833 tdep
->mips_default_saved_regsize
= 8;
5834 tdep
->mips_default_stack_argsize
= 8;
5835 tdep
->mips_fp_register_double
= 1;
5836 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 8 - 1;
5837 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
5838 tdep
->default_mask_address_p
= 0;
5839 set_gdbarch_long_bit (gdbarch
, 64);
5840 set_gdbarch_ptr_bit (gdbarch
, 64);
5841 set_gdbarch_long_long_bit (gdbarch
, 64);
5842 set_gdbarch_deprecated_reg_struct_has_addr
5843 (gdbarch
, mips_eabi_reg_struct_has_addr
);
5844 set_gdbarch_use_struct_convention (gdbarch
,
5845 mips_eabi_use_struct_convention
);
5848 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
5849 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
5850 tdep
->mips_default_saved_regsize
= 8;
5851 tdep
->mips_default_stack_argsize
= 8;
5852 tdep
->mips_fp_register_double
= 1;
5853 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 8 - 1;
5854 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
5855 tdep
->default_mask_address_p
= 0;
5856 set_gdbarch_long_bit (gdbarch
, 32);
5857 set_gdbarch_ptr_bit (gdbarch
, 32);
5858 set_gdbarch_long_long_bit (gdbarch
, 64);
5859 set_gdbarch_deprecated_reg_struct_has_addr
5860 (gdbarch
, mips_n32n64_reg_struct_has_addr
);
5863 set_gdbarch_push_dummy_call (gdbarch
, mips_n32n64_push_dummy_call
);
5864 set_gdbarch_return_value (gdbarch
, mips_n32n64_return_value
);
5865 tdep
->mips_default_saved_regsize
= 8;
5866 tdep
->mips_default_stack_argsize
= 8;
5867 tdep
->mips_fp_register_double
= 1;
5868 tdep
->mips_last_arg_regnum
= A0_REGNUM
+ 8 - 1;
5869 tdep
->mips_last_fp_arg_regnum
= tdep
->regnum
->fp0
+ 12 + 8 - 1;
5870 tdep
->default_mask_address_p
= 0;
5871 set_gdbarch_long_bit (gdbarch
, 64);
5872 set_gdbarch_ptr_bit (gdbarch
, 64);
5873 set_gdbarch_long_long_bit (gdbarch
, 64);
5874 set_gdbarch_deprecated_reg_struct_has_addr
5875 (gdbarch
, mips_n32n64_reg_struct_has_addr
);
5878 internal_error (__FILE__
, __LINE__
,
5879 "unknown ABI in switch");
5882 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5883 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5886 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5887 flag in object files because to do so would make it impossible to
5888 link with libraries compiled without "-gp32". This is
5889 unnecessarily restrictive.
5891 We could solve this problem by adding "-gp32" multilibs to gcc,
5892 but to set this flag before gcc is built with such multilibs will
5893 break too many systems.''
5895 But even more unhelpfully, the default linker output target for
5896 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5897 for 64-bit programs - you need to change the ABI to change this,
5898 and not all gcc targets support that currently. Therefore using
5899 this flag to detect 32-bit mode would do the wrong thing given
5900 the current gcc - it would make GDB treat these 64-bit programs
5901 as 32-bit programs by default. */
5903 /* enable/disable the MIPS FPU */
5904 if (!mips_fpu_type_auto
)
5905 tdep
->mips_fpu_type
= mips_fpu_type
;
5906 else if (info
.bfd_arch_info
!= NULL
5907 && info
.bfd_arch_info
->arch
== bfd_arch_mips
)
5908 switch (info
.bfd_arch_info
->mach
)
5910 case bfd_mach_mips3900
:
5911 case bfd_mach_mips4100
:
5912 case bfd_mach_mips4111
:
5913 tdep
->mips_fpu_type
= MIPS_FPU_NONE
;
5915 case bfd_mach_mips4650
:
5916 tdep
->mips_fpu_type
= MIPS_FPU_SINGLE
;
5919 tdep
->mips_fpu_type
= MIPS_FPU_DOUBLE
;
5923 tdep
->mips_fpu_type
= MIPS_FPU_DOUBLE
;
5925 /* MIPS version of register names. */
5926 set_gdbarch_register_name (gdbarch
, mips_register_name
);
5927 if (info
.osabi
== GDB_OSABI_IRIX
)
5928 tdep
->mips_processor_reg_names
= mips_irix_reg_names
;
5929 else if (info
.bfd_arch_info
!= NULL
&& info
.bfd_arch_info
->mach
== bfd_mach_mips3900
)
5930 tdep
->mips_processor_reg_names
= mips_tx39_reg_names
;
5932 tdep
->mips_processor_reg_names
= mips_generic_reg_names
;
5933 set_gdbarch_read_pc (gdbarch
, mips_read_pc
);
5934 set_gdbarch_write_pc (gdbarch
, generic_target_write_pc
);
5935 set_gdbarch_deprecated_target_read_fp (gdbarch
, mips_read_sp
); /* Draft FRAME base. */
5936 set_gdbarch_read_sp (gdbarch
, mips_read_sp
);
5938 /* Add/remove bits from an address. The MIPS needs be careful to
5939 ensure that all 32 bit addresses are sign extended to 64 bits. */
5940 set_gdbarch_addr_bits_remove (gdbarch
, mips_addr_bits_remove
);
5942 /* There's a mess in stack frame creation. See comments in
5943 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5944 set_gdbarch_deprecated_init_frame_pc_first (gdbarch
, mips_init_frame_pc_first
);
5946 /* Map debug register numbers onto internal register numbers. */
5947 set_gdbarch_stab_reg_to_regnum (gdbarch
, mips_stab_reg_to_regnum
);
5948 set_gdbarch_ecoff_reg_to_regnum (gdbarch
, mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
5949 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
5950 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, mips_dwarf_dwarf2_ecoff_reg_to_regnum
);
5951 set_gdbarch_register_sim_regno (gdbarch
, mips_register_sim_regno
);
5953 /* Initialize a frame */
5954 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, mips_find_saved_regs
);
5955 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, mips_init_extra_frame_info
);
5957 /* MIPS version of CALL_DUMMY */
5959 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
5960 replaced by a command, and all targets will default to on stack
5961 (regardless of the stack's execute status). */
5962 set_gdbarch_call_dummy_location (gdbarch
, AT_SYMBOL
);
5963 set_gdbarch_deprecated_pop_frame (gdbarch
, mips_pop_frame
);
5964 set_gdbarch_frame_align (gdbarch
, mips_frame_align
);
5965 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch
, generic_save_dummy_frame_tos
);
5966 set_gdbarch_deprecated_register_convertible (gdbarch
, mips_register_convertible
);
5967 set_gdbarch_deprecated_register_convert_to_virtual (gdbarch
, mips_register_convert_to_virtual
);
5968 set_gdbarch_deprecated_register_convert_to_raw (gdbarch
, mips_register_convert_to_raw
);
5970 set_gdbarch_deprecated_frame_chain (gdbarch
, mips_frame_chain
);
5971 set_gdbarch_frameless_function_invocation (gdbarch
,
5972 generic_frameless_function_invocation_not
);
5973 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, mips_frame_saved_pc
);
5974 set_gdbarch_frame_args_skip (gdbarch
, 0);
5976 set_gdbarch_deprecated_get_saved_register (gdbarch
, mips_get_saved_register
);
5978 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
5979 set_gdbarch_breakpoint_from_pc (gdbarch
, mips_breakpoint_from_pc
);
5980 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
5982 set_gdbarch_skip_prologue (gdbarch
, mips_skip_prologue
);
5983 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, mips_saved_pc_after_call
);
5985 set_gdbarch_pointer_to_address (gdbarch
, signed_pointer_to_address
);
5986 set_gdbarch_address_to_pointer (gdbarch
, address_to_signed_pointer
);
5987 set_gdbarch_integer_to_address (gdbarch
, mips_integer_to_address
);
5989 set_gdbarch_function_start_offset (gdbarch
, 0);
5991 set_gdbarch_register_type (gdbarch
, mips_register_type
);
5993 set_gdbarch_print_registers_info (gdbarch
, mips_print_registers_info
);
5994 set_gdbarch_pc_in_sigtramp (gdbarch
, mips_pc_in_sigtramp
);
5996 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_mips
);
5998 /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT,
5999 HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT
6000 need to all be folded into the target vector. Since they are
6001 being used as guards for STOPPED_BY_WATCHPOINT, why not have
6002 STOPPED_BY_WATCHPOINT return the type of watchpoint that the code
6004 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
6006 /* Hook in OS ABI-specific overrides, if they have been registered. */
6007 gdbarch_init_osabi (info
, gdbarch
);
6009 set_gdbarch_extract_struct_value_address (gdbarch
,
6010 mips_extract_struct_value_address
);
6012 set_gdbarch_skip_trampoline_code (gdbarch
, mips_skip_stub
);
6014 set_gdbarch_in_solib_call_trampoline (gdbarch
, mips_in_call_stub
);
6015 set_gdbarch_in_solib_return_trampoline (gdbarch
, mips_in_return_stub
);
6021 mips_abi_update (char *ignore_args
, int from_tty
,
6022 struct cmd_list_element
*c
)
6024 struct gdbarch_info info
;
6026 /* Force the architecture to update, and (if it's a MIPS architecture)
6027 mips_gdbarch_init will take care of the rest. */
6028 gdbarch_info_init (&info
);
6029 gdbarch_update_p (info
);
6032 /* Print out which MIPS ABI is in use. */
6035 show_mips_abi (char *ignore_args
, int from_tty
)
6037 if (gdbarch_bfd_arch_info (current_gdbarch
)->arch
!= bfd_arch_mips
)
6039 "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6042 enum mips_abi global_abi
= global_mips_abi ();
6043 enum mips_abi actual_abi
= mips_abi (current_gdbarch
);
6044 const char *actual_abi_str
= mips_abi_strings
[actual_abi
];
6046 if (global_abi
== MIPS_ABI_UNKNOWN
)
6047 printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6049 else if (global_abi
== actual_abi
)
6051 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6055 /* Probably shouldn't happen... */
6057 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6059 mips_abi_strings
[global_abi
]);
6065 mips_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
6067 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
6071 int ef_mips_32bitmode
;
6072 /* determine the ISA */
6073 switch (tdep
->elf_flags
& EF_MIPS_ARCH
)
6091 /* determine the size of a pointer */
6092 ef_mips_32bitmode
= (tdep
->elf_flags
& EF_MIPS_32BITMODE
);
6093 fprintf_unfiltered (file
,
6094 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6096 fprintf_unfiltered (file
,
6097 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6099 fprintf_unfiltered (file
,
6100 "mips_dump_tdep: ef_mips_arch = %d\n",
6102 fprintf_unfiltered (file
,
6103 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6105 mips_abi_strings
[tdep
->mips_abi
]);
6106 fprintf_unfiltered (file
,
6107 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6108 mips_mask_address_p (),
6109 tdep
->default_mask_address_p
);
6111 fprintf_unfiltered (file
,
6112 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6113 FP_REGISTER_DOUBLE
);
6114 fprintf_unfiltered (file
,
6115 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6116 MIPS_DEFAULT_FPU_TYPE
,
6117 (MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_NONE
? "none"
6118 : MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_SINGLE
? "single"
6119 : MIPS_DEFAULT_FPU_TYPE
== MIPS_FPU_DOUBLE
? "double"
6121 fprintf_unfiltered (file
,
6122 "mips_dump_tdep: MIPS_EABI = %d\n",
6124 fprintf_unfiltered (file
,
6125 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6127 (MIPS_FPU_TYPE
== MIPS_FPU_NONE
? "none"
6128 : MIPS_FPU_TYPE
== MIPS_FPU_SINGLE
? "single"
6129 : MIPS_FPU_TYPE
== MIPS_FPU_DOUBLE
? "double"
6131 fprintf_unfiltered (file
,
6132 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6133 MIPS_DEFAULT_SAVED_REGSIZE
);
6134 fprintf_unfiltered (file
,
6135 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6136 FP_REGISTER_DOUBLE
);
6137 fprintf_unfiltered (file
,
6138 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6139 MIPS_DEFAULT_STACK_ARGSIZE
);
6140 fprintf_unfiltered (file
,
6141 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6142 MIPS_STACK_ARGSIZE
);
6143 fprintf_unfiltered (file
,
6144 "mips_dump_tdep: A0_REGNUM = %d\n",
6146 fprintf_unfiltered (file
,
6147 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6148 XSTRING (ADDR_BITS_REMOVE(ADDR
)));
6149 fprintf_unfiltered (file
,
6150 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6151 XSTRING (ATTACH_DETACH
));
6152 fprintf_unfiltered (file
,
6153 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6154 XSTRING (DWARF_REG_TO_REGNUM (REGNUM
)));
6155 fprintf_unfiltered (file
,
6156 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6157 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM
)));
6158 fprintf_unfiltered (file
,
6159 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6160 FIRST_EMBED_REGNUM
);
6161 fprintf_unfiltered (file
,
6162 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6163 XSTRING (IGNORE_HELPER_CALL (PC
)));
6164 fprintf_unfiltered (file
,
6165 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6166 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC
, NAME
)));
6167 fprintf_unfiltered (file
,
6168 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6169 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC
, NAME
)));
6170 fprintf_unfiltered (file
,
6171 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6173 #ifdef MACHINE_CPROC_FP_OFFSET
6174 fprintf_unfiltered (file
,
6175 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6176 MACHINE_CPROC_FP_OFFSET
);
6178 #ifdef MACHINE_CPROC_PC_OFFSET
6179 fprintf_unfiltered (file
,
6180 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6181 MACHINE_CPROC_PC_OFFSET
);
6183 #ifdef MACHINE_CPROC_SP_OFFSET
6184 fprintf_unfiltered (file
,
6185 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6186 MACHINE_CPROC_SP_OFFSET
);
6188 fprintf_unfiltered (file
,
6189 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6191 fprintf_unfiltered (file
,
6192 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6193 fprintf_unfiltered (file
,
6194 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6195 fprintf_unfiltered (file
,
6196 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6198 fprintf_unfiltered (file
,
6199 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6200 MIPS_LAST_ARG_REGNUM
,
6201 MIPS_LAST_ARG_REGNUM
- A0_REGNUM
+ 1);
6202 fprintf_unfiltered (file
,
6203 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6205 fprintf_unfiltered (file
,
6206 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6207 MIPS_SAVED_REGSIZE
);
6208 fprintf_unfiltered (file
,
6209 "mips_dump_tdep: PRID_REGNUM = %d\n",
6211 fprintf_unfiltered (file
,
6212 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6213 fprintf_unfiltered (file
,
6214 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6215 fprintf_unfiltered (file
,
6216 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6217 fprintf_unfiltered (file
,
6218 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6219 fprintf_unfiltered (file
,
6220 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6221 fprintf_unfiltered (file
,
6222 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6223 fprintf_unfiltered (file
,
6224 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6225 fprintf_unfiltered (file
,
6226 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6227 fprintf_unfiltered (file
,
6228 "mips_dump_tdep: PROC_PC_REG = function?\n");
6229 fprintf_unfiltered (file
,
6230 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6231 fprintf_unfiltered (file
,
6232 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6233 fprintf_unfiltered (file
,
6234 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6235 fprintf_unfiltered (file
,
6236 "mips_dump_tdep: PS_REGNUM = %d\n",
6238 fprintf_unfiltered (file
,
6239 "mips_dump_tdep: RA_REGNUM = %d\n",
6242 fprintf_unfiltered (file
,
6243 "mips_dump_tdep: SAVED_BYTES = %d\n",
6247 fprintf_unfiltered (file
,
6248 "mips_dump_tdep: SAVED_FP = %d\n",
6252 fprintf_unfiltered (file
,
6253 "mips_dump_tdep: SAVED_PC = %d\n",
6256 fprintf_unfiltered (file
,
6257 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6258 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS
, ARGS
)));
6259 fprintf_unfiltered (file
,
6260 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6261 fprintf_unfiltered (file
,
6262 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6264 fprintf_unfiltered (file
,
6265 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6266 SIGFRAME_FPREGSAVE_OFF
);
6267 fprintf_unfiltered (file
,
6268 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6270 fprintf_unfiltered (file
,
6271 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6272 SIGFRAME_REGSAVE_OFF
);
6273 fprintf_unfiltered (file
,
6274 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6276 fprintf_unfiltered (file
,
6277 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6278 XSTRING (SKIP_TRAMPOLINE_CODE (PC
)));
6279 fprintf_unfiltered (file
,
6280 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6281 XSTRING (SOFTWARE_SINGLE_STEP (SIG
, BP_P
)));
6282 fprintf_unfiltered (file
,
6283 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6284 SOFTWARE_SINGLE_STEP_P ());
6285 fprintf_unfiltered (file
,
6286 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6287 XSTRING (STAB_REG_TO_REGNUM (REGNUM
)));
6288 #ifdef STACK_END_ADDR
6289 fprintf_unfiltered (file
,
6290 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6293 fprintf_unfiltered (file
,
6294 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6295 XSTRING (STEP_SKIPS_DELAY (PC
)));
6296 fprintf_unfiltered (file
,
6297 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6298 STEP_SKIPS_DELAY_P
);
6299 fprintf_unfiltered (file
,
6300 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6301 XSTRING (STOPPED_BY_WATCHPOINT (WS
)));
6302 fprintf_unfiltered (file
,
6303 "mips_dump_tdep: T9_REGNUM = %d\n",
6305 fprintf_unfiltered (file
,
6306 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6307 fprintf_unfiltered (file
,
6308 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6309 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE
,CNT
,OTHERTYPE
)));
6310 fprintf_unfiltered (file
,
6311 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6312 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS
));
6314 fprintf_unfiltered (file
,
6315 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6316 XSTRING (TRACE_CLEAR (THREAD
, STATE
)));
6319 fprintf_unfiltered (file
,
6320 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6323 #ifdef TRACE_FLAVOR_SIZE
6324 fprintf_unfiltered (file
,
6325 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6329 fprintf_unfiltered (file
,
6330 "mips_dump_tdep: TRACE_SET # %s\n",
6331 XSTRING (TRACE_SET (X
,STATE
)));
6333 #ifdef UNUSED_REGNUM
6334 fprintf_unfiltered (file
,
6335 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6338 fprintf_unfiltered (file
,
6339 "mips_dump_tdep: V0_REGNUM = %d\n",
6341 fprintf_unfiltered (file
,
6342 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6343 (long) VM_MIN_ADDRESS
);
6344 fprintf_unfiltered (file
,
6345 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6347 fprintf_unfiltered (file
,
6348 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6352 extern initialize_file_ftype _initialize_mips_tdep
; /* -Wmissing-prototypes */
6355 _initialize_mips_tdep (void)
6357 static struct cmd_list_element
*mipsfpulist
= NULL
;
6358 struct cmd_list_element
*c
;
6360 mips_abi_string
= mips_abi_strings
[MIPS_ABI_UNKNOWN
];
6361 if (MIPS_ABI_LAST
+ 1
6362 != sizeof (mips_abi_strings
) / sizeof (mips_abi_strings
[0]))
6363 internal_error (__FILE__
, __LINE__
, "mips_abi_strings out of sync");
6365 gdbarch_register (bfd_arch_mips
, mips_gdbarch_init
, mips_dump_tdep
);
6367 /* Add root prefix command for all "set mips"/"show mips" commands */
6368 add_prefix_cmd ("mips", no_class
, set_mips_command
,
6369 "Various MIPS specific commands.",
6370 &setmipscmdlist
, "set mips ", 0, &setlist
);
6372 add_prefix_cmd ("mips", no_class
, show_mips_command
,
6373 "Various MIPS specific commands.",
6374 &showmipscmdlist
, "show mips ", 0, &showlist
);
6376 /* Allow the user to override the saved register size. */
6377 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6380 &mips_saved_regsize_string
, "\
6381 Set size of general purpose registers saved on the stack.\n\
6382 This option can be set to one of:\n\
6383 32 - Force GDB to treat saved GP registers as 32-bit\n\
6384 64 - Force GDB to treat saved GP registers as 64-bit\n\
6385 auto - Allow GDB to use the target's default setting or autodetect the\n\
6386 saved GP register size from information contained in the executable.\n\
6391 /* Allow the user to override the argument stack size. */
6392 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6395 &mips_stack_argsize_string
, "\
6396 Set the amount of stack space reserved for each argument.\n\
6397 This option can be set to one of:\n\
6398 32 - Force GDB to allocate 32-bit chunks per argument\n\
6399 64 - Force GDB to allocate 64-bit chunks per argument\n\
6400 auto - Allow GDB to determine the correct setting from the current\n\
6401 target and executable (default)",
6405 /* Allow the user to override the ABI. */
6406 c
= add_set_enum_cmd
6407 ("abi", class_obscure
, mips_abi_strings
, &mips_abi_string
,
6408 "Set the ABI used by this program.\n"
6409 "This option can be set to one of:\n"
6410 " auto - the default ABI associated with the current binary\n"
6418 set_cmd_sfunc (c
, mips_abi_update
);
6419 add_cmd ("abi", class_obscure
, show_mips_abi
,
6420 "Show ABI in use by MIPS target", &showmipscmdlist
);
6422 /* Let the user turn off floating point and set the fence post for
6423 heuristic_proc_start. */
6425 add_prefix_cmd ("mipsfpu", class_support
, set_mipsfpu_command
,
6426 "Set use of MIPS floating-point coprocessor.",
6427 &mipsfpulist
, "set mipsfpu ", 0, &setlist
);
6428 add_cmd ("single", class_support
, set_mipsfpu_single_command
,
6429 "Select single-precision MIPS floating-point coprocessor.",
6431 add_cmd ("double", class_support
, set_mipsfpu_double_command
,
6432 "Select double-precision MIPS floating-point coprocessor.",
6434 add_alias_cmd ("on", "double", class_support
, 1, &mipsfpulist
);
6435 add_alias_cmd ("yes", "double", class_support
, 1, &mipsfpulist
);
6436 add_alias_cmd ("1", "double", class_support
, 1, &mipsfpulist
);
6437 add_cmd ("none", class_support
, set_mipsfpu_none_command
,
6438 "Select no MIPS floating-point coprocessor.",
6440 add_alias_cmd ("off", "none", class_support
, 1, &mipsfpulist
);
6441 add_alias_cmd ("no", "none", class_support
, 1, &mipsfpulist
);
6442 add_alias_cmd ("0", "none", class_support
, 1, &mipsfpulist
);
6443 add_cmd ("auto", class_support
, set_mipsfpu_auto_command
,
6444 "Select MIPS floating-point coprocessor automatically.",
6446 add_cmd ("mipsfpu", class_support
, show_mipsfpu_command
,
6447 "Show current use of MIPS floating-point coprocessor target.",
6450 /* We really would like to have both "0" and "unlimited" work, but
6451 command.c doesn't deal with that. So make it a var_zinteger
6452 because the user can always use "999999" or some such for unlimited. */
6453 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
6454 (char *) &heuristic_fence_post
,
6456 Set the distance searched for the start of a function.\n\
6457 If you are debugging a stripped executable, GDB needs to search through the\n\
6458 program for the start of a function. This command sets the distance of the\n\
6459 search. The only need to set it is when debugging a stripped executable.",
6461 /* We need to throw away the frame cache when we set this, since it
6462 might change our ability to get backtraces. */
6463 set_cmd_sfunc (c
, reinit_frame_cache_sfunc
);
6464 add_show_from_set (c
, &showlist
);
6466 /* Allow the user to control whether the upper bits of 64-bit
6467 addresses should be zeroed. */
6468 add_setshow_auto_boolean_cmd ("mask-address", no_class
, &mask_address_var
, "\
6469 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6470 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6471 allow GDB to determine the correct value.\n", "\
6472 Show zeroing of upper 32 bits of 64-bit addresses.",
6473 NULL
, show_mask_address
,
6474 &setmipscmdlist
, &showmipscmdlist
);
6476 /* Allow the user to control the size of 32 bit registers within the
6477 raw remote packet. */
6478 add_setshow_cmd ("remote-mips64-transfers-32bit-regs", class_obscure
,
6479 var_boolean
, &mips64_transfers_32bit_regs_p
, "\
6480 Set compatibility with 64-bit MIPS targets that transfer 32-bit quantities.\n\
6481 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6482 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6483 64 bits for others. Use \"off\" to disable compatibility mode", "\
6484 Show compatibility with 64-bit MIPS targets that transfer 32-bit quantities.\n\
6485 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6486 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6487 64 bits for others. Use \"off\" to disable compatibility mode",
6488 set_mips64_transfers_32bit_regs
, NULL
,
6489 &setlist
, &showlist
);
6491 /* Debug this files internals. */
6492 add_show_from_set (add_set_cmd ("mips", class_maintenance
, var_zinteger
,
6493 &mips_debug
, "Set mips debugging.\n\
6494 When non-zero, mips specific debugging is enabled.", &setdebuglist
),