]> Git Repo - binutils.git/blob - gdb/mips-tdep.c
2003-06-13 Andrew Cagney <[email protected]>
[binutils.git] / gdb / mips-tdep.c
1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
2
3    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4    1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
6    Contributed by Alessandro Forin([email protected]) at CMU
7    and by Per Bothner([email protected]) at U.Wisconsin.
8
9    This file is part of GDB.
10
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.
15
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.
20
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.  */
25
26 #include "defs.h"
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
29 #include "frame.h"
30 #include "inferior.h"
31 #include "symtab.h"
32 #include "value.h"
33 #include "gdbcmd.h"
34 #include "language.h"
35 #include "gdbcore.h"
36 #include "symfile.h"
37 #include "objfiles.h"
38 #include "gdbtypes.h"
39 #include "target.h"
40 #include "arch-utils.h"
41 #include "regcache.h"
42 #include "osabi.h"
43 #include "mips-tdep.h"
44 #include "block.h"
45
46 #include "opcode/mips.h"
47 #include "elf/mips.h"
48 #include "elf-bfd.h"
49 #include "symcat.h"
50
51 static void set_reg_offset (CORE_ADDR *saved_regs, int regnum, CORE_ADDR off);
52
53 /* A useful bit in the CP0 status register (PS_REGNUM).  */
54 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip.  */
55 #define ST0_FR (1 << 26)
56
57 /* The sizes of floating point registers.  */
58
59 enum
60 {
61   MIPS_FPU_SINGLE_REGSIZE = 4,
62   MIPS_FPU_DOUBLE_REGSIZE = 8
63 };
64
65
66 static const char *mips_abi_string;
67
68 static const char *mips_abi_strings[] = {
69   "auto",
70   "n32",
71   "o32",
72   "n64",
73   "o64",
74   "eabi32",
75   "eabi64",
76   NULL
77 };
78
79 struct frame_extra_info
80   {
81     mips_extra_func_info_t proc_desc;
82     int num_args;
83   };
84
85 /* Various MIPS ISA options (related to stack analysis) can be
86    overridden dynamically.  Establish an enum/array for managing
87    them. */
88
89 static const char size_auto[] = "auto";
90 static const char size_32[] = "32";
91 static const char size_64[] = "64";
92
93 static const char *size_enums[] = {
94   size_auto,
95   size_32,
96   size_64,
97   0
98 };
99
100 /* Some MIPS boards don't support floating point while others only
101    support single-precision floating-point operations.  See also
102    FP_REGISTER_DOUBLE. */
103
104 enum mips_fpu_type
105   {
106     MIPS_FPU_DOUBLE,            /* Full double precision floating point.  */
107     MIPS_FPU_SINGLE,            /* Single precision floating point (R4650).  */
108     MIPS_FPU_NONE               /* No floating point.  */
109   };
110
111 #ifndef MIPS_DEFAULT_FPU_TYPE
112 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
113 #endif
114 static int mips_fpu_type_auto = 1;
115 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
116
117 static int mips_debug = 0;
118
119 /* MIPS specific per-architecture information */
120 struct gdbarch_tdep
121   {
122     /* from the elf header */
123     int elf_flags;
124
125     /* mips options */
126     enum mips_abi mips_abi;
127     enum mips_abi found_abi;
128     enum mips_fpu_type mips_fpu_type;
129     int mips_last_arg_regnum;
130     int mips_last_fp_arg_regnum;
131     int mips_default_saved_regsize;
132     int mips_fp_register_double;
133     int mips_default_stack_argsize;
134     int gdb_target_is_mips64;
135     int default_mask_address_p;
136   };
137
138 #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
139                    || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
140
141 #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
142
143 #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
144
145 #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
146
147 /* Return the currently configured (or set) saved register size. */
148
149 #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize)
150
151 static const char *mips_saved_regsize_string = size_auto;
152
153 #define MIPS_SAVED_REGSIZE (mips_saved_regsize())
154
155 /* MIPS16 function addresses are odd (bit 0 is set).  Here are some
156    functions to test, set, or clear bit 0 of addresses.  */
157
158 static CORE_ADDR
159 is_mips16_addr (CORE_ADDR addr)
160 {
161   return ((addr) & 1);
162 }
163
164 static CORE_ADDR
165 make_mips16_addr (CORE_ADDR addr)
166 {
167   return ((addr) | 1);
168 }
169
170 static CORE_ADDR
171 unmake_mips16_addr (CORE_ADDR addr)
172 {
173   return ((addr) & ~1);
174 }
175
176 /* Return the contents of register REGNUM as a signed integer.  */
177
178 static LONGEST
179 read_signed_register (int regnum)
180 {
181   void *buf = alloca (REGISTER_RAW_SIZE (regnum));
182   deprecated_read_register_gen (regnum, buf);
183   return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
184 }
185
186 static LONGEST
187 read_signed_register_pid (int regnum, ptid_t ptid)
188 {
189   ptid_t save_ptid;
190   LONGEST retval;
191
192   if (ptid_equal (ptid, inferior_ptid))
193     return read_signed_register (regnum);
194
195   save_ptid = inferior_ptid;
196
197   inferior_ptid = ptid;
198
199   retval = read_signed_register (regnum);
200
201   inferior_ptid = save_ptid;
202
203   return retval;
204 }
205
206 /* Return the MIPS ABI associated with GDBARCH.  */
207 enum mips_abi
208 mips_abi (struct gdbarch *gdbarch)
209 {
210   return gdbarch_tdep (gdbarch)->mips_abi;
211 }
212
213 static unsigned int
214 mips_saved_regsize (void)
215 {
216   if (mips_saved_regsize_string == size_auto)
217     return MIPS_DEFAULT_SAVED_REGSIZE;
218   else if (mips_saved_regsize_string == size_64)
219     return 8;
220   else /* if (mips_saved_regsize_string == size_32) */
221     return 4;
222 }
223
224 /* Functions for setting and testing a bit in a minimal symbol that
225    marks it as 16-bit function.  The MSB of the minimal symbol's
226    "info" field is used for this purpose. This field is already
227    being used to store the symbol size, so the assumption is
228    that the symbol size cannot exceed 2^31.
229
230    ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special",
231    i.e. refers to a 16-bit function, and sets a "special" bit in a
232    minimal symbol to mark it as a 16-bit function
233
234    MSYMBOL_IS_SPECIAL   tests the "special" bit in a minimal symbol
235    MSYMBOL_SIZE         returns the size of the minimal symbol, i.e.
236    the "info" field with the "special" bit masked out */
237
238 static void
239 mips_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
240 {
241   if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_MIPS16) 
242     { 
243       MSYMBOL_INFO (msym) = (char *) 
244         (((long) MSYMBOL_INFO (msym)) | 0x80000000); 
245       SYMBOL_VALUE_ADDRESS (msym) |= 1; 
246     } 
247 }
248
249 static int
250 msymbol_is_special (struct minimal_symbol *msym)
251 {
252   return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
253 }
254
255 static long
256 msymbol_size (struct minimal_symbol *msym)
257 {
258   return ((long) MSYMBOL_INFO (msym) & 0x7fffffff);
259 }
260
261 /* XFER a value from the big/little/left end of the register.
262    Depending on the size of the value it might occupy the entire
263    register or just part of it.  Make an allowance for this, aligning
264    things accordingly.  */
265
266 static void
267 mips_xfer_register (struct regcache *regcache, int reg_num, int length,
268                     enum bfd_endian endian, bfd_byte *in, const bfd_byte *out,
269                     int buf_offset)
270 {
271   bfd_byte reg[MAX_REGISTER_SIZE];
272   int reg_offset = 0;
273   /* Need to transfer the left or right part of the register, based on
274      the targets byte order.  */
275   switch (endian)
276     {
277     case BFD_ENDIAN_BIG:
278       reg_offset = REGISTER_RAW_SIZE (reg_num) - length;
279       break;
280     case BFD_ENDIAN_LITTLE:
281       reg_offset = 0;
282       break;
283     case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment.  */
284       reg_offset = 0;
285       break;
286     default:
287       internal_error (__FILE__, __LINE__, "bad switch");
288     }
289   if (mips_debug)
290     fprintf_unfiltered (gdb_stderr,
291                         "xfer $%d, reg offset %d, buf offset %d, length %d, ",
292                         reg_num, reg_offset, buf_offset, length);
293   if (mips_debug && out != NULL)
294     {
295       int i;
296       fprintf_unfiltered (gdb_stdlog, "out ");
297       for (i = 0; i < length; i++)
298         fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
299     }
300   if (in != NULL)
301     regcache_raw_read_part (regcache, reg_num, reg_offset, length, in + buf_offset);
302   if (out != NULL)
303     regcache_raw_write_part (regcache, reg_num, reg_offset, length, out + buf_offset);
304   if (mips_debug && in != NULL)
305     {
306       int i;
307       fprintf_unfiltered (gdb_stdlog, "in ");
308       for (i = 0; i < length; i++)
309         fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
310     }
311   if (mips_debug)
312     fprintf_unfiltered (gdb_stdlog, "\n");
313 }
314
315 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
316    compatiblity mode.  A return value of 1 means that we have
317    physical 64-bit registers, but should treat them as 32-bit registers.  */
318
319 static int
320 mips2_fp_compat (void)
321 {
322   /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
323      meaningful.  */
324   if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4)
325     return 0;
326
327 #if 0
328   /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
329      in all the places we deal with FP registers.  PR gdb/413.  */
330   /* Otherwise check the FR bit in the status register - it controls
331      the FP compatiblity mode.  If it is clear we are in compatibility
332      mode.  */
333   if ((read_register (PS_REGNUM) & ST0_FR) == 0)
334     return 1;
335 #endif
336
337   return 0;
338 }
339
340 /* Indicate that the ABI makes use of double-precision registers
341    provided by the FPU (rather than combining pairs of registers to
342    form double-precision values).  Do not use "TARGET_IS_MIPS64" to
343    determine if the ABI is using double-precision registers.  See also
344    MIPS_FPU_TYPE. */
345 #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double)
346
347 /* The amount of space reserved on the stack for registers. This is
348    different to MIPS_SAVED_REGSIZE as it determines the alignment of
349    data allocated after the registers have run out. */
350
351 #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize)
352
353 #define MIPS_STACK_ARGSIZE (mips_stack_argsize ())
354
355 static const char *mips_stack_argsize_string = size_auto;
356
357 static unsigned int
358 mips_stack_argsize (void)
359 {
360   if (mips_stack_argsize_string == size_auto)
361     return MIPS_DEFAULT_STACK_ARGSIZE;
362   else if (mips_stack_argsize_string == size_64)
363     return 8;
364   else /* if (mips_stack_argsize_string == size_32) */
365     return 4;
366 }
367
368 #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0)
369
370 #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p)
371
372 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
373
374 int gdb_print_insn_mips (bfd_vma, disassemble_info *);
375
376 static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR,
377                                                    struct frame_info *, int);
378
379 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
380
381 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
382
383 static int mips_set_processor_type (char *);
384
385 static void mips_show_processor_type_command (char *, int);
386
387 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
388
389 static mips_extra_func_info_t find_proc_desc (CORE_ADDR pc,
390                                               struct frame_info *next_frame,
391                                               int cur_frame);
392
393 static CORE_ADDR after_prologue (CORE_ADDR pc,
394                                  mips_extra_func_info_t proc_desc);
395
396 static struct type *mips_float_register_type (void);
397 static struct type *mips_double_register_type (void);
398
399 /* This value is the model of MIPS in use.  It is derived from the value
400    of the PrID register.  */
401
402 char *mips_processor_type;
403
404 char *tmp_mips_processor_type;
405
406 /* The list of available "set mips " and "show mips " commands */
407
408 static struct cmd_list_element *setmipscmdlist = NULL;
409 static struct cmd_list_element *showmipscmdlist = NULL;
410
411 /* A set of original names, to be used when restoring back to generic
412    registers from a specific set.  */
413 static char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES;
414
415 /* Integer registers 0 thru 31 are handled explicitly by
416    mips_register_name().  Processor specific registers 32 and above
417    are listed in the sets of register names assigned to
418    mips_processor_reg_names.  */
419 static char **mips_processor_reg_names = mips_generic_reg_names;
420
421 /* Return the name of the register corresponding to REGNO.  */
422 static const char *
423 mips_register_name (int regno)
424 {
425   /* GPR names for all ABIs other than n32/n64.  */
426   static char *mips_gpr_names[] = {
427     "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
428     "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
429     "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
430     "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra",
431   };
432
433   /* GPR names for n32 and n64 ABIs.  */
434   static char *mips_n32_n64_gpr_names[] = {
435     "zero", "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3", 
436     "a4",   "a5",   "a6",   "a7",   "t0",   "t1",   "t2",   "t3", 
437     "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7", 
438     "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "s8",   "ra"
439   };
440
441   enum mips_abi abi = mips_abi (current_gdbarch);
442
443   /* The MIPS integer registers are always mapped from 0 to 31.  The
444      names of the registers (which reflects the conventions regarding
445      register use) vary depending on the ABI.  */
446   if (0 <= regno && regno < 32)
447     {
448       if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
449         return mips_n32_n64_gpr_names[regno];
450       else
451         return mips_gpr_names[regno];
452     }
453   else if (32 <= regno && regno < NUM_REGS)
454     return mips_processor_reg_names[regno - 32];
455   else
456     internal_error (__FILE__, __LINE__,
457                     "mips_register_name: bad register number %d", regno);
458 }
459
460 /* *INDENT-OFF* */
461 /* Names of IDT R3041 registers.  */
462
463 char *mips_r3041_reg_names[] = {
464         "sr",   "lo",   "hi",   "bad",  "cause","pc",
465         "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
466         "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
467         "f16",  "f17",  "f18",  "f19",  "f20",  "f21",  "f22",  "f23",
468         "f24",  "f25",  "f26",  "f27",  "f28",  "f29",  "f30",  "f31",
469         "fsr",  "fir",  "",/*"fp"*/     "",
470         "",     "",     "bus",  "ccfg", "",     "",     "",     "",
471         "",     "",     "port", "cmp",  "",     "",     "epc",  "prid",
472 };
473
474 /* Names of IDT R3051 registers.  */
475
476 char *mips_r3051_reg_names[] = {
477         "sr",   "lo",   "hi",   "bad",  "cause","pc",
478         "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
479         "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
480         "f16",  "f17",  "f18",  "f19",  "f20",  "f21",  "f22",  "f23",
481         "f24",  "f25",  "f26",  "f27",  "f28",  "f29",  "f30",  "f31",
482         "fsr",  "fir",  ""/*"fp"*/,     "",
483         "inx",  "rand", "elo",  "",     "ctxt", "",     "",     "",
484         "",     "",     "ehi",  "",     "",     "",     "epc",  "prid",
485 };
486
487 /* Names of IDT R3081 registers.  */
488
489 char *mips_r3081_reg_names[] = {
490         "sr",   "lo",   "hi",   "bad",  "cause","pc",
491         "f0",   "f1",   "f2",   "f3",   "f4",   "f5",   "f6",   "f7",
492         "f8",   "f9",   "f10",  "f11",  "f12",  "f13",  "f14",  "f15",
493         "f16",  "f17",  "f18",  "f19",  "f20",  "f21",  "f22",  "f23",
494         "f24",  "f25",  "f26",  "f27",  "f28",  "f29",  "f30",  "f31",
495         "fsr",  "fir",  ""/*"fp"*/,     "",
496         "inx",  "rand", "elo",  "cfg",  "ctxt", "",     "",     "",
497         "",     "",     "ehi",  "",     "",     "",     "epc",  "prid",
498 };
499
500 /* Names of LSI 33k registers.  */
501
502 char *mips_lsi33k_reg_names[] = {
503         "epc",  "hi",   "lo",   "sr",   "cause","badvaddr",
504         "dcic", "bpc",  "bda",  "",     "",     "",     "",      "",
505         "",     "",     "",     "",     "",     "",     "",      "",
506         "",     "",     "",     "",     "",     "",     "",      "",
507         "",     "",     "",     "",     "",     "",     "",      "",
508         "",     "",     "",     "",
509         "",     "",     "",     "",     "",     "",     "",      "",
510         "",     "",     "",     "",     "",     "",     "",      "",
511 };
512
513 struct {
514   char *name;
515   char **regnames;
516 } mips_processor_type_table[] = {
517   { "generic", mips_generic_reg_names },
518   { "r3041", mips_r3041_reg_names },
519   { "r3051", mips_r3051_reg_names },
520   { "r3071", mips_r3081_reg_names },
521   { "r3081", mips_r3081_reg_names },
522   { "lsi33k", mips_lsi33k_reg_names },
523   { NULL, NULL }
524 };
525 /* *INDENT-ON* */
526
527
528
529
530 /* Table to translate MIPS16 register field to actual register number.  */
531 static int mips16_to_32_reg[8] =
532 {16, 17, 2, 3, 4, 5, 6, 7};
533
534 /* Heuristic_proc_start may hunt through the text section for a long
535    time across a 2400 baud serial line.  Allows the user to limit this
536    search.  */
537
538 static unsigned int heuristic_fence_post = 0;
539
540 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)   /* least address */
541 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr)        /* upper address bound */
542 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
543 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
544 #define PROC_FRAME_ADJUST(proc)  ((proc)->frame_adjust)
545 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
546 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
547 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
548 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
549 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
550 /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long,
551    this will corrupt pdr.iline.  Fortunately we don't use it.  */
552 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
553 #define _PROC_MAGIC_ 0x0F0F0F0F
554 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
555 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
556
557 struct linked_proc_info
558   {
559     struct mips_extra_func_info info;
560     struct linked_proc_info *next;
561   }
562  *linked_proc_desc_table = NULL;
563
564 void
565 mips_print_extra_frame_info (struct frame_info *fi)
566 {
567   if (fi
568       && get_frame_extra_info (fi)
569       && get_frame_extra_info (fi)->proc_desc
570       && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
571     printf_filtered (" frame pointer is at %s+%s\n",
572                      REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
573                      paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
574 }
575
576 /* Number of bytes of storage in the actual machine representation for
577    register N.  NOTE: This indirectly defines the register size
578    transfered by the GDB protocol. */
579
580 static int mips64_transfers_32bit_regs_p = 0;
581
582 static int
583 mips_register_raw_size (int reg_nr)
584 {
585   if (mips64_transfers_32bit_regs_p)
586     return REGISTER_VIRTUAL_SIZE (reg_nr);
587   else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32
588            && FP_REGISTER_DOUBLE)
589     /* For MIPS_ABI_N32 (for example) we need 8 byte floating point
590        registers.  */
591     return 8;
592   else
593     return MIPS_REGSIZE;
594 }
595
596 /* Convert between RAW and VIRTUAL registers.  The RAW register size
597    defines the remote-gdb packet. */
598
599 static int
600 mips_register_convertible (int reg_nr)
601 {
602   if (mips64_transfers_32bit_regs_p)
603     return 0;
604   else
605     return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr));
606 }
607
608 static void
609 mips_register_convert_to_virtual (int n, struct type *virtual_type,
610                                   char *raw_buf, char *virt_buf)
611 {
612   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
613     memcpy (virt_buf,
614             raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
615             TYPE_LENGTH (virtual_type));
616   else
617     memcpy (virt_buf,
618             raw_buf,
619             TYPE_LENGTH (virtual_type));
620 }
621
622 static void
623 mips_register_convert_to_raw (struct type *virtual_type, int n,
624                               const char *virt_buf, char *raw_buf)
625 {
626   memset (raw_buf, 0, REGISTER_RAW_SIZE (n));
627   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
628     memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)),
629             virt_buf,
630             TYPE_LENGTH (virtual_type));
631   else
632     memcpy (raw_buf,
633             virt_buf,
634             TYPE_LENGTH (virtual_type));
635 }
636
637 void
638 mips_register_convert_to_type (int regnum, struct type *type, char *buffer)
639 {
640   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
641       && REGISTER_RAW_SIZE (regnum) == 4
642       && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
643       && TYPE_CODE(type) == TYPE_CODE_FLT
644       && TYPE_LENGTH(type) == 8) 
645     {
646       char temp[4];
647       memcpy (temp, ((char *)(buffer))+4, 4);
648       memcpy (((char *)(buffer))+4, (buffer), 4);
649       memcpy (((char *)(buffer)), temp, 4); 
650     }
651 }
652
653 void
654 mips_register_convert_from_type (int regnum, struct type *type, char *buffer)
655 {
656 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
657     && REGISTER_RAW_SIZE (regnum) == 4
658     && (regnum) >= FP0_REGNUM && (regnum) < FP0_REGNUM + 32
659     && TYPE_CODE(type) == TYPE_CODE_FLT
660     && TYPE_LENGTH(type) == 8) 
661   {
662     char temp[4];
663     memcpy (temp, ((char *)(buffer))+4, 4);
664     memcpy (((char *)(buffer))+4, (buffer), 4);
665     memcpy (((char *)(buffer)), temp, 4);
666   }
667 }
668
669 /* Return the GDB type object for the "standard" data type
670    of data in register REG.  
671    
672    Note: kevinb/2002-08-01: The definition below should faithfully
673    reproduce the behavior of each of the REGISTER_VIRTUAL_TYPE
674    definitions found in config/mips/tm-*.h.  I'm concerned about the
675    ``FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM'' clause though.
676    In some cases DEPRECATED_FP_REGNUM is in this range, and I doubt
677    that this code is correct for the 64-bit case.  */
678
679 static struct type *
680 mips_register_virtual_type (int reg)
681 {
682   if (FP0_REGNUM <= reg && reg < FP0_REGNUM + 32)
683     {
684       /* Floating point registers...  */
685       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
686         return builtin_type_ieee_double_big;
687       else
688         return builtin_type_ieee_double_little;
689     }
690   else if (reg == PS_REGNUM /* CR */)
691     return builtin_type_uint32;
692   else if (FCRCS_REGNUM <= reg && reg <= LAST_EMBED_REGNUM)
693     return builtin_type_uint32;
694   else
695     {
696       /* Everything else...
697          Return type appropriate for width of register.  */
698       if (MIPS_REGSIZE == TYPE_LENGTH (builtin_type_uint64))
699         return builtin_type_uint64;
700       else
701         return builtin_type_uint32;
702     }
703 }
704
705 /* TARGET_READ_SP -- Remove useless bits from the stack pointer.  */
706
707 static CORE_ADDR
708 mips_read_sp (void)
709 {
710   return read_signed_register (SP_REGNUM);
711 }
712
713 /* Should the upper word of 64-bit addresses be zeroed? */
714 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
715
716 static int
717 mips_mask_address_p (void)
718 {
719   switch (mask_address_var)
720     {
721     case AUTO_BOOLEAN_TRUE:
722       return 1;
723     case AUTO_BOOLEAN_FALSE:
724       return 0;
725       break;
726     case AUTO_BOOLEAN_AUTO:
727       return MIPS_DEFAULT_MASK_ADDRESS_P;
728     default:
729       internal_error (__FILE__, __LINE__,
730                       "mips_mask_address_p: bad switch");
731       return -1;
732     }
733 }
734
735 static void
736 show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c)
737 {
738   switch (mask_address_var)
739     {
740     case AUTO_BOOLEAN_TRUE:
741       printf_filtered ("The 32 bit mips address mask is enabled\n");
742       break;
743     case AUTO_BOOLEAN_FALSE:
744       printf_filtered ("The 32 bit mips address mask is disabled\n");
745       break;
746     case AUTO_BOOLEAN_AUTO:
747       printf_filtered ("The 32 bit address mask is set automatically.  Currently %s\n",
748                        mips_mask_address_p () ? "enabled" : "disabled");
749       break;
750     default:
751       internal_error (__FILE__, __LINE__,
752                       "show_mask_address: bad switch");
753       break;
754     }
755 }
756
757 /* Should call_function allocate stack space for a struct return?  */
758
759 static int
760 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
761 {
762   return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
763 }
764
765 static int
766 mips_n32n64_use_struct_convention (int gcc_p, struct type *type)
767 {
768   return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
769 }
770
771 /* Should call_function pass struct by reference? 
772    For each architecture, structs are passed either by
773    value or by reference, depending on their size.  */
774
775 static int
776 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
777 {
778   enum type_code typecode = TYPE_CODE (check_typedef (type));
779   int len = TYPE_LENGTH (check_typedef (type));
780
781   if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
782     return (len > MIPS_SAVED_REGSIZE);
783
784   return 0;
785 }
786
787 static int
788 mips_n32n64_reg_struct_has_addr (int gcc_p, struct type *type)
789 {
790   return 0;     /* Assumption: N32/N64 never passes struct by ref.  */
791 }
792
793 static int
794 mips_o32_reg_struct_has_addr (int gcc_p, struct type *type)
795 {
796   return 0;     /* Assumption: O32/O64 never passes struct by ref.  */
797 }
798
799 /* Tell if the program counter value in MEMADDR is in a MIPS16 function.  */
800
801 static int
802 pc_is_mips16 (bfd_vma memaddr)
803 {
804   struct minimal_symbol *sym;
805
806   /* If bit 0 of the address is set, assume this is a MIPS16 address. */
807   if (is_mips16_addr (memaddr))
808     return 1;
809
810   /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
811      the high bit of the info field.  Use this to decide if the function is
812      MIPS16 or normal MIPS.  */
813   sym = lookup_minimal_symbol_by_pc (memaddr);
814   if (sym)
815     return msymbol_is_special (sym);
816   else
817     return 0;
818 }
819
820 /* MIPS believes that the PC has a sign extended value.  Perhaphs the
821    all registers should be sign extended for simplicity? */
822
823 static CORE_ADDR
824 mips_read_pc (ptid_t ptid)
825 {
826   return read_signed_register_pid (PC_REGNUM, ptid);
827 }
828
829 /* This returns the PC of the first inst after the prologue.  If we can't
830    find the prologue, then return 0.  */
831
832 static CORE_ADDR
833 after_prologue (CORE_ADDR pc,
834                 mips_extra_func_info_t proc_desc)
835 {
836   struct symtab_and_line sal;
837   CORE_ADDR func_addr, func_end;
838
839   /* Pass cur_frame == 0 to find_proc_desc.  We should not attempt
840      to read the stack pointer from the current machine state, because
841      the current machine state has nothing to do with the information
842      we need from the proc_desc; and the process may or may not exist
843      right now.  */
844   if (!proc_desc)
845     proc_desc = find_proc_desc (pc, NULL, 0);
846
847   if (proc_desc)
848     {
849       /* If function is frameless, then we need to do it the hard way.  I
850          strongly suspect that frameless always means prologueless... */
851       if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
852           && PROC_FRAME_OFFSET (proc_desc) == 0)
853         return 0;
854     }
855
856   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
857     return 0;                   /* Unknown */
858
859   sal = find_pc_line (func_addr, 0);
860
861   if (sal.end < func_end)
862     return sal.end;
863
864   /* The line after the prologue is after the end of the function.  In this
865      case, tell the caller to find the prologue the hard way.  */
866
867   return 0;
868 }
869
870 /* Decode a MIPS32 instruction that saves a register in the stack, and
871    set the appropriate bit in the general register mask or float register mask
872    to indicate which register is saved.  This is a helper function
873    for mips_find_saved_regs.  */
874
875 static void
876 mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask,
877                         unsigned long *float_mask)
878 {
879   int reg;
880
881   if ((inst & 0xffe00000) == 0xafa00000         /* sw reg,n($sp) */
882       || (inst & 0xffe00000) == 0xafc00000      /* sw reg,n($r30) */
883       || (inst & 0xffe00000) == 0xffa00000)     /* sd reg,n($sp) */
884     {
885       /* It might be possible to use the instruction to
886          find the offset, rather than the code below which
887          is based on things being in a certain order in the
888          frame, but figuring out what the instruction's offset
889          is relative to might be a little tricky.  */
890       reg = (inst & 0x001f0000) >> 16;
891       *gen_mask |= (1 << reg);
892     }
893   else if ((inst & 0xffe00000) == 0xe7a00000    /* swc1 freg,n($sp) */
894            || (inst & 0xffe00000) == 0xe7c00000         /* swc1 freg,n($r30) */
895            || (inst & 0xffe00000) == 0xf7a00000)        /* sdc1 freg,n($sp) */
896
897     {
898       reg = ((inst & 0x001f0000) >> 16);
899       *float_mask |= (1 << reg);
900     }
901 }
902
903 /* Decode a MIPS16 instruction that saves a register in the stack, and
904    set the appropriate bit in the general register or float register mask
905    to indicate which register is saved.  This is a helper function
906    for mips_find_saved_regs.  */
907
908 static void
909 mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask)
910 {
911   if ((inst & 0xf800) == 0xd000)        /* sw reg,n($sp) */
912     {
913       int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
914       *gen_mask |= (1 << reg);
915     }
916   else if ((inst & 0xff00) == 0xf900)   /* sd reg,n($sp) */
917     {
918       int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
919       *gen_mask |= (1 << reg);
920     }
921   else if ((inst & 0xff00) == 0x6200    /* sw $ra,n($sp) */
922            || (inst & 0xff00) == 0xfa00)        /* sd $ra,n($sp) */
923     *gen_mask |= (1 << RA_REGNUM);
924 }
925
926
927 /* Fetch and return instruction from the specified location.  If the PC
928    is odd, assume it's a MIPS16 instruction; otherwise MIPS32.  */
929
930 static t_inst
931 mips_fetch_instruction (CORE_ADDR addr)
932 {
933   char buf[MIPS_INSTLEN];
934   int instlen;
935   int status;
936
937   if (pc_is_mips16 (addr))
938     {
939       instlen = MIPS16_INSTLEN;
940       addr = unmake_mips16_addr (addr);
941     }
942   else
943     instlen = MIPS_INSTLEN;
944   status = read_memory_nobpt (addr, buf, instlen);
945   if (status)
946     memory_error (status, addr);
947   return extract_unsigned_integer (buf, instlen);
948 }
949
950
951 /* These the fields of 32 bit mips instructions */
952 #define mips32_op(x) (x >> 26)
953 #define itype_op(x) (x >> 26)
954 #define itype_rs(x) ((x >> 21) & 0x1f)
955 #define itype_rt(x) ((x >> 16) & 0x1f)
956 #define itype_immediate(x) (x & 0xffff)
957
958 #define jtype_op(x) (x >> 26)
959 #define jtype_target(x) (x & 0x03ffffff)
960
961 #define rtype_op(x) (x >> 26)
962 #define rtype_rs(x) ((x >> 21) & 0x1f)
963 #define rtype_rt(x) ((x >> 16) & 0x1f)
964 #define rtype_rd(x) ((x >> 11) & 0x1f)
965 #define rtype_shamt(x) ((x >> 6) & 0x1f)
966 #define rtype_funct(x) (x & 0x3f)
967
968 static CORE_ADDR
969 mips32_relative_offset (unsigned long inst)
970 {
971   long x;
972   x = itype_immediate (inst);
973   if (x & 0x8000)               /* sign bit set */
974     {
975       x |= 0xffff0000;          /* sign extension */
976     }
977   x = x << 2;
978   return x;
979 }
980
981 /* Determine whate to set a single step breakpoint while considering
982    branch prediction */
983 static CORE_ADDR
984 mips32_next_pc (CORE_ADDR pc)
985 {
986   unsigned long inst;
987   int op;
988   inst = mips_fetch_instruction (pc);
989   if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
990     {
991       if (itype_op (inst) >> 2 == 5)
992                                 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
993         {
994           op = (itype_op (inst) & 0x03);
995           switch (op)
996             {
997             case 0:             /* BEQL */
998               goto equal_branch;
999             case 1:             /* BNEL */
1000               goto neq_branch;
1001             case 2:             /* BLEZL */
1002               goto less_branch;
1003             case 3:             /* BGTZ */
1004               goto greater_branch;
1005             default:
1006               pc += 4;
1007             }
1008         }
1009       else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
1010                                 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1011         {
1012           int tf = itype_rt (inst) & 0x01;
1013           int cnum = itype_rt (inst) >> 2;
1014           int fcrcs = read_signed_register (FCRCS_REGNUM);
1015           int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1016
1017           if (((cond >> cnum) & 0x01) == tf)
1018             pc += mips32_relative_offset (inst) + 4;
1019           else
1020             pc += 8;
1021         }
1022       else
1023         pc += 4;                /* Not a branch, next instruction is easy */
1024     }
1025   else
1026     {                           /* This gets way messy */
1027
1028       /* Further subdivide into SPECIAL, REGIMM and other */
1029       switch (op = itype_op (inst) & 0x07)      /* extract bits 28,27,26 */
1030         {
1031         case 0:         /* SPECIAL */
1032           op = rtype_funct (inst);
1033           switch (op)
1034             {
1035             case 8:             /* JR */
1036             case 9:             /* JALR */
1037               /* Set PC to that address */
1038               pc = read_signed_register (rtype_rs (inst));
1039               break;
1040             default:
1041               pc += 4;
1042             }
1043
1044           break;        /* end SPECIAL */
1045         case 1:         /* REGIMM */
1046           {
1047             op = itype_rt (inst);       /* branch condition */
1048             switch (op)
1049               {
1050               case 0:           /* BLTZ */
1051               case 2:           /* BLTZL */
1052               case 16:          /* BLTZAL */
1053               case 18:          /* BLTZALL */
1054               less_branch:
1055                 if (read_signed_register (itype_rs (inst)) < 0)
1056                   pc += mips32_relative_offset (inst) + 4;
1057                 else
1058                   pc += 8;      /* after the delay slot */
1059                 break;
1060               case 1:           /* BGEZ */
1061               case 3:           /* BGEZL */
1062               case 17:          /* BGEZAL */
1063               case 19:          /* BGEZALL */
1064               greater_equal_branch:
1065                 if (read_signed_register (itype_rs (inst)) >= 0)
1066                   pc += mips32_relative_offset (inst) + 4;
1067                 else
1068                   pc += 8;      /* after the delay slot */
1069                 break;
1070                 /* All of the other instructions in the REGIMM category */
1071               default:
1072                 pc += 4;
1073               }
1074           }
1075           break;        /* end REGIMM */
1076         case 2:         /* J */
1077         case 3:         /* JAL */
1078           {
1079             unsigned long reg;
1080             reg = jtype_target (inst) << 2;
1081             /* Upper four bits get never changed... */
1082             pc = reg + ((pc + 4) & 0xf0000000);
1083           }
1084           break;
1085           /* FIXME case JALX : */
1086           {
1087             unsigned long reg;
1088             reg = jtype_target (inst) << 2;
1089             pc = reg + ((pc + 4) & 0xf0000000) + 1;     /* yes, +1 */
1090             /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1091           }
1092           break;                /* The new PC will be alternate mode */
1093         case 4:         /* BEQ, BEQL */
1094         equal_branch:
1095           if (read_signed_register (itype_rs (inst)) ==
1096               read_signed_register (itype_rt (inst)))
1097             pc += mips32_relative_offset (inst) + 4;
1098           else
1099             pc += 8;
1100           break;
1101         case 5:         /* BNE, BNEL */
1102         neq_branch:
1103           if (read_signed_register (itype_rs (inst)) !=
1104               read_signed_register (itype_rt (inst)))
1105             pc += mips32_relative_offset (inst) + 4;
1106           else
1107             pc += 8;
1108           break;
1109         case 6:         /* BLEZ, BLEZL */
1110         less_zero_branch:
1111           if (read_signed_register (itype_rs (inst) <= 0))
1112             pc += mips32_relative_offset (inst) + 4;
1113           else
1114             pc += 8;
1115           break;
1116         case 7:
1117         default:
1118         greater_branch: /* BGTZ, BGTZL */
1119           if (read_signed_register (itype_rs (inst) > 0))
1120             pc += mips32_relative_offset (inst) + 4;
1121           else
1122             pc += 8;
1123           break;
1124         }                       /* switch */
1125     }                           /* else */
1126   return pc;
1127 }                               /* mips32_next_pc */
1128
1129 /* Decoding the next place to set a breakpoint is irregular for the
1130    mips 16 variant, but fortunately, there fewer instructions. We have to cope
1131    ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1132    We dont want to set a single step instruction on the extend instruction
1133    either.
1134  */
1135
1136 /* Lots of mips16 instruction formats */
1137 /* Predicting jumps requires itype,ritype,i8type
1138    and their extensions      extItype,extritype,extI8type
1139  */
1140 enum mips16_inst_fmts
1141 {
1142   itype,                        /* 0  immediate 5,10 */
1143   ritype,                       /* 1   5,3,8 */
1144   rrtype,                       /* 2   5,3,3,5 */
1145   rritype,                      /* 3   5,3,3,5 */
1146   rrrtype,                      /* 4   5,3,3,3,2 */
1147   rriatype,                     /* 5   5,3,3,1,4 */
1148   shifttype,                    /* 6   5,3,3,3,2 */
1149   i8type,                       /* 7   5,3,8 */
1150   i8movtype,                    /* 8   5,3,3,5 */
1151   i8mov32rtype,                 /* 9   5,3,5,3 */
1152   i64type,                      /* 10  5,3,8 */
1153   ri64type,                     /* 11  5,3,3,5 */
1154   jalxtype,                     /* 12  5,1,5,5,16 - a 32 bit instruction */
1155   exiItype,                     /* 13  5,6,5,5,1,1,1,1,1,1,5 */
1156   extRitype,                    /* 14  5,6,5,5,3,1,1,1,5 */
1157   extRRItype,                   /* 15  5,5,5,5,3,3,5 */
1158   extRRIAtype,                  /* 16  5,7,4,5,3,3,1,4 */
1159   EXTshifttype,                 /* 17  5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1160   extI8type,                    /* 18  5,6,5,5,3,1,1,1,5 */
1161   extI64type,                   /* 19  5,6,5,5,3,1,1,1,5 */
1162   extRi64type,                  /* 20  5,6,5,5,3,3,5 */
1163   extshift64type                /* 21  5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1164 };
1165 /* I am heaping all the fields of the formats into one structure and
1166    then, only the fields which are involved in instruction extension */
1167 struct upk_mips16
1168   {
1169     CORE_ADDR offset;
1170     unsigned int regx;          /* Function in i8 type */
1171     unsigned int regy;
1172   };
1173
1174
1175 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1176    for the bits which make up the immediatate extension.  */
1177
1178 static CORE_ADDR
1179 extended_offset (unsigned int extension)
1180 {
1181   CORE_ADDR value;
1182   value = (extension >> 21) & 0x3f;     /* * extract 15:11 */
1183   value = value << 6;
1184   value |= (extension >> 16) & 0x1f;    /* extrace 10:5 */
1185   value = value << 5;
1186   value |= extension & 0x01f;   /* extract 4:0 */
1187   return value;
1188 }
1189
1190 /* Only call this function if you know that this is an extendable
1191    instruction, It wont malfunction, but why make excess remote memory references?
1192    If the immediate operands get sign extended or somthing, do it after
1193    the extension is performed.
1194  */
1195 /* FIXME: Every one of these cases needs to worry about sign extension
1196    when the offset is to be used in relative addressing */
1197
1198
1199 static unsigned int
1200 fetch_mips_16 (CORE_ADDR pc)
1201 {
1202   char buf[8];
1203   pc &= 0xfffffffe;             /* clear the low order bit */
1204   target_read_memory (pc, buf, 2);
1205   return extract_unsigned_integer (buf, 2);
1206 }
1207
1208 static void
1209 unpack_mips16 (CORE_ADDR pc,
1210                unsigned int extension,
1211                unsigned int inst,
1212                enum mips16_inst_fmts insn_format,
1213                struct upk_mips16 *upk)
1214 {
1215   CORE_ADDR offset;
1216   int regx;
1217   int regy;
1218   switch (insn_format)
1219     {
1220     case itype:
1221       {
1222         CORE_ADDR value;
1223         if (extension)
1224           {
1225             value = extended_offset (extension);
1226             value = value << 11;        /* rom for the original value */
1227             value |= inst & 0x7ff;              /* eleven bits from instruction */
1228           }
1229         else
1230           {
1231             value = inst & 0x7ff;
1232             /* FIXME : Consider sign extension */
1233           }
1234         offset = value;
1235         regx = -1;
1236         regy = -1;
1237       }
1238       break;
1239     case ritype:
1240     case i8type:
1241       {                         /* A register identifier and an offset */
1242         /* Most of the fields are the same as I type but the
1243            immediate value is of a different length */
1244         CORE_ADDR value;
1245         if (extension)
1246           {
1247             value = extended_offset (extension);
1248             value = value << 8; /* from the original instruction */
1249             value |= inst & 0xff;       /* eleven bits from instruction */
1250             regx = (extension >> 8) & 0x07;     /* or i8 funct */
1251             if (value & 0x4000) /* test the sign bit , bit 26 */
1252               {
1253                 value &= ~0x3fff;       /* remove the sign bit */
1254                 value = -value;
1255               }
1256           }
1257         else
1258           {
1259             value = inst & 0xff;        /* 8 bits */
1260             regx = (inst >> 8) & 0x07;  /* or i8 funct */
1261             /* FIXME: Do sign extension , this format needs it */
1262             if (value & 0x80)   /* THIS CONFUSES ME */
1263               {
1264                 value &= 0xef;  /* remove the sign bit */
1265                 value = -value;
1266               }
1267           }
1268         offset = value;
1269         regy = -1;
1270         break;
1271       }
1272     case jalxtype:
1273       {
1274         unsigned long value;
1275         unsigned int nexthalf;
1276         value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1277         value = value << 16;
1278         nexthalf = mips_fetch_instruction (pc + 2);     /* low bit still set */
1279         value |= nexthalf;
1280         offset = value;
1281         regx = -1;
1282         regy = -1;
1283         break;
1284       }
1285     default:
1286       internal_error (__FILE__, __LINE__,
1287                       "bad switch");
1288     }
1289   upk->offset = offset;
1290   upk->regx = regx;
1291   upk->regy = regy;
1292 }
1293
1294
1295 static CORE_ADDR
1296 add_offset_16 (CORE_ADDR pc, int offset)
1297 {
1298   return ((offset << 2) | ((pc + 2) & (0xf0000000)));
1299 }
1300
1301 static CORE_ADDR
1302 extended_mips16_next_pc (CORE_ADDR pc,
1303                          unsigned int extension,
1304                          unsigned int insn)
1305 {
1306   int op = (insn >> 11);
1307   switch (op)
1308     {
1309     case 2:             /* Branch */
1310       {
1311         CORE_ADDR offset;
1312         struct upk_mips16 upk;
1313         unpack_mips16 (pc, extension, insn, itype, &upk);
1314         offset = upk.offset;
1315         if (offset & 0x800)
1316           {
1317             offset &= 0xeff;
1318             offset = -offset;
1319           }
1320         pc += (offset << 1) + 2;
1321         break;
1322       }
1323     case 3:             /* JAL , JALX - Watch out, these are 32 bit instruction */
1324       {
1325         struct upk_mips16 upk;
1326         unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1327         pc = add_offset_16 (pc, upk.offset);
1328         if ((insn >> 10) & 0x01)        /* Exchange mode */
1329           pc = pc & ~0x01;      /* Clear low bit, indicate 32 bit mode */
1330         else
1331           pc |= 0x01;
1332         break;
1333       }
1334     case 4:             /* beqz */
1335       {
1336         struct upk_mips16 upk;
1337         int reg;
1338         unpack_mips16 (pc, extension, insn, ritype, &upk);
1339         reg = read_signed_register (upk.regx);
1340         if (reg == 0)
1341           pc += (upk.offset << 1) + 2;
1342         else
1343           pc += 2;
1344         break;
1345       }
1346     case 5:             /* bnez */
1347       {
1348         struct upk_mips16 upk;
1349         int reg;
1350         unpack_mips16 (pc, extension, insn, ritype, &upk);
1351         reg = read_signed_register (upk.regx);
1352         if (reg != 0)
1353           pc += (upk.offset << 1) + 2;
1354         else
1355           pc += 2;
1356         break;
1357       }
1358     case 12:            /* I8 Formats btez btnez */
1359       {
1360         struct upk_mips16 upk;
1361         int reg;
1362         unpack_mips16 (pc, extension, insn, i8type, &upk);
1363         /* upk.regx contains the opcode */
1364         reg = read_signed_register (24);        /* Test register is 24 */
1365         if (((upk.regx == 0) && (reg == 0))     /* BTEZ */
1366             || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1367           /* pc = add_offset_16(pc,upk.offset) ; */
1368           pc += (upk.offset << 1) + 2;
1369         else
1370           pc += 2;
1371         break;
1372       }
1373     case 29:            /* RR Formats JR, JALR, JALR-RA */
1374       {
1375         struct upk_mips16 upk;
1376         /* upk.fmt = rrtype; */
1377         op = insn & 0x1f;
1378         if (op == 0)
1379           {
1380             int reg;
1381             upk.regx = (insn >> 8) & 0x07;
1382             upk.regy = (insn >> 5) & 0x07;
1383             switch (upk.regy)
1384               {
1385               case 0:
1386                 reg = upk.regx;
1387                 break;
1388               case 1:
1389                 reg = 31;
1390                 break;  /* Function return instruction */
1391               case 2:
1392                 reg = upk.regx;
1393                 break;
1394               default:
1395                 reg = 31;
1396                 break;  /* BOGUS Guess */
1397               }
1398             pc = read_signed_register (reg);
1399           }
1400         else
1401           pc += 2;
1402         break;
1403       }
1404     case 30:
1405       /* This is an instruction extension.  Fetch the real instruction
1406          (which follows the extension) and decode things based on
1407          that. */
1408       {
1409         pc += 2;
1410         pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc));
1411         break;
1412       }
1413     default:
1414       {
1415         pc += 2;
1416         break;
1417       }
1418     }
1419   return pc;
1420 }
1421
1422 static CORE_ADDR
1423 mips16_next_pc (CORE_ADDR pc)
1424 {
1425   unsigned int insn = fetch_mips_16 (pc);
1426   return extended_mips16_next_pc (pc, 0, insn);
1427 }
1428
1429 /* The mips_next_pc function supports single_step when the remote
1430    target monitor or stub is not developed enough to do a single_step.
1431    It works by decoding the current instruction and predicting where a
1432    branch will go. This isnt hard because all the data is available.
1433    The MIPS32 and MIPS16 variants are quite different */
1434 CORE_ADDR
1435 mips_next_pc (CORE_ADDR pc)
1436 {
1437   if (pc & 0x01)
1438     return mips16_next_pc (pc);
1439   else
1440     return mips32_next_pc (pc);
1441 }
1442
1443 /* Set up the 'saved_regs' array.  This is a data structure containing
1444    the addresses on the stack where each register has been saved, for
1445    each stack frame.  Registers that have not been saved will have
1446    zero here.  The stack pointer register is special: rather than the
1447    address where the stack register has been saved,
1448    saved_regs[SP_REGNUM] will have the actual value of the previous
1449    frame's stack register.  */
1450
1451 static void
1452 mips_find_saved_regs (struct frame_info *fci)
1453 {
1454   int ireg;
1455   /* r0 bit means kernel trap */
1456   int kernel_trap;
1457   /* What registers have been saved?  Bitmasks.  */
1458   unsigned long gen_mask, float_mask;
1459   mips_extra_func_info_t proc_desc;
1460   t_inst inst;
1461   CORE_ADDR *saved_regs;
1462
1463   if (get_frame_saved_regs (fci) != NULL)
1464     return;
1465   saved_regs = frame_saved_regs_zalloc (fci);
1466
1467   /* If it is the frame for sigtramp, the saved registers are located
1468      in a sigcontext structure somewhere on the stack.  If the stack
1469      layout for sigtramp changes we might have to change these
1470      constants and the companion fixup_sigtramp in mdebugread.c */
1471 #ifndef SIGFRAME_BASE
1472   /* To satisfy alignment restrictions, sigcontext is located 4 bytes
1473      above the sigtramp frame.  */
1474 #define SIGFRAME_BASE           MIPS_REGSIZE
1475 /* FIXME!  Are these correct?? */
1476 #define SIGFRAME_PC_OFF         (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
1477 #define SIGFRAME_REGSAVE_OFF    (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
1478 #define SIGFRAME_FPREGSAVE_OFF  \
1479         (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
1480 #endif
1481 #ifndef SIGFRAME_REG_SIZE
1482   /* FIXME!  Is this correct?? */
1483 #define SIGFRAME_REG_SIZE       MIPS_REGSIZE
1484 #endif
1485   if ((get_frame_type (fci) == SIGTRAMP_FRAME))
1486     {
1487       for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1488         {
1489           CORE_ADDR reg_position = (get_frame_base (fci) + SIGFRAME_REGSAVE_OFF
1490                                     + ireg * SIGFRAME_REG_SIZE);
1491           set_reg_offset (saved_regs, ireg, reg_position);
1492         }
1493       for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
1494         {
1495           CORE_ADDR reg_position = (get_frame_base (fci)
1496                                     + SIGFRAME_FPREGSAVE_OFF
1497                                     + ireg * SIGFRAME_REG_SIZE);
1498           set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1499         }
1500
1501       set_reg_offset (saved_regs, PC_REGNUM, get_frame_base (fci) + SIGFRAME_PC_OFF);
1502       /* SP_REGNUM, contains the value and not the address.  */
1503       set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1504       return;
1505     }
1506
1507   proc_desc = get_frame_extra_info (fci)->proc_desc;
1508   if (proc_desc == NULL)
1509     /* I'm not sure how/whether this can happen.  Normally when we
1510        can't find a proc_desc, we "synthesize" one using
1511        heuristic_proc_desc and set the saved_regs right away.  */
1512     return;
1513
1514   kernel_trap = PROC_REG_MASK (proc_desc) & 1;
1515   gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
1516   float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc);
1517
1518   if (/* In any frame other than the innermost or a frame interrupted
1519          by a signal, we assume that all registers have been saved.
1520          This assumes that all register saves in a function happen
1521          before the first function call.  */
1522        (get_next_frame (fci) == NULL
1523         || (get_frame_type (get_next_frame (fci)) == SIGTRAMP_FRAME))
1524
1525        /* In a dummy frame we know exactly where things are saved.  */
1526        && !PROC_DESC_IS_DUMMY (proc_desc)
1527
1528        /* Don't bother unless we are inside a function prologue.
1529           Outside the prologue, we know where everything is. */
1530
1531        && in_prologue (get_frame_pc (fci), PROC_LOW_ADDR (proc_desc))
1532
1533        /* Not sure exactly what kernel_trap means, but if it means the
1534           kernel saves the registers without a prologue doing it, we
1535           better not examine the prologue to see whether registers
1536           have been saved yet.  */
1537        && !kernel_trap)
1538     {
1539       /* We need to figure out whether the registers that the
1540          proc_desc claims are saved have been saved yet.  */
1541
1542       CORE_ADDR addr;
1543
1544       /* Bitmasks; set if we have found a save for the register.  */
1545       unsigned long gen_save_found = 0;
1546       unsigned long float_save_found = 0;
1547       int instlen;
1548
1549       /* If the address is odd, assume this is MIPS16 code.  */
1550       addr = PROC_LOW_ADDR (proc_desc);
1551       instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1552
1553       /* Scan through this function's instructions preceding the
1554          current PC, and look for those that save registers.  */
1555       while (addr < get_frame_pc (fci))
1556         {
1557           inst = mips_fetch_instruction (addr);
1558           if (pc_is_mips16 (addr))
1559             mips16_decode_reg_save (inst, &gen_save_found);
1560           else
1561             mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
1562           addr += instlen;
1563         }
1564       gen_mask = gen_save_found;
1565       float_mask = float_save_found;
1566     }
1567
1568   /* Fill in the offsets for the registers which gen_mask says were
1569      saved.  */
1570   {
1571     CORE_ADDR reg_position = (get_frame_base (fci)
1572                               + PROC_REG_OFFSET (proc_desc));
1573     for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1574       if (gen_mask & 0x80000000)
1575         {
1576           set_reg_offset (saved_regs, ireg, reg_position);
1577           reg_position -= MIPS_SAVED_REGSIZE;
1578         }
1579   }
1580
1581   /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse
1582      order of that normally used by gcc.  Therefore, we have to fetch
1583      the first instruction of the function, and if it's an entry
1584      instruction that saves $s0 or $s1, correct their saved addresses.  */
1585   if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
1586     {
1587       inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1588       if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)
1589         /* entry */
1590         {
1591           int reg;
1592           int sreg_count = (inst >> 6) & 3;
1593
1594           /* Check if the ra register was pushed on the stack.  */
1595           CORE_ADDR reg_position = (get_frame_base (fci)
1596                                     + PROC_REG_OFFSET (proc_desc));
1597           if (inst & 0x20)
1598             reg_position -= MIPS_SAVED_REGSIZE;
1599
1600           /* Check if the s0 and s1 registers were pushed on the
1601              stack.  */
1602           for (reg = 16; reg < sreg_count + 16; reg++)
1603             {
1604               set_reg_offset (saved_regs, reg, reg_position);
1605               reg_position -= MIPS_SAVED_REGSIZE;
1606             }
1607         }
1608     }
1609
1610   /* Fill in the offsets for the registers which float_mask says were
1611      saved.  */
1612   {
1613     CORE_ADDR reg_position = (get_frame_base (fci)
1614                               + PROC_FREG_OFFSET (proc_desc));
1615
1616     /* Apparently, the freg_offset gives the offset to the first 64
1617        bit saved.
1618
1619        When the ABI specifies 64 bit saved registers, the FREG_OFFSET
1620        designates the first saved 64 bit register.
1621
1622        When the ABI specifies 32 bit saved registers, the ``64 bit
1623        saved DOUBLE'' consists of two adjacent 32 bit registers, Hence
1624        FREG_OFFSET, designates the address of the lower register of
1625        the register pair.  Adjust the offset so that it designates the
1626        upper register of the pair -- i.e., the address of the first
1627        saved 32 bit register.  */
1628
1629     if (MIPS_SAVED_REGSIZE == 4)
1630       reg_position += MIPS_SAVED_REGSIZE;
1631
1632     /* Fill in the offsets for the float registers which float_mask
1633        says were saved.  */
1634     for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1635       if (float_mask & 0x80000000)
1636         {
1637           set_reg_offset (saved_regs, FP0_REGNUM + ireg, reg_position);
1638           reg_position -= MIPS_SAVED_REGSIZE;
1639         }
1640
1641     set_reg_offset (saved_regs, PC_REGNUM, saved_regs[RA_REGNUM]);
1642   }
1643
1644   /* SP_REGNUM, contains the value and not the address.  */
1645   set_reg_offset (saved_regs, SP_REGNUM, get_frame_base (fci));
1646 }
1647
1648 static CORE_ADDR
1649 read_next_frame_reg (struct frame_info *fi, int regno)
1650 {
1651   int optimized;
1652   CORE_ADDR addr;
1653   int realnum;
1654   enum lval_type lval;
1655   char raw_buffer[MAX_REGISTER_SIZE];
1656
1657   if (fi == NULL)
1658     {
1659       regcache_cooked_read (current_regcache, regno, raw_buffer);
1660     }
1661   else
1662     {
1663       frame_register_unwind (fi, regno, &optimized, &lval, &addr, &realnum,
1664                              raw_buffer);
1665       /* FIXME: cagney/2002-09-13: This is just soooo bad.  The MIPS
1666          should have a pseudo register range that correspons to the ABI's,
1667          rather than the ISA's, view of registers.  These registers would
1668          then implicitly describe their size and hence could be used
1669          without the below munging.  */
1670       if (lval == lval_memory)
1671         {
1672           if (regno < 32)
1673             {
1674               /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
1675                  saved. */
1676               return read_memory_integer (addr, MIPS_SAVED_REGSIZE);
1677             }
1678         }
1679     }
1680
1681   return extract_signed_integer (raw_buffer, REGISTER_VIRTUAL_SIZE (regno));
1682 }
1683
1684 /* mips_addr_bits_remove - remove useless address bits  */
1685
1686 static CORE_ADDR
1687 mips_addr_bits_remove (CORE_ADDR addr)
1688 {
1689   if (GDB_TARGET_IS_MIPS64)
1690     {
1691       if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff))
1692         {
1693           /* This hack is a work-around for existing boards using
1694              PMON, the simulator, and any other 64-bit targets that
1695              doesn't have true 64-bit addressing.  On these targets,
1696              the upper 32 bits of addresses are ignored by the
1697              hardware.  Thus, the PC or SP are likely to have been
1698              sign extended to all 1s by instruction sequences that
1699              load 32-bit addresses.  For example, a typical piece of
1700              code that loads an address is this:
1701                  lui $r2, <upper 16 bits>
1702                  ori $r2, <lower 16 bits>
1703              But the lui sign-extends the value such that the upper 32
1704              bits may be all 1s.  The workaround is simply to mask off
1705              these bits.  In the future, gcc may be changed to support
1706              true 64-bit addressing, and this masking will have to be
1707              disabled.  */
1708           addr &= (CORE_ADDR) 0xffffffff;
1709         }
1710     }
1711   else if (mips_mask_address_p ())
1712     {
1713       /* FIXME: This is wrong!  mips_addr_bits_remove() shouldn't be
1714          masking off bits, instead, the actual target should be asking
1715          for the address to be converted to a valid pointer. */
1716       /* Even when GDB is configured for some 32-bit targets
1717          (e.g. mips-elf), BFD is configured to handle 64-bit targets,
1718          so CORE_ADDR is 64 bits.  So we still have to mask off
1719          useless bits from addresses.  */
1720       addr &= (CORE_ADDR) 0xffffffff;
1721     }
1722   return addr;
1723 }
1724
1725 /* mips_software_single_step() is called just before we want to resume
1726    the inferior, if we want to single-step it but there is no hardware
1727    or kernel single-step support (MIPS on GNU/Linux for example).  We find
1728    the target of the coming instruction and breakpoint it.
1729
1730    single_step is also called just after the inferior stops.  If we had
1731    set up a simulated single-step, we undo our damage.  */
1732
1733 void
1734 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1735 {
1736   static CORE_ADDR next_pc;
1737   typedef char binsn_quantum[BREAKPOINT_MAX];
1738   static binsn_quantum break_mem;
1739   CORE_ADDR pc;
1740
1741   if (insert_breakpoints_p)
1742     {
1743       pc = read_register (PC_REGNUM);
1744       next_pc = mips_next_pc (pc);
1745
1746       target_insert_breakpoint (next_pc, break_mem);
1747     }
1748   else
1749     target_remove_breakpoint (next_pc, break_mem);
1750 }
1751
1752 static CORE_ADDR
1753 mips_init_frame_pc_first (int fromleaf, struct frame_info *prev)
1754 {
1755   CORE_ADDR pc, tmp;
1756
1757   pc = ((fromleaf)
1758         ? DEPRECATED_SAVED_PC_AFTER_CALL (get_next_frame (prev))
1759         : get_next_frame (prev)
1760         ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
1761         : read_pc ());
1762   tmp = SKIP_TRAMPOLINE_CODE (pc);
1763   return tmp ? tmp : pc;
1764 }
1765
1766
1767 static CORE_ADDR
1768 mips_frame_saved_pc (struct frame_info *frame)
1769 {
1770   CORE_ADDR saved_pc;
1771   mips_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
1772   /* We have to get the saved pc from the sigcontext
1773      if it is a signal handler frame.  */
1774   int pcreg = (get_frame_type (frame) == SIGTRAMP_FRAME) ? PC_REGNUM
1775   : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM);
1776
1777   if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
1778     {
1779       LONGEST tmp;
1780       frame_unwind_signed_register (frame, PC_REGNUM, &tmp);
1781       saved_pc = tmp;
1782     }
1783   else if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1784     saved_pc = read_memory_integer (get_frame_base (frame) - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1785   else
1786     saved_pc = read_next_frame_reg (frame, pcreg);
1787
1788   return ADDR_BITS_REMOVE (saved_pc);
1789 }
1790
1791 static struct mips_extra_func_info temp_proc_desc;
1792
1793 /* This hack will go away once the get_prev_frame() code has been
1794    modified to set the frame's type first.  That is BEFORE init extra
1795    frame info et.al.  is called.  This is because it will become
1796    possible to skip the init extra info call for sigtramp and dummy
1797    frames.  */
1798 static CORE_ADDR *temp_saved_regs;
1799
1800 /* Set a register's saved stack address in temp_saved_regs.  If an
1801    address has already been set for this register, do nothing; this
1802    way we will only recognize the first save of a given register in a
1803    function prologue.  */
1804
1805 static void
1806 set_reg_offset (CORE_ADDR *saved_regs, int regno, CORE_ADDR offset)
1807 {
1808   if (saved_regs[regno] == 0)
1809     saved_regs[regno] = offset;
1810 }
1811
1812
1813 /* Test whether the PC points to the return instruction at the
1814    end of a function. */
1815
1816 static int
1817 mips_about_to_return (CORE_ADDR pc)
1818 {
1819   if (pc_is_mips16 (pc))
1820     /* This mips16 case isn't necessarily reliable.  Sometimes the compiler
1821        generates a "jr $ra"; other times it generates code to load
1822        the return address from the stack to an accessible register (such
1823        as $a3), then a "jr" using that register.  This second case
1824        is almost impossible to distinguish from an indirect jump
1825        used for switch statements, so we don't even try.  */
1826     return mips_fetch_instruction (pc) == 0xe820;       /* jr $ra */
1827   else
1828     return mips_fetch_instruction (pc) == 0x3e00008;    /* jr $ra */
1829 }
1830
1831
1832 /* This fencepost looks highly suspicious to me.  Removing it also
1833    seems suspicious as it could affect remote debugging across serial
1834    lines.  */
1835
1836 static CORE_ADDR
1837 heuristic_proc_start (CORE_ADDR pc)
1838 {
1839   CORE_ADDR start_pc;
1840   CORE_ADDR fence;
1841   int instlen;
1842   int seen_adjsp = 0;
1843
1844   pc = ADDR_BITS_REMOVE (pc);
1845   start_pc = pc;
1846   fence = start_pc - heuristic_fence_post;
1847   if (start_pc == 0)
1848     return 0;
1849
1850   if (heuristic_fence_post == UINT_MAX
1851       || fence < VM_MIN_ADDRESS)
1852     fence = VM_MIN_ADDRESS;
1853
1854   instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1855
1856   /* search back for previous return */
1857   for (start_pc -= instlen;; start_pc -= instlen)
1858     if (start_pc < fence)
1859       {
1860         /* It's not clear to me why we reach this point when
1861            stop_soon, but with this test, at least we
1862            don't print out warnings for every child forked (eg, on
1863            decstation).  22apr93 [email protected].  */
1864         if (stop_soon == NO_STOP_QUIETLY)
1865           {
1866             static int blurb_printed = 0;
1867
1868             warning ("Warning: GDB can't find the start of the function at 0x%s.",
1869                      paddr_nz (pc));
1870
1871             if (!blurb_printed)
1872               {
1873                 /* This actually happens frequently in embedded
1874                    development, when you first connect to a board
1875                    and your stack pointer and pc are nowhere in
1876                    particular.  This message needs to give people
1877                    in that situation enough information to
1878                    determine that it's no big deal.  */
1879                 printf_filtered ("\n\
1880     GDB is unable to find the start of the function at 0x%s\n\
1881 and thus can't determine the size of that function's stack frame.\n\
1882 This means that GDB may be unable to access that stack frame, or\n\
1883 the frames below it.\n\
1884     This problem is most likely caused by an invalid program counter or\n\
1885 stack pointer.\n\
1886     However, if you think GDB should simply search farther back\n\
1887 from 0x%s for code which looks like the beginning of a\n\
1888 function, you can increase the range of the search using the `set\n\
1889 heuristic-fence-post' command.\n",
1890                                  paddr_nz (pc), paddr_nz (pc));
1891                 blurb_printed = 1;
1892               }
1893           }
1894
1895         return 0;
1896       }
1897     else if (pc_is_mips16 (start_pc))
1898       {
1899         unsigned short inst;
1900
1901         /* On MIPS16, any one of the following is likely to be the
1902            start of a function:
1903            entry
1904            addiu sp,-n
1905            daddiu sp,-n
1906            extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'  */
1907         inst = mips_fetch_instruction (start_pc);
1908         if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)      /* entry */
1909             || (inst & 0xff80) == 0x6380        /* addiu sp,-n */
1910             || (inst & 0xff80) == 0xfb80        /* daddiu sp,-n */
1911             || ((inst & 0xf810) == 0xf010 && seen_adjsp))       /* extend -n */
1912           break;
1913         else if ((inst & 0xff00) == 0x6300      /* addiu sp */
1914                  || (inst & 0xff00) == 0xfb00)  /* daddiu sp */
1915           seen_adjsp = 1;
1916         else
1917           seen_adjsp = 0;
1918       }
1919     else if (mips_about_to_return (start_pc))
1920       {
1921         start_pc += 2 * MIPS_INSTLEN;   /* skip return, and its delay slot */
1922         break;
1923       }
1924
1925   return start_pc;
1926 }
1927
1928 /* Fetch the immediate value from a MIPS16 instruction.
1929    If the previous instruction was an EXTEND, use it to extend
1930    the upper bits of the immediate value.  This is a helper function
1931    for mips16_heuristic_proc_desc.  */
1932
1933 static int
1934 mips16_get_imm (unsigned short prev_inst,       /* previous instruction */
1935                 unsigned short inst,    /* current instruction */
1936                 int nbits,              /* number of bits in imm field */
1937                 int scale,              /* scale factor to be applied to imm */
1938                 int is_signed)          /* is the imm field signed? */
1939 {
1940   int offset;
1941
1942   if ((prev_inst & 0xf800) == 0xf000)   /* prev instruction was EXTEND? */
1943     {
1944       offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1945       if (offset & 0x8000)      /* check for negative extend */
1946         offset = 0 - (0x10000 - (offset & 0xffff));
1947       return offset | (inst & 0x1f);
1948     }
1949   else
1950     {
1951       int max_imm = 1 << nbits;
1952       int mask = max_imm - 1;
1953       int sign_bit = max_imm >> 1;
1954
1955       offset = inst & mask;
1956       if (is_signed && (offset & sign_bit))
1957         offset = 0 - (max_imm - offset);
1958       return offset * scale;
1959     }
1960 }
1961
1962
1963 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1964    stream from start_pc to limit_pc.  */
1965
1966 static void
1967 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1968                             struct frame_info *next_frame, CORE_ADDR sp)
1969 {
1970   CORE_ADDR cur_pc;
1971   CORE_ADDR frame_addr = 0;     /* Value of $r17, used as frame pointer */
1972   unsigned short prev_inst = 0; /* saved copy of previous instruction */
1973   unsigned inst = 0;            /* current instruction */
1974   unsigned entry_inst = 0;      /* the entry instruction */
1975   int reg, offset;
1976
1977   PROC_FRAME_OFFSET (&temp_proc_desc) = 0;      /* size of stack frame */
1978   PROC_FRAME_ADJUST (&temp_proc_desc) = 0;      /* offset of FP from SP */
1979
1980   for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1981     {
1982       /* Save the previous instruction.  If it's an EXTEND, we'll extract
1983          the immediate offset extension from it in mips16_get_imm.  */
1984       prev_inst = inst;
1985
1986       /* Fetch and decode the instruction.   */
1987       inst = (unsigned short) mips_fetch_instruction (cur_pc);
1988       if ((inst & 0xff00) == 0x6300     /* addiu sp */
1989           || (inst & 0xff00) == 0xfb00)         /* daddiu sp */
1990         {
1991           offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1992           if (offset < 0)       /* negative stack adjustment? */
1993             PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
1994           else
1995             /* Exit loop if a positive stack adjustment is found, which
1996                usually means that the stack cleanup code in the function
1997                epilogue is reached.  */
1998             break;
1999         }
2000       else if ((inst & 0xf800) == 0xd000)       /* sw reg,n($sp) */
2001         {
2002           offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2003           reg = mips16_to_32_reg[(inst & 0x700) >> 8];
2004           PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2005           set_reg_offset (temp_saved_regs, reg, sp + offset);
2006         }
2007       else if ((inst & 0xff00) == 0xf900)       /* sd reg,n($sp) */
2008         {
2009           offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2010           reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2011           PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2012           set_reg_offset (temp_saved_regs, reg, sp + offset);
2013         }
2014       else if ((inst & 0xff00) == 0x6200)       /* sw $ra,n($sp) */
2015         {
2016           offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2017           PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2018           set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2019         }
2020       else if ((inst & 0xff00) == 0xfa00)       /* sd $ra,n($sp) */
2021         {
2022           offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2023           PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2024           set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2025         }
2026       else if (inst == 0x673d)  /* move $s1, $sp */
2027         {
2028           frame_addr = sp;
2029           PROC_FRAME_REG (&temp_proc_desc) = 17;
2030         }
2031       else if ((inst & 0xff00) == 0x0100)       /* addiu $s1,sp,n */
2032         {
2033           offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2034           frame_addr = sp + offset;
2035           PROC_FRAME_REG (&temp_proc_desc) = 17;
2036           PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2037         }
2038       else if ((inst & 0xFF00) == 0xd900)       /* sw reg,offset($s1) */
2039         {
2040           offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2041           reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2042           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2043           set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2044         }
2045       else if ((inst & 0xFF00) == 0x7900)       /* sd reg,offset($s1) */
2046         {
2047           offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2048           reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2049           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2050           set_reg_offset (temp_saved_regs, reg, frame_addr + offset);
2051         }
2052       else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)    /* entry */
2053         entry_inst = inst;      /* save for later processing */
2054       else if ((inst & 0xf800) == 0x1800)       /* jal(x) */
2055         cur_pc += MIPS16_INSTLEN;       /* 32-bit instruction */
2056     }
2057
2058   /* The entry instruction is typically the first instruction in a function,
2059      and it stores registers at offsets relative to the value of the old SP
2060      (before the prologue).  But the value of the sp parameter to this
2061      function is the new SP (after the prologue has been executed).  So we
2062      can't calculate those offsets until we've seen the entire prologue,
2063      and can calculate what the old SP must have been. */
2064   if (entry_inst != 0)
2065     {
2066       int areg_count = (entry_inst >> 8) & 7;
2067       int sreg_count = (entry_inst >> 6) & 3;
2068
2069       /* The entry instruction always subtracts 32 from the SP.  */
2070       PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2071
2072       /* Now we can calculate what the SP must have been at the
2073          start of the function prologue.  */
2074       sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2075
2076       /* Check if a0-a3 were saved in the caller's argument save area.  */
2077       for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2078         {
2079           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2080           set_reg_offset (temp_saved_regs, reg, sp + offset);
2081           offset += MIPS_SAVED_REGSIZE;
2082         }
2083
2084       /* Check if the ra register was pushed on the stack.  */
2085       offset = -4;
2086       if (entry_inst & 0x20)
2087         {
2088           PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2089           set_reg_offset (temp_saved_regs, RA_REGNUM, sp + offset);
2090           offset -= MIPS_SAVED_REGSIZE;
2091         }
2092
2093       /* Check if the s0 and s1 registers were pushed on the stack.  */
2094       for (reg = 16; reg < sreg_count + 16; reg++)
2095         {
2096           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2097           set_reg_offset (temp_saved_regs, reg, sp + offset);
2098           offset -= MIPS_SAVED_REGSIZE;
2099         }
2100     }
2101 }
2102
2103 static void
2104 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2105                             struct frame_info *next_frame, CORE_ADDR sp)
2106 {
2107   CORE_ADDR cur_pc;
2108   CORE_ADDR frame_addr = 0;     /* Value of $r30. Used by gcc for frame-pointer */
2109 restart:
2110   temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2111   memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2112   PROC_FRAME_OFFSET (&temp_proc_desc) = 0;
2113   PROC_FRAME_ADJUST (&temp_proc_desc) = 0;      /* offset of FP from SP */
2114   for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2115     {
2116       unsigned long inst, high_word, low_word;
2117       int reg;
2118
2119       /* Fetch the instruction.   */
2120       inst = (unsigned long) mips_fetch_instruction (cur_pc);
2121
2122       /* Save some code by pre-extracting some useful fields.  */
2123       high_word = (inst >> 16) & 0xffff;
2124       low_word = inst & 0xffff;
2125       reg = high_word & 0x1f;
2126
2127       if (high_word == 0x27bd   /* addiu $sp,$sp,-i */
2128           || high_word == 0x23bd        /* addi $sp,$sp,-i */
2129           || high_word == 0x67bd)       /* daddiu $sp,$sp,-i */
2130         {
2131           if (low_word & 0x8000)        /* negative stack adjustment? */
2132             PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word;
2133           else
2134             /* Exit loop if a positive stack adjustment is found, which
2135                usually means that the stack cleanup code in the function
2136                epilogue is reached.  */
2137             break;
2138         }
2139       else if ((high_word & 0xFFE0) == 0xafa0)  /* sw reg,offset($sp) */
2140         {
2141           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2142           set_reg_offset (temp_saved_regs, reg, sp + low_word);
2143         }
2144       else if ((high_word & 0xFFE0) == 0xffa0)  /* sd reg,offset($sp) */
2145         {
2146           /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
2147              but the register size used is only 32 bits. Make the address
2148              for the saved register point to the lower 32 bits.  */
2149           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2150           set_reg_offset (temp_saved_regs, reg, sp + low_word + 8 - MIPS_REGSIZE);
2151         }
2152       else if (high_word == 0x27be)     /* addiu $30,$sp,size */
2153         {
2154           /* Old gcc frame, r30 is virtual frame pointer.  */
2155           if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc))
2156             frame_addr = sp + low_word;
2157           else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2158             {
2159               unsigned alloca_adjust;
2160               PROC_FRAME_REG (&temp_proc_desc) = 30;
2161               frame_addr = read_next_frame_reg (next_frame, 30);
2162               alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2163               if (alloca_adjust > 0)
2164                 {
2165                   /* FP > SP + frame_size. This may be because
2166                    * of an alloca or somethings similar.
2167                    * Fix sp to "pre-alloca" value, and try again.
2168                    */
2169                   sp += alloca_adjust;
2170                   goto restart;
2171                 }
2172             }
2173         }
2174       /* move $30,$sp.  With different versions of gas this will be either
2175          `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2176          Accept any one of these.  */
2177       else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2178         {
2179           /* New gcc frame, virtual frame pointer is at r30 + frame_size.  */
2180           if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
2181             {
2182               unsigned alloca_adjust;
2183               PROC_FRAME_REG (&temp_proc_desc) = 30;
2184               frame_addr = read_next_frame_reg (next_frame, 30);
2185               alloca_adjust = (unsigned) (frame_addr - sp);
2186               if (alloca_adjust > 0)
2187                 {
2188                   /* FP > SP + frame_size. This may be because
2189                    * of an alloca or somethings similar.
2190                    * Fix sp to "pre-alloca" value, and try again.
2191                    */
2192                   sp += alloca_adjust;
2193                   goto restart;
2194                 }
2195             }
2196         }
2197       else if ((high_word & 0xFFE0) == 0xafc0)  /* sw reg,offset($30) */
2198         {
2199           PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2200           set_reg_offset (temp_saved_regs, reg, frame_addr + low_word);
2201         }
2202     }
2203 }
2204
2205 static mips_extra_func_info_t
2206 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2207                      struct frame_info *next_frame, int cur_frame)
2208 {
2209   CORE_ADDR sp;
2210
2211   if (cur_frame)
2212     sp = read_next_frame_reg (next_frame, SP_REGNUM);
2213   else
2214     sp = 0;
2215
2216   if (start_pc == 0)
2217     return NULL;
2218   memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2219   temp_saved_regs = xrealloc (temp_saved_regs, SIZEOF_FRAME_SAVED_REGS);
2220   memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
2221   PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2222   PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
2223   PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2224
2225   if (start_pc + 200 < limit_pc)
2226     limit_pc = start_pc + 200;
2227   if (pc_is_mips16 (start_pc))
2228     mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2229   else
2230     mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
2231   return &temp_proc_desc;
2232 }
2233
2234 struct mips_objfile_private
2235 {
2236   bfd_size_type size;
2237   char *contents;
2238 };
2239
2240 /* Global used to communicate between non_heuristic_proc_desc and
2241    compare_pdr_entries within qsort ().  */
2242 static bfd *the_bfd;
2243
2244 static int
2245 compare_pdr_entries (const void *a, const void *b)
2246 {
2247   CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2248   CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2249
2250   if (lhs < rhs)
2251     return -1;
2252   else if (lhs == rhs)
2253     return 0;
2254   else
2255     return 1;
2256 }
2257
2258 static mips_extra_func_info_t
2259 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2260 {
2261   CORE_ADDR startaddr;
2262   mips_extra_func_info_t proc_desc;
2263   struct block *b = block_for_pc (pc);
2264   struct symbol *sym;
2265   struct obj_section *sec;
2266   struct mips_objfile_private *priv;
2267
2268   if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
2269     return NULL;
2270
2271   find_pc_partial_function (pc, NULL, &startaddr, NULL);
2272   if (addrptr)
2273     *addrptr = startaddr;
2274
2275   priv = NULL;
2276
2277   sec = find_pc_section (pc);
2278   if (sec != NULL)
2279     {
2280       priv = (struct mips_objfile_private *) sec->objfile->obj_private;
2281
2282       /* Search the ".pdr" section generated by GAS.  This includes most of
2283          the information normally found in ECOFF PDRs.  */
2284
2285       the_bfd = sec->objfile->obfd;
2286       if (priv == NULL
2287           && (the_bfd->format == bfd_object
2288               && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2289               && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2290         {
2291           /* Right now GAS only outputs the address as a four-byte sequence.
2292              This means that we should not bother with this method on 64-bit
2293              targets (until that is fixed).  */
2294
2295           priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2296                                 sizeof (struct mips_objfile_private));
2297           priv->size = 0;
2298           sec->objfile->obj_private = priv;
2299         }
2300       else if (priv == NULL)
2301         {
2302           asection *bfdsec;
2303
2304           priv = obstack_alloc (& sec->objfile->psymbol_obstack,
2305                                 sizeof (struct mips_objfile_private));
2306
2307           bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2308           if (bfdsec != NULL)
2309             {
2310               priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2311               priv->contents = obstack_alloc (& sec->objfile->psymbol_obstack,
2312                                               priv->size);
2313               bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2314                                         priv->contents, 0, priv->size);
2315
2316               /* In general, the .pdr section is sorted.  However, in the
2317                  presence of multiple code sections (and other corner cases)
2318                  it can become unsorted.  Sort it so that we can use a faster
2319                  binary search.  */
2320               qsort (priv->contents, priv->size / 32, 32, compare_pdr_entries);
2321             }
2322           else
2323             priv->size = 0;
2324
2325           sec->objfile->obj_private = priv;
2326         }
2327       the_bfd = NULL;
2328
2329       if (priv->size != 0)
2330         {
2331           int low, mid, high;
2332           char *ptr;
2333
2334           low = 0;
2335           high = priv->size / 32;
2336
2337           do
2338             {
2339               CORE_ADDR pdr_pc;
2340
2341               mid = (low + high) / 2;
2342
2343               ptr = priv->contents + mid * 32;
2344               pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2345               pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2346                                   SECT_OFF_TEXT (sec->objfile));
2347               if (pdr_pc == startaddr)
2348                 break;
2349               if (pdr_pc > startaddr)
2350                 high = mid;
2351               else
2352                 low = mid + 1;
2353             }
2354           while (low != high);
2355
2356           if (low != high)
2357             {
2358               struct symbol *sym = find_pc_function (pc);
2359
2360               /* Fill in what we need of the proc_desc.  */
2361               proc_desc = (mips_extra_func_info_t)
2362                 obstack_alloc (&sec->objfile->psymbol_obstack,
2363                                sizeof (struct mips_extra_func_info));
2364               PROC_LOW_ADDR (proc_desc) = startaddr;
2365
2366               /* Only used for dummy frames.  */
2367               PROC_HIGH_ADDR (proc_desc) = 0;
2368
2369               PROC_FRAME_OFFSET (proc_desc)
2370                 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2371               PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2372                                                        ptr + 24);
2373               PROC_FRAME_ADJUST (proc_desc) = 0;
2374               PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2375                                                       ptr + 4);
2376               PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2377                                                        ptr + 12);
2378               PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2379                                                         ptr + 8);
2380               PROC_FREG_OFFSET (proc_desc)
2381                 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2382               PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2383                                                     ptr + 28);
2384               proc_desc->pdr.isym = (long) sym;
2385
2386               return proc_desc;
2387             }
2388         }
2389     }
2390
2391   if (b == NULL)
2392     return NULL;
2393
2394   if (startaddr > BLOCK_START (b))
2395     {
2396       /* This is the "pathological" case referred to in a comment in
2397          print_frame_info.  It might be better to move this check into
2398          symbol reading.  */
2399       return NULL;
2400     }
2401
2402   sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
2403
2404   /* If we never found a PDR for this function in symbol reading, then
2405      examine prologues to find the information.  */
2406   if (sym)
2407     {
2408       proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
2409       if (PROC_FRAME_REG (proc_desc) == -1)
2410         return NULL;
2411       else
2412         return proc_desc;
2413     }
2414   else
2415     return NULL;
2416 }
2417
2418
2419 static mips_extra_func_info_t
2420 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame)
2421 {
2422   mips_extra_func_info_t proc_desc;
2423   CORE_ADDR startaddr = 0;
2424
2425   proc_desc = non_heuristic_proc_desc (pc, &startaddr);
2426
2427   if (proc_desc)
2428     {
2429       /* IF this is the topmost frame AND
2430        * (this proc does not have debugging information OR
2431        * the PC is in the procedure prologue)
2432        * THEN create a "heuristic" proc_desc (by analyzing
2433        * the actual code) to replace the "official" proc_desc.
2434        */
2435       if (next_frame == NULL)
2436         {
2437           struct symtab_and_line val;
2438           struct symbol *proc_symbol =
2439             PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc);
2440
2441           if (proc_symbol)
2442             {
2443               val = find_pc_line (BLOCK_START
2444                                   (SYMBOL_BLOCK_VALUE (proc_symbol)),
2445                                   0);
2446               val.pc = val.end ? val.end : pc;
2447             }
2448           if (!proc_symbol || pc < val.pc)
2449             {
2450               mips_extra_func_info_t found_heuristic =
2451                 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
2452                                      pc, next_frame, cur_frame);
2453               if (found_heuristic)
2454                 proc_desc = found_heuristic;
2455             }
2456         }
2457     }
2458   else
2459     {
2460       /* Is linked_proc_desc_table really necessary?  It only seems to be used
2461          by procedure call dummys.  However, the procedures being called ought
2462          to have their own proc_descs, and even if they don't,
2463          heuristic_proc_desc knows how to create them! */
2464
2465       register struct linked_proc_info *link;
2466
2467       for (link = linked_proc_desc_table; link; link = link->next)
2468         if (PROC_LOW_ADDR (&link->info) <= pc
2469             && PROC_HIGH_ADDR (&link->info) > pc)
2470           return &link->info;
2471
2472       if (startaddr == 0)
2473         startaddr = heuristic_proc_start (pc);
2474
2475       proc_desc =
2476         heuristic_proc_desc (startaddr, pc, next_frame, cur_frame);
2477     }
2478   return proc_desc;
2479 }
2480
2481 static CORE_ADDR
2482 get_frame_pointer (struct frame_info *frame,
2483                    mips_extra_func_info_t proc_desc)
2484 {
2485   return (read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
2486           + PROC_FRAME_OFFSET (proc_desc)
2487           - PROC_FRAME_ADJUST (proc_desc));
2488 }
2489
2490 static mips_extra_func_info_t cached_proc_desc;
2491
2492 static CORE_ADDR
2493 mips_frame_chain (struct frame_info *frame)
2494 {
2495   mips_extra_func_info_t proc_desc;
2496   CORE_ADDR tmp;
2497   CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
2498
2499   if (saved_pc == 0 || inside_entry_file (saved_pc))
2500     return 0;
2501
2502   /* Check if the PC is inside a call stub.  If it is, fetch the
2503      PC of the caller of that stub.  */
2504   if ((tmp = SKIP_TRAMPOLINE_CODE (saved_pc)) != 0)
2505     saved_pc = tmp;
2506
2507   if (DEPRECATED_PC_IN_CALL_DUMMY (saved_pc, 0, 0))
2508     {
2509       /* A dummy frame, uses SP not FP.  Get the old SP value.  If all
2510          is well, frame->frame the bottom of the current frame will
2511          contain that value.  */
2512       return get_frame_base (frame);
2513     }
2514
2515   /* Look up the procedure descriptor for this PC.  */
2516   proc_desc = find_proc_desc (saved_pc, frame, 1);
2517   if (!proc_desc)
2518     return 0;
2519
2520   cached_proc_desc = proc_desc;
2521
2522   /* If no frame pointer and frame size is zero, we must be at end
2523      of stack (or otherwise hosed).  If we don't check frame size,
2524      we loop forever if we see a zero size frame.  */
2525   if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
2526       && PROC_FRAME_OFFSET (proc_desc) == 0
2527       /* The previous frame from a sigtramp frame might be frameless
2528          and have frame size zero.  */
2529       && !(get_frame_type (frame) == SIGTRAMP_FRAME)
2530       /* For a generic dummy frame, let get_frame_pointer() unwind a
2531          register value saved as part of the dummy frame call.  */
2532       && !(DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0)))
2533     return 0;
2534   else
2535     return get_frame_pointer (frame, proc_desc);
2536 }
2537
2538 static void
2539 mips_init_extra_frame_info (int fromleaf, struct frame_info *fci)
2540 {
2541   int regnum;
2542   mips_extra_func_info_t proc_desc;
2543
2544   if (get_frame_type (fci) == DUMMY_FRAME)
2545     return;
2546
2547   /* Use proc_desc calculated in frame_chain.  When there is no
2548      next frame, i.e, get_next_frame (fci) == NULL, we call
2549      find_proc_desc () to calculate it, passing an explicit
2550      NULL as the frame parameter.  */
2551   proc_desc =
2552     get_next_frame (fci)
2553     ? cached_proc_desc
2554     : find_proc_desc (get_frame_pc (fci),
2555                       NULL /* i.e, get_next_frame (fci) */,
2556                       1);
2557
2558   frame_extra_info_zalloc (fci, sizeof (struct frame_extra_info));
2559
2560   deprecated_set_frame_saved_regs_hack (fci, NULL);
2561   get_frame_extra_info (fci)->proc_desc =
2562     proc_desc == &temp_proc_desc ? 0 : proc_desc;
2563   if (proc_desc)
2564     {
2565       /* Fixup frame-pointer - only needed for top frame */
2566       /* This may not be quite right, if proc has a real frame register.
2567          Get the value of the frame relative sp, procedure might have been
2568          interrupted by a signal at it's very start.  */
2569       if (get_frame_pc (fci) == PROC_LOW_ADDR (proc_desc)
2570           && !PROC_DESC_IS_DUMMY (proc_desc))
2571         deprecated_update_frame_base_hack (fci, read_next_frame_reg (get_next_frame (fci), SP_REGNUM));
2572       else if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fci), 0, 0))
2573         /* Do not ``fix'' fci->frame.  It will have the value of the
2574            generic dummy frame's top-of-stack (since the draft
2575            fci->frame is obtained by returning the unwound stack
2576            pointer) and that is what we want.  That way the fci->frame
2577            value will match the top-of-stack value that was saved as
2578            part of the dummy frames data.  */
2579         /* Do nothing.  */;
2580       else
2581         deprecated_update_frame_base_hack (fci, get_frame_pointer (get_next_frame (fci), proc_desc));
2582
2583       if (proc_desc == &temp_proc_desc)
2584         {
2585           char *name;
2586
2587           /* Do not set the saved registers for a sigtramp frame,
2588              mips_find_saved_registers will do that for us.  We can't
2589              use (get_frame_type (fci) == SIGTRAMP_FRAME), it is not
2590              yet set.  */
2591           /* FIXME: cagney/2002-11-18: This problem will go away once
2592              frame.c:get_prev_frame() is modified to set the frame's
2593              type before calling functions like this.  */
2594           find_pc_partial_function (get_frame_pc (fci), &name,
2595                                     (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
2596           if (!PC_IN_SIGTRAMP (get_frame_pc (fci), name))
2597             {
2598               frame_saved_regs_zalloc (fci);
2599               /* Set value of previous frame's stack pointer.
2600                  Remember that saved_regs[SP_REGNUM] is special in
2601                  that it contains the value of the stack pointer
2602                  register.  The other saved_regs values are addresses
2603                  (in the inferior) at which a given register's value
2604                  may be found.  */
2605               set_reg_offset (temp_saved_regs, SP_REGNUM,
2606                               get_frame_base (fci));
2607               set_reg_offset (temp_saved_regs, PC_REGNUM,
2608                               temp_saved_regs[RA_REGNUM]);
2609               memcpy (get_frame_saved_regs (fci), temp_saved_regs,
2610                       SIZEOF_FRAME_SAVED_REGS);
2611             }
2612         }
2613
2614       /* hack: if argument regs are saved, guess these contain args */
2615       /* assume we can't tell how many args for now */
2616       get_frame_extra_info (fci)->num_args = -1;
2617       for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
2618         {
2619           if (PROC_REG_MASK (proc_desc) & (1 << regnum))
2620             {
2621               get_frame_extra_info (fci)->num_args = regnum - A0_REGNUM + 1;
2622               break;
2623             }
2624         }
2625     }
2626 }
2627
2628 /* MIPS stack frames are almost impenetrable.  When execution stops,
2629    we basically have to look at symbol information for the function
2630    that we stopped in, which tells us *which* register (if any) is
2631    the base of the frame pointer, and what offset from that register
2632    the frame itself is at.
2633
2634    This presents a problem when trying to examine a stack in memory
2635    (that isn't executing at the moment), using the "frame" command.  We
2636    don't have a PC, nor do we have any registers except SP.
2637
2638    This routine takes two arguments, SP and PC, and tries to make the
2639    cached frames look as if these two arguments defined a frame on the
2640    cache.  This allows the rest of info frame to extract the important
2641    arguments without difficulty.  */
2642
2643 struct frame_info *
2644 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
2645 {
2646   if (argc != 2)
2647     error ("MIPS frame specifications require two arguments: sp and pc");
2648
2649   return create_new_frame (argv[0], argv[1]);
2650 }
2651
2652 /* According to the current ABI, should the type be passed in a
2653    floating-point register (assuming that there is space)?  When there
2654    is no FPU, FP are not even considered as possibile candidates for
2655    FP registers and, consequently this returns false - forces FP
2656    arguments into integer registers. */
2657
2658 static int
2659 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2660 {
2661   return ((typecode == TYPE_CODE_FLT
2662            || (MIPS_EABI
2663                && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
2664                && TYPE_NFIELDS (arg_type) == 1
2665                && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
2666           && MIPS_FPU_TYPE != MIPS_FPU_NONE);
2667 }
2668
2669 /* On o32, argument passing in GPRs depends on the alignment of the type being
2670    passed.  Return 1 if this type must be aligned to a doubleword boundary. */
2671
2672 static int
2673 mips_type_needs_double_align (struct type *type)
2674 {
2675   enum type_code typecode = TYPE_CODE (type);
2676
2677   if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2678     return 1;
2679   else if (typecode == TYPE_CODE_STRUCT)
2680     {
2681       if (TYPE_NFIELDS (type) < 1)
2682         return 0;
2683       return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2684     }
2685   else if (typecode == TYPE_CODE_UNION)
2686     {
2687       int i, n;
2688
2689       n = TYPE_NFIELDS (type);
2690       for (i = 0; i < n; i++)
2691         if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2692           return 1;
2693       return 0;
2694     }
2695   return 0;
2696 }
2697
2698 /* Macros to round N up or down to the next A boundary; 
2699    A must be a power of two.  */
2700
2701 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
2702 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
2703
2704 /* Adjust the address downward (direction of stack growth) so that it
2705    is correctly aligned for a new stack frame.  */
2706 static CORE_ADDR
2707 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2708 {
2709   return ROUND_DOWN (addr, 16);
2710 }
2711
2712 static CORE_ADDR
2713 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2714                            struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2715                            struct value **args, CORE_ADDR sp, int struct_return,
2716                            CORE_ADDR struct_addr)
2717 {
2718   int argreg;
2719   int float_argreg;
2720   int argnum;
2721   int len = 0;
2722   int stack_offset = 0;
2723
2724   /* For shared libraries, "t9" needs to point at the function
2725      address.  */
2726   regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2727
2728   /* Set the return address register to point to the entry point of
2729      the program, where a breakpoint lies in wait.  */
2730   regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2731
2732   /* First ensure that the stack and structure return address (if any)
2733      are properly aligned.  The stack has to be at least 64-bit
2734      aligned even on 32-bit machines, because doubles must be 64-bit
2735      aligned.  For n32 and n64, stack frames need to be 128-bit
2736      aligned, so we round to this widest known alignment.  */
2737
2738   sp = ROUND_DOWN (sp, 16);
2739   struct_addr = ROUND_DOWN (struct_addr, 16);
2740
2741   /* Now make space on the stack for the args.  We allocate more
2742      than necessary for EABI, because the first few arguments are
2743      passed in registers, but that's OK.  */
2744   for (argnum = 0; argnum < nargs; argnum++)
2745     len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), 
2746                      MIPS_STACK_ARGSIZE);
2747   sp -= ROUND_UP (len, 16);
2748
2749   if (mips_debug)
2750     fprintf_unfiltered (gdb_stdlog, 
2751                         "mips_eabi_push_dummy_call: sp=0x%s allocated %d\n",
2752                         paddr_nz (sp), ROUND_UP (len, 16));
2753
2754   /* Initialize the integer and float register pointers.  */
2755   argreg = A0_REGNUM;
2756   float_argreg = FPA0_REGNUM;
2757
2758   /* The struct_return pointer occupies the first parameter-passing reg.  */
2759   if (struct_return)
2760     {
2761       if (mips_debug)
2762         fprintf_unfiltered (gdb_stdlog,
2763                             "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
2764                             argreg, paddr_nz (struct_addr));
2765       write_register (argreg++, struct_addr);
2766     }
2767
2768   /* Now load as many as possible of the first arguments into
2769      registers, and push the rest onto the stack.  Loop thru args
2770      from first to last.  */
2771   for (argnum = 0; argnum < nargs; argnum++)
2772     {
2773       char *val;
2774       char valbuf[MAX_REGISTER_SIZE];
2775       struct value *arg = args[argnum];
2776       struct type *arg_type = check_typedef (VALUE_TYPE (arg));
2777       int len = TYPE_LENGTH (arg_type);
2778       enum type_code typecode = TYPE_CODE (arg_type);
2779
2780       if (mips_debug)
2781         fprintf_unfiltered (gdb_stdlog,
2782                             "mips_eabi_push_dummy_call: %d len=%d type=%d",
2783                             argnum + 1, len, (int) typecode);
2784
2785       /* The EABI passes structures that do not fit in a register by
2786          reference.  */
2787       if (len > MIPS_SAVED_REGSIZE
2788           && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2789         {
2790           store_unsigned_integer (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
2791           typecode = TYPE_CODE_PTR;
2792           len = MIPS_SAVED_REGSIZE;
2793           val = valbuf;
2794           if (mips_debug)
2795             fprintf_unfiltered (gdb_stdlog, " push");
2796         }
2797       else
2798         val = (char *) VALUE_CONTENTS (arg);
2799
2800       /* 32-bit ABIs always start floating point arguments in an
2801          even-numbered floating point register.  Round the FP register
2802          up before the check to see if there are any FP registers
2803          left.  Non MIPS_EABI targets also pass the FP in the integer
2804          registers so also round up normal registers.  */
2805       if (!FP_REGISTER_DOUBLE
2806           && fp_register_arg_p (typecode, arg_type))
2807         {
2808           if ((float_argreg & 1))
2809             float_argreg++;
2810         }
2811
2812       /* Floating point arguments passed in registers have to be
2813          treated specially.  On 32-bit architectures, doubles
2814          are passed in register pairs; the even register gets
2815          the low word, and the odd register gets the high word.
2816          On non-EABI processors, the first two floating point arguments are
2817          also copied to general registers, because MIPS16 functions
2818          don't use float registers for arguments.  This duplication of
2819          arguments in general registers can't hurt non-MIPS16 functions
2820          because those registers are normally skipped.  */
2821       /* MIPS_EABI squeezes a struct that contains a single floating
2822          point value into an FP register instead of pushing it onto the
2823          stack.  */
2824       if (fp_register_arg_p (typecode, arg_type)
2825           && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
2826         {
2827           if (!FP_REGISTER_DOUBLE && len == 8)
2828             {
2829               int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
2830               unsigned long regval;
2831
2832               /* Write the low word of the double to the even register(s).  */
2833               regval = extract_unsigned_integer (val + low_offset, 4);
2834               if (mips_debug)
2835                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2836                                     float_argreg, phex (regval, 4));
2837               write_register (float_argreg++, regval);
2838
2839               /* Write the high word of the double to the odd register(s).  */
2840               regval = extract_unsigned_integer (val + 4 - low_offset, 4);
2841               if (mips_debug)
2842                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2843                                     float_argreg, phex (regval, 4));
2844               write_register (float_argreg++, regval);
2845             }
2846           else
2847             {
2848               /* This is a floating point value that fits entirely
2849                  in a single register.  */
2850               /* On 32 bit ABI's the float_argreg is further adjusted
2851                  above to ensure that it is even register aligned.  */
2852               LONGEST regval = extract_unsigned_integer (val, len);
2853               if (mips_debug)
2854                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
2855                                     float_argreg, phex (regval, len));
2856               write_register (float_argreg++, regval);
2857             }
2858         }
2859       else
2860         {
2861           /* Copy the argument to general registers or the stack in
2862              register-sized pieces.  Large arguments are split between
2863              registers and stack.  */
2864           /* Note: structs whose size is not a multiple of MIPS_REGSIZE
2865              are treated specially: Irix cc passes them in registers
2866              where gcc sometimes puts them on the stack.  For maximum
2867              compatibility, we will put them in both places.  */
2868           int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
2869                                   (len % MIPS_SAVED_REGSIZE != 0));
2870
2871           /* Note: Floating-point values that didn't fit into an FP
2872              register are only written to memory.  */
2873           while (len > 0)
2874             {
2875               /* Remember if the argument was written to the stack.  */
2876               int stack_used_p = 0;
2877               int partial_len = 
2878                 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
2879
2880               if (mips_debug)
2881                 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2882                                     partial_len);
2883
2884               /* Write this portion of the argument to the stack.  */
2885               if (argreg > MIPS_LAST_ARG_REGNUM
2886                   || odd_sized_struct
2887                   || fp_register_arg_p (typecode, arg_type))
2888                 {
2889                   /* Should shorter than int integer values be
2890                      promoted to int before being stored? */
2891                   int longword_offset = 0;
2892                   CORE_ADDR addr;
2893                   stack_used_p = 1;
2894                   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2895                     {
2896                       if (MIPS_STACK_ARGSIZE == 8 &&
2897                           (typecode == TYPE_CODE_INT ||
2898                            typecode == TYPE_CODE_PTR ||
2899                            typecode == TYPE_CODE_FLT) && len <= 4)
2900                         longword_offset = MIPS_STACK_ARGSIZE - len;
2901                       else if ((typecode == TYPE_CODE_STRUCT ||
2902                                 typecode == TYPE_CODE_UNION) &&
2903                                TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE)
2904                         longword_offset = MIPS_STACK_ARGSIZE - len;
2905                     }
2906
2907                   if (mips_debug)
2908                     {
2909                       fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2910                                           paddr_nz (stack_offset));
2911                       fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2912                                           paddr_nz (longword_offset));
2913                     }
2914
2915                   addr = sp + stack_offset + longword_offset;
2916
2917                   if (mips_debug)
2918                     {
2919                       int i;
2920                       fprintf_unfiltered (gdb_stdlog, " @0x%s ", 
2921                                           paddr_nz (addr));
2922                       for (i = 0; i < partial_len; i++)
2923                         {
2924                           fprintf_unfiltered (gdb_stdlog, "%02x", 
2925                                               val[i] & 0xff);
2926                         }
2927                     }
2928                   write_memory (addr, val, partial_len);
2929                 }
2930
2931               /* Note!!! This is NOT an else clause.  Odd sized
2932                  structs may go thru BOTH paths.  Floating point
2933                  arguments will not.  */
2934               /* Write this portion of the argument to a general
2935                  purpose register.  */
2936               if (argreg <= MIPS_LAST_ARG_REGNUM
2937                   && !fp_register_arg_p (typecode, arg_type))
2938                 {
2939                   LONGEST regval = extract_unsigned_integer (val, partial_len);
2940
2941                   if (mips_debug)
2942                     fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
2943                                       argreg,
2944                                       phex (regval, MIPS_SAVED_REGSIZE));
2945                   write_register (argreg, regval);
2946                   argreg++;
2947                 }
2948
2949               len -= partial_len;
2950               val += partial_len;
2951
2952               /* Compute the the offset into the stack at which we
2953                  will copy the next parameter.
2954
2955                  In the new EABI (and the NABI32), the stack_offset
2956                  only needs to be adjusted when it has been used.  */
2957
2958               if (stack_used_p)
2959                 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
2960             }
2961         }
2962       if (mips_debug)
2963         fprintf_unfiltered (gdb_stdlog, "\n");
2964     }
2965
2966   regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
2967
2968   /* Return adjusted stack pointer.  */
2969   return sp;
2970 }
2971
2972 /* N32/N64 version of push_dummy_call.  */
2973
2974 static CORE_ADDR
2975 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
2976                              struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2977                              struct value **args, CORE_ADDR sp, int struct_return,
2978                              CORE_ADDR struct_addr)
2979 {
2980   int argreg;
2981   int float_argreg;
2982   int argnum;
2983   int len = 0;
2984   int stack_offset = 0;
2985
2986   /* For shared libraries, "t9" needs to point at the function
2987      address.  */
2988   regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
2989
2990   /* Set the return address register to point to the entry point of
2991      the program, where a breakpoint lies in wait.  */
2992   regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
2993
2994   /* First ensure that the stack and structure return address (if any)
2995      are properly aligned.  The stack has to be at least 64-bit
2996      aligned even on 32-bit machines, because doubles must be 64-bit
2997      aligned.  For n32 and n64, stack frames need to be 128-bit
2998      aligned, so we round to this widest known alignment.  */
2999
3000   sp = ROUND_DOWN (sp, 16);
3001   struct_addr = ROUND_DOWN (struct_addr, 16);
3002
3003   /* Now make space on the stack for the args.  */
3004   for (argnum = 0; argnum < nargs; argnum++)
3005     len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), 
3006                      MIPS_STACK_ARGSIZE);
3007   sp -= ROUND_UP (len, 16);
3008
3009   if (mips_debug)
3010     fprintf_unfiltered (gdb_stdlog, 
3011                         "mips_n32n64_push_dummy_call: sp=0x%s allocated %d\n",
3012                         paddr_nz (sp), ROUND_UP (len, 16));
3013
3014   /* Initialize the integer and float register pointers.  */
3015   argreg = A0_REGNUM;
3016   float_argreg = FPA0_REGNUM;
3017
3018   /* The struct_return pointer occupies the first parameter-passing reg.  */
3019   if (struct_return)
3020     {
3021       if (mips_debug)
3022         fprintf_unfiltered (gdb_stdlog,
3023                             "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3024                             argreg, paddr_nz (struct_addr));
3025       write_register (argreg++, struct_addr);
3026     }
3027
3028   /* Now load as many as possible of the first arguments into
3029      registers, and push the rest onto the stack.  Loop thru args
3030      from first to last.  */
3031   for (argnum = 0; argnum < nargs; argnum++)
3032     {
3033       char *val;
3034       char valbuf[MAX_REGISTER_SIZE];
3035       struct value *arg = args[argnum];
3036       struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3037       int len = TYPE_LENGTH (arg_type);
3038       enum type_code typecode = TYPE_CODE (arg_type);
3039
3040       if (mips_debug)
3041         fprintf_unfiltered (gdb_stdlog,
3042                             "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3043                             argnum + 1, len, (int) typecode);
3044
3045       val = (char *) VALUE_CONTENTS (arg);
3046
3047       if (fp_register_arg_p (typecode, arg_type)
3048           && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3049         {
3050           /* This is a floating point value that fits entirely
3051              in a single register.  */
3052           /* On 32 bit ABI's the float_argreg is further adjusted
3053              above to ensure that it is even register aligned.  */
3054           LONGEST regval = extract_unsigned_integer (val, len);
3055           if (mips_debug)
3056             fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3057                                 float_argreg, phex (regval, len));
3058           write_register (float_argreg++, regval);
3059
3060           if (mips_debug)
3061             fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3062                                 argreg, phex (regval, len));
3063           write_register (argreg, regval);
3064           argreg += 1;
3065         }
3066       else
3067         {
3068           /* Copy the argument to general registers or the stack in
3069              register-sized pieces.  Large arguments are split between
3070              registers and stack.  */
3071           /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3072              are treated specially: Irix cc passes them in registers
3073              where gcc sometimes puts them on the stack.  For maximum
3074              compatibility, we will put them in both places.  */
3075           int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3076                                   (len % MIPS_SAVED_REGSIZE != 0));
3077           /* Note: Floating-point values that didn't fit into an FP
3078              register are only written to memory.  */
3079           while (len > 0)
3080             {
3081               /* Rememer if the argument was written to the stack.  */
3082               int stack_used_p = 0;
3083               int partial_len = len < MIPS_SAVED_REGSIZE ? 
3084                 len : MIPS_SAVED_REGSIZE;
3085
3086               if (mips_debug)
3087                 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3088                                     partial_len);
3089
3090               /* Write this portion of the argument to the stack.  */
3091               if (argreg > MIPS_LAST_ARG_REGNUM
3092                   || odd_sized_struct
3093                   || fp_register_arg_p (typecode, arg_type))
3094                 {
3095                   /* Should shorter than int integer values be
3096                      promoted to int before being stored? */
3097                   int longword_offset = 0;
3098                   CORE_ADDR addr;
3099                   stack_used_p = 1;
3100                   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3101                     {
3102                       if (MIPS_STACK_ARGSIZE == 8 &&
3103                           (typecode == TYPE_CODE_INT ||
3104                            typecode == TYPE_CODE_PTR ||
3105                            typecode == TYPE_CODE_FLT) && len <= 4)
3106                         longword_offset = MIPS_STACK_ARGSIZE - len;
3107                     }
3108
3109                   if (mips_debug)
3110                     {
3111                       fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3112                                           paddr_nz (stack_offset));
3113                       fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3114                                           paddr_nz (longword_offset));
3115                     }
3116
3117                   addr = sp + stack_offset + longword_offset;
3118
3119                   if (mips_debug)
3120                     {
3121                       int i;
3122                       fprintf_unfiltered (gdb_stdlog, " @0x%s ", 
3123                                           paddr_nz (addr));
3124                       for (i = 0; i < partial_len; i++)
3125                         {
3126                           fprintf_unfiltered (gdb_stdlog, "%02x", 
3127                                               val[i] & 0xff);
3128                         }
3129                     }
3130                   write_memory (addr, val, partial_len);
3131                 }
3132
3133               /* Note!!! This is NOT an else clause.  Odd sized
3134                  structs may go thru BOTH paths.  Floating point
3135                  arguments will not.  */
3136               /* Write this portion of the argument to a general
3137                  purpose register.  */
3138               if (argreg <= MIPS_LAST_ARG_REGNUM
3139                   && !fp_register_arg_p (typecode, arg_type))
3140                 {
3141                   LONGEST regval = extract_unsigned_integer (val, partial_len);
3142
3143                   /* A non-floating-point argument being passed in a
3144                      general register.  If a struct or union, and if
3145                      the remaining length is smaller than the register
3146                      size, we have to adjust the register value on
3147                      big endian targets.
3148
3149                      It does not seem to be necessary to do the
3150                      same for integral types.
3151
3152                      cagney/2001-07-23: gdb/179: Also, GCC, when
3153                      outputting LE O32 with sizeof (struct) <
3154                      MIPS_SAVED_REGSIZE, generates a left shift as
3155                      part of storing the argument in a register a
3156                      register (the left shift isn't generated when
3157                      sizeof (struct) >= MIPS_SAVED_REGSIZE).  Since it
3158                      is quite possible that this is GCC contradicting
3159                      the LE/O32 ABI, GDB has not been adjusted to
3160                      accommodate this.  Either someone needs to
3161                      demonstrate that the LE/O32 ABI specifies such a
3162                      left shift OR this new ABI gets identified as
3163                      such and GDB gets tweaked accordingly.  */
3164
3165                   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3166                       && partial_len < MIPS_SAVED_REGSIZE
3167                       && (typecode == TYPE_CODE_STRUCT ||
3168                           typecode == TYPE_CODE_UNION))
3169                     regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3170                                 TARGET_CHAR_BIT);
3171
3172                   if (mips_debug)
3173                     fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3174                                       argreg,
3175                                       phex (regval, MIPS_SAVED_REGSIZE));
3176                   write_register (argreg, regval);
3177                   argreg++;
3178                 }
3179
3180               len -= partial_len;
3181               val += partial_len;
3182
3183               /* Compute the the offset into the stack at which we
3184                  will copy the next parameter.
3185
3186                  In N32 (N64?), the stack_offset only needs to be
3187                  adjusted when it has been used.  */
3188
3189               if (stack_used_p)
3190                 stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3191             }
3192         }
3193       if (mips_debug)
3194         fprintf_unfiltered (gdb_stdlog, "\n");
3195     }
3196
3197   regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3198
3199   /* Return adjusted stack pointer.  */
3200   return sp;
3201 }
3202
3203 /* O32 version of push_dummy_call.  */
3204
3205 static CORE_ADDR
3206 mips_o32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3207                           struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3208                           struct value **args, CORE_ADDR sp, int struct_return,
3209                           CORE_ADDR struct_addr)
3210 {
3211   int argreg;
3212   int float_argreg;
3213   int argnum;
3214   int len = 0;
3215   int stack_offset = 0;
3216
3217   /* For shared libraries, "t9" needs to point at the function
3218      address.  */
3219   regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3220
3221   /* Set the return address register to point to the entry point of
3222      the program, where a breakpoint lies in wait.  */
3223   regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3224
3225   /* First ensure that the stack and structure return address (if any)
3226      are properly aligned.  The stack has to be at least 64-bit
3227      aligned even on 32-bit machines, because doubles must be 64-bit
3228      aligned.  For n32 and n64, stack frames need to be 128-bit
3229      aligned, so we round to this widest known alignment.  */
3230
3231   sp = ROUND_DOWN (sp, 16);
3232   struct_addr = ROUND_DOWN (struct_addr, 16);
3233
3234   /* Now make space on the stack for the args.  */
3235   for (argnum = 0; argnum < nargs; argnum++)
3236     len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), 
3237                      MIPS_STACK_ARGSIZE);
3238   sp -= ROUND_UP (len, 16);
3239
3240   if (mips_debug)
3241     fprintf_unfiltered (gdb_stdlog, 
3242                         "mips_o32_push_dummy_call: sp=0x%s allocated %d\n",
3243                         paddr_nz (sp), ROUND_UP (len, 16));
3244
3245   /* Initialize the integer and float register pointers.  */
3246   argreg = A0_REGNUM;
3247   float_argreg = FPA0_REGNUM;
3248
3249   /* The struct_return pointer occupies the first parameter-passing reg.  */
3250   if (struct_return)
3251     {
3252       if (mips_debug)
3253         fprintf_unfiltered (gdb_stdlog,
3254                             "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3255                             argreg, paddr_nz (struct_addr));
3256       write_register (argreg++, struct_addr);
3257       stack_offset += MIPS_STACK_ARGSIZE;
3258     }
3259
3260   /* Now load as many as possible of the first arguments into
3261      registers, and push the rest onto the stack.  Loop thru args
3262      from first to last.  */
3263   for (argnum = 0; argnum < nargs; argnum++)
3264     {
3265       char *val;
3266       char valbuf[MAX_REGISTER_SIZE];
3267       struct value *arg = args[argnum];
3268       struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3269       int len = TYPE_LENGTH (arg_type);
3270       enum type_code typecode = TYPE_CODE (arg_type);
3271
3272       if (mips_debug)
3273         fprintf_unfiltered (gdb_stdlog,
3274                             "mips_o32_push_dummy_call: %d len=%d type=%d",
3275                             argnum + 1, len, (int) typecode);
3276
3277       val = (char *) VALUE_CONTENTS (arg);
3278
3279       /* 32-bit ABIs always start floating point arguments in an
3280          even-numbered floating point register.  Round the FP register
3281          up before the check to see if there are any FP registers
3282          left.  O32/O64 targets also pass the FP in the integer
3283          registers so also round up normal registers.  */
3284       if (!FP_REGISTER_DOUBLE
3285           && fp_register_arg_p (typecode, arg_type))
3286         {
3287           if ((float_argreg & 1))
3288             float_argreg++;
3289         }
3290
3291       /* Floating point arguments passed in registers have to be
3292          treated specially.  On 32-bit architectures, doubles
3293          are passed in register pairs; the even register gets
3294          the low word, and the odd register gets the high word.
3295          On O32/O64, the first two floating point arguments are
3296          also copied to general registers, because MIPS16 functions
3297          don't use float registers for arguments.  This duplication of
3298          arguments in general registers can't hurt non-MIPS16 functions
3299          because those registers are normally skipped.  */
3300
3301       if (fp_register_arg_p (typecode, arg_type)
3302           && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3303         {
3304           if (!FP_REGISTER_DOUBLE && len == 8)
3305             {
3306               int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3307               unsigned long regval;
3308
3309               /* Write the low word of the double to the even register(s).  */
3310               regval = extract_unsigned_integer (val + low_offset, 4);
3311               if (mips_debug)
3312                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3313                                     float_argreg, phex (regval, 4));
3314               write_register (float_argreg++, regval);
3315               if (mips_debug)
3316                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3317                                     argreg, phex (regval, 4));
3318               write_register (argreg++, regval);
3319
3320               /* Write the high word of the double to the odd register(s).  */
3321               regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3322               if (mips_debug)
3323                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3324                                     float_argreg, phex (regval, 4));
3325               write_register (float_argreg++, regval);
3326
3327               if (mips_debug)
3328                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3329                                     argreg, phex (regval, 4));
3330               write_register (argreg++, regval);
3331             }
3332           else
3333             {
3334               /* This is a floating point value that fits entirely
3335                  in a single register.  */
3336               /* On 32 bit ABI's the float_argreg is further adjusted
3337                  above to ensure that it is even register aligned.  */
3338               LONGEST regval = extract_unsigned_integer (val, len);
3339               if (mips_debug)
3340                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3341                                     float_argreg, phex (regval, len));
3342               write_register (float_argreg++, regval);
3343               /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3344                  registers for each argument.  The below is (my
3345                  guess) to ensure that the corresponding integer
3346                  register has reserved the same space.  */
3347               if (mips_debug)
3348                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3349                                     argreg, phex (regval, len));
3350               write_register (argreg, regval);
3351               argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3352             }
3353           /* Reserve space for the FP register.  */
3354           stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3355         }
3356       else
3357         {
3358           /* Copy the argument to general registers or the stack in
3359              register-sized pieces.  Large arguments are split between
3360              registers and stack.  */
3361           /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3362              are treated specially: Irix cc passes them in registers
3363              where gcc sometimes puts them on the stack.  For maximum
3364              compatibility, we will put them in both places.  */
3365           int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3366                                   (len % MIPS_SAVED_REGSIZE != 0));
3367           /* Structures should be aligned to eight bytes (even arg registers)
3368              on MIPS_ABI_O32, if their first member has double precision.  */
3369           if (MIPS_SAVED_REGSIZE < 8
3370               && mips_type_needs_double_align (arg_type))
3371             {
3372               if ((argreg & 1))
3373                 argreg++;
3374             }
3375           /* Note: Floating-point values that didn't fit into an FP
3376              register are only written to memory.  */
3377           while (len > 0)
3378             {
3379               /* Remember if the argument was written to the stack.  */
3380               int stack_used_p = 0;
3381               int partial_len = 
3382                 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3383
3384               if (mips_debug)
3385                 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3386                                     partial_len);
3387
3388               /* Write this portion of the argument to the stack.  */
3389               if (argreg > MIPS_LAST_ARG_REGNUM
3390                   || odd_sized_struct
3391                   || fp_register_arg_p (typecode, arg_type))
3392                 {
3393                   /* Should shorter than int integer values be
3394                      promoted to int before being stored? */
3395                   int longword_offset = 0;
3396                   CORE_ADDR addr;
3397                   stack_used_p = 1;
3398                   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3399                     {
3400                       if (MIPS_STACK_ARGSIZE == 8 &&
3401                           (typecode == TYPE_CODE_INT ||
3402                            typecode == TYPE_CODE_PTR ||
3403                            typecode == TYPE_CODE_FLT) && len <= 4)
3404                         longword_offset = MIPS_STACK_ARGSIZE - len;
3405                     }
3406
3407                   if (mips_debug)
3408                     {
3409                       fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3410                                           paddr_nz (stack_offset));
3411                       fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3412                                           paddr_nz (longword_offset));
3413                     }
3414
3415                   addr = sp + stack_offset + longword_offset;
3416
3417                   if (mips_debug)
3418                     {
3419                       int i;
3420                       fprintf_unfiltered (gdb_stdlog, " @0x%s ", 
3421                                           paddr_nz (addr));
3422                       for (i = 0; i < partial_len; i++)
3423                         {
3424                           fprintf_unfiltered (gdb_stdlog, "%02x", 
3425                                               val[i] & 0xff);
3426                         }
3427                     }
3428                   write_memory (addr, val, partial_len);
3429                 }
3430
3431               /* Note!!! This is NOT an else clause.  Odd sized
3432                  structs may go thru BOTH paths.  Floating point
3433                  arguments will not.  */
3434               /* Write this portion of the argument to a general
3435                  purpose register.  */
3436               if (argreg <= MIPS_LAST_ARG_REGNUM
3437                   && !fp_register_arg_p (typecode, arg_type))
3438                 {
3439                   LONGEST regval = extract_signed_integer (val, partial_len);
3440                   /* Value may need to be sign extended, because 
3441                      MIPS_REGSIZE != MIPS_SAVED_REGSIZE.  */
3442
3443                   /* A non-floating-point argument being passed in a
3444                      general register.  If a struct or union, and if
3445                      the remaining length is smaller than the register
3446                      size, we have to adjust the register value on
3447                      big endian targets.
3448
3449                      It does not seem to be necessary to do the
3450                      same for integral types.
3451
3452                      Also don't do this adjustment on O64 binaries.
3453
3454                      cagney/2001-07-23: gdb/179: Also, GCC, when
3455                      outputting LE O32 with sizeof (struct) <
3456                      MIPS_SAVED_REGSIZE, generates a left shift as
3457                      part of storing the argument in a register a
3458                      register (the left shift isn't generated when
3459                      sizeof (struct) >= MIPS_SAVED_REGSIZE).  Since it
3460                      is quite possible that this is GCC contradicting
3461                      the LE/O32 ABI, GDB has not been adjusted to
3462                      accommodate this.  Either someone needs to
3463                      demonstrate that the LE/O32 ABI specifies such a
3464                      left shift OR this new ABI gets identified as
3465                      such and GDB gets tweaked accordingly.  */
3466
3467                   if (MIPS_SAVED_REGSIZE < 8
3468                       && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3469                       && partial_len < MIPS_SAVED_REGSIZE
3470                       && (typecode == TYPE_CODE_STRUCT ||
3471                           typecode == TYPE_CODE_UNION))
3472                     regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3473                                 TARGET_CHAR_BIT);
3474
3475                   if (mips_debug)
3476                     fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3477                                       argreg,
3478                                       phex (regval, MIPS_SAVED_REGSIZE));
3479                   write_register (argreg, regval);
3480                   argreg++;
3481
3482                   /* Prevent subsequent floating point arguments from
3483                      being passed in floating point registers.  */
3484                   float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3485                 }
3486
3487               len -= partial_len;
3488               val += partial_len;
3489
3490               /* Compute the the offset into the stack at which we
3491                  will copy the next parameter.
3492
3493                  In older ABIs, the caller reserved space for
3494                  registers that contained arguments.  This was loosely
3495                  refered to as their "home".  Consequently, space is
3496                  always allocated.  */
3497
3498               stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3499             }
3500         }
3501       if (mips_debug)
3502         fprintf_unfiltered (gdb_stdlog, "\n");
3503     }
3504
3505   regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3506
3507   /* Return adjusted stack pointer.  */
3508   return sp;
3509 }
3510
3511 /* O64 version of push_dummy_call.  */
3512
3513 static CORE_ADDR
3514 mips_o64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
3515                           struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
3516                           struct value **args, CORE_ADDR sp, int struct_return,
3517                           CORE_ADDR struct_addr)
3518 {
3519   int argreg;
3520   int float_argreg;
3521   int argnum;
3522   int len = 0;
3523   int stack_offset = 0;
3524
3525   /* For shared libraries, "t9" needs to point at the function
3526      address.  */
3527   regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3528
3529   /* Set the return address register to point to the entry point of
3530      the program, where a breakpoint lies in wait.  */
3531   regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3532
3533   /* First ensure that the stack and structure return address (if any)
3534      are properly aligned.  The stack has to be at least 64-bit
3535      aligned even on 32-bit machines, because doubles must be 64-bit
3536      aligned.  For n32 and n64, stack frames need to be 128-bit
3537      aligned, so we round to this widest known alignment.  */
3538
3539   sp = ROUND_DOWN (sp, 16);
3540   struct_addr = ROUND_DOWN (struct_addr, 16);
3541
3542   /* Now make space on the stack for the args.  */
3543   for (argnum = 0; argnum < nargs; argnum++)
3544     len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), 
3545                      MIPS_STACK_ARGSIZE);
3546   sp -= ROUND_UP (len, 16);
3547
3548   if (mips_debug)
3549     fprintf_unfiltered (gdb_stdlog, 
3550                         "mips_o64_push_dummy_call: sp=0x%s allocated %d\n",
3551                         paddr_nz (sp), ROUND_UP (len, 16));
3552
3553   /* Initialize the integer and float register pointers.  */
3554   argreg = A0_REGNUM;
3555   float_argreg = FPA0_REGNUM;
3556
3557   /* The struct_return pointer occupies the first parameter-passing reg.  */
3558   if (struct_return)
3559     {
3560       if (mips_debug)
3561         fprintf_unfiltered (gdb_stdlog,
3562                             "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
3563                             argreg, paddr_nz (struct_addr));
3564       write_register (argreg++, struct_addr);
3565       stack_offset += MIPS_STACK_ARGSIZE;
3566     }
3567
3568   /* Now load as many as possible of the first arguments into
3569      registers, and push the rest onto the stack.  Loop thru args
3570      from first to last.  */
3571   for (argnum = 0; argnum < nargs; argnum++)
3572     {
3573       char *val;
3574       char valbuf[MAX_REGISTER_SIZE];
3575       struct value *arg = args[argnum];
3576       struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3577       int len = TYPE_LENGTH (arg_type);
3578       enum type_code typecode = TYPE_CODE (arg_type);
3579
3580       if (mips_debug)
3581         fprintf_unfiltered (gdb_stdlog,
3582                             "mips_o64_push_dummy_call: %d len=%d type=%d",
3583                             argnum + 1, len, (int) typecode);
3584
3585       val = (char *) VALUE_CONTENTS (arg);
3586
3587       /* 32-bit ABIs always start floating point arguments in an
3588          even-numbered floating point register.  Round the FP register
3589          up before the check to see if there are any FP registers
3590          left.  O32/O64 targets also pass the FP in the integer
3591          registers so also round up normal registers.  */
3592       if (!FP_REGISTER_DOUBLE
3593           && fp_register_arg_p (typecode, arg_type))
3594         {
3595           if ((float_argreg & 1))
3596             float_argreg++;
3597         }
3598
3599       /* Floating point arguments passed in registers have to be
3600          treated specially.  On 32-bit architectures, doubles
3601          are passed in register pairs; the even register gets
3602          the low word, and the odd register gets the high word.
3603          On O32/O64, the first two floating point arguments are
3604          also copied to general registers, because MIPS16 functions
3605          don't use float registers for arguments.  This duplication of
3606          arguments in general registers can't hurt non-MIPS16 functions
3607          because those registers are normally skipped.  */
3608
3609       if (fp_register_arg_p (typecode, arg_type)
3610           && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3611         {
3612           if (!FP_REGISTER_DOUBLE && len == 8)
3613             {
3614               int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3615               unsigned long regval;
3616
3617               /* Write the low word of the double to the even register(s).  */
3618               regval = extract_unsigned_integer (val + low_offset, 4);
3619               if (mips_debug)
3620                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3621                                     float_argreg, phex (regval, 4));
3622               write_register (float_argreg++, regval);
3623               if (mips_debug)
3624                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3625                                     argreg, phex (regval, 4));
3626               write_register (argreg++, regval);
3627
3628               /* Write the high word of the double to the odd register(s).  */
3629               regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3630               if (mips_debug)
3631                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3632                                     float_argreg, phex (regval, 4));
3633               write_register (float_argreg++, regval);
3634
3635               if (mips_debug)
3636                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3637                                     argreg, phex (regval, 4));
3638               write_register (argreg++, regval);
3639             }
3640           else
3641             {
3642               /* This is a floating point value that fits entirely
3643                  in a single register.  */
3644               /* On 32 bit ABI's the float_argreg is further adjusted
3645                  above to ensure that it is even register aligned.  */
3646               LONGEST regval = extract_unsigned_integer (val, len);
3647               if (mips_debug)
3648                 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3649                                     float_argreg, phex (regval, len));
3650               write_register (float_argreg++, regval);
3651               /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
3652                  registers for each argument.  The below is (my
3653                  guess) to ensure that the corresponding integer
3654                  register has reserved the same space.  */
3655               if (mips_debug)
3656                 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3657                                     argreg, phex (regval, len));
3658               write_register (argreg, regval);
3659               argreg += FP_REGISTER_DOUBLE ? 1 : 2;
3660             }
3661           /* Reserve space for the FP register.  */
3662           stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE);
3663         }
3664       else
3665         {
3666           /* Copy the argument to general registers or the stack in
3667              register-sized pieces.  Large arguments are split between
3668              registers and stack.  */
3669           /* Note: structs whose size is not a multiple of MIPS_REGSIZE
3670              are treated specially: Irix cc passes them in registers
3671              where gcc sometimes puts them on the stack.  For maximum
3672              compatibility, we will put them in both places.  */
3673           int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
3674                                   (len % MIPS_SAVED_REGSIZE != 0));
3675           /* Structures should be aligned to eight bytes (even arg registers)
3676              on MIPS_ABI_O32, if their first member has double precision.  */
3677           if (MIPS_SAVED_REGSIZE < 8
3678               && mips_type_needs_double_align (arg_type))
3679             {
3680               if ((argreg & 1))
3681                 argreg++;
3682             }
3683           /* Note: Floating-point values that didn't fit into an FP
3684              register are only written to memory.  */
3685           while (len > 0)
3686             {
3687               /* Remember if the argument was written to the stack.  */
3688               int stack_used_p = 0;
3689               int partial_len = 
3690                 len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
3691
3692               if (mips_debug)
3693                 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3694                                     partial_len);
3695
3696               /* Write this portion of the argument to the stack.  */
3697               if (argreg > MIPS_LAST_ARG_REGNUM
3698                   || odd_sized_struct
3699                   || fp_register_arg_p (typecode, arg_type))
3700                 {
3701                   /* Should shorter than int integer values be
3702                      promoted to int before being stored? */
3703                   int longword_offset = 0;
3704                   CORE_ADDR addr;
3705                   stack_used_p = 1;
3706                   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3707                     {
3708                       if (MIPS_STACK_ARGSIZE == 8 &&
3709                           (typecode == TYPE_CODE_INT ||
3710                            typecode == TYPE_CODE_PTR ||
3711                            typecode == TYPE_CODE_FLT) && len <= 4)
3712                         longword_offset = MIPS_STACK_ARGSIZE - len;
3713                     }
3714
3715                   if (mips_debug)
3716                     {
3717                       fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3718                                           paddr_nz (stack_offset));
3719                       fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3720                                           paddr_nz (longword_offset));
3721                     }
3722
3723                   addr = sp + stack_offset + longword_offset;
3724
3725                   if (mips_debug)
3726                     {
3727                       int i;
3728                       fprintf_unfiltered (gdb_stdlog, " @0x%s ", 
3729                                           paddr_nz (addr));
3730                       for (i = 0; i < partial_len; i++)
3731                         {
3732                           fprintf_unfiltered (gdb_stdlog, "%02x", 
3733                                               val[i] & 0xff);
3734                         }
3735                     }
3736                   write_memory (addr, val, partial_len);
3737                 }
3738
3739               /* Note!!! This is NOT an else clause.  Odd sized
3740                  structs may go thru BOTH paths.  Floating point
3741                  arguments will not.  */
3742               /* Write this portion of the argument to a general
3743                  purpose register.  */
3744               if (argreg <= MIPS_LAST_ARG_REGNUM
3745                   && !fp_register_arg_p (typecode, arg_type))
3746                 {
3747                   LONGEST regval = extract_signed_integer (val, partial_len);
3748                   /* Value may need to be sign extended, because 
3749                      MIPS_REGSIZE != MIPS_SAVED_REGSIZE.  */
3750
3751                   /* A non-floating-point argument being passed in a
3752                      general register.  If a struct or union, and if
3753                      the remaining length is smaller than the register
3754                      size, we have to adjust the register value on
3755                      big endian targets.
3756
3757                      It does not seem to be necessary to do the
3758                      same for integral types.
3759
3760                      Also don't do this adjustment on O64 binaries.
3761
3762                      cagney/2001-07-23: gdb/179: Also, GCC, when
3763                      outputting LE O32 with sizeof (struct) <
3764                      MIPS_SAVED_REGSIZE, generates a left shift as
3765                      part of storing the argument in a register a
3766                      register (the left shift isn't generated when
3767                      sizeof (struct) >= MIPS_SAVED_REGSIZE).  Since it
3768                      is quite possible that this is GCC contradicting
3769                      the LE/O32 ABI, GDB has not been adjusted to
3770                      accommodate this.  Either someone needs to
3771                      demonstrate that the LE/O32 ABI specifies such a
3772                      left shift OR this new ABI gets identified as
3773                      such and GDB gets tweaked accordingly.  */
3774
3775                   if (MIPS_SAVED_REGSIZE < 8
3776                       && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3777                       && partial_len < MIPS_SAVED_REGSIZE
3778                       && (typecode == TYPE_CODE_STRUCT ||
3779                           typecode == TYPE_CODE_UNION))
3780                     regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
3781                                 TARGET_CHAR_BIT);
3782
3783                   if (mips_debug)
3784                     fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3785                                       argreg,
3786                                       phex (regval, MIPS_SAVED_REGSIZE));
3787                   write_register (argreg, regval);
3788                   argreg++;
3789
3790                   /* Prevent subsequent floating point arguments from
3791                      being passed in floating point registers.  */
3792                   float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3793                 }
3794
3795               len -= partial_len;
3796               val += partial_len;
3797
3798               /* Compute the the offset into the stack at which we
3799                  will copy the next parameter.
3800
3801                  In older ABIs, the caller reserved space for
3802                  registers that contained arguments.  This was loosely
3803                  refered to as their "home".  Consequently, space is
3804                  always allocated.  */
3805
3806               stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE);
3807             }
3808         }
3809       if (mips_debug)
3810         fprintf_unfiltered (gdb_stdlog, "\n");
3811     }
3812
3813   regcache_cooked_write_signed (regcache, SP_REGNUM, sp);
3814
3815   /* Return adjusted stack pointer.  */
3816   return sp;
3817 }
3818
3819 static void
3820 mips_pop_frame (void)
3821 {
3822   register int regnum;
3823   struct frame_info *frame = get_current_frame ();
3824   CORE_ADDR new_sp = get_frame_base (frame);
3825   mips_extra_func_info_t proc_desc;
3826
3827   if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), 0, 0))
3828     {
3829       generic_pop_dummy_frame ();
3830       flush_cached_frames ();
3831       return;
3832     }
3833
3834   proc_desc = get_frame_extra_info (frame)->proc_desc;
3835   write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
3836   mips_find_saved_regs (frame);
3837   for (regnum = 0; regnum < NUM_REGS; regnum++)
3838     if (regnum != SP_REGNUM && regnum != PC_REGNUM
3839         && get_frame_saved_regs (frame)[regnum])
3840       {
3841         /* Floating point registers must not be sign extended, 
3842            in case MIPS_SAVED_REGSIZE = 4 but sizeof (FP0_REGNUM) == 8.  */
3843
3844         if (FP0_REGNUM <= regnum && regnum < FP0_REGNUM + 32)
3845           write_register (regnum,
3846                           read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
3847                                                         MIPS_SAVED_REGSIZE));
3848         else
3849           write_register (regnum,
3850                           read_memory_integer (get_frame_saved_regs (frame)[regnum],
3851                                                MIPS_SAVED_REGSIZE));
3852       }
3853
3854   write_register (SP_REGNUM, new_sp);
3855   flush_cached_frames ();
3856
3857   if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
3858     {
3859       struct linked_proc_info *pi_ptr, *prev_ptr;
3860
3861       for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
3862            pi_ptr != NULL;
3863            prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
3864         {
3865           if (&pi_ptr->info == proc_desc)
3866             break;
3867         }
3868
3869       if (pi_ptr == NULL)
3870         error ("Can't locate dummy extra frame info\n");
3871
3872       if (prev_ptr != NULL)
3873         prev_ptr->next = pi_ptr->next;
3874       else
3875         linked_proc_desc_table = pi_ptr->next;
3876
3877       xfree (pi_ptr);
3878
3879       write_register (HI_REGNUM,
3880                       read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE,
3881                                            MIPS_SAVED_REGSIZE));
3882       write_register (LO_REGNUM,
3883                       read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE,
3884                                            MIPS_SAVED_REGSIZE));
3885       if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
3886         write_register (FCRCS_REGNUM,
3887                         read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE,
3888                                              MIPS_SAVED_REGSIZE));
3889     }
3890 }
3891
3892 /* Floating point register management.
3893
3894    Background: MIPS1 & 2 fp registers are 32 bits wide.  To support
3895    64bit operations, these early MIPS cpus treat fp register pairs
3896    (f0,f1) as a single register (d0).  Later MIPS cpu's have 64 bit fp
3897    registers and offer a compatibility mode that emulates the MIPS2 fp
3898    model.  When operating in MIPS2 fp compat mode, later cpu's split
3899    double precision floats into two 32-bit chunks and store them in
3900    consecutive fp regs.  To display 64-bit floats stored in this
3901    fashion, we have to combine 32 bits from f0 and 32 bits from f1.
3902    Throw in user-configurable endianness and you have a real mess.
3903
3904    The way this works is:
3905      - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
3906        double-precision value will be split across two logical registers.
3907        The lower-numbered logical register will hold the low-order bits,
3908        regardless of the processor's endianness.
3909      - If we are on a 64-bit processor, and we are looking for a
3910        single-precision value, it will be in the low ordered bits
3911        of a 64-bit GPR (after mfc1, for example) or a 64-bit register
3912        save slot in memory.
3913      - If we are in 64-bit mode, everything is straightforward.
3914
3915    Note that this code only deals with "live" registers at the top of the
3916    stack.  We will attempt to deal with saved registers later, when
3917    the raw/cooked register interface is in place. (We need a general
3918    interface that can deal with dynamic saved register sizes -- fp
3919    regs could be 32 bits wide in one frame and 64 on the frame above
3920    and below).  */
3921
3922 static struct type *
3923 mips_float_register_type (void)
3924 {
3925   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3926     return builtin_type_ieee_single_big;
3927   else
3928     return builtin_type_ieee_single_little;
3929 }
3930
3931 static struct type *
3932 mips_double_register_type (void)
3933 {
3934   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3935     return builtin_type_ieee_double_big;
3936   else
3937     return builtin_type_ieee_double_little;
3938 }
3939
3940 /* Copy a 32-bit single-precision value from the current frame
3941    into rare_buffer.  */
3942
3943 static void
3944 mips_read_fp_register_single (struct frame_info *frame, int regno,
3945                               char *rare_buffer)
3946 {
3947   int raw_size = REGISTER_RAW_SIZE (regno);
3948   char *raw_buffer = alloca (raw_size);
3949
3950   if (!frame_register_read (frame, regno, raw_buffer))
3951     error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3952   if (raw_size == 8)
3953     {
3954       /* We have a 64-bit value for this register.  Find the low-order
3955          32 bits.  */
3956       int offset;
3957
3958       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3959         offset = 4;
3960       else
3961         offset = 0;
3962
3963       memcpy (rare_buffer, raw_buffer + offset, 4);
3964     }
3965   else
3966     {
3967       memcpy (rare_buffer, raw_buffer, 4);
3968     }
3969 }
3970
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
3973    register.  */
3974
3975 static void
3976 mips_read_fp_register_double (struct frame_info *frame, int regno,
3977                               char *rare_buffer)
3978 {
3979   int raw_size = REGISTER_RAW_SIZE (regno);
3980
3981   if (raw_size == 8 && !mips2_fp_compat ())
3982     {
3983       /* We have a 64-bit value for this register, and we should use
3984          all 64 bits.  */
3985       if (!frame_register_read (frame, regno, rare_buffer))
3986         error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
3987     }
3988   else
3989     {
3990       if ((regno - FP0_REGNUM) & 1)
3991         internal_error (__FILE__, __LINE__,
3992                         "mips_read_fp_register_double: bad access to "
3993                         "odd-numbered FP register");
3994
3995       /* mips_read_fp_register_single will find the correct 32 bits from
3996          each register.  */
3997       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3998         {
3999           mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4000           mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4001         }
4002       else
4003         {
4004           mips_read_fp_register_single (frame, regno, rare_buffer);
4005           mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4006         }
4007     }
4008 }
4009
4010 static void
4011 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4012                         int regnum)
4013 {                               /* do values for FP (float) regs */
4014   char *raw_buffer;
4015   double doub, flt1, flt2;      /* doubles extracted from raw hex data */
4016   int inv1, inv2, namelen;
4017
4018   raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
4019
4020   fprintf_filtered (file, "%s:", REGISTER_NAME (regnum));
4021   fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)),
4022                     "");
4023
4024   if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ())
4025     {
4026       /* 4-byte registers: Print hex and floating.  Also print even
4027          numbered registers as doubles.  */
4028       mips_read_fp_register_single (frame, regnum, raw_buffer);
4029       flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4030
4031       print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', file);
4032
4033       fprintf_filtered (file, " flt: ");
4034       if (inv1)
4035         fprintf_filtered (file, " <invalid float> ");
4036       else
4037         fprintf_filtered (file, "%-17.9g", flt1);
4038
4039       if (regnum % 2 == 0)
4040         {
4041           mips_read_fp_register_double (frame, regnum, raw_buffer);
4042           doub = unpack_double (mips_double_register_type (), raw_buffer,
4043                                 &inv2);
4044
4045           fprintf_filtered (file, " dbl: ");
4046           if (inv2)
4047             fprintf_filtered (file, "<invalid double>");
4048           else
4049             fprintf_filtered (file, "%-24.17g", doub);
4050         }
4051     }
4052   else
4053     {
4054       /* Eight byte registers: print each one as hex, float and double.  */
4055       mips_read_fp_register_single (frame, regnum, raw_buffer);
4056       flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4057
4058       mips_read_fp_register_double (frame, regnum, raw_buffer);
4059       doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4060
4061
4062       print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', file);
4063
4064       fprintf_filtered (file, " flt: ");
4065       if (inv1)
4066         fprintf_filtered (file, "<invalid float>");
4067       else
4068         fprintf_filtered (file, "%-17.9g", flt1);
4069
4070       fprintf_filtered (file, " dbl: ");
4071       if (inv2)
4072         fprintf_filtered (file, "<invalid double>");
4073       else
4074         fprintf_filtered (file, "%-24.17g", doub);
4075     }
4076 }
4077
4078 static void
4079 mips_print_register (struct ui_file *file, struct frame_info *frame,
4080                      int regnum, int all)
4081 {
4082   char raw_buffer[MAX_REGISTER_SIZE];
4083   int offset;
4084
4085   if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4086     {
4087       mips_print_fp_register (file, frame, regnum);
4088       return;
4089     }
4090
4091   /* Get the data in raw format.  */
4092   if (!frame_register_read (frame, regnum, raw_buffer))
4093     {
4094       fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum));
4095       return;
4096     }
4097
4098   fputs_filtered (REGISTER_NAME (regnum), file);
4099
4100   /* The problem with printing numeric register names (r26, etc.) is that
4101      the user can't use them on input.  Probably the best solution is to
4102      fix it so that either the numeric or the funky (a2, etc.) names
4103      are accepted on input.  */
4104   if (regnum < MIPS_NUMREGS)
4105     fprintf_filtered (file, "(r%d): ", regnum);
4106   else
4107     fprintf_filtered (file, ": ");
4108
4109   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4110     offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4111   else
4112     offset = 0;
4113
4114   print_scalar_formatted (raw_buffer + offset,
4115                           REGISTER_VIRTUAL_TYPE (regnum),
4116                           'x', 0, file);
4117 }
4118
4119 /* Replacement for generic do_registers_info.
4120    Print regs in pretty columns.  */
4121
4122 static int
4123 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4124                        int regnum)
4125 {
4126   fprintf_filtered (file, " ");
4127   mips_print_fp_register (file, frame, regnum);
4128   fprintf_filtered (file, "\n");
4129   return regnum + 1;
4130 }
4131
4132
4133 /* Print a row's worth of GP (int) registers, with name labels above */
4134
4135 static int
4136 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4137                        int regnum)
4138 {
4139   /* do values for GP (int) regs */
4140   char raw_buffer[MAX_REGISTER_SIZE];
4141   int ncols = (MIPS_REGSIZE == 8 ? 4 : 8);      /* display cols per row */
4142   int col, byte;
4143   int start_regnum = regnum;
4144   int numregs = NUM_REGS;
4145
4146
4147   /* For GP registers, we print a separate row of names above the vals */
4148   fprintf_filtered (file, "     ");
4149   for (col = 0; col < ncols && regnum < numregs; regnum++)
4150     {
4151       if (*REGISTER_NAME (regnum) == '\0')
4152         continue;               /* unused register */
4153       if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4154         break;                  /* end the row: reached FP register */
4155       fprintf_filtered (file, MIPS_REGSIZE == 8 ? "%17s" : "%9s",
4156                         REGISTER_NAME (regnum));
4157       col++;
4158     }
4159   fprintf_filtered (file,
4160                     start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n      ",
4161                     start_regnum);      /* print the R0 to R31 names */
4162
4163   regnum = start_regnum;        /* go back to start of row */
4164   /* now print the values in hex, 4 or 8 to the row */
4165   for (col = 0; col < ncols && regnum < numregs; regnum++)
4166     {
4167       if (*REGISTER_NAME (regnum) == '\0')
4168         continue;               /* unused register */
4169       if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4170         break;                  /* end row: reached FP register */
4171       /* OK: get the data in raw format.  */
4172       if (!frame_register_read (frame, regnum, raw_buffer))
4173         error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4174       /* pad small registers */
4175       for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++)
4176         printf_filtered ("  ");
4177       /* Now print the register value in hex, endian order. */
4178       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4179         for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum);
4180              byte < REGISTER_RAW_SIZE (regnum);
4181              byte++)
4182           fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4183       else
4184         for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1;
4185              byte >= 0;
4186              byte--)
4187           fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
4188       fprintf_filtered (file, " ");
4189       col++;
4190     }
4191   if (col > 0)                  /* ie. if we actually printed anything... */
4192     fprintf_filtered (file, "\n");
4193
4194   return regnum;
4195 }
4196
4197 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4198
4199 static void
4200 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4201                            struct frame_info *frame, int regnum, int all)
4202 {
4203   if (regnum != -1)             /* do one specified register */
4204     {
4205       if (*(REGISTER_NAME (regnum)) == '\0')
4206         error ("Not a valid register for the current processor type");
4207
4208       mips_print_register (file, frame, regnum, 0);
4209       fprintf_filtered (file, "\n");
4210     }
4211   else
4212     /* do all (or most) registers */
4213     {
4214       regnum = 0;
4215       while (regnum < NUM_REGS)
4216         {
4217           if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4218             {
4219               if (all)          /* true for "INFO ALL-REGISTERS" command */
4220                 regnum = print_fp_register_row (file, frame, regnum);
4221               else
4222                 regnum += MIPS_NUMREGS; /* skip floating point regs */
4223             }
4224           else
4225             regnum = print_gp_register_row (file, frame, regnum);
4226         }
4227     }
4228 }
4229
4230 /* Is this a branch with a delay slot?  */
4231
4232 static int is_delayed (unsigned long);
4233
4234 static int
4235 is_delayed (unsigned long insn)
4236 {
4237   int i;
4238   for (i = 0; i < NUMOPCODES; ++i)
4239     if (mips_opcodes[i].pinfo != INSN_MACRO
4240         && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4241       break;
4242   return (i < NUMOPCODES
4243           && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4244                                        | INSN_COND_BRANCH_DELAY
4245                                        | INSN_COND_BRANCH_LIKELY)));
4246 }
4247
4248 int
4249 mips_step_skips_delay (CORE_ADDR pc)
4250 {
4251   char buf[MIPS_INSTLEN];
4252
4253   /* There is no branch delay slot on MIPS16.  */
4254   if (pc_is_mips16 (pc))
4255     return 0;
4256
4257   if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
4258     /* If error reading memory, guess that it is not a delayed branch.  */
4259     return 0;
4260   return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN));
4261 }
4262
4263
4264 /* Skip the PC past function prologue instructions (32-bit version).
4265    This is a helper function for mips_skip_prologue.  */
4266
4267 static CORE_ADDR
4268 mips32_skip_prologue (CORE_ADDR pc)
4269 {
4270   t_inst inst;
4271   CORE_ADDR end_pc;
4272   int seen_sp_adjust = 0;
4273   int load_immediate_bytes = 0;
4274
4275   /* Skip the typical prologue instructions. These are the stack adjustment
4276      instruction and the instructions that save registers on the stack
4277      or in the gcc frame.  */
4278   for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
4279     {
4280       unsigned long high_word;
4281
4282       inst = mips_fetch_instruction (pc);
4283       high_word = (inst >> 16) & 0xffff;
4284
4285       if (high_word == 0x27bd   /* addiu $sp,$sp,offset */
4286           || high_word == 0x67bd)       /* daddiu $sp,$sp,offset */
4287         seen_sp_adjust = 1;
4288       else if (inst == 0x03a1e823 ||    /* subu $sp,$sp,$at */
4289                inst == 0x03a8e823)      /* subu $sp,$sp,$t0 */
4290         seen_sp_adjust = 1;
4291       else if (((inst & 0xFFE00000) == 0xAFA00000       /* sw reg,n($sp) */
4292                 || (inst & 0xFFE00000) == 0xFFA00000)   /* sd reg,n($sp) */
4293                && (inst & 0x001F0000))  /* reg != $zero */
4294         continue;
4295
4296       else if ((inst & 0xFFE00000) == 0xE7A00000)       /* swc1 freg,n($sp) */
4297         continue;
4298       else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
4299         /* sx reg,n($s8) */
4300         continue;               /* reg != $zero */
4301
4302       /* move $s8,$sp.  With different versions of gas this will be either
4303          `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
4304          Accept any one of these.  */
4305       else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
4306         continue;
4307
4308       else if ((inst & 0xFF9F07FF) == 0x00800021)       /* move reg,$a0-$a3 */
4309         continue;
4310       else if (high_word == 0x3c1c)     /* lui $gp,n */
4311         continue;
4312       else if (high_word == 0x279c)     /* addiu $gp,$gp,n */
4313         continue;
4314       else if (inst == 0x0399e021       /* addu $gp,$gp,$t9 */
4315                || inst == 0x033ce021)   /* addu $gp,$t9,$gp */
4316         continue;
4317       /* The following instructions load $at or $t0 with an immediate
4318          value in preparation for a stack adjustment via
4319          subu $sp,$sp,[$at,$t0]. These instructions could also initialize
4320          a local variable, so we accept them only before a stack adjustment
4321          instruction was seen.  */
4322       else if (!seen_sp_adjust)
4323         {
4324           if (high_word == 0x3c01 ||    /* lui $at,n */
4325               high_word == 0x3c08)      /* lui $t0,n */
4326             {
4327               load_immediate_bytes += MIPS_INSTLEN;     /* FIXME!! */
4328               continue;
4329             }
4330           else if (high_word == 0x3421 ||       /* ori $at,$at,n */
4331                    high_word == 0x3508 ||       /* ori $t0,$t0,n */
4332                    high_word == 0x3401 ||       /* ori $at,$zero,n */
4333                    high_word == 0x3408)         /* ori $t0,$zero,n */
4334             {
4335               load_immediate_bytes += MIPS_INSTLEN;     /* FIXME!! */
4336               continue;
4337             }
4338           else
4339             break;
4340         }
4341       else
4342         break;
4343     }
4344
4345   /* In a frameless function, we might have incorrectly
4346      skipped some load immediate instructions. Undo the skipping
4347      if the load immediate was not followed by a stack adjustment.  */
4348   if (load_immediate_bytes && !seen_sp_adjust)
4349     pc -= load_immediate_bytes;
4350   return pc;
4351 }
4352
4353 /* Skip the PC past function prologue instructions (16-bit version).
4354    This is a helper function for mips_skip_prologue.  */
4355
4356 static CORE_ADDR
4357 mips16_skip_prologue (CORE_ADDR pc)
4358 {
4359   CORE_ADDR end_pc;
4360   int extend_bytes = 0;
4361   int prev_extend_bytes;
4362
4363   /* Table of instructions likely to be found in a function prologue.  */
4364   static struct
4365     {
4366       unsigned short inst;
4367       unsigned short mask;
4368     }
4369   table[] =
4370   {
4371     {
4372       0x6300, 0xff00
4373     }
4374     ,                           /* addiu $sp,offset */
4375     {
4376       0xfb00, 0xff00
4377     }
4378     ,                           /* daddiu $sp,offset */
4379     {
4380       0xd000, 0xf800
4381     }
4382     ,                           /* sw reg,n($sp) */
4383     {
4384       0xf900, 0xff00
4385     }
4386     ,                           /* sd reg,n($sp) */
4387     {
4388       0x6200, 0xff00
4389     }
4390     ,                           /* sw $ra,n($sp) */
4391     {
4392       0xfa00, 0xff00
4393     }
4394     ,                           /* sd $ra,n($sp) */
4395     {
4396       0x673d, 0xffff
4397     }
4398     ,                           /* move $s1,sp */
4399     {
4400       0xd980, 0xff80
4401     }
4402     ,                           /* sw $a0-$a3,n($s1) */
4403     {
4404       0x6704, 0xff1c
4405     }
4406     ,                           /* move reg,$a0-$a3 */
4407     {
4408       0xe809, 0xf81f
4409     }
4410     ,                           /* entry pseudo-op */
4411     {
4412       0x0100, 0xff00
4413     }
4414     ,                           /* addiu $s1,$sp,n */
4415     {
4416       0, 0
4417     }                           /* end of table marker */
4418   };
4419
4420   /* Skip the typical prologue instructions. These are the stack adjustment
4421      instruction and the instructions that save registers on the stack
4422      or in the gcc frame.  */
4423   for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
4424     {
4425       unsigned short inst;
4426       int i;
4427
4428       inst = mips_fetch_instruction (pc);
4429
4430       /* Normally we ignore an extend instruction.  However, if it is
4431          not followed by a valid prologue instruction, we must adjust
4432          the pc back over the extend so that it won't be considered
4433          part of the prologue.  */
4434       if ((inst & 0xf800) == 0xf000)    /* extend */
4435         {
4436           extend_bytes = MIPS16_INSTLEN;
4437           continue;
4438         }
4439       prev_extend_bytes = extend_bytes;
4440       extend_bytes = 0;
4441
4442       /* Check for other valid prologue instructions besides extend.  */
4443       for (i = 0; table[i].mask != 0; i++)
4444         if ((inst & table[i].mask) == table[i].inst)    /* found, get out */
4445           break;
4446       if (table[i].mask != 0)   /* it was in table? */
4447         continue;               /* ignore it */
4448       else
4449         /* non-prologue */
4450         {
4451           /* Return the current pc, adjusted backwards by 2 if
4452              the previous instruction was an extend.  */
4453           return pc - prev_extend_bytes;
4454         }
4455     }
4456   return pc;
4457 }
4458
4459 /* To skip prologues, I use this predicate.  Returns either PC itself
4460    if the code at PC does not look like a function prologue; otherwise
4461    returns an address that (if we're lucky) follows the prologue.  If
4462    LENIENT, then we must skip everything which is involved in setting
4463    up the frame (it's OK to skip more, just so long as we don't skip
4464    anything which might clobber the registers which are being saved.
4465    We must skip more in the case where part of the prologue is in the
4466    delay slot of a non-prologue instruction).  */
4467
4468 static CORE_ADDR
4469 mips_skip_prologue (CORE_ADDR pc)
4470 {
4471   /* See if we can determine the end of the prologue via the symbol table.
4472      If so, then return either PC, or the PC after the prologue, whichever
4473      is greater.  */
4474
4475   CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
4476
4477   if (post_prologue_pc != 0)
4478     return max (pc, post_prologue_pc);
4479
4480   /* Can't determine prologue from the symbol table, need to examine
4481      instructions.  */
4482
4483   if (pc_is_mips16 (pc))
4484     return mips16_skip_prologue (pc);
4485   else
4486     return mips32_skip_prologue (pc);
4487 }
4488
4489 /* Determine how a return value is stored within the MIPS register
4490    file, given the return type `valtype'. */
4491
4492 struct return_value_word
4493 {
4494   int len;
4495   int reg;
4496   int reg_offset;
4497   int buf_offset;
4498 };
4499
4500 static void
4501 return_value_location (struct type *valtype,
4502                        struct return_value_word *hi,
4503                        struct return_value_word *lo)
4504 {
4505   int len = TYPE_LENGTH (valtype);
4506
4507   if (TYPE_CODE (valtype) == TYPE_CODE_FLT
4508       && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
4509           || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
4510     {
4511       if (!FP_REGISTER_DOUBLE && len == 8)
4512         {
4513           /* We need to break a 64bit float in two 32 bit halves and
4514              spread them across a floating-point register pair. */
4515           lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4516           hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
4517           lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4518                              && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
4519                             ? 4 : 0);
4520           hi->reg_offset = lo->reg_offset;
4521           lo->reg = FP0_REGNUM + 0;
4522           hi->reg = FP0_REGNUM + 1;
4523           lo->len = 4;
4524           hi->len = 4;
4525         }
4526       else
4527         {
4528           /* The floating point value fits in a single floating-point
4529              register. */
4530           lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4531                              && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
4532                              && len == 4)
4533                             ? 4 : 0);
4534           lo->reg = FP0_REGNUM;
4535           lo->len = len;
4536           lo->buf_offset = 0;
4537           hi->len = 0;
4538           hi->reg_offset = 0;
4539           hi->buf_offset = 0;
4540           hi->reg = 0;
4541         }
4542     }
4543   else
4544     {
4545       /* Locate a result possibly spread across two registers. */
4546       int regnum = 2;
4547       lo->reg = regnum + 0;
4548       hi->reg = regnum + 1;
4549       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4550           && len < MIPS_SAVED_REGSIZE)
4551         {
4552           /* "un-left-justify" the value in the low register */
4553           lo->reg_offset = MIPS_SAVED_REGSIZE - len;
4554           lo->len = len;
4555           hi->reg_offset = 0;
4556           hi->len = 0;
4557         }
4558       else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4559                && len > MIPS_SAVED_REGSIZE      /* odd-size structs */
4560                && len < MIPS_SAVED_REGSIZE * 2
4561                && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
4562                    TYPE_CODE (valtype) == TYPE_CODE_UNION))
4563         {
4564           /* "un-left-justify" the value spread across two registers. */
4565           lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
4566           lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
4567           hi->reg_offset = 0;
4568           hi->len = len - lo->len;
4569         }
4570       else
4571         {
4572           /* Only perform a partial copy of the second register. */
4573           lo->reg_offset = 0;
4574           hi->reg_offset = 0;
4575           if (len > MIPS_SAVED_REGSIZE)
4576             {
4577               lo->len = MIPS_SAVED_REGSIZE;
4578               hi->len = len - MIPS_SAVED_REGSIZE;
4579             }
4580           else
4581             {
4582               lo->len = len;
4583               hi->len = 0;
4584             }
4585         }
4586       if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4587           && REGISTER_RAW_SIZE (regnum) == 8
4588           && MIPS_SAVED_REGSIZE == 4)
4589         {
4590           /* Account for the fact that only the least-signficant part
4591              of the register is being used */
4592           lo->reg_offset += 4;
4593           hi->reg_offset += 4;
4594         }
4595       lo->buf_offset = 0;
4596       hi->buf_offset = lo->len;
4597     }
4598 }
4599
4600 /* Given a return value in `regbuf' with a type `valtype', extract and
4601    copy its value into `valbuf'. */
4602
4603 static void
4604 mips_eabi_extract_return_value (struct type *valtype,
4605                                 char regbuf[],
4606                                 char *valbuf)
4607 {
4608   struct return_value_word lo;
4609   struct return_value_word hi;
4610   return_value_location (valtype, &hi, &lo);
4611
4612   memcpy (valbuf + lo.buf_offset,
4613           regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4614           lo.len);
4615
4616   if (hi.len > 0)
4617     memcpy (valbuf + hi.buf_offset,
4618             regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4619             hi.len);
4620 }
4621
4622 static void
4623 mips_o64_extract_return_value (struct type *valtype,
4624                                char regbuf[],
4625                                char *valbuf)
4626 {
4627   struct return_value_word lo;
4628   struct return_value_word hi;
4629   return_value_location (valtype, &hi, &lo);
4630
4631   memcpy (valbuf + lo.buf_offset,
4632           regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
4633           lo.len);
4634
4635   if (hi.len > 0)
4636     memcpy (valbuf + hi.buf_offset,
4637             regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
4638             hi.len);
4639 }
4640
4641 /* Given a return value in `valbuf' with a type `valtype', write it's
4642    value into the appropriate register. */
4643
4644 static void
4645 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
4646 {
4647   char raw_buffer[MAX_REGISTER_SIZE];
4648   struct return_value_word lo;
4649   struct return_value_word hi;
4650   return_value_location (valtype, &hi, &lo);
4651
4652   memset (raw_buffer, 0, sizeof (raw_buffer));
4653   memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4654   deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4655                                    REGISTER_RAW_SIZE (lo.reg));
4656
4657   if (hi.len > 0)
4658     {
4659       memset (raw_buffer, 0, sizeof (raw_buffer));
4660       memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4661       deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4662                                        REGISTER_RAW_SIZE (hi.reg));
4663     }
4664 }
4665
4666 static void
4667 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4668 {
4669   char raw_buffer[MAX_REGISTER_SIZE];
4670   struct return_value_word lo;
4671   struct return_value_word hi;
4672   return_value_location (valtype, &hi, &lo);
4673
4674   memset (raw_buffer, 0, sizeof (raw_buffer));
4675   memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4676   deprecated_write_register_bytes (REGISTER_BYTE (lo.reg), raw_buffer,
4677                                    REGISTER_RAW_SIZE (lo.reg));
4678
4679   if (hi.len > 0)
4680     {
4681       memset (raw_buffer, 0, sizeof (raw_buffer));
4682       memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4683       deprecated_write_register_bytes (REGISTER_BYTE (hi.reg), raw_buffer,
4684                                        REGISTER_RAW_SIZE (hi.reg));
4685     }
4686 }
4687
4688 /* O32 ABI stuff.  */
4689
4690 static void
4691 mips_o32_xfer_return_value (struct type *type,
4692                             struct regcache *regcache,
4693                             bfd_byte *in, const bfd_byte *out)
4694 {
4695   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4696   if (TYPE_CODE (type) == TYPE_CODE_FLT
4697       && TYPE_LENGTH (type) == 4
4698       && tdep->mips_fpu_type != MIPS_FPU_NONE)
4699     {
4700       /* A single-precision floating-point value.  It fits in the
4701          least significant part of FP0.  */
4702       if (mips_debug)
4703         fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4704       mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4705                           TARGET_BYTE_ORDER, in, out, 0);
4706     }
4707   else if (TYPE_CODE (type) == TYPE_CODE_FLT
4708            && TYPE_LENGTH (type) == 8
4709            && tdep->mips_fpu_type != MIPS_FPU_NONE)
4710     {
4711       /* A double-precision floating-point value.  It fits in the
4712          least significant part of FP0/FP1 but with byte ordering
4713          based on the target (???).  */
4714       if (mips_debug)
4715         fprintf_unfiltered (gdb_stderr, "Return float in $fp0/$fp1\n");
4716       switch (TARGET_BYTE_ORDER)
4717         {
4718         case BFD_ENDIAN_LITTLE:
4719           mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4720                               TARGET_BYTE_ORDER, in, out, 0);
4721           mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4722                               TARGET_BYTE_ORDER, in, out, 4);
4723           break;
4724         case BFD_ENDIAN_BIG:
4725           mips_xfer_register (regcache, FP0_REGNUM + 1, 4,
4726                               TARGET_BYTE_ORDER, in, out, 0);
4727           mips_xfer_register (regcache, FP0_REGNUM + 0, 4,
4728                               TARGET_BYTE_ORDER, in, out, 4);
4729           break;
4730         default:
4731           internal_error (__FILE__, __LINE__, "bad switch");
4732         }
4733     }
4734 #if 0
4735   else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4736            && TYPE_NFIELDS (type) <= 2
4737            && TYPE_NFIELDS (type) >= 1
4738            && ((TYPE_NFIELDS (type) == 1
4739                 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4740                     == TYPE_CODE_FLT))
4741                || (TYPE_NFIELDS (type) == 2
4742                    && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4743                        == TYPE_CODE_FLT)
4744                    && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4745                        == TYPE_CODE_FLT)))
4746            && tdep->mips_fpu_type != MIPS_FPU_NONE)
4747     {
4748       /* A struct that contains one or two floats.  Each value is part
4749          in the least significant part of their floating point
4750          register..  */
4751       bfd_byte reg[MAX_REGISTER_SIZE];
4752       int regnum;
4753       int field;
4754       for (field = 0, regnum = FP0_REGNUM;
4755            field < TYPE_NFIELDS (type);
4756            field++, regnum += 2)
4757         {
4758           int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4759                         / TARGET_CHAR_BIT);
4760           if (mips_debug)
4761             fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4762           mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4763                               TARGET_BYTE_ORDER, in, out, offset);
4764         }
4765     }
4766 #endif
4767 #if 0
4768   else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4769            || TYPE_CODE (type) == TYPE_CODE_UNION)
4770     {
4771       /* A structure or union.  Extract the left justified value,
4772          regardless of the byte order.  I.e. DO NOT USE
4773          mips_xfer_lower.  */
4774       int offset;
4775       int regnum;
4776       for (offset = 0, regnum = V0_REGNUM;
4777            offset < TYPE_LENGTH (type);
4778            offset += REGISTER_RAW_SIZE (regnum), regnum++)
4779         {
4780           int xfer = REGISTER_RAW_SIZE (regnum);
4781           if (offset + xfer > TYPE_LENGTH (type))
4782             xfer = TYPE_LENGTH (type) - offset;
4783           if (mips_debug)
4784             fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4785                                 offset, xfer, regnum);
4786           mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4787                               in, out, offset);
4788         }
4789     }
4790 #endif
4791   else
4792     {
4793       /* A scalar extract each part but least-significant-byte
4794          justified.  o32 thinks registers are 4 byte, regardless of
4795          the ISA.  mips_stack_argsize controls this.  */
4796       int offset;
4797       int regnum;
4798       for (offset = 0, regnum = V0_REGNUM;
4799            offset < TYPE_LENGTH (type);
4800            offset += mips_stack_argsize (), regnum++)
4801         {
4802           int xfer = mips_stack_argsize ();
4803           int pos = 0;
4804           if (offset + xfer > TYPE_LENGTH (type))
4805             xfer = TYPE_LENGTH (type) - offset;
4806           if (mips_debug)
4807             fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4808                                 offset, xfer, regnum);
4809           mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4810                               in, out, offset);
4811         }
4812     }
4813 }
4814
4815 static void
4816 mips_o32_extract_return_value (struct type *type,
4817                                struct regcache *regcache,
4818                                void *valbuf)
4819 {
4820   mips_o32_xfer_return_value (type, regcache, valbuf, NULL); 
4821 }
4822
4823 static void
4824 mips_o32_store_return_value (struct type *type, char *valbuf)
4825 {
4826   mips_o32_xfer_return_value (type, current_regcache, NULL, valbuf); 
4827 }
4828
4829 /* N32/N44 ABI stuff.  */
4830
4831 static void
4832 mips_n32n64_xfer_return_value (struct type *type,
4833                                struct regcache *regcache,
4834                                bfd_byte *in, const bfd_byte *out)
4835 {
4836   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4837   if (TYPE_CODE (type) == TYPE_CODE_FLT
4838       && tdep->mips_fpu_type != MIPS_FPU_NONE)
4839     {
4840       /* A floating-point value belongs in the least significant part
4841          of FP0.  */
4842       if (mips_debug)
4843         fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4844       mips_xfer_register (regcache, FP0_REGNUM, TYPE_LENGTH (type),
4845                           TARGET_BYTE_ORDER, in, out, 0);
4846     }
4847   else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4848            && TYPE_NFIELDS (type) <= 2
4849            && TYPE_NFIELDS (type) >= 1
4850            && ((TYPE_NFIELDS (type) == 1
4851                 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4852                     == TYPE_CODE_FLT))
4853                || (TYPE_NFIELDS (type) == 2
4854                    && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4855                        == TYPE_CODE_FLT)
4856                    && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4857                        == TYPE_CODE_FLT)))
4858            && tdep->mips_fpu_type != MIPS_FPU_NONE)
4859     {
4860       /* A struct that contains one or two floats.  Each value is part
4861          in the least significant part of their floating point
4862          register..  */
4863       bfd_byte reg[MAX_REGISTER_SIZE];
4864       int regnum;
4865       int field;
4866       for (field = 0, regnum = FP0_REGNUM;
4867            field < TYPE_NFIELDS (type);
4868            field++, regnum += 2)
4869         {
4870           int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4871                         / TARGET_CHAR_BIT);
4872           if (mips_debug)
4873             fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", offset);
4874           mips_xfer_register (regcache, regnum, TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4875                               TARGET_BYTE_ORDER, in, out, offset);
4876         }
4877     }
4878   else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4879            || TYPE_CODE (type) == TYPE_CODE_UNION)
4880     {
4881       /* A structure or union.  Extract the left justified value,
4882          regardless of the byte order.  I.e. DO NOT USE
4883          mips_xfer_lower.  */
4884       int offset;
4885       int regnum;
4886       for (offset = 0, regnum = V0_REGNUM;
4887            offset < TYPE_LENGTH (type);
4888            offset += REGISTER_RAW_SIZE (regnum), regnum++)
4889         {
4890           int xfer = REGISTER_RAW_SIZE (regnum);
4891           if (offset + xfer > TYPE_LENGTH (type))
4892             xfer = TYPE_LENGTH (type) - offset;
4893           if (mips_debug)
4894             fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4895                                 offset, xfer, regnum);
4896           mips_xfer_register (regcache, regnum, xfer, BFD_ENDIAN_UNKNOWN,
4897                               in, out, offset);
4898         }
4899     }
4900   else
4901     {
4902       /* A scalar extract each part but least-significant-byte
4903          justified.  */
4904       int offset;
4905       int regnum;
4906       for (offset = 0, regnum = V0_REGNUM;
4907            offset < TYPE_LENGTH (type);
4908            offset += REGISTER_RAW_SIZE (regnum), regnum++)
4909         {
4910           int xfer = REGISTER_RAW_SIZE (regnum);
4911           int pos = 0;
4912           if (offset + xfer > TYPE_LENGTH (type))
4913             xfer = TYPE_LENGTH (type) - offset;
4914           if (mips_debug)
4915             fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4916                                 offset, xfer, regnum);
4917           mips_xfer_register (regcache, regnum, xfer, TARGET_BYTE_ORDER,
4918                               in, out, offset);
4919         }
4920     }
4921 }
4922
4923 static void
4924 mips_n32n64_extract_return_value (struct type *type,
4925                                   struct regcache *regcache,
4926                                   void *valbuf)
4927 {
4928   mips_n32n64_xfer_return_value (type, regcache, valbuf, NULL);
4929 }
4930
4931 static void
4932 mips_n32n64_store_return_value (struct type *type, char *valbuf)
4933 {
4934   mips_n32n64_xfer_return_value (type, current_regcache, NULL, valbuf);
4935 }
4936
4937 static CORE_ADDR
4938 mips_extract_struct_value_address (struct regcache *regcache)
4939 {
4940   /* FIXME: This will only work at random.  The caller passes the
4941      struct_return address in V0, but it is not preserved.  It may
4942      still be there, or this may be a random value.  */
4943   LONGEST val;
4944
4945   regcache_cooked_read_signed (regcache, V0_REGNUM, &val);
4946   return val;
4947 }
4948
4949 /* Exported procedure: Is PC in the signal trampoline code */
4950
4951 static int
4952 mips_pc_in_sigtramp (CORE_ADDR pc, char *ignore)
4953 {
4954   if (sigtramp_address == 0)
4955     fixup_sigtramp ();
4956   return (pc >= sigtramp_address && pc < sigtramp_end);
4957 }
4958
4959 /* Root of all "set mips "/"show mips " commands. This will eventually be
4960    used for all MIPS-specific commands.  */
4961
4962 static void
4963 show_mips_command (char *args, int from_tty)
4964 {
4965   help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4966 }
4967
4968 static void
4969 set_mips_command (char *args, int from_tty)
4970 {
4971   printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n");
4972   help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4973 }
4974
4975 /* Commands to show/set the MIPS FPU type.  */
4976
4977 static void
4978 show_mipsfpu_command (char *args, int from_tty)
4979 {
4980   char *fpu;
4981   switch (MIPS_FPU_TYPE)
4982     {
4983     case MIPS_FPU_SINGLE:
4984       fpu = "single-precision";
4985       break;
4986     case MIPS_FPU_DOUBLE:
4987       fpu = "double-precision";
4988       break;
4989     case MIPS_FPU_NONE:
4990       fpu = "absent (none)";
4991       break;
4992     default:
4993       internal_error (__FILE__, __LINE__, "bad switch");
4994     }
4995   if (mips_fpu_type_auto)
4996     printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4997                        fpu);
4998   else
4999     printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
5000                        fpu);
5001 }
5002
5003
5004 static void
5005 set_mipsfpu_command (char *args, int from_tty)
5006 {
5007   printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5008   show_mipsfpu_command (args, from_tty);
5009 }
5010
5011 static void
5012 set_mipsfpu_single_command (char *args, int from_tty)
5013 {
5014   mips_fpu_type = MIPS_FPU_SINGLE;
5015   mips_fpu_type_auto = 0;
5016   gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE;
5017 }
5018
5019 static void
5020 set_mipsfpu_double_command (char *args, int from_tty)
5021 {
5022   mips_fpu_type = MIPS_FPU_DOUBLE;
5023   mips_fpu_type_auto = 0;
5024   gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE;
5025 }
5026
5027 static void
5028 set_mipsfpu_none_command (char *args, int from_tty)
5029 {
5030   mips_fpu_type = MIPS_FPU_NONE;
5031   mips_fpu_type_auto = 0;
5032   gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE;
5033 }
5034
5035 static void
5036 set_mipsfpu_auto_command (char *args, int from_tty)
5037 {
5038   mips_fpu_type_auto = 1;
5039 }
5040
5041 /* Command to set the processor type.  */
5042
5043 void
5044 mips_set_processor_type_command (char *args, int from_tty)
5045 {
5046   int i;
5047
5048   if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
5049     {
5050       printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
5051       for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5052         printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
5053
5054       /* Restore the value.  */
5055       tmp_mips_processor_type = xstrdup (mips_processor_type);
5056
5057       return;
5058     }
5059
5060   if (!mips_set_processor_type (tmp_mips_processor_type))
5061     {
5062       error ("Unknown processor type `%s'.", tmp_mips_processor_type);
5063       /* Restore its value.  */
5064       tmp_mips_processor_type = xstrdup (mips_processor_type);
5065     }
5066 }
5067
5068 static void
5069 mips_show_processor_type_command (char *args, int from_tty)
5070 {
5071 }
5072
5073 /* Modify the actual processor type. */
5074
5075 static int
5076 mips_set_processor_type (char *str)
5077 {
5078   int i;
5079
5080   if (str == NULL)
5081     return 0;
5082
5083   for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
5084     {
5085       if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
5086         {
5087           mips_processor_type = str;
5088           mips_processor_reg_names = mips_processor_type_table[i].regnames;
5089           return 1;
5090           /* FIXME tweak fpu flag too */
5091         }
5092     }
5093
5094   return 0;
5095 }
5096
5097 /* Attempt to identify the particular processor model by reading the
5098    processor id.  */
5099
5100 char *
5101 mips_read_processor_type (void)
5102 {
5103   CORE_ADDR prid;
5104
5105   prid = read_register (PRID_REGNUM);
5106
5107   if ((prid & ~0xf) == 0x700)
5108     return savestring ("r3041", strlen ("r3041"));
5109
5110   return NULL;
5111 }
5112
5113 /* Just like reinit_frame_cache, but with the right arguments to be
5114    callable as an sfunc.  */
5115
5116 static void
5117 reinit_frame_cache_sfunc (char *args, int from_tty,
5118                           struct cmd_list_element *c)
5119 {
5120   reinit_frame_cache ();
5121 }
5122
5123 int
5124 gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info)
5125 {
5126   mips_extra_func_info_t proc_desc;
5127
5128   /* Search for the function containing this address.  Set the low bit
5129      of the address when searching, in case we were given an even address
5130      that is the start of a 16-bit function.  If we didn't do this,
5131      the search would fail because the symbol table says the function
5132      starts at an odd address, i.e. 1 byte past the given address.  */
5133   memaddr = ADDR_BITS_REMOVE (memaddr);
5134   proc_desc = non_heuristic_proc_desc (make_mips16_addr (memaddr), NULL);
5135
5136   /* Make an attempt to determine if this is a 16-bit function.  If
5137      the procedure descriptor exists and the address therein is odd,
5138      it's definitely a 16-bit function.  Otherwise, we have to just
5139      guess that if the address passed in is odd, it's 16-bits.  */
5140   if (proc_desc)
5141     info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ?
5142       bfd_mach_mips16 : 0;
5143   else
5144     info->mach = pc_is_mips16 (memaddr) ?
5145       bfd_mach_mips16 : 0;
5146
5147   /* Round down the instruction address to the appropriate boundary.  */
5148   memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5149
5150   /* Call the appropriate disassembler based on the target endian-ness.  */
5151   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5152     return print_insn_big_mips (memaddr, info);
5153   else
5154     return print_insn_little_mips (memaddr, info);
5155 }
5156
5157 /* This function implements the BREAKPOINT_FROM_PC macro.  It uses the program
5158    counter value to determine whether a 16- or 32-bit breakpoint should be
5159    used.  It returns a pointer to a string of bytes that encode a breakpoint
5160    instruction, stores the length of the string to *lenptr, and adjusts pc
5161    (if necessary) to point to the actual memory location where the
5162    breakpoint should be inserted.  */
5163
5164 static const unsigned char *
5165 mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
5166 {
5167   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5168     {
5169       if (pc_is_mips16 (*pcptr))
5170         {
5171           static unsigned char mips16_big_breakpoint[] = {0xe8, 0xa5};
5172           *pcptr = unmake_mips16_addr (*pcptr);
5173           *lenptr = sizeof (mips16_big_breakpoint);
5174           return mips16_big_breakpoint;
5175         }
5176       else
5177         {
5178           /* The IDT board uses an unusual breakpoint value, and
5179              sometimes gets confused when it sees the usual MIPS
5180              breakpoint instruction.  */
5181           static unsigned char big_breakpoint[] = {0, 0x5, 0, 0xd};
5182           static unsigned char pmon_big_breakpoint[] = {0, 0, 0, 0xd};
5183           static unsigned char idt_big_breakpoint[] = {0, 0, 0x0a, 0xd};
5184
5185           *lenptr = sizeof (big_breakpoint);
5186
5187           if (strcmp (target_shortname, "mips") == 0)
5188             return idt_big_breakpoint;
5189           else if (strcmp (target_shortname, "ddb") == 0
5190                    || strcmp (target_shortname, "pmon") == 0
5191                    || strcmp (target_shortname, "lsi") == 0)
5192             return pmon_big_breakpoint;
5193           else
5194             return big_breakpoint;
5195         }
5196     }
5197   else
5198     {
5199       if (pc_is_mips16 (*pcptr))
5200         {
5201           static unsigned char mips16_little_breakpoint[] = {0xa5, 0xe8};
5202           *pcptr = unmake_mips16_addr (*pcptr);
5203           *lenptr = sizeof (mips16_little_breakpoint);
5204           return mips16_little_breakpoint;
5205         }
5206       else
5207         {
5208           static unsigned char little_breakpoint[] = {0xd, 0, 0x5, 0};
5209           static unsigned char pmon_little_breakpoint[] = {0xd, 0, 0, 0};
5210           static unsigned char idt_little_breakpoint[] = {0xd, 0x0a, 0, 0};
5211
5212           *lenptr = sizeof (little_breakpoint);
5213
5214           if (strcmp (target_shortname, "mips") == 0)
5215             return idt_little_breakpoint;
5216           else if (strcmp (target_shortname, "ddb") == 0
5217                    || strcmp (target_shortname, "pmon") == 0
5218                    || strcmp (target_shortname, "lsi") == 0)
5219             return pmon_little_breakpoint;
5220           else
5221             return little_breakpoint;
5222         }
5223     }
5224 }
5225
5226 /* If PC is in a mips16 call or return stub, return the address of the target
5227    PC, which is either the callee or the caller.  There are several
5228    cases which must be handled:
5229
5230    * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5231    target PC is in $31 ($ra).
5232    * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5233    and the target PC is in $2.
5234    * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5235    before the jal instruction, this is effectively a call stub
5236    and the the target PC is in $2.  Otherwise this is effectively
5237    a return stub and the target PC is in $18.
5238
5239    See the source code for the stubs in gcc/config/mips/mips16.S for
5240    gory details.
5241
5242    This function implements the SKIP_TRAMPOLINE_CODE macro.
5243  */
5244
5245 static CORE_ADDR
5246 mips_skip_stub (CORE_ADDR pc)
5247 {
5248   char *name;
5249   CORE_ADDR start_addr;
5250
5251   /* Find the starting address and name of the function containing the PC.  */
5252   if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5253     return 0;
5254
5255   /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5256      target PC is in $31 ($ra).  */
5257   if (strcmp (name, "__mips16_ret_sf") == 0
5258       || strcmp (name, "__mips16_ret_df") == 0)
5259     return read_signed_register (RA_REGNUM);
5260
5261   if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5262     {
5263       /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5264          and the target PC is in $2.  */
5265       if (name[19] >= '0' && name[19] <= '9')
5266         return read_signed_register (2);
5267
5268       /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5269          before the jal instruction, this is effectively a call stub
5270          and the the target PC is in $2.  Otherwise this is effectively
5271          a return stub and the target PC is in $18.  */
5272       else if (name[19] == 's' || name[19] == 'd')
5273         {
5274           if (pc == start_addr)
5275             {
5276               /* Check if the target of the stub is a compiler-generated
5277                  stub.  Such a stub for a function bar might have a name
5278                  like __fn_stub_bar, and might look like this:
5279                  mfc1    $4,$f13
5280                  mfc1    $5,$f12
5281                  mfc1    $6,$f15
5282                  mfc1    $7,$f14
5283                  la      $1,bar   (becomes a lui/addiu pair)
5284                  jr      $1
5285                  So scan down to the lui/addi and extract the target
5286                  address from those two instructions.  */
5287
5288               CORE_ADDR target_pc = read_signed_register (2);
5289               t_inst inst;
5290               int i;
5291
5292               /* See if the name of the target function is  __fn_stub_*.  */
5293               if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
5294                 return target_pc;
5295               if (strncmp (name, "__fn_stub_", 10) != 0
5296                   && strcmp (name, "etext") != 0
5297                   && strcmp (name, "_etext") != 0)
5298                 return target_pc;
5299
5300               /* Scan through this _fn_stub_ code for the lui/addiu pair.
5301                  The limit on the search is arbitrarily set to 20
5302                  instructions.  FIXME.  */
5303               for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5304                 {
5305                   inst = mips_fetch_instruction (target_pc);
5306                   if ((inst & 0xffff0000) == 0x3c010000)        /* lui $at */
5307                     pc = (inst << 16) & 0xffff0000;     /* high word */
5308                   else if ((inst & 0xffff0000) == 0x24210000)   /* addiu $at */
5309                     return pc | (inst & 0xffff);        /* low word */
5310                 }
5311
5312               /* Couldn't find the lui/addui pair, so return stub address.  */
5313               return target_pc;
5314             }
5315           else
5316             /* This is the 'return' part of a call stub.  The return
5317                address is in $r18.  */
5318             return read_signed_register (18);
5319         }
5320     }
5321   return 0;                     /* not a stub */
5322 }
5323
5324
5325 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5326    This implements the IN_SOLIB_CALL_TRAMPOLINE macro.  */
5327
5328 static int
5329 mips_in_call_stub (CORE_ADDR pc, char *name)
5330 {
5331   CORE_ADDR start_addr;
5332
5333   /* Find the starting address of the function containing the PC.  If the
5334      caller didn't give us a name, look it up at the same time.  */
5335   if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
5336     return 0;
5337
5338   if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5339     {
5340       /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub.  */
5341       if (name[19] >= '0' && name[19] <= '9')
5342         return 1;
5343       /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5344          before the jal instruction, this is effectively a call stub.  */
5345       else if (name[19] == 's' || name[19] == 'd')
5346         return pc == start_addr;
5347     }
5348
5349   return 0;                     /* not a stub */
5350 }
5351
5352
5353 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5354    This implements the IN_SOLIB_RETURN_TRAMPOLINE macro.  */
5355
5356 static int
5357 mips_in_return_stub (CORE_ADDR pc, char *name)
5358 {
5359   CORE_ADDR start_addr;
5360
5361   /* Find the starting address of the function containing the PC.  */
5362   if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5363     return 0;
5364
5365   /* If the PC is in __mips16_ret_{d,s}f, this is a return stub.  */
5366   if (strcmp (name, "__mips16_ret_sf") == 0
5367       || strcmp (name, "__mips16_ret_df") == 0)
5368     return 1;
5369
5370   /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5371      i.e. after the jal instruction, this is effectively a return stub.  */
5372   if (strncmp (name, "__mips16_call_stub_", 19) == 0
5373       && (name[19] == 's' || name[19] == 'd')
5374       && pc != start_addr)
5375     return 1;
5376
5377   return 0;                     /* not a stub */
5378 }
5379
5380
5381 /* Return non-zero if the PC is in a library helper function that should
5382    be ignored.  This implements the IGNORE_HELPER_CALL macro.  */
5383
5384 int
5385 mips_ignore_helper (CORE_ADDR pc)
5386 {
5387   char *name;
5388
5389   /* Find the starting address and name of the function containing the PC.  */
5390   if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5391     return 0;
5392
5393   /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5394      that we want to ignore.  */
5395   return (strcmp (name, "__mips16_ret_sf") == 0
5396           || strcmp (name, "__mips16_ret_df") == 0);
5397 }
5398
5399
5400 /* Return a location where we can set a breakpoint that will be hit
5401    when an inferior function call returns.  This is normally the
5402    program's entry point.  Executables that don't have an entry
5403    point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
5404    whose address is the location where the breakpoint should be placed.  */
5405
5406 static CORE_ADDR
5407 mips_call_dummy_address (void)
5408 {
5409   struct minimal_symbol *sym;
5410
5411   sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
5412   if (sym)
5413     return SYMBOL_VALUE_ADDRESS (sym);
5414   else
5415     return entry_point_address ();
5416 }
5417
5418
5419 /* When debugging a 64 MIPS target running a 32 bit ABI, the size of
5420    the register stored on the stack (32) is different to its real raw
5421    size (64).  The below ensures that registers are fetched from the
5422    stack using their ABI size and then stored into the RAW_BUFFER
5423    using their raw size.
5424
5425    The alternative to adding this function would be to add an ABI
5426    macro - REGISTER_STACK_SIZE(). */
5427
5428 static void
5429 mips_get_saved_register (char *raw_buffer,
5430                          int *optimizedp,
5431                          CORE_ADDR *addrp,
5432                          struct frame_info *frame,
5433                          int regnum,
5434                          enum lval_type *lvalp)
5435 {
5436   CORE_ADDR addrx;
5437   enum lval_type lvalx;
5438   int optimizedx;
5439
5440   if (!target_has_registers)
5441     error ("No registers.");
5442
5443   /* Make certain that all needed parameters are present.  */
5444   if (addrp == NULL)
5445     addrp = &addrx;
5446   if (lvalp == NULL)
5447     lvalp = &lvalx;
5448   if (optimizedp == NULL)
5449     optimizedp = &optimizedx;
5450   deprecated_unwind_get_saved_register (raw_buffer, optimizedp, addrp, frame,
5451                                         regnum, lvalp);
5452   /* FIXME: cagney/2002-09-13: This is just so bad.  The MIPS should
5453      have a pseudo register range that correspons to the ABI's, rather
5454      than the ISA's, view of registers.  These registers would then
5455      implicitly describe their size and hence could be used without
5456      the below munging.  */
5457   if ((*lvalp) == lval_memory)
5458     {
5459       if (raw_buffer != NULL)
5460         {
5461           if (regnum < 32)
5462             {
5463               /* Only MIPS_SAVED_REGSIZE bytes of GP registers are
5464                  saved. */
5465               LONGEST val = read_memory_integer ((*addrp), MIPS_SAVED_REGSIZE);
5466               store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), val);
5467             }
5468         }
5469     }
5470 }
5471
5472 /* Immediately after a function call, return the saved pc.
5473    Can't always go through the frames for this because on some machines
5474    the new frame is not set up until the new function executes
5475    some instructions.  */
5476
5477 static CORE_ADDR
5478 mips_saved_pc_after_call (struct frame_info *frame)
5479 {
5480   return read_signed_register (RA_REGNUM);
5481 }
5482
5483
5484 /* Convert a dbx stab register number (from `r' declaration) to a gdb
5485    REGNUM */
5486
5487 static int
5488 mips_stab_reg_to_regnum (int num)
5489 {
5490   if (num >= 0 && num < 32)
5491     return num;
5492   else if (num >= 38 && num < 70)
5493     return num + FP0_REGNUM - 38;
5494   else if (num == 70)
5495     return HI_REGNUM;
5496   else if (num == 71)
5497     return LO_REGNUM;
5498   else
5499     {
5500       /* This will hopefully (eventually) provoke a warning.  Should
5501          we be calling complaint() here?  */
5502       return NUM_REGS + NUM_PSEUDO_REGS;
5503     }
5504 }
5505
5506
5507 /* Convert a dwarf, dwarf2, or ecoff register number to a gdb REGNUM */
5508
5509 static int
5510 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5511 {
5512   if (num >= 0 && num < 32)
5513     return num;
5514   else if (num >= 32 && num < 64)
5515     return num + FP0_REGNUM - 32;
5516   else if (num == 64)
5517     return HI_REGNUM;
5518   else if (num == 65)
5519     return LO_REGNUM;
5520   else
5521     {
5522       /* This will hopefully (eventually) provoke a warning.  Should
5523          we be calling complaint() here?  */
5524       return NUM_REGS + NUM_PSEUDO_REGS;
5525     }
5526 }
5527
5528
5529 /* Convert an integer into an address.  By first converting the value
5530    into a pointer and then extracting it signed, the address is
5531    guarenteed to be correctly sign extended.  */
5532
5533 static CORE_ADDR
5534 mips_integer_to_address (struct type *type, void *buf)
5535 {
5536   char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5537   LONGEST val = unpack_long (type, buf);
5538   store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5539   return extract_signed_integer (tmp,
5540                                  TYPE_LENGTH (builtin_type_void_data_ptr));
5541 }
5542
5543 static void
5544 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5545 {
5546   enum mips_abi *abip = (enum mips_abi *) obj;
5547   const char *name = bfd_get_section_name (abfd, sect);
5548
5549   if (*abip != MIPS_ABI_UNKNOWN)
5550     return;
5551
5552   if (strncmp (name, ".mdebug.", 8) != 0)
5553     return;
5554
5555   if (strcmp (name, ".mdebug.abi32") == 0)
5556     *abip = MIPS_ABI_O32;
5557   else if (strcmp (name, ".mdebug.abiN32") == 0)
5558     *abip = MIPS_ABI_N32;
5559   else if (strcmp (name, ".mdebug.abi64") == 0)
5560     *abip = MIPS_ABI_N64;
5561   else if (strcmp (name, ".mdebug.abiO64") == 0)
5562     *abip = MIPS_ABI_O64;
5563   else if (strcmp (name, ".mdebug.eabi32") == 0)
5564     *abip = MIPS_ABI_EABI32;
5565   else if (strcmp (name, ".mdebug.eabi64") == 0)
5566     *abip = MIPS_ABI_EABI64;
5567   else
5568     warning ("unsupported ABI %s.", name + 8);
5569 }
5570
5571 static enum mips_abi
5572 global_mips_abi (void)
5573 {
5574   int i;
5575
5576   for (i = 0; mips_abi_strings[i] != NULL; i++)
5577     if (mips_abi_strings[i] == mips_abi_string)
5578       return (enum mips_abi) i;
5579
5580   internal_error (__FILE__, __LINE__,
5581                   "unknown ABI string");
5582 }
5583
5584 static struct gdbarch *
5585 mips_gdbarch_init (struct gdbarch_info info,
5586                    struct gdbarch_list *arches)
5587 {
5588   struct gdbarch *gdbarch;
5589   struct gdbarch_tdep *tdep;
5590   int elf_flags;
5591   enum mips_abi mips_abi, found_abi, wanted_abi;
5592
5593   /* Reset the disassembly info, in case it was set to something
5594      non-default.  */
5595   deprecated_tm_print_insn_info.flavour = bfd_target_unknown_flavour;
5596   deprecated_tm_print_insn_info.arch = bfd_arch_unknown;
5597   deprecated_tm_print_insn_info.mach = 0;
5598
5599   elf_flags = 0;
5600
5601   if (info.abfd)
5602     {
5603       /* First of all, extract the elf_flags, if available.  */
5604       if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5605         elf_flags = elf_elfheader (info.abfd)->e_flags;
5606     }
5607
5608   /* Check ELF_FLAGS to see if it specifies the ABI being used.  */
5609   switch ((elf_flags & EF_MIPS_ABI))
5610     {
5611     case E_MIPS_ABI_O32:
5612       mips_abi = MIPS_ABI_O32;
5613       break;
5614     case E_MIPS_ABI_O64:
5615       mips_abi = MIPS_ABI_O64;
5616       break;
5617     case E_MIPS_ABI_EABI32:
5618       mips_abi = MIPS_ABI_EABI32;
5619       break;
5620     case E_MIPS_ABI_EABI64:
5621       mips_abi = MIPS_ABI_EABI64;
5622       break;
5623     default:
5624       if ((elf_flags & EF_MIPS_ABI2))
5625         mips_abi = MIPS_ABI_N32;
5626       else
5627         mips_abi = MIPS_ABI_UNKNOWN;
5628       break;
5629     }
5630
5631   /* GCC creates a pseudo-section whose name describes the ABI.  */
5632   if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5633     bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi);
5634
5635   /* If we have no bfd, then mips_abi will still be MIPS_ABI_UNKNOWN.
5636      Use the ABI from the last architecture if there is one.  */
5637   if (info.abfd == NULL && arches != NULL)
5638     mips_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5639
5640   /* Try the architecture for any hint of the correct ABI.  */
5641   if (mips_abi == MIPS_ABI_UNKNOWN
5642       && info.bfd_arch_info != NULL
5643       && info.bfd_arch_info->arch == bfd_arch_mips)
5644     {
5645       switch (info.bfd_arch_info->mach)
5646         {
5647         case bfd_mach_mips3900:
5648           mips_abi = MIPS_ABI_EABI32;
5649           break;
5650         case bfd_mach_mips4100:
5651         case bfd_mach_mips5000:
5652           mips_abi = MIPS_ABI_EABI64;
5653           break;
5654         case bfd_mach_mips8000:
5655         case bfd_mach_mips10000:
5656           /* On Irix, ELF64 executables use the N64 ABI.  The
5657              pseudo-sections which describe the ABI aren't present
5658              on IRIX.  (Even for executables created by gcc.)  */
5659           if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5660               && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5661             mips_abi = MIPS_ABI_N64;
5662           else
5663             mips_abi = MIPS_ABI_N32;
5664           break;
5665         }
5666     }
5667
5668   if (mips_abi == MIPS_ABI_UNKNOWN)
5669     mips_abi = MIPS_ABI_O32;
5670
5671   /* Now that we have found what the ABI for this binary would be,
5672      check whether the user is overriding it.  */
5673   found_abi = mips_abi;
5674   wanted_abi = global_mips_abi ();
5675   if (wanted_abi != MIPS_ABI_UNKNOWN)
5676     mips_abi = wanted_abi;
5677
5678   /* We have to set deprecated_tm_print_insn_info before looking for a
5679      pre-existing architecture, otherwise we may return before we get
5680      a chance to set it up.  */
5681   if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5682     {
5683       /* Set up the disassembler info, so that we get the right
5684          register names from libopcodes.  */
5685       if (mips_abi == MIPS_ABI_N32)
5686         deprecated_tm_print_insn_info.disassembler_options = "gpr-names=n32";
5687       else
5688         deprecated_tm_print_insn_info.disassembler_options = "gpr-names=64";
5689       deprecated_tm_print_insn_info.flavour = bfd_target_elf_flavour;
5690       deprecated_tm_print_insn_info.arch = bfd_arch_mips;
5691       if (info.bfd_arch_info != NULL
5692           && info.bfd_arch_info->arch == bfd_arch_mips
5693           && info.bfd_arch_info->mach)
5694         deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
5695       else
5696         deprecated_tm_print_insn_info.mach = bfd_mach_mips8000;
5697     }
5698   else
5699     /* This string is not recognized explicitly by the disassembler,
5700        but it tells the disassembler to not try to guess the ABI from
5701        the bfd elf headers, such that, if the user overrides the ABI
5702        of a program linked as NewABI, the disassembly will follow the
5703        register naming conventions specified by the user.  */
5704     deprecated_tm_print_insn_info.disassembler_options = "gpr-names=32";
5705
5706   if (gdbarch_debug)
5707     {
5708       fprintf_unfiltered (gdb_stdlog,
5709                           "mips_gdbarch_init: elf_flags = 0x%08x\n",
5710                           elf_flags);
5711       fprintf_unfiltered (gdb_stdlog,
5712                           "mips_gdbarch_init: mips_abi = %d\n",
5713                           mips_abi);
5714       fprintf_unfiltered (gdb_stdlog,
5715                           "mips_gdbarch_init: found_mips_abi = %d\n",
5716                           found_abi);
5717     }
5718
5719   /* try to find a pre-existing architecture */
5720   for (arches = gdbarch_list_lookup_by_info (arches, &info);
5721        arches != NULL;
5722        arches = gdbarch_list_lookup_by_info (arches->next, &info))
5723     {
5724       /* MIPS needs to be pedantic about which ABI the object is
5725          using.  */
5726       if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5727         continue;
5728       if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5729         continue;
5730       return arches->gdbarch;
5731     }
5732
5733   /* Need a new architecture.  Fill in a target specific vector.  */
5734   tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5735   gdbarch = gdbarch_alloc (&info, tdep);
5736   tdep->elf_flags = elf_flags;
5737
5738   /* Initially set everything according to the default ABI/ISA.  */
5739   set_gdbarch_short_bit (gdbarch, 16);
5740   set_gdbarch_int_bit (gdbarch, 32);
5741   set_gdbarch_float_bit (gdbarch, 32);
5742   set_gdbarch_double_bit (gdbarch, 64);
5743   set_gdbarch_long_double_bit (gdbarch, 64);
5744   set_gdbarch_deprecated_register_raw_size (gdbarch, mips_register_raw_size);
5745   tdep->found_abi = found_abi;
5746   tdep->mips_abi = mips_abi;
5747
5748   set_gdbarch_elf_make_msymbol_special (gdbarch, 
5749                                         mips_elf_make_msymbol_special);
5750
5751   if (info.osabi == GDB_OSABI_IRIX)
5752     set_gdbarch_num_regs (gdbarch, 71);
5753   else
5754     set_gdbarch_num_regs (gdbarch, 90);
5755
5756   switch (mips_abi)
5757     {
5758     case MIPS_ABI_O32:
5759       set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
5760       set_gdbarch_deprecated_store_return_value (gdbarch, mips_o32_store_return_value);
5761       set_gdbarch_extract_return_value (gdbarch, mips_o32_extract_return_value);
5762       tdep->mips_default_saved_regsize = 4;
5763       tdep->mips_default_stack_argsize = 4;
5764       tdep->mips_fp_register_double = 0;
5765       tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5766       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5767       tdep->gdb_target_is_mips64 = 0;
5768       tdep->default_mask_address_p = 0;
5769       set_gdbarch_long_bit (gdbarch, 32);
5770       set_gdbarch_ptr_bit (gdbarch, 32);
5771       set_gdbarch_long_long_bit (gdbarch, 64);
5772       set_gdbarch_reg_struct_has_addr (gdbarch, 
5773                                        mips_o32_reg_struct_has_addr);
5774       set_gdbarch_use_struct_convention (gdbarch, 
5775                                          always_use_struct_convention);
5776       break;
5777     case MIPS_ABI_O64:
5778       set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
5779       set_gdbarch_deprecated_store_return_value (gdbarch, mips_o64_store_return_value);
5780       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_o64_extract_return_value);
5781       tdep->mips_default_saved_regsize = 8;
5782       tdep->mips_default_stack_argsize = 8;
5783       tdep->mips_fp_register_double = 1;
5784       tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
5785       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1;
5786       tdep->gdb_target_is_mips64 = 1;
5787       tdep->default_mask_address_p = 0;
5788       set_gdbarch_long_bit (gdbarch, 32);
5789       set_gdbarch_ptr_bit (gdbarch, 32);
5790       set_gdbarch_long_long_bit (gdbarch, 64);
5791       set_gdbarch_reg_struct_has_addr (gdbarch, 
5792                                        mips_o32_reg_struct_has_addr);
5793       set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
5794       break;
5795     case MIPS_ABI_EABI32:
5796       set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5797       set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5798       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5799       tdep->mips_default_saved_regsize = 4;
5800       tdep->mips_default_stack_argsize = 4;
5801       tdep->mips_fp_register_double = 0;
5802       tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5803       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5804       tdep->gdb_target_is_mips64 = 0;
5805       tdep->default_mask_address_p = 0;
5806       set_gdbarch_long_bit (gdbarch, 32);
5807       set_gdbarch_ptr_bit (gdbarch, 32);
5808       set_gdbarch_long_long_bit (gdbarch, 64);
5809       set_gdbarch_reg_struct_has_addr (gdbarch, 
5810                                        mips_eabi_reg_struct_has_addr);
5811       set_gdbarch_use_struct_convention (gdbarch, 
5812                                          mips_eabi_use_struct_convention);
5813       break;
5814     case MIPS_ABI_EABI64:
5815       set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
5816       set_gdbarch_deprecated_store_return_value (gdbarch, mips_eabi_store_return_value);
5817       set_gdbarch_deprecated_extract_return_value (gdbarch, mips_eabi_extract_return_value);
5818       tdep->mips_default_saved_regsize = 8;
5819       tdep->mips_default_stack_argsize = 8;
5820       tdep->mips_fp_register_double = 1;
5821       tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5822       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5823       tdep->gdb_target_is_mips64 = 1;
5824       tdep->default_mask_address_p = 0;
5825       set_gdbarch_long_bit (gdbarch, 64);
5826       set_gdbarch_ptr_bit (gdbarch, 64);
5827       set_gdbarch_long_long_bit (gdbarch, 64);
5828       set_gdbarch_reg_struct_has_addr (gdbarch, 
5829                                        mips_eabi_reg_struct_has_addr);
5830       set_gdbarch_use_struct_convention (gdbarch, 
5831                                          mips_eabi_use_struct_convention);
5832       break;
5833     case MIPS_ABI_N32:
5834       set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5835       set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5836       set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5837       tdep->mips_default_saved_regsize = 8;
5838       tdep->mips_default_stack_argsize = 8;
5839       tdep->mips_fp_register_double = 1;
5840       tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5841       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5842       tdep->gdb_target_is_mips64 = 1;
5843       tdep->default_mask_address_p = 0;
5844       set_gdbarch_long_bit (gdbarch, 32);
5845       set_gdbarch_ptr_bit (gdbarch, 32);
5846       set_gdbarch_long_long_bit (gdbarch, 64);
5847       set_gdbarch_use_struct_convention (gdbarch, 
5848                                          mips_n32n64_use_struct_convention);
5849       set_gdbarch_reg_struct_has_addr (gdbarch, 
5850                                        mips_n32n64_reg_struct_has_addr);
5851       break;
5852     case MIPS_ABI_N64:
5853       set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
5854       set_gdbarch_deprecated_store_return_value (gdbarch, mips_n32n64_store_return_value);
5855       set_gdbarch_extract_return_value (gdbarch, mips_n32n64_extract_return_value);
5856       tdep->mips_default_saved_regsize = 8;
5857       tdep->mips_default_stack_argsize = 8;
5858       tdep->mips_fp_register_double = 1;
5859       tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
5860       tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1;
5861       tdep->gdb_target_is_mips64 = 1;
5862       tdep->default_mask_address_p = 0;
5863       set_gdbarch_long_bit (gdbarch, 64);
5864       set_gdbarch_ptr_bit (gdbarch, 64);
5865       set_gdbarch_long_long_bit (gdbarch, 64);
5866       set_gdbarch_use_struct_convention (gdbarch, 
5867                                          mips_n32n64_use_struct_convention);
5868       set_gdbarch_reg_struct_has_addr (gdbarch, 
5869                                        mips_n32n64_reg_struct_has_addr);
5870       break;
5871     default:
5872       internal_error (__FILE__, __LINE__,
5873                       "unknown ABI in switch");
5874     }
5875
5876   /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5877      that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5878      comment:
5879
5880      ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5881      flag in object files because to do so would make it impossible to
5882      link with libraries compiled without "-gp32".  This is
5883      unnecessarily restrictive.
5884
5885      We could solve this problem by adding "-gp32" multilibs to gcc,
5886      but to set this flag before gcc is built with such multilibs will
5887      break too many systems.''
5888
5889      But even more unhelpfully, the default linker output target for
5890      mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5891      for 64-bit programs - you need to change the ABI to change this,
5892      and not all gcc targets support that currently.  Therefore using
5893      this flag to detect 32-bit mode would do the wrong thing given
5894      the current gcc - it would make GDB treat these 64-bit programs
5895      as 32-bit programs by default.  */
5896
5897   /* enable/disable the MIPS FPU */
5898   if (!mips_fpu_type_auto)
5899     tdep->mips_fpu_type = mips_fpu_type;
5900   else if (info.bfd_arch_info != NULL
5901            && info.bfd_arch_info->arch == bfd_arch_mips)
5902     switch (info.bfd_arch_info->mach)
5903       {
5904       case bfd_mach_mips3900:
5905       case bfd_mach_mips4100:
5906       case bfd_mach_mips4111:
5907         tdep->mips_fpu_type = MIPS_FPU_NONE;
5908         break;
5909       case bfd_mach_mips4650:
5910         tdep->mips_fpu_type = MIPS_FPU_SINGLE;
5911         break;
5912       default:
5913         tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5914         break;
5915       }
5916   else
5917     tdep->mips_fpu_type = MIPS_FPU_DOUBLE;
5918
5919   /* MIPS version of register names.  NOTE: At present the MIPS
5920      register name management is part way between the old -
5921      #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr).
5922      Further work on it is required.  */
5923   /* NOTE: many targets (esp. embedded) do not go thru the
5924      gdbarch_register_name vector at all, instead bypassing it
5925      by defining REGISTER_NAMES.  */
5926   set_gdbarch_register_name (gdbarch, mips_register_name);
5927   set_gdbarch_read_pc (gdbarch, mips_read_pc);
5928   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
5929   set_gdbarch_deprecated_target_read_fp (gdbarch, mips_read_sp); /* Draft FRAME base.  */
5930   set_gdbarch_read_sp (gdbarch, mips_read_sp);
5931
5932   /* Add/remove bits from an address.  The MIPS needs be careful to
5933      ensure that all 32 bit addresses are sign extended to 64 bits.  */
5934   set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5935
5936   /* There's a mess in stack frame creation.  See comments in
5937      blockframe.c near reference to DEPRECATED_INIT_FRAME_PC_FIRST.  */
5938   set_gdbarch_deprecated_init_frame_pc_first (gdbarch, mips_init_frame_pc_first);
5939   set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
5940
5941   /* Map debug register numbers onto internal register numbers.  */
5942   set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
5943   set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5944   set_gdbarch_dwarf_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5945   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5946
5947   /* Initialize a frame */
5948   set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mips_find_saved_regs);
5949   set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mips_init_extra_frame_info);
5950
5951   /* MIPS version of CALL_DUMMY */
5952
5953   set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address);
5954   set_gdbarch_deprecated_pop_frame (gdbarch, mips_pop_frame);
5955   set_gdbarch_frame_align (gdbarch, mips_frame_align);
5956   set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
5957   set_gdbarch_deprecated_register_convertible (gdbarch, mips_register_convertible);
5958   set_gdbarch_deprecated_register_convert_to_virtual (gdbarch, mips_register_convert_to_virtual);
5959   set_gdbarch_deprecated_register_convert_to_raw (gdbarch, mips_register_convert_to_raw);
5960
5961   set_gdbarch_deprecated_frame_chain (gdbarch, mips_frame_chain);
5962   set_gdbarch_frameless_function_invocation (gdbarch, 
5963                                              generic_frameless_function_invocation_not);
5964   set_gdbarch_deprecated_frame_saved_pc (gdbarch, mips_frame_saved_pc);
5965   set_gdbarch_frame_args_skip (gdbarch, 0);
5966
5967   set_gdbarch_deprecated_get_saved_register (gdbarch, mips_get_saved_register);
5968
5969   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5970   set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
5971   set_gdbarch_decr_pc_after_break (gdbarch, 0);
5972
5973   set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
5974   set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mips_saved_pc_after_call);
5975
5976   set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5977   set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5978   set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
5979
5980   set_gdbarch_function_start_offset (gdbarch, 0);
5981
5982   /* There are MIPS targets which do not yet use this since they still
5983      define REGISTER_VIRTUAL_TYPE.  */
5984   set_gdbarch_deprecated_register_virtual_type (gdbarch, mips_register_virtual_type);
5985
5986   set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
5987   set_gdbarch_pc_in_sigtramp (gdbarch, mips_pc_in_sigtramp);
5988
5989   /* Hook in OS ABI-specific overrides, if they have been registered.  */
5990   gdbarch_init_osabi (info, gdbarch);
5991
5992   set_gdbarch_extract_struct_value_address (gdbarch, 
5993                                             mips_extract_struct_value_address);
5994   
5995   set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
5996
5997   set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
5998   set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
5999
6000   return gdbarch;
6001 }
6002
6003 static void
6004 mips_abi_update (char *ignore_args, int from_tty, 
6005                  struct cmd_list_element *c)
6006 {
6007   struct gdbarch_info info;
6008
6009   /* Force the architecture to update, and (if it's a MIPS architecture)
6010      mips_gdbarch_init will take care of the rest.  */
6011   gdbarch_info_init (&info);
6012   gdbarch_update_p (info);
6013 }
6014
6015 /* Print out which MIPS ABI is in use.  */
6016
6017 static void
6018 show_mips_abi (char *ignore_args, int from_tty)
6019 {
6020   if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6021     printf_filtered (
6022       "The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6023   else
6024     {
6025       enum mips_abi global_abi = global_mips_abi ();
6026       enum mips_abi actual_abi = mips_abi (current_gdbarch);
6027       const char *actual_abi_str = mips_abi_strings[actual_abi];
6028
6029       if (global_abi == MIPS_ABI_UNKNOWN)
6030         printf_filtered ("The MIPS ABI is set automatically (currently \"%s\").\n",
6031                          actual_abi_str);
6032       else if (global_abi == actual_abi)
6033         printf_filtered (
6034           "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6035           actual_abi_str);
6036       else
6037         {
6038           /* Probably shouldn't happen...  */
6039           printf_filtered (
6040             "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6041             actual_abi_str,
6042             mips_abi_strings[global_abi]);
6043         }
6044     }
6045 }
6046
6047 static void
6048 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6049 {
6050   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6051   if (tdep != NULL)
6052     {
6053       int ef_mips_arch;
6054       int ef_mips_32bitmode;
6055       /* determine the ISA */
6056       switch (tdep->elf_flags & EF_MIPS_ARCH)
6057         {
6058         case E_MIPS_ARCH_1:
6059           ef_mips_arch = 1;
6060           break;
6061         case E_MIPS_ARCH_2:
6062           ef_mips_arch = 2;
6063           break;
6064         case E_MIPS_ARCH_3:
6065           ef_mips_arch = 3;
6066           break;
6067         case E_MIPS_ARCH_4:
6068           ef_mips_arch = 4;
6069           break;
6070         default:
6071           ef_mips_arch = 0;
6072           break;
6073         }
6074       /* determine the size of a pointer */
6075       ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6076       fprintf_unfiltered (file,
6077                           "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6078                           tdep->elf_flags);
6079       fprintf_unfiltered (file,
6080                           "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6081                           ef_mips_32bitmode);
6082       fprintf_unfiltered (file,
6083                           "mips_dump_tdep: ef_mips_arch = %d\n",
6084                           ef_mips_arch);
6085       fprintf_unfiltered (file,
6086                           "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6087                           tdep->mips_abi,
6088                           mips_abi_strings[tdep->mips_abi]);
6089       fprintf_unfiltered (file,
6090                           "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6091                           mips_mask_address_p (),
6092                           tdep->default_mask_address_p);
6093     }
6094   fprintf_unfiltered (file,
6095                       "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6096                       FP_REGISTER_DOUBLE);
6097   fprintf_unfiltered (file,
6098                       "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6099                       MIPS_DEFAULT_FPU_TYPE,
6100                       (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6101                        : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6102                        : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6103                        : "???"));
6104   fprintf_unfiltered (file,
6105                       "mips_dump_tdep: MIPS_EABI = %d\n",
6106                       MIPS_EABI);
6107   fprintf_unfiltered (file,
6108                       "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n",
6109                       MIPS_LAST_FP_ARG_REGNUM,
6110                       MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1);
6111   fprintf_unfiltered (file,
6112                       "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6113                       MIPS_FPU_TYPE,
6114                       (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6115                        : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6116                        : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6117                        : "???"));
6118   fprintf_unfiltered (file,
6119                       "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n",
6120                       MIPS_DEFAULT_SAVED_REGSIZE);
6121   fprintf_unfiltered (file,
6122                       "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n",
6123                       FP_REGISTER_DOUBLE);
6124   fprintf_unfiltered (file,
6125                       "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n",
6126                       MIPS_DEFAULT_STACK_ARGSIZE);
6127   fprintf_unfiltered (file,
6128                       "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n",
6129                       MIPS_STACK_ARGSIZE);
6130   fprintf_unfiltered (file,
6131                       "mips_dump_tdep: MIPS_REGSIZE = %d\n",
6132                       MIPS_REGSIZE);
6133   fprintf_unfiltered (file,
6134                       "mips_dump_tdep: A0_REGNUM = %d\n",
6135                       A0_REGNUM);
6136   fprintf_unfiltered (file,
6137                       "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6138                       XSTRING (ADDR_BITS_REMOVE(ADDR)));
6139   fprintf_unfiltered (file,
6140                       "mips_dump_tdep: ATTACH_DETACH # %s\n",
6141                       XSTRING (ATTACH_DETACH));
6142   fprintf_unfiltered (file,
6143                       "mips_dump_tdep: BADVADDR_REGNUM = %d\n",
6144                       BADVADDR_REGNUM);
6145   fprintf_unfiltered (file,
6146                       "mips_dump_tdep: CAUSE_REGNUM = %d\n",
6147                       CAUSE_REGNUM);
6148   fprintf_unfiltered (file,
6149                       "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6150                       XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6151   fprintf_unfiltered (file,
6152                       "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6153                       XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6154   fprintf_unfiltered (file,
6155                       "mips_dump_tdep: FCRCS_REGNUM = %d\n",
6156                       FCRCS_REGNUM);
6157   fprintf_unfiltered (file,
6158                       "mips_dump_tdep: FCRIR_REGNUM = %d\n",
6159                       FCRIR_REGNUM);
6160   fprintf_unfiltered (file,
6161                       "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6162                       FIRST_EMBED_REGNUM);
6163   fprintf_unfiltered (file,
6164                       "mips_dump_tdep: FPA0_REGNUM = %d\n",
6165                       FPA0_REGNUM);
6166   fprintf_unfiltered (file,
6167                       "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n",
6168                       GDB_TARGET_IS_MIPS64);
6169   fprintf_unfiltered (file,
6170                       "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n",
6171                       XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT));
6172   fprintf_unfiltered (file,
6173                       "mips_dump_tdep:  HI_REGNUM = %d\n",
6174                       HI_REGNUM);
6175   fprintf_unfiltered (file,
6176                       "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n",
6177                       XSTRING (IGNORE_HELPER_CALL (PC)));
6178   fprintf_unfiltered (file,
6179                       "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6180                       XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6181   fprintf_unfiltered (file,
6182                       "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6183                       XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6184   fprintf_unfiltered (file,
6185                       "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6186                       LAST_EMBED_REGNUM);
6187   fprintf_unfiltered (file,
6188                       "mips_dump_tdep: LO_REGNUM = %d\n",
6189                       LO_REGNUM);
6190 #ifdef MACHINE_CPROC_FP_OFFSET
6191   fprintf_unfiltered (file,
6192                       "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6193                       MACHINE_CPROC_FP_OFFSET);
6194 #endif
6195 #ifdef MACHINE_CPROC_PC_OFFSET
6196   fprintf_unfiltered (file,
6197                       "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6198                       MACHINE_CPROC_PC_OFFSET);
6199 #endif
6200 #ifdef MACHINE_CPROC_SP_OFFSET
6201   fprintf_unfiltered (file,
6202                       "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6203                       MACHINE_CPROC_SP_OFFSET);
6204 #endif
6205   fprintf_unfiltered (file,
6206                       "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6207                       MIPS16_INSTLEN);
6208   fprintf_unfiltered (file,
6209                       "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6210   fprintf_unfiltered (file,
6211                       "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6212   fprintf_unfiltered (file,
6213                       "mips_dump_tdep: MIPS_INSTLEN = %d\n",
6214                       MIPS_INSTLEN);
6215   fprintf_unfiltered (file,
6216                       "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6217                       MIPS_LAST_ARG_REGNUM,
6218                       MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6219   fprintf_unfiltered (file,
6220                       "mips_dump_tdep: MIPS_NUMREGS = %d\n",
6221                       MIPS_NUMREGS);
6222   fprintf_unfiltered (file,
6223                       "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n");
6224   fprintf_unfiltered (file,
6225                       "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n",
6226                       MIPS_SAVED_REGSIZE);
6227   fprintf_unfiltered (file,
6228                       "mips_dump_tdep: OP_LDFPR = used?\n");
6229   fprintf_unfiltered (file,
6230                       "mips_dump_tdep: OP_LDGPR = used?\n");
6231   fprintf_unfiltered (file,
6232                       "mips_dump_tdep: PRID_REGNUM = %d\n",
6233                       PRID_REGNUM);
6234   fprintf_unfiltered (file,
6235                       "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n",
6236                       XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME)));
6237   fprintf_unfiltered (file,
6238                       "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n");
6239   fprintf_unfiltered (file,
6240                       "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6241   fprintf_unfiltered (file,
6242                       "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6243   fprintf_unfiltered (file,
6244                       "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6245   fprintf_unfiltered (file,
6246                       "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6247   fprintf_unfiltered (file,
6248                       "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6249   fprintf_unfiltered (file,
6250                       "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6251   fprintf_unfiltered (file,
6252                       "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6253   fprintf_unfiltered (file,
6254                       "mips_dump_tdep: PROC_PC_REG = function?\n");
6255   fprintf_unfiltered (file,
6256                       "mips_dump_tdep: PROC_REG_MASK = function?\n");
6257   fprintf_unfiltered (file,
6258                       "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6259   fprintf_unfiltered (file,
6260                       "mips_dump_tdep: PROC_SYMBOL = function?\n");
6261   fprintf_unfiltered (file,
6262                       "mips_dump_tdep: PS_REGNUM = %d\n",
6263                       PS_REGNUM);
6264   fprintf_unfiltered (file,
6265                       "mips_dump_tdep: RA_REGNUM = %d\n",
6266                       RA_REGNUM);
6267   fprintf_unfiltered (file,
6268                       "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n",
6269                       XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6270   fprintf_unfiltered (file,
6271                       "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n",
6272                       XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER)));
6273   fprintf_unfiltered (file,
6274                       "mips_dump_tdep: REGISTER_NAMES = delete?\n");
6275   fprintf_unfiltered (file,
6276                       "mips_dump_tdep: ROUND_DOWN = function?\n");
6277   fprintf_unfiltered (file,
6278                       "mips_dump_tdep: ROUND_UP = function?\n");
6279 #ifdef SAVED_BYTES
6280   fprintf_unfiltered (file,
6281                       "mips_dump_tdep: SAVED_BYTES = %d\n",
6282                       SAVED_BYTES);
6283 #endif
6284 #ifdef SAVED_FP
6285   fprintf_unfiltered (file,
6286                       "mips_dump_tdep: SAVED_FP = %d\n",
6287                       SAVED_FP);
6288 #endif
6289 #ifdef SAVED_PC
6290   fprintf_unfiltered (file,
6291                       "mips_dump_tdep: SAVED_PC = %d\n",
6292                       SAVED_PC);
6293 #endif
6294   fprintf_unfiltered (file,
6295                       "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6296                       XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6297   fprintf_unfiltered (file,
6298                       "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n");
6299   fprintf_unfiltered (file,
6300                       "mips_dump_tdep: SIGFRAME_BASE = %d\n",
6301                       SIGFRAME_BASE);
6302   fprintf_unfiltered (file,
6303                       "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n",
6304                       SIGFRAME_FPREGSAVE_OFF);
6305   fprintf_unfiltered (file,
6306                       "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n",
6307                       SIGFRAME_PC_OFF);
6308   fprintf_unfiltered (file,
6309                       "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n",
6310                       SIGFRAME_REGSAVE_OFF);
6311   fprintf_unfiltered (file,
6312                       "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n",
6313                       SIGFRAME_REG_SIZE);
6314   fprintf_unfiltered (file,
6315                       "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6316                       XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6317   fprintf_unfiltered (file,
6318                       "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6319                       XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6320   fprintf_unfiltered (file,
6321                       "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6322                       SOFTWARE_SINGLE_STEP_P ());
6323   fprintf_unfiltered (file,
6324                       "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6325                       XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6326 #ifdef STACK_END_ADDR
6327   fprintf_unfiltered (file,
6328                       "mips_dump_tdep: STACK_END_ADDR = %d\n",
6329                       STACK_END_ADDR);
6330 #endif
6331   fprintf_unfiltered (file,
6332                       "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6333                       XSTRING (STEP_SKIPS_DELAY (PC)));
6334   fprintf_unfiltered (file,
6335                       "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6336                       STEP_SKIPS_DELAY_P);
6337   fprintf_unfiltered (file,
6338                       "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6339                       XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6340   fprintf_unfiltered (file,
6341                       "mips_dump_tdep: T9_REGNUM = %d\n",
6342                       T9_REGNUM);
6343   fprintf_unfiltered (file,
6344                       "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6345   fprintf_unfiltered (file,
6346                       "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6347                       XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE)));
6348   fprintf_unfiltered (file,
6349                       "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n",
6350                       XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS));
6351 #ifdef TRACE_CLEAR
6352   fprintf_unfiltered (file,
6353                       "mips_dump_tdep: TRACE_CLEAR # %s\n",
6354                       XSTRING (TRACE_CLEAR (THREAD, STATE)));
6355 #endif
6356 #ifdef TRACE_FLAVOR
6357   fprintf_unfiltered (file,
6358                       "mips_dump_tdep: TRACE_FLAVOR = %d\n",
6359                       TRACE_FLAVOR);
6360 #endif
6361 #ifdef TRACE_FLAVOR_SIZE
6362   fprintf_unfiltered (file,
6363                       "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6364                       TRACE_FLAVOR_SIZE);
6365 #endif
6366 #ifdef TRACE_SET
6367   fprintf_unfiltered (file,
6368                       "mips_dump_tdep: TRACE_SET # %s\n",
6369                       XSTRING (TRACE_SET (X,STATE)));
6370 #endif
6371 #ifdef UNUSED_REGNUM
6372   fprintf_unfiltered (file,
6373                       "mips_dump_tdep: UNUSED_REGNUM = %d\n",
6374                       UNUSED_REGNUM);
6375 #endif
6376   fprintf_unfiltered (file,
6377                       "mips_dump_tdep: V0_REGNUM = %d\n",
6378                       V0_REGNUM);
6379   fprintf_unfiltered (file,
6380                       "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6381                       (long) VM_MIN_ADDRESS);
6382 #ifdef VX_NUM_REGS
6383   fprintf_unfiltered (file,
6384                       "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n",
6385                       VX_NUM_REGS);
6386 #endif
6387   fprintf_unfiltered (file,
6388                       "mips_dump_tdep: ZERO_REGNUM = %d\n",
6389                       ZERO_REGNUM);
6390   fprintf_unfiltered (file,
6391                       "mips_dump_tdep: _PROC_MAGIC_ = %d\n",
6392                       _PROC_MAGIC_);
6393 }
6394
6395 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6396
6397 void
6398 _initialize_mips_tdep (void)
6399 {
6400   static struct cmd_list_element *mipsfpulist = NULL;
6401   struct cmd_list_element *c;
6402
6403   mips_abi_string = mips_abi_strings [MIPS_ABI_UNKNOWN];
6404   if (MIPS_ABI_LAST + 1
6405       != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6406     internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6407
6408   gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6409   if (!deprecated_tm_print_insn)         /* Someone may have already set it */
6410     deprecated_tm_print_insn = gdb_print_insn_mips;
6411
6412   /* Add root prefix command for all "set mips"/"show mips" commands */
6413   add_prefix_cmd ("mips", no_class, set_mips_command,
6414                   "Various MIPS specific commands.",
6415                   &setmipscmdlist, "set mips ", 0, &setlist);
6416
6417   add_prefix_cmd ("mips", no_class, show_mips_command,
6418                   "Various MIPS specific commands.",
6419                   &showmipscmdlist, "show mips ", 0, &showlist);
6420
6421   /* Allow the user to override the saved register size. */
6422   add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6423                                        class_obscure,
6424                                        size_enums,
6425                                        &mips_saved_regsize_string, "\
6426 Set size of general purpose registers saved on the stack.\n\
6427 This option can be set to one of:\n\
6428   32    - Force GDB to treat saved GP registers as 32-bit\n\
6429   64    - Force GDB to treat saved GP registers as 64-bit\n\
6430   auto  - Allow GDB to use the target's default setting or autodetect the\n\
6431           saved GP register size from information contained in the executable.\n\
6432           (default: auto)",
6433                                        &setmipscmdlist),
6434                      &showmipscmdlist);
6435
6436   /* Allow the user to override the argument stack size. */
6437   add_show_from_set (add_set_enum_cmd ("stack-arg-size",
6438                                        class_obscure,
6439                                        size_enums,
6440                                        &mips_stack_argsize_string, "\
6441 Set the amount of stack space reserved for each argument.\n\
6442 This option can be set to one of:\n\
6443   32    - Force GDB to allocate 32-bit chunks per argument\n\
6444   64    - Force GDB to allocate 64-bit chunks per argument\n\
6445   auto  - Allow GDB to determine the correct setting from the current\n\
6446           target and executable (default)",
6447                                        &setmipscmdlist),
6448                      &showmipscmdlist);
6449
6450   /* Allow the user to override the ABI. */
6451   c = add_set_enum_cmd
6452     ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6453      "Set the ABI used by this program.\n"
6454      "This option can be set to one of:\n"
6455      "  auto  - the default ABI associated with the current binary\n"
6456      "  o32\n"
6457      "  o64\n"
6458      "  n32\n"
6459      "  n64\n"
6460      "  eabi32\n"
6461      "  eabi64",
6462      &setmipscmdlist);
6463   set_cmd_sfunc (c, mips_abi_update);
6464   add_cmd ("abi", class_obscure, show_mips_abi,
6465            "Show ABI in use by MIPS target", &showmipscmdlist);
6466
6467   /* Let the user turn off floating point and set the fence post for
6468      heuristic_proc_start.  */
6469
6470   add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6471                   "Set use of MIPS floating-point coprocessor.",
6472                   &mipsfpulist, "set mipsfpu ", 0, &setlist);
6473   add_cmd ("single", class_support, set_mipsfpu_single_command,
6474            "Select single-precision MIPS floating-point coprocessor.",
6475            &mipsfpulist);
6476   add_cmd ("double", class_support, set_mipsfpu_double_command,
6477            "Select double-precision MIPS floating-point coprocessor.",
6478            &mipsfpulist);
6479   add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6480   add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6481   add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6482   add_cmd ("none", class_support, set_mipsfpu_none_command,
6483            "Select no MIPS floating-point coprocessor.",
6484            &mipsfpulist);
6485   add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6486   add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6487   add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6488   add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6489            "Select MIPS floating-point coprocessor automatically.",
6490            &mipsfpulist);
6491   add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6492            "Show current use of MIPS floating-point coprocessor target.",
6493            &showlist);
6494
6495   /* We really would like to have both "0" and "unlimited" work, but
6496      command.c doesn't deal with that.  So make it a var_zinteger
6497      because the user can always use "999999" or some such for unlimited.  */
6498   c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6499                    (char *) &heuristic_fence_post,
6500                    "\
6501 Set the distance searched for the start of a function.\n\
6502 If you are debugging a stripped executable, GDB needs to search through the\n\
6503 program for the start of a function.  This command sets the distance of the\n\
6504 search.  The only need to set it is when debugging a stripped executable.",
6505                    &setlist);
6506   /* We need to throw away the frame cache when we set this, since it
6507      might change our ability to get backtraces.  */
6508   set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6509   add_show_from_set (c, &showlist);
6510
6511   /* Allow the user to control whether the upper bits of 64-bit
6512      addresses should be zeroed.  */
6513   add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6514 Set zeroing of upper 32 bits of 64-bit addresses.\n\
6515 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6516 allow GDB to determine the correct value.\n", "\
6517 Show zeroing of upper 32 bits of 64-bit addresses.",
6518                                 NULL, show_mask_address,
6519                                 &setmipscmdlist, &showmipscmdlist);
6520
6521   /* Allow the user to control the size of 32 bit registers within the
6522      raw remote packet.  */
6523   add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs",
6524                                   class_obscure,
6525                                   var_boolean,
6526                                   (char *)&mips64_transfers_32bit_regs_p, "\
6527 Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\
6528 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6529 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6530 64 bits for others.  Use \"off\" to disable compatibility mode",
6531                                   &setlist),
6532                      &showlist);
6533
6534   /* Debug this files internals. */
6535   add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger,
6536                                   &mips_debug, "Set mips debugging.\n\
6537 When non-zero, mips specific debugging is enabled.", &setdebuglist),
6538                      &showdebuglist);
6539 }
This page took 0.39983 seconds and 4 git commands to generate.