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