]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/mips-tdep.c
* mips-tdep.c (mips32_scan_prologue): Use the ABI register size
[thirdparty/binutils-gdb.git] / gdb / mips-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
bf64bfd6 2
6aba47ca 3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
9b254dd1 4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
47a35522 5 Free Software Foundation, Inc.
bf64bfd6 6
c906108c
SS
7 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
8 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
9
c5aa993b 10 This file is part of GDB.
c906108c 11
c5aa993b
JM
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
a9762ec7 14 the Free Software Foundation; either version 3 of the License, or
c5aa993b 15 (at your option) any later version.
c906108c 16
c5aa993b
JM
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
c906108c 21
c5aa993b 22 You should have received a copy of the GNU General Public License
a9762ec7 23 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
24
25#include "defs.h"
26#include "gdb_string.h"
5e2e9765 27#include "gdb_assert.h"
c906108c
SS
28#include "frame.h"
29#include "inferior.h"
30#include "symtab.h"
31#include "value.h"
32#include "gdbcmd.h"
33#include "language.h"
34#include "gdbcore.h"
35#include "symfile.h"
36#include "objfiles.h"
37#include "gdbtypes.h"
38#include "target.h"
28d069e6 39#include "arch-utils.h"
4e052eda 40#include "regcache.h"
70f80edf 41#include "osabi.h"
d1973055 42#include "mips-tdep.h"
fe898f56 43#include "block.h"
a4b8ebc8 44#include "reggroups.h"
c906108c 45#include "opcode/mips.h"
c2d11a7d
JM
46#include "elf/mips.h"
47#include "elf-bfd.h"
2475bac3 48#include "symcat.h"
a4b8ebc8 49#include "sim-regno.h"
a89aa300 50#include "dis-asm.h"
edfae063
AC
51#include "frame-unwind.h"
52#include "frame-base.h"
53#include "trad-frame.h"
7d9b040b 54#include "infcall.h"
fed7ba43 55#include "floatformat.h"
29709017
DJ
56#include "remote.h"
57#include "target-descriptions.h"
2bd0c3d7 58#include "dwarf2-frame.h"
f8b73d13 59#include "user-regs.h"
c906108c 60
8d5f9dcb
DJ
61static const struct objfile_data *mips_pdr_data;
62
5bbcb741 63static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum);
e0f7ec59 64
24e05951 65/* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
dd824b04
DJ
66/* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
67#define ST0_FR (1 << 26)
68
b0069a17
AC
69/* The sizes of floating point registers. */
70
71enum
72{
73 MIPS_FPU_SINGLE_REGSIZE = 4,
74 MIPS_FPU_DOUBLE_REGSIZE = 8
75};
76
1a69e1e4
DJ
77enum
78{
79 MIPS32_REGSIZE = 4,
80 MIPS64_REGSIZE = 8
81};
0dadbba0 82
2e4ebe70
DJ
83static const char *mips_abi_string;
84
85static const char *mips_abi_strings[] = {
86 "auto",
87 "n32",
88 "o32",
28d169de 89 "n64",
2e4ebe70
DJ
90 "o64",
91 "eabi32",
92 "eabi64",
93 NULL
94};
95
f8b73d13
DJ
96/* The standard register names, and all the valid aliases for them. */
97struct register_alias
98{
99 const char *name;
100 int regnum;
101};
102
103/* Aliases for o32 and most other ABIs. */
104const struct register_alias mips_o32_aliases[] = {
105 { "ta0", 12 },
106 { "ta1", 13 },
107 { "ta2", 14 },
108 { "ta3", 15 }
109};
110
111/* Aliases for n32 and n64. */
112const struct register_alias mips_n32_n64_aliases[] = {
113 { "ta0", 8 },
114 { "ta1", 9 },
115 { "ta2", 10 },
116 { "ta3", 11 }
117};
118
119/* Aliases for ABI-independent registers. */
120const struct register_alias mips_register_aliases[] = {
121 /* The architecture manuals specify these ABI-independent names for
122 the GPRs. */
123#define R(n) { "r" #n, n }
124 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
125 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
126 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
127 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
128#undef R
129
130 /* k0 and k1 are sometimes called these instead (for "kernel
131 temp"). */
132 { "kt0", 26 },
133 { "kt1", 27 },
134
135 /* This is the traditional GDB name for the CP0 status register. */
136 { "sr", MIPS_PS_REGNUM },
137
138 /* This is the traditional GDB name for the CP0 BadVAddr register. */
139 { "bad", MIPS_EMBED_BADVADDR_REGNUM },
140
141 /* This is the traditional GDB name for the FCSR. */
142 { "fsr", MIPS_EMBED_FP0_REGNUM + 32 }
143};
144
7a292a7a 145/* Some MIPS boards don't support floating point while others only
ceae6e75 146 support single-precision floating-point operations. */
c906108c
SS
147
148enum mips_fpu_type
6d82d43b
AC
149{
150 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
151 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
152 MIPS_FPU_NONE /* No floating point. */
153};
c906108c
SS
154
155#ifndef MIPS_DEFAULT_FPU_TYPE
156#define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
157#endif
158static int mips_fpu_type_auto = 1;
159static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
7a292a7a 160
9ace0497 161static int mips_debug = 0;
7a292a7a 162
29709017
DJ
163/* Properties (for struct target_desc) describing the g/G packet
164 layout. */
165#define PROPERTY_GP32 "internal: transfers-32bit-registers"
166#define PROPERTY_GP64 "internal: transfers-64bit-registers"
167
4eb0ad19
DJ
168struct target_desc *mips_tdesc_gp32;
169struct target_desc *mips_tdesc_gp64;
170
c2d11a7d
JM
171/* MIPS specific per-architecture information */
172struct gdbarch_tdep
6d82d43b
AC
173{
174 /* from the elf header */
175 int elf_flags;
176
177 /* mips options */
178 enum mips_abi mips_abi;
179 enum mips_abi found_abi;
180 enum mips_fpu_type mips_fpu_type;
181 int mips_last_arg_regnum;
182 int mips_last_fp_arg_regnum;
6d82d43b
AC
183 int default_mask_address_p;
184 /* Is the target using 64-bit raw integer registers but only
185 storing a left-aligned 32-bit value in each? */
186 int mips64_transfers_32bit_regs_p;
187 /* Indexes for various registers. IRIX and embedded have
188 different values. This contains the "public" fields. Don't
189 add any that do not need to be public. */
190 const struct mips_regnum *regnum;
191 /* Register names table for the current register set. */
192 const char **mips_processor_reg_names;
29709017
DJ
193
194 /* The size of register data available from the target, if known.
195 This doesn't quite obsolete the manual
196 mips64_transfers_32bit_regs_p, since that is documented to force
197 left alignment even for big endian (very strange). */
198 int register_size_valid_p;
199 int register_size;
6d82d43b 200};
c2d11a7d 201
56cea623
AC
202const struct mips_regnum *
203mips_regnum (struct gdbarch *gdbarch)
204{
205 return gdbarch_tdep (gdbarch)->regnum;
206}
207
208static int
209mips_fpa0_regnum (struct gdbarch *gdbarch)
210{
211 return mips_regnum (gdbarch)->fp0 + 12;
212}
213
0dadbba0 214#define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \
216a600b 215 || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64)
c2d11a7d 216
c2d11a7d 217#define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum)
c2d11a7d 218
c2d11a7d 219#define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum)
c2d11a7d 220
c2d11a7d 221#define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type)
c2d11a7d 222
95404a3e
AC
223/* MIPS16 function addresses are odd (bit 0 is set). Here are some
224 functions to test, set, or clear bit 0 of addresses. */
225
226static CORE_ADDR
227is_mips16_addr (CORE_ADDR addr)
228{
229 return ((addr) & 1);
230}
231
95404a3e
AC
232static CORE_ADDR
233unmake_mips16_addr (CORE_ADDR addr)
234{
5b652102 235 return ((addr) & ~(CORE_ADDR) 1);
95404a3e
AC
236}
237
d1973055
KB
238/* Return the MIPS ABI associated with GDBARCH. */
239enum mips_abi
240mips_abi (struct gdbarch *gdbarch)
241{
242 return gdbarch_tdep (gdbarch)->mips_abi;
243}
244
4246e332 245int
1b13c4f6 246mips_isa_regsize (struct gdbarch *gdbarch)
4246e332 247{
29709017
DJ
248 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
249
250 /* If we know how big the registers are, use that size. */
251 if (tdep->register_size_valid_p)
252 return tdep->register_size;
253
254 /* Fall back to the previous behavior. */
4246e332
AC
255 return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word
256 / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte);
257}
258
480d3dd2
AC
259/* Return the currently configured (or set) saved register size. */
260
e6bc2e8a 261unsigned int
13326b4e 262mips_abi_regsize (struct gdbarch *gdbarch)
d929b26f 263{
1a69e1e4
DJ
264 switch (mips_abi (gdbarch))
265 {
266 case MIPS_ABI_EABI32:
267 case MIPS_ABI_O32:
268 return 4;
269 case MIPS_ABI_N32:
270 case MIPS_ABI_N64:
271 case MIPS_ABI_O64:
272 case MIPS_ABI_EABI64:
273 return 8;
274 case MIPS_ABI_UNKNOWN:
275 case MIPS_ABI_LAST:
276 default:
277 internal_error (__FILE__, __LINE__, _("bad switch"));
278 }
d929b26f
AC
279}
280
71b8ef93 281/* Functions for setting and testing a bit in a minimal symbol that
5a89d8aa 282 marks it as 16-bit function. The MSB of the minimal symbol's
f594e5e9 283 "info" field is used for this purpose.
5a89d8aa 284
95f1da47 285 gdbarch_elf_make_msymbol_special tests whether an ELF symbol is "special",
5a89d8aa
MS
286 i.e. refers to a 16-bit function, and sets a "special" bit in a
287 minimal symbol to mark it as a 16-bit function
288
f594e5e9 289 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
5a89d8aa 290
5a89d8aa 291static void
6d82d43b
AC
292mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
293{
294 if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16)
295 {
296 MSYMBOL_INFO (msym) = (char *)
297 (((long) MSYMBOL_INFO (msym)) | 0x80000000);
298 SYMBOL_VALUE_ADDRESS (msym) |= 1;
299 }
5a89d8aa
MS
300}
301
71b8ef93
MS
302static int
303msymbol_is_special (struct minimal_symbol *msym)
304{
305 return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0);
306}
307
88658117
AC
308/* XFER a value from the big/little/left end of the register.
309 Depending on the size of the value it might occupy the entire
310 register or just part of it. Make an allowance for this, aligning
311 things accordingly. */
312
313static void
ba32f989
DJ
314mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache,
315 int reg_num, int length,
870cd05e
MK
316 enum bfd_endian endian, gdb_byte *in,
317 const gdb_byte *out, int buf_offset)
88658117 318{
88658117 319 int reg_offset = 0;
72a155b4
UW
320
321 gdb_assert (reg_num >= gdbarch_num_regs (gdbarch));
cb1d2653
AC
322 /* Need to transfer the left or right part of the register, based on
323 the targets byte order. */
88658117
AC
324 switch (endian)
325 {
326 case BFD_ENDIAN_BIG:
72a155b4 327 reg_offset = register_size (gdbarch, reg_num) - length;
88658117
AC
328 break;
329 case BFD_ENDIAN_LITTLE:
330 reg_offset = 0;
331 break;
6d82d43b 332 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
88658117
AC
333 reg_offset = 0;
334 break;
335 default:
e2e0b3e5 336 internal_error (__FILE__, __LINE__, _("bad switch"));
88658117
AC
337 }
338 if (mips_debug)
cb1d2653
AC
339 fprintf_unfiltered (gdb_stderr,
340 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
341 reg_num, reg_offset, buf_offset, length);
88658117
AC
342 if (mips_debug && out != NULL)
343 {
344 int i;
cb1d2653 345 fprintf_unfiltered (gdb_stdlog, "out ");
88658117 346 for (i = 0; i < length; i++)
cb1d2653 347 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
88658117
AC
348 }
349 if (in != NULL)
6d82d43b
AC
350 regcache_cooked_read_part (regcache, reg_num, reg_offset, length,
351 in + buf_offset);
88658117 352 if (out != NULL)
6d82d43b
AC
353 regcache_cooked_write_part (regcache, reg_num, reg_offset, length,
354 out + buf_offset);
88658117
AC
355 if (mips_debug && in != NULL)
356 {
357 int i;
cb1d2653 358 fprintf_unfiltered (gdb_stdlog, "in ");
88658117 359 for (i = 0; i < length; i++)
cb1d2653 360 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
88658117
AC
361 }
362 if (mips_debug)
363 fprintf_unfiltered (gdb_stdlog, "\n");
364}
365
dd824b04
DJ
366/* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
367 compatiblity mode. A return value of 1 means that we have
368 physical 64-bit registers, but should treat them as 32-bit registers. */
369
370static int
9c9acae0 371mips2_fp_compat (struct frame_info *frame)
dd824b04 372{
72a155b4 373 struct gdbarch *gdbarch = get_frame_arch (frame);
dd824b04
DJ
374 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
375 meaningful. */
72a155b4 376 if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4)
dd824b04
DJ
377 return 0;
378
379#if 0
380 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
381 in all the places we deal with FP registers. PR gdb/413. */
382 /* Otherwise check the FR bit in the status register - it controls
383 the FP compatiblity mode. If it is clear we are in compatibility
384 mode. */
9c9acae0 385 if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0)
dd824b04
DJ
386 return 1;
387#endif
361d1df0 388
dd824b04
DJ
389 return 0;
390}
391
7a292a7a 392#define VM_MIN_ADDRESS (CORE_ADDR)0x400000
c906108c 393
a14ed312 394static CORE_ADDR heuristic_proc_start (CORE_ADDR);
c906108c 395
a14ed312 396static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
c906108c 397
67b2c998
DJ
398static struct type *mips_float_register_type (void);
399static struct type *mips_double_register_type (void);
400
acdb74a0
AC
401/* The list of available "set mips " and "show mips " commands */
402
403static struct cmd_list_element *setmipscmdlist = NULL;
404static struct cmd_list_element *showmipscmdlist = NULL;
405
5e2e9765
KB
406/* Integer registers 0 thru 31 are handled explicitly by
407 mips_register_name(). Processor specific registers 32 and above
8a9fc081 408 are listed in the following tables. */
691c0433 409
6d82d43b
AC
410enum
411{ NUM_MIPS_PROCESSOR_REGS = (90 - 32) };
691c0433
AC
412
413/* Generic MIPS. */
414
415static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
6d82d43b
AC
416 "sr", "lo", "hi", "bad", "cause", "pc",
417 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
418 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
419 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
420 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
421 "fsr", "fir", "" /*"fp" */ , "",
422 "", "", "", "", "", "", "", "",
423 "", "", "", "", "", "", "", "",
691c0433
AC
424};
425
426/* Names of IDT R3041 registers. */
427
428static const char *mips_r3041_reg_names[] = {
6d82d43b
AC
429 "sr", "lo", "hi", "bad", "cause", "pc",
430 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
431 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
432 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
433 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
434 "fsr", "fir", "", /*"fp" */ "",
435 "", "", "bus", "ccfg", "", "", "", "",
436 "", "", "port", "cmp", "", "", "epc", "prid",
691c0433
AC
437};
438
439/* Names of tx39 registers. */
440
441static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
6d82d43b
AC
442 "sr", "lo", "hi", "bad", "cause", "pc",
443 "", "", "", "", "", "", "", "",
444 "", "", "", "", "", "", "", "",
445 "", "", "", "", "", "", "", "",
446 "", "", "", "", "", "", "", "",
447 "", "", "", "",
448 "", "", "", "", "", "", "", "",
449 "", "", "config", "cache", "debug", "depc", "epc", ""
691c0433
AC
450};
451
452/* Names of IRIX registers. */
453static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
6d82d43b
AC
454 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
455 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
456 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
457 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
458 "pc", "cause", "bad", "hi", "lo", "fsr", "fir"
691c0433
AC
459};
460
cce74817 461
5e2e9765 462/* Return the name of the register corresponding to REGNO. */
5a89d8aa 463static const char *
d93859e2 464mips_register_name (struct gdbarch *gdbarch, int regno)
cce74817 465{
d93859e2 466 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5e2e9765
KB
467 /* GPR names for all ABIs other than n32/n64. */
468 static char *mips_gpr_names[] = {
6d82d43b
AC
469 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
470 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
471 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
472 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
5e2e9765
KB
473 };
474
475 /* GPR names for n32 and n64 ABIs. */
476 static char *mips_n32_n64_gpr_names[] = {
6d82d43b
AC
477 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
478 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
479 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
480 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
5e2e9765
KB
481 };
482
d93859e2 483 enum mips_abi abi = mips_abi (gdbarch);
5e2e9765 484
f57d151a
UW
485 /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
486 but then don't make the raw register names visible. */
d93859e2
UW
487 int rawnum = regno % gdbarch_num_regs (gdbarch);
488 if (regno < gdbarch_num_regs (gdbarch))
a4b8ebc8
AC
489 return "";
490
5e2e9765
KB
491 /* The MIPS integer registers are always mapped from 0 to 31. The
492 names of the registers (which reflects the conventions regarding
493 register use) vary depending on the ABI. */
a4b8ebc8 494 if (0 <= rawnum && rawnum < 32)
5e2e9765
KB
495 {
496 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
a4b8ebc8 497 return mips_n32_n64_gpr_names[rawnum];
5e2e9765 498 else
a4b8ebc8 499 return mips_gpr_names[rawnum];
5e2e9765 500 }
d93859e2
UW
501 else if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
502 return tdesc_register_name (gdbarch, rawnum);
503 else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch))
691c0433
AC
504 {
505 gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS);
506 return tdep->mips_processor_reg_names[rawnum - 32];
507 }
5e2e9765
KB
508 else
509 internal_error (__FILE__, __LINE__,
e2e0b3e5 510 _("mips_register_name: bad register number %d"), rawnum);
cce74817 511}
5e2e9765 512
a4b8ebc8 513/* Return the groups that a MIPS register can be categorised into. */
c5aa993b 514
a4b8ebc8
AC
515static int
516mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
517 struct reggroup *reggroup)
518{
519 int vector_p;
520 int float_p;
521 int raw_p;
72a155b4
UW
522 int rawnum = regnum % gdbarch_num_regs (gdbarch);
523 int pseudo = regnum / gdbarch_num_regs (gdbarch);
a4b8ebc8
AC
524 if (reggroup == all_reggroup)
525 return pseudo;
526 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
527 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
528 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
529 (gdbarch), as not all architectures are multi-arch. */
72a155b4
UW
530 raw_p = rawnum < gdbarch_num_regs (gdbarch);
531 if (gdbarch_register_name (gdbarch, regnum) == NULL
532 || gdbarch_register_name (gdbarch, regnum)[0] == '\0')
a4b8ebc8
AC
533 return 0;
534 if (reggroup == float_reggroup)
535 return float_p && pseudo;
536 if (reggroup == vector_reggroup)
537 return vector_p && pseudo;
538 if (reggroup == general_reggroup)
539 return (!vector_p && !float_p) && pseudo;
540 /* Save the pseudo registers. Need to make certain that any code
541 extracting register values from a saved register cache also uses
542 pseudo registers. */
543 if (reggroup == save_reggroup)
544 return raw_p && pseudo;
545 /* Restore the same pseudo register. */
546 if (reggroup == restore_reggroup)
547 return raw_p && pseudo;
6d82d43b 548 return 0;
a4b8ebc8
AC
549}
550
f8b73d13
DJ
551/* Return the groups that a MIPS register can be categorised into.
552 This version is only used if we have a target description which
553 describes real registers (and their groups). */
554
555static int
556mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
557 struct reggroup *reggroup)
558{
559 int rawnum = regnum % gdbarch_num_regs (gdbarch);
560 int pseudo = regnum / gdbarch_num_regs (gdbarch);
561 int ret;
562
563 /* Only save, restore, and display the pseudo registers. Need to
564 make certain that any code extracting register values from a
565 saved register cache also uses pseudo registers.
566
567 Note: saving and restoring the pseudo registers is slightly
568 strange; if we have 64 bits, we should save and restore all
569 64 bits. But this is hard and has little benefit. */
570 if (!pseudo)
571 return 0;
572
573 ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup);
574 if (ret != -1)
575 return ret;
576
577 return mips_register_reggroup_p (gdbarch, regnum, reggroup);
578}
579
a4b8ebc8 580/* Map the symbol table registers which live in the range [1 *
f57d151a 581 gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
47ebcfbe 582 registers. Take care of alignment and size problems. */
c5aa993b 583
a4b8ebc8
AC
584static void
585mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
47a35522 586 int cookednum, gdb_byte *buf)
a4b8ebc8 587{
72a155b4
UW
588 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
589 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
590 && cookednum < 2 * gdbarch_num_regs (gdbarch));
47ebcfbe 591 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
de38af99 592 regcache_raw_read (regcache, rawnum, buf);
6d82d43b
AC
593 else if (register_size (gdbarch, rawnum) >
594 register_size (gdbarch, cookednum))
47ebcfbe
AC
595 {
596 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p
72a155b4 597 || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
47ebcfbe
AC
598 regcache_raw_read_part (regcache, rawnum, 0, 4, buf);
599 else
600 regcache_raw_read_part (regcache, rawnum, 4, 4, buf);
601 }
602 else
e2e0b3e5 603 internal_error (__FILE__, __LINE__, _("bad register size"));
a4b8ebc8
AC
604}
605
606static void
6d82d43b
AC
607mips_pseudo_register_write (struct gdbarch *gdbarch,
608 struct regcache *regcache, int cookednum,
47a35522 609 const gdb_byte *buf)
a4b8ebc8 610{
72a155b4
UW
611 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
612 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
613 && cookednum < 2 * gdbarch_num_regs (gdbarch));
47ebcfbe 614 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
de38af99 615 regcache_raw_write (regcache, rawnum, buf);
6d82d43b
AC
616 else if (register_size (gdbarch, rawnum) >
617 register_size (gdbarch, cookednum))
47ebcfbe
AC
618 {
619 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p
72a155b4 620 || gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
47ebcfbe
AC
621 regcache_raw_write_part (regcache, rawnum, 0, 4, buf);
622 else
623 regcache_raw_write_part (regcache, rawnum, 4, 4, buf);
624 }
625 else
e2e0b3e5 626 internal_error (__FILE__, __LINE__, _("bad register size"));
a4b8ebc8 627}
c5aa993b 628
c906108c 629/* Table to translate MIPS16 register field to actual register number. */
6d82d43b 630static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
c906108c
SS
631
632/* Heuristic_proc_start may hunt through the text section for a long
633 time across a 2400 baud serial line. Allows the user to limit this
634 search. */
635
636static unsigned int heuristic_fence_post = 0;
637
46cd78fb 638/* Number of bytes of storage in the actual machine representation for
719ec221
AC
639 register N. NOTE: This defines the pseudo register type so need to
640 rebuild the architecture vector. */
43e526b9
JM
641
642static int mips64_transfers_32bit_regs_p = 0;
643
719ec221
AC
644static void
645set_mips64_transfers_32bit_regs (char *args, int from_tty,
646 struct cmd_list_element *c)
43e526b9 647{
719ec221
AC
648 struct gdbarch_info info;
649 gdbarch_info_init (&info);
650 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
651 instead of relying on globals. Doing that would let generic code
652 handle the search for this specific architecture. */
653 if (!gdbarch_update_p (info))
a4b8ebc8 654 {
719ec221 655 mips64_transfers_32bit_regs_p = 0;
8a3fe4f8 656 error (_("32-bit compatibility mode not supported"));
a4b8ebc8 657 }
a4b8ebc8
AC
658}
659
47ebcfbe 660/* Convert to/from a register and the corresponding memory value. */
43e526b9 661
ff2e87ac 662static int
0abe36f5 663mips_convert_register_p (struct gdbarch *gdbarch, int regnum, struct type *type)
ff2e87ac 664{
0abe36f5
MD
665 return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
666 && register_size (gdbarch, regnum) == 4
667 && (regnum % gdbarch_num_regs (gdbarch))
668 >= mips_regnum (gdbarch)->fp0
669 && (regnum % gdbarch_num_regs (gdbarch))
670 < mips_regnum (gdbarch)->fp0 + 32
6d82d43b 671 && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8);
ff2e87ac
AC
672}
673
42c466d7 674static void
ff2e87ac 675mips_register_to_value (struct frame_info *frame, int regnum,
47a35522 676 struct type *type, gdb_byte *to)
102182a9 677{
47a35522
MK
678 get_frame_register (frame, regnum + 0, to + 4);
679 get_frame_register (frame, regnum + 1, to + 0);
102182a9
MS
680}
681
42c466d7 682static void
ff2e87ac 683mips_value_to_register (struct frame_info *frame, int regnum,
47a35522 684 struct type *type, const gdb_byte *from)
102182a9 685{
47a35522
MK
686 put_frame_register (frame, regnum + 0, from + 4);
687 put_frame_register (frame, regnum + 1, from + 0);
102182a9
MS
688}
689
a4b8ebc8
AC
690/* Return the GDB type object for the "standard" data type of data in
691 register REG. */
78fde5f8
KB
692
693static struct type *
a4b8ebc8
AC
694mips_register_type (struct gdbarch *gdbarch, int regnum)
695{
72a155b4
UW
696 gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch));
697 if ((regnum % gdbarch_num_regs (gdbarch)) >= mips_regnum (gdbarch)->fp0
698 && (regnum % gdbarch_num_regs (gdbarch))
699 < mips_regnum (gdbarch)->fp0 + 32)
a6425924 700 {
5ef80fb0 701 /* The floating-point registers raw, or cooked, always match
1b13c4f6 702 mips_isa_regsize(), and also map 1:1, byte for byte. */
8da61cc4
DJ
703 if (mips_isa_regsize (gdbarch) == 4)
704 return builtin_type_ieee_single;
705 else
706 return builtin_type_ieee_double;
a6425924 707 }
72a155b4 708 else if (regnum < gdbarch_num_regs (gdbarch))
d5ac5a39
AC
709 {
710 /* The raw or ISA registers. These are all sized according to
711 the ISA regsize. */
712 if (mips_isa_regsize (gdbarch) == 4)
713 return builtin_type_int32;
714 else
715 return builtin_type_int64;
716 }
78fde5f8 717 else
d5ac5a39
AC
718 {
719 /* The cooked or ABI registers. These are sized according to
720 the ABI (with a few complications). */
72a155b4
UW
721 if (regnum >= (gdbarch_num_regs (gdbarch)
722 + mips_regnum (gdbarch)->fp_control_status)
723 && regnum <= gdbarch_num_regs (gdbarch) + MIPS_LAST_EMBED_REGNUM)
d5ac5a39
AC
724 /* The pseudo/cooked view of the embedded registers is always
725 32-bit. The raw view is handled below. */
726 return builtin_type_int32;
727 else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p)
728 /* The target, while possibly using a 64-bit register buffer,
729 is only transfering 32-bits of each integer register.
730 Reflect this in the cooked/pseudo (ABI) register value. */
731 return builtin_type_int32;
732 else if (mips_abi_regsize (gdbarch) == 4)
733 /* The ABI is restricted to 32-bit registers (the ISA could be
734 32- or 64-bit). */
735 return builtin_type_int32;
736 else
737 /* 64-bit ABI. */
738 return builtin_type_int64;
739 }
78fde5f8
KB
740}
741
f8b73d13
DJ
742/* Return the GDB type for the pseudo register REGNUM, which is the
743 ABI-level view. This function is only called if there is a target
744 description which includes registers, so we know precisely the
745 types of hardware registers. */
746
747static struct type *
748mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
749{
750 const int num_regs = gdbarch_num_regs (gdbarch);
751 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
752 int rawnum = regnum % num_regs;
753 struct type *rawtype;
754
755 gdb_assert (regnum >= num_regs && regnum < 2 * num_regs);
756
757 /* Absent registers are still absent. */
758 rawtype = gdbarch_register_type (gdbarch, rawnum);
759 if (TYPE_LENGTH (rawtype) == 0)
760 return rawtype;
761
762 if (rawnum >= MIPS_EMBED_FP0_REGNUM && rawnum < MIPS_EMBED_FP0_REGNUM + 32)
763 /* Present the floating point registers however the hardware did;
764 do not try to convert between FPU layouts. */
765 return rawtype;
766
767 if (rawnum >= MIPS_EMBED_FP0_REGNUM + 32 && rawnum <= MIPS_LAST_EMBED_REGNUM)
768 {
769 /* The pseudo/cooked view of embedded registers is always
770 32-bit, even if the target transfers 64-bit values for them.
771 New targets relying on XML descriptions should only transfer
772 the necessary 32 bits, but older versions of GDB expected 64,
773 so allow the target to provide 64 bits without interfering
774 with the displayed type. */
775 return builtin_type_int32;
776 }
777
778 /* Use pointer types for registers if we can. For n32 we can not,
779 since we do not have a 64-bit pointer type. */
780 if (mips_abi_regsize (gdbarch) == TYPE_LENGTH (builtin_type_void_data_ptr))
781 {
782 if (rawnum == MIPS_SP_REGNUM || rawnum == MIPS_EMBED_BADVADDR_REGNUM)
783 return builtin_type_void_data_ptr;
784 else if (rawnum == MIPS_EMBED_PC_REGNUM)
785 return builtin_type_void_func_ptr;
786 }
787
788 if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8
789 && rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_EMBED_PC_REGNUM)
790 return builtin_type_int32;
791
792 /* For all other registers, pass through the hardware type. */
793 return rawtype;
794}
bcb0cc15 795
c906108c 796/* Should the upper word of 64-bit addresses be zeroed? */
7f19b9a2 797enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
4014092b
AC
798
799static int
480d3dd2 800mips_mask_address_p (struct gdbarch_tdep *tdep)
4014092b
AC
801{
802 switch (mask_address_var)
803 {
7f19b9a2 804 case AUTO_BOOLEAN_TRUE:
4014092b 805 return 1;
7f19b9a2 806 case AUTO_BOOLEAN_FALSE:
4014092b
AC
807 return 0;
808 break;
7f19b9a2 809 case AUTO_BOOLEAN_AUTO:
480d3dd2 810 return tdep->default_mask_address_p;
4014092b 811 default:
e2e0b3e5 812 internal_error (__FILE__, __LINE__, _("mips_mask_address_p: bad switch"));
4014092b 813 return -1;
361d1df0 814 }
4014092b
AC
815}
816
817static void
08546159
AC
818show_mask_address (struct ui_file *file, int from_tty,
819 struct cmd_list_element *c, const char *value)
4014092b 820{
480d3dd2 821 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
08546159
AC
822
823 deprecated_show_value_hack (file, from_tty, c, value);
4014092b
AC
824 switch (mask_address_var)
825 {
7f19b9a2 826 case AUTO_BOOLEAN_TRUE:
4014092b
AC
827 printf_filtered ("The 32 bit mips address mask is enabled\n");
828 break;
7f19b9a2 829 case AUTO_BOOLEAN_FALSE:
4014092b
AC
830 printf_filtered ("The 32 bit mips address mask is disabled\n");
831 break;
7f19b9a2 832 case AUTO_BOOLEAN_AUTO:
6d82d43b
AC
833 printf_filtered
834 ("The 32 bit address mask is set automatically. Currently %s\n",
835 mips_mask_address_p (tdep) ? "enabled" : "disabled");
4014092b
AC
836 break;
837 default:
e2e0b3e5 838 internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
4014092b 839 break;
361d1df0 840 }
4014092b 841}
c906108c 842
c906108c
SS
843/* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
844
0fe7e7c8
AC
845int
846mips_pc_is_mips16 (CORE_ADDR memaddr)
c906108c
SS
847{
848 struct minimal_symbol *sym;
849
850 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
95404a3e 851 if (is_mips16_addr (memaddr))
c906108c
SS
852 return 1;
853
854 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
855 the high bit of the info field. Use this to decide if the function is
856 MIPS16 or normal MIPS. */
857 sym = lookup_minimal_symbol_by_pc (memaddr);
858 if (sym)
71b8ef93 859 return msymbol_is_special (sym);
c906108c
SS
860 else
861 return 0;
862}
863
b2fa5097 864/* MIPS believes that the PC has a sign extended value. Perhaps the
6c997a34
AC
865 all registers should be sign extended for simplicity? */
866
867static CORE_ADDR
61a1198a 868mips_read_pc (struct regcache *regcache)
6c997a34 869{
61a1198a
UW
870 ULONGEST pc;
871 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
872 regcache_cooked_read_signed (regcache, regnum, &pc);
873 return pc;
b6cb9035
AC
874}
875
58dfe9ff
AC
876static CORE_ADDR
877mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
878{
72a155b4
UW
879 return frame_unwind_register_signed
880 (next_frame, gdbarch_num_regs (gdbarch) + mips_regnum (gdbarch)->pc);
edfae063
AC
881}
882
30244cd8
UW
883static CORE_ADDR
884mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
885{
72a155b4
UW
886 return frame_unwind_register_signed
887 (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM);
30244cd8
UW
888}
889
edfae063
AC
890/* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
891 dummy frame. The frame ID's base needs to match the TOS value
892 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
893 breakpoint. */
894
895static struct frame_id
896mips_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
897{
f57d151a
UW
898 return frame_id_build
899 (frame_unwind_register_signed (next_frame,
72a155b4 900 gdbarch_num_regs (gdbarch)
f57d151a
UW
901 + MIPS_SP_REGNUM),
902 frame_pc_unwind (next_frame));
58dfe9ff
AC
903}
904
b6cb9035 905static void
61a1198a 906mips_write_pc (struct regcache *regcache, CORE_ADDR pc)
b6cb9035 907{
61a1198a
UW
908 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
909 regcache_cooked_write_unsigned (regcache, regnum, pc);
6c997a34 910}
c906108c 911
c906108c
SS
912/* Fetch and return instruction from the specified location. If the PC
913 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
914
d37cca3d 915static ULONGEST
acdb74a0 916mips_fetch_instruction (CORE_ADDR addr)
c906108c 917{
47a35522 918 gdb_byte buf[MIPS_INSN32_SIZE];
c906108c
SS
919 int instlen;
920 int status;
921
0fe7e7c8 922 if (mips_pc_is_mips16 (addr))
c906108c 923 {
95ac2dcf 924 instlen = MIPS_INSN16_SIZE;
95404a3e 925 addr = unmake_mips16_addr (addr);
c906108c
SS
926 }
927 else
95ac2dcf 928 instlen = MIPS_INSN32_SIZE;
8defab1a 929 status = target_read_memory (addr, buf, instlen);
c906108c
SS
930 if (status)
931 memory_error (status, addr);
932 return extract_unsigned_integer (buf, instlen);
933}
934
c906108c 935/* These the fields of 32 bit mips instructions */
e135b889
DJ
936#define mips32_op(x) (x >> 26)
937#define itype_op(x) (x >> 26)
938#define itype_rs(x) ((x >> 21) & 0x1f)
c906108c 939#define itype_rt(x) ((x >> 16) & 0x1f)
e135b889 940#define itype_immediate(x) (x & 0xffff)
c906108c 941
e135b889
DJ
942#define jtype_op(x) (x >> 26)
943#define jtype_target(x) (x & 0x03ffffff)
c906108c 944
e135b889
DJ
945#define rtype_op(x) (x >> 26)
946#define rtype_rs(x) ((x >> 21) & 0x1f)
947#define rtype_rt(x) ((x >> 16) & 0x1f)
948#define rtype_rd(x) ((x >> 11) & 0x1f)
949#define rtype_shamt(x) ((x >> 6) & 0x1f)
950#define rtype_funct(x) (x & 0x3f)
c906108c 951
06987e64
MK
952static LONGEST
953mips32_relative_offset (ULONGEST inst)
c5aa993b 954{
06987e64 955 return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2;
c906108c
SS
956}
957
f49e4e6d
MS
958/* Determine where to set a single step breakpoint while considering
959 branch prediction. */
5a89d8aa 960static CORE_ADDR
0b1b3e42 961mips32_next_pc (struct frame_info *frame, CORE_ADDR pc)
c5aa993b
JM
962{
963 unsigned long inst;
964 int op;
965 inst = mips_fetch_instruction (pc);
e135b889 966 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */
c5aa993b 967 {
e135b889 968 if (itype_op (inst) >> 2 == 5)
6d82d43b 969 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
c5aa993b 970 {
e135b889 971 op = (itype_op (inst) & 0x03);
c906108c
SS
972 switch (op)
973 {
e135b889
DJ
974 case 0: /* BEQL */
975 goto equal_branch;
976 case 1: /* BNEL */
977 goto neq_branch;
978 case 2: /* BLEZL */
979 goto less_branch;
313628cc 980 case 3: /* BGTZL */
e135b889 981 goto greater_branch;
c5aa993b
JM
982 default:
983 pc += 4;
c906108c
SS
984 }
985 }
e135b889 986 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
6d82d43b 987 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
e135b889
DJ
988 {
989 int tf = itype_rt (inst) & 0x01;
990 int cnum = itype_rt (inst) >> 2;
6d82d43b 991 int fcrcs =
72a155b4
UW
992 get_frame_register_signed (frame,
993 mips_regnum (get_frame_arch (frame))->
0b1b3e42 994 fp_control_status);
e135b889
DJ
995 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
996
997 if (((cond >> cnum) & 0x01) == tf)
998 pc += mips32_relative_offset (inst) + 4;
999 else
1000 pc += 8;
1001 }
c5aa993b
JM
1002 else
1003 pc += 4; /* Not a branch, next instruction is easy */
c906108c
SS
1004 }
1005 else
c5aa993b
JM
1006 { /* This gets way messy */
1007
c906108c 1008 /* Further subdivide into SPECIAL, REGIMM and other */
e135b889 1009 switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */
c906108c 1010 {
c5aa993b
JM
1011 case 0: /* SPECIAL */
1012 op = rtype_funct (inst);
1013 switch (op)
1014 {
1015 case 8: /* JR */
1016 case 9: /* JALR */
6c997a34 1017 /* Set PC to that address */
0b1b3e42 1018 pc = get_frame_register_signed (frame, rtype_rs (inst));
c5aa993b
JM
1019 break;
1020 default:
1021 pc += 4;
1022 }
1023
6d82d43b 1024 break; /* end SPECIAL */
c5aa993b 1025 case 1: /* REGIMM */
c906108c 1026 {
e135b889
DJ
1027 op = itype_rt (inst); /* branch condition */
1028 switch (op)
c906108c 1029 {
c5aa993b 1030 case 0: /* BLTZ */
e135b889
DJ
1031 case 2: /* BLTZL */
1032 case 16: /* BLTZAL */
c5aa993b 1033 case 18: /* BLTZALL */
c906108c 1034 less_branch:
0b1b3e42 1035 if (get_frame_register_signed (frame, itype_rs (inst)) < 0)
c5aa993b
JM
1036 pc += mips32_relative_offset (inst) + 4;
1037 else
1038 pc += 8; /* after the delay slot */
1039 break;
e135b889 1040 case 1: /* BGEZ */
c5aa993b
JM
1041 case 3: /* BGEZL */
1042 case 17: /* BGEZAL */
1043 case 19: /* BGEZALL */
0b1b3e42 1044 if (get_frame_register_signed (frame, itype_rs (inst)) >= 0)
c5aa993b
JM
1045 pc += mips32_relative_offset (inst) + 4;
1046 else
1047 pc += 8; /* after the delay slot */
1048 break;
e135b889 1049 /* All of the other instructions in the REGIMM category */
c5aa993b
JM
1050 default:
1051 pc += 4;
c906108c
SS
1052 }
1053 }
6d82d43b 1054 break; /* end REGIMM */
c5aa993b
JM
1055 case 2: /* J */
1056 case 3: /* JAL */
1057 {
1058 unsigned long reg;
1059 reg = jtype_target (inst) << 2;
e135b889 1060 /* Upper four bits get never changed... */
5b652102 1061 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff);
c906108c 1062 }
c5aa993b
JM
1063 break;
1064 /* FIXME case JALX : */
1065 {
1066 unsigned long reg;
1067 reg = jtype_target (inst) << 2;
5b652102 1068 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + 1; /* yes, +1 */
c906108c
SS
1069 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1070 }
c5aa993b 1071 break; /* The new PC will be alternate mode */
e135b889 1072 case 4: /* BEQ, BEQL */
c5aa993b 1073 equal_branch:
0b1b3e42
UW
1074 if (get_frame_register_signed (frame, itype_rs (inst)) ==
1075 get_frame_register_signed (frame, itype_rt (inst)))
c5aa993b
JM
1076 pc += mips32_relative_offset (inst) + 4;
1077 else
1078 pc += 8;
1079 break;
e135b889 1080 case 5: /* BNE, BNEL */
c5aa993b 1081 neq_branch:
0b1b3e42
UW
1082 if (get_frame_register_signed (frame, itype_rs (inst)) !=
1083 get_frame_register_signed (frame, itype_rt (inst)))
c5aa993b
JM
1084 pc += mips32_relative_offset (inst) + 4;
1085 else
1086 pc += 8;
1087 break;
e135b889 1088 case 6: /* BLEZ, BLEZL */
0b1b3e42 1089 if (get_frame_register_signed (frame, itype_rs (inst)) <= 0)
c5aa993b
JM
1090 pc += mips32_relative_offset (inst) + 4;
1091 else
1092 pc += 8;
1093 break;
1094 case 7:
e135b889
DJ
1095 default:
1096 greater_branch: /* BGTZ, BGTZL */
0b1b3e42 1097 if (get_frame_register_signed (frame, itype_rs (inst)) > 0)
c5aa993b
JM
1098 pc += mips32_relative_offset (inst) + 4;
1099 else
1100 pc += 8;
1101 break;
c5aa993b
JM
1102 } /* switch */
1103 } /* else */
1104 return pc;
1105} /* mips32_next_pc */
c906108c
SS
1106
1107/* Decoding the next place to set a breakpoint is irregular for the
e26cc349 1108 mips 16 variant, but fortunately, there fewer instructions. We have to cope
c906108c
SS
1109 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
1110 We dont want to set a single step instruction on the extend instruction
1111 either.
c5aa993b 1112 */
c906108c
SS
1113
1114/* Lots of mips16 instruction formats */
1115/* Predicting jumps requires itype,ritype,i8type
1116 and their extensions extItype,extritype,extI8type
c5aa993b 1117 */
c906108c
SS
1118enum mips16_inst_fmts
1119{
c5aa993b
JM
1120 itype, /* 0 immediate 5,10 */
1121 ritype, /* 1 5,3,8 */
1122 rrtype, /* 2 5,3,3,5 */
1123 rritype, /* 3 5,3,3,5 */
1124 rrrtype, /* 4 5,3,3,3,2 */
1125 rriatype, /* 5 5,3,3,1,4 */
1126 shifttype, /* 6 5,3,3,3,2 */
1127 i8type, /* 7 5,3,8 */
1128 i8movtype, /* 8 5,3,3,5 */
1129 i8mov32rtype, /* 9 5,3,5,3 */
1130 i64type, /* 10 5,3,8 */
1131 ri64type, /* 11 5,3,3,5 */
1132 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1133 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1134 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1135 extRRItype, /* 15 5,5,5,5,3,3,5 */
1136 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1137 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1138 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1139 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1140 extRi64type, /* 20 5,6,5,5,3,3,5 */
1141 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1142};
12f02c2a
AC
1143/* I am heaping all the fields of the formats into one structure and
1144 then, only the fields which are involved in instruction extension */
c906108c 1145struct upk_mips16
6d82d43b
AC
1146{
1147 CORE_ADDR offset;
1148 unsigned int regx; /* Function in i8 type */
1149 unsigned int regy;
1150};
c906108c
SS
1151
1152
12f02c2a 1153/* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
c68cf8ad 1154 for the bits which make up the immediate extension. */
c906108c 1155
12f02c2a
AC
1156static CORE_ADDR
1157extended_offset (unsigned int extension)
c906108c 1158{
12f02c2a 1159 CORE_ADDR value;
c5aa993b
JM
1160 value = (extension >> 21) & 0x3f; /* * extract 15:11 */
1161 value = value << 6;
1162 value |= (extension >> 16) & 0x1f; /* extrace 10:5 */
1163 value = value << 5;
1164 value |= extension & 0x01f; /* extract 4:0 */
1165 return value;
c906108c
SS
1166}
1167
1168/* Only call this function if you know that this is an extendable
bcf1ea1e
MR
1169 instruction. It won't malfunction, but why make excess remote memory
1170 references? If the immediate operands get sign extended or something,
1171 do it after the extension is performed. */
c906108c 1172/* FIXME: Every one of these cases needs to worry about sign extension
bcf1ea1e 1173 when the offset is to be used in relative addressing. */
c906108c 1174
12f02c2a 1175static unsigned int
c5aa993b 1176fetch_mips_16 (CORE_ADDR pc)
c906108c 1177{
47a35522 1178 gdb_byte buf[8];
c5aa993b
JM
1179 pc &= 0xfffffffe; /* clear the low order bit */
1180 target_read_memory (pc, buf, 2);
1181 return extract_unsigned_integer (buf, 2);
c906108c
SS
1182}
1183
1184static void
c5aa993b 1185unpack_mips16 (CORE_ADDR pc,
12f02c2a
AC
1186 unsigned int extension,
1187 unsigned int inst,
6d82d43b 1188 enum mips16_inst_fmts insn_format, struct upk_mips16 *upk)
c906108c 1189{
12f02c2a
AC
1190 CORE_ADDR offset;
1191 int regx;
1192 int regy;
1193 switch (insn_format)
c906108c 1194 {
c5aa993b 1195 case itype:
c906108c 1196 {
12f02c2a
AC
1197 CORE_ADDR value;
1198 if (extension)
c5aa993b
JM
1199 {
1200 value = extended_offset (extension);
1201 value = value << 11; /* rom for the original value */
6d82d43b 1202 value |= inst & 0x7ff; /* eleven bits from instruction */
c906108c
SS
1203 }
1204 else
c5aa993b 1205 {
12f02c2a 1206 value = inst & 0x7ff;
c5aa993b 1207 /* FIXME : Consider sign extension */
c906108c 1208 }
12f02c2a
AC
1209 offset = value;
1210 regx = -1;
1211 regy = -1;
c906108c 1212 }
c5aa993b
JM
1213 break;
1214 case ritype:
1215 case i8type:
1216 { /* A register identifier and an offset */
c906108c
SS
1217 /* Most of the fields are the same as I type but the
1218 immediate value is of a different length */
12f02c2a
AC
1219 CORE_ADDR value;
1220 if (extension)
c906108c 1221 {
c5aa993b
JM
1222 value = extended_offset (extension);
1223 value = value << 8; /* from the original instruction */
12f02c2a
AC
1224 value |= inst & 0xff; /* eleven bits from instruction */
1225 regx = (extension >> 8) & 0x07; /* or i8 funct */
c5aa993b
JM
1226 if (value & 0x4000) /* test the sign bit , bit 26 */
1227 {
1228 value &= ~0x3fff; /* remove the sign bit */
1229 value = -value;
c906108c
SS
1230 }
1231 }
c5aa993b
JM
1232 else
1233 {
12f02c2a
AC
1234 value = inst & 0xff; /* 8 bits */
1235 regx = (inst >> 8) & 0x07; /* or i8 funct */
c5aa993b
JM
1236 /* FIXME: Do sign extension , this format needs it */
1237 if (value & 0x80) /* THIS CONFUSES ME */
1238 {
1239 value &= 0xef; /* remove the sign bit */
1240 value = -value;
1241 }
c5aa993b 1242 }
12f02c2a
AC
1243 offset = value;
1244 regy = -1;
c5aa993b 1245 break;
c906108c 1246 }
c5aa993b 1247 case jalxtype:
c906108c 1248 {
c5aa993b 1249 unsigned long value;
12f02c2a
AC
1250 unsigned int nexthalf;
1251 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
c5aa993b
JM
1252 value = value << 16;
1253 nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */
1254 value |= nexthalf;
12f02c2a
AC
1255 offset = value;
1256 regx = -1;
1257 regy = -1;
c5aa993b 1258 break;
c906108c
SS
1259 }
1260 default:
e2e0b3e5 1261 internal_error (__FILE__, __LINE__, _("bad switch"));
c906108c 1262 }
12f02c2a
AC
1263 upk->offset = offset;
1264 upk->regx = regx;
1265 upk->regy = regy;
c906108c
SS
1266}
1267
1268
c5aa993b
JM
1269static CORE_ADDR
1270add_offset_16 (CORE_ADDR pc, int offset)
c906108c 1271{
5b652102 1272 return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff)));
c906108c
SS
1273}
1274
12f02c2a 1275static CORE_ADDR
0b1b3e42 1276extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc,
6d82d43b 1277 unsigned int extension, unsigned int insn)
c906108c 1278{
12f02c2a
AC
1279 int op = (insn >> 11);
1280 switch (op)
c906108c 1281 {
6d82d43b 1282 case 2: /* Branch */
12f02c2a
AC
1283 {
1284 CORE_ADDR offset;
1285 struct upk_mips16 upk;
1286 unpack_mips16 (pc, extension, insn, itype, &upk);
1287 offset = upk.offset;
1288 if (offset & 0x800)
1289 {
1290 offset &= 0xeff;
1291 offset = -offset;
1292 }
1293 pc += (offset << 1) + 2;
1294 break;
1295 }
6d82d43b 1296 case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */
12f02c2a
AC
1297 {
1298 struct upk_mips16 upk;
1299 unpack_mips16 (pc, extension, insn, jalxtype, &upk);
1300 pc = add_offset_16 (pc, upk.offset);
1301 if ((insn >> 10) & 0x01) /* Exchange mode */
1302 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */
1303 else
1304 pc |= 0x01;
1305 break;
1306 }
6d82d43b 1307 case 4: /* beqz */
12f02c2a
AC
1308 {
1309 struct upk_mips16 upk;
1310 int reg;
1311 unpack_mips16 (pc, extension, insn, ritype, &upk);
0b1b3e42 1312 reg = get_frame_register_signed (frame, upk.regx);
12f02c2a
AC
1313 if (reg == 0)
1314 pc += (upk.offset << 1) + 2;
1315 else
1316 pc += 2;
1317 break;
1318 }
6d82d43b 1319 case 5: /* bnez */
12f02c2a
AC
1320 {
1321 struct upk_mips16 upk;
1322 int reg;
1323 unpack_mips16 (pc, extension, insn, ritype, &upk);
0b1b3e42 1324 reg = get_frame_register_signed (frame, upk.regx);
12f02c2a
AC
1325 if (reg != 0)
1326 pc += (upk.offset << 1) + 2;
1327 else
1328 pc += 2;
1329 break;
1330 }
6d82d43b 1331 case 12: /* I8 Formats btez btnez */
12f02c2a
AC
1332 {
1333 struct upk_mips16 upk;
1334 int reg;
1335 unpack_mips16 (pc, extension, insn, i8type, &upk);
1336 /* upk.regx contains the opcode */
0b1b3e42 1337 reg = get_frame_register_signed (frame, 24); /* Test register is 24 */
12f02c2a
AC
1338 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1339 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1340 /* pc = add_offset_16(pc,upk.offset) ; */
1341 pc += (upk.offset << 1) + 2;
1342 else
1343 pc += 2;
1344 break;
1345 }
6d82d43b 1346 case 29: /* RR Formats JR, JALR, JALR-RA */
12f02c2a
AC
1347 {
1348 struct upk_mips16 upk;
1349 /* upk.fmt = rrtype; */
1350 op = insn & 0x1f;
1351 if (op == 0)
c5aa993b 1352 {
12f02c2a
AC
1353 int reg;
1354 upk.regx = (insn >> 8) & 0x07;
1355 upk.regy = (insn >> 5) & 0x07;
1356 switch (upk.regy)
c5aa993b 1357 {
12f02c2a
AC
1358 case 0:
1359 reg = upk.regx;
1360 break;
1361 case 1:
1362 reg = 31;
6d82d43b 1363 break; /* Function return instruction */
12f02c2a
AC
1364 case 2:
1365 reg = upk.regx;
1366 break;
1367 default:
1368 reg = 31;
6d82d43b 1369 break; /* BOGUS Guess */
c906108c 1370 }
0b1b3e42 1371 pc = get_frame_register_signed (frame, reg);
c906108c 1372 }
12f02c2a 1373 else
c5aa993b 1374 pc += 2;
12f02c2a
AC
1375 break;
1376 }
1377 case 30:
1378 /* This is an instruction extension. Fetch the real instruction
1379 (which follows the extension) and decode things based on
1380 that. */
1381 {
1382 pc += 2;
0b1b3e42 1383 pc = extended_mips16_next_pc (frame, pc, insn, fetch_mips_16 (pc));
12f02c2a
AC
1384 break;
1385 }
1386 default:
1387 {
1388 pc += 2;
1389 break;
1390 }
c906108c 1391 }
c5aa993b 1392 return pc;
12f02c2a 1393}
c906108c 1394
5a89d8aa 1395static CORE_ADDR
0b1b3e42 1396mips16_next_pc (struct frame_info *frame, CORE_ADDR pc)
12f02c2a
AC
1397{
1398 unsigned int insn = fetch_mips_16 (pc);
0b1b3e42 1399 return extended_mips16_next_pc (frame, pc, 0, insn);
12f02c2a
AC
1400}
1401
1402/* The mips_next_pc function supports single_step when the remote
7e73cedf 1403 target monitor or stub is not developed enough to do a single_step.
12f02c2a
AC
1404 It works by decoding the current instruction and predicting where a
1405 branch will go. This isnt hard because all the data is available.
ce1f96de 1406 The MIPS32 and MIPS16 variants are quite different. */
ad527d2e 1407static CORE_ADDR
0b1b3e42 1408mips_next_pc (struct frame_info *frame, CORE_ADDR pc)
c906108c 1409{
ce1f96de 1410 if (is_mips16_addr (pc))
0b1b3e42 1411 return mips16_next_pc (frame, pc);
c5aa993b 1412 else
0b1b3e42 1413 return mips32_next_pc (frame, pc);
12f02c2a 1414}
c906108c 1415
edfae063
AC
1416struct mips_frame_cache
1417{
1418 CORE_ADDR base;
1419 struct trad_frame_saved_reg *saved_regs;
1420};
1421
29639122
JB
1422/* Set a register's saved stack address in temp_saved_regs. If an
1423 address has already been set for this register, do nothing; this
1424 way we will only recognize the first save of a given register in a
1425 function prologue.
eec63939 1426
f57d151a
UW
1427 For simplicity, save the address in both [0 .. gdbarch_num_regs) and
1428 [gdbarch_num_regs .. 2*gdbarch_num_regs).
1429 Strictly speaking, only the second range is used as it is only second
1430 range (the ABI instead of ISA registers) that comes into play when finding
1431 saved registers in a frame. */
eec63939
AC
1432
1433static void
29639122
JB
1434set_reg_offset (struct mips_frame_cache *this_cache, int regnum,
1435 CORE_ADDR offset)
eec63939 1436{
29639122
JB
1437 if (this_cache != NULL
1438 && this_cache->saved_regs[regnum].addr == -1)
1439 {
f57d151a
UW
1440 this_cache->saved_regs[regnum
1441 + 0 * gdbarch_num_regs (current_gdbarch)].addr
1442 = offset;
1443 this_cache->saved_regs[regnum
1444 + 1 * gdbarch_num_regs (current_gdbarch)].addr
1445 = offset;
29639122 1446 }
eec63939
AC
1447}
1448
eec63939 1449
29639122
JB
1450/* Fetch the immediate value from a MIPS16 instruction.
1451 If the previous instruction was an EXTEND, use it to extend
1452 the upper bits of the immediate value. This is a helper function
1453 for mips16_scan_prologue. */
eec63939 1454
29639122
JB
1455static int
1456mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1457 unsigned short inst, /* current instruction */
1458 int nbits, /* number of bits in imm field */
1459 int scale, /* scale factor to be applied to imm */
1460 int is_signed) /* is the imm field signed? */
eec63939 1461{
29639122 1462 int offset;
eec63939 1463
29639122
JB
1464 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1465 {
1466 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1467 if (offset & 0x8000) /* check for negative extend */
1468 offset = 0 - (0x10000 - (offset & 0xffff));
1469 return offset | (inst & 0x1f);
1470 }
eec63939 1471 else
29639122
JB
1472 {
1473 int max_imm = 1 << nbits;
1474 int mask = max_imm - 1;
1475 int sign_bit = max_imm >> 1;
45c9dd44 1476
29639122
JB
1477 offset = inst & mask;
1478 if (is_signed && (offset & sign_bit))
1479 offset = 0 - (max_imm - offset);
1480 return offset * scale;
1481 }
1482}
eec63939 1483
65596487 1484
29639122
JB
1485/* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1486 the associated FRAME_CACHE if not null.
1487 Return the address of the first instruction past the prologue. */
eec63939 1488
29639122
JB
1489static CORE_ADDR
1490mips16_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1491 struct frame_info *next_frame,
1492 struct mips_frame_cache *this_cache)
1493{
1494 CORE_ADDR cur_pc;
1495 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1496 CORE_ADDR sp;
1497 long frame_offset = 0; /* Size of stack frame. */
1498 long frame_adjust = 0; /* Offset of FP from SP. */
1499 int frame_reg = MIPS_SP_REGNUM;
1500 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1501 unsigned inst = 0; /* current instruction */
1502 unsigned entry_inst = 0; /* the entry instruction */
2207132d 1503 unsigned save_inst = 0; /* the save instruction */
29639122 1504 int reg, offset;
a343eb3c 1505
29639122
JB
1506 int extend_bytes = 0;
1507 int prev_extend_bytes;
1508 CORE_ADDR end_prologue_addr = 0;
72a155b4 1509 struct gdbarch *gdbarch = get_frame_arch (next_frame);
a343eb3c 1510
29639122
JB
1511 /* Can be called when there's no process, and hence when there's no
1512 NEXT_FRAME. */
1513 if (next_frame != NULL)
d2ca4222 1514 sp = frame_unwind_register_signed (next_frame,
72a155b4 1515 gdbarch_num_regs (gdbarch)
d2ca4222 1516 + MIPS_SP_REGNUM);
29639122
JB
1517 else
1518 sp = 0;
eec63939 1519
29639122
JB
1520 if (limit_pc > start_pc + 200)
1521 limit_pc = start_pc + 200;
eec63939 1522
95ac2dcf 1523 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE)
29639122
JB
1524 {
1525 /* Save the previous instruction. If it's an EXTEND, we'll extract
1526 the immediate offset extension from it in mips16_get_imm. */
1527 prev_inst = inst;
eec63939 1528
29639122
JB
1529 /* Fetch and decode the instruction. */
1530 inst = (unsigned short) mips_fetch_instruction (cur_pc);
eec63939 1531
29639122
JB
1532 /* Normally we ignore extend instructions. However, if it is
1533 not followed by a valid prologue instruction, then this
1534 instruction is not part of the prologue either. We must
1535 remember in this case to adjust the end_prologue_addr back
1536 over the extend. */
1537 if ((inst & 0xf800) == 0xf000) /* extend */
1538 {
95ac2dcf 1539 extend_bytes = MIPS_INSN16_SIZE;
29639122
JB
1540 continue;
1541 }
eec63939 1542
29639122
JB
1543 prev_extend_bytes = extend_bytes;
1544 extend_bytes = 0;
eec63939 1545
29639122
JB
1546 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1547 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1548 {
1549 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1550 if (offset < 0) /* negative stack adjustment? */
1551 frame_offset -= offset;
1552 else
1553 /* Exit loop if a positive stack adjustment is found, which
1554 usually means that the stack cleanup code in the function
1555 epilogue is reached. */
1556 break;
1557 }
1558 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1559 {
1560 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1561 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1562 set_reg_offset (this_cache, reg, sp + offset);
1563 }
1564 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1565 {
1566 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1567 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1568 set_reg_offset (this_cache, reg, sp + offset);
1569 }
1570 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1571 {
1572 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
4c7d22cb 1573 set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset);
29639122
JB
1574 }
1575 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1576 {
1577 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
4c7d22cb 1578 set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset);
29639122
JB
1579 }
1580 else if (inst == 0x673d) /* move $s1, $sp */
1581 {
1582 frame_addr = sp;
1583 frame_reg = 17;
1584 }
1585 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1586 {
1587 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1588 frame_addr = sp + offset;
1589 frame_reg = 17;
1590 frame_adjust = offset;
1591 }
1592 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1593 {
1594 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1595 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1596 set_reg_offset (this_cache, reg, frame_addr + offset);
1597 }
1598 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1599 {
1600 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1601 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1602 set_reg_offset (this_cache, reg, frame_addr + offset);
1603 }
1604 else if ((inst & 0xf81f) == 0xe809
1605 && (inst & 0x700) != 0x700) /* entry */
1606 entry_inst = inst; /* save for later processing */
2207132d
MR
1607 else if ((inst & 0xff80) == 0x6480) /* save */
1608 {
1609 save_inst = inst; /* save for later processing */
1610 if (prev_extend_bytes) /* extend */
1611 save_inst |= prev_inst << 16;
1612 }
29639122 1613 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
95ac2dcf 1614 cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */
29639122
JB
1615 else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
1616 {
1617 /* This instruction is part of the prologue, but we don't
1618 need to do anything special to handle it. */
1619 }
1620 else
1621 {
1622 /* This instruction is not an instruction typically found
1623 in a prologue, so we must have reached the end of the
1624 prologue. */
1625 if (end_prologue_addr == 0)
1626 end_prologue_addr = cur_pc - prev_extend_bytes;
1627 }
1628 }
eec63939 1629
29639122
JB
1630 /* The entry instruction is typically the first instruction in a function,
1631 and it stores registers at offsets relative to the value of the old SP
1632 (before the prologue). But the value of the sp parameter to this
1633 function is the new SP (after the prologue has been executed). So we
1634 can't calculate those offsets until we've seen the entire prologue,
1635 and can calculate what the old SP must have been. */
1636 if (entry_inst != 0)
1637 {
1638 int areg_count = (entry_inst >> 8) & 7;
1639 int sreg_count = (entry_inst >> 6) & 3;
eec63939 1640
29639122
JB
1641 /* The entry instruction always subtracts 32 from the SP. */
1642 frame_offset += 32;
1643
1644 /* Now we can calculate what the SP must have been at the
1645 start of the function prologue. */
1646 sp += frame_offset;
1647
1648 /* Check if a0-a3 were saved in the caller's argument save area. */
1649 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
1650 {
1651 set_reg_offset (this_cache, reg, sp + offset);
72a155b4 1652 offset += mips_abi_regsize (gdbarch);
29639122
JB
1653 }
1654
1655 /* Check if the ra register was pushed on the stack. */
1656 offset = -4;
1657 if (entry_inst & 0x20)
1658 {
4c7d22cb 1659 set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset);
72a155b4 1660 offset -= mips_abi_regsize (gdbarch);
29639122
JB
1661 }
1662
1663 /* Check if the s0 and s1 registers were pushed on the stack. */
1664 for (reg = 16; reg < sreg_count + 16; reg++)
1665 {
1666 set_reg_offset (this_cache, reg, sp + offset);
72a155b4 1667 offset -= mips_abi_regsize (gdbarch);
29639122
JB
1668 }
1669 }
1670
2207132d
MR
1671 /* The SAVE instruction is similar to ENTRY, except that defined by the
1672 MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
1673 size of the frame is specified as an immediate field of instruction
1674 and an extended variation exists which lets additional registers and
1675 frame space to be specified. The instruction always treats registers
1676 as 32-bit so its usefulness for 64-bit ABIs is questionable. */
1677 if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4)
1678 {
1679 static int args_table[16] = {
1680 0, 0, 0, 0, 1, 1, 1, 1,
1681 2, 2, 2, 0, 3, 3, 4, -1,
1682 };
1683 static int astatic_table[16] = {
1684 0, 1, 2, 3, 0, 1, 2, 3,
1685 0, 1, 2, 4, 0, 1, 0, -1,
1686 };
1687 int aregs = (save_inst >> 16) & 0xf;
1688 int xsregs = (save_inst >> 24) & 0x7;
1689 int args = args_table[aregs];
1690 int astatic = astatic_table[aregs];
1691 long frame_size;
1692
1693 if (args < 0)
1694 {
1695 warning (_("Invalid number of argument registers encoded in SAVE."));
1696 args = 0;
1697 }
1698 if (astatic < 0)
1699 {
1700 warning (_("Invalid number of static registers encoded in SAVE."));
1701 astatic = 0;
1702 }
1703
1704 /* For standard SAVE the frame size of 0 means 128. */
1705 frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf);
1706 if (frame_size == 0 && (save_inst >> 16) == 0)
1707 frame_size = 16;
1708 frame_size *= 8;
1709 frame_offset += frame_size;
1710
1711 /* Now we can calculate what the SP must have been at the
1712 start of the function prologue. */
1713 sp += frame_offset;
1714
1715 /* Check if A0-A3 were saved in the caller's argument save area. */
1716 for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++)
1717 {
1718 set_reg_offset (this_cache, reg, sp + offset);
1719 offset += mips_abi_regsize (gdbarch);
1720 }
1721
1722 offset = -4;
1723
1724 /* Check if the RA register was pushed on the stack. */
1725 if (save_inst & 0x40)
1726 {
1727 set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset);
1728 offset -= mips_abi_regsize (gdbarch);
1729 }
1730
1731 /* Check if the S8 register was pushed on the stack. */
1732 if (xsregs > 6)
1733 {
1734 set_reg_offset (this_cache, 30, sp + offset);
1735 offset -= mips_abi_regsize (gdbarch);
1736 xsregs--;
1737 }
1738 /* Check if S2-S7 were pushed on the stack. */
1739 for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--)
1740 {
1741 set_reg_offset (this_cache, reg, sp + offset);
1742 offset -= mips_abi_regsize (gdbarch);
1743 }
1744
1745 /* Check if the S1 register was pushed on the stack. */
1746 if (save_inst & 0x10)
1747 {
1748 set_reg_offset (this_cache, 17, sp + offset);
1749 offset -= mips_abi_regsize (gdbarch);
1750 }
1751 /* Check if the S0 register was pushed on the stack. */
1752 if (save_inst & 0x20)
1753 {
1754 set_reg_offset (this_cache, 16, sp + offset);
1755 offset -= mips_abi_regsize (gdbarch);
1756 }
1757
1758 /* Check if A0-A3 were pushed on the stack. */
1759 for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--)
1760 {
1761 set_reg_offset (this_cache, reg, sp + offset);
1762 offset -= mips_abi_regsize (gdbarch);
1763 }
1764 }
1765
29639122
JB
1766 if (this_cache != NULL)
1767 {
1768 this_cache->base =
f57d151a 1769 (frame_unwind_register_signed (next_frame,
72a155b4 1770 gdbarch_num_regs (gdbarch) + frame_reg)
29639122
JB
1771 + frame_offset - frame_adjust);
1772 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
1773 be able to get rid of the assignment below, evetually. But it's
1774 still needed for now. */
72a155b4
UW
1775 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
1776 + mips_regnum (gdbarch)->pc]
1777 = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM];
29639122
JB
1778 }
1779
1780 /* If we didn't reach the end of the prologue when scanning the function
1781 instructions, then set end_prologue_addr to the address of the
1782 instruction immediately after the last one we scanned. */
1783 if (end_prologue_addr == 0)
1784 end_prologue_addr = cur_pc;
1785
1786 return end_prologue_addr;
eec63939
AC
1787}
1788
29639122
JB
1789/* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
1790 Procedures that use the 32-bit instruction set are handled by the
1791 mips_insn32 unwinder. */
1792
1793static struct mips_frame_cache *
1794mips_insn16_frame_cache (struct frame_info *next_frame, void **this_cache)
eec63939 1795{
29639122 1796 struct mips_frame_cache *cache;
eec63939
AC
1797
1798 if ((*this_cache) != NULL)
1799 return (*this_cache);
29639122
JB
1800 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
1801 (*this_cache) = cache;
1802 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
eec63939 1803
29639122
JB
1804 /* Analyze the function prologue. */
1805 {
6de5b849
JB
1806 const CORE_ADDR pc =
1807 frame_unwind_address_in_block (next_frame, NORMAL_FRAME);
29639122 1808 CORE_ADDR start_addr;
eec63939 1809
29639122
JB
1810 find_pc_partial_function (pc, NULL, &start_addr, NULL);
1811 if (start_addr == 0)
1812 start_addr = heuristic_proc_start (pc);
1813 /* We can't analyze the prologue if we couldn't find the begining
1814 of the function. */
1815 if (start_addr == 0)
1816 return cache;
eec63939 1817
29639122
JB
1818 mips16_scan_prologue (start_addr, pc, next_frame, *this_cache);
1819 }
1820
3e8c568d 1821 /* gdbarch_sp_regnum contains the value and not the address. */
72a155b4
UW
1822 trad_frame_set_value (cache->saved_regs,
1823 gdbarch_num_regs (get_frame_arch (next_frame))
1824 + MIPS_SP_REGNUM,
1825 cache->base);
eec63939 1826
29639122 1827 return (*this_cache);
eec63939
AC
1828}
1829
1830static void
29639122
JB
1831mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache,
1832 struct frame_id *this_id)
eec63939 1833{
29639122
JB
1834 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
1835 this_cache);
93d42b30
DJ
1836 (*this_id) = frame_id_build (info->base,
1837 frame_func_unwind (next_frame, NORMAL_FRAME));
eec63939
AC
1838}
1839
1840static void
29639122 1841mips_insn16_frame_prev_register (struct frame_info *next_frame,
eec63939
AC
1842 void **this_cache,
1843 int regnum, int *optimizedp,
1844 enum lval_type *lvalp, CORE_ADDR *addrp,
a8a0fc4c 1845 int *realnump, gdb_byte *valuep)
eec63939 1846{
29639122
JB
1847 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
1848 this_cache);
1849 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
1850 optimizedp, lvalp, addrp, realnump, valuep);
eec63939
AC
1851}
1852
29639122 1853static const struct frame_unwind mips_insn16_frame_unwind =
eec63939
AC
1854{
1855 NORMAL_FRAME,
29639122
JB
1856 mips_insn16_frame_this_id,
1857 mips_insn16_frame_prev_register
eec63939
AC
1858};
1859
1860static const struct frame_unwind *
29639122 1861mips_insn16_frame_sniffer (struct frame_info *next_frame)
eec63939 1862{
6de5b849 1863 CORE_ADDR pc = frame_pc_unwind (next_frame);
0fe7e7c8 1864 if (mips_pc_is_mips16 (pc))
29639122
JB
1865 return &mips_insn16_frame_unwind;
1866 return NULL;
eec63939
AC
1867}
1868
1869static CORE_ADDR
29639122
JB
1870mips_insn16_frame_base_address (struct frame_info *next_frame,
1871 void **this_cache)
eec63939 1872{
29639122
JB
1873 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
1874 this_cache);
1875 return info->base;
eec63939
AC
1876}
1877
29639122 1878static const struct frame_base mips_insn16_frame_base =
eec63939 1879{
29639122
JB
1880 &mips_insn16_frame_unwind,
1881 mips_insn16_frame_base_address,
1882 mips_insn16_frame_base_address,
1883 mips_insn16_frame_base_address
eec63939
AC
1884};
1885
1886static const struct frame_base *
29639122 1887mips_insn16_frame_base_sniffer (struct frame_info *next_frame)
eec63939 1888{
29639122
JB
1889 if (mips_insn16_frame_sniffer (next_frame) != NULL)
1890 return &mips_insn16_frame_base;
eec63939
AC
1891 else
1892 return NULL;
edfae063
AC
1893}
1894
29639122
JB
1895/* Mark all the registers as unset in the saved_regs array
1896 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
1897
1898void
1899reset_saved_regs (struct mips_frame_cache *this_cache)
c906108c 1900{
29639122
JB
1901 if (this_cache == NULL || this_cache->saved_regs == NULL)
1902 return;
1903
1904 {
f57d151a 1905 const int num_regs = gdbarch_num_regs (current_gdbarch);
29639122 1906 int i;
64159455 1907
29639122
JB
1908 for (i = 0; i < num_regs; i++)
1909 {
1910 this_cache->saved_regs[i].addr = -1;
1911 }
1912 }
c906108c
SS
1913}
1914
29639122
JB
1915/* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1916 the associated FRAME_CACHE if not null.
1917 Return the address of the first instruction past the prologue. */
c906108c 1918
875e1767 1919static CORE_ADDR
29639122
JB
1920mips32_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc,
1921 struct frame_info *next_frame,
1922 struct mips_frame_cache *this_cache)
c906108c 1923{
29639122
JB
1924 CORE_ADDR cur_pc;
1925 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
1926 CORE_ADDR sp;
1927 long frame_offset;
1928 int frame_reg = MIPS_SP_REGNUM;
8fa9cfa1 1929
29639122
JB
1930 CORE_ADDR end_prologue_addr = 0;
1931 int seen_sp_adjust = 0;
1932 int load_immediate_bytes = 0;
72a155b4 1933 struct gdbarch *gdbarch = get_frame_arch (next_frame);
7d1e6fb8 1934 int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8);
8fa9cfa1 1935
29639122
JB
1936 /* Can be called when there's no process, and hence when there's no
1937 NEXT_FRAME. */
1938 if (next_frame != NULL)
d2ca4222 1939 sp = frame_unwind_register_signed (next_frame,
72a155b4 1940 gdbarch_num_regs (gdbarch)
d2ca4222 1941 + MIPS_SP_REGNUM);
8fa9cfa1 1942 else
29639122 1943 sp = 0;
9022177c 1944
29639122
JB
1945 if (limit_pc > start_pc + 200)
1946 limit_pc = start_pc + 200;
9022177c 1947
29639122 1948restart:
9022177c 1949
29639122 1950 frame_offset = 0;
95ac2dcf 1951 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE)
9022177c 1952 {
29639122
JB
1953 unsigned long inst, high_word, low_word;
1954 int reg;
9022177c 1955
29639122
JB
1956 /* Fetch the instruction. */
1957 inst = (unsigned long) mips_fetch_instruction (cur_pc);
9022177c 1958
29639122
JB
1959 /* Save some code by pre-extracting some useful fields. */
1960 high_word = (inst >> 16) & 0xffff;
1961 low_word = inst & 0xffff;
1962 reg = high_word & 0x1f;
fe29b929 1963
29639122
JB
1964 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
1965 || high_word == 0x23bd /* addi $sp,$sp,-i */
1966 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
1967 {
1968 if (low_word & 0x8000) /* negative stack adjustment? */
1969 frame_offset += 0x10000 - low_word;
1970 else
1971 /* Exit loop if a positive stack adjustment is found, which
1972 usually means that the stack cleanup code in the function
1973 epilogue is reached. */
1974 break;
1975 seen_sp_adjust = 1;
1976 }
7d1e6fb8
KB
1977 else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
1978 && !regsize_is_64_bits)
29639122
JB
1979 {
1980 set_reg_offset (this_cache, reg, sp + low_word);
1981 }
7d1e6fb8
KB
1982 else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
1983 && regsize_is_64_bits)
29639122
JB
1984 {
1985 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
1986 set_reg_offset (this_cache, reg, sp + low_word);
1987 }
1988 else if (high_word == 0x27be) /* addiu $30,$sp,size */
1989 {
1990 /* Old gcc frame, r30 is virtual frame pointer. */
1991 if ((long) low_word != frame_offset)
1992 frame_addr = sp + low_word;
d2ca4222 1993 else if (next_frame && frame_reg == MIPS_SP_REGNUM)
29639122
JB
1994 {
1995 unsigned alloca_adjust;
a4b8ebc8 1996
29639122 1997 frame_reg = 30;
d2ca4222 1998 frame_addr = frame_unwind_register_signed
72a155b4 1999 (next_frame, gdbarch_num_regs (gdbarch) + 30);
d2ca4222 2000
29639122
JB
2001 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2002 if (alloca_adjust > 0)
2003 {
2004 /* FP > SP + frame_size. This may be because of
2005 an alloca or somethings similar. Fix sp to
2006 "pre-alloca" value, and try again. */
2007 sp += alloca_adjust;
2008 /* Need to reset the status of all registers. Otherwise,
2009 we will hit a guard that prevents the new address
2010 for each register to be recomputed during the second
2011 pass. */
2012 reset_saved_regs (this_cache);
2013 goto restart;
2014 }
2015 }
2016 }
2017 /* move $30,$sp. With different versions of gas this will be either
2018 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2019 Accept any one of these. */
2020 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2021 {
2022 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
d2ca4222 2023 if (next_frame && frame_reg == MIPS_SP_REGNUM)
29639122
JB
2024 {
2025 unsigned alloca_adjust;
c906108c 2026
29639122 2027 frame_reg = 30;
d2ca4222 2028 frame_addr = frame_unwind_register_signed
72a155b4 2029 (next_frame, gdbarch_num_regs (gdbarch) + 30);
d2ca4222 2030
29639122
JB
2031 alloca_adjust = (unsigned) (frame_addr - sp);
2032 if (alloca_adjust > 0)
2033 {
2034 /* FP > SP + frame_size. This may be because of
2035 an alloca or somethings similar. Fix sp to
2036 "pre-alloca" value, and try again. */
2037 sp = frame_addr;
2038 /* Need to reset the status of all registers. Otherwise,
2039 we will hit a guard that prevents the new address
2040 for each register to be recomputed during the second
2041 pass. */
2042 reset_saved_regs (this_cache);
2043 goto restart;
2044 }
2045 }
2046 }
7d1e6fb8
KB
2047 else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
2048 && !regsize_is_64_bits)
29639122
JB
2049 {
2050 set_reg_offset (this_cache, reg, frame_addr + low_word);
2051 }
2052 else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
2053 || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
2054 || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
2055 || high_word == 0x3c1c /* lui $gp,n */
2056 || high_word == 0x279c /* addiu $gp,$gp,n */
2057 || inst == 0x0399e021 /* addu $gp,$gp,$t9 */
2058 || inst == 0x033ce021 /* addu $gp,$t9,$gp */
2059 )
2060 {
2061 /* These instructions are part of the prologue, but we don't
2062 need to do anything special to handle them. */
2063 }
2064 /* The instructions below load $at or $t0 with an immediate
2065 value in preparation for a stack adjustment via
2066 subu $sp,$sp,[$at,$t0]. These instructions could also
2067 initialize a local variable, so we accept them only before
2068 a stack adjustment instruction was seen. */
2069 else if (!seen_sp_adjust
2070 && (high_word == 0x3c01 /* lui $at,n */
2071 || high_word == 0x3c08 /* lui $t0,n */
2072 || high_word == 0x3421 /* ori $at,$at,n */
2073 || high_word == 0x3508 /* ori $t0,$t0,n */
2074 || high_word == 0x3401 /* ori $at,$zero,n */
2075 || high_word == 0x3408 /* ori $t0,$zero,n */
2076 ))
2077 {
95ac2dcf 2078 load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */
29639122
JB
2079 }
2080 else
2081 {
2082 /* This instruction is not an instruction typically found
2083 in a prologue, so we must have reached the end of the
2084 prologue. */
2085 /* FIXME: brobecker/2004-10-10: Can't we just break out of this
2086 loop now? Why would we need to continue scanning the function
2087 instructions? */
2088 if (end_prologue_addr == 0)
2089 end_prologue_addr = cur_pc;
2090 }
a4b8ebc8 2091 }
c906108c 2092
29639122
JB
2093 if (this_cache != NULL)
2094 {
2095 this_cache->base =
f57d151a 2096 (frame_unwind_register_signed (next_frame,
72a155b4 2097 gdbarch_num_regs (gdbarch) + frame_reg)
29639122
JB
2098 + frame_offset);
2099 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
2100 this assignment below, eventually. But it's still needed
2101 for now. */
72a155b4
UW
2102 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
2103 + mips_regnum (gdbarch)->pc]
2104 = this_cache->saved_regs[gdbarch_num_regs (gdbarch)
f57d151a 2105 + MIPS_RA_REGNUM];
29639122 2106 }
c906108c 2107
29639122
JB
2108 /* If we didn't reach the end of the prologue when scanning the function
2109 instructions, then set end_prologue_addr to the address of the
2110 instruction immediately after the last one we scanned. */
2111 /* brobecker/2004-10-10: I don't think this would ever happen, but
2112 we may as well be careful and do our best if we have a null
2113 end_prologue_addr. */
2114 if (end_prologue_addr == 0)
2115 end_prologue_addr = cur_pc;
2116
2117 /* In a frameless function, we might have incorrectly
2118 skipped some load immediate instructions. Undo the skipping
2119 if the load immediate was not followed by a stack adjustment. */
2120 if (load_immediate_bytes && !seen_sp_adjust)
2121 end_prologue_addr -= load_immediate_bytes;
c906108c 2122
29639122 2123 return end_prologue_addr;
c906108c
SS
2124}
2125
29639122
JB
2126/* Heuristic unwinder for procedures using 32-bit instructions (covers
2127 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
2128 instructions (a.k.a. MIPS16) are handled by the mips_insn16
2129 unwinder. */
c906108c 2130
29639122
JB
2131static struct mips_frame_cache *
2132mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache)
c906108c 2133{
29639122 2134 struct mips_frame_cache *cache;
c906108c 2135
29639122
JB
2136 if ((*this_cache) != NULL)
2137 return (*this_cache);
c5aa993b 2138
29639122
JB
2139 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
2140 (*this_cache) = cache;
2141 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
c5aa993b 2142
29639122
JB
2143 /* Analyze the function prologue. */
2144 {
6de5b849
JB
2145 const CORE_ADDR pc =
2146 frame_unwind_address_in_block (next_frame, NORMAL_FRAME);
29639122 2147 CORE_ADDR start_addr;
c906108c 2148
29639122
JB
2149 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2150 if (start_addr == 0)
2151 start_addr = heuristic_proc_start (pc);
2152 /* We can't analyze the prologue if we couldn't find the begining
2153 of the function. */
2154 if (start_addr == 0)
2155 return cache;
c5aa993b 2156
29639122
JB
2157 mips32_scan_prologue (start_addr, pc, next_frame, *this_cache);
2158 }
2159
3e8c568d 2160 /* gdbarch_sp_regnum contains the value and not the address. */
f57d151a 2161 trad_frame_set_value (cache->saved_regs,
72a155b4
UW
2162 gdbarch_num_regs (get_frame_arch (next_frame))
2163 + MIPS_SP_REGNUM,
f57d151a 2164 cache->base);
c5aa993b 2165
29639122 2166 return (*this_cache);
c906108c
SS
2167}
2168
29639122
JB
2169static void
2170mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache,
2171 struct frame_id *this_id)
c906108c 2172{
29639122
JB
2173 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2174 this_cache);
93d42b30
DJ
2175 (*this_id) = frame_id_build (info->base,
2176 frame_func_unwind (next_frame, NORMAL_FRAME));
29639122 2177}
c906108c 2178
29639122
JB
2179static void
2180mips_insn32_frame_prev_register (struct frame_info *next_frame,
2181 void **this_cache,
2182 int regnum, int *optimizedp,
2183 enum lval_type *lvalp, CORE_ADDR *addrp,
a8a0fc4c 2184 int *realnump, gdb_byte *valuep)
29639122
JB
2185{
2186 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2187 this_cache);
2188 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
2189 optimizedp, lvalp, addrp, realnump, valuep);
c906108c
SS
2190}
2191
29639122
JB
2192static const struct frame_unwind mips_insn32_frame_unwind =
2193{
2194 NORMAL_FRAME,
2195 mips_insn32_frame_this_id,
2196 mips_insn32_frame_prev_register
2197};
c906108c 2198
29639122
JB
2199static const struct frame_unwind *
2200mips_insn32_frame_sniffer (struct frame_info *next_frame)
2201{
6de5b849 2202 CORE_ADDR pc = frame_pc_unwind (next_frame);
0fe7e7c8 2203 if (! mips_pc_is_mips16 (pc))
29639122
JB
2204 return &mips_insn32_frame_unwind;
2205 return NULL;
2206}
c906108c 2207
1c645fec 2208static CORE_ADDR
29639122
JB
2209mips_insn32_frame_base_address (struct frame_info *next_frame,
2210 void **this_cache)
c906108c 2211{
29639122
JB
2212 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2213 this_cache);
2214 return info->base;
2215}
c906108c 2216
29639122
JB
2217static const struct frame_base mips_insn32_frame_base =
2218{
2219 &mips_insn32_frame_unwind,
2220 mips_insn32_frame_base_address,
2221 mips_insn32_frame_base_address,
2222 mips_insn32_frame_base_address
2223};
1c645fec 2224
29639122
JB
2225static const struct frame_base *
2226mips_insn32_frame_base_sniffer (struct frame_info *next_frame)
2227{
2228 if (mips_insn32_frame_sniffer (next_frame) != NULL)
2229 return &mips_insn32_frame_base;
a65bbe44 2230 else
29639122
JB
2231 return NULL;
2232}
a65bbe44 2233
29639122
JB
2234static struct trad_frame_cache *
2235mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache)
2236{
2237 CORE_ADDR pc;
2238 CORE_ADDR start_addr;
2239 CORE_ADDR stack_addr;
2240 struct trad_frame_cache *this_trad_cache;
72a155b4 2241 struct gdbarch *gdbarch = get_frame_arch (next_frame);
c906108c 2242
29639122
JB
2243 if ((*this_cache) != NULL)
2244 return (*this_cache);
2245 this_trad_cache = trad_frame_cache_zalloc (next_frame);
2246 (*this_cache) = this_trad_cache;
1c645fec 2247
29639122 2248 /* The return address is in the link register. */
3e8c568d 2249 trad_frame_set_reg_realreg (this_trad_cache,
72a155b4
UW
2250 gdbarch_pc_regnum (gdbarch),
2251 (gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM));
1c645fec 2252
29639122
JB
2253 /* Frame ID, since it's a frameless / stackless function, no stack
2254 space is allocated and SP on entry is the current SP. */
2255 pc = frame_pc_unwind (next_frame);
2256 find_pc_partial_function (pc, NULL, &start_addr, NULL);
4c7d22cb 2257 stack_addr = frame_unwind_register_signed (next_frame, MIPS_SP_REGNUM);
aa6c981f 2258 trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr));
1c645fec 2259
29639122
JB
2260 /* Assume that the frame's base is the same as the
2261 stack-pointer. */
2262 trad_frame_set_this_base (this_trad_cache, stack_addr);
c906108c 2263
29639122
JB
2264 return this_trad_cache;
2265}
c906108c 2266
29639122
JB
2267static void
2268mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache,
2269 struct frame_id *this_id)
2270{
2271 struct trad_frame_cache *this_trad_cache
2272 = mips_stub_frame_cache (next_frame, this_cache);
2273 trad_frame_get_id (this_trad_cache, this_id);
2274}
c906108c 2275
29639122
JB
2276static void
2277mips_stub_frame_prev_register (struct frame_info *next_frame,
2278 void **this_cache,
2279 int regnum, int *optimizedp,
2280 enum lval_type *lvalp, CORE_ADDR *addrp,
a8a0fc4c 2281 int *realnump, gdb_byte *valuep)
29639122
JB
2282{
2283 struct trad_frame_cache *this_trad_cache
2284 = mips_stub_frame_cache (next_frame, this_cache);
2285 trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp,
2286 lvalp, addrp, realnump, valuep);
2287}
c906108c 2288
29639122
JB
2289static const struct frame_unwind mips_stub_frame_unwind =
2290{
2291 NORMAL_FRAME,
2292 mips_stub_frame_this_id,
2293 mips_stub_frame_prev_register
2294};
c906108c 2295
29639122
JB
2296static const struct frame_unwind *
2297mips_stub_frame_sniffer (struct frame_info *next_frame)
2298{
aa6c981f 2299 gdb_byte dummy[4];
979b38e0 2300 struct obj_section *s;
93d42b30 2301 CORE_ADDR pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME);
979b38e0 2302
aa6c981f
DJ
2303 /* Use the stub unwinder for unreadable code. */
2304 if (target_read_memory (frame_pc_unwind (next_frame), dummy, 4) != 0)
2305 return &mips_stub_frame_unwind;
2306
29639122
JB
2307 if (in_plt_section (pc, NULL))
2308 return &mips_stub_frame_unwind;
979b38e0
DJ
2309
2310 /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */
2311 s = find_pc_section (pc);
2312
2313 if (s != NULL
2314 && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section),
2315 ".MIPS.stubs") == 0)
2316 return &mips_stub_frame_unwind;
2317
2318 return NULL;
29639122 2319}
c906108c 2320
29639122
JB
2321static CORE_ADDR
2322mips_stub_frame_base_address (struct frame_info *next_frame,
2323 void **this_cache)
2324{
2325 struct trad_frame_cache *this_trad_cache
2326 = mips_stub_frame_cache (next_frame, this_cache);
2327 return trad_frame_get_this_base (this_trad_cache);
2328}
0fce0821 2329
29639122
JB
2330static const struct frame_base mips_stub_frame_base =
2331{
2332 &mips_stub_frame_unwind,
2333 mips_stub_frame_base_address,
2334 mips_stub_frame_base_address,
2335 mips_stub_frame_base_address
2336};
2337
2338static const struct frame_base *
2339mips_stub_frame_base_sniffer (struct frame_info *next_frame)
2340{
2341 if (mips_stub_frame_sniffer (next_frame) != NULL)
2342 return &mips_stub_frame_base;
2343 else
2344 return NULL;
2345}
2346
29639122 2347/* mips_addr_bits_remove - remove useless address bits */
65596487 2348
29639122
JB
2349static CORE_ADDR
2350mips_addr_bits_remove (CORE_ADDR addr)
65596487 2351{
29639122
JB
2352 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2353 if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
2354 /* This hack is a work-around for existing boards using PMON, the
2355 simulator, and any other 64-bit targets that doesn't have true
2356 64-bit addressing. On these targets, the upper 32 bits of
2357 addresses are ignored by the hardware. Thus, the PC or SP are
2358 likely to have been sign extended to all 1s by instruction
2359 sequences that load 32-bit addresses. For example, a typical
2360 piece of code that loads an address is this:
65596487 2361
29639122
JB
2362 lui $r2, <upper 16 bits>
2363 ori $r2, <lower 16 bits>
65596487 2364
29639122
JB
2365 But the lui sign-extends the value such that the upper 32 bits
2366 may be all 1s. The workaround is simply to mask off these
2367 bits. In the future, gcc may be changed to support true 64-bit
2368 addressing, and this masking will have to be disabled. */
2369 return addr &= 0xffffffffUL;
2370 else
2371 return addr;
65596487
JB
2372}
2373
3d5f6d12
DJ
2374/* Instructions used during single-stepping of atomic sequences. */
2375#define LL_OPCODE 0x30
2376#define LLD_OPCODE 0x34
2377#define SC_OPCODE 0x38
2378#define SCD_OPCODE 0x3c
2379
2380/* Checks for an atomic sequence of instructions beginning with a LL/LLD
2381 instruction and ending with a SC/SCD instruction. If such a sequence
2382 is found, attempt to step through it. A breakpoint is placed at the end of
2383 the sequence. */
2384
2385static int
2386deal_with_atomic_sequence (CORE_ADDR pc)
2387{
2388 CORE_ADDR breaks[2] = {-1, -1};
2389 CORE_ADDR loc = pc;
2390 CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */
2391 unsigned long insn;
2392 int insn_count;
2393 int index;
2394 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
2395 const int atomic_sequence_length = 16; /* Instruction sequence length. */
2396
2397 if (pc & 0x01)
2398 return 0;
2399
2400 insn = mips_fetch_instruction (loc);
2401 /* Assume all atomic sequences start with a ll/lld instruction. */
2402 if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE)
2403 return 0;
2404
2405 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
2406 instructions. */
2407 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
2408 {
2409 int is_branch = 0;
2410 loc += MIPS_INSN32_SIZE;
2411 insn = mips_fetch_instruction (loc);
2412
2413 /* Assume that there is at most one branch in the atomic
2414 sequence. If a branch is found, put a breakpoint in its
2415 destination address. */
2416 switch (itype_op (insn))
2417 {
2418 case 0: /* SPECIAL */
2419 if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */
2420 return 0; /* fallback to the standard single-step code. */
2421 break;
2422 case 1: /* REGIMM */
2423 is_branch = ((itype_rt (insn) & 0xc0) == 0); /* B{LT,GE}Z* */
2424 break;
2425 case 2: /* J */
2426 case 3: /* JAL */
2427 return 0; /* fallback to the standard single-step code. */
2428 case 4: /* BEQ */
2429 case 5: /* BNE */
2430 case 6: /* BLEZ */
2431 case 7: /* BGTZ */
2432 case 20: /* BEQL */
2433 case 21: /* BNEL */
2434 case 22: /* BLEZL */
2435 case 23: /* BGTTL */
2436 is_branch = 1;
2437 break;
2438 case 17: /* COP1 */
2439 case 18: /* COP2 */
2440 case 19: /* COP3 */
2441 is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
2442 break;
2443 }
2444 if (is_branch)
2445 {
2446 branch_bp = loc + mips32_relative_offset (insn) + 4;
2447 if (last_breakpoint >= 1)
2448 return 0; /* More than one branch found, fallback to the
2449 standard single-step code. */
2450 breaks[1] = branch_bp;
2451 last_breakpoint++;
2452 }
2453
2454 if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE)
2455 break;
2456 }
2457
2458 /* Assume that the atomic sequence ends with a sc/scd instruction. */
2459 if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE)
2460 return 0;
2461
2462 loc += MIPS_INSN32_SIZE;
2463
2464 /* Insert a breakpoint right after the end of the atomic sequence. */
2465 breaks[0] = loc;
2466
2467 /* Check for duplicated breakpoints. Check also for a breakpoint
2468 placed (branch instruction's destination) in the atomic sequence */
2469 if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0])
2470 last_breakpoint = 0;
2471
2472 /* Effectively inserts the breakpoints. */
2473 for (index = 0; index <= last_breakpoint; index++)
2474 insert_single_step_breakpoint (breaks[index]);
2475
2476 return 1;
2477}
2478
29639122
JB
2479/* mips_software_single_step() is called just before we want to resume
2480 the inferior, if we want to single-step it but there is no hardware
2481 or kernel single-step support (MIPS on GNU/Linux for example). We find
e0cd558a 2482 the target of the coming instruction and breakpoint it. */
29639122 2483
e6590a1b 2484int
0b1b3e42 2485mips_software_single_step (struct frame_info *frame)
c906108c 2486{
8181d85f 2487 CORE_ADDR pc, next_pc;
65596487 2488
0b1b3e42 2489 pc = get_frame_pc (frame);
3d5f6d12
DJ
2490 if (deal_with_atomic_sequence (pc))
2491 return 1;
2492
0b1b3e42 2493 next_pc = mips_next_pc (frame, pc);
e6590a1b 2494
e0cd558a 2495 insert_single_step_breakpoint (next_pc);
e6590a1b 2496 return 1;
29639122 2497}
a65bbe44 2498
29639122
JB
2499/* Test whether the PC points to the return instruction at the
2500 end of a function. */
65596487 2501
29639122
JB
2502static int
2503mips_about_to_return (CORE_ADDR pc)
2504{
0fe7e7c8 2505 if (mips_pc_is_mips16 (pc))
29639122
JB
2506 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2507 generates a "jr $ra"; other times it generates code to load
2508 the return address from the stack to an accessible register (such
2509 as $a3), then a "jr" using that register. This second case
2510 is almost impossible to distinguish from an indirect jump
2511 used for switch statements, so we don't even try. */
2512 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
2513 else
2514 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
2515}
c906108c 2516
c906108c 2517
29639122
JB
2518/* This fencepost looks highly suspicious to me. Removing it also
2519 seems suspicious as it could affect remote debugging across serial
2520 lines. */
c906108c 2521
29639122
JB
2522static CORE_ADDR
2523heuristic_proc_start (CORE_ADDR pc)
2524{
2525 CORE_ADDR start_pc;
2526 CORE_ADDR fence;
2527 int instlen;
2528 int seen_adjsp = 0;
65596487 2529
bf6ae464 2530 pc = gdbarch_addr_bits_remove (current_gdbarch, pc);
29639122
JB
2531 start_pc = pc;
2532 fence = start_pc - heuristic_fence_post;
2533 if (start_pc == 0)
2534 return 0;
65596487 2535
29639122
JB
2536 if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS)
2537 fence = VM_MIN_ADDRESS;
65596487 2538
95ac2dcf 2539 instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE;
98b4dd94 2540
29639122
JB
2541 /* search back for previous return */
2542 for (start_pc -= instlen;; start_pc -= instlen)
2543 if (start_pc < fence)
2544 {
2545 /* It's not clear to me why we reach this point when
2546 stop_soon, but with this test, at least we
2547 don't print out warnings for every child forked (eg, on
2548 decstation). 22apr93 rich@cygnus.com. */
2549 if (stop_soon == NO_STOP_QUIETLY)
2550 {
2551 static int blurb_printed = 0;
98b4dd94 2552
8a3fe4f8 2553 warning (_("GDB can't find the start of the function at 0x%s."),
29639122
JB
2554 paddr_nz (pc));
2555
2556 if (!blurb_printed)
2557 {
2558 /* This actually happens frequently in embedded
2559 development, when you first connect to a board
2560 and your stack pointer and pc are nowhere in
2561 particular. This message needs to give people
2562 in that situation enough information to
2563 determine that it's no big deal. */
2564 printf_filtered ("\n\
2565 GDB is unable to find the start of the function at 0x%s\n\
2566and thus can't determine the size of that function's stack frame.\n\
2567This means that GDB may be unable to access that stack frame, or\n\
2568the frames below it.\n\
2569 This problem is most likely caused by an invalid program counter or\n\
2570stack pointer.\n\
2571 However, if you think GDB should simply search farther back\n\
2572from 0x%s for code which looks like the beginning of a\n\
2573function, you can increase the range of the search using the `set\n\
2574heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc));
2575 blurb_printed = 1;
2576 }
2577 }
2578
2579 return 0;
2580 }
0fe7e7c8 2581 else if (mips_pc_is_mips16 (start_pc))
29639122
JB
2582 {
2583 unsigned short inst;
2584
2585 /* On MIPS16, any one of the following is likely to be the
2586 start of a function:
193774b3
MR
2587 extend save
2588 save
29639122
JB
2589 entry
2590 addiu sp,-n
2591 daddiu sp,-n
2592 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
2593 inst = mips_fetch_instruction (start_pc);
193774b3
MR
2594 if ((inst & 0xff80) == 0x6480) /* save */
2595 {
2596 if (start_pc - instlen >= fence)
2597 {
2598 inst = mips_fetch_instruction (start_pc - instlen);
2599 if ((inst & 0xf800) == 0xf000) /* extend */
2600 start_pc -= instlen;
2601 }
2602 break;
2603 }
2604 else if (((inst & 0xf81f) == 0xe809
2605 && (inst & 0x700) != 0x700) /* entry */
2606 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2607 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2608 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
29639122
JB
2609 break;
2610 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2611 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2612 seen_adjsp = 1;
2613 else
2614 seen_adjsp = 0;
2615 }
2616 else if (mips_about_to_return (start_pc))
2617 {
4c7d22cb 2618 /* Skip return and its delay slot. */
95ac2dcf 2619 start_pc += 2 * MIPS_INSN32_SIZE;
29639122
JB
2620 break;
2621 }
2622
2623 return start_pc;
c906108c
SS
2624}
2625
6c0d6680
DJ
2626struct mips_objfile_private
2627{
2628 bfd_size_type size;
2629 char *contents;
2630};
2631
f09ded24
AC
2632/* According to the current ABI, should the type be passed in a
2633 floating-point register (assuming that there is space)? When there
a1f5b845 2634 is no FPU, FP are not even considered as possible candidates for
f09ded24
AC
2635 FP registers and, consequently this returns false - forces FP
2636 arguments into integer registers. */
2637
2638static int
2639fp_register_arg_p (enum type_code typecode, struct type *arg_type)
2640{
2641 return ((typecode == TYPE_CODE_FLT
2642 || (MIPS_EABI
6d82d43b
AC
2643 && (typecode == TYPE_CODE_STRUCT
2644 || typecode == TYPE_CODE_UNION)
f09ded24 2645 && TYPE_NFIELDS (arg_type) == 1
b2d6f210
MS
2646 && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0)))
2647 == TYPE_CODE_FLT))
c86b5b38 2648 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
f09ded24
AC
2649}
2650
49e790b0
DJ
2651/* On o32, argument passing in GPRs depends on the alignment of the type being
2652 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2653
2654static int
2655mips_type_needs_double_align (struct type *type)
2656{
2657 enum type_code typecode = TYPE_CODE (type);
361d1df0 2658
49e790b0
DJ
2659 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2660 return 1;
2661 else if (typecode == TYPE_CODE_STRUCT)
2662 {
2663 if (TYPE_NFIELDS (type) < 1)
2664 return 0;
2665 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2666 }
2667 else if (typecode == TYPE_CODE_UNION)
2668 {
361d1df0 2669 int i, n;
49e790b0
DJ
2670
2671 n = TYPE_NFIELDS (type);
2672 for (i = 0; i < n; i++)
2673 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2674 return 1;
2675 return 0;
2676 }
2677 return 0;
2678}
2679
dc604539
AC
2680/* Adjust the address downward (direction of stack growth) so that it
2681 is correctly aligned for a new stack frame. */
2682static CORE_ADDR
2683mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2684{
5b03f266 2685 return align_down (addr, 16);
dc604539
AC
2686}
2687
f7ab6ec6 2688static CORE_ADDR
7d9b040b 2689mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
6d82d43b
AC
2690 struct regcache *regcache, CORE_ADDR bp_addr,
2691 int nargs, struct value **args, CORE_ADDR sp,
2692 int struct_return, CORE_ADDR struct_addr)
c906108c
SS
2693{
2694 int argreg;
2695 int float_argreg;
2696 int argnum;
2697 int len = 0;
2698 int stack_offset = 0;
480d3dd2 2699 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7d9b040b 2700 CORE_ADDR func_addr = find_function_addr (function, NULL);
1a69e1e4 2701 int regsize = mips_abi_regsize (gdbarch);
c906108c 2702
25ab4790
AC
2703 /* For shared libraries, "t9" needs to point at the function
2704 address. */
4c7d22cb 2705 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
25ab4790
AC
2706
2707 /* Set the return address register to point to the entry point of
2708 the program, where a breakpoint lies in wait. */
4c7d22cb 2709 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
25ab4790 2710
c906108c 2711 /* First ensure that the stack and structure return address (if any)
cb3d25d1
MS
2712 are properly aligned. The stack has to be at least 64-bit
2713 aligned even on 32-bit machines, because doubles must be 64-bit
2714 aligned. For n32 and n64, stack frames need to be 128-bit
2715 aligned, so we round to this widest known alignment. */
2716
5b03f266
AC
2717 sp = align_down (sp, 16);
2718 struct_addr = align_down (struct_addr, 16);
c5aa993b 2719
46e0f506 2720 /* Now make space on the stack for the args. We allocate more
c906108c 2721 than necessary for EABI, because the first few arguments are
46e0f506 2722 passed in registers, but that's OK. */
c906108c 2723 for (argnum = 0; argnum < nargs; argnum++)
1a69e1e4 2724 len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize);
5b03f266 2725 sp -= align_up (len, 16);
c906108c 2726
9ace0497 2727 if (mips_debug)
6d82d43b 2728 fprintf_unfiltered (gdb_stdlog,
5b03f266
AC
2729 "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n",
2730 paddr_nz (sp), (long) align_up (len, 16));
9ace0497 2731
c906108c 2732 /* Initialize the integer and float register pointers. */
4c7d22cb 2733 argreg = MIPS_A0_REGNUM;
72a155b4 2734 float_argreg = mips_fpa0_regnum (gdbarch);
c906108c 2735
46e0f506 2736 /* The struct_return pointer occupies the first parameter-passing reg. */
c906108c 2737 if (struct_return)
9ace0497
AC
2738 {
2739 if (mips_debug)
2740 fprintf_unfiltered (gdb_stdlog,
25ab4790 2741 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
cb3d25d1 2742 argreg, paddr_nz (struct_addr));
9c9acae0 2743 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
9ace0497 2744 }
c906108c
SS
2745
2746 /* Now load as many as possible of the first arguments into
2747 registers, and push the rest onto the stack. Loop thru args
2748 from first to last. */
2749 for (argnum = 0; argnum < nargs; argnum++)
2750 {
47a35522
MK
2751 const gdb_byte *val;
2752 gdb_byte valbuf[MAX_REGISTER_SIZE];
ea7c478f 2753 struct value *arg = args[argnum];
4991999e 2754 struct type *arg_type = check_typedef (value_type (arg));
c906108c
SS
2755 int len = TYPE_LENGTH (arg_type);
2756 enum type_code typecode = TYPE_CODE (arg_type);
2757
9ace0497
AC
2758 if (mips_debug)
2759 fprintf_unfiltered (gdb_stdlog,
25ab4790 2760 "mips_eabi_push_dummy_call: %d len=%d type=%d",
acdb74a0 2761 argnum + 1, len, (int) typecode);
9ace0497 2762
c906108c 2763 /* The EABI passes structures that do not fit in a register by
46e0f506 2764 reference. */
1a69e1e4 2765 if (len > regsize
9ace0497 2766 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
c906108c 2767 {
1a69e1e4 2768 store_unsigned_integer (valbuf, regsize, VALUE_ADDRESS (arg));
c906108c 2769 typecode = TYPE_CODE_PTR;
1a69e1e4 2770 len = regsize;
c906108c 2771 val = valbuf;
9ace0497
AC
2772 if (mips_debug)
2773 fprintf_unfiltered (gdb_stdlog, " push");
c906108c
SS
2774 }
2775 else
47a35522 2776 val = value_contents (arg);
c906108c
SS
2777
2778 /* 32-bit ABIs always start floating point arguments in an
acdb74a0
AC
2779 even-numbered floating point register. Round the FP register
2780 up before the check to see if there are any FP registers
46e0f506
MS
2781 left. Non MIPS_EABI targets also pass the FP in the integer
2782 registers so also round up normal registers. */
1a69e1e4 2783 if (regsize < 8 && fp_register_arg_p (typecode, arg_type))
acdb74a0
AC
2784 {
2785 if ((float_argreg & 1))
2786 float_argreg++;
2787 }
c906108c
SS
2788
2789 /* Floating point arguments passed in registers have to be
2790 treated specially. On 32-bit architectures, doubles
c5aa993b
JM
2791 are passed in register pairs; the even register gets
2792 the low word, and the odd register gets the high word.
2793 On non-EABI processors, the first two floating point arguments are
2794 also copied to general registers, because MIPS16 functions
2795 don't use float registers for arguments. This duplication of
2796 arguments in general registers can't hurt non-MIPS16 functions
2797 because those registers are normally skipped. */
1012bd0e
EZ
2798 /* MIPS_EABI squeezes a struct that contains a single floating
2799 point value into an FP register instead of pushing it onto the
46e0f506 2800 stack. */
f09ded24
AC
2801 if (fp_register_arg_p (typecode, arg_type)
2802 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
c906108c 2803 {
6da397e0
KB
2804 /* EABI32 will pass doubles in consecutive registers, even on
2805 64-bit cores. At one time, we used to check the size of
2806 `float_argreg' to determine whether or not to pass doubles
2807 in consecutive registers, but this is not sufficient for
2808 making the ABI determination. */
2809 if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32)
c906108c 2810 {
72a155b4 2811 int low_offset = gdbarch_byte_order (gdbarch)
4c6b5505 2812 == BFD_ENDIAN_BIG ? 4 : 0;
c906108c
SS
2813 unsigned long regval;
2814
2815 /* Write the low word of the double to the even register(s). */
c5aa993b 2816 regval = extract_unsigned_integer (val + low_offset, 4);
9ace0497 2817 if (mips_debug)
acdb74a0 2818 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
9ace0497 2819 float_argreg, phex (regval, 4));
9c9acae0 2820 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
c906108c
SS
2821
2822 /* Write the high word of the double to the odd register(s). */
c5aa993b 2823 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
9ace0497 2824 if (mips_debug)
acdb74a0 2825 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
9ace0497 2826 float_argreg, phex (regval, 4));
9c9acae0 2827 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
c906108c
SS
2828 }
2829 else
2830 {
2831 /* This is a floating point value that fits entirely
2832 in a single register. */
53a5351d 2833 /* On 32 bit ABI's the float_argreg is further adjusted
6d82d43b 2834 above to ensure that it is even register aligned. */
9ace0497
AC
2835 LONGEST regval = extract_unsigned_integer (val, len);
2836 if (mips_debug)
acdb74a0 2837 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
9ace0497 2838 float_argreg, phex (regval, len));
9c9acae0 2839 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
c906108c
SS
2840 }
2841 }
2842 else
2843 {
2844 /* Copy the argument to general registers or the stack in
2845 register-sized pieces. Large arguments are split between
2846 registers and stack. */
1a69e1e4
DJ
2847 /* Note: structs whose size is not a multiple of regsize
2848 are treated specially: Irix cc passes
d5ac5a39
AC
2849 them in registers where gcc sometimes puts them on the
2850 stack. For maximum compatibility, we will put them in
2851 both places. */
1a69e1e4 2852 int odd_sized_struct = (len > regsize && len % regsize != 0);
46e0f506 2853
f09ded24 2854 /* Note: Floating-point values that didn't fit into an FP
6d82d43b 2855 register are only written to memory. */
c906108c
SS
2856 while (len > 0)
2857 {
ebafbe83 2858 /* Remember if the argument was written to the stack. */
566f0f7a 2859 int stack_used_p = 0;
1a69e1e4 2860 int partial_len = (len < regsize ? len : regsize);
c906108c 2861
acdb74a0
AC
2862 if (mips_debug)
2863 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
2864 partial_len);
2865
566f0f7a 2866 /* Write this portion of the argument to the stack. */
f09ded24
AC
2867 if (argreg > MIPS_LAST_ARG_REGNUM
2868 || odd_sized_struct
2869 || fp_register_arg_p (typecode, arg_type))
c906108c 2870 {
c906108c
SS
2871 /* Should shorter than int integer values be
2872 promoted to int before being stored? */
c906108c 2873 int longword_offset = 0;
9ace0497 2874 CORE_ADDR addr;
566f0f7a 2875 stack_used_p = 1;
72a155b4 2876 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
7a292a7a 2877 {
1a69e1e4 2878 if (regsize == 8
480d3dd2
AC
2879 && (typecode == TYPE_CODE_INT
2880 || typecode == TYPE_CODE_PTR
6d82d43b 2881 || typecode == TYPE_CODE_FLT) && len <= 4)
1a69e1e4 2882 longword_offset = regsize - len;
480d3dd2
AC
2883 else if ((typecode == TYPE_CODE_STRUCT
2884 || typecode == TYPE_CODE_UNION)
1a69e1e4
DJ
2885 && TYPE_LENGTH (arg_type) < regsize)
2886 longword_offset = regsize - len;
7a292a7a 2887 }
c5aa993b 2888
9ace0497
AC
2889 if (mips_debug)
2890 {
cb3d25d1
MS
2891 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
2892 paddr_nz (stack_offset));
2893 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
2894 paddr_nz (longword_offset));
9ace0497 2895 }
361d1df0 2896
9ace0497
AC
2897 addr = sp + stack_offset + longword_offset;
2898
2899 if (mips_debug)
2900 {
2901 int i;
6d82d43b 2902 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
cb3d25d1 2903 paddr_nz (addr));
9ace0497
AC
2904 for (i = 0; i < partial_len; i++)
2905 {
6d82d43b 2906 fprintf_unfiltered (gdb_stdlog, "%02x",
cb3d25d1 2907 val[i] & 0xff);
9ace0497
AC
2908 }
2909 }
2910 write_memory (addr, val, partial_len);
c906108c
SS
2911 }
2912
f09ded24
AC
2913 /* Note!!! This is NOT an else clause. Odd sized
2914 structs may go thru BOTH paths. Floating point
46e0f506 2915 arguments will not. */
566f0f7a 2916 /* Write this portion of the argument to a general
6d82d43b 2917 purpose register. */
f09ded24
AC
2918 if (argreg <= MIPS_LAST_ARG_REGNUM
2919 && !fp_register_arg_p (typecode, arg_type))
c906108c 2920 {
6d82d43b
AC
2921 LONGEST regval =
2922 extract_unsigned_integer (val, partial_len);
c906108c 2923
9ace0497 2924 if (mips_debug)
acdb74a0 2925 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
9ace0497 2926 argreg,
1a69e1e4 2927 phex (regval, regsize));
9c9acae0 2928 regcache_cooked_write_unsigned (regcache, argreg, regval);
c906108c 2929 argreg++;
c906108c 2930 }
c5aa993b 2931
c906108c
SS
2932 len -= partial_len;
2933 val += partial_len;
2934
566f0f7a 2935 /* Compute the the offset into the stack at which we
6d82d43b 2936 will copy the next parameter.
566f0f7a 2937
566f0f7a 2938 In the new EABI (and the NABI32), the stack_offset
46e0f506 2939 only needs to be adjusted when it has been used. */
c906108c 2940
46e0f506 2941 if (stack_used_p)
1a69e1e4 2942 stack_offset += align_up (partial_len, regsize);
c906108c
SS
2943 }
2944 }
9ace0497
AC
2945 if (mips_debug)
2946 fprintf_unfiltered (gdb_stdlog, "\n");
c906108c
SS
2947 }
2948
f10683bb 2949 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
310e9b6a 2950
0f71a2f6
JM
2951 /* Return adjusted stack pointer. */
2952 return sp;
2953}
2954
a1f5b845 2955/* Determine the return value convention being used. */
6d82d43b 2956
9c8fdbfa
AC
2957static enum return_value_convention
2958mips_eabi_return_value (struct gdbarch *gdbarch,
2959 struct type *type, struct regcache *regcache,
47a35522 2960 gdb_byte *readbuf, const gdb_byte *writebuf)
6d82d43b 2961{
9c8fdbfa
AC
2962 if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch))
2963 return RETURN_VALUE_STRUCT_CONVENTION;
2964 if (readbuf)
2965 memset (readbuf, 0, TYPE_LENGTH (type));
2966 return RETURN_VALUE_REGISTER_CONVENTION;
6d82d43b
AC
2967}
2968
6d82d43b
AC
2969
2970/* N32/N64 ABI stuff. */
ebafbe83 2971
8d26208a
DJ
2972/* Search for a naturally aligned double at OFFSET inside a struct
2973 ARG_TYPE. The N32 / N64 ABIs pass these in floating point
2974 registers. */
2975
2976static int
2977mips_n32n64_fp_arg_chunk_p (struct type *arg_type, int offset)
2978{
2979 int i;
2980
2981 if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT)
2982 return 0;
2983
2984 if (MIPS_FPU_TYPE != MIPS_FPU_DOUBLE)
2985 return 0;
2986
2987 if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE)
2988 return 0;
2989
2990 for (i = 0; i < TYPE_NFIELDS (arg_type); i++)
2991 {
2992 int pos;
2993 struct type *field_type;
2994
2995 /* We're only looking at normal fields. */
2996 if (TYPE_FIELD_STATIC (arg_type, i)
2997 || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0)
2998 continue;
2999
3000 /* If we have gone past the offset, there is no double to pass. */
3001 pos = TYPE_FIELD_BITPOS (arg_type, i) / 8;
3002 if (pos > offset)
3003 return 0;
3004
3005 field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i));
3006
3007 /* If this field is entirely before the requested offset, go
3008 on to the next one. */
3009 if (pos + TYPE_LENGTH (field_type) <= offset)
3010 continue;
3011
3012 /* If this is our special aligned double, we can stop. */
3013 if (TYPE_CODE (field_type) == TYPE_CODE_FLT
3014 && TYPE_LENGTH (field_type) == MIPS64_REGSIZE)
3015 return 1;
3016
3017 /* This field starts at or before the requested offset, and
3018 overlaps it. If it is a structure, recurse inwards. */
3019 return mips_n32n64_fp_arg_chunk_p (field_type, offset - pos);
3020 }
3021
3022 return 0;
3023}
3024
f7ab6ec6 3025static CORE_ADDR
7d9b040b 3026mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
6d82d43b
AC
3027 struct regcache *regcache, CORE_ADDR bp_addr,
3028 int nargs, struct value **args, CORE_ADDR sp,
3029 int struct_return, CORE_ADDR struct_addr)
cb3d25d1
MS
3030{
3031 int argreg;
3032 int float_argreg;
3033 int argnum;
3034 int len = 0;
3035 int stack_offset = 0;
480d3dd2 3036 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7d9b040b 3037 CORE_ADDR func_addr = find_function_addr (function, NULL);
cb3d25d1 3038
25ab4790
AC
3039 /* For shared libraries, "t9" needs to point at the function
3040 address. */
4c7d22cb 3041 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
25ab4790
AC
3042
3043 /* Set the return address register to point to the entry point of
3044 the program, where a breakpoint lies in wait. */
4c7d22cb 3045 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
25ab4790 3046
cb3d25d1
MS
3047 /* First ensure that the stack and structure return address (if any)
3048 are properly aligned. The stack has to be at least 64-bit
3049 aligned even on 32-bit machines, because doubles must be 64-bit
3050 aligned. For n32 and n64, stack frames need to be 128-bit
3051 aligned, so we round to this widest known alignment. */
3052
5b03f266
AC
3053 sp = align_down (sp, 16);
3054 struct_addr = align_down (struct_addr, 16);
cb3d25d1
MS
3055
3056 /* Now make space on the stack for the args. */
3057 for (argnum = 0; argnum < nargs; argnum++)
1a69e1e4 3058 len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE);
5b03f266 3059 sp -= align_up (len, 16);
cb3d25d1
MS
3060
3061 if (mips_debug)
6d82d43b 3062 fprintf_unfiltered (gdb_stdlog,
5b03f266
AC
3063 "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n",
3064 paddr_nz (sp), (long) align_up (len, 16));
cb3d25d1
MS
3065
3066 /* Initialize the integer and float register pointers. */
4c7d22cb 3067 argreg = MIPS_A0_REGNUM;
72a155b4 3068 float_argreg = mips_fpa0_regnum (gdbarch);
cb3d25d1 3069
46e0f506 3070 /* The struct_return pointer occupies the first parameter-passing reg. */
cb3d25d1
MS
3071 if (struct_return)
3072 {
3073 if (mips_debug)
3074 fprintf_unfiltered (gdb_stdlog,
25ab4790 3075 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
cb3d25d1 3076 argreg, paddr_nz (struct_addr));
9c9acae0 3077 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
cb3d25d1
MS
3078 }
3079
3080 /* Now load as many as possible of the first arguments into
3081 registers, and push the rest onto the stack. Loop thru args
3082 from first to last. */
3083 for (argnum = 0; argnum < nargs; argnum++)
3084 {
47a35522 3085 const gdb_byte *val;
cb3d25d1 3086 struct value *arg = args[argnum];
4991999e 3087 struct type *arg_type = check_typedef (value_type (arg));
cb3d25d1
MS
3088 int len = TYPE_LENGTH (arg_type);
3089 enum type_code typecode = TYPE_CODE (arg_type);
3090
3091 if (mips_debug)
3092 fprintf_unfiltered (gdb_stdlog,
25ab4790 3093 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
cb3d25d1
MS
3094 argnum + 1, len, (int) typecode);
3095
47a35522 3096 val = value_contents (arg);
cb3d25d1
MS
3097
3098 if (fp_register_arg_p (typecode, arg_type)
8d26208a 3099 && argreg <= MIPS_LAST_ARG_REGNUM)
cb3d25d1
MS
3100 {
3101 /* This is a floating point value that fits entirely
3102 in a single register. */
cb3d25d1
MS
3103 LONGEST regval = extract_unsigned_integer (val, len);
3104 if (mips_debug)
3105 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3106 float_argreg, phex (regval, len));
8d26208a 3107 regcache_cooked_write_unsigned (regcache, float_argreg, regval);
cb3d25d1
MS
3108
3109 if (mips_debug)
3110 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3111 argreg, phex (regval, len));
9c9acae0 3112 regcache_cooked_write_unsigned (regcache, argreg, regval);
8d26208a
DJ
3113 float_argreg++;
3114 argreg++;
cb3d25d1
MS
3115 }
3116 else
3117 {
3118 /* Copy the argument to general registers or the stack in
3119 register-sized pieces. Large arguments are split between
3120 registers and stack. */
ab2e1992
MR
3121 /* For N32/N64, structs, unions, or other composite types are
3122 treated as a sequence of doublewords, and are passed in integer
3123 or floating point registers as though they were simple scalar
3124 parameters to the extent that they fit, with any excess on the
3125 stack packed according to the normal memory layout of the
3126 object.
3127 The caller does not reserve space for the register arguments;
3128 the callee is responsible for reserving it if required. */
cb3d25d1 3129 /* Note: Floating-point values that didn't fit into an FP
6d82d43b 3130 register are only written to memory. */
cb3d25d1
MS
3131 while (len > 0)
3132 {
ad018eee 3133 /* Remember if the argument was written to the stack. */
cb3d25d1 3134 int stack_used_p = 0;
1a69e1e4 3135 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
cb3d25d1
MS
3136
3137 if (mips_debug)
3138 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3139 partial_len);
3140
8d26208a
DJ
3141 if (fp_register_arg_p (typecode, arg_type))
3142 gdb_assert (argreg > MIPS_LAST_ARG_REGNUM);
3143
cb3d25d1 3144 /* Write this portion of the argument to the stack. */
ab2e1992 3145 if (argreg > MIPS_LAST_ARG_REGNUM)
cb3d25d1
MS
3146 {
3147 /* Should shorter than int integer values be
3148 promoted to int before being stored? */
3149 int longword_offset = 0;
3150 CORE_ADDR addr;
3151 stack_used_p = 1;
72a155b4 3152 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
cb3d25d1 3153 {
1a69e1e4
DJ
3154 if ((typecode == TYPE_CODE_INT
3155 || typecode == TYPE_CODE_PTR
3156 || typecode == TYPE_CODE_FLT)
3157 && len <= 4)
3158 longword_offset = MIPS64_REGSIZE - len;
cb3d25d1
MS
3159 }
3160
3161 if (mips_debug)
3162 {
3163 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3164 paddr_nz (stack_offset));
3165 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3166 paddr_nz (longword_offset));
3167 }
3168
3169 addr = sp + stack_offset + longword_offset;
3170
3171 if (mips_debug)
3172 {
3173 int i;
6d82d43b 3174 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
cb3d25d1
MS
3175 paddr_nz (addr));
3176 for (i = 0; i < partial_len; i++)
3177 {
6d82d43b 3178 fprintf_unfiltered (gdb_stdlog, "%02x",
cb3d25d1
MS
3179 val[i] & 0xff);
3180 }
3181 }
3182 write_memory (addr, val, partial_len);
3183 }
3184
3185 /* Note!!! This is NOT an else clause. Odd sized
8d26208a 3186 structs may go thru BOTH paths. */
cb3d25d1 3187 /* Write this portion of the argument to a general
6d82d43b 3188 purpose register. */
8d26208a 3189 if (argreg <= MIPS_LAST_ARG_REGNUM)
cb3d25d1 3190 {
5863b5d5
MR
3191 LONGEST regval;
3192
3193 /* Sign extend pointers, 32-bit integers and signed
3194 16-bit and 8-bit integers; everything else is taken
3195 as is. */
3196
3197 if ((partial_len == 4
3198 && (typecode == TYPE_CODE_PTR
3199 || typecode == TYPE_CODE_INT))
3200 || (partial_len < 4
3201 && typecode == TYPE_CODE_INT
3202 && !TYPE_UNSIGNED (arg_type)))
3203 regval = extract_signed_integer (val, partial_len);
3204 else
3205 regval = extract_unsigned_integer (val, partial_len);
cb3d25d1
MS
3206
3207 /* A non-floating-point argument being passed in a
3208 general register. If a struct or union, and if
3209 the remaining length is smaller than the register
3210 size, we have to adjust the register value on
3211 big endian targets.
3212
3213 It does not seem to be necessary to do the
1a69e1e4 3214 same for integral types. */
cb3d25d1 3215
72a155b4 3216 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
1a69e1e4 3217 && partial_len < MIPS64_REGSIZE
06f9a1af
MR
3218 && (typecode == TYPE_CODE_STRUCT
3219 || typecode == TYPE_CODE_UNION))
1a69e1e4 3220 regval <<= ((MIPS64_REGSIZE - partial_len)
9ecf7166 3221 * TARGET_CHAR_BIT);
cb3d25d1
MS
3222
3223 if (mips_debug)
3224 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3225 argreg,
1a69e1e4 3226 phex (regval, MIPS64_REGSIZE));
9c9acae0 3227 regcache_cooked_write_unsigned (regcache, argreg, regval);
8d26208a
DJ
3228
3229 if (mips_n32n64_fp_arg_chunk_p (arg_type,
3230 TYPE_LENGTH (arg_type) - len))
3231 {
3232 if (mips_debug)
3233 fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s",
3234 float_argreg,
3235 phex (regval, MIPS64_REGSIZE));
3236 regcache_cooked_write_unsigned (regcache, float_argreg,
3237 regval);
3238 }
3239
3240 float_argreg++;
cb3d25d1
MS
3241 argreg++;
3242 }
3243
3244 len -= partial_len;
3245 val += partial_len;
3246
3247 /* Compute the the offset into the stack at which we
6d82d43b 3248 will copy the next parameter.
cb3d25d1
MS
3249
3250 In N32 (N64?), the stack_offset only needs to be
3251 adjusted when it has been used. */
3252
3253 if (stack_used_p)
1a69e1e4 3254 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
cb3d25d1
MS
3255 }
3256 }
3257 if (mips_debug)
3258 fprintf_unfiltered (gdb_stdlog, "\n");
3259 }
3260
f10683bb 3261 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
310e9b6a 3262
cb3d25d1
MS
3263 /* Return adjusted stack pointer. */
3264 return sp;
3265}
3266
6d82d43b
AC
3267static enum return_value_convention
3268mips_n32n64_return_value (struct gdbarch *gdbarch,
3269 struct type *type, struct regcache *regcache,
47a35522 3270 gdb_byte *readbuf, const gdb_byte *writebuf)
ebafbe83 3271{
72a155b4 3272 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
b18bb924
MR
3273
3274 /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
3275
3276 Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
3277 if needed), as appropriate for the type. Composite results (struct,
3278 union, or array) are returned in $2/$f0 and $3/$f2 according to the
3279 following rules:
3280
3281 * A struct with only one or two floating point fields is returned in $f0
3282 (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
3283 case.
3284
3285 * Any other struct or union results of at most 128 bits are returned in
3286 $2 (first 64 bits) and $3 (remainder, if necessary).
3287
3288 * Larger composite results are handled by converting the function to a
3289 procedure with an implicit first parameter, which is a pointer to an area
3290 reserved by the caller to receive the result. [The o32-bit ABI requires
3291 that all composite results be handled by conversion to implicit first
3292 parameters. The MIPS/SGI Fortran implementation has always made a
3293 specific exception to return COMPLEX results in the floating point
3294 registers.] */
3295
3296 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1a69e1e4 3297 || TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE)
6d82d43b 3298 return RETURN_VALUE_STRUCT_CONVENTION;
d05f6826
DJ
3299 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3300 && TYPE_LENGTH (type) == 16
3301 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3302 {
3303 /* A 128-bit floating-point value fills both $f0 and $f2. The
3304 two registers are used in the same as memory order, so the
3305 eight bytes with the lower memory address are in $f0. */
3306 if (mips_debug)
3307 fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n");
ba32f989 3308 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3309 gdbarch_num_regs (gdbarch)
3310 + mips_regnum (gdbarch)->fp0,
3311 8, gdbarch_byte_order (gdbarch),
4c6b5505 3312 readbuf, writebuf, 0);
ba32f989 3313 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3314 gdbarch_num_regs (gdbarch)
3315 + mips_regnum (gdbarch)->fp0 + 2,
3316 8, gdbarch_byte_order (gdbarch),
4c6b5505 3317 readbuf ? readbuf + 8 : readbuf,
d05f6826
DJ
3318 writebuf ? writebuf + 8 : writebuf, 0);
3319 return RETURN_VALUE_REGISTER_CONVENTION;
3320 }
6d82d43b
AC
3321 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3322 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3323 {
59aa1faa 3324 /* A single or double floating-point value that fits in FP0. */
6d82d43b
AC
3325 if (mips_debug)
3326 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
ba32f989 3327 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3328 gdbarch_num_regs (gdbarch)
3329 + mips_regnum (gdbarch)->fp0,
6d82d43b 3330 TYPE_LENGTH (type),
72a155b4 3331 gdbarch_byte_order (gdbarch),
4c6b5505 3332 readbuf, writebuf, 0);
6d82d43b
AC
3333 return RETURN_VALUE_REGISTER_CONVENTION;
3334 }
3335 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3336 && TYPE_NFIELDS (type) <= 2
3337 && TYPE_NFIELDS (type) >= 1
3338 && ((TYPE_NFIELDS (type) == 1
b18bb924 3339 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
6d82d43b
AC
3340 == TYPE_CODE_FLT))
3341 || (TYPE_NFIELDS (type) == 2
b18bb924 3342 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
6d82d43b 3343 == TYPE_CODE_FLT)
b18bb924 3344 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1)))
6d82d43b
AC
3345 == TYPE_CODE_FLT)))
3346 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3347 {
3348 /* A struct that contains one or two floats. Each value is part
3349 in the least significant part of their floating point
3350 register.. */
6d82d43b
AC
3351 int regnum;
3352 int field;
72a155b4 3353 for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
6d82d43b
AC
3354 field < TYPE_NFIELDS (type); field++, regnum += 2)
3355 {
3356 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3357 / TARGET_CHAR_BIT);
3358 if (mips_debug)
3359 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3360 offset);
ba32f989
DJ
3361 mips_xfer_register (gdbarch, regcache,
3362 gdbarch_num_regs (gdbarch) + regnum,
6d82d43b 3363 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
72a155b4 3364 gdbarch_byte_order (gdbarch),
4c6b5505 3365 readbuf, writebuf, offset);
6d82d43b
AC
3366 }
3367 return RETURN_VALUE_REGISTER_CONVENTION;
3368 }
3369 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3370 || TYPE_CODE (type) == TYPE_CODE_UNION)
3371 {
3372 /* A structure or union. Extract the left justified value,
3373 regardless of the byte order. I.e. DO NOT USE
3374 mips_xfer_lower. */
3375 int offset;
3376 int regnum;
4c7d22cb 3377 for (offset = 0, regnum = MIPS_V0_REGNUM;
6d82d43b 3378 offset < TYPE_LENGTH (type);
72a155b4 3379 offset += register_size (gdbarch, regnum), regnum++)
6d82d43b 3380 {
72a155b4 3381 int xfer = register_size (gdbarch, regnum);
6d82d43b
AC
3382 if (offset + xfer > TYPE_LENGTH (type))
3383 xfer = TYPE_LENGTH (type) - offset;
3384 if (mips_debug)
3385 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3386 offset, xfer, regnum);
ba32f989
DJ
3387 mips_xfer_register (gdbarch, regcache,
3388 gdbarch_num_regs (gdbarch) + regnum,
72a155b4
UW
3389 xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf,
3390 offset);
6d82d43b
AC
3391 }
3392 return RETURN_VALUE_REGISTER_CONVENTION;
3393 }
3394 else
3395 {
3396 /* A scalar extract each part but least-significant-byte
3397 justified. */
3398 int offset;
3399 int regnum;
4c7d22cb 3400 for (offset = 0, regnum = MIPS_V0_REGNUM;
6d82d43b 3401 offset < TYPE_LENGTH (type);
72a155b4 3402 offset += register_size (gdbarch, regnum), regnum++)
6d82d43b 3403 {
72a155b4 3404 int xfer = register_size (gdbarch, regnum);
6d82d43b
AC
3405 if (offset + xfer > TYPE_LENGTH (type))
3406 xfer = TYPE_LENGTH (type) - offset;
3407 if (mips_debug)
3408 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3409 offset, xfer, regnum);
ba32f989
DJ
3410 mips_xfer_register (gdbarch, regcache,
3411 gdbarch_num_regs (gdbarch) + regnum,
72a155b4 3412 xfer, gdbarch_byte_order (gdbarch),
4c6b5505 3413 readbuf, writebuf, offset);
6d82d43b
AC
3414 }
3415 return RETURN_VALUE_REGISTER_CONVENTION;
3416 }
3417}
3418
3419/* O32 ABI stuff. */
3420
3421static CORE_ADDR
7d9b040b 3422mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
6d82d43b
AC
3423 struct regcache *regcache, CORE_ADDR bp_addr,
3424 int nargs, struct value **args, CORE_ADDR sp,
3425 int struct_return, CORE_ADDR struct_addr)
3426{
3427 int argreg;
3428 int float_argreg;
3429 int argnum;
3430 int len = 0;
3431 int stack_offset = 0;
3432 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7d9b040b 3433 CORE_ADDR func_addr = find_function_addr (function, NULL);
6d82d43b
AC
3434
3435 /* For shared libraries, "t9" needs to point at the function
3436 address. */
4c7d22cb 3437 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
6d82d43b
AC
3438
3439 /* Set the return address register to point to the entry point of
3440 the program, where a breakpoint lies in wait. */
4c7d22cb 3441 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
6d82d43b
AC
3442
3443 /* First ensure that the stack and structure return address (if any)
3444 are properly aligned. The stack has to be at least 64-bit
3445 aligned even on 32-bit machines, because doubles must be 64-bit
ebafbe83
MS
3446 aligned. For n32 and n64, stack frames need to be 128-bit
3447 aligned, so we round to this widest known alignment. */
3448
5b03f266
AC
3449 sp = align_down (sp, 16);
3450 struct_addr = align_down (struct_addr, 16);
ebafbe83
MS
3451
3452 /* Now make space on the stack for the args. */
3453 for (argnum = 0; argnum < nargs; argnum++)
968b5391
MR
3454 {
3455 struct type *arg_type = check_typedef (value_type (args[argnum]));
3456 int arglen = TYPE_LENGTH (arg_type);
3457
3458 /* Align to double-word if necessary. */
2afd3f0a 3459 if (mips_type_needs_double_align (arg_type))
1a69e1e4 3460 len = align_up (len, MIPS32_REGSIZE * 2);
968b5391 3461 /* Allocate space on the stack. */
1a69e1e4 3462 len += align_up (arglen, MIPS32_REGSIZE);
968b5391 3463 }
5b03f266 3464 sp -= align_up (len, 16);
ebafbe83
MS
3465
3466 if (mips_debug)
6d82d43b 3467 fprintf_unfiltered (gdb_stdlog,
5b03f266
AC
3468 "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n",
3469 paddr_nz (sp), (long) align_up (len, 16));
ebafbe83
MS
3470
3471 /* Initialize the integer and float register pointers. */
4c7d22cb 3472 argreg = MIPS_A0_REGNUM;
72a155b4 3473 float_argreg = mips_fpa0_regnum (gdbarch);
ebafbe83 3474
bcb0cc15 3475 /* The struct_return pointer occupies the first parameter-passing reg. */
ebafbe83
MS
3476 if (struct_return)
3477 {
3478 if (mips_debug)
3479 fprintf_unfiltered (gdb_stdlog,
25ab4790 3480 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
ebafbe83 3481 argreg, paddr_nz (struct_addr));
9c9acae0 3482 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
1a69e1e4 3483 stack_offset += MIPS32_REGSIZE;
ebafbe83
MS
3484 }
3485
3486 /* Now load as many as possible of the first arguments into
3487 registers, and push the rest onto the stack. Loop thru args
3488 from first to last. */
3489 for (argnum = 0; argnum < nargs; argnum++)
3490 {
47a35522 3491 const gdb_byte *val;
ebafbe83 3492 struct value *arg = args[argnum];
4991999e 3493 struct type *arg_type = check_typedef (value_type (arg));
ebafbe83
MS
3494 int len = TYPE_LENGTH (arg_type);
3495 enum type_code typecode = TYPE_CODE (arg_type);
3496
3497 if (mips_debug)
3498 fprintf_unfiltered (gdb_stdlog,
25ab4790 3499 "mips_o32_push_dummy_call: %d len=%d type=%d",
46cac009
AC
3500 argnum + 1, len, (int) typecode);
3501
47a35522 3502 val = value_contents (arg);
46cac009
AC
3503
3504 /* 32-bit ABIs always start floating point arguments in an
3505 even-numbered floating point register. Round the FP register
3506 up before the check to see if there are any FP registers
3507 left. O32/O64 targets also pass the FP in the integer
3508 registers so also round up normal registers. */
2afd3f0a 3509 if (fp_register_arg_p (typecode, arg_type))
46cac009
AC
3510 {
3511 if ((float_argreg & 1))
3512 float_argreg++;
3513 }
3514
3515 /* Floating point arguments passed in registers have to be
3516 treated specially. On 32-bit architectures, doubles
3517 are passed in register pairs; the even register gets
3518 the low word, and the odd register gets the high word.
3519 On O32/O64, the first two floating point arguments are
3520 also copied to general registers, because MIPS16 functions
3521 don't use float registers for arguments. This duplication of
3522 arguments in general registers can't hurt non-MIPS16 functions
3523 because those registers are normally skipped. */
3524
3525 if (fp_register_arg_p (typecode, arg_type)
3526 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3527 {
8b07f6d8 3528 if (register_size (gdbarch, float_argreg) < 8 && len == 8)
46cac009 3529 {
72a155b4 3530 int low_offset = gdbarch_byte_order (gdbarch)
4c6b5505 3531 == BFD_ENDIAN_BIG ? 4 : 0;
46cac009
AC
3532 unsigned long regval;
3533
3534 /* Write the low word of the double to the even register(s). */
3535 regval = extract_unsigned_integer (val + low_offset, 4);
3536 if (mips_debug)
3537 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3538 float_argreg, phex (regval, 4));
9c9acae0 3539 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
46cac009
AC
3540 if (mips_debug)
3541 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3542 argreg, phex (regval, 4));
9c9acae0 3543 regcache_cooked_write_unsigned (regcache, argreg++, regval);
46cac009
AC
3544
3545 /* Write the high word of the double to the odd register(s). */
3546 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3547 if (mips_debug)
3548 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3549 float_argreg, phex (regval, 4));
9c9acae0 3550 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
46cac009
AC
3551
3552 if (mips_debug)
3553 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3554 argreg, phex (regval, 4));
9c9acae0 3555 regcache_cooked_write_unsigned (regcache, argreg++, regval);
46cac009
AC
3556 }
3557 else
3558 {
3559 /* This is a floating point value that fits entirely
3560 in a single register. */
3561 /* On 32 bit ABI's the float_argreg is further adjusted
6d82d43b 3562 above to ensure that it is even register aligned. */
46cac009
AC
3563 LONGEST regval = extract_unsigned_integer (val, len);
3564 if (mips_debug)
3565 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3566 float_argreg, phex (regval, len));
9c9acae0 3567 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
46cac009 3568 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
6d82d43b
AC
3569 registers for each argument. The below is (my
3570 guess) to ensure that the corresponding integer
3571 register has reserved the same space. */
46cac009
AC
3572 if (mips_debug)
3573 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3574 argreg, phex (regval, len));
9c9acae0 3575 regcache_cooked_write_unsigned (regcache, argreg, regval);
2afd3f0a 3576 argreg += 2;
46cac009
AC
3577 }
3578 /* Reserve space for the FP register. */
1a69e1e4 3579 stack_offset += align_up (len, MIPS32_REGSIZE);
46cac009
AC
3580 }
3581 else
3582 {
3583 /* Copy the argument to general registers or the stack in
3584 register-sized pieces. Large arguments are split between
3585 registers and stack. */
1a69e1e4
DJ
3586 /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
3587 are treated specially: Irix cc passes
d5ac5a39
AC
3588 them in registers where gcc sometimes puts them on the
3589 stack. For maximum compatibility, we will put them in
3590 both places. */
1a69e1e4
DJ
3591 int odd_sized_struct = (len > MIPS32_REGSIZE
3592 && len % MIPS32_REGSIZE != 0);
46cac009
AC
3593 /* Structures should be aligned to eight bytes (even arg registers)
3594 on MIPS_ABI_O32, if their first member has double precision. */
2afd3f0a 3595 if (mips_type_needs_double_align (arg_type))
46cac009
AC
3596 {
3597 if ((argreg & 1))
968b5391
MR
3598 {
3599 argreg++;
1a69e1e4 3600 stack_offset += MIPS32_REGSIZE;
968b5391 3601 }
46cac009 3602 }
46cac009
AC
3603 while (len > 0)
3604 {
3605 /* Remember if the argument was written to the stack. */
3606 int stack_used_p = 0;
1a69e1e4 3607 int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE);
46cac009
AC
3608
3609 if (mips_debug)
3610 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3611 partial_len);
3612
3613 /* Write this portion of the argument to the stack. */
3614 if (argreg > MIPS_LAST_ARG_REGNUM
968b5391 3615 || odd_sized_struct)
46cac009
AC
3616 {
3617 /* Should shorter than int integer values be
3618 promoted to int before being stored? */
3619 int longword_offset = 0;
3620 CORE_ADDR addr;
3621 stack_used_p = 1;
46cac009
AC
3622
3623 if (mips_debug)
3624 {
3625 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3626 paddr_nz (stack_offset));
3627 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3628 paddr_nz (longword_offset));
3629 }
3630
3631 addr = sp + stack_offset + longword_offset;
3632
3633 if (mips_debug)
3634 {
3635 int i;
6d82d43b 3636 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
46cac009
AC
3637 paddr_nz (addr));
3638 for (i = 0; i < partial_len; i++)
3639 {
6d82d43b 3640 fprintf_unfiltered (gdb_stdlog, "%02x",
46cac009
AC
3641 val[i] & 0xff);
3642 }
3643 }
3644 write_memory (addr, val, partial_len);
3645 }
3646
3647 /* Note!!! This is NOT an else clause. Odd sized
968b5391 3648 structs may go thru BOTH paths. */
46cac009 3649 /* Write this portion of the argument to a general
6d82d43b 3650 purpose register. */
968b5391 3651 if (argreg <= MIPS_LAST_ARG_REGNUM)
46cac009
AC
3652 {
3653 LONGEST regval = extract_signed_integer (val, partial_len);
4246e332 3654 /* Value may need to be sign extended, because
1b13c4f6 3655 mips_isa_regsize() != mips_abi_regsize(). */
46cac009
AC
3656
3657 /* A non-floating-point argument being passed in a
3658 general register. If a struct or union, and if
3659 the remaining length is smaller than the register
3660 size, we have to adjust the register value on
3661 big endian targets.
3662
3663 It does not seem to be necessary to do the
3664 same for integral types.
3665
3666 Also don't do this adjustment on O64 binaries.
3667
3668 cagney/2001-07-23: gdb/179: Also, GCC, when
3669 outputting LE O32 with sizeof (struct) <
e914cb17
MR
3670 mips_abi_regsize(), generates a left shift
3671 as part of storing the argument in a register
3672 (the left shift isn't generated when
1b13c4f6 3673 sizeof (struct) >= mips_abi_regsize()). Since
480d3dd2
AC
3674 it is quite possible that this is GCC
3675 contradicting the LE/O32 ABI, GDB has not been
3676 adjusted to accommodate this. Either someone
3677 needs to demonstrate that the LE/O32 ABI
3678 specifies such a left shift OR this new ABI gets
3679 identified as such and GDB gets tweaked
3680 accordingly. */
3681
72a155b4 3682 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
1a69e1e4 3683 && partial_len < MIPS32_REGSIZE
06f9a1af
MR
3684 && (typecode == TYPE_CODE_STRUCT
3685 || typecode == TYPE_CODE_UNION))
1a69e1e4 3686 regval <<= ((MIPS32_REGSIZE - partial_len)
9ecf7166 3687 * TARGET_CHAR_BIT);
46cac009
AC
3688
3689 if (mips_debug)
3690 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3691 argreg,
1a69e1e4 3692 phex (regval, MIPS32_REGSIZE));
9c9acae0 3693 regcache_cooked_write_unsigned (regcache, argreg, regval);
46cac009
AC
3694 argreg++;
3695
3696 /* Prevent subsequent floating point arguments from
3697 being passed in floating point registers. */
3698 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
3699 }
3700
3701 len -= partial_len;
3702 val += partial_len;
3703
3704 /* Compute the the offset into the stack at which we
6d82d43b 3705 will copy the next parameter.
46cac009 3706
6d82d43b
AC
3707 In older ABIs, the caller reserved space for
3708 registers that contained arguments. This was loosely
3709 refered to as their "home". Consequently, space is
3710 always allocated. */
46cac009 3711
1a69e1e4 3712 stack_offset += align_up (partial_len, MIPS32_REGSIZE);
46cac009
AC
3713 }
3714 }
3715 if (mips_debug)
3716 fprintf_unfiltered (gdb_stdlog, "\n");
3717 }
3718
f10683bb 3719 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
310e9b6a 3720
46cac009
AC
3721 /* Return adjusted stack pointer. */
3722 return sp;
3723}
3724
6d82d43b
AC
3725static enum return_value_convention
3726mips_o32_return_value (struct gdbarch *gdbarch, struct type *type,
3727 struct regcache *regcache,
47a35522 3728 gdb_byte *readbuf, const gdb_byte *writebuf)
6d82d43b 3729{
72a155b4 3730 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
6d82d43b
AC
3731
3732 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3733 || TYPE_CODE (type) == TYPE_CODE_UNION
3734 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
3735 return RETURN_VALUE_STRUCT_CONVENTION;
3736 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3737 && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3738 {
3739 /* A single-precision floating-point value. It fits in the
3740 least significant part of FP0. */
3741 if (mips_debug)
3742 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
ba32f989 3743 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3744 gdbarch_num_regs (gdbarch)
3745 + mips_regnum (gdbarch)->fp0,
6d82d43b 3746 TYPE_LENGTH (type),
72a155b4 3747 gdbarch_byte_order (gdbarch),
4c6b5505 3748 readbuf, writebuf, 0);
6d82d43b
AC
3749 return RETURN_VALUE_REGISTER_CONVENTION;
3750 }
3751 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3752 && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3753 {
3754 /* A double-precision floating-point value. The most
3755 significant part goes in FP1, and the least significant in
3756 FP0. */
3757 if (mips_debug)
3758 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
72a155b4 3759 switch (gdbarch_byte_order (gdbarch))
6d82d43b
AC
3760 {
3761 case BFD_ENDIAN_LITTLE:
ba32f989 3762 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3763 gdbarch_num_regs (gdbarch)
3764 + mips_regnum (gdbarch)->fp0 +
3765 0, 4, gdbarch_byte_order (gdbarch),
4c6b5505 3766 readbuf, writebuf, 0);
ba32f989 3767 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3768 gdbarch_num_regs (gdbarch)
3769 + mips_regnum (gdbarch)->fp0 + 1,
3770 4, gdbarch_byte_order (gdbarch),
4c6b5505 3771 readbuf, writebuf, 4);
6d82d43b
AC
3772 break;
3773 case BFD_ENDIAN_BIG:
ba32f989 3774 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3775 gdbarch_num_regs (gdbarch)
3776 + mips_regnum (gdbarch)->fp0 + 1,
3777 4, gdbarch_byte_order (gdbarch),
4c6b5505 3778 readbuf, writebuf, 0);
ba32f989 3779 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
3780 gdbarch_num_regs (gdbarch)
3781 + mips_regnum (gdbarch)->fp0 + 0,
3782 4, gdbarch_byte_order (gdbarch),
4c6b5505 3783 readbuf, writebuf, 4);
6d82d43b
AC
3784 break;
3785 default:
e2e0b3e5 3786 internal_error (__FILE__, __LINE__, _("bad switch"));
6d82d43b
AC
3787 }
3788 return RETURN_VALUE_REGISTER_CONVENTION;
3789 }
3790#if 0
3791 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3792 && TYPE_NFIELDS (type) <= 2
3793 && TYPE_NFIELDS (type) >= 1
3794 && ((TYPE_NFIELDS (type) == 1
3795 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3796 == TYPE_CODE_FLT))
3797 || (TYPE_NFIELDS (type) == 2
3798 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3799 == TYPE_CODE_FLT)
3800 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
3801 == TYPE_CODE_FLT)))
3802 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3803 {
3804 /* A struct that contains one or two floats. Each value is part
3805 in the least significant part of their floating point
3806 register.. */
870cd05e 3807 gdb_byte reg[MAX_REGISTER_SIZE];
6d82d43b
AC
3808 int regnum;
3809 int field;
72a155b4 3810 for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
6d82d43b
AC
3811 field < TYPE_NFIELDS (type); field++, regnum += 2)
3812 {
3813 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3814 / TARGET_CHAR_BIT);
3815 if (mips_debug)
3816 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3817 offset);
ba32f989
DJ
3818 mips_xfer_register (gdbarch, regcache,
3819 gdbarch_num_regs (gdbarch) + regnum,
6d82d43b 3820 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
72a155b4 3821 gdbarch_byte_order (gdbarch),
4c6b5505 3822 readbuf, writebuf, offset);
6d82d43b
AC
3823 }
3824 return RETURN_VALUE_REGISTER_CONVENTION;
3825 }
3826#endif
3827#if 0
3828 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3829 || TYPE_CODE (type) == TYPE_CODE_UNION)
3830 {
3831 /* A structure or union. Extract the left justified value,
3832 regardless of the byte order. I.e. DO NOT USE
3833 mips_xfer_lower. */
3834 int offset;
3835 int regnum;
4c7d22cb 3836 for (offset = 0, regnum = MIPS_V0_REGNUM;
6d82d43b 3837 offset < TYPE_LENGTH (type);
72a155b4 3838 offset += register_size (gdbarch, regnum), regnum++)
6d82d43b 3839 {
72a155b4 3840 int xfer = register_size (gdbarch, regnum);
6d82d43b
AC
3841 if (offset + xfer > TYPE_LENGTH (type))
3842 xfer = TYPE_LENGTH (type) - offset;
3843 if (mips_debug)
3844 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3845 offset, xfer, regnum);
ba32f989
DJ
3846 mips_xfer_register (gdbarch, regcache,
3847 gdbarch_num_regs (gdbarch) + regnum, xfer,
6d82d43b
AC
3848 BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
3849 }
3850 return RETURN_VALUE_REGISTER_CONVENTION;
3851 }
3852#endif
3853 else
3854 {
3855 /* A scalar extract each part but least-significant-byte
3856 justified. o32 thinks registers are 4 byte, regardless of
1a69e1e4 3857 the ISA. */
6d82d43b
AC
3858 int offset;
3859 int regnum;
4c7d22cb 3860 for (offset = 0, regnum = MIPS_V0_REGNUM;
6d82d43b 3861 offset < TYPE_LENGTH (type);
1a69e1e4 3862 offset += MIPS32_REGSIZE, regnum++)
6d82d43b 3863 {
1a69e1e4 3864 int xfer = MIPS32_REGSIZE;
6d82d43b
AC
3865 if (offset + xfer > TYPE_LENGTH (type))
3866 xfer = TYPE_LENGTH (type) - offset;
3867 if (mips_debug)
3868 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3869 offset, xfer, regnum);
ba32f989
DJ
3870 mips_xfer_register (gdbarch, regcache,
3871 gdbarch_num_regs (gdbarch) + regnum, xfer,
72a155b4 3872 gdbarch_byte_order (gdbarch),
4c6b5505 3873 readbuf, writebuf, offset);
6d82d43b
AC
3874 }
3875 return RETURN_VALUE_REGISTER_CONVENTION;
3876 }
3877}
3878
3879/* O64 ABI. This is a hacked up kind of 64-bit version of the o32
3880 ABI. */
46cac009
AC
3881
3882static CORE_ADDR
7d9b040b 3883mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
6d82d43b
AC
3884 struct regcache *regcache, CORE_ADDR bp_addr,
3885 int nargs,
3886 struct value **args, CORE_ADDR sp,
3887 int struct_return, CORE_ADDR struct_addr)
46cac009
AC
3888{
3889 int argreg;
3890 int float_argreg;
3891 int argnum;
3892 int len = 0;
3893 int stack_offset = 0;
480d3dd2 3894 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7d9b040b 3895 CORE_ADDR func_addr = find_function_addr (function, NULL);
46cac009 3896
25ab4790
AC
3897 /* For shared libraries, "t9" needs to point at the function
3898 address. */
4c7d22cb 3899 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
25ab4790
AC
3900
3901 /* Set the return address register to point to the entry point of
3902 the program, where a breakpoint lies in wait. */
4c7d22cb 3903 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
25ab4790 3904
46cac009
AC
3905 /* First ensure that the stack and structure return address (if any)
3906 are properly aligned. The stack has to be at least 64-bit
3907 aligned even on 32-bit machines, because doubles must be 64-bit
3908 aligned. For n32 and n64, stack frames need to be 128-bit
3909 aligned, so we round to this widest known alignment. */
3910
5b03f266
AC
3911 sp = align_down (sp, 16);
3912 struct_addr = align_down (struct_addr, 16);
46cac009
AC
3913
3914 /* Now make space on the stack for the args. */
3915 for (argnum = 0; argnum < nargs; argnum++)
968b5391
MR
3916 {
3917 struct type *arg_type = check_typedef (value_type (args[argnum]));
3918 int arglen = TYPE_LENGTH (arg_type);
3919
968b5391 3920 /* Allocate space on the stack. */
1a69e1e4 3921 len += align_up (arglen, MIPS64_REGSIZE);
968b5391 3922 }
5b03f266 3923 sp -= align_up (len, 16);
46cac009
AC
3924
3925 if (mips_debug)
6d82d43b 3926 fprintf_unfiltered (gdb_stdlog,
5b03f266
AC
3927 "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n",
3928 paddr_nz (sp), (long) align_up (len, 16));
46cac009
AC
3929
3930 /* Initialize the integer and float register pointers. */
4c7d22cb 3931 argreg = MIPS_A0_REGNUM;
72a155b4 3932 float_argreg = mips_fpa0_regnum (gdbarch);
46cac009
AC
3933
3934 /* The struct_return pointer occupies the first parameter-passing reg. */
3935 if (struct_return)
3936 {
3937 if (mips_debug)
3938 fprintf_unfiltered (gdb_stdlog,
25ab4790 3939 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
46cac009 3940 argreg, paddr_nz (struct_addr));
9c9acae0 3941 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
1a69e1e4 3942 stack_offset += MIPS64_REGSIZE;
46cac009
AC
3943 }
3944
3945 /* Now load as many as possible of the first arguments into
3946 registers, and push the rest onto the stack. Loop thru args
3947 from first to last. */
3948 for (argnum = 0; argnum < nargs; argnum++)
3949 {
47a35522 3950 const gdb_byte *val;
46cac009 3951 struct value *arg = args[argnum];
4991999e 3952 struct type *arg_type = check_typedef (value_type (arg));
46cac009
AC
3953 int len = TYPE_LENGTH (arg_type);
3954 enum type_code typecode = TYPE_CODE (arg_type);
3955
3956 if (mips_debug)
3957 fprintf_unfiltered (gdb_stdlog,
25ab4790 3958 "mips_o64_push_dummy_call: %d len=%d type=%d",
ebafbe83
MS
3959 argnum + 1, len, (int) typecode);
3960
47a35522 3961 val = value_contents (arg);
ebafbe83 3962
ebafbe83
MS
3963 /* Floating point arguments passed in registers have to be
3964 treated specially. On 32-bit architectures, doubles
3965 are passed in register pairs; the even register gets
3966 the low word, and the odd register gets the high word.
3967 On O32/O64, the first two floating point arguments are
3968 also copied to general registers, because MIPS16 functions
3969 don't use float registers for arguments. This duplication of
3970 arguments in general registers can't hurt non-MIPS16 functions
3971 because those registers are normally skipped. */
3972
3973 if (fp_register_arg_p (typecode, arg_type)
3974 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3975 {
2afd3f0a
MR
3976 LONGEST regval = extract_unsigned_integer (val, len);
3977 if (mips_debug)
3978 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3979 float_argreg, phex (regval, len));
9c9acae0 3980 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
2afd3f0a
MR
3981 if (mips_debug)
3982 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3983 argreg, phex (regval, len));
9c9acae0 3984 regcache_cooked_write_unsigned (regcache, argreg, regval);
2afd3f0a 3985 argreg++;
ebafbe83 3986 /* Reserve space for the FP register. */
1a69e1e4 3987 stack_offset += align_up (len, MIPS64_REGSIZE);
ebafbe83
MS
3988 }
3989 else
3990 {
3991 /* Copy the argument to general registers or the stack in
3992 register-sized pieces. Large arguments are split between
3993 registers and stack. */
1a69e1e4 3994 /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
436aafc4
MR
3995 are treated specially: Irix cc passes them in registers
3996 where gcc sometimes puts them on the stack. For maximum
3997 compatibility, we will put them in both places. */
1a69e1e4
DJ
3998 int odd_sized_struct = (len > MIPS64_REGSIZE
3999 && len % MIPS64_REGSIZE != 0);
ebafbe83
MS
4000 while (len > 0)
4001 {
4002 /* Remember if the argument was written to the stack. */
4003 int stack_used_p = 0;
1a69e1e4 4004 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
ebafbe83
MS
4005
4006 if (mips_debug)
4007 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
4008 partial_len);
4009
4010 /* Write this portion of the argument to the stack. */
4011 if (argreg > MIPS_LAST_ARG_REGNUM
968b5391 4012 || odd_sized_struct)
ebafbe83
MS
4013 {
4014 /* Should shorter than int integer values be
4015 promoted to int before being stored? */
4016 int longword_offset = 0;
4017 CORE_ADDR addr;
4018 stack_used_p = 1;
72a155b4 4019 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ebafbe83 4020 {
1a69e1e4
DJ
4021 if ((typecode == TYPE_CODE_INT
4022 || typecode == TYPE_CODE_PTR
4023 || typecode == TYPE_CODE_FLT)
4024 && len <= 4)
4025 longword_offset = MIPS64_REGSIZE - len;
ebafbe83
MS
4026 }
4027
4028 if (mips_debug)
4029 {
4030 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
4031 paddr_nz (stack_offset));
4032 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
4033 paddr_nz (longword_offset));
4034 }
4035
4036 addr = sp + stack_offset + longword_offset;
4037
4038 if (mips_debug)
4039 {
4040 int i;
6d82d43b 4041 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
ebafbe83
MS
4042 paddr_nz (addr));
4043 for (i = 0; i < partial_len; i++)
4044 {
6d82d43b 4045 fprintf_unfiltered (gdb_stdlog, "%02x",
ebafbe83
MS
4046 val[i] & 0xff);
4047 }
4048 }
4049 write_memory (addr, val, partial_len);
4050 }
4051
4052 /* Note!!! This is NOT an else clause. Odd sized
968b5391 4053 structs may go thru BOTH paths. */
ebafbe83 4054 /* Write this portion of the argument to a general
6d82d43b 4055 purpose register. */
968b5391 4056 if (argreg <= MIPS_LAST_ARG_REGNUM)
ebafbe83
MS
4057 {
4058 LONGEST regval = extract_signed_integer (val, partial_len);
4246e332 4059 /* Value may need to be sign extended, because
1b13c4f6 4060 mips_isa_regsize() != mips_abi_regsize(). */
ebafbe83
MS
4061
4062 /* A non-floating-point argument being passed in a
4063 general register. If a struct or union, and if
4064 the remaining length is smaller than the register
4065 size, we have to adjust the register value on
4066 big endian targets.
4067
4068 It does not seem to be necessary to do the
401835eb 4069 same for integral types. */
480d3dd2 4070
72a155b4 4071 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
1a69e1e4 4072 && partial_len < MIPS64_REGSIZE
06f9a1af
MR
4073 && (typecode == TYPE_CODE_STRUCT
4074 || typecode == TYPE_CODE_UNION))
1a69e1e4 4075 regval <<= ((MIPS64_REGSIZE - partial_len)
9ecf7166 4076 * TARGET_CHAR_BIT);
ebafbe83
MS
4077
4078 if (mips_debug)
4079 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4080 argreg,
1a69e1e4 4081 phex (regval, MIPS64_REGSIZE));
9c9acae0 4082 regcache_cooked_write_unsigned (regcache, argreg, regval);
ebafbe83
MS
4083 argreg++;
4084
4085 /* Prevent subsequent floating point arguments from
4086 being passed in floating point registers. */
4087 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
4088 }
4089
4090 len -= partial_len;
4091 val += partial_len;
4092
4093 /* Compute the the offset into the stack at which we
6d82d43b 4094 will copy the next parameter.
ebafbe83 4095
6d82d43b
AC
4096 In older ABIs, the caller reserved space for
4097 registers that contained arguments. This was loosely
4098 refered to as their "home". Consequently, space is
4099 always allocated. */
ebafbe83 4100
1a69e1e4 4101 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
ebafbe83
MS
4102 }
4103 }
4104 if (mips_debug)
4105 fprintf_unfiltered (gdb_stdlog, "\n");
4106 }
4107
f10683bb 4108 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
310e9b6a 4109
ebafbe83
MS
4110 /* Return adjusted stack pointer. */
4111 return sp;
4112}
4113
9c8fdbfa
AC
4114static enum return_value_convention
4115mips_o64_return_value (struct gdbarch *gdbarch,
4116 struct type *type, struct regcache *regcache,
47a35522 4117 gdb_byte *readbuf, const gdb_byte *writebuf)
6d82d43b 4118{
72a155b4 4119 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7a076fd2
FF
4120
4121 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4122 || TYPE_CODE (type) == TYPE_CODE_UNION
4123 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
4124 return RETURN_VALUE_STRUCT_CONVENTION;
4125 else if (fp_register_arg_p (TYPE_CODE (type), type))
4126 {
4127 /* A floating-point value. It fits in the least significant
4128 part of FP0. */
4129 if (mips_debug)
4130 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
ba32f989 4131 mips_xfer_register (gdbarch, regcache,
72a155b4
UW
4132 gdbarch_num_regs (gdbarch)
4133 + mips_regnum (gdbarch)->fp0,
7a076fd2 4134 TYPE_LENGTH (type),
72a155b4 4135 gdbarch_byte_order (gdbarch),
4c6b5505 4136 readbuf, writebuf, 0);
7a076fd2
FF
4137 return RETURN_VALUE_REGISTER_CONVENTION;
4138 }
4139 else
4140 {
4141 /* A scalar extract each part but least-significant-byte
4142 justified. */
4143 int offset;
4144 int regnum;
4145 for (offset = 0, regnum = MIPS_V0_REGNUM;
4146 offset < TYPE_LENGTH (type);
1a69e1e4 4147 offset += MIPS64_REGSIZE, regnum++)
7a076fd2 4148 {
1a69e1e4 4149 int xfer = MIPS64_REGSIZE;
7a076fd2
FF
4150 if (offset + xfer > TYPE_LENGTH (type))
4151 xfer = TYPE_LENGTH (type) - offset;
4152 if (mips_debug)
4153 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4154 offset, xfer, regnum);
ba32f989
DJ
4155 mips_xfer_register (gdbarch, regcache,
4156 gdbarch_num_regs (gdbarch) + regnum,
72a155b4 4157 xfer, gdbarch_byte_order (gdbarch),
4c6b5505 4158 readbuf, writebuf, offset);
7a076fd2
FF
4159 }
4160 return RETURN_VALUE_REGISTER_CONVENTION;
4161 }
6d82d43b
AC
4162}
4163
dd824b04
DJ
4164/* Floating point register management.
4165
4166 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4167 64bit operations, these early MIPS cpus treat fp register pairs
4168 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4169 registers and offer a compatibility mode that emulates the MIPS2 fp
4170 model. When operating in MIPS2 fp compat mode, later cpu's split
4171 double precision floats into two 32-bit chunks and store them in
4172 consecutive fp regs. To display 64-bit floats stored in this
4173 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4174 Throw in user-configurable endianness and you have a real mess.
4175
4176 The way this works is:
4177 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4178 double-precision value will be split across two logical registers.
4179 The lower-numbered logical register will hold the low-order bits,
4180 regardless of the processor's endianness.
4181 - If we are on a 64-bit processor, and we are looking for a
4182 single-precision value, it will be in the low ordered bits
4183 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4184 save slot in memory.
4185 - If we are in 64-bit mode, everything is straightforward.
4186
4187 Note that this code only deals with "live" registers at the top of the
4188 stack. We will attempt to deal with saved registers later, when
4189 the raw/cooked register interface is in place. (We need a general
4190 interface that can deal with dynamic saved register sizes -- fp
4191 regs could be 32 bits wide in one frame and 64 on the frame above
4192 and below). */
4193
67b2c998
DJ
4194static struct type *
4195mips_float_register_type (void)
4196{
8da61cc4 4197 return builtin_type_ieee_single;
67b2c998
DJ
4198}
4199
4200static struct type *
4201mips_double_register_type (void)
4202{
8da61cc4 4203 return builtin_type_ieee_double;
67b2c998
DJ
4204}
4205
dd824b04
DJ
4206/* Copy a 32-bit single-precision value from the current frame
4207 into rare_buffer. */
4208
4209static void
e11c53d2 4210mips_read_fp_register_single (struct frame_info *frame, int regno,
47a35522 4211 gdb_byte *rare_buffer)
dd824b04 4212{
72a155b4
UW
4213 struct gdbarch *gdbarch = get_frame_arch (frame);
4214 int raw_size = register_size (gdbarch, regno);
47a35522 4215 gdb_byte *raw_buffer = alloca (raw_size);
dd824b04 4216
e11c53d2 4217 if (!frame_register_read (frame, regno, raw_buffer))
c9f4d572 4218 error (_("can't read register %d (%s)"),
72a155b4 4219 regno, gdbarch_register_name (gdbarch, regno));
dd824b04
DJ
4220 if (raw_size == 8)
4221 {
4222 /* We have a 64-bit value for this register. Find the low-order
6d82d43b 4223 32 bits. */
dd824b04
DJ
4224 int offset;
4225
72a155b4 4226 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
dd824b04
DJ
4227 offset = 4;
4228 else
4229 offset = 0;
4230
4231 memcpy (rare_buffer, raw_buffer + offset, 4);
4232 }
4233 else
4234 {
4235 memcpy (rare_buffer, raw_buffer, 4);
4236 }
4237}
4238
4239/* Copy a 64-bit double-precision value from the current frame into
4240 rare_buffer. This may include getting half of it from the next
4241 register. */
4242
4243static void
e11c53d2 4244mips_read_fp_register_double (struct frame_info *frame, int regno,
47a35522 4245 gdb_byte *rare_buffer)
dd824b04 4246{
72a155b4
UW
4247 struct gdbarch *gdbarch = get_frame_arch (frame);
4248 int raw_size = register_size (gdbarch, regno);
dd824b04 4249
9c9acae0 4250 if (raw_size == 8 && !mips2_fp_compat (frame))
dd824b04
DJ
4251 {
4252 /* We have a 64-bit value for this register, and we should use
6d82d43b 4253 all 64 bits. */
e11c53d2 4254 if (!frame_register_read (frame, regno, rare_buffer))
c9f4d572 4255 error (_("can't read register %d (%s)"),
72a155b4 4256 regno, gdbarch_register_name (gdbarch, regno));
dd824b04
DJ
4257 }
4258 else
4259 {
72a155b4 4260 int rawnum = regno % gdbarch_num_regs (gdbarch);
82e91389 4261
72a155b4 4262 if ((rawnum - mips_regnum (gdbarch)->fp0) & 1)
dd824b04 4263 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
4264 _("mips_read_fp_register_double: bad access to "
4265 "odd-numbered FP register"));
dd824b04
DJ
4266
4267 /* mips_read_fp_register_single will find the correct 32 bits from
6d82d43b 4268 each register. */
72a155b4 4269 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
dd824b04 4270 {
e11c53d2
AC
4271 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4272 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
dd824b04 4273 }
361d1df0 4274 else
dd824b04 4275 {
e11c53d2
AC
4276 mips_read_fp_register_single (frame, regno, rare_buffer);
4277 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
dd824b04
DJ
4278 }
4279 }
4280}
4281
c906108c 4282static void
e11c53d2
AC
4283mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4284 int regnum)
c5aa993b 4285{ /* do values for FP (float) regs */
72a155b4 4286 struct gdbarch *gdbarch = get_frame_arch (frame);
47a35522 4287 gdb_byte *raw_buffer;
3903d437
AC
4288 double doub, flt1; /* doubles extracted from raw hex data */
4289 int inv1, inv2;
c5aa993b 4290
72a155b4 4291 raw_buffer = alloca (2 * register_size (gdbarch, mips_regnum (gdbarch)->fp0));
c906108c 4292
72a155b4 4293 fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum));
c9f4d572 4294 fprintf_filtered (file, "%*s",
72a155b4 4295 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)),
e11c53d2 4296 "");
f0ef6b29 4297
72a155b4 4298 if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame))
c906108c 4299 {
f0ef6b29
KB
4300 /* 4-byte registers: Print hex and floating. Also print even
4301 numbered registers as doubles. */
e11c53d2 4302 mips_read_fp_register_single (frame, regnum, raw_buffer);
67b2c998 4303 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
c5aa993b 4304
6d82d43b
AC
4305 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
4306 file);
dd824b04 4307
e11c53d2 4308 fprintf_filtered (file, " flt: ");
1adad886 4309 if (inv1)
e11c53d2 4310 fprintf_filtered (file, " <invalid float> ");
1adad886 4311 else
e11c53d2 4312 fprintf_filtered (file, "%-17.9g", flt1);
1adad886 4313
72a155b4 4314 if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0)
f0ef6b29 4315 {
e11c53d2 4316 mips_read_fp_register_double (frame, regnum, raw_buffer);
f0ef6b29 4317 doub = unpack_double (mips_double_register_type (), raw_buffer,
6d82d43b 4318 &inv2);
1adad886 4319
e11c53d2 4320 fprintf_filtered (file, " dbl: ");
f0ef6b29 4321 if (inv2)
e11c53d2 4322 fprintf_filtered (file, "<invalid double>");
f0ef6b29 4323 else
e11c53d2 4324 fprintf_filtered (file, "%-24.17g", doub);
f0ef6b29 4325 }
c906108c
SS
4326 }
4327 else
dd824b04 4328 {
f0ef6b29 4329 /* Eight byte registers: print each one as hex, float and double. */
e11c53d2 4330 mips_read_fp_register_single (frame, regnum, raw_buffer);
2f38ef89 4331 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
c906108c 4332
e11c53d2 4333 mips_read_fp_register_double (frame, regnum, raw_buffer);
f0ef6b29
KB
4334 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4335
361d1df0 4336
6d82d43b
AC
4337 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4338 file);
f0ef6b29 4339
e11c53d2 4340 fprintf_filtered (file, " flt: ");
1adad886 4341 if (inv1)
e11c53d2 4342 fprintf_filtered (file, "<invalid float>");
1adad886 4343 else
e11c53d2 4344 fprintf_filtered (file, "%-17.9g", flt1);
1adad886 4345
e11c53d2 4346 fprintf_filtered (file, " dbl: ");
f0ef6b29 4347 if (inv2)
e11c53d2 4348 fprintf_filtered (file, "<invalid double>");
1adad886 4349 else
e11c53d2 4350 fprintf_filtered (file, "%-24.17g", doub);
f0ef6b29
KB
4351 }
4352}
4353
4354static void
e11c53d2 4355mips_print_register (struct ui_file *file, struct frame_info *frame,
0cc93a06 4356 int regnum)
f0ef6b29 4357{
a4b8ebc8 4358 struct gdbarch *gdbarch = get_frame_arch (frame);
47a35522 4359 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
f0ef6b29 4360 int offset;
1adad886 4361
7b9ee6a8 4362 if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
f0ef6b29 4363 {
e11c53d2 4364 mips_print_fp_register (file, frame, regnum);
f0ef6b29
KB
4365 return;
4366 }
4367
4368 /* Get the data in raw format. */
e11c53d2 4369 if (!frame_register_read (frame, regnum, raw_buffer))
f0ef6b29 4370 {
c9f4d572 4371 fprintf_filtered (file, "%s: [Invalid]",
72a155b4 4372 gdbarch_register_name (gdbarch, regnum));
f0ef6b29 4373 return;
c906108c 4374 }
f0ef6b29 4375
72a155b4 4376 fputs_filtered (gdbarch_register_name (gdbarch, regnum), file);
f0ef6b29
KB
4377
4378 /* The problem with printing numeric register names (r26, etc.) is that
4379 the user can't use them on input. Probably the best solution is to
4380 fix it so that either the numeric or the funky (a2, etc.) names
4381 are accepted on input. */
4382 if (regnum < MIPS_NUMREGS)
e11c53d2 4383 fprintf_filtered (file, "(r%d): ", regnum);
f0ef6b29 4384 else
e11c53d2 4385 fprintf_filtered (file, ": ");
f0ef6b29 4386
72a155b4 4387 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
6d82d43b 4388 offset =
72a155b4 4389 register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
f0ef6b29
KB
4390 else
4391 offset = 0;
4392
6d82d43b 4393 print_scalar_formatted (raw_buffer + offset,
7b9ee6a8 4394 register_type (gdbarch, regnum), 'x', 0,
6d82d43b 4395 file);
c906108c
SS
4396}
4397
f0ef6b29
KB
4398/* Replacement for generic do_registers_info.
4399 Print regs in pretty columns. */
4400
4401static int
e11c53d2
AC
4402print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4403 int regnum)
f0ef6b29 4404{
e11c53d2
AC
4405 fprintf_filtered (file, " ");
4406 mips_print_fp_register (file, frame, regnum);
4407 fprintf_filtered (file, "\n");
f0ef6b29
KB
4408 return regnum + 1;
4409}
4410
4411
c906108c
SS
4412/* Print a row's worth of GP (int) registers, with name labels above */
4413
4414static int
e11c53d2 4415print_gp_register_row (struct ui_file *file, struct frame_info *frame,
a4b8ebc8 4416 int start_regnum)
c906108c 4417{
a4b8ebc8 4418 struct gdbarch *gdbarch = get_frame_arch (frame);
c906108c 4419 /* do values for GP (int) regs */
47a35522 4420 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
d5ac5a39 4421 int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */
c906108c 4422 int col, byte;
a4b8ebc8 4423 int regnum;
c906108c
SS
4424
4425 /* For GP registers, we print a separate row of names above the vals */
a4b8ebc8 4426 for (col = 0, regnum = start_regnum;
72a155b4
UW
4427 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4428 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 4429 regnum++)
c906108c 4430 {
72a155b4 4431 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
c5aa993b 4432 continue; /* unused register */
7b9ee6a8 4433 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
6d82d43b 4434 TYPE_CODE_FLT)
c5aa993b 4435 break; /* end the row: reached FP register */
0cc93a06 4436 /* Large registers are handled separately. */
72a155b4 4437 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
0cc93a06
DJ
4438 {
4439 if (col > 0)
4440 break; /* End the row before this register. */
4441
4442 /* Print this register on a row by itself. */
4443 mips_print_register (file, frame, regnum);
4444 fprintf_filtered (file, "\n");
4445 return regnum + 1;
4446 }
d05f6826
DJ
4447 if (col == 0)
4448 fprintf_filtered (file, " ");
6d82d43b 4449 fprintf_filtered (file,
72a155b4
UW
4450 mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s",
4451 gdbarch_register_name (gdbarch, regnum));
c906108c
SS
4452 col++;
4453 }
d05f6826
DJ
4454
4455 if (col == 0)
4456 return regnum;
4457
a4b8ebc8 4458 /* print the R0 to R31 names */
72a155b4 4459 if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS)
f57d151a 4460 fprintf_filtered (file, "\n R%-4d",
72a155b4 4461 start_regnum % gdbarch_num_regs (gdbarch));
20e6603c
AC
4462 else
4463 fprintf_filtered (file, "\n ");
c906108c 4464
c906108c 4465 /* now print the values in hex, 4 or 8 to the row */
a4b8ebc8 4466 for (col = 0, regnum = start_regnum;
72a155b4
UW
4467 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4468 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 4469 regnum++)
c906108c 4470 {
72a155b4 4471 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
c5aa993b 4472 continue; /* unused register */
7b9ee6a8 4473 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
6d82d43b 4474 TYPE_CODE_FLT)
c5aa993b 4475 break; /* end row: reached FP register */
72a155b4 4476 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
0cc93a06
DJ
4477 break; /* End row: large register. */
4478
c906108c 4479 /* OK: get the data in raw format. */
e11c53d2 4480 if (!frame_register_read (frame, regnum, raw_buffer))
c9f4d572 4481 error (_("can't read register %d (%s)"),
72a155b4 4482 regnum, gdbarch_register_name (gdbarch, regnum));
c906108c 4483 /* pad small registers */
4246e332 4484 for (byte = 0;
72a155b4
UW
4485 byte < (mips_abi_regsize (gdbarch)
4486 - register_size (gdbarch, regnum)); byte++)
c906108c
SS
4487 printf_filtered (" ");
4488 /* Now print the register value in hex, endian order. */
72a155b4 4489 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
6d82d43b 4490 for (byte =
72a155b4
UW
4491 register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
4492 byte < register_size (gdbarch, regnum); byte++)
47a35522 4493 fprintf_filtered (file, "%02x", raw_buffer[byte]);
c906108c 4494 else
72a155b4 4495 for (byte = register_size (gdbarch, regnum) - 1;
6d82d43b 4496 byte >= 0; byte--)
47a35522 4497 fprintf_filtered (file, "%02x", raw_buffer[byte]);
e11c53d2 4498 fprintf_filtered (file, " ");
c906108c
SS
4499 col++;
4500 }
c5aa993b 4501 if (col > 0) /* ie. if we actually printed anything... */
e11c53d2 4502 fprintf_filtered (file, "\n");
c906108c
SS
4503
4504 return regnum;
4505}
4506
4507/* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
4508
bf1f5b4c 4509static void
e11c53d2
AC
4510mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4511 struct frame_info *frame, int regnum, int all)
c906108c 4512{
c5aa993b 4513 if (regnum != -1) /* do one specified register */
c906108c 4514 {
72a155b4
UW
4515 gdb_assert (regnum >= gdbarch_num_regs (gdbarch));
4516 if (*(gdbarch_register_name (gdbarch, regnum)) == '\0')
8a3fe4f8 4517 error (_("Not a valid register for the current processor type"));
c906108c 4518
0cc93a06 4519 mips_print_register (file, frame, regnum);
e11c53d2 4520 fprintf_filtered (file, "\n");
c906108c 4521 }
c5aa993b
JM
4522 else
4523 /* do all (or most) registers */
c906108c 4524 {
72a155b4
UW
4525 regnum = gdbarch_num_regs (gdbarch);
4526 while (regnum < gdbarch_num_regs (gdbarch)
4527 + gdbarch_num_pseudo_regs (gdbarch))
c906108c 4528 {
7b9ee6a8 4529 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
6d82d43b 4530 TYPE_CODE_FLT)
e11c53d2
AC
4531 {
4532 if (all) /* true for "INFO ALL-REGISTERS" command */
4533 regnum = print_fp_register_row (file, frame, regnum);
4534 else
4535 regnum += MIPS_NUMREGS; /* skip floating point regs */
4536 }
c906108c 4537 else
e11c53d2 4538 regnum = print_gp_register_row (file, frame, regnum);
c906108c
SS
4539 }
4540 }
4541}
4542
c906108c
SS
4543/* Is this a branch with a delay slot? */
4544
c906108c 4545static int
acdb74a0 4546is_delayed (unsigned long insn)
c906108c
SS
4547{
4548 int i;
4549 for (i = 0; i < NUMOPCODES; ++i)
4550 if (mips_opcodes[i].pinfo != INSN_MACRO
4551 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4552 break;
4553 return (i < NUMOPCODES
4554 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4555 | INSN_COND_BRANCH_DELAY
4556 | INSN_COND_BRANCH_LIKELY)));
4557}
4558
4559int
3352ef37
AC
4560mips_single_step_through_delay (struct gdbarch *gdbarch,
4561 struct frame_info *frame)
c906108c 4562{
3352ef37 4563 CORE_ADDR pc = get_frame_pc (frame);
47a35522 4564 gdb_byte buf[MIPS_INSN32_SIZE];
c906108c
SS
4565
4566 /* There is no branch delay slot on MIPS16. */
0fe7e7c8 4567 if (mips_pc_is_mips16 (pc))
c906108c
SS
4568 return 0;
4569
06648491
MK
4570 if (!breakpoint_here_p (pc + 4))
4571 return 0;
4572
3352ef37
AC
4573 if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf))
4574 /* If error reading memory, guess that it is not a delayed
4575 branch. */
c906108c 4576 return 0;
4c7d22cb 4577 return is_delayed (extract_unsigned_integer (buf, sizeof buf));
c906108c
SS
4578}
4579
6d82d43b
AC
4580/* To skip prologues, I use this predicate. Returns either PC itself
4581 if the code at PC does not look like a function prologue; otherwise
4582 returns an address that (if we're lucky) follows the prologue. If
4583 LENIENT, then we must skip everything which is involved in setting
4584 up the frame (it's OK to skip more, just so long as we don't skip
4585 anything which might clobber the registers which are being saved.
4586 We must skip more in the case where part of the prologue is in the
4587 delay slot of a non-prologue instruction). */
4588
4589static CORE_ADDR
6093d2eb 4590mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
6d82d43b 4591{
8b622e6a
AC
4592 CORE_ADDR limit_pc;
4593 CORE_ADDR func_addr;
4594
6d82d43b
AC
4595 /* See if we can determine the end of the prologue via the symbol table.
4596 If so, then return either PC, or the PC after the prologue, whichever
4597 is greater. */
8b622e6a
AC
4598 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
4599 {
4600 CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr);
4601 if (post_prologue_pc != 0)
4602 return max (pc, post_prologue_pc);
4603 }
6d82d43b
AC
4604
4605 /* Can't determine prologue from the symbol table, need to examine
4606 instructions. */
4607
98b4dd94
JB
4608 /* Find an upper limit on the function prologue using the debug
4609 information. If the debug information could not be used to provide
4610 that bound, then use an arbitrary large number as the upper bound. */
4611 limit_pc = skip_prologue_using_sal (pc);
4612 if (limit_pc == 0)
4613 limit_pc = pc + 100; /* Magic. */
4614
0fe7e7c8 4615 if (mips_pc_is_mips16 (pc))
a65bbe44 4616 return mips16_scan_prologue (pc, limit_pc, NULL, NULL);
6d82d43b 4617 else
a65bbe44 4618 return mips32_scan_prologue (pc, limit_pc, NULL, NULL);
88658117
AC
4619}
4620
97ab0fdd
MR
4621/* Check whether the PC is in a function epilogue (32-bit version).
4622 This is a helper function for mips_in_function_epilogue_p. */
4623static int
4624mips32_in_function_epilogue_p (CORE_ADDR pc)
4625{
4626 CORE_ADDR func_addr = 0, func_end = 0;
4627
4628 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4629 {
4630 /* The MIPS epilogue is max. 12 bytes long. */
4631 CORE_ADDR addr = func_end - 12;
4632
4633 if (addr < func_addr + 4)
4634 addr = func_addr + 4;
4635 if (pc < addr)
4636 return 0;
4637
4638 for (; pc < func_end; pc += MIPS_INSN32_SIZE)
4639 {
4640 unsigned long high_word;
4641 unsigned long inst;
4642
4643 inst = mips_fetch_instruction (pc);
4644 high_word = (inst >> 16) & 0xffff;
4645
4646 if (high_word != 0x27bd /* addiu $sp,$sp,offset */
4647 && high_word != 0x67bd /* daddiu $sp,$sp,offset */
4648 && inst != 0x03e00008 /* jr $ra */
4649 && inst != 0x00000000) /* nop */
4650 return 0;
4651 }
4652
4653 return 1;
4654 }
4655
4656 return 0;
4657}
4658
4659/* Check whether the PC is in a function epilogue (16-bit version).
4660 This is a helper function for mips_in_function_epilogue_p. */
4661static int
4662mips16_in_function_epilogue_p (CORE_ADDR pc)
4663{
4664 CORE_ADDR func_addr = 0, func_end = 0;
4665
4666 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4667 {
4668 /* The MIPS epilogue is max. 12 bytes long. */
4669 CORE_ADDR addr = func_end - 12;
4670
4671 if (addr < func_addr + 4)
4672 addr = func_addr + 4;
4673 if (pc < addr)
4674 return 0;
4675
4676 for (; pc < func_end; pc += MIPS_INSN16_SIZE)
4677 {
4678 unsigned short inst;
4679
4680 inst = mips_fetch_instruction (pc);
4681
4682 if ((inst & 0xf800) == 0xf000) /* extend */
4683 continue;
4684
4685 if (inst != 0x6300 /* addiu $sp,offset */
4686 && inst != 0xfb00 /* daddiu $sp,$sp,offset */
4687 && inst != 0xe820 /* jr $ra */
4688 && inst != 0xe8a0 /* jrc $ra */
4689 && inst != 0x6500) /* nop */
4690 return 0;
4691 }
4692
4693 return 1;
4694 }
4695
4696 return 0;
4697}
4698
4699/* The epilogue is defined here as the area at the end of a function,
4700 after an instruction which destroys the function's stack frame. */
4701static int
4702mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
4703{
4704 if (mips_pc_is_mips16 (pc))
4705 return mips16_in_function_epilogue_p (pc);
4706 else
4707 return mips32_in_function_epilogue_p (pc);
4708}
4709
a5ea2558
AC
4710/* Root of all "set mips "/"show mips " commands. This will eventually be
4711 used for all MIPS-specific commands. */
4712
a5ea2558 4713static void
acdb74a0 4714show_mips_command (char *args, int from_tty)
a5ea2558
AC
4715{
4716 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
4717}
4718
a5ea2558 4719static void
acdb74a0 4720set_mips_command (char *args, int from_tty)
a5ea2558 4721{
6d82d43b
AC
4722 printf_unfiltered
4723 ("\"set mips\" must be followed by an appropriate subcommand.\n");
a5ea2558
AC
4724 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
4725}
4726
c906108c
SS
4727/* Commands to show/set the MIPS FPU type. */
4728
c906108c 4729static void
acdb74a0 4730show_mipsfpu_command (char *args, int from_tty)
c906108c 4731{
c906108c 4732 char *fpu;
6ca0852e
UW
4733
4734 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
4735 {
4736 printf_unfiltered
4737 ("The MIPS floating-point coprocessor is unknown "
4738 "because the current architecture is not MIPS.\n");
4739 return;
4740 }
4741
c906108c
SS
4742 switch (MIPS_FPU_TYPE)
4743 {
4744 case MIPS_FPU_SINGLE:
4745 fpu = "single-precision";
4746 break;
4747 case MIPS_FPU_DOUBLE:
4748 fpu = "double-precision";
4749 break;
4750 case MIPS_FPU_NONE:
4751 fpu = "absent (none)";
4752 break;
93d56215 4753 default:
e2e0b3e5 4754 internal_error (__FILE__, __LINE__, _("bad switch"));
c906108c
SS
4755 }
4756 if (mips_fpu_type_auto)
6d82d43b
AC
4757 printf_unfiltered
4758 ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
4759 fpu);
c906108c 4760 else
6d82d43b
AC
4761 printf_unfiltered
4762 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu);
c906108c
SS
4763}
4764
4765
c906108c 4766static void
acdb74a0 4767set_mipsfpu_command (char *args, int from_tty)
c906108c 4768{
6d82d43b
AC
4769 printf_unfiltered
4770 ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
c906108c
SS
4771 show_mipsfpu_command (args, from_tty);
4772}
4773
c906108c 4774static void
acdb74a0 4775set_mipsfpu_single_command (char *args, int from_tty)
c906108c 4776{
8d5838b5
AC
4777 struct gdbarch_info info;
4778 gdbarch_info_init (&info);
c906108c
SS
4779 mips_fpu_type = MIPS_FPU_SINGLE;
4780 mips_fpu_type_auto = 0;
8d5838b5
AC
4781 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4782 instead of relying on globals. Doing that would let generic code
4783 handle the search for this specific architecture. */
4784 if (!gdbarch_update_p (info))
e2e0b3e5 4785 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
c906108c
SS
4786}
4787
c906108c 4788static void
acdb74a0 4789set_mipsfpu_double_command (char *args, int from_tty)
c906108c 4790{
8d5838b5
AC
4791 struct gdbarch_info info;
4792 gdbarch_info_init (&info);
c906108c
SS
4793 mips_fpu_type = MIPS_FPU_DOUBLE;
4794 mips_fpu_type_auto = 0;
8d5838b5
AC
4795 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4796 instead of relying on globals. Doing that would let generic code
4797 handle the search for this specific architecture. */
4798 if (!gdbarch_update_p (info))
e2e0b3e5 4799 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
c906108c
SS
4800}
4801
c906108c 4802static void
acdb74a0 4803set_mipsfpu_none_command (char *args, int from_tty)
c906108c 4804{
8d5838b5
AC
4805 struct gdbarch_info info;
4806 gdbarch_info_init (&info);
c906108c
SS
4807 mips_fpu_type = MIPS_FPU_NONE;
4808 mips_fpu_type_auto = 0;
8d5838b5
AC
4809 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
4810 instead of relying on globals. Doing that would let generic code
4811 handle the search for this specific architecture. */
4812 if (!gdbarch_update_p (info))
e2e0b3e5 4813 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
c906108c
SS
4814}
4815
c906108c 4816static void
acdb74a0 4817set_mipsfpu_auto_command (char *args, int from_tty)
c906108c
SS
4818{
4819 mips_fpu_type_auto = 1;
4820}
4821
c906108c 4822/* Attempt to identify the particular processor model by reading the
691c0433
AC
4823 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
4824 the relevant processor still exists (it dates back to '94) and
4825 secondly this is not the way to do this. The processor type should
4826 be set by forcing an architecture change. */
c906108c 4827
691c0433
AC
4828void
4829deprecated_mips_set_processor_regs_hack (void)
c906108c 4830{
691c0433 4831 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
a9614958 4832 ULONGEST prid;
c906108c 4833
594f7785 4834 regcache_cooked_read_unsigned (get_current_regcache (),
a9614958 4835 MIPS_PRID_REGNUM, &prid);
c906108c 4836 if ((prid & ~0xf) == 0x700)
691c0433 4837 tdep->mips_processor_reg_names = mips_r3041_reg_names;
c906108c
SS
4838}
4839
4840/* Just like reinit_frame_cache, but with the right arguments to be
4841 callable as an sfunc. */
4842
4843static void
acdb74a0
AC
4844reinit_frame_cache_sfunc (char *args, int from_tty,
4845 struct cmd_list_element *c)
c906108c
SS
4846{
4847 reinit_frame_cache ();
4848}
4849
a89aa300
AC
4850static int
4851gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
c906108c 4852{
e5ab0dce 4853 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
c906108c 4854
d31431ed
AC
4855 /* FIXME: cagney/2003-06-26: Is this even necessary? The
4856 disassembler needs to be able to locally determine the ISA, and
4857 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
4858 work. */
ec4045ea
AC
4859 if (mips_pc_is_mips16 (memaddr))
4860 info->mach = bfd_mach_mips16;
c906108c
SS
4861
4862 /* Round down the instruction address to the appropriate boundary. */
65c11066 4863 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
c5aa993b 4864
e5ab0dce 4865 /* Set the disassembler options. */
6d82d43b 4866 if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64)
e5ab0dce
AC
4867 {
4868 /* Set up the disassembler info, so that we get the right
6d82d43b 4869 register names from libopcodes. */
e5ab0dce
AC
4870 if (tdep->mips_abi == MIPS_ABI_N32)
4871 info->disassembler_options = "gpr-names=n32";
4872 else
4873 info->disassembler_options = "gpr-names=64";
4874 info->flavour = bfd_target_elf_flavour;
4875 }
4876 else
4877 /* This string is not recognized explicitly by the disassembler,
4878 but it tells the disassembler to not try to guess the ABI from
4879 the bfd elf headers, such that, if the user overrides the ABI
4880 of a program linked as NewABI, the disassembly will follow the
4881 register naming conventions specified by the user. */
4882 info->disassembler_options = "gpr-names=32";
4883
c906108c 4884 /* Call the appropriate disassembler based on the target endian-ness. */
40887e1a 4885 if (info->endian == BFD_ENDIAN_BIG)
c906108c
SS
4886 return print_insn_big_mips (memaddr, info);
4887 else
4888 return print_insn_little_mips (memaddr, info);
4889}
4890
3b3b875c
UW
4891/* This function implements gdbarch_breakpoint_from_pc. It uses the program
4892 counter value to determine whether a 16- or 32-bit breakpoint should be used.
4893 It returns a pointer to a string of bytes that encode a breakpoint
4894 instruction, stores the length of the string to *lenptr, and adjusts pc (if
4895 necessary) to point to the actual memory location where the breakpoint
4896 should be inserted. */
c906108c 4897
47a35522 4898static const gdb_byte *
67d57894 4899mips_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
c906108c 4900{
67d57894 4901 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
c906108c 4902 {
0fe7e7c8 4903 if (mips_pc_is_mips16 (*pcptr))
c906108c 4904 {
47a35522 4905 static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
95404a3e 4906 *pcptr = unmake_mips16_addr (*pcptr);
c5aa993b 4907 *lenptr = sizeof (mips16_big_breakpoint);
c906108c
SS
4908 return mips16_big_breakpoint;
4909 }
4910 else
4911 {
aaab4dba
AC
4912 /* The IDT board uses an unusual breakpoint value, and
4913 sometimes gets confused when it sees the usual MIPS
4914 breakpoint instruction. */
47a35522
MK
4915 static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
4916 static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
4917 static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
c906108c 4918
c5aa993b 4919 *lenptr = sizeof (big_breakpoint);
c906108c
SS
4920
4921 if (strcmp (target_shortname, "mips") == 0)
4922 return idt_big_breakpoint;
4923 else if (strcmp (target_shortname, "ddb") == 0
4924 || strcmp (target_shortname, "pmon") == 0
4925 || strcmp (target_shortname, "lsi") == 0)
4926 return pmon_big_breakpoint;
4927 else
4928 return big_breakpoint;
4929 }
4930 }
4931 else
4932 {
0fe7e7c8 4933 if (mips_pc_is_mips16 (*pcptr))
c906108c 4934 {
47a35522 4935 static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
95404a3e 4936 *pcptr = unmake_mips16_addr (*pcptr);
c5aa993b 4937 *lenptr = sizeof (mips16_little_breakpoint);
c906108c
SS
4938 return mips16_little_breakpoint;
4939 }
4940 else
4941 {
47a35522
MK
4942 static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
4943 static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
4944 static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
c906108c 4945
c5aa993b 4946 *lenptr = sizeof (little_breakpoint);
c906108c
SS
4947
4948 if (strcmp (target_shortname, "mips") == 0)
4949 return idt_little_breakpoint;
4950 else if (strcmp (target_shortname, "ddb") == 0
4951 || strcmp (target_shortname, "pmon") == 0
4952 || strcmp (target_shortname, "lsi") == 0)
4953 return pmon_little_breakpoint;
4954 else
4955 return little_breakpoint;
4956 }
4957 }
4958}
4959
4960/* If PC is in a mips16 call or return stub, return the address of the target
4961 PC, which is either the callee or the caller. There are several
4962 cases which must be handled:
4963
4964 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
c5aa993b 4965 target PC is in $31 ($ra).
c906108c 4966 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
c5aa993b 4967 and the target PC is in $2.
c906108c 4968 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
c5aa993b
JM
4969 before the jal instruction, this is effectively a call stub
4970 and the the target PC is in $2. Otherwise this is effectively
4971 a return stub and the target PC is in $18.
c906108c
SS
4972
4973 See the source code for the stubs in gcc/config/mips/mips16.S for
e7d6a6d2 4974 gory details. */
c906108c 4975
757a7cc6 4976static CORE_ADDR
52f729a7 4977mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
c906108c
SS
4978{
4979 char *name;
4980 CORE_ADDR start_addr;
4981
4982 /* Find the starting address and name of the function containing the PC. */
4983 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
4984 return 0;
4985
4986 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
4987 target PC is in $31 ($ra). */
4988 if (strcmp (name, "__mips16_ret_sf") == 0
4989 || strcmp (name, "__mips16_ret_df") == 0)
52f729a7 4990 return get_frame_register_signed (frame, MIPS_RA_REGNUM);
c906108c
SS
4991
4992 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
4993 {
4994 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
4995 and the target PC is in $2. */
4996 if (name[19] >= '0' && name[19] <= '9')
52f729a7 4997 return get_frame_register_signed (frame, 2);
c906108c
SS
4998
4999 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
c5aa993b
JM
5000 before the jal instruction, this is effectively a call stub
5001 and the the target PC is in $2. Otherwise this is effectively
5002 a return stub and the target PC is in $18. */
c906108c
SS
5003 else if (name[19] == 's' || name[19] == 'd')
5004 {
5005 if (pc == start_addr)
5006 {
5007 /* Check if the target of the stub is a compiler-generated
c5aa993b
JM
5008 stub. Such a stub for a function bar might have a name
5009 like __fn_stub_bar, and might look like this:
5010 mfc1 $4,$f13
5011 mfc1 $5,$f12
5012 mfc1 $6,$f15
5013 mfc1 $7,$f14
5014 la $1,bar (becomes a lui/addiu pair)
5015 jr $1
5016 So scan down to the lui/addi and extract the target
5017 address from those two instructions. */
c906108c 5018
52f729a7 5019 CORE_ADDR target_pc = get_frame_register_signed (frame, 2);
d37cca3d 5020 ULONGEST inst;
c906108c
SS
5021 int i;
5022
5023 /* See if the name of the target function is __fn_stub_*. */
6d82d43b
AC
5024 if (find_pc_partial_function (target_pc, &name, NULL, NULL) ==
5025 0)
c906108c
SS
5026 return target_pc;
5027 if (strncmp (name, "__fn_stub_", 10) != 0
5028 && strcmp (name, "etext") != 0
5029 && strcmp (name, "_etext") != 0)
5030 return target_pc;
5031
5032 /* Scan through this _fn_stub_ code for the lui/addiu pair.
c5aa993b
JM
5033 The limit on the search is arbitrarily set to 20
5034 instructions. FIXME. */
95ac2dcf 5035 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE)
c906108c 5036 {
c5aa993b
JM
5037 inst = mips_fetch_instruction (target_pc);
5038 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5039 pc = (inst << 16) & 0xffff0000; /* high word */
5040 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5041 return pc | (inst & 0xffff); /* low word */
c906108c
SS
5042 }
5043
5044 /* Couldn't find the lui/addui pair, so return stub address. */
5045 return target_pc;
5046 }
5047 else
5048 /* This is the 'return' part of a call stub. The return
5049 address is in $r18. */
52f729a7 5050 return get_frame_register_signed (frame, 18);
c906108c
SS
5051 }
5052 }
c5aa993b 5053 return 0; /* not a stub */
c906108c
SS
5054}
5055
a4b8ebc8 5056/* Convert a dbx stab register number (from `r' declaration) to a GDB
f57d151a 5057 [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
88c72b7d
AC
5058
5059static int
d3f73121 5060mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
88c72b7d 5061{
a4b8ebc8 5062 int regnum;
2f38ef89 5063 if (num >= 0 && num < 32)
a4b8ebc8 5064 regnum = num;
2f38ef89 5065 else if (num >= 38 && num < 70)
d3f73121 5066 regnum = num + mips_regnum (gdbarch)->fp0 - 38;
040b99fd 5067 else if (num == 70)
d3f73121 5068 regnum = mips_regnum (gdbarch)->hi;
040b99fd 5069 else if (num == 71)
d3f73121 5070 regnum = mips_regnum (gdbarch)->lo;
2f38ef89 5071 else
a4b8ebc8
AC
5072 /* This will hopefully (eventually) provoke a warning. Should
5073 we be calling complaint() here? */
d3f73121
MD
5074 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5075 return gdbarch_num_regs (gdbarch) + regnum;
88c72b7d
AC
5076}
5077
2f38ef89 5078
a4b8ebc8 5079/* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
f57d151a 5080 gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
88c72b7d
AC
5081
5082static int
d3f73121 5083mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num)
88c72b7d 5084{
a4b8ebc8 5085 int regnum;
2f38ef89 5086 if (num >= 0 && num < 32)
a4b8ebc8 5087 regnum = num;
2f38ef89 5088 else if (num >= 32 && num < 64)
d3f73121 5089 regnum = num + mips_regnum (gdbarch)->fp0 - 32;
040b99fd 5090 else if (num == 64)
d3f73121 5091 regnum = mips_regnum (gdbarch)->hi;
040b99fd 5092 else if (num == 65)
d3f73121 5093 regnum = mips_regnum (gdbarch)->lo;
2f38ef89 5094 else
a4b8ebc8
AC
5095 /* This will hopefully (eventually) provoke a warning. Should we
5096 be calling complaint() here? */
d3f73121
MD
5097 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5098 return gdbarch_num_regs (gdbarch) + regnum;
a4b8ebc8
AC
5099}
5100
5101static int
e7faf938 5102mips_register_sim_regno (struct gdbarch *gdbarch, int regnum)
a4b8ebc8
AC
5103{
5104 /* Only makes sense to supply raw registers. */
e7faf938 5105 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
a4b8ebc8
AC
5106 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5107 decide if it is valid. Should instead define a standard sim/gdb
5108 register numbering scheme. */
e7faf938
MD
5109 if (gdbarch_register_name (gdbarch,
5110 gdbarch_num_regs (gdbarch) + regnum) != NULL
5111 && gdbarch_register_name (gdbarch,
5112 gdbarch_num_regs (gdbarch) + regnum)[0] != '\0')
a4b8ebc8
AC
5113 return regnum;
5114 else
6d82d43b 5115 return LEGACY_SIM_REGNO_IGNORE;
88c72b7d
AC
5116}
5117
2f38ef89 5118
4844f454
CV
5119/* Convert an integer into an address. Extracting the value signed
5120 guarantees a correctly sign extended address. */
fc0c74b1
AC
5121
5122static CORE_ADDR
79dd2d24 5123mips_integer_to_address (struct gdbarch *gdbarch,
870cd05e 5124 struct type *type, const gdb_byte *buf)
fc0c74b1 5125{
4844f454 5126 return (CORE_ADDR) extract_signed_integer (buf, TYPE_LENGTH (type));
fc0c74b1
AC
5127}
5128
82e91389
DJ
5129/* Dummy virtual frame pointer method. This is no more or less accurate
5130 than most other architectures; we just need to be explicit about it,
5131 because the pseudo-register gdbarch_sp_regnum will otherwise lead to
5132 an assertion failure. */
5133
5134static void
a54fba4c
MD
5135mips_virtual_frame_pointer (struct gdbarch *gdbarch,
5136 CORE_ADDR pc, int *reg, LONGEST *offset)
82e91389
DJ
5137{
5138 *reg = MIPS_SP_REGNUM;
5139 *offset = 0;
5140}
5141
caaa3122
DJ
5142static void
5143mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5144{
5145 enum mips_abi *abip = (enum mips_abi *) obj;
5146 const char *name = bfd_get_section_name (abfd, sect);
5147
5148 if (*abip != MIPS_ABI_UNKNOWN)
5149 return;
5150
5151 if (strncmp (name, ".mdebug.", 8) != 0)
5152 return;
5153
5154 if (strcmp (name, ".mdebug.abi32") == 0)
5155 *abip = MIPS_ABI_O32;
5156 else if (strcmp (name, ".mdebug.abiN32") == 0)
5157 *abip = MIPS_ABI_N32;
62a49b2c 5158 else if (strcmp (name, ".mdebug.abi64") == 0)
e3bddbfa 5159 *abip = MIPS_ABI_N64;
caaa3122
DJ
5160 else if (strcmp (name, ".mdebug.abiO64") == 0)
5161 *abip = MIPS_ABI_O64;
5162 else if (strcmp (name, ".mdebug.eabi32") == 0)
5163 *abip = MIPS_ABI_EABI32;
5164 else if (strcmp (name, ".mdebug.eabi64") == 0)
5165 *abip = MIPS_ABI_EABI64;
5166 else
8a3fe4f8 5167 warning (_("unsupported ABI %s."), name + 8);
caaa3122
DJ
5168}
5169
22e47e37
FF
5170static void
5171mips_find_long_section (bfd *abfd, asection *sect, void *obj)
5172{
5173 int *lbp = (int *) obj;
5174 const char *name = bfd_get_section_name (abfd, sect);
5175
5176 if (strncmp (name, ".gcc_compiled_long32", 20) == 0)
5177 *lbp = 32;
5178 else if (strncmp (name, ".gcc_compiled_long64", 20) == 0)
5179 *lbp = 64;
5180 else if (strncmp (name, ".gcc_compiled_long", 18) == 0)
5181 warning (_("unrecognized .gcc_compiled_longXX"));
5182}
5183
2e4ebe70
DJ
5184static enum mips_abi
5185global_mips_abi (void)
5186{
5187 int i;
5188
5189 for (i = 0; mips_abi_strings[i] != NULL; i++)
5190 if (mips_abi_strings[i] == mips_abi_string)
5191 return (enum mips_abi) i;
5192
e2e0b3e5 5193 internal_error (__FILE__, __LINE__, _("unknown ABI string"));
2e4ebe70
DJ
5194}
5195
29709017
DJ
5196static void
5197mips_register_g_packet_guesses (struct gdbarch *gdbarch)
5198{
29709017
DJ
5199 /* If the size matches the set of 32-bit or 64-bit integer registers,
5200 assume that's what we've got. */
4eb0ad19
DJ
5201 register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32);
5202 register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64);
29709017
DJ
5203
5204 /* If the size matches the full set of registers GDB traditionally
5205 knows about, including floating point, for either 32-bit or
5206 64-bit, assume that's what we've got. */
4eb0ad19
DJ
5207 register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32);
5208 register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64);
29709017
DJ
5209
5210 /* Otherwise we don't have a useful guess. */
5211}
5212
f8b73d13
DJ
5213static struct value *
5214value_of_mips_user_reg (struct frame_info *frame, const void *baton)
5215{
5216 const int *reg_p = baton;
5217 return value_of_register (*reg_p, frame);
5218}
5219
c2d11a7d 5220static struct gdbarch *
6d82d43b 5221mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
c2d11a7d 5222{
c2d11a7d
JM
5223 struct gdbarch *gdbarch;
5224 struct gdbarch_tdep *tdep;
5225 int elf_flags;
2e4ebe70 5226 enum mips_abi mips_abi, found_abi, wanted_abi;
f8b73d13 5227 int i, num_regs;
8d5838b5 5228 enum mips_fpu_type fpu_type;
f8b73d13 5229 struct tdesc_arch_data *tdesc_data = NULL;
609ca2b9 5230 int elf_fpu_type = 0;
f8b73d13
DJ
5231
5232 /* Check any target description for validity. */
5233 if (tdesc_has_registers (info.target_desc))
5234 {
5235 static const char *const mips_gprs[] = {
5236 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5237 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5238 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5239 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5240 };
5241 static const char *const mips_fprs[] = {
5242 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5243 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5244 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5245 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
5246 };
5247
5248 const struct tdesc_feature *feature;
5249 int valid_p;
5250
5251 feature = tdesc_find_feature (info.target_desc,
5252 "org.gnu.gdb.mips.cpu");
5253 if (feature == NULL)
5254 return NULL;
5255
5256 tdesc_data = tdesc_data_alloc ();
5257
5258 valid_p = 1;
5259 for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++)
5260 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
5261 mips_gprs[i]);
5262
5263
5264 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5265 MIPS_EMBED_LO_REGNUM, "lo");
5266 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5267 MIPS_EMBED_HI_REGNUM, "hi");
5268 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5269 MIPS_EMBED_PC_REGNUM, "pc");
5270
5271 if (!valid_p)
5272 {
5273 tdesc_data_cleanup (tdesc_data);
5274 return NULL;
5275 }
5276
5277 feature = tdesc_find_feature (info.target_desc,
5278 "org.gnu.gdb.mips.cp0");
5279 if (feature == NULL)
5280 {
5281 tdesc_data_cleanup (tdesc_data);
5282 return NULL;
5283 }
5284
5285 valid_p = 1;
5286 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5287 MIPS_EMBED_BADVADDR_REGNUM,
5288 "badvaddr");
5289 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5290 MIPS_PS_REGNUM, "status");
5291 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5292 MIPS_EMBED_CAUSE_REGNUM, "cause");
5293
5294 if (!valid_p)
5295 {
5296 tdesc_data_cleanup (tdesc_data);
5297 return NULL;
5298 }
5299
5300 /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
5301 backend is not prepared for that, though. */
5302 feature = tdesc_find_feature (info.target_desc,
5303 "org.gnu.gdb.mips.fpu");
5304 if (feature == NULL)
5305 {
5306 tdesc_data_cleanup (tdesc_data);
5307 return NULL;
5308 }
5309
5310 valid_p = 1;
5311 for (i = 0; i < 32; i++)
5312 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5313 i + MIPS_EMBED_FP0_REGNUM,
5314 mips_fprs[i]);
5315
5316 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5317 MIPS_EMBED_FP0_REGNUM + 32, "fcsr");
5318 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5319 MIPS_EMBED_FP0_REGNUM + 33, "fir");
5320
5321 if (!valid_p)
5322 {
5323 tdesc_data_cleanup (tdesc_data);
5324 return NULL;
5325 }
5326
5327 /* It would be nice to detect an attempt to use a 64-bit ABI
5328 when only 32-bit registers are provided. */
5329 }
c2d11a7d 5330
ec03c1ac
AC
5331 /* First of all, extract the elf_flags, if available. */
5332 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5333 elf_flags = elf_elfheader (info.abfd)->e_flags;
6214a8a1
AC
5334 else if (arches != NULL)
5335 elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags;
ec03c1ac
AC
5336 else
5337 elf_flags = 0;
5338 if (gdbarch_debug)
5339 fprintf_unfiltered (gdb_stdlog,
6d82d43b 5340 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags);
c2d11a7d 5341
102182a9 5342 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
0dadbba0
AC
5343 switch ((elf_flags & EF_MIPS_ABI))
5344 {
5345 case E_MIPS_ABI_O32:
ec03c1ac 5346 found_abi = MIPS_ABI_O32;
0dadbba0
AC
5347 break;
5348 case E_MIPS_ABI_O64:
ec03c1ac 5349 found_abi = MIPS_ABI_O64;
0dadbba0
AC
5350 break;
5351 case E_MIPS_ABI_EABI32:
ec03c1ac 5352 found_abi = MIPS_ABI_EABI32;
0dadbba0
AC
5353 break;
5354 case E_MIPS_ABI_EABI64:
ec03c1ac 5355 found_abi = MIPS_ABI_EABI64;
0dadbba0
AC
5356 break;
5357 default:
acdb74a0 5358 if ((elf_flags & EF_MIPS_ABI2))
ec03c1ac 5359 found_abi = MIPS_ABI_N32;
acdb74a0 5360 else
ec03c1ac 5361 found_abi = MIPS_ABI_UNKNOWN;
0dadbba0
AC
5362 break;
5363 }
acdb74a0 5364
caaa3122 5365 /* GCC creates a pseudo-section whose name describes the ABI. */
ec03c1ac
AC
5366 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5367 bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi);
caaa3122 5368
dc305454 5369 /* If we have no useful BFD information, use the ABI from the last
ec03c1ac
AC
5370 MIPS architecture (if there is one). */
5371 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
5372 found_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
2e4ebe70 5373
32a6503c 5374 /* Try the architecture for any hint of the correct ABI. */
ec03c1ac 5375 if (found_abi == MIPS_ABI_UNKNOWN
bf64bfd6
AC
5376 && info.bfd_arch_info != NULL
5377 && info.bfd_arch_info->arch == bfd_arch_mips)
5378 {
5379 switch (info.bfd_arch_info->mach)
5380 {
5381 case bfd_mach_mips3900:
ec03c1ac 5382 found_abi = MIPS_ABI_EABI32;
bf64bfd6
AC
5383 break;
5384 case bfd_mach_mips4100:
5385 case bfd_mach_mips5000:
ec03c1ac 5386 found_abi = MIPS_ABI_EABI64;
bf64bfd6 5387 break;
1d06468c
EZ
5388 case bfd_mach_mips8000:
5389 case bfd_mach_mips10000:
32a6503c
KB
5390 /* On Irix, ELF64 executables use the N64 ABI. The
5391 pseudo-sections which describe the ABI aren't present
5392 on IRIX. (Even for executables created by gcc.) */
28d169de
KB
5393 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5394 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
ec03c1ac 5395 found_abi = MIPS_ABI_N64;
28d169de 5396 else
ec03c1ac 5397 found_abi = MIPS_ABI_N32;
1d06468c 5398 break;
bf64bfd6
AC
5399 }
5400 }
2e4ebe70 5401
26c53e50
DJ
5402 /* Default 64-bit objects to N64 instead of O32. */
5403 if (found_abi == MIPS_ABI_UNKNOWN
5404 && info.abfd != NULL
5405 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5406 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5407 found_abi = MIPS_ABI_N64;
5408
ec03c1ac
AC
5409 if (gdbarch_debug)
5410 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n",
5411 found_abi);
5412
5413 /* What has the user specified from the command line? */
5414 wanted_abi = global_mips_abi ();
5415 if (gdbarch_debug)
5416 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n",
5417 wanted_abi);
2e4ebe70
DJ
5418
5419 /* Now that we have found what the ABI for this binary would be,
5420 check whether the user is overriding it. */
2e4ebe70
DJ
5421 if (wanted_abi != MIPS_ABI_UNKNOWN)
5422 mips_abi = wanted_abi;
ec03c1ac
AC
5423 else if (found_abi != MIPS_ABI_UNKNOWN)
5424 mips_abi = found_abi;
5425 else
5426 mips_abi = MIPS_ABI_O32;
5427 if (gdbarch_debug)
5428 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n",
5429 mips_abi);
2e4ebe70 5430
ec03c1ac 5431 /* Also used when doing an architecture lookup. */
4b9b3959 5432 if (gdbarch_debug)
ec03c1ac
AC
5433 fprintf_unfiltered (gdb_stdlog,
5434 "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n",
5435 mips64_transfers_32bit_regs_p);
0dadbba0 5436
8d5838b5 5437 /* Determine the MIPS FPU type. */
609ca2b9
DJ
5438#ifdef HAVE_ELF
5439 if (info.abfd
5440 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5441 elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5442 Tag_GNU_MIPS_ABI_FP);
5443#endif /* HAVE_ELF */
5444
8d5838b5
AC
5445 if (!mips_fpu_type_auto)
5446 fpu_type = mips_fpu_type;
609ca2b9
DJ
5447 else if (elf_fpu_type != 0)
5448 {
5449 switch (elf_fpu_type)
5450 {
5451 case 1:
5452 fpu_type = MIPS_FPU_DOUBLE;
5453 break;
5454 case 2:
5455 fpu_type = MIPS_FPU_SINGLE;
5456 break;
5457 case 3:
5458 default:
5459 /* Soft float or unknown. */
5460 fpu_type = MIPS_FPU_NONE;
5461 break;
5462 }
5463 }
8d5838b5
AC
5464 else if (info.bfd_arch_info != NULL
5465 && info.bfd_arch_info->arch == bfd_arch_mips)
5466 switch (info.bfd_arch_info->mach)
5467 {
5468 case bfd_mach_mips3900:
5469 case bfd_mach_mips4100:
5470 case bfd_mach_mips4111:
a9d61c86 5471 case bfd_mach_mips4120:
8d5838b5
AC
5472 fpu_type = MIPS_FPU_NONE;
5473 break;
5474 case bfd_mach_mips4650:
5475 fpu_type = MIPS_FPU_SINGLE;
5476 break;
5477 default:
5478 fpu_type = MIPS_FPU_DOUBLE;
5479 break;
5480 }
5481 else if (arches != NULL)
5482 fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type;
5483 else
5484 fpu_type = MIPS_FPU_DOUBLE;
5485 if (gdbarch_debug)
5486 fprintf_unfiltered (gdb_stdlog,
6d82d43b 5487 "mips_gdbarch_init: fpu_type = %d\n", fpu_type);
8d5838b5 5488
29709017
DJ
5489 /* Check for blatant incompatibilities. */
5490
5491 /* If we have only 32-bit registers, then we can't debug a 64-bit
5492 ABI. */
5493 if (info.target_desc
5494 && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL
5495 && mips_abi != MIPS_ABI_EABI32
5496 && mips_abi != MIPS_ABI_O32)
f8b73d13
DJ
5497 {
5498 if (tdesc_data != NULL)
5499 tdesc_data_cleanup (tdesc_data);
5500 return NULL;
5501 }
29709017 5502
c2d11a7d
JM
5503 /* try to find a pre-existing architecture */
5504 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5505 arches != NULL;
5506 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5507 {
5508 /* MIPS needs to be pedantic about which ABI the object is
102182a9 5509 using. */
9103eae0 5510 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
c2d11a7d 5511 continue;
9103eae0 5512 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
0dadbba0 5513 continue;
719ec221
AC
5514 /* Need to be pedantic about which register virtual size is
5515 used. */
5516 if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p
5517 != mips64_transfers_32bit_regs_p)
5518 continue;
8d5838b5
AC
5519 /* Be pedantic about which FPU is selected. */
5520 if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type)
5521 continue;
f8b73d13
DJ
5522
5523 if (tdesc_data != NULL)
5524 tdesc_data_cleanup (tdesc_data);
4be87837 5525 return arches->gdbarch;
c2d11a7d
JM
5526 }
5527
102182a9 5528 /* Need a new architecture. Fill in a target specific vector. */
c2d11a7d
JM
5529 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5530 gdbarch = gdbarch_alloc (&info, tdep);
5531 tdep->elf_flags = elf_flags;
719ec221 5532 tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p;
ec03c1ac
AC
5533 tdep->found_abi = found_abi;
5534 tdep->mips_abi = mips_abi;
8d5838b5 5535 tdep->mips_fpu_type = fpu_type;
29709017
DJ
5536 tdep->register_size_valid_p = 0;
5537 tdep->register_size = 0;
5538
5539 if (info.target_desc)
5540 {
5541 /* Some useful properties can be inferred from the target. */
5542 if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL)
5543 {
5544 tdep->register_size_valid_p = 1;
5545 tdep->register_size = 4;
5546 }
5547 else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL)
5548 {
5549 tdep->register_size_valid_p = 1;
5550 tdep->register_size = 8;
5551 }
5552 }
c2d11a7d 5553
102182a9 5554 /* Initially set everything according to the default ABI/ISA. */
c2d11a7d
JM
5555 set_gdbarch_short_bit (gdbarch, 16);
5556 set_gdbarch_int_bit (gdbarch, 32);
5557 set_gdbarch_float_bit (gdbarch, 32);
5558 set_gdbarch_double_bit (gdbarch, 64);
5559 set_gdbarch_long_double_bit (gdbarch, 64);
a4b8ebc8
AC
5560 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
5561 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
5562 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
1d06468c 5563
6d82d43b 5564 set_gdbarch_elf_make_msymbol_special (gdbarch,
f7ab6ec6
MS
5565 mips_elf_make_msymbol_special);
5566
16e109ca 5567 /* Fill in the OS dependant register numbers and names. */
56cea623 5568 {
16e109ca 5569 const char **reg_names;
56cea623
AC
5570 struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch,
5571 struct mips_regnum);
f8b73d13
DJ
5572 if (tdesc_has_registers (info.target_desc))
5573 {
5574 regnum->lo = MIPS_EMBED_LO_REGNUM;
5575 regnum->hi = MIPS_EMBED_HI_REGNUM;
5576 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
5577 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
5578 regnum->pc = MIPS_EMBED_PC_REGNUM;
5579 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
5580 regnum->fp_control_status = 70;
5581 regnum->fp_implementation_revision = 71;
5582 num_regs = MIPS_LAST_EMBED_REGNUM + 1;
5583 reg_names = NULL;
5584 }
5585 else if (info.osabi == GDB_OSABI_IRIX)
56cea623
AC
5586 {
5587 regnum->fp0 = 32;
5588 regnum->pc = 64;
5589 regnum->cause = 65;
5590 regnum->badvaddr = 66;
5591 regnum->hi = 67;
5592 regnum->lo = 68;
5593 regnum->fp_control_status = 69;
5594 regnum->fp_implementation_revision = 70;
5595 num_regs = 71;
16e109ca 5596 reg_names = mips_irix_reg_names;
56cea623
AC
5597 }
5598 else
5599 {
5600 regnum->lo = MIPS_EMBED_LO_REGNUM;
5601 regnum->hi = MIPS_EMBED_HI_REGNUM;
5602 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
5603 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
5604 regnum->pc = MIPS_EMBED_PC_REGNUM;
5605 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
5606 regnum->fp_control_status = 70;
5607 regnum->fp_implementation_revision = 71;
5608 num_regs = 90;
16e109ca
AC
5609 if (info.bfd_arch_info != NULL
5610 && info.bfd_arch_info->mach == bfd_mach_mips3900)
5611 reg_names = mips_tx39_reg_names;
5612 else
5613 reg_names = mips_generic_reg_names;
56cea623 5614 }
3e8c568d 5615 /* FIXME: cagney/2003-11-15: For MIPS, hasn't gdbarch_pc_regnum been
56cea623 5616 replaced by read_pc? */
f10683bb
MH
5617 set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs);
5618 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
56cea623
AC
5619 set_gdbarch_fp0_regnum (gdbarch, regnum->fp0);
5620 set_gdbarch_num_regs (gdbarch, num_regs);
5621 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
16e109ca 5622 set_gdbarch_register_name (gdbarch, mips_register_name);
82e91389 5623 set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer);
16e109ca
AC
5624 tdep->mips_processor_reg_names = reg_names;
5625 tdep->regnum = regnum;
56cea623 5626 }
fe29b929 5627
0dadbba0 5628 switch (mips_abi)
c2d11a7d 5629 {
0dadbba0 5630 case MIPS_ABI_O32:
25ab4790 5631 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
29dfb2ac 5632 set_gdbarch_return_value (gdbarch, mips_o32_return_value);
4c7d22cb 5633 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
56cea623 5634 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
4014092b 5635 tdep->default_mask_address_p = 0;
c2d11a7d
JM
5636 set_gdbarch_long_bit (gdbarch, 32);
5637 set_gdbarch_ptr_bit (gdbarch, 32);
5638 set_gdbarch_long_long_bit (gdbarch, 64);
5639 break;
0dadbba0 5640 case MIPS_ABI_O64:
25ab4790 5641 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
9c8fdbfa 5642 set_gdbarch_return_value (gdbarch, mips_o64_return_value);
4c7d22cb 5643 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
56cea623 5644 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
361d1df0 5645 tdep->default_mask_address_p = 0;
c2d11a7d
JM
5646 set_gdbarch_long_bit (gdbarch, 32);
5647 set_gdbarch_ptr_bit (gdbarch, 32);
5648 set_gdbarch_long_long_bit (gdbarch, 64);
5649 break;
0dadbba0 5650 case MIPS_ABI_EABI32:
25ab4790 5651 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
9c8fdbfa 5652 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
4c7d22cb 5653 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
56cea623 5654 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
4014092b 5655 tdep->default_mask_address_p = 0;
c2d11a7d
JM
5656 set_gdbarch_long_bit (gdbarch, 32);
5657 set_gdbarch_ptr_bit (gdbarch, 32);
5658 set_gdbarch_long_long_bit (gdbarch, 64);
5659 break;
0dadbba0 5660 case MIPS_ABI_EABI64:
25ab4790 5661 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
9c8fdbfa 5662 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
4c7d22cb 5663 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
56cea623 5664 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
4014092b 5665 tdep->default_mask_address_p = 0;
c2d11a7d
JM
5666 set_gdbarch_long_bit (gdbarch, 64);
5667 set_gdbarch_ptr_bit (gdbarch, 64);
5668 set_gdbarch_long_long_bit (gdbarch, 64);
5669 break;
0dadbba0 5670 case MIPS_ABI_N32:
25ab4790 5671 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
29dfb2ac 5672 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
4c7d22cb 5673 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
56cea623 5674 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
4014092b 5675 tdep->default_mask_address_p = 0;
0dadbba0
AC
5676 set_gdbarch_long_bit (gdbarch, 32);
5677 set_gdbarch_ptr_bit (gdbarch, 32);
5678 set_gdbarch_long_long_bit (gdbarch, 64);
fed7ba43 5679 set_gdbarch_long_double_bit (gdbarch, 128);
b14d30e1 5680 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
28d169de
KB
5681 break;
5682 case MIPS_ABI_N64:
25ab4790 5683 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
29dfb2ac 5684 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
4c7d22cb 5685 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
56cea623 5686 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
28d169de
KB
5687 tdep->default_mask_address_p = 0;
5688 set_gdbarch_long_bit (gdbarch, 64);
5689 set_gdbarch_ptr_bit (gdbarch, 64);
5690 set_gdbarch_long_long_bit (gdbarch, 64);
fed7ba43 5691 set_gdbarch_long_double_bit (gdbarch, 128);
b14d30e1 5692 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
0dadbba0 5693 break;
c2d11a7d 5694 default:
e2e0b3e5 5695 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
c2d11a7d
JM
5696 }
5697
22e47e37
FF
5698 /* GCC creates a pseudo-section whose name specifies the size of
5699 longs, since -mlong32 or -mlong64 may be used independent of
5700 other options. How those options affect pointer sizes is ABI and
5701 architecture dependent, so use them to override the default sizes
5702 set by the ABI. This table shows the relationship between ABI,
5703 -mlongXX, and size of pointers:
5704
5705 ABI -mlongXX ptr bits
5706 --- -------- --------
5707 o32 32 32
5708 o32 64 32
5709 n32 32 32
5710 n32 64 64
5711 o64 32 32
5712 o64 64 64
5713 n64 32 32
5714 n64 64 64
5715 eabi32 32 32
5716 eabi32 64 32
5717 eabi64 32 32
5718 eabi64 64 64
5719
5720 Note that for o32 and eabi32, pointers are always 32 bits
5721 regardless of any -mlongXX option. For all others, pointers and
5722 longs are the same, as set by -mlongXX or set by defaults.
5723 */
5724
5725 if (info.abfd != NULL)
5726 {
5727 int long_bit = 0;
5728
5729 bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit);
5730 if (long_bit)
5731 {
5732 set_gdbarch_long_bit (gdbarch, long_bit);
5733 switch (mips_abi)
5734 {
5735 case MIPS_ABI_O32:
5736 case MIPS_ABI_EABI32:
5737 break;
5738 case MIPS_ABI_N32:
5739 case MIPS_ABI_O64:
5740 case MIPS_ABI_N64:
5741 case MIPS_ABI_EABI64:
5742 set_gdbarch_ptr_bit (gdbarch, long_bit);
5743 break;
5744 default:
5745 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
5746 }
5747 }
5748 }
5749
a5ea2558
AC
5750 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
5751 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
5752 comment:
5753
5754 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
5755 flag in object files because to do so would make it impossible to
102182a9 5756 link with libraries compiled without "-gp32". This is
a5ea2558 5757 unnecessarily restrictive.
361d1df0 5758
a5ea2558
AC
5759 We could solve this problem by adding "-gp32" multilibs to gcc,
5760 but to set this flag before gcc is built with such multilibs will
5761 break too many systems.''
5762
5763 But even more unhelpfully, the default linker output target for
5764 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
5765 for 64-bit programs - you need to change the ABI to change this,
102182a9 5766 and not all gcc targets support that currently. Therefore using
a5ea2558
AC
5767 this flag to detect 32-bit mode would do the wrong thing given
5768 the current gcc - it would make GDB treat these 64-bit programs
102182a9 5769 as 32-bit programs by default. */
a5ea2558 5770
6c997a34 5771 set_gdbarch_read_pc (gdbarch, mips_read_pc);
b6cb9035 5772 set_gdbarch_write_pc (gdbarch, mips_write_pc);
c2d11a7d 5773
102182a9
MS
5774 /* Add/remove bits from an address. The MIPS needs be careful to
5775 ensure that all 32 bit addresses are sign extended to 64 bits. */
875e1767
AC
5776 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
5777
58dfe9ff
AC
5778 /* Unwind the frame. */
5779 set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc);
30244cd8 5780 set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp);
edfae063 5781 set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id);
10312cc4 5782
102182a9 5783 /* Map debug register numbers onto internal register numbers. */
88c72b7d 5784 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6d82d43b
AC
5785 set_gdbarch_ecoff_reg_to_regnum (gdbarch,
5786 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5787 set_gdbarch_dwarf_reg_to_regnum (gdbarch,
5788 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
5789 set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
5790 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
a4b8ebc8 5791 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
88c72b7d 5792
c2d11a7d
JM
5793 /* MIPS version of CALL_DUMMY */
5794
9710e734
AC
5795 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
5796 replaced by a command, and all targets will default to on stack
5797 (regardless of the stack's execute status). */
5798 set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL);
dc604539 5799 set_gdbarch_frame_align (gdbarch, mips_frame_align);
d05285fa 5800
87783b8b
AC
5801 set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p);
5802 set_gdbarch_register_to_value (gdbarch, mips_register_to_value);
5803 set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
5804
f7b9e9fc
AC
5805 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
5806 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
f7b9e9fc
AC
5807
5808 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
f7b9e9fc 5809
97ab0fdd
MR
5810 set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p);
5811
fc0c74b1
AC
5812 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
5813 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
5814 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
70f80edf 5815
a4b8ebc8 5816 set_gdbarch_register_type (gdbarch, mips_register_type);
78fde5f8 5817
e11c53d2 5818 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
bf1f5b4c 5819
e5ab0dce
AC
5820 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
5821
3a3bc038
AC
5822 /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT,
5823 HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT
5824 need to all be folded into the target vector. Since they are
5825 being used as guards for STOPPED_BY_WATCHPOINT, why not have
5826 STOPPED_BY_WATCHPOINT return the type of watchpoint that the code
5827 is sitting on? */
5828 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
5829
e7d6a6d2 5830 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code);
757a7cc6 5831
3352ef37
AC
5832 set_gdbarch_single_step_through_delay (gdbarch, mips_single_step_through_delay);
5833
0d5de010
DJ
5834 /* Virtual tables. */
5835 set_gdbarch_vbit_in_delta (gdbarch, 1);
5836
29709017
DJ
5837 mips_register_g_packet_guesses (gdbarch);
5838
6de918a6 5839 /* Hook in OS ABI-specific overrides, if they have been registered. */
822b6570 5840 info.tdep_info = (void *) tdesc_data;
6de918a6 5841 gdbarch_init_osabi (info, gdbarch);
757a7cc6 5842
5792a79b 5843 /* Unwind the frame. */
2bd0c3d7 5844 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
eec63939 5845 frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer);
45c9dd44
AC
5846 frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer);
5847 frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer);
2bd0c3d7 5848 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
eec63939 5849 frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer);
45c9dd44
AC
5850 frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer);
5851 frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer);
5792a79b 5852
f8b73d13
DJ
5853 if (tdesc_data)
5854 {
5855 set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type);
7cc46491 5856 tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
f8b73d13
DJ
5857
5858 /* Override the normal target description methods to handle our
5859 dual real and pseudo registers. */
5860 set_gdbarch_register_name (gdbarch, mips_register_name);
5861 set_gdbarch_register_reggroup_p (gdbarch, mips_tdesc_register_reggroup_p);
5862
5863 num_regs = gdbarch_num_regs (gdbarch);
5864 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
5865 set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs);
5866 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
5867 }
5868
5869 /* Add ABI-specific aliases for the registers. */
5870 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
5871 for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++)
5872 user_reg_add (gdbarch, mips_n32_n64_aliases[i].name,
5873 value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum);
5874 else
5875 for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++)
5876 user_reg_add (gdbarch, mips_o32_aliases[i].name,
5877 value_of_mips_user_reg, &mips_o32_aliases[i].regnum);
5878
5879 /* Add some other standard aliases. */
5880 for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++)
5881 user_reg_add (gdbarch, mips_register_aliases[i].name,
5882 value_of_mips_user_reg, &mips_register_aliases[i].regnum);
5883
4b9b3959
AC
5884 return gdbarch;
5885}
5886
2e4ebe70 5887static void
6d82d43b 5888mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c)
2e4ebe70
DJ
5889{
5890 struct gdbarch_info info;
5891
5892 /* Force the architecture to update, and (if it's a MIPS architecture)
5893 mips_gdbarch_init will take care of the rest. */
5894 gdbarch_info_init (&info);
5895 gdbarch_update_p (info);
5896}
5897
ad188201
KB
5898/* Print out which MIPS ABI is in use. */
5899
5900static void
1f8ca57c
JB
5901show_mips_abi (struct ui_file *file,
5902 int from_tty,
5903 struct cmd_list_element *ignored_cmd,
5904 const char *ignored_value)
ad188201
KB
5905{
5906 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
1f8ca57c
JB
5907 fprintf_filtered
5908 (file,
5909 "The MIPS ABI is unknown because the current architecture "
5910 "is not MIPS.\n");
ad188201
KB
5911 else
5912 {
5913 enum mips_abi global_abi = global_mips_abi ();
5914 enum mips_abi actual_abi = mips_abi (current_gdbarch);
5915 const char *actual_abi_str = mips_abi_strings[actual_abi];
5916
5917 if (global_abi == MIPS_ABI_UNKNOWN)
1f8ca57c
JB
5918 fprintf_filtered
5919 (file,
5920 "The MIPS ABI is set automatically (currently \"%s\").\n",
6d82d43b 5921 actual_abi_str);
ad188201 5922 else if (global_abi == actual_abi)
1f8ca57c
JB
5923 fprintf_filtered
5924 (file,
5925 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6d82d43b 5926 actual_abi_str);
ad188201
KB
5927 else
5928 {
5929 /* Probably shouldn't happen... */
1f8ca57c
JB
5930 fprintf_filtered
5931 (file,
5932 "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6d82d43b 5933 actual_abi_str, mips_abi_strings[global_abi]);
ad188201
KB
5934 }
5935 }
5936}
5937
4b9b3959 5938static void
72a155b4 5939mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
4b9b3959 5940{
72a155b4 5941 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4b9b3959 5942 if (tdep != NULL)
c2d11a7d 5943 {
acdb74a0
AC
5944 int ef_mips_arch;
5945 int ef_mips_32bitmode;
f49e4e6d 5946 /* Determine the ISA. */
acdb74a0
AC
5947 switch (tdep->elf_flags & EF_MIPS_ARCH)
5948 {
5949 case E_MIPS_ARCH_1:
5950 ef_mips_arch = 1;
5951 break;
5952 case E_MIPS_ARCH_2:
5953 ef_mips_arch = 2;
5954 break;
5955 case E_MIPS_ARCH_3:
5956 ef_mips_arch = 3;
5957 break;
5958 case E_MIPS_ARCH_4:
93d56215 5959 ef_mips_arch = 4;
acdb74a0
AC
5960 break;
5961 default:
93d56215 5962 ef_mips_arch = 0;
acdb74a0
AC
5963 break;
5964 }
f49e4e6d 5965 /* Determine the size of a pointer. */
acdb74a0 5966 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
4b9b3959
AC
5967 fprintf_unfiltered (file,
5968 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
0dadbba0 5969 tdep->elf_flags);
4b9b3959 5970 fprintf_unfiltered (file,
acdb74a0
AC
5971 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
5972 ef_mips_32bitmode);
5973 fprintf_unfiltered (file,
5974 "mips_dump_tdep: ef_mips_arch = %d\n",
5975 ef_mips_arch);
5976 fprintf_unfiltered (file,
5977 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6d82d43b 5978 tdep->mips_abi, mips_abi_strings[tdep->mips_abi]);
4014092b
AC
5979 fprintf_unfiltered (file,
5980 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
480d3dd2 5981 mips_mask_address_p (tdep),
4014092b 5982 tdep->default_mask_address_p);
c2d11a7d 5983 }
4b9b3959
AC
5984 fprintf_unfiltered (file,
5985 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
5986 MIPS_DEFAULT_FPU_TYPE,
5987 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
5988 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
5989 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
5990 : "???"));
6d82d43b 5991 fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI);
4b9b3959
AC
5992 fprintf_unfiltered (file,
5993 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
5994 MIPS_FPU_TYPE,
5995 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
5996 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
5997 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
5998 : "???"));
c2d11a7d
JM
5999}
6000
6d82d43b 6001extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
a78f21af 6002
c906108c 6003void
acdb74a0 6004_initialize_mips_tdep (void)
c906108c
SS
6005{
6006 static struct cmd_list_element *mipsfpulist = NULL;
6007 struct cmd_list_element *c;
6008
6d82d43b 6009 mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN];
2e4ebe70
DJ
6010 if (MIPS_ABI_LAST + 1
6011 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
e2e0b3e5 6012 internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync"));
2e4ebe70 6013
4b9b3959 6014 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
c906108c 6015
8d5f9dcb
DJ
6016 mips_pdr_data = register_objfile_data ();
6017
4eb0ad19
DJ
6018 /* Create feature sets with the appropriate properties. The values
6019 are not important. */
6020 mips_tdesc_gp32 = allocate_target_description ();
6021 set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, "");
6022
6023 mips_tdesc_gp64 = allocate_target_description ();
6024 set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, "");
6025
a5ea2558
AC
6026 /* Add root prefix command for all "set mips"/"show mips" commands */
6027 add_prefix_cmd ("mips", no_class, set_mips_command,
1bedd215 6028 _("Various MIPS specific commands."),
a5ea2558
AC
6029 &setmipscmdlist, "set mips ", 0, &setlist);
6030
6031 add_prefix_cmd ("mips", no_class, show_mips_command,
1bedd215 6032 _("Various MIPS specific commands."),
a5ea2558
AC
6033 &showmipscmdlist, "show mips ", 0, &showlist);
6034
2e4ebe70 6035 /* Allow the user to override the ABI. */
7ab04401
AC
6036 add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings,
6037 &mips_abi_string, _("\
6038Set the MIPS ABI used by this program."), _("\
6039Show the MIPS ABI used by this program."), _("\
6040This option can be set to one of:\n\
6041 auto - the default ABI associated with the current binary\n\
6042 o32\n\
6043 o64\n\
6044 n32\n\
6045 n64\n\
6046 eabi32\n\
6047 eabi64"),
6048 mips_abi_update,
6049 show_mips_abi,
6050 &setmipscmdlist, &showmipscmdlist);
2e4ebe70 6051
c906108c
SS
6052 /* Let the user turn off floating point and set the fence post for
6053 heuristic_proc_start. */
6054
6055 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
1bedd215 6056 _("Set use of MIPS floating-point coprocessor."),
c906108c
SS
6057 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6058 add_cmd ("single", class_support, set_mipsfpu_single_command,
1a966eab 6059 _("Select single-precision MIPS floating-point coprocessor."),
c906108c
SS
6060 &mipsfpulist);
6061 add_cmd ("double", class_support, set_mipsfpu_double_command,
1a966eab 6062 _("Select double-precision MIPS floating-point coprocessor."),
c906108c
SS
6063 &mipsfpulist);
6064 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6065 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6066 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6067 add_cmd ("none", class_support, set_mipsfpu_none_command,
1a966eab 6068 _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
c906108c
SS
6069 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6070 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6071 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6072 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
1a966eab 6073 _("Select MIPS floating-point coprocessor automatically."),
c906108c
SS
6074 &mipsfpulist);
6075 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
1a966eab 6076 _("Show current use of MIPS floating-point coprocessor target."),
c906108c
SS
6077 &showlist);
6078
c906108c
SS
6079 /* We really would like to have both "0" and "unlimited" work, but
6080 command.c doesn't deal with that. So make it a var_zinteger
6081 because the user can always use "999999" or some such for unlimited. */
6bcadd06 6082 add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
7915a72c
AC
6083 &heuristic_fence_post, _("\
6084Set the distance searched for the start of a function."), _("\
6085Show the distance searched for the start of a function."), _("\
c906108c
SS
6086If you are debugging a stripped executable, GDB needs to search through the\n\
6087program for the start of a function. This command sets the distance of the\n\
7915a72c 6088search. The only need to set it is when debugging a stripped executable."),
2c5b56ce 6089 reinit_frame_cache_sfunc,
7915a72c 6090 NULL, /* FIXME: i18n: The distance searched for the start of a function is %s. */
6bcadd06 6091 &setlist, &showlist);
c906108c
SS
6092
6093 /* Allow the user to control whether the upper bits of 64-bit
6094 addresses should be zeroed. */
7915a72c
AC
6095 add_setshow_auto_boolean_cmd ("mask-address", no_class,
6096 &mask_address_var, _("\
6097Set zeroing of upper 32 bits of 64-bit addresses."), _("\
6098Show zeroing of upper 32 bits of 64-bit addresses."), _("\
e9e68a56 6099Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
7915a72c 6100allow GDB to determine the correct value."),
08546159
AC
6101 NULL, show_mask_address,
6102 &setmipscmdlist, &showmipscmdlist);
43e526b9
JM
6103
6104 /* Allow the user to control the size of 32 bit registers within the
6105 raw remote packet. */
b3f42336 6106 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure,
7915a72c
AC
6107 &mips64_transfers_32bit_regs_p, _("\
6108Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6109 _("\
6110Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6111 _("\
719ec221
AC
6112Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6113that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
7915a72c 611464 bits for others. Use \"off\" to disable compatibility mode"),
2c5b56ce 6115 set_mips64_transfers_32bit_regs,
7915a72c 6116 NULL, /* FIXME: i18n: Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s. */
7915a72c 6117 &setlist, &showlist);
9ace0497
AC
6118
6119 /* Debug this files internals. */
6bcadd06 6120 add_setshow_zinteger_cmd ("mips", class_maintenance,
7915a72c
AC
6121 &mips_debug, _("\
6122Set mips debugging."), _("\
6123Show mips debugging."), _("\
6124When non-zero, mips specific debugging is enabled."),
2c5b56ce 6125 NULL,
7915a72c 6126 NULL, /* FIXME: i18n: Mips debugging is currently %s. */
6bcadd06 6127 &setdebuglist, &showdebuglist);
c906108c 6128}