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