1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
39 #include "arch-utils.h"
42 #include "mips-tdep.h"
44 #include "opcode/mips.h"
49 /* A useful bit in the CP0 status register (PS_REGNUM). */
50 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
51 #define ST0_FR (1 << 26)
53 /* The sizes of floating point registers. */
57 MIPS_FPU_SINGLE_REGSIZE = 4,
58 MIPS_FPU_DOUBLE_REGSIZE = 8
62 static const char *mips_abi_string;
64 static const char *mips_abi_strings[] = {
75 struct frame_extra_info
77 mips_extra_func_info_t proc_desc;
81 /* Various MIPS ISA options (related to stack analysis) can be
82 overridden dynamically. Establish an enum/array for managing
85 static const char size_auto[] = "auto";
86 static const char size_32[] = "32";
87 static const char size_64[] = "64";
89 static const char *size_enums[] = {
96 /* Some MIPS boards don't support floating point while others only
97 support single-precision floating-point operations. See also
98 FP_REGISTER_DOUBLE. */
102 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
103 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
104 MIPS_FPU_NONE /* No floating point. */
107 #ifndef MIPS_DEFAULT_FPU_TYPE
108 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
110 static int mips_fpu_type_auto = 1;
111 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
113 static int mips_debug = 0;
115 /* MIPS specific per-architecture information */
118 /* from the elf header */
122 enum mips_abi mips_abi;
123 enum mips_abi found_abi;
124 enum mips_fpu_type mips_fpu_type;
125 int mips_last_arg_regnum;
126 int mips_last_fp_arg_regnum;
127 int mips_default_saved_regsize;
128 int mips_fp_register_double;
129 int mips_default_stack_argsize;
130 int gdb_target_is_mips64;
131 int default_mask_address_p;
134 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
135 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
137 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
139 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
141 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
143 /* Return the currently configured (or set) saved register size. */
145 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
147 static const char *mips_saved_regsize_string = size_auto;
149 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
151 /* Return the MIPS ABI associated with GDBARCH. */
153 mips_abi (struct gdbarch *gdbarch)
155 return gdbarch_tdep (gdbarch)->mips_abi;
159 mips_saved_regsize (void)
161 if (mips_saved_regsize_string == size_auto)
162 return MIPS_DEFAULT_SAVED_REGSIZE;
163 else if (mips_saved_regsize_string == size_64)
165 else /* if (mips_saved_regsize_string == size_32) */
169 /* Functions for setting and testing a bit in a minimal symbol that
170 marks it as 16-bit function. The MSB of the minimal symbol's
171 "info" field is used for this purpose. This field is already
172 being used to store the symbol size, so the assumption is
173 that the symbol size cannot exceed 2^31.
175 ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
176 i.e. refers to a 16-bit function, and sets a "special" bit in a
177 minimal symbol to mark it as a 16-bit function
179 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
180 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
181 the "info" field with the "special" bit masked out */
184 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
186 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16)
188 MSYMBOL_INFO (msym) = (char *)
189 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
190 SYMBOL_VALUE_ADDRESS (msym) |= 1;
195 msymbol_is_special (struct minimal_symbol *msym)
197 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
201 msymbol_size (struct minimal_symbol *msym)
203 return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
206 /* XFER a value from the big/little/left end of the register.
207 Depending on the size of the value it might occupy the entire
208 register or just part of it. Make an allowance for this, aligning
209 things accordingly. */
212 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
213 enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
216 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
218 /* Need to transfer the left or right part of the register, based on
219 the targets byte order. */
223 reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
225 case BFD_ENDIAN_LITTLE:
228 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
232 internal_error (__FILE__, __LINE__, "bad switch");
235 fprintf_unfiltered (gdb_stderr,
236 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
237 reg_num, reg_offset, buf_offset, length);
238 if (mips_debug && out != NULL)
241 fprintf_unfiltered (gdb_stdlog, "out ");
242 for (i = 0; i < length; i++)
243 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
246 regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
248 regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
249 if (mips_debug && in != NULL)
252 fprintf_unfiltered (gdb_stdlog, "in ");
253 for (i = 0; i < length; i++)
254 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
257 fprintf_unfiltered (gdb_stdlog, "\n");
260 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
261 compatiblity mode. A return value of 1 means that we have
262 physical 64-bit registers, but should treat them as 32-bit registers. */
265 mips2_fp_compat (void)
267 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
269 if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
273 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
274 in all the places we deal with FP registers. PR gdb/413. */
275 /* Otherwise check the FR bit in the status register - it controls
276 the FP compatiblity mode. If it is clear we are in compatibility
278 if ((read_register (PS_REGNUM) & ST0_FR) == 0)
285 /* Indicate that the ABI makes use of double-precision registers
286 provided by the FPU (rather than combining pairs of registers to
287 form double-precision values). Do not use "TARGET_IS_MIPS64" to
288 determine if the ABI is using double-precision registers. See also
290 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
292 /* The amount of space reserved on the stack for registers. This is
293 different to MIPS_SAVED_REGSIZE as it determines the alignment of
294 data allocated after the registers have run out. */
296 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
298 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
300 static const char *mips_stack_argsize_string = size_auto;
303 mips_stack_argsize (void)
305 if (mips_stack_argsize_string == size_auto)
306 return MIPS_DEFAULT_STACK_ARGSIZE;
307 else if (mips_stack_argsize_string == size_64)
309 else /* if (mips_stack_argsize_string == size_32) */
313 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
315 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
317 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
319 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
321 static void mips_print_register (int, int);
323 static mips_extra_func_info_t
324 heuristic_proc_desc (CORE_ADDR, CORE_ADDR, struct frame_info *, int);
326 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
328 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
330 static int mips_set_processor_type (char *);
332 static void mips_show_processor_type_command (char *, int);
334 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
336 static mips_extra_func_info_t
337 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame);
339 static CORE_ADDR after_prologue (CORE_ADDR pc,
340 mips_extra_func_info_t proc_desc);
342 static void mips_read_fp_register_single (int regno, char *rare_buffer);
343 static void mips_read_fp_register_double (int regno, char *rare_buffer);
345 static struct type *mips_float_register_type (void);
346 static struct type *mips_double_register_type (void);
348 /* This value is the model of MIPS in use. It is derived from the value
349 of the PrID register. */
351 char *mips_processor_type;
353 char *tmp_mips_processor_type;
355 /* The list of available "set mips " and "show mips " commands */
357 static struct cmd_list_element *setmipscmdlist = NULL;
358 static struct cmd_list_element *showmipscmdlist = NULL;
360 /* A set of original names, to be used when restoring back to generic
361 registers from a specific set. */
363 char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
364 char **mips_processor_reg_names = mips_generic_reg_names;
367 mips_register_name (int i)
369 return mips_processor_reg_names[i];
372 /* Names of IDT R3041 registers. */
374 char *mips_r3041_reg_names[] = {
375 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
376 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
377 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
378 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
379 "sr", "lo", "hi", "bad", "cause","pc",
380 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
381 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
382 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
383 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
384 "fsr", "fir", "",/*"fp"*/ "",
385 "", "", "bus", "ccfg", "", "", "", "",
386 "", "", "port", "cmp", "", "", "epc", "prid",
389 /* Names of IDT R3051 registers. */
391 char *mips_r3051_reg_names[] = {
392 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
393 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
394 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
395 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
396 "sr", "lo", "hi", "bad", "cause","pc",
397 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
398 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
399 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
400 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
401 "fsr", "fir", ""/*"fp"*/, "",
402 "inx", "rand", "elo", "", "ctxt", "", "", "",
403 "", "", "ehi", "", "", "", "epc", "prid",
406 /* Names of IDT R3081 registers. */
408 char *mips_r3081_reg_names[] = {
409 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
410 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
411 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
412 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
413 "sr", "lo", "hi", "bad", "cause","pc",
414 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
415 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
416 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
417 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
418 "fsr", "fir", ""/*"fp"*/, "",
419 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
420 "", "", "ehi", "", "", "", "epc", "prid",
423 /* Names of LSI 33k registers. */
425 char *mips_lsi33k_reg_names[] = {
426 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
427 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
428 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
429 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
430 "epc", "hi", "lo", "sr", "cause","badvaddr",
431 "dcic", "bpc", "bda", "", "", "", "", "",
432 "", "", "", "", "", "", "", "",
433 "", "", "", "", "", "", "", "",
434 "", "", "", "", "", "", "", "",
436 "", "", "", "", "", "", "", "",
437 "", "", "", "", "", "", "", "",
443 } mips_processor_type_table[] = {
444 { "generic", mips_generic_reg_names },
445 { "r3041", mips_r3041_reg_names },
446 { "r3051", mips_r3051_reg_names },
447 { "r3071", mips_r3081_reg_names },
448 { "r3081", mips_r3081_reg_names },
449 { "lsi33k", mips_lsi33k_reg_names },
457 /* Table to translate MIPS16 register field to actual register number. */
458 static int mips16_to_32_reg[8] =
459 {16, 17, 2, 3, 4, 5, 6, 7};
461 /* Heuristic_proc_start may hunt through the text section for a long
462 time across a 2400 baud serial line. Allows the user to limit this
465 static unsigned int heuristic_fence_post = 0;
467 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
468 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
469 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
470 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
471 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
472 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
473 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
474 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
475 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
476 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
477 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
478 this will corrupt pdr.iline. Fortunately we don't use it. */
479 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
480 #define _PROC_MAGIC_ 0x0F0F0F0F
481 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
482 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
484 struct linked_proc_info
486 struct mips_extra_func_info info;
487 struct linked_proc_info *next;
489 *linked_proc_desc_table = NULL;
492 mips_print_extra_frame_info (struct frame_info *fi)
495 && get_frame_extra_info (fi)
496 && get_frame_extra_info (fi)->proc_desc
497 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
498 printf_filtered (" frame pointer is at %s+%s\n",
499 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
500 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
503 /* Number of bytes of storage in the actual machine representation for
504 register N. NOTE: This indirectly defines the register size
505 transfered by the GDB protocol. */
507 static int mips64_transfers_32bit_regs_p = 0;
510 mips_register_raw_size (int reg_nr)
512 if (mips64_transfers_32bit_regs_p)
513 return REGISTER_VIRTUAL_SIZE (reg_nr);
514 else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
515 && FP_REGISTER_DOUBLE)
516 /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
523 /* Convert between RAW and VIRTUAL registers. The RAW register size
524 defines the remote-gdb packet. */
527 mips_register_convertible (int reg_nr)
529 if (mips64_transfers_32bit_regs_p)
532 return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
536 mips_register_convert_to_virtual (int n, struct type *virtual_type,
537 char *raw_buf, char *virt_buf)
539 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
541 raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
542 TYPE_LENGTH (virtual_type));
546 TYPE_LENGTH (virtual_type));
550 mips_register_convert_to_raw (struct type *virtual_type, int n,
551 char *virt_buf, char *raw_buf)
553 memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
554 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
555 memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
557 TYPE_LENGTH (virtual_type));
561 TYPE_LENGTH (virtual_type));
565 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
567 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
568 && REGISTER_RAW_SIZE (regnum) == 4
569 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
570 && TYPE_CODE(type) == TYPE_CODE_FLT
571 && TYPE_LENGTH(type) == 8)
574 memcpy (temp, ((char *)(buffer))+4, 4);
575 memcpy (((char *)(buffer))+4, (buffer), 4);
576 memcpy (((char *)(buffer)), temp, 4);
581 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
583 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
584 && REGISTER_RAW_SIZE (regnum) == 4
585 && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
586 && TYPE_CODE(type) == TYPE_CODE_FLT
587 && TYPE_LENGTH(type) == 8)
590 memcpy (temp, ((char *)(buffer))+4, 4);
591 memcpy (((char *)(buffer))+4, (buffer), 4);
592 memcpy (((char *)(buffer)), temp, 4);
596 /* Return the GDB type object for the "standard" data type
597 of data in register REG.
599 Note: kevinb/2002-08-01: The definition below should faithfully
600 reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
601 definitions found in config/mips/tm-*.h. I'm concerned about
602 the ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause
603 though. In some cases FP_REGNUM is in this range, and I doubt
604 that this code is correct for the 64-bit case. */
607 mips_register_virtual_type (int reg)
609 if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
611 /* Floating point registers... */
612 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
613 return builtin_type_ieee_double_big;
615 return builtin_type_ieee_double_little;
617 else if (reg == PS_REGNUM /* CR */)
618 return builtin_type_uint32;
619 else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
620 return builtin_type_uint32;
623 /* Everything else...
624 Return type appropriate for width of register. */
625 if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
626 return builtin_type_uint64;
628 return builtin_type_uint32;
632 /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */
637 return ADDR_BITS_REMOVE (read_register (SP_REGNUM));
640 /* Should the upper word of 64-bit addresses be zeroed? */
641 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
644 mips_mask_address_p (void)
646 switch (mask_address_var)
648 case AUTO_BOOLEAN_TRUE:
650 case AUTO_BOOLEAN_FALSE:
653 case AUTO_BOOLEAN_AUTO:
654 return MIPS_DEFAULT_MASK_ADDRESS_P;
656 internal_error (__FILE__, __LINE__,
657 "mips_mask_address_p: bad switch");
663 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
665 switch (mask_address_var)
667 case AUTO_BOOLEAN_TRUE:
668 printf_filtered ("The 32 bit mips address mask is enabled\n");
670 case AUTO_BOOLEAN_FALSE:
671 printf_filtered ("The 32 bit mips address mask is disabled\n");
673 case AUTO_BOOLEAN_AUTO:
674 printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n",
675 mips_mask_address_p () ? "enabled" : "disabled");
678 internal_error (__FILE__, __LINE__,
679 "show_mask_address: bad switch");
684 /* Should call_function allocate stack space for a struct return? */
687 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
689 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
693 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
695 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
699 mips_o32_use_struct_convention (int gcc_p, struct type *type)
701 return 1; /* Structures are returned by ref in extra arg0. */
704 /* Should call_function pass struct by reference?
705 For each architecture, structs are passed either by
706 value or by reference, depending on their size. */
709 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
711 enum type_code typecode = TYPE_CODE (check_typedef (type));
712 int len = TYPE_LENGTH (check_typedef (type));
714 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
715 return (len > MIPS_SAVED_REGSIZE);
721 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
723 return 0; /* Assumption: N32/N64 never passes struct by ref. */
727 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
729 return 0; /* Assumption: O32/O64 never passes struct by ref. */
732 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
735 pc_is_mips16 (bfd_vma memaddr)
737 struct minimal_symbol *sym;
739 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
740 if (IS_MIPS16_ADDR (memaddr))
743 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
744 the high bit of the info field. Use this to decide if the function is
745 MIPS16 or normal MIPS. */
746 sym = lookup_minimal_symbol_by_pc (memaddr);
748 return msymbol_is_special (sym);
753 /* MIPS believes that the PC has a sign extended value. Perhaphs the
754 all registers should be sign extended for simplicity? */
757 mips_read_pc (ptid_t ptid)
759 return read_signed_register_pid (PC_REGNUM, ptid);
762 /* This returns the PC of the first inst after the prologue. If we can't
763 find the prologue, then return 0. */
766 after_prologue (CORE_ADDR pc,
767 mips_extra_func_info_t proc_desc)
769 struct symtab_and_line sal;
770 CORE_ADDR func_addr, func_end;
772 /* Pass cur_frame == 0 to find_proc_desc. We should not attempt
773 to read the stack pointer from the current machine state, because
774 the current machine state has nothing to do with the information
775 we need from the proc_desc; and the process may or may not exist
778 proc_desc = find_proc_desc (pc, NULL, 0);
782 /* If function is frameless, then we need to do it the hard way. I
783 strongly suspect that frameless always means prologueless... */
784 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
785 && PROC_FRAME_OFFSET (proc_desc) == 0)
789 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
790 return 0; /* Unknown */
792 sal = find_pc_line (func_addr, 0);
794 if (sal.end < func_end)
797 /* The line after the prologue is after the end of the function. In this
798 case, tell the caller to find the prologue the hard way. */
803 /* Decode a MIPS32 instruction that saves a register in the stack, and
804 set the appropriate bit in the general register mask or float register mask
805 to indicate which register is saved. This is a helper function
806 for mips_find_saved_regs. */
809 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
810 unsigned long *float_mask)
814 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
815 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
816 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
818 /* It might be possible to use the instruction to
819 find the offset, rather than the code below which
820 is based on things being in a certain order in the
821 frame, but figuring out what the instruction's offset
822 is relative to might be a little tricky. */
823 reg = (inst & 0x001f0000) >> 16;
824 *gen_mask |= (1 << reg);
826 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
827 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
828 || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */
831 reg = ((inst & 0x001f0000) >> 16);
832 *float_mask |= (1 << reg);
836 /* Decode a MIPS16 instruction that saves a register in the stack, and
837 set the appropriate bit in the general register or float register mask
838 to indicate which register is saved. This is a helper function
839 for mips_find_saved_regs. */
842 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
844 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
846 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
847 *gen_mask |= (1 << reg);
849 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
851 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
852 *gen_mask |= (1 << reg);
854 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
855 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
856 *gen_mask |= (1 << RA_REGNUM);
860 /* Fetch and return instruction from the specified location. If the PC
861 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
864 mips_fetch_instruction (CORE_ADDR addr)
866 char buf[MIPS_INSTLEN];
870 if (pc_is_mips16 (addr))
872 instlen = MIPS16_INSTLEN;
873 addr = UNMAKE_MIPS16_ADDR (addr);
876 instlen = MIPS_INSTLEN;
877 status = read_memory_nobpt (addr, buf, instlen);
879 memory_error (status, addr);
880 return extract_unsigned_integer (buf, instlen);
884 /* These the fields of 32 bit mips instructions */
885 #define mips32_op(x) (x >> 26)
886 #define itype_op(x) (x >> 26)
887 #define itype_rs(x) ((x >> 21) & 0x1f)
888 #define itype_rt(x) ((x >> 16) & 0x1f)
889 #define itype_immediate(x) (x & 0xffff)
891 #define jtype_op(x) (x >> 26)
892 #define jtype_target(x) (x & 0x03ffffff)
894 #define rtype_op(x) (x >> 26)
895 #define rtype_rs(x) ((x >> 21) & 0x1f)
896 #define rtype_rt(x) ((x >> 16) & 0x1f)
897 #define rtype_rd(x) ((x >> 11) & 0x1f)
898 #define rtype_shamt(x) ((x >> 6) & 0x1f)
899 #define rtype_funct(x) (x & 0x3f)
902 mips32_relative_offset (unsigned long inst)
905 x = itype_immediate (inst);
906 if (x & 0x8000) /* sign bit set */
908 x |= 0xffff0000; /* sign extension */
914 /* Determine whate to set a single step breakpoint while considering
917 mips32_next_pc (CORE_ADDR pc)
921 inst = mips_fetch_instruction (pc);
922 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
924 if (itype_op (inst) >> 2 == 5)
925 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
927 op = (itype_op (inst) & 0x03);
942 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
943 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
945 int tf = itype_rt (inst) & 0x01;
946 int cnum = itype_rt (inst) >> 2;
947 int fcrcs = read_signed_register (FCRCS_REGNUM);
948 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
950 if (((cond >> cnum) & 0x01) == tf)
951 pc += mips32_relative_offset (inst) + 4;
956 pc += 4; /* Not a branch, next instruction is easy */
959 { /* This gets way messy */
961 /* Further subdivide into SPECIAL, REGIMM and other */
962 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
964 case 0: /* SPECIAL */
965 op = rtype_funct (inst);
970 /* Set PC to that address */
971 pc = read_signed_register (rtype_rs (inst));
977 break; /* end SPECIAL */
980 op = itype_rt (inst); /* branch condition */
985 case 16: /* BLTZAL */
986 case 18: /* BLTZALL */
988 if (read_signed_register (itype_rs (inst)) < 0)
989 pc += mips32_relative_offset (inst) + 4;
991 pc += 8; /* after the delay slot */
995 case 17: /* BGEZAL */
996 case 19: /* BGEZALL */
997 greater_equal_branch:
998 if (read_signed_register (itype_rs (inst)) >= 0)
999 pc += mips32_relative_offset (inst) + 4;
1001 pc += 8; /* after the delay slot */
1003 /* All of the other instructions in the REGIMM category */
1008 break; /* end REGIMM */
1013 reg = jtype_target (inst) << 2;
1014 /* Upper four bits get never changed... */
1015 pc = reg + ((pc + 4) & 0xf0000000);
1018 /* FIXME case JALX : */
1021 reg = jtype_target (inst) << 2;
1022 pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */
1023 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1025 break; /* The new PC will be alternate mode */
1026 case 4: /* BEQ, BEQL */
1028 if (read_signed_register (itype_rs (inst)) ==
1029 read_signed_register (itype_rt (inst)))
1030 pc += mips32_relative_offset (inst) + 4;
1034 case 5: /* BNE, BNEL */
1036 if (read_signed_register (itype_rs (inst)) !=
1037 read_signed_register (itype_rt (inst)))
1038 pc += mips32_relative_offset (inst) + 4;
1042 case 6: /* BLEZ, BLEZL */
1044 if (read_signed_register (itype_rs (inst) <= 0))
1045 pc += mips32_relative_offset (inst) + 4;
1051 greater_branch: /* BGTZ, BGTZL */
1052 if (read_signed_register (itype_rs (inst) > 0))
1053 pc += mips32_relative_offset (inst) + 4;
1060 } /* mips32_next_pc */
1062 /* Decoding the next place to set a breakpoint is irregular for the
1063 mips 16 variant, but fortunately, there fewer instructions. We have to cope
1064 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1065 We dont want to set a single step instruction on the extend instruction
1069 /* Lots of mips16 instruction formats */
1070 /* Predicting jumps requires itype,ritype,i8type
1071 and their extensions extItype,extritype,extI8type
1073 enum mips16_inst_fmts
1075 itype, /* 0 immediate 5,10 */
1076 ritype, /* 1 5,3,8 */
1077 rrtype, /* 2 5,3,3,5 */
1078 rritype, /* 3 5,3,3,5 */
1079 rrrtype, /* 4 5,3,3,3,2 */
1080 rriatype, /* 5 5,3,3,1,4 */
1081 shifttype, /* 6 5,3,3,3,2 */
1082 i8type, /* 7 5,3,8 */
1083 i8movtype, /* 8 5,3,3,5 */
1084 i8mov32rtype, /* 9 5,3,5,3 */
1085 i64type, /* 10 5,3,8 */
1086 ri64type, /* 11 5,3,3,5 */
1087 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1088 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1089 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1090 extRRItype, /* 15 5,5,5,5,3,3,5 */
1091 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1092 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1093 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1094 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1095 extRi64type, /* 20 5,6,5,5,3,3,5 */
1096 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1098 /* I am heaping all the fields of the formats into one structure and
1099 then, only the fields which are involved in instruction extension */
1103 unsigned int regx; /* Function in i8 type */
1108 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1109 for the bits which make up the immediatate extension. */
1112 extended_offset (unsigned int extension)
1115 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1117 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1119 value |= extension & 0x01f; /* extract 4:0 */
1123 /* Only call this function if you know that this is an extendable
1124 instruction, It wont malfunction, but why make excess remote memory references?
1125 If the immediate operands get sign extended or somthing, do it after
1126 the extension is performed.
1128 /* FIXME: Every one of these cases needs to worry about sign extension
1129 when the offset is to be used in relative addressing */
1133 fetch_mips_16 (CORE_ADDR pc)
1136 pc &= 0xfffffffe; /* clear the low order bit */
1137 target_read_memory (pc, buf, 2);
1138 return extract_unsigned_integer (buf, 2);
1142 unpack_mips16 (CORE_ADDR pc,
1143 unsigned int extension,
1145 enum mips16_inst_fmts insn_format,
1146 struct upk_mips16 *upk)
1151 switch (insn_format)
1158 value = extended_offset (extension);
1159 value = value << 11; /* rom for the original value */
1160 value |= inst & 0x7ff; /* eleven bits from instruction */
1164 value = inst & 0x7ff;
1165 /* FIXME : Consider sign extension */
1174 { /* A register identifier and an offset */
1175 /* Most of the fields are the same as I type but the
1176 immediate value is of a different length */
1180 value = extended_offset (extension);
1181 value = value << 8; /* from the original instruction */
1182 value |= inst & 0xff; /* eleven bits from instruction */
1183 regx = (extension >> 8) & 0x07; /* or i8 funct */
1184 if (value & 0x4000) /* test the sign bit , bit 26 */
1186 value &= ~0x3fff; /* remove the sign bit */
1192 value = inst & 0xff; /* 8 bits */
1193 regx = (inst >> 8) & 0x07; /* or i8 funct */
1194 /* FIXME: Do sign extension , this format needs it */
1195 if (value & 0x80) /* THIS CONFUSES ME */
1197 value &= 0xef; /* remove the sign bit */
1207 unsigned long value;
1208 unsigned int nexthalf;
1209 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1210 value = value << 16;
1211 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1219 internal_error (__FILE__, __LINE__,
1222 upk->offset = offset;
1229 add_offset_16 (CORE_ADDR pc, int offset)
1231 return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1235 extended_mips16_next_pc (CORE_ADDR pc,
1236 unsigned int extension,
1239 int op = (insn >> 11);
1242 case 2: /* Branch */
1245 struct upk_mips16 upk;
1246 unpack_mips16 (pc, extension, insn, itype, &upk);
1247 offset = upk.offset;
1253 pc += (offset << 1) + 2;
1256 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
1258 struct upk_mips16 upk;
1259 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1260 pc = add_offset_16 (pc, upk.offset);
1261 if ((insn >> 10) & 0x01) /* Exchange mode */
1262 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1269 struct upk_mips16 upk;
1271 unpack_mips16 (pc, extension, insn, ritype, &upk);
1272 reg = read_signed_register (upk.regx);
1274 pc += (upk.offset << 1) + 2;
1281 struct upk_mips16 upk;
1283 unpack_mips16 (pc, extension, insn, ritype, &upk);
1284 reg = read_signed_register (upk.regx);
1286 pc += (upk.offset << 1) + 2;
1291 case 12: /* I8 Formats btez btnez */
1293 struct upk_mips16 upk;
1295 unpack_mips16 (pc, extension, insn, i8type, &upk);
1296 /* upk.regx contains the opcode */
1297 reg = read_signed_register (24); /* Test register is 24 */
1298 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1299 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1300 /* pc = add_offset_16(pc,upk.offset) ; */
1301 pc += (upk.offset << 1) + 2;
1306 case 29: /* RR Formats JR, JALR, JALR-RA */
1308 struct upk_mips16 upk;
1309 /* upk.fmt = rrtype; */
1314 upk.regx = (insn >> 8) & 0x07;
1315 upk.regy = (insn >> 5) & 0x07;
1323 break; /* Function return instruction */
1329 break; /* BOGUS Guess */
1331 pc = read_signed_register (reg);
1338 /* This is an instruction extension. Fetch the real instruction
1339 (which follows the extension) and decode things based on
1343 pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1356 mips16_next_pc (CORE_ADDR pc)
1358 unsigned int insn = fetch_mips_16 (pc);
1359 return extended_mips16_next_pc (pc, 0, insn);
1362 /* The mips_next_pc function supports single_step when the remote
1363 target monitor or stub is not developed enough to do a single_step.
1364 It works by decoding the current instruction and predicting where a
1365 branch will go. This isnt hard because all the data is available.
1366 The MIPS32 and MIPS16 variants are quite different */
1368 mips_next_pc (CORE_ADDR pc)
1371 return mips16_next_pc (pc);
1373 return mips32_next_pc (pc);
1376 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
1379 Note: kevinb/2002-08-09: The only caller of this function is (and
1380 should remain) mips_frame_init_saved_regs(). In fact,
1381 aside from calling mips_find_saved_regs(), mips_frame_init_saved_regs()
1382 does nothing more than set frame->saved_regs[SP_REGNUM]. These two
1383 functions should really be combined and now that there is only one
1384 caller, it should be straightforward. (Watch out for multiple returns
1388 mips_find_saved_regs (struct frame_info *fci)
1391 CORE_ADDR reg_position;
1392 /* r0 bit means kernel trap */
1394 /* What registers have been saved? Bitmasks. */
1395 unsigned long gen_mask, float_mask;
1396 mips_extra_func_info_t proc_desc;
1399 frame_saved_regs_zalloc (fci);
1401 /* If it is the frame for sigtramp, the saved registers are located
1402 in a sigcontext structure somewhere on the stack.
1403 If the stack layout for sigtramp changes we might have to change these
1404 constants and the companion fixup_sigtramp in mdebugread.c */
1405 #ifndef SIGFRAME_BASE
1406 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1407 above the sigtramp frame. */
1408 #define SIGFRAME_BASE MIPS_REGSIZE
1409 /* FIXME! Are these correct?? */
1410 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1411 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1412 #define SIGFRAME_FPREGSAVE_OFF \
1413 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1415 #ifndef SIGFRAME_REG_SIZE
1416 /* FIXME! Is this correct?? */
1417 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
1419 if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1421 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1423 reg_position = get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1424 + ireg * SIGFRAME_REG_SIZE;
1425 get_frame_saved_regs (fci)[ireg] = reg_position;
1427 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1429 reg_position = get_frame_base (fci) + SIGFRAME_FPREGSAVE_OFF
1430 + ireg * SIGFRAME_REG_SIZE;
1431 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1433 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_base (fci) + SIGFRAME_PC_OFF;
1437 proc_desc = get_frame_extra_info (fci)->proc_desc;
1438 if (proc_desc == NULL)
1439 /* I'm not sure how/whether this can happen. Normally when we can't
1440 find a proc_desc, we "synthesize" one using heuristic_proc_desc
1441 and set the saved_regs right away. */
1444 kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1445 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1446 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1448 if ( /* In any frame other than the innermost or a frame interrupted by
1449 a signal, we assume that all registers have been saved.
1450 This assumes that all register saves in a function happen before
1451 the first function call. */
1452 (get_next_frame (fci) == NULL
1453 || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1455 /* In a dummy frame we know exactly where things are saved. */
1456 && !PROC_DESC_IS_DUMMY (proc_desc)
1458 /* Don't bother unless we are inside a function prologue. Outside the
1459 prologue, we know where everything is. */
1461 && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1463 /* Not sure exactly what kernel_trap means, but if it means
1464 the kernel saves the registers without a prologue doing it,
1465 we better not examine the prologue to see whether registers
1466 have been saved yet. */
1469 /* We need to figure out whether the registers that the proc_desc
1470 claims are saved have been saved yet. */
1474 /* Bitmasks; set if we have found a save for the register. */
1475 unsigned long gen_save_found = 0;
1476 unsigned long float_save_found = 0;
1479 /* If the address is odd, assume this is MIPS16 code. */
1480 addr = PROC_LOW_ADDR (proc_desc);
1481 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1483 /* Scan through this function's instructions preceding the current
1484 PC, and look for those that save registers. */
1485 while (addr < get_frame_pc (fci))
1487 inst = mips_fetch_instruction (addr);
1488 if (pc_is_mips16 (addr))
1489 mips16_decode_reg_save (inst, &gen_save_found);
1491 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1494 gen_mask = gen_save_found;
1495 float_mask = float_save_found;
1498 /* Fill in the offsets for the registers which gen_mask says
1500 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1501 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1502 if (gen_mask & 0x80000000)
1504 get_frame_saved_regs (fci)[ireg] = reg_position;
1505 reg_position -= MIPS_SAVED_REGSIZE;
1508 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
1509 of that normally used by gcc. Therefore, we have to fetch the first
1510 instruction of the function, and if it's an entry instruction that
1511 saves $s0 or $s1, correct their saved addresses. */
1512 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1514 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1515 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1518 int sreg_count = (inst >> 6) & 3;
1520 /* Check if the ra register was pushed on the stack. */
1521 reg_position = get_frame_base (fci) + PROC_REG_OFFSET (proc_desc);
1523 reg_position -= MIPS_SAVED_REGSIZE;
1525 /* Check if the s0 and s1 registers were pushed on the stack. */
1526 for (reg = 16; reg < sreg_count + 16; reg++)
1528 get_frame_saved_regs (fci)[reg] = reg_position;
1529 reg_position -= MIPS_SAVED_REGSIZE;
1534 /* Fill in the offsets for the registers which float_mask says
1536 reg_position = get_frame_base (fci) + PROC_FREG_OFFSET (proc_desc);
1538 /* Apparently, the freg_offset gives the offset to the first 64 bit
1541 When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1542 designates the first saved 64 bit register.
1544 When the ABI specifies 32 bit saved registers, the ``64 bit saved
1545 DOUBLE'' consists of two adjacent 32 bit registers, Hence
1546 FREG_OFFSET, designates the address of the lower register of the
1547 register pair. Adjust the offset so that it designates the upper
1548 register of the pair -- i.e., the address of the first saved 32
1551 if (MIPS_SAVED_REGSIZE == 4)
1552 reg_position += MIPS_SAVED_REGSIZE;
1554 /* Fill in the offsets for the float registers which float_mask says
1556 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1557 if (float_mask & 0x80000000)
1559 get_frame_saved_regs (fci)[FP0_REGNUM + ireg] = reg_position;
1560 reg_position -= MIPS_SAVED_REGSIZE;
1563 get_frame_saved_regs (fci)[PC_REGNUM] = get_frame_saved_regs (fci)[RA_REGNUM];
1566 /* Set up the 'saved_regs' array. This is a data structure containing
1567 the addresses on the stack where each register has been saved, for
1568 each stack frame. Registers that have not been saved will have
1569 zero here. The stack pointer register is special: rather than the
1570 address where the stack register has been saved, saved_regs[SP_REGNUM]
1571 will have the actual value of the previous frame's stack register. */
1574 mips_frame_init_saved_regs (struct frame_info *frame)
1576 if (get_frame_saved_regs (frame) == NULL)
1578 mips_find_saved_regs (frame);
1580 get_frame_saved_regs (frame)[SP_REGNUM] = get_frame_base (frame);
1584 read_next_frame_reg (struct frame_info *fi, int regno)
1589 enum lval_type lval;
1590 void *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
1591 frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1593 /* FIXME: cagney/2002-09-13: This is just soooo bad. The MIPS
1594 should have a pseudo register range that correspons to the ABI's,
1595 rather than the ISA's, view of registers. These registers would
1596 then implicitly describe their size and hence could be used
1597 without the below munging. */
1598 if (lval == lval_memory)
1602 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1604 return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1608 return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1611 /* mips_addr_bits_remove - remove useless address bits */
1614 mips_addr_bits_remove (CORE_ADDR addr)
1616 if (GDB_TARGET_IS_MIPS64)
1618 if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1620 /* This hack is a work-around for existing boards using
1621 PMON, the simulator, and any other 64-bit targets that
1622 doesn't have true 64-bit addressing. On these targets,
1623 the upper 32 bits of addresses are ignored by the
1624 hardware. Thus, the PC or SP are likely to have been
1625 sign extended to all 1s by instruction sequences that
1626 load 32-bit addresses. For example, a typical piece of
1627 code that loads an address is this:
1628 lui $r2, <upper 16 bits>
1629 ori $r2, <lower 16 bits>
1630 But the lui sign-extends the value such that the upper 32
1631 bits may be all 1s. The workaround is simply to mask off
1632 these bits. In the future, gcc may be changed to support
1633 true 64-bit addressing, and this masking will have to be
1635 addr &= (CORE_ADDR) 0xffffffff;
1638 else if (mips_mask_address_p ())
1640 /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be
1641 masking off bits, instead, the actual target should be asking
1642 for the address to be converted to a valid pointer. */
1643 /* Even when GDB is configured for some 32-bit targets
1644 (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1645 so CORE_ADDR is 64 bits. So we still have to mask off
1646 useless bits from addresses. */
1647 addr &= (CORE_ADDR) 0xffffffff;
1652 /* mips_software_single_step() is called just before we want to resume
1653 the inferior, if we want to single-step it but there is no hardware
1654 or kernel single-step support (MIPS on GNU/Linux for example). We find
1655 the target of the coming instruction and breakpoint it.
1657 single_step is also called just after the inferior stops. If we had
1658 set up a simulated single-step, we undo our damage. */
1661 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1663 static CORE_ADDR next_pc;
1664 typedef char binsn_quantum[BREAKPOINT_MAX];
1665 static binsn_quantum break_mem;
1668 if (insert_breakpoints_p)
1670 pc = read_register (PC_REGNUM);
1671 next_pc = mips_next_pc (pc);
1673 target_insert_breakpoint (next_pc, break_mem);
1676 target_remove_breakpoint (next_pc, break_mem);
1680 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1685 ? SAVED_PC_AFTER_CALL (get_next_frame (prev))
1686 : get_next_frame (prev)
1687 ? FRAME_SAVED_PC (get_next_frame (prev))
1689 tmp = SKIP_TRAMPOLINE_CODE (pc);
1690 return tmp ? tmp : pc;
1695 mips_frame_saved_pc (struct frame_info *frame)
1698 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1699 /* We have to get the saved pc from the sigcontext
1700 if it is a signal handler frame. */
1701 int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1702 : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1704 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1707 frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1710 else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1711 saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1713 saved_pc = read_next_frame_reg (frame, pcreg);
1715 return ADDR_BITS_REMOVE (saved_pc);
1718 static struct mips_extra_func_info temp_proc_desc;
1720 /* This hack will go away once the get_prev_frame() code has been
1721 modified to set the frame's type first. That is BEFORE init extra
1722 frame info et.al. is called. This is because it will become
1723 possible to skip the init extra info call for sigtramp and dummy
1725 static CORE_ADDR *temp_saved_regs;
1727 /* Set a register's saved stack address in temp_saved_regs. If an address
1728 has already been set for this register, do nothing; this way we will
1729 only recognize the first save of a given register in a function prologue.
1730 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1733 set_reg_offset (int regno, CORE_ADDR offset)
1735 if (temp_saved_regs[regno] == 0)
1736 temp_saved_regs[regno] = offset;
1740 /* Test whether the PC points to the return instruction at the
1741 end of a function. */
1744 mips_about_to_return (CORE_ADDR pc)
1746 if (pc_is_mips16 (pc))
1747 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1748 generates a "jr $ra"; other times it generates code to load
1749 the return address from the stack to an accessible register (such
1750 as $a3), then a "jr" using that register. This second case
1751 is almost impossible to distinguish from an indirect jump
1752 used for switch statements, so we don't even try. */
1753 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1755 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1759 /* This fencepost looks highly suspicious to me. Removing it also
1760 seems suspicious as it could affect remote debugging across serial
1764 heuristic_proc_start (CORE_ADDR pc)
1771 pc = ADDR_BITS_REMOVE (pc);
1773 fence = start_pc - heuristic_fence_post;
1777 if (heuristic_fence_post == UINT_MAX
1778 || fence < VM_MIN_ADDRESS)
1779 fence = VM_MIN_ADDRESS;
1781 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1783 /* search back for previous return */
1784 for (start_pc -= instlen;; start_pc -= instlen)
1785 if (start_pc < fence)
1787 /* It's not clear to me why we reach this point when
1788 stop_soon_quietly, but with this test, at least we
1789 don't print out warnings for every child forked (eg, on
1791 if (!stop_soon_quietly)
1793 static int blurb_printed = 0;
1795 warning ("Warning: GDB can't find the start of the function at 0x%s.",
1800 /* This actually happens frequently in embedded
1801 development, when you first connect to a board
1802 and your stack pointer and pc are nowhere in
1803 particular. This message needs to give people
1804 in that situation enough information to
1805 determine that it's no big deal. */
1806 printf_filtered ("\n\
1807 GDB is unable to find the start of the function at 0x%s\n\
1808 and thus can't determine the size of that function's stack frame.\n\
1809 This means that GDB may be unable to access that stack frame, or\n\
1810 the frames below it.\n\
1811 This problem is most likely caused by an invalid program counter or\n\
1813 However, if you think GDB should simply search farther back\n\
1814 from 0x%s for code which looks like the beginning of a\n\
1815 function, you can increase the range of the search using the `set\n\
1816 heuristic-fence-post' command.\n",
1817 paddr_nz (pc), paddr_nz (pc));
1824 else if (pc_is_mips16 (start_pc))
1826 unsigned short inst;
1828 /* On MIPS16, any one of the following is likely to be the
1829 start of a function:
1833 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1834 inst = mips_fetch_instruction (start_pc);
1835 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1836 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1837 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1838 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1840 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1841 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1846 else if (mips_about_to_return (start_pc))
1848 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1855 /* Fetch the immediate value from a MIPS16 instruction.
1856 If the previous instruction was an EXTEND, use it to extend
1857 the upper bits of the immediate value. This is a helper function
1858 for mips16_heuristic_proc_desc. */
1861 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1862 unsigned short inst, /* current instruction */
1863 int nbits, /* number of bits in imm field */
1864 int scale, /* scale factor to be applied to imm */
1865 int is_signed) /* is the imm field signed? */
1869 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1871 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1872 if (offset & 0x8000) /* check for negative extend */
1873 offset = 0 - (0x10000 - (offset & 0xffff));
1874 return offset | (inst & 0x1f);
1878 int max_imm = 1 << nbits;
1879 int mask = max_imm - 1;
1880 int sign_bit = max_imm >> 1;
1882 offset = inst & mask;
1883 if (is_signed && (offset & sign_bit))
1884 offset = 0 - (max_imm - offset);
1885 return offset * scale;
1890 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1891 stream from start_pc to limit_pc. */
1894 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1895 struct frame_info *next_frame, CORE_ADDR sp)
1898 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1899 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1900 unsigned inst = 0; /* current instruction */
1901 unsigned entry_inst = 0; /* the entry instruction */
1904 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
1905 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1907 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1909 /* Save the previous instruction. If it's an EXTEND, we'll extract
1910 the immediate offset extension from it in mips16_get_imm. */
1913 /* Fetch and decode the instruction. */
1914 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1915 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1916 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1918 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1919 if (offset < 0) /* negative stack adjustment? */
1920 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1922 /* Exit loop if a positive stack adjustment is found, which
1923 usually means that the stack cleanup code in the function
1924 epilogue is reached. */
1927 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1929 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1930 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1931 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1932 set_reg_offset (reg, sp + offset);
1934 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1936 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1937 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1938 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
1939 set_reg_offset (reg, sp + offset);
1941 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1943 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1944 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1945 set_reg_offset (RA_REGNUM, sp + offset);
1947 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1949 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1950 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
1951 set_reg_offset (RA_REGNUM, sp + offset);
1953 else if (inst == 0x673d) /* move $s1, $sp */
1956 PROC_FRAME_REG (&temp_proc_desc) = 17;
1958 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1960 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1961 frame_addr = sp + offset;
1962 PROC_FRAME_REG (&temp_proc_desc) = 17;
1963 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
1965 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1967 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1968 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1969 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
1970 set_reg_offset (reg, frame_addr + offset);
1972 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1974 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1975 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1976 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
1977 set_reg_offset (reg, frame_addr + offset);
1979 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1980 entry_inst = inst; /* save for later processing */
1981 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
1982 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
1985 /* The entry instruction is typically the first instruction in a function,
1986 and it stores registers at offsets relative to the value of the old SP
1987 (before the prologue). But the value of the sp parameter to this
1988 function is the new SP (after the prologue has been executed). So we
1989 can't calculate those offsets until we've seen the entire prologue,
1990 and can calculate what the old SP must have been. */
1991 if (entry_inst != 0)
1993 int areg_count = (entry_inst >> 8) & 7;
1994 int sreg_count = (entry_inst >> 6) & 3;
1996 /* The entry instruction always subtracts 32 from the SP. */
1997 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
1999 /* Now we can calculate what the SP must have been at the
2000 start of the function prologue. */
2001 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2003 /* Check if a0-a3 were saved in the caller's argument save area. */
2004 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2006 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2007 set_reg_offset (reg, sp + offset);
2008 offset += MIPS_SAVED_REGSIZE;
2011 /* Check if the ra register was pushed on the stack. */
2013 if (entry_inst & 0x20)
2015 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2016 set_reg_offset (RA_REGNUM, sp + offset);
2017 offset -= MIPS_SAVED_REGSIZE;
2020 /* Check if the s0 and s1 registers were pushed on the stack. */
2021 for (reg = 16; reg < sreg_count + 16; reg++)
2023 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2024 set_reg_offset (reg, sp + offset);
2025 offset -= MIPS_SAVED_REGSIZE;
2031 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2032 struct frame_info *next_frame, CORE_ADDR sp)
2035 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2037 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2038 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2039 PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2040 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2041 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2043 unsigned long inst, high_word, low_word;
2046 /* Fetch the instruction. */
2047 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2049 /* Save some code by pre-extracting some useful fields. */
2050 high_word = (inst >> 16) & 0xffff;
2051 low_word = inst & 0xffff;
2052 reg = high_word & 0x1f;
2054 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2055 || high_word == 0x23bd /* addi $sp,$sp,-i */
2056 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2058 if (low_word & 0x8000) /* negative stack adjustment? */
2059 PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2061 /* Exit loop if a positive stack adjustment is found, which
2062 usually means that the stack cleanup code in the function
2063 epilogue is reached. */
2066 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2068 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2069 set_reg_offset (reg, sp + low_word);
2071 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2073 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2074 but the register size used is only 32 bits. Make the address
2075 for the saved register point to the lower 32 bits. */
2076 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2077 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
2079 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2081 /* Old gcc frame, r30 is virtual frame pointer. */
2082 if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2083 frame_addr = sp + low_word;
2084 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2086 unsigned alloca_adjust;
2087 PROC_FRAME_REG (&temp_proc_desc) = 30;
2088 frame_addr = read_next_frame_reg (next_frame, 30);
2089 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2090 if (alloca_adjust > 0)
2092 /* FP > SP + frame_size. This may be because
2093 * of an alloca or somethings similar.
2094 * Fix sp to "pre-alloca" value, and try again.
2096 sp += alloca_adjust;
2101 /* move $30,$sp. With different versions of gas this will be either
2102 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2103 Accept any one of these. */
2104 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2106 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2107 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2109 unsigned alloca_adjust;
2110 PROC_FRAME_REG (&temp_proc_desc) = 30;
2111 frame_addr = read_next_frame_reg (next_frame, 30);
2112 alloca_adjust = (unsigned) (frame_addr - sp);
2113 if (alloca_adjust > 0)
2115 /* FP > SP + frame_size. This may be because
2116 * of an alloca or somethings similar.
2117 * Fix sp to "pre-alloca" value, and try again.
2119 sp += alloca_adjust;
2124 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2126 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2127 set_reg_offset (reg, frame_addr + low_word);
2132 static mips_extra_func_info_t
2133 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2134 struct frame_info *next_frame, int cur_frame)
2139 sp = read_next_frame_reg (next_frame, SP_REGNUM);
2145 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2146 temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2147 memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2148 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2149 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2150 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2152 if (start_pc + 200 < limit_pc)
2153 limit_pc = start_pc + 200;
2154 if (pc_is_mips16 (start_pc))
2155 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2157 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2158 return &temp_proc_desc;
2161 struct mips_objfile_private
2167 /* Global used to communicate between non_heuristic_proc_desc and
2168 compare_pdr_entries within qsort (). */
2169 static bfd *the_bfd;
2172 compare_pdr_entries (const void *a, const void *b)
2174 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2175 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2179 else if (lhs == rhs)
2185 static mips_extra_func_info_t
2186 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2188 CORE_ADDR startaddr;
2189 mips_extra_func_info_t proc_desc;
2190 struct block *b = block_for_pc (pc);
2192 struct obj_section *sec;
2193 struct mips_objfile_private *priv;
2195 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2198 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2200 *addrptr = startaddr;
2204 sec = find_pc_section (pc);
2207 priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2209 /* Search the ".pdr" section generated by GAS. This includes most of
2210 the information normally found in ECOFF PDRs. */
2212 the_bfd = sec->objfile->obfd;
2214 && (the_bfd->format == bfd_object
2215 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2216 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2218 /* Right now GAS only outputs the address as a four-byte sequence.
2219 This means that we should not bother with this method on 64-bit
2220 targets (until that is fixed). */
2222 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2223 sizeof (struct mips_objfile_private));
2225 sec->objfile->obj_private = priv;
2227 else if (priv == NULL)
2231 priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2232 sizeof (struct mips_objfile_private));
2234 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2237 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2238 priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2240 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2241 priv->contents, 0, priv->size);
2243 /* In general, the .pdr section is sorted. However, in the
2244 presence of multiple code sections (and other corner cases)
2245 it can become unsorted. Sort it so that we can use a faster
2247 qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2252 sec->objfile->obj_private = priv;
2256 if (priv->size != 0)
2262 high = priv->size / 32;
2268 mid = (low + high) / 2;
2270 ptr = priv->contents + mid * 32;
2271 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2272 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2273 SECT_OFF_TEXT (sec->objfile));
2274 if (pdr_pc == startaddr)
2276 if (pdr_pc > startaddr)
2281 while (low != high);
2285 struct symbol *sym = find_pc_function (pc);
2287 /* Fill in what we need of the proc_desc. */
2288 proc_desc = (mips_extra_func_info_t)
2289 obstack_alloc (&sec->objfile->psymbol_obstack,
2290 sizeof (struct mips_extra_func_info));
2291 PROC_LOW_ADDR (proc_desc) = startaddr;
2293 /* Only used for dummy frames. */
2294 PROC_HIGH_ADDR (proc_desc) = 0;
2296 PROC_FRAME_OFFSET (proc_desc)
2297 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2298 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2300 PROC_FRAME_ADJUST (proc_desc) = 0;
2301 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2303 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2305 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2307 PROC_FREG_OFFSET (proc_desc)
2308 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2309 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2311 proc_desc->pdr.isym = (long) sym;
2321 if (startaddr > BLOCK_START (b))
2323 /* This is the "pathological" case referred to in a comment in
2324 print_frame_info. It might be better to move this check into
2329 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
2331 /* If we never found a PDR for this function in symbol reading, then
2332 examine prologues to find the information. */
2335 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2336 if (PROC_FRAME_REG (proc_desc) == -1)
2346 static mips_extra_func_info_t
2347 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2349 mips_extra_func_info_t proc_desc;
2350 CORE_ADDR startaddr = 0;
2352 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2356 /* IF this is the topmost frame AND
2357 * (this proc does not have debugging information OR
2358 * the PC is in the procedure prologue)
2359 * THEN create a "heuristic" proc_desc (by analyzing
2360 * the actual code) to replace the "official" proc_desc.
2362 if (next_frame == NULL)
2364 struct symtab_and_line val;
2365 struct symbol *proc_symbol =
2366 PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2370 val = find_pc_line (BLOCK_START
2371 (SYMBOL_BLOCK_VALUE (proc_symbol)),
2373 val.pc = val.end ? val.end : pc;
2375 if (!proc_symbol || pc < val.pc)
2377 mips_extra_func_info_t found_heuristic =
2378 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2379 pc, next_frame, cur_frame);
2380 if (found_heuristic)
2381 proc_desc = found_heuristic;
2387 /* Is linked_proc_desc_table really necessary? It only seems to be used
2388 by procedure call dummys. However, the procedures being called ought
2389 to have their own proc_descs, and even if they don't,
2390 heuristic_proc_desc knows how to create them! */
2392 register struct linked_proc_info *link;
2394 for (link = linked_proc_desc_table; link; link = link->next)
2395 if (PROC_LOW_ADDR (&link->info) <= pc
2396 && PROC_HIGH_ADDR (&link->info) > pc)
2400 startaddr = heuristic_proc_start (pc);
2403 heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2409 get_frame_pointer (struct frame_info *frame,
2410 mips_extra_func_info_t proc_desc)
2412 return ADDR_BITS_REMOVE (read_next_frame_reg (frame,
2413 PROC_FRAME_REG (proc_desc)) +
2414 PROC_FRAME_OFFSET (proc_desc) -
2415 PROC_FRAME_ADJUST (proc_desc));
2418 static mips_extra_func_info_t cached_proc_desc;
2421 mips_frame_chain (struct frame_info *frame)
2423 mips_extra_func_info_t proc_desc;
2425 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
2427 if (saved_pc == 0 || inside_entry_file (saved_pc))
2430 /* Check if the PC is inside a call stub. If it is, fetch the
2431 PC of the caller of that stub. */
2432 if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2435 if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2437 /* A dummy frame, uses SP not FP. Get the old SP value. If all
2438 is well, frame->frame the bottom of the current frame will
2439 contain that value. */
2440 return get_frame_base (frame);
2443 /* Look up the procedure descriptor for this PC. */
2444 proc_desc = find_proc_desc (saved_pc, frame, 1);
2448 cached_proc_desc = proc_desc;
2450 /* If no frame pointer and frame size is zero, we must be at end
2451 of stack (or otherwise hosed). If we don't check frame size,
2452 we loop forever if we see a zero size frame. */
2453 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2454 && PROC_FRAME_OFFSET (proc_desc) == 0
2455 /* The previous frame from a sigtramp frame might be frameless
2456 and have frame size zero. */
2457 && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2458 /* For a generic dummy frame, let get_frame_pointer() unwind a
2459 register value saved as part of the dummy frame call. */
2460 && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2463 return get_frame_pointer (frame, proc_desc);
2467 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2471 /* Use proc_desc calculated in frame_chain */
2472 mips_extra_func_info_t proc_desc =
2473 get_next_frame (fci)
2475 : find_proc_desc (get_frame_pc (fci), get_next_frame (fci), 1);
2477 frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2479 fci->saved_regs = NULL;
2480 get_frame_extra_info (fci)->proc_desc =
2481 proc_desc == &temp_proc_desc ? 0 : proc_desc;
2484 /* Fixup frame-pointer - only needed for top frame */
2485 /* This may not be quite right, if proc has a real frame register.
2486 Get the value of the frame relative sp, procedure might have been
2487 interrupted by a signal at it's very start. */
2488 if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2489 && !PROC_DESC_IS_DUMMY (proc_desc))
2490 deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2491 else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2492 /* Do not ``fix'' fci->frame. It will have the value of the
2493 generic dummy frame's top-of-stack (since the draft
2494 fci->frame is obtained by returning the unwound stack
2495 pointer) and that is what we want. That way the fci->frame
2496 value will match the top-of-stack value that was saved as
2497 part of the dummy frames data. */
2500 deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2502 if (proc_desc == &temp_proc_desc)
2506 /* Do not set the saved registers for a sigtramp frame,
2507 mips_find_saved_registers will do that for us. We can't
2508 use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2510 /* FIXME: cagney/2002-11-18: This problem will go away once
2511 frame.c:get_prev_frame() is modified to set the frame's
2512 type before calling functions like this. */
2513 find_pc_partial_function (get_frame_pc (fci), &name,
2514 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2515 if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2517 frame_saved_regs_zalloc (fci);
2518 memcpy (get_frame_saved_regs (fci), temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2519 get_frame_saved_regs (fci)[PC_REGNUM]
2520 = get_frame_saved_regs (fci)[RA_REGNUM];
2521 /* Set value of previous frame's stack pointer. Remember that
2522 saved_regs[SP_REGNUM] is special in that it contains the
2523 value of the stack pointer register. The other saved_regs
2524 values are addresses (in the inferior) at which a given
2525 register's value may be found. */
2526 get_frame_saved_regs (fci)[SP_REGNUM] = get_frame_base (fci);
2530 /* hack: if argument regs are saved, guess these contain args */
2531 /* assume we can't tell how many args for now */
2532 get_frame_extra_info (fci)->num_args = -1;
2533 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2535 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2537 get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2544 /* MIPS stack frames are almost impenetrable. When execution stops,
2545 we basically have to look at symbol information for the function
2546 that we stopped in, which tells us *which* register (if any) is
2547 the base of the frame pointer, and what offset from that register
2548 the frame itself is at.
2550 This presents a problem when trying to examine a stack in memory
2551 (that isn't executing at the moment), using the "frame" command. We
2552 don't have a PC, nor do we have any registers except SP.
2554 This routine takes two arguments, SP and PC, and tries to make the
2555 cached frames look as if these two arguments defined a frame on the
2556 cache. This allows the rest of info frame to extract the important
2557 arguments without difficulty. */
2560 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2563 error ("MIPS frame specifications require two arguments: sp and pc");
2565 return create_new_frame (argv[0], argv[1]);
2568 /* According to the current ABI, should the type be passed in a
2569 floating-point register (assuming that there is space)? When there
2570 is no FPU, FP are not even considered as possibile candidates for
2571 FP registers and, consequently this returns false - forces FP
2572 arguments into integer registers. */
2575 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2577 return ((typecode == TYPE_CODE_FLT
2579 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2580 && TYPE_NFIELDS (arg_type) == 1
2581 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2582 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2585 /* On o32, argument passing in GPRs depends on the alignment of the type being
2586 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2589 mips_type_needs_double_align (struct type *type)
2591 enum type_code typecode = TYPE_CODE (type);
2593 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2595 else if (typecode == TYPE_CODE_STRUCT)
2597 if (TYPE_NFIELDS (type) < 1)
2599 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2601 else if (typecode == TYPE_CODE_UNION)
2605 n = TYPE_NFIELDS (type);
2606 for (i = 0; i < n; i++)
2607 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2614 /* Macros to round N up or down to the next A boundary;
2615 A must be a power of two. */
2617 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2618 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2620 /* Adjust the address downward (direction of stack growth) so that it
2621 is correctly aligned for a new stack frame. */
2623 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2625 return ROUND_DOWN (addr, 16);
2629 mips_eabi_push_arguments (int nargs,
2630 struct value **args,
2633 CORE_ADDR struct_addr)
2639 int stack_offset = 0;
2641 /* First ensure that the stack and structure return address (if any)
2642 are properly aligned. The stack has to be at least 64-bit
2643 aligned even on 32-bit machines, because doubles must be 64-bit
2644 aligned. For n32 and n64, stack frames need to be 128-bit
2645 aligned, so we round to this widest known alignment. */
2647 sp = ROUND_DOWN (sp, 16);
2648 struct_addr = ROUND_DOWN (struct_addr, 16);
2650 /* Now make space on the stack for the args. We allocate more
2651 than necessary for EABI, because the first few arguments are
2652 passed in registers, but that's OK. */
2653 for (argnum = 0; argnum < nargs; argnum++)
2654 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2655 MIPS_STACK_ARGSIZE);
2656 sp -= ROUND_UP (len, 16);
2659 fprintf_unfiltered (gdb_stdlog,
2660 "mips_eabi_push_arguments: sp=0x%s allocated %d\n",
2661 paddr_nz (sp), ROUND_UP (len, 16));
2663 /* Initialize the integer and float register pointers. */
2665 float_argreg = FPA0_REGNUM;
2667 /* The struct_return pointer occupies the first parameter-passing reg. */
2671 fprintf_unfiltered (gdb_stdlog,
2672 "mips_eabi_push_arguments: struct_return reg=%d 0x%s\n",
2673 argreg, paddr_nz (struct_addr));
2674 write_register (argreg++, struct_addr);
2677 /* Now load as many as possible of the first arguments into
2678 registers, and push the rest onto the stack. Loop thru args
2679 from first to last. */
2680 for (argnum = 0; argnum < nargs; argnum++)
2683 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2684 struct value *arg = args[argnum];
2685 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2686 int len = TYPE_LENGTH (arg_type);
2687 enum type_code typecode = TYPE_CODE (arg_type);
2690 fprintf_unfiltered (gdb_stdlog,
2691 "mips_eabi_push_arguments: %d len=%d type=%d",
2692 argnum + 1, len, (int) typecode);
2694 /* The EABI passes structures that do not fit in a register by
2696 if (len > MIPS_SAVED_REGSIZE
2697 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2699 store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2700 typecode = TYPE_CODE_PTR;
2701 len = MIPS_SAVED_REGSIZE;
2704 fprintf_unfiltered (gdb_stdlog, " push");
2707 val = (char *) VALUE_CONTENTS (arg);
2709 /* 32-bit ABIs always start floating point arguments in an
2710 even-numbered floating point register. Round the FP register
2711 up before the check to see if there are any FP registers
2712 left. Non MIPS_EABI targets also pass the FP in the integer
2713 registers so also round up normal registers. */
2714 if (!FP_REGISTER_DOUBLE
2715 && fp_register_arg_p (typecode, arg_type))
2717 if ((float_argreg & 1))
2721 /* Floating point arguments passed in registers have to be
2722 treated specially. On 32-bit architectures, doubles
2723 are passed in register pairs; the even register gets
2724 the low word, and the odd register gets the high word.
2725 On non-EABI processors, the first two floating point arguments are
2726 also copied to general registers, because MIPS16 functions
2727 don't use float registers for arguments. This duplication of
2728 arguments in general registers can't hurt non-MIPS16 functions
2729 because those registers are normally skipped. */
2730 /* MIPS_EABI squeezes a struct that contains a single floating
2731 point value into an FP register instead of pushing it onto the
2733 if (fp_register_arg_p (typecode, arg_type)
2734 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2736 if (!FP_REGISTER_DOUBLE && len == 8)
2738 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2739 unsigned long regval;
2741 /* Write the low word of the double to the even register(s). */
2742 regval = extract_unsigned_integer (val + low_offset, 4);
2744 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2745 float_argreg, phex (regval, 4));
2746 write_register (float_argreg++, regval);
2748 /* Write the high word of the double to the odd register(s). */
2749 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2751 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2752 float_argreg, phex (regval, 4));
2753 write_register (float_argreg++, regval);
2757 /* This is a floating point value that fits entirely
2758 in a single register. */
2759 /* On 32 bit ABI's the float_argreg is further adjusted
2760 above to ensure that it is even register aligned. */
2761 LONGEST regval = extract_unsigned_integer (val, len);
2763 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2764 float_argreg, phex (regval, len));
2765 write_register (float_argreg++, regval);
2770 /* Copy the argument to general registers or the stack in
2771 register-sized pieces. Large arguments are split between
2772 registers and stack. */
2773 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2774 are treated specially: Irix cc passes them in registers
2775 where gcc sometimes puts them on the stack. For maximum
2776 compatibility, we will put them in both places. */
2777 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2778 (len % MIPS_SAVED_REGSIZE != 0));
2780 /* Note: Floating-point values that didn't fit into an FP
2781 register are only written to memory. */
2784 /* Remember if the argument was written to the stack. */
2785 int stack_used_p = 0;
2787 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2790 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2793 /* Write this portion of the argument to the stack. */
2794 if (argreg > MIPS_LAST_ARG_REGNUM
2796 || fp_register_arg_p (typecode, arg_type))
2798 /* Should shorter than int integer values be
2799 promoted to int before being stored? */
2800 int longword_offset = 0;
2803 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2805 if (MIPS_STACK_ARGSIZE == 8 &&
2806 (typecode == TYPE_CODE_INT ||
2807 typecode == TYPE_CODE_PTR ||
2808 typecode == TYPE_CODE_FLT) && len <= 4)
2809 longword_offset = MIPS_STACK_ARGSIZE - len;
2810 else if ((typecode == TYPE_CODE_STRUCT ||
2811 typecode == TYPE_CODE_UNION) &&
2812 TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2813 longword_offset = MIPS_STACK_ARGSIZE - len;
2818 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2819 paddr_nz (stack_offset));
2820 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2821 paddr_nz (longword_offset));
2824 addr = sp + stack_offset + longword_offset;
2829 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
2831 for (i = 0; i < partial_len; i++)
2833 fprintf_unfiltered (gdb_stdlog, "%02x",
2837 write_memory (addr, val, partial_len);
2840 /* Note!!! This is NOT an else clause. Odd sized
2841 structs may go thru BOTH paths. Floating point
2842 arguments will not. */
2843 /* Write this portion of the argument to a general
2844 purpose register. */
2845 if (argreg <= MIPS_LAST_ARG_REGNUM
2846 && !fp_register_arg_p (typecode, arg_type))
2848 LONGEST regval = extract_unsigned_integer (val, partial_len);
2851 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2853 phex (regval, MIPS_SAVED_REGSIZE));
2854 write_register (argreg, regval);
2861 /* Compute the the offset into the stack at which we
2862 will copy the next parameter.
2864 In the new EABI (and the NABI32), the stack_offset
2865 only needs to be adjusted when it has been used. */
2868 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2872 fprintf_unfiltered (gdb_stdlog, "\n");
2875 /* Return adjusted stack pointer. */
2879 /* N32/N64 version of push_arguments. */
2882 mips_n32n64_push_arguments (int nargs,
2883 struct value **args,
2886 CORE_ADDR struct_addr)
2892 int stack_offset = 0;
2894 /* First ensure that the stack and structure return address (if any)
2895 are properly aligned. The stack has to be at least 64-bit
2896 aligned even on 32-bit machines, because doubles must be 64-bit
2897 aligned. For n32 and n64, stack frames need to be 128-bit
2898 aligned, so we round to this widest known alignment. */
2900 sp = ROUND_DOWN (sp, 16);
2901 struct_addr = ROUND_DOWN (struct_addr, 16);
2903 /* Now make space on the stack for the args. */
2904 for (argnum = 0; argnum < nargs; argnum++)
2905 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
2906 MIPS_STACK_ARGSIZE);
2907 sp -= ROUND_UP (len, 16);
2910 fprintf_unfiltered (gdb_stdlog,
2911 "mips_n32n64_push_arguments: sp=0x%s allocated %d\n",
2912 paddr_nz (sp), ROUND_UP (len, 16));
2914 /* Initialize the integer and float register pointers. */
2916 float_argreg = FPA0_REGNUM;
2918 /* The struct_return pointer occupies the first parameter-passing reg. */
2922 fprintf_unfiltered (gdb_stdlog,
2923 "mips_n32n64_push_arguments: struct_return reg=%d 0x%s\n",
2924 argreg, paddr_nz (struct_addr));
2925 write_register (argreg++, struct_addr);
2928 /* Now load as many as possible of the first arguments into
2929 registers, and push the rest onto the stack. Loop thru args
2930 from first to last. */
2931 for (argnum = 0; argnum < nargs; argnum++)
2934 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
2935 struct value *arg = args[argnum];
2936 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2937 int len = TYPE_LENGTH (arg_type);
2938 enum type_code typecode = TYPE_CODE (arg_type);
2941 fprintf_unfiltered (gdb_stdlog,
2942 "mips_n32n64_push_arguments: %d len=%d type=%d",
2943 argnum + 1, len, (int) typecode);
2945 val = (char *) VALUE_CONTENTS (arg);
2947 if (fp_register_arg_p (typecode, arg_type)
2948 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2950 /* This is a floating point value that fits entirely
2951 in a single register. */
2952 /* On 32 bit ABI's the float_argreg is further adjusted
2953 above to ensure that it is even register aligned. */
2954 LONGEST regval = extract_unsigned_integer (val, len);
2956 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2957 float_argreg, phex (regval, len));
2958 write_register (float_argreg++, regval);
2961 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
2962 argreg, phex (regval, len));
2963 write_register (argreg, regval);
2968 /* Copy the argument to general registers or the stack in
2969 register-sized pieces. Large arguments are split between
2970 registers and stack. */
2971 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2972 are treated specially: Irix cc passes them in registers
2973 where gcc sometimes puts them on the stack. For maximum
2974 compatibility, we will put them in both places. */
2975 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2976 (len % MIPS_SAVED_REGSIZE != 0));
2977 /* Note: Floating-point values that didn't fit into an FP
2978 register are only written to memory. */
2981 /* Rememer if the argument was written to the stack. */
2982 int stack_used_p = 0;
2983 int partial_len = len < MIPS_SAVED_REGSIZE ?
2984 len : MIPS_SAVED_REGSIZE;
2987 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2990 /* Write this portion of the argument to the stack. */
2991 if (argreg > MIPS_LAST_ARG_REGNUM
2993 || fp_register_arg_p (typecode, arg_type))
2995 /* Should shorter than int integer values be
2996 promoted to int before being stored? */
2997 int longword_offset = 0;
3000 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3002 if (MIPS_STACK_ARGSIZE == 8 &&
3003 (typecode == TYPE_CODE_INT ||
3004 typecode == TYPE_CODE_PTR ||
3005 typecode == TYPE_CODE_FLT) && len <= 4)
3006 longword_offset = MIPS_STACK_ARGSIZE - len;
3011 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3012 paddr_nz (stack_offset));
3013 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3014 paddr_nz (longword_offset));
3017 addr = sp + stack_offset + longword_offset;
3022 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3024 for (i = 0; i < partial_len; i++)
3026 fprintf_unfiltered (gdb_stdlog, "%02x",
3030 write_memory (addr, val, partial_len);
3033 /* Note!!! This is NOT an else clause. Odd sized
3034 structs may go thru BOTH paths. Floating point
3035 arguments will not. */
3036 /* Write this portion of the argument to a general
3037 purpose register. */
3038 if (argreg <= MIPS_LAST_ARG_REGNUM
3039 && !fp_register_arg_p (typecode, arg_type))
3041 LONGEST regval = extract_unsigned_integer (val, partial_len);
3043 /* A non-floating-point argument being passed in a
3044 general register. If a struct or union, and if
3045 the remaining length is smaller than the register
3046 size, we have to adjust the register value on
3049 It does not seem to be necessary to do the
3050 same for integral types.
3052 cagney/2001-07-23: gdb/179: Also, GCC, when
3053 outputting LE O32 with sizeof (struct) <
3054 MIPS_SAVED_REGSIZE, generates a left shift as
3055 part of storing the argument in a register a
3056 register (the left shift isn't generated when
3057 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3058 is quite possible that this is GCC contradicting
3059 the LE/O32 ABI, GDB has not been adjusted to
3060 accommodate this. Either someone needs to
3061 demonstrate that the LE/O32 ABI specifies such a
3062 left shift OR this new ABI gets identified as
3063 such and GDB gets tweaked accordingly. */
3065 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3066 && partial_len < MIPS_SAVED_REGSIZE
3067 && (typecode == TYPE_CODE_STRUCT ||
3068 typecode == TYPE_CODE_UNION))
3069 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3073 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3075 phex (regval, MIPS_SAVED_REGSIZE));
3076 write_register (argreg, regval);
3083 /* Compute the the offset into the stack at which we
3084 will copy the next parameter.
3086 In N32 (N64?), the stack_offset only needs to be
3087 adjusted when it has been used. */
3090 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3094 fprintf_unfiltered (gdb_stdlog, "\n");
3097 /* Return adjusted stack pointer. */
3101 /* O32 version of push_arguments. */
3104 mips_o32_push_arguments (int nargs,
3105 struct value **args,
3108 CORE_ADDR struct_addr)
3114 int stack_offset = 0;
3116 /* First ensure that the stack and structure return address (if any)
3117 are properly aligned. The stack has to be at least 64-bit
3118 aligned even on 32-bit machines, because doubles must be 64-bit
3119 aligned. For n32 and n64, stack frames need to be 128-bit
3120 aligned, so we round to this widest known alignment. */
3122 sp = ROUND_DOWN (sp, 16);
3123 struct_addr = ROUND_DOWN (struct_addr, 16);
3125 /* Now make space on the stack for the args. */
3126 for (argnum = 0; argnum < nargs; argnum++)
3127 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3128 MIPS_STACK_ARGSIZE);
3129 sp -= ROUND_UP (len, 16);
3132 fprintf_unfiltered (gdb_stdlog,
3133 "mips_o32_push_arguments: sp=0x%s allocated %d\n",
3134 paddr_nz (sp), ROUND_UP (len, 16));
3136 /* Initialize the integer and float register pointers. */
3138 float_argreg = FPA0_REGNUM;
3140 /* The struct_return pointer occupies the first parameter-passing reg. */
3144 fprintf_unfiltered (gdb_stdlog,
3145 "mips_o32_push_arguments: struct_return reg=%d 0x%s\n",
3146 argreg, paddr_nz (struct_addr));
3147 write_register (argreg++, struct_addr);
3148 stack_offset += MIPS_STACK_ARGSIZE;
3151 /* Now load as many as possible of the first arguments into
3152 registers, and push the rest onto the stack. Loop thru args
3153 from first to last. */
3154 for (argnum = 0; argnum < nargs; argnum++)
3157 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3158 struct value *arg = args[argnum];
3159 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3160 int len = TYPE_LENGTH (arg_type);
3161 enum type_code typecode = TYPE_CODE (arg_type);
3164 fprintf_unfiltered (gdb_stdlog,
3165 "mips_o32_push_arguments: %d len=%d type=%d",
3166 argnum + 1, len, (int) typecode);
3168 val = (char *) VALUE_CONTENTS (arg);
3170 /* 32-bit ABIs always start floating point arguments in an
3171 even-numbered floating point register. Round the FP register
3172 up before the check to see if there are any FP registers
3173 left. O32/O64 targets also pass the FP in the integer
3174 registers so also round up normal registers. */
3175 if (!FP_REGISTER_DOUBLE
3176 && fp_register_arg_p (typecode, arg_type))
3178 if ((float_argreg & 1))
3182 /* Floating point arguments passed in registers have to be
3183 treated specially. On 32-bit architectures, doubles
3184 are passed in register pairs; the even register gets
3185 the low word, and the odd register gets the high word.
3186 On O32/O64, the first two floating point arguments are
3187 also copied to general registers, because MIPS16 functions
3188 don't use float registers for arguments. This duplication of
3189 arguments in general registers can't hurt non-MIPS16 functions
3190 because those registers are normally skipped. */
3192 if (fp_register_arg_p (typecode, arg_type)
3193 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3195 if (!FP_REGISTER_DOUBLE && len == 8)
3197 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3198 unsigned long regval;
3200 /* Write the low word of the double to the even register(s). */
3201 regval = extract_unsigned_integer (val + low_offset, 4);
3203 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3204 float_argreg, phex (regval, 4));
3205 write_register (float_argreg++, regval);
3207 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3208 argreg, phex (regval, 4));
3209 write_register (argreg++, regval);
3211 /* Write the high word of the double to the odd register(s). */
3212 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3214 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3215 float_argreg, phex (regval, 4));
3216 write_register (float_argreg++, regval);
3219 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3220 argreg, phex (regval, 4));
3221 write_register (argreg++, regval);
3225 /* This is a floating point value that fits entirely
3226 in a single register. */
3227 /* On 32 bit ABI's the float_argreg is further adjusted
3228 above to ensure that it is even register aligned. */
3229 LONGEST regval = extract_unsigned_integer (val, len);
3231 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3232 float_argreg, phex (regval, len));
3233 write_register (float_argreg++, regval);
3234 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3235 registers for each argument. The below is (my
3236 guess) to ensure that the corresponding integer
3237 register has reserved the same space. */
3239 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3240 argreg, phex (regval, len));
3241 write_register (argreg, regval);
3242 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3244 /* Reserve space for the FP register. */
3245 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3249 /* Copy the argument to general registers or the stack in
3250 register-sized pieces. Large arguments are split between
3251 registers and stack. */
3252 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3253 are treated specially: Irix cc passes them in registers
3254 where gcc sometimes puts them on the stack. For maximum
3255 compatibility, we will put them in both places. */
3256 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3257 (len % MIPS_SAVED_REGSIZE != 0));
3258 /* Structures should be aligned to eight bytes (even arg registers)
3259 on MIPS_ABI_O32, if their first member has double precision. */
3260 if (MIPS_SAVED_REGSIZE < 8
3261 && mips_type_needs_double_align (arg_type))
3266 /* Note: Floating-point values that didn't fit into an FP
3267 register are only written to memory. */
3270 /* Remember if the argument was written to the stack. */
3271 int stack_used_p = 0;
3273 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3276 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3279 /* Write this portion of the argument to the stack. */
3280 if (argreg > MIPS_LAST_ARG_REGNUM
3282 || fp_register_arg_p (typecode, arg_type))
3284 /* Should shorter than int integer values be
3285 promoted to int before being stored? */
3286 int longword_offset = 0;
3289 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3291 if (MIPS_STACK_ARGSIZE == 8 &&
3292 (typecode == TYPE_CODE_INT ||
3293 typecode == TYPE_CODE_PTR ||
3294 typecode == TYPE_CODE_FLT) && len <= 4)
3295 longword_offset = MIPS_STACK_ARGSIZE - len;
3300 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3301 paddr_nz (stack_offset));
3302 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3303 paddr_nz (longword_offset));
3306 addr = sp + stack_offset + longword_offset;
3311 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3313 for (i = 0; i < partial_len; i++)
3315 fprintf_unfiltered (gdb_stdlog, "%02x",
3319 write_memory (addr, val, partial_len);
3322 /* Note!!! This is NOT an else clause. Odd sized
3323 structs may go thru BOTH paths. Floating point
3324 arguments will not. */
3325 /* Write this portion of the argument to a general
3326 purpose register. */
3327 if (argreg <= MIPS_LAST_ARG_REGNUM
3328 && !fp_register_arg_p (typecode, arg_type))
3330 LONGEST regval = extract_signed_integer (val, partial_len);
3331 /* Value may need to be sign extended, because
3332 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3334 /* A non-floating-point argument being passed in a
3335 general register. If a struct or union, and if
3336 the remaining length is smaller than the register
3337 size, we have to adjust the register value on
3340 It does not seem to be necessary to do the
3341 same for integral types.
3343 Also don't do this adjustment on O64 binaries.
3345 cagney/2001-07-23: gdb/179: Also, GCC, when
3346 outputting LE O32 with sizeof (struct) <
3347 MIPS_SAVED_REGSIZE, generates a left shift as
3348 part of storing the argument in a register a
3349 register (the left shift isn't generated when
3350 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3351 is quite possible that this is GCC contradicting
3352 the LE/O32 ABI, GDB has not been adjusted to
3353 accommodate this. Either someone needs to
3354 demonstrate that the LE/O32 ABI specifies such a
3355 left shift OR this new ABI gets identified as
3356 such and GDB gets tweaked accordingly. */
3358 if (MIPS_SAVED_REGSIZE < 8
3359 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3360 && partial_len < MIPS_SAVED_REGSIZE
3361 && (typecode == TYPE_CODE_STRUCT ||
3362 typecode == TYPE_CODE_UNION))
3363 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3367 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3369 phex (regval, MIPS_SAVED_REGSIZE));
3370 write_register (argreg, regval);
3373 /* Prevent subsequent floating point arguments from
3374 being passed in floating point registers. */
3375 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3381 /* Compute the the offset into the stack at which we
3382 will copy the next parameter.
3384 In older ABIs, the caller reserved space for
3385 registers that contained arguments. This was loosely
3386 refered to as their "home". Consequently, space is
3387 always allocated. */
3389 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3393 fprintf_unfiltered (gdb_stdlog, "\n");
3396 /* Return adjusted stack pointer. */
3400 /* O64 version of push_arguments. */
3403 mips_o64_push_arguments (int nargs,
3404 struct value **args,
3407 CORE_ADDR struct_addr)
3413 int stack_offset = 0;
3415 /* First ensure that the stack and structure return address (if any)
3416 are properly aligned. The stack has to be at least 64-bit
3417 aligned even on 32-bit machines, because doubles must be 64-bit
3418 aligned. For n32 and n64, stack frames need to be 128-bit
3419 aligned, so we round to this widest known alignment. */
3421 sp = ROUND_DOWN (sp, 16);
3422 struct_addr = ROUND_DOWN (struct_addr, 16);
3424 /* Now make space on the stack for the args. */
3425 for (argnum = 0; argnum < nargs; argnum++)
3426 len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3427 MIPS_STACK_ARGSIZE);
3428 sp -= ROUND_UP (len, 16);
3431 fprintf_unfiltered (gdb_stdlog,
3432 "mips_o64_push_arguments: sp=0x%s allocated %d\n",
3433 paddr_nz (sp), ROUND_UP (len, 16));
3435 /* Initialize the integer and float register pointers. */
3437 float_argreg = FPA0_REGNUM;
3439 /* The struct_return pointer occupies the first parameter-passing reg. */
3443 fprintf_unfiltered (gdb_stdlog,
3444 "mips_o64_push_arguments: struct_return reg=%d 0x%s\n",
3445 argreg, paddr_nz (struct_addr));
3446 write_register (argreg++, struct_addr);
3447 stack_offset += MIPS_STACK_ARGSIZE;
3450 /* Now load as many as possible of the first arguments into
3451 registers, and push the rest onto the stack. Loop thru args
3452 from first to last. */
3453 for (argnum = 0; argnum < nargs; argnum++)
3456 char *valbuf = alloca (MAX_REGISTER_RAW_SIZE);
3457 struct value *arg = args[argnum];
3458 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3459 int len = TYPE_LENGTH (arg_type);
3460 enum type_code typecode = TYPE_CODE (arg_type);
3463 fprintf_unfiltered (gdb_stdlog,
3464 "mips_o64_push_arguments: %d len=%d type=%d",
3465 argnum + 1, len, (int) typecode);
3467 val = (char *) VALUE_CONTENTS (arg);
3469 /* 32-bit ABIs always start floating point arguments in an
3470 even-numbered floating point register. Round the FP register
3471 up before the check to see if there are any FP registers
3472 left. O32/O64 targets also pass the FP in the integer
3473 registers so also round up normal registers. */
3474 if (!FP_REGISTER_DOUBLE
3475 && fp_register_arg_p (typecode, arg_type))
3477 if ((float_argreg & 1))
3481 /* Floating point arguments passed in registers have to be
3482 treated specially. On 32-bit architectures, doubles
3483 are passed in register pairs; the even register gets
3484 the low word, and the odd register gets the high word.
3485 On O32/O64, the first two floating point arguments are
3486 also copied to general registers, because MIPS16 functions
3487 don't use float registers for arguments. This duplication of
3488 arguments in general registers can't hurt non-MIPS16 functions
3489 because those registers are normally skipped. */
3491 if (fp_register_arg_p (typecode, arg_type)
3492 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3494 if (!FP_REGISTER_DOUBLE && len == 8)
3496 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3497 unsigned long regval;
3499 /* Write the low word of the double to the even register(s). */
3500 regval = extract_unsigned_integer (val + low_offset, 4);
3502 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3503 float_argreg, phex (regval, 4));
3504 write_register (float_argreg++, regval);
3506 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3507 argreg, phex (regval, 4));
3508 write_register (argreg++, regval);
3510 /* Write the high word of the double to the odd register(s). */
3511 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3513 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3514 float_argreg, phex (regval, 4));
3515 write_register (float_argreg++, regval);
3518 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3519 argreg, phex (regval, 4));
3520 write_register (argreg++, regval);
3524 /* This is a floating point value that fits entirely
3525 in a single register. */
3526 /* On 32 bit ABI's the float_argreg is further adjusted
3527 above to ensure that it is even register aligned. */
3528 LONGEST regval = extract_unsigned_integer (val, len);
3530 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3531 float_argreg, phex (regval, len));
3532 write_register (float_argreg++, regval);
3533 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3534 registers for each argument. The below is (my
3535 guess) to ensure that the corresponding integer
3536 register has reserved the same space. */
3538 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3539 argreg, phex (regval, len));
3540 write_register (argreg, regval);
3541 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3543 /* Reserve space for the FP register. */
3544 stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3548 /* Copy the argument to general registers or the stack in
3549 register-sized pieces. Large arguments are split between
3550 registers and stack. */
3551 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3552 are treated specially: Irix cc passes them in registers
3553 where gcc sometimes puts them on the stack. For maximum
3554 compatibility, we will put them in both places. */
3555 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3556 (len % MIPS_SAVED_REGSIZE != 0));
3557 /* Structures should be aligned to eight bytes (even arg registers)
3558 on MIPS_ABI_O32, if their first member has double precision. */
3559 if (MIPS_SAVED_REGSIZE < 8
3560 && mips_type_needs_double_align (arg_type))
3565 /* Note: Floating-point values that didn't fit into an FP
3566 register are only written to memory. */
3569 /* Remember if the argument was written to the stack. */
3570 int stack_used_p = 0;
3572 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3575 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3578 /* Write this portion of the argument to the stack. */
3579 if (argreg > MIPS_LAST_ARG_REGNUM
3581 || fp_register_arg_p (typecode, arg_type))
3583 /* Should shorter than int integer values be
3584 promoted to int before being stored? */
3585 int longword_offset = 0;
3588 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3590 if (MIPS_STACK_ARGSIZE == 8 &&
3591 (typecode == TYPE_CODE_INT ||
3592 typecode == TYPE_CODE_PTR ||
3593 typecode == TYPE_CODE_FLT) && len <= 4)
3594 longword_offset = MIPS_STACK_ARGSIZE - len;
3599 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3600 paddr_nz (stack_offset));
3601 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3602 paddr_nz (longword_offset));
3605 addr = sp + stack_offset + longword_offset;
3610 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3612 for (i = 0; i < partial_len; i++)
3614 fprintf_unfiltered (gdb_stdlog, "%02x",
3618 write_memory (addr, val, partial_len);
3621 /* Note!!! This is NOT an else clause. Odd sized
3622 structs may go thru BOTH paths. Floating point
3623 arguments will not. */
3624 /* Write this portion of the argument to a general
3625 purpose register. */
3626 if (argreg <= MIPS_LAST_ARG_REGNUM
3627 && !fp_register_arg_p (typecode, arg_type))
3629 LONGEST regval = extract_signed_integer (val, partial_len);
3630 /* Value may need to be sign extended, because
3631 MIPS_REGSIZE != MIPS_SAVED_REGSIZE. */
3633 /* A non-floating-point argument being passed in a
3634 general register. If a struct or union, and if
3635 the remaining length is smaller than the register
3636 size, we have to adjust the register value on
3639 It does not seem to be necessary to do the
3640 same for integral types.
3642 Also don't do this adjustment on O64 binaries.
3644 cagney/2001-07-23: gdb/179: Also, GCC, when
3645 outputting LE O32 with sizeof (struct) <
3646 MIPS_SAVED_REGSIZE, generates a left shift as
3647 part of storing the argument in a register a
3648 register (the left shift isn't generated when
3649 sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it
3650 is quite possible that this is GCC contradicting
3651 the LE/O32 ABI, GDB has not been adjusted to
3652 accommodate this. Either someone needs to
3653 demonstrate that the LE/O32 ABI specifies such a
3654 left shift OR this new ABI gets identified as
3655 such and GDB gets tweaked accordingly. */
3657 if (MIPS_SAVED_REGSIZE < 8
3658 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3659 && partial_len < MIPS_SAVED_REGSIZE
3660 && (typecode == TYPE_CODE_STRUCT ||
3661 typecode == TYPE_CODE_UNION))
3662 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3666 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3668 phex (regval, MIPS_SAVED_REGSIZE));
3669 write_register (argreg, regval);
3672 /* Prevent subsequent floating point arguments from
3673 being passed in floating point registers. */
3674 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3680 /* Compute the the offset into the stack at which we
3681 will copy the next parameter.
3683 In older ABIs, the caller reserved space for
3684 registers that contained arguments. This was loosely
3685 refered to as their "home". Consequently, space is
3686 always allocated. */
3688 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3692 fprintf_unfiltered (gdb_stdlog, "\n");
3695 /* Return adjusted stack pointer. */
3700 mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
3702 /* Set the return address register to point to the entry
3703 point of the program, where a breakpoint lies in wait. */
3704 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
3709 mips_push_register (CORE_ADDR * sp, int regno)
3711 char *buffer = alloca (MAX_REGISTER_RAW_SIZE);
3714 if (MIPS_SAVED_REGSIZE < REGISTER_RAW_SIZE (regno))
3716 regsize = MIPS_SAVED_REGSIZE;
3717 offset = (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3718 ? REGISTER_RAW_SIZE (regno) - MIPS_SAVED_REGSIZE
3723 regsize = REGISTER_RAW_SIZE (regno);
3727 deprecated_read_register_gen (regno, buffer);
3728 write_memory (*sp, buffer + offset, regsize);
3731 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
3732 #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
3735 mips_push_dummy_frame (void)
3738 struct linked_proc_info *link = (struct linked_proc_info *)
3739 xmalloc (sizeof (struct linked_proc_info));
3740 mips_extra_func_info_t proc_desc = &link->info;
3741 CORE_ADDR sp = ADDR_BITS_REMOVE (read_signed_register (SP_REGNUM));
3742 CORE_ADDR old_sp = sp;
3743 link->next = linked_proc_desc_table;
3744 linked_proc_desc_table = link;
3746 /* FIXME! are these correct ? */
3747 #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
3748 #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
3749 #define FLOAT_REG_SAVE_MASK MASK(0,19)
3750 #define FLOAT_SINGLE_REG_SAVE_MASK \
3751 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
3753 * The registers we must save are all those not preserved across
3754 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
3755 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
3756 * and FP Control/Status registers.
3759 * Dummy frame layout:
3762 * Saved MMHI, MMLO, FPC_CSR
3767 * Saved D18 (i.e. F19, F18)
3769 * Saved D0 (i.e. F1, F0)
3770 * Argument build area and stack arguments written via mips_push_arguments
3774 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
3775 PROC_FRAME_REG (proc_desc) = PUSH_FP_REGNUM;
3776 PROC_FRAME_OFFSET (proc_desc) = 0;
3777 PROC_FRAME_ADJUST (proc_desc) = 0;
3778 mips_push_register (&sp, PC_REGNUM);
3779 mips_push_register (&sp, HI_REGNUM);
3780 mips_push_register (&sp, LO_REGNUM);
3781 mips_push_register (&sp, MIPS_FPU_TYPE == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
3783 /* Save general CPU registers */
3784 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
3785 /* PROC_REG_OFFSET is the offset of the first saved register from FP. */
3786 PROC_REG_OFFSET (proc_desc) = sp - old_sp - MIPS_SAVED_REGSIZE;
3787 for (ireg = 32; --ireg >= 0;)
3788 if (PROC_REG_MASK (proc_desc) & (1 << ireg))
3789 mips_push_register (&sp, ireg);
3791 /* Save floating point registers starting with high order word */
3792 PROC_FREG_MASK (proc_desc) =
3793 MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
3794 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
3795 /* PROC_FREG_OFFSET is the offset of the first saved *double* register
3797 PROC_FREG_OFFSET (proc_desc) = sp - old_sp - 8;
3798 for (ireg = 32; --ireg >= 0;)
3799 if (PROC_FREG_MASK (proc_desc) & (1 << ireg))
3800 mips_push_register (&sp, ireg + FP0_REGNUM);
3802 /* Update the frame pointer for the call dummy and the stack pointer.
3803 Set the procedure's starting and ending addresses to point to the
3804 call dummy address at the entry point. */
3805 write_register (PUSH_FP_REGNUM, old_sp);
3806 write_register (SP_REGNUM, sp);
3807 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
3808 PROC_HIGH_ADDR (proc_desc) = CALL_DUMMY_ADDRESS () + 4;
3809 SET_PROC_DESC_IS_DUMMY (proc_desc);
3810 PROC_PC_REG (proc_desc) = RA_REGNUM;
3814 mips_pop_frame (void)
3816 register int regnum;
3817 struct frame_info *frame = get_current_frame ();
3818 CORE_ADDR new_sp = get_frame_base (frame);
3819 mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
3821 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3823 generic_pop_dummy_frame ();
3824 flush_cached_frames ();
3828 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
3829 if (get_frame_saved_regs (frame) == NULL)
3830 FRAME_INIT_SAVED_REGS (frame);
3831 for (regnum = 0; regnum < NUM_REGS; regnum++)
3832 if (regnum != SP_REGNUM && regnum != PC_REGNUM
3833 && get_frame_saved_regs (frame)[regnum])
3835 /* Floating point registers must not be sign extended,
3836 in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8. */
3838 if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3839 write_register (regnum,
3840 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3841 MIPS_SAVED_REGSIZE));
3843 write_register (regnum,
3844 read_memory_integer (get_frame_saved_regs (frame)[regnum],
3845 MIPS_SAVED_REGSIZE));
3848 write_register (SP_REGNUM, new_sp);
3849 flush_cached_frames ();
3851 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3853 struct linked_proc_info *pi_ptr, *prev_ptr;
3855 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3857 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3859 if (&pi_ptr->info == proc_desc)
3864 error ("Can't locate dummy extra frame info\n");
3866 if (prev_ptr != NULL)
3867 prev_ptr->next = pi_ptr->next;
3869 linked_proc_desc_table = pi_ptr->next;
3873 write_register (HI_REGNUM,
3874 read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3875 MIPS_SAVED_REGSIZE));
3876 write_register (LO_REGNUM,
3877 read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3878 MIPS_SAVED_REGSIZE));
3879 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3880 write_register (FCRCS_REGNUM,
3881 read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3882 MIPS_SAVED_REGSIZE));
3887 mips_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
3888 struct value **args, struct type *type, int gcc_p)
3890 write_register(T9_REGNUM, fun);
3893 /* Floating point register management.
3895 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
3896 64bit operations, these early MIPS cpus treat fp register pairs
3897 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
3898 registers and offer a compatibility mode that emulates the MIPS2 fp
3899 model. When operating in MIPS2 fp compat mode, later cpu's split
3900 double precision floats into two 32-bit chunks and store them in
3901 consecutive fp regs. To display 64-bit floats stored in this
3902 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3903 Throw in user-configurable endianness and you have a real mess.
3905 The way this works is:
3906 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3907 double-precision value will be split across two logical registers.
3908 The lower-numbered logical register will hold the low-order bits,
3909 regardless of the processor's endianness.
3910 - If we are on a 64-bit processor, and we are looking for a
3911 single-precision value, it will be in the low ordered bits
3912 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3913 save slot in memory.
3914 - If we are in 64-bit mode, everything is straightforward.
3916 Note that this code only deals with "live" registers at the top of the
3917 stack. We will attempt to deal with saved registers later, when
3918 the raw/cooked register interface is in place. (We need a general
3919 interface that can deal with dynamic saved register sizes -- fp
3920 regs could be 32 bits wide in one frame and 64 on the frame above
3923 static struct type *
3924 mips_float_register_type (void)
3926 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3927 return builtin_type_ieee_single_big;
3929 return builtin_type_ieee_single_little;
3932 static struct type *
3933 mips_double_register_type (void)
3935 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3936 return builtin_type_ieee_double_big;
3938 return builtin_type_ieee_double_little;
3941 /* Copy a 32-bit single-precision value from the current frame
3942 into rare_buffer. */
3945 mips_read_fp_register_single (int regno, char *rare_buffer)
3947 int raw_size = REGISTER_RAW_SIZE (regno);
3948 char *raw_buffer = alloca (raw_size);
3950 if (!frame_register_read (deprecated_selected_frame, regno, raw_buffer))
3951 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3954 /* We have a 64-bit value for this register. Find the low-order
3958 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3963 memcpy (rare_buffer, raw_buffer + offset, 4);
3967 memcpy (rare_buffer, raw_buffer, 4);
3971 /* Copy a 64-bit double-precision value from the current frame into
3972 rare_buffer. This may include getting half of it from the next
3976 mips_read_fp_register_double (int regno, char *rare_buffer)
3978 int raw_size = REGISTER_RAW_SIZE (regno);
3980 if (raw_size == 8 && !mips2_fp_compat ())
3982 /* We have a 64-bit value for this register, and we should use
3984 if (!frame_register_read (deprecated_selected_frame, regno, rare_buffer))
3985 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3989 if ((regno - FP0_REGNUM) & 1)
3990 internal_error (__FILE__, __LINE__,
3991 "mips_read_fp_register_double: bad access to "
3992 "odd-numbered FP register");
3994 /* mips_read_fp_register_single will find the correct 32 bits from
3996 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3998 mips_read_fp_register_single (regno, rare_buffer + 4);
3999 mips_read_fp_register_single (regno + 1, rare_buffer);
4003 mips_read_fp_register_single (regno, rare_buffer);
4004 mips_read_fp_register_single (regno + 1, rare_buffer + 4);
4010 mips_print_register (int regnum, int all)
4012 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4014 /* Get the data in raw format. */
4015 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4017 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
4021 /* If we have a actual 32-bit floating point register (or we are in
4022 32-bit compatibility mode), and the register is even-numbered,
4023 also print it as a double (spanning two registers). */
4024 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
4025 && (REGISTER_RAW_SIZE (regnum) == 4
4026 || mips2_fp_compat ())
4027 && !((regnum - FP0_REGNUM) & 1))
4029 char *dbuffer = alloca (2 * MAX_REGISTER_RAW_SIZE);
4031 mips_read_fp_register_double (regnum, dbuffer);
4033 printf_filtered ("(d%d: ", regnum - FP0_REGNUM);
4034 val_print (mips_double_register_type (), dbuffer, 0, 0,
4035 gdb_stdout, 0, 1, 0, Val_pretty_default);
4036 printf_filtered ("); ");
4038 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
4040 /* The problem with printing numeric register names (r26, etc.) is that
4041 the user can't use them on input. Probably the best solution is to
4042 fix it so that either the numeric or the funky (a2, etc.) names
4043 are accepted on input. */
4044 if (regnum < MIPS_NUMREGS)
4045 printf_filtered ("(r%d): ", regnum);
4047 printf_filtered (": ");
4049 /* If virtual format is floating, print it that way. */
4050 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4051 if (REGISTER_RAW_SIZE (regnum) == 8 && !mips2_fp_compat ())
4053 /* We have a meaningful 64-bit value in this register. Show
4054 it as a 32-bit float and a 64-bit double. */
4055 int offset = 4 * (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG);
4057 printf_filtered (" (float) ");
4058 val_print (mips_float_register_type (), raw_buffer + offset, 0, 0,
4059 gdb_stdout, 0, 1, 0, Val_pretty_default);
4060 printf_filtered (", (double) ");
4061 val_print (mips_double_register_type (), raw_buffer, 0, 0,
4062 gdb_stdout, 0, 1, 0, Val_pretty_default);
4065 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
4066 gdb_stdout, 0, 1, 0, Val_pretty_default);
4067 /* Else print as integer in hex. */
4072 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4073 offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4077 print_scalar_formatted (raw_buffer + offset,
4078 REGISTER_VIRTUAL_TYPE (regnum),
4079 'x', 0, gdb_stdout);
4083 /* Replacement for generic do_registers_info.
4084 Print regs in pretty columns. */
4087 do_fp_register_row (int regnum)
4088 { /* do values for FP (float) regs */
4090 double doub, flt1, flt2; /* doubles extracted from raw hex data */
4091 int inv1, inv2, inv3;
4093 raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
4095 if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4097 /* 4-byte registers: we can fit two registers per row. */
4098 /* Also print every pair of 4-byte regs as an 8-byte double. */
4099 mips_read_fp_register_single (regnum, raw_buffer);
4100 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4102 mips_read_fp_register_single (regnum + 1, raw_buffer);
4103 flt2 = unpack_double (mips_float_register_type (), raw_buffer, &inv2);
4105 mips_read_fp_register_double (regnum, raw_buffer);
4106 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
4108 printf_filtered (" %-5s", REGISTER_NAME (regnum));
4110 printf_filtered (": <invalid float>");
4112 printf_filtered ("%-17.9g", flt1);
4114 printf_filtered (" %-5s", REGISTER_NAME (regnum + 1));
4116 printf_filtered (": <invalid float>");
4118 printf_filtered ("%-17.9g", flt2);
4120 printf_filtered (" dbl: ");
4122 printf_filtered ("<invalid double>");
4124 printf_filtered ("%-24.17g", doub);
4125 printf_filtered ("\n");
4127 /* may want to do hex display here (future enhancement) */
4132 /* Eight byte registers: print each one as float AND as double. */
4133 mips_read_fp_register_single (regnum, raw_buffer);
4134 flt1 = unpack_double (mips_double_register_type (), raw_buffer, &inv1);
4136 mips_read_fp_register_double (regnum, raw_buffer);
4137 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3);
4139 printf_filtered (" %-5s: ", REGISTER_NAME (regnum));
4141 printf_filtered ("<invalid float>");
4143 printf_filtered ("flt: %-17.9g", flt1);
4145 printf_filtered (" dbl: ");
4147 printf_filtered ("<invalid double>");
4149 printf_filtered ("%-24.17g", doub);
4151 printf_filtered ("\n");
4152 /* may want to do hex display here (future enhancement) */
4158 /* Print a row's worth of GP (int) registers, with name labels above */
4161 do_gp_register_row (int regnum)
4163 /* do values for GP (int) regs */
4164 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4165 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
4167 int start_regnum = regnum;
4168 int numregs = NUM_REGS;
4171 /* For GP registers, we print a separate row of names above the vals */
4172 printf_filtered (" ");
4173 for (col = 0; col < ncols && regnum < numregs; regnum++)
4175 if (*REGISTER_NAME (regnum) == '\0')
4176 continue; /* unused register */
4177 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4178 break; /* end the row: reached FP register */
4179 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4180 REGISTER_NAME (regnum));
4183 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
4184 start_regnum); /* print the R0 to R31 names */
4186 regnum = start_regnum; /* go back to start of row */
4187 /* now print the values in hex, 4 or 8 to the row */
4188 for (col = 0; col < ncols && regnum < numregs; regnum++)
4190 if (*REGISTER_NAME (regnum) == '\0')
4191 continue; /* unused register */
4192 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4193 break; /* end row: reached FP register */
4194 /* OK: get the data in raw format. */
4195 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
4196 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4197 /* pad small registers */
4198 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4199 printf_filtered (" ");
4200 /* Now print the register value in hex, endian order. */
4201 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4202 for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4203 byte < REGISTER_RAW_SIZE (regnum);
4205 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4207 for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4210 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
4211 printf_filtered (" ");
4214 if (col > 0) /* ie. if we actually printed anything... */
4215 printf_filtered ("\n");
4220 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4223 mips_do_registers_info (int regnum, int fpregs)
4225 if (regnum != -1) /* do one specified register */
4227 if (*(REGISTER_NAME (regnum)) == '\0')
4228 error ("Not a valid register for the current processor type");
4230 mips_print_register (regnum, 0);
4231 printf_filtered ("\n");
4234 /* do all (or most) registers */
4237 while (regnum < NUM_REGS)
4239 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4240 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
4241 regnum = do_fp_register_row (regnum); /* FP regs */
4243 regnum += MIPS_NUMREGS; /* skip floating point regs */
4245 regnum = do_gp_register_row (regnum); /* GP (int) regs */
4250 /* Is this a branch with a delay slot? */
4252 static int is_delayed (unsigned long);
4255 is_delayed (unsigned long insn)
4258 for (i = 0; i < NUMOPCODES; ++i)
4259 if (mips_opcodes[i].pinfo != INSN_MACRO
4260 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4262 return (i < NUMOPCODES
4263 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4264 | INSN_COND_BRANCH_DELAY
4265 | INSN_COND_BRANCH_LIKELY)));
4269 mips_step_skips_delay (CORE_ADDR pc)
4271 char buf[MIPS_INSTLEN];
4273 /* There is no branch delay slot on MIPS16. */
4274 if (pc_is_mips16 (pc))
4277 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4278 /* If error reading memory, guess that it is not a delayed branch. */
4280 return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4284 /* Skip the PC past function prologue instructions (32-bit version).
4285 This is a helper function for mips_skip_prologue. */
4288 mips32_skip_prologue (CORE_ADDR pc)
4292 int seen_sp_adjust = 0;
4293 int load_immediate_bytes = 0;
4295 /* Skip the typical prologue instructions. These are the stack adjustment
4296 instruction and the instructions that save registers on the stack
4297 or in the gcc frame. */
4298 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4300 unsigned long high_word;
4302 inst = mips_fetch_instruction (pc);
4303 high_word = (inst >> 16) & 0xffff;
4305 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
4306 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
4308 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
4309 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
4311 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
4312 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
4313 && (inst & 0x001F0000)) /* reg != $zero */
4316 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
4318 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4320 continue; /* reg != $zero */
4322 /* move $s8,$sp. With different versions of gas this will be either
4323 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4324 Accept any one of these. */
4325 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4328 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
4330 else if (high_word == 0x3c1c) /* lui $gp,n */
4332 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
4334 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
4335 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
4337 /* The following instructions load $at or $t0 with an immediate
4338 value in preparation for a stack adjustment via
4339 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4340 a local variable, so we accept them only before a stack adjustment
4341 instruction was seen. */
4342 else if (!seen_sp_adjust)
4344 if (high_word == 0x3c01 || /* lui $at,n */
4345 high_word == 0x3c08) /* lui $t0,n */
4347 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4350 else if (high_word == 0x3421 || /* ori $at,$at,n */
4351 high_word == 0x3508 || /* ori $t0,$t0,n */
4352 high_word == 0x3401 || /* ori $at,$zero,n */
4353 high_word == 0x3408) /* ori $t0,$zero,n */
4355 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
4365 /* In a frameless function, we might have incorrectly
4366 skipped some load immediate instructions. Undo the skipping
4367 if the load immediate was not followed by a stack adjustment. */
4368 if (load_immediate_bytes && !seen_sp_adjust)
4369 pc -= load_immediate_bytes;
4373 /* Skip the PC past function prologue instructions (16-bit version).
4374 This is a helper function for mips_skip_prologue. */
4377 mips16_skip_prologue (CORE_ADDR pc)
4380 int extend_bytes = 0;
4381 int prev_extend_bytes;
4383 /* Table of instructions likely to be found in a function prologue. */
4386 unsigned short inst;
4387 unsigned short mask;
4394 , /* addiu $sp,offset */
4398 , /* daddiu $sp,offset */
4402 , /* sw reg,n($sp) */
4406 , /* sd reg,n($sp) */
4410 , /* sw $ra,n($sp) */
4414 , /* sd $ra,n($sp) */
4422 , /* sw $a0-$a3,n($s1) */
4426 , /* move reg,$a0-$a3 */
4430 , /* entry pseudo-op */
4434 , /* addiu $s1,$sp,n */
4437 } /* end of table marker */
4440 /* Skip the typical prologue instructions. These are the stack adjustment
4441 instruction and the instructions that save registers on the stack
4442 or in the gcc frame. */
4443 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4445 unsigned short inst;
4448 inst = mips_fetch_instruction (pc);
4450 /* Normally we ignore an extend instruction. However, if it is
4451 not followed by a valid prologue instruction, we must adjust
4452 the pc back over the extend so that it won't be considered
4453 part of the prologue. */
4454 if ((inst & 0xf800) == 0xf000) /* extend */
4456 extend_bytes = MIPS16_INSTLEN;
4459 prev_extend_bytes = extend_bytes;
4462 /* Check for other valid prologue instructions besides extend. */
4463 for (i = 0; table[i].mask != 0; i++)
4464 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
4466 if (table[i].mask != 0) /* it was in table? */
4467 continue; /* ignore it */
4471 /* Return the current pc, adjusted backwards by 2 if
4472 the previous instruction was an extend. */
4473 return pc - prev_extend_bytes;
4479 /* To skip prologues, I use this predicate. Returns either PC itself
4480 if the code at PC does not look like a function prologue; otherwise
4481 returns an address that (if we're lucky) follows the prologue. If
4482 LENIENT, then we must skip everything which is involved in setting
4483 up the frame (it's OK to skip more, just so long as we don't skip
4484 anything which might clobber the registers which are being saved.
4485 We must skip more in the case where part of the prologue is in the
4486 delay slot of a non-prologue instruction). */
4489 mips_skip_prologue (CORE_ADDR pc)
4491 /* See if we can determine the end of the prologue via the symbol table.
4492 If so, then return either PC, or the PC after the prologue, whichever
4495 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4497 if (post_prologue_pc != 0)
4498 return max (pc, post_prologue_pc);
4500 /* Can't determine prologue from the symbol table, need to examine
4503 if (pc_is_mips16 (pc))
4504 return mips16_skip_prologue (pc);
4506 return mips32_skip_prologue (pc);
4509 /* Determine how a return value is stored within the MIPS register
4510 file, given the return type `valtype'. */
4512 struct return_value_word
4521 return_value_location (struct type *valtype,
4522 struct return_value_word *hi,
4523 struct return_value_word *lo)
4525 int len = TYPE_LENGTH (valtype);
4527 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4528 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4529 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4531 if (!FP_REGISTER_DOUBLE && len == 8)
4533 /* We need to break a 64bit float in two 32 bit halves and
4534 spread them across a floating-point register pair. */
4535 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4536 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4537 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4538 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4540 hi->reg_offset = lo->reg_offset;
4541 lo->reg = FP0_REGNUM + 0;
4542 hi->reg = FP0_REGNUM + 1;
4548 /* The floating point value fits in a single floating-point
4550 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4551 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4554 lo->reg = FP0_REGNUM;
4565 /* Locate a result possibly spread across two registers. */
4567 lo->reg = regnum + 0;
4568 hi->reg = regnum + 1;
4569 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4570 && len < MIPS_SAVED_REGSIZE)
4572 /* "un-left-justify" the value in the low register */
4573 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4578 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4579 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
4580 && len < MIPS_SAVED_REGSIZE * 2
4581 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4582 TYPE_CODE (valtype) == TYPE_CODE_UNION))
4584 /* "un-left-justify" the value spread across two registers. */
4585 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4586 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4588 hi->len = len - lo->len;
4592 /* Only perform a partial copy of the second register. */
4595 if (len > MIPS_SAVED_REGSIZE)
4597 lo->len = MIPS_SAVED_REGSIZE;
4598 hi->len = len - MIPS_SAVED_REGSIZE;
4606 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4607 && REGISTER_RAW_SIZE (regnum) == 8
4608 && MIPS_SAVED_REGSIZE == 4)
4610 /* Account for the fact that only the least-signficant part
4611 of the register is being used */
4612 lo->reg_offset += 4;
4613 hi->reg_offset += 4;
4616 hi->buf_offset = lo->len;
4620 /* Given a return value in `regbuf' with a type `valtype', extract and
4621 copy its value into `valbuf'. */
4624 mips_eabi_extract_return_value (struct type *valtype,
4625 char regbuf[REGISTER_BYTES],
4628 struct return_value_word lo;
4629 struct return_value_word hi;
4630 return_value_location (valtype, &hi, &lo);
4632 memcpy (valbuf + lo.buf_offset,
4633 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4637 memcpy (valbuf + hi.buf_offset,
4638 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4643 mips_o64_extract_return_value (struct type *valtype,
4644 char regbuf[REGISTER_BYTES],
4647 struct return_value_word lo;
4648 struct return_value_word hi;
4649 return_value_location (valtype, &hi, &lo);
4651 memcpy (valbuf + lo.buf_offset,
4652 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4656 memcpy (valbuf + hi.buf_offset,
4657 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4661 /* Given a return value in `valbuf' with a type `valtype', write it's
4662 value into the appropriate register. */
4665 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4667 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4668 struct return_value_word lo;
4669 struct return_value_word hi;
4670 return_value_location (valtype, &hi, &lo);
4672 memset (raw_buffer, 0, sizeof (raw_buffer));
4673 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4674 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4675 REGISTER_RAW_SIZE (lo.reg));
4679 memset (raw_buffer, 0, sizeof (raw_buffer));
4680 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4681 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4682 REGISTER_RAW_SIZE (hi.reg));
4687 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4689 char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
4690 struct return_value_word lo;
4691 struct return_value_word hi;
4692 return_value_location (valtype, &hi, &lo);
4694 memset (raw_buffer, 0, sizeof (raw_buffer));
4695 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4696 deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4697 REGISTER_RAW_SIZE (lo.reg));
4701 memset (raw_buffer, 0, sizeof (raw_buffer));
4702 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4703 deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4704 REGISTER_RAW_SIZE (hi.reg));
4708 /* O32 ABI stuff. */
4711 mips_o32_xfer_return_value (struct type *type,
4712 struct regcache *regcache,
4713 bfd_byte *in, const bfd_byte *out)
4715 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4716 if (TYPE_CODE (type) == TYPE_CODE_FLT
4717 && TYPE_LENGTH (type) == 4
4718 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4720 /* A single-precision floating-point value. It fits in the
4721 least significant part of FP0. */
4723 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4724 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4725 TARGET_BYTE_ORDER, in, out, 0);
4727 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4728 && TYPE_LENGTH (type) == 8
4729 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4731 /* A double-precision floating-point value. It fits in the
4732 least significant part of FP0/FP1 but with byte ordering
4733 based on the target (???). */
4735 fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4736 switch (TARGET_BYTE_ORDER)
4738 case BFD_ENDIAN_LITTLE:
4739 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4740 TARGET_BYTE_ORDER, in, out, 0);
4741 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4742 TARGET_BYTE_ORDER, in, out, 4);
4744 case BFD_ENDIAN_BIG:
4745 mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4746 TARGET_BYTE_ORDER, in, out, 0);
4747 mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4748 TARGET_BYTE_ORDER, in, out, 4);
4751 internal_error (__FILE__, __LINE__, "bad switch");
4755 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4756 && TYPE_NFIELDS (type) <= 2
4757 && TYPE_NFIELDS (type) >= 1
4758 && ((TYPE_NFIELDS (type) == 1
4759 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4761 || (TYPE_NFIELDS (type) == 2
4762 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4764 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4766 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4768 /* A struct that contains one or two floats. Each value is part
4769 in the least significant part of their floating point
4771 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4774 for (field = 0, regnum = FP0_REGNUM;
4775 field < TYPE_NFIELDS (type);
4776 field++, regnum += 2)
4778 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4781 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4782 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4783 TARGET_BYTE_ORDER, in, out, offset);
4788 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4789 || TYPE_CODE (type) == TYPE_CODE_UNION)
4791 /* A structure or union. Extract the left justified value,
4792 regardless of the byte order. I.e. DO NOT USE
4796 for (offset = 0, regnum = V0_REGNUM;
4797 offset < TYPE_LENGTH (type);
4798 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4800 int xfer = REGISTER_RAW_SIZE (regnum);
4801 if (offset + xfer > TYPE_LENGTH (type))
4802 xfer = TYPE_LENGTH (type) - offset;
4804 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4805 offset, xfer, regnum);
4806 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4813 /* A scalar extract each part but least-significant-byte
4814 justified. o32 thinks registers are 4 byte, regardless of
4815 the ISA. mips_stack_argsize controls this. */
4818 for (offset = 0, regnum = V0_REGNUM;
4819 offset < TYPE_LENGTH (type);
4820 offset += mips_stack_argsize (), regnum++)
4822 int xfer = mips_stack_argsize ();
4824 if (offset + xfer > TYPE_LENGTH (type))
4825 xfer = TYPE_LENGTH (type) - offset;
4827 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4828 offset, xfer, regnum);
4829 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4836 mips_o32_extract_return_value (struct type *type,
4837 struct regcache *regcache,
4840 mips_o32_xfer_return_value (type, regcache, valbuf, NULL);
4844 mips_o32_store_return_value (struct type *type, char *valbuf)
4846 mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf);
4849 /* N32/N44 ABI stuff. */
4852 mips_n32n64_xfer_return_value (struct type *type,
4853 struct regcache *regcache,
4854 bfd_byte *in, const bfd_byte *out)
4856 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4857 if (TYPE_CODE (type) == TYPE_CODE_FLT
4858 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4860 /* A floating-point value belongs in the least significant part
4863 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4864 mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4865 TARGET_BYTE_ORDER, in, out, 0);
4867 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4868 && TYPE_NFIELDS (type) <= 2
4869 && TYPE_NFIELDS (type) >= 1
4870 && ((TYPE_NFIELDS (type) == 1
4871 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4873 || (TYPE_NFIELDS (type) == 2
4874 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4876 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4878 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4880 /* A struct that contains one or two floats. Each value is part
4881 in the least significant part of their floating point
4883 bfd_byte *reg = alloca (MAX_REGISTER_RAW_SIZE);
4886 for (field = 0, regnum = FP0_REGNUM;
4887 field < TYPE_NFIELDS (type);
4888 field++, regnum += 2)
4890 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4893 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4894 mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4895 TARGET_BYTE_ORDER, in, out, offset);
4898 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4899 || TYPE_CODE (type) == TYPE_CODE_UNION)
4901 /* A structure or union. Extract the left justified value,
4902 regardless of the byte order. I.e. DO NOT USE
4906 for (offset = 0, regnum = V0_REGNUM;
4907 offset < TYPE_LENGTH (type);
4908 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4910 int xfer = REGISTER_RAW_SIZE (regnum);
4911 if (offset + xfer > TYPE_LENGTH (type))
4912 xfer = TYPE_LENGTH (type) - offset;
4914 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4915 offset, xfer, regnum);
4916 mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4922 /* A scalar extract each part but least-significant-byte
4926 for (offset = 0, regnum = V0_REGNUM;
4927 offset < TYPE_LENGTH (type);
4928 offset += REGISTER_RAW_SIZE (regnum), regnum++)
4930 int xfer = REGISTER_RAW_SIZE (regnum);
4932 if (offset + xfer > TYPE_LENGTH (type))
4933 xfer = TYPE_LENGTH (type) - offset;
4935 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4936 offset, xfer, regnum);
4937 mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4944 mips_n32n64_extract_return_value (struct type *type,
4945 struct regcache *regcache,
4948 mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4952 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4954 mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4958 mips_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
4960 /* Nothing to do -- push_arguments does all the work. */
4964 mips_extract_struct_value_address (struct regcache *regcache)
4966 /* FIXME: This will only work at random. The caller passes the
4967 struct_return address in V0, but it is not preserved. It may
4968 still be there, or this may be a random value. */
4971 regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4975 /* Exported procedure: Is PC in the signal trampoline code */
4978 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4980 if (sigtramp_address == 0)
4982 return (pc >= sigtramp_address && pc < sigtramp_end);
4985 /* Root of all "set mips "/"show mips " commands. This will eventually be
4986 used for all MIPS-specific commands. */
4989 show_mips_command (char *args, int from_tty)
4991 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4995 set_mips_command (char *args, int from_tty)
4997 printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4998 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5001 /* Commands to show/set the MIPS FPU type. */
5004 show_mipsfpu_command (char *args, int from_tty)
5007 switch (MIPS_FPU_TYPE)
5009 case MIPS_FPU_SINGLE:
5010 fpu = "single-precision";
5012 case MIPS_FPU_DOUBLE:
5013 fpu = "double-precision";
5016 fpu = "absent (none)";
5019 internal_error (__FILE__, __LINE__, "bad switch");
5021 if (mips_fpu_type_auto)
5022 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5025 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5031 set_mipsfpu_command (char *args, int from_tty)
5033 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5034 show_mipsfpu_command (args, from_tty);
5038 set_mipsfpu_single_command (char *args, int from_tty)
5040 mips_fpu_type = MIPS_FPU_SINGLE;
5041 mips_fpu_type_auto = 0;
5042 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5046 set_mipsfpu_double_command (char *args, int from_tty)
5048 mips_fpu_type = MIPS_FPU_DOUBLE;
5049 mips_fpu_type_auto = 0;
5050 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5054 set_mipsfpu_none_command (char *args, int from_tty)
5056 mips_fpu_type = MIPS_FPU_NONE;
5057 mips_fpu_type_auto = 0;
5058 gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5062 set_mipsfpu_auto_command (char *args, int from_tty)
5064 mips_fpu_type_auto = 1;
5067 /* Command to set the processor type. */
5070 mips_set_processor_type_command (char *args, int from_tty)
5074 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5076 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5077 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5078 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5080 /* Restore the value. */
5081 tmp_mips_processor_type = xstrdup (mips_processor_type);
5086 if (!mips_set_processor_type (tmp_mips_processor_type))
5088 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5089 /* Restore its value. */
5090 tmp_mips_processor_type = xstrdup (mips_processor_type);
5095 mips_show_processor_type_command (char *args, int from_tty)
5099 /* Modify the actual processor type. */
5102 mips_set_processor_type (char *str)
5109 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5111 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5113 mips_processor_type = str;
5114 mips_processor_reg_names = mips_processor_type_table[i].regnames;
5116 /* FIXME tweak fpu flag too */
5123 /* Attempt to identify the particular processor model by reading the
5127 mips_read_processor_type (void)
5131 prid = read_register (PRID_REGNUM);
5133 if ((prid & ~0xf) == 0x700)
5134 return savestring ("r3041", strlen ("r3041"));
5139 /* Just like reinit_frame_cache, but with the right arguments to be
5140 callable as an sfunc. */
5143 reinit_frame_cache_sfunc (char *args, int from_tty,
5144 struct cmd_list_element *c)
5146 reinit_frame_cache ();
5150 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5152 mips_extra_func_info_t proc_desc;
5154 /* Search for the function containing this address. Set the low bit
5155 of the address when searching, in case we were given an even address
5156 that is the start of a 16-bit function. If we didn't do this,
5157 the search would fail because the symbol table says the function
5158 starts at an odd address, i.e. 1 byte past the given address. */
5159 memaddr = ADDR_BITS_REMOVE (memaddr);
5160 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
5162 /* Make an attempt to determine if this is a 16-bit function. If
5163 the procedure descriptor exists and the address therein is odd,
5164 it's definitely a 16-bit function. Otherwise, we have to just
5165 guess that if the address passed in is odd, it's 16-bits. */
5167 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5168 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5170 info->mach = pc_is_mips16 (memaddr) ?
5171 bfd_mach_mips16 : TM_PRINT_INSN_MACH;
5173 /* Round down the instruction address to the appropriate boundary. */
5174 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5176 /* Call the appropriate disassembler based on the target endian-ness. */
5177 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5178 return print_insn_big_mips (memaddr, info);
5180 return print_insn_little_mips (memaddr, info);
5183 /* Old-style breakpoint macros.
5184 The IDT board uses an unusual breakpoint value, and sometimes gets
5185 confused when it sees the usual MIPS breakpoint instruction. */
5187 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
5188 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
5189 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
5190 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
5191 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
5192 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
5193 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
5194 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
5196 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5197 counter value to determine whether a 16- or 32-bit breakpoint should be
5198 used. It returns a pointer to a string of bytes that encode a breakpoint
5199 instruction, stores the length of the string to *lenptr, and adjusts pc
5200 (if necessary) to point to the actual memory location where the
5201 breakpoint should be inserted. */
5203 static const unsigned char *
5204 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5206 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5208 if (pc_is_mips16 (*pcptr))
5210 static unsigned char mips16_big_breakpoint[] =
5211 MIPS16_BIG_BREAKPOINT;
5212 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5213 *lenptr = sizeof (mips16_big_breakpoint);
5214 return mips16_big_breakpoint;
5218 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
5219 static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
5220 static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
5222 *lenptr = sizeof (big_breakpoint);
5224 if (strcmp (target_shortname, "mips") == 0)
5225 return idt_big_breakpoint;
5226 else if (strcmp (target_shortname, "ddb") == 0
5227 || strcmp (target_shortname, "pmon") == 0
5228 || strcmp (target_shortname, "lsi") == 0)
5229 return pmon_big_breakpoint;
5231 return big_breakpoint;
5236 if (pc_is_mips16 (*pcptr))
5238 static unsigned char mips16_little_breakpoint[] =
5239 MIPS16_LITTLE_BREAKPOINT;
5240 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
5241 *lenptr = sizeof (mips16_little_breakpoint);
5242 return mips16_little_breakpoint;
5246 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
5247 static unsigned char pmon_little_breakpoint[] =
5248 PMON_LITTLE_BREAKPOINT;
5249 static unsigned char idt_little_breakpoint[] =
5250 IDT_LITTLE_BREAKPOINT;
5252 *lenptr = sizeof (little_breakpoint);
5254 if (strcmp (target_shortname, "mips") == 0)
5255 return idt_little_breakpoint;
5256 else if (strcmp (target_shortname, "ddb") == 0
5257 || strcmp (target_shortname, "pmon") == 0
5258 || strcmp (target_shortname, "lsi") == 0)
5259 return pmon_little_breakpoint;
5261 return little_breakpoint;
5266 /* If PC is in a mips16 call or return stub, return the address of the target
5267 PC, which is either the callee or the caller. There are several
5268 cases which must be handled:
5270 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5271 target PC is in $31 ($ra).
5272 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5273 and the target PC is in $2.
5274 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5275 before the jal instruction, this is effectively a call stub
5276 and the the target PC is in $2. Otherwise this is effectively
5277 a return stub and the target PC is in $18.
5279 See the source code for the stubs in gcc/config/mips/mips16.S for
5282 This function implements the SKIP_TRAMPOLINE_CODE macro.
5286 mips_skip_stub (CORE_ADDR pc)
5289 CORE_ADDR start_addr;
5291 /* Find the starting address and name of the function containing the PC. */
5292 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5295 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5296 target PC is in $31 ($ra). */
5297 if (strcmp (name, "__mips16_ret_sf") == 0
5298 || strcmp (name, "__mips16_ret_df") == 0)
5299 return read_signed_register (RA_REGNUM);
5301 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5303 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5304 and the target PC is in $2. */
5305 if (name[19] >= '0' && name[19] <= '9')
5306 return read_signed_register (2);
5308 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5309 before the jal instruction, this is effectively a call stub
5310 and the the target PC is in $2. Otherwise this is effectively
5311 a return stub and the target PC is in $18. */
5312 else if (name[19] == 's' || name[19] == 'd')
5314 if (pc == start_addr)
5316 /* Check if the target of the stub is a compiler-generated
5317 stub. Such a stub for a function bar might have a name
5318 like __fn_stub_bar, and might look like this:
5323 la $1,bar (becomes a lui/addiu pair)
5325 So scan down to the lui/addi and extract the target
5326 address from those two instructions. */
5328 CORE_ADDR target_pc = read_signed_register (2);
5332 /* See if the name of the target function is __fn_stub_*. */
5333 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5335 if (strncmp (name, "__fn_stub_", 10) != 0
5336 && strcmp (name, "etext") != 0
5337 && strcmp (name, "_etext") != 0)
5340 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5341 The limit on the search is arbitrarily set to 20
5342 instructions. FIXME. */
5343 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5345 inst = mips_fetch_instruction (target_pc);
5346 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5347 pc = (inst << 16) & 0xffff0000; /* high word */
5348 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5349 return pc | (inst & 0xffff); /* low word */
5352 /* Couldn't find the lui/addui pair, so return stub address. */
5356 /* This is the 'return' part of a call stub. The return
5357 address is in $r18. */
5358 return read_signed_register (18);
5361 return 0; /* not a stub */
5365 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5366 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5369 mips_in_call_stub (CORE_ADDR pc, char *name)
5371 CORE_ADDR start_addr;
5373 /* Find the starting address of the function containing the PC. If the
5374 caller didn't give us a name, look it up at the same time. */
5375 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5378 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5380 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5381 if (name[19] >= '0' && name[19] <= '9')
5383 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5384 before the jal instruction, this is effectively a call stub. */
5385 else if (name[19] == 's' || name[19] == 'd')
5386 return pc == start_addr;
5389 return 0; /* not a stub */
5393 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5394 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5397 mips_in_return_stub (CORE_ADDR pc, char *name)
5399 CORE_ADDR start_addr;
5401 /* Find the starting address of the function containing the PC. */
5402 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5405 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5406 if (strcmp (name, "__mips16_ret_sf") == 0
5407 || strcmp (name, "__mips16_ret_df") == 0)
5410 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5411 i.e. after the jal instruction, this is effectively a return stub. */
5412 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5413 && (name[19] == 's' || name[19] == 'd')
5414 && pc != start_addr)
5417 return 0; /* not a stub */
5421 /* Return non-zero if the PC is in a library helper function that should
5422 be ignored. This implements the IGNORE_HELPER_CALL macro. */
5425 mips_ignore_helper (CORE_ADDR pc)
5429 /* Find the starting address and name of the function containing the PC. */
5430 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5433 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5434 that we want to ignore. */
5435 return (strcmp (name, "__mips16_ret_sf") == 0
5436 || strcmp (name, "__mips16_ret_df") == 0);
5440 /* Return a location where we can set a breakpoint that will be hit
5441 when an inferior function call returns. This is normally the
5442 program's entry point. Executables that don't have an entry
5443 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5444 whose address is the location where the breakpoint should be placed. */
5447 mips_call_dummy_address (void)
5449 struct minimal_symbol *sym;
5451 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5453 return SYMBOL_VALUE_ADDRESS (sym);
5455 return entry_point_address ();
5459 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5460 the register stored on the stack (32) is different to its real raw
5461 size (64). The below ensures that registers are fetched from the
5462 stack using their ABI size and then stored into the RAW_BUFFER
5463 using their raw size.
5465 The alternative to adding this function would be to add an ABI
5466 macro - REGISTER_STACK_SIZE(). */
5469 mips_get_saved_register (char *raw_buffer,
5472 struct frame_info *frame,
5474 enum lval_type *lvalp)
5477 enum lval_type lvalx;
5481 if (!target_has_registers)
5482 error ("No registers.");
5484 /* Make certain that all needed parameters are present. */
5489 if (optimizedp == NULL)
5490 optimizedp = &optimizedx;
5491 frame_register_unwind (get_next_frame (frame), regnum, optimizedp, lvalp,
5492 addrp, &realnum, raw_buffer);
5493 /* FIXME: cagney/2002-09-13: This is just so bad. The MIPS should
5494 have a pseudo register range that correspons to the ABI's, rather
5495 than the ISA's, view of registers. These registers would then
5496 implicitly describe their size and hence could be used without
5497 the below munging. */
5498 if ((*lvalp) == lval_memory)
5500 if (raw_buffer != NULL)
5504 /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5506 LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5507 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5513 /* Immediately after a function call, return the saved pc.
5514 Can't always go through the frames for this because on some machines
5515 the new frame is not set up until the new function executes
5516 some instructions. */
5519 mips_saved_pc_after_call (struct frame_info *frame)
5521 return read_signed_register (RA_REGNUM);
5525 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5529 mips_stab_reg_to_regnum (int num)
5534 return num + FP0_REGNUM - 38;
5537 /* Convert a ecoff register number to a gdb REGNUM */
5540 mips_ecoff_reg_to_regnum (int num)
5545 return num + FP0_REGNUM - 32;
5548 /* Convert an integer into an address. By first converting the value
5549 into a pointer and then extracting it signed, the address is
5550 guarenteed to be correctly sign extended. */
5553 mips_integer_to_address (struct type *type, void *buf)
5555 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5556 LONGEST val = unpack_long (type, buf);
5557 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5558 return extract_signed_integer (tmp,
5559 TYPE_LENGTH (builtin_type_void_data_ptr));
5563 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5565 enum mips_abi *abip = (enum mips_abi *) obj;
5566 const char *name = bfd_get_section_name (abfd, sect);
5568 if (*abip != MIPS_ABI_UNKNOWN)
5571 if (strncmp (name, ".mdebug.", 8) != 0)
5574 if (strcmp (name, ".mdebug.abi32") == 0)
5575 *abip = MIPS_ABI_O32;
5576 else if (strcmp (name, ".mdebug.abiN32") == 0)
5577 *abip = MIPS_ABI_N32;
5578 else if (strcmp (name, ".mdebug.abi64") == 0)
5579 *abip = MIPS_ABI_N64;
5580 else if (strcmp (name, ".mdebug.abiO64") == 0)
5581 *abip = MIPS_ABI_O64;
5582 else if (strcmp (name, ".mdebug.eabi32") == 0)
5583 *abip = MIPS_ABI_EABI32;
5584 else if (strcmp (name, ".mdebug.eabi64") == 0)
5585 *abip = MIPS_ABI_EABI64;
5587 warning ("unsupported ABI %s.", name + 8);
5590 static enum mips_abi
5591 global_mips_abi (void)
5595 for (i = 0; mips_abi_strings[i] != NULL; i++)
5596 if (mips_abi_strings[i] == mips_abi_string)
5597 return (enum mips_abi) i;
5599 internal_error (__FILE__, __LINE__,
5600 "unknown ABI string");
5603 static struct gdbarch *
5604 mips_gdbarch_init (struct gdbarch_info info,
5605 struct gdbarch_list *arches)
5607 static LONGEST mips_call_dummy_words[] =
5609 struct gdbarch *gdbarch;
5610 struct gdbarch_tdep *tdep;
5612 enum mips_abi mips_abi, found_abi, wanted_abi;
5614 /* Reset the disassembly info, in case it was set to something
5616 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5617 tm_print_insn_info.arch = bfd_arch_unknown;
5618 tm_print_insn_info.mach = 0;
5624 /* First of all, extract the elf_flags, if available. */
5625 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5626 elf_flags = elf_elfheader (info.abfd)->e_flags;
5629 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5630 switch ((elf_flags & EF_MIPS_ABI))
5632 case E_MIPS_ABI_O32:
5633 mips_abi = MIPS_ABI_O32;
5635 case E_MIPS_ABI_O64:
5636 mips_abi = MIPS_ABI_O64;
5638 case E_MIPS_ABI_EABI32:
5639 mips_abi = MIPS_ABI_EABI32;
5641 case E_MIPS_ABI_EABI64:
5642 mips_abi = MIPS_ABI_EABI64;
5645 if ((elf_flags & EF_MIPS_ABI2))
5646 mips_abi = MIPS_ABI_N32;
5648 mips_abi = MIPS_ABI_UNKNOWN;
5652 /* GCC creates a pseudo-section whose name describes the ABI. */
5653 if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5654 bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5656 /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5657 Use the ABI from the last architecture if there is one. */
5658 if (info.abfd == NULL && arches != NULL)
5659 mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5661 /* Try the architecture for any hint of the correct ABI. */
5662 if (mips_abi == MIPS_ABI_UNKNOWN
5663 && info.bfd_arch_info != NULL
5664 && info.bfd_arch_info->arch == bfd_arch_mips)
5666 switch (info.bfd_arch_info->mach)
5668 case bfd_mach_mips3900:
5669 mips_abi = MIPS_ABI_EABI32;
5671 case bfd_mach_mips4100:
5672 case bfd_mach_mips5000:
5673 mips_abi = MIPS_ABI_EABI64;
5675 case bfd_mach_mips8000:
5676 case bfd_mach_mips10000:
5677 /* On Irix, ELF64 executables use the N64 ABI. The
5678 pseudo-sections which describe the ABI aren't present
5679 on IRIX. (Even for executables created by gcc.) */
5680 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5681 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5682 mips_abi = MIPS_ABI_N64;
5684 mips_abi = MIPS_ABI_N32;
5689 if (mips_abi == MIPS_ABI_UNKNOWN)
5690 mips_abi = MIPS_ABI_O32;
5692 /* Now that we have found what the ABI for this binary would be,
5693 check whether the user is overriding it. */
5694 found_abi = mips_abi;
5695 wanted_abi = global_mips_abi ();
5696 if (wanted_abi != MIPS_ABI_UNKNOWN)
5697 mips_abi = wanted_abi;
5701 fprintf_unfiltered (gdb_stdlog,
5702 "mips_gdbarch_init: elf_flags = 0x%08x\n",
5704 fprintf_unfiltered (gdb_stdlog,
5705 "mips_gdbarch_init: mips_abi = %d\n",
5707 fprintf_unfiltered (gdb_stdlog,
5708 "mips_gdbarch_init: found_mips_abi = %d\n",
5712 /* try to find a pre-existing architecture */
5713 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5715 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5717 /* MIPS needs to be pedantic about which ABI the object is
5719 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5721 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5723 return arches->gdbarch;
5726 /* Need a new architecture. Fill in a target specific vector. */
5727 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5728 gdbarch = gdbarch_alloc (&info, tdep);
5729 tdep->elf_flags = elf_flags;
5731 /* Initially set everything according to the default ABI/ISA. */
5732 set_gdbarch_short_bit (gdbarch, 16);
5733 set_gdbarch_int_bit (gdbarch, 32);
5734 set_gdbarch_float_bit (gdbarch, 32);
5735 set_gdbarch_double_bit (gdbarch, 64);
5736 set_gdbarch_long_double_bit (gdbarch, 64);
5737 set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size);
5738 set_gdbarch_max_register_raw_size (gdbarch, 8);
5739 set_gdbarch_max_register_virtual_size (gdbarch, 8);
5740 tdep->found_abi = found_abi;
5741 tdep->mips_abi = mips_abi;
5743 set_gdbarch_elf_make_msymbol_special (gdbarch,
5744 mips_elf_make_msymbol_special);
5746 if (info.osabi == GDB_OSABI_IRIX)
5747 set_gdbarch_num_regs (gdbarch, 71);
5749 set_gdbarch_num_regs (gdbarch, 90);
5754 set_gdbarch_push_arguments (gdbarch, mips_o32_push_arguments);
5755 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5756 set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5757 tdep->mips_default_saved_regsize = 4;
5758 tdep->mips_default_stack_argsize = 4;
5759 tdep->mips_fp_register_double = 0;
5760 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5761 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5762 tdep->gdb_target_is_mips64 = 0;
5763 tdep->default_mask_address_p = 0;
5764 set_gdbarch_long_bit (gdbarch, 32);
5765 set_gdbarch_ptr_bit (gdbarch, 32);
5766 set_gdbarch_long_long_bit (gdbarch, 64);
5767 set_gdbarch_reg_struct_has_addr (gdbarch,
5768 mips_o32_reg_struct_has_addr);
5769 set_gdbarch_use_struct_convention (gdbarch,
5770 mips_o32_use_struct_convention);
5773 set_gdbarch_push_arguments (gdbarch, mips_o64_push_arguments);
5774 set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5775 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5776 tdep->mips_default_saved_regsize = 8;
5777 tdep->mips_default_stack_argsize = 8;
5778 tdep->mips_fp_register_double = 1;
5779 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5780 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5781 tdep->gdb_target_is_mips64 = 1;
5782 tdep->default_mask_address_p = 0;
5783 set_gdbarch_long_bit (gdbarch, 32);
5784 set_gdbarch_ptr_bit (gdbarch, 32);
5785 set_gdbarch_long_long_bit (gdbarch, 64);
5786 set_gdbarch_reg_struct_has_addr (gdbarch,
5787 mips_o32_reg_struct_has_addr);
5788 set_gdbarch_use_struct_convention (gdbarch,
5789 mips_o32_use_struct_convention);
5791 case MIPS_ABI_EABI32:
5792 set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
5793 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5794 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5795 tdep->mips_default_saved_regsize = 4;
5796 tdep->mips_default_stack_argsize = 4;
5797 tdep->mips_fp_register_double = 0;
5798 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5799 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5800 tdep->gdb_target_is_mips64 = 0;
5801 tdep->default_mask_address_p = 0;
5802 set_gdbarch_long_bit (gdbarch, 32);
5803 set_gdbarch_ptr_bit (gdbarch, 32);
5804 set_gdbarch_long_long_bit (gdbarch, 64);
5805 set_gdbarch_reg_struct_has_addr (gdbarch,
5806 mips_eabi_reg_struct_has_addr);
5807 set_gdbarch_use_struct_convention (gdbarch,
5808 mips_eabi_use_struct_convention);
5810 case MIPS_ABI_EABI64:
5811 set_gdbarch_push_arguments (gdbarch, mips_eabi_push_arguments);
5812 set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5813 set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5814 tdep->mips_default_saved_regsize = 8;
5815 tdep->mips_default_stack_argsize = 8;
5816 tdep->mips_fp_register_double = 1;
5817 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5818 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5819 tdep->gdb_target_is_mips64 = 1;
5820 tdep->default_mask_address_p = 0;
5821 set_gdbarch_long_bit (gdbarch, 64);
5822 set_gdbarch_ptr_bit (gdbarch, 64);
5823 set_gdbarch_long_long_bit (gdbarch, 64);
5824 set_gdbarch_reg_struct_has_addr (gdbarch,
5825 mips_eabi_reg_struct_has_addr);
5826 set_gdbarch_use_struct_convention (gdbarch,
5827 mips_eabi_use_struct_convention);
5830 set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
5831 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5832 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_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 = FPA0_REGNUM + 8 - 1;
5838 tdep->gdb_target_is_mips64 = 1;
5839 tdep->default_mask_address_p = 0;
5840 set_gdbarch_long_bit (gdbarch, 32);
5841 set_gdbarch_ptr_bit (gdbarch, 32);
5842 set_gdbarch_long_long_bit (gdbarch, 64);
5844 /* Set up the disassembler info, so that we get the right
5845 register names from libopcodes. */
5846 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5847 tm_print_insn_info.arch = bfd_arch_mips;
5848 if (info.bfd_arch_info != NULL
5849 && info.bfd_arch_info->arch == bfd_arch_mips
5850 && info.bfd_arch_info->mach)
5851 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5853 tm_print_insn_info.mach = bfd_mach_mips8000;
5855 set_gdbarch_use_struct_convention (gdbarch,
5856 mips_n32n64_use_struct_convention);
5857 set_gdbarch_reg_struct_has_addr (gdbarch,
5858 mips_n32n64_reg_struct_has_addr);
5861 set_gdbarch_push_arguments (gdbarch, mips_n32n64_push_arguments);
5862 set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5863 set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5864 tdep->mips_default_saved_regsize = 8;
5865 tdep->mips_default_stack_argsize = 8;
5866 tdep->mips_fp_register_double = 1;
5867 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5868 tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5869 tdep->gdb_target_is_mips64 = 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);
5875 /* Set up the disassembler info, so that we get the right
5876 register names from libopcodes. */
5877 tm_print_insn_info.flavour = bfd_target_elf_flavour;
5878 tm_print_insn_info.arch = bfd_arch_mips;
5879 if (info.bfd_arch_info != NULL
5880 && info.bfd_arch_info->arch == bfd_arch_mips
5881 && info.bfd_arch_info->mach)
5882 tm_print_insn_info.mach = info.bfd_arch_info->mach;
5884 tm_print_insn_info.mach = bfd_mach_mips8000;
5886 set_gdbarch_use_struct_convention (gdbarch,
5887 mips_n32n64_use_struct_convention);
5888 set_gdbarch_reg_struct_has_addr (gdbarch,
5889 mips_n32n64_reg_struct_has_addr);
5892 internal_error (__FILE__, __LINE__,
5893 "unknown ABI in switch");
5896 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5897 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5900 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5901 flag in object files because to do so would make it impossible to
5902 link with libraries compiled without "-gp32". This is
5903 unnecessarily restrictive.
5905 We could solve this problem by adding "-gp32" multilibs to gcc,
5906 but to set this flag before gcc is built with such multilibs will
5907 break too many systems.''
5909 But even more unhelpfully, the default linker output target for
5910 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5911 for 64-bit programs - you need to change the ABI to change this,
5912 and not all gcc targets support that currently. Therefore using
5913 this flag to detect 32-bit mode would do the wrong thing given
5914 the current gcc - it would make GDB treat these 64-bit programs
5915 as 32-bit programs by default. */
5917 /* enable/disable the MIPS FPU */
5918 if (!mips_fpu_type_auto)
5919 tdep->mips_fpu_type = mips_fpu_type;
5920 else if (info.bfd_arch_info != NULL
5921 && info.bfd_arch_info->arch == bfd_arch_mips)
5922 switch (info.bfd_arch_info->mach)
5924 case bfd_mach_mips3900:
5925 case bfd_mach_mips4100:
5926 case bfd_mach_mips4111:
5927 tdep->mips_fpu_type = MIPS_FPU_NONE;
5929 case bfd_mach_mips4650:
5930 tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5933 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5937 tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5939 /* MIPS version of register names. NOTE: At present the MIPS
5940 register name management is part way between the old -
5941 #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5942 Further work on it is required. */
5943 /* NOTE: many targets (esp. embedded) do not go thru the
5944 gdbarch_register_name vector at all, instead bypassing it
5945 by defining REGISTER_NAMES. */
5946 set_gdbarch_register_name (gdbarch, mips_register_name);
5947 set_gdbarch_read_pc (gdbarch, mips_read_pc);
5948 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5949 set_gdbarch_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base. */
5950 set_gdbarch_read_sp (gdbarch, mips_read_sp);
5951 set_gdbarch_write_sp (gdbarch, generic_target_write_sp);
5953 /* Add/remove bits from an address. The MIPS needs be careful to
5954 ensure that all 32 bit addresses are sign extended to 64 bits. */
5955 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5957 /* There's a mess in stack frame creation. See comments in
5958 blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST. */
5959 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5960 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5962 /* Map debug register numbers onto internal register numbers. */
5963 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5964 set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_ecoff_reg_to_regnum);
5966 /* Initialize a frame */
5967 set_gdbarch_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5968 set_gdbarch_frame_init_saved_regs (gdbarch, mips_frame_init_saved_regs);
5970 /* MIPS version of CALL_DUMMY */
5972 set_gdbarch_call_dummy_p (gdbarch, 1);
5973 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
5974 set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5975 set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
5976 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
5977 set_gdbarch_pop_frame (gdbarch, mips_pop_frame);
5978 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
5979 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
5980 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
5981 set_gdbarch_call_dummy_length (gdbarch, 0);
5982 set_gdbarch_fix_call_dummy (gdbarch, mips_fix_call_dummy);
5983 set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words);
5984 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words));
5985 set_gdbarch_push_return_address (gdbarch, mips_push_return_address);
5986 set_gdbarch_frame_align (gdbarch, mips_frame_align);
5987 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5988 set_gdbarch_register_convertible (gdbarch, mips_register_convertible);
5989 set_gdbarch_register_convert_to_virtual (gdbarch,
5990 mips_register_convert_to_virtual);
5991 set_gdbarch_register_convert_to_raw (gdbarch,
5992 mips_register_convert_to_raw);
5994 set_gdbarch_frame_chain (gdbarch, mips_frame_chain);
5995 set_gdbarch_frameless_function_invocation (gdbarch,
5996 generic_frameless_function_invocation_not);
5997 set_gdbarch_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5998 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
5999 set_gdbarch_frame_args_skip (gdbarch, 0);
6001 set_gdbarch_get_saved_register (gdbarch, mips_get_saved_register);
6003 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6004 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6005 set_gdbarch_decr_pc_after_break (gdbarch, 0);
6007 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6008 set_gdbarch_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
6010 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6011 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6012 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6014 set_gdbarch_function_start_offset (gdbarch, 0);
6016 /* There are MIPS targets which do not yet use this since they still
6017 define REGISTER_VIRTUAL_TYPE. */
6018 set_gdbarch_register_virtual_type (gdbarch, mips_register_virtual_type);
6019 set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
6021 set_gdbarch_deprecated_do_registers_info (gdbarch, mips_do_registers_info);
6022 set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
6024 /* Hook in OS ABI-specific overrides, if they have been registered. */
6025 gdbarch_init_osabi (info, gdbarch);
6027 set_gdbarch_store_struct_return (gdbarch, mips_store_struct_return);
6028 set_gdbarch_extract_struct_value_address (gdbarch,
6029 mips_extract_struct_value_address);
6031 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6033 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6034 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6040 mips_abi_update (char *ignore_args, int from_tty,
6041 struct cmd_list_element *c)
6043 struct gdbarch_info info;
6045 /* Force the architecture to update, and (if it's a MIPS architecture)
6046 mips_gdbarch_init will take care of the rest. */
6047 gdbarch_info_init (&info);
6048 gdbarch_update_p (info);
6052 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6054 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6058 int ef_mips_32bitmode;
6059 /* determine the ISA */
6060 switch (tdep->elf_flags & EF_MIPS_ARCH)
6078 /* determine the size of a pointer */
6079 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6080 fprintf_unfiltered (file,
6081 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6083 fprintf_unfiltered (file,
6084 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6086 fprintf_unfiltered (file,
6087 "mips_dump_tdep: ef_mips_arch = %d\n",
6089 fprintf_unfiltered (file,
6090 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6092 mips_abi_strings[tdep->mips_abi]);
6093 fprintf_unfiltered (file,
6094 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6095 mips_mask_address_p (),
6096 tdep->default_mask_address_p);
6098 fprintf_unfiltered (file,
6099 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6100 FP_REGISTER_DOUBLE);
6101 fprintf_unfiltered (file,
6102 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6103 MIPS_DEFAULT_FPU_TYPE,
6104 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6105 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6106 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6108 fprintf_unfiltered (file,
6109 "mips_dump_tdep: MIPS_EABI = %d\n",
6111 fprintf_unfiltered (file,
6112 "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6113 MIPS_LAST_FP_ARG_REGNUM,
6114 MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6115 fprintf_unfiltered (file,
6116 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6118 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6119 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6120 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6122 fprintf_unfiltered (file,
6123 "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6124 MIPS_DEFAULT_SAVED_REGSIZE);
6125 fprintf_unfiltered (file,
6126 "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6127 FP_REGISTER_DOUBLE);
6128 fprintf_unfiltered (file,
6129 "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6130 MIPS_DEFAULT_STACK_ARGSIZE);
6131 fprintf_unfiltered (file,
6132 "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6133 MIPS_STACK_ARGSIZE);
6134 fprintf_unfiltered (file,
6135 "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6137 fprintf_unfiltered (file,
6138 "mips_dump_tdep: A0_REGNUM = %d\n",
6140 fprintf_unfiltered (file,
6141 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6142 XSTRING (ADDR_BITS_REMOVE(ADDR)));
6143 fprintf_unfiltered (file,
6144 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6145 XSTRING (ATTACH_DETACH));
6146 fprintf_unfiltered (file,
6147 "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6149 fprintf_unfiltered (file,
6150 "mips_dump_tdep: BIG_BREAKPOINT = delete?\n");
6151 fprintf_unfiltered (file,
6152 "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6154 fprintf_unfiltered (file,
6155 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6156 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6157 fprintf_unfiltered (file,
6158 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6159 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6160 fprintf_unfiltered (file,
6161 "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6163 fprintf_unfiltered (file,
6164 "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6166 fprintf_unfiltered (file,
6167 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6168 FIRST_EMBED_REGNUM);
6169 fprintf_unfiltered (file,
6170 "mips_dump_tdep: FPA0_REGNUM = %d\n",
6172 fprintf_unfiltered (file,
6173 "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6174 GDB_TARGET_IS_MIPS64);
6175 fprintf_unfiltered (file,
6176 "mips_dump_tdep: GEN_REG_SAVE_MASK = %d\n",
6178 fprintf_unfiltered (file,
6179 "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6180 XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6181 fprintf_unfiltered (file,
6182 "mips_dump_tdep: HI_REGNUM = %d\n",
6184 fprintf_unfiltered (file,
6185 "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n");
6186 fprintf_unfiltered (file,
6187 "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n");
6188 fprintf_unfiltered (file,
6189 "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6190 XSTRING (IGNORE_HELPER_CALL (PC)));
6191 fprintf_unfiltered (file,
6192 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6193 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6194 fprintf_unfiltered (file,
6195 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6196 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6197 fprintf_unfiltered (file,
6198 "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n");
6199 fprintf_unfiltered (file,
6200 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6202 fprintf_unfiltered (file,
6203 "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n");
6204 fprintf_unfiltered (file,
6205 "mips_dump_tdep: LO_REGNUM = %d\n",
6207 #ifdef MACHINE_CPROC_FP_OFFSET
6208 fprintf_unfiltered (file,
6209 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6210 MACHINE_CPROC_FP_OFFSET);
6212 #ifdef MACHINE_CPROC_PC_OFFSET
6213 fprintf_unfiltered (file,
6214 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6215 MACHINE_CPROC_PC_OFFSET);
6217 #ifdef MACHINE_CPROC_SP_OFFSET
6218 fprintf_unfiltered (file,
6219 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6220 MACHINE_CPROC_SP_OFFSET);
6222 fprintf_unfiltered (file,
6223 "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n");
6224 fprintf_unfiltered (file,
6225 "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n");
6226 fprintf_unfiltered (file,
6227 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6229 fprintf_unfiltered (file,
6230 "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n");
6231 fprintf_unfiltered (file,
6232 "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6233 fprintf_unfiltered (file,
6234 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6235 fprintf_unfiltered (file,
6236 "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6238 fprintf_unfiltered (file,
6239 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6240 MIPS_LAST_ARG_REGNUM,
6241 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6242 fprintf_unfiltered (file,
6243 "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6245 fprintf_unfiltered (file,
6246 "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6247 fprintf_unfiltered (file,
6248 "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6249 MIPS_SAVED_REGSIZE);
6250 fprintf_unfiltered (file,
6251 "mips_dump_tdep: OP_LDFPR = used?\n");
6252 fprintf_unfiltered (file,
6253 "mips_dump_tdep: OP_LDGPR = used?\n");
6254 fprintf_unfiltered (file,
6255 "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n");
6256 fprintf_unfiltered (file,
6257 "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n");
6258 fprintf_unfiltered (file,
6259 "mips_dump_tdep: PRID_REGNUM = %d\n",
6261 fprintf_unfiltered (file,
6262 "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6263 XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6264 fprintf_unfiltered (file,
6265 "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6266 fprintf_unfiltered (file,
6267 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6268 fprintf_unfiltered (file,
6269 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6270 fprintf_unfiltered (file,
6271 "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6272 fprintf_unfiltered (file,
6273 "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6274 fprintf_unfiltered (file,
6275 "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6276 fprintf_unfiltered (file,
6277 "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6278 fprintf_unfiltered (file,
6279 "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6280 fprintf_unfiltered (file,
6281 "mips_dump_tdep: PROC_PC_REG = function?\n");
6282 fprintf_unfiltered (file,
6283 "mips_dump_tdep: PROC_REG_MASK = function?\n");
6284 fprintf_unfiltered (file,
6285 "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6286 fprintf_unfiltered (file,
6287 "mips_dump_tdep: PROC_SYMBOL = function?\n");
6288 fprintf_unfiltered (file,
6289 "mips_dump_tdep: PS_REGNUM = %d\n",
6291 fprintf_unfiltered (file,
6292 "mips_dump_tdep: PUSH_FP_REGNUM = %d\n",
6294 fprintf_unfiltered (file,
6295 "mips_dump_tdep: RA_REGNUM = %d\n",
6297 fprintf_unfiltered (file,
6298 "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6299 XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6300 fprintf_unfiltered (file,
6301 "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6302 XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6303 fprintf_unfiltered (file,
6304 "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6305 fprintf_unfiltered (file,
6306 "mips_dump_tdep: ROUND_DOWN = function?\n");
6307 fprintf_unfiltered (file,
6308 "mips_dump_tdep: ROUND_UP = function?\n");
6310 fprintf_unfiltered (file,
6311 "mips_dump_tdep: SAVED_BYTES = %d\n",
6315 fprintf_unfiltered (file,
6316 "mips_dump_tdep: SAVED_FP = %d\n",
6320 fprintf_unfiltered (file,
6321 "mips_dump_tdep: SAVED_PC = %d\n",
6324 fprintf_unfiltered (file,
6325 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6326 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6327 fprintf_unfiltered (file,
6328 "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6329 fprintf_unfiltered (file,
6330 "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6332 fprintf_unfiltered (file,
6333 "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6334 SIGFRAME_FPREGSAVE_OFF);
6335 fprintf_unfiltered (file,
6336 "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6338 fprintf_unfiltered (file,
6339 "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6340 SIGFRAME_REGSAVE_OFF);
6341 fprintf_unfiltered (file,
6342 "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6344 fprintf_unfiltered (file,
6345 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6346 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6347 fprintf_unfiltered (file,
6348 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6349 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6350 fprintf_unfiltered (file,
6351 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6352 SOFTWARE_SINGLE_STEP_P ());
6353 fprintf_unfiltered (file,
6354 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6355 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6356 #ifdef STACK_END_ADDR
6357 fprintf_unfiltered (file,
6358 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6361 fprintf_unfiltered (file,
6362 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6363 XSTRING (STEP_SKIPS_DELAY (PC)));
6364 fprintf_unfiltered (file,
6365 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6366 STEP_SKIPS_DELAY_P);
6367 fprintf_unfiltered (file,
6368 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6369 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6370 fprintf_unfiltered (file,
6371 "mips_dump_tdep: T9_REGNUM = %d\n",
6373 fprintf_unfiltered (file,
6374 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6375 fprintf_unfiltered (file,
6376 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6377 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6378 fprintf_unfiltered (file,
6379 "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6380 XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6381 fprintf_unfiltered (file,
6382 "mips_dump_tdep: TARGET_MIPS = used?\n");
6383 fprintf_unfiltered (file,
6384 "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n",
6385 XSTRING (TM_PRINT_INSN_MACH));
6387 fprintf_unfiltered (file,
6388 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6389 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6392 fprintf_unfiltered (file,
6393 "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6396 #ifdef TRACE_FLAVOR_SIZE
6397 fprintf_unfiltered (file,
6398 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6402 fprintf_unfiltered (file,
6403 "mips_dump_tdep: TRACE_SET # %s\n",
6404 XSTRING (TRACE_SET (X,STATE)));
6406 fprintf_unfiltered (file,
6407 "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n");
6408 #ifdef UNUSED_REGNUM
6409 fprintf_unfiltered (file,
6410 "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6413 fprintf_unfiltered (file,
6414 "mips_dump_tdep: V0_REGNUM = %d\n",
6416 fprintf_unfiltered (file,
6417 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6418 (long) VM_MIN_ADDRESS);
6420 fprintf_unfiltered (file,
6421 "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6424 fprintf_unfiltered (file,
6425 "mips_dump_tdep: ZERO_REGNUM = %d\n",
6427 fprintf_unfiltered (file,
6428 "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6433 _initialize_mips_tdep (void)
6435 static struct cmd_list_element *mipsfpulist = NULL;
6436 struct cmd_list_element *c;
6438 mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6439 if (MIPS_ABI_LAST + 1
6440 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6441 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6443 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6444 if (!tm_print_insn) /* Someone may have already set it */
6445 tm_print_insn = gdb_print_insn_mips;
6447 /* Add root prefix command for all "set mips"/"show mips" commands */
6448 add_prefix_cmd ("mips", no_class, set_mips_command,
6449 "Various MIPS specific commands.",
6450 &setmipscmdlist, "set mips ", 0, &setlist);
6452 add_prefix_cmd ("mips", no_class, show_mips_command,
6453 "Various MIPS specific commands.",
6454 &showmipscmdlist, "show mips ", 0, &showlist);
6456 /* Allow the user to override the saved register size. */
6457 add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6460 &mips_saved_regsize_string, "\
6461 Set size of general purpose registers saved on the stack.\n\
6462 This option can be set to one of:\n\
6463 32 - Force GDB to treat saved GP registers as 32-bit\n\
6464 64 - Force GDB to treat saved GP registers as 64-bit\n\
6465 auto - Allow GDB to use the target's default setting or autodetect the\n\
6466 saved GP register size from information contained in the executable.\n\
6471 /* Allow the user to override the argument stack size. */
6472 add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6475 &mips_stack_argsize_string, "\
6476 Set the amount of stack space reserved for each argument.\n\
6477 This option can be set to one of:\n\
6478 32 - Force GDB to allocate 32-bit chunks per argument\n\
6479 64 - Force GDB to allocate 64-bit chunks per argument\n\
6480 auto - Allow GDB to determine the correct setting from the current\n\
6481 target and executable (default)",
6485 /* Allow the user to override the ABI. */
6486 c = add_set_enum_cmd
6487 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6488 "Set the ABI used by this program.\n"
6489 "This option can be set to one of:\n"
6490 " auto - the default ABI associated with the current binary\n"
6498 add_show_from_set (c, &showmipscmdlist);
6499 set_cmd_sfunc (c, mips_abi_update);
6501 /* Let the user turn off floating point and set the fence post for
6502 heuristic_proc_start. */
6504 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6505 "Set use of MIPS floating-point coprocessor.",
6506 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6507 add_cmd ("single", class_support, set_mipsfpu_single_command,
6508 "Select single-precision MIPS floating-point coprocessor.",
6510 add_cmd ("double", class_support, set_mipsfpu_double_command,
6511 "Select double-precision MIPS floating-point coprocessor.",
6513 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6514 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6515 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6516 add_cmd ("none", class_support, set_mipsfpu_none_command,
6517 "Select no MIPS floating-point coprocessor.",
6519 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6520 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6521 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6522 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6523 "Select MIPS floating-point coprocessor automatically.",
6525 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6526 "Show current use of MIPS floating-point coprocessor target.",
6529 /* We really would like to have both "0" and "unlimited" work, but
6530 command.c doesn't deal with that. So make it a var_zinteger
6531 because the user can always use "999999" or some such for unlimited. */
6532 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6533 (char *) &heuristic_fence_post,
6535 Set the distance searched for the start of a function.\n\
6536 If you are debugging a stripped executable, GDB needs to search through the\n\
6537 program for the start of a function. This command sets the distance of the\n\
6538 search. The only need to set it is when debugging a stripped executable.",
6540 /* We need to throw away the frame cache when we set this, since it
6541 might change our ability to get backtraces. */
6542 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6543 add_show_from_set (c, &showlist);
6545 /* Allow the user to control whether the upper bits of 64-bit
6546 addresses should be zeroed. */
6547 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6548 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6549 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6550 allow GDB to determine the correct value.\n", "\
6551 Show zeroing of upper 32 bits of 64-bit addresses.",
6552 NULL, show_mask_address,
6553 &setmipscmdlist, &showmipscmdlist);
6555 /* Allow the user to control the size of 32 bit registers within the
6556 raw remote packet. */
6557 add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6560 (char *)&mips64_transfers_32bit_regs_p, "\
6561 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6562 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6563 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6564 64 bits for others. Use \"off\" to disable compatibility mode",
6568 /* Debug this files internals. */
6569 add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6570 &mips_debug, "Set mips debugging.\n\
6571 When non-zero, mips specific debugging is enabled.", &setdebuglist),