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