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