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