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